Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef AUTOBUILD
  2.         ?include "lang.h--"
  3. #endif
  4.  
  5. #define MEMSIZE 0xDFE800
  6. #include "..\lib\mem.h"
  7. #include "..\lib\strings.h"
  8. #include "..\lib\list_box.h"
  9. #include "..\lib\clipboard.h"
  10. #include "..\lib\gui.h"
  11. #include "..\lib\obj\box_lib.h"
  12.  
  13.  
  14. //===================================================//
  15. //                                                   //
  16. //                       DATA                        //
  17. //                                                   //
  18. //===================================================//
  19.  
  20. ?define WINDOW_HEADER "Clipboard Viewer v1.02"
  21. ?define T_DELETE_LAST_SLOT "Delete last slot"
  22. ?define T_DELETE_ALL_SLOTS "Delete all slots"
  23. ?define T_RESET_BUFFER_LOCK "Reset the lock buffer"
  24. ?define T_COLUMNS_TITLE "# | Data size | Data type | Contents"
  25. ?define T_COLUMN_VIEW "View"
  26. ?define T_VIEW_OPTIONS "TEXT  HEX"
  27. ?define T_CLIPBOARD_IS_EMPTY "Clipboard is empty"
  28. ?define DEFAULT_SAVE_PATH "/tmp0/1/clipview.tmp"
  29. char *data_type[] = { "Text", "Image", "RAW", "Unknown" };
  30.  
  31. enum {
  32.         BT_DELETE_LAST_SLOT = 10,
  33.         BT_DELETE_ALL_SLOTS,
  34.         BT_UNLOCK
  35. };
  36.  
  37.  
  38. #define PANEL_TOP_H 20
  39. #define PANEL_BOTTOM_H 30
  40. #define LIST_PADDING 12
  41.  
  42. llist list;
  43.  
  44. proc_info Form;
  45.  
  46. Clipboard clipboard;
  47.  
  48. scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  49.  
  50.  
  51. //===================================================//
  52. //                                                   //
  53. //                       CODE                        //
  54. //                                                   //
  55. //===================================================//
  56.  
  57. void main()
  58. {  
  59.         int id;
  60.  
  61.         list.SetFont(8, 14, 0x90);
  62.         list.no_selection = true;
  63.         SetEventMask(0x27);
  64.         load_dll(boxlib, #box_lib_init,0);
  65.         loop()
  66.         {
  67.           WaitEventTimeout(10);
  68.           switch(EAX & 0xFF)
  69.           {
  70.                 case evMouse:
  71.                         if (!CheckActiveProcess(Form.ID)) break;
  72.                         mouse.get();
  73.                         scrollbar_v_mouse (#scroll1);
  74.                         if (list.first != scroll1.position)
  75.                         {
  76.                                 list.first = scroll1.position;
  77.                                 Draw_List();
  78.                                 break;
  79.                         }
  80.                         if (mouse.vert) && (list.MouseScroll(mouse.vert)) Draw_List();
  81.                         break;
  82.  
  83.  
  84.                 case evButton:
  85.                         id=GetButtonID();
  86.                         if (id==1) ExitProcess();
  87.                         if (id==BT_DELETE_LAST_SLOT) EventDeleteLastSlot();
  88.                         if (id==BT_DELETE_ALL_SLOTS) EventDeleteAllSlots();
  89.                         if (id==BT_UNLOCK) EventResetBufferLock();
  90.                         if (id>=100) && (id<300) EventOpenAsText(id-100);
  91.                         if (id>=300) EventOpenAsHex(id-300);
  92.                         break;
  93.          
  94.                 case evKey:
  95.                         GetKeys();
  96.                         if (list.ProcessKey(key_scancode)) Draw_List();
  97.                         break;
  98.                  
  99.                 case evReDraw:
  100.                         system.color.get();                    
  101.                         DefineAndDrawWindow(screen.width-700/2,80,700,454+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
  102.                         GetProcessInfo(#Form, SelfInfo);
  103.                         IF (Form.status_window>=2) break;
  104.                         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
  105.                         if (Form.width  < 570) { MoveSize(OLD,OLD,570,OLD); break; }
  106.                         list.SetSizes(LIST_PADDING, LIST_PADDING+PANEL_TOP_H, Form.cwidth-LIST_PADDING-LIST_PADDING-scroll1.size_x,
  107.                                 Form.cheight-PANEL_BOTTOM_H-PANEL_TOP_H-LIST_PADDING-LIST_PADDING, 20);
  108.                         DrawWindowContent();
  109.                         Draw_List();
  110.                         break;
  111.  
  112.                 default:
  113.                         if (clipboard.GetSlotCount() > list.count) Draw_List();
  114.                         break;
  115.           }
  116.    }
  117. }
  118.  
  119. void DrawWindowContent()
  120. {
  121.         int button_x = list.x;
  122.         DrawBar(0,0, Form.cwidth, PANEL_TOP_H, system.color.work);
  123.         DrawBar(0,Form.cheight-PANEL_BOTTOM_H, Form.cwidth, PANEL_BOTTOM_H, system.color.work);
  124.         DrawRectangle3D(list.x-2, list.y-2, list.w+3+scroll1.size_x, list.h+3, system.color.work_dark, system.color.work_light);
  125.         DrawWideRectangle(list.x-LIST_PADDING, list.y-LIST_PADDING, LIST_PADDING*2+list.w+scroll1.size_x, LIST_PADDING*2+list.h, LIST_PADDING-2, system.color.work);
  126.         button_x += DrawStandartCaptButton(button_x, list.y + list.h + 8, BT_DELETE_LAST_SLOT, T_DELETE_LAST_SLOT);
  127.         button_x += DrawStandartCaptButton(button_x, list.y + list.h + 8, BT_DELETE_ALL_SLOTS, T_DELETE_ALL_SLOTS);
  128.         button_x += DrawStandartCaptButton(button_x, list.y + list.h + 8, BT_UNLOCK, T_RESET_BUFFER_LOCK);
  129.         DrawRectangle(list.x-1, list.y-1, list.w+1+scroll1.size_x, list.h+1, system.color.work_graph);
  130.         WriteText(list.x+12, list.y - 23, list.font_type, system.color.work_text, T_COLUMNS_TITLE);
  131.         WriteText(list.x+list.w-68, list.y - 23, list.font_type, system.color.work_text, T_COLUMN_VIEW);
  132. }
  133.  
  134. void DrawScroller()
  135. {
  136.         scroll1.bckg_col = MixColors(system.color.work, 0xBBBbbb, 80);
  137.         scroll1.frnt_col = MixColors(system.color.work,0xFFFfff,120);
  138.         scroll1.line_col = system.color.work_graph;
  139.  
  140.         scroll1.max_area = list.count;
  141.         scroll1.cur_area = list.visible;
  142.         scroll1.position = list.first;
  143.  
  144.         scroll1.all_redraw=1;
  145.         scroll1.start_x = list.x + list.w;
  146.         scroll1.start_y = list.y-1;
  147.         scroll1.size_y = list.h+2;
  148.  
  149.         scrollbar_v_draw(#scroll1);
  150. }
  151.  
  152. replace_char(dword in_str, char from_char, to_char, int length) {
  153.         int i;
  154.         for (i=0; i<length; i++) {
  155.                 if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
  156.         }
  157.         ESBYTE[in_str+length]=0;
  158. }
  159.  
  160. void Draw_List()
  161. {
  162.         int i, yyy, list_last, slot_data_type_number, length;
  163.         dword line_text[2048];
  164.         dword size_kb;
  165.         dword text_color = 0;
  166.  
  167.         list.count = clipboard.GetSlotCount();
  168.         list.CheckDoesValuesOkey();
  169.  
  170.         if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
  171.  
  172.         for (i=0; i<list.visible; i++;) DeleteButton(list.first + i + 100);
  173.         for (i=0; i<list.visible; i++;) DeleteButton(list.first + i + 300);
  174.  
  175.         for (i=0; i<list_last; i++;)
  176.         {
  177.                 clipboard.GetSlotData(list.first + i);
  178.                 yyy = i*list.item_h+list.y;            
  179.                 DrawBar(list.x,yyy,list.w, list.item_h, 0xFFFfff);
  180.                 WriteText(list.x+12, yyy+list.text_y, list.font_type, text_color, itoa(list.first + i));
  181.                 //WriteText(list.x+44, yyy+list.text_y, list.font_type, text_color, itoa(clipboard.slot_data.size));
  182.                 size_kb = ConvertSizeToKb(clipboard.slot_data.size);
  183.                 WriteText(list.x+44, yyy+list.text_y, list.font_type, text_color, size_kb);
  184.                 slot_data_type_number = clipboard.slot_data.type;
  185.                 WriteText(list.x+140, yyy+list.text_y, list.font_type, text_color, data_type[slot_data_type_number]);
  186.                 WriteText(list.x+list.w - 88, yyy+list.text_y, list.font_type, 0x006597, T_VIEW_OPTIONS);
  187.                 DefineButton(list.x+list.w - 95, yyy, 50, list.item_h, 100+i+BT_HIDE, NULL);
  188.                 DefineButton(list.x+list.w - 95 + 51, yyy, 40, list.item_h, 300+i+BT_HIDE, NULL);
  189.  
  190.                 length = list.w-236 - 95 / list.font_w - 2;
  191.                 if (clipboard.slot_data.size-8 < length) length = clipboard.slot_data.size-8;
  192.                 memmov(#line_text, clipboard.slot_data.content, length);
  193.                 replace_char(#line_text, 0, 31, length); // 31 is a dot
  194.                 WriteText(list.x+236, yyy+list.text_y, list.font_type, text_color, #line_text);
  195.         }
  196.         DrawBar(list.x,i*list.item_h+list.y, list.w, -i*list.item_h+ list.h, 0xFFFfff);
  197.         if (!list.count) WriteText(-strlen(T_CLIPBOARD_IS_EMPTY)*list.font_w + list.w / 2 + list.x + 1,
  198.                 list.h / 2 - 8 + list.y, list.font_type, 0x999999, T_CLIPBOARD_IS_EMPTY);
  199.         DrawScroller();
  200. }
  201.  
  202. int SaveSlotContents(int slot_id) {
  203.         clipboard.GetSlotData(slot_id);
  204.         EAX = WriteFile(clipboard.slot_data.size, clipboard.slot_data.content, DEFAULT_SAVE_PATH);
  205.         if (!EAX)
  206.         {
  207.                 return true;
  208.         }
  209.         else {
  210.                 notify("'Can not create /tmp0/1/clipview.tmp\nPreview function is not available.' -E");
  211.                 return false;
  212.         }
  213. }
  214.  
  215. //===================================================//
  216. //                                                   //
  217. //                     EVENTS                        //
  218. //                                                   //
  219. //===================================================//
  220.  
  221. void EventDeleteLastSlot()
  222. {
  223.         clipboard.DelLastSlot();
  224.         Draw_List();
  225. }
  226.  
  227. void EventDeleteAllSlots()
  228. {
  229.         while (clipboard.GetSlotCount()) clipboard.DelLastSlot();
  230.         Draw_List();
  231. }
  232.  
  233. void EventResetBufferLock() {
  234.         clipboard.ResetBlockingBuffer();
  235.         Draw_List();
  236. }
  237.  
  238. void EventOpenAsText(int slot_id) {
  239.         if (SaveSlotContents(slot_id)) RunProgram("/sys/tinypad", DEFAULT_SAVE_PATH);
  240. }
  241.  
  242. void EventOpenAsHex(int slot_id) {
  243.         if (SaveSlotContents(slot_id)) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
  244. }
  245.  
  246. stop:
  247.