Converted uiSizing to a dynamically allocated structure. This will be needed for handling coordinate conversion.

This commit is contained in:
Pietro Gagliardi 2015-05-18 11:46:50 -04:00
parent e06f9ae9fe
commit a4cfd3880d
5 changed files with 32 additions and 21 deletions

View File

@ -55,7 +55,7 @@ interface Control {
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 QueueResize(void);
func GetSizing(d *Sizing);
func Sizing(void) *Sizing;
func ContainerVisible(void) int;
func Show(void);
func Hide(void);
@ -69,6 +69,8 @@ interface Control {
func StartZOrder(p *uiControlSysFuncParams) int;
};
func FreeSizing(d *Sizing);
func MakeContainer(c *Control);
interface Window from Control {

View File

@ -46,8 +46,8 @@ struct uiSizingSys {
// Use these in your preferredSize() implementation with baseX and baseY.
#define uiWindowsDlgUnitsToX(dlg, baseX) MulDiv((dlg), baseX, 4)
#define uiWindowsDlgUnitsToY(dlg, baseY) MulDiv((dlg), baseY, 8)
// Use this as your control's GetSizing() implementation.
extern void uiWindowsGetSizing(uiControl *, uiSizing *);
// Use this as your control's Sizing() implementation.
extern uiSizing *uiWindowsSizing(uiControl *);
// and use this if you need the text of the window width
_UI_EXTERN intmax_t uiWindowsWindowTextWidth(HWND hwnd);

View File

@ -67,9 +67,9 @@ static void singleQueueResize(uiControl *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)
@ -236,7 +236,7 @@ void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p)
// PreferredSize() implemented by the individual controls
uiControl(c)->Resize = singleResize;
uiControl(c)->QueueResize = singleQueueResize;
uiControl(c)->GetSizing = singleGetSizing;
uiControl(c)->Sizing = singleSizing;
uiControl(c)->ContainerVisible = singleContainerVisible;
uiControl(c)->Show = singleShow;
uiControl(c)->Hide = singleHide;

View File

@ -75,38 +75,48 @@ void moveAndReorderWindow(HWND hwnd, HWND insertAfter, intmax_t x, intmax_t y, i
#define winXPadding 4
#define winYPadding 4
void uiWindowsGetSizing(uiControl *c, uiSizing *d)
uiSizing *uiWindowsSizing(uiControl *c)
{
uiSizing *d;
HWND hwnd;
HDC dc;
HFONT prevfont;
TEXTMETRICW tm;
SIZE size;
d = uiNew(uiSizing);
d->Sys = uiNew(uiSizingSys);
hwnd = (HWND) uiControlHandle(c);
dc = GetDC(hwnd);
if (dc == NULL)
logLastError("error getting DC in uiWindowsGetSizing()");
logLastError("error getting DC in uiWindowsSizing()");
prevfont = (HFONT) SelectObject(dc, hMessageFont);
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));
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)
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->BaseY = (int) tm.tmHeight;
d->Sys->InternalLeading = tm.tmInternalLeading;
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)
logLastError("error releasing DC in uiWindowsGetSizing()");
logLastError("error releasing DC in uiWindowsSizing()");
d->XPadding = uiWindowsDlgUnitsToX(winXPadding, d->Sys->BaseX);
d->YPadding = uiWindowsDlgUnitsToY(winYPadding, d->Sys->BaseY);
}
void uiFreeSizing(uiSizing *d)
{
uiFree(d->Sys);
uiFree(d);
}

View File

@ -135,9 +135,9 @@ static void windowQueueResize(uiControl *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)
@ -284,8 +284,7 @@ static void windowResizeChild(uiControl *c)
{
struct window *w = (struct window *) c;
RECT r;
uiSizing d;
uiSizingSys sys;
uiSizing *d;
if (w->child == NULL)
return;
@ -294,9 +293,9 @@ static void windowResizeChild(uiControl *c)
if (w->margined) {
// TODO
}
d.Sys = &sys;
uiControlGetSizing(uiControl(w), &d);
uiControlResize(w->child, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
d = uiControlSizing(uiControl(w));
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
@ -370,7 +369,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
uiControl(w)->PreferredSize = windowPreferredSize;
uiControl(w)->Resize = windowResize;
uiControl(w)->QueueResize = windowQueueResize;
uiControl(w)->GetSizing = windowGetSizing;
uiControl(w)->Sizing = windowSizing;
uiControl(w)->ContainerVisible = windowContainerVisible;
uiControl(w)->Show = windowShow;
uiControl(w)->Hide = windowHide;