Subversion Repositories Kolibri OS

Rev

Rev 5674 | Rev 6638 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5674 Rev 5818
Line -... Line 1...
-
 
1
#ifndef AUTOBUILD
-
 
2
	#include "lang.h--"
-
 
3
#endif
-
 
4
 
1
#define MEMSIZE 0x8000
5
#define MEMSIZE 0x8000
2
#include "..\lib\kolibri.h" 
-
 
3
#include "..\lib\strings.h"
6
#include "..\lib\strings.h"
4
#include "..\lib\mem.h"
7
#include "..\lib\io.h"
5
#include "..\lib\file_system.h"
-
 
6
#include "..\lib\gui.h"
8
#include "..\lib\gui.h"
7
#include "..\lib\dll.h"
-
 
8
#include "..\lib\obj\box_lib.h"
9
#include "..\lib\obj\box_lib.h"
Line 9... Line -...
9
 
-
 
10
 
10
 
11
unsigned char speaker[23*40*3]= FROM "speaker.raw";
-
 
12
char title[]= "Dictionary v1.32";
-
 
13
char direction[] = "Translate direction:";
-
 
14
char translate_caption[] = "Translate";
-
 
15
char dict_not_found[] = "Dictionary not found";
-
 
16
char dict_opened[] = "Dictionary loaded";
-
 
Line 17... Line 11...
17
char empty_word[] = "Type a word to translate";
11
unsigned char speaker[23*40*3]= FROM "speaker.raw";
-
 
12
 
-
 
13
#ifdef LANG_RUS
-
 
14
  #define WINDOW_TITLE "‘«®¢ à¨ª 2.0"
-
 
15
  #define DICTIONARY_NOT_FOUND "‘«®¢ àì ­¥ ­ ©¤¥­"
-
 
16
  #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
-
 
17
  #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
-
 
18
  #define ERROR "Žè¨¡ª  #"
-
 
19
#else
-
 
20
  #define WINDOW_TITLE "Dictionary v2.0"
-
 
21
  #define DICTIONARY_NOT_FOUND "Dictionary not found"
-
 
22
  #define DICTIONARY_LOADED "Dictionary loaded"
-
 
23
  #define WORD_NOT_FOUND "Word isn't found in the dictionary"
Line 18... Line -...
18
 
-
 
19
proc_info Form;
24
  #define ERROR "Error #"
20
 
25
  #endif
21
char edword[256], search_word[256], translate_result[4096], cur_dict[256];
26
 
22
dword dict_folder;
27
proc_info Form;
-
 
28
char edword[256], search_word[256], translate_result[4096];
-
 
29
#define PRONOUNCED_FILE "/sys/pronounced.txt"
-
 
30
#define SPEECH_PATH "/kolibrios/media/speech/speech"
23
#define DICT_DIRECROTY "dictionaries"
31
#define TOPH 44
-
 
32
 
-
 
33
#define TEXT_ENG_RUS "ENG\26RUS"
-
 
34
#define TEXT_RUS_ENG "RUS\26ENG"
Line 24... Line 35...
24
#define PRONOUNCED_FILE "/sys/pronounced.txt"
35
#define ENG_RUS 0
25
#define SPEECH_PATH "/kolibrios/media/speech/speech"
36
#define RUS_ENG 1
Line 26... Line 37...
26
dword dir_buf, file_buf, fsize;
37
int active_dict=2;
27
 
38
 
28
int mouse_dd, speaker_id;
39
int mouse_dd, speaker_id;
29
edit_box edit1= {200,20,16,0xffffff,0x94AECE,0x94AECE,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b};
-
 
30
 
40
edit_box edit1= {200,16,16,0xffffff,0x94AECE,0xffffff,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b};
31
 
-
 
32
void main()
-
 
