Subversion Repositories Kolibri OS

Rev

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