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