Subversion Repositories Kolibri OS

Rev

Rev 7957 | Rev 8020 | 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. 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*6];
  413.         theme.text    = color_schemes[curcol_scheme*6+1];
  414.         scroll.bckg_col = theme.bg;
  415.         scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*6+2];
  416.         selection.color = color_schemes[curcol_scheme*6+3];
  417.         theme.cursor    = color_schemes[curcol_scheme*6+4];
  418.         theme.found     = color_schemes[curcol_scheme*6+5];
  419.         if (list.count) ParseAndPaint();
  420. }
  421.  
  422.  
  423. void EventShowInfo() {
  424.         static dword shared_about;
  425.         if (!shared_about) {
  426.                 shared_about = memopen("QUARK_ABOUT", sizeof(about)+1, SHM_OPEN_ALWAYS + SHM_READ);
  427.                 strcpy(shared_about, #about);
  428.         }
  429.         RunProgram("/sys/dialog", "-info 122 *QUARK_ABOUT");
  430. }
  431.  
  432. void EventChangeCharset(dword id)
  433. {
  434.         if (param[0]=='\0') return;
  435.         user_encoding = id;
  436.         LoadFile(#param);
  437.         ParseAndPaint();
  438.         draw_window();
  439. }
  440.  
  441. void EventOpenFileInOtherApp(dword _id)
  442. {
  443.         dword app;
  444.         byte open_param[4096];
  445.         switch(_id) {
  446.                 case 0: app = "/sys/tinypad"; break;
  447.                 case 1: app = "/sys/develop/t_edit"; break;
  448.                 case 2: app = "/sys/network/webview"; break;
  449.                 case 3: app = "/sys/fb2read"; break;
  450.                 case 4: app = "/sys/develop/heed"; break;
  451.                 case 5: open_param[0]='~';
  452.                         strcpy(#open_param+1,#param);
  453.                         RunProgram("/sys/@open", #open_param);
  454.                         return;
  455.         }
  456.         RunProgram(app, #param);
  457. }
  458.  
  459. void EventMenuClick()
  460. {
  461.         dword click_id = get_menu_click();
  462.  
  463.         if (click_id) && (menu_id) switch(menu_id)
  464.         {
  465.                 case CHANGE_CHARSET: EventChangeCharset(click_id-1); break;
  466.                 case REOPEN_IN_APP:  EventOpenFileInOtherApp(click_id-1); break;
  467.                 case COLOR_SCHEME:   EventSetColorScheme(click_id-1); break;
  468.                 case RMB_MENU:       EventRbmMenuClick(click_id-1); break;
  469.                 default: notify("'Error: wrong menu number'E");
  470.         }
  471.         menu_id = NULL;
  472. }
  473.  
  474. void EventClickSearch()
  475. {
  476.         if (search.visible) {
  477.                 search.hide();
  478.         } else {
  479.                 search.show();
  480.         }
  481. }
  482.  
  483. void EventInsertCharIntoText()
  484. {
  485.         dword cursor_pos = lines.get(list.cur_y) + list.cur_x;
  486.  
  487.         switch(key_scancode)
  488.         {
  489.                 case SCAN_CODE_DOWN:
  490.                 case SCAN_CODE_UP:
  491.                 case SCAN_CODE_HOME:
  492.                 case SCAN_CODE_END:
  493.                 case SCAN_CODE_PGUP:
  494.                 case SCAN_CODE_PGDN:
  495.                 return;
  496.                 case SCAN_CODE_BS:
  497.                 case SCAN_CODE_DEL:
  498.                 notify("'Not supported yet'A");
  499.                 return;
  500.         }
  501.  
  502.         if (list.cur_x >= list.column_max) return;
  503.  
  504.         ESBYTE[cursor_pos] = key_ascii;
  505.         list.KeyRight();
  506.         PaintVisible();
  507. }
  508.  
  509. void EventOpenSysfuncs()
  510. {
  511.         if (io.run("/sys/docpack", "f") <= 0) {
  512.                 notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E");
  513.         }
  514. }
  515.  
  516. void EventOpenPipet()
  517. {
  518.         io.run("/sys/develop/pipet", NULL);
  519. }
  520.  
  521. void EventRbmMenuClick(dword id)
  522. {
  523.         switch(id) {
  524.                 case 0: EventCut(); break;
  525.                 case 1: EventCopy(); break;
  526.                 case 2: EventPaste(); break;
  527.                 case 3: EventRevealInFolder(); break;
  528.                 case 4: EventCopyFilePath(); break;
  529.         }
  530. }
  531.  
  532. void EventCut()
  533. {
  534.         //selection.copy();
  535. }
  536.  
  537. void EventCopy()
  538. {
  539.         char copy_status_text[32];
  540.  
  541.         dword copy_buf;
  542.         dword copy_len;
  543.         dword copy_start;
  544.         dword copy_end;
  545.  
  546.         if (selection.is_active()) {
  547.                 copy_start = selection.start_offset;
  548.                 copy_end = selection.end_offset;
  549.                 if (copy_start > copy_end) copy_start >< copy_end;
  550.         } else {
  551.                 copy_start = lines.get(list.cur_y);
  552.                 copy_end = lines.get(list.cur_y+1);
  553.         }
  554.         copy_len = copy_end - copy_start;
  555.         copy_buf = malloc(copy_len + 2);
  556.         strncpy(copy_buf, copy_start, copy_len);
  557.         ESBYTE[copy_buf+copy_len] = '\0';
  558.         Clipboard__CopyText(copy_buf);
  559.         free(copy_buf);
  560.  
  561.         sprintf(#copy_status_text, #copied_chars, copy_len);
  562.         DrawStatusBar(#copy_status_text);
  563. }
  564.  
  565. void EventPaste()
  566. {
  567.         //selection.copy();
  568. }
  569.  
  570. void EventRevealInFolder()
  571. {
  572.         RunProgram("/sys/File managers/Eolite", #param);
  573. }
  574.  
  575. void EventCopyFilePath()
  576. {
  577.         char copy_status_text[32];
  578.         Clipboard__CopyText(#param);
  579.         sprintf(#copy_status_text, #copied_chars, strlen(#param));
  580.         DrawStatusBar(#copy_status_text);
  581. }
  582.  
  583. void EventEnableEdit()
  584. {
  585.         enable_edit ^= 1;
  586.         if (enable_edit) notify("'Edit mode is enabled.\nNow you can only replace text, not insert, nor delete.'I");
  587.         draw_window();
  588. }
  589.  
  590. //===================================================//
  591. //                                                   //
  592. //               DRAWS AND OTHER FUNCS               //
  593. //                                                   //
  594. //===================================================//
  595.  
  596. void EncodeToDos()
  597. {
  598.         real_encoding = user_encoding;
  599.  
  600.         // Autodetecting charset
  601.         if (real_encoding == CH_AUTO) {
  602.                 real_encoding = CH_CP866;
  603.                 if (strstr(io.buffer_data, "\208\190")) real_encoding = CH_UTF8;
  604.                 else {
  605.                         if (chrnum(io.buffer_data, '\246')>5)
  606.                         || (strstr(io.buffer_data, "\239\240")) real_encoding = CH_CP1251;
  607.                 }
  608.         }
  609.         if (real_encoding != CH_CP866) {
  610.                 ChangeCharset(real_encoding, "CP866", io.buffer_data);         
  611.         }
  612. }
  613.  
  614. void LoadFile(dword f_path)
  615. {
  616.         if (io.buffer_data) free(io.buffer_data);
  617.         if (ESBYTE[f_path]) {
  618.                 strcpy(#param, f_path);
  619.                 if (!io.read(#param)) goto NO_DATA;
  620.                 sprintf(#title, "%s - %s", #param, #short_app_name);
  621.                 EncodeToDos(); 
  622.         }
  623.         else {
  624.                 NO_DATA:
  625.                 io.buffer_data = malloc(sizeof(intro));
  626.                 strcpy(io.buffer_data, #intro);
  627.                 strcpy(#title, #short_app_name);
  628.         }
  629.         list.ClearList();
  630. }
  631.  
  632. int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) {
  633.         if (_hotkey) key.add_n(_hotkey, _event);
  634.         return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
  635. }
  636.  
  637.  
  638. void DrawToolbar()
  639. {
  640.         #define SMALL_GAP 26+5
  641.         #define BIG_GAP 26+18
  642.         incn x;
  643.         bool thema = false;
  644.         bool reopa = false;
  645.  
  646.         bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H);
  647.         if (menu_id == COLOR_SCHEME) thema = true;
  648.         if (menu_id == REOPEN_IN_APP) reopa = true;
  649.  
  650.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
  651.         DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
  652.        
  653.         x.set(-SMALL_GAP+8);
  654.         if(enable_edit) AddTopBarButton(#EventNewFile,        ECTRL+SCAN_CODE_KEY_N, 2,  x.inc(SMALL_GAP), false);
  655.                         AddTopBarButton(#EventOpenDialog,     ECTRL+SCAN_CODE_KEY_O, 0,  x.inc(SMALL_GAP), false);
  656.         if(enable_edit) && (param[0]) AddTopBarButton(#EventSave,           ECTRL+SCAN_CODE_KEY_S, 5,  x.inc(SMALL_GAP), false);
  657.                         AddTopBarButton(#EventShowFileInfo,   ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
  658.                         AddTopBarButton(#EventMagnifyMinus,   ECTRL+SCAN_CODE_MINUS, 33, x.inc(BIG_GAP),   false);
  659.                         AddTopBarButton(#EventMagnifyPlus,    ECTRL+SCAN_CODE_PLUS,  32, x.inc(SMALL_GAP), false);
  660.                         AddTopBarButton(#EventClickSearch,    ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP),   serha);  search_mx = EAX;
  661.         x.set(Form.cwidth-4);
  662.                         AddTopBarButton(#EventEnableEdit,       NULL,                  38, x.inc(-SMALL_GAP), enable_edit);
  663.         //if(enable_edit) AddTopBarButton(#EventShowInfo,       NULL,                  -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
  664.                         AddTopBarButton(#EventShowThemesList, NULL,                  40, x.inc(-BIG_GAP), thema); theme_mx = EAX;
  665.                         AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP),   reopa); reopenin_mx = EAX;
  666.         if(enable_edit) AddTopBarButton(#EventOpenSysfuncs,   NULL,                  18, x.inc(-SMALL_GAP), false);
  667.         if(enable_edit) AddTopBarButton(#EventOpenPipet,      NULL,                  39, x.inc(-SMALL_GAP), false);
  668. }
  669.  
  670. void DrawStatusBar(dword _in_text)
  671. {
  672.         static char status_text[64];
  673.         if (Form.status_window>2) return;
  674.         if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
  675.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
  676.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
  677.         WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
  678.         if (param[0]) {
  679.                 WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
  680.                         60, sc.work_text, real_encoding*10+#charsets);
  681.                 DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
  682.                         60, 12, BTN_CHANGE_CHARSET+10);
  683.         }
  684. }
  685.  
  686. void draw_window()
  687. {
  688.         int old_w = list.w;
  689.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
  690.         GetProcessInfo(#Form, SelfInfo);
  691.         sc.get();
  692.         if (Form.status_window>2) return;
  693.         if (Form.width  < 430) { MoveSize(OLD,OLD,430,OLD); return; }
  694.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  695.        
  696.         button.init(40);
  697.         key.init(40);
  698.  
  699.         SetSizes(font_size);
  700.  
  701.         if ((list.w == old_w) && (list.count)) {
  702.                 DrawPage();
  703.         } else {
  704.                 ParseAndPaint();
  705.         }
  706.  
  707.         DrawToolbar();
  708.         DrawStatusBar(NULL);
  709. }
  710.  
  711. void DrawPage()
  712. {
  713.         scroll.max_area = list.count;
  714.         scroll.cur_area = list.visible;
  715.         scroll.position = list.first;
  716.         scroll.all_redraw = 0;
  717.         scroll.start_x = list.x + list.w;
  718.         scroll.start_y = list.y;
  719.         scroll.size_y = list.h;
  720.         scrollbar_v_draw(#scroll);
  721.  
  722.         DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x,
  723.                 scroll.size_y-1, scroll.bckg_col);
  724.         PaintVisible();
  725. }
  726.  
  727.  
  728. void SetSizes(char _size)
  729. {
  730.         font_size = _size;
  731.         if (font_size == 'S') list.SetFont(6, 9, 00001000b);
  732.         if (font_size == 'M') list.SetFont(8, 14, 00011000b);
  733.         list.item_w = list.font_w;
  734.         list.horisontal_selelection = true;
  735.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
  736.                 Form.cheight - TOOLBAR_H - calc(search.visible * SEARCH_H) - STATUSBAR_H /*- TAB_H*/,
  737.                 math.round(list.font_h * 1.4));
  738. }