Subversion Repositories Kolibri OS

Rev

Rev 7975 | Rev 8381 | 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. bool search_next = false;
  60.  
  61. #include "data.h"
  62.  
  63. #include "search.h"
  64. #include "selection.h"
  65. #include "prepare_page.h"
  66.  
  67. //===================================================//
  68. //                                                   //
  69. //                       DATA                        //
  70. //                                                   //
  71. //===================================================//
  72.  
  73. scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,
  74.         0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  75.  
  76. char title[4196];
  77.  
  78. int reopenin_mx,
  79.     theme_mx,
  80.     burger_mx,
  81.     search_mx;
  82.  
  83. enum {
  84.         CHANGE_CHARSET=12,
  85.         REOPEN_IN_APP=1,
  86.         COLOR_SCHEME=8,
  87.         RMB_MENU,
  88.         BTN_FIND_NEXT,
  89.         BTN_FIND_CLOSE,
  90.         BTN_CHANGE_CHARSET
  91. };
  92.  
  93. dword menu_id;
  94.  
  95. EVENTS button;
  96. EVENTS key;
  97.  
  98. //===================================================//
  99. //                                                   //
  100. //                       CODE                        //
  101. //                                                   //
  102. //===================================================//
  103.  
  104. void InitDlls()
  105. {
  106.         load_dll(boxlib,    #box_lib_init,   0);
  107.         load_dll(libio,     #libio_init,     1);
  108.         load_dll(libimg,    #libimg_init,    1);
  109.         load_dll(libini,    #lib_init,       1);
  110.         load_dll(iconv_lib, #iconv_open,     0);
  111.         load_dll(Proc_lib,  #OpenDialog_init,0);
  112.         OpenDialog_init stdcall (#o_dialog);
  113. }
  114.  
  115. void LoadFileFromDocPack()
  116. {
  117.         dword bufsize = atoi(#param + 1) + 20;
  118.         dword bufpointer = malloc(bufsize);
  119.  
  120.         ESDWORD[bufpointer+0] = 0;
  121.         ESDWORD[bufpointer+4] = 8;
  122.         IpcSetArea(bufpointer, bufsize);
  123.  
  124.         SetEventMask(EVM_IPC);
  125.         if (@WaitEventTimeout(200) != evIPC) {
  126.                 notify("'IPC FAIL'E");
  127.                 return;
  128.         }
  129.  
  130.         io.buffer_data = malloc(ESDWORD[bufpointer+12]);
  131.         strcpy(io.buffer_data, bufpointer + 16);
  132. }
  133.  
  134. void main()
  135. {      
  136.         InitDlls();
  137.         LoadIniSettings();
  138.         EventSetColorScheme(curcol_scheme);
  139.         if (param[0] == '*') {
  140.                 LoadFileFromDocPack();
  141.                 param[0]='\0';
  142.                 sprintf(#title, "#DOCPACK - %s", #short_app_name);
  143.         } else {
  144.                 if (streq(#param,"-new")) {Form.left+=40;Form.top+=40;}
  145.                 LoadFile(#param);
  146.         }
  147.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  148.         loop()
  149.         {
  150.                 switch(@WaitEventTimeout(400))
  151.                 {
  152.                         case evMouse:
  153.                                 HandleMouseEvent();
  154.                                 break;
  155.                         case evKey:
  156.                                 HandleKeyEvent();
  157.                                 break;
  158.                         case evButton:
  159.                                 HandleButtonEvent();
  160.                                 break;
  161.                         case evReDraw:
  162.                                 if (CheckActiveProcess(Form.ID)) EventMenuClick();
  163.                                 draw_window();
  164.                                 break;
  165.                         default:
  166.                                 DrawStatusBar(" "); //clean DrawStatusBar text with delay
  167.                 }
  168.         }
  169. }
  170.  
  171. //===================================================//
  172. //                                                   //
  173. //                  EVENT HANDLERS                   //
  174. //                                                   //
  175. //===================================================//
  176.  
  177. void HandleButtonEvent()
  178. {
  179.         int btn = GetButtonID();
  180.         if (btn==1) {
  181.                 SaveIniSettings();
  182.                 ExitProcess();
  183.         }
  184.         button.press(btn);
  185.         switch(btn-10)
  186.         {
  187.                 case BTN_FIND_NEXT:
  188.                         EventSearchNext();
  189.                         break;
  190.                 case BTN_FIND_CLOSE:
  191.                         search.hide();
  192.                         break;
  193.                 case BTN_CHANGE_CHARSET:
  194.                         EventShowCharsetsList();
  195.                         break;
  196.         }
  197. }
  198.  
  199. void HandleKeyEvent()
  200. {
  201.         GetKeys();
  202.  
  203.         switch (key_scancode)
  204.         {
  205.                 case SCAN_CODE_F1:
  206.                         EventShowInfo();
  207.                         return;
  208.                 case SCAN_CODE_ESC:
  209.                         search.hide();
  210.                         return;
  211.                 case SCAN_CODE_ENTER:
  212.                         if (! search_box.flags & ed_focus) return;
  213.                 case SCAN_CODE_F3:
  214.                         EventSearchNext();
  215.                         return;
  216.         }
  217.  
  218.         if (search.edit_key()) return;
  219.  
  220.         if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
  221.                 if (key.press(ECTRL + key_scancode)) return;
  222.                 switch (key_scancode)
  223.                 {
  224.                         case SCAN_CODE_KEY_A:
  225.                                 selection.select_all();
  226.                                 DrawPage();
  227.                                 return;
  228.                         case SCAN_CODE_KEY_X:
  229.                                 EventCut();
  230.                                 return;
  231.                         case SCAN_CODE_KEY_C:
  232.                                 EventCopy();
  233.                                 return;
  234.                         case SCAN_CODE_KEY_V:
  235.                                 EventPaste();
  236.                                 return;
  237.                         case SCAN_CODE_UP:
  238.                                 EventMagnifyPlus();
  239.                                 return;
  240.                         case SCAN_CODE_DOWN:
  241.                                 EventMagnifyMinus();
  242.                                 return;
  243.                         case SCAN_CODE_TAB:
  244.                                 EventShowCharsetsList();
  245.                                 return;
  246.                         case SCAN_CODE_KEY_F:
  247.                                 search.show();
  248.                                 return;
  249.                 }
  250.         }
  251.  
  252.         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  253.                 selection.set_start();
  254.         } else {
  255.                 selection.cancel();
  256.         }
  257.  
  258.         if (list.ProcessKey(key_scancode)) {
  259.                 if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
  260.                 DrawPage();
  261.                 return;
  262.         }
  263.         if(enable_edit) EventInsertCharIntoText();
  264. }
  265.  
  266. void HandleMouseEvent()
  267. {
  268.         mouse.get();
  269.         list.wheel_size = 7;
  270.         if (list.MouseScroll(mouse.vert)) {
  271.                 DrawPage();
  272.                 return;
  273.         }
  274.         if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) {
  275.                 if (mouse.key&MOUSE_LEFT) {
  276.  
  277.                         GetKeyModifier();
  278.                         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  279.                                 if (mouse.down) selection.set_start();
  280.                                 list.ProcessMouse(mouse.x, mouse.y);
  281.                                 if (mouse.up) selection.set_end();
  282.                                 DrawPage();
  283.                                 return;
  284.                         }
  285.  
  286.                         //as we have lines of variable width, we need to recalculate column_max
  287.                         list.column_max = lines.len(mouse.y - list.y / list.item_h + list.first);
  288.  
  289.                         list.ProcessMouse(mouse.x, mouse.y);
  290.  
  291.                         if (mouse.down) {
  292.                                 selection.cancel();
  293.                                 selection.set_start();
  294.                         }
  295.                         selection.set_end();
  296.                         DrawPage();
  297.                 }
  298.                 if (mouse.key&MOUSE_RIGHT) && (mouse.up) {
  299.                         EventShowRmbMenu();
  300.                 }
  301.                 return;
  302.         }
  303.         scrollbar_v_mouse (#scroll);
  304.         if (list.first != scroll.position) {
  305.                 list.first = scroll.position;
  306.                 DrawPage();
  307.         }
  308.         search.edit_mouse();
  309. }
  310.  
  311. //===================================================//
  312. //                                                   //
  313. //                      EVENTS                       //
  314. //                                                   //
  315. //===================================================//
  316.  
  317. bool EventSearchNext()
  318. {
  319.         int new_y = search.find_next(list.first+1);
  320.         if (new_y) {
  321.                 list.first = new_y;
  322.                 list.CheckDoesValuesOkey();
  323.                 search_next = true;
  324.                 DrawPage();    
  325.         }
  326. }
  327.  
  328. void EventNewFile()
  329. {
  330.         RunProgram(#program_path, "-new");
  331. }
  332.  
  333. void EventOpenDialog()
  334. {
  335.         OpenDialog_start stdcall (#o_dialog);
  336.         if (o_dialog.status) {
  337.                 LoadFile(#openfile_path);
  338.                 ParseAndPaint();
  339.         }
  340. }
  341.  
  342. void EventSave()
  343. {
  344.         int res;
  345.         char backy_param[4096];
  346.         if (io.buffer_data) {
  347.                 io.dir.make("/tmp0/1/quark_backups");
  348.                 sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #param);
  349.                 io.run("/sys/develop/backy", #backy_param);
  350.                 if (! io.write(#param, io.buffer_data) ) {
  351.                         notify(FILE_SAVED_WELL);
  352.                 } else {
  353.                         notify(FILE_NOT_SAVED);
  354.                 }
  355.         }
  356. }
  357.  
  358. void EventShowFileInfo()
  359. {
  360.         char ss_param[4096];
  361.         if (!param) return;
  362.         strcpy(#ss_param, "-p ");
  363.         strcpy(#ss_param+3, #param);
  364.         RunProgram("/sys/File managers/Eolite", #ss_param);
  365. }
  366.  
  367. void EventMagnifyMinus()
  368. {
  369.         SetSizes('S');
  370.         ParseAndPaint();
  371. }
  372.  
  373. void EventMagnifyPlus()
  374. {
  375.         SetSizes('M');
  376.         ParseAndPaint();
  377. }
  378.  
  379. void EventShowCharsetsList()
  380. {
  381.         menu_id = CHANGE_CHARSET;
  382.         open_lmenu(Form.cwidth-4, Form.cheight - 6, MENU_BOT_RIGHT,
  383.                 user_encoding+1,
  384.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
  385. }
  386.  
  387. void EventShowReopenMenu()
  388. {
  389.         menu_id = REOPEN_IN_APP;
  390.         open_lmenu(reopenin_mx + 23, 29, MENU_TOP_RIGHT, NULL,
  391.                 "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
  392. }
  393.  
  394. void EventShowThemesList()
  395. {
  396.         menu_id = COLOR_SCHEME;
  397.         open_lmenu(theme_mx + 23, 29, MENU_TOP_RIGHT,
  398.                 curcol_scheme+1, #color_scheme_names);
  399. }
  400.  
  401. void EventShowRmbMenu()
  402. {
  403.         menu_id = RMB_MENU;
  404.         open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu);
  405. }
  406.  
  407.  
  408. void EventSetColorScheme(dword _setn)
  409. {
  410.         curcol_scheme = _setn;
  411.         theme.bg      = color_schemes[curcol_scheme*6];
  412.         theme.text    = color_schemes[curcol_scheme*6+1];
  413.         scroll.bckg_col = theme.bg;
  414.         scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*6+2];
  415.         selection.color = color_schemes[curcol_scheme*6+3];
  416.         theme.cursor    = color_schemes[curcol_scheme*6+4];
  417.         theme.found     = color_schemes[curcol_scheme*6+5];
  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(#param);
  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, "\239\240")) real_encoding = CH_CP1251;
  606.                 }
  607.         }
  608.         if (real_encoding != CH_CP866) {
  609.                 ChangeCharset(real_encoding, "CP866", io.buffer_data);         
  610.         }
  611. }
  612.  
  613. void LoadFile(dword f_path)
  614. {
  615.         if (io.buffer_data) free(io.buffer_data);
  616.         if (ESBYTE[f_path]) {
  617.                 strcpy(#param, f_path);
  618.                 if (!io.read(#param)) goto NO_DATA;
  619.                 sprintf(#title, "%s - %s", #param, #short_app_name);
  620.                 EncodeToDos(); 
  621.         }
  622.         else {
  623.                 NO_DATA:
  624.                 io.buffer_data = malloc(sizeof(intro));
  625.                 strcpy(io.buffer_data, #intro);
  626.                 strcpy(#title, #short_app_name);
  627.         }
  628.         list.ClearList();
  629. }
  630.  
  631. int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) {
  632.         if (_hotkey) key.add_n(_hotkey, _event);
  633.         return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
  634. }
  635.  
  636.  
  637. void DrawToolbar()
  638. {
  639.         #define SMALL_GAP 26+5
  640.         #define BIG_GAP 26+18
  641.         incn x;
  642.         bool thema = false;
  643.         bool reopa = false;
  644.  
  645.         bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H);
  646.         if (menu_id == COLOR_SCHEME) thema = true;
  647.         if (menu_id == REOPEN_IN_APP) reopa = true;
  648.  
  649.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
  650.         DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
  651.        
  652.         x.set(-SMALL_GAP+8);
  653.         if(enable_edit) AddTopBarButton(#EventNewFile,        ECTRL+SCAN_CODE_KEY_N, 2,  x.inc(SMALL_GAP), false);
  654.                         AddTopBarButton(#EventOpenDialog,     ECTRL+SCAN_CODE_KEY_O, 0,  x.inc(SMALL_GAP), false);
  655.         if(enable_edit) && (param[0]) AddTopBarButton(#EventSave,           ECTRL+SCAN_CODE_KEY_S, 5,  x.inc(SMALL_GAP), false);
  656.                         AddTopBarButton(#EventShowFileInfo,   ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
  657.                         AddTopBarButton(#EventMagnifyMinus,   ECTRL+SCAN_CODE_MINUS, 33, x.inc(BIG_GAP),   false);
  658.                         AddTopBarButton(#EventMagnifyPlus,    ECTRL+SCAN_CODE_PLUS,  32, x.inc(SMALL_GAP), false);
  659.                         AddTopBarButton(#EventClickSearch,    ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP),   serha);  search_mx = EAX;
  660.         x.set(Form.cwidth-4);
  661.                         AddTopBarButton(#EventEnableEdit,       NULL,                  38, x.inc(-SMALL_GAP), enable_edit);
  662.         //if(enable_edit) AddTopBarButton(#EventShowInfo,       NULL,                  -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
  663.                         AddTopBarButton(#EventShowThemesList, NULL,                  40, x.inc(-BIG_GAP), thema); theme_mx = EAX;
  664.                         AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP),   reopa); reopenin_mx = EAX;
  665.         if(enable_edit) AddTopBarButton(#EventOpenSysfuncs,   NULL,                  18, x.inc(-SMALL_GAP), false);
  666.         if(enable_edit) AddTopBarButton(#EventOpenPipet,      NULL,                  39, x.inc(-SMALL_GAP), false);
  667. }
  668.  
  669. void DrawStatusBar(dword _in_text)
  670. {
  671.         static char status_text[64];
  672.         if (Form.status_window>2) return;
  673.         if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
  674.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
  675.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
  676.         WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
  677.         if (param[0]) {
  678.                 WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
  679.                         60, sc.work_text, real_encoding*10+#charsets);
  680.                 DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
  681.                         60, 12, BTN_CHANGE_CHARSET+10);
  682.         }
  683. }
  684.  
  685. void draw_window()
  686. {
  687.         int old_w = list.w;
  688.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
  689.         GetProcessInfo(#Form, SelfInfo);
  690.         sc.get();
  691.         if (Form.status_window>2) return;
  692.         if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
  693.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  694.        
  695.         button.init(40);
  696.         key.init(40);
  697.  
  698.         SetSizes(font_size);
  699.  
  700.         if ((list.w == old_w) && (list.count)) {
  701.                 DrawPage();
  702.         } else {
  703.                 ParseAndPaint();
  704.         }
  705.  
  706.         DrawToolbar();
  707.         DrawStatusBar(NULL);
  708. }
  709.  
  710. void DrawPage()
  711. {
  712.         scroll.max_area = list.count;
  713.         scroll.cur_area = list.visible;
  714.         scroll.position = list.first;
  715.         scroll.all_redraw = 0;
  716.         scroll.start_x = list.x + list.w;
  717.         scroll.start_y = list.y;
  718.         scroll.size_y = list.h;
  719.         scrollbar_v_draw(#scroll);
  720.  
  721.         DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x,
  722.                 scroll.size_y-1, scroll.bckg_col);
  723.         PaintVisible();
  724. }
  725.  
  726.  
  727. void SetSizes(char _size)
  728. {
  729.         font_size = _size;
  730.         if (font_size == 'S') list.SetFont(6, 9, 00001000b);
  731.         if (font_size == 'M') list.SetFont(8, 14, 00011000b);
  732.         list.item_w = list.font_w;
  733.         list.horisontal_selelection = true;
  734.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
  735.                 Form.cheight - TOOLBAR_H - calc(search.visible * SEARCH_H) - STATUSBAR_H /*- TAB_H*/,
  736.                 math.round(list.font_h * 1.4));
  737. }