Subversion Repositories Kolibri OS

Rev

Rev 7504 | Rev 7516 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7504 Rev 7507
Line 4... Line 4...
4
#include "func.h"
4
#include "func.h"
5
#include "parser.h"
5
#include "parser.h"
6
#include "calc.h"
6
#include "calc.h"
7
#include "use_library.h"
7
#include "use_library.h"
Line 8... Line 8...
8
 
8
 
Line 9... Line 9...
9
#define TABLE_VERSION "0.98.9"
9
#define TABLE_VERSION "0.99"
10
 
10
 
11
// strings
11
// strings
12
const char *sFileSign = "KolibriTable File\n";
12
const char *sFileSign = "KolibriTable File\n";
Line 59... Line 59...
59
#define SCROLL_SIZE 16
59
#define SCROLL_SIZE 16
60
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};
60
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};
61
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};
61
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};
Line 62... Line 62...
62
 
62
 
63
// ячейки - их параметры и текст
63
// ячейки - их параметры и текст
64
DWORD col_count = 101, row_count = 101;
64
DWORD col_count = 100, row_count = 100;
65
DWORD *cell_w, *cell_h;
65
DWORD *cell_w, *cell_h;
Line 66... Line 66...
66
char ***cells;
66
char ***cells;
67
 
67
 
Line 99... Line 99...
99
bool sel_end_move = 0;
99
bool sel_end_move = 0;
100
// сколько ячеек помещается в окне по х и у
100
// сколько ячеек помещается в окне по х и у
101
DWORD nx = 0, ny = 0;
101
DWORD nx = 0, ny = 0;
Line 102... Line 102...
102
 
102
 
103
// флаг реадктирования ячейки
-
 
104
//bool is_edit = 0;
-
 
105
#define ed_focus 2
103
// флаг реадктирования ячейки
Line 106... Line 104...
106
#define is_edit (cell_box.flags & ed_focus)
104
#define is_edit (cell_box.flags & ed_focus)
107
 
105
 
108
// редактирование имени файла
106
// редактирование имени файла
Line 119... Line 117...
119
 
117
 
120
// растаскивание ячейки при ее тащении за правый нижний угол, с заполнением ячеек
118
// растаскивание ячейки при ее тащении за правый нижний угол, с заполнением ячеек
121
int drag_x, drag_y;
119
int drag_x, drag_y;
Line 122... Line -...
122
int old_end_x, old_end_y;
-
 
123
 
120
int old_end_x, old_end_y;
Line 124... Line 121...
124
void draw_window();
121
 
125
void draw_grid();
122
void draw_grid();
126
 
123
 
Line 171... Line 168...
171
		ch = 1;
168
		ch = 1;
172
	}
169
	}
173
	if (ch)
170
	if (ch)
174
	{
171
	{
175
		sel_moved = 1;
172
		sel_moved = 1;
176
		draw_window();
173
		draw_grid();
177
	}
174
	}
Line 178... Line 175...
178
 
175
 
Line 179... Line 176...
179
	file_box.flags &= ~ed_focus;
176
	file_box.flags &= ~ed_focus;
180
 
177
 
181
	cell_box.flags |= ed_focus;
178
	cell_box.flags = ed_focus;
182
	cell_box.left = cell_x[x] + 1;
179
	cell_box.left = cell_x[x] + 1;
183
	cell_box.top = cell_y[y];
180
	cell_box.top = cell_y[y];
184
	cell_box.width = cell_w[x] - 2;
181
	cell_box.width = cell_w[x] - 2;
185
	memset((Byte*)edit_text, 0, sizeof(edit_text));
182
	memset((Byte*)edit_text, 0, sizeof(edit_text));
186
	if (cells[x][y])
183
	if (cells[x][y])
187
	{
-
 
188
		strcpy(edit_text, cells[x][y]);
184
	{
-
 
185
		strcpy(edit_text, cells[x][y]);
189
		edit_text[strlen(cells[x][y]) - 1] = '\0';
186
	}
190
	}
-
 
Line -... Line 187...
-
 
187
	cell_box.offset = cell_box.shift = cell_box.shift_old = 0;
191
	cell_box.pos = cell_box.size = strlen(edit_text);
188
	cell_box.pos = cell_box.size = strlen(edit_text);
192
	cell_box.offset = 0;
189
 
Line 193... Line 190...
193
 
190
	edit_box_draw((DWORD)&cell_box);
194
	draw_window();
191
	edit_box_draw((DWORD)&file_box);
195
}
192
}
Line 217... Line 214...
217
{
214
{
218
	if (!is_edit)
215
	if (!is_edit)
219
		return;
216
		return;
220
	cell_box.flags &= ~ed_focus;
217
	cell_box.flags &= ~ed_focus;
221
	memset((Byte*)edit_text,0, 256);
218
	memset((Byte*)edit_text,0, 256);
222
	draw_window();
219
	draw_grid();
223
}
220
}
Line 224... Line 221...
224
 
221
 
225
void check_sel()
222
void check_sel()
226
{
223
{
Line 432... Line 429...
432
				else {
429
				else {
433
					text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]);
430
					text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]);
434
				}
431
				}
Line 435... Line 432...
435
 
432
 
436
				DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false);
433
				DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false);
437
				if (draw_frame_selection) {
434
				if (draw_frame_selection && j
438
					DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i], TEXT_COLOR);
435
					DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i]+1, TEXT_COLOR);
439
				}
436
				}
440
				else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0);
437
				else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0);
441
			}
438
			}
442
			x += cell_w[j];
439
			x += cell_w[j];
Line 521... Line 518...
521
	kos_DrawLine(x0, y0, x1, y0, DCOLOR, DINVERT);
518
	kos_DrawLine(x0, y0, x1, y0, DCOLOR, DINVERT);
522
	kos_DrawLine(x1, y0, x1, y1, DCOLOR, DINVERT);
519
	kos_DrawLine(x1, y0, x1, y1, DCOLOR, DINVERT);
523
	kos_DrawLine(x0, y1, x1, y1, DCOLOR, DINVERT);
520
	kos_DrawLine(x0, y1, x1, y1, DCOLOR, DINVERT);
524
}
521
}
Line 525... Line 522...
525
 
522
 
526
bool draw_and_define_window()
523
void draw_window()
527
{
524
{
528
	kos_WindowRedrawStatus(1);
525
	kos_WindowRedrawStatus(1);
529
	kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION);
526
	kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION);
Line 539... Line 536...
539
	grid.x = 0;
536
	grid.x = 0;
540
	grid.y = 0;
537
	grid.y = 0;
541
	grid.w = cWidth - SCROLL_SIZE - 1;
538
	grid.w = cWidth - SCROLL_SIZE - 1;
542
	grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE;
539
	grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE;
Line 543... Line 540...
543
 
540
 
Line 544... Line 541...
544
	if (info.processInfo.status_window&0x04) return false; //draw nothing if window is rolled-up
541
	if (info.processInfo.status_window&0x04) return; //draw nothing if window is rolled-up
545
 
542
 
Line 546... Line 543...
546
	if (cWidth < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return false; }
543
	if (cWidth  < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return; }
-
 
544
	if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return; }
Line 547... Line -...
547
	if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return false; }
-
 
548
 
-
 
549
	sel_moved = 0;
-
 
550
 
-
 
551
	return true;
-
 
552
}
545
 
553
 
-
 
554
void draw_window()
546
	sel_moved = 0;
555
{
547
	if (is_edit) stop_edit();
556
	int panel_y = cHeight - MENU_PANEL_HEIGHT + 1;
-
 
557
 
548
 
558
	kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, sc.work);
-
 
559
	kos_WriteTextToWindow(3 + 1, panel_y + 14, 0x90, sc.work_text, (char*)sFilename, 0);	
549
	int panel_y = cHeight - MENU_PANEL_HEIGHT + 1;
560
 
550
	kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, sc.work);
561
	file_box.top = panel_y + 10;
