Subversion Repositories Kolibri OS

Rev

Rev 8389 | Rev 8749 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.         Quark Code Edit
  3.         Author: Kiril Lipatov aka Leency
  4.         Licence: GPLv2
  5.  
  6.         The core components of this app are:
  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
  11. */
  12.  
  13. #define MEMSIZE 60*1024
  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;
  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};
  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.  
  61. bool search_next = false;
  62.  
  63. #include "data.h"
  64. #include "textbuf.h"
  65. #include "selection.h"
  66. #include "search.h"
  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,
  88.         BTN_FIND_PREVIOUS,
  89.         BTN_FIND_CLOSE,
  90.         BTN_CHANGE_CHARSET
  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. {
  116.         dword bufsize = atoi(#file_path + 1) + 20;
  117.         dword bufpointer = malloc(bufsize);
  118.  
  119.         ESDWORD[bufpointer+0] = 0;
  120.         ESDWORD[bufpointer+4] = 8;
  121.         IpcSetArea(bufpointer, bufsize);
  122.  
  123.         SetEventMask(EVM_IPC);
  124.         if (@WaitEventTimeout(200) != evIPC) {
  125.                 notify("'IPC FAIL'E");
  126.         } else {
  127.                 textbuf.set(bufpointer + 16, ESDWORD[bufpointer+12]);
  128.         }
  129.         free(bufpointer);
  130.         file_path[0]='\0';
  131.         sprintf(#title, "#DOCPACK - %s", #short_app_name);
  132. }
  133.  
  134. void main()
  135. {
  136.         InitDlls();
  137.         LoadIniSettings();
  138.         EventSetColorScheme(curcol_scheme);
  139.         if (file_path[0] == '*') {
  140.                 LoadFileFromDocPack();
  141.         } else {
  142.                 if (streq(#file_path,"-new")) {Form.left+=40;Form.top+=40;}
  143.                 LoadFile(#file_path);
  144.         }
  145.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  146.         loop() switch(@WaitEventTimeout(400))
  147.         {
  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
  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.         {
  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;
  176.         }
  177. }
  178.  
  179. void HandleKeyEvent()
  180. {
  181.         GetKeys();
  182.  
  183.         switch (key_scancode)
  184.         {
  185.                 case SCAN_CODE_F1:
  186.                         EventShowInfo();
  187.                         return;
  188.                 case SCAN_CODE_ESC:
  189.                         search.hide();
  190.                         return;
  191.                 case SCAN_CODE_ENTER:
  192.                         if (! search_box.flags & ed_focus) break;
  193.                 case SCAN_CODE_F3:
  194.                         if (key_modifier & KEY_LSHIFT) {
  195.                                 EventSearchPrevious();
  196.                         } else {
  197.                                 EventSearchNext();
  198.                         }
  199.                         return;
  200.         }
  201.  
  202.         if (search.edit_key()) return;
  203.  
  204.         if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
  205.                 if (key.press(ECTRL + key_scancode)) return;
  206.                 switch (key_scancode)
  207.                 {
  208.                         case SCAN_CODE_KEY_A: EventSelectAllText();    return;
  209.                         case SCAN_CODE_KEY_X: EventCut();              return;
  210.                         case SCAN_CODE_KEY_C: EventCopy();             return;
  211.                         case SCAN_CODE_KEY_V: EventPaste();            return;
  212.                         case SCAN_CODE_UP:    EventMagnifyPlus();      return;
  213.                         case SCAN_CODE_DOWN:  EventMagnifyMinus();     return;
  214.                         case SCAN_CODE_TAB:   EventShowCharsetsList(); return;
  215.                         case SCAN_CODE_KEY_F: search.show();           return;
  216.                 }
  217.         }
  218.  
  219.         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  220.                 selection.set_start();
  221.         } else {
  222.                 EventInsertCharIntoText();
  223.                 selection.cancel();
  224.         }
  225.  
  226.         if (key_scancode == SCAN_CODE_LEFT) && (!list.cur_x) && (list.cur_y) list.column_max = lines.len(list.cur_y-1);
  227.         if (list.ProcessKey(key_scancode)) {
  228.                 if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
  229.                 DrawPage();
  230.                 return;
  231.         }
  232. }
  233.  
  234. void HandleMouseEvent()
  235. {
  236.         mouse.get();
  237.         list.wheel_size = 7;
  238.         if (list.MouseScroll(mouse.vert)) {
  239.                 DrawPage();
  240.                 return;
  241.         }
  242.         if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) {
  243.                 if (mouse.key&MOUSE_LEFT) {
  244.  
  245.                         GetKeyModifier();
  246.                         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  247.                                 if (mouse.down) selection.set_start();
  248.                                 list.ProcessMouse(mouse.x, mouse.y);
  249.                                 if (mouse.up) selection.set_end();
  250.                                 DrawPage();
  251.                                 return;
  252.                         }
  253.  
  254.                         //as we have lines of variable width, we need to recalculate column_max
  255.                         list.column_max = lines.len(mouse.y - list.y / list.item_h + list.first);
  256.  
  257.                         list.ProcessMouse(mouse.x, mouse.y);
  258.  
  259.                         if (mouse.down) {
  260.                                 selection.cancel();
  261.                                 selection.set_start();
  262.                         }
  263.                         selection.set_end();
  264.                         DrawPage();
  265.                 }
  266.                 if (mouse.key&MOUSE_RIGHT) && (mouse.up) {
  267.                         EventShowRmbMenu();
  268.                 }
  269.                 return;
  270.         }
  271.         scrollbar_v_mouse (#scroll);
  272.         if (list.first != scroll.position) {
  273.                 list.first = scroll.position;
  274.                 DrawPage();
  275.         }
  276.         search.edit_mouse();
  277. }
  278.  
  279. //===================================================//
  280. //                                                   //
  281. //                      EVENTS                       //
  282. //                                                   //
  283. //===================================================//
  284.  
  285. bool EventSearchNext()
  286. {
  287.         if (search.find_next(list.first+1)) {
  288.                 list.first = EAX;
  289.                 list.CheckDoesValuesOkey();
  290.                 search_next = true;
  291.                 DrawPage();
  292.         }
  293. }
  294.  
  295. bool EventSearchPrevious()
  296. {
  297.         if (search.find_prior(list.first)) {
  298.                 list.first = EAX;
  299.                 list.CheckDoesValuesOkey();
  300.                 search_next = true;
  301.                 DrawPage();
  302.         }
  303. }
  304.  
  305. void EventNewFile()
  306. {
  307.         RunProgram(#program_path, "-new");
  308. }
  309.  
  310. void EventOpenDialog()
  311. {
  312.         OpenDialog_start stdcall (#o_dialog);
  313.         if (o_dialog.status) {
  314.                 LoadFile(#openfile_path);
  315.                 ParseAndPaint();
  316.         }
  317. }
  318.  
  319. void EventSave()
  320. {
  321.         int res;
  322.         char backy_param[4096];
  323.         io.dir.make("/tmp0/1/quark_backups");
  324.         sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #file_path);
  325.         RunProgram("/sys/develop/backy", #backy_param);
  326.         if (! WriteFile(0, textbuf.len, textbuf.p, #file_path) ) {
  327.                 notify(FILE_SAVED_WELL);
  328.         } else {
  329.                 notify(FILE_NOT_SAVED);
  330.         }
  331. }
  332.  
  333. void EventShowFileInfo()
  334. {
  335.         char ss_param[4096];
  336.         if (!file_path) return;
  337.         strcpy(#ss_param, "-p ");
  338.         strcpy(#ss_param+3, #file_path);
  339.         RunProgram("/sys/File managers/Eolite", #ss_param);
  340. }
  341.  
  342. void EventMagnifyMinus()
  343. {
  344.         font_size = math.max(0, font_size-1);
  345.         SetFontSize(font_size);
  346.         ParseAndPaint();
  347. }
  348.  
  349. void EventMagnifyPlus()
  350. {
  351.         font_size = math.min(3, font_size+1);
  352.         SetFontSize(font_size);
  353.         ParseAndPaint();
  354. }
  355.  
  356. void EventShowCharsetsList()
  357. {
  358.         menu_id = CHANGE_CHARSET;
  359.         open_lmenu(Form.cwidth-4, Form.cheight - 6, MENU_BOT_RIGHT,
  360.                 user_encoding+1,
  361.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
  362. }
  363.  
  364. void EventShowReopenMenu()
  365. {
  366.         menu_id = REOPEN_IN_APP;
  367.         open_lmenu(reopenin_mx + 23, 29, MENU_TOP_RIGHT, NULL,
  368.                 "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
  369. }
  370.  
  371. void EventShowThemesList()
  372. {
  373.         menu_id = COLOR_SCHEME;
  374.         open_lmenu(theme_mx + 23, 29, MENU_TOP_RIGHT,
  375.                 curcol_scheme+1, #color_scheme_names);
  376. }
  377.  
  378. void EventShowRmbMenu()
  379. {
  380.         menu_id = RMB_MENU;
  381.         open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu);
  382. }
  383.  
  384.  
  385. void EventSetColorScheme(dword _setn)
  386. {
  387.         curcol_scheme = _setn;
  388.         theme.bg      = color_schemes[curcol_scheme*6];
  389.         theme.text    = color_schemes[curcol_scheme*6+1];
  390.         scroll.bckg_col = theme.bg;
  391.         scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*6+2];
  392.         selection.color = color_schemes[curcol_scheme*6+3];
  393.         theme.cursor    = color_schemes[curcol_scheme*6+4];
  394.         theme.found     = color_schemes[curcol_scheme*6+5];
  395.         if (list.count) ParseAndPaint();
  396. }
  397.  
  398.  
  399. void EventShowInfo() {
  400.         notify(#about);
  401. }
  402.  
  403. void EventChangeCharset(dword id)
  404. {
  405.         if (file_path[0]=='\0') return;
  406.         user_encoding = id;
  407.         LoadFile(#file_path);
  408.         ParseAndPaint();
  409.         draw_window();
  410. }
  411.  
  412. void EventOpenFileInOtherApp(dword _id)
  413. {
  414.         dword app;
  415.         byte open_param[4096];
  416.         switch(_id) {
  417.                 case 0: app = "/sys/tinypad"; break;
  418.                 case 1: app = "/sys/develop/t_edit"; break;
  419.                 case 2: app = "/sys/network/webview"; break;
  420.                 case 3: app = "/sys/fb2read"; break;
  421.                 case 4: app = "/sys/develop/heed"; break;
  422.                 case 5: open_param[0]='~';
  423.                         strcpy(#open_param+1,#file_path);
  424.                         RunProgram("/sys/@open", #open_param);
  425.                         return;
  426.         }
  427.         RunProgram(app, #file_path);
  428. }
  429.  
  430. void EventMenuClick()
  431. {
  432.         dword click_id = get_menu_click();
  433.  
  434.         if (click_id) && (menu_id) switch(menu_id)
  435.         {
  436.                 case CHANGE_CHARSET: EventChangeCharset(click_id-1); break;
  437.                 case REOPEN_IN_APP:  EventOpenFileInOtherApp(click_id-1); break;
  438.                 case COLOR_SCHEME:   EventSetColorScheme(click_id-1); break;
  439.                 case RMB_MENU:       EventRbmMenuClick(click_id-1); break;
  440.                 default: notify("'Error: wrong menu number'E");
  441.         }
  442.         menu_id = NULL;
  443. }
  444.  
  445. void EventClickSearch()
  446. {
  447.         if (search.visible) {
  448.                 search.hide();
  449.         } else {
  450.                 search.show();
  451.         }
  452. }
  453.  
  454. void EventInsertCharIntoText()
  455. {
  456.         dword i;
  457.         dword cursor_pos = lines.get(list.cur_y) + list.cur_x;
  458.  
  459.         switch(key_scancode)
  460.         {
  461.                 case SCAN_CODE_DOWN:
  462.                 case SCAN_CODE_UP:
  463.                 case SCAN_CODE_LEFT:
  464.                 case SCAN_CODE_RIGHT:
  465.                 case SCAN_CODE_HOME:
  466.                 case SCAN_CODE_END:
  467.                 case SCAN_CODE_PGUP:
  468.                 case SCAN_CODE_PGDN:
  469.                         return;
  470.                 case SCAN_CODE_BS:
  471.                         if (selection.is_active()) {
  472.                                 EventDeleteSelectedText();
  473.                         } else {
  474.                                 if (!list.cur_x) && (!list.cur_y) break;
  475.                                 textbuf.del(cursor_pos-1, cursor_pos);
  476.                                 if (!list.cur_x) && (list.cur_y) {
  477.                                         list.column_max = lines.len(list.cur_y-1);
  478.                                         list.KeyLeft();
  479.                                 }
  480.                                 list.KeyLeft();
  481.                         }
  482.                         ParseAndPaint();
  483.                         return;
  484.                 case SCAN_CODE_DEL:
  485.                         if (selection.is_active()) {
  486.                                 EventDeleteSelectedText();
  487.                         } else {
  488.                                 if (cursor_pos < textbuf.p + textbuf.len) textbuf.del(cursor_pos, cursor_pos+1);
  489.                         }
  490.                         ParseAndPaint();
  491.                         return;
  492.                 default:
  493.                         if (selection.is_active()) {
  494.                                 EventDeleteSelectedText();
  495.                                 Parse();
  496.                         }
  497.                         cursor_pos = lines.get(list.cur_y) + list.cur_x;
  498.                         textbuf.insert_ch(cursor_pos, key_ascii);
  499.                         list.KeyRight();
  500.                         Parse();
  501.                         list.column_max = lines.len(list.cur_y);
  502.                         if (key_scancode == SCAN_CODE_ENTER) list.KeyRight();
  503.                         DrawPage();
  504.         }
  505. }
  506.  
  507. void EventOpenSysfuncs()
  508. {
  509.         if (RunProgram("/sys/docpack", "f") <= 0) {
  510.                 notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E");
  511.         }
  512. }
  513.  
  514. void EventOpenPipet()
  515. {
  516.         RunProgram("/sys/develop/pipet", NULL);
  517. }
  518.  
  519. void EventRbmMenuClick(dword id)
  520. {
  521.         switch(id) {
  522.                 case 0: EventCut(); break;
  523.                 case 1: EventCopy(); break;
  524.                 case 2: EventPaste(); break;
  525.                 case 3: EventRevealInFolder(); break;
  526.                 case 4: EventCopyFilePath(); break;
  527.         }
  528. }
  529.  
  530. void EventSelectAllText()
  531. {
  532.         selection.select_all();
  533.         DrawPage();
  534. }
  535.  
  536. void EventCopy()
  537. {
  538.         char copy_status_text[32];
  539.  
  540.         dword copy_buf;
  541.         dword copy_len;
  542.         dword copy_start;
  543.         dword copy_end;
  544.  
  545.         if (selection.is_active()) {
  546.                 copy_start = selection.start_offset;
  547.                 copy_end = selection.end_offset;
  548.                 if (copy_start > copy_end) copy_start >< copy_end;
  549.         } else {
  550.                 copy_start = lines.get(list.cur_y);
  551.                 copy_end = lines.get(list.cur_y+1);
  552.         }
  553.         copy_len = copy_end - copy_start;
  554.         copy_buf = malloc(copy_len + 2);
  555.         strncpy(copy_buf, copy_start, copy_len);
  556.         ESBYTE[copy_buf+copy_len] = '\0';
  557.         Clipboard__CopyText(copy_buf);
  558.         free(copy_buf);
  559.  
  560.         sprintf(#copy_status_text, #copied_chars, copy_len);
  561.         DrawStatusBar(#copy_status_text);
  562. }
  563.  
  564. void EventCut()
  565. {
  566.         if (!selection.is_active()) {
  567.                 selection.start_offset = lines.get(list.cur_y);
  568.                 selection.end_offset = lines.get(list.cur_y+1);
  569.         }
  570.         EventCopy();
  571.         EventDeleteSelectedText();
  572.         ParseAndPaint();
  573. }
  574.  
  575. void EventPaste()
  576. {
  577.         int i;
  578.         dword buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  579.         if (selection.is_active()) {
  580.                 EventDeleteSelectedText();
  581.         }
  582.         cursor_pos = lines.get(list.cur_y) + list.cur_x;
  583.         textbuf.insert_str(cursor_pos, buf+12, ESDWORD[buf]-12);
  584.         for (i=0; i<ESDWORD[buf]-12; i++) list.KeyRight();
  585.         ParseAndPaint();
  586. }
  587.  
  588. void EventDeleteSelectedText()
  589. {
  590.         textbuf.del(selection.start_offset, selection.end_offset);
  591.         list.cur_x = math.min(selection.start_x, selection.end_x);
  592.         list.cur_y = math.min(selection.start_y, selection.end_y);
  593.         selection.cancel();
  594. }
  595.  
  596. void EventRevealInFolder()
  597. {
  598.         RunProgram("/sys/File managers/Eolite", #file_path);
  599. }
  600.  
  601. void EventCopyFilePath()
  602. {
  603.         char copy_status_text[32];
  604.         Clipboard__CopyText(#file_path);
  605.         sprintf(#copy_status_text, #copied_chars, strlen(#file_path));
  606.         DrawStatusBar(#copy_status_text);
  607. }
  608.  
  609. //===================================================//
  610. //                                                   //
  611. //               DRAWS AND OTHER FUNCS               //
  612. //                                                   //
  613. //===================================================//
  614.  
  615. void EncodeToDos()
  616. {
  617.         real_encoding = user_encoding;
  618.  
  619.         // Autodetecting charset
  620.         if (real_encoding == CH_AUTO) {
  621.                 real_encoding = CH_CP866;
  622.                 if (strstr(textbuf.p, "\208\190")) real_encoding = CH_UTF8;
  623.                 else {
  624.                         if (chrnum(textbuf.p, '\246')>5)
  625.                         || (strstr(textbuf.p, "\239\240")) real_encoding = CH_CP1251;
  626.                 }
  627.         }
  628.         if (real_encoding != CH_CP866) {
  629.                 ChangeCharset(real_encoding, "CP866", textbuf.p);
  630.         }
  631. }
  632.  
  633. void LoadFile(dword f_path)
  634. {
  635.         if (ESBYTE[f_path]) {
  636.                 strcpy(#file_path, f_path);
  637.                 if (!io.read(#file_path)) goto NO_DATA;
  638.                 textbuf.set(io.buffer_data, io.FILES_SIZE);
  639.                 free(io.buffer_data);
  640.                 sprintf(#title, "%s - %s", #file_path, #short_app_name);
  641.                 EncodeToDos();
  642.         }
  643.         else {
  644.                 NO_DATA:
  645.                 textbuf.set(#intro, sizeof(intro)-1);
  646.                 strcpy(#title, #short_app_name);
  647.         }
  648.         list.ClearList();
  649. }
  650.  
  651. int TopBarBt(dword _event, _hotkey, char image_id, int x, pressed) {
  652.         if (_hotkey) key.add_n(_hotkey, _event);
  653.         return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
  654. }
  655.  
  656.  
  657. void DrawToolbar()
  658. {
  659.         #define GAP_S 26+5
  660.         #define GAP_B 26+18
  661.         incn x;
  662.         bool thema = false;
  663.         bool reopa = false;
  664.  
  665.         if (menu_id == COLOR_SCHEME) thema = true;
  666.         if (menu_id == REOPEN_IN_APP) reopa = true;
  667.  
  668.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
  669.         DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
  670.  
  671.         x.set(-GAP_S+8);
  672.         TopBarBt(#EventNewFile,        ECTRL+SCAN_CODE_KEY_N, 2,  x.inc(GAP_S), false);
  673.         TopBarBt(#EventOpenDialog,     ECTRL+SCAN_CODE_KEY_O, 0,  x.inc(GAP_S), false);
  674.         TopBarBt(#EventSave,           ECTRL+SCAN_CODE_KEY_S, 5,  x.inc(GAP_S), false);
  675.         TopBarBt(#EventShowFileInfo,   ECTRL+SCAN_CODE_KEY_I, 10, x.inc(GAP_S), false);
  676.         TopBarBt(#EventMagnifyMinus,   ECTRL+SCAN_CODE_MINUS, 33, x.inc(GAP_B),   false);
  677.         TopBarBt(#EventMagnifyPlus,    ECTRL+SCAN_CODE_PLUS,  32, x.inc(GAP_S), false);
  678.         TopBarBt(#EventClickSearch,    ECTRL+SCAN_CODE_KEY_F, 49, x.inc(GAP_B),   search.visible);  search_mx = EAX;
  679.         x.set(Form.cwidth-4);
  680.         TopBarBt(#EventShowInfo,       NULL,                  -1, x.inc(-GAP_S), false); burger_mx = EAX;
  681.         TopBarBt(#EventShowThemesList, NULL,                  40, x.inc(-GAP_B), thema); theme_mx = EAX;
  682.         TopBarBt(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-GAP_S), reopa); reopenin_mx = EAX;
  683.         TopBarBt(#EventOpenSysfuncs,   NULL,                  18, x.inc(-GAP_S), false);
  684.         TopBarBt(#EventOpenPipet,      NULL,                  39, x.inc(-GAP_S), false);
  685. }
  686.  
  687. void DrawStatusBar(dword _in_text)
  688. {
  689.         static char status_text[64];
  690.         if (Form.status_window>2) return;
  691.         if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
  692.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
  693.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
  694.         WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
  695.         if (file_path[0]) {
  696.                 WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
  697.                         60, sc.work_text, real_encoding*10+#charsets);
  698.                 DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
  699.                         60, 12, BTN_CHANGE_CHARSET+10);
  700.         }
  701. }
  702.  
  703. void draw_window()
  704. {
  705.         int old_w = list.w;
  706.         if (CheckActiveProcess(Form.ID)) EventMenuClick();
  707.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
  708.         GetProcessInfo(#Form, SelfInfo);
  709.         sc.get();
  710.         if (Form.status_window>2) return;
  711.         if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
  712.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  713.  
  714.         button.init(40);
  715.         key.init(40);
  716.  
  717.         SetFontSize(font_size);
  718.  
  719.         if ((list.w == old_w) && (list.count)) {
  720.                 DrawPage();
  721.         } else {
  722.                 ParseAndPaint();
  723.         }
  724.  
  725.         DrawToolbar();
  726.         DrawSearch();
  727.         DrawStatusBar(NULL);
  728. }
  729.  
  730. bool DrawSearch()
  731. {
  732.         char matches[30];
  733.         int _y = Form.cheight - SEARCH_H - STATUSBAR_H;
  734.         if (!search.visible) return false;
  735.         DrawBar(0, _y, Form.cwidth, 1, sc.work_graph);
  736.         DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work);
  737.  
  738.         search_box.top = _y + 6;
  739.         search_box.width = math.min(Form.width - 200, 150);
  740.  
  741.         DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
  742.  
  743.         edit_box_draw stdcall(#search_box);
  744.  
  745.         DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 30,
  746.                 TOOLBAR_ICON_HEIGHT+1, BTN_FIND_PREVIOUS+10, sc.work_light, sc.work_text, "<");
  747.         DrawCaptButton(search_box.left+search_box.width+44, search_box.top-1, 30,
  748.                 TOOLBAR_ICON_HEIGHT+1, BTN_FIND_NEXT+10, sc.work_light, sc.work_text, ">");
  749.  
  750.         sprintf(#matches, T_MATCHES, search.found.count);
  751.         WriteTextWithBg(search_box.left+search_box.width+14+85,
  752.                 search_box.top+3, 0xD0, sc.work_text, #matches, sc.work);
  753.  
  754.         DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1,
  755.                 TOOLBAR_ICON_HEIGHT+1, BTN_FIND_CLOSE+10);
  756.         WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
  757.         return true;
  758. }
  759.  
  760. void SetFontSize(char _size)
  761. {
  762.         font_size = _size;
  763.         if (font_size == 0) list.SetFont(  6,      9, 00001000b);
  764.         if (font_size == 1) list.SetFont(  8,     14, 00011000b);
  765.         if (font_size == 2) list.SetFont(2*6,    2*9, 00001001b);
  766.         if (font_size == 3) list.SetFont(2*8, 2*14-2, 00011001b);
  767.         list.item_w = list.font_w;
  768.         list.horisontal_selelection = true;
  769.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
  770.                 Form.cheight - TOOLBAR_H - calc(search.visible * SEARCH_H) - STATUSBAR_H /*- TAB_H*/,
  771.                 math.round(list.font_h * 1.4));
  772. }