Subversion Repositories Kolibri OS

Rev

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