milsko/examples/basic/clipboard.c

78 lines
2 KiB
C
Raw Normal View History

2025-12-18 17:46:23 -07:00
#include <Mw/Milsko.h>
2026-04-15 10:58:46 -07:00
MwWidget window, instructions, text1, text2, cur_text;
2025-12-18 17:46:23 -07:00
2026-04-22 12:05:49 +09:00
static void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
2026-03-17 17:43:22 -07:00
unsigned int w, h;
2025-12-18 17:46:23 -07:00
(void)user_data;
(void)call_data;
w = MwGetInteger(handle, MwNwidth);
h = MwGetInteger(handle, MwNheight);
2025-12-30 17:12:12 -07:00
MwVaApply(instructions,
2026-03-17 17:43:22 -07:00
MwNy, 50,
2025-12-18 17:46:23 -07:00
MwNwidth, w - 50 * 2,
MwNheight, h - 125 - 50 * 3,
NULL);
2026-04-15 10:58:46 -07:00
MwVaApply(text1,
MwNy, 150,
MwNwidth, w - 25 * 2,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(text2,
MwNy, 250,
MwNwidth, w - 25 * 2,
2025-12-18 17:46:23 -07:00
MwNheight, h - 125 - 50 * 3,
NULL);
}
2026-04-22 12:05:49 +09:00
static void MWAPI clipboard(MwWidget handle, void* user_data, void* call_data) {
2025-12-30 17:14:39 -07:00
char* clipboard = call_data;
2025-12-18 17:46:23 -07:00
(void)handle;
(void)user_data;
if(clipboard != NULL) {
2026-04-15 10:58:46 -07:00
MwVaApply(cur_text, MwNtext, clipboard, NULL);
MwForceRender(cur_text);
2025-12-18 17:46:23 -07:00
}
}
2026-04-22 12:05:49 +09:00
static void MWAPI tick(MwWidget handle, void* user_data, void* call_data) {
2026-04-15 10:58:46 -07:00
cur_text = text1;
2026-04-17 01:36:34 +09:00
MwGetClipboard(handle, MwCLIPBOARD_MAIN);
2026-04-15 10:58:46 -07:00
cur_text = text2;
2026-04-17 01:36:34 +09:00
MwGetClipboard(handle, MwCLIPBOARD_PRIMARY);
2026-04-15 10:58:46 -07:00
MwForceRender(window);
2026-03-27 14:40:07 +09:00
}
2025-12-18 17:46:23 -07:00
int main() {
MwLibraryInit();
2025-12-30 17:12:12 -07:00
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 400,
MwNtitle, "clipboard",
NULL);
instructions = MwVaCreateWidget(MwLabelClass, "button", window, 50, 50, 300, 125,
MwNtext, "clipboard contents will show up below.",
NULL);
2026-04-15 10:58:46 -07:00
text1 = MwVaCreateWidget(MwLabelClass, "label", window, 25, 150, 300, 75,
MwNtext, "",
NULL);
text2 = MwVaCreateWidget(MwLabelClass, "label2", window, 25, 250, 300, 75,
2025-12-30 17:12:12 -07:00
MwNtext, "",
NULL);
2025-12-18 17:46:23 -07:00
2026-04-15 10:58:46 -07:00
cur_text = text1;
2025-12-18 17:46:23 -07:00
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
2025-12-30 17:12:12 -07:00
MwAddUserHandler(window, MwNclipboardHandler, clipboard, NULL);
2026-03-23 13:38:26 -07:00
MwAddUserHandler(instructions, MwNclipboardHandler, clipboard, NULL);
2026-04-15 10:58:46 -07:00
MwAddUserHandler(cur_text, MwNclipboardHandler, clipboard, NULL);
2026-03-27 14:40:07 +09:00
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
2025-12-18 17:46:23 -07:00
resize(window, NULL, NULL);
MwLoop(window);
}