Subversion Repositories Kolibri OS

Rev

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