Subversion Repositories Kolibri OS

Rev

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

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