wip. work on clipboard

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@581 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-03 19:05:33 +00:00
parent ee2f19eb9a
commit 1640c834b5
4 changed files with 87 additions and 10 deletions

View File

@@ -47,9 +47,14 @@ enum MwLLKeyEnum {
MwLLKeyEnter,
MwLLKeyEscape,
MwLLKeyLeftShift,
MwLLKeyRightShift
MwLLKeyRightShift,
MwLLKeyAlt,
MwLLKeyControl
};
#define MwLLControlMask MwLLKeyMask | (1 << 30)
#define MwLLAltMask MwLLKeyMask | (1 << 29)
enum MwLLMouseEnum {
MwLLMouseLeft = 1,
MwLLMouseMiddle,
@@ -129,6 +134,9 @@ MWDECL void MwLLSetBackground(MwLL handle, MwLLColor color);
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);
#ifdef __cplusplus
}
#endif

View File

@@ -126,16 +126,25 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
PostQuitMessage(0);
} else if(msg == WM_CLOSE) {
MwLLDispatch(u->ll, close, NULL);
} else if(msg == WM_CHAR) {
int n = wp;
} else if(msg == WM_CHAR || msg == WM_SYSCHAR) {
int n = wp;
const int base = 'A' - 1;
MwLLDispatch(u->ll, key, &n);
if(0x00 <= n && n <= 0x1f) {
n = (n + base) | MwLLControlMask;
if(!(HIBYTE(VkKeyScan(wp)) & 1)) n += 0x20;
}
if(HIBYTE(VkKeyScan(wp)) & 2) n |= MwLLControlMask;
if(msg == WM_SYSCHAR) n |= MwLLAltMask;
if((0x20 <= n && n <= 0x7f) || (n & MwLLKeyMask)) MwLLDispatch(u->ll, key, &n);
} else if(msg == WM_SETFOCUS) {
MwLLDispatch(u->ll, focus_in, NULL);
} else if(msg == WM_KILLFOCUS) {
MwLLDispatch(u->ll, focus_out, NULL);
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP) {
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP || msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP) {
int n = -1;
if(wp == VK_MENU && msg == WM_KEYUP) return 0;
if(wp == VK_LEFT) n = MwLLKeyLeft;
if(wp == VK_RIGHT) n = MwLLKeyRight;
if(wp == VK_UP) n = MwLLKeyUp;
@@ -145,8 +154,14 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
if(wp == VK_ESCAPE) n = MwLLKeyEscape;
if(wp == VK_LSHIFT) n = MwLLKeyLeftShift;
if(wp == VK_RSHIFT) n = MwLLKeyRightShift;
if(wp == VK_MENU) n = MwLLKeyAlt;
if(wp == VK_CONTROL) n = MwLLKeyControl;
if((msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP) && n != -1 && wp != VK_MENU) {
n |= MwLLAltMask;
}
if(n != -1) {
if(msg == WM_KEYDOWN) {
if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
MwLLDispatch(u->ll, key, &n);
} else {
MwLLDispatch(u->ll, key_released, &n);
@@ -183,6 +198,9 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else {
return DefWindowProc(hWnd, msg, wp, lp);
}
} else if(msg == WM_SETCURSOR) {
if(LOWORD(lp) != HTCLIENT) return DefWindowProc(hWnd, msg, wp, lp);
if(u->ll->cursor != NULL) SetCursor(u->ll->cursor);
} else {
return DefWindowProc(hWnd, msg, wp, lp);
}
@@ -216,6 +234,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
r->copy_buffer = 1;
r->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->hWnd, 0, wc.hInstance, NULL);
r->hInstance = wc.hInstance;
r->cursor = NULL;
u->ll = r;
u->min_set = 0;
@@ -248,6 +267,8 @@ void MwLLDestroy(MwLL handle) {
SetWindowLongPtr(handle->hWnd, GWLP_USERDATA, (LPARAM)NULL);
DestroyWindow(handle->hWnd);
if(handle->cursor != NULL) DestroyCursor(handle->cursor);
free(handle);
}
@@ -539,10 +560,8 @@ void MwLLSetCursor(MwLL handle, MwCursor* image, MwCursor* mask) {
cursor = CreateCursor(GetModuleHandle(NULL), xs, ys, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
SetClassLongPtr(handle->hWnd, GCLP_HCURSOR, (LPARAM)cursor);
SetCursor(cursor);
DestroyCursor(cursor);
if(handle->cursor != NULL) DestroyCursor(handle->cursor);
handle->cursor = cursor;
free(dimage);
free(dmask);
@@ -642,3 +661,38 @@ void MwLLGrabPointer(MwLL handle, int toggle) {
ClipCursor(NULL);
}
}
void MwLLSetClipboard(MwLL handle, const char* text) {
HGLOBAL hg;
if(OpenClipboard(handle->hWnd) != 0) {
char* lock;
EmptyClipboard();
hg = GlobalAlloc(GHND | GMEM_SHARE, strlen(text) + 1);
lock = GlobalLock(hg);
strcpy(lock, text);
GlobalUnlock(hg);
SetClipboardData(CF_TEXT, hg);
CloseClipboard();
}
}
char* MwLLGetClipboard(MwLL handle) {
HGLOBAL hg;
char* r = NULL;
if(OpenClipboard(handle->hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* lock;
r = malloc(GlobalSize(hg));
lock = GlobalLock(hg);
strcpy(r, lock);
GlobalUnlock(hg);
CloseClipboard();
}
return r;
}

View File

@@ -28,6 +28,7 @@ struct _MwLL {
HDC hDC;
void* user;
int copy_buffer;
HCURSOR cursor;
MwLLHandler handler;

View File

@@ -786,3 +786,17 @@ void MwLLGrabPointer(MwLL handle, int toggle) {
handle->grabbed = 0;
}
}
void MwLLSetClipboard(MwLL handle, const char* text) {
/* TODO */
(void)handle;
(void)text;
}
char* MwLLGetClipboard(MwLL handle) {
/* TODO */
(void)handle;
return NULL;
}