Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7500 leency 1
//если выделить область ячеек и сдвинуть курсор ввода с помощью клавиш, "следы" остануться
2
//нельзя перемещаться по буквам в редактируемой строке
2751 leency 3
 
1114 leency 4
#include "func.h"
5
#include "parser.h"
990 barsuk 6
#include "calc.h"
1114 leency 7
#include "use_library.h"
8
 
7516 leency 9
#ifdef AUTOBUILD
10
extern char params[1024];
11
#endif
12
char params[1024];
1114 leency 13
 
7518 leency 14
#define TABLE_VERSION "0.99.2"
7516 leency 15
 
7504 leency 16
// strings
1114 leency 17
const char *sFileSign = "KolibriTable File\n";
7498 leency 18
const char sFilename[] = "Filename:";
1114 leency 19
const char sSave[] = "Save";
20
const char sLoad[] = "Load";
21
const char sNew[] = "New";
22
 
7504 leency 23
const char er_file_not_found[] = "'Cannot open file' -E";
24
const char er_format[] = "'Error: bad format' -E";
25
const char msg_save[] = "'File saved' -O";
26
const char msg_load[] = "'File loaded' -O";
27
const char msg_new[] = "'Memory cleared' -I";
1114 leency 28
 
7498 leency 29
// initial window sizes
7504 leency 30
#define WND_W 718
31
#define WND_H 514
7498 leency 32
// new window size and coordinates
33
int cWidth;
34
int cHeight;
7504 leency 35
kosSysColors sc;
36
// bottom panel
37
#define MENU_PANEL_HEIGHT 40
1114 leency 38
 
7498 leency 39
// interface colors
1114 leency 40
#define GRID_COLOR 0xa0a0a0
41
#define TEXT_COLOR 0x000000
42
#define CELL_COLOR 0xffffff
7504 leency 43
#define CELL_COLOR_ACTIVE 0xe0e0ff
7503 leency 44
#define HEADER_CELL_COLOR 0xE9E7E3
7504 leency 45
#define HEADER_CELL_COLOR_ACTIVE 0xC4C5BA //0xBBBBFF
1114 leency 46
 
7498 leency 47
// button IDs
7518 leency 48
#define SAVE_BUTTON 100
49
#define LOAD_BUTTON 101
50
#define NEW_BUTTON  102
51
#define SELECT_ALL_BUTTON 103
1114 leency 52
 
53
#define COL_BUTTON 0x100
54
#define ROW_BUTTON (COL_BUTTON + 0x100)
55
#define COL_HEAD_BUTTON (ROW_BUTTON + 0x100)
56
#define ROW_HEAD_BUTTON (COL_HEAD_BUTTON + 0x100)
57
#define CELL_BUTTON (ROW_HEAD_BUTTON + 0x100)
58
 
7504 leency 59
// editbox data
60
char edit_text[256];
61
edit_box cell_box = {0,9*8-6,WND_H - 16-32,0xffffff,0x94AECE,0,0x808080,0x10000000,255,(dword)&edit_text,0,0};
1114 leency 62
 
7504 leency 63
// scrolls
64
#define SCROLL_SIZE 16
7498 leency 65
scroll_bar scroll_v = { SCROLL_SIZE,200,398, NULL, SCROLL_SIZE,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
66
scroll_bar scroll_h = { 200,NULL,SCROLL_SIZE, NULL, SCROLL_SIZE,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
1114 leency 67
 
7500 leency 68
// ячейки - их параметры и текст
7507 leency 69
DWORD col_count = 100, row_count = 100;
7503 leency 70
DWORD *cell_w, *cell_h;
1114 leency 71
char ***cells;
72
 
7500 leency 73
struct GRID
74
{
75
	int x,y,w,h;
7504 leency 76
	int firstx, firsty; // cell x:y in the top left corner
77
} grid = {
78
	0,0,NULL,NULL,
79
	1,1
80
};
1114 leency 81
 
7500 leency 82
char ***values;	// значения формул, если есть
83
 
7503 leency 84
bool display_formulas = false;	// отображать ли формулы вместо значений
7500 leency 85
 
86
// координаты отображаемых столбцов и строк
7503 leency 87
DWORD *cell_x, *cell_y;
1114 leency 88
 
7500 leency 89
// буфер обмена
1114 leency 90
char ***buffer = NULL;
91
DWORD buf_col, buf_row;
92
DWORD buf_old_x, buf_old_y;
93
 
7500 leency 94
// это выделенная ячейка
1114 leency 95
DWORD sel_x = 1, sel_y = 1;
7500 leency 96
DWORD prev_x = 0, prev_y = 0;	// предыдущая выделенная
1114 leency 97
int was_single_selection = 0;
98
 
7500 leency 99
// конец выделения если выделено несколько ячеек
1114 leency 100
DWORD sel_end_x = sel_x, sel_end_y = sel_y;
101
 
7500 leency 102
// флаг
1114 leency 103
bool sel_moved = 0;
104
bool sel_end_move = 0;
7500 leency 105
// сколько ячеек помещается в окне по х и у
1114 leency 106
DWORD nx = 0, ny = 0;
107
 
7500 leency 108
// флаг реадктирования ячейки
1114 leency 109
#define is_edit (cell_box.flags & ed_focus)
110
 
7500 leency 111
// редактирование имени файла
1114 leency 112
bool fn_edit = 0;
990 barsuk 113
char fname[256];
7504 leency 114
edit_box file_box = {160,9*8+12,WND_H - 16-32,0xffffff,0x94AECE,0,0x808080,0x10000000,255,(dword)&fname,0,0};
1114 leency 115
 
7500 leency 116
// изменение размеров
117
#define SIZE_X 1 // состояние
1114 leency 118
#define SIZE_Y 2
119
#define SIZE_SELECT 3
120
#define SIZE_DRAG 4
1112 barsuk 121
int size_mouse_x, size_mouse_y, size_id, size_state = 0;
122
 
7500 leency 123
// растаскивание ячейки при ее тащении за правый нижний угол, с заполнением ячеек
1114 leency 124
int drag_x, drag_y;
125
int old_end_x, old_end_y;
126
 
7503 leency 127
void draw_grid();
7518 leency 128
void EventGridSelectAll();
1114 leency 129
 
7503 leency 130
void DrawSelectedFrame(int x, int y, int w, int h, DWORD col)
990 barsuk 131
{
7503 leency 132
	kos_DrawBar(x,y,w,2,col);          // up
133
	kos_DrawBar(x,y,2,h,col);          // left
134
	kos_DrawBar(x,y+h-2,w-2-3,2,col);  // bottom
135
	kos_DrawBar(x+w-2,y, 2,h-2-3,col); // right
136
	kos_DrawBar(x+w-4,y+h-4,4,4,col);
1114 leency 137
}
138
 
7498 leency 139
void DrawScrolls()
140
{
141
	// HOR
142
	scroll_h.x = 0;
7500 leency 143
	scroll_h.y = grid.y + grid.h;
7503 leency 144
	scroll_h.w = grid.w + SCROLL_SIZE + 1;
7498 leency 145
	scroll_h.all_redraw = true;
7503 leency 146
	scroll_h.max_area = col_count - 2;
7504 leency 147
	scroll_h.cur_area = nx-grid.firstx-1;
148
	scroll_h.position = grid.firstx-1;
7498 leency 149
	scrollbar_h_draw((DWORD)&scroll_h);
150
 
151
	// VER
7500 leency 152
	scroll_v.x = grid.x + grid.w;
7498 leency 153
	scroll_v.y = 0;
7503 leency 154
	scroll_v.h = grid.h + 1;
7498 leency 155
	scroll_v.all_redraw = true;
7503 leency 156
	scroll_v.max_area = row_count - 2;
7504 leency 157
	scroll_v.cur_area = ny-grid.firsty-1;
158
	scroll_v.position = grid.firsty-1;
7498 leency 159
	scrollbar_v_draw((DWORD)&scroll_v);
160
}
161
 
162
 
1114 leency 163
void start_edit(int x, int y)
164
{
165
	int ch = 0;
7504 leency 166
	if (x < grid.firstx || x > nx - 1)
1114 leency 167
	{
7504 leency 168
		grid.firstx = x;
1114 leency 169
		ch = 1;
170
	}
7504 leency 171
	if (y < grid.firsty || y > ny - 1)
1114 leency 172
	{
7504 leency 173
		grid.firsty = y;
1114 leency 174
		ch = 1;
175
	}
176
	if (ch)
177
	{
178
		sel_moved = 1;
7507 leency 179
		draw_grid();
990 barsuk 180
	}
181
 
1114 leency 182
	file_box.flags &= ~ed_focus;
183
 
7507 leency 184
	cell_box.flags = ed_focus;
7504 leency 185
	cell_box.left = cell_x[x] + 1;
186
	cell_box.top = cell_y[y];
187
	cell_box.width = cell_w[x] - 2;
1114 leency 188
	memset((Byte*)edit_text, 0, sizeof(edit_text));
990 barsuk 189
	if (cells[x][y])
1114 leency 190
	{
191
		strcpy(edit_text, cells[x][y]);
990 barsuk 192
	}
7507 leency 193
	cell_box.offset = cell_box.shift = cell_box.shift_old = 0;
7504 leency 194
	cell_box.pos = cell_box.size = strlen(edit_text);
1114 leency 195
 
7507 leency 196
	edit_box_draw((DWORD)&cell_box);
197
	edit_box_draw((DWORD)&file_box);
1114 leency 198
}
199
 
200
void stop_edit()
201
{
202
	if (is_edit)
203
	{
204
		cell_box.flags &= ~ed_focus;
205
		if (cells[sel_x][sel_y])
206
			freemem(cells[sel_x][sel_y]);
207
		if (strlen(edit_text) > 0)
208
		{
209
			cells[sel_x][sel_y] = (char*)allocmem(strlen(edit_text)+1);
210
			strcpy(cells[sel_x][sel_y], edit_text);
211
		}
212
		else
213
			cells[sel_x][sel_y] = NULL;
214
		//memset((Byte*)edit_text,0, 256);
990 barsuk 215
		calculate_values();
1114 leency 216
	}
217
}
218
 
219
void cancel_edit()
220
{
221
	if (!is_edit)
222
		return;
223
	cell_box.flags &= ~ed_focus;
224
	memset((Byte*)edit_text,0, 256);
7507 leency 225
	draw_grid();
1114 leency 226
}
227
 
228
void check_sel()
229
{
7504 leency 230
	DWORD sx0=grid.firstx, sy0=grid.firsty;
1114 leency 231
 
7504 leency 232
	if (sel_x >= nx - 1  /*&& sel_x < col_count - nx + grid.firstx + 1*/)
1114 leency 233
		//if (sel_x == nx)
7504 leency 234
			grid.firstx++;
1114 leency 235
		//else
7504 leency 236
		//	grid.firstx = sel_x;
237
	if (sel_y >= ny - 1 /*&& sel_y < row_count - ny + grid.firsty */)
1114 leency 238
		//if (sel_y == ny)
7504 leency 239
			grid.firsty++;
1114 leency 240
		//else
7504 leency 241
		//	grid.firsty = sel_y;
1114 leency 242
 
7504 leency 243
	if (sel_x < grid.firstx)
244
		grid.firstx = sel_x;
245
	if (sel_y < grid.firsty)
246
		grid.firsty = sel_y;
1114 leency 247
 
7504 leency 248
	if (sx0 != grid.firstx || sy0 != grid.firsty)
7500 leency 249
		sel_moved = 0;			// надо перерисовать все
1114 leency 250
 
251
}
252
 
7498 leency 253
void move_selection(DWORD new_x, DWORD new_y)
1114 leency 254
{
255
	sel_moved = 1;
256
	stop_edit();
257
	prev_x = sel_x;
258
	prev_y = sel_y;
259
	sel_x = new_x;
260
	if (sel_x < 1)
261
		sel_x = 1;
262
	if (sel_x > col_count - 1)
263
		sel_x = col_count - 1;
264
	sel_end_x = sel_x;
265
	sel_y = new_y;
266
	if (sel_y < 1)
267
		sel_y = 1;
268
	if (sel_y > row_count - 1)
269
		sel_y = row_count - 1;
270
	sel_end_y = sel_y;
271
	check_sel();
7503 leency 272
	draw_grid();
1114 leency 273
}
274
 
7500 leency 275
// x - между low и high ? - необязательно low
1114 leency 276
bool is_between(Dword x, Dword low, Dword high)
277
{
278
	return ((low= low && x <= high):(x >= high && x <= low));
279
}
280
 
281
void clear_cell_slow(int px, int py)
282
{
283
	int i;
7503 leency 284
	int x0 = cell_w[0];
7504 leency 285
	for (i = grid.firstx; i < px; i++)
1114 leency 286
	{
7503 leency 287
		x0 += cell_w[i];
1114 leency 288
	}
289
	int x1 = x0;
7503 leency 290
	x1 += cell_w[px];
291
	int y0 = cell_h[0];
7504 leency 292
	for (i = grid.firsty; i < py; i++)
1114 leency 293
	{
7503 leency 294
		y0 += cell_h[i];
1114 leency 295
	}
296
	int y1 = y0;
7503 leency 297
	y1 += cell_h[py];
1114 leency 298
	kos_DrawBar(x0 + 1, y0 + 1, x1 - x0 - 1, y1 - y0 - 1, 0xffffff);
299
}
300
 
301
 
7500 leency 302
 
303
// рисование ячеек
1114 leency 304
#define is_x_changed(v) ((v) == sel_x || (v) == prev_x)
305
#define is_y_changed(v) ((v) == sel_y || (v) == prev_y)
306
 
7503 leency 307
void DrawCell(int x, int y, Dword w, Dword h, Dword id, Dword bg_color, char* text, bool header)
308
{
309
	bool small = false;
310
	if (x>grid.x+grid.w || w>grid.w || w<=0) return;
311
	if (x+w > grid.x + grid.w) {
312
		w = grid.x + grid.w - x;
313
		small = true;
314
	}
315
	if (y+h > grid.y + grid.h) {
316
		h = grid.y + grid.h - y;
317
		small = true;
318
	}
319
	kos_DrawBar(x, y, w, h, bg_color);
320
	if (!small) {
321
		if (id) kos_DefineButton(x+5, y, w-10, h-1, id+BT_NODRAW,0);
7504 leency 322
		if (header) kos_WriteTextToWindow( x + w/2 -strlen(text)*4, h/2-7+y, 0x90,TEXT_COLOR,text,0); //WriteTextCenter
323
		else kos_DrawCutTextSmall(x+3, h/2-7+y, w-7, TEXT_COLOR, text);
7503 leency 324
	}
325
}
326
 
1114 leency 327
void draw_grid()
328
{
329
	int i,j;
7503 leency 330
	long x0 = 0, y0 = 0, x = 0, y = 0;
7498 leency 331
	DWORD bg_color;
7503 leency 332
	kos_DrawBar(0,0,cell_w[0],cell_h[0],HEADER_CELL_COLOR); // left top cell
7518 leency 333
	kos_DefineButton(0,0,cell_w[0]-4,cell_h[0]-4, SELECT_ALL_BUTTON + BT_NODRAW, 0);
1114 leency 334
 
7504 leency 335
	//kos_DebugValue("sel_moved", sel_moved);
336
 
1114 leency 337
	nx=ny=0;
338
 
7500 leency 339
	// очистить область около выделенной ячейки
1114 leency 340
	if (sel_moved)
341
	{
342
		clear_cell_slow(sel_x, sel_y);
343
		clear_cell_slow(prev_x, prev_y);
344
	}
345
	else
346
	{
7503 leency 347
		// clean all cells
348
		//kos_DrawBar(cell_w[0]+1, cell_h[0]+1, grid.w - SCROLL_SIZE-cell_w[0]-1, he - SCROLL_SIZE-cell_h[0]-1, 0xffffff);
1114 leency 349
	}
350
 
7503 leency 351
	// column headers + vertical lines
352
	cell_x[0] = 0;
353
	x = cell_w[0];
1114 leency 354
	nx = 1;
7503 leency 355
	for (i = 1; i < col_count && x-x0 < grid.w; i++)
1114 leency 356
	{
7503 leency 357
		cell_x[i] = -1;
7504 leency 358
		if (i >= grid.firstx)
1114 leency 359
		{
360
			{
7504 leency 361
				//if (!sel_moved || (is_x_changed(i))) {
362
					if (is_between(i,sel_x,sel_end_x)) bg_color = HEADER_CELL_COLOR_ACTIVE; else bg_color = HEADER_CELL_COLOR;
7503 leency 363
					kos_DrawBar(x-x0, 0, 1, grid.h, GRID_COLOR);
364
					DrawCell(x-x0+1, 0, cell_w[i]-1, cell_h[0], i+COL_HEAD_BUTTON, bg_color, cells[i][0], true);
7504 leency 365
				//}
7503 leency 366
				cell_x[i] = x - x0;
1114 leency 367
			}
368
		}
369
		else
370
		{
7503 leency 371
			x0 += cell_w[i];
1114 leency 372
		}
7503 leency 373
		x += cell_w[i];
1114 leency 374
		nx++;
375
	}
376
 
7503 leency 377
	// row headers + horizontal lines
378
	y = cell_h[0];
1114 leency 379
	ny = 1;
7503 leency 380
	cell_y[0] = 0;
381
	for (i = 1; i < row_count && y-y0 < grid.h; i++)
1114 leency 382
	{
7503 leency 383
		cell_y[i] = -1;
7504 leency 384
		if (i >= grid.firsty)
1114 leency 385
		{
386
			{
7504 leency 387
				//if (!sel_moved || (is_y_changed(i))) {
388
					if (is_between(i,sel_y,sel_end_y)) bg_color = HEADER_CELL_COLOR_ACTIVE; else bg_color = HEADER_CELL_COLOR;
7503 leency 389
					kos_DrawBar(0, y-y0, grid.w, 1, GRID_COLOR);
390
					DrawCell(0, y-y0+1, cell_w[0], cell_h[i]-1, i+ROW_HEAD_BUTTON, bg_color, cells[0][i], true);
7504 leency 391
				//}
7503 leency 392
				cell_y[i] = y - y0;
1114 leency 393
			}
394
		}
395
		else
396
		{
7503 leency 397
			y0 += cell_h[i];
1114 leency 398
		}
7503 leency 399
		y += cell_h[i];
1114 leency 400
		ny++;
401
	}
402
 
7500 leency 403
	// cells itself
7503 leency 404
	y = cell_h[0];
7504 leency 405
	for (i = grid.firsty; i < ny; i++)
1114 leency 406
	{
7503 leency 407
		x = cell_w[0];
7504 leency 408
		for (j = grid.firstx; j < nx; j++)
1114 leency 409
		{
7503 leency 410
			if (i && j)	//no need to draw headers one more
1114 leency 411
			{
7503 leency 412
				bool draw_frame_selection = false;
413
				bool error = false;
414
				bg_color = CELL_COLOR;
1114 leency 415
 
7503 leency 416
				if (is_between(j,sel_x,sel_end_x) && is_between(i, sel_y, sel_end_y)	// (j,i) - selected
417
				&& ((!sel_moved) || (is_x_changed(j) && is_y_changed(i))))			// and we must draw it
1114 leency 418
				{
7503 leency 419
					if (i == sel_y && j == sel_x)
1114 leency 420
					{
7503 leency 421
						draw_frame_selection = true;
422
						drag_x = x + cell_w[j] - 4;
423
						drag_y = y + cell_h[i] - 4;
1114 leency 424
					}
7503 leency 425
					else {
7504 leency 426
						bg_color = CELL_COLOR_ACTIVE; // selected but not main
7503 leency 427
					}
1114 leency 428
				}
429
 
430
				char *text;
431
				if (values[j][i] && values[j][i][0] == '#')
432
				{
433
					text = cells[j][i];
7503 leency 434
					error = true;
1114 leency 435
				}
7503 leency 436
				else {
1114 leency 437
					text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]);
7503 leency 438
				}
1114 leency 439
 
7503 leency 440
				DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false);
7507 leency 441
				if (draw_frame_selection && j
442
					DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i]+1, TEXT_COLOR);
7504 leency 443
				}
7503 leency 444
				else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0);