551
	kos_WriteTextToWindow(3 + 1, panel_y + 14, 0x90, sc.work_text, (char*)sFilename, 0);	
562
 
552
	file_box.top = panel_y + 10;
563
	#define BTX 230
553
	#define BTX 230
564
	#define BTW 70
-
 
565
	//save
554
	#define BTW 70
566
	kos_DefineButton(BTX + 25, file_box.top, BTW, 21, SAVE_BUTTON, sc.work);
555
	//save
567
	kos_WriteTextToWindow(BTX + 25 + (BTW - strlen(sSave) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sSave, 0);
556
	kos_DefineButton(BTX + 25, file_box.top, BTW, 21, SAVE_BUTTON, sc.work);
568
 
-
 
569
	//load
557
	kos_WriteTextToWindow(BTX + 25 + (BTW - strlen(sSave) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sSave, 0);
570
	kos_DefineButton(BTX + 25+BTW+5, file_box.top, BTW, 21, LOAD_BUTTON, sc.work);
-
 
571
	kos_WriteTextToWindow(BTX + 25+BTW+5 + (BTW - strlen(sLoad) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sLoad, 0);
558
	//load
572
 
559
	kos_DefineButton(BTX + 25+BTW+5, file_box.top, BTW, 21, LOAD_BUTTON, sc.work);
573
	//new (clean)
-
 
574
	/*
-
 
575
	kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, sc.work);
-
 
576
	kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, sc.work_text, (char*)sNew, strlen(sNew));
-
 
577
	*/
-
 
578
 
-
 
579
	if ((void*)edit_box_draw != NULL)
-
 
580
	{
-
 
Line 581... Line 560...
581
		if (is_edit)
560
	kos_WriteTextToWindow(BTX + 25+BTW+5 + (BTW - strlen(sLoad) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sLoad, 0);
582
			edit_box_draw((DWORD)&cell_box);
561
	// // new (clean)
583
		edit_box_draw((DWORD)&file_box);
562
	// kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, sc.work);
-
 
563
	// kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, sc.work_text, (char*)sNew, strlen(sNew));
-
 
564
 
-
 
565
	if (sel_end_move) sel_moved = 0;
584
	}
566
	draw_grid();
Line 585... Line 567...
585
 
567
	sel_moved = 0;
586
	if (sel_end_move) sel_moved = 0;
568
 
587
	draw_grid();
569
	if (is_edit) edit_box_draw((DWORD)&cell_box);
Line 607... Line 589...
607
	if (!sel_moved && !size_state) //do not handle scrollbars when user selects cells
589
	if (!sel_moved && !size_state) //do not handle scrollbars when user selects cells
608
	{
590
	{
609
		if (!scroll_h.delta2) scrollbar_v_mouse((DWORD)&scroll_v);
591
		if (!scroll_h.delta2) scrollbar_v_mouse((DWORD)&scroll_v);
610
		if (scroll_v.position != grid.firsty-1)
592
		if (scroll_v.position != grid.firsty-1)
611
		{
593
		{
-
 
594
			stop_edit();
612
			grid.firsty = scroll_v.position + 1;
595
			grid.firsty = scroll_v.position + 1;
613
			draw_grid();
596
			draw_grid();
614
		}
597
		}
Line 615... Line 598...
615
 
598
 
616
		if (!scroll_v.delta2) scrollbar_h_mouse((DWORD)&scroll_h);
599
		if (!scroll_v.delta2) scrollbar_h_mouse((DWORD)&scroll_h);
617
		if (scroll_h.position != grid.firstx-1)
600
		if (scroll_h.position != grid.firstx-1)
-
 
601
		{
618
		{
602
			stop_edit();
619
			grid.firstx = scroll_h.position + 1;
603
			grid.firstx = scroll_h.position + 1;
620
			draw_grid();
604
			draw_grid();
621
		}
605
		}
622
	}
606
	}
Line 623... Line 607...
623
	if (scroll_v.delta2 || scroll_h.delta2) return;
607
	if (scroll_v.delta2 || scroll_h.delta2) return;
624
 
608
 
Line 625... Line 609...
625
	edit_box_mouse((dword)&cell_box);
609
	if (is_edit) edit_box_mouse((dword)&cell_box);
626
	edit_box_mouse((dword)&file_box);
610
	edit_box_mouse((dword)&file_box);
627
 
611
 
628
	int mouse_x, mouse_y, i;
612
	int mouse_x, mouse_y, i;
Line -... Line 613...
-
 
613
	kos_GetMouseState(mouse_btn, mouse_x, mouse_y);
-
 
614
	mouse_x -= 5;
-
 
615
	mouse_y -= kos_GetSkinHeight();
629
	kos_GetMouseState(mouse_btn, mouse_x, mouse_y);
616
 
Line 630... Line 617...
630
	mouse_x -= 5;
617
	if (is_edit && mouse_x>=cell_box.left && mouse_x<=cell_box.left+cell_box.width 
631
	mouse_y -= kos_GetSkinHeight();
618
		&& mouse_y>=cell_box.top && mouse_y<=cell_box.top+22) return;
632
 
619
 
Line 797... Line 784...
797
	}         
784
	}         
798
	size_mouse_x = mouse_x;
785
	size_mouse_x = mouse_x;
799
	size_mouse_y = mouse_y; 
786
	size_mouse_y = mouse_y; 
800
}
787
}
Line -... Line 788...
-
 
