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