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