Subversion Repositories Kolibri OS

Rev

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