More uiWindow and bin work.
This commit is contained in:
parent
ae8bb69385
commit
71d368876a
|
@ -13,6 +13,7 @@ extern void complain(const char *, ...);
|
|||
extern uiContainer *newBin(void);
|
||||
extern void binSetMainControl(uiContainer *, uiControl *);
|
||||
extern void binSetMargins(uiContainer *, intmax_t, intmax_t, intmax_t, intmax_t);
|
||||
extern void binSetParent(uiContainer *, uintptr_t);
|
||||
|
||||
// lifetimes.c
|
||||
extern void properlyDestroyControl(uiControl *);
|
||||
|
|
|
@ -1,19 +1,6 @@
|
|||
// 6 april 2015
|
||||
#include "uipriv_windows.h"
|
||||
|
||||
struct window {
|
||||
uiWindow w;
|
||||
HWND hwnd;
|
||||
uiOSContainer *content;
|
||||
BOOL shownOnce;
|
||||
int (*onClosing)(uiWindow *, void *);
|
||||
void *onClosingData;
|
||||
int margined;
|
||||
BOOL canDestroy;
|
||||
};
|
||||
|
||||
#define uiWindowClass L"uiWindowClass"
|
||||
|
||||
static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
struct window *w;
|
||||
|
@ -75,67 +62,3 @@ ATOM registerWindowClass(HICON hDefaultIcon, HCURSOR hDefaultCursor)
|
|||
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
||||
return RegisterClassW(&wc);
|
||||
}
|
||||
|
||||
#define exstyle 0
|
||||
#define style WS_OVERLAPPEDWINDOW
|
||||
|
||||
static int defaultOnClosing(uiWindow *w, void *data)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||
{
|
||||
struct window *w;
|
||||
RECT adjust;
|
||||
WCHAR *wtitle;
|
||||
BOOL hasMenubarBOOL;
|
||||
HMENU hmenu;
|
||||
|
||||
w = uiNew(struct window);
|
||||
w->onClosing = defaultOnClosing;
|
||||
|
||||
hasMenubarBOOL = FALSE;
|
||||
if (hasMenubar)
|
||||
hasMenubarBOOL = TRUE;
|
||||
|
||||
adjust.left = 0;
|
||||
adjust.top = 0;
|
||||
adjust.right = width;
|
||||
adjust.bottom = height;
|
||||
// TODO does not handle menu wrapping; see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx
|
||||
if (AdjustWindowRectEx(&adjust, style, hasMenubarBOOL, exstyle) == 0)
|
||||
logLastError("error getting real window coordinates in uiWindow()");
|
||||
|
||||
wtitle = toUTF16(title);
|
||||
w->hwnd = CreateWindowExW(exstyle,
|
||||
uiWindowClass, wtitle,
|
||||
style,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
adjust.right - adjust.left, adjust.bottom - adjust.top,
|
||||
NULL, NULL, hInstance, w);
|
||||
if (w->hwnd == NULL)
|
||||
logLastError("error creating window in uiWindow()");
|
||||
uiFree(wtitle);
|
||||
|
||||
w->content = uiNewOSContainer((uintptr_t) (w->hwnd));
|
||||
|
||||
if (hasMenubar) {
|
||||
hmenu = makeMenubar();
|
||||
if (SetMenu(w->hwnd, hmenu) == 0)
|
||||
logLastError("error giving menu to window in uiNewWindow()");
|
||||
}
|
||||
|
||||
uiWindow(w)->Destroy = windowDestroy;
|
||||
uiWindow(w)->Handle = windowHandle;
|
||||
uiWindow(w)->Title = windowTitle;
|
||||
uiWindow(w)->SetTitle = windowSetTitle;
|
||||
uiWindow(w)->Show = windowShow;
|
||||
uiWindow(w)->Hide = windowHide;
|
||||
uiWindow(w)->OnClosing = windowOnClosing;
|
||||
uiWindow(w)->SetChild = windowSetChild;
|
||||
uiWindow(w)->Margined = windowMargined;
|
||||
uiWindow(w)->SetMargined = windowSetMargined;
|
||||
|
||||
return uiWindow(w);
|
||||
}
|
||||
|
|
|
@ -99,3 +99,12 @@ void binSetMargins(uiContainer *c, intmax_t left, intmax_t top, intmax_t right,
|
|||
b->marginBottom = bottom;
|
||||
uiContainerUpdate(uiContainer(b));
|
||||
}
|
||||
|
||||
void binSetParent(uiContainer *c, uintptr_t osParent)
|
||||
{
|
||||
struct bin *b = (struct bin *) c;
|
||||
HWND newParent = (HWND) osParent;
|
||||
|
||||
if (SetParent(b->hwnd, newParent) == 0)
|
||||
logLastError("error changing bin's parent in binSetParent()");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// 27 april 2015
|
||||
#include "uipriv_windows.h"
|
||||
|
||||
#define windowClass L"libui_uiWindowClass"
|
||||
|
||||
struct window {
|
||||
uiWindow w;
|
||||
HWND hwnd;
|
||||
|
@ -14,6 +16,11 @@ struct window {
|
|||
|
||||
// TODO window class and init functions
|
||||
|
||||
static int defaultOnClosing(uiWindow *w, void *data)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void windowDestroy(uiControl *c)
|
||||
{
|
||||
struct window *w = (struct window *) c;
|
||||
|
@ -155,3 +162,66 @@ static void windowSetMargined(uiWindow *ww, int margined)
|
|||
else
|
||||
binSetMargins(w->bin, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||
{
|
||||
struct window *w;
|
||||
RECT adjust;
|
||||
WCHAR *wtitle;
|
||||
BOOL hasMenubarBOOL;
|
||||
HMENU hmenu;
|
||||
|
||||
w = uiNew(struct window);
|
||||
|
||||
hasMenubarBOOL = FALSE;
|
||||
if (hasMenubar)
|
||||
hasMenubarBOOL = TRUE;
|
||||
|
||||
adjust.left = 0;
|
||||
adjust.top = 0;
|
||||
adjust.right = width;
|
||||
adjust.bottom = height;
|
||||
// TODO does not handle menu wrapping; see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx
|
||||
if (AdjustWindowRectEx(&adjust, style, hasMenubarBOOL, exstyle) == 0)
|
||||
logLastError("error getting real window coordinates in uiNewWindow()");
|
||||
|
||||
wtitle = toUTF16(title);
|
||||
w->hwnd = CreateWindowExW(0,
|
||||
windowClass, wtitle,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
adjust.right - adjust.left, adjust.bottom - adjust.top,
|
||||
NULL, NULL, hInstance, w);
|
||||
if (w->hwnd == NULL)
|
||||
logLastError("error creating window in uiWindow()");
|
||||
uiFree(wtitle);
|
||||
|
||||
w->bin = newBin();
|
||||
binSetParent(w->bin, (uintptr_t) (w->hwnd));
|
||||
|
||||
if (hasMenubar) {
|
||||
hmenu = makeMenubar();
|
||||
if (SetMenu(w->hwnd, hmenu) == 0)
|
||||
logLastError("error giving menu to window in uiNewWindow()");
|
||||
}
|
||||
|
||||
uiControl(w)->Destroy = windowDestroy;
|
||||
uiControl(w)->Handle = windowHandle;
|
||||
uiControl(w)->SetParent = windowSetParent;
|
||||
uiControl(w)->PreferredSize = windowPreferredSize;
|
||||
uiControl(w)->Resize = windowResize;
|
||||
uiControl(w)->Visible = windowVisible;
|
||||
uiControl(w)->Show = windowShow;
|
||||
uiControl(w)->Hide = windowHide;
|
||||
uiControl(w)->Enable = windowEnable;
|
||||
uiControl(w)->Disable = windowDisable;
|
||||
|
||||
uiWindow(w)->Title = windowTitle;
|
||||
uiWindow(w)->SetTitle = windowSetTitle;
|
||||
uiWindow(w)->OnClosing = windowOnClosing;
|
||||
uiWindow(w)->SetChild = windowSetChild;
|
||||
uiWindow(w)->Margined = windowMargined;
|
||||
uiWindow(w)->SetMargined = windowSetMargined;
|
||||
|
||||
return uiWindow(w);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue