Rev 7503 | Rev 7507 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7503 | Rev 7504 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | #include "func.h" |
4 | #include "func.h" |
5 | #include "parser.h" |
5 | #include "parser.h" |
6 | #include "calc.h" |
6 | #include "calc.h" |
7 | #include "use_library.h" |
7 | #include "use_library.h" |
Line 8... | Line 8... | ||
8 | 8 | ||
Line 9... | Line 9... | ||
9 | #define TABLE_VERSION "0.98.7" |
9 | #define TABLE_VERSION "0.98.9" |
10 | 10 | ||
11 | // строки, которые выводит программа |
11 | // strings |
12 | const char *sFileSign = "KolibriTable File\n"; |
12 | const char *sFileSign = "KolibriTable File\n"; |
13 | const char sFilename[] = "Filename:"; |
13 | const char sFilename[] = "Filename:"; |
14 | const char sSave[] = "Save"; |
14 | const char sSave[] = "Save"; |
Line 15... | Line 15... | ||
15 | const char sLoad[] = "Load"; |
15 | const char sLoad[] = "Load"; |
16 | const char sNew[] = "New"; |
16 | const char sNew[] = "New"; |
17 | 17 | ||
18 | const char er_file_not_found[] = "Cannot open file. "; |
18 | const char er_file_not_found[] = "'Cannot open file' -E"; |
19 | const char er_format[] = "Error: bad format. "; |
19 | const char er_format[] = "'Error: bad format' -E"; |
Line 20... | Line 20... | ||
20 | const char msg_save[] = "File saved. "; |
20 | const char msg_save[] = "'File saved' -O"; |
21 | const char msg_load[] = "File loaded. "; |
21 | const char msg_load[] = "'File loaded' -O"; |
22 | const char msg_new[] = "Memory cleared. "; |
22 | const char msg_new[] = "'Memory cleared' -I"; |
23 | 23 | ||
24 | // initial window sizes |
24 | // initial window sizes |
25 | #define WND_W 640 |
25 | #define WND_W 718 |
- | 26 | #define WND_H 514 |
|
- | 27 | // new window size and coordinates |
|
- | 28 | int cWidth; |
|
Line 26... | Line 29... | ||
26 | #define WND_H 480 |
29 | int cHeight; |
27 | // new window size and coordinates |
30 | kosSysColors sc; |
28 | int cWidth; |
31 | // bottom panel |
29 | int cHeight; |
32 | #define MENU_PANEL_HEIGHT 40 |
30 | 33 | ||
31 | // interface colors |
34 | // interface colors |
32 | #define GRID_COLOR 0xa0a0a0 |
35 | #define GRID_COLOR 0xa0a0a0 |
33 | #define TEXT_COLOR 0x000000 |
- | |
34 | #define CELL_COLOR 0xffffff |
- | |
35 | #define SEL_CELL_COLOR 0xe0e0ff |
- | |
Line 36... | Line 36... | ||
36 | #define HEADER_CELL_COLOR 0xE9E7E3 |
36 | #define TEXT_COLOR 0x000000 |
37 | #define SEL_HEADER_CELL_COLOR 0xC4C5BA //0xBBBBFF |
- | |
38 | #define PANEL_BG_COLOR 0xe4dfe1 |
37 | #define CELL_COLOR 0xffffff |
39 | 38 | #define CELL_COLOR_ACTIVE 0xe0e0ff |
|
40 | #define SCROLL_SIZE 16 |
39 | #define HEADER_CELL_COLOR 0xE9E7E3 |
41 | 40 | #define HEADER_CELL_COLOR_ACTIVE 0xC4C5BA //0xBBBBFF |
|
Line 50... | Line 49... | ||
50 | #define ROW_BUTTON (COL_BUTTON + 0x100) |
49 | #define ROW_BUTTON (COL_BUTTON + 0x100) |
51 | #define COL_HEAD_BUTTON (ROW_BUTTON + 0x100) |
50 | #define COL_HEAD_BUTTON (ROW_BUTTON + 0x100) |
52 | #define ROW_HEAD_BUTTON (COL_HEAD_BUTTON + 0x100) |
51 | #define ROW_HEAD_BUTTON (COL_HEAD_BUTTON + 0x100) |
53 | #define CELL_BUTTON (ROW_HEAD_BUTTON + 0x100) |
52 | #define CELL_BUTTON (ROW_HEAD_BUTTON + 0x100) |
Line 54... | Line -... | ||
54 | - | ||
55 | // bottom panel |
- | |
56 | #define MENU_PANEL_HEIGHT 40 |
- | |
57 | Dword panel_y = 0; |
- | |
58 | 53 | ||
59 | // editbox data |
54 | // editbox data |
60 | char edit_text[256] = ""; |
55 | char edit_text[256]; |
- | 56 | edit_box cell_box = {0,9*8-6,WND_H - 16-32,0xffffff,0x94AECE,0,0x808080,0x10000000,255,(dword)&edit_text,0,0}; |
|
- | 57 | ||
- | 58 | // scrolls |
|
61 | edit_box cell_box = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,255,(dword)&edit_text,0,0}; |
59 | #define SCROLL_SIZE 16 |
62 | scroll_bar scroll_v = { SCROLL_SIZE,200,398, NULL, SCROLL_SIZE,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
60 | scroll_bar scroll_v = { SCROLL_SIZE,200,398, NULL, SCROLL_SIZE,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
Line 63... | Line 61... | ||
63 | scroll_bar scroll_h = { 200,NULL,SCROLL_SIZE, NULL, SCROLL_SIZE,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
61 | scroll_bar scroll_h = { 200,NULL,SCROLL_SIZE, NULL, SCROLL_SIZE,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
64 | 62 | ||
65 | // ячейки - их параметры и текст |
63 | // ячейки - их параметры и текст |
66 | DWORD col_count = 100, row_count = 100; |
64 | DWORD col_count = 101, row_count = 101; |
Line 67... | Line 65... | ||
67 | DWORD *cell_w, *cell_h; |
65 | DWORD *cell_w, *cell_h; |
68 | char ***cells; |
66 | char ***cells; |
69 | 67 | ||
- | 68 | struct GRID |
|
70 | struct GRID |
69 | { |
- | 70 | int x,y,w,h; |
|
- | 71 | int firstx, firsty; // cell x:y in the top left corner |
|
- | 72 | } grid = { |
|
Line 71... | Line 73... | ||
71 | { |
73 | 0,0,NULL,NULL, |
Line 72... | Line 74... | ||
72 | int x,y,w,h; |
74 | 1,1 |
Line 82... | Line 84... | ||
82 | // буфер обмена |
84 | // буфер обмена |
83 | char ***buffer = NULL; |
85 | char ***buffer = NULL; |
84 | DWORD buf_col, buf_row; |
86 | DWORD buf_col, buf_row; |
85 | DWORD buf_old_x, buf_old_y; |
87 | DWORD buf_old_x, buf_old_y; |
Line 86... | Line -... | ||
86 | - | ||
87 | // это координаты ячейки, отображаемой в ЛВ угле |
- | |
88 | DWORD scroll_x = 1, scroll_y = 1; |
88 | |
89 | // это выделенная ячейка |
89 | // это выделенная ячейка |
90 | DWORD sel_x = 1, sel_y = 1; |
90 | DWORD sel_x = 1, sel_y = 1; |
91 | DWORD prev_x = 0, prev_y = 0; // предыдущая выделенная |
91 | DWORD prev_x = 0, prev_y = 0; // предыдущая выделенная |
Line 106... | Line 106... | ||
106 | #define is_edit (cell_box.flags & ed_focus) |
106 | #define is_edit (cell_box.flags & ed_focus) |
Line 107... | Line 107... | ||
107 | 107 | ||
108 | // редактирование имени файла |
108 | // редактирование имени файла |
109 | bool fn_edit = 0; |
109 | bool fn_edit = 0; |
110 | char fname[256]; |
110 | char fname[256]; |
Line 111... | Line 111... | ||
111 | edit_box file_box = {98,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,255,(dword)&fname,0,0}; |
111 | edit_box file_box = {160,9*8+12,WND_H - 16-32,0xffffff,0x94AECE,0,0x808080,0x10000000,255,(dword)&fname,0,0}; |
112 | 112 | ||
113 | // изменение размеров |
113 | // изменение размеров |
114 | #define SIZE_X 1 // состояние |
114 | #define SIZE_X 1 // состояние |
Line 139... | Line 139... | ||
139 | scroll_h.x = 0; |
139 | scroll_h.x = 0; |
140 | scroll_h.y = grid.y + grid.h; |
140 | scroll_h.y = grid.y + grid.h; |
141 | scroll_h.w = grid.w + SCROLL_SIZE + 1; |
141 | scroll_h.w = grid.w + SCROLL_SIZE + 1; |
142 | scroll_h.all_redraw = true; |
142 | scroll_h.all_redraw = true; |
143 | scroll_h.max_area = col_count - 2; |
143 | scroll_h.max_area = col_count - 2; |
144 | scroll_h.cur_area = nx-scroll_x-1; |
144 | scroll_h.cur_area = nx-grid.firstx-1; |
145 | scroll_h.position = scroll_x-1; |
145 | scroll_h.position = grid.firstx-1; |
146 | scrollbar_h_draw((DWORD)&scroll_h); |
146 | scrollbar_h_draw((DWORD)&scroll_h); |
Line 147... | Line 147... | ||
147 | 147 | ||
148 | // VER |
148 | // VER |
149 | scroll_v.x = grid.x + grid.w; |
149 | scroll_v.x = grid.x + grid.w; |
150 | scroll_v.y = 0; |
150 | scroll_v.y = 0; |
151 | scroll_v.h = grid.h + 1; |
151 | scroll_v.h = grid.h + 1; |
152 | scroll_v.all_redraw = true; |
152 | scroll_v.all_redraw = true; |
153 | scroll_v.max_area = row_count - 2; |
153 | scroll_v.max_area = row_count - 2; |
154 | scroll_v.cur_area = ny-scroll_y-1; |
154 | scroll_v.cur_area = ny-grid.firsty-1; |
155 | scroll_v.position = scroll_y-1; |
155 | scroll_v.position = grid.firsty-1; |
156 | scrollbar_v_draw((DWORD)&scroll_v); |
156 | scrollbar_v_draw((DWORD)&scroll_v); |
Line 157... | Line 157... | ||
157 | } |
157 | } |
158 | 158 | ||
159 | 159 | ||
160 | void start_edit(int x, int y) |
160 | void start_edit(int x, int y) |
161 | { |
161 | { |
162 | int ch = 0; |
162 | int ch = 0; |
163 | if (x < scroll_x || x > nx - 1) |
163 | if (x < grid.firstx || x > nx - 1) |
164 | { |
164 | { |
165 | scroll_x = x; |
165 | grid.firstx = x; |
166 | ch = 1; |
166 | ch = 1; |
167 | } |
167 | } |
168 | if (y < scroll_y || y > ny - 1) |
168 | if (y < grid.firsty || y > ny - 1) |
169 | { |
169 | { |
170 | scroll_y = y; |
170 | grid.firsty = y; |
171 | ch = 1; |
171 | ch = 1; |
172 | } |
172 | } |
Line 177... | Line 177... | ||
177 | } |
177 | } |
Line 178... | Line 178... | ||
178 | 178 | ||
Line 179... | Line 179... | ||
179 | file_box.flags &= ~ed_focus; |
179 | file_box.flags &= ~ed_focus; |
180 | 180 | ||
181 | cell_box.flags |= ed_focus; |
181 | cell_box.flags |= ed_focus; |
182 | cell_box.left = cell_x[x] + 2; |
182 | cell_box.left = cell_x[x] + 1; |
183 | cell_box.top = cell_y[y] + 2; |
- | |
184 | cell_box.width = cell_w[x] - 4; |
183 | cell_box.top = cell_y[y]; |
185 | //cell_box.height= cell_h[y]; |
184 | cell_box.width = cell_w[x] - 2; |
186 | memset((Byte*)edit_text, 0, sizeof(edit_text)); |
185 | memset((Byte*)edit_text, 0, sizeof(edit_text)); |
187 | if (cells[x][y]) |
186 | if (cells[x][y]) |
188 | { |
187 | { |
189 | strcpy(edit_text, cells[x][y]); |
188 | strcpy(edit_text, cells[x][y]); |
190 | edit_text[strlen(cells[x][y]) - 1] = '\0'; |
189 | edit_text[strlen(cells[x][y]) - 1] = '\0'; |
- | 190 | } |
|
Line 191... | Line 191... | ||
191 | } |
191 | cell_box.pos = cell_box.size = strlen(edit_text); |
192 | cell_box.pos = cell_box.offset = 0; |
192 | cell_box.offset = 0; |
Line 193... | Line 193... | ||
193 | 193 | ||
Line 222... | Line 222... | ||
222 | draw_window(); |
222 | draw_window(); |
223 | } |
223 | } |
Line 224... | Line 224... | ||
224 | 224 | ||
225 | void check_sel() |
225 | void check_sel() |
226 | { |
226 | { |
Line 227... | Line 227... | ||
227 | DWORD sx0=scroll_x, sy0=scroll_y; |
227 | DWORD sx0=grid.firstx, sy0=grid.firsty; |
228 | 228 | ||
229 | if (sel_x >= nx - 1 /*&& sel_x < col_count - nx + scroll_x + 1*/) |
229 | if (sel_x >= nx - 1 /*&& sel_x < col_count - nx + grid.firstx + 1*/) |
230 | //if (sel_x == nx) |
230 | //if (sel_x == nx) |
231 | scroll_x++; |
231 | grid.firstx++; |
232 | //else |
232 | //else |
233 | // scroll_x = sel_x; |
233 | // grid.firstx = sel_x; |
234 | if (sel_y >= ny - 1 /*&& sel_y < row_count - ny + scroll_y */) |
234 | if (sel_y >= ny - 1 /*&& sel_y < row_count - ny + grid.firsty */) |
235 | //if (sel_y == ny) |
235 | //if (sel_y == ny) |
236 | scroll_y++; |
236 | grid.firsty++; |
Line 237... | Line 237... | ||
237 | //else |
237 | //else |
238 | // scroll_y = sel_y; |
238 | // grid.firsty = sel_y; |
239 | 239 | ||
240 | if (sel_x < scroll_x) |
240 | if (sel_x < grid.firstx) |
Line 241... | Line 241... | ||
241 | scroll_x = sel_x; |
241 | grid.firstx = sel_x; |
242 | if (sel_y < scroll_y) |
242 | if (sel_y < grid.firsty) |
Line 243... | Line 243... | ||
243 | scroll_y = sel_y; |
243 | grid.firsty = sel_y; |
Line 244... | Line 244... | ||
244 | 244 | ||
Line 277... | Line 277... | ||
277 | 277 | ||
278 | void clear_cell_slow(int px, int py) |
278 | void clear_cell_slow(int px, int py) |
279 | { |
279 | { |
280 | int i; |
280 | int i; |
281 | int x0 = cell_w[0]; |
281 | int x0 = cell_w[0]; |
282 | for (i = scroll_x; i < px; i++) |
282 | for (i = grid.firstx; i < px; i++) |
283 | { |
283 | { |
284 | x0 += cell_w[i]; |
284 | x0 += cell_w[i]; |
285 | } |
285 | } |
286 | int x1 = x0; |
286 | int x1 = x0; |
287 | x1 += cell_w[px]; |
287 | x1 += cell_w[px]; |
288 | int y0 = cell_h[0]; |
288 | int y0 = cell_h[0]; |
289 | for (i = scroll_y; i < py; i++) |
289 | for (i = grid.firsty; i < py; i++) |
290 | { |
290 | { |
291 | y0 += cell_h[i]; |
291 | y0 += cell_h[i]; |
292 | } |
292 | } |
293 | int y1 = y0; |
293 | int y1 = y0; |
Line 314... | Line 314... | ||
314 | small = true; |
314 | small = true; |
315 | } |
315 | } |
316 | kos_DrawBar(x, y, w, h, bg_color); |
316 | kos_DrawBar(x, y, w, h, bg_color); |
317 | if (!small) { |
317 | if (!small) { |
318 | if (id) kos_DefineButton(x+5, y, w-10, h-1, id+BT_NODRAW,0); |
318 | if (id) kos_DefineButton(x+5, y, w-10, h-1, id+BT_NODRAW,0); |
319 | if (header) kos_WriteTextToWindow( x + w/2 -strlen(text)*3, h/2-4+y, 0x80,TEXT_COLOR,text,0); //WriteTextCenter |
319 | if (header) kos_WriteTextToWindow( x + w/2 -strlen(text)*4, h/2-7+y, 0x90,TEXT_COLOR,text,0); //WriteTextCenter |
320 | else kos_DrawCutTextSmall(x+2, h/2-4+y, w-7, TEXT_COLOR, text); |
320 | else kos_DrawCutTextSmall(x+3, h/2-7+y, w-7, TEXT_COLOR, text); |
321 | } |
321 | } |
322 | } |
322 | } |
Line 323... | Line 323... | ||
323 | 323 | ||
324 | void draw_grid() |
324 | void draw_grid() |
325 | { |
325 | { |
326 | int i,j; |
326 | int i,j; |
327 | long x0 = 0, y0 = 0, x = 0, y = 0; |
327 | long x0 = 0, y0 = 0, x = 0, y = 0; |
328 | DWORD bg_color; |
328 | DWORD bg_color; |
Line -... | Line 329... | ||
- | 329 | kos_DrawBar(0,0,cell_w[0],cell_h[0],HEADER_CELL_COLOR); // left top cell |
|
- | 330 | ||
329 | kos_DrawBar(0,0,cell_w[0],cell_h[0],HEADER_CELL_COLOR); // left top cell |
331 | //kos_DebugValue("sel_moved", sel_moved); |
Line 330... | Line 332... | ||
330 | 332 | ||
331 | nx=ny=0; |
333 | nx=ny=0; |
332 | 334 | ||
Line 347... | Line 349... | ||
347 | x = cell_w[0]; |
349 | x = cell_w[0]; |
348 | nx = 1; |
350 | nx = 1; |
349 | for (i = 1; i < col_count && x-x0 < grid.w; i++) |
351 | for (i = 1; i < col_count && x-x0 < grid.w; i++) |
350 | { |
352 | { |
351 | cell_x[i] = -1; |
353 | cell_x[i] = -1; |
352 | if (i >= scroll_x) |
354 | if (i >= grid.firstx) |
353 | { |
355 | { |
354 | { |
356 | { |
355 | if (!sel_moved || (is_x_changed(i))) { |
357 | //if (!sel_moved || (is_x_changed(i))) { |
356 | if (is_between(i,sel_x,sel_end_x)) bg_color = SEL_HEADER_CELL_COLOR; else bg_color = HEADER_CELL_COLOR; |
358 | if (is_between(i,sel_x,sel_end_x)) bg_color = HEADER_CELL_COLOR_ACTIVE; else bg_color = HEADER_CELL_COLOR; |
357 | kos_DrawBar(x-x0, 0, 1, grid.h, GRID_COLOR); |
359 | kos_DrawBar(x-x0, 0, 1, grid.h, GRID_COLOR); |
358 | DrawCell(x-x0+1, 0, cell_w[i]-1, cell_h[0], i+COL_HEAD_BUTTON, bg_color, cells[i][0], true); |
360 | DrawCell(x-x0+1, 0, cell_w[i]-1, cell_h[0], i+COL_HEAD_BUTTON, bg_color, cells[i][0], true); |
359 | } |
361 | //} |
360 | cell_x[i] = x - x0; |
362 | cell_x[i] = x - x0; |
361 | } |
363 | } |
362 | } |
364 | } |
363 | else |
365 | else |
364 | { |
366 | { |
Line 373... | Line 375... | ||
373 | ny = 1; |
375 | ny = 1; |
374 | cell_y[0] = 0; |
376 | cell_y[0] = 0; |
375 | for (i = 1; i < row_count && y-y0 < grid.h; i++) |
377 | for (i = 1; i < row_count && y-y0 < grid.h; i++) |
376 | { |
378 | { |
377 | cell_y[i] = -1; |
379 | cell_y[i] = -1; |
378 | if (i >= scroll_y) |
380 | if (i >= grid.firsty) |
379 | { |
381 | { |
380 | { |
382 | { |
381 | if (!sel_moved || (is_y_changed(i))) { |
383 | //if (!sel_moved || (is_y_changed(i))) { |
382 | if (is_between(i,sel_y,sel_end_y)) bg_color = SEL_HEADER_CELL_COLOR; else bg_color = HEADER_CELL_COLOR; |
384 | if (is_between(i,sel_y,sel_end_y)) bg_color = HEADER_CELL_COLOR_ACTIVE; else bg_color = HEADER_CELL_COLOR; |
383 | kos_DrawBar(0, y-y0, grid.w, 1, GRID_COLOR); |
385 | kos_DrawBar(0, y-y0, grid.w, 1, GRID_COLOR); |
384 | DrawCell(0, y-y0+1, cell_w[0], cell_h[i]-1, i+ROW_HEAD_BUTTON, bg_color, cells[0][i], true); |
386 | DrawCell(0, y-y0+1, cell_w[0], cell_h[i]-1, i+ROW_HEAD_BUTTON, bg_color, cells[0][i], true); |
385 | } |
387 | //} |
386 | cell_y[i] = y - y0; |
388 | cell_y[i] = y - y0; |
387 | } |
389 | } |
388 | } |
390 | } |
389 | else |
391 | else |
390 | { |
392 | { |
Line 394... | Line 396... | ||
394 | ny++; |
396 | ny++; |
395 | } |
397 | } |
Line 396... | Line 398... | ||
396 | 398 | ||
397 | // cells itself |
399 | // cells itself |
398 | y = cell_h[0]; |
400 | y = cell_h[0]; |
399 | for (i = scroll_y; i < ny; i++) |
401 | for (i = grid.firsty; i < ny; i++) |
400 | { |
402 | { |
401 | x = cell_w[0]; |
403 | x = cell_w[0]; |
402 | for (j = scroll_x; j < nx; j++) |
404 | for (j = grid.firstx; j < nx; j++) |
403 | { |
405 | { |
404 | if (i && j) //no need to draw headers one more |
406 | if (i && j) //no need to draw headers one more |
405 | { |
407 | { |
406 | bool draw_frame_selection = false; |
408 | bool draw_frame_selection = false; |
Line 415... | Line 417... | ||
415 | draw_frame_selection = true; |
417 | draw_frame_selection = true; |
416 | drag_x = x + cell_w[j] - 4; |
418 | drag_x = x + cell_w[j] - 4; |
417 | drag_y = y + cell_h[i] - 4; |
419 | drag_y = y + cell_h[i] - 4; |
418 | } |
420 | } |
419 | else { |
421 | else { |
420 | bg_color = SEL_CELL_COLOR; // selected but not main |
422 | bg_color = CELL_COLOR_ACTIVE; // selected but not main |
421 | } |
423 | } |
422 | } |
424 | } |
Line 423... | Line 425... | ||
423 | 425 | ||
424 | char *text; |
426 | char *text; |
Line 430... | Line 432... | ||
430 | else { |
432 | else { |
431 | text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]); |
433 | text = (values[j][i] && !display_formulas ? values[j][i] : cells[j][i]); |
432 | } |
434 | } |
Line 433... | Line 435... | ||
433 | 435 | ||
- | 436 | DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false); |
|
434 | DrawCell(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0, bg_color, text, false); |
437 | if (draw_frame_selection) { |
- | 438 | DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i], TEXT_COLOR); |
|
435 | if (draw_frame_selection) DrawSelectedFrame(x+1,y, cell_w[j]-1, cell_h[i], TEXT_COLOR); |
439 | } |
436 | else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0); |
440 | else if (error) kos_DrawRegion(x+1, y+1, cell_w[j]-1, cell_h[i]-1, 0xff0000, 0); |
437 | } |
441 | } |
438 | x += cell_w[j]; |
442 | x += cell_w[j]; |
439 | } |
443 | } |
Line 453... | Line 457... | ||
453 | 457 | ||
454 | x = cell_w[0]; |
458 | x = cell_w[0]; |
455 | x0 = 0; |
459 | x0 = 0; |
456 | for (i = 1; i < col_count && x - x0 + cell_w[i] < grid.w - 10; i++) |
460 | for (i = 1; i < col_count && x - x0 + cell_w[i] < grid.w - 10; i++) |
457 | { |
461 | { |
458 | if (i >= scroll_x) |
462 | if (i >= grid.firstx) |
459 | { |
463 | { |
460 | if (i >= size_id) |
464 | if (i >= size_id) |
461 | kos_DrawLine(x - x0, 0, x - x0, grid.h, 0, 1); |
465 | kos_DrawLine(x - x0, 0, x - x0, grid.h, 0, 1); |
462 | } |
466 | } |
Line 472... | Line 476... | ||
472 | 476 | ||
473 | y = cell_h[0]; |
477 | y = cell_h[0]; |
474 | y0 = 0; |
478 | y0 = 0; |
475 | for (i = 1; i < col_count && y - y0 + cell_h[i] < grid.h - 10; i++) |
479 | for (i = 1; i < col_count && y - y0 + cell_h[i] < grid.h - 10; i++) |
476 | { |
480 | { |
477 | if (i >= scroll_y) |
481 | if (i >= grid.firsty) |
478 | { |
482 | { |
479 | if (i >= size_id) |
483 | if (i >= size_id) |
480 | kos_DrawLine(0, y - y0, grid.w, y - y0, 0, 1); |
484 | kos_DrawLine(0, y - y0, grid.w, y - y0, 0, 1); |
481 | } |
485 | } |
Line 523... | Line 527... | ||
523 | { |
527 | { |
524 | kos_WindowRedrawStatus(1); |
528 | kos_WindowRedrawStatus(1); |
525 | kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION); |
529 | kos_DefineAndDrawWindow(110,40,WND_W,WND_H,0x73,0x40FFFFFF,0,0,(Dword)"Table v" TABLE_VERSION); |
526 | kos_WindowRedrawStatus(2); |
530 | kos_WindowRedrawStatus(2); |
Line -... | Line 531... | ||
- | 531 | ||
- | 532 | kos_GetSystemColors(&sc); |
|
527 | 533 | ||
528 | sProcessInfo info; |
534 | sProcessInfo info; |
529 | kos_ProcessInfo(&info, 0xFFFFFFFF); |
535 | kos_ProcessInfo(&info, 0xFFFFFFFF); |
530 | cWidth = info.processInfo.width - 9; |
536 | cWidth = info.processInfo.width - 9; |
Line 535... | Line 541... | ||
535 | grid.w = cWidth - SCROLL_SIZE - 1; |
541 | grid.w = cWidth - SCROLL_SIZE - 1; |
536 | grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE; |
542 | grid.h = cHeight - MENU_PANEL_HEIGHT - SCROLL_SIZE; |
Line 537... | Line 543... | ||
537 | 543 | ||
Line 538... | Line 544... | ||
538 | if (info.processInfo.status_window&0x04) return false; //draw nothing if window is rolled-up |
544 | if (info.processInfo.status_window&0x04) return false; //draw nothing if window is rolled-up |
539 | 545 | ||
Line 540... | Line 546... | ||
540 | if (grid.h < 100) { kos_ChangeWindow( -1, -1, -1, 180 ); return false; } |
546 | if (cWidth < 430) { kos_ChangeWindow( -1, -1, 450, -1 ); return false; } |
Line 541... | Line 547... | ||
541 | if (grid.w < 340) { kos_ChangeWindow( -1, -1, 350, -1 ); return false; } |
547 | if (cHeight < 250) { kos_ChangeWindow( -1, -1, -1, 300 ); return false; } |
542 | 548 | ||
Line 543... | Line 549... | ||
543 | sel_moved = 0; |
549 | sel_moved = 0; |
544 | 550 | ||
- | 551 | return true; |
|
Line 545... | Line -... | ||
545 | return true; |
- | |
546 | } |
- | |
547 | - | ||
548 | void draw_window() |
- | |
549 | { |
552 | } |
550 | 553 | ||
Line 551... | Line 554... | ||
551 | if (sel_end_move) sel_moved = 0; |
554 | void draw_window() |
Line -... | Line 555... | ||
- | 555 | { |
|
- | 556 | int panel_y = cHeight - MENU_PANEL_HEIGHT + 1; |
|
552 | 557 | ||
553 | panel_y = cHeight - MENU_PANEL_HEIGHT + 1; |
558 | kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, sc.work); |
554 | 559 | kos_WriteTextToWindow(3 + 1, panel_y + 14, 0x90, sc.work_text, (char*)sFilename, 0); |
|
Line 555... | Line 560... | ||
555 | kos_DrawBar(0, panel_y, cWidth, MENU_PANEL_HEIGHT-1, PANEL_BG_COLOR); |
560 | |
556 | kos_WriteTextToWindow(3 + 1, panel_y + 16, 0x80, 0x000000, (char*)sFilename, 0); |
561 | file_box.top = panel_y + 10; |
557 | 562 | ||
Line 558... | Line 563... | ||
558 | file_box.top = panel_y + 12; |
563 | #define BTX 230 |
559 | 564 | #define BTW 70 |
|
560 | //save |
565 | //save |
561 | kos_DefineButton(20 + 160, panel_y + 9, 60, 20, SAVE_BUTTON, 0xd0d0d0); |
566 | kos_DefineButton(BTX + 25, file_box.top, BTW, 21, SAVE_BUTTON, sc.work); |
562 | kos_WriteTextToWindow(22 + 160 + (60 - strlen(sSave) * 6) / 2, panel_y + 16, 0x80, 0x000000, (char*)sSave, 0); |
567 | kos_WriteTextToWindow(BTX + 25 + (BTW - strlen(sSave) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sSave, 0); |
Line 563... | Line 568... | ||
563 | 568 | ||
564 | //load |
569 | //load |
565 | kos_DefineButton(90 + 160, panel_y + 9, 60, 20, LOAD_BUTTON, 0xd0d0d0); |
570 | kos_DefineButton(BTX + 25+BTW+5, file_box.top, BTW, 21, LOAD_BUTTON, sc.work); |
566 | kos_WriteTextToWindow(92 + 160 + (60 - strlen(sLoad) * 6) / 2, panel_y + 16, 0x80, 0x000000, (char*)sLoad, 0); |
571 | kos_WriteTextToWindow(BTX + 25+BTW+5 + (BTW - strlen(sLoad) * 8) / 2, panel_y + 14, 0x90, sc.work_text, (char*)sLoad, 0); |
567 | 572 | ||
568 | //new (clean) |
573 | //new (clean) |
Line -... | Line 574... | ||
- | 574 | /* |
|
569 | /* |
575 | kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, sc.work); |
570 | kos_DefineButton(90 + 160 + 70, panel_y + 9, 60, 20, NEW_BUTTON, 0xd0d0d0); |
576 | kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, sc.work_text, (char*)sNew, strlen(sNew)); |
571 | kos_WriteTextToWindow(92 + 160 + 10 + 70, panel_y + 16, 0, 0x000000, (char*)sNew, strlen(sNew)); |
577 | */ |
Line 572... | Line 578... | ||
572 | */ |
578 | |
573 | 579 | if ((void*)edit_box_draw != NULL) |
|
574 | if ((void*)edit_box_draw != NULL) |
580 | { |
575 | { |
- | |
576 | if (is_edit) |
- | |
577 | edit_box_draw((DWORD)&cell_box); |
- | |
578 | edit_box_draw((DWORD)&file_box); |
- | |
579 | } |
- | |
Line 580... | Line 581... | ||
580 | 581 | if (is_edit) |
|
581 | draw_grid(); |
582 | edit_box_draw((DWORD)&cell_box); |
582 | sel_moved = 0; |
- | |
583 | } |
583 | edit_box_draw((DWORD)&file_box); |
584 | 584 | } |
|
585 | void process_mouse() |
585 | |
586 | { |
586 | if (sel_end_move) sel_moved = 0; |
587 | Dword mouse_btn, ckeys, shift, ctrl; |
587 | draw_grid(); |
588 | int mouse_x, mouse_y, i, dx = 0, dy = 0; |
588 | sel_moved = 0; |
589 | bool window_is_dragged=false; |
589 | } |
590 | 590 | ||
591 | edit_box_mouse((dword)&cell_box); |
591 | void process_mouse() |
Line 592... | Line 592... | ||
592 | edit_box_mouse((dword)&file_box); |
592 | { |
593 | 593 | Dword mouse_btn, ckeys, shift, ctrl; |
|
594 | int vert, hor; |
594 | |
595 | kos_GetScrollInfo(vert, hor); |
595 | int vert, hor; |
596 | 596 | kos_GetScrollInfo(vert, hor); |
|
597 | if (vert != 0) |
597 | if (vert != 0) |
598 | { |
598 | { |
599 | stop_edit(); |
599 | stop_edit(); |
Line 600... | Line 600... | ||
600 | scroll_y += vert; |
600 | grid.firsty += vert; |
601 | if (scroll_y<1) scroll_y=1; |
601 | if (grid.firsty<1) grid.firsty=1; |
602 | if (scroll_y>row_count-25) scroll_y=row_count-25; |
602 | if (grid.firsty>row_count-25) grid.firsty=row_count-25; |
603 | draw_grid(); |
603 | draw_grid(); |
604 | return; |
604 | return; |
605 | } |
605 | } |
606 | 606 | ||
- | 607 | if (!sel_moved && !size_state) //do not handle scrollbars when user selects cells |
|
- | 608 | { |
|
- | 609 | if (!scroll_h.delta2) scrollbar_v_mouse((DWORD)&scroll_v); |
|
- | 610 | if (scroll_v.position != grid.firsty-1) |
|
Line -... | Line 611... | ||
- | 611 | { |
|
607 | if (!sel_moved && !size_state) //do not handle scrollbars when user selects cells |
612 | grid.firsty = scroll_v.position + 1; |
608 | { |
613 | draw_grid(); |
609 | scrollbar_v_mouse((DWORD)&scroll_v); |
614 | } |
Line 610... | Line 615... | ||
610 | if (scroll_v.position != scroll_y-1) |
615 | |
Line 731... | Line 736... | ||
731 | fill_cells(sel_x, sel_y, sel_end_x, sel_end_y, old_end_x, old_end_y); |
736 | fill_cells(sel_x, sel_y, sel_end_x, sel_end_y, old_end_x, old_end_y); |
732 | } |
737 | } |
Line 733... | Line 738... | ||
733 | 738 | ||
734 | //sel_moved = (size_state == SIZE_SELECT && sel_x == sel_end_x && sel_y == sel_end_y && was_single_selection); |
739 | //sel_moved = (size_state == SIZE_SELECT && sel_x == sel_end_x && sel_y == sel_end_y && was_single_selection); |
735 | size_state = 0; |
740 | size_state = 0; |
736 | draw_window(); // все сдвинулось - надо обновиться |
741 | draw_grid(); // все сдвинулось - надо обновиться |
737 | return; |
742 | return; |
738 | } |
743 | } |
739 | if (size_state == SIZE_X && mouse_x != size_mouse_x) |
744 | if (size_state == SIZE_X && mouse_x != size_mouse_x) |
740 | { |
745 | { |
Line 829... | Line 834... | ||
829 | break; |
834 | break; |
830 | case 177: |
835 | case 177: |
831 | dy = 1; |
836 | dy = 1; |
832 | break; |
837 | break; |
833 | case 183: |
838 | case 183: |
834 | dy = ny - scroll_y-1; |
839 | dy = ny - grid.firsty-1; |
835 | break; |
840 | break; |
836 | case 184: |
841 | case 184: |
837 | dy = - (ny - scroll_y); |
842 | dy = - (ny - grid.firsty); |
838 | break; |
843 | break; |
839 | case 180: //home |
844 | case 180: //home |
840 | dx = -sel_x + 1; |
845 | dx = -sel_x + 1; |
841 | dy = 0; |
846 | dy = 0; |
842 | draw_grid(); |
847 | draw_grid(); |
843 | break; |
848 | break; |
844 | case 181: //end |
849 | case 181: //end |
845 | dx = col_count - (nx - scroll_x) - 1 - sel_x; |
850 | dx = col_count - (nx - grid.firstx) - 1 - sel_x; |
846 | dy = 0; |
851 | dy = 0; |
847 | draw_grid(); |
852 | draw_grid(); |
848 | break; |
853 | break; |
849 | case 27: // escape |
854 | case 27: // escape |
850 | cancel_edit(); |
855 | cancel_edit(); |
Line 872... | Line 877... | ||
872 | } |
877 | } |
873 | case 0x0D: // enter |
878 | case 0x0D: // enter |
874 | if (is_edit) |
879 | if (is_edit) |
875 | { |
880 | { |
876 | stop_edit(); |
881 | stop_edit(); |
877 | draw_window(); |
882 | draw_grid(); |
878 | } |
883 | } |
879 | break; |
884 | break; |
880 | case 22: // contol-v |
885 | case 22: // contol-v |
881 | { |
886 | { |
882 | if (ctrl) |
887 | if (ctrl) |
Line 1050... | Line 1055... | ||
1050 | draw_grid(); |
1055 | draw_grid(); |
1051 | } |
1056 | } |
1052 | } |
1057 | } |
1053 | } |
1058 | } |
Line 1054... | Line -... | ||
1054 | - | ||
1055 | 1059 | ||
1056 | void process_button() |
1060 | void process_button() |
1057 | { |
- | |
1058 | Dword mouse_btn, ckeys, shift, ctrl; |
- | |
1059 | int mouse_x, mouse_y, i, p, dx = 0, dy = 0; |
- | |
1060 | 1061 | { |
|
1061 | Dword button; |
1062 | Dword button; |
1062 | if (!kos_GetButtonID(button)) return; |
- | |
1063 | - | ||
1064 | // sprintf(debuf, "button %U", button); |
- | |
1065 | // rtlDebugOutString(debuf); |
- | |
1066 | 1063 | if (!kos_GetButtonID(button)) return; |
|
1067 | switch (button) |
1064 | switch (button) |
1068 | { |
1065 | { |
1069 | case 1: |
1066 | case 1: |
Line 1070... | Line 1067... | ||
1070 | kos_ExitApp(); |
1067 | kos_ExitApp(); |
1071 | 1068 | ||
1072 | case NEW_BUTTON: // clear the table |
1069 | case NEW_BUTTON: // clear the table |
1073 | reinit(); |
- | |
1074 | draw_window(); |
- | |
1075 | break; |
- | |
1076 | - | ||
1077 | case FILENAME_BUTTON: |
- | |
1078 | sel_moved = 1; |
- | |
1079 | stop_edit(); |
- | |
1080 | fn_edit = 1; |
- | |
1081 | strcpy(edit_text, fname); |
1070 | reinit(); |
Line 1082... | Line 1071... | ||
1082 | draw_window(); |
1071 | draw_grid(); |
1083 | break; |
1072 | break; |
1084 | - | ||
1085 | case SAVE_BUTTON: |
- | |
1086 | stop_edit(); |
1073 | |
1087 | if (SaveFile(fname)) { |
- | |
1088 | kos_DrawBar(320, panel_y + 16, cWidth - 320, 12, PANEL_BG_COLOR); |
1074 | case SAVE_BUTTON: |
Line 1089... | Line 1075... | ||
1089 | kos_WriteTextToWindow(320, panel_y + 16, 0x80, 0x000000, (char*)msg_save, 0); |
1075 | stop_edit(); |
1090 | } |
1076 | if (SaveFile(fname)) kos_AppRun("/sys/@notify", (char*)msg_save); |
1091 | break; |
1077 | break; |
1092 | - | ||
1093 | case LOAD_BUTTON: |
1078 | |
1094 | stop_edit(); |
1079 | case LOAD_BUTTON: |
1095 | int r = LoadFile(fname); |
- | |
1096 | kos_DrawBar(320, panel_y + 16, cWidth - 320, 12, PANEL_BG_COLOR); |
1080 | stop_edit(); |
1097 | char *result; |
1081 | int r = LoadFile(fname); |
1098 | if (r > 0) |
1082 | char *result; |
1099 | { |
1083 | if (r > 0) { |
1100 | calculate_values(); |
1084 | calculate_values(); |
1101 | sel_moved = 0; |
1085 | sel_moved = 0; |
1102 | draw_window(); |
1086 | draw_grid(); |
1103 | result = (char*)msg_load; |
1087 | result = (char*)msg_load; |
1104 | } |
1088 | } |
1105 | else if (r == -1) result = (char*)er_file_not_found; |
1089 | else if (r == -1) result = (char*)er_file_not_found; |
1106 | else if (r == -2) result = (char*)er_format; |
1090 | else if (r == -2) result = (char*)er_format; |
1107 | kos_WriteTextToWindow(320, panel_y + 16, 0x80, 0x000000, result, 0); |
1091 | kos_AppRun("/sys/@notify", result); |
1108 | break; |
1092 | break; |
Line 1123... | Line 1107... | ||
1123 | sel_end_x = col_count - 1; |
1107 | sel_end_x = col_count - 1; |
1124 | stop_edit(); |
1108 | stop_edit(); |
1125 | draw_grid(); |
1109 | draw_grid(); |
1126 | return; |
1110 | return; |
1127 | } |
1111 | } |
1128 | - | ||
1129 | } |
1112 | } |
Line 1130... | Line 1113... | ||
1130 | 1113 | ||
1131 | void kos_Main() |
1114 | void kos_Main() |
1132 | { |
1115 | { |
1133 | kos_InitHeap(); |
1116 | kos_InitHeap(); |
1134 | load_edit_box(); |
1117 | load_edit_box(); |
1135 | init(); |
1118 | init(); |
1136 | kos_SetMaskForEvents(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
- | |
1137 | 1119 | kos_SetMaskForEvents(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
|
1138 | for (;;) |
1120 | for (;;) |
1139 | { |
1121 | { |
1140 | switch (kos_WaitForEvent()) |
1122 | switch (kos_WaitForEvent()) |
1141 | { |
1123 | { |