Converted uiSizing to a dynamically allocated structure. This will be needed for handling coordinate conversion.
This commit is contained in:
parent
e06f9ae9fe
commit
a4cfd3880d
|
@ -55,7 +55,7 @@ interface Control {
|
||||||
func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t);
|
func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t);
|
||||||
func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing);
|
func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing);
|
||||||
func QueueResize(void);
|
func QueueResize(void);
|
||||||
func GetSizing(d *Sizing);
|
func Sizing(void) *Sizing;
|
||||||
func ContainerVisible(void) int;
|
func ContainerVisible(void) int;
|
||||||
func Show(void);
|
func Show(void);
|
||||||
func Hide(void);
|
func Hide(void);
|
||||||
|
@ -69,6 +69,8 @@ interface Control {
|
||||||
func StartZOrder(p *uiControlSysFuncParams) int;
|
func StartZOrder(p *uiControlSysFuncParams) int;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
func FreeSizing(d *Sizing);
|
||||||
|
|
||||||
func MakeContainer(c *Control);
|
func MakeContainer(c *Control);
|
||||||
|
|
||||||
interface Window from Control {
|
interface Window from Control {
|
||||||
|
|
|
@ -46,8 +46,8 @@ struct uiSizingSys {
|
||||||
// Use these in your preferredSize() implementation with baseX and baseY.
|
// Use these in your preferredSize() implementation with baseX and baseY.
|
||||||
#define uiWindowsDlgUnitsToX(dlg, baseX) MulDiv((dlg), baseX, 4)
|
#define uiWindowsDlgUnitsToX(dlg, baseX) MulDiv((dlg), baseX, 4)
|
||||||
#define uiWindowsDlgUnitsToY(dlg, baseY) MulDiv((dlg), baseY, 8)
|
#define uiWindowsDlgUnitsToY(dlg, baseY) MulDiv((dlg), baseY, 8)
|
||||||
// Use this as your control's GetSizing() implementation.
|
// Use this as your control's Sizing() implementation.
|
||||||
extern void uiWindowsGetSizing(uiControl *, uiSizing *);
|
extern uiSizing *uiWindowsSizing(uiControl *);
|
||||||
|
|
||||||
// and use this if you need the text of the window width
|
// and use this if you need the text of the window width
|
||||||
_UI_EXTERN intmax_t uiWindowsWindowTextWidth(HWND hwnd);
|
_UI_EXTERN intmax_t uiWindowsWindowTextWidth(HWND hwnd);
|
||||||
|
|
|
@ -67,9 +67,9 @@ static void singleQueueResize(uiControl *c)
|
||||||
queueResize(c);
|
queueResize(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void singleGetSizing(uiControl *c, uiSizing *d)
|
static uiSizing *singleSizing(uiControl *c)
|
||||||
{
|
{
|
||||||
uiWindowsGetSizing(c, d);
|
return uiWindowsSizing(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int singleContainerVisible(uiControl *c)
|
static int singleContainerVisible(uiControl *c)
|
||||||
|
@ -236,7 +236,7 @@ void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p)
|
||||||
// PreferredSize() implemented by the individual controls
|
// PreferredSize() implemented by the individual controls
|
||||||
uiControl(c)->Resize = singleResize;
|
uiControl(c)->Resize = singleResize;
|
||||||
uiControl(c)->QueueResize = singleQueueResize;
|
uiControl(c)->QueueResize = singleQueueResize;
|
||||||
uiControl(c)->GetSizing = singleGetSizing;
|
uiControl(c)->Sizing = singleSizing;
|
||||||
uiControl(c)->ContainerVisible = singleContainerVisible;
|
uiControl(c)->ContainerVisible = singleContainerVisible;
|
||||||
uiControl(c)->Show = singleShow;
|
uiControl(c)->Show = singleShow;
|
||||||
uiControl(c)->Hide = singleHide;
|
uiControl(c)->Hide = singleHide;
|
||||||
|
|
|
@ -75,38 +75,48 @@ void moveAndReorderWindow(HWND hwnd, HWND insertAfter, intmax_t x, intmax_t y, i
|
||||||
#define winXPadding 4
|
#define winXPadding 4
|
||||||
#define winYPadding 4
|
#define winYPadding 4
|
||||||
|
|
||||||
void uiWindowsGetSizing(uiControl *c, uiSizing *d)
|
uiSizing *uiWindowsSizing(uiControl *c)
|
||||||
{
|
{
|
||||||
|
uiSizing *d;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
HDC dc;
|
HDC dc;
|
||||||
HFONT prevfont;
|
HFONT prevfont;
|
||||||
TEXTMETRICW tm;
|
TEXTMETRICW tm;
|
||||||
SIZE size;
|
SIZE size;
|
||||||
|
|
||||||
|
d = uiNew(uiSizing);
|
||||||
|
d->Sys = uiNew(uiSizingSys);
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = (HWND) uiControlHandle(c);
|
||||||
|
|
||||||
dc = GetDC(hwnd);
|
dc = GetDC(hwnd);
|
||||||
if (dc == NULL)
|
if (dc == NULL)
|
||||||
logLastError("error getting DC in uiWindowsGetSizing()");
|
logLastError("error getting DC in uiWindowsSizing()");
|
||||||
prevfont = (HFONT) SelectObject(dc, hMessageFont);
|
prevfont = (HFONT) SelectObject(dc, hMessageFont);
|
||||||
if (prevfont == NULL)
|
if (prevfont == NULL)
|
||||||
logLastError("error loading control font into device context in uiWindowsGetSizing()");
|
logLastError("error loading control font into device context in uiWindowsSizing()");
|
||||||
|
|
||||||
ZeroMemory(&tm, sizeof (TEXTMETRICW));
|
ZeroMemory(&tm, sizeof (TEXTMETRICW));
|
||||||
if (GetTextMetricsW(dc, &tm) == 0)
|
if (GetTextMetricsW(dc, &tm) == 0)
|
||||||
logLastError("error getting text metrics in uiWindowsGetSizing()");
|
logLastError("error getting text metrics in uiWindowsSizing()");
|
||||||
if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0)
|
if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0)
|
||||||
logLastError("error getting text extent point in uiWindowsGetSizing()");
|
logLastError("error getting text extent point in uiWindowsSizing()");
|
||||||
|
|
||||||
d->Sys->BaseX = (int) ((size.cx / 26 + 1) / 2);
|
d->Sys->BaseX = (int) ((size.cx / 26 + 1) / 2);
|
||||||
d->Sys->BaseY = (int) tm.tmHeight;
|
d->Sys->BaseY = (int) tm.tmHeight;
|
||||||
d->Sys->InternalLeading = tm.tmInternalLeading;
|
d->Sys->InternalLeading = tm.tmInternalLeading;
|
||||||
|
|
||||||
if (SelectObject(dc, prevfont) != hMessageFont)
|
if (SelectObject(dc, prevfont) != hMessageFont)
|
||||||
logLastError("error restoring previous font into device context in uiWindowsGetSizing()");
|
logLastError("error restoring previous font into device context in uiWindowsSizing()");
|
||||||
if (ReleaseDC(hwnd, dc) == 0)
|
if (ReleaseDC(hwnd, dc) == 0)
|
||||||
logLastError("error releasing DC in uiWindowsGetSizing()");
|
logLastError("error releasing DC in uiWindowsSizing()");
|
||||||
|
|
||||||
d->XPadding = uiWindowsDlgUnitsToX(winXPadding, d->Sys->BaseX);
|
d->XPadding = uiWindowsDlgUnitsToX(winXPadding, d->Sys->BaseX);
|
||||||
d->YPadding = uiWindowsDlgUnitsToY(winYPadding, d->Sys->BaseY);
|
d->YPadding = uiWindowsDlgUnitsToY(winYPadding, d->Sys->BaseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiFreeSizing(uiSizing *d)
|
||||||
|
{
|
||||||
|
uiFree(d->Sys);
|
||||||
|
uiFree(d);
|
||||||
|
}
|
||||||
|
|
|
@ -135,9 +135,9 @@ static void windowQueueResize(uiControl *c)
|
||||||
queueResize(c);
|
queueResize(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowGetSizing(uiControl *c, uiSizing *d)
|
static uiSizing *windowSizing(uiControl *c)
|
||||||
{
|
{
|
||||||
uiWindowsGetSizing(c, d);
|
return uiWindowsSizing(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int windowContainerVisible(uiControl *c)
|
static int windowContainerVisible(uiControl *c)
|
||||||
|
@ -284,8 +284,7 @@ static void windowResizeChild(uiControl *c)
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) c;
|
struct window *w = (struct window *) c;
|
||||||
RECT r;
|
RECT r;
|
||||||
uiSizing d;
|
uiSizing *d;
|
||||||
uiSizingSys sys;
|
|
||||||
|
|
||||||
if (w->child == NULL)
|
if (w->child == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -294,9 +293,9 @@ static void windowResizeChild(uiControl *c)
|
||||||
if (w->margined) {
|
if (w->margined) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
d.Sys = &sys;
|
d = uiControlSizing(uiControl(w));
|
||||||
uiControlGetSizing(uiControl(w), &d);
|
uiControlResize(w->child, r.left, r.top, r.right - r.left, r.bottom - r.top, d);
|
||||||
uiControlResize(w->child, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
|
uiFreeSizing(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx
|
// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx
|
||||||
|
@ -370,7 +369,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
uiControl(w)->PreferredSize = windowPreferredSize;
|
uiControl(w)->PreferredSize = windowPreferredSize;
|
||||||
uiControl(w)->Resize = windowResize;
|
uiControl(w)->Resize = windowResize;
|
||||||
uiControl(w)->QueueResize = windowQueueResize;
|
uiControl(w)->QueueResize = windowQueueResize;
|
||||||
uiControl(w)->GetSizing = windowGetSizing;
|
uiControl(w)->Sizing = windowSizing;
|
||||||
uiControl(w)->ContainerVisible = windowContainerVisible;
|
uiControl(w)->ContainerVisible = windowContainerVisible;
|
||||||
uiControl(w)->Show = windowShow;
|
uiControl(w)->Show = windowShow;
|
||||||
uiControl(w)->Hide = windowHide;
|
uiControl(w)->Hide = windowHide;
|
||||||
|
|
Loading…
Reference in New Issue