Subversion Repositories Kolibri OS

Rev

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