Subversion Repositories Kolibri OS

Rev

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

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