1114 leency 445
			}
7503 leency 446
			x += cell_w[j];
1114 leency 447
		}
7503 leency 448
		y += cell_h[i];
1114 leency 449
	}
7498 leency 450
	DrawScrolls();
1114 leency 451
}
452
 
7500 leency 453
// очень быстрое рисование сетки, в процессе изменения размеров ячеек
1114 leency 454
void draw_size_grid()
455
{
456
	//rtlDebugOutString("draw size grid");
457
 
458
	if (size_state == SIZE_X)
459
	{
460
		int x, x0, i;
461
 
7503 leency 462
		x = cell_w[0];
1114 leency 463
		x0 = 0;
7503 leency 464
		for (i = 1; i < col_count && x - x0 + cell_w[i] < grid.w - 10; i++)
1114 leency 465
		{
7504 leency 466
			if (i >= grid.firstx)
1114 leency 467
			{
468
				if (i >= size_id)
7500 leency 469
					kos_DrawLine(x - x0, 0, x - x0, grid.h, 0, 1);
1114 leency 470
			}
471
			else
7503 leency 472
				x0 += cell_w[i];
473
			x += cell_w[i];
1114 leency 474
		}
7500 leency 475
		kos_DrawLine(x - x0, 0, x - x0, grid.h, 0, 1);
1114 leency 476
	}
477
	else
478
	{
479
		int y, y0, i;
480
 
7503 leency 481
		y = cell_h[0];
1114 leency 482
		y0 = 0;
7503 leency 483
		for (i = 1; i < col_count && y - y0 + cell_h[i] < grid.h - 10; i++)
1114 leency 484
		{
7504 leency 485
			if (i >= grid.firsty)
1114 leency 486
			{
487
				if (i >= size_id)
7500 leency 488
					kos_DrawLine(0, y - y0, grid.w, y - y0, 0, 1);
1114 leency 489
			}
490
			else
7503 leency 491
				y0 += cell_h[i];
492
			y += cell_h[i];
1114 leency 493
		}
7500 leency 494
		kos_DrawLine(0, y - y0, grid.w, y - y0, 0, 1);
1114 leency 495
	}
496
 
497
}
498
 
