Subversion Repositories Kolibri OS

Rev

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

  1. #define ENTRY_POINT #main
  2.  
  3. #define MEMSIZE 4096*20
  4.  
  5. #include "..\lib\strings.h"
  6. #include "..\lib\clipboard.h"
  7. #include "..\lib\gui.h"
  8. #include "..\lib\fs.h"
  9.  
  10. //===================================================//
  11. //                                                   //
  12. //                       DATA                        //
  13. //                                                   //
  14. //===================================================//
  15.  
  16. ?define T_COLUMNS_TITLE "# | Data size | Data type | Contents"
  17. ?define T_COLUMN_VIEW "| View"
  18. ?define DEFAULT_SAVE_PATH "/tmp0/1/clipview.tmp"
  19. char *data_type[] = { "Text", "Image", "RAW", "Unknown" };
  20.  
  21. enum {
  22.         BT_DELETE_LAST = 10,
  23.         BT_DELETE_ALL,
  24.         BT_UNLOCK,
  25.         BT_LIST_LEFT,
  26.         BT_LIST_RIGHT
  27. };
  28.  
  29. #define PANEL_BOTTOM_H 35
  30. #define GAP 5
  31. #define LIST_Y 32
  32. #define PANEL_TOP_H LIST_Y-2
  33. #define LINE_H 20
  34. #define TEXT_Y LINE_H - 14 / 2
  35.  
  36. proc_info Form;
  37.  
  38. struct LIST {
  39.         int w,h;
  40.         int count;
  41.         int first;
  42.         int visible;
  43. } list = 0;
  44.  
  45. //===================================================//
  46. //                                                   //
  47. //                       CODE                        //
  48. //                                                   //
  49. //===================================================//
  50.  
  51. void main()
  52. {  
  53.         mem_init();
  54.         @SetEventMask(EVM_REDRAW + EVM_BUTTON);
  55.         loop() switch(@WaitEventTimeout(10))
  56.         {
  57.                 case evButton:
  58.                         @GetButtonID();
  59.                         switch(EAX) {
  60.                                 case 1:
  61.                                         ExitProcess();
  62.                                 case BT_DELETE_LAST:
  63.                                         EventDeleteLastSlot();
  64.                                         break;
  65.                                 case BT_DELETE_ALL:
  66.                                         EventDeleteAllSlots();
  67.                                         break;
  68.                                 case BT_UNLOCK:
  69.                                         EventResetBufferLock();
  70.                                         break;
  71.                                 case BT_LIST_LEFT:
  72.                                         list.first -= list.visible;
  73.                                         if (list.first <= 0) list.first = 0;
  74.                                         ClipViewSelectListDraw();
  75.                                         break;
  76.                                 case BT_LIST_RIGHT:
  77.                                         if (list.first + list.visible < list.count) list.first += list.visible;
  78.                                         ClipViewSelectListDraw();
  79.                                         break;
  80.                                 default:
  81.                                         if (EAX>=300) EventOpenAsHex(EAX-300);
  82.                                         else EventOpenAsText(EAX-100);
  83.                         }
  84.                         break;
  85.                  
  86.                 case evReDraw:
  87.                         sc.get();                      
  88.                         DefineAndDrawWindow(GetScreenWidth()-600/2,80,600,400,0x73,NULL,"Clipboard Viewer",NULL);
  89.                         GetProcessInfo(#Form, SelfInfo);
  90.                         IF (Form.status_window>=2) break;
  91.                         IF (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
  92.                         IF (Form.width  < 570) { MoveSize(OLD,OLD,570,OLD); break; }
  93.                         DrawWindowContent();
  94.                         break;
  95.  
  96.                 default:
  97.                         if (Clipboard__GetSlotCount() > list.count) ClipViewSelectListDraw();
  98.    }
  99. }
  100.  
  101. void DrawWindowContent()
  102. {
  103.         list.w = Form.cwidth-GAP-GAP;
  104.         list.h = Form.cheight-PANEL_BOTTOM_H-LIST_Y-GAP;
  105.         list.visible = list.h / LINE_H;
  106.         if (list.first > list.count) list.first = list.count - list.visible;
  107.  
  108.         DrawBar(0,0, Form.cwidth, PANEL_TOP_H, sc.work);
  109.         DrawBar(0,Form.cheight-PANEL_BOTTOM_H, Form.cwidth, PANEL_BOTTOM_H, sc.work);
  110.         DrawWideRectangle(GAP-GAP, LIST_Y-GAP, GAP*2+list.w, GAP*2+list.h, GAP-2, sc.work);
  111.  
  112.         DefineButton(GAP, list.h + LIST_Y + 8, 110, 25, BT_DELETE_LAST, sc.button);
  113.         $inc edx
  114.         $add ebx, 130 << 16    //BT_DELETE_ALL
  115.         $int 64
  116.         $inc edx
  117.         $add ebx, 130 << 16    //BT_UNLOCK
  118.         $int 64
  119.  
  120.         WriteText(GAP+10, LIST_Y + list.h + 14, 0x90, sc.button_text, "Delete last      Delete all        Unlock");
  121.  
  122.         WriteText(GAP+12, LIST_Y - 23, 0x90, sc.work_text, T_COLUMNS_TITLE);
  123.         WriteText(GAP+list.w - 88-14, LIST_Y - 23, 0x90, sc.work_text, T_COLUMN_VIEW);
  124.         ClipViewSelectListDraw();
  125.         SelectList_DrawBorder();
  126. }
  127.  
  128. dword slot_data;
  129. struct clipboard_data
  130. {
  131.         dword   size;
  132.         dword   type;
  133.         dword   encoding;
  134.         dword   content;
  135.         dword   content_offset;
  136. } cdata;
  137.  
  138. void SelectList_DrawLine(dword i)
  139. {
  140.         int yyy, slot_data_type_number;
  141.  
  142.         yyy = i*LINE_H+LIST_Y;
  143.         DrawBar(GAP, yyy, list.w, LINE_H, -i%2 * 0x0E0E0E + 0xF1F1f1);
  144.  
  145.         if (list.first + i >= list.count) {
  146.                 return;
  147.         }
  148.  
  149.         slot_data = Clipboard__GetSlotData(list.first + i);
  150.         cdata.size = ESDWORD[slot_data];
  151.         cdata.type = ESDWORD[slot_data+4];
  152.         if (cdata.type==SLOT_DATA_TYPE_TEXT) || (cdata.type==SLOT_DATA_TYPE_TEXT_BLOCK)
  153.                 cdata.content_offset = 12;
  154.         else
  155.                 cdata.content_offset = 8;
  156.         cdata.content = slot_data + cdata.content_offset;
  157.  
  158.         WriteText(GAP+12, yyy+TEXT_Y, 0x90, 0x000000, itoa(list.first + i));
  159.         EDX = ConvertSizeToKb(cdata.size);
  160.         WriteText(GAP+44, yyy+TEXT_Y, 0x90, 0x000000, EDX);
  161.         slot_data_type_number = cdata.type;
  162.         WriteText(GAP+140, yyy+TEXT_Y, 0x90, 0x000000, data_type[slot_data_type_number]);
  163.         WriteText(GAP+list.w - 88, yyy+TEXT_Y, 0x90, 0x006597, "TEXT  HEX");
  164.         DefineButton(GAP+list.w - 98, yyy, 50, LINE_H, 100+i+BT_HIDE, NULL);
  165.         DefineButton(GAP+list.w - 95 + 51, yyy, 40, LINE_H, 300+i+BT_HIDE, NULL);
  166.  
  167.         ESI = list.w - 345 / 8;
  168.         if (cdata.size - cdata.content_offset < ESI) ESI = cdata.size - cdata.content_offset;
  169.         WriteText(GAP+236, yyy+TEXT_Y, 0x30, 0x000000, cdata.content);
  170. }
  171.  
  172. int SaveSlotContents(dword size, off) {
  173.         if (! CreateFile(size, off, DEFAULT_SAVE_PATH)) {
  174.                 return true;
  175.         } else {
  176.                 notify("'Can not create /tmp0/1/clipview.tmp\nPreview function is not available.' -E");
  177.                 return false;
  178.         }
  179. }
  180.  
  181. void ClipViewSelectListDraw()
  182. {
  183.         int i, list_last;
  184.  
  185.         list.count = Clipboard__GetSlotCount();
  186.  
  187.         if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
  188.  
  189.         for (i=0; i<list_last; i++;) SelectList_DrawLine(i);
  190.  
  191.         DrawBar(GAP,i*LINE_H+LIST_Y, list.w, -i*LINE_H+ list.h, 0xFFFfff);
  192.         if (!list.count) WriteText(list.w / 2 + GAP - 60,
  193.                 list.h / 2 - 8 + LIST_Y, 0x90, 0x999999, "No data to show");
  194.  
  195.         if (list.count > list.visible) {
  196.                 param[0] = list.first / list.visible + '0';
  197.                 DefineButton(Form.cwidth-84-GAP, list.h + LIST_Y + 8, 25, 25, BT_LIST_LEFT, sc.button); //BT_LEFT
  198.                 $inc edx
  199.                 $add ebx, 57 << 16 //BT_RIGHT
  200.                 $int 64
  201.                 WriteText(Form.cwidth-84-GAP+10, list.h + LIST_Y + 14, 0x90, sc.button_text, "<      >");
  202.                 $add ebx, 28 << 16
  203.                 $mov edx, #param;
  204.                 $mov edi, sc.work_text
  205.                 $add ecx, 0x40 << 24
  206.                 $int 64
  207.         }
  208. }
  209.  
  210. void SelectList_DrawBorder() {
  211.         DrawRectangle3D(GAP-2, LIST_Y-2,
  212.                 list.w+3, list.h+3,
  213.                 sc.work_dark, sc.work_light);
  214.         DrawRectangle3D(GAP-1, LIST_Y-1,
  215.                 list.w+1, list.h+1,
  216.                 sc.work_graph, sc.work_graph);
  217. }
  218.  
  219. //===================================================//
  220. //                                                   //
  221. //                     EVENTS                        //
  222. //                                                   //
  223. //===================================================//
  224.  
  225. void EventDeleteLastSlot()
  226. {
  227.         int i;
  228.         for (i=0; i<list.visible; i++;) {
  229.                 DeleteButton(list.first + i + 100);
  230.                 $add edx, 200
  231.                 $int 64
  232.         }
  233.         Clipboard__DeleteLastSlot();
  234.         DrawWindowContent();
  235. }
  236.  
  237. void EventDeleteAllSlots()
  238. {
  239.         while (Clipboard__GetSlotCount()) Clipboard__DeleteLastSlot();
  240.         DrawWindowContent();
  241. }
  242.  
  243. void EventResetBufferLock() {
  244.         Clipboard__ResetBlockingBuffer();
  245.         DrawWindowContent();
  246. }
  247.  
  248. void EventOpenAsText(int slot_id) {
  249.         slot_data = Clipboard__GetSlotData(slot_id);
  250.         cdata.size = ESDWORD[slot_data]-12;
  251.         cdata.content = slot_data+12;
  252.         if (SaveSlotContents(cdata.size, cdata.content)) RunProgram("/sys/develop/cedit", DEFAULT_SAVE_PATH);
  253. }
  254.  
  255. void EventOpenAsHex(int slot_id) {
  256.         slot_data = Clipboard__GetSlotData(slot_id);
  257.         cdata.size = ESDWORD[slot_data];
  258.         cdata.content = slot_data;
  259.         if (SaveSlotContents(cdata.size, cdata.content)) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
  260. }
  261.  
  262. stop:
  263.