Subversion Repositories Kolibri OS

Rev

Rev 6640 | Rev 6746 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6640 Rev 6678
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 45
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,13,13,0xffffff,0x94AECE,0xffffff,0x94AECE,0x10000000,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
			edit_box_key stdcall(#edit1);	
72
			edit_box_key stdcall(#edit1);	
73
			Translate();
73
			Translate();
74
			break;
74
			break;
75
			
75
			
76
         case evReDraw:
76
         case evReDraw:
77
			system.color.get();
77
			system.color.get();
78
			DefineAndDrawWindow(215,120,500,350,0x73,system.color.work,WINDOW_TITLE);
78
			DefineAndDrawWindow(215,120,500,350,0x73,system.color.work,WINDOW_TITLE);
79
			GetProcessInfo(#Form, SelfInfo);
79
			GetProcessInfo(#Form, SelfInfo);
80
			if (Form.status_window>2) break;
80
			if (Form.status_window>2) break;
81
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
81
			if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
82
			if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); 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
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);
84
			DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
85
			edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
85
			edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
86
			edit_box_draw stdcall(#edit1);
86
			edit_box_draw stdcall(#edit1);
87
			DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 19, 2, 0xffffff);
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, 20, system.color.work_graph);
88
			DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, system.color.work_graph);
89
			WriteText(Form.width-120, edit1.top, 0x90, system.color.work_text, TEXT_VOCABULARIES);
89
			WriteText(Form.width-120, edit1.top+3, 0x90, system.color.work_text, TEXT_VOCABULARIES);
90
			DrawTranslation();
90
			DrawTranslation();
91
			DrawLangButtons();
91
			DrawLangButtons();
92
      }
92
      }
93
   }
93
   }
94
}
94
}
95
 
95
 
96
 
96
 
97
void DrawLangButtons()
97
void DrawLangButtons()
98
{
98
{
99
	dword direction;
99
	dword direction;
100
	DefineButton(Form.width-88, edit1.top-4, 20, 20, BUTTON_CHANGE_LANGUAGE, system.color.work_button);
100
	DefineButton(Form.width-88, edit1.top-4+3, 20, 20, BUTTON_CHANGE_LANGUAGE, system.color.work_button);
101
	if (active_dict == ENG_RUS) direction = "\26"; else direction = "\27";
101
	if (active_dict == ENG_RUS) direction = "\26"; else direction = "\27";
102
	WriteText(Form.width-82, edit1.top-1, 10000001b, system.color.work_button_text, direction);
102
	WriteText(Form.width-82, edit1.top-1+3, 10000001b, system.color.work_button_text, direction);
103
}
103
}
104
 
104
 
105
void Translate()
105
void Translate()
106
{
106
{
107
	dword translation_start, translation_end;
107
	dword translation_start, translation_end;
108
 
108
 
109
	sprintf(#search_word, "\10%s\13", #edword);
109
	sprintf(#search_word, "\10%s\13", #edword);
110
	strupr(#search_word);
110
	strupr(#search_word);
111
 
111
 
112
	if (!io.FILES_SIZE) || (!edword) goto _TR_END;
112
	if (!io.FILES_SIZE) || (!edword) goto _TR_END;
113
 
113
 
114
	translation_start = strstr(io.buffer_data, #search_word);
114
	translation_start = strstr(io.buffer_data, #search_word);
115
	if (!translation_start) 
115
	if (!translation_start) 
116
	{
116
	{
117
		strcpy(#translate_result, WORD_NOT_FOUND); 
117
		strcpy(#translate_result, WORD_NOT_FOUND); 
118
	}
118
	}
119
	else 
119
	else 
120
	{
120
	{
121
		translation_start = strchr(translation_start, '"') + 1;
121
		translation_start = strchr(translation_start, '"') + 1;
122
		translation_end = strchr(translation_start, '"');
122
		translation_end = strchr(translation_start, '"');
123
		strlcpy(#translate_result, translation_start, translation_end - translation_start);
123
		strlcpy(#translate_result, translation_start, translation_end - translation_start);
124
	}
124
	}
125
	_TR_END:
125
	_TR_END:
126
	strcpy(#search_word, #search_word+1);
126
	strcpy(#search_word, #search_word+1);
127
	DrawTranslation();
127
	DrawTranslation();
128
}
128
}
129
 
129
 
130
 
130
 
131
void OpenDictionary(dword dict_id)
131
void OpenDictionary(dword dict_id)
132
{
132
{
133
	dword res;
133
	dword res;
134
	if (dict_id==active_dict) return;
134
	if (dict_id==active_dict) return;
135
	active_dict = dict_id;
135
	active_dict = dict_id;
136
	if (io.buffer_data) free(io.buffer_data);
136
	if (io.buffer_data) free(io.buffer_data);
137
	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");
138
	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");	
139
	if (!io.buffer_data)
139
	if (!io.buffer_data)
140
	{
140
	{
141
		sprintf(#search_word, ERROR, res);
141
		sprintf(#search_word, ERROR, res);
142
		strcpy(#translate_result, DICTIONARY_NOT_FOUND);
142
		strcpy(#translate_result, DICTIONARY_NOT_FOUND);
143
	}
143
	}
144
	else
144
	else
145
	{
145
	{
146
		if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS);
146
		if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS);
147
		if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG);
147
		if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG);
148
		strcpy(#translate_result, DICTIONARY_LOADED);
148
		strcpy(#translate_result, DICTIONARY_LOADED);
149
	}
149
	}
150
	DrawTranslation();	
150
	DrawTranslation();	
151
}
151
}
152
 
152
 
153
 
153
 
154
void DrawTranslation()
154
void DrawTranslation()
155
{
155
{
156
	int y_pos=TOPH+1;
156
	int y_pos=TOPH+1;
157
	char draw_buf[4096];
157
	char draw_buf[4096];
158
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf));
158
	strlcpy(#draw_buf, #translate_result, sizeof(draw_buf));
159
	
159
	
160
	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);
161
	strttl(#draw_buf);
161
	strttl(#draw_buf);
162
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
162
	WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
-
 
163
 
163
 
164
	debugln(#draw_buf);
164
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 15, 
165
	DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 
165
		#draw_buf, -1, 0x000000);
166
		#draw_buf, -1, 0x000000);
166
}
167
}
167
 
168
 
168
 
169
 
169
stop:
170
stop: