Rev 8911 | Rev 9473 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8584 | leency | 1 | /* |
7957 | leency | 2 | Quark Code Edit |
7921 | leency | 3 | Author: Kiril Lipatov aka Leency |
4 | Licence: GPLv2 |
||
5 | |||
6 | The core components of this app are: |
||
8584 | leency | 7 | 1. textbuf: page data |
8 | 2. list: text grid with keyboard and mouse events |
||
9 | 3. lines: the mas of pointers for each line start |
||
10 | 4. selection |
||
7921 | leency | 11 | */ |
12 | |||
8749 | leency | 13 | #define MEMSIZE 50*1024 |
7921 | leency | 14 | |
15 | //===================================================// |
||
16 | // // |
||
17 | // LIB // |
||
18 | // // |
||
19 | //===================================================// |
||
20 | |||
21 | #include "../lib/io.h" |
||
22 | #include "../lib/gui.h" |
||
23 | #include "../lib/list_box.h" |
||
24 | #include "../lib/draw_buf.h" |
||
25 | #include "../lib/events.h" |
||
26 | #include "../lib/array.h" |
||
27 | #include "../lib/clipboard.h" |
||
28 | #include "../lib/math.h" |
||
29 | |||
30 | #include "../lib/obj/box_lib.h" |
||
31 | #include "../lib/obj/libini.h" |
||
32 | #include "../lib/obj/libimg.h" |
||
33 | #include "../lib/obj/iconv.h" |
||
34 | #include "../lib/obj/proc_lib.h" |
||
35 | |||
36 | #include "../lib/patterns/simple_open_dialog.h" |
||
37 | #include "../lib/patterns/toolbar_button.h" |
||
38 | |||
39 | //===================================================// |
||
40 | // // |
||
41 | // INTERNAL INCLUDES // |
||
42 | // // |
||
43 | //===================================================// |
||
44 | |||
45 | proc_info Form; |
||
46 | llist list; |
||
8584 | leency | 47 | scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee, |
48 | 0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
||
7921 | leency | 49 | |
50 | #define TOOLBAR_H 38 |
||
51 | #define TOOLBAR_ICON_WIDTH 24 |
||
52 | #define TOOLBAR_ICON_HEIGHT 22 |
||
53 | #define STATUSBAR_H 15 |
||
54 | #define TAB_H 20 |
||
55 | |||
56 | int user_encoding; |
||
57 | int real_encoding = CH_CP866; |
||
58 | int curcol_scheme; |
||
59 | int font_size; |
||
60 | |||
7975 | leency | 61 | bool search_next = false; |
7945 | leency | 62 | |
7921 | leency | 63 | #include "data.h" |
8584 | leency | 64 | #include "textbuf.h" |
65 | #include "selection.h" |
||
7941 | leency | 66 | #include "search.h" |
7921 | leency | 67 | #include "prepare_page.h" |
68 | |||
69 | //===================================================// |
||
70 | // // |
||
71 | // DATA // |
||
72 | // // |
||
73 | //===================================================// |
||
74 | |||
75 | char title[4196]; |
||
76 | |||
77 | int reopenin_mx, |
||
78 | theme_mx, |
||
79 | burger_mx, |
||
80 | search_mx; |
||
81 | |||
82 | enum { |
||
83 | CHANGE_CHARSET=12, |
||
84 | REOPEN_IN_APP=1, |
||
85 | COLOR_SCHEME=8, |
||
86 | RMB_MENU, |
||
87 | BTN_FIND_NEXT, |
||
8584 | leency | 88 | BTN_FIND_PREVIOUS, |
7924 | leency | 89 | BTN_FIND_CLOSE, |
90 | BTN_CHANGE_CHARSET |
||
7921 | leency | 91 | }; |
92 | |||
93 | dword menu_id; |
||
94 | |||
95 | EVENTS button; |
||
96 | EVENTS key; |
||
97 | |||
98 | //===================================================// |
||
99 | // // |
||
100 | // CODE // |
||
101 | // // |
||
102 | //===================================================// |
||
103 | |||
104 | void InitDlls() |
||
105 | { |
||
106 | load_dll(boxlib, #box_lib_init, 0); |
||
107 | load_dll(libimg, #libimg_init, 1); |
||
108 | load_dll(libini, #lib_init, 1); |
||
109 | load_dll(iconv_lib, #iconv_open, 0); |
||
110 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
111 | OpenDialog_init stdcall (#o_dialog); |
||
112 | } |
||
113 | |||
114 | void LoadFileFromDocPack() |
||
115 | { |
||
8584 | leency | 116 | dword bufsize = atoi(#file_path + 1) + 20; |
7921 | leency | 117 | dword bufpointer = malloc(bufsize); |
118 | |||
119 | ESDWORD[bufpointer+0] = 0; |
||
120 | ESDWORD[bufpointer+4] = 8; |
||
7924 | leency | 121 | IpcSetArea(bufpointer, bufsize); |
7921 | leency | 122 | |
123 | SetEventMask(EVM_IPC); |
||
124 | if (@WaitEventTimeout(200) != evIPC) { |
||
125 | notify("'IPC FAIL'E"); |
||
8584 | leency | 126 | } else { |
127 | textbuf.set(bufpointer + 16, ESDWORD[bufpointer+12]); |
||
7921 | leency | 128 | } |
8584 | leency | 129 | free(bufpointer); |
130 | file_path[0]='\0'; |
||
131 | sprintf(#title, "#DOCPACK - %s", #short_app_name); |
||
7921 | leency | 132 | } |
133 | |||
134 | void main() |
||
8584 | leency | 135 | { |
7921 | leency | 136 | InitDlls(); |
137 | LoadIniSettings(); |
||
138 | EventSetColorScheme(curcol_scheme); |
||
8584 | leency | 139 | if (file_path[0] == '*') { |
7921 | leency | 140 | LoadFileFromDocPack(); |
141 | } else { |
||
8584 | leency | 142 | if (streq(#file_path,"-new")) {Form.left+=40;Form.top+=40;} |
143 | LoadFile(#file_path); |
||
7921 | leency | 144 | } |
145 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
||
8584 | leency | 146 | loop() switch(@WaitEventTimeout(400)) |
7921 | leency | 147 | { |
8584 | leency | 148 | case evMouse: HandleMouseEvent(); break; |
149 | case evKey: HandleKeyEvent(); break; |
||
150 | case evButton: HandleButtonEvent(); break; |
||
151 | case evReDraw: draw_window(); break; |
||
152 | default: DrawStatusBar(" "); //clean DrawStatusBar text with delay |
||
7921 | leency | 153 | } |
154 | } |
||
155 | |||
156 | //===================================================// |
||
157 | // // |
||
158 | // EVENT HANDLERS // |
||
159 | // // |
||
160 | //===================================================// |
||
161 | |||
162 | void HandleButtonEvent() |
||
163 | { |
||
164 | int btn = GetButtonID(); |
||
165 | if (btn==1) { |
||
166 | SaveIniSettings(); |
||
167 | ExitProcess(); |
||
168 | } |
||
169 | button.press(btn); |
||
170 | switch(btn-10) |
||
171 | { |
||
8584 | leency | 172 | case BTN_FIND_NEXT: EventSearchNext(); break; |
173 | case BTN_FIND_PREVIOUS: EventSearchPrevious(); break; |
||
174 | case BTN_FIND_CLOSE: search.hide(); break; |
||
175 | case BTN_CHANGE_CHARSET: EventShowCharsetsList(); break; |
||
7921 | leency | 176 | } |
177 | } |
||
178 | |||
179 | void HandleKeyEvent() |
||
180 | { |
||
181 | GetKeys(); |
||
182 | |||
7941 | leency | 183 | switch (key_scancode) |
184 | { |
||
185 | case SCAN_CODE_ESC: |
||
186 | search.hide(); |
||
187 | return; |
||
188 | case SCAN_CODE_ENTER: |
||
8584 | leency | 189 | if (! search_box.flags & ed_focus) break; |
7941 | leency | 190 | case SCAN_CODE_F3: |
8584 | leency | 191 | if (key_modifier & KEY_LSHIFT) { |
192 | EventSearchPrevious(); |
||
193 | } else { |
||
194 | EventSearchNext(); |
||
195 | } |
||
7941 | leency | 196 | return; |
197 | } |
||
198 | |||
199 | if (search.edit_key()) return; |
||
200 | |||
7921 | leency | 201 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
202 | if (key.press(ECTRL + key_scancode)) return; |
||
203 | switch (key_scancode) |
||
204 | { |
||
8584 | leency | 205 | case SCAN_CODE_KEY_A: EventSelectAllText(); return; |
206 | case SCAN_CODE_KEY_C: EventCopy(); return; |
||
8749 | leency | 207 | //case SCAN_CODE_KEY_X: EventCut(); return; |
208 | //case SCAN_CODE_KEY_V: EventPaste(); return; |
||
8584 | leency | 209 | case SCAN_CODE_UP: EventMagnifyPlus(); return; |
210 | case SCAN_CODE_DOWN: EventMagnifyMinus(); return; |
||
211 | case SCAN_CODE_TAB: EventShowCharsetsList(); return; |
||
212 | case SCAN_CODE_KEY_F: search.show(); return; |
||
7921 | leency | 213 | } |
214 | } |
||
7941 | leency | 215 | |
216 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) { |
||
217 | selection.set_start(); |
||
7924 | leency | 218 | } else { |
8749 | leency | 219 | //EventInsertCharIntoText(); |
7941 | leency | 220 | selection.cancel(); |
7921 | leency | 221 | } |
7941 | leency | 222 | |
8584 | leency | 223 | if (key_scancode == SCAN_CODE_LEFT) && (!list.cur_x) && (list.cur_y) list.column_max = lines.len(list.cur_y-1); |
7941 | leency | 224 | if (list.ProcessKey(key_scancode)) { |
225 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end(); |
||
226 | DrawPage(); |
||
7945 | leency | 227 | return; |
7941 | leency | 228 | } |
7921 | leency | 229 | } |
230 | |||
231 | void HandleMouseEvent() |
||
232 | { |
||
233 | mouse.get(); |
||
234 | list.wheel_size = 7; |
||
235 | if (list.MouseScroll(mouse.vert)) { |
||
7924 | leency | 236 | DrawPage(); |
8584 | leency | 237 | return; |
7921 | leency | 238 | } |
239 | if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) { |
||
240 | if (mouse.key&MOUSE_LEFT) { |
||
241 | |||
242 | GetKeyModifier(); |
||
243 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) { |
||
7924 | leency | 244 | if (mouse.down) selection.set_start(); |
7921 | leency | 245 | list.ProcessMouse(mouse.x, mouse.y); |
246 | if (mouse.up) selection.set_end(); |
||
247 | DrawPage(); |
||
248 | return; |
||
249 | } |
||
250 | |||
7941 | leency | 251 | //as we have lines of variable width, we need to recalculate column_max |
252 | list.column_max = lines.len(mouse.y - list.y / list.item_h + list.first); |
||
253 | |||
7921 | leency | 254 | list.ProcessMouse(mouse.x, mouse.y); |
7941 | leency | 255 | |
7921 | leency | 256 | if (mouse.down) { |
7924 | leency | 257 | selection.cancel(); |
7921 | leency | 258 | selection.set_start(); |
8584 | leency | 259 | } |
7921 | leency | 260 | selection.set_end(); |
261 | DrawPage(); |
||
262 | } |
||
263 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) { |
||
264 | EventShowRmbMenu(); |
||
265 | } |
||
266 | return; |
||
8584 | leency | 267 | } |
7921 | leency | 268 | scrollbar_v_mouse (#scroll); |
269 | if (list.first != scroll.position) { |
||
270 | list.first = scroll.position; |
||
8584 | leency | 271 | DrawPage(); |
7921 | leency | 272 | } |
273 | search.edit_mouse(); |
||
274 | } |
||
275 | |||
276 | //===================================================// |
||
277 | // // |
||
278 | // EVENTS // |
||
279 | // // |
||
280 | //===================================================// |
||
281 | |||
282 | bool EventSearchNext() |
||
283 | { |
||
8584 | leency | 284 | if (search.find_next(list.first+1)) { |
285 | list.first = EAX; |
||
7921 | leency | 286 | list.CheckDoesValuesOkey(); |
7975 | leency | 287 | search_next = true; |
8584 | leency | 288 | DrawPage(); |
7921 | leency | 289 | } |
290 | } |
||
291 | |||
8584 | leency | 292 | bool EventSearchPrevious() |
293 | { |
||
294 | if (search.find_prior(list.first)) { |
||
295 | list.first = EAX; |
||
296 | list.CheckDoesValuesOkey(); |
||
297 | search_next = true; |
||
298 | DrawPage(); |
||
299 | } |
||
300 | } |
||
301 | |||
7921 | leency | 302 | void EventOpenDialog() |
303 | { |
||
304 | OpenDialog_start stdcall (#o_dialog); |
||
305 | if (o_dialog.status) { |
||
306 | LoadFile(#openfile_path); |
||
307 | ParseAndPaint(); |
||
308 | } |
||
309 | } |
||
310 | |||
311 | void EventShowFileInfo() |
||
312 | { |
||
313 | char ss_param[4096]; |
||
8584 | leency | 314 | if (!file_path) return; |
7921 | leency | 315 | strcpy(#ss_param, "-p "); |
8584 | leency | 316 | strcpy(#ss_param+3, #file_path); |
7921 | leency | 317 | RunProgram("/sys/File managers/Eolite", #ss_param); |
318 | } |
||
319 | |||
320 | void EventMagnifyMinus() |
||
321 | { |
||
8584 | leency | 322 | font_size = math.max(0, font_size-1); |
323 | SetFontSize(font_size); |
||
7921 | leency | 324 | ParseAndPaint(); |
325 | } |
||
326 | |||
327 | void EventMagnifyPlus() |
||
328 | { |
||
8584 | leency | 329 | font_size = math.min(3, font_size+1); |
330 | SetFontSize(font_size); |
||
7921 | leency | 331 | ParseAndPaint(); |
332 | } |
||
333 | |||
334 | void EventShowCharsetsList() |
||
335 | { |
||
336 | menu_id = CHANGE_CHARSET; |
||
8584 | leency | 337 | open_lmenu(Form.cwidth-4, Form.cheight - 6, MENU_BOT_RIGHT, |
338 | user_encoding+1, |
||
7921 | leency | 339 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO"); |
340 | } |
||
341 | |||
342 | void EventShowReopenMenu() |
||
343 | { |
||
344 | menu_id = REOPEN_IN_APP; |
||
8749 | leency | 345 | open_lmenu(reopenin_mx, 29, MENU_TOP_LEFT, NULL, |
346 | "Tinypad\nCodeEdit\nWebView\nFB2Read\nHexView\nOther"); |
||
7921 | leency | 347 | } |
348 | |||
349 | void EventShowThemesList() |
||
350 | { |
||
351 | menu_id = COLOR_SCHEME; |
||
8749 | leency | 352 | open_lmenu(theme_mx, 29, MENU_TOP_LEFT, |
7921 | leency | 353 | curcol_scheme+1, #color_scheme_names); |
354 | } |
||
355 | |||
356 | void EventShowRmbMenu() |
||
357 | { |
||
358 | menu_id = RMB_MENU; |
||
8020 | leency | 359 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu); |
7921 | leency | 360 | } |
361 | |||
362 | |||
363 | void EventSetColorScheme(dword _setn) |
||
364 | { |
||
365 | curcol_scheme = _setn; |
||
7960 | leency | 366 | theme.bg = color_schemes[curcol_scheme*6]; |
367 | theme.text = color_schemes[curcol_scheme*6+1]; |
||
7921 | leency | 368 | scroll.bckg_col = theme.bg; |
7960 | leency | 369 | scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*6+2]; |
370 | selection.color = color_schemes[curcol_scheme*6+3]; |
||
371 | theme.cursor = color_schemes[curcol_scheme*6+4]; |
||
372 | theme.found = color_schemes[curcol_scheme*6+5]; |
||
7921 | leency | 373 | if (list.count) ParseAndPaint(); |
374 | } |
||
375 | |||
376 | void EventChangeCharset(dword id) |
||
377 | { |
||
8584 | leency | 378 | if (file_path[0]=='\0') return; |
7921 | leency | 379 | user_encoding = id; |
8584 | leency | 380 | LoadFile(#file_path); |
7921 | leency | 381 | ParseAndPaint(); |
382 | draw_window(); |
||
383 | } |
||
384 | |||
385 | void EventOpenFileInOtherApp(dword _id) |
||
386 | { |
||
387 | dword app; |
||
388 | byte open_param[4096]; |
||
389 | switch(_id) { |
||
390 | case 0: app = "/sys/tinypad"; break; |
||
8749 | leency | 391 | case 1: app = "/sys/develop/cedit"; break; |
7921 | leency | 392 | case 2: app = "/sys/network/webview"; break; |
393 | case 3: app = "/sys/fb2read"; break; |
||
394 | case 4: app = "/sys/develop/heed"; break; |
||
395 | case 5: open_param[0]='~'; |
||
8584 | leency | 396 | strcpy(#open_param+1,#file_path); |
7921 | leency | 397 | RunProgram("/sys/@open", #open_param); |
398 | return; |
||
399 | } |
||
8584 | leency | 400 | RunProgram(app, #file_path); |
7921 | leency | 401 | } |
402 | |||
403 | void EventMenuClick() |
||
404 | { |
||
405 | dword click_id = get_menu_click(); |
||
406 | |||
407 | if (click_id) && (menu_id) switch(menu_id) |
||
408 | { |
||
409 | case CHANGE_CHARSET: EventChangeCharset(click_id-1); break; |
||
410 | case REOPEN_IN_APP: EventOpenFileInOtherApp(click_id-1); break; |
||
411 | case COLOR_SCHEME: EventSetColorScheme(click_id-1); break; |
||
412 | case RMB_MENU: EventRbmMenuClick(click_id-1); break; |
||
413 | default: notify("'Error: wrong menu number'E"); |
||
414 | } |
||
415 | menu_id = NULL; |
||
416 | } |
||
417 | |||
418 | void EventClickSearch() |
||
419 | { |
||
420 | if (search.visible) { |
||
421 | search.hide(); |
||
422 | } else { |
||
423 | search.show(); |
||
424 | } |
||
425 | } |
||
426 | |||
8749 | leency | 427 | /* |
7921 | leency | 428 | void EventInsertCharIntoText() |
429 | { |
||
8584 | leency | 430 | dword i; |
7921 | leency | 431 | dword cursor_pos = lines.get(list.cur_y) + list.cur_x; |
432 | |||
433 | switch(key_scancode) |
||
434 | { |
||
435 | case SCAN_CODE_DOWN: |
||
436 | case SCAN_CODE_UP: |
||
8584 | leency | 437 | case SCAN_CODE_LEFT: |
438 | case SCAN_CODE_RIGHT: |
||
7921 | leency | 439 | case SCAN_CODE_HOME: |
440 | case SCAN_CODE_END: |
||
441 | case SCAN_CODE_PGUP: |
||
442 | case SCAN_CODE_PGDN: |
||
8584 | leency | 443 | return; |
7921 | leency | 444 | case SCAN_CODE_BS: |
8584 | leency | 445 | if (selection.is_active()) { |
446 | EventDeleteSelectedText(); |
||
447 | } else { |
||
448 | if (!list.cur_x) && (!list.cur_y) break; |
||
449 | textbuf.del(cursor_pos-1, cursor_pos); |
||
450 | if (!list.cur_x) && (list.cur_y) { |
||
451 | list.column_max = lines.len(list.cur_y-1); |
||
452 | list.KeyLeft(); |
||
453 | } |
||
454 | list.KeyLeft(); |
||
455 | } |
||
456 | ParseAndPaint(); |
||
457 | return; |
||
7921 | leency | 458 | case SCAN_CODE_DEL: |
8584 | leency | 459 | if (selection.is_active()) { |
460 | EventDeleteSelectedText(); |
||
461 | } else { |
||
462 | if (cursor_pos < textbuf.p + textbuf.len) textbuf.del(cursor_pos, cursor_pos+1); |
||
463 | } |
||
464 | ParseAndPaint(); |
||
465 | return; |
||
466 | default: |
||
467 | if (selection.is_active()) { |
||
468 | EventDeleteSelectedText(); |
||
469 | Parse(); |
||
470 | } |
||
471 | cursor_pos = lines.get(list.cur_y) + list.cur_x; |
||
472 | textbuf.insert_ch(cursor_pos, key_ascii); |
||
473 | list.KeyRight(); |
||
474 | Parse(); |
||
475 | list.column_max = lines.len(list.cur_y); |
||
476 | if (key_scancode == SCAN_CODE_ENTER) list.KeyRight(); |
||
477 | DrawPage(); |
||
7921 | leency | 478 | } |
479 | } |
||
8749 | leency | 480 | */ |
7921 | leency | 481 | |
482 | void EventRbmMenuClick(dword id) |
||
483 | { |
||
484 | switch(id) { |
||
8749 | leency | 485 | case 0: EventCopy(); break; |
486 | case 1: EventRevealInFolder(); break; |
||
487 | case 2: EventCopyFilePath(); break; |
||
7921 | leency | 488 | } |
489 | } |
||
490 | |||
8584 | leency | 491 | void EventSelectAllText() |
7921 | leency | 492 | { |
8584 | leency | 493 | selection.select_all(); |
494 | DrawPage(); |
||
7921 | leency | 495 | } |
496 | |||
497 | void EventCopy() |
||
498 | { |
||
499 | char copy_status_text[32]; |
||
500 | |||
501 | dword copy_buf; |
||
502 | dword copy_len; |
||
503 | dword copy_start; |
||
504 | dword copy_end; |
||
505 | |||
506 | if (selection.is_active()) { |
||
507 | copy_start = selection.start_offset; |
||
508 | copy_end = selection.end_offset; |
||
509 | if (copy_start > copy_end) copy_start >< copy_end; |
||
510 | } else { |
||
511 | copy_start = lines.get(list.cur_y); |
||
512 | copy_end = lines.get(list.cur_y+1); |
||
513 | } |
||
514 | copy_len = copy_end - copy_start; |
||
515 | copy_buf = malloc(copy_len + 2); |
||
516 | strncpy(copy_buf, copy_start, copy_len); |
||
517 | ESBYTE[copy_buf+copy_len] = '\0'; |
||
518 | Clipboard__CopyText(copy_buf); |
||
519 | free(copy_buf); |
||
520 | |||
521 | sprintf(#copy_status_text, #copied_chars, copy_len); |
||
522 | DrawStatusBar(#copy_status_text); |
||
523 | } |
||
524 | |||
8749 | leency | 525 | /* |
8584 | leency | 526 | void EventCut() |
527 | { |
||
528 | if (!selection.is_active()) { |
||
529 | selection.start_offset = lines.get(list.cur_y); |
||
530 | selection.end_offset = lines.get(list.cur_y+1); |
||
531 | } |
||
532 | EventCopy(); |
||
533 | EventDeleteSelectedText(); |
||
534 | ParseAndPaint(); |
||
535 | } |
||
536 | |||
7921 | leency | 537 | void EventPaste() |
538 | { |
||
8584 | leency | 539 | int i; |
540 | dword buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1); |
||
541 | if (selection.is_active()) { |
||
542 | EventDeleteSelectedText(); |
||
543 | } |
||
544 | cursor_pos = lines.get(list.cur_y) + list.cur_x; |
||
545 | textbuf.insert_str(cursor_pos, buf+12, ESDWORD[buf]-12); |
||
546 | for (i=0; i |
||
547 | ParseAndPaint(); |
||
7921 | leency | 548 | } |
549 | |||
8584 | leency | 550 | void EventDeleteSelectedText() |
551 | { |
||
552 | textbuf.del(selection.start_offset, selection.end_offset); |
||
553 | list.cur_x = math.min(selection.start_x, selection.end_x); |
||
554 | list.cur_y = math.min(selection.start_y, selection.end_y); |
||
555 | selection.cancel(); |
||
556 | } |
||
8749 | leency | 557 | */ |
8584 | leency | 558 | |
7921 | leency | 559 | void EventRevealInFolder() |
560 | { |
||
8584 | leency | 561 | RunProgram("/sys/File managers/Eolite", #file_path); |
7921 | leency | 562 | } |
563 | |||
564 | void EventCopyFilePath() |
||
565 | { |
||
566 | char copy_status_text[32]; |
||
8584 | leency | 567 | Clipboard__CopyText(#file_path); |
568 | sprintf(#copy_status_text, #copied_chars, strlen(#file_path)); |
||
7921 | leency | 569 | DrawStatusBar(#copy_status_text); |
570 | } |
||
571 | |||
572 | //===================================================// |
||
573 | // // |
||
574 | // DRAWS AND OTHER FUNCS // |
||
575 | // // |
||
576 | //===================================================// |
||
577 | |||
578 | void EncodeToDos() |
||
579 | { |
||
580 | real_encoding = user_encoding; |
||
581 | |||
582 | // Autodetecting charset |
||
583 | if (real_encoding == CH_AUTO) { |
||
584 | real_encoding = CH_CP866; |
||
8584 | leency | 585 | if (strstr(textbuf.p, "\208\190")) real_encoding = CH_UTF8; |
7921 | leency | 586 | else { |
8584 | leency | 587 | if (chrnum(textbuf.p, '\246')>5) |
588 | || (strstr(textbuf.p, "\239\240")) real_encoding = CH_CP1251; |
||
7921 | leency | 589 | } |
590 | } |
||
7957 | leency | 591 | if (real_encoding != CH_CP866) { |
8584 | leency | 592 | ChangeCharset(real_encoding, "CP866", textbuf.p); |
7957 | leency | 593 | } |
7921 | leency | 594 | } |
595 | |||
8584 | leency | 596 | void LoadFile(dword f_path) |
7921 | leency | 597 | { |
598 | if (ESBYTE[f_path]) { |
||
8584 | leency | 599 | strcpy(#file_path, f_path); |
600 | if (!io.read(#file_path)) goto NO_DATA; |
||
601 | textbuf.set(io.buffer_data, io.FILES_SIZE); |
||
602 | free(io.buffer_data); |
||
603 | sprintf(#title, "%s - %s", #file_path, #short_app_name); |
||
604 | EncodeToDos(); |
||
7921 | leency | 605 | } |
606 | else { |
||
607 | NO_DATA: |
||
8584 | leency | 608 | textbuf.set(#intro, sizeof(intro)-1); |
609 | strcpy(#title, #short_app_name); |
||
7921 | leency | 610 | } |
611 | list.ClearList(); |
||
612 | } |
||
613 | |||
8584 | leency | 614 | int TopBarBt(dword _event, _hotkey, char image_id, int x, pressed) { |
7921 | leency | 615 | if (_hotkey) key.add_n(_hotkey, _event); |
616 | return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed); |
||
617 | } |
||
618 | |||
619 | |||
620 | void DrawToolbar() |
||
621 | { |
||
8584 | leency | 622 | #define GAP_S 26+5 |
623 | #define GAP_B 26+18 |
||
7921 | leency | 624 | incn x; |
625 | bool thema = false; |
||
626 | bool reopa = false; |
||
627 | |||
628 | if (menu_id == COLOR_SCHEME) thema = true; |
||
629 | if (menu_id == REOPEN_IN_APP) reopa = true; |
||
630 | |||
631 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work); |
||
632 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph); |
||
8584 | leency | 633 | |
634 | x.set(-GAP_S+8); |
||
635 | TopBarBt(#EventOpenDialog, ECTRL+SCAN_CODE_KEY_O, 0, x.inc(GAP_S), false); |
||
636 | TopBarBt(#EventShowFileInfo, ECTRL+SCAN_CODE_KEY_I, 10, x.inc(GAP_S), false); |
||
637 | TopBarBt(#EventMagnifyMinus, ECTRL+SCAN_CODE_MINUS, 33, x.inc(GAP_B), false); |
||
638 | TopBarBt(#EventMagnifyPlus, ECTRL+SCAN_CODE_PLUS, 32, x.inc(GAP_S), false); |
||
639 | TopBarBt(#EventClickSearch, ECTRL+SCAN_CODE_KEY_F, 49, x.inc(GAP_B), search.visible); search_mx = EAX; |
||
8749 | leency | 640 | TopBarBt(#EventShowThemesList, NULL, 40, x.inc(GAP_B), thema); theme_mx = EAX; |
641 | TopBarBt(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(GAP_S), reopa); reopenin_mx = EAX; |
||
7921 | leency | 642 | } |
643 | |||
644 | void DrawStatusBar(dword _in_text) |
||
645 | { |
||
646 | static char status_text[64]; |
||
8946 | leency | 647 | if (Form.status_window&ROLLED_UP) return; |
7921 | leency | 648 | if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text)); |
649 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph); |
||
650 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); |
||
651 | WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text); |
||
8584 | leency | 652 | if (file_path[0]) { |
7924 | leency | 653 | WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4, |
654 | 60, sc.work_text, real_encoding*10+#charsets); |
||
655 | DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1, |
||
656 | 60, 12, BTN_CHANGE_CHARSET+10); |
||
657 | } |
||
7921 | leency | 658 | } |
659 | |||
660 | void draw_window() |
||
661 | { |
||
662 | int old_w = list.w; |
||
8584 | leency | 663 | if (CheckActiveProcess(Form.ID)) EventMenuClick(); |
7921 | leency | 664 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
665 | GetProcessInfo(#Form, SelfInfo); |
||
666 | sc.get(); |
||
8946 | leency | 667 | if (Form.status_window&ROLLED_UP) return; |
7975 | leency | 668 | if (Form.width < 450) { MoveSize(OLD,OLD,450,OLD); return; } |
7921 | leency | 669 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
8584 | leency | 670 | |
7921 | leency | 671 | button.init(40); |
672 | key.init(40); |
||
673 | |||
8584 | leency | 674 | SetFontSize(font_size); |
7921 | leency | 675 | |
676 | if ((list.w == old_w) && (list.count)) { |
||
8584 | leency | 677 | DrawPage(); |
7921 | leency | 678 | } else { |
679 | ParseAndPaint(); |
||
680 | } |
||
681 | |||
682 | DrawToolbar(); |
||
8584 | leency | 683 | DrawSearch(); |
7921 | leency | 684 | DrawStatusBar(NULL); |
685 | } |
||
686 | |||
8584 | leency | 687 | bool DrawSearch() |
7921 | leency | 688 | { |
8584 | leency | 689 | char matches[30]; |
690 | int _y = Form.cheight - SEARCH_H - STATUSBAR_H; |
||
691 | if (!search.visible) return false; |
||
692 | DrawBar(0, _y, Form.cwidth, 1, sc.work_graph); |
||
693 | DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work); |
||
7921 | leency | 694 | |
8584 | leency | 695 | search_box.top = _y + 6; |
696 | search_box.width = math.min(Form.width - 200, 150); |
||
697 | |||
698 | DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph); |
||
699 | |||
700 | edit_box_draw stdcall(#search_box); |
||
701 | |||
702 | DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 30, |
||
703 | TOOLBAR_ICON_HEIGHT+1, BTN_FIND_PREVIOUS+10, sc.work_light, sc.work_text, "<"); |
||
704 | DrawCaptButton(search_box.left+search_box.width+44, search_box.top-1, 30, |
||
705 | TOOLBAR_ICON_HEIGHT+1, BTN_FIND_NEXT+10, sc.work_light, sc.work_text, ">"); |
||
706 | |||
707 | sprintf(#matches, T_MATCHES, search.found.count); |
||
708 | WriteTextWithBg(search_box.left+search_box.width+14+85, |
||
709 | search_box.top+3, 0xD0, sc.work_text, #matches, sc.work); |
||
710 | |||
711 | DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1, |
||
712 | TOOLBAR_ICON_HEIGHT+1, BTN_FIND_CLOSE+10); |
||
713 | WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x"); |
||
714 | return true; |
||
7921 | leency | 715 | } |
716 | |||
8584 | leency | 717 | void SetFontSize(char _size) |
7921 | leency | 718 | { |
719 | font_size = _size; |
||
8584 | leency | 720 | if (font_size == 0) list.SetFont( 6, 9, 00001000b); |
721 | if (font_size == 1) list.SetFont( 8, 14, 00011000b); |
||
722 | if (font_size == 2) list.SetFont(2*6, 2*9, 00001001b); |
||
723 | if (font_size == 3) list.SetFont(2*8, 2*14-2, 00011001b); |
||
7921 | leency | 724 | list.item_w = list.font_w; |
725 | list.horisontal_selelection = true; |
||
8584 | leency | 726 | list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, |
727 | Form.cheight - TOOLBAR_H - calc(search.visible * SEARCH_H) - STATUSBAR_H /*- TAB_H*/, |
||
8911 | leency | 728 | math.round(list.font_h * 1.3)); |
7921 | leency | 729 | }"); |