Subversion Repositories Kolibri OS

Rev

Rev 7806 | Rev 7991 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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