499
 
7500 leency 500
// быстрое рисование выделенной области при выделении мышью
1114 leency 501
#define DCOLOR 0
502
//0xff0000
503
#define DINVERT 1
504
void draw_drag()
505
{
7500 leency 506
	// inverted lines
1114 leency 507
	int k0 = min(sel_x, sel_end_x);
508
	int k1 = max(sel_x, sel_end_x);
509
	int n0 = min(sel_y, sel_end_y);
510
	int n1 = max(sel_y, sel_end_y);
511
 
7503 leency 512
	DWORD x0 = cell_x[k0] - 1;
513
	DWORD x1 = cell_x[k1] + cell_w[k1] + 1;
514
	DWORD y0 = cell_y[n0] - 1;
515
	DWORD y1 = cell_y[n1] + cell_h[n1] + 1;
7500 leency 516
	if (x0 > grid.w - 1) x0 = grid.w - 1;
517
	if (x1 > grid.w - 1) x1 = grid.w - 1;
518
	if (y0 > grid.h - 1) y0 = grid.h - 1;
519
	if (y1 > grid.h - 1) y1 = grid.h - 1;
1114 leency 520
 
521
	//sprintf(debuf,"drag %U %U %U %U",k0,k1,n0,n1);
990 barsuk 522
	//rtlDebugOutString(debuf);
523
 
1114 leency 524
	kos_DrawLine(x0, y0, x0, y1, DCOLOR, DINVERT);
525
	kos_DrawLine(x0, y0, x1, y0, DCOLOR, DINVERT);
526
	kos_DrawLine(x1, y0, x1, y1, DCOLOR, DINVERT);
527
	kos_DrawLine(x0, y1, x1, y1, DCOLOR, DINVERT);
528
}
529
 
7507 leency 530
void draw_window()
1114 leency 531
{
7500 leency 532
	kos_WindowRedrawStatus(1);
533
	kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION);
534
	kos_WindowRedrawStatus(2);
1114 leency 535
 
7504 leency 536
	kos_GetSystemColors(&sc);
537
 
7500 leency 538
	sProcessInfo info;
539
	kos_ProcessInfo(&info, 0xFFFFFFFF);
540
	cWidth = info.processInfo.width - 9;
541
	cHeight = info.processInfo.height - kos_GetSkinHeight() - 4;
1114 leency 542
 
7500 leency 543
	grid.x = 0;
544
	grid.y = 0;
7503 leency 545
	grid.w = cWidth - SCROLL_SIZE - 1;
7500 leency 546
	grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE;
1114 leency 547
 
7507 leency 548
	if (info.processInfo.status_window&0x04) return; //draw nothing if window is rolled-up
1114 leency 549
 
7507 leency 550
	if (cWidth  < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return; }
551
	if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return; }
7498 leency 552
 
7503 leency 553
	sel_moved = 0;
7507 leency 554
	if (is_edit) stop_edit();
7503 leency 555
 
7504 leency 556
	int panel_y = cHeight - MENU_PANEL_HEIGHT + 1;
557
	kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, sc.work);
558
	kos_WriteTextToWindow(3 + 1, panel_y + 14, 0x90, sc.work_text, (char*)sFilename, 0);
559
	file_box.top = panel_y + 10;
560
	#define BTX 230
561
	#define BTW 70
7500 leency 562
	//save
7504 leency 563
	kos_DefineButton(BTX + 25, file_box.top, BTW, 21, SAVE_BUTTON, sc.work);
564
	kos_WriteTextToWindow(BTX + 25 + (BTW - strlen(sSave) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sSave, 0);
7500 leency 565
	//load
7504 leency 566
	kos_DefineButton(BTX + 25+BTW+5, file_box.top, BTW, 21, LOAD_BUTTON, sc.work);
567
	kos_WriteTextToWindow(BTX + 25+BTW+5 + (BTW - strlen(sLoad) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sLoad, 0);
7507 leency 568
	// // new (clean)
569
	// kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, sc.work);
570
	// kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, sc.work_text, (char*)sNew, strlen(sNew));
1114 leency 571
 
7504 leency 572
	if (sel_end_move) sel_moved = 0;
1114 leency 573
	draw_grid();
574
	sel_moved = 0;
7507 leency 575
 
576
	if (is_edit) edit_box_draw((DWORD)&cell_box);
577
	edit_box_draw((DWORD)&file_box);
1114 leency 578
}
579
 
580
void process_mouse()
581
{
582
	Dword mouse_btn, ckeys, shift, ctrl;
990 barsuk 583
 
1114 leency 584
	int vert, hor;
7504 leency 585
	kos_GetScrollInfo(vert, hor);
7498 leency 586
	if (vert != 0)
1114 leency 587
	{
7498 leency 588
		stop_edit();
7504 leency 589
		grid.firsty += vert;
590
		if (grid.firsty<1) grid.firsty=1;
591
		if (grid.firsty>row_count-25) grid.firsty=row_count-25;
7498 leency 592
		draw_grid();
1114 leency 593
		return;
594
	}
7498 leency 595
 
7500 leency 596
	if (!sel_moved && !size_state) //do not handle scrollbars when user selects cells
7498 leency 597
	{
7504 leency 598
		if (!scroll_h.delta2) scrollbar_v_mouse((DWORD)&scroll_v);
599
		if (scroll_v.position != grid.firsty-1)
7500 leency 600
		{
7507 leency 601
			stop_edit();
7504 leency 602
			grid.firsty = scroll_v.position + 1;
7500 leency 603
			draw_grid();
604
		}
7498 leency 605
 
7504 leency 606
		if (!scroll_v.delta2) scrollbar_h_mouse((DWORD)&scroll_h);
607
		if (scroll_h.position != grid.firstx-1)
7500 leency 608
		{
7507 leency 609
			stop_edit();
7504 leency 610
			grid.firstx = scroll_h.position + 1;
7500 leency 611
			draw_grid();
7504 leency 612
		}
7498 leency 613
	}
7504 leency 614
	if (scroll_v.delta2 || scroll_h.delta2) return;
7498 leency 615
 
7507 leency 616
	if (is_edit) edit_box_mouse((dword)&cell_box);
7504 leency 617
	edit_box_mouse((dword)&file_box);
618
 
619
	int mouse_x, mouse_y, i;
1114 leency 620
	kos_GetMouseState(mouse_btn, mouse_x, mouse_y);
621
	mouse_x -= 5;
1112 barsuk 622
	mouse_y -= kos_GetSkinHeight();
623
 
7507 leency 624
	if (is_edit && mouse_x>=cell_box.left && mouse_x<=cell_box.left+cell_box.width
625
		&& mouse_y>=cell_box.top && mouse_y<=cell_box.top+22) return;
626
 
1114 leency 627
	mouse_btn &= 0x0001;
628
 
7500 leency 629
	if (mouse_btn)
630
	{
631
		if (mouse_y < 0) return; // do nothing if mouse over header
632
		if (mouse_y > grid.y + grid.h) return;
633
	}
634
 
1114 leency 635
	ckeys = kos_GetSpecialKeyState();
636
	shift = ckeys & 0x3;
637
 
638
	if (!size_state && !mouse_btn)
639
		return;
640
	if (mouse_btn && !size_state)		// LMB down
641
	{
642
		//rtlDebugOutString("lmb down and not resize");
643
 
644
		if (mouse_x >= drag_x && mouse_x <= drag_x + 4 && mouse_y >= drag_y && mouse_y <= drag_y + 4)
645
		{
646
			size_state = SIZE_DRAG;
647
			old_end_x = sel_end_x;
648
			old_end_y = sel_end_y;
649
		}
7503 leency 650
		else if (mouse_y <= cell_h[0])
1114 leency 651
		{
7503 leency 652
			//rtlDebugOutString("can resize col_count");
1114 leency 653
			int kx = -1, i;
654
			for (i = 0; i < col_count - 1; i++)
7503 leency 655
			if (mouse_x >= cell_x[i] + cell_w[i] - 5 &&
656
				mouse_x <= cell_x[i + 1] + 5)
990 barsuk 657
			{
1114 leency 658
				kx = i; break;
659
			}
660
			if (kx != -1)
661
			{
662
				//sprintf(debuf,"size x %U",k);
663
				//rtlDebugOutString(debuf);
664
				size_id = kx;
665
				size_state = SIZE_X;
666
			}
667
		}
7503 leency 668
		else if (mouse_x <= cell_w[0])
1114 leency 669
		{
670
			int ky = -1;
671
			for (i = 0; i < row_count - 1; i++)
7503 leency 672
			if (mouse_y >= cell_y[i] + cell_h[i] - 5 &&
673
				mouse_y <= cell_y[i + 1] + 5)
1114 leency 674
			{
675
				ky = i; break;
676
			}
677
			if (ky != -1)
678
			{
679
				size_id = ky;
680
				size_state = SIZE_Y;
681
			}
682
		}
7504 leency 683
		else   // click on cell
7503 leency 684
		if (mouse_x <= cell_x[nx - 1] &&  mouse_y <= cell_y[ny - 1])
1114 leency 685
		{
686
			was_single_selection = sel_x == sel_end_x && sel_y == sel_end_y;
687
			int kx = -1, i;
688
			for (i = 0; i < col_count - 1; i++)
7503 leency 689
			if (mouse_x >= cell_x[i] &&
690
				mouse_x <= cell_x[i] + cell_w[i])
1114 leency 691
			{
692
				kx = i; break;
693
			}
694
			int ky = -1;
695
			for (i = 0; i < row_count - 1; i++)
7503 leency 696
			if (mouse_y >= cell_y[i] &&
697
				mouse_y <= cell_y[i] + cell_h[i])
1114 leency 698
			{
699
				ky = i; break;
700
			}
701
			if (kx != -1 && ky != -1)
702
			{
990 barsuk 703
				if (!shift)
1114 leency 704
				{
7498 leency 705
					move_selection(kx, ky);
1112 barsuk 706
					//return;
1114 leency 707
				}
708
				else
709
				{
1112 barsuk 710
					sel_end_x = kx;
1114 leency 711
					sel_end_y = ky;
712
				}
713
				size_state = SIZE_SELECT;
714
			}
715
		}
716
		if (size_state)
717
		{
718
			size_mouse_x = mouse_x;
719
			size_mouse_y = mouse_y;
720
		}
721
		return;
722
	}
723
	else if (!mouse_btn && size_state)
724
	{
7500 leency 725
		sel_moved = 0;		// for a good redraw
1114 leency 726
		//rtlDebugOutString("resize end");
727
 
728
		if (size_state == SIZE_DRAG)
729
		{
730
			fill_cells(sel_x, sel_y, sel_end_x, sel_end_y, old_end_x, old_end_y);
731
		}
732
 
733
		//sel_moved = (size_state == SIZE_SELECT && sel_x == sel_end_x && sel_y == sel_end_y && was_single_selection);
734
		size_state = 0;
7504 leency 735
		draw_grid();		// все сдвинулось - надо обновиться
1114 leency 736
		return;
737
	}
738
	if (size_state == SIZE_X && mouse_x != size_mouse_x)
739
	{
740
		draw_size_grid();
7503 leency 741
		cell_w[size_id] += mouse_x - size_mouse_x;
742
		if (cell_w[size_id] < 15)
743
			cell_w[size_id] = 15;
744
		else if (cell_w[size_id] > grid.w / 2)
745
			cell_w[size_id] = grid.w / 2;
1114 leency 746
		draw_size_grid();
747
	}
748
	if (size_state == SIZE_Y && mouse_y != size_mouse_y)
749
	{
750
		draw_size_grid();
7503 leency 751
		cell_h[size_id] += mouse_y - size_mouse_y;
752
		if (cell_h[size_id] < 15)
753
			cell_h[size_id] = 15;
754
		else if (cell_h[size_id] > grid.h / 2)
755
			cell_h[size_id] = grid.h / 2;
1114 leency 756
		draw_size_grid();
757
	}
758
	if ((size_state == SIZE_SELECT || size_state == SIZE_DRAG) && (mouse_x != size_mouse_x || mouse_y != size_mouse_y))
759
	{
760
		draw_drag();
761
		int kx = -1, i;
762
		for (i = 0; i < col_count - 1; i++)
7503 leency 763
			if (mouse_x >= cell_x[i] &&
764
				mouse_x <= cell_x[i + 1])
1114 leency 765
			{
7503 leency 766
				//sprintf(debuf, "yyy %U",cell_x[i+1]);
1114 leency 767
				//rtlDebugOutString(debuf);
768
				kx = i; break;
769
			}
770
		int ky = -1;
771
		for (i = 0; i < row_count - 1; i++)
7503 leency 772
			if (mouse_y >= cell_y[i] &&
773
				mouse_y <= cell_y[i + 1])
1114 leency 774
			{
775
				ky = i; break;
776
			}
777
		if (kx != -1) sel_end_x = kx;
7503 leency 778
		if (ky != -1) sel_end_y = ky;
1114 leency 779
		if (size_state == SIZE_DRAG)
780
		{
781
			if (abs(sel_end_x - sel_x) > 0)
782
			{
783
				sel_end_y = old_end_y;
784
			}
785
			else if (abs(sel_end_y - sel_y) > 0)
786
			{
787
				sel_end_x = old_end_x;
788
			}
789
		}
790
		draw_drag();
791
	}
792
	size_mouse_x = mouse_x;
793
	size_mouse_y = mouse_y;
794
}
795
 
7507 leency 796
 
797
void shift_selection(int dx, int dy, Dword shift)
798
{
799
	if (dx != 0)
800
	{
801
		if (shift)
802
		{
803
			sel_end_x += dx;
804
			if (sel_end_x <= 1)
805
				sel_end_x = 1;
806
			else if (sel_end_x >= col_count)
807
				sel_end_x = col_count - 1;
808
		//	sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y);
809
		//	rtlDebugOutString(debuf);
810
			sel_moved = sel_end_move = 1;
811
			//stop_edit();
812
			//draw_grid();
813
		}
814
		else
815
		{
816
		}
817
	}
818
	if (dy != 0)
819
	{
820
		if (shift)
821
		{
822
			sel_end_y += dy;
823
			if (sel_end_y <= 1)
824
				sel_end_y = 1;
825
			else if (sel_end_y >= row_count)
826
				sel_end_y = row_count - 1;
827
		//	sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y);
828
		//	rtlDebugOutString(debuf);
829
			sel_moved = sel_end_move = 1;
830
			//stop_edit();
831
			//draw_grid();
832
		}
833
	}
834
	/*
835
	if (sel_end_x < sel_x)
836
	{
837
		Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp;
838
	}
839
	if (sel_end_y < sel_y)
840
	{
841
		Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp;
842
	}
843
	*/
844
	if ((dx || dy))
845
	{
846
		if (!shift)
847
		{
848
			if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //stub
849
			else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;}
850
			else {
851
			move_selection(sel_x + dx, sel_y + dy);
852
			}
853
		}
854
		else
855
		{
856
			sel_moved = 0;
857
			stop_edit();
858
			draw_grid();
859
		}
860
	}
861
}
862
 
