Subversion Repositories Kolibri OS

Rev

Rev 9274 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6771 leency 1
#define MEMSIZE 4096 * 1024 * 2
8923 leency 2
#define NO_DLL_INIT
6772 leency 3
#include "../lib/strings.h"
4
#include "../lib/gui.h"
5
#include "../lib/obj/box_lib.h"
3363 leency 6
 
5818 leency 7
#ifdef LANG_RUS
8923 leency 8
  #define WINDOW_TITLE "Словарик 2.4"
5818 leency 9
  #define DICTIONARY_LOADED "Словарь загружен"
10
  #define WORD_NOT_FOUND "Слово не найдено в словаре"
6638 leency 11
  #define ERROR "Ошибка #%d"
5818 leency 12
#else
8923 leency 13
  #define WINDOW_TITLE "Dictionary v2.4"
5818 leency 14
  #define DICTIONARY_LOADED "Dictionary loaded"
15
  #define WORD_NOT_FOUND "Word isn't found in the dictionary"
6638 leency 16
  #define ERROR "Error #%d"
8923 leency 17
#endif
5818 leency 18
 
8923 leency 19
#define TEXT_ENG_RUS "ENG\26RUS"
20
#define TEXT_RUS_ENG "RUS\26ENG"
21
#define TEXT_RU2EN "ENG     RUS"
22
#define TEXT_EN2RU "RUS     ENG"
23
 
24
unsigned char speaker[23*40*3]= FROM "speaker.raw";
25
 
3363 leency 26
proc_info Form;
8923 leency 27
char search_word[256], translate_result[4096];
6678 leency 28
#define TOPH 45
8923 leency 29
#define PRONOUNCED_FILE "/tmp0/1/pronounced.txt"
30
#define SPEECH_PATH "/kolibrios/media/speech/speech"
31
dword speaker_id;
3363 leency 32
 
6771 leency 33
unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
34
unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
35
dword io_buffer_data;
36
 
5818 leency 37
#define ENG_RUS 0
38
#define RUS_ENG 1
39
int active_dict=2;
40
 
8923 leency 41
#define BTN_CHANGE_LANGUAGE 10
42
#define BTN_SPEAKER 11
3363 leency 43
 
