2021-06-24 22:42:19 +02:00
|
|
|
#define ENTRY_POINT #main
|
2016-10-05 15:12:39 +02:00
|
|
|
|
2016-11-02 15:30:45 +01:00
|
|
|
#define MEMSIZE 4096*20
|
2021-06-24 22:42:19 +02:00
|
|
|
|
2016-10-05 15:12:39 +02:00
|
|
|
#include "..\lib\strings.h"
|
|
|
|
#include "..\lib\clipboard.h"
|
|
|
|
#include "..\lib\gui.h"
|
2021-06-24 22:42:19 +02:00
|
|
|
#include "..\lib\fs.h"
|
2016-10-05 15:12:39 +02:00
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// DATA //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2021-07-06 09:17:41 +02:00
|
|
|
?define T_COLUMNS_TITLE "# Size Type Contents"
|
2016-10-05 15:12:39 +02:00
|
|
|
?define DEFAULT_SAVE_PATH "/tmp0/1/clipview.tmp"
|
|
|
|
char *data_type[] = { "Text", "Image", "RAW", "Unknown" };
|
|
|
|
|
|
|
|
enum {
|
2021-06-24 22:42:19 +02:00
|
|
|
BT_DELETE_LAST = 10,
|
|
|
|
BT_DELETE_ALL,
|
|
|
|
BT_UNLOCK,
|
|
|
|
BT_LIST_LEFT,
|
|
|
|
BT_LIST_RIGHT
|
2016-10-05 15:12:39 +02:00
|
|
|
};
|
|
|
|
|
2021-06-24 22:42:19 +02:00
|
|
|
#define PANEL_BOTTOM_H 35
|
|
|
|
#define GAP 5
|
|
|
|
#define LIST_Y 32
|
|
|
|
#define PANEL_TOP_H LIST_Y-2
|
|
|
|
#define LINE_H 20
|
|
|
|
#define TEXT_Y LINE_H - 14 / 2
|
2016-10-05 15:12:39 +02:00
|
|
|
|
|
|
|
proc_info Form;
|
|
|
|
|
2021-06-24 22:42:19 +02:00
|
|
|
struct LIST {
|
|
|
|
int w,h;
|
|
|
|
int count;
|
|
|
|
int first;
|
|
|
|
int visible;
|
|
|
|
} list = 0;
|
|
|
|
|
2016-10-05 15:12:39 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// CODE //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2021-06-24 23:13:37 +02:00
|
|
|
@mem_init();
|
2021-06-24 22:42:19 +02:00
|
|
|
@SetEventMask(EVM_REDRAW + EVM_BUTTON);
|
2020-05-26 02:17:12 +02:00
|
|
|
loop() switch(@WaitEventTimeout(10))
|
2016-10-05 15:12:39 +02:00
|
|
|
{
|
|
|
|
case evButton:
|
2021-06-24 22:42:19 +02:00
|
|
|
@GetButtonID();
|
|
|
|
switch(EAX) {
|
|
|
|
case 1:
|
|
|
|
ExitProcess();
|
|
|
|
case BT_DELETE_LAST:
|
|
|
|
EventDeleteLastSlot();
|
|
|
|
break;
|
|
|
|
case BT_DELETE_ALL:
|
|
|
|
EventDeleteAllSlots();
|
|
|
|
break;
|
|
|
|
case BT_UNLOCK:
|
|
|
|
EventResetBufferLock();
|
|
|
|
break;
|
|
|
|
case BT_LIST_LEFT:
|
|
|
|
list.first -= list.visible;
|
|
|
|
if (list.first <= 0) list.first = 0;
|
|
|
|
ClipViewSelectListDraw();
|
|
|
|
break;
|
|
|
|
case BT_LIST_RIGHT:
|
|
|
|
if (list.first + list.visible < list.count) list.first += list.visible;
|
|
|
|
ClipViewSelectListDraw();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (EAX>=300) EventOpenAsHex(EAX-300);
|
|
|
|
else EventOpenAsText(EAX-100);
|
2020-05-26 02:17:12 +02:00
|
|
|
}
|
2016-10-05 15:12:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evReDraw:
|
2020-04-18 01:52:24 +02:00
|
|
|
sc.get();
|
2021-06-24 22:42:19 +02:00
|
|
|
DefineAndDrawWindow(GetScreenWidth()-600/2,80,600,400,0x73,NULL,"Clipboard Viewer",NULL);
|
2016-10-05 15:12:39 +02:00
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2021-06-26 09:59:13 +02:00
|
|
|
IF (Form.status_window&ROLLED_UP) break;
|
2020-05-26 02:17:12 +02:00
|
|
|
IF (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
|
|
|
|
IF (Form.width < 570) { MoveSize(OLD,OLD,570,OLD); break; }
|
2016-10-05 15:12:39 +02:00
|
|
|
DrawWindowContent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-06-24 22:42:19 +02:00
|
|
|
if (Clipboard__GetSlotCount() > list.count) ClipViewSelectListDraw();
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawWindowContent()
|
|
|
|
{
|
2021-06-24 22:42:19 +02:00
|
|
|
list.w = Form.cwidth-GAP-GAP;
|
|
|
|
list.h = Form.cheight-PANEL_BOTTOM_H-LIST_Y-GAP;
|
|
|
|
list.visible = list.h / LINE_H;
|
|
|
|
|
2020-04-18 01:52:24 +02:00
|
|
|
DrawBar(0,0, Form.cwidth, PANEL_TOP_H, sc.work);
|
|
|
|
DrawBar(0,Form.cheight-PANEL_BOTTOM_H, Form.cwidth, PANEL_BOTTOM_H, sc.work);
|
2021-06-24 22:42:19 +02:00
|
|
|
DrawWideRectangle(GAP-GAP, LIST_Y-GAP, GAP*2+list.w, GAP*2+list.h, GAP-2, sc.work);
|
|
|
|
|
|
|
|
DefineButton(GAP, list.h + LIST_Y + 8, 110, 25, BT_DELETE_LAST, sc.button);
|
|
|
|
$inc edx
|
|
|
|
$add ebx, 130 << 16 //BT_DELETE_ALL
|
|
|
|
$int 64
|
|
|
|
$inc edx
|
|
|
|
$add ebx, 130 << 16 //BT_UNLOCK
|
|
|
|
$int 64
|
|
|
|
|
2021-06-25 11:52:19 +02:00
|
|
|
WriteText(GAP+11, LIST_Y + list.h + 14, 0x90, sc.button_text, "Delete last Delete all Reset lock");
|
2021-06-24 22:42:19 +02:00
|
|
|
|
2021-07-06 09:17:41 +02:00
|
|
|
WriteText(GAP+18, LIST_Y - 23, 0x90, sc.work_text, T_COLUMNS_TITLE);
|
2016-11-03 13:41:15 +01:00
|
|
|
ClipViewSelectListDraw();
|
|
|
|
SelectList_DrawBorder();
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-01 13:57:00 +02:00
|
|
|
dword slot_data;
|
|
|
|
struct clipboard_data
|
|
|
|
{
|
|
|
|
dword size;
|
|
|
|
dword type;
|
|
|
|
dword encoding;
|
|
|
|
dword content;
|
|
|
|
dword content_offset;
|
|
|
|
} cdata;
|
|
|
|
|
2016-11-02 15:30:45 +01:00
|
|
|
void SelectList_DrawLine(dword i)
|
2016-10-05 15:12:39 +02:00
|
|
|
{
|
2021-06-24 22:42:19 +02:00
|
|
|
int yyy, slot_data_type_number;
|
|
|
|
|
|
|
|
yyy = i*LINE_H+LIST_Y;
|
|
|
|
DrawBar(GAP, yyy, list.w, LINE_H, -i%2 * 0x0E0E0E + 0xF1F1f1);
|
2016-10-05 15:12:39 +02:00
|
|
|
|
2021-06-24 22:42:19 +02:00
|
|
|
if (list.first + i >= list.count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot_data = Clipboard__GetSlotData(list.first + i);
|
2017-10-01 13:57:00 +02:00
|
|
|
cdata.size = ESDWORD[slot_data];
|
|
|
|
cdata.type = ESDWORD[slot_data+4];
|
|
|
|
if (cdata.type==SLOT_DATA_TYPE_TEXT) || (cdata.type==SLOT_DATA_TYPE_TEXT_BLOCK)
|
|
|
|
cdata.content_offset = 12;
|
|
|
|
else
|
|
|
|
cdata.content_offset = 8;
|
|
|
|
cdata.content = slot_data + cdata.content_offset;
|
|
|
|
|
2021-07-06 09:17:41 +02:00
|
|
|
WriteText(list.first+i/10^1*8+GAP+12, yyy+TEXT_Y, 0x90, 0x000000, itoa(list.first + i));
|
2020-05-26 02:17:12 +02:00
|
|
|
EDX = ConvertSizeToKb(cdata.size);
|
2021-07-06 09:17:41 +02:00
|
|
|
WriteText(GAP+44+16, yyy+TEXT_Y, 0x90, 0x000000, EDX);
|
2017-10-01 13:57:00 +02:00
|
|
|
slot_data_type_number = cdata.type;
|
2021-11-14 16:23:19 +01:00
|
|
|
if (slot_data_type_number >= 4) slot_data_type_number = 3;
|
2021-06-24 22:42:19 +02:00
|
|
|
WriteText(GAP+140, yyy+TEXT_Y, 0x90, 0x000000, data_type[slot_data_type_number]);
|
2021-07-06 09:17:41 +02:00
|
|
|
WriteTextB(GAP+list.w - 88, yyy+TEXT_Y, 0x90, 0x006597, "TEXT HEX");
|
2021-06-24 22:42:19 +02:00
|
|
|
DefineButton(GAP+list.w - 98, yyy, 50, LINE_H, 100+i+BT_HIDE, NULL);
|
2021-06-24 23:13:37 +02:00
|
|
|
$add edx, 200
|
|
|
|
$add ebx, 52 << 16 - 10 //BT_HEX
|
|
|
|
$int 64
|
2021-06-24 22:42:19 +02:00
|
|
|
|
|
|
|
ESI = list.w - 345 / 8;
|
|
|
|
if (cdata.size - cdata.content_offset < ESI) ESI = cdata.size - cdata.content_offset;
|
|
|
|
WriteText(GAP+236, yyy+TEXT_Y, 0x30, 0x000000, cdata.content);
|
2016-11-02 13:19:15 +01:00
|
|
|
}
|
2016-10-05 15:12:39 +02:00
|
|
|
|
2021-06-24 23:13:37 +02:00
|
|
|
int SaveSlotContents() {
|
|
|
|
if (! CreateFile(cdata.size, cdata.content, DEFAULT_SAVE_PATH)) {
|
2016-10-05 15:12:39 +02:00
|
|
|
return true;
|
2020-05-26 02:17:12 +02:00
|
|
|
} else {
|
2021-06-24 23:13:37 +02:00
|
|
|
notify("'Can not create /tmp0/1/clipview.tmp' -E");
|
2016-10-05 15:12:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-24 22:42:19 +02:00
|
|
|
void ClipViewSelectListDraw()
|
|
|
|
{
|
|
|
|
int i, list_last;
|
|
|
|
|
|
|
|
list.count = Clipboard__GetSlotCount();
|
2021-06-24 23:13:37 +02:00
|
|
|
if (list.first >= list.count) list.first = list.count - list.visible;
|
|
|
|
if (list.first < 0) list.first = 0;
|
2021-06-24 22:42:19 +02:00
|
|
|
|
|
|
|
if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
|
|
|
|
|
|
|
|
for (i=0; i<list_last; i++;) SelectList_DrawLine(i);
|
|
|
|
|
|
|
|
DrawBar(GAP,i*LINE_H+LIST_Y, list.w, -i*LINE_H+ list.h, 0xFFFfff);
|
|
|
|
if (!list.count) WriteText(list.w / 2 + GAP - 60,
|
|
|
|
list.h / 2 - 8 + LIST_Y, 0x90, 0x999999, "No data to show");
|
|
|
|
|
2021-06-25 11:52:19 +02:00
|
|
|
//Show "<" and ">" buttons and a page number
|
|
|
|
//in case when there are items more than visible at once
|
2021-06-24 22:42:19 +02:00
|
|
|
if (list.count > list.visible) {
|
|
|
|
param[0] = list.first / list.visible + '0';
|
2021-07-06 09:17:41 +02:00
|
|
|
param[1] = '\0';
|
2021-06-24 22:42:19 +02:00
|
|
|
DefineButton(Form.cwidth-84-GAP, list.h + LIST_Y + 8, 25, 25, BT_LIST_LEFT, sc.button); //BT_LEFT
|
|
|
|
$inc edx
|
|
|
|
$add ebx, 57 << 16 //BT_RIGHT
|
|
|
|
$int 64
|
|
|
|
WriteText(Form.cwidth-84-GAP+10, list.h + LIST_Y + 14, 0x90, sc.button_text, "< >");
|
|
|
|
$add ebx, 28 << 16
|
|
|
|
$mov edx, #param;
|
2021-06-24 23:13:37 +02:00
|
|
|
$mov edi, sc.work
|
2021-07-06 09:17:41 +02:00
|
|
|
$mov ecx, 11010000b << 24
|
2021-06-25 11:52:19 +02:00
|
|
|
$add ecx, sc.work_text //page number
|
2021-06-24 22:42:19 +02:00
|
|
|
$int 64
|
|
|
|
}
|
2016-11-02 15:30:45 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 22:42:19 +02:00
|
|
|
void SelectList_DrawBorder() {
|
|
|
|
DrawRectangle3D(GAP-2, LIST_Y-2,
|
|
|
|
list.w+3, list.h+3,
|
2022-01-09 07:36:16 +01:00
|
|
|
sc.dark, sc.light);
|
2021-06-24 22:42:19 +02:00
|
|
|
DrawRectangle3D(GAP-1, LIST_Y-1,
|
|
|
|
list.w+1, list.h+1,
|
2022-01-09 07:36:16 +01:00
|
|
|
sc.line, sc.line);
|
2016-11-02 15:30:45 +01:00
|
|
|
}
|
|
|
|
|
2016-10-05 15:12:39 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// EVENTS //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
void EventDeleteLastSlot()
|
|
|
|
{
|
2016-11-02 15:30:45 +01:00
|
|
|
int i;
|
2021-06-24 22:42:19 +02:00
|
|
|
for (i=0; i<list.visible; i++;) {
|
|
|
|
DeleteButton(list.first + i + 100);
|
|
|
|
$add edx, 200
|
|
|
|
$int 64
|
|
|
|
}
|
2017-10-01 13:57:00 +02:00
|
|
|
Clipboard__DeleteLastSlot();
|
2021-06-24 22:42:19 +02:00
|
|
|
DrawWindowContent();
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventDeleteAllSlots()
|
|
|
|
{
|
2017-10-01 13:57:00 +02:00
|
|
|
while (Clipboard__GetSlotCount()) Clipboard__DeleteLastSlot();
|
2021-06-24 22:42:19 +02:00
|
|
|
DrawWindowContent();
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventResetBufferLock() {
|
2017-10-01 13:57:00 +02:00
|
|
|
Clipboard__ResetBlockingBuffer();
|
2021-06-24 22:42:19 +02:00
|
|
|
DrawWindowContent();
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventOpenAsText(int slot_id) {
|
2017-10-01 13:57:00 +02:00
|
|
|
slot_data = Clipboard__GetSlotData(slot_id);
|
|
|
|
cdata.size = ESDWORD[slot_data]-12;
|
|
|
|
cdata.content = slot_data+12;
|
2021-06-24 23:13:37 +02:00
|
|
|
if (SaveSlotContents()) RunProgram("/sys/develop/cedit", DEFAULT_SAVE_PATH);
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventOpenAsHex(int slot_id) {
|
2017-10-01 13:57:00 +02:00
|
|
|
slot_data = Clipboard__GetSlotData(slot_id);
|
|
|
|
cdata.size = ESDWORD[slot_data];
|
|
|
|
cdata.content = slot_data;
|
2021-06-24 23:13:37 +02:00
|
|
|
if (SaveSlotContents()) RunProgram("/sys/develop/heed", DEFAULT_SAVE_PATH);
|
2016-10-05 15:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stop:
|