Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.         Quark Code Edit v0.2
  3.         Author: Kiril Lipatov aka Leency
  4.         Licence: GPLv2
  5.  
  6.         The core components of this app are:
  7.                 1. list: text grid with keyboard and mouse events
  8.                 2. lines: the mas of pointers for each line start
  9.                 3. selection
  10. */
  11.  
  12. #define MEMSIZE 1024*100
  13.  
  14. //===================================================//
  15. //                                                   //
  16. //                       LIB                         //
  17. //                                                   //
  18. //===================================================//
  19.  
  20. #include "../lib/io.h"
  21. #include "../lib/gui.h"
  22. #include "../lib/list_box.h"
  23. #include "../lib/draw_buf.h"
  24. #include "../lib/events.h"
  25. #include "../lib/array.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/libimg.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.  
  47. #define TOOLBAR_H 38
  48. #define TOOLBAR_ICON_WIDTH  24
  49. #define TOOLBAR_ICON_HEIGHT 22
  50. #define STATUSBAR_H 15
  51. #define TAB_H 20
  52.  
  53. int user_encoding;
  54. int real_encoding = CH_CP866;
  55. int curcol_scheme;
  56. int font_size;
  57.  
  58. bool enable_edit = false;
  59.  
  60. #include "data.h"
  61.  
  62. #include "search.h"
  63. #include "selection.h"
  64. #include "prepare_page.h"
  65.  
  66. //===================================================//
  67. //                                                   //
  68. //                       DATA                        //
  69. //                                                   //
  70. //===================================================//
  71.  
  72. scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,
  73.         0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  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_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(libio,     #libio_init,     1);
  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(#param + 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.                 return;
  127.         }
  128.  
  129.         io.buffer_data = malloc(ESDWORD[bufpointer+12]);
  130.         strcpy(io.buffer_data, bufpointer + 16);
  131. }
  132.  
  133. void main()
  134. {      
  135.         InitDlls();
  136.         LoadIniSettings();
  137.         EventSetColorScheme(curcol_scheme);
  138.         if (param[0] == '*') {
  139.                 LoadFileFromDocPack();
  140.                 param[0]='\0';
  141.                 sprintf(#title, "#DOCPACK - %s", #short_app_name);
  142.         } else {
  143.                 if (streq(#param,"-new")) {Form.left+=40;Form.top+=40;}
  144.                 LoadFile(#param);
  145.         }
  146.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  147.         loop()
  148.         {
  149.                 switch(@WaitEventTimeout(400))
  150.                 {
  151.                         case evMouse:
  152.                                 HandleMouseEvent();
  153.                                 break;
  154.                         case evKey:
  155.                                 HandleKeyEvent();
  156.                                 break;
  157.                         case evButton:
  158.                                 HandleButtonEvent();
  159.                                 break;
  160.                         case evReDraw:
  161.                                 if (CheckActiveProcess(Form.ID)) EventMenuClick();
  162.                                 draw_window();
  163.                                 break;
  164.                         default:
  165.                                 DrawStatusBar(" "); //clean DrawStatusBar text with delay
  166.                 }
  167.         }
  168. }
  169.  
  170. //===================================================//
  171. //                                                   //
  172. //                  EVENT HANDLERS                   //
  173. //                                                   //
  174. //===================================================//
  175.  
  176. void HandleButtonEvent()
  177. {
  178.         int btn = GetButtonID();
  179.         if (btn==1) {
  180.                 SaveIniSettings();
  181.                 ExitProcess();
  182.         }
  183.         button.press(btn);
  184.         switch(btn-10)
  185.         {
  186.                 case BTN_FIND_NEXT:
  187.                         EventSearchNext();
  188.                         break;
  189.                 case BTN_FIND_CLOSE:
  190.                         search.hide();
  191.                         break;
  192.                 case BTN_CHANGE_CHARSET:
  193.                         EventShowCharsetsList();
  194.                         break;
  195.         }
  196. }
  197.  
  198. void HandleKeyEvent()
  199. {
  200.         GetKeys();
  201.  
  202.         switch (key_scancode)
  203.         {
  204.                 case SCAN_CODE_F1:
  205.                         EventShowInfo();
  206.                         return;
  207.                 case SCAN_CODE_ESC:
  208.                         search.hide();
  209.                         return;
  210.                 case SCAN_CODE_ENTER:
  211.                         if (! search_box.flags & ed_focus) return;
  212.                 case SCAN_CODE_F3:
  213.                         EventSearchNext();
  214.                         return;
  215.         }
  216.  
  217.         if (search.edit_key()) return;
  218.  
  219.         if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
  220.                 if (key.press(ECTRL + key_scancode)) return;
  221.                 switch (key_scancode)
  222.                 {
  223.                         case SCAN_CODE_KEY_A:
  224.                                 selection.select_all();
  225.                                 DrawPage();
  226.                                 return;
  227.                         case SCAN_CODE_KEY_X:
  228.                                 EventCut();
  229.                                 return;
  230.                         case SCAN_CODE_KEY_C:
  231.                                 EventCopy();
  232.                                 return;
  233.                         case SCAN_CODE_KEY_V:
  234.                                 EventPaste();
  235.                                 return;
  236.                         case SCAN_CODE_UP:
  237.                                 EventMagnifyPlus();
  238.                                 return;
  239.                         case SCAN_CODE_DOWN:
  240.                                 EventMagnifyMinus();
  241.                                 return;
  242.                         case SCAN_CODE_TAB:
  243.                                 EventShowCharsetsList();
  244.                                 return;
  245.                         case SCAN_CODE_KEY_F:
  246.                                 search.show();
  247.                                 return;
  248.                 }
  249.         }
  250.  
  251.         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  252.                 selection.set_start();
  253.         } else {
  254.                 selection.cancel();
  255.         }
  256.  
  257.         if (list.ProcessKey(key_scancode)) {
  258.                 if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
  259.                 DrawPage();
  260.                 return;
  261.         }
  262.         if(enable_edit) EventInsertCharIntoText();
  263. }
  264.  
  265. void HandleMouseEvent()
  266. {
  267.         mouse.get();
  268.         list.wheel_size = 7;
  269.         if (list.MouseScroll(mouse.vert)) {
  270.                 DrawPage();
  271.                 return;
  272.         }
  273.         if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) {
  274.                 if (mouse.key&MOUSE_LEFT) {
  275.  
  276.                         GetKeyModifier();
  277.                         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  278.                                 if (mouse.down) selection.set_start();
  279.                                 list.ProcessMouse(mouse.x, mouse.y);
  280.                                 if (mouse.up) selection.set_end();
  281.                                 DrawPage();
  282.                                 return;
  283.                         }
  284.  
  285.                         //as we have lines of variable width, we need to recalculate column_max
  286.                         list.column_max = lines.len(mouse.y - list.y / list.item_h + list.first);
  287.  
  288.                         list.ProcessMouse(mouse.x, mouse.y);
  289.  
  290.                         if (mouse.down) {
  291.                                 selection.cancel();
  292.                                 selection.set_start();
  293.                         }
  294.                         selection.set_end();
  295.                         DrawPage();
  296.                 }
  297.                 if (mouse.key&MOUSE_RIGHT) && (mouse.up) {
  298.                         EventShowRmbMenu();
  299.                 }
  300.                 return;
  301.         }
  302.         scrollbar_v_mouse (#scroll);
  303.         if (list.first != scroll.position) {
  304.                 list.first = scroll.position;
  305.                 DrawPage();
  306.         }
  307.         search.edit_mouse();
  308. }
  309.  
  310. //===================================================//
  311. //                                                   //
  312. //                      EVENTS                       //
  313. //                                                   //
  314. //===================================================//
  315.  
  316. bool EventSearchNext()
  317. {
  318.         int new_y = search.find_next(list.first);
  319.         if (new_y) {
  320.                 list.first = new_y;
  321.                 list.CheckDoesValuesOkey();
  322.                 DrawPage();            
  323.         }
  324. }
  325.  
  326. void EventNewFile()
  327. {
  328.         RunProgram(#program_path, "-new");
  329. }
  330.  
  331. void EventOpenDialog()
  332. {
  333.         OpenDialog_start stdcall (#o_dialog);
  334.         if (o_dialog.status) {
  335.                 LoadFile(#openfile_path);
  336.                 ParseAndPaint();
  337.         }
  338. }
  339.  
  340. void EventSave()
  341. {
  342.         int res;
  343.         char backy_param[4096];
  344.         if (io.buffer_data) {
  345.                 io.dir.make("/tmp0/1/quark_backups");
  346.                 sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #param);
  347.                 io.run("/sys/develop/backy", #backy_param);
  348.                 if (! io.write(#param, io.buffer_data) ) {
  349.                         notify(FILE_SAVED_WELL);
  350.                 } else {
  351.                         notify(FILE_NOT_SAVED);
  352.                 }
  353.         }
  354. }
  355.  
  356. void EventShowFileInfo()
  357. {
  358.         char ss_param[4096];
  359.         if (!param) return;
  360.         strcpy(#ss_param, "-p ");
  361.         strcpy(#ss_param+3, #param);
  362.         RunProgram("/sys/File managers/Eolite", #ss_param);
  363. }
  364.  
  365. void EventMagnifyMinus()
  366. {
  367.         SetSizes('S');
  368.         ParseAndPaint();
  369. }
  370.  
  371. void EventMagnifyPlus()
  372. {
  373.         SetSizes('M');
  374.         ParseAndPaint();
  375. }
  376.  
  377. void EventShowCharsetsList()
  378. {
  379.         menu_id = CHANGE_CHARSET;
  380.         open_lmenu(Form.left + Form.cwidth, Form.top + skin_height
  381.                 + Form.cheight - 6, MENU_ALIGN_BOT_RIGHT, user_encoding+1,
  382.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
  383. }
  384.  
  385. void EventShowReopenMenu()
  386. {
  387.         menu_id = REOPEN_IN_APP;
  388.         open_lmenu(Form.left+5 + reopenin_mx + 23, Form.top+29+skin_height,
  389.                 MENU_ALIGN_TOP_RIGHT, NULL,
  390.                 "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
  391. }
  392.  
  393. void EventShowThemesList()
  394. {
  395.         menu_id = COLOR_SCHEME;
  396.         open_lmenu(Form.left+5 + theme_mx + 23,
  397.                 Form.top+29+skin_height, MENU_ALIGN_TOP_RIGHT,
  398.                 curcol_scheme+1, #color_scheme_names);
  399. }
  400.  
  401. void EventShowRmbMenu()
  402. {
  403.         menu_id = RMB_MENU;
  404.         open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y,
  405.                 MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu);
  406. }
  407.  
  408.  
  409. void EventSetColorScheme(dword _setn)
  410. {
  411.         curcol_scheme = _setn;
  412.         theme.bg      = color_schemes[curcol_scheme*5];
  413.         theme.text    = color_schemes[curcol_scheme*5+1];
  414.         scroll.bckg_col = theme.bg;
  415.         scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*5+2];
  416.         selection.color = color_schemes[curcol_scheme*5+3];
  417.         theme.cursor    = color_schemes[curcol_scheme*5+4];
  418.         if (list.count) ParseAndPaint();
  419. }
  420.  
  421.  
  422. void EventShowInfo() {
  423.         static dword shared_about;
  424.         if (!shared_about) {
  425.                 shared_about = memopen("QUARK_ABOUT", sizeof(about)+1, SHM_OPEN_ALWAYS + SHM_READ);
  426.                 strcpy(shared_about, #about);
  427.         }
  428.         RunProgram("/sys/dialog", "-info 122 *QUARK_ABOUT");
  429. }
  430.  
  431. void EventChangeCharset(dword id)
  432. {
  433.         if (param[0]=='\0') return;
  434.         user_encoding = id;
  435.         LoadFile(#openfile_path);
  436.         ParseAndPaint();
  437.         draw_window();
  438. }
  439.  
  440. void EventOpenFileInOtherApp(dword _id)
  441. {
  442.         dword app;
  443.         byte open_param[4096];
  444.         switch(_id) {
  445.                 case 0: app = "/sys/tinypad"; break;
  446.                 case 1: app = "/sys/develop/t_edit"; break;
  447.                 case 2: app = "/sys/network/webview"; break;
  448.                 case 3: app = "/sys/fb2read"; break;
  449.                 case 4: app = "/sys/develop/heed"; break;
  450.                 case 5: open_param[0]='~';
  451.                         strcpy(#open_param+1,#param);
  452.                         RunProgram("/sys/@open", #open_param);
  453.                         return;
  454.         }
  455.         RunProgram(app, #param);
  456. }
  457.  
  458. void EventMenuClick()
  459. {
  460.         dword click_id = get_menu_click();
  461.  
  462.         if (click_id) && (menu_id) switch(menu_id)
  463.         {
  464.                 case CHANGE_CHARSET: EventChangeCharset(click_id-1); break;
  465.                 case REOPEN_IN_APP:  EventOpenFileInOtherApp(click_id-1); break;
  466.                 case COLOR_SCHEME:   EventSetColorScheme(click_id-1); break;
  467.                 case RMB_MENU:       EventRbmMenuClick(click_id-1); break;
  468.                 default: notify("'Error: wrong menu number'E");
  469.         }
  470.         menu_id = NULL;
  471. }
  472.  
  473. void EventClickSearch()
  474. {
  475.         if (search.visible) {
  476.                 search.hide();
  477.         } else {
  478.                 search.show();
  479.         }
  480. }
  481.  
  482. void EventInsertCharIntoText()
  483. {
  484.         dword cursor_pos = lines.get(list.cur_y) + list.cur_x;
  485.  
  486.         switch(key_scancode)
  487.         {
  488.                 case SCAN_CODE_DOWN:
  489.                 case SCAN_CODE_UP:
  490.                 case SCAN_CODE_HOME:
  491.                 case SCAN_CODE_END:
  492.                 case SCAN_CODE_PGUP:
  493.                 case SCAN_CODE_PGDN:
  494.                 return;
  495.                 case SCAN_CODE_BS:
  496.                 case SCAN_CODE_DEL:
  497.                 notify("'Not supported yet'A");
  498.                 return;
  499.         }
  500.  
  501.         if (list.cur_x >= list.column_max) return;
  502.  
  503.         ESBYTE[cursor_pos] = key_ascii;
  504.         list.KeyRight();
  505.         PaintVisible();
  506. }
  507.  
  508. void EventOpenSysfuncs()
  509. {
  510.         if (io.run("/sys/docpack", "f") <= 0) {
  511.                 notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E");
  512.         }
  513. }
  514.  
  515. void EventOpenPipet()
  516. {
  517.         io.run("/sys/develop/pipet", NULL);
  518. }
  519.  
  520. void EventRbmMenuClick(dword id)
  521. {
  522.         switch(id) {
  523.                 case 0: EventCut(); break;
  524.                 case 1: EventCopy(); break;
  525.                 case 2: EventPaste(); break;
  526.                 case 3: EventRevealInFolder(); break;
  527.                 case 4: EventCopyFilePath(); break;
  528.         }
  529. }
  530.  
  531. void EventCut()
  532. {
  533.         //selection.copy();
  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 EventPaste()
  565. {
  566.         //selection.copy();
  567. }
  568.  
  569. void EventRevealInFolder()
  570. {
  571.         RunProgram("/sys/File managers/Eolite", #param);
  572. }
  573.  
  574. void EventCopyFilePath()
  575. {
  576.         char copy_status_text[32];
  577.         Clipboard__CopyText(#param);
  578.         sprintf(#copy_status_text, #copied_chars, strlen(#param));
  579.         DrawStatusBar(#copy_status_text);
  580. }
  581.  
  582. void EventEnableEdit()
  583. {
  584.         enable_edit ^= 1;
  585.         if (enable_edit) notify("'Edit mode is enabled.\nNow you can only replace text, not insert, nor delete.'I");
  586.         draw_window();
  587. }
  588.  
  589. //===================================================//
  590. //                                                   //
  591. //               DRAWS AND OTHER FUNCS               //
  592. //                                                   //
  593. //===================================================//
  594.  
  595. void EncodeToDos()
  596. {
  597.         real_encoding = user_encoding;
  598.  
  599.         // Autodetecting charset
  600.         if (real_encoding == CH_AUTO) {
  601.                 real_encoding = CH_CP866;
  602.                 if (strstr(io.buffer_data, "\208\190")) real_encoding = CH_UTF8;
  603.                 else {
  604.                         if (chrnum(io.buffer_data, '\246')>5)
  605.                         || (strstr(io.buffer_data, "пр")) real_encoding = CH_CP1251;
  606.                 }
  607.         }
  608.         if (real_encoding != CH_CP866)
  609.                 ChangeCharset(real_encoding, "CP866", io.buffer_data);         
  610. }
  611.  
  612. void LoadFile(dword f_path)
  613. {
  614.         if (io.buffer_data) free(io.buffer_data);
  615.         if (ESBYTE[f_path]) {
  616.                 strcpy(#param, f_path);
  617.                 if (!io.read(#param)) goto NO_DATA;
  618.                 sprintf(#title, "%s - %s", #param, #short_app_name);
  619.                 EncodeToDos(); 
  620.         }
  621.         else {
  622.                 NO_DATA:
  623.                 io.buffer_data = malloc(sizeof(intro));
  624.                 strcpy(io.buffer_data, #intro);
  625.                 strcpy(#title, #short_app_name);
  626.         }
  627.         list.ClearList();
  628. }
  629.  
  630. int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) {
  631.         if (_hotkey) key.add_n(_hotkey, _event);
  632.         return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
  633. }
  634.  
  635.  
  636. void DrawToolbar()
  637. {
  638.         #define SMALL_GAP 26+5
  639.         #define BIG_GAP 26+18
  640.         incn x;
  641.         bool thema = false;
  642.         bool reopa = false;
  643.  
  644.         bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H);
  645.         if (menu_id == COLOR_SCHEME) thema = true;
  646.         if (menu_id == REOPEN_IN_APP) reopa = true;
  647.  
  648.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
  649.         DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
  650.        
  651.         x.set(-SMALL_GAP+8);
  652.         if(enable_edit) AddTopBarButton(#EventNewFile,        ECTRL+SCAN_CODE_KEY_N, 2,  x.inc(SMALL_GAP), false);
  653.                         AddTopBarButton(#EventOpenDialog,     ECTRL+SCAN_CODE_KEY_O, 0,  x.inc(SMALL_GAP), false);
  654.         if(enable_edit) && (param[0]) AddTopBarButton(#EventSave,           ECTRL+SCAN_CODE_KEY_S, 5,  x.inc(SMALL_GAP), false);
  655.                         AddTopBarButton(#EventShowFileInfo,   ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
  656.                         AddTopBarButton(#EventMagnifyMinus,   ECTRL+SCAN_CODE_MINUS, 33, x.inc(BIG_GAP),   false);
  657.                         AddTopBarButton(#EventMagnifyPlus,    ECTRL+SCAN_CODE_PLUS,  32, x.inc(SMALL_GAP), false);
  658.                         AddTopBarButton(#EventClickSearch,    ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP),   serha);  search_mx = EAX;
  659.         x.set(Form.cwidth-4);
  660.                         AddTopBarButton(#EventEnableEdit,       NULL,                  38, x.inc(-SMALL_GAP), enable_edit);
  661.         //if(enable_edit) AddTopBarButton(#EventShowInfo,       NULL,                  -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
  662.                         AddTopBarButton(#EventShowThemesList, NULL,                  40, x.inc(-BIG_GAP), thema); theme_mx = EAX;
  663.                         AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP),   reopa); reopenin_mx = EAX;
  664.         if(enable_edit) AddTopBarButton(#EventOpenSysfuncs,   NULL,                  18, x.inc(-SMALL_GAP), false);
  665.         if(enable_edit) AddTopBarButton(#EventOpenPipet,      NULL,                  39, x.inc(-SMALL_GAP), false);
  666. }
  667.  
  668. void DrawStatusBar(dword _in_text)
  669. {
  670.         static char status_text[64];
  671.         if (Form.status_window>2) return;
  672.         if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
  673.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
  674.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
  675.         WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
  676.         if (param[0]) {
  677.                 WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
  678.                         60, sc.work_text, real_encoding*10+#charsets);
  679.                 DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
  680.                         60, 12, BTN_CHANGE_CHARSET+10);
  681.         }
  682. }
  683.  
  684. void draw_window()
  685. {
  686.         int old_w = list.w;
  687.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
  688.         GetProcessInfo(#Form, SelfInfo);
  689.         sc.get();
  690.         if (Form.status_window>2) return;
  691.         if (Form.width  < 430) { MoveSize(OLD,OLD,430,OLD); return; }
  692.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  693.        
  694.         button.init(40);
  695.         key.init(40);
  696.  
  697.         SetSizes(font_size);
  698.  
  699.         if ((list.w == old_w) && (list.count)) {
  700.                 DrawPage();
  701.         } else {
  702.                 ParseAndPaint();
  703.         }
  704.  
  705.         DrawToolbar();
  706.         DrawStatusBar(NULL);
  707. }
  708.  
  709. void DrawPage()
  710. {
  711.         scroll.max_area = list.count;
  712.         scroll.cur_area = list.visible;
  713.         scroll.position = list.first;
  714.         scroll.all_redraw = 0;
  715.         scroll.start_x = list.x + list.w;
  716.         scroll.start_y = list.y;
  717.         scroll.size_y = list.h;
  718.         scrollbar_v_draw(#scroll);
  719.  
  720.         DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x,
  721.                 scroll.size_y-1, scroll.bckg_col);
  722.         PaintVisible();
  723. }
  724.  
  725.  
  726. void SetSizes(char _size)
  727. {
  728.         font_size = _size;
  729.         if (font_size == 'S') list.SetFont(6, 9, 00001000b);
  730.         if (font_size == 'M') list.SetFont(8, 14, 00011000b);
  731.         list.item_w = list.font_w;
  732.         list.horisontal_selelection = true;
  733.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
  734.                 Form.cheight - TOOLBAR_H - calc(search.visible * SEARCH_H) - STATUSBAR_H /*- TAB_H*/,
  735.                 math.round(list.font_h * 1.4));
  736. }