2018-10-23 17:29:05 +02:00
|
|
|
|
//если выделить область ячеек и сдвинуть курсор ввода с помощью клавиш, "следы" остануться
|
|
|
|
|
//нельзя перемещаться по буквам в редактируемой строке
|
2012-06-06 23:55:18 +02:00
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#include "func.h"
|
|
|
|
|
#include "parser.h"
|
2008-12-30 00:23:33 +01:00
|
|
|
|
#include "calc.h"
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#include "use_library.h"
|
|
|
|
|
|
2018-10-31 22:22:48 +01:00
|
|
|
|
#ifdef AUTOBUILD
|
|
|
|
|
extern char params[1024];
|
|
|
|
|
#endif
|
|
|
|
|
char params[1024];
|
|
|
|
|
|
2018-11-07 23:32:57 +01:00
|
|
|
|
#define TABLE_VERSION "0.99.3"
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
// strings
|
2009-06-13 00:16:16 +02:00
|
|
|
|
const char *sFileSign = "KolibriTable File\n";
|
2018-10-21 23:03:45 +02:00
|
|
|
|
const char sFilename[] = "Filename:";
|
2009-06-13 00:16:16 +02:00
|
|
|
|
const char sSave[] = "Save";
|
|
|
|
|
const char sLoad[] = "Load";
|
|
|
|
|
const char sNew[] = "New";
|
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
const char er_file_not_found[] = "'Cannot open file' -E";
|
|
|
|
|
const char er_format[] = "'Error: bad format' -E";
|
|
|
|
|
const char msg_save[] = "'File saved' -O";
|
2020-05-08 14:20:36 +02:00
|
|
|
|
//const char msg_load[] = "'File loaded' -O";
|
2018-11-07 23:32:57 +01:00
|
|
|
|
const char msg_save_error[] = "'Error saving file' -E";
|
2018-10-27 19:55:12 +02:00
|
|
|
|
const char msg_new[] = "'Memory cleared' -I";
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-21 23:03:45 +02:00
|
|
|
|
// initial window sizes
|
2018-10-27 19:55:12 +02:00
|
|
|
|
#define WND_W 718
|
|
|
|
|
#define WND_H 514
|
2018-10-21 23:03:45 +02:00
|
|
|
|
// new window size and coordinates
|
|
|
|
|
int cWidth;
|
|
|
|
|
int cHeight;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
kosSysColors sc;
|
|
|
|
|
// bottom panel
|
|
|
|
|
#define MENU_PANEL_HEIGHT 40
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-21 23:03:45 +02:00
|
|
|
|
// interface colors
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#define GRID_COLOR 0xa0a0a0
|
|
|
|
|
#define TEXT_COLOR 0x000000
|
|
|
|
|
#define CELL_COLOR 0xffffff
|
2018-10-27 19:55:12 +02:00
|
|
|
|
#define CELL_COLOR_ACTIVE 0xe0e0ff
|
2018-10-26 15:12:28 +02:00
|
|
|
|
#define HEADER_CELL_COLOR 0xE9E7E3
|
2018-10-27 19:55:12 +02:00
|
|
|
|
#define HEADER_CELL_COLOR_ACTIVE 0xC4C5BA //0xBBBBFF
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-21 23:03:45 +02:00
|
|
|
|
// button IDs
|
2018-11-01 10:23:57 +01:00
|
|
|
|
#define SAVE_BUTTON 100
|
|
|
|
|
#define LOAD_BUTTON 101
|
|
|
|
|
#define NEW_BUTTON 102
|
|
|
|
|
#define SELECT_ALL_BUTTON 103
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
|
|
|
|
#define COL_BUTTON 0x100
|
|
|
|
|
#define ROW_BUTTON (COL_BUTTON + 0x100)
|
|
|
|
|
#define COL_HEAD_BUTTON (ROW_BUTTON + 0x100)
|
|
|
|
|
#define ROW_HEAD_BUTTON (COL_HEAD_BUTTON + 0x100)
|
|
|
|
|
#define CELL_BUTTON (ROW_HEAD_BUTTON + 0x100)
|
|
|
|
|
|
2018-10-21 23:03:45 +02:00
|
|
|
|
// editbox data
|
2018-10-27 19:55:12 +02:00
|
|
|
|
char edit_text[256];
|
2020-05-10 12:00:04 +02:00
|
|
|
|
edit_box cell_box = {0,9*8-6,WND_H - 16-32,0xffffff,0x94AECE,0,
|
|
|
|
|
0x808080,0x10000000,sizeof(edit_text)-1,(dword)&edit_text,0,0};
|
2018-10-27 19:55:12 +02:00
|
|
|
|
|
|
|
|
|
// scrolls
|
|
|
|
|
#define SCROLL_SIZE 16
|
2020-05-10 12:00:04 +02:00
|
|
|
|
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};
|
|
|
|
|
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};
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// ячейки - их параметры и текст
|
2018-10-29 19:16:01 +01:00
|
|
|
|
DWORD col_count = 100, row_count = 100;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
DWORD *cell_w, *cell_h;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
char ***cells;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
struct GRID
|
|
|
|
|
{
|
|
|
|
|
int x,y,w,h;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
int firstx, firsty; // cell x:y in the top left corner
|
|
|
|
|
} grid = {
|
|
|
|
|
0,0,NULL,NULL,
|
|
|
|
|
1,1
|
|
|
|
|
};
|
2018-10-23 17:29:05 +02:00
|
|
|
|
|
|
|
|
|
char ***values; // значения формул, если есть
|
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
bool display_formulas = false; // отображать ли формулы вместо значений
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// координаты отображаемых столбцов и строк
|
2018-10-26 15:12:28 +02:00
|
|
|
|
DWORD *cell_x, *cell_y;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// буфер обмена
|
2009-06-13 00:16:16 +02:00
|
|
|
|
char ***buffer = NULL;
|
|
|
|
|
DWORD buf_col, buf_row;
|
|
|
|
|
DWORD buf_old_x, buf_old_y;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// это выделенная ячейка
|
2009-06-13 00:16:16 +02:00
|
|
|
|
DWORD sel_x = 1, sel_y = 1;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
DWORD prev_x = 0, prev_y = 0; // предыдущая выделенная
|
2009-06-13 00:16:16 +02:00
|
|
|
|
int was_single_selection = 0;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// конец выделения если выделено несколько ячеек
|
2009-06-13 00:16:16 +02:00
|
|
|
|
DWORD sel_end_x = sel_x, sel_end_y = sel_y;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// флаг
|
2009-06-13 00:16:16 +02:00
|
|
|
|
bool sel_moved = 0;
|
|
|
|
|
bool sel_end_move = 0;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// сколько ячеек помещается в окне по х и у
|
2009-06-13 00:16:16 +02:00
|
|
|
|
DWORD nx = 0, ny = 0;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// флаг реадктирования ячейки
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#define is_edit (cell_box.flags & ed_focus)
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// редактирование имени файла
|
2009-06-13 00:16:16 +02:00
|
|
|
|
bool fn_edit = 0;
|
2008-12-30 00:23:33 +01:00
|
|
|
|
char fname[256];
|
2020-05-10 12:00:04 +02:00
|
|
|
|
edit_box file_box = {160,9*8+12,WND_H - 16-32,0xffffff,0x94AECE,
|
|
|
|
|
0,0x808080,0x10000000,sizeof(fname)-1,(dword)&fname,0,0};
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// изменение размеров
|
|
|
|
|
#define SIZE_X 1 // состояние
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#define SIZE_Y 2
|
|
|
|
|
#define SIZE_SELECT 3
|
|
|
|
|
#define SIZE_DRAG 4
|
2009-06-12 16:19:47 +02:00
|
|
|
|
int size_mouse_x, size_mouse_y, size_id, size_state = 0;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// растаскивание ячейки при ее тащении за правый нижний угол, с заполнением ячеек
|
2009-06-13 00:16:16 +02:00
|
|
|
|
int drag_x, drag_y;
|
|
|
|
|
int old_end_x, old_end_y;
|
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
void draw_grid();
|
2018-11-01 10:23:57 +01:00
|
|
|
|
void EventGridSelectAll();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
void DrawSelectedFrame(int x, int y, int w, int h, DWORD col)
|
2018-10-21 23:03:45 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
kos_DrawBar(x,y,w,2,col); // up
|
|
|
|
|
kos_DrawBar(x,y,2,h,col); // left
|
|
|
|
|
kos_DrawBar(x,y+h-2,w-2-3,2,col); // bottom
|
|
|
|
|
kos_DrawBar(x+w-2,y, 2,h-2-3,col); // right
|
|
|
|
|
kos_DrawBar(x+w-4,y+h-4,4,4,col);
|
2018-10-21 23:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawScrolls()
|
|
|
|
|
{
|
|
|
|
|
// HOR
|
|
|
|
|
scroll_h.x = 0;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
scroll_h.y = grid.y + grid.h;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
scroll_h.w = grid.w + SCROLL_SIZE + 1;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
scroll_h.all_redraw = true;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
scroll_h.max_area = col_count - 2;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
scroll_h.cur_area = nx-grid.firstx-1;
|
|
|
|
|
scroll_h.position = grid.firstx-1;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
scrollbar_h_draw((DWORD)&scroll_h);
|
|
|
|
|
|
|
|
|
|
// VER
|
2018-10-23 17:29:05 +02:00
|
|
|
|
scroll_v.x = grid.x + grid.w;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
scroll_v.y = 0;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
scroll_v.h = grid.h + 1;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
scroll_v.all_redraw = true;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
scroll_v.max_area = row_count - 2;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
scroll_v.cur_area = ny-grid.firsty-1;
|
|
|
|
|
scroll_v.position = grid.firsty-1;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
scrollbar_v_draw((DWORD)&scroll_v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void start_edit(int x, int y)
|
|
|
|
|
{
|
2009-06-13 00:16:16 +02:00
|
|
|
|
int ch = 0;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (x < grid.firstx || x > nx - 1)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firstx = x;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
ch = 1;
|
|
|
|
|
}
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (y < grid.firsty || y > ny - 1)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firsty = y;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
ch = 1;
|
|
|
|
|
}
|
|
|
|
|
if (ch)
|
|
|
|
|
{
|
|
|
|
|
sel_moved = 1;
|
2018-10-29 19:16:01 +01:00
|
|
|
|
draw_grid();
|
2008-12-30 00:23:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
file_box.flags &= ~ed_focus;
|
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
cell_box.flags = ed_focus;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
cell_box.left = cell_x[x] + 1;
|
|
|
|
|
cell_box.top = cell_y[y];
|
|
|
|
|
cell_box.width = cell_w[x] - 2;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
memset((Byte*)edit_text, 0, sizeof(edit_text));
|
2008-12-30 00:23:33 +01:00
|
|
|
|
if (cells[x][y])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
strcpy(edit_text, cells[x][y]);
|
2008-12-30 00:23:33 +01:00
|
|
|
|
}
|
2018-10-29 19:16:01 +01:00
|
|
|
|
cell_box.offset = cell_box.shift = cell_box.shift_old = 0;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
cell_box.pos = cell_box.size = strlen(edit_text);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
edit_box_draw((DWORD)&cell_box);
|
|
|
|
|
edit_box_draw((DWORD)&file_box);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stop_edit()
|
|
|
|
|
{
|
|
|
|
|
if (is_edit)
|
|
|
|
|
{
|
|
|
|
|
cell_box.flags &= ~ed_focus;
|
|
|
|
|
if (cells[sel_x][sel_y])
|
|
|
|
|
freemem(cells[sel_x][sel_y]);
|
|
|
|
|
if (strlen(edit_text) > 0)
|
|
|
|
|
{
|
|
|
|
|
cells[sel_x][sel_y] = (char*)allocmem(strlen(edit_text)+1);
|
|
|
|
|
strcpy(cells[sel_x][sel_y], edit_text);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cells[sel_x][sel_y] = NULL;
|
|
|
|
|
//memset((Byte*)edit_text,0, 256);
|
2008-12-30 00:23:33 +01:00
|
|
|
|
calculate_values();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cancel_edit()
|
|
|
|
|
{
|
|
|
|
|
if (!is_edit)
|
|
|
|
|
return;
|
|
|
|
|
cell_box.flags &= ~ed_focus;
|
|
|
|
|
memset((Byte*)edit_text,0, 256);
|
2018-10-29 19:16:01 +01:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void check_sel()
|
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
DWORD sx0=grid.firstx, sy0=grid.firsty;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (sel_x >= nx - 1 /*&& sel_x < col_count - nx + grid.firstx + 1*/)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
//if (sel_x == nx)
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firstx++;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
//else
|
2018-10-27 19:55:12 +02:00
|
|
|
|
// grid.firstx = sel_x;
|
|
|
|
|
if (sel_y >= ny - 1 /*&& sel_y < row_count - ny + grid.firsty */)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
//if (sel_y == ny)
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firsty++;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
//else
|
2018-10-27 19:55:12 +02:00
|
|
|
|
// grid.firsty = sel_y;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (sel_x < grid.firstx)
|
|
|
|
|
grid.firstx = sel_x;
|
|
|
|
|
if (sel_y < grid.firsty)
|
|
|
|
|
grid.firsty = sel_y;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (sx0 != grid.firstx || sy0 != grid.firsty)
|
2018-10-23 17:29:05 +02:00
|
|
|
|
sel_moved = 0; // надо перерисовать все
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-21 23:03:45 +02:00
|
|
|
|
void move_selection(DWORD new_x, DWORD new_y)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
sel_moved = 1;
|
|
|
|
|
stop_edit();
|
|
|
|
|
prev_x = sel_x;
|
|
|
|
|
prev_y = sel_y;
|
|
|
|
|
sel_x = new_x;
|
|
|
|
|
if (sel_x < 1)
|
|
|
|
|
sel_x = 1;
|
|
|
|
|
if (sel_x > col_count - 1)
|
|
|
|
|
sel_x = col_count - 1;
|
|
|
|
|
sel_end_x = sel_x;
|
|
|
|
|
sel_y = new_y;
|
|
|
|
|
if (sel_y < 1)
|
|
|
|
|
sel_y = 1;
|
|
|
|
|
if (sel_y > row_count - 1)
|
|
|
|
|
sel_y = row_count - 1;
|
|
|
|
|
sel_end_y = sel_y;
|
|
|
|
|
check_sel();
|
2018-10-26 15:12:28 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// x - между low и high ? - необязательно low<high
|
2009-06-13 00:16:16 +02:00
|
|
|
|
bool is_between(Dword x, Dword low, Dword high)
|
|
|
|
|
{
|
|
|
|
|
return ((low<high)?(x >= low && x <= high):(x >= high && x <= low));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clear_cell_slow(int px, int py)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
int x0 = cell_w[0];
|
2018-10-27 19:55:12 +02:00
|
|
|
|
for (i = grid.firstx; i < px; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x0 += cell_w[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
int x1 = x0;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x1 += cell_w[px];
|
|
|
|
|
int y0 = cell_h[0];
|
2018-10-27 19:55:12 +02:00
|
|
|
|
for (i = grid.firsty; i < py; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y0 += cell_h[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
int y1 = y0;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y1 += cell_h[py];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
kos_DrawBar(x0 + 1, y0 + 1, x1 - x0 - 1, y1 - y0 - 1, 0xffffff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
|
|
|
|
|
// рисование ячеек
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#define is_x_changed(v) ((v) == sel_x || (v) == prev_x)
|
|
|
|
|
#define is_y_changed(v) ((v) == sel_y || (v) == prev_y)
|
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
void DrawCell(int x, int y, Dword w, Dword h, Dword id, Dword bg_color, char* text, bool header)
|
|
|
|
|
{
|
|
|
|
|
bool small = false;
|
|
|
|
|
if (x>grid.x+grid.w || w>grid.w || w<=0) return;
|
|
|
|
|
if (x+w > grid.x + grid.w) {
|
|
|
|
|
w = grid.x + grid.w - x;
|
|
|
|
|
small = true;
|
|
|
|
|
}
|
|
|
|
|
if (y+h > grid.y + grid.h) {
|
|
|
|
|
h = grid.y + grid.h - y;
|
|
|
|
|
small = true;
|
|
|
|
|
}
|
|
|
|
|
kos_DrawBar(x, y, w, h, bg_color);
|
|
|
|
|
if (!small) {
|
|
|
|
|
if (id) kos_DefineButton(x+5, y, w-10, h-1, id+BT_NODRAW,0);
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (header) kos_WriteTextToWindow( x + w/2 -strlen(text)*4, h/2-7+y, 0x90,TEXT_COLOR,text,0); //WriteTextCenter
|
|
|
|
|
else kos_DrawCutTextSmall(x+3, h/2-7+y, w-7, TEXT_COLOR, text);
|
2018-10-26 15:12:28 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
void draw_grid()
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
long x0 = 0, y0 = 0, x = 0, y = 0;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
DWORD bg_color;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
kos_DrawBar(0,0,cell_w[0],cell_h[0],HEADER_CELL_COLOR); // left top cell
|
2018-11-01 10:23:57 +01:00
|
|
|
|
kos_DefineButton(0,0,cell_w[0]-4,cell_h[0]-4, SELECT_ALL_BUTTON + BT_NODRAW, 0);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
//kos_DebugValue("sel_moved", sel_moved);
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
nx=ny=0;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// очистить область около выделенной ячейки
|
2009-06-13 00:16:16 +02:00
|
|
|
|
if (sel_moved)
|
|
|
|
|
{
|
|
|
|
|
clear_cell_slow(sel_x, sel_y);
|
|
|
|
|
clear_cell_slow(prev_x, prev_y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
// clean all cells
|
|
|
|
|
//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);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
// column headers + vertical lines
|
|
|
|
|
cell_x[0] = 0;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
x = cell_w[0];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
nx = 1;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
for (i = 1; i < col_count && x-x0 < grid.w; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_x[i] = -1;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (i >= grid.firstx)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2024-05-29 23:37:05 +02:00
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
//if (!sel_moved || (is_x_changed(i))) {
|
|
|
|
|
if (is_between(i,sel_x,sel_end_x)) bg_color = HEADER_CELL_COLOR_ACTIVE; else bg_color = HEADER_CELL_COLOR;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
kos_DrawBar(x-x0, 0, 1, grid.h, GRID_COLOR);
|
|
|
|
|
DrawCell(x-x0+1, 0, cell_w[i]-1, cell_h[0], i+COL_HEAD_BUTTON, bg_color, cells[i][0], true);
|
2018-10-27 19:55:12 +02:00
|
|
|
|
//}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_x[i] = x - x0;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x0 += cell_w[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x += cell_w[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
nx++;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
// row headers + horizontal lines
|
|
|
|
|
y = cell_h[0];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
ny = 1;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_y[0] = 0;
|
|
|
|
|
for (i = 1; i < row_count && y-y0 < grid.h; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_y[i] = -1;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (i >= grid.firsty)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
//if (!sel_moved || (is_y_changed(i))) {
|
|
|
|
|
if (is_between(i,sel_y,sel_end_y)) bg_color = HEADER_CELL_COLOR_ACTIVE; else bg_color = HEADER_CELL_COLOR;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
kos_DrawBar(0, y-y0, grid.w, 1, GRID_COLOR);
|
|
|
|
|
DrawCell(0, y-y0+1, cell_w[0], cell_h[i]-1, i+ROW_HEAD_BUTTON, bg_color, cells[0][i], true);
|
2018-10-27 19:55:12 +02:00
|
|
|
|
//}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_y[i] = y - y0;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y0 += cell_h[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y += cell_h[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
ny++;
|
|
|
|
|
}
|
2024-05-29 23:37:05 +02:00
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// cells itself
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y = cell_h[0];
|
2018-10-27 19:55:12 +02:00
|
|
|
|
for (i = grid.firsty; i < ny; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x = cell_w[0];
|
2018-10-27 19:55:12 +02:00
|
|
|
|
for (j = grid.firstx; j < nx; j++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (i && j) //no need to draw headers one more
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
bool draw_frame_selection = false;
|
|
|
|
|
bool error = false;
|
|
|
|
|
bg_color = CELL_COLOR;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (is_between(j,sel_x,sel_end_x) && is_between(i, sel_y, sel_end_y) // (j,i) - selected
|
|
|
|
|
&& ((!sel_moved) || (is_x_changed(j) && is_y_changed(i)))) // and we must draw it
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (i == sel_y && j == sel_x)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
draw_frame_selection = true;
|
|
|
|
|
drag_x = x + cell_w[j] - 4;
|
|
|
|
|
drag_y = y + cell_h[i] - 4;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2018-10-27 19:55:12 +02:00
|
|
|
|
bg_color = CELL_COLOR_ACTIVE; // selected but not main
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *text;
|
|
|
|
|
if (values[j][i] && values[j][i][0] == '#')
|
|
|
|
|
{
|
|
|
|
|
text = cells[j][i];
|
2018-10-26 15:12:28 +02:00
|
|
|
|
error = true;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
else {
|
2009-06-13 00:16:16 +02:00
|
|
|
|
text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]);
|
2018-10-26 15:12:28 +02:00
|
|
|
|
}
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false);
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (draw_frame_selection && j<nx-1 && i<ny-1) {
|
|
|
|
|
DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i]+1, TEXT_COLOR);
|
2018-10-27 19:55:12 +02:00
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x += cell_w[j];
|
2024-05-29 23:37:05 +02:00
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y += cell_h[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-21 23:03:45 +02:00
|
|
|
|
DrawScrolls();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// очень быстрое рисование сетки, в процессе изменения размеров ячеек
|
2009-06-13 00:16:16 +02:00
|
|
|
|
void draw_size_grid()
|
|
|
|
|
{
|
|
|
|
|
//rtlDebugOutString("draw size grid");
|
|
|
|
|
|
|
|
|
|
if (size_state == SIZE_X)
|
|
|
|
|
{
|
|
|
|
|
int x, x0, i;
|
|
|
|
|
|
2024-05-29 23:37:05 +02:00
|
|
|
|
x = cell_w[0];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
x0 = 0;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
for (i = 1; i < col_count && x - x0 + cell_w[i] < grid.w - 10; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (i >= grid.firstx)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
if (i >= size_id)
|
2018-10-23 17:29:05 +02:00
|
|
|
|
kos_DrawLine(x - x0, 0, x - x0, grid.h, 0, 1);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2018-10-26 15:12:28 +02:00
|
|
|
|
x0 += cell_w[i];
|
|
|
|
|
x += cell_w[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-23 17:29:05 +02:00
|
|
|
|
kos_DrawLine(x - x0, 0, x - x0, grid.h, 0, 1);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int y, y0, i;
|
|
|
|
|
|
2024-05-29 23:37:05 +02:00
|
|
|
|
y = cell_h[0];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
y0 = 0;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
for (i = 1; i < col_count && y - y0 + cell_h[i] < grid.h - 10; i++)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (i >= grid.firsty)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
if (i >= size_id)
|
2018-10-23 17:29:05 +02:00
|
|
|
|
kos_DrawLine(0, y - y0, grid.w, y - y0, 0, 1);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2018-10-26 15:12:28 +02:00
|
|
|
|
y0 += cell_h[i];
|
|
|
|
|
y += cell_h[i];
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-23 17:29:05 +02:00
|
|
|
|
kos_DrawLine(0, y - y0, grid.w, y - y0, 0, 1);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// быстрое рисование выделенной области при выделении мышью
|
2009-06-13 00:16:16 +02:00
|
|
|
|
#define DCOLOR 0
|
|
|
|
|
//0xff0000
|
|
|
|
|
#define DINVERT 1
|
|
|
|
|
void draw_drag()
|
|
|
|
|
{
|
2018-10-23 17:29:05 +02:00
|
|
|
|
// inverted lines
|
2009-06-13 00:16:16 +02:00
|
|
|
|
int k0 = min(sel_x, sel_end_x);
|
|
|
|
|
int k1 = max(sel_x, sel_end_x);
|
|
|
|
|
int n0 = min(sel_y, sel_end_y);
|
|
|
|
|
int n1 = max(sel_y, sel_end_y);
|
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
DWORD x0 = cell_x[k0] - 1;
|
|
|
|
|
DWORD x1 = cell_x[k1] + cell_w[k1] + 1;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
DWORD y0 = cell_y[n0] - 1;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
DWORD y1 = cell_y[n1] + cell_h[n1] + 1;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
if (x0 > grid.w - 1) x0 = grid.w - 1;
|
|
|
|
|
if (x1 > grid.w - 1) x1 = grid.w - 1;
|
|
|
|
|
if (y0 > grid.h - 1) y0 = grid.h - 1;
|
|
|
|
|
if (y1 > grid.h - 1) y1 = grid.h - 1;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
|
|
|
|
//sprintf(debuf,"drag %U %U %U %U",k0,k1,n0,n1);
|
2008-12-30 00:23:33 +01:00
|
|
|
|
//rtlDebugOutString(debuf);
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
kos_DrawLine(x0, y0, x0, y1, DCOLOR, DINVERT);
|
|
|
|
|
kos_DrawLine(x0, y0, x1, y0, DCOLOR, DINVERT);
|
|
|
|
|
kos_DrawLine(x1, y0, x1, y1, DCOLOR, DINVERT);
|
|
|
|
|
kos_DrawLine(x0, y1, x1, y1, DCOLOR, DINVERT);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
void draw_window()
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-23 17:29:05 +02:00
|
|
|
|
kos_WindowRedrawStatus(1);
|
|
|
|
|
kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION);
|
2024-05-29 23:37:05 +02:00
|
|
|
|
kos_WindowRedrawStatus(2);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
kos_GetSystemColors(&sc);
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
sProcessInfo info;
|
|
|
|
|
kos_ProcessInfo(&info, 0xFFFFFFFF);
|
|
|
|
|
cWidth = info.processInfo.width - 9;
|
|
|
|
|
cHeight = info.processInfo.height - kos_GetSkinHeight() - 4;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
grid.x = 0;
|
|
|
|
|
grid.y = 0;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
grid.w = cWidth - SCROLL_SIZE - 1;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (info.processInfo.status_window&0x04) return; //draw nothing if window is rolled-up
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (cWidth < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return; }
|
|
|
|
|
if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return; }
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
2018-10-26 15:12:28 +02:00
|
|
|
|
sel_moved = 0;
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (is_edit) stop_edit();
|
2018-10-26 15:12:28 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
int panel_y = cHeight - MENU_PANEL_HEIGHT + 1;
|
|
|
|
|
kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, sc.work);
|
2024-05-29 23:37:05 +02:00
|
|
|
|
kos_WriteTextToWindow(3 + 1, panel_y + 14, 0x90, sc.work_text, (char*)sFilename, 0);
|
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
file_box.top = panel_y + 10;
|
2020-05-10 12:00:04 +02:00
|
|
|
|
file_box.width = cWidth - 265;
|
|
|
|
|
int BTX = cWidth - 190;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
#define BTW 70
|
2018-10-23 17:29:05 +02:00
|
|
|
|
//save
|
2018-10-27 19:55:12 +02:00
|
|
|
|
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);
|
2018-10-23 17:29:05 +02:00
|
|
|
|
//load
|
2018-10-27 19:55:12 +02:00
|
|
|
|
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);
|
2018-10-29 19:16:01 +01:00
|
|
|
|
// // 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));
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (sel_end_move) sel_moved = 0;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
draw_grid();
|
|
|
|
|
sel_moved = 0;
|
2018-10-29 19:16:01 +01:00
|
|
|
|
|
|
|
|
|
if (is_edit) edit_box_draw((DWORD)&cell_box);
|
|
|
|
|
edit_box_draw((DWORD)&file_box);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void process_mouse()
|
|
|
|
|
{
|
|
|
|
|
Dword mouse_btn, ckeys, shift, ctrl;
|
2008-12-30 00:23:33 +01:00
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
int vert, hor;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
kos_GetScrollInfo(vert, hor);
|
2018-10-21 23:03:45 +02:00
|
|
|
|
if (vert != 0)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-21 23:03:45 +02:00
|
|
|
|
stop_edit();
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firsty += vert;
|
|
|
|
|
if (grid.firsty<1) grid.firsty=1;
|
|
|
|
|
if (grid.firsty>row_count-25) grid.firsty=row_count-25;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
2018-11-07 23:32:57 +01:00
|
|
|
|
if (!size_state) //do not handle scrollbars when user selects cells
|
2018-10-21 23:03:45 +02:00
|
|
|
|
{
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (!scroll_h.delta2) scrollbar_v_mouse((DWORD)&scroll_v);
|
|
|
|
|
if (scroll_v.position != grid.firsty-1)
|
2018-10-23 17:29:05 +02:00
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
stop_edit();
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firsty = scroll_v.position + 1;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
draw_grid();
|
|
|
|
|
}
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (!scroll_v.delta2) scrollbar_h_mouse((DWORD)&scroll_h);
|
|
|
|
|
if (scroll_h.position != grid.firstx-1)
|
2018-10-23 17:29:05 +02:00
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
stop_edit();
|
2018-10-27 19:55:12 +02:00
|
|
|
|
grid.firstx = scroll_h.position + 1;
|
2018-10-23 17:29:05 +02:00
|
|
|
|
draw_grid();
|
2018-10-27 19:55:12 +02:00
|
|
|
|
}
|
2018-10-21 23:03:45 +02:00
|
|
|
|
}
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (scroll_v.delta2 || scroll_h.delta2) return;
|
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (is_edit) edit_box_mouse((dword)&cell_box);
|
2018-10-27 19:55:12 +02:00
|
|
|
|
edit_box_mouse((dword)&file_box);
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
2018-10-27 19:55:12 +02:00
|
|
|
|
int mouse_x, mouse_y, i;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
kos_GetMouseState(mouse_btn, mouse_x, mouse_y);
|
|
|
|
|
mouse_x -= 5;
|
2009-06-12 16:19:47 +02:00
|
|
|
|
mouse_y -= kos_GetSkinHeight();
|
|
|
|
|
|
2024-05-29 23:37:05 +02:00
|
|
|
|
if (is_edit && mouse_x>=cell_box.left && mouse_x<=cell_box.left+cell_box.width
|
2018-10-29 19:16:01 +01:00
|
|
|
|
&& mouse_y>=cell_box.top && mouse_y<=cell_box.top+22) return;
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
mouse_btn &= 0x0001;
|
|
|
|
|
|
2018-10-23 17:29:05 +02:00
|
|
|
|
if (mouse_btn)
|
|
|
|
|
{
|
|
|
|
|
if (mouse_y < 0) return; // do nothing if mouse over header
|
|
|
|
|
if (mouse_y > grid.y + grid.h) return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
ckeys = kos_GetSpecialKeyState();
|
|
|
|
|
shift = ckeys & 0x3;
|
|
|
|
|
|
|
|
|
|
if (!size_state && !mouse_btn)
|
|
|
|
|
return;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
if (mouse_btn && !size_state) // LMB down
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
//rtlDebugOutString("lmb down and not resize");
|
|
|
|
|
|
|
|
|
|
if (mouse_x >= drag_x && mouse_x <= drag_x + 4 && mouse_y >= drag_y && mouse_y <= drag_y + 4)
|
|
|
|
|
{
|
|
|
|
|
size_state = SIZE_DRAG;
|
|
|
|
|
old_end_x = sel_end_x;
|
|
|
|
|
old_end_y = sel_end_y;
|
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
else if (mouse_y <= cell_h[0])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
//rtlDebugOutString("can resize col_count");
|
2009-06-13 00:16:16 +02:00
|
|
|
|
int kx = -1, i;
|
|
|
|
|
for (i = 0; i < col_count - 1; i++)
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_x >= cell_x[i] + cell_w[i] - 5 &&
|
|
|
|
|
mouse_x <= cell_x[i + 1] + 5)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
kx = i; break;
|
|
|
|
|
}
|
|
|
|
|
if (kx != -1)
|
|
|
|
|
{
|
|
|
|
|
//sprintf(debuf,"size x %U",k);
|
|
|
|
|
//rtlDebugOutString(debuf);
|
|
|
|
|
size_id = kx;
|
|
|
|
|
size_state = SIZE_X;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-26 15:12:28 +02:00
|
|
|
|
else if (mouse_x <= cell_w[0])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
int ky = -1;
|
|
|
|
|
for (i = 0; i < row_count - 1; i++)
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_y >= cell_y[i] + cell_h[i] - 5 &&
|
|
|
|
|
mouse_y <= cell_y[i + 1] + 5)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
ky = i; break;
|
|
|
|
|
}
|
|
|
|
|
if (ky != -1)
|
|
|
|
|
{
|
|
|
|
|
size_id = ky;
|
|
|
|
|
size_state = SIZE_Y;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-27 19:55:12 +02:00
|
|
|
|
else // click on cell
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_x <= cell_x[nx - 1] && mouse_y <= cell_y[ny - 1])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
was_single_selection = sel_x == sel_end_x && sel_y == sel_end_y;
|
|
|
|
|
int kx = -1, i;
|
|
|
|
|
for (i = 0; i < col_count - 1; i++)
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_x >= cell_x[i] &&
|
|
|
|
|
mouse_x <= cell_x[i] + cell_w[i])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
kx = i; break;
|
|
|
|
|
}
|
|
|
|
|
int ky = -1;
|
|
|
|
|
for (i = 0; i < row_count - 1; i++)
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_y >= cell_y[i] &&
|
|
|
|
|
mouse_y <= cell_y[i] + cell_h[i])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
ky = i; break;
|
|
|
|
|
}
|
|
|
|
|
if (kx != -1 && ky != -1)
|
2008-12-30 00:23:33 +01:00
|
|
|
|
{
|
2024-05-29 23:37:05 +02:00
|
|
|
|
if (!shift)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-21 23:03:45 +02:00
|
|
|
|
move_selection(kx, ky);
|
2009-06-12 16:19:47 +02:00
|
|
|
|
//return;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-06-12 16:19:47 +02:00
|
|
|
|
sel_end_x = kx;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
sel_end_y = ky;
|
|
|
|
|
}
|
|
|
|
|
size_state = SIZE_SELECT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (size_state)
|
|
|
|
|
{
|
|
|
|
|
size_mouse_x = mouse_x;
|
|
|
|
|
size_mouse_y = mouse_y;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (!mouse_btn && size_state)
|
|
|
|
|
{
|
2018-10-23 17:29:05 +02:00
|
|
|
|
sel_moved = 0; // for a good redraw
|
2009-06-13 00:16:16 +02:00
|
|
|
|
//rtlDebugOutString("resize end");
|
|
|
|
|
|
|
|
|
|
if (size_state == SIZE_DRAG)
|
|
|
|
|
{
|
|
|
|
|
fill_cells(sel_x, sel_y, sel_end_x, sel_end_y, old_end_x, old_end_y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//sel_moved = (size_state == SIZE_SELECT && sel_x == sel_end_x && sel_y == sel_end_y && was_single_selection);
|
|
|
|
|
size_state = 0;
|
2018-10-27 19:55:12 +02:00
|
|
|
|
draw_grid(); // все сдвинулось - надо обновиться
|
2009-06-13 00:16:16 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (size_state == SIZE_X && mouse_x != size_mouse_x)
|
|
|
|
|
{
|
|
|
|
|
draw_size_grid();
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_w[size_id] += mouse_x - size_mouse_x;
|
|
|
|
|
if (cell_w[size_id] < 15)
|
|
|
|
|
cell_w[size_id] = 15;
|
|
|
|
|
else if (cell_w[size_id] > grid.w / 2)
|
|
|
|
|
cell_w[size_id] = grid.w / 2;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
draw_size_grid();
|
|
|
|
|
}
|
|
|
|
|
if (size_state == SIZE_Y && mouse_y != size_mouse_y)
|
|
|
|
|
{
|
|
|
|
|
draw_size_grid();
|
2018-10-26 15:12:28 +02:00
|
|
|
|
cell_h[size_id] += mouse_y - size_mouse_y;
|
|
|
|
|
if (cell_h[size_id] < 15)
|
|
|
|
|
cell_h[size_id] = 15;
|
|
|
|
|
else if (cell_h[size_id] > grid.h / 2)
|
|
|
|
|
cell_h[size_id] = grid.h / 2;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
draw_size_grid();
|
|
|
|
|
}
|
|
|
|
|
if ((size_state == SIZE_SELECT || size_state == SIZE_DRAG) && (mouse_x != size_mouse_x || mouse_y != size_mouse_y))
|
|
|
|
|
{
|
|
|
|
|
draw_drag();
|
|
|
|
|
int kx = -1, i;
|
|
|
|
|
for (i = 0; i < col_count - 1; i++)
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_x >= cell_x[i] &&
|
|
|
|
|
mouse_x <= cell_x[i + 1])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-26 15:12:28 +02:00
|
|
|
|
//sprintf(debuf, "yyy %U",cell_x[i+1]);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
//rtlDebugOutString(debuf);
|
|
|
|
|
kx = i; break;
|
|
|
|
|
}
|
|
|
|
|
int ky = -1;
|
|
|
|
|
for (i = 0; i < row_count - 1; i++)
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (mouse_y >= cell_y[i] &&
|
|
|
|
|
mouse_y <= cell_y[i + 1])
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
ky = i; break;
|
|
|
|
|
}
|
|
|
|
|
if (kx != -1) sel_end_x = kx;
|
2018-10-26 15:12:28 +02:00
|
|
|
|
if (ky != -1) sel_end_y = ky;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
if (size_state == SIZE_DRAG)
|
|
|
|
|
{
|
|
|
|
|
if (abs(sel_end_x - sel_x) > 0)
|
|
|
|
|
{
|
|
|
|
|
sel_end_y = old_end_y;
|
|
|
|
|
}
|
|
|
|
|
else if (abs(sel_end_y - sel_y) > 0)
|
|
|
|
|
{
|
|
|
|
|
sel_end_x = old_end_x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
draw_drag();
|
2024-05-29 23:37:05 +02:00
|
|
|
|
}
|
2009-06-13 00:16:16 +02:00
|
|
|
|
size_mouse_x = mouse_x;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
size_mouse_y = mouse_y;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
|
2024-05-29 23:37:05 +02:00
|
|
|
|
void shift_selection(int dx, int dy, Dword shift)
|
2018-10-29 19:16:01 +01:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
void process_key()
|
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
Dword ckeys, shift, ctrl;
|
|
|
|
|
dword key_editbox;
|
|
|
|
|
Byte key_ascii, key_scancode;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2024-05-29 23:37:05 +02:00
|
|
|
|
// key pressed, read it
|
2009-06-13 00:16:16 +02:00
|
|
|
|
ckeys = kos_GetSpecialKeyState();
|
|
|
|
|
shift = ckeys & 0x3;
|
|
|
|
|
ctrl = ckeys & 0x0c;
|
|
|
|
|
sel_moved = 0;
|
|
|
|
|
sel_end_move = 0;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
kos_GetKeys(key_editbox, key_ascii, key_scancode);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (cell_box.flags & ed_focus) {
|
|
|
|
|
if (SCAN_CODE_ENTER == key_scancode) {
|
|
|
|
|
stop_edit();
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2018-10-29 19:16:01 +01:00
|
|
|
|
}
|
|
|
|
|
else if (SCAN_CODE_ESC == key_scancode) {
|
2009-06-13 00:16:16 +02:00
|
|
|
|
cancel_edit();
|
2018-10-29 19:16:01 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
__asm
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
mov eax, key_editbox
|
2008-12-30 00:23:33 +01:00
|
|
|
|
}
|
2024-05-29 23:37:05 +02:00
|
|
|
|
edit_box_key((dword)&cell_box);
|
2018-10-29 19:16:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (file_box.flags & ed_focus) {
|
|
|
|
|
__asm
|
|
|
|
|
{
|
|
|
|
|
mov eax, key_editbox
|
|
|
|
|
}
|
|
|
|
|
edit_box_key((dword)&file_box);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (ctrl) {
|
|
|
|
|
switch (key_scancode)
|
|
|
|
|
{
|
2018-11-01 10:23:57 +01:00
|
|
|
|
case SCAN_CODE_KEY_A:
|
|
|
|
|
EventGridSelectAll();
|
|
|
|
|
break;
|
2018-10-29 19:16:01 +01:00
|
|
|
|
case SCAN_CODE_KEY_V:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
int i, j, x0, y0;
|
|
|
|
|
x0 = min(sel_x, sel_end_x);
|
|
|
|
|
y0 = min(sel_y, sel_end_y);
|
|
|
|
|
int delta_x = x0 - buf_old_x;
|
|
|
|
|
int delta_y = y0 - buf_old_y;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < buf_col; i++)
|
|
|
|
|
for (j = 0; j < buf_row; j++)
|
|
|
|
|
{
|
|
|
|
|
if (i + x0 >= col_count || j + y0 >= row_count)
|
|
|
|
|
continue;
|
|
|
|
|
if (cells[i + x0][j + y0])
|
|
|
|
|
freemem(cells[i + x0][j + y0]);
|
|
|
|
|
if (buffer[i][j])
|
|
|
|
|
{
|
|
|
|
|
cf_x0 = buf_old_x; cf_y0 = buf_old_y;
|
|
|
|
|
cf_x1 = buf_old_x + buf_col;
|
|
|
|
|
cf_y1 = buf_old_y + buf_row;
|
|
|
|
|
cells[i + x0][j + y0] = change_formula(buffer[i][j], delta_x, delta_y);
|
|
|
|
|
//cells[i + x0][j + y0] = (char*)allocmem(strlen(buffer[i][j]));
|
|
|
|
|
//strcpy(cells[i + x0][j + y0], buffer[i][j]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cells[i + x0][j + y0] = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculate_values();
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-29 19:16:01 +01:00
|
|
|
|
case SCAN_CODE_KEY_X:
|
|
|
|
|
case SCAN_CODE_KEY_C:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
int i, j, x0, y0;
|
|
|
|
|
|
|
|
|
|
freeBuffer();
|
|
|
|
|
|
|
|
|
|
buf_col = abs(sel_end_x - sel_x) + 1;
|
|
|
|
|
buf_row = abs(sel_end_y - sel_y) + 1;
|
|
|
|
|
x0 = min(sel_x, sel_end_x);
|
|
|
|
|
y0 = min(sel_y, sel_end_y);
|
|
|
|
|
buf_old_x = x0;
|
|
|
|
|
buf_old_y = y0;
|
|
|
|
|
|
|
|
|
|
//sprintf(debuf, "%U %U %U %U", buf_col, buf_row, x0, y0);
|
|
|
|
|
//rtlDebugOutString(debuf);
|
2024-05-29 23:37:05 +02:00
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
buffer = (char***)allocmem(buf_col * sizeof(char**));
|
|
|
|
|
for (i = 0; i < buf_col; i++)
|
|
|
|
|
{
|
|
|
|
|
buffer[i] = (char**)allocmem(buf_row * sizeof(char*));
|
|
|
|
|
for (j = 0; j < buf_row; j++)
|
|
|
|
|
{
|
|
|
|
|
if (cells[i + x0][j + y0])
|
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (SCAN_CODE_KEY_C == key_scancode)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0]));
|
|
|
|
|
strcpy(buffer[i][j], cells[i + x0][j + y0]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buffer[i][j] = cells[i + x0][j + y0];
|
|
|
|
|
cells[i + x0][j + y0] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
buffer[i][j] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 23:37:05 +02:00
|
|
|
|
if (key_ascii == 24) ///////Unexpected!????
|
2009-06-13 00:16:16 +02:00
|
|
|
|
calculate_values();
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-29 19:16:01 +01:00
|
|
|
|
case SCAN_CODE_KEY_F:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
display_formulas = !display_formulas;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
2018-10-29 19:16:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else switch (key_scancode)
|
|
|
|
|
{
|
|
|
|
|
case SCAN_CODE_UP:
|
|
|
|
|
shift_selection(0, -1, shift);
|
|
|
|
|
break;
|
|
|
|
|
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:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
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++)
|
2008-12-30 00:23:33 +01:00
|
|
|
|
{
|
2018-10-29 19:16:01 +01:00
|
|
|
|
if (cells[i][j])
|
|
|
|
|
{
|
|
|
|
|
freemem(cells[i][j]);
|
|
|
|
|
cells[i][j] = NULL;
|
|
|
|
|
}
|
2008-12-30 00:23:33 +01:00
|
|
|
|
}
|
2018-10-29 19:16:01 +01:00
|
|
|
|
calculate_values();
|
|
|
|
|
draw_grid();
|
|
|
|
|
break;
|
2008-12-30 00:23:33 +01:00
|
|
|
|
}
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
2018-10-29 19:16:01 +01:00
|
|
|
|
case SCAN_CODE_F2:
|
|
|
|
|
start_edit(sel_x, sel_y);
|
|
|
|
|
break;
|
|
|
|
|
case SCAN_CODE_F5:
|
2008-12-30 00:23:33 +01:00
|
|
|
|
draw_grid();
|
2018-10-29 19:16:01 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
start_edit(sel_x, sel_y);
|
|
|
|
|
__asm
|
|
|
|
|
{
|
|
|
|
|
mov eax, key_editbox
|
|
|
|
|
}
|
|
|
|
|
edit_box_key((dword)&cell_box);
|
|
|
|
|
break;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 22:22:48 +01:00
|
|
|
|
void EventLoadFile()
|
|
|
|
|
{
|
|
|
|
|
stop_edit();
|
|
|
|
|
int r = LoadFile(fname);
|
|
|
|
|
if (r > 0) {
|
|
|
|
|
calculate_values();
|
|
|
|
|
sel_moved = 0;
|
|
|
|
|
draw_grid();
|
2020-05-08 14:20:36 +02:00
|
|
|
|
//result = (char*)msg_load;
|
|
|
|
|
} else {
|
|
|
|
|
char *result;
|
|
|
|
|
if (r == -1) result = (char*)er_file_not_found;
|
|
|
|
|
else if (r == -2) result = (char*)er_format;
|
|
|
|
|
kos_AppRun("/sys/@notify", result);
|
2018-10-31 22:22:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 10:23:57 +01:00
|
|
|
|
void EventGridSelectAll()
|
|
|
|
|
{
|
|
|
|
|
sel_y = 1;
|
|
|
|
|
sel_x = 1;
|
|
|
|
|
sel_end_x = col_count - 1;
|
|
|
|
|
sel_end_y = row_count - 1;
|
|
|
|
|
stop_edit();
|
|
|
|
|
draw_grid();
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-13 00:16:16 +02:00
|
|
|
|
void process_button()
|
|
|
|
|
{
|
|
|
|
|
Dword button;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
if (!kos_GetButtonID(button)) return;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
switch (button)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
kos_ExitApp();
|
|
|
|
|
|
|
|
|
|
case NEW_BUTTON: // clear the table
|
|
|
|
|
reinit();
|
2018-10-27 19:55:12 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SAVE_BUTTON:
|
|
|
|
|
stop_edit();
|
2018-11-07 23:32:57 +01:00
|
|
|
|
if (SaveFile(fname)) {
|
|
|
|
|
kos_AppRun("/sys/@notify", (char*)msg_save);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
kos_AppRun("/sys/@notify", (char*)msg_save_error);
|
|
|
|
|
}
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOAD_BUTTON:
|
2018-10-31 22:22:48 +01:00
|
|
|
|
EventLoadFile();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
break;
|
2018-11-01 10:23:57 +01:00
|
|
|
|
|
|
|
|
|
case SELECT_ALL_BUTTON:
|
|
|
|
|
EventGridSelectAll();
|
|
|
|
|
break;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
2018-10-27 19:55:12 +02:00
|
|
|
|
if (button >= COL_HEAD_BUTTON && button < ROW_HEAD_BUTTON)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
sel_end_x = sel_x = button - COL_HEAD_BUTTON;
|
|
|
|
|
sel_y = 1;
|
|
|
|
|
sel_end_y = row_count - 1;
|
|
|
|
|
stop_edit();
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-10-27 19:55:12 +02:00
|
|
|
|
else if (button >= ROW_HEAD_BUTTON && button < CELL_BUTTON)
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
|
|
|
|
sel_end_y = sel_y = button - ROW_HEAD_BUTTON;
|
|
|
|
|
sel_x = 1;
|
|
|
|
|
sel_end_x = col_count - 1;
|
|
|
|
|
stop_edit();
|
2018-10-21 23:03:45 +02:00
|
|
|
|
draw_grid();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void kos_Main()
|
|
|
|
|
{
|
2008-12-30 00:23:33 +01:00
|
|
|
|
kos_InitHeap();
|
|
|
|
|
load_edit_box();
|
2009-06-13 00:16:16 +02:00
|
|
|
|
init();
|
2018-10-31 22:22:48 +01:00
|
|
|
|
if (params[0]) {
|
|
|
|
|
strcpy(fname, params);
|
|
|
|
|
file_box.size = file_box.pos = strlen(fname);
|
|
|
|
|
EventLoadFile();
|
|
|
|
|
}
|
2024-05-29 23:37:05 +02:00
|
|
|
|
kos_SetMaskForEvents(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
|
2009-06-13 00:16:16 +02:00
|
|
|
|
for (;;)
|
|
|
|
|
{
|
2012-06-06 23:55:18 +02:00
|
|
|
|
switch (kos_WaitForEvent())
|
2009-06-13 00:16:16 +02:00
|
|
|
|
{
|
2018-10-21 23:03:45 +02:00
|
|
|
|
case EM_MOUSE_EVENT:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
process_mouse();
|
|
|
|
|
break;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
|
|
|
|
case EM_KEY_PRESS:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
process_key();
|
|
|
|
|
break;
|
2018-10-21 23:03:45 +02:00
|
|
|
|
|
|
|
|
|
case EM_BUTTON_CLICK:
|
2009-06-13 00:16:16 +02:00
|
|
|
|
process_button();
|
2008-12-30 00:23:33 +01:00
|
|
|
|
break;
|
2024-05-29 23:37:05 +02:00
|
|
|
|
|
2018-10-21 23:03:45 +02:00
|
|
|
|
case EM_WINDOW_REDRAW:
|
2018-10-29 19:16:01 +01:00
|
|
|
|
draw_window();
|
2018-10-21 23:03:45 +02:00
|
|
|
|
break;
|
2009-06-13 00:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|