Rev 3444 | Rev 3991 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3444 | Rev 3860 | ||
---|---|---|---|
1 | #define MEMSIZE 0x8000 |
1 | #define MEMSIZE 0x8000 |
2 | #include "..\lib\kolibri.h" |
2 | #include "..\lib\kolibri.h" |
3 | #include "..\lib\strings.h" |
3 | #include "..\lib\strings.h" |
4 | #include "..\lib\mem.h" |
4 | #include "..\lib\mem.h" |
5 | #include "..\lib\file_system.h" |
5 | #include "..\lib\file_system.h" |
6 | #include "..\lib\figures.h" |
6 | #include "..\lib\figures.h" |
7 | #include "..\lib\dll.h" |
7 | #include "..\lib\dll.h" |
8 | #include "..\lib\edit_box_lib.h" |
8 | #include "..\lib\lib.obj\box_lib.h" |
9 | 9 | ||
10 | 10 | ||
11 | unsigned char speaker[23*40*3]= FROM "speaker.raw"; |
11 | unsigned char speaker[23*40*3]= FROM "speaker.raw"; |
12 | char title[]= "Dictionary v1.31"; |
12 | char title[]= "Dictionary v1.31"; |
13 | char direction[] = "Translate direction:"; |
13 | char direction[] = "Translate direction:"; |
14 | char translate_caption[] = "Translate"; |
14 | char translate_caption[] = "Translate"; |
15 | char dict_not_found[] = "Dictionary not found"; |
15 | char dict_not_found[] = "Dictionary not found"; |
16 | char dict_opened[] = "Dictionary loaded"; |
16 | char dict_opened[] = "Dictionary loaded"; |
17 | char empty_word[] = "Type a word to translate"; |
17 | char empty_word[] = "Type a word to translate"; |
18 | 18 | ||
19 | 19 | ||
20 | system_colors sc; |
20 | system_colors sc; |
21 | proc_info Form; |
21 | proc_info Form; |
22 | 22 | ||
23 | char edword[256], search_word[256], translate_result[4096], dict_folder[4096], cur_dict[256]; |
23 | char edword[256], search_word[256], translate_result[4096], dict_folder[4096], cur_dict[256]; |
24 | #define DICT_DIRECROTY "dictionaries" |
24 | #define DICT_DIRECROTY "dictionaries" |
25 | #define PRONOUNCED_FILE "/tmp9/1/dicty/pronounced.txt" |
25 | #define PRONOUNCED_FILE "/tmp9/1/dicty/pronounced.txt" |
26 | #define SPEECH_PATH "/tmp9/1/media/speech/speech" |
26 | #define SPEECH_PATH "/tmp9/1/media/speech/speech" |
27 | dword dir_buf, file_buf, fsize; |
27 | dword dir_buf, file_buf, fsize; |
28 | 28 | ||
29 | int mouse_dd, speaker_id; |
29 | int mouse_dd, speaker_id; |
30 | edit_box edit1= {200,20,16,0xffffff,0x94AECE,0x94AECE,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b}; |
30 | edit_box edit1= {200,20,16,0xffffff,0x94AECE,0x94AECE,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b}; |
31 | 31 | ||
32 | 32 | ||
33 | void main() |
33 | void main() |
34 | { |
34 | { |
35 | int id, key; |
35 | int id, key; |
36 | mem_Init(); |
36 | mem_Init(); |
37 | load_dll2(boxlib, #edit_box_draw,0); |
37 | if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Error while loading GUI library /sys/lib/boxlib.obj"); |
38 | 38 | ||
39 | program_path[strrchr(#program_path, '/')] = 0; |
39 | program_path[strrchr(#program_path, '/')] = 0; |
40 | strcpy(#dict_folder, #program_path); |
40 | strcpy(#dict_folder, #program_path); |
41 | strcat(#dict_folder, DICT_DIRECROTY); |
41 | strcat(#dict_folder, DICT_DIRECROTY); |
42 | SetCurDir(#dict_folder); |
42 | SetCurDir(#dict_folder); |
43 | OpenDictionary(0); |
43 | OpenDictionary(0); |
44 | 44 | ||
45 | if (param) |
45 | if (param) |
46 | { |
46 | { |
47 | strcpy(#edword, #param); |
47 | strcpy(#edword, #param); |
48 | edit1.size=edit1.pos=strlen(#edword); |
48 | edit1.size=edit1.pos=strlen(#edword); |
49 | Translate(); |
49 | Translate(); |
50 | DrawTranslation(); |
50 | DrawTranslation(); |
51 | edit_box_draw stdcall(#edit1); |
51 | edit_box_draw stdcall(#edit1); |
52 | } |
52 | } |
53 | 53 | ||
54 | SetEventMask(0x27); |
54 | SetEventMask(0x27); |
55 | loop() |
55 | loop() |
56 | { |
56 | { |
57 | switch(WaitEvent()) |
57 | switch(WaitEvent()) |
58 | { |
58 | { |
59 | case evMouse: |
59 | case evMouse: |
60 | edit_box_mouse stdcall (#edit1); |
60 | edit_box_mouse stdcall (#edit1); |
61 | break; |
61 | break; |
62 | 62 | ||
63 | case evButton: |
63 | case evButton: |
64 | id=GetButtonID(); |
64 | id=GetButtonID(); |
65 | if (id==1) {KillProcess(speaker_id); ExitProcess();} |
65 | if (id==1) {KillProcess(speaker_id); ExitProcess();} |
66 | if (id==10) { Translate(); DrawTranslation(); } |
66 | if (id==10) { Translate(); DrawTranslation(); } |
67 | if (id==11) ShowDictList(); |
67 | if (id==11) ShowDictList(); |
68 | if (id==12) DrawWindowContent(); |
68 | if (id==12) DrawWindowContent(); |
69 | if (id==15) |
69 | if (id==15) |
70 | { |
70 | { |
71 | if (GetProcessSlot(speaker_id)!=0)) |
71 | if (GetProcessSlot(speaker_id)!=0)) |
72 | { |
72 | { |
73 | KillProcess(speaker_id); |
73 | KillProcess(speaker_id); |
74 | pause(50); |
74 | pause(50); |
75 | } |
75 | } |
76 | else |
76 | else |
77 | { |
77 | { |
78 | if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break; |
78 | if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break; |
79 | pause(50); |
79 | pause(50); |
80 | speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE); |
80 | speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE); |
81 | } |
81 | } |
82 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
82 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
83 | } |
83 | } |
84 | if (id>=20) OpenDictionary(id - 20); |
84 | if (id>=20) OpenDictionary(id - 20); |
85 | break; |
85 | break; |
86 | 86 | ||
87 | case evKey: |
87 | case evKey: |
88 | key = GetKey(); |
88 | key = GetKey(); |
89 | IF (key==013) //Enter |
89 | IF (key==013) //Enter |
90 | { |
90 | { |
91 | Translate(); |
91 | Translate(); |
92 | DrawTranslation(); |
92 | DrawTranslation(); |
93 | } |
93 | } |
94 | 94 | ||
95 | EAX=key<<8; |
95 | EAX=key<<8; |
96 | edit_box_key stdcall(#edit1); |
96 | edit_box_key stdcall(#edit1); |
97 | 97 | ||
98 | //LiveSearch(); |
98 | //LiveSearch(); |
99 | break; |
99 | break; |
100 | 100 | ||
101 | case evReDraw: |
101 | case evReDraw: |
102 | DrawWindowContent(); |
102 | DrawWindowContent(); |
103 | break; |
103 | break; |
104 | } |
104 | } |
105 | } |
105 | } |
106 | } |
106 | } |
107 | 107 | ||
108 | 108 | ||
109 | void DrawWindowContent() |
109 | void DrawWindowContent() |
110 | { |
110 | { |
111 | sc.get(); |
111 | sc.get(); |
112 | DefineAndDrawWindow(215,120,400,250,0x73,sc.work,#title); |
112 | DefineAndDrawWindow(215,120,400,250,0x73,sc.work,#title); |
113 | GetProcessInfo(#Form, SelfInfo); |
113 | GetProcessInfo(#Form, SelfInfo); |
114 | if (Form.status_window>2) return; |
114 | if (Form.status_window>2) return; |
115 | if (Form.height<140) MoveSize(OLD,OLD,OLD,140); |
115 | if (Form.height<140) MoveSize(OLD,OLD,OLD,140); |
116 | if (Form.width<400) MoveSize(OLD,OLD,400,OLD); |
116 | if (Form.width<400) MoveSize(OLD,OLD,400,OLD); |
117 | edit1.focus_border_color=sc.work_graph; |
117 | edit1.focus_border_color=sc.work_graph; |
118 | edit1.width=Form.width-edit1.left-edit1.left-9; |
118 | edit1.width=Form.width-edit1.left-edit1.left-9; |
119 | 119 | ||
120 | DrawBar(0, 0, Form.width-9, 69, sc.work); |
120 | DrawBar(0, 0, Form.width-9, 69, sc.work); |
121 | edit_box_draw stdcall(#edit1); |
121 | edit_box_draw stdcall(#edit1); |
122 | DrawCaptButton(edit1.left+edit1.width-80,35, 80,20, 10, sc.work_button, sc.work_button_text,#translate_caption); |
122 | DrawCaptButton(edit1.left+edit1.width-80,35, 80,20, 10, sc.work_button, sc.work_button_text,#translate_caption); |
123 | DrawBar(0, 69, Form.width-9, 1, sc.work_graph); |
123 | DrawBar(0, 69, Form.width-9, 1, sc.work_graph); |
124 | 124 | ||
125 | WriteText(edit1.left,35+7,0x80,sc.work_text,#direction); |
125 | WriteText(edit1.left,35+7,0x80,sc.work_text,#direction); |
126 | DefineButton(edit1.left+130,35, 120,20, 11, sc.work_button); |
126 | DefineButton(edit1.left+130,35, 120,20, 11, sc.work_button); |
127 | DrawBar(edit1.left+130+1,36, 107,19, 0xFFFFFF); |
127 | DrawBar(edit1.left+130+1,36, 107,19, 0xFFFFFF); |
128 | WriteText(edit1.left+130+112,35+7,0x80,sc.work_button_text,"\x19"); |
128 | WriteText(edit1.left+130+112,35+7,0x80,sc.work_button_text,"\x19"); |
129 | WriteText(edit1.left+130+8,35+7,0x80,0x000000,#cur_dict); |
129 | WriteText(edit1.left+130+8,35+7,0x80,0x000000,#cur_dict); |
130 | 130 | ||
131 | DrawTranslation(); |
131 | DrawTranslation(); |
132 | } |
132 | } |
133 | 133 | ||
134 | void SpeakerDraw(dword x, y) |
134 | void SpeakerDraw(dword x, y) |
135 | { |
135 | { |
136 | if (!strstr(#cur_dict, "- rus")) return; |
136 | if (!strstr(#cur_dict, "- rus")) return; |
137 | DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0); |
137 | DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0); |
138 | if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker); |
138 | if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker); |
139 | } |
139 | } |
140 | 140 | ||
141 | void Translate() |
141 | void Translate() |
142 | { |
142 | { |
143 | dword tj; |
143 | dword tj; |
144 | char w_native[100], w_translation[100], bukva[1]; |
144 | char w_native[100], w_translation[100], bukva[1]; |
145 | 145 | ||
146 | byte InfType; |
146 | byte InfType; |
147 | #define NATIVE_WORD 0 |
147 | #define NATIVE_WORD 0 |
148 | #define TRANSLATION 1 |
148 | #define TRANSLATION 1 |
149 | #define IGNORE 2 |
149 | #define IGNORE 2 |
150 | 150 | ||
151 | if (!fsize) return; |
151 | if (!fsize) return; |
152 | KillProcess(speaker_id); |
152 | KillProcess(speaker_id); |
153 | 153 | ||
154 | translate_result = 0; |
154 | translate_result = 0; |
155 | strcpy(#search_word, #edword); |
155 | strcpy(#search_word, #edword); |
156 | strupr(#search_word); |
156 | strupr(#search_word); |
157 | 157 | ||
158 | if (!edword) |
158 | if (!edword) |
159 | { |
159 | { |
160 | strcpy(#translate_result, #empty_word); |
160 | strcpy(#translate_result, #empty_word); |
161 | return; |
161 | return; |
162 | } |
162 | } |
163 | 163 | ||
164 | for (tj=0; tj |
164 | for (tj=0; tj |
165 | { |
165 | { |
166 | bukva = ESBYTE[file_buf+tj]; |
166 | bukva = ESBYTE[file_buf+tj]; |
167 | switch (bukva) |
167 | switch (bukva) |
168 | { |
168 | { |
169 | case '"': |
169 | case '"': |
170 | if (w_translation) |
170 | if (w_translation) |
171 | { |
171 | { |
172 | if (!strcmp(#w_native, #search_word)) |
172 | if (!strcmp(#w_native, #search_word)) |
173 | { |
173 | { |
174 | 174 | ||
175 | if (translate_result) strcat(#translate_result, ", "); |
175 | if (translate_result) strcat(#translate_result, ", "); |
176 | strcat(#translate_result, #w_translation); |
176 | strcat(#translate_result, #w_translation); |
177 | } |
177 | } |
178 | else |
178 | else |
179 | if (translate_result) return; |
179 | if (translate_result) return; |
180 | 180 | ||
181 | w_translation = w_native = 0; |
181 | w_translation = w_native = 0; |
182 | } |
182 | } |
183 | InfType = TRANSLATION; |
183 | InfType = TRANSLATION; |
184 | break; |
184 | break; |
185 | case 0x0a: |
185 | case 0x0a: |
186 | InfType = NATIVE_WORD; |
186 | InfType = NATIVE_WORD; |
187 | break; |
187 | break; |
188 | default: |
188 | default: |
189 | if (InfType==NATIVE_WORD) |
189 | if (InfType==NATIVE_WORD) |
190 | { |
190 | { |
191 | chrcat(#w_native, bukva); |
191 | chrcat(#w_native, bukva); |
192 | //if (w_native<>search_word) InfType = IGNORE; //åñëè ïåðâàÿ áóêâà íå ñîâïàäàåò èãíîðèì âñ¸ ñëîâî |
192 | //if (w_native<>search_word) InfType = IGNORE; //åñëè ïåðâàÿ áóêâà íå ñîâïàäàåò èãíîðèì âñ¸ ñëîâî |
193 | } |
193 | } |
194 | if (InfType==TRANSLATION) chrcat(#w_translation, bukva); |
194 | if (InfType==TRANSLATION) chrcat(#w_translation, bukva); |
195 | } |
195 | } |
196 | } |
196 | } |
197 | if (!translate_result) strcpy(#translate_result, "Word is'nt found in the dictionary"); |
197 | if (!translate_result) strcpy(#translate_result, "Word is'nt found in the dictionary"); |
198 | } |
198 | } |
199 | 199 | ||
200 | 200 | ||
201 | void OpenDictionary(dword fileid) |
201 | void OpenDictionary(dword fileid) |
202 | { |
202 | { |
203 | KillProcess(speaker_id); |
203 | KillProcess(speaker_id); |
204 | if (!dir_buf) ShowDictList(); |
204 | if (!dir_buf) ShowDictList(); |
205 | if (!dir_buf) strcpy(#cur_dict, "none"); |
205 | if (!dir_buf) strcpy(#cur_dict, "none"); |
206 | else strcpy(#cur_dict, fileid*304+dir_buf+72); |
206 | else strcpy(#cur_dict, fileid*304+dir_buf+72); |
207 | fsize = ESDWORD[fileid*304 + dir_buf+64]; |
207 | fsize = ESDWORD[fileid*304 + dir_buf+64]; |
208 | 208 | ||
209 | free(file_buf); |
209 | free(file_buf); |
210 | file_buf = malloc(fsize); |
210 | file_buf = malloc(fsize); |
211 | ReadFile(0, fsize, file_buf, #cur_dict); |
211 | ReadFile(0, fsize, file_buf, #cur_dict); |
212 | IF (EAX<>0) |
212 | IF (EAX<>0) |
213 | { |
213 | { |
214 | fsize = 0; |
214 | fsize = 0; |
215 | strcpy(#search_word, "Error #"); |
215 | strcpy(#search_word, "Error #"); |
216 | strcat(#search_word, itoa(EAX)); |
216 | strcat(#search_word, itoa(EAX)); |
217 | strcpy(#translate_result, #dict_not_found); |
217 | strcpy(#translate_result, #dict_not_found); |
218 | DrawWindowContent(); |
218 | DrawWindowContent(); |
219 | return; |
219 | return; |
220 | } |
220 | } |
221 | strcpy(#search_word, #cur_dict); |
221 | strcpy(#search_word, #cur_dict); |
222 | strcpy(#translate_result, #dict_opened); |
222 | strcpy(#translate_result, #dict_opened); |
223 | DrawWindowContent(); |
223 | DrawWindowContent(); |
224 | } |
224 | } |
225 | 225 | ||
226 | 226 | ||
227 | void ShowDictList() |
227 | void ShowDictList() |
228 | { |
228 | { |
229 | int j, fcount, error; |
229 | int j, fcount, error; |
230 | 230 | ||
231 | free(dir_buf); |
231 | free(dir_buf); |
232 | error = GetDir(#dir_buf, #fcount, #dict_folder, DIRS_ONLYREAL); |
232 | error = GetDir(#dir_buf, #fcount, #dict_folder, DIRS_ONLYREAL); |
233 | if (!error) |
233 | if (!error) |
234 | { |
234 | { |
235 | DefineButton(0,0, Form.width,Form.height, 12+BT_HIDE+BT_NOFRAME, sc.work_button); |
235 | DefineButton(0,0, Form.width,Form.height, 12+BT_HIDE+BT_NOFRAME, sc.work_button); |
236 | for (j=0; j |
236 | for (j=0; j |
237 | { |
237 | { |
238 | DefineButton(edit1.left+130,j+1*20+35, 107,20, 20+j, sc.work_button); |
238 | DefineButton(edit1.left+130,j+1*20+35, 107,20, 20+j, sc.work_button); |
239 | WriteText(edit1.left+130+8,j+1*20+35+7,0x80,sc.work_button_text, j*304+dir_buf+72); |
239 | WriteText(edit1.left+130+8,j+1*20+35+7,0x80,sc.work_button_text, j*304+dir_buf+72); |
240 | } |
240 | } |
241 | } |
241 | } |
242 | } |
242 | } |
243 | 243 | ||
244 | 244 | ||
245 | void DrawTranslation() |
245 | void DrawTranslation() |
246 | { |
246 | { |
247 | int text_break=0; |
247 | int text_break=0; |
248 | char tt[4096]=''; |
248 | char tt[4096]=''; |
249 | 249 | ||
250 | int y_pos=70; |
250 | int y_pos=70; |
251 | char draw_buf[4096]; |
251 | char draw_buf[4096]; |
252 | strcpy(#draw_buf, #translate_result); |
252 | strcpy(#draw_buf, #translate_result); |
253 | 253 | ||
254 | DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF); |
254 | DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF); |
255 | strttl(#draw_buf); |
255 | strttl(#draw_buf); |
256 | WriteTextB(10+1, y_pos+8, 0x90, 0x800080, #search_word); |
256 | WriteTextB(10+1, y_pos+8, 0x90, 0x800080, #search_word); |
257 | while (draw_buf) |
257 | while (draw_buf) |
258 | { |
258 | { |
259 | text_break= Form.width/6-6; |
259 | text_break= Form.width/6-6; |
260 | if (text_break>strlen(#draw_buf)) |
260 | if (text_break>strlen(#draw_buf)) |
261 | { |
261 | { |
262 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
262 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
263 | break; |
263 | break; |
264 | } |
264 | } |
265 | while (draw_buf[text_break]<>' ') && (text_break>0) text_break--; |
265 | while (draw_buf[text_break]<>' ') && (text_break>0) text_break--; |
266 | strcpy(#tt, #draw_buf+text_break+1); |
266 | strcpy(#tt, #draw_buf+text_break+1); |
267 | draw_buf[text_break]=0x0; |
267 | draw_buf[text_break]=0x0; |
268 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
268 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
269 | strcpy(#draw_buf, #tt); |
269 | strcpy(#draw_buf, #tt); |
270 | y_pos+=12; |
270 | y_pos+=12; |
271 | if (y_pos+24+8>Form.cheight) break; //÷òîá íå çàëåçàëî íà íèæíèé îáîäîê |
271 | if (y_pos+24+8>Form.cheight) break; //÷òîá íå çàëåçàëî íà íèæíèé îáîäîê |
272 | } |
272 | } |
273 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
273 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
274 | } |
274 | } |
275 | 275 | ||
276 | 276 | ||
277 | stop:>>>400)>140)>8; |
277 | stop:>>>400)>140)>8; |
278 | ><8; |
278 | ><8; |
279 | > |
279 | > |