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