2015-04-27 17:04:41 -05:00
|
|
|
// 27 april 2015
|
2015-04-24 13:09:48 -05:00
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct window {
|
|
|
|
uiWindow w;
|
|
|
|
HWND hwnd;
|
2015-04-27 17:04:41 -05:00
|
|
|
uiContainer *bin;
|
|
|
|
int hidden;
|
2015-04-27 19:02:33 -05:00
|
|
|
BOOL shownOnce;
|
|
|
|
int (*onClosing)(uiWindow *, void *);
|
|
|
|
void *onClosingData;
|
2015-04-24 13:09:48 -05:00
|
|
|
int margined;
|
|
|
|
};
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
// TODO window class and init functions
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowDestroy(uiControl *c)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
// first hide ourselves
|
|
|
|
ShowWindow(w->hwnd, SW_HIDE);
|
|
|
|
// now destroy the bin
|
|
|
|
// the bin has no parent, so we can just call uiControlDestroy()
|
|
|
|
uiControlDestroy(uiControl(w->bin));
|
|
|
|
// TODO menus
|
|
|
|
// now destroy ourselves
|
|
|
|
if (DestroyWindow(w->hwnd) == 0)
|
|
|
|
logLastError("error destroying uiWindow in windowDestroy()");
|
|
|
|
uiFree(w);
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static uintptr_t windowHandle(uiControl *c)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
|
|
|
return (uintptr_t) (w->hwnd);
|
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowSetParent(uiControl *c)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
complain("attempt to give the uiWindow at %p a parent", c);
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
complain("attempt to get the preferred size of the uiWindow at %p", c);
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
complain("attempt to resize the uiWindow at %p", c);
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static int windowVisible(uiControl *c)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
return !w->hidden;
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowShow(uiControl *w)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 19:02:33 -05:00
|
|
|
if (w->shownOnce) {
|
|
|
|
ShowWindow(w->hwnd, SW_SHOW);
|
|
|
|
w->hidden = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
w->shownOnce = TRUE;
|
|
|
|
ShowWindow(w->hwnd, nCmdShow);
|
|
|
|
if (UpdateWindow(w->hwnd) == 0)
|
|
|
|
logLastError("error calling UpdateWindow() after showing uiWindow for the first time in windowShow()");
|
2015-04-27 17:04:41 -05:00
|
|
|
w->hidden = 0;
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowHide(uiControl *w)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
ShowWindow(w->hwnd, SW_HIDE);
|
|
|
|
w->hidden = 1;
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowEnable(uiControl *c)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
EnableWindow(w->hwnd, TRUE);
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
static void windowDisable(uiControl *c)
|
2015-04-24 13:09:48 -05:00
|
|
|
{
|
2015-04-27 17:04:41 -05:00
|
|
|
struct window *w = (struct window *) c;
|
2015-04-24 13:09:48 -05:00
|
|
|
|
2015-04-27 17:04:41 -05:00
|
|
|
EnableWindow(w->hwnd, FALSE);
|
2015-04-24 13:09:48 -05:00
|
|
|
}
|
2015-04-27 19:02:33 -05:00
|
|
|
|
|
|
|
static char *windowTitle(uiWindow *ww)
|
|
|
|
{
|
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
WCHAR *wtext;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
wtext = windowText(w->hwnd);
|
|
|
|
text = toUTF8(wtext);
|
|
|
|
uiFree(wtext);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void windowSetTitle(uiWindow *ww, const char *title)
|
|
|
|
{
|
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
WCHAR *wtext;
|
|
|
|
|
|
|
|
wtext = toUTF16(text);
|
|
|
|
if (SetWindowTextW(w->hwnd, wtext) == 0)
|
|
|
|
logLastError("error setting window title in uiWindowSetTitle()");
|
|
|
|
uiFree(wtext);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
|
|
|
w->onClosing = f;
|
|
|
|
w->onClosingData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void windowSetChild(uiWindow *ww, uiControl *child)
|
|
|
|
{
|
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
|
|
|
binSetMainControl(w->bin, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int windowMargined(uiWindow *ww)
|
|
|
|
{
|
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
|
|
|
return w->margined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
#define windowMargin 7
|
|
|
|
|
|
|
|
static void windowSetMargined(uiWindow *ww, int margined)
|
|
|
|
{
|
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
|
|
|
w->margined = margined;
|
|
|
|
if (w->margined)
|
|
|
|
binSetMargins(w->bin, windowMargin, windowMargin, windowMargin, windowMargin);
|
|
|
|
else
|
|
|
|
binSetMargins(w->bin, 0, 0, 0, 0);
|
|
|
|
}
|