Subversion Repositories Kolibri OS

Rev

Rev 6570 | Rev 6638 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6567 leency 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
 
6570 leency 20
?define WINDOW_HEADER "Clipboard Viewer v1.01"
6567 leency 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);
6631 leency 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);
6567 leency 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
 
153
void Draw_List()
154
{
155
	int i, yyy, list_last, slot_data_type_number;
156
	dword text_color = 0x000000;
157
	char line_text[512];
158
	dword size_kb;
159
 
160
	list.count = clipboard.GetSlotCount();
161
	list.CheckDoesValuesOkey();
162
 
163
 
164
	if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
165
 
166
	for (i=0; i
167
	for (i=0; i
168
 
169
	for (i=0; i
170
	{
171
		clipboard.GetSlotData(list.first + i);
172
		yyy = i*list.item_h+list.y;
173
		DrawBar(list.x,yyy,list.w, list.item_h, 0xFFFfff);
174
		WriteText(list.x+12, yyy+list.text_y, list.font_type, text_color, itoa(list.first + i));
175
		//WriteText(list.x+44, yyy+list.text_y, list.font_type, text_color, itoa(clipboard.slot_data.size));
176
		size_kb = ConvertSizeToKb(clipboard.slot_data.size);
177
		WriteText(list.x+44, yyy+list.text_y, list.font_type, text_color, size_kb);
178
		slot_data_type_number = clipboard.slot_data.type;
179
		WriteText(list.x+140, yyy+list.text_y, list.font_type, text_color, data_type[slot_data_type_number]);
180
		WriteText(list.x+list.w - 88, yyy+list.text_y, list.font_type, 0x006597, T_VIEW_OPTIONS);
181
		DefineButton(list.x+list.w - 95, yyy, 50, list.item_h, 100+i+BT_HIDE, NULL);
182
		DefineButton(list.x+list.w - 95 + 51, yyy, 40, list.item_h, 300+i+BT_HIDE, NULL);
183
 
184
		strlcpy(#line_text, clipboard.slot_data.content, list.w-236 - 95/list.font_w-3);
185
		WriteText(list.x+236, yyy+list.text_y, list.font_type, text_color, #line_text);
186
	}
187
	DrawBar(list.x,i*list.item_h+list.y, list.w, -i*list.item_h+ list.h, 0xFFFfff);
188
	if (!list.count) WriteText(-strlen(T_CLIPBOARD_IS_EMPTY)*list.font_w + list.w / 2 + list.x + 1, list.h / 2 - 8 + list.y, list.font_type, 0x999999, T_CLIPBOARD_IS_EMPTY);
189
	DrawScroller();
190
}
191
 
192
int SaveSlotContents(int slot_id) {
193
	clipboard.GetSlotData(slot_id);
194
	EAX = WriteFile(clipboard.slot_data.size, clipboard.slot_data.content, DEFAULT_SAVE_PATH);
195
	if (!EAX)
196
	{
197
		return true;
198
	}
199
	else {
200
		notify("'Can not create /tmp0/1/clipview.tmp\nPreview function is not available.' -E");
201
	 	return false;
202
	}
203
}
204
 
205
//===================================================//
206
//                                                   //
207
//                     EVENTS                        //
208
//                                                   //
209
//===================================================//
210
 
211
void EventDeleteLastSlot()
212
{
213
	clipboard.DelLastSlot();
214
	Draw_List();
215
}
216
 
217
void EventDeleteAllSlots()
218
{
219
	while (clipboard.GetSlotCount()) clipboard.DelLastSlot();
220
	Draw_List();
221
}
222
 
223
void EventResetBufferLock() {
224
	clipboard.ResetBlockingBuffer();
225
	Draw_List();
226
}
227
 
228
void EventOpenAsText(int slot_id) {
229
	if (SaveSlotContents(slot_id)) RunProgram("/sys/tinypad", DEFAULT_SAVE_PATH);
230
}
231
 
232
void EventOpenAsHex(int slot_id) {
233
	if (SaveSlotContents(slot_id)) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
234
}
235
 
236
stop: