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