Subversion Repositories Kolibri OS

Rev

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