Subversion Repositories Kolibri OS

Rev

Rev 7051 | Rev 7750 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7051 Rev 7252
1
#ifndef AUTOBUILD
1
#ifndef AUTOBUILD
2
	#include "lang.h--"
2
	#include "lang.h--"
3
#endif
3
#endif
4
 
4
 
5
#define MEMSIZE 4096 * 1024 * 2
5
#define MEMSIZE 4096 * 1024 * 2
6
#include "../lib/strings.h"
6
#include "../lib/strings.h"
7
#include "../lib/gui.h"
7
#include "../lib/gui.h"
8
#include "../lib/obj/box_lib.h"
8
#include "../lib/obj/box_lib.h"
9
 
9
 
10
#ifdef LANG_RUS
10
#ifdef LANG_RUS
11
  #define WINDOW_TITLE "‘«®¢ à¨ª 2.3"
11
  #define WINDOW_TITLE "‘«®¢ à¨ª 2.3"
12
  #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
12
  #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
13
  #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
13
  #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
14
  #define ERROR "Žè¨¡ª  #%d"
14
  #define ERROR "Žè¨¡ª  #%d"
15
#else
15
#else
16
  #define WINDOW_TITLE "Dictionary v2.3"
16
  #define WINDOW_TITLE "Dictionary v2.3"
17
  #define DICTIONARY_LOADED "Dictionary loaded"
17
  #define DICTIONARY_LOADED "Dictionary loaded"
18
  #define WORD_NOT_FOUND "Word isn't found in the dictionary"
18
  #define WORD_NOT_FOUND "Word isn't found in the dictionary"
19
  #define ERROR "Error #%d"
19
  #define ERROR "Error #%d"
20
  #endif
20
  #endif
21
 
21
 
22
proc_info Form;
22
proc_info Form;
23
char edit_text[256], search_word[256], translate_result[4096];
23
char edit_text[256], search_word[256], translate_result[4096];
24
#define TOPH 45
24
#define TOPH 45
25
 
25
 
26
unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
26
unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
27
unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
27
unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
28
dword io_buffer_data;
28
dword io_buffer_data;
29
 
29
 
30
#define TEXT_ENG_RUS "ENG\26RUS"
30
#define TEXT_ENG_RUS "ENG\26RUS"
31
#define TEXT_RUS_ENG "RUS\26ENG"
31
#define TEXT_RUS_ENG "RUS\26ENG"
32
#define TEXT_VOC_R_E "ENG     RUS"
32
#define TEXT_VOC_R_E "ENG     RUS"
33
#define TEXT_VOC_E_R "RUS     ENG"
33
#define TEXT_VOC_E_R "RUS     ENG"
34
#define ENG_RUS 0
34
#define ENG_RUS 0
35
#define RUS_ENG 1
35
#define RUS_ENG 1
36
#define BUTTON_CHANGE_LANGUAGE 10
36
#define BUTTON_CHANGE_LANGUAGE 10
37
int active_dict=2;
37
int active_dict=2;
38
 
-
 
39
int mouse_dd;
38
 
40
edit_box edit1= {200,13,13,0xffffff,0x94AECE,0xffffff,0x94AECE,0x10000000,248,#edit_text,#mouse_dd,100000000000010b};
39
edit_box edit1= {200,13,13,0xffffff,0x94AECE,0xffffff,0x94AECE,0x10000000,248,#edit_text,0,100000000000010b};
41
 
40
 
42
 
41
 
43
 
42
 
44
void main()
43
void main()
45
{   
44
{   
46
	int id;
45
	int id;
47
	load_dll(boxlib, #box_lib_init,0);
46
	load_dll(boxlib, #box_lib_init,0);
48
	OpenDictionary(ENG_RUS);
47
	OpenDictionary(ENG_RUS);
49
	if (param)
48
	if (param)
50
	{
49
	{
51
		strcpy(#edit_text, #param);
50
		strcpy(#edit_text, #param);
52
		edit1.size=edit1.pos=strlen(#edit_text);
51
		edit1.size=edit1.pos=strlen(#edit_text);
53
		Translate();
52
		Translate();
54
	}
53
	}
55
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);	
54
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);	
56
	loop()
55
	loop()
57
	{
56
	{
58
		switch(WaitEvent()) 
57
		switch(WaitEvent()) 
59
		{
58
		{
60
		case evMouse:
59
		case evMouse:
61
			edit_box_mouse stdcall (#edit1);
60
			edit_box_mouse stdcall (#edit1);
62
			break;
61
			break;
63
 
62
 
64
		case evButton:
63
		case evButton:
65
            id=GetButtonID();               
64
            id=GetButtonID();               
66
            if (id==01) ExitProcess();
65
            if (id==01) ExitProcess();
67
			if (id==BUTTON_CHANGE_LANGUAGE) { 
66
			if (id==BUTTON_CHANGE_LANGUAGE) { 
68
				if (active_dict == ENG_RUS) OpenDictionary(RUS_ENG); else OpenDictionary(ENG_RUS);
67
				if (active_dict == ENG_RUS) OpenDictionary(RUS_ENG); else OpenDictionary(ENG_RUS);
69
				DrawLangButtons();
68
				DrawLangButtons();
70
			}
69
			}
71
			break;
70
			break;
72
 
71
 
73
        case evKey:
72
        case evKey:
74
			GetKeys();
73
			GetKeys();
75
			edit_box_key stdcall(#edit1);	
74
			edit_box_key stdcall(#edit1);	
76
			Translate();
75
			Translate();
77
			break;
76
			break;
78
			
77
			
79
         case evReDraw:
78
         case evReDraw:
80
			system.color.get();
79
			system.color.get();
81
			DefineAndDrawWindow(215,120,500,350,0x73,system.color.work,WINDOW_TITLE,0);
80
			DefineAndDrawWindow(215,120,500,350,0x73,system.color.work,WINDOW_TITLE,0);
82
			GetProcessInfo(#Form, SelfInfo);
81
			GetProcessInfo(#Form, SelfInfo);
83
			if (Form.status_window>2) break;
82
			if (Form.status_window>2) break;
84
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
83
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
85
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
84
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
86
			DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg
85
			DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg
87
			DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
86
			DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
88
			edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
87
			edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
89
			edit_box_draw stdcall(#edit1);
88
			edit_box_draw stdcall(#edit1);
90
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
89
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
91
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, system.color.work_graph);
90
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, system.color.work_graph);
92
			DrawTranslation();
91
			DrawTranslation();
93
			DrawLangButtons();
92
			DrawLangButtons();
94
      }
93
      }
95
   }
94
   }
96
}
95
}
97
 
96
 
98
 
97
 
99
void DrawLangButtons()
98
void DrawLangButtons()
100
{
99
{
101
	dword direction;
100
	dword direction;
102
	DrawBar(Form.width-120, edit1.top+3, 100, 25, system.color.work);
101
	DrawBar(Form.width-120, edit1.top+3, 100, 25, system.color.work);
103
	DefineButton(Form.width-88, edit1.top-4+3, 20, 20, BUTTON_CHANGE_LANGUAGE, system.color.work_button);
102
	DefineButton(Form.width-88, edit1.top-4+3, 20, 20, BUTTON_CHANGE_LANGUAGE, system.color.work_button);
104
	WriteText(Form.width-82, edit1.top-1+3, 10000001b, system.color.work_button_text, "\26");
103
	WriteText(Form.width-82, edit1.top-1+3, 10000001b, system.color.work_button_text, "\26");
105
	if (active_dict == ENG_RUS) direction = TEXT_VOC_R_E; else direction = TEXT_VOC_E_R;
104
	if (active_dict == ENG_RUS) direction = TEXT_VOC_R_E; else direction = TEXT_VOC_E_R;
106
	WriteText(Form.width-120, edit1.top+3, 0x90, system.color.work_text, direction);
105
	WriteText(Form.width-120, edit1.top+3, 0x90, system.color.work_text, direction);
107
}
106
}
108
 
107
 
109
void Translate()
108
void Translate()
110
{
109
{
111
	dword translation_start, translation_end;
110
	dword translation_start, translation_end;
112
 
111
 
113
	sprintf(#search_word, "\10%s\13", #edit_text);
112
	sprintf(#search_word, "\10%s\13", #edit_text);
114
	strupr(#search_word);
113
	strupr(#search_word);
115
 
114
 
116
	if (!edit_text) goto _TR_END;
115
	if (!edit_text) goto _TR_END;
117
 
116
 
118
	translation_start = strstr(io_buffer_data, #search_word);
117
	translation_start = strstr(io_buffer_data, #search_word);
119
	if (!translation_start) 
118
	if (!translation_start) 
120
	{
119
	{
121
		strcpy(#translate_result, WORD_NOT_FOUND); 
120
		strcpy(#translate_result, WORD_NOT_FOUND); 
122
	}
121
	}
123
	else 
122
	else 
124
	{
123
	{
125
		translation_start = strchr(translation_start, '"') + 1;
124
		translation_start = strchr(translation_start, '"') + 1;
126
		translation_end = strchr(translation_start, '"');
125
		translation_end = strchr(translation_start, '"');
127
		strlcpy(#translate_result, translation_start, translation_end - translation_start);
126
		strlcpy(#translate_result, translation_start, translation_end - translation_start);
128
	}
127
	}
129
	_TR_END:
128
	_TR_END:
130
	strcpy(#search_word, #search_word+1);
129
	strcpy(#search_word, #search_word+1);
131
	DrawTranslation();
130
	DrawTranslation();
132
}
131
}
133
 
132
 
134
 
133
 
135
void OpenDictionary(dword dict_id)
134
void OpenDictionary(dword dict_id)
136
{
135
{
137
	if (dict_id==active_dict) return;
136
	if (dict_id==active_dict) return;
138
	active_dict = dict_id;
137
	active_dict = dict_id;
139
	if (active_dict==ENG_RUS) 
138
	if (active_dict==ENG_RUS) 
140
	{
139
	{
141
		io_buffer_data=#eng_rus;
140
		io_buffer_data=#eng_rus;
142
		strcpy(#search_word, TEXT_ENG_RUS);
141
		strcpy(#search_word, TEXT_ENG_RUS);
143
	}
142
	}
144
	if (active_dict==RUS_ENG) 
143
	if (active_dict==RUS_ENG) 
145
	{
144
	{
146
		io_buffer_data=#rus_eng;
145
		io_buffer_data=#rus_eng;
147
		strcpy(#search_word, TEXT_RUS_ENG);
146
		strcpy(#search_word, TEXT_RUS_ENG);
148
	}
147
	}
149
	strcpy(#translate_result, DICTIONARY_LOADED);
148
	strcpy(#translate_result, DICTIONARY_LOADED);
150
	DrawTranslation();	
149
	DrawTranslation();	
151
}
150
}
152
 
151
 
153
 
152
 
154
void DrawTranslation()
153
void DrawTranslation()
155
{
154
{
156
	int y_pos=TOPH+1;
155
	int y_pos=TOPH+1;
157
	char draw_buf[4096];
156
	char draw_buf[4096];
158
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf));
157
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf));
159
	
158
	
160
	DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
159
	DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
161
	strttl(#draw_buf);
160
	strttl(#draw_buf);
162
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
161
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
163
 
162
 
164
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 
163
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 
165
		#draw_buf, -1, 0x000000);
164
		#draw_buf, -1, 0x000000);
166
}
165
}
167
 
166
 
168
 
167
 
169
stop:
168
stop: