Subversion Repositories Kolibri OS

Rev

Rev 6662 | Rev 7050 | 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
 
6653 leency 5
#define MEMSIZE 4096*20
6567 leency 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
 
6651 leency 13
#include "..\lib\patterns\select_list.h"
6567 leency 14
 
6651 leency 15
 
6567 leency 16
//===================================================//
17
//                                                   //
18
//                       DATA                        //
19
//                                                   //
20
//===================================================//
21
 
6638 leency 22
?define WINDOW_HEADER "Clipboard Viewer v1.02"
6567 leency 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
//===================================================//
45
//                                                   //
46
//                       CODE                        //
47
//                                                   //
48
//===================================================//
49
 
50
void main()
51
{
52
	int id;
7037 leency 53
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
6567 leency 54
	load_dll(boxlib, #box_lib_init,0);
55
	loop()
56
	{
57
	  WaitEventTimeout(10);
58
	  switch(EAX & 0xFF)
59
	  {
60
	  	case evMouse:
6653 leency 61
			SelectList_ProcessMouse();
6567 leency 62
	  		break;
63
 
64
		case evButton:
7037 leency 65
			id = GetButtonID();
6567 leency 66
			if (id==1) ExitProcess();
67
			if (id==BT_DELETE_LAST_SLOT) EventDeleteLastSlot();
68
			if (id==BT_DELETE_ALL_SLOTS) EventDeleteAllSlots();
69
			if (id==BT_UNLOCK) EventResetBufferLock();
70
			if (id>=100) && (id<300) EventOpenAsText(id-100);
71
			if (id>=300) EventOpenAsHex(id-300);
72
			break;
73
 
74
		case evKey:
75
			GetKeys();
6653 leency 76
			if (select_list.ProcessKey(key_scancode)) ClipViewSelectListDraw();
6567 leency 77
			break;
78
 
79
		case evReDraw:
80
			system.color.get();
81
			DefineAndDrawWindow(screen.width-700/2,80,700,454+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
82
			GetProcessInfo(#Form, SelfInfo);
83
			IF (Form.status_window>=2) break;
84
			if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
85
			if (Form.width  < 570) { MoveSize(OLD,OLD,570,OLD); break; }
6653 leency 86
			SelectList_Init(
6651 leency 87
				LIST_PADDING,
88
				LIST_PADDING+PANEL_TOP_H,
89
				Form.cwidth-LIST_PADDING-LIST_PADDING-scroll1.size_x,
90
				Form.cheight-PANEL_BOTTOM_H-PANEL_TOP_H-LIST_PADDING-LIST_PADDING,
91
				true
6653 leency 92
				);
6567 leency 93
		 	DrawWindowContent();
94
		 	break;
95
 
96
		default:
7037 leency 97
			if (Clipboard__GetSlotCount() > select_list.count) ClipViewSelectListDraw();
6567 leency 98
			break;
99
	  }
100
   }
101
}
102
 
103
void DrawWindowContent()
104
{
6651 leency 105
	int button_x = select_list.x;
6567 leency 106
	DrawBar(0,0, Form.cwidth, PANEL_TOP_H, system.color.work);
107
	DrawBar(0,Form.cheight-PANEL_BOTTOM_H, Form.cwidth, PANEL_BOTTOM_H, system.color.work);
6651 leency 108
	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);
109
	button_x += DrawStandartCaptButton(button_x, select_list.y + select_list.h + 8, BT_DELETE_LAST_SLOT, T_DELETE_LAST_SLOT);
110
	button_x += DrawStandartCaptButton(button_x, select_list.y + select_list.h + 8, BT_DELETE_ALL_SLOTS, T_DELETE_ALL_SLOTS);
111
	button_x += DrawStandartCaptButton(button_x, select_list.y + select_list.h + 8, BT_UNLOCK, T_RESET_BUFFER_LOCK);
112
	WriteText(select_list.x+12, select_list.y - 23, select_list.font_type, system.color.work_text, T_COLUMNS_TITLE);
113
	WriteText(select_list.x+select_list.w-68, select_list.y - 23, select_list.font_type, system.color.work_text, T_COLUMN_VIEW);
6662 leency 114
 	ClipViewSelectListDraw();
115
 	SelectList_DrawBorder();
6567 leency 116
}
117
 
7037 leency 118
dword slot_data;
119
struct clipboard_data
120
{
121
	dword	size;
122
	dword	type;
123
	dword	encoding;
124
	dword	content;
125
	dword	content_offset;
126
} cdata;
127
 
6653 leency 128
void SelectList_DrawLine(dword i)
6567 leency 129
{
6651 leency 130
	int yyy, length, slot_data_type_number;
131
	dword line_text[2048];
132
	dword size_kb;
133
	dword text_color = 0;
6567 leency 134
 
7037 leency 135
	slot_data = Clipboard__GetSlotData(select_list.first + i);
136
	cdata.size = ESDWORD[slot_data];
137
	cdata.type = ESDWORD[slot_data+4];
138
	if (cdata.type==SLOT_DATA_TYPE_TEXT) || (cdata.type==SLOT_DATA_TYPE_TEXT_BLOCK)
139
		cdata.content_offset = 12;
140
	else
141
		cdata.content_offset = 8;
142
	cdata.content = slot_data + cdata.content_offset;
143
 
6651 leency 144
	yyy = i*select_list.item_h+select_list.y;
145
	WriteText(select_list.x+12, yyy+select_list.text_y, select_list.font_type, text_color, itoa(select_list.first + i));
7037 leency 146
	size_kb = ConvertSizeToKb(cdata.size);
6651 leency 147
	WriteText(select_list.x+44, yyy+select_list.text_y, select_list.font_type, text_color, size_kb);
7037 leency 148
	slot_data_type_number = cdata.type;
6651 leency 149
	WriteText(select_list.x+140, yyy+select_list.text_y, select_list.font_type, text_color, data_type[slot_data_type_number]);
150
	WriteText(select_list.x+select_list.w - 88, yyy+select_list.text_y, select_list.font_type, 0x006597, T_VIEW_OPTIONS);
151
	DefineButton(select_list.x+select_list.w - 95, yyy, 50, select_list.item_h, 100+i+BT_HIDE, NULL);
152
	DefineButton(select_list.x+select_list.w - 95 + 51, yyy, 40, select_list.item_h, 300+i+BT_HIDE, NULL);
6567 leency 153
 
6651 leency 154
	length = select_list.w-236 - 95 / select_list.font_w - 2;
7037 leency 155
	if (cdata.size - cdata.content_offset < length) length = cdata.size - cdata.content_offset;
156
	memmov(#line_text, cdata.content, length);
6651 leency 157
	replace_char(#line_text, 0, 31, length); // 31 is a dot
158
	WriteText(select_list.x+236, yyy+select_list.text_y, select_list.font_type, text_color, #line_text);
6567 leency 159
}
160
 
6651 leency 161
 
162
 
6638 leency 163
replace_char(dword in_str, char from_char, to_char, int length) {
164
	int i;
165
	for (i=0; i
166
		if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
167
	}
168
	ESBYTE[in_str+length]=0;
169
}
6567 leency 170
 
7037 leency 171
int SaveSlotContents(dword size, off) {
172
	EAX = WriteFile(size, off, DEFAULT_SAVE_PATH);
6567 leency 173
	if (!EAX)
174
	{
175
		return true;
176
	}
177
	else {
178
		notify("'Can not create /tmp0/1/clipview.tmp\nPreview function is not available.' -E");
179
	 	return false;
180
	}
181
}
182
 
6653 leency 183
void ClipViewSelectListDraw() {
7037 leency 184
	select_list.count = Clipboard__GetSlotCount();
6653 leency 185
	SelectList_Draw();
186
}
187
 
188
void SelectList_LineChanged() {
189
	return;
190
}
191
 
6567 leency 192
//===================================================//
193
//                                                   //
194
//                     EVENTS                        //
195
//                                                   //
196
//===================================================//
197
 
198
void EventDeleteLastSlot()
199
{
6653 leency 200
	int i;
201
	for (i=0; i
202
	for (i=0; i
7037 leency 203
	Clipboard__DeleteLastSlot();
6653 leency 204
	ClipViewSelectListDraw();
6567 leency 205
}
206
 
207
void EventDeleteAllSlots()
208
{
7037 leency 209
	while (Clipboard__GetSlotCount()) Clipboard__DeleteLastSlot();
6653 leency 210
	ClipViewSelectListDraw();
6567 leency 211
}
212
 
213
void EventResetBufferLock() {
7037 leency 214
	Clipboard__ResetBlockingBuffer();
6653 leency 215
	ClipViewSelectListDraw();
6567 leency 216
}
217
 
218
void EventOpenAsText(int slot_id) {
7037 leency 219
	slot_data = Clipboard__GetSlotData(slot_id);
220
	cdata.size = ESDWORD[slot_data]-12;
221
	cdata.content = slot_data+12;
222
	if (SaveSlotContents(cdata.size, cdata.content)) RunProgram("/sys/tinypad", DEFAULT_SAVE_PATH);
6567 leency 223
}
224
 
225
void EventOpenAsHex(int slot_id) {
7037 leency 226
	slot_data = Clipboard__GetSlotData(slot_id);
227
	cdata.size = ESDWORD[slot_data];
228
	cdata.content = slot_data;
229
	if (SaveSlotContents(cdata.size, cdata.content)) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
6567 leency 230
}
231
 
232
stop: