Subversion Repositories Kolibri OS

Rev

Rev 7924 | 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 proceed
  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. #include "data.h"
  59.  
  60. #include "../txtread/search.h"
  61. #include "selection.h"
  62. #include "prepare_page.h"
  63.  
  64. //===================================================//
  65. //                                                   //
  66. //                       DATA                        //
  67. //                                                   //
  68. //===================================================//
  69.  
  70. scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,
  71.         0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  72.  
  73. char title[4196];
  74.  
  75. bool help_opened = false;
  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. };
  90.  
  91. dword menu_id;
  92.  
  93. EVENTS button;
  94. EVENTS key;
  95.  
  96. //===================================================//
  97. //                                                   //
  98. //                       CODE                        //
  99. //                                                   //
  100. //===================================================//
  101.  
  102. void InitDlls()
  103. {
  104.         load_dll(boxlib,    #box_lib_init,   0);
  105.         load_dll(libio,     #libio_init,     1);
  106.         load_dll(libimg,    #libimg_init,    1);
  107.         load_dll(libini,    #lib_init,       1);
  108.         load_dll(iconv_lib, #iconv_open,     0);
  109.         load_dll(Proc_lib,  #OpenDialog_init,0);
  110.         OpenDialog_init stdcall (#o_dialog);
  111. }
  112.  
  113. void LoadFileFromDocPack()
  114. {
  115.         dword bufsize = atoi(#param + 1) + 20;
  116.         dword bufpointer = malloc(bufsize);
  117.         dword filesize;
  118.  
  119.         ESDWORD[bufpointer+0] = 0;
  120.         ESDWORD[bufpointer+4] = 8;
  121.  
  122.         IpcSetArea(bufpointer, bufsize);
  123.         SetEventMask(EVM_IPC);
  124.  
  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.         }
  194. }
  195.  
  196. void HandleKeyEvent()
  197. {
  198.         int new_y;
  199.         if (help_opened) {
  200.                 help_opened = false;
  201.                 DrawPage();
  202.                 return;
  203.         }
  204.         GetKeys();
  205.  
  206.         if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
  207.                 if (key.press(ECTRL + key_scancode)) return;
  208.                 switch (key_scancode)
  209.                 {
  210.                         case SCAN_CODE_KEY_X:
  211.                                 EventCut();
  212.                                 return;
  213.                         case SCAN_CODE_KEY_C:
  214.                                 EventCopy();
  215.                                 return;
  216.                         case SCAN_CODE_KEY_V:
  217.                                 EventPaste();
  218.                                 return;
  219.                         case SCAN_CODE_UP:
  220.                                 EventMagnifyPlus();
  221.                                 return;
  222.                         case SCAN_CODE_DOWN:
  223.                                 EventMagnifyMinus();
  224.                                 return;
  225.                         case SCAN_CODE_TAB:
  226.                                 EventShowCharsetsList();
  227.                                 return;
  228.                         case SCAN_CODE_KEY_F:
  229.                                 search.show();
  230.                                 return;
  231.                         case SCAN_CODE_HOME:
  232.                                 list.KeyHome();
  233.                                 list.KeyHomeHor();
  234.                                 DrawPage();
  235.                                 return;
  236.                         case SCAN_CODE_END:
  237.                                 list.KeyEnd();
  238.                                 list.column_max = strlen(lines.get(list.cur_y));
  239.                                 list.KeyEndHor();
  240.                                 DrawPage();
  241.                                 return;
  242.                         case SCAN_CODE_KEY_A:
  243.                                 selection.select_all();
  244.                                 DrawPage();
  245.                                 return;
  246.                 }
  247.         }
  248.         switch (key_scancode)
  249.         {
  250.                 case SCAN_CODE_F1:
  251.                         EventShowInfo();
  252.                         return;
  253.                 case SCAN_CODE_ESC:
  254.                         search.hide();
  255.                         return;
  256.                 case SCAN_CODE_ENTER:
  257.                         if (! search_box.flags & ed_focus) return;
  258.                 case SCAN_CODE_F3:
  259.                         EventSearchNext();
  260.                         return;
  261.         }
  262.         if (search.edit_key()) {
  263.                 return;
  264.         } else if (list.ProcessKey(key_scancode)) {
  265.                 DrawPage();
  266.                 return;
  267.         }
  268.         EventInsertCharIntoText();
  269. }
  270.  
  271. void HandleMouseEvent()
  272. {
  273.         mouse.get();
  274.         list.wheel_size = 7;
  275.         if (list.MouseScroll(mouse.vert)) {
  276.                 DrawPage();
  277.                 return;
  278.         }
  279.         if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) {
  280.                 if (mouse.key&MOUSE_LEFT) {
  281.  
  282.                         GetKeyModifier();
  283.                         if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
  284.                                 if (mouse.down) && (!selection.is_active()) selection.set_start();
  285.                                 list.ProcessMouse(mouse.x, mouse.y);
  286.                                 if (mouse.up) selection.set_end();
  287.                                 DrawPage();
  288.                                 return;
  289.                         }
  290.  
  291.                         list.ProcessMouse(mouse.x, mouse.y);
  292.                         if (mouse.down) {
  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, theme.bg);
  320.         if (new_y) {
  321.                 list.first = new_y / list.item_h;
  322.                 list.CheckDoesValuesOkey();
  323.                 DrawPage();            
  324.         }
  325. }
  326.  
  327. void EventNewFile()
  328. {
  329.         RunProgram(#program_path, "-new");
  330. }
  331.  
  332. void EventOpenDialog()
  333. {
  334.         OpenDialog_start stdcall (#o_dialog);
  335.         if (o_dialog.status) {
  336.                 LoadFile(#openfile_path);
  337.                 ParseAndPaint();
  338.         }
  339. }
  340.  
  341. void EventSave()
  342. {
  343.         int res;
  344.         char backy_param[4096];
  345.         if (io.buffer_data) {
  346.                 io.dir.make("/tmp0/1/quark_backups");
  347.                 sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #param);
  348.                 io.run("/sys/develop/backy", #backy_param);
  349.                 if (! io.write(#param, io.buffer_data) ) {
  350.                         notify(FILE_SAVED_WELL);
  351.                 } else {
  352.                         notify(FILE_NOT_SAVED);
  353.                 }
  354.         }
  355. }
  356.  
  357. void EventShowFileInfo()
  358. {
  359.         char ss_param[4096];
  360.         if (!param) return;
  361.         strcpy(#ss_param, "-p ");
  362.         strcpy(#ss_param+3, #param);
  363.         RunProgram("/sys/File managers/Eolite", #ss_param);
  364. }
  365.  
  366. void EventMagnifyMinus()
  367. {
  368.         SetSizes('S');
  369.         ParseAndPaint();
  370. }
  371.  
  372. void EventMagnifyPlus()
  373. {
  374.         SetSizes('M');
  375.         ParseAndPaint();
  376. }
  377.  
  378. void EventShowCharsetsList()
  379. {
  380.         menu_id = CHANGE_CHARSET;
  381.         open_lmenu(Form.left + Form.cwidth, Form.top + skin_height
  382.                 + Form.cheight - 6, MENU_ALIGN_BOT_RIGHT, user_encoding+1,
  383.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
  384. }
  385.  
  386. void EventShowReopenMenu()
  387. {
  388.         menu_id = REOPEN_IN_APP;
  389.         open_lmenu(Form.left+5 + reopenin_mx, Form.top+29+skin_height,
  390.                 MENU_ALIGN_TOP_LEFT, NULL,
  391.                 "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
  392. }
  393.  
  394. void EventShowThemesList()
  395. {
  396.         menu_id = COLOR_SCHEME;
  397.         open_lmenu(Form.left+2 + theme_mx + 26,
  398.                 Form.top+29+skin_height, MENU_ALIGN_TOP_RIGHT,
  399.                 curcol_scheme+1, #color_scheme_names);
  400. }
  401.  
  402. void EventShowRmbMenu()
  403. {
  404.         menu_id = RMB_MENU;
  405.         open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y,
  406.                 MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu);
  407. }
  408.  
  409.  
  410. void EventSetColorScheme(dword _setn)
  411. {
  412.         curcol_scheme = _setn;
  413.         theme.bg      = color_schemes[curcol_scheme*5];
  414.         theme.text    = color_schemes[curcol_scheme*5+1];
  415.         scroll.bckg_col = theme.bg;
  416.         scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*5+2];
  417.         selection.color = color_schemes[curcol_scheme*5+3];
  418.         theme.cursor    = color_schemes[curcol_scheme*5+4];
  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(#openfile_path);
  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. //===================================================//
  584. //                                                   //
  585. //               DRAWS AND OTHER FUNCS               //
  586. //                                                   //
  587. //===================================================//
  588.  
  589. void EncodeToDos()
  590. {
  591.         real_encoding = user_encoding;
  592.  
  593.         // Autodetecting charset
  594.         if (real_encoding == CH_AUTO) {
  595.                 real_encoding = CH_CP866;
  596.                 if (strstr(io.buffer_data, "\208\190")) real_encoding = CH_UTF8;
  597.                 else {
  598.                         if (chrnum(io.buffer_data, '\246')>5)
  599.                         || (strstr(io.buffer_data, "пр")) real_encoding = CH_CP1251;
  600.                 }
  601.         }
  602.         if (real_encoding != CH_CP866)
  603.                 ChangeCharset(real_encoding, "CP866", io.buffer_data);         
  604. }
  605.  
  606. void LoadFile(dword f_path)
  607. {
  608.         if (io.buffer_data) free(io.buffer_data);
  609.         if (ESBYTE[f_path]) {
  610.                 strcpy(#param, f_path);
  611.                 if (!io.read(#param)) goto NO_DATA;
  612.                 sprintf(#title, "%s - %s", #param, #short_app_name);
  613.                 EncodeToDos(); 
  614.         }
  615.         else {
  616.                 NO_DATA:
  617.                 io.buffer_data = malloc(sizeof(intro));
  618.                 strcpy(io.buffer_data, #intro);
  619.                 strcpy(#title, #short_app_name);
  620.         }
  621.         list.ClearList();
  622. }
  623.  
  624. int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) {
  625.         if (_hotkey) key.add_n(_hotkey, _event);
  626.         return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
  627. }
  628.  
  629.  
  630. void DrawToolbar()
  631. {
  632.         #define SMALL_GAP 26+5
  633.         #define BIG_GAP 26+18
  634.         incn x;
  635.         bool thema = false;
  636.         bool reopa = false;
  637.  
  638.         bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H);
  639.         if (menu_id == COLOR_SCHEME) thema = true;
  640.         if (menu_id == REOPEN_IN_APP) reopa = true;
  641.  
  642.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
  643.         DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
  644.        
  645.         //AddTopBarButton(#EventNewFile,        ECTRL+SCAN_CODE_KEY_N, 2,  x.set(8),         false);
  646.         AddTopBarButton(#EventOpenDialog,     ECTRL+SCAN_CODE_KEY_O, 0,  x.set(8), false);
  647.         //AddTopBarButton(#EventSave,           ECTRL+SCAN_CODE_KEY_S, 5,  x.inc(SMALL_GAP), false);
  648.         AddTopBarButton(#EventShowFileInfo,   ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
  649.         AddTopBarButton(#EventMagnifyMinus,   ECTRL+SCAN_CODE_MINUS, 32, x.inc(BIG_GAP),   false);
  650.         AddTopBarButton(#EventMagnifyPlus,    ECTRL+SCAN_CODE_PLUS,  33, x.inc(SMALL_GAP), false);
  651.         AddTopBarButton(#EventClickSearch,    ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP),   serha);  search_mx = EAX;
  652.         x.set(Form.cwidth-4);
  653.         AddTopBarButton(#EventShowInfo,       NULL,                  -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
  654.         AddTopBarButton(#EventShowThemesList, NULL,                  40, x.inc(-BIG_GAP), thema); theme_mx = EAX;
  655.         AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP),   reopa); reopenin_mx = EAX;
  656.         //AddTopBarButton(#EventOpenSysfuncs,   NULL,                  18, x.inc(-SMALL_GAP), false);
  657.         //AddTopBarButton(#EventOpenPipet,      NULL,                  39, x.inc(-SMALL_GAP), false);
  658.         DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
  659.                 60, 12, button.add(#EventShowCharsetsList));
  660. }
  661.  
  662. void DrawStatusBar(dword _in_text)
  663. {
  664.         static char status_text[64];
  665.         if (Form.status_window>2) return;
  666.         if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
  667.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
  668.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
  669.         WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
  670.                 60, sc.work_text, real_encoding*10+#charsets);
  671.         WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
  672. }
  673.  
  674. void draw_window()
  675. {
  676.         int old_w = list.w;
  677.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
  678.         GetProcessInfo(#Form, SelfInfo);
  679.         sc.get();
  680.         if (Form.status_window>2) return;
  681.         if (Form.width  < 430) { MoveSize(OLD,OLD,430,OLD); return; }
  682.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  683.        
  684.         button.init(40);
  685.         key.init(40);
  686.  
  687.         SetSizes(font_size);
  688.  
  689.         if ((list.w == old_w) && (list.count)) {
  690.                 DrawPage();
  691.         } else {
  692.                 ParseAndPaint();
  693.         }
  694.  
  695.         DrawToolbar();
  696.         DrawStatusBar(NULL);
  697. }
  698.  
  699. void DrawPage()
  700. {
  701.         scroll.max_area = list.count;
  702.         scroll.cur_area = list.visible;
  703.         scroll.position = list.first;
  704.         scroll.all_redraw = 0;
  705.         scroll.start_x = list.x + list.w;
  706.         scroll.start_y = list.y;
  707.         scroll.size_y = list.h;
  708.         scrollbar_v_draw(#scroll);
  709.  
  710.         DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x,
  711.                 scroll.size_y-1, scroll.bckg_col);
  712.         PaintVisible();
  713. }
  714.  
  715.  
  716. void SetSizes(char _size)
  717. {
  718.         font_size = _size;
  719.         if (font_size == 'S') list.SetFont(6, 9, 00001000b);
  720.         if (font_size == 'M') list.SetFont(8, 14, 00011000b);
  721.         list.item_w = list.font_w;
  722.         list.horisontal_selelection = true;
  723.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
  724.                 Form.cheight - TOOLBAR_H - search.height() - STATUSBAR_H /*- TAB_H*/,
  725.                 math.round(list.font_h * 1.4));
  726. }