788
 
-
 
789
 
-
 
790
void shift_selection(int dx, int dy, Dword shift) 
-
 
791
{
-
 
792
	if (dx != 0)
-
 
793
	{
-
 
794
		if (shift)
-
 
795
		{
-
 
796
			sel_end_x += dx;
-
 
797
			if (sel_end_x <= 1)
-
 
798
				sel_end_x = 1;
-
 
799
			else if (sel_end_x >= col_count)
-
 
800
				sel_end_x = col_count - 1;
-
 
801
		//	sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y);
-
 
802
		//	rtlDebugOutString(debuf);
-
 
803
			sel_moved = sel_end_move = 1;
-
 
804
			//stop_edit();
-
 
805
			//draw_grid();
-
 
806
		}
-
 
807
		else
-
 
808
		{
-
 
809
		}
-
 
810
	}
-
 
811
	if (dy != 0)
-
 
812
	{
-
 
813
		if (shift)
-
 
814
		{
-
 
815
			sel_end_y += dy;
-
 
816
			if (sel_end_y <= 1)
-
 
817
				sel_end_y = 1;
-
 
818
			else if (sel_end_y >= row_count)
-
 
819
				sel_end_y = row_count - 1;
-
 
820
		//	sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y);
-
 
821
		//	rtlDebugOutString(debuf);
-
 
822
			sel_moved = sel_end_move = 1;
-
 
823
			//stop_edit();
-
 
824
			//draw_grid();
-
 
825
		}
-
 
826
	}
-
 
827
	/*
-
 
828
	if (sel_end_x < sel_x)
-
 
829
	{
-
 
830
		Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp;
-
 
831
	}
-
 
832
	if (sel_end_y < sel_y)
-
 
833
	{
-
 
834
		Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp;
-
 
835
	}
-
 
836
	*/
-
 
837
	if ((dx || dy))
-
 
838
	{
-
 
839
		if (!shift)
-
 
840
		{
-
 
841
			if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //stub
-
 
842
			else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;}
-
 
843
			else {
-
 
844
			move_selection(sel_x + dx, sel_y + dy);
-
 
845
			}
-
 
846
		}
-
 
847
		else
-
 
848
		{
-
 
849
			sel_moved = 0;
-
 
850
			stop_edit();
-
 
851
			draw_grid();
-
 
852
		}
-
 
853
	}
-
 
854
}
-
 
855
 
801
 
856
 
802
void process_key()
857
void process_key()
803
{
858
{
-
 
859
	Dword ckeys, shift, ctrl;
804
	Dword mouse_btn, ckeys, shift, ctrl;
860
	dword key_editbox;
Line 805... Line 861...
805
	int mouse_x, mouse_y, dx = 0, dy = 0;
861
	Byte key_ascii, key_scancode;
806
 
-
 
807
	// key pressed, read it 
862
 
808
	Byte keyCode;
863
	// key pressed, read it 
809
	ckeys = kos_GetSpecialKeyState();
864
	ckeys = kos_GetSpecialKeyState();
810
	shift = ckeys & 0x3;
865
	shift = ckeys & 0x3;
811
	ctrl = ckeys & 0x0c;
866
	ctrl = ckeys & 0x0c;
812
	sel_moved = 0;
-
 
Line 813... Line -...
813
	sel_end_move = 0;
-
 
814
	kos_GetKey(keyCode);
-
 
815
 
-
 
816
	__asm
-
 
817
	{
867
	sel_moved = 0;
818
		mov ah, keyCode
-
 
Line 819... Line -...
819
	}
-
 
820
	edit_box_key((dword)&cell_box);
-
 
821
	edit_box_key((dword)&file_box);
-
 
822
 
-
 
823
 
-
 
824
	switch (keyCode)
-
 
825
	{
-
 
826
		case 178:
-
 
827
			dy = -1;
-
 
828
			break;
-
 
829
		case 176:
-
 
830
			dx = -1;
-
 
831
			break;
-
 
832
		case 179:
-
 
833
			dx = 1;
-
 
834
			break;
-
 
835
		case 177:
868
	sel_end_move = 0;
836
			dy = 1;
-
 
837
			break;
-
 
838
		case 183:
869
	
839
			dy = ny - grid.firsty-1;
-
 
840
			break;
-
 
841
		case 184:
-
 
842
			dy = - (ny - grid.firsty);
-
 
843
			break;
870
	kos_GetKeys(key_editbox, key_ascii, key_scancode);
844
		case 180: //home
-
 
845
			dx = -sel_x + 1;
-
 
846
			dy = 0;
-
 
847
			draw_grid();
-
 
848
			break;
871
 
849
		case 181: //end
872
	if (cell_box.flags & ed_focus) {
850
			dx = col_count - (nx - grid.firstx) - 1 - sel_x;
873
		if (SCAN_CODE_ENTER == key_scancode) {
851
			dy = 0;
874
			stop_edit();
852
			draw_grid();
-
 
853
			break;
-
 
854
		case 27:		// escape
875
			draw_grid();
855
			cancel_edit();
-
 
856
			break;
-
 
857
		case 182:		// delete
-
 
858
			{
-
 
859
				int i,j,n0,n1,k0,k1;
-
 
860
				n0 = min(sel_x, sel_end_x);
-
 
861
				n1 = max(sel_x, sel_end_x);
-
 
862
				k0 = min(sel_y, sel_end_y);
-
 
863
				k1 = max(sel_y, sel_end_y);
876
		}
864
 
877
		else if (SCAN_CODE_ESC == key_scancode) {
865
				for (i = n0; i <= n1; i++)
878
			cancel_edit();
866
					for (j = k0; j <= k1; j++)
879
		}
867
					{
-
 
868
						if (cells[i][j])
880
		else {
-
 
881
			__asm
869
						{
882
			{
870
							freemem(cells[i][j]);
-
 
871
							cells[i][j] = NULL;
-
 
872
						}
-
 
873
					}
883
				mov eax, key_editbox
874
				calculate_values();
884
			}
875
				draw_grid();
885
			edit_box_key((dword)&cell_box);			
876
				break;
886
		}
877
			}
887
	}
878
		case 0x0D:		// enter
-
 
879
			if (is_edit)
888
	else if (file_box.flags & ed_focus) {
-
 
889
		__asm
880
			{
890
		{
-
 
891
			mov eax, key_editbox
-
 
892
		}
881
				stop_edit();
893
		edit_box_key((dword)&file_box);
882
				draw_grid();
894
		return;
883
			}
895
	}
884
			break;
896
	else if (ctrl) {
885
		case 22:	// contol-v
897
		switch (key_scancode)
886
			{
898
		{
887
				if (ctrl)
899
			case SCAN_CODE_KEY_V:
888
				{
900
				{
Line 914... Line 926...
914
 
926
 
915
					calculate_values();
927
					calculate_values();
916
					draw_grid();
928
					draw_grid();
917
					break;
929
					break;
918
				}
-
 
919
			}
930
				}
920
			case 24:	// control-x
931
				case SCAN_CODE_KEY_X:
921
			case 03:	// control-c
932
				case SCAN_CODE_KEY_C:
922
			{
-
 
923
				if (ctrl)
-
 
924
				{
-
 
925
					//rtlDebugOutString("control-c!");
933
				{
Line 926... Line 934...
926
					int i, j, x0, y0;
934
					int i, j, x0, y0;
Line 927... Line 935...
927
 
935
 
Line 943... Line 951...
943
						buffer[i] = (char**)allocmem(buf_row * sizeof(char*));
951
						buffer[i] = (char**)allocmem(buf_row * sizeof(char*));
944
						for (j = 0; j < buf_row; j++)
952
						for (j = 0; j < buf_row; j++)
945
						{
953
						{
946
							if (cells[i + x0][j + y0])
954
							if (cells[i + x0][j + y0])
947
							{
955
							{
948
								if (keyCode == 03)	// ctrl-c
956
								if (SCAN_CODE_KEY_C == key_scancode)
949
								{
957
								{
950
									buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0]));
958
									buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0]));
951
									strcpy(buffer[i][j], cells[i + x0][j + y0]);
959
									strcpy(buffer[i][j], cells[i + x0][j + y0]);
952
								}
960
								}
953
								else
961
								else
Line 958... Line 966...
958
							}
966
							}
959
							else
967
							else
960
								buffer[i][j] = NULL;
968
								buffer[i][j] = NULL;
961
						}
969
						}
962
					}
970
					}
