Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
990 barsuk 1
 
2
#include "parser.h"
3
#include "calc.h"
4
#include "use_library.h"
5
///#include "use_library.h"
6
//const char header[] = "Table";
7
8
 
1112 barsuk 9
990 barsuk 10
 
11
const char *sFileSign = "KolibriTable File\n";
12
const char sFilename[] = "Filename: ";
13
const char sSave[] = "Save";
14
const char sLoad[] = "Load";
15
const char sNew[] = "New";
16
17
 
18
const char er_format[] = "Error: bad format. ";
19
const char msg_save[] = "File saved. ";
20
const char msg_load[] = "File loaded. ";
21
const char msg_new[] = "Memory cleared. ";
22
23
 
24
Dword myPID = -1;
25
26
 
27
#define WND_W 550
28
#define WND_H 400
29
// новые размеры и координаты
30
int wi = WND_W, he = WND_H;
31
int win_x, win_y;
32
33
 
34
#define GRID_COLOR 0xa0a0a0
35
#define TEXT_COLOR 0x000000
36
#define CELL_COLOR 0xffffff
37
#define SEL_CELL_COLOR 0xe0e0ff
38
#define FIXED_CELL_COLOR 0xe0e0ff
39
#define SEL_FIXED_CELL_COLOR 0x758FC1
40
#define TEXT_SEL_FIXED_COLOR 0xffffff
41
42
 
43
#define SCROLL_BAR_HEIGHT 16
44
45
 
46
#define FILENAME_BUTTON 0x10
47
#define SAVE_BUTTON 0x11
48
#define LOAD_BUTTON 0x12
49
#define NEW_BUTTON 0x13
50
#define DRAG_BUTTON 0x20
51
52
 
53
#define SCROLL_RIGHT_BUTTON 0x22
54
#define SCROLL_UP_BUTTON 0x23
55
#define SCROLL_DOWN_BUTTON 0x24
56
#define SCROLL_WIDTH 0x25
57
#define SCROLL_HEIGHT 0x26
58
59
 
60
#define ROW_BUTTON (COL_BUTTON + 0x100)
61
#define COL_HEAD_BUTTON (ROW_BUTTON + 0x100)
62
#define ROW_HEAD_BUTTON (COL_HEAD_BUTTON + 0x100)
63
#define CELL_BUTTON (ROW_HEAD_BUTTON + 0x100)
64
65
 
66
 
67
#define MENU_PANEL_HEIGHT 40
68
Dword panel_y = 0;
69
70
 
71
char edit_text[256] = "";
72
edit_box cell_box = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,255,(dword)&edit_text,0};
73
74
 
75
DWORD def_col_width = 80, def_row_height = 16;
76
DWORD col_count = 200, row_count = 100;
77
DWORD *col_width, *row_height;
78
char ***cells;
79
char ***values;	// значения формул, если есть
80
81
 
82
83
 
84
DWORD *col_left, *row_top;
85
86
 
87
char ***buffer = NULL;
88
DWORD buf_col, buf_row;
89
DWORD buf_old_x, buf_old_y;
90
91
 
92
DWORD scroll_x = 1, scroll_y = 1;
93
// это выделенная ячейка
94
DWORD sel_x = 1, sel_y = 1;
95
DWORD prev_x = 0, prev_y = 0;	// предыдущая выделенная
96
int was_single_selection = 0;
97
98
 
99
DWORD sel_end_x = sel_x, sel_end_y = sel_y;
100
101
 
102
bool sel_moved = 0;
103
bool sel_end_move = 0;
104
// сколько ячеек помещается в окне по х и у
105
DWORD nx = 0, ny = 0;
106
107
 
108
//bool is_edit = 0;
109
#define ed_focus 2
110
#define is_edit (cell_box.flags & ed_focus)
111
112
 
113
bool fn_edit = 0;
114
char fname[256];
115
edit_box file_box = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,255,(dword)&fname,0};
116
117
 
118
#define SIZE_X 1 // состояние
119
#define SIZE_Y 2
120
#define SIZE_SELECT 3
121
#define SIZE_DRAG 4
122
int size_mouse_x, size_mouse_y, size_id, size_state = 0;
1112 barsuk 123
124
 
125
990 barsuk 126
 
127
int drag_x, drag_y;
128
int old_end_x, old_end_y;
129
130
 
131
132
 
133
134
 
135
{
136
	kos_DrawLine(x,y,x+width-2,y,color1,invert);
137
	kos_DrawLine(x,y+1,x,y+height-1,color1,invert);
138
	kos_DrawLine(x+width-1,y,x+width-1,y+height-2,color1,invert);
139
	kos_DrawLine(x+1,y+height-1,x+width-1,y+height-1,color1,invert);
140
}
141
142
 
143
{
144
145
 
146
	if (x < scroll_x || x > nx - 1)
147
	{
148
		scroll_x = x;
149
		ch = 1;
150
	}
151
	if (y < scroll_y || y > ny - 1)
152
	{
153
		scroll_y = y;
154
		ch = 1;
155
	}
156
	if (ch)
157
	{
158
		sel_moved = 1;
159
		draw_window();
160
	}
161
162
 
163
164
 
165
	cell_box.left = col_left[x] + 1;
166
	cell_box.top = row_top[y] + 1;
167
	cell_box.width = col_width[x] - 2;
168
	//cell_box.height= row_height[y];
169
	memset((Byte*)edit_text, 0, sizeof(edit_text));
170
	if (cells[x][y])
171
	{
172
		strcpy(edit_text, cells[x][y]);
173
		edit_text[strlen(cells[x][y]) - 1] = '\0';
174
	}
175
	cell_box.pos = cell_box.offset = 0;
176
177
 
178
}
179
180
 
181
{
182
	if (is_edit)
183
	{
184
		cell_box.flags &= ~ed_focus;
185
		if (cells[sel_x][sel_y])
186
			freemem(cells[sel_x][sel_y]);
187
		if (strlen(edit_text) > 0)
188
		{
189
			cells[sel_x][sel_y] = (char*)allocmem(strlen(edit_text)+1);
190
			strcpy(cells[sel_x][sel_y], edit_text);
191
		}
192
		else
193
			cells[sel_x][sel_y] = NULL;
194
		//memset((Byte*)edit_text,0, 256);
195
		calculate_values();
196
	}
197
}
198
199
 
200
{
201
	if (!is_edit)
202
		return;
203
	cell_box.flags &= ~ed_focus;
204
	memset((Byte*)edit_text,0, 256);
205
	draw_window();
206
}
207
208
 
209
{
210
	DWORD sx0=scroll_x, sy0=scroll_y;
211
212
 
213
		//if (sel_x == nx)
214
			scroll_x++;
215
		//else
216
		//	scroll_x = sel_x;
217
	if (sel_y >= ny - 1 /*&& sel_y < row_count - ny + scroll_y */)
218
		//if (sel_y == ny)
219
			scroll_y++;
220
		//else
221
		//	scroll_y = sel_y;
222
223
 
224
		scroll_x = sel_x;
225
	if (sel_y < scroll_y)
226
		scroll_y = sel_y;
227
228
 
229
		sel_moved = 0;			// надо перерисовать все
230
231
 
232
233
 
234
void move_sel(DWORD new_x, DWORD new_y)
235
{
236
	sel_moved = 1;
237
	stop_edit();
238
	prev_x = sel_x;
239
	prev_y = sel_y;
240
	sel_x = new_x;
241
	if (sel_x < 1)
242
		sel_x = 1;
243
	if (sel_x > col_count - 1)
244
		sel_x = col_count - 1;
245
	sel_end_x = sel_x;
246
	sel_y = new_y;
247
	if (sel_y < 1)
248
		sel_y = 1;
249
	if (sel_y > row_count - 1)
250
		sel_y = row_count - 1;
251
	sel_end_y = sel_y;
252
	check_sel();
253
	draw_window();
254
}
255
256
 
257
{
258
	int x1 = x0 + sx;
259
	int y1 = y0 + sy;
260
261
 
262
263
 
264
265
 
266
267
 
268
269
 
270
	kos_DrawLine(x0, y0, x0, y1, 0xffffff, 0);
271
272
 
273
	kos_DrawLine(x0, y1, x1, y1, 0xc7c7c7, 0);
274
	kos_DrawLine(x1, y0, x1, y1, 0xc7c7c7, 0);
275
}
276
277
 
278
bool is_between(Dword x, Dword low, Dword high)
279
{
280
	return ((low= low && x <= high):(x >= high && x <= low));
281
}
282
283
 
284
{
285
	int i;
286
	int x0 = col_width[0];
287
	for (i = scroll_x; i < px; i++)
288
	{
289
		x0 += col_width[i];
290
	}
291
	int x1 = x0;
292
	x1 += col_width[px];
293
	int y0 = row_height[0];
294
	for (i = scroll_y; i < py; i++)
295
	{
296
		y0 += row_height[i];
297
	}
298
	int y1 = y0;
299
	y1 += row_height[py];
300
	kos_DrawBar(x0 + 1, y0 + 1, x1 - x0 - 1, y1 - y0 - 1, 0xffffff);
301
}
302
303
 
304
const int debugcolor[10]={0xff0000,0x00ff00,0x0000ff,0xffff00,0x00ffff,0xff00ff,0x800000,0x008000,0x000080,0x800080};
305
int debugc=0;
306
307
 
308
#define is_x_changed(v) ((v) == sel_x || (v) == prev_x)
309
#define is_y_changed(v) ((v) == sel_y || (v) == prev_y)
310
311
 
312
{
313
	int i,j;
314
	long x0 = 0, y0 = 0, x = 0, y = 0, dx, popravka;
315
	DWORD text_color;
316
	//int lx, ly;
317
318
 
319
//	rtlDebugOutString(debuf);
320
321
 
322
323
 
324
	if (sel_moved)
325
	{
326
		clear_cell_slow(sel_x, sel_y);
327
		clear_cell_slow(prev_x, prev_y);
328
	}
329
	else
330
	{
331
		// очистить всю область ячеек
332
		//kos_DrawBar(col_width[0]+1, row_height[0]+1, wi - SCROLL_BAR_WIDTH-col_width[0]-1, he - SCROLL_BAR_HEIGHT-row_height[0]-1, 0xffffff);
333
	}
334
335
 
336
	// ячейки - заголовки столбцов + вертикальные линии
337
	x = col_width[0];
338
	nx = 1;
339
	for (i = 1; i < col_count; i++)
340
	{
341
		col_left[i] = -1;
342
		if (i >= scroll_x)
343
		{
344
			{
345
				if (!sel_moved || is_x_changed(i))
346
					kos_DrawLine(x-x0, 0, x-x0, row_height[0], GRID_COLOR, 0);
347
			// и заголовок ячейки по х
348
				text_color = TEXT_COLOR;
349
				dx = (col_width[i]-6)/2;
350
				int dy = (row_height[0] - 8) / 2 + 1;
351
				int cur_width = col_width[i] - 1;
352
				if (cur_width + x - x0 > wi - SCROLL_BAR_WIDTH)
353
					cur_width = wi - SCROLL_BAR_WIDTH - x + x0;
354
				if (!sel_moved || (is_x_changed(i)))
355
					if (is_between(i,sel_x,sel_end_x))
356
					{
357
						kos_DrawBar(x - x0 + 1,0,cur_width,row_height[0],SEL_FIXED_CELL_COLOR); //0x0000CC
358
						text_color = TEXT_SEL_FIXED_COLOR;
359
					}
360
					else
361
					{
362
						kos_DrawBar(x - x0 + 1,0,cur_width,row_height[0],FIXED_CELL_COLOR);
363
						text_color = TEXT_COLOR;
364
					}
365
				if (!sel_moved || (is_x_changed(i))) kos_WriteTextToWindow(x-x0+2+dx,dy,0,text_color,cells[i][0],strlen(cells[i][0]));
366
367
 
368
				if (x - x0 + col_width[i] <= wi - col_width[0])
369
					kos_DefineButton(x-x0+5,0,cur_width - 10,row_height[0]-1,0x60000000+COL_HEAD_BUTTON+i,0);
370
				//kos_DefineButton(x-x0+col_width[i]-10,0,15,row_height[0]-1,0x60000000+COL_SIZE_BUTTON+i,0);
371
				col_left[i] = x - x0;
372
			}
373
			if (x - x0 > wi - col_width[0])
374
			{
375
				x += col_width[i];
376
				nx++;
377
				break;
378
			}
379
		}
380
		else
381
		{
382
			x0 += col_width[i];
383
		}
384
		x += col_width[i];
385
		nx++;
386
	}
387
388
 
389
390
 
391
		col_left[j] = wi;
392
	//if (!sel_moved || (is_x_changed(nx))) kos_DrawLine(x - x0, 0, x - x0, he, GRID_COLOR, 0);
393
394
 
395
	y = row_height[0];
396
	ny = 1;
397
	row_top[0] = 0;
398
	for (i = 1; i < row_count && y - y0 < he - 10; i++)
399
	{
400
		row_top[i] = -1;
401
		if (i >= scroll_y)
402
		{
403
			{
404
				if (!sel_moved || (is_y_changed(i)))
405
					kos_DrawLine(0, y - y0, wi - SCROLL_BAR_WIDTH, y - y0, GRID_COLOR, 0);
406
				// и заголовок ячейки по y
407
				text_color = TEXT_COLOR;
408
				dx = (col_width[0]-6 * strlen(cells[0][i]))/2;	// optimize this, change strlen
409
				int dy = (row_height[i] - 8) / 2 + 1;
410
				if (!sel_moved || (is_y_changed(i)))
411
					if (is_between(i,sel_y,sel_end_y))
412
					{
413
						kos_DrawBar(0,y-y0+1,col_width[0],row_height[i] - 1,SEL_FIXED_CELL_COLOR);
414
						text_color = TEXT_SEL_FIXED_COLOR;
415
					}
416
					else
417
					{
418
						kos_DrawBar(0,y-y0+1,col_width[0],row_height[i] - 1,FIXED_CELL_COLOR);
419
						text_color = TEXT_COLOR;
420
					}
421
422
 
423
					kos_WriteTextToWindow(2+dx,y-y0+dy,0,text_color,cells[0][i],strlen(cells[0][i]));
424
425
 
426
				//kos_DefineButton(0,y-y0+row_height[i]-5,col_width[0]-1,10,0x60000000+ROW_SIZE_BUTTON+i,0);
427
				row_top[i] = y - y0;
428
			}
429
		}
430
		else
431
		{
432
			y0 += row_height[i];
433
		}
434
		y += row_height[i];
435
		ny++;
436
	}
437
438
 
439
440
 
441
		row_top[j] = he;
442
	if (!sel_moved || (is_y_changed(ny)))
443
		kos_DrawLine(0, y - y0, wi - SCROLL_BAR_WIDTH, y - y0, GRID_COLOR, 0);
444
445
 
446
		kos_DrawBar(0,0,col_width[0],row_height[0],FIXED_CELL_COLOR);
447
	// ЛВ ячейка
448
449
 
450
	//rtlDebugOutString(debuf);
451
452
 
453
	//sprintf(debuf, "%U, %U", scroll_y, ny);
454
	//rtlDebugOutString(debuf);
455
456
 
457
 
458
459
 
460
	for (i = scroll_y; i < ny; i++)
461
	{
462
		x = col_width[0];
463
		if (!sel_moved)
464
			kos_DrawBar(col_width[0]+1, y+1, wi - SCROLL_BAR_WIDTH-col_width[0]-1, row_height[i]-1, 0xffffff);
465
		for (j = scroll_x; j < nx-1; j++)
466
		{
467
			if (!sel_moved || is_x_changed(j) || is_y_changed(i))
468
				kos_DrawLine(col_left[j], row_top[i], col_left[j], row_height[i], GRID_COLOR, 0);
469
470
 
471
			if (i && j)
472
			{
473
				//kos_DrawBar(x+1, y+1, col_width[i]-1, row_height[i]-1, 0xffffff);
474
475
 
476
				//if (j >= sel_x && j <= sel_end_x && i >= sel_y && i <= sel_end_y)
477
				if (is_between(j,sel_x,sel_end_x) && is_between(i, sel_y, sel_end_y)	// (j,i) - выделена
478
					&& ((!sel_moved) || (is_x_changed(j) && is_y_changed(i))))			// и ее нужно нарисовать
479
				{
480
					if (i == sel_y && j == sel_x)		// рамка
481
					{
482
						kos_DrawBar(x,y,col_width[j],2,TEXT_COLOR);	// up
483
						kos_DrawBar(x,y,2,row_height[i],TEXT_COLOR);	// left
484
						kos_DrawBar(x,y+row_height[i]-2,col_width[j]-2-3,2,TEXT_COLOR);				// bottom
485
						kos_DrawBar(x+col_width[j]-2,y, 2,row_height[i]-2-3,TEXT_COLOR);				// right
486
487
 
488
						//kos_DefineButton(x+col_width[j]-2,y+row_height[i]-2,4,4,0x60000000+DRAG_BUTTON,0x000000);
489
						drag_x = x + col_width[j] - 4;
490
						drag_y = y + row_height[i] - 4;
491
					}
492
					else
493
						kos_DrawBar(x + 1,y + 1,col_width[j] - 2,row_height[i] - 2,SEL_CELL_COLOR);	//	выделена но не основная(серая)
494
495
 
496
				//kos_DefineButton(x,y,col_width[j]-1,row_height[i]-1,0x60000000+CELL_BUTTON+((i << 8) + j),0);
497
498
 
499
				if (values[j][i] && values[j][i][0] == '#')
500
				{
501
					text = cells[j][i];
502
					kos_DrawRegion(x+1, y+1, col_width[j]-1, row_height[i]-1, 0xff0000, 0);
503
				}
504
				else
505
					text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]);
506
507
 
508
509
 
510
					if (strlen(text) < col_width[j]/6)
511
						kos_WriteTextToWindow(x+2,y+dy,0,text_color,text,strlen(text));
512
					else
513
						kos_WriteTextToWindow(x+2,y+dy,0,text_color,text,col_width[j]/6);
514
515
 
516
			if (!sel_moved || is_x_changed(j) || is_y_changed(i))
517
				kos_DrawLine(col_left[j]+col_width[j], row_top[i], col_left[j]+col_width[j], row_height[i], GRID_COLOR, 0);
518
			x += col_width[j];
519
		}
520
		y += row_height[i];
521
	}
522
523
 
524
	// horizontal
525
526
 
527
	//if (!sel_moved) kos_DrawBar(scroll_x * wi / col_count, he - SCROLL_BAR_HEIGHT, wi / col_count, SCROLL_BAR_HEIGHT, SEL_FIXED_CELL_COLOR);
528
	if (!sel_moved)
529
	{
530
		// горизонталь
531
		kos_DrawBar(17, he - SCROLL_BAR_HEIGHT, wi - SCROLL_BAR_WIDTH - 32, SCROLL_BAR_HEIGHT, 0xced0d0);
532
		// синие линии
533
		kos_DrawRegion(0, he - SCROLL_BAR_HEIGHT, wi - SCROLL_BAR_WIDTH, SCROLL_BAR_HEIGHT+1, 0x94aece, 0);
534
		// левая кнопка
535
		draw_custom_button(1, he - SCROLL_BAR_HEIGHT + 1, 14, 14, 1);
536
		kos_WriteTextToWindow(6, he - SCROLL_BAR_HEIGHT + 5, 0, 0, "\x1B", 1);
537
		// правая
538
		draw_custom_button(wi - SCROLL_BAR_WIDTH * 2 + 1, he - SCROLL_BAR_HEIGHT + 1, 14, 14, 1);
539
		kos_WriteTextToWindow(wi - SCROLL_BAR_WIDTH * 2 + 6, he - SCROLL_BAR_HEIGHT + 5, 0, 0, "\x1A", 1);
540
		// ползунок
541
		int tmp_w = (nx - scroll_x) * (wi - SCROLL_BAR_WIDTH - 2 * 14 - 14) / (col_count + 1);
542
		if (tmp_w < 16)
543
			tmp_w = 16;
544
		draw_custom_button(17 + (scroll_x - 1) * (wi - SCROLL_BAR_WIDTH - 2 * 14 - 14) / (col_count + 1), he - SCROLL_BAR_HEIGHT + 1,
545
			tmp_w, 14, 1);
546
547
 
548
// не пинайте меня за это, было лень переставлять руками...
549
550
 
551
		kos_DrawBar(sw(17, wi - SCROLL_BAR_WIDTH), sw(he - SCROLL_BAR_HEIGHT - 33, SCROLL_BAR_WIDTH), 0xced0d0);
552
		// синие линии
553
		kos_DrawRegion(sw(0, wi - SCROLL_BAR_WIDTH), sw(he - SCROLL_BAR_HEIGHT, SCROLL_BAR_WIDTH+1), 0x94aece, 0); // up
554
555
 
556
		draw_custom_button(sw(1, wi - SCROLL_BAR_WIDTH + 1), 14, 14, 1);
557
		kos_WriteTextToWindow(sw(5, wi - SCROLL_BAR_WIDTH + 6), 0, 0, "\x18", 1);
558
		// нижняя
559
		draw_custom_button(sw(he - SCROLL_BAR_HEIGHT * 2 + 1, wi - SCROLL_BAR_WIDTH + 1), 14, 14, 1);
560
		//draw_custom_button(sw(he - SCROLL_BAR_HEIGHT * 2 + 1, wi - SCROLL_BAR_WIDTH + 1), 14, 14, 1);
561
		kos_WriteTextToWindow(sw(he - SCROLL_BAR_HEIGHT * 2 + 5, wi - SCROLL_BAR_WIDTH + 6), 0, 0, "\x19", 1);
562
		// ползунок
563
		int tmp_h = (ny - scroll_y) * (he - SCROLL_BAR_HEIGHT - 2 * 14 - 14) / (row_count + 1);
564
		if (tmp_h < 16)
565
			tmp_h = 16;
566
		draw_custom_button(sw(17 + (scroll_y - 1) * (he - SCROLL_BAR_HEIGHT - 2 * 14 - 14) / (row_count + 1), wi - SCROLL_BAR_WIDTH + 1),
567
			sw(tmp_h, 14), 1);
568
	}
569
#define NO_DRAW 0x60000000
570
	kos_DefineButton(1, he - SCROLL_BAR_HEIGHT + 1, 14, 14, NO_DRAW + SCROLL_LEFT_BUTTON,0);
571
	kos_DefineButton(wi - SCROLL_BAR_WIDTH * 2 + 2, he - SCROLL_BAR_HEIGHT + 1, 14, 14, NO_DRAW + SCROLL_RIGHT_BUTTON,0);
572
	kos_DefineButton(17, he - SCROLL_BAR_HEIGHT + 1,  (wi - SCROLL_BAR_WIDTH - 2 * 14), 14, NO_DRAW + SCROLL_WIDTH,0);
573
574
 
575
	kos_DefineButton(sw(he - SCROLL_BAR_HEIGHT * 2 + 2, wi - SCROLL_BAR_WIDTH + 1), 14, 14, NO_DRAW + SCROLL_DOWN_BUTTON,0);
576
	kos_DefineButton(sw(17, wi - SCROLL_BAR_WIDTH + 1),  sw((he - SCROLL_BAR_HEIGHT - 2 * 14), 14), NO_DRAW + SCROLL_HEIGHT,0);
577
578
 
579
580
 
581
void draw_size_grid()
582
{
583
	//rtlDebugOutString("draw size grid");
584
585
 
586
587
 
588
	{
589
		int x, x0, i;
590
591
 
592
		x0 = 0;
593
		for (i = 1; i < col_count && x - x0 + col_width[i] < wi - 10; i++)
594
		{
595
			if (i >= scroll_x)
596
			{
597
				if (i >= size_id)
598
					kos_DrawLine(x - x0, 0, x - x0, he, 0, 1);
599
			}
600
			else
601
				x0 += col_width[i];
602
			x += col_width[i];
603
		}
604
		kos_DrawLine(x - x0, 0, x - x0, he, 0, 1);
605
	}
606
	else
607
	{
608
		int y, y0, i;
609
610
 
611
		y0 = 0;
612
		for (i = 1; i < col_count && y - y0 + row_height[i] < he - 10; i++)
613
		{
614
			if (i >= scroll_y)
615
			{
616
				if (i >= size_id)
617
					kos_DrawLine(0, y - y0, wi, y - y0, 0, 1);
618
			}
619
			else
620
				y0 += row_height[i];
621
			y += row_height[i];
622
		}
623
		kos_DrawLine(0, y - y0, wi, y - y0, 0, 1);
624
	}
625
626
 
627
 
628
}
629
630
 
631
 
632
#define DCOLOR 0
633
//0xff0000
634
#define DINVERT 1
635
void draw_drag()
636
{
637
	kos_WindowRedrawStatus(1);
638
639
 
640
641
 
642
	int k1 = max(sel_x, sel_end_x);
643
	int n0 = min(sel_y, sel_end_y);
644
	int n1 = max(sel_y, sel_end_y);
645
646
 
647
	DWORD x1 = col_left[k1] + col_width[k1] + 1;
648
	DWORD y0 = row_top[n0] - 1;
649
	DWORD y1 = row_top[n1] + row_height[n1] + 1;
650
	if (x0 > wi - 1) x0 = wi - 1;
651
	if (x1 > wi - 1) x1 = wi - 1;
652
	if (y0 > he - 1) y0 = he - 1;
653
	if (y1 > he - 1) y1 = he - 1;
654
655
 
656
	//rtlDebugOutString(debuf);
657
658
 
659
	kos_DrawLine(x0, y0, x1, y0, DCOLOR, DINVERT);
660
	kos_DrawLine(x1, y0, x1, y1, DCOLOR, DINVERT);
661
	kos_DrawLine(x0, y1, x1, y1, DCOLOR, DINVERT);
662
663
 
664
}
665
666
 
667
{
668
	int i;
669
	double xx0=0.0, yy0=0.0;
670
	sProcessInfo info;
671
	void *p;
672
673
 
674
		sel_moved = 0;
675
676
 
677
678
 
679
680
 
681
	wi = *(Dword *)(p);
682
	he = *(Dword *)((Byte *)p + 4);
683
	win_x = *(Dword *)((Byte *)p - 8);
684
	win_y = *(Dword *)((Byte *)p - 4);
685
686
 
687
688
 
689
		wi = WND_W;
690
	if (he == 0)
691
		he = WND_H;
692
693
 
694
	wi -= 6 + 4;
695
696
 
697
	kos_WindowRedrawStatus(1);
698
699
 
700
701
 
702
	{
703
		kos_WindowRedrawStatus(2);
704
		return;
705
	}
706
707
 
708
	{
709
		kos_DrawBar(wi-15,he - kos_GetSkinHeight() +7,16,16,0xe4dfe1);
710
		kos_DrawBar(0,he - kos_GetSkinHeight() + 23,wi + 1,MENU_PANEL_HEIGHT-4,0xe4dfe1);
711
	}
712
713
 
714
	int y = he + kos_GetSkinHeight() - 10;
715
716
 
717
	{
718
		kos_WriteTextToWindow(3 + 1, y + 3, 0x80 , 0x000000, (char*)sFilename, strlen(sFilename));
719
	}
720
721
 
722
	//kos_DrawRegion(61, y - 2, 102, 18, fn_line_color, 0);
723
724
 
725
726
 
727
	file_box.left = 64;
728
	file_box.top = y - 1;
729
	file_box.width = 98;
730
		//editbox_h = 18;
731
	//kos_DefineButton(62, y + 3, 100, 16, 0x60000000+FILENAME_BUTTON, 0xd0d0d0);
732
733
 
734
 
735
	kos_DefineButton(20 + 160, y - 5, 60, 20, SAVE_BUTTON, 0xd0d0d0);
736
	kos_WriteTextToWindow(22 + 160 + (60 - strlen(sSave) * 6) / 2, y + 2, 0, 0x000000, (char*)sSave, strlen(sSave));
737
738
 
739
	kos_DefineButton(90 + 160, y - 5, 60, 20, LOAD_BUTTON, 0xd0d0d0);
740
	kos_WriteTextToWindow(92 + 160 + (60 - strlen(sLoad) * 6) / 2, y + 2, 0, 0x000000, (char*)sLoad, strlen(sLoad));
741
742
 
743
	/*
744
	kos_DefineButton(90 + 160 + 70, y - 5, 60, 20, NEW_BUTTON, 0xd0d0d0);
745
	kos_WriteTextToWindow(92 + 160 + 10 + 70, y + 2, 0, 0x000000, (char*)sNew, strlen(sNew));
746
	*/
747
	panel_y = y;
748
749
 
750
	//kos_DefineButton(0,0,WND_W,WND_H,0x60000002,0);
751
	//if (is_edit) KEdit();
752
753
 
754
	{
755
		if (is_edit)
756
			edit_box_draw((DWORD)&cell_box);
757
		edit_box_draw((DWORD)&file_box);
758
	}
759
760
 
761
	kos_WindowRedrawStatus(2);
762
	sel_moved = 0;
763
}
764
765
 
766
 
767
{
768
	Dword mouse_btn, ckeys, shift, ctrl;
769
	int mouse_x, mouse_y, i, p, dx = 0, dy = 0;
770
	int redraw = 0;
771
772
 
773
	if (kos_GetActiveSlot() != mySlot)
774
		return;
775
776
 
777
	edit_box_mouse((dword)&file_box);
778
779
 
780
	kos_GetScrollInfo(vert, hor);
781
782
 
783
	//rtlDebugOutString(debuf);
784
785
 
786
	{
787
		move_sel(sel_x, sel_y + vert);
788
		//move_sel(sel_x + hor, sel_y);
789
		return;
790
	}
791
792
 
793
	mouse_x -= 5;
794
	mouse_y -= kos_GetSkinHeight();
1112 barsuk 795
796
 
990 barsuk 797
798
 
799
	shift = ckeys & 0x3;
800
801
 
1112 barsuk 802
	{
803
		window_is_dragged = 1;
804
		return;
805
	}
806
	if (window_is_dragged)
807
	{
808
		if (mouse_btn)
809
			return;
810
		else
811
			window_is_dragged = 0;
812
	}
813
814
 
990 barsuk 815
		return;
816
	if (mouse_btn && !size_state)		// LMB down
817
	{
818
		//rtlDebugOutString("lmb down and not resize");
819
820
 
821
		{
822
			size_state = SIZE_DRAG;
823
			old_end_x = sel_end_x;
824
			old_end_y = sel_end_y;
825
		}
826
		else if (mouse_y <= row_height[0])
827
		{
828
			//rtlDebugOutString("can resize cols");
829
			int kx = -1, i;
830
			for (i = 0; i < col_count - 1; i++)
831
			if (mouse_x >= col_left[i] + col_width[i] - 5 &&
832
				mouse_x <= col_left[i + 1] + 5)
833
			{
834
				kx = i; break;
835
			}
836
			if (kx != -1)
837
			{
838
				//sprintf(debuf,"size x %U",k);
839
				//rtlDebugOutString(debuf);
840
				size_id = kx;
841
				size_state = SIZE_X;
842
			}
843
		}
844
		else if (mouse_x <= col_width[0])
845
		{
846
			int ky = -1;
847
			for (i = 0; i < row_count - 1; i++)
848
			if (mouse_y >= row_top[i] + row_height[i] - 5 &&
849
				mouse_y <= row_top[i + 1] + 5)
850
			{
851
				ky = i; break;
852
			}
853
			if (ky != -1)
854
			{
855
				size_id = ky;
856
				size_state = SIZE_Y;
857
			}
858
		}
859
		else		// кликнута ячейка
860
		if (mouse_x <= col_left[nx - 1] &&  mouse_y <= row_top[ny - 1])
861
		{
862
			was_single_selection = sel_x == sel_end_x && sel_y == sel_end_y;
863
			int kx = -1, i;
864
			for (i = 0; i < col_count - 1; i++)
865
			if (mouse_x >= col_left[i] &&
866
				mouse_x <= col_left[i] + col_width[i])
867
			{
868
				kx = i; break;
869
			}
870
			int ky = -1;
871
			for (i = 0; i < row_count - 1; i++)
872
			if (mouse_y >= row_top[i] &&
873
				mouse_y <= row_top[i] + row_height[i])
874
			{
875
				ky = i; break;
876
			}
877
			if (kx != -1 && ky != -1)
878
			{
879
				if (!shift)
880
				{
881
					move_sel(kx, ky);
882
					//return;
1112 barsuk 883
				}
990 barsuk 884
				else
885
				{
886
					sel_end_x = kx;
1112 barsuk 887
					sel_end_y = ky;
990 barsuk 888
				}
889
				size_state = SIZE_SELECT;
890
			}
891
		}
892
		if (size_state)
893
		{
894
			size_mouse_x = mouse_x;
895
			size_mouse_y = mouse_y;
896
		}
897
		return;
898
	}
899
	else if (!mouse_btn && size_state)
900
	{
901
		sel_moved = 0;		// чтобы была тру перерисовка
902
		//rtlDebugOutString("resize end");
903
904
 
905
		{
906
			fill_cells(sel_x, sel_y, sel_end_x, sel_end_y, old_end_x, old_end_y);
907
		}
908
909
 
1112 barsuk 910
		size_state = 0;
990 barsuk 911
		draw_window();		// все сдвинулось - надо обновиться
912
		return;
913
	}
914
	if (size_state == SIZE_X && mouse_x != size_mouse_x)
915
	{
916
		draw_size_grid();
917
		col_width[size_id] += mouse_x - size_mouse_x;
918
		if (col_width[size_id] < 15)
919
			col_width[size_id] = 15;
920
		else if (col_width[size_id] > wi / 2)
921
			col_width[size_id] = wi / 2;
922
		draw_size_grid();
923
	}
924
	if (size_state == SIZE_Y && mouse_y != size_mouse_y)
925
	{
926
		draw_size_grid();
927
		row_height[size_id] += mouse_y - size_mouse_y;
928
		if (row_height[size_id] < 15)
929
			row_height[size_id] = 15;
930
		else if (row_height[size_id] > he / 2)
931
			row_height[size_id] = he / 2;
932
		draw_size_grid();
933
	}
934
	if ((size_state == SIZE_SELECT || size_state == SIZE_DRAG) && (mouse_x != size_mouse_x || mouse_y != size_mouse_y))
935
	{
936
		draw_drag();
937
		int kx = -1, i;
938
		for (i = 0; i < col_count - 1; i++)
939
			if (mouse_x >= col_left[i] &&
940
				mouse_x <= col_left[i + 1])
941
			{
942
				sprintf(debuf, "yyy %U",col_left[i+1]);
943
				rtlDebugOutString(debuf);
944
				kx = i; break;
945
			}
946
		int ky = -1;
947
		for (i = 0; i < row_count - 1; i++)
948
			if (mouse_y >= row_top[i] &&
949
				mouse_y <= row_top[i + 1])
950
			{
951
				ky = i; break;
952
			}
953
		if (kx != -1) sel_end_x = kx;
954
		if (kx != -1) sel_end_y = ky;
955
		if (size_state == SIZE_DRAG)
956
		{
957
			if (abs(sel_end_x - sel_x) > 0)
958
			{
959
				sel_end_y = old_end_y;
960
			}
961
			else if (abs(sel_end_y - sel_y) > 0)
962
			{
963
				sel_end_x = old_end_x;
964
			}
965
		}
966
		draw_drag();
967
	}
968
	size_mouse_x = mouse_x;
969
	size_mouse_y = mouse_y;
970
}
971
972
 
973
{
974
	Dword mouse_btn, ckeys, shift, ctrl;
975
	int mouse_x, mouse_y, i, p, dx = 0, dy = 0;
976
977
 
978
	Byte keyCode;
979
	ckeys = kos_GetSpecialKeyState();
980
	shift = ckeys & 0x3;
981
	ctrl = ckeys & 0x0c;
982
	//if (ctrl)
983
	//	rtlDebugOutString("control pressed!");
984
	dx = 0, dy = 0;
985
	sel_moved = 0;
986
	sel_end_move = 0;
987
	kos_GetKey(keyCode);
988
989
 
990
	{
991
		mov ah, keyCode
992
	}
993
	edit_box_key((dword)&cell_box);
994
	edit_box_key((dword)&file_box);
995
996
 
997
 
998
	{
999
		case 178:			// стрелки
1000
			//dx = 0;
1001
			dy = -1;
1002
			break;
1003
		case 176:
1004
			dx = -1;
1005
			//dy = 0;
1006
			break;
1007
		case 179:
1008
			dx = 1;
1009
			//dy = 0;
1010
			break;
1011
		case 177:
1012
			//dx = 0;
1013
			dy = 1;
1014
			break;
1015
		/*
1016
		case 183:
1017
			if (sel_y < row_count-(ny - scroll_y))	// page down
1018
				dy = ny - scroll_y;
1019
			else
1020
				dy = row_count-(ny - scroll_y) - sel_y;
1021
			dx = 0;
1022
			redraw = 1;
1023
			break;
1024
		case 184:
1025
			if (sel_y > ny - scroll_y)		// page up
1026
				dy= - (ny - scroll_y);
1027
			else
1028
				dy = - (ny - scroll_y) + sel_y;
1029
			dx = 0;
1030
			redraw = 1;
1031
			break;
1032
		*/
1033
		case 180: //home
1034
			dx = -sel_x + 1;
1035
			dy = 0;
1036
			draw_grid(); //draw_window();
1037
			break;
1038
		case 181: //end
1039
			dx = col_count - (nx - scroll_x) - 1 - sel_x;
1040
			dy = 0;
1041
			draw_grid(); //draw_window();
1042
			break;
1043
		case 27:		// escape
1044
			cancel_edit();
1045
			break;
1046
		case 182:			// delete
1047
			{
1048
				int i,j,n0,n1,k0,k1;
1049
				n0 = min(sel_x, sel_end_x);
1050
				n1 = max(sel_x, sel_end_x);
1051
				k0 = min(sel_y, sel_end_y);
1052
				k1 = max(sel_y, sel_end_y);
1053
1054
 
1055
					for (j = k0; j <= k1; j++)
1056
					{
1057
						if (cells[i][j])
1058
						{
1059
							freemem(cells[i][j]);
1060
							cells[i][j] = NULL;
1061
						}
1062
					}
1063
				calculate_values();
1064
				draw_grid();
1065
				break;
1066
			}
1067
		case 0x0D:			// enter
1068
			if (is_edit)
1069
			{
1070
				stop_edit();
1071
				draw_window();
1072
			}
1073
			break;
1074
		//case 0x08:			// backspace
1075
			/*if (is_edit || fn_edit)
1076
			{
1077
				if (strlen(edit_text) != 0)
1078
					edit_text[strlen(edit_text) - 1] = '\0';
1079
				KEdit();
1080
			}
1081
			else if (cells[sel_x][sel_y])
1082
			{
1083
				start_edit(sel_x, sel_y);
1084
			}
1085
			*/
1086
		//	break;
1087
		case 22:	// contol-v
1088
			{
1089
				if (ctrl)
1090
				{
1091
					//rtlDebugOutString("control-v!");
1092
					int i, j, x0, y0;
1093
					x0 = min(sel_x, sel_end_x);
1094
					y0 = min(sel_y, sel_end_y);
1095
					int delta_x = x0 - buf_old_x;
1096
					int delta_y = y0 - buf_old_y;
1097
1098
 
1099
						for (j = 0; j < buf_row; j++)
1100
						{
1101
							if (i + x0 >= col_count || j + y0 >= row_count)
1102
								continue;
1103
							if (cells[i + x0][j + y0])
1104
								freemem(cells[i + x0][j + y0]);
1105
							if (buffer[i][j])
1106
							{
1107
								cf_x0 = buf_old_x; cf_y0 = buf_old_y;
1108
								cf_x1 = buf_old_x + buf_col;
1109
								cf_y1 = buf_old_y + buf_row;
1110
								cells[i + x0][j + y0] = change_formula(buffer[i][j], delta_x, delta_y);
1111
								//cells[i + x0][j + y0] = (char*)allocmem(strlen(buffer[i][j]));
1112
								//strcpy(cells[i + x0][j + y0], buffer[i][j]);
1113
							}
1114
							else
1115
								cells[i + x0][j + y0] = NULL;
1116
						}
1117
1118
 
1119
					draw_window();
1120
					break;
1121
				}
1122
			}
1123
			case 24:	// control-x
1124
			case 03:	// control-c
1125
			{
1126
				if (ctrl)
1127
				{
1128
					//rtlDebugOutString("control-c!");
1129
					int i, j, x0, y0;
1130
1131
 
1132
1133
 
1134
					buf_row = abs(sel_end_y - sel_y) + 1;
1135
					x0 = min(sel_x, sel_end_x);
1136
					y0 = min(sel_y, sel_end_y);
1137
					buf_old_x = x0;
1138
					buf_old_y = y0;
1139
1140
 
1141
					//rtlDebugOutString(debuf);
1142
1143
 
1144
					for (i = 0; i < buf_col; i++)
1145
					{
1146
						buffer[i] = (char**)allocmem(buf_row * sizeof(char*));
1147
						for (j = 0; j < buf_row; j++)
1148
						{
1149
							if (cells[i + x0][j + y0])
1150
							{
1151
								if (keyCode == 03)	// ctrl-c
1152
								{
1153
									buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0]));
1154
									strcpy(buffer[i][j], cells[i + x0][j + y0]);
1155
								}
1156
								else
1157
								{
1158
									buffer[i][j] = cells[i + x0][j + y0];
1159
									cells[i + x0][j + y0] = NULL;
1160
								}
1161
							}
1162
							else
1163
								buffer[i][j] = NULL;
1164
						}
1165
					}
1166
					if (keyCode == 24)
1167
						calculate_values();
1168
					draw_window();
1169
					break;
1170
				}
1171
			}
1172
		case 06:		// control-f
1173
			{
1174
				display_formulas = !display_formulas;
1175
				draw_grid(); //draw_window();
1176
				break;
1177
			}
1178
		default:
1179
1180
 
1181
			{
1182
				start_edit(sel_x, sel_y);
1183
				if (keyCode == 8)
1184
				{
1185
					cell_box.pos = strlen(edit_text);
1186
				}
1187
				else
1188
				{
1189
					__asm
1190
					{
1191
						mov ah, keyCode
1192
					}
1193
					edit_box_key((dword)&cell_box);
1194
				}
1195
			}
1196
			if (is_edit)
1197
				edit_box_draw((dword)&cell_box);
1198
			/*
1199
			if (strlen(edit_text)<256)
1200
			{
1201
				edit_text[strlen(edit_text)]=keyCode;
1202
				edit_text[strlen(edit_text) + 1]='\0';
1203
				KEdit();
1204
			}
1205
			*/
1206
			break;
1207
	}
1208
	if (dx != 0)
1209
	{
1210
		if (shift)
1211
		{
1212
			sel_end_x += dx;
1213
			if (sel_end_x <= 1)
1214
				sel_end_x = 1;
1215
			else if (sel_end_x >= col_count)
1216
				sel_end_x = col_count - 1;
1217
		//	sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y);
1218
		//	rtlDebugOutString(debuf);
1219
			sel_moved = sel_end_move = 1;
1220
			//stop_edit();
1221
			//draw_grid();
1222
		}
1223
		else
1224
		{
1225
		}
1226
	}
1227
	if (dy != 0)
1228
	{
1229
		if (shift)
1230
		{
1231
			sel_end_y += dy;
1232
			if (sel_end_y <= 1)
1233
				sel_end_y = 1;
1234
			else if (sel_end_y >= row_count)
1235
				sel_end_y = row_count - 1;
1236
		//	sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y);
1237
		//	rtlDebugOutString(debuf);
1238
			sel_moved = sel_end_move = 1;
1239
			//stop_edit();
1240
			//draw_grid();
1241
		}
1242
	}
1243
	/*
1244
	if (sel_end_x < sel_x)
1245
	{
1246
		Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp;
1247
	}
1248
	if (sel_end_y < sel_y)
1249
	{
1250
		Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp;
1251
	}
1252
	*/