863
 
1114 leency 864
void process_key()
865
{
7507 leency 866
	Dword ckeys, shift, ctrl;
867
	dword key_editbox;
868
	Byte key_ascii, key_scancode;
1114 leency 869
 
870
	// key pressed, read it
871
	ckeys = kos_GetSpecialKeyState();
872
	shift = ckeys & 0x3;
873
	ctrl = ckeys & 0x0c;
874
	sel_moved = 0;
875
	sel_end_move = 0;
7507 leency 876
 
877
	kos_GetKeys(key_editbox, key_ascii, key_scancode);
990 barsuk 878
 
7507 leency 879
	if (cell_box.flags & ed_focus) {
880
		if (SCAN_CODE_ENTER == key_scancode) {
881
			stop_edit();
7498 leency 882
			draw_grid();
7507 leency 883
		}
884
		else if (SCAN_CODE_ESC == key_scancode) {
1114 leency 885
			cancel_edit();
7507 leency 886
		}
887
		else {
888
			__asm
1114 leency 889
			{
7507 leency 890
				mov eax, key_editbox
1114 leency 891
			}
7507 leency 892
			edit_box_key((dword)&cell_box);
893
		}
894
	}
895
	else if (file_box.flags & ed_focus) {
896
		__asm
897
		{
898
			mov eax, key_editbox
899
		}
900
		edit_box_key((dword)&file_box);
901
		return;
902
	}
903
	else if (ctrl) {
904
		switch (key_scancode)
905
		{
7518 leency 906
			case SCAN_CODE_KEY_A:
907
				EventGridSelectAll();
908
				break;
7507 leency 909
			case SCAN_CODE_KEY_V:
1114 leency 910
				{
911
					int i, j, x0, y0;
912
					x0 = min(sel_x, sel_end_x);
913
					y0 = min(sel_y, sel_end_y);
914
					int delta_x = x0 - buf_old_x;
915
					int delta_y = y0 - buf_old_y;
916
 
917
					for (i = 0; i < buf_col; i++)
918
						for (j = 0; j < buf_row; j++)
919
						{
920
							if (i + x0 >= col_count || j + y0 >= row_count)
921
								continue;
922
							if (cells[i + x0][j + y0])
923
								freemem(cells[i + x0][j + y0]);
924
							if (buffer[i][j])
925
							{
926
								cf_x0 = buf_old_x; cf_y0 = buf_old_y;
927
								cf_x1 = buf_old_x + buf_col;
928
								cf_y1 = buf_old_y + buf_row;
929
								cells[i + x0][j + y0] = change_formula(buffer[i][j], delta_x, delta_y);
930
								//cells[i + x0][j + y0] = (char*)allocmem(strlen(buffer[i][j]));
931
								//strcpy(cells[i + x0][j + y0], buffer[i][j]);
932
							}
933
							else
934
								cells[i + x0][j + y0] = NULL;
935
						}
936
 
937
					calculate_values();
7498 leency 938
					draw_grid();
1114 leency 939
					break;
940
				}
7507 leency 941
				case SCAN_CODE_KEY_X:
942
				case SCAN_CODE_KEY_C:
1114 leency 943
				{
944
					int i, j, x0, y0;
945
 
946
					freeBuffer();
947
 
948
					buf_col = abs(sel_end_x - sel_x) + 1;
949
					buf_row = abs(sel_end_y - sel_y) + 1;
950
					x0 = min(sel_x, sel_end_x);
951
					y0 = min(sel_y, sel_end_y);
952
					buf_old_x = x0;
953
					buf_old_y = y0;
954
 
955
					//sprintf(debuf, "%U %U %U %U", buf_col, buf_row, x0, y0);
956
					//rtlDebugOutString(debuf);
957
 
958
					buffer = (char***)allocmem(buf_col * sizeof(char**));
959
					for (i = 0; i < buf_col; i++)
960
					{
961
						buffer[i] = (char**)allocmem(buf_row * sizeof(char*));
962
						for (j = 0; j < buf_row; j++)
963
						{
964
							if (cells[i + x0][j + y0])
965
							{
7507 leency 966
								if (SCAN_CODE_KEY_C == key_scancode)
1114 leency 967
								{
968
									buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0]));
969
									strcpy(buffer[i][j], cells[i + x0][j + y0]);
970
								}
971
								else
972
								{
973
									buffer[i][j] = cells[i + x0][j + y0];
974
									cells[i + x0][j + y0] = NULL;
975
								}
976
							}
977
							else
978
								buffer[i][j] = NULL;
979
						}
980
					}
7507 leency 981
					if (key_ascii == 24)     ///////WTF????
1114 leency 982
						calculate_values();
7498 leency 983
					draw_grid();
1114 leency 984
					break;
985
				}
7507 leency 986
			case SCAN_CODE_KEY_F:
1114 leency 987
				display_formulas = !display_formulas;
7498 leency 988
				draw_grid();
1114 leency 989
				break;
7507 leency 990
		}
991
	}
992
	else switch (key_scancode)
993
	{
994
		case SCAN_CODE_UP:
995
			shift_selection(0, -1, shift);
996
			break;
997
		case SCAN_CODE_LEFT:
998
			shift_selection(-1, 0, shift);
999
			break;
1000
		case SCAN_CODE_RIGHT:
1001
			shift_selection(1, 0, shift);
1002
			break;
1003
		case SCAN_CODE_DOWN:
1004
			shift_selection(0, 1, shift);
1005
			break;
1006
		case SCAN_CODE_PGDN:
1007
			shift_selection(0, ny-grid.firsty-1, shift);
1008
			break;
1009
		case SCAN_CODE_PGUP:
1010
			shift_selection(0, -(ny-grid.firsty), shift);
1011
			break;
1012
		case SCAN_CODE_HOME:
1013
			shift_selection(-sel_x + 1, 0, shift);
1014
			break;
1015
		case SCAN_CODE_END:
1016
			shift_selection(col_count - (nx - grid.firstx) - 1 - sel_x, 0, shift);
1017
			break;
1018
		case SCAN_CODE_DEL:
1114 leency 1019
			{
7507 leency 1020
				int n0 = min(sel_x, sel_end_x);
1021
				int n1 = max(sel_x, sel_end_x);
1022
				int k0 = min(sel_y, sel_end_y);
1023
				int k1 = max(sel_y, sel_end_y);
1024
 
1025
				for (int i = n0; i <= n1; i++)
1026
					for (int j = k0; j <= k1; j++)
990 barsuk 1027
					{
7507 leency 1028
						if (cells[i][j])
1029
						{
1030
							freemem(cells[i][j]);
1031
							cells[i][j] = NULL;
1032
						}
990 barsuk 1033
					}
7507 leency 1034
				calculate_values();
1035
				draw_grid();
1036
				break;
990 barsuk 1037
			}
1114 leency 1038
			break;
7507 leency 1039
		case SCAN_CODE_F2:
1040
			start_edit(sel_x, sel_y);
1041
			break;
1042
		case SCAN_CODE_F5:
1043
			draw_grid();
1044
			break;
1045
		default:
1046
			start_edit(sel_x, sel_y);
1047
			__asm
1048
			{
1049
				mov eax, key_editbox
2749 leency 1050
			}
7507 leency 1051
			edit_box_key((dword)&cell_box);
1052
			break;
1114 leency 1053
	}
1054
}
1055
 
7516 leency 1056
void EventLoadFile()
1057
{
1058
	stop_edit();
1059
	int r = LoadFile(fname);
1060
	char *result;
1061
	if (r > 0) {
1062
		calculate_values();
1063
		sel_moved = 0;
1064
		draw_grid();
1065
		result = (char*)msg_load;
1066
	}
1067
	else if (r == -1) result = (char*)er_file_not_found;
1068
	else if (r == -2) result = (char*)er_format;
1069
	kos_AppRun("/sys/@notify", result);
1070
}
1071
 
7518 leency 1072
void EventGridSelectAll()
1073
{
1074
	sel_y = 1;
1075
	sel_x = 1;
1076
	sel_end_x = col_count - 1;
1077
	sel_end_y = row_count - 1;
1078
	stop_edit();
1079
	draw_grid();
1080
}
1081
 
1114 leency 1082
void process_button()
1083
{
1084
	Dword button;
7498 leency 1085
	if (!kos_GetButtonID(button)) return;
1114 leency 1086
	switch (button)
1087
	{
1088
	case 1:
1089
		kos_ExitApp();
1090
 
1091
	case NEW_BUTTON:	// clear the table
1092
		reinit();
7504 leency 1093
		draw_grid();
1114 leency 1094
		break;
1095
 
1096
	case SAVE_BUTTON:
1097
		stop_edit();
7504 leency 1098
		if (SaveFile(fname)) kos_AppRun("/sys/@notify", (char*)msg_save);
1114 leency 1099
		break;
1100
 
1101
	case LOAD_BUTTON:
7516 leency 1102
		EventLoadFile();
1114 leency 1103
		break;
7518 leency 1104
 
1105
	case SELECT_ALL_BUTTON:
1106
		EventGridSelectAll();
1107
		break;
1114 leency 1108
	}
7504 leency 1109
	if (button >= COL_HEAD_BUTTON    &&    button < ROW_HEAD_BUTTON)
1114 leency 1110
	{
1111
		sel_end_x = sel_x = button - COL_HEAD_BUTTON;
1112
		sel_y = 1;
1113
		sel_end_y = row_count - 1;
1114
		stop_edit();
7498 leency 1115
		draw_grid();
1114 leency 1116
		return;
1117
	}
7504 leency 1118
	else if (button >= ROW_HEAD_BUTTON    &&    button < CELL_BUTTON)
1114 leency 1119
	{
1120
		sel_end_y = sel_y = button - ROW_HEAD_BUTTON;
1121
		sel_x = 1;
1122
		sel_end_x = col_count - 1;
1123
		stop_edit();
7498 leency 1124
		draw_grid();
1114 leency 1125
		return;
1126
	}
1127
}
1128
 
1129
void kos_Main()
1130
{
990 barsuk 1131
	kos_InitHeap();
1132
	load_edit_box();
1114 leency 1133
	init();
7516 leency 1134
	if (params[0]) {
1135
		strcpy(fname, params);
1136
		file_box.size = file_box.pos = strlen(fname);
1137
		EventLoadFile();
1138
	}
7504 leency 1139
	kos_SetMaskForEvents(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
1114 leency 1140
	for (;;)
1141
	{
2751 leency 1142
		switch (kos_WaitForEvent())
1114 leency 1143
		{
7498 leency 1144
		case EM_MOUSE_EVENT:
1114 leency 1145
			process_mouse();
990 barsuk 1146
			break;
7498 leency 1147
 
1148
		case EM_KEY_PRESS:
1114 leency 1149
			process_key();
1150
			break;
7498 leency 1151
 
1152
		case EM_BUTTON_CLICK:
1114 leency 1153
			process_button();
1154
			break;
7498 leency 1155
 
1156
		case EM_WINDOW_REDRAW:
7507 leency 1157
			draw_window();
7498 leency 1158
			break;
1114 leency 1159
		}
1160
	}
1161
}
1162