Migrated group.cpp.
This commit is contained in:
parent
d68e11eac1
commit
26b22b2da3
|
@ -4,26 +4,13 @@
|
||||||
struct uiGroup {
|
struct uiGroup {
|
||||||
uiWindowsControl c;
|
uiWindowsControl c;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
struct child *child;
|
struct uiControl *child;
|
||||||
int margined;
|
int margined;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onDestroy(uiGroup *);
|
|
||||||
|
|
||||||
uiWindowsDefineControlWithOnDestroy(
|
|
||||||
uiGroup, // type name
|
|
||||||
onDestroy(me); // on destroy
|
|
||||||
)
|
|
||||||
|
|
||||||
static void onDestroy(uiGroup *g)
|
|
||||||
{
|
|
||||||
if (g->child != NULL)
|
|
||||||
childDestroy(g->child);
|
|
||||||
}
|
|
||||||
|
|
||||||
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
#define groupXMargin 6
|
#define groupXMargin 6
|
||||||
#define groupYMarginTop 11 /* note this value /includes the groupbox label */
|
#define groupYMarginTop 11 /* note this value /includes/ the groupbox label */
|
||||||
#define groupYMarginBottom 7
|
#define groupYMarginBottom 7
|
||||||
|
|
||||||
// unfortunately because the client area of a groupbox includes the frame and caption text, we have to apply some margins ourselves, even if we don't want "any"
|
// unfortunately because the client area of a groupbox includes the frame and caption text, we have to apply some margins ourselves, even if we don't want "any"
|
||||||
|
@ -33,24 +20,26 @@ static void onDestroy(uiGroup *g)
|
||||||
#define groupUnmarginedYMarginTop 8
|
#define groupUnmarginedYMarginTop 8
|
||||||
#define groupUnmarginedYMarginBottom 3
|
#define groupUnmarginedYMarginBottom 3
|
||||||
|
|
||||||
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
static void groupMargins(uiGroup *g, int *mx, int *mtop, int *mbottom)
|
||||||
{
|
{
|
||||||
uiGroup *g = uiGroup(c);
|
uiWindowsSizing sizing;
|
||||||
|
int dummy;
|
||||||
|
|
||||||
*width = 0;
|
*mx = groupUnmarginedXMargin;
|
||||||
*height = 0;
|
*mtop = groupUnmarginedYMarginTop;
|
||||||
if (g->child != NULL)
|
*mbottom = groupUnmarginedYMarginBottom;
|
||||||
childMinimumSize(g->child, d, width, height);
|
dummy = 1; // for the bottom conversion
|
||||||
if (g->margined) {
|
if (g->margined) {
|
||||||
*width += 2 * uiWindowsDlgUnitsToX(groupXMargin, d->BaseX);
|
*mx = groupXMargin;
|
||||||
*height += uiWindowsDlgUnitsToY(groupYMarginTop, d->BaseY) + uiWindowsDlgUnitsToY(groupYMarginBottom, d->BaseY);
|
*mtop = groupYMarginTop;
|
||||||
} else {
|
*mbottom = groupYMarginBottom;
|
||||||
*width += 2 * uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->BaseX);
|
|
||||||
*height += uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->BaseY) + uiWindowsDlgUnitsToY(groupUnmarginedYMarginBottom, d->BaseY);
|
|
||||||
}
|
}
|
||||||
|
uiWindowsControlGetSizing(uiWindowsControl(g), &sizing);
|
||||||
|
uiWindowsSizingDlgUnitsToPixels(&sizing, mx, mtop);
|
||||||
|
uiWindowsSizingDlgUnitsToPixels(&sizing, &dummy, mbottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void groupRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height)
|
static void groupRelayout(uiGroup *g)
|
||||||
{
|
{
|
||||||
uiGroup *g = uiGroup(c);
|
uiGroup *g = uiGroup(c);
|
||||||
uiWindowsSizing *d;
|
uiWindowsSizing *d;
|
||||||
|
@ -78,14 +67,71 @@ static void groupRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t
|
||||||
childRelayout(g->child, x, y, width, height);
|
childRelayout(g->child, x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void groupContainerUpdateState(uiControl *c)
|
static void uiGroupDestroy(uiControl *c)
|
||||||
{
|
{
|
||||||
uiGroup *g = uiGroup(c);
|
uiGroup *g = uiGroup(c);
|
||||||
|
|
||||||
if (g->child != NULL)
|
if (g->child != NULL) {
|
||||||
childUpdateState(g->child);
|
uiControlSetParent(g->child, NULL);
|
||||||
|
uiControlDestroy(g->child);
|
||||||
|
}
|
||||||
|
uiWindowsEnsureDestroyWindow(g->hwnd);
|
||||||
|
uiFreeControl(uiControl(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uiWindowsControlDefaultHandle(uiGroup)
|
||||||
|
uiWindowsControlDefaultParent(uiGroup)
|
||||||
|
uiWindowsControlDefaultSetParent(uiGroup)
|
||||||
|
uiWindowsControlDefaultToplevel(uiGroup)
|
||||||
|
uiWindowsControlDefaultVisible(uiGroup)
|
||||||
|
uiWindowsControlDefaultShow(uiGroup)
|
||||||
|
uiWindowsControlDefaultHide(uiGroup)
|
||||||
|
uiWindowsControlDefaultEnabled(uiGroup)
|
||||||
|
uiWindowsControlDefaultEnable(uiGroup)
|
||||||
|
uiWindowsControlDefaultDisable(uiGroup)
|
||||||
|
|
||||||
|
static void uiGroupSyncEnableState(uiWindowsControl *c, int enabled)
|
||||||
|
{
|
||||||
|
uiGroup *g = uiGroup(c);
|
||||||
|
|
||||||
|
if (uiWindowsShouldStopSyncEnableState(uiWindowsControl(g), enabled))
|
||||||
|
return;
|
||||||
|
EnableWindow(g->hwnd, enabled);
|
||||||
|
if (g->child != NULL)
|
||||||
|
uiWindowsControlSyncEnableState(uiWindowsControl(g->child), enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
uiWindowsControlDefaultSetParentHWND(uiGroup)
|
||||||
|
|
||||||
|
static void uiGroupMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height)
|
||||||
|
{
|
||||||
|
uiGroup *g = uiGroup(c);
|
||||||
|
int mx, mtop, mbottom;
|
||||||
|
|
||||||
|
*width = 0;
|
||||||
|
*height = 0;
|
||||||
|
if (g->child != NULL)
|
||||||
|
uiWindowsControlMinimumSize(uiWindowsControl(g->child), width, height);
|
||||||
|
groupMargins(g, &mx, &mtop, &mbottom);
|
||||||
|
*width += 2 * mx;
|
||||||
|
*height += mtop + mbottom;
|
||||||
|
// TODO label width? and when?
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uiGroupMinimumSizeChanged(uiWindowsControl *c)
|
||||||
|
{
|
||||||
|
uiGroup *g = uiGroup(c);
|
||||||
|
|
||||||
|
if (uiWindowsControlTooSmall(uiWindowsControl(g))) {
|
||||||
|
uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(g));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
groupRelayout(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
uiWindowsControlDefaultLayoutRect(uiGroup)
|
||||||
|
uiWindowsControlDefaultAssignControlIDZorder(uiGroup)
|
||||||
|
|
||||||
static void groupArrangeChildrenControlIDsZOrder(uiWindowsControl *c)
|
static void groupArrangeChildrenControlIDsZOrder(uiWindowsControl *c)
|
||||||
{
|
{
|
||||||
uiGroup *g = uiGroup(c);
|
uiGroup *g = uiGroup(c);
|
||||||
|
@ -108,12 +154,16 @@ void uiGroupSetTitle(uiGroup *g, const char *text)
|
||||||
|
|
||||||
void uiGroupSetChild(uiGroup *g, uiControl *child)
|
void uiGroupSetChild(uiGroup *g, uiControl *child)
|
||||||
{
|
{
|
||||||
if (g->child != NULL)
|
|
||||||
childRemove(g->child);
|
|
||||||
g->child = newChild(child, uiControl(g), g->hwnd);
|
|
||||||
if (g->child != NULL) {
|
if (g->child != NULL) {
|
||||||
childSetSoleControlID(g->child);
|
uiControlSetParent(g->child, NULL);
|
||||||
uiWindowsControlQueueRelayout(uiWindowsControl(g));
|
uiWindowsControlSetParentHWND(uiWindowsControl(g->child), NULL);
|
||||||
|
}
|
||||||
|
g->child = child;
|
||||||
|
if (g->child != NULL) {
|
||||||
|
uiControlSetParent(g->child, uiControl(g));
|
||||||
|
uiWindowsControlSetParentHWND(uiWindowsControl(g->child), g->hwnd);
|
||||||
|
uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl(g->child));
|
||||||
|
uiWindowsControlChildMinimumSizeChanged(uiWindowsControl(g));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,16 +175,24 @@ int uiGroupMargined(uiGroup *g)
|
||||||
void uiGroupSetMargined(uiGroup *g, int margined)
|
void uiGroupSetMargined(uiGroup *g, int margined)
|
||||||
{
|
{
|
||||||
g->margined = margined;
|
g->margined = margined;
|
||||||
uiWindowsControlQueueRelayout(uiWindowsControl(g));
|
uiWindowsControlChildMinimumSizeChanged(uiWindowsControl(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK groupSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
static LRESULT CALLBACK groupSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||||
{
|
{
|
||||||
|
uiGroup *g = uiGroup(dwRefData);
|
||||||
LRESULT lResult;
|
LRESULT lResult;
|
||||||
|
|
||||||
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
||||||
return lResult;
|
return lResult;
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
|
case WM_WINDOWPOSCHANGED:
|
||||||
|
// TODO check
|
||||||
|
// TODO add check in container.c
|
||||||
|
groupRelayout(g);
|
||||||
|
// TODO is this right?
|
||||||
|
break;
|
||||||
|
// TODO WM_GETMINMAXINFO
|
||||||
case WM_NCDESTROY:
|
case WM_NCDESTROY:
|
||||||
if (RemoveWindowSubclass(hwnd, groupSubProc, uIdSubclass) == FALSE)
|
if (RemoveWindowSubclass(hwnd, groupSubProc, uIdSubclass) == FALSE)
|
||||||
logLastError(L"error removing groupbox subclass");
|
logLastError(L"error removing groupbox subclass");
|
||||||
|
@ -148,7 +206,7 @@ uiGroup *uiNewGroup(const char *text)
|
||||||
uiGroup *g;
|
uiGroup *g;
|
||||||
WCHAR *wtext;
|
WCHAR *wtext;
|
||||||
|
|
||||||
g = (uiGroup *) uiNewControl(uiGroup);
|
uiWindowsNewControl(uiGroup, g);
|
||||||
|
|
||||||
wtext = toUTF16(text);
|
wtext = toUTF16(text);
|
||||||
g->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT,
|
g->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT,
|
||||||
|
@ -161,10 +219,5 @@ uiGroup *uiNewGroup(const char *text)
|
||||||
if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE)
|
if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE)
|
||||||
logLastError(L"error subclassing groupbox to handle parent messages");
|
logLastError(L"error subclassing groupbox to handle parent messages");
|
||||||
|
|
||||||
uiWindowsFinishNewControl(g, uiGroup);
|
|
||||||
uiControl(g)->ContainerUpdateState = groupContainerUpdateState;
|
|
||||||
uiWindowsControl(g)->Relayout = groupRelayout;
|
|
||||||
uiWindowsControl(g)->ArrangeChildrenControlIDsZOrder = groupArrangeChildrenControlIDsZOrder;
|
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ static void uiTabMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *hei
|
||||||
*height = r.bottom - r.top;
|
*height = r.bottom - r.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uiTabChildMinimumSizeChanged(uiWindowsControl *c)
|
static void uiTabMinimumSizeChanged(uiWindowsControl *c)
|
||||||
{
|
{
|
||||||
uiTab *t = uiTab(c);
|
uiTab *t = uiTab(c);
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
|
||||||
page = newTabPage(child);
|
page = newTabPage(child);
|
||||||
uiWindowsEnsureSetParent(page->hwnd, t->hwnd);
|
uiWindowsEnsureSetParent(page->hwnd, t->hwnd);
|
||||||
t->pages->insert(t->pages->begin() + n, page);
|
t->pages->insert(t->pages->begin() + n, page);
|
||||||
// TODO adjust page to set the sole control ID
|
// TODO adjust tabpage.cpp to set the sole control ID
|
||||||
tabArrangePages(t);
|
tabArrangePages(t);
|
||||||
|
|
||||||
ZeroMemory(&item, sizeof (TCITEMW));
|
ZeroMemory(&item, sizeof (TCITEMW));
|
||||||
|
|
Loading…
Reference in New Issue