Subversion Repositories Kolibri OS

Rev

Rev 8946 | Rev 9004 | 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 "#    Size      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&ROLLED_UP) 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.  
  107.         DrawBar(0,0, Form.cwidth, PANEL_TOP_H, sc.work);
  108.         DrawBar(0,Form.cheight-PANEL_BOTTOM_H, Form.cwidth, PANEL_BOTTOM_H, sc.work);
  109.         DrawWideRectangle(GAP-GAP, LIST_Y-GAP, GAP*2+list.w, GAP*2+list.h, GAP-2, sc.work);
  110.  
  111.         DefineButton(GAP, list.h + LIST_Y + 8, 110, 25, BT_DELETE_LAST, sc.button);
  112.         $inc edx
  113.         $add ebx, 130 << 16    //BT_DELETE_ALL
  114.         $int 64
  115.         $inc edx
  116.         $add ebx, 130 << 16    //BT_UNLOCK
  117.         $int 64
  118.  
  119.         WriteText(GAP+11, LIST_Y + list.h + 14, 0x90, sc.button_text, "Delete last      Delete all      Reset lock");
  120.  
  121.         WriteText(GAP+18, LIST_Y - 23, 0x90, sc.work_text, T_COLUMNS_TITLE);
  122.         WriteText(GAP+list.w - 70, LIST_Y - 23, 0x90, sc.work_text, T_COLUMN_VIEW);
  123.         ClipViewSelectListDraw();
  124.         SelectList_DrawBorder();
  125. }
  126.  
  127. dword slot_data;
  128. struct clipboard_data
  129. {
  130.         dword   size;
  131.         dword   type;
  132.         dword   encoding;
  133.         dword   content;
  134.         dword   content_offset;
  135. } cdata;
  136.  
  137. void SelectList_DrawLine(dword i)
  138. {
  139.         int yyy, slot_data_type_number;
  140.  
  141.         yyy = i*LINE_H+LIST_Y;
  142.         DrawBar(GAP, yyy, list.w, LINE_H, -i%2 * 0x0E0E0E + 0xF1F1f1);
  143.  
  144.         if (list.first + i >= list.count) {
  145.                 return;
  146.         }
  147.  
  148.         slot_data = Clipboard__GetSlotData(list.first + i);
  149.         cdata.size = ESDWORD[slot_data];
  150.         cdata.type = ESDWORD[slot_data+4];
  151.         if (cdata.type==SLOT_DATA_TYPE_TEXT) || (cdata.type==SLOT_DATA_TYPE_TEXT_BLOCK)
  152.                 cdata.content_offset = 12;
  153.         else
  154.                 cdata.content_offset = 8;
  155.         cdata.content = slot_data + cdata.content_offset;
  156.  
  157.         WriteText(list.first+i/10^1*8+GAP+12, yyy+TEXT_Y, 0x90, 0x000000, itoa(list.first + i));
  158.         EDX = ConvertSizeToKb(cdata.size);
  159.         WriteText(GAP+44+16, yyy+TEXT_Y, 0x90, 0x000000, EDX);
  160.         slot_data_type_number = cdata.type;
  161.         WriteText(GAP+140, yyy+TEXT_Y, 0x90, 0x000000, data_type[slot_data_type_number]);
  162.         WriteTextB(GAP+list.w - 88, yyy+TEXT_Y, 0x90, 0x006597, "TEXT  HEX");
  163.         DefineButton(GAP+list.w - 98, yyy, 50, LINE_H, 100+i+BT_HIDE, NULL);
  164.         $add edx, 200
  165.         $add ebx, 52 << 16 - 10 //BT_HEX
  166.         $int 64
  167.  
  168.         ESI = list.w - 345 / 8;
  169.         if (cdata.size - cdata.content_offset < ESI) ESI = cdata.size - cdata.content_offset;
  170.         WriteText(GAP+236, yyy+TEXT_Y, 0x30, 0x000000, cdata.content);
  171. }
  172.  
  173. int SaveSlotContents() {
  174.         if (! CreateFile(cdata.size, cdata.content, DEFAULT_SAVE_PATH)) {
  175.                 return true;
  176.         } else {
  177.                 notify("'Can not create /tmp0/1/clipview.tmp' -E");
  178.                 return false;
  179.         }
  180. }
  181.  
  182. void ClipViewSelectListDraw()
  183. {
  184.         int i, list_last;
  185.  
  186.         list.count = Clipboard__GetSlotCount();
  187.         if (list.first >= list.count) list.first = list.count - list.visible;
  188.         if (list.first < 0) list.first = 0;
  189.  
  190.         if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
  191.  
  192.         for (i=0; i<list_last; i++;) SelectList_DrawLine(i);
  193.  
  194.         DrawBar(GAP,i*LINE_H+LIST_Y, list.w, -i*LINE_H+ list.h, 0xFFFfff);
  195.         if (!list.count) WriteText(list.w / 2 + GAP - 60,
  196.                 list.h / 2 - 8 + LIST_Y, 0x90, 0x999999, "No data to show");
  197.  
  198.         //Show "<" and ">" buttons and a page number
  199.         //in case when there are items more than visible at once
  200.         if (list.count > list.visible) {
  201.                 param[0] = list.first / list.visible + '0';
  202.                 param[1] = '\0';
  203.                 DefineButton(Form.cwidth-84-GAP, list.h + LIST_Y + 8, 25, 25, BT_LIST_LEFT, sc.button); //BT_LEFT
  204.                 $inc edx
  205.                 $add ebx, 57 << 16 //BT_RIGHT
  206.                 $int 64
  207.                 WriteText(Form.cwidth-84-GAP+10, list.h + LIST_Y + 14, 0x90, sc.button_text, "<      >");
  208.                 $add ebx, 28 << 16
  209.                 $mov edx, #param;
  210.                 $mov edi, sc.work
  211.                 $mov ecx, 11010000b << 24
  212.                 $add ecx, sc.work_text //page number
  213.                 $int 64
  214.         }
  215. }
  216.  
  217. void SelectList_DrawBorder() {
  218.         DrawRectangle3D(GAP-2, LIST_Y-2,
  219.                 list.w+3, list.h+3,
  220.                 sc.work_dark, sc.work_light);
  221.         DrawRectangle3D(GAP-1, LIST_Y-1,
  222.                 list.w+1, list.h+1,
  223.                 sc.work_graph, sc.work_graph);
  224. }
  225.  
  226. //===================================================//
  227. //                                                   //
  228. //                     EVENTS                        //
  229. //                                                   //
  230. //===================================================//
  231.  
  232. void EventDeleteLastSlot()
  233. {
  234.         int i;
  235.         for (i=0; i<list.visible; i++;) {
  236.                 DeleteButton(list.first + i + 100);
  237.                 $add edx, 200
  238.                 $int 64
  239.         }
  240.         Clipboard__DeleteLastSlot();
  241.         DrawWindowContent();
  242. }
  243.  
  244. void EventDeleteAllSlots()
  245. {
  246.         while (Clipboard__GetSlotCount()) Clipboard__DeleteLastSlot();
  247.         DrawWindowContent();
  248. }
  249.  
  250. void EventResetBufferLock() {
  251.         Clipboard__ResetBlockingBuffer();
  252.         DrawWindowContent();
  253. }
  254.  
  255. void EventOpenAsText(int slot_id) {
  256.         slot_data = Clipboard__GetSlotData(slot_id);
  257.         cdata.size = ESDWORD[slot_data]-12;
  258.         cdata.content = slot_data+12;
  259.         if (SaveSlotContents()) RunProgram("/sys/develop/cedit", DEFAULT_SAVE_PATH);
  260. }
  261.  
  262. void EventOpenAsHex(int slot_id) {
  263.         slot_data = Clipboard__GetSlotData(slot_id);
  264.         cdata.size = ESDWORD[slot_data];
  265.         cdata.content = slot_data;
  266.         if (SaveSlotContents()) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
  267. }
  268.  
  269. stop:
  270.