Migrated windows/newcontrol.c.
This commit is contained in:
parent
90bb60a435
commit
c7bbd1d374
|
@ -9,19 +9,17 @@ struct singleHWND {
|
|||
BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *);
|
||||
void (*onDestroy)(void *);
|
||||
void *onDestroyData;
|
||||
uiParent *parent;
|
||||
BOOL userHid;
|
||||
BOOL containerHid;
|
||||
BOOL userDisabled;
|
||||
BOOL containerDisabled;
|
||||
uiContainer *parent;
|
||||
int hidden;
|
||||
};
|
||||
|
||||
// TODO destruction blocking
|
||||
static void singleDestroy(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
if (s->parent != NULL)
|
||||
complain("attempt to destroy a uiControl at %p while it still has a parent %p", c, s->parent);
|
||||
complain("attempt to destroy a uiControl at %p while it still has a parent", c);
|
||||
SendMessageW(s->hwnd, msgCanDestroyNow, 0, 0);
|
||||
(*(s->onDestroy))(s->onDestroyData);
|
||||
if (DestroyWindow(s->hwnd) == 0)
|
||||
|
@ -36,23 +34,23 @@ static uintptr_t singleHandle(uiControl *c)
|
|||
return (uintptr_t) (s->hwnd);
|
||||
}
|
||||
|
||||
static void singleSetParent(uiControl *c, uiParent *parent)
|
||||
static void singleSetParent(uiControl *c, uiContainer *parent)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
uiParent *oldparent;
|
||||
uiContainer *oldparent;
|
||||
HWND newParentHWND;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = parent;
|
||||
newParentHWND = initialParent;
|
||||
if (s->parent != NULL)
|
||||
newParentHWND = uiParentHWND(s->parent);
|
||||
newParentHWND = (HWND) uiControlHandle(uiControl(s->parent));
|
||||
if (SetParent(s->hwnd, newParentHWND) == NULL)
|
||||
logLastError("error setting control parent in singleSetParent()");
|
||||
if (oldparent != NULL)
|
||||
uiParentUpdate(oldparent);
|
||||
uiContainerUpdate(oldparent);
|
||||
if (s->parent != NULL)
|
||||
uiParentUpdate(s->parent);
|
||||
uiContainerUpdate(s->parent);
|
||||
}
|
||||
|
||||
static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
||||
|
@ -67,86 +65,40 @@ static int singleVisible(uiControl *c)
|
|||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
if (s->userHid)
|
||||
return 0;
|
||||
return 1;
|
||||
return !s->hidden;
|
||||
}
|
||||
|
||||
static void singleShow(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->userHid = FALSE;
|
||||
if (!s->containerHid) {
|
||||
ShowWindow(s->hwnd, SW_SHOW);
|
||||
if (s->parent != NULL)
|
||||
uiParentUpdate(s->parent);
|
||||
}
|
||||
ShowWindow(s->hwnd, SW_SHOW);
|
||||
if (s->parent != NULL)
|
||||
uiContainerUpdate(s->parent);
|
||||
s->hidden = 0;
|
||||
}
|
||||
|
||||
static void singleHide(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->userHid = TRUE;
|
||||
ShowWindow(s->hwnd, SW_HIDE);
|
||||
if (s->parent != NULL)
|
||||
uiParentUpdate(s->parent);
|
||||
}
|
||||
|
||||
static void singleContainerShow(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->containerHid = FALSE;
|
||||
if (!s->userHid) {
|
||||
ShowWindow(s->hwnd, SW_SHOW);
|
||||
if (s->parent != NULL)
|
||||
uiParentUpdate(s->parent);
|
||||
}
|
||||
}
|
||||
|
||||
static void singleContainerHide(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->containerHid = TRUE;
|
||||
ShowWindow(s->hwnd, SW_HIDE);
|
||||
if (s->parent != NULL)
|
||||
uiParentUpdate(s->parent);
|
||||
uiContainerUpdate(s->parent);
|
||||
s->hidden = 1;
|
||||
}
|
||||
|
||||
static void singleEnable(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->userDisabled = FALSE;
|
||||
if (!s->containerDisabled)
|
||||
EnableWindow(s->hwnd, TRUE);
|
||||
EnableWindow(s->hwnd, TRUE);
|
||||
}
|
||||
|
||||
static void singleDisable(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->userDisabled = TRUE;
|
||||
EnableWindow(s->hwnd, FALSE);
|
||||
}
|
||||
|
||||
static void singleContainerEnable(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->containerDisabled = FALSE;
|
||||
if (!s->userDisabled)
|
||||
EnableWindow(s->hwnd, TRUE);
|
||||
}
|
||||
|
||||
static void singleContainerDisable(uiControl *c)
|
||||
{
|
||||
singleHWND *s = (singleHWND *) (c->Internal);
|
||||
|
||||
s->containerDisabled = TRUE;
|
||||
EnableWindow(s->hwnd, FALSE);
|
||||
}
|
||||
|
||||
|
@ -165,11 +117,7 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||
if ((*(s->onWM_NOTIFY))(c, (NMHDR *) lParam, &lResult) != FALSE)
|
||||
return lResult;
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
case WM_NCDESTROY: // just in case
|
||||
complain("trying to destroy control at %p before uiControlDestroy()", c);
|
||||
break;
|
||||
case msgCanDestroyNow:
|
||||
case WM_NCDESTROY:
|
||||
if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE)
|
||||
logLastError("error removing Windows control subclass in singleSubclassProc()");
|
||||
break;
|
||||
|
@ -197,20 +145,6 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
|
|||
s->onDestroy = p->onDestroy;
|
||||
s->onDestroyData = p->onDestroyData;
|
||||
|
||||
c->Destroy = singleDestroy;
|
||||
c->Handle = singleHandle;
|
||||
c->SetParent = singleSetParent;
|
||||
c->Resize = singleResize;
|
||||
c->Visible = singleVisible;
|
||||
c->Show = singleShow;
|
||||
c->Hide = singleHide;
|
||||
c->ContainerShow = singleContainerShow;
|
||||
c->ContainerHide = singleContainerHide;
|
||||
c->Enable = singleEnable;
|
||||
c->Disable = singleDisable;
|
||||
c->ContainerEnable = singleContainerEnable;
|
||||
c->ContainerDisable = singleContainerDisable;
|
||||
|
||||
if (p->useStandardControlFont)
|
||||
SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
||||
|
||||
|
@ -219,6 +153,15 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
|
|||
logLastError("error subclassing Windows control in uiWindowsNewControl()");
|
||||
|
||||
c->Internal = s;
|
||||
c->Destroy = singleDestroy;
|
||||
c->Handle = singleHandle;
|
||||
c->SetParent = singleSetParent;
|
||||
c->Resize = singleResize;
|
||||
c->Visible = singleVisible;
|
||||
c->Show = singleShow;
|
||||
c->Hide = singleHide;
|
||||
c->Enable = singleEnable;
|
||||
c->Disable = singleDisable;
|
||||
}
|
||||
|
||||
char *uiWindowsControlText(uiControl *c)
|
||||
|
|
Loading…
Reference in New Issue