963
					if (keyCode == 24) 
971
					if (key_ascii == 24)     ///////WTF???? 
964
						calculate_values();
972
						calculate_values();
965
					draw_grid();
973
					draw_grid();
966
					break;
974
					break;
967
				}
975
				}
968
			}
-
 
969
		case 06:		// control-f
976
			case SCAN_CODE_KEY_F:
970
			{
-
 
971
				display_formulas = !display_formulas;
977
				display_formulas = !display_formulas;
972
				draw_grid();
978
				draw_grid();
973
				break;
979
				break;
974
			}
980
		}
975
		default:		
-
 
976
			if (!is_edit && !(file_box.flags & ed_focus))
-
 
977
			{
-
 
978
				start_edit(sel_x, sel_y);
-
 
979
				if (keyCode == 8)
-
 
980
				{
-
 
981
					cell_box.pos = strlen(edit_text);
-
 
982
				}
981
	}
983
				else
-
 
984
				{
-
 
985
					__asm
982
	else switch (key_scancode)
986
					{
983
	{
987
						mov ah, keyCode
-
 
988
					}
-
 
989
					edit_box_key((dword)&cell_box);
-
 
990
				}
-
 
991
			}
-
 
992
			if (is_edit)
984
		case SCAN_CODE_UP:
993
				edit_box_draw((dword)&cell_box);
985
			shift_selection(0, -1, shift);
994
			break;
986
			break;
995
	}
-
 
996
	if (dx != 0)
987
		case SCAN_CODE_LEFT:
997
	{
-
 
998
		if (shift)
988
			shift_selection(-1, 0, shift);
999
		{
989
			break;
1000
			sel_end_x += dx;
990
		case SCAN_CODE_RIGHT:
1001
			if (sel_end_x <= 1)
991
			shift_selection(1, 0, shift);
1002
				sel_end_x = 1;
992
			break;
1003
			else if (sel_end_x >= col_count)
993
		case SCAN_CODE_DOWN:
1004
				sel_end_x = col_count - 1;
994
			shift_selection(0, 1, shift);
1005
		//	sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y);
995
			break;
1006
		//	rtlDebugOutString(debuf);
996
		case SCAN_CODE_PGDN:
1007
			sel_moved = sel_end_move = 1;
997
			shift_selection(0, ny-grid.firsty-1, shift);
1008
			//stop_edit();
998
			break;
1009
			//draw_grid();
999
		case SCAN_CODE_PGUP:
-
 
1000
			shift_selection(0, -(ny-grid.firsty), shift);
1010
		}
1001
			break;
1011
		else
1002
		case SCAN_CODE_HOME:
1012
		{
-
 
-
 
1003
			shift_selection(-sel_x + 1, 0, shift);
1013
		}
1004
			break;
1014
	}
-
 
1015
	if (dy != 0)
1005
		case SCAN_CODE_END:
-
 
1006
			shift_selection(col_count - (nx - grid.firstx) - 1 - sel_x, 0, shift);
1016
	{
1007
			break;
1017
		if (shift)
1008
		case SCAN_CODE_DEL:
1018
		{
1009
			{
1019
			sel_end_y += dy;
-
 
1020
			if (sel_end_y <= 1)
1010
				int n0 = min(sel_x, sel_end_x);
1021
				sel_end_y = 1;
-
 
1022
			else if (sel_end_y >= row_count)
1011
				int n1 = max(sel_x, sel_end_x);
1023
				sel_end_y = row_count - 1;
1012
				int k0 = min(sel_y, sel_end_y);
1024
		//	sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y);
-
 
1025
		//	rtlDebugOutString(debuf);
-
 
1026
			sel_moved = sel_end_move = 1;
1013
				int k1 = max(sel_y, sel_end_y);
1027
			//stop_edit();
-
 
1028
			//draw_grid();
-
 
1029
		}
-
 
1030
	}
1014
 
1031
	/*
-
 
1032
	if (sel_end_x < sel_x)
1015
				for (int i = n0; i <= n1; i++)
-
 
1016
					for (int j = k0; j <= k1; j++)
1033
	{
1017
					{
1034
		Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp;
-
 
1035
	}
-
 
1036
	if (sel_end_y < sel_y)
1018
						if (cells[i][j])
1037
	{
1019
						{
1038
		Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp;
1020
							freemem(cells[i][j]);
-
 
1021
							cells[i][j] = NULL;
1039
	}
1022
						}
1040
	*/
-
 
1041
	if ((dx || dy))
-
 
1042
	{
-
 
1043
		if (!shift)
-
 
1044
		{
-
 
1045
			if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //stub
-
 
1046
			else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;}
-
 
1047
			else {
-
 
1048
			move_selection(sel_x + dx, sel_y + dy);
-
 
1049
			}
1023
					}
-
 
1024
				calculate_values();
-
 
1025
				draw_grid();
-
 
1026
				break;
1050
		}
1027
			}
1051
		else
1028
			break;
1052
		{
1029
		case SCAN_CODE_F2:
1053
			sel_moved = 0;
1030
			start_edit(sel_x, sel_y);
1054
			stop_edit();
1031
			break;
-
 
1032
		case SCAN_CODE_F5:
1055
			draw_grid();
1033
			draw_grid();
-
 
1034
			break;
-
 
1035
		default:
-
 
1036
			start_edit(sel_x, sel_y);
-
 
1037
			__asm
-
 
1038
			{
-
 
1039
				mov eax, key_editbox
1056
		}
1040
			}
-
 
1041
			edit_box_key((dword)&cell_box);
-
 
1042
			break;
1057
	}
1043
	}
1058
}
1044
}
Line 1059... Line 1045...
1059
 
1045
 
1060
void process_button()
1046
void process_button()
Line 1132... Line 1118...
1132
		case EM_BUTTON_CLICK:
1118
		case EM_BUTTON_CLICK:
1133
			process_button();
1119
			process_button();
1134
			break;
1120
			break;
Line 1135... Line 1121...
1135
		
1121
		
1136
		case EM_WINDOW_REDRAW:
1122
		case EM_WINDOW_REDRAW:
1137
			if (draw_and_define_window()) draw_window();
1123
			draw_window();
1138
			break;
1124
			break;
1139
		}
1125
		}
1140
	}
1126
	}