8923 leency 44
char edit_text[256];
45
edit_box edit1 = {0,13,13,0xffffff,0x94AECE,0xffffff,0xffffff,
46
	0x10000000,248,#edit_text,0,ed_focus+ed_always_focus};
3363 leency 47
 
48
void main()
49
{
8923 leency 50
	int btnid;
5626 leency 51
	load_dll(boxlib, #box_lib_init,0);
5818 leency 52
	OpenDictionary(ENG_RUS);
8923 leency 53
	if (param) {
6771 leency 54
		strcpy(#edit_text, #param);
8923 leency 55
		edit_box_set_text stdcall (#edit1, #param);
3363 leency 56
		Translate();
57
	}
8923 leency 58
	@SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
59
	loop() switch(@WaitEvent())
3363 leency 60
	{
61
		case evMouse:
62
			edit_box_mouse stdcall (#edit1);
63
			break;
64
 
65
		case evButton:
8923 leency 66
			btnid = @GetButtonID();
67
			if (btnid==01) ExitProcess();
68
			if (btnid==BTN_CHANGE_LANGUAGE) {
69
				if (active_dict == ENG_RUS) {
70
					OpenDictionary(RUS_ENG);
71
				} else {
72
					OpenDictionary(ENG_RUS);
73
				}
6638 leency 74
				DrawLangButtons();
3363 leency 75
			}
8923 leency 76
			if (btnid==BTN_SPEAKER) {
77
				if (GetProcessSlot(speaker_id)!=0) {
78
					KillProcess(speaker_id);
79
					pause(50);
80
				} else {
81
					if (CreateFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
82
					pause(50);
83
					speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
84
				}
85
				SpeakerDraw();
86
			}
3363 leency 87
			break;
88
 
8923 leency 89
		case evKey:
90
			@GetKey();
5818 leency 91
			edit_box_key stdcall(#edit1);
92
			Translate();
3363 leency 93
			break;
94
 
8923 leency 95
		case evReDraw:
7806 leency 96
			sc.get();
97
			DefineAndDrawWindow(215,120,500,350,0x73,sc.work,WINDOW_TITLE,0);
5818 leency 98
			GetProcessInfo(#Form, SelfInfo);
8946 leency 99
			if (Form.status_window&ROLLED_UP) break;
5818 leency 100
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
101
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
7806 leency 102
			DrawBar(0, 0, Form.cwidth, TOPH, sc.work); //top bg
9602 leency 103
			DrawBar(0, TOPH, Form.cwidth, 1, sc.line);
8923 leency 104
			edit1.width = Form.cwidth-edit1.left-edit1.left - 116;
5818 leency 105
			edit_box_draw stdcall(#edit1);
6678 leency 106
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
9602 leency 107
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, sc.line);
5818 leency 108
			DrawTranslation();
109
			DrawLangButtons();
8923 leency 110
	}
3363 leency 111
}
112
 
113
 
5818 leency 114
void DrawLangButtons()
3363 leency 115
{
6638 leency 116
	dword direction;
8923 leency 117
	int y = edit1.top+3;
118
	DrawBar(Form.cwidth-111, y, 100, 25, sc.work);
119
	DefineButton(Form.cwidth-79, y-4, 20, 20, BTN_CHANGE_LANGUAGE, sc.button);
9274 leency 120
	WriteText(Form.cwidth-73, y-1, 10000001b, sc.button_text, "\26");
8923 leency 121
	if (active_dict == ENG_RUS) {
122
		direction = TEXT_RU2EN;
123
	} else {
124
		direction = TEXT_EN2RU;
125
	}
126
	WriteText(Form.cwidth-111, y, 0x90, sc.work_text, direction);
3363 leency 127
}
128
 
129
void Translate()
130
{
8923 leency 131
	dword tr_start, tr_end;
5818 leency 132
 
6771 leency 133
	sprintf(#search_word, "\10%s\13", #edit_text);
3363 leency 134
	strupr(#search_word);
5818 leency 135
 
6771 leency 136
	if (!edit_text) goto _TR_END;
5818 leency 137
 
8923 leency 138
	tr_start = strstr(io_buffer_data, #search_word);
139
	if (!tr_start) {
5818 leency 140
		strcpy(#translate_result, WORD_NOT_FOUND);
8923 leency 141
	} else {
142
		tr_start = strchr(tr_start, '"') + 1;
143
		tr_end = strchr(tr_start, '"');
144
		strlcpy(#translate_result, tr_start, tr_end - tr_start);
3363 leency 145
	}
5818 leency 146
	_TR_END:
147
	strcpy(#search_word, #search_word+1);
148
	DrawTranslation();
3363 leency 149
}
150
 
151
 
5818 leency 152
void OpenDictionary(dword dict_id)
3363 leency 153
{
5818 leency 154
	if (dict_id==active_dict) return;
155
	active_dict = dict_id;
6771 leency 156
	if (active_dict==ENG_RUS)
3363 leency 157
	{
6771 leency 158
		io_buffer_data=#eng_rus;
159
		strcpy(#search_word, TEXT_ENG_RUS);
5423 leency 160
	}
6771 leency 161
	if (active_dict==RUS_ENG)
5423 leency 162
	{
6771 leency 163
		io_buffer_data=#rus_eng;
164
		strcpy(#search_word, TEXT_RUS_ENG);
5423 leency 165
	}
6771 leency 166
	strcpy(#translate_result, DICTIONARY_LOADED);
5818 leency 167
	DrawTranslation();
3363 leency 168
}
169
 
170
 
171
void DrawTranslation()
172
{
5818 leency 173
	int y_pos=TOPH+1;
3363 leency 174
	char draw_buf[4096];
7750 leency 175
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf)-1);
3363 leency 176
 
7783 leency 177
	DrawBar(0, y_pos, Form.cwidth, Form.cheight - y_pos, 0xFFFFFF);
3363 leency 178
	strttl(#draw_buf);
5818 leency 179
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
6638 leency 180
 
6678 leency 181
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30,
6638 leency 182
		#draw_buf, -1, 0x000000);
8923 leency 183
 
184
	SpeakerDraw();
3363 leency 185
}
186
 
8923 leency 187
void SpeakerDraw()
188
{
189
	dword x = Form.cwidth-38;
190
	dword y = Form.cheight-32;
191
	if (active_dict == RUS_ENG)
192
	{
193
		DeleteButton(15);
194
		DrawBar(x,y,23,20,0xFFFFFF);
195
	} else {
196
		DefineHiddenButton(x-5, y-5, 23+10, 20+9, BTN_SPEAKER);
197
		if (!GetProcessSlot(speaker_id)) {
9602 leency 198
			PutImage(x, y, 23,20, #speaker);
8923 leency 199
		} else {
9602 leency 200
			PutImage(x, y, 23,20, 23*20*3+#speaker);
8923 leency 201
		}
202
	}
203
}
3363 leency 204
 
205
stop: