Compare commits

...

5 Commits

Author SHA1 Message Date
NishiOwO
72820e87f1 rename clipboard_received to clipboard 2025-12-31 04:35:10 +09:00
NishiOwO
d3147ac087 format 2025-12-31 04:29:27 +09:00
NishiOwO
4bdda59693 better api for clipboard 2025-12-31 04:29:13 +09:00
NishiOwO
823c865791 handle WM_DELETE_WINDOW better 2025-12-31 00:48:44 +09:00
NishiOwO
3f9125d1ae fix 2025-12-30 23:54:30 +09:00
33 changed files with 118 additions and 119 deletions

1
.gitignore vendored
View File

@@ -5,6 +5,7 @@ examples/*/*.exe
!examples/*/
!examples/*.*
!examples/*/*.*
*.exe
*.o
*.so
*.dll

View File

@@ -29,6 +29,9 @@ void handler(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
(void)user_data;
(void)call_data;
/* nishi: please rewrite this part */
/*
char* clipboard;
clipboard = MwLLGetClipboard(handle->lowlevel);
@@ -37,6 +40,7 @@ void handler(MwWidget handle, void* user_data, void* call_data) {
MwVaApply(text, MwNtext, clipboard);
MwForceRender(text);
}
*/
resize(window, NULL, NULL);
}

View File

@@ -147,6 +147,7 @@ struct _MwLLHandler {
void (*key_released)(MwLL handle, void* data);
void (*focus_in)(MwLL handle, void* data);
void (*focus_out)(MwLL handle, void* data);
void (*clipboard)(MwLL handle, void* data);
};
#ifdef __cplusplus
@@ -203,7 +204,7 @@ MWDECL void (*MwLLFocus)(MwLL handle);
MWDECL void (*MwLLGrabPointer)(MwLL handle, int toggle);
MWDECL void (*MwLLSetClipboard)(MwLL handle, const char* text);
MWDECL char* (*MwLLGetClipboard)(MwLL handle);
MWDECL void (*MwLLGetClipboard)(MwLL handle);
MWDECL void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
MWDECL void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);

View File

@@ -21,6 +21,7 @@ struct _MwLLGDI {
int grabbed;
int force_render;
int get_clipboard;
};
struct _MwLLGDIColor {

View File

@@ -29,6 +29,7 @@ struct _MwLLX11 {
GC gc;
Colormap colormap;
Atom wm_delete;
Atom wm_protocols;
XIM xim;
XIC xic;

View File

@@ -71,5 +71,6 @@
#define MwNdirectoryChosenHandler "CdirectoryChosen" /* char* */
#define MwNcolorChosenHandler "CcolorChosen" /* MwRGB* */
#define MwNdrawHandler "Cdraw" /* NULL */
#define MwNclipboardHandler "Cclipboard" /* char* */
#endif

View File

@@ -39,6 +39,7 @@ typedef void (*MwHandlerChildrenProp)(MwWidget handle, MwWidget child, const cha
typedef void (*MwHandlerKey)(MwWidget handle, int key);
typedef void (*MwHandlerMouse)(MwWidget handle, void* ptr);
typedef void (*MwHandlerExecute)(MwWidget handle, const char* name, void* out, va_list args);
typedef void (*MwHandlerClipboardReceived)(MwWidget handle, const char* data);
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
@@ -211,11 +212,11 @@ struct _MwClass {
MwHandler resize;
MwHandler children_update;
MwHandlerChildrenProp children_prop_change;
MwHandlerClipboardReceived clipboard;
void* reserved1;
void* reserved2;
void* reserved3;
void* reserved4;
void* reserved5;
};
#endif

View File

@@ -122,6 +122,7 @@
<handler name="directoryChosen" />
<handler name="colorChosen" />
<handler name="draw" />
<handler name="clipboard" />
</properties>
<enumerations>
<enumeration name="MwDIRECTION">

View File

@@ -237,6 +237,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->common.copy_buffer = 1;
r->common.type = MwLLBackendGDI;
r->gdi.get_clipboard = 1;
r->gdi.force_render = 0;
r->gdi.grabbed = 0;
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL);
@@ -383,6 +384,7 @@ static int MwLLPendingImpl(MwLL handle) {
(void)handle;
if(handle->gdi.get_clipboard) return 1;
return PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE) ? 1 : 0;
}
@@ -391,6 +393,24 @@ static void MwLLNextEventImpl(MwLL handle) {
(void)handle;
if(handle->gdi.get_clipboard) {
HGLOBAL hg;
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* txt = malloc(GlobalSize(hg));
char* clp = GlobalLock(hg);
strcpy(txt, clp);
GlobalUnlock(hg);
CloseClipboard();
MwLLDispatch(handle, clipboard, txt);
free(txt);
}
handle->gdi.get_clipboard = 0;
}
while(PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, handle->gdi.hWnd, 0, 0);
TranslateMessage(&msg);
@@ -697,21 +717,8 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
}
}
static char* MwLLGetClipboardImpl(MwLL handle) {
HGLOBAL hg;
char* r = NULL;
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* lock;
r = malloc(GlobalSize(hg));
lock = GlobalLock(hg);
strcpy(r, lock);
GlobalUnlock(hg);
CloseClipboard();
}
return r;
static void MwLLGetClipboardImpl(MwLL handle) {
handle->gdi.get_clipboard = 1; /* nishi: we do this to make clipboard api work similar to other backends */
}
static void MwLLMakeToolWindowImpl(MwLL handle) {

View File

@@ -211,6 +211,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->x11.colormap = DefaultColormap(r->x11.display, XDefaultScreen(r->x11.display));
r->x11.wm_delete = XInternAtom(r->x11.display, "WM_DELETE_WINDOW", False);
r->x11.wm_protocols = XInternAtom(r->x11.display, "WM_PROTOCOLS", False);
XSetWMProtocols(r->x11.display, r->x11.window, &r->x11.wm_delete, 1);
r->x11.gc = XCreateGC(r->x11.display, r->x11.window, 0, NULL);
@@ -471,7 +472,7 @@ static void MwLLNextEventImpl(MwLL handle) {
handle->x11.width = ev.xconfigure.width;
handle->x11.height = ev.xconfigure.height;
} else if(ev.type == ClientMessage) {
if(ev.xclient.data.l[0] == (long)handle->x11.wm_delete) {
if(ev.xclient.message_type == handle->x11.wm_protocols && ev.xclient.data.l[0] == (long)handle->x11.wm_delete) {
MwLLDispatch(handle, close, NULL);
}
} else if(ev.type == FocusIn) {
@@ -956,45 +957,10 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
(void)text;
}
static char* MwLLGetClipboardImpl(MwLL handle) {
Atom clip, target, prop;
XEvent ev;
XEvent* queue = NULL;
char* r = NULL;
static void MwLLGetClipboardImpl(MwLL handle) {
/* TODO */
clip = XInternAtom(handle->x11.display, "CLIPBOARD", 0);
target = XA_STRING;
prop = XInternAtom(handle->x11.display, "XSEL_DATA", 0);
XConvertSelection(handle->x11.display, clip, target, prop, handle->x11.window, CurrentTime);
while(1) {
XNextEvent(handle->x11.display, &ev);
if(ev.type == SelectionNotify) {
if(ev.xselection.selection == clip && ev.xselection.property != 0) {
Atom t;
unsigned long size, N;
char* data;
int format;
XGetWindowProperty(ev.xselection.display, ev.xselection.requestor, ev.xselection.property, 0, (~0L), 0, AnyPropertyType, &t, &format, &size, &N, (unsigned char**)&data);
if(t == target) {
r = MwStringDuplicate(data);
XFree(data);
}
XDeleteProperty(ev.xselection.display, ev.xselection.requestor, ev.xselection.property);
}
break;
}
}
while(arrlen(queue) > 0) {
XPutBackEvent(handle->x11.display, &queue[0]);
arrdel(queue, 0);
}
arrfree(queue);
return r;
(void)handle;
}
static void MwLLMakeToolWindowImpl(MwLL handle) {

View File

@@ -107,6 +107,13 @@ static void llfocusouthandler(MwLL handle, void* data) {
MwDispatchUserHandler(h, MwNfocusOutHandler, data);
}
static void llclipboardhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwDispatch3(h, clipboard, data);
MwDispatchUserHandler(h, MwNclipboardHandler, data);
}
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
MwWidget h = malloc(sizeof(*h));
@@ -148,6 +155,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->lowlevel->common.handler->key_released = llkeyrelhandler;
h->lowlevel->common.handler->focus_in = llfocusinhandler;
h->lowlevel->common.handler->focus_out = llfocusouthandler;
h->lowlevel->common.handler->clipboard = llclipboardhandler;
}
if(parent != NULL) arrput(parent->children, h);
@@ -387,6 +395,9 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
MwDispatch3(handle, prop_change, key);
if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key);
}
if(strcmp(key, MwNforceInverted) == 0) {
MwForceRender(handle);
}
}
void MwSetText(MwWidget handle, const char* key, const char* value) {

View File

@@ -46,7 +46,7 @@ void (*MwLLFocus)(MwLL handle);
void (*MwLLGrabPointer)(MwLL handle, int toggle);
void (*MwLLSetClipboard)(MwLL handle, const char* text);
char* (*MwLLGetClipboard)(MwLL handle);
void (*MwLLGetClipboard)(MwLL handle);
void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);