1253
	if ((dx || dy))
1254
	{
1255
		if (!shift)
1256
		{
1257
			move_sel(sel_x + dx, sel_y + dy);
1258
		}
1259
		else
1260
		{
1261
			sel_moved = 0;
1262
			stop_edit();
1263
			draw_grid();
1264
		}
1265
	}
1266
}
1267
1268
 
1269
 
1270
{
1271
	Dword mouse_btn, ckeys, shift, ctrl;
1272
	int mouse_x, mouse_y, i, p, dx = 0, dy = 0;
1273
	int redraw = 0;
1274
1275
 
1276
	kos_GetButtonID(button);
1277
1278
 
1279
	sprintf(debuf, "button %U", button);
1280
	rtlDebugOutString(debuf);
1281
	//*/
1282
1283
 
1284
	{
1285
	case 1:
1286
		kos_ExitApp();
1287
1288
 
1289
		//rtlDebugOutString("scroll left btn");
1290
		stop_edit();
1291
		scroll_x--;
1292
		if (scroll_x <= 0)
1293
			scroll_x = 1;
1294
		sel_moved = 0;
1295
		/*if (sel_x > nx - 1)
1296
		{
1297
			nx - 1;
1298
			sel_end_x = sel_x;
1299
		}*/
1300
		draw_window();
1301
		return;
1302
1303
 
1304
		//rtlDebugOutString("scroll right btn");
1305
		stop_edit();
1306
		scroll_x++;
1307
		if (scroll_x >= col_count - 1)
1308
			scroll_x = col_count - 1;
1309
		sel_moved = 0;/*
1310
		if (sel_x < scroll_x)
1311
		{
1312
			sel_x = scroll_x;
1313
			sel_end_x = sel_x;
1314
		}*/
1315
		draw_window();
1316
		return;
1317
1318
 
1319
		{
1320
			//rtlDebugOutString("scroll width btn");
1321
			stop_edit();
1322
			kos_GetMouseState(mouse_btn, mouse_x, mouse_y);
1323
			mouse_x -= 5;
1324
			mouse_y -= kos_GetSkinHeight();
1325
1326
 
1327
1328
 
1329
			if (tmp_w < 16)
1330
				tmp_w = 16;
1331
			scroll_x = (mouse_x - 14 - tmp_w / 2) * (col_count + 1) / (wi - SCROLL_BAR_WIDTH - 3 * 14) + 1;
1332
			if (scroll_x <= 0)
1333
				scroll_x = 1;
1334
			else if (scroll_x >= col_count - 1)
1335
				scroll_x = col_count - 1;
1336
			sel_moved = 0;
1337
			draw_window();
1338
			return;
1339
		}
1340
1341
 
1342
		stop_edit();
1343
		scroll_y--;
1344
		if (scroll_y <= 0)
1345
			scroll_y = 1;
1346
		sel_moved = 0;
1347
		//draw_window();
1348
		draw_grid();
1349
		/*
1350
		if (sel_y > ny - 1)
1351
		{
1352
			sel_y = ny - 1;
1353
			sel_end_y = sel_y;
1354
		}*/
1355
		return;
1356
1357
 
1358
		stop_edit();
1359
		scroll_y++;
1360
		if (scroll_y >= row_count - 1)
1361
			scroll_y = row_count - 1;
1362
		sel_moved = 0;/*
1363
		if (sel_y < scroll_y)
1364
		{
1365
			sel_y = scroll_y;
1366
			sel_end_y = sel_y;
1367
		}*/
1368
		draw_grid();
1369
		return;
1370
1371
 
1372
		{
1373
			stop_edit();
1374
			kos_GetMouseState(mouse_btn, mouse_x, mouse_y);
1375
			mouse_x -= 5;
1376
			mouse_y -= kos_GetSkinHeight();
1377
			int tmp_h = (ny - scroll_y) * (he - SCROLL_BAR_HEIGHT - 2 * 14) / row_count;
1378
			if (tmp_h < 16)
1379
				tmp_h = 16;
1380
			scroll_y = (mouse_y - 2 * 14) * (row_count + 1) / (he - SCROLL_BAR_HEIGHT - 3 * 14) + 1;
1381
			if (scroll_y <= 0)
1382
				scroll_y = 1;
1383
			else if (scroll_y >= row_count - 1)
1384
				scroll_y = row_count - 1;
1385
			sel_moved = 0;
1386
			draw_grid();
1387
			return;
1388
		}
1389
1390
 
1391
		reinit();
1392
		draw_window();
1393
		break;
1394
1395
 
1396
		sel_moved = 1;
1397
		stop_edit();
1398
		fn_edit = 1;
1399
		strcpy(edit_text, fname);
1400
		draw_window();
1401
		break;
1402
1403
 
1404
		stop_edit();
1405
		kos_DrawBar(320, panel_y, wi - 320 - 10, 10, 0xe4dfe1);
1406
		if (SaveFile(fname))
1407
			kos_WriteTextToWindow(320, panel_y, 0, 0x000000, (char*)msg_save, strlen(msg_save));
1408
		break;
1409
1410
 
1411
		stop_edit();
1412
		int r = LoadFile(fname);
1413
		kos_DrawBar(320, panel_y, wi - 320 - 10, 10, 0xe4dfe1);
1414
		if (r > 0)
1415
		{
1416
			calculate_values();
1417
			sel_moved = 0;
1418
			draw_window();
1419
			kos_WriteTextToWindow(320, panel_y,0,0x000000,(char*)msg_load, strlen(msg_load));
1420
		}
1421
		else if (r == -1)
1422
			kos_WriteTextToWindow(320, panel_y,0,0x000000,(char*)er_file_not_found,strlen(er_file_not_found));
1423
		else if (r == -2)
1424
			kos_WriteTextToWindow(320, panel_y,0,0x000000,(char*)er_format,strlen(er_format));
1425
		break;
1426
	}
1427
	if (button >= COL_HEAD_BUTTON && button < ROW_HEAD_BUTTON)
1428
	{
1429
		sel_end_x = sel_x = button - COL_HEAD_BUTTON;
1430
		sel_y = 1;
1431
		sel_end_y = row_count - 1;
1432
		stop_edit();
1433
		draw_window();
1434
		return;
1435
	}
1436
	else if (button >= ROW_HEAD_BUTTON && button < CELL_BUTTON)
1437
	{
1438
		sel_end_y = sel_y = button - ROW_HEAD_BUTTON;
1439
		sel_x = 1;
1440
		sel_end_x = col_count - 1;
1441
		stop_edit();
1442
		draw_window();
1443
		return;
1444
	}
1445
1446
 
1447
1448
 
1449
{
1450
	kos_InitHeap();
1451
	load_edit_box();
1452
1453
 
1454
	draw_window();
1455
	for (;;)
1456
	{
1457
		switch (kos_WaitForEvent(10))	// да, плохо. потом нужно будет просто ловить события мыши.
1458
		{
1459
		case 0:
1460
			process_mouse();
1461
			break;
1462
		case 1:
1463
			draw_window();
1464
			break;
1465
		case 2:
1466
			process_key();
1467
			break;
1468
		case 3:
1469
			process_button();
1470
			break;
1471
		//case 6:
1472
		//	draw_window();
1473
		//	break;
1474
		}
1475
	}
1476
}
1477
>
1478