Subversion Repositories Kolibri OS

Rev

Rev 8584 | Rev 8911 | 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 50*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_ESC:
  186.                         search.hide();
  187.                         return;
  188.                 case SCAN_CODE_ENTER:
  189.                         if (! search_box.flags & ed_focus) break;
  190.                 case SCAN_CODE_F3:
  191.                         if (key_modifier & KEY_LSHIFT) {
  192.                                 EventSearchPrevious();
  193.                         } else {
  194.                                 EventSearchNext();
  195.                         }
  196.                         return;
  197.         }
  198.  
  199.         if (search.edit_key()) return;
  200.  
  201.         if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
  202.                 if (key.press(ECTRL + key_scancode)) return;
  203.                 switch (key_scancode)
  204.                 {
  205.                         case SCAN_CODE_KEY_A: EventSelectAllText();    return;
  206.                         case SCAN_CODE_KEY_C: EventCopy();             return;
  207.                         //case SCAN_CODE_KEY_X: EventCut();              return;
  208.                         //case SCAN_CODE_KEY_V: EventPaste();            return;
  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;
  213.                 }
  214.         }
  215.  
  216.         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  217.                 selection.set_start();
  218.         } else {
  219.                 //EventInsertCharIntoText();
  220.                 selection.cancel();
  221.         }
  222.  
  223.         if (key_scancode == SCAN_CODE_LEFT) && (!list.cur_x) && (list.cur_y) list.column_max = lines.len(list.cur_y-1);
  224.         if (list.ProcessKey(key_scancode)) {
  225.                 if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
  226.                 DrawPage();
  227.                 return;
  228.         }
  229. }
  230.  
  231. void HandleMouseEvent()
  232. {
  233.         mouse.get();
  234.         list.wheel_size = 7;
  235.         if (list.MouseScroll(mouse.vert)) {
  236.                 DrawPage();
  237.                 return;
  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) {
  244.                                 if (mouse.down) selection.set_start();
  245.                                 list.ProcessMouse(mouse.x, mouse.y);
  246.                                 if (mouse.up) selection.set_end();
  247.                                 DrawPage();
  248.                                 return;
  249.                         }
  250.  
  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.  
  254.                         list.ProcessMouse(mouse.x, mouse.y);
  255.  
  256.                         if (mouse.down) {
  257.                                 selection.cancel();
  258.                                 selection.set_start();
  259.                         }
  260.                         selection.set_end();
  261.                         DrawPage();
  262.                 }
  263.                 if (mouse.key&MOUSE_RIGHT) && (mouse.up) {
  264.                         EventShowRmbMenu();
  265.                 }
  266.                 return;
  267.         }
  268.         scrollbar_v_mouse (#scroll);
  269.         if (list.first != scroll.position) {
  270.                 list.first = scroll.position;
  271.                 DrawPage();
  272.         }
  273.         search.edit_mouse();
  274. }
  275.  
  276. //===================================================//
  277. //                                                   //
  278. //                      EVENTS                       //
  279. //                                                   //
  280. //===================================================//
  281.  
  282. bool EventSearchNext()
  283. {
  284.         if (search.find_next(list.first+1)) {
  285.                 list.first = EAX;
  286.                 list.CheckDoesValuesOkey();
  287.                 search_next = true;
  288.                 DrawPage();
  289.         }
  290. }
  291.  
  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.  
  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];
  314.         if (!file_path) return;
  315.         strcpy(#ss_param, "-p ");
  316.         strcpy(#ss_param+3, #file_path);
  317.         RunProgram("/sys/File managers/Eolite", #ss_param);
  318. }
  319.  
  320. void EventMagnifyMinus()
  321. {
  322.         font_size = math.max(0, font_size-1);
  323.         SetFontSize(font_size);
  324.         ParseAndPaint();
  325. }
  326.  
  327. void EventMagnifyPlus()
  328. {
  329.         font_size = math.min(3, font_size+1);
  330.         SetFontSize(font_size);
  331.         ParseAndPaint();
  332. }
  333.  
  334. void EventShowCharsetsList()
  335. {
  336.         menu_id = CHANGE_CHARSET;
  337.         open_lmenu(Form.cwidth-4, Form.cheight - 6, MENU_BOT_RIGHT,
  338.                 user_encoding+1,
  339.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
  340. }
  341.  
  342. void EventShowReopenMenu()
  343. {
  344.         menu_id = REOPEN_IN_APP;
  345.         open_lmenu(reopenin_mx, 29, MENU_TOP_LEFT, NULL,
  346.                 "Tinypad\nCodeEdit\nWebView\nFB2Read\nHexView\nOther");
  347. }
  348.  
  349. void EventShowThemesList()
  350. {
  351.         menu_id = COLOR_SCHEME;
  352.         open_lmenu(theme_mx, 29, MENU_TOP_LEFT,
  353.                 curcol_scheme+1, #color_scheme_names);
  354. }
  355.  
  356. void EventShowRmbMenu()
  357. {
  358.         menu_id = RMB_MENU;
  359.         open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu);
  360. }
  361.  
  362.  
  363. void EventSetColorScheme(dword _setn)
  364. {
  365.         curcol_scheme = _setn;
  366.         theme.bg      = color_schemes[curcol_scheme*6];
  367.         theme.text    = color_schemes[curcol_scheme*6+1];
  368.         scroll.bckg_col = theme.bg;
  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];
  373.         if (list.count) ParseAndPaint();
  374. }
  375.  
  376. void EventChangeCharset(dword id)
  377. {
  378.         if (file_path[0]=='\0') return;
  379.         user_encoding = id;
  380.         LoadFile(#file_path);
  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;
  391.                 case 1: app = "/sys/develop/cedit"; break;
  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]='~';
  396.                         strcpy(#open_param+1,#file_path);
  397.                         RunProgram("/sys/@open", #open_param);
  398.                         return;
  399.         }
  400.         RunProgram(app, #file_path);
  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.  
  427. /*
  428. void EventInsertCharIntoText()
  429. {
  430.         dword i;
  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:
  437.                 case SCAN_CODE_LEFT:
  438.                 case SCAN_CODE_RIGHT:
  439.                 case SCAN_CODE_HOME:
  440.                 case SCAN_CODE_END:
  441.                 case SCAN_CODE_PGUP:
  442.                 case SCAN_CODE_PGDN:
  443.                         return;
  444.                 case SCAN_CODE_BS:
  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;
  458.                 case SCAN_CODE_DEL:
  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();
  478.         }
  479. }
  480. */
  481.  
  482. void EventRbmMenuClick(dword id)
  483. {
  484.         switch(id) {
  485.                 case 0: EventCopy(); break;
  486.                 case 1: EventRevealInFolder(); break;
  487.                 case 2: EventCopyFilePath(); break;
  488.         }
  489. }
  490.  
  491. void EventSelectAllText()
  492. {
  493.         selection.select_all();
  494.         DrawPage();
  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.  
  525. /*
  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.  
  537. void EventPaste()
  538. {
  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<ESDWORD[buf]-12; i++) list.KeyRight();
  547.         ParseAndPaint();
  548. }
  549.  
  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. }
  557. */
  558.  
  559. void EventRevealInFolder()
  560. {
  561.         RunProgram("/sys/File managers/Eolite", #file_path);
  562. }
  563.  
  564. void EventCopyFilePath()
  565. {
  566.         char copy_status_text[32];
  567.         Clipboard__CopyText(#file_path);
  568.         sprintf(#copy_status_text, #copied_chars, strlen(#file_path));
  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;
  585.                 if (strstr(textbuf.p, "\208\190")) real_encoding = CH_UTF8;
  586.                 else {
  587.                         if (chrnum(textbuf.p, '\246')>5)
  588.                         || (strstr(textbuf.p, "\239\240")) real_encoding = CH_CP1251;
  589.                 }
  590.         }
  591.         if (real_encoding != CH_CP866) {
  592.                 ChangeCharset(real_encoding, "CP866", textbuf.p);
  593.         }
  594. }
  595.  
  596. void LoadFile(dword f_path)
  597. {
  598.         if (ESBYTE[f_path]) {
  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();
  605.         }
  606.         else {
  607.                 NO_DATA:
  608.                 textbuf.set(#intro, sizeof(intro)-1);
  609.                 strcpy(#title, #short_app_name);
  610.         }
  611.         list.ClearList();
  612. }
  613.  
  614. int TopBarBt(dword _event, _hotkey, char image_id, int x, pressed) {
  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. {
  622.         #define GAP_S 26+5
  623.         #define GAP_B 26+18
  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);
  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;
  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;
  642. }
  643.  
  644. void DrawStatusBar(dword _in_text)
  645. {
  646.         static char status_text[64];
  647.         if (Form.status_window>2) return;
  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);
  652.         if (file_path[0]) {
  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.         }
  658. }
  659.  
  660. void draw_window()
  661. {
  662.         int old_w = list.w;
  663.         if (CheckActiveProcess(Form.ID)) EventMenuClick();
  664.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
  665.         GetProcessInfo(#Form, SelfInfo);
  666.         sc.get();
  667.         if (Form.status_window>2) return;
  668.         if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
  669.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  670.  
  671.         button.init(40);
  672.         key.init(40);
  673.  
  674.         SetFontSize(font_size);
  675.  
  676.         if ((list.w == old_w) && (list.count)) {
  677.                 DrawPage();
  678.         } else {
  679.                 ParseAndPaint();
  680.         }
  681.  
  682.         DrawToolbar();
  683.         DrawSearch();
  684.         DrawStatusBar(NULL);
  685. }
  686.  
  687. bool DrawSearch()
  688. {
  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);
  694.  
  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;
  715. }
  716.  
  717. void SetFontSize(char _size)
  718. {
  719.         font_size = _size;
  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);
  724.         list.item_w = list.font_w;
  725.         list.horisontal_selelection = true;
  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*/,
  728.                 math.round(list.font_h * 1.4));
  729. }