View File

@@ -114,7 +114,7 @@ MwClassRec MwBoxClassRec = {
resize, /* resize */
children_update, /* children_update */
children_prop_change, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -107,7 +107,7 @@ MwClassRec MwButtonClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -53,7 +53,7 @@ MwClassRec MwCheckBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -204,7 +204,7 @@ MwClassRec MwComboBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -109,20 +109,7 @@ static void key(MwWidget handle, int code) {
} else if(code == MwLLKeyEnter) {
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
} else if(code == (MwLLControlMask | 'v')) {
char* c = MwLLGetClipboard(handle->lowlevel);
if(c != NULL) {
char* out = malloc(strlen(str) + strlen(c) + 1);
MwUTF8Copy(str, 0, out, 0, t->cursor);
MwUTF8Copy(c, 0, out, t->cursor, MwUTF8Length(c));
MwUTF8Copy(str, t->cursor, out, t->cursor + MwUTF8Length(c), MwUTF8Length(str) - t->cursor);
t->cursor += MwUTF8Length(c);
MwSetText(handle, MwNtext, out);
free(out);
free(c);
}
MwLLGetClipboard(handle->lowlevel);
} else if(!(code & MwLLKeyMask)) {
int incr = 0;
out = malloc(strlen(str) + 5 + 1);
@@ -157,6 +144,23 @@ static void prop_change(MwWidget handle, const char* prop) {
}
}
static void clipboard(MwWidget handle, const char* data) {
MwEntry t = handle->internal;
const char* str = MwGetText(handle, MwNtext);
char* out = malloc(strlen(str) + strlen(data) + 1);
if(str == NULL) str = "";
MwUTF8Copy(str, 0, out, 0, t->cursor);
MwUTF8Copy(data, 0, out, t->cursor, MwUTF8Length(data));
MwUTF8Copy(str, t->cursor, out, t->cursor + MwUTF8Length(data), MwUTF8Length(str) - t->cursor);
t->cursor += MwUTF8Length(data);
MwSetText(handle, MwNtext, out);
free(out);
}
MwClassRec MwEntryClassRec = {
create, /* create */
destroy, /* destroy */
@@ -173,7 +177,7 @@ MwClassRec MwEntryClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
clipboard, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -61,7 +61,7 @@ MwClassRec MwFrameClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -57,7 +57,7 @@ MwClassRec MwImageClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -375,7 +375,7 @@ MwClassRec MwLabelClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -608,7 +608,7 @@ MwClassRec MwListBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -204,7 +204,7 @@ MwClassRec MwMenuClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -143,7 +143,7 @@ MwClassRec MwNumberEntryClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -244,7 +244,7 @@ MwClassRec MwOpenGLClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -61,7 +61,7 @@ MwClassRec MwProgressBarClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -62,7 +62,7 @@ MwClassRec MwRadioBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -272,7 +272,7 @@ MwClassRec MwScrollBarClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -50,7 +50,7 @@ MwClassRec MwSeparatorClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -253,7 +253,7 @@ MwClassRec MwSubMenuClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -496,7 +496,7 @@ MwClassRec MwTreeViewClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -191,7 +191,7 @@ MwClassRec MwViewportClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -524,7 +524,7 @@ MwClassRec MwVulkanClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View File

@@ -59,7 +59,7 @@ MwClassRec MwWindowClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,