Subversion Repositories Kolibri OS

Rev

Rev 6638 | Rev 6653 | 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. #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.                         mouse.get();
  66.                         scrollbar_v_mouse (#scroll1);
  67.                         if (select_list.first != scroll1.position)
  68.                         {
  69.                                 select_list.first = scroll1.position;
  70.                                 DrawSelectList(clipboard.GetSlotCount());
  71.                                 break;
  72.                         }
  73.                         if (mouse.vert) && (select_list.MouseScroll(mouse.vert)) DrawSelectList(clipboard.GetSlotCount());
  74.                         break;
  75.  
  76.  
  77.                 case evButton:
  78.                         id=GetButtonID();
  79.                         if (id==1) ExitProcess();
  80.                         if (id==BT_DELETE_LAST_SLOT) EventDeleteLastSlot();
  81.                         if (id==BT_DELETE_ALL_SLOTS) EventDeleteAllSlots();
  82.                         if (id==BT_UNLOCK) EventResetBufferLock();
  83.                         if (id>=100) && (id<300) EventOpenAsText(id-100);
  84.                         if (id>=300) EventOpenAsHex(id-300);
  85.                         break;
  86.          
  87.                 case evKey:
  88.                         GetKeys();
  89.                         if (select_list.ProcessKey(key_scancode)) DrawSelectList(clipboard.GetSlotCount());
  90.                         break;
  91.                  
  92.                 case evReDraw:
  93.                         system.color.get();                    
  94.                         DefineAndDrawWindow(screen.width-700/2,80,700,454+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
  95.                         GetProcessInfo(#Form, SelfInfo);
  96.                         IF (Form.status_window>=2) break;
  97.                         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
  98.                         if (Form.width  < 570) { MoveSize(OLD,OLD,570,OLD); break; }
  99.                         InitSelectList(
  100.                                 LIST_PADDING,
  101.                                 LIST_PADDING+PANEL_TOP_H,
  102.                                 Form.cwidth-LIST_PADDING-LIST_PADDING-scroll1.size_x,
  103.                                 Form.cheight-PANEL_BOTTOM_H-PANEL_TOP_H-LIST_PADDING-LIST_PADDING,
  104.                                 true
  105.                         );
  106.                         DrawWindowContent();
  107.                         DrawSelectList(clipboard.GetSlotCount());
  108.                         break;
  109.  
  110.                 default:
  111.                         if (clipboard.GetSlotCount() > select_list.count) DrawSelectList(clipboard.GetSlotCount());
  112.                         break;
  113.           }
  114.    }
  115. }
  116.  
  117. void DrawWindowContent()
  118. {
  119.         int button_x = select_list.x;
  120.         DrawBar(0,0, Form.cwidth, PANEL_TOP_H, system.color.work);
  121.         DrawBar(0,Form.cheight-PANEL_BOTTOM_H, Form.cwidth, PANEL_BOTTOM_H, system.color.work);
  122.         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);
  123.         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);
  124.         button_x += DrawStandartCaptButton(button_x, select_list.y + select_list.h + 8, BT_DELETE_LAST_SLOT, T_DELETE_LAST_SLOT);
  125.         button_x += DrawStandartCaptButton(button_x, select_list.y + select_list.h + 8, BT_DELETE_ALL_SLOTS, T_DELETE_ALL_SLOTS);
  126.         button_x += DrawStandartCaptButton(button_x, select_list.y + select_list.h + 8, BT_UNLOCK, T_RESET_BUFFER_LOCK);
  127.         DrawRectangle(select_list.x-1, select_list.y-1, select_list.w+1+scroll1.size_x, select_list.h+1, system.color.work_graph);
  128.         WriteText(select_list.x+12, select_list.y - 23, select_list.font_type, system.color.work_text, T_COLUMNS_TITLE);
  129.         WriteText(select_list.x+select_list.w-68, select_list.y - 23, select_list.font_type, system.color.work_text, T_COLUMN_VIEW);
  130. }
  131.  
  132. void DrawSelectList_Line(dword i)
  133. {
  134.         int yyy, length, slot_data_type_number;
  135.         dword line_text[2048];
  136.         dword size_kb;
  137.         dword text_color = 0;
  138.  
  139.         clipboard.GetSlotData(select_list.first + i);
  140.         yyy = i*select_list.item_h+select_list.y;
  141.         WriteText(select_list.x+12, yyy+select_list.text_y, select_list.font_type, text_color, itoa(select_list.first + i));
  142.         //WriteText(select_list.x+44, yyy+select_list.text_y, select_list.font_type, text_color, itoa(clipboard.slot_data.size));
  143.         size_kb = ConvertSizeToKb(clipboard.slot_data.size);
  144.         WriteText(select_list.x+44, yyy+select_list.text_y, select_list.font_type, text_color, size_kb);
  145.         slot_data_type_number = clipboard.slot_data.type;
  146.         WriteText(select_list.x+140, yyy+select_list.text_y, select_list.font_type, text_color, data_type[slot_data_type_number]);
  147.         WriteText(select_list.x+select_list.w - 88, yyy+select_list.text_y, select_list.font_type, 0x006597, T_VIEW_OPTIONS);
  148.         DefineButton(select_list.x+select_list.w - 95, yyy, 50, select_list.item_h, 100+i+BT_HIDE, NULL);
  149.         DefineButton(select_list.x+select_list.w - 95 + 51, yyy, 40, select_list.item_h, 300+i+BT_HIDE, NULL);
  150.  
  151.         length = select_list.w-236 - 95 / select_list.font_w - 2;
  152.         if (clipboard.slot_data.size-8 < length) length = clipboard.slot_data.size-8;
  153.         memmov(#line_text, clipboard.slot_data.content, length);
  154.         replace_char(#line_text, 0, 31, length); // 31 is a dot
  155.         WriteText(select_list.x+236, yyy+select_list.text_y, select_list.font_type, text_color, #line_text);
  156. }
  157.  
  158.  
  159.  
  160. replace_char(dword in_str, char from_char, to_char, int length) {
  161.         int i;
  162.         for (i=0; i<length; i++) {
  163.                 if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
  164.         }
  165.         ESBYTE[in_str+length]=0;
  166. }
  167.  
  168. int SaveSlotContents(int slot_id) {
  169.         clipboard.GetSlotData(slot_id);
  170.         EAX = WriteFile(clipboard.slot_data.size, clipboard.slot_data.content, DEFAULT_SAVE_PATH);
  171.         if (!EAX)
  172.         {
  173.                 return true;
  174.         }
  175.         else {
  176.                 notify("'Can not create /tmp0/1/clipview.tmp\nPreview function is not available.' -E");
  177.                 return false;
  178.         }
  179. }
  180.  
  181. //===================================================//
  182. //                                                   //
  183. //                     EVENTS                        //
  184. //                                                   //
  185. //===================================================//
  186.  
  187. void EventDeleteLastSlot()
  188. {
  189.         clipboard.DelLastSlot();
  190.         DrawSelectList(clipboard.GetSlotCount());
  191. }
  192.  
  193. void EventDeleteAllSlots()
  194. {
  195.         while (clipboard.GetSlotCount()) clipboard.DelLastSlot();
  196.         DrawSelectList(clipboard.GetSlotCount());
  197. }
  198.  
  199. void EventResetBufferLock() {
  200.         clipboard.ResetBlockingBuffer();
  201.         DrawSelectList(clipboard.GetSlotCount());
  202. }
  203.  
  204. void EventOpenAsText(int slot_id) {
  205.         if (SaveSlotContents(slot_id)) RunProgram("/sys/tinypad", DEFAULT_SAVE_PATH);
  206. }
  207.  
  208. void EventOpenAsHex(int slot_id) {
  209.         if (SaveSlotContents(slot_id)) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
  210. }
  211.  
  212. stop:
  213.