33
{   
41
 
34
	int id, key;
-
 
35
	
42
 
36
	load_dll(boxlib, #box_lib_init,0);
43
void main()
37
 
44
{   
38
	dict_folder = abspath(DICT_DIRECROTY);
45
	int id;
39
	OpenDictionary(0);
46
	load_dll(boxlib, #box_lib_init,0);
40
	
-
 
41
	if (param)
-
 
42
	{
47
	OpenDictionary(ENG_RUS);
43
		strcpy(#edword, #param);
-
 
44
		edit1.size=edit1.pos=strlen(#edword);
48
	if (param)
45
		Translate();
49
	{
46
		DrawTranslation();
50
		strcpy(#edword, #param);
47
		edit_box_draw stdcall(#edit1);
51
		edit1.size=edit1.pos=strlen(#edword);
48
	}
52
		Translate();
Line 56... Line 60...
56
			edit_box_mouse stdcall (#edit1);
60
			edit_box_mouse stdcall (#edit1);
57
			break;
61
			break;
Line 58... Line 62...
58
 
62
 
59
		case evButton:
63
		case evButton:
60
            id=GetButtonID();               
64
            id=GetButtonID();               
61
            if (id==1) {KillProcess(speaker_id); ExitProcess();}
65
            if (id==01) { KillProcess(speaker_id); ExitProcess(); }
62
			if (id==10) { Translate(); DrawTranslation(); }
-
 
63
			if (id==11)	ShowDictList();
66
			if (id==10) { OpenDictionary(ENG_RUS); DrawLangButtons(); }
64
			if (id==12)	DrawWindowContent();
67
			if (id==11) { OpenDictionary(RUS_ENG); DrawLangButtons(); }
65
			if (id==15)
68
			if (id==15)
66
			{
69
			{
67
				if (GetProcessSlot(speaker_id)!=0))
70
				if (GetProcessSlot(speaker_id)!=0))
68
				{
71
				{
Line 73... Line 76...
73
				{
76
				{
74
					if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
77
					if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
75
					pause(50);
78
					pause(50);
76
					speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
79
					speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
77
				}
80
				}
78
				SpeakerDraw(Form.cwidth-38, Form.cheight-32);
81
				SpeakerDraw();
79
			}
82
			}
80
			if (id>=20)	OpenDictionary(id - 20);
-
 
81
			break;
83
			break;
Line 82... Line 84...
82
 
84
 
83
        case evKey:
85
        case evKey:
84
			key = GetKey();
-
 
85
			IF (key==013) //Enter
-
 
86
			{
-
 
87
				Translate();
-
 
88
				DrawTranslation();
-
 
89
			}
-
 
90
			
86
			GetKeys();			
91
			EAX=key<<8;
87
			EAX=key_ascii<<8;
92
			edit_box_key stdcall(#edit1);
-
 
93
			
88
			edit_box_key stdcall(#edit1);	
94
			// Translate();
-
 
95
			// DrawTranslation();
89
			Translate();
Line 96... Line 90...
96
			break;
90
			break;
-
 
91
			
-
 
92
         case evReDraw:
-
 
93
			system.color.get();
-
 
94
			DefineAndDrawWindow(215,120,400,250,0x73,system.color.work,WINDOW_TITLE);
-
 
95
			GetProcessInfo(#Form, SelfInfo);
-
 
96
			if (Form.status_window>2) break;
-
 
97
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
-
 
98
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
-
 
99
			DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg
-
 
100
			DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
-
 
101
			edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
-
 
102
			edit_box_draw stdcall(#edit1);
97
			
103
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 19, 2, 0xffffff);
98
         case evReDraw:
104
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 20, system.color.work_graph);
99
			DrawWindowContent();
105
			DrawTranslation();
100
			break;
106
			DrawLangButtons();
101
      }
107
      }
Line 102... Line 108...
102
   }
108
   }
103
}
109
}
104
 
-
 
105
 
-
 
106
void DrawWindowContent()
-
 
107
{
-
 
108
	system.color.get();
-
 
109
	DefineAndDrawWindow(215,120,400,250,0x73,system.color.work,#title);
-
 
110
	GetProcessInfo(#Form, SelfInfo);
-
 
111
	if (Form.status_window>2) return;
-
 
112
	if (Form.height<140) MoveSize(OLD,OLD,OLD,140);
-
 
113
	if (Form.width<400) MoveSize(OLD,OLD,400,OLD);
-
 
114
	edit1.focus_border_color=system.color.work_graph;
-
 
115
	edit1.width=Form.width-edit1.left-edit1.left-9;
110
 
116
 
-
 
117
	DrawBar(0, 0, Form.width-9, 69, system.color.work);
-
 
118
	edit_box_draw stdcall(#edit1);
-
 
119
	DrawCaptButton(edit1.left+edit1.width-80,35, 80,20, 10, system.color.work_button, system.color.work_button_text,#translate_caption);
-
 
120
	DrawBar(0, 69, Form.width-9, 1, system.color.work_graph);
-
 
121
 
111
 
122
	WriteText(edit1.left,35+7,0x80,system.color.work_text,#direction);
112
void DrawLangButtons()
123
	DefineButton(edit1.left+130,35, 120,20, 11, system.color.work_button);
-
 
124
	DrawBar(edit1.left+130+1,36,  107,19, 0xFFFFFF);
113
{
125
	WriteText(edit1.left+130+112,35+7,0x80,system.color.work_button_text,"\x19");
114
	DrawCaptButton(Form.width-130, edit1.top-3, 50,19, 10, system.color.work_button, system.color.work_button_text, TEXT_ENG_RUS);
Line 126... Line 115...
126
	WriteText(edit1.left+130+8,35+7,0x80,0x000000,#cur_dict);
115
	DrawCaptButton(Form.width-70, edit1.top-3, 50,19, 11, system.color.work_button, system.color.work_button_text, TEXT_RUS_ENG);
-
 
116
	PutShadow(-active_dict*60 + Form.width-70, edit1.top-3, 50,19, 1, 2);
-
 
117
	SpeakerDraw();
-
 
118
}
-
 
119
 
-
 
120
void SpeakerDraw()
-
 
121
{
-
 
122
	dword x, y;
-
 
123
	x = Form.cwidth-38;
-
 
124
	y = Form.cheight-32;
-
 
125
	if (active_dict)
127
 
126
	{
128
	DrawTranslation();
-
 
129
}
127
		DeleteButton(15);
130
 
128
		DrawBar(x,y,23,20,0xFFFFFF);
131
void SpeakerDraw(dword x, y)
129
	}
-
 
130
	else
Line 132... Line 131...
132
{
131
	{
133
	if (!strstr(#cur_dict, "- rus")) return;
132
		DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0);
134
	DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0);
-
 
135
	if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker);
133
		if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker);		
Line 136... Line -...
136
}
-
 
137
 
-
 
138
void Translate()
-
 
139
{
-
 
140
	dword tj;
-
 
141
	char w_native[100], w_translation[100], bukva[1];
-
 
142
	
134
	}
143
	byte InfType;
-
 
144
	#define NATIVE_WORD 0
-
 
145
	#define TRANSLATION 1
135
}
146
	#define IGNORE      2
136
 
Line 147... Line -...
147
	
-
 
148
	if (!fsize) return;
-
 
149
	KillProcess(speaker_id);
137
void Translate()
150
		
-
 
151
	translate_result = 0;
-
 
Line -... Line 138...
-
 
138
{
152
	strcpy(#search_word, #edword);
139
	dword translation_start, translation_end;
153
	strupr(#search_word);
140
 
154
	
-
 
155
	if (!edword)
-
 
156
	{
-
 
157
		strcpy(#translate_result, #empty_word);
-
 
158
		return;
-
 
159
	}
-
 
160
 
-
 
161
	for (tj=0; tj
-
 
162
	{   
-
 
163
		bukva = ESBYTE[file_buf+tj];
-
 
164
		switch (bukva)
141
	KillProcess(speaker_id);
165
		{
142
	sprintf(#search_word, "\10%s\13", #edword);
166
			case '"':
143
	strupr(#search_word);
167
				if (w_translation)
-
 
168
				{
-
 
169
					if (!strcmp(#w_native, #search_word))
-
 
170
					{
-
 
171
					
-
 
172
						if (translate_result) strcat(#translate_result, ", ");
-
 
173
						strcat(#translate_result, #w_translation);
-
 
174
					}
-
 
175
					else
-
 
176
						if (translate_result) return;
-
 
177
										
-
 
178
					w_translation = w_native = 0;
144
 
179
				}
145
	if (!io.FILES_SIZE) || (!edword) goto _TR_END;
180
				InfType = TRANSLATION;
146
 
181
				break;				
-
 
182
			case 0x0a:
147
	translation_start = strstr(io.buffer_data, #search_word);
183
				InfType = NATIVE_WORD;
148
	if (!translation_start) 
184
				break;
149
	{
185
			default:
150
		strcpy(#translate_result, WORD_NOT_FOUND); 
-
 
151
	}
186
				if (InfType==NATIVE_WORD)
152
	else 
Line 187... Line 153...
187
				{
153
	{
188
					chrcat(#w_native, bukva);
154
		translation_start = strchr(translation_start, '"') + 1;
-
 
155
		translation_end = strchr(translation_start, '"');
189
					//if (w_native<>search_word) InfType = IGNORE; //åñëè ïåðâàÿ áóêâà íå ñîâïàäàåò èãíîðèì âñ¸ ñëîâî
156
		strlcpy(#translate_result, translation_start, translation_end - translation_start);
190
				}
157
	}
191
				if (InfType==TRANSLATION) chrcat(#w_translation, bukva);
158
	_TR_END:
192
		}
159
	strcpy(#search_word, #search_word+1);
193
	}
160
	DrawTranslation();
194
	if (!translate_result) strcpy(#translate_result, "Word is'nt found in the dictionary"); 
161
}
195
}
-
 
196
 
162
 
197
 
-
 
198
void OpenDictionary(dword fileid)
-
 
199
{
-
 
200
	char open_file_path[4096];
-
 
201
	KillProcess(speaker_id);
-
 
202
	if (!dir_buf) ShowDictList();
-
 
203
	if (!dir_buf) strcpy(#cur_dict, "none");
-
 
204
	else strcpy(#cur_dict, fileid*304+dir_buf+72);
-
 
205
	fsize = ESDWORD[fileid*304 + dir_buf+64];
-
 
206
 
-
 
207
	free(file_buf);
-
 
208
	file_buf = malloc(fsize);
-
 
209
	strcpy(#open_file_path, dict_folder);
-
 
210
	strcat(#open_file_path, "/");
163
 
211
	strcat(#open_file_path, #cur_dict);
164
void OpenDictionary(dword dict_id)
212
	ReadFile(0, fsize, file_buf, #open_file_path);
165
{
213
	IF (EAX<>0)
166
	dword res;
214
	{
-
 
215
		fsize = 0;
-
 
216
		strcpy(#search_word, "Error #");
-
 
217
		strcat(#search_word, itoa(EAX));
-
 
218
		strcpy(#translate_result, #dict_not_found);
-
 
219
	}
-
 
220
	else
-
 
221
	{
-
 
222
		strcpy(#search_word, #cur_dict);
-
 
223
		strcpy(#translate_result, #dict_opened);
-
 
224
	}
-
 
225
	DrawWindowContent();	
167
	if (dict_id==active_dict) return;
226
}
-
 
227
 
-
 
228
 
168
	KillProcess(speaker_id);
229
void ShowDictList()
169
	active_dict = dict_id;
230
{
170
	if (io.buffer_data) free(io.buffer_data);
231
	int j, fcount, error;
-
 
-
 
171
	if (active_dict==ENG_RUS) res=io.read("dictionaries/eng - rus.dict");
232
	
172
	if (active_dict==RUS_ENG) res=io.read("dictionaries/rus - eng.dict");	
-
 
173
	if (!io.buffer_data)
233
	free(dir_buf);
174
	{
Line 234... Line 175...
234
	error = GetDir(#dir_buf, #fcount, dict_folder, DIRS_ONLYREAL);
175
		sprintf(#search_word, ERROR, res);
235
	if (!error)
176
		strcpy(#translate_result, DICTIONARY_NOT_FOUND);
236
	{
177
	}
237
		DefineButton(0,0, Form.width,Form.height, 12+BT_HIDE+BT_NOFRAME, system.color.work_button);
178
	else
Line 238... Line 179...
238
		for (j=0; j
179
	{
239
		{
180
		if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS);
240
			DefineButton(edit1.left+130,j+1*20+35, 107,20, 20+j, system.color.work_button);
181
		if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG);
Line 241... Line 182...
241
			WriteText(edit1.left+130+8,j+1*20+35+7,0x80,system.color.work_button_text, j*304+dir_buf+72);
182
		strcpy(#translate_result, DICTIONARY_LOADED);
242
		}
183
	}
243
	}
184
	DrawTranslation();	
244
}
185
}
245
 
186
 
246
 
187
 
247
void DrawTranslation()
188
void DrawTranslation()
248
{
189
{
249
	int text_break=0;
190
	int text_break=0;
250
	char tt[4096]='';
191
	char tt[4096]='';
251
	
192
	
252
	int y_pos=70;
193
	int y_pos=TOPH+1;
253
	char draw_buf[4096];
194
	char draw_buf[4096];
254
	strcpy(#draw_buf, #translate_result);
195
	strcpy(#draw_buf, #translate_result);
255
	
196
	
256
	DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
197
	DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
257
	strttl(#draw_buf);
198
	strttl(#draw_buf);
258
	WriteTextB(10+1, y_pos+8, 0x90, 0x800080, #search_word);
199
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
259
	while (draw_buf)
200
	while (draw_buf)
260
	{
201
	{
261
		text_break= Form.width/6-6;
202
		text_break= Form.width/6-6;
Line 262... Line 203...
262
		if (text_break>strlen(#draw_buf))
203
		if (text_break>strlen(#draw_buf))