Migrated windows/newcontrol.c.

This commit is contained in:
Pietro Gagliardi 2015-04-29 01:37:49 -04:00
parent 90bb60a435
commit c7bbd1d374
1 changed files with 27 additions and 84 deletions

View File

@ -9,19 +9,17 @@ struct singleHWND {
BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *); BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *);
void (*onDestroy)(void *); void (*onDestroy)(void *);
void *onDestroyData; void *onDestroyData;
uiParent *parent; uiContainer *parent;
BOOL userHid; int hidden;
BOOL containerHid;
BOOL userDisabled;
BOOL containerDisabled;
}; };
// TODO destruction blocking
static void singleDestroy(uiControl *c) static void singleDestroy(uiControl *c)
{ {
singleHWND *s = (singleHWND *) (c->Internal); singleHWND *s = (singleHWND *) (c->Internal);
if (s->parent != NULL) 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); SendMessageW(s->hwnd, msgCanDestroyNow, 0, 0);
(*(s->onDestroy))(s->onDestroyData); (*(s->onDestroy))(s->onDestroyData);
if (DestroyWindow(s->hwnd) == 0) if (DestroyWindow(s->hwnd) == 0)
@ -36,23 +34,23 @@ static uintptr_t singleHandle(uiControl *c)
return (uintptr_t) (s->hwnd); return (uintptr_t) (s->hwnd);
} }
static void singleSetParent(uiControl *c, uiParent *parent) static void singleSetParent(uiControl *c, uiContainer *parent)
{ {
singleHWND *s = (singleHWND *) (c->Internal); singleHWND *s = (singleHWND *) (c->Internal);
uiParent *oldparent; uiContainer *oldparent;
HWND newParentHWND; HWND newParentHWND;
oldparent = s->parent; oldparent = s->parent;
s->parent = parent; s->parent = parent;
newParentHWND = initialParent; newParentHWND = initialParent;
if (s->parent != NULL) if (s->parent != NULL)
newParentHWND = uiParentHWND(s->parent); newParentHWND = (HWND) uiControlHandle(uiControl(s->parent));
if (SetParent(s->hwnd, newParentHWND) == NULL) if (SetParent(s->hwnd, newParentHWND) == NULL)
logLastError("error setting control parent in singleSetParent()"); logLastError("error setting control parent in singleSetParent()");
if (oldparent != NULL) if (oldparent != NULL)
uiParentUpdate(oldparent); uiContainerUpdate(oldparent);
if (s->parent != NULL) 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) 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); singleHWND *s = (singleHWND *) (c->Internal);
if (s->userHid) return !s->hidden;
return 0;
return 1;
} }
static void singleShow(uiControl *c) static void singleShow(uiControl *c)
{ {
singleHWND *s = (singleHWND *) (c->Internal); singleHWND *s = (singleHWND *) (c->Internal);
s->userHid = FALSE; ShowWindow(s->hwnd, SW_SHOW);
if (!s->containerHid) { if (s->parent != NULL)
ShowWindow(s->hwnd, SW_SHOW); uiContainerUpdate(s->parent);
if (s->parent != NULL) s->hidden = 0;
uiParentUpdate(s->parent);
}
} }
static void singleHide(uiControl *c) static void singleHide(uiControl *c)
{ {
singleHWND *s = (singleHWND *) (c->Internal); singleHWND *s = (singleHWND *) (c->Internal);
s->userHid = TRUE;
ShowWindow(s->hwnd, SW_HIDE); ShowWindow(s->hwnd, SW_HIDE);
if (s->parent != NULL) if (s->parent != NULL)
uiParentUpdate(s->parent); uiContainerUpdate(s->parent);
} s->hidden = 1;
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);
} }
static void singleEnable(uiControl *c) static void singleEnable(uiControl *c)
{ {
singleHWND *s = (singleHWND *) (c->Internal); singleHWND *s = (singleHWND *) (c->Internal);
s->userDisabled = FALSE; EnableWindow(s->hwnd, TRUE);
if (!s->containerDisabled)
EnableWindow(s->hwnd, TRUE);
} }
static void singleDisable(uiControl *c) static void singleDisable(uiControl *c)
{ {
singleHWND *s = (singleHWND *) (c->Internal); 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); 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) if ((*(s->onWM_NOTIFY))(c, (NMHDR *) lParam, &lResult) != FALSE)
return lResult; return lResult;
break; break;
case WM_DESTROY: case WM_NCDESTROY:
case WM_NCDESTROY: // just in case
complain("trying to destroy control at %p before uiControlDestroy()", c);
break;
case msgCanDestroyNow:
if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE) if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE)
logLastError("error removing Windows control subclass in singleSubclassProc()"); logLastError("error removing Windows control subclass in singleSubclassProc()");
break; break;
@ -197,20 +145,6 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
s->onDestroy = p->onDestroy; s->onDestroy = p->onDestroy;
s->onDestroyData = p->onDestroyData; 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) if (p->useStandardControlFont)
SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); 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()"); logLastError("error subclassing Windows control in uiWindowsNewControl()");
c->Internal = s; 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) char *uiWindowsControlText(uiControl *c)