6,7 → 6,7 |
#include "calc.h" |
#include "use_library.h" |
|
#define TABLE_VERSION "0.98.9" |
#define TABLE_VERSION "0.99" |
|
// strings |
const char *sFileSign = "KolibriTable File\n"; |
61,7 → 61,7 |
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}; |
|
// ячейки - их параметры и текст |
DWORD col_count = 101, row_count = 101; |
DWORD col_count = 100, row_count = 100; |
DWORD *cell_w, *cell_h; |
char ***cells; |
|
101,8 → 101,6 |
DWORD nx = 0, ny = 0; |
|
// флаг реадктирования ячейки |
//bool is_edit = 0; |
#define ed_focus 2 |
#define is_edit (cell_box.flags & ed_focus) |
|
// редактирование имени файла |
121,7 → 119,6 |
int drag_x, drag_y; |
int old_end_x, old_end_y; |
|
void draw_window(); |
void draw_grid(); |
|
void DrawSelectedFrame(int x, int y, int w, int h, DWORD col) |
173,12 → 170,12 |
if (ch) |
{ |
sel_moved = 1; |
draw_window(); |
draw_grid(); |
} |
|
file_box.flags &= ~ed_focus; |
|
cell_box.flags |= ed_focus; |
cell_box.flags = ed_focus; |
cell_box.left = cell_x[x] + 1; |
cell_box.top = cell_y[y]; |
cell_box.width = cell_w[x] - 2; |
186,12 → 183,12 |
if (cells[x][y]) |
{ |
strcpy(edit_text, cells[x][y]); |
edit_text[strlen(cells[x][y]) - 1] = '\0'; |
} |
cell_box.offset = cell_box.shift = cell_box.shift_old = 0; |
cell_box.pos = cell_box.size = strlen(edit_text); |
cell_box.offset = 0; |
|
draw_window(); |
edit_box_draw((DWORD)&cell_box); |
edit_box_draw((DWORD)&file_box); |
} |
|
void stop_edit() |
219,7 → 216,7 |
return; |
cell_box.flags &= ~ed_focus; |
memset((Byte*)edit_text,0, 256); |
draw_window(); |
draw_grid(); |
} |
|
void check_sel() |
434,8 → 431,8 |
} |
|
DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false); |
if (draw_frame_selection) { |
DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i], TEXT_COLOR); |
if (draw_frame_selection && j<nx-1 && i<ny-1) { |
DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i]+1, TEXT_COLOR); |
} |
else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0); |
} |
523,7 → 520,7 |
kos_DrawLine(x0, y1, x1, y1, DCOLOR, DINVERT); |
} |
|
bool draw_and_define_window() |
void draw_window() |
{ |
kos_WindowRedrawStatus(1); |
kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION); |
541,51 → 538,36 |
grid.w = cWidth - SCROLL_SIZE - 1; |
grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE; |
|
if (info.processInfo.status_window&0x04) return false; //draw nothing if window is rolled-up |
if (info.processInfo.status_window&0x04) return; //draw nothing if window is rolled-up |
|
if (cWidth < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return false; } |
if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return false; } |
if (cWidth < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return; } |
if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return; } |
|
sel_moved = 0; |
if (is_edit) stop_edit(); |
|
return true; |
} |
|
void draw_window() |
{ |
int panel_y = cHeight - MENU_PANEL_HEIGHT + 1; |
|
kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, sc.work); |
kos_WriteTextToWindow(3 + 1, panel_y + 14, 0x90, sc.work_text, (char*)sFilename, 0); |
|
file_box.top = panel_y + 10; |
|
#define BTX 230 |
#define BTW 70 |
//save |
kos_DefineButton(BTX + 25, file_box.top, BTW, 21, SAVE_BUTTON, sc.work); |
kos_WriteTextToWindow(BTX + 25 + (BTW - strlen(sSave) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sSave, 0); |
|
//load |
kos_DefineButton(BTX + 25+BTW+5, file_box.top, BTW, 21, LOAD_BUTTON, sc.work); |
kos_WriteTextToWindow(BTX + 25+BTW+5 + (BTW - strlen(sLoad) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sLoad, 0); |
// // new (clean) |
// kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, sc.work); |
// kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, sc.work_text, (char*)sNew, strlen(sNew)); |
|
//new (clean) |
/* |
kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, sc.work); |
kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, sc.work_text, (char*)sNew, strlen(sNew)); |
*/ |
|
if ((void*)edit_box_draw != NULL) |
{ |
if (is_edit) |
edit_box_draw((DWORD)&cell_box); |
edit_box_draw((DWORD)&file_box); |
} |
|
if (sel_end_move) sel_moved = 0; |
draw_grid(); |
sel_moved = 0; |
|
if (is_edit) edit_box_draw((DWORD)&cell_box); |
edit_box_draw((DWORD)&file_box); |
} |
|
void process_mouse() |
609,6 → 591,7 |
if (!scroll_h.delta2) scrollbar_v_mouse((DWORD)&scroll_v); |
if (scroll_v.position != grid.firsty-1) |
{ |
stop_edit(); |
grid.firsty = scroll_v.position + 1; |
draw_grid(); |
} |
616,6 → 599,7 |
if (!scroll_v.delta2) scrollbar_h_mouse((DWORD)&scroll_h); |
if (scroll_h.position != grid.firstx-1) |
{ |
stop_edit(); |
grid.firstx = scroll_h.position + 1; |
draw_grid(); |
} |
622,7 → 606,7 |
} |
if (scroll_v.delta2 || scroll_h.delta2) return; |
|
edit_box_mouse((dword)&cell_box); |
if (is_edit) edit_box_mouse((dword)&cell_box); |
edit_box_mouse((dword)&file_box); |
|
int mouse_x, mouse_y, i; |
630,6 → 614,9 |
mouse_x -= 5; |
mouse_y -= kos_GetSkinHeight(); |
|
if (is_edit && mouse_x>=cell_box.left && mouse_x<=cell_box.left+cell_box.width |
&& mouse_y>=cell_box.top && mouse_y<=cell_box.top+22) return; |
|
mouse_btn &= 0x0001; |
|
if (mouse_btn) |
799,92 → 786,117 |
size_mouse_y = mouse_y; |
} |
|
|
void shift_selection(int dx, int dy, Dword shift) |
{ |
if (dx != 0) |
{ |
if (shift) |
{ |
sel_end_x += dx; |
if (sel_end_x <= 1) |
sel_end_x = 1; |
else if (sel_end_x >= col_count) |
sel_end_x = col_count - 1; |
// sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y); |
// rtlDebugOutString(debuf); |
sel_moved = sel_end_move = 1; |
//stop_edit(); |
//draw_grid(); |
} |
else |
{ |
} |
} |
if (dy != 0) |
{ |
if (shift) |
{ |
sel_end_y += dy; |
if (sel_end_y <= 1) |
sel_end_y = 1; |
else if (sel_end_y >= row_count) |
sel_end_y = row_count - 1; |
// sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y); |
// rtlDebugOutString(debuf); |
sel_moved = sel_end_move = 1; |
//stop_edit(); |
//draw_grid(); |
} |
} |
/* |
if (sel_end_x < sel_x) |
{ |
Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp; |
} |
if (sel_end_y < sel_y) |
{ |
Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp; |
} |
*/ |
if ((dx || dy)) |
{ |
if (!shift) |
{ |
if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //stub |
else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;} |
else { |
move_selection(sel_x + dx, sel_y + dy); |
} |
} |
else |
{ |
sel_moved = 0; |
stop_edit(); |
draw_grid(); |
} |
} |
} |
|
|
void process_key() |
{ |
Dword mouse_btn, ckeys, shift, ctrl; |
int mouse_x, mouse_y, dx = 0, dy = 0; |
Dword ckeys, shift, ctrl; |
dword key_editbox; |
Byte key_ascii, key_scancode; |
|
// key pressed, read it |
Byte keyCode; |
ckeys = kos_GetSpecialKeyState(); |
shift = ckeys & 0x3; |
ctrl = ckeys & 0x0c; |
sel_moved = 0; |
sel_end_move = 0; |
kos_GetKey(keyCode); |
|
__asm |
{ |
mov ah, keyCode |
} |
edit_box_key((dword)&cell_box); |
edit_box_key((dword)&file_box); |
kos_GetKeys(key_editbox, key_ascii, key_scancode); |
|
|
switch (keyCode) |
{ |
case 178: |
dy = -1; |
break; |
case 176: |
dx = -1; |
break; |
case 179: |
dx = 1; |
break; |
case 177: |
dy = 1; |
break; |
case 183: |
dy = ny - grid.firsty-1; |
break; |
case 184: |
dy = - (ny - grid.firsty); |
break; |
case 180: //home |
dx = -sel_x + 1; |
dy = 0; |
if (cell_box.flags & ed_focus) { |
if (SCAN_CODE_ENTER == key_scancode) { |
stop_edit(); |
draw_grid(); |
break; |
case 181: //end |
dx = col_count - (nx - grid.firstx) - 1 - sel_x; |
dy = 0; |
draw_grid(); |
break; |
case 27: // escape |
} |
else if (SCAN_CODE_ESC == key_scancode) { |
cancel_edit(); |
break; |
case 182: // delete |
} |
else { |
__asm |
{ |
int i,j,n0,n1,k0,k1; |
n0 = min(sel_x, sel_end_x); |
n1 = max(sel_x, sel_end_x); |
k0 = min(sel_y, sel_end_y); |
k1 = max(sel_y, sel_end_y); |
|
for (i = n0; i <= n1; i++) |
for (j = k0; j <= k1; j++) |
{ |
if (cells[i][j]) |
{ |
freemem(cells[i][j]); |
cells[i][j] = NULL; |
mov eax, key_editbox |
} |
edit_box_key((dword)&cell_box); |
} |
calculate_values(); |
draw_grid(); |
break; |
} |
case 0x0D: // enter |
if (is_edit) |
else if (file_box.flags & ed_focus) { |
__asm |
{ |
stop_edit(); |
draw_grid(); |
mov eax, key_editbox |
} |
break; |
case 22: // contol-v |
edit_box_key((dword)&file_box); |
return; |
} |
else if (ctrl) { |
switch (key_scancode) |
{ |
if (ctrl) |
case SCAN_CODE_KEY_V: |
{ |
int i, j, x0, y0; |
x0 = min(sel_x, sel_end_x); |
916,13 → 928,9 |
draw_grid(); |
break; |
} |
} |
case 24: // control-x |
case 03: // control-c |
case SCAN_CODE_KEY_X: |
case SCAN_CODE_KEY_C: |
{ |
if (ctrl) |
{ |
//rtlDebugOutString("control-c!"); |
int i, j, x0, y0; |
|
freeBuffer(); |
945,7 → 953,7 |
{ |
if (cells[i + x0][j + y0]) |
{ |
if (keyCode == 03) // ctrl-c |
if (SCAN_CODE_KEY_C == key_scancode) |
{ |
buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0])); |
strcpy(buffer[i][j], cells[i + x0][j + y0]); |
960,102 → 968,80 |
buffer[i][j] = NULL; |
} |
} |
if (keyCode == 24) |
if (key_ascii == 24) ///////WTF???? |
calculate_values(); |
draw_grid(); |
break; |
} |
} |
case 06: // control-f |
{ |
case SCAN_CODE_KEY_F: |
display_formulas = !display_formulas; |
draw_grid(); |
break; |
} |
default: |
if (!is_edit && !(file_box.flags & ed_focus)) |
{ |
start_edit(sel_x, sel_y); |
if (keyCode == 8) |
{ |
cell_box.pos = strlen(edit_text); |
} |
else |
else switch (key_scancode) |
{ |
__asm |
{ |
mov ah, keyCode |
} |
edit_box_key((dword)&cell_box); |
} |
} |
if (is_edit) |
edit_box_draw((dword)&cell_box); |
case SCAN_CODE_UP: |
shift_selection(0, -1, shift); |
break; |
} |
if (dx != 0) |
case SCAN_CODE_LEFT: |
shift_selection(-1, 0, shift); |
break; |
case SCAN_CODE_RIGHT: |
shift_selection(1, 0, shift); |
break; |
case SCAN_CODE_DOWN: |
shift_selection(0, 1, shift); |
break; |
case SCAN_CODE_PGDN: |
shift_selection(0, ny-grid.firsty-1, shift); |
break; |
case SCAN_CODE_PGUP: |
shift_selection(0, -(ny-grid.firsty), shift); |
break; |
case SCAN_CODE_HOME: |
shift_selection(-sel_x + 1, 0, shift); |
break; |
case SCAN_CODE_END: |
shift_selection(col_count - (nx - grid.firstx) - 1 - sel_x, 0, shift); |
break; |
case SCAN_CODE_DEL: |
{ |
if (shift) |
int n0 = min(sel_x, sel_end_x); |
int n1 = max(sel_x, sel_end_x); |
int k0 = min(sel_y, sel_end_y); |
int k1 = max(sel_y, sel_end_y); |
|
for (int i = n0; i <= n1; i++) |
for (int j = k0; j <= k1; j++) |
{ |
sel_end_x += dx; |
if (sel_end_x <= 1) |
sel_end_x = 1; |
else if (sel_end_x >= col_count) |
sel_end_x = col_count - 1; |
// sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y); |
// rtlDebugOutString(debuf); |
sel_moved = sel_end_move = 1; |
//stop_edit(); |
//draw_grid(); |
} |
else |
if (cells[i][j]) |
{ |
freemem(cells[i][j]); |
cells[i][j] = NULL; |
} |
} |
if (dy != 0) |
{ |
if (shift) |
{ |
sel_end_y += dy; |
if (sel_end_y <= 1) |
sel_end_y = 1; |
else if (sel_end_y >= row_count) |
sel_end_y = row_count - 1; |
// sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y); |
// rtlDebugOutString(debuf); |
sel_moved = sel_end_move = 1; |
//stop_edit(); |
//draw_grid(); |
calculate_values(); |
draw_grid(); |
break; |
} |
} |
/* |
if (sel_end_x < sel_x) |
break; |
case SCAN_CODE_F2: |
start_edit(sel_x, sel_y); |
break; |
case SCAN_CODE_F5: |
draw_grid(); |
break; |
default: |
start_edit(sel_x, sel_y); |
__asm |
{ |
Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp; |
mov eax, key_editbox |
} |
if (sel_end_y < sel_y) |
{ |
Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp; |
edit_box_key((dword)&cell_box); |
break; |
} |
*/ |
if ((dx || dy)) |
{ |
if (!shift) |
{ |
if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //stub |
else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;} |
else { |
move_selection(sel_x + dx, sel_y + dy); |
} |
} |
else |
{ |
sel_moved = 0; |
stop_edit(); |
draw_grid(); |
} |
} |
} |
|
void process_button() |
{ |
1134,7 → 1120,7 |
break; |
|
case EM_WINDOW_REDRAW: |
if (draw_and_define_window()) draw_window(); |
draw_window(); |
break; |
} |
} |