aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/windows/window.cpp
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-09-23 02:58:04 +0200
committerStapleButter <thetotalworm@gmail.com>2017-09-23 02:58:04 +0200
commit14b7cf1987f01b706a902d2bafdd4e72bb88889a (patch)
treea6649108921d73c7d22ef3eb141fa35cfc513308 /src/libui_sdl/libui/windows/window.cpp
parenta9cacb9dd789b64e50dd09b18b863afb02b966ea (diff)
add hooks for when the window gets/loses focus.
properly refocus draw area. lay base for dragdrop.
Diffstat (limited to 'src/libui_sdl/libui/windows/window.cpp')
-rw-r--r--src/libui_sdl/libui/windows/window.cpp68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/libui_sdl/libui/windows/window.cpp b/src/libui_sdl/libui/windows/window.cpp
index c04410d..07496b3 100644
--- a/src/libui_sdl/libui/windows/window.cpp
+++ b/src/libui_sdl/libui/windows/window.cpp
@@ -10,16 +10,23 @@ struct uiWindow {
uiControl *child;
BOOL shownOnce;
int visible;
- int (*onClosing)(uiWindow *, void *);
- void *onClosingData;
int margined;
BOOL hasMenubar;
- void (*onContentSizeChanged)(uiWindow *, void *);
- void *onContentSizeChangedData;
BOOL changingSize;
int fullscreen;
WINDOWPLACEMENT fsPrevPlacement;
int borderless;
+
+ int (*onClosing)(uiWindow *, void *);
+ void *onClosingData;
+ void (*onContentSizeChanged)(uiWindow *, void *);
+ void *onContentSizeChangedData;
+ void (*onDropFile)(uiWindow *, char *, void *);
+ void *onDropFileData;
+ void (*onGetFocus)(uiWindow *, void *);
+ void *onGetFocusData;
+ void (*onLoseFocus)(uiWindow *, void *);
+ void *onLoseFocusData;
};
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
@@ -108,6 +115,37 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
mmi->ptMinTrackSize.x = width;
mmi->ptMinTrackSize.y = height;
return lResult;
+
+ case WM_DROPFILES:
+ if (w->onDropFile)
+ {
+ HDROP eggdrop = (HDROP)wParam;
+ WCHAR filename[1024];
+ DragQueryFile(eggdrop, 0, filename, 1024);
+
+ char* filename8 = toUTF8(filename);
+ w->onDropFile(w, filename8, w->onDropFileData);
+ uiFreeText(filename8);
+
+ DragFinish(eggdrop);
+ }
+ break;
+
+ case WM_SETFOCUS:
+ if (w->onGetFocus)
+ {
+ w->onGetFocus(w, w->onGetFocusData);
+ return 0;
+ }
+ break;
+ case WM_KILLFOCUS:
+ if (w->onLoseFocus)
+ {
+ w->onLoseFocus(w, w->onLoseFocusData);
+ return 0;
+ }
+ break;
+
case WM_PRINTCLIENT:
// we do no special painting; just erase the background
// don't worry about the return value; we let DefWindowProcW() handle this message
@@ -383,6 +421,24 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
w->onClosingData = data;
}
+void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *, char *, void *), void *data)
+{
+ w->onDropFile = f;
+ w->onDropFileData = data;
+}
+
+void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data)
+{
+ w->onGetFocus = f;
+ w->onGetFocusData = data;
+}
+
+void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data)
+{
+ w->onLoseFocus = f;
+ w->onLoseFocusData = data;
+}
+
int uiWindowBorderless(uiWindow *w)
{
return w->borderless;
@@ -492,6 +548,10 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
uiWindowOnClosing(w, defaultOnClosing, NULL);
uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL);
+ uiWindowOnDropFile(w, NULL, NULL);
+ uiWindowOnGetFocus(w, NULL, NULL);
+ uiWindowOnLoseFocus(w, NULL, NULL);
+
windows[w] = true;
return w;
}