Subversion Repositories Kolibri OS

Rev

Rev 9602 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9602 Rev 9855
1
#define MEMSIZE 4096 * 1024 * 2
1
#define MEMSIZE 4096 * 1024 * 2
2
#define NO_DLL_INIT
2
#define NO_DLL_INIT
3
#include "../lib/strings.h"
3
#include "../lib/strings.h"
4
#include "../lib/gui.h"
4
#include "../lib/gui.h"
5
#include "../lib/obj/box_lib.h"
5
#include "../lib/obj/box_lib.h"
6
 
6
 
7
#ifdef LANG_RUS
7
#ifdef LANG_RUS
8
  #define WINDOW_TITLE "‘«®¢ à¨ª 2.4"
8
  #define WINDOW_TITLE "‘«®¢ à¨ª 2.4"
9
  #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
9
  #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
10
  #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
10
  #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
11
  #define ERROR "Žè¨¡ª  #%d"
11
  #define ERROR "Žè¨¡ª  #%d"
12
#else
12
#else
13
  #define WINDOW_TITLE "Dictionary v2.4"
13
  #define WINDOW_TITLE "Dictionary v2.4"
14
  #define DICTIONARY_LOADED "Dictionary loaded"
14
  #define DICTIONARY_LOADED "Dictionary loaded"
15
  #define WORD_NOT_FOUND "Word isn't found in the dictionary"
15
  #define WORD_NOT_FOUND "Word isn't found in the dictionary"
16
  #define ERROR "Error #%d"
16
  #define ERROR "Error #%d"
17
#endif
17
#endif
18
 
18
 
19
#define TEXT_ENG_RUS "ENG\26RUS"
19
#define TEXT_ENG_RUS "ENG\26RUS"
20
#define TEXT_RUS_ENG "RUS\26ENG"
20
#define TEXT_RUS_ENG "RUS\26ENG"
21
#define TEXT_RU2EN "ENG     RUS"
21
#define TEXT_RU2EN "ENG     RUS"
22
#define TEXT_EN2RU "RUS     ENG"
22
#define TEXT_EN2RU "RUS     ENG"
23
 
23
 
24
unsigned char speaker[23*40*3]= FROM "speaker.raw";
24
unsigned char speaker[23*40*3]= FROM "speaker.raw";
25
 
25
 
26
proc_info Form;
26
proc_info Form;
27
char search_word[256], translate_result[4096];
27
char search_word[256], translate_result[4096];
28
#define TOPH 45
28
#define TOPH 45
29
#define PRONOUNCED_FILE "/tmp0/1/pronounced.txt"
29
#define PRONOUNCED_FILE "/tmp0/1/pronounced.txt"
30
#define SPEECH_PATH "/kolibrios/media/speech/speech"
30
#define SPEECH_PATH "/kolibrios/speech/speech"
31
dword speaker_id;
31
dword speaker_id;
32
 
32
 
33
unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
33
unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
34
unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
34
unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
35
dword io_buffer_data;
35
dword io_buffer_data;
36
 
36
 
37
#define ENG_RUS 0
37
#define ENG_RUS 0
38
#define RUS_ENG 1
38
#define RUS_ENG 1
39
int active_dict=2;
39
int active_dict=2;
40
 
40
 
41
#define BTN_CHANGE_LANGUAGE 10
41
#define BTN_CHANGE_LANGUAGE 10
42
#define BTN_SPEAKER 11
42
#define BTN_SPEAKER 11
43
 
43
 
44
char edit_text[256];
44
char edit_text[256];
45
edit_box edit1 = {0,13,13,0xffffff,0x94AECE,0xffffff,0xffffff,
45
edit_box edit1 = {0,13,13,0xffffff,0x94AECE,0xffffff,0xffffff,
46
	0x10000000,248,#edit_text,0,ed_focus+ed_always_focus};
46
	0x10000000,248,#edit_text,0,ed_focus+ed_always_focus};
47
 
47
 
48
void main()
48
void main()
49
{   
49
{   
50
	int btnid;
50
	int btnid;
51
	load_dll(boxlib, #box_lib_init,0);
51
	load_dll(boxlib, #box_lib_init,0);
52
	OpenDictionary(ENG_RUS);
52
	OpenDictionary(ENG_RUS);
53
	if (param) {
53
	if (param) {
54
		strcpy(#edit_text, #param);
54
		strcpy(#edit_text, #param);
55
		edit_box_set_text stdcall (#edit1, #param);
55
		edit_box_set_text stdcall (#edit1, #param);
56
		Translate();
56
		Translate();
57
	}
57
	}
58
	@SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);	
58
	@SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);	
59
	loop() switch(@WaitEvent()) 
59
	loop() switch(@WaitEvent()) 
60
	{
60
	{
61
		case evMouse:
61
		case evMouse:
62
			edit_box_mouse stdcall (#edit1);
62
			edit_box_mouse stdcall (#edit1);
63
			break;
63
			break;
64
 
64
 
65
		case evButton:
65
		case evButton:
66
			btnid = @GetButtonID();               
66
			btnid = @GetButtonID();               
67
			if (btnid==01) ExitProcess();
67
			if (btnid==01) ExitProcess();
68
			if (btnid==BTN_CHANGE_LANGUAGE) { 
68
			if (btnid==BTN_CHANGE_LANGUAGE) { 
69
				if (active_dict == ENG_RUS) {
69
				if (active_dict == ENG_RUS) {
70
					OpenDictionary(RUS_ENG); 
70
					OpenDictionary(RUS_ENG); 
71
				} else {
71
				} else {
72
					OpenDictionary(ENG_RUS);
72
					OpenDictionary(ENG_RUS);
73
				}
73
				}
74
				DrawLangButtons();
74
				DrawLangButtons();
75
			}
75
			}
76
			if (btnid==BTN_SPEAKER) {
76
			if (btnid==BTN_SPEAKER) {
77
				if (GetProcessSlot(speaker_id)!=0) {
77
				if (GetProcessSlot(speaker_id)!=0) {
78
					KillProcess(speaker_id);
78
					KillProcess(speaker_id);
79
					pause(50);
79
					pause(50);
80
				} else {
80
				} else {
81
					if (CreateFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
81
					if (CreateFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
82
					pause(50);
82
					pause(50);
83
					speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
83
					speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
84
				}
84
				}
85
				SpeakerDraw();
85
				SpeakerDraw();
86
			} 
86
			} 
87
			break;
87
			break;
88
 
88
 
89
		case evKey:
89
		case evKey:
90
			@GetKey();
90
			@GetKey();
91
			edit_box_key stdcall(#edit1);	
91
			edit_box_key stdcall(#edit1);	
92
			Translate();
92
			Translate();
93
			break;
93
			break;
94
			
94
			
95
		case evReDraw:
95
		case evReDraw:
96
			sc.get();
96
			sc.get();
97
			DefineAndDrawWindow(215,120,500,350,0x73,sc.work,WINDOW_TITLE,0);
97
			DefineAndDrawWindow(215,120,500,350,0x73,sc.work,WINDOW_TITLE,0);
98
			GetProcessInfo(#Form, SelfInfo);
98
			GetProcessInfo(#Form, SelfInfo);
99
			if (Form.status_window&ROLLED_UP) break;
99
			if (Form.status_window&ROLLED_UP) break;
100
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
100
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
101
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
101
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
102
			DrawBar(0, 0, Form.cwidth, TOPH, sc.work); //top bg
102
			DrawBar(0, 0, Form.cwidth, TOPH, sc.work); //top bg
103
			DrawBar(0, TOPH, Form.cwidth, 1, sc.line);
103
			DrawBar(0, TOPH, Form.cwidth, 1, sc.line);
104
			edit1.width = Form.cwidth-edit1.left-edit1.left - 116;
104
			edit1.width = Form.cwidth-edit1.left-edit1.left - 116;
105
			edit_box_draw stdcall(#edit1);
105
			edit_box_draw stdcall(#edit1);
106
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
106
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
107
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, sc.line);
107
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, sc.line);
108
			DrawTranslation();
108
			DrawTranslation();
109
			DrawLangButtons();
109
			DrawLangButtons();
110
	}
110
	}
111
}
111
}
112
 
112
 
113
 
113
 
114
void DrawLangButtons()
114
void DrawLangButtons()
115
{
115
{
116
	dword direction;
116
	dword direction;
117
	int y = edit1.top+3;
117
	int y = edit1.top+3;
118
	DrawBar(Form.cwidth-111, y, 100, 25, sc.work);
118
	DrawBar(Form.cwidth-111, y, 100, 25, sc.work);
119
	DefineButton(Form.cwidth-79, y-4, 20, 20, BTN_CHANGE_LANGUAGE, sc.button);
119
	DefineButton(Form.cwidth-79, y-4, 20, 20, BTN_CHANGE_LANGUAGE, sc.button);
120
	WriteText(Form.cwidth-73, y-1, 10000001b, sc.button_text, "\26");
120
	WriteText(Form.cwidth-73, y-1, 10000001b, sc.button_text, "\26");
121
	if (active_dict == ENG_RUS) {
121
	if (active_dict == ENG_RUS) {
122
		direction = TEXT_RU2EN; 
122
		direction = TEXT_RU2EN; 
123
	} else {
123
	} else {
124
		direction = TEXT_EN2RU;
124
		direction = TEXT_EN2RU;
125
	}
125
	}
126
	WriteText(Form.cwidth-111, y, 0x90, sc.work_text, direction);
126
	WriteText(Form.cwidth-111, y, 0x90, sc.work_text, direction);
127
}
127
}
128
 
128
 
129
void Translate()
129
void Translate()
130
{
130
{
131
	dword tr_start, tr_end;
131
	dword tr_start, tr_end;
132
 
132
 
133
	sprintf(#search_word, "\10%s\13", #edit_text);
133
	sprintf(#search_word, "\10%s\13", #edit_text);
134
	strupr(#search_word);
134
	strupr(#search_word);
135
 
135
 
136
	if (!edit_text) goto _TR_END;
136
	if (!edit_text) goto _TR_END;
137
 
137
 
138
	tr_start = strstr(io_buffer_data, #search_word);
138
	tr_start = strstr(io_buffer_data, #search_word);
139
	if (!tr_start) {
139
	if (!tr_start) {
140
		strcpy(#translate_result, WORD_NOT_FOUND); 
140
		strcpy(#translate_result, WORD_NOT_FOUND); 
141
	} else {
141
	} else {
142
		tr_start = strchr(tr_start, '"') + 1;
142
		tr_start = strchr(tr_start, '"') + 1;
143
		tr_end = strchr(tr_start, '"');
143
		tr_end = strchr(tr_start, '"');
144
		strlcpy(#translate_result, tr_start, tr_end - tr_start);
144
		strlcpy(#translate_result, tr_start, tr_end - tr_start);
145
	}
145
	}
146
	_TR_END:
146
	_TR_END:
147
	strcpy(#search_word, #search_word+1);
147
	strcpy(#search_word, #search_word+1);
148
	DrawTranslation();
148
	DrawTranslation();
149
}
149
}
150
 
150
 
151
 
151
 
152
void OpenDictionary(dword dict_id)
152
void OpenDictionary(dword dict_id)
153
{
153
{
154
	if (dict_id==active_dict) return;
154
	if (dict_id==active_dict) return;
155
	active_dict = dict_id;
155
	active_dict = dict_id;
156
	if (active_dict==ENG_RUS) 
156
	if (active_dict==ENG_RUS) 
157
	{
157
	{
158
		io_buffer_data=#eng_rus;
158
		io_buffer_data=#eng_rus;
159
		strcpy(#search_word, TEXT_ENG_RUS);
159
		strcpy(#search_word, TEXT_ENG_RUS);
160
	}
160
	}
161
	if (active_dict==RUS_ENG) 
161
	if (active_dict==RUS_ENG) 
162
	{
162
	{
163
		io_buffer_data=#rus_eng;
163
		io_buffer_data=#rus_eng;
164
		strcpy(#search_word, TEXT_RUS_ENG);
164
		strcpy(#search_word, TEXT_RUS_ENG);
165
	}
165
	}
166
	strcpy(#translate_result, DICTIONARY_LOADED);
166
	strcpy(#translate_result, DICTIONARY_LOADED);
167
	DrawTranslation();	
167
	DrawTranslation();	
168
}
168
}
169
 
169
 
170
 
170
 
171
void DrawTranslation()
171
void DrawTranslation()
172
{
172
{
173
	int y_pos=TOPH+1;
173
	int y_pos=TOPH+1;
174
	char draw_buf[4096];
174
	char draw_buf[4096];
175
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf)-1);
175
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf)-1);
176
	
176
	
177
	DrawBar(0, y_pos, Form.cwidth, Form.cheight - y_pos, 0xFFFFFF);
177
	DrawBar(0, y_pos, Form.cwidth, Form.cheight - y_pos, 0xFFFFFF);
178
	strttl(#draw_buf);
178
	strttl(#draw_buf);
179
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
179
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
180
 
180
 
181
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 
181
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 
182
		#draw_buf, -1, 0x000000);
182
		#draw_buf, -1, 0x000000);
183
 
183
 
184
	SpeakerDraw();
184
	SpeakerDraw();
185
}
185
}
186
 
186
 
187
void SpeakerDraw()
187
void SpeakerDraw()
188
{
188
{
189
	dword x = Form.cwidth-38;
189
	dword x = Form.cwidth-38;
190
	dword y = Form.cheight-32;
190
	dword y = Form.cheight-32;
191
	if (active_dict == RUS_ENG)
191
	if (active_dict == RUS_ENG)
192
	{
192
	{
193
		DeleteButton(15);
193
		DeleteButton(15);
194
		DrawBar(x,y,23,20,0xFFFFFF);
194
		DrawBar(x,y,23,20,0xFFFFFF);
195
	} else {
195
	} else {
196
		DefineHiddenButton(x-5, y-5, 23+10, 20+9, BTN_SPEAKER);
196
		DefineHiddenButton(x-5, y-5, 23+10, 20+9, BTN_SPEAKER);
197
		if (!GetProcessSlot(speaker_id)) {
197
		if (!GetProcessSlot(speaker_id)) {
198
			PutImage(x, y, 23,20, #speaker);
198
			PutImage(x, y, 23,20, #speaker);
199
		} else {
199
		} else {
200
			PutImage(x, y, 23,20, 23*20*3+#speaker);
200
			PutImage(x, y, 23,20, 23*20*3+#speaker);
201
		}
201
		}
202
	}
202
	}
203
}
203
}
204
 
204
 
205
stop:
205
stop: