Started doing a migration of the many many many controls over to the new object system.

This commit is contained in:
Pietro Gagliardi 2015-05-29 18:03:24 -04:00
parent ecd14aaa12
commit 6dba84b99b
12 changed files with 123 additions and 216 deletions

View File

@ -6,8 +6,11 @@ struct checkbox {
HWND hwnd; HWND hwnd;
void (*onToggled)(uiCheckbox *, void *); void (*onToggled)(uiCheckbox *, void *);
void *onToggledData; void *onToggledData;
void (*baseCommitDestroy)(uiControl *);
}; };
uiDefineControlType(uiCheckbox, uiTypeCheckbox, struct checkbox)
static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult) static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult)
{ {
struct checkbox *c = (struct checkbox *) cc; struct checkbox *c = (struct checkbox *) cc;
@ -27,12 +30,12 @@ static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult)
return TRUE; return TRUE;
} }
static void onDestroy(void *data) static void checkboxCommitDestroy(uiControl *cc)
{ {
struct checkbox *c = (struct checkbox *) data; struct checkbox *c = (struct checkbox *) cc;
uiWindowsUnregisterWM_COMMANDHandler(c->hwnd); uiWindowsUnregisterWM_COMMANDHandler(c->hwnd);
uiFree(c); (*(c->baseCommitDestroy))(uiControl(c));
} }
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
@ -95,28 +98,23 @@ uiCheckbox *uiNewCheckbox(const char *text)
uiWindowsMakeControlParams p; uiWindowsMakeControlParams p;
WCHAR *wtext; WCHAR *wtext;
c = uiNew(struct checkbox); c = (struct checkbox *) uiWindowsNewSingleHWNDControl(uiTypeCheckbox());
uiTyped(c)->Type = uiTypeCheckbox();
p.dwExStyle = 0;
p.lpClassName = L"button";
wtext = toUTF16(text); wtext = toUTF16(text);
p.lpWindowName = wtext; c->hwnd = uiWindowsUtilCreateControlHWND(0,
p.dwStyle = BS_CHECKBOX | WS_TABSTOP; L"button", wtext,
p.hInstance = hInstance; BS_CHECKBOX | WS_TABSTOP,
p.lpParam = NULL; hInstance, NULL,
p.useStandardControlFont = TRUE; TRUE);
p.onDestroy = onDestroy;
p.onDestroyData = c;
uiWindowsMakeControl(uiControl(c), &p);
uiFree(wtext); uiFree(wtext);
c->hwnd = (HWND) uiControlHandle(uiControl(c));
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c)); uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
c->onToggled = defaultOnToggled; c->onToggled = defaultOnToggled;
uiControl(c)->PreferredSize = checkboxPreferredSize; uiControl(c)->PreferredSize = checkboxPreferredSize;
c->baseCommitDestroy = uiControl(c)->CommitDestroy;
uiControl(c)->CommitDestroy = checkboxCommitDestroy;
uiCheckbox(c)->Text = checkboxText; uiCheckbox(c)->Text = checkboxText;
uiCheckbox(c)->SetText = checkboxSetText; uiCheckbox(c)->SetText = checkboxSetText;

View File

@ -8,12 +8,7 @@ struct combobox {
HWND hwnd; HWND hwnd;
}; };
static void onDestroy(void *data) uiDefineControlType(uiCombobox, uiTypeCombobox, struct combobox)
{
struct combobox *c = (struct combobox *) data;
uiFree(c);
}
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */ #define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */
@ -45,22 +40,14 @@ static uiCombobox *finishNewCombobox(DWORD style)
struct combobox *c; struct combobox *c;
uiWindowsMakeControlParams p; uiWindowsMakeControlParams p;
c = uiNew(struct combobox); c = (struct combobox *) uiWindowsNewSingleHWNDControl(uiTypeCombobox());
uiTyped(c)->Type = uiTypeCombobox();
// TODO client edge? // TODO client edge?
p.dwExStyle = WS_EX_CLIENTEDGE; c->hwnd = uiWindowsUtilCreateControlHWND(WS_EX_CLIENTEDGE,
p.lpClassName = L"combobox"; L"combobox", L"",
p.lpWindowName = L""; style | WS_TABSTOP,
p.dwStyle = style | WS_TABSTOP; hInstance, NULL,
p.hInstance = hInstance; TRUE);
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = c;
uiWindowsMakeControl(uiControl(c), &p);
c->hwnd = (HWND) uiControlHandle(uiControl(c));
uiControl(c)->PreferredSize = comboboxPreferredSize; uiControl(c)->PreferredSize = comboboxPreferredSize;

View File

@ -55,11 +55,7 @@ void uninitContainer(void)
logLastError("error unregistering container window class in uninitContainer()"); logLastError("error unregistering container window class in uninitContainer()");
} }
static void onDestroy(void *data) // TODO make into a uiNewContainer()
{
// do nothing
}
void uiMakeContainer(uiControl *c) void uiMakeContainer(uiControl *c)
{ {
uiWindowsMakeControlParams p; uiWindowsMakeControlParams p;

View File

@ -8,12 +8,7 @@ struct datetimepicker {
HWND hwnd; HWND hwnd;
}; };
static void onDestroy(void *data) uiDefineControlType(uiDateTimePicker, uiTypeDateTimePicker, struct datetimepicker)
{
struct datetimepicker *d = (struct datetimepicker *) data;
uiFree(d);
}
// TODO // TODO
// TODO use DTM_GETIDEALSIZE when making Vista-only // TODO use DTM_GETIDEALSIZE when making Vista-only
@ -32,21 +27,13 @@ uiDateTimePicker *finishNewDateTimePicker(DWORD style, WCHAR *format)
struct datetimepicker *d; struct datetimepicker *d;
uiWindowsMakeControlParams p; uiWindowsMakeControlParams p;
d = uiNew(struct datetimepicker); d = (struct datetimepicker *) uiWindowsNewSingleHWNDControluiTypeDateTimePicker());
uiTyped(d)->Type = uiTypeDateTimePicker();
p.dwExStyle = 0; // TODO client edge? d->hwnd = uiWindowsUtilCreateControlHWND(0, // TODO client edge?
p.lpClassName = DATETIMEPICK_CLASSW; DATETIMEPICK_CLASSW, L"",
p.lpWindowName = L""; style | WS_TABSTOP,
p.dwStyle = style | WS_TABSTOP; hInstance, NULL,
p.hInstance = hInstance; TRUE);
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = d;
uiWindowsMakeControl(uiControl(d), &p);
d->hwnd = (HWND) uiControlHandle(uiControl(d));
if (format != NULL) if (format != NULL)
if (SendMessageW(d->hwnd, DTM_SETFORMAT, 0, (LPARAM) format) == 0) if (SendMessageW(d->hwnd, DTM_SETFORMAT, 0, (LPARAM) format) == 0)

View File

@ -7,8 +7,11 @@ struct entry {
void (*onChanged)(uiEntry *, void *); void (*onChanged)(uiEntry *, void *);
void *onChangedData; void *onChangedData;
BOOL inhibitChanged; BOOL inhibitChanged;
void (*baseCommitDestroy)(uiControl *);
}; };
uiDefineControlType(uiEntry, uiTypeEntry, struct entry)
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
{ {
struct entry *e = (struct entry *) c; struct entry *e = (struct entry *) c;
@ -22,12 +25,12 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
return TRUE; return TRUE;
} }
static void onDestroy(void *data) static void entryCommitDestroy(uiControl *c)
{ {
struct entry *e = (struct entry *) data; struct entry *e = (struct entry *) c;
uiWindowsUnregisterWM_COMMANDHandler(e->hwnd); uiWindowsUnregisterWM_COMMANDHandler(e->hwnd);
uiFree(e); (*(e->baseCommitDestroy))(uiControl(e));
} }
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
@ -90,28 +93,22 @@ static void entrySetReadOnly(uiEntry *ee, int readonly)
uiEntry *uiNewEntry(void) uiEntry *uiNewEntry(void)
{ {
struct entry *e; struct entry *e;
uiWindowsMakeControlParams p;
e = uiNew(struct entry); e = (struct entry *) uiWindowsNewSingleHWNDControl(uiTypeEntry());
uiTyped(e)->Type = uiTypeEntry();
p.dwExStyle = WS_EX_CLIENTEDGE; e->hwnd = uiWindowsNewSingleHWNDControl(WS_EX_CLIENTEDGE,
p.lpClassName = L"edit"; L"edit", L"",
p.lpWindowName = L""; ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP,
p.dwStyle = ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP; hInstance, NULL,
p.hInstance = hInstance; TRUE);
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = e;
uiWindowsMakeControl(uiControl(e), &p);
e->hwnd = (HWND) uiControlHandle(uiControl(e));
uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e)); uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e));
e->onChanged = defaultOnChanged; e->onChanged = defaultOnChanged;
uiControl(e)->PreferredSize = entryPreferredSize; uiControl(e)->PreferredSize = entryPreferredSize;
e->baseCommitDestroy = uiControl(e)->CommitDestroy;
uiControl(e)->CommitDestroy = entryCommitDestroy;
uiEntry(e)->Text = entryText; uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText; uiEntry(e)->SetText = entrySetText;

View File

@ -6,10 +6,7 @@ struct group {
HWND hwnd; HWND hwnd;
}; };
static void onDestroy(void *data) uiDefineControlType(uiGroup, uiTypeGroup, struct group)
{
// TODO
}
static void groupPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) static void groupPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{ {
@ -26,27 +23,18 @@ static void groupSetChild(uiGroup *gg, uiControl *c)
uiGroup *uiNewGroup(const char *text) uiGroup *uiNewGroup(const char *text)
{ {
struct group *g; struct group *g;
uiWindowsMakeControlParams p;
WCHAR *wtext; WCHAR *wtext;
g = uiNew(struct group); g = (struct group *) uiWindowsNewSingleHWNDControl(uiTypeGroup());
uiTyped(g)->Type = uiTypeGroup();
p.dwExStyle = WS_EX_CONTROLPARENT;
p.lpClassName = L"button";
wtext = toUTF16(text); wtext = toUTF16(text);
p.lpWindowName = wtext; g->hwnd = uiWindowsNewSingleHWNDControl(WS_EX_CONTROLPARENT,
p.dwStyle = BS_GROUPBOX; L"button", wtext,
p.hInstance = hInstance; BS_GROUPBOX,
p.lpParam = NULL; hInstance, NULL,
p.useStandardControlFont = TRUE; TRUE);
p.onDestroy = onDestroy;
p.onDestroyData = g;
uiWindowsMakeControl(uiControl(g), &p);
uiFree(wtext); uiFree(wtext);
g->hwnd = (HWND) uiControlHandle(uiControl(g));
uiControl(g)->PreferredSize = groupPreferredSize; uiControl(g)->PreferredSize = groupPreferredSize;
uiGroup(g)->SetChild = groupSetChild; uiGroup(g)->SetChild = groupSetChild;

View File

@ -6,12 +6,7 @@ struct label {
HWND hwnd; HWND hwnd;
}; };
static void onDestroy(void *data) uiDefineControlType(uiLabel, uiTypeLabel, struct label)
{
struct label *l = (struct label *) data;
uiFree(l);
}
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define labelHeight 8 #define labelHeight 8
@ -37,29 +32,20 @@ static void labelSetText(uiLabel *l, const char *text)
uiLabel *uiNewLabel(const char *text) uiLabel *uiNewLabel(const char *text)
{ {
struct label *l; struct label *l;
uiWindowsMakeControlParams p;
WCHAR *wtext; WCHAR *wtext;
l = uiNew(struct label); l = (struct label *) uiWindowsNewSingleHWNDControl(uiTypeLabel());
uiTyped(l)->Type = uiTypeLabel();
p.dwExStyle = 0;
p.lpClassName = L"static";
wtext = toUTF16(text); wtext = toUTF16(text);
p.lpWindowName = wtext; l->hwnd = uiWindowsNewSingleHWNDControl(0,
L"static", wtext,
// SS_LEFTNOWORDWRAP clips text past the end; SS_NOPREFIX avoids accelerator translation // SS_LEFTNOWORDWRAP clips text past the end; SS_NOPREFIX avoids accelerator translation
// controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi) // controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi)
p.dwStyle = SS_LEFTNOWORDWRAP | SS_NOPREFIX; SS_LEFTNOWORDWRAP | SS_NOPREFIX,
p.hInstance = hInstance; hInstance, NULL,
p.lpParam = NULL; TRUE);
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = l;
uiWindowsMakeControl(uiControl(l), &p);
uiFree(wtext); uiFree(wtext);
l->hwnd = (HWND) uiControlHandle(uiControl(l));
uiControl(l)->PreferredSize = labelPreferredSize; uiControl(l)->PreferredSize = labelPreferredSize;
uiLabel(l)->Text = labelText; uiLabel(l)->Text = labelText;

View File

@ -6,12 +6,7 @@ struct progressbar {
HWND hwnd; HWND hwnd;
}; };
static void onDestroy(void *data) uiDefineControlType(uiProgressBar, uiTypeProgressBar, struct progressbar)
{
struct progressbar *p = (struct progressbar *) data;
uiFree(p);
}
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define pbarWidth 237 #define pbarWidth 237
@ -35,28 +30,19 @@ static void progressbarSetValue(uiProgressBar *pp, int value)
uiProgressBar *uiNewProgressBar(void) uiProgressBar *uiNewProgressBar(void)
{ {
struct progressbar *pbar; struct progressbar *p;
uiWindowsMakeControlParams p;
pbar = uiNew(struct progressbar); p = (struct progressbar *) uiWindowsNewSingleHWNDControl(uiTypeProgressBar());
uiTyped(pbar)->Type = uiTypeProgressBar();
p.dwExStyle = 0; p->hwnd = uiWindowsNewSingleHWNDControl(0,
p.lpClassName = PROGRESS_CLASSW; PROGRESS_CLASSW, L"",
p.lpWindowName = L""; PBS_SMOOTH,
p.dwStyle = PBS_SMOOTH; hInstance, NULL,
p.hInstance = hInstance; FALSE);
p.lpParam = NULL;
p.useStandardControlFont = FALSE;
p.onDestroy = onDestroy;
p.onDestroyData = pbar;
uiWindowsMakeControl(uiControl(pbar), &p);
pbar->hwnd = (HWND) uiControlHandle(uiControl(pbar)); uiControl(p)->PreferredSize = progressbarPreferredSize;
uiControl(pbar)->PreferredSize = progressbarPreferredSize; uiProgressBar(p)->SetValue = progressbarSetValue;
uiProgressBar(pbar)->SetValue = progressbarSetValue; return uiProgressBar(p);
return uiProgressBar(pbar);
} }

View File

@ -10,12 +10,7 @@ struct separator {
HWND hwnd; HWND hwnd;
}; };
static void onDestroy(void *data) uiDefineControlType(uiSeparator, uiTypeSeparator, struct separator)
{
struct separator *s = (struct separator *) data;
uiFree(s);
}
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
// TODO // TODO
@ -30,23 +25,14 @@ static void separatorPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, i
uiSeparator *uiNewHorizontalSeparator(void) uiSeparator *uiNewHorizontalSeparator(void)
{ {
struct separator *s; struct separator *s;
uiWindowsMakeControlParams p;
s = uiNew(struct separator); s = (struct separator *) uiWindowsNewSingleHWNDControl(uiTypeSeparator());
uiTyped(s)->Type = uiTypeSeparator();
p.dwExStyle = 0; s->hwnd = uiWindowsNewSingleHWNDControl(0,
p.lpClassName = L"static"; L"static", L"",
p.lpWindowName = L""; SS_ETCHEDHORZ,
p.dwStyle = SS_ETCHEDHORZ; hInstance, NULL,
p.hInstance = hInstance; TRUE);
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = s;
uiWindowsMakeControl(uiControl(s), &p);
s->hwnd = (HWND) uiControlHandle(uiControl(s));
uiControl(s)->PreferredSize = separatorPreferredSize; uiControl(s)->PreferredSize = separatorPreferredSize;

View File

@ -11,8 +11,11 @@ struct slider {
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *); void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
void (*onChanged)(uiSlider *, void *); void (*onChanged)(uiSlider *, void *);
void *onChangedData; void *onChangedData;
void (*baseCommitDestroy)(uiControl *);
}; };
uiDefineControlType(uiSlider, uiTypeSlider, struct slider)
static BOOL onWM_HSCROLL(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) static BOOL onWM_HSCROLL(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
{ {
struct slider *s = (struct slider *) c; struct slider *s = (struct slider *) c;
@ -22,12 +25,12 @@ static BOOL onWM_HSCROLL(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
return TRUE; return TRUE;
} }
static void onDestroy(void *data) static void sliderCommitDestroy(uiControl *c)
{ {
struct slider *s = (struct slider *) data; struct slider *s = (struct slider *) c;
uiWindowsUnregisterWM_HSCROLLHandler(s->hwnd); uiWindowsUnregisterWM_HSCROLLHandler(s->hwnd);
uiFree(s); (*(s->baseCommitDestroy))(uiControl(s));
} }
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
@ -72,24 +75,16 @@ static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *d
uiSlider *uiNewSlider(intmax_t min, intmax_t max) uiSlider *uiNewSlider(intmax_t min, intmax_t max)
{ {
struct slider *s; struct slider *s;
uiWindowsMakeControlParams p;
s = uiNew(struct slider); s = (struct slider *) uiWindowsNewSingleHWNDControl(uiTypeSlider());
uiTyped(s)->Type = uiTypeSlider();
p.dwExStyle = 0; s->hwnd = uiWindowsNewSingleHWNDControl(0,
p.lpClassName = TRACKBAR_CLASSW; TRACKBAR_CLASSW, L"",
p.lpWindowName = L"";
// TODO TBS_TRANSPARENTBKGND when making Vista-only // TODO TBS_TRANSPARENTBKGND when making Vista-only
p.dwStyle = TBS_HORZ | TBS_TOOLTIPS | WS_TABSTOP; TBS_HORZ | TBS_TOOLTIPS | WS_TABSTOP,
p.hInstance = hInstance; hInstance, NULL,
p.lpParam = NULL; TRUE);
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = s;
uiWindowsMakeControl(uiControl(s), &p);
s->hwnd = (HWND) uiControlHandle(uiControl(s));
uiWindowsRegisterWM_HSCROLLHandler(s->hwnd, onWM_HSCROLL, uiControl(s)); uiWindowsRegisterWM_HSCROLLHandler(s->hwnd, onWM_HSCROLL, uiControl(s));
SendMessageW(s->hwnd, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) min); SendMessageW(s->hwnd, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) min);
@ -99,6 +94,8 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max)
s->onChanged = defaultOnChanged; s->onChanged = defaultOnChanged;
uiControl(s)->PreferredSize = sliderPreferredSize; uiControl(s)->PreferredSize = sliderPreferredSize;
s->baseCommitDestroy = uiControl(s)->CommitDestroy;
uiControl(s)->CommitDestroy = sliderCommitDestroy;
uiSlider(s)->Value = sliderValue; uiSlider(s)->Value = sliderValue;
uiSlider(s)->SetValue = sliderSetValue; uiSlider(s)->SetValue = sliderSetValue;

View File

@ -9,8 +9,11 @@ struct spinbox {
void (*onChanged)(uiSpinbox *, void *); void (*onChanged)(uiSpinbox *, void *);
void *onChangedData; void *onChangedData;
BOOL inhibitChanged; BOOL inhibitChanged;
void (*baseCommitDestroy)(uiControl *);
}; };
uiDefineControlType(uiSpinbox, uiTypeSpinbox, struct spinbox)
// utility functions // utility functions
static intmax_t value(struct spinbox *s) static intmax_t value(struct spinbox *s)
@ -47,12 +50,13 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
return TRUE; return TRUE;
} }
static void onDestroy(void *data) static void spinboxCommitDestroy(uiControl *c)
{ {
struct spinbox *s = (struct spinbox *) data; struct spinbox *s = (struct spinbox *) c;
uiWindowsUnregisterWM_COMMANDHandler(s->hwnd); uiWindowsUnregisterWM_COMMANDHandler(s->hwnd);
uiFree(s); // TODO destroy the updown
(*(s->baseCommitDestroy))(uiControl(s));
} }
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
@ -148,23 +152,15 @@ static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void
uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max) uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
{ {
struct spinbox *s; struct spinbox *s;
uiWindowsMakeControlParams p;
s = uiNew(struct spinbox); s = (struct spinbox *) uiWindowsNewSingleHWNDControl(uiTypeSpinbox());
uiTyped(s)->Type = uiTypeSpinbox();
p.dwExStyle = WS_EX_CLIENTEDGE; s->hwnd = uiWindowsNewSingleHWNDControl(WS_EX_CLIENTEDGE,
p.lpClassName = L"edit"; L"edit", L"",
p.lpWindowName = L""; ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | ES_NUMBER | WS_TABSTOP,
p.dwStyle = ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | ES_NUMBER | WS_TABSTOP; hInstance, NULL,
p.hInstance = hInstance; TRUE);
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = s;
uiWindowsMakeControl(uiControl(s), &p);
s->hwnd = (HWND) uiControlHandle(uiControl(s));
uiWindowsRegisterWM_COMMANDHandler(s->hwnd, onWM_COMMAND, uiControl(s)); uiWindowsRegisterWM_COMMANDHandler(s->hwnd, onWM_COMMAND, uiControl(s));
recreateUpDown(s); recreateUpDown(s);
@ -178,6 +174,8 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
uiControl(s)->PreferredSize = spinboxPreferredSize; uiControl(s)->PreferredSize = spinboxPreferredSize;
s->baseResize = uiControl(s)->Resize; s->baseResize = uiControl(s)->Resize;
uiControl(s)->Resize = spinboxResize; uiControl(s)->Resize = spinboxResize;
s->baseCommitDestroy = uiControl(s)->CommitDestroy;
uiControl(s)->CommitDestroy = spinboxCommitDestroy;
uiSpinbox(s)->Value = spinboxValue; uiSpinbox(s)->Value = spinboxValue;
uiSpinbox(s)->SetValue = spinboxSetValue; uiSpinbox(s)->SetValue = spinboxSetValue;

View File

@ -9,6 +9,7 @@ struct tab {
HWND hwnd; HWND hwnd;
struct ptrArray *pages; struct ptrArray *pages;
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *); void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
void (*baseCommitDestroy)(uiControl *);
}; };
struct tabPage { struct tabPage {
@ -16,6 +17,8 @@ struct tabPage {
int margined; int margined;
}; };
uiDefineControlType(uiTab, uiTypeTab, struct tab)
// utility functions // utility functions
static LRESULT curpage(struct tab *t) static LRESULT curpage(struct tab *t)
@ -54,10 +57,13 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nm, LRESULT *lResult)
return TRUE; return TRUE;
} }
static void onDestroy(void *data) static void tabCommitDestroy(uiControl *c)
{ {
struct tab *t = (struct tab *) c;
// TODO // TODO
//TODO uiWindowsUnregisterWM_NOTIFYHandler(t->hwnd); uiWindowsUnregisterWM_NOTIFYHandler(t->hwnd);
(*(t->baseCommitDestroy))(uiControl(t));
} }
// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
@ -199,21 +205,14 @@ uiTab *uiNewTab(void)
struct tab *t; struct tab *t;
uiWindowsMakeControlParams p; uiWindowsMakeControlParams p;
t = uiNew(struct tab); t = (struct tab *) uiWindowsNewSingleHWNDControl(uiTypeTab());
uiTyped(t)->Type = uiTypeTab();
p.dwExStyle = 0; // don't set WS_EX_CONTROLPARENT yet; we do that dynamically in the message loop (see main_windows.c) t->hwnd = uiWindowsNewSingleHWNDControl(0, // don't set WS_EX_CONTROLPARENT yet; we do that dynamically in the message loop (see main_windows.c)
p.lpClassName = WC_TABCONTROLW; WC_TABCONTROLW, L"",
p.lpWindowName = L""; TCS_TOOLTIPS | WS_TABSTOP, // start with this; we will alternate between this and WS_EX_CONTROLPARENT as needed (see main.c and msgHasTabStops above and the toggling functions below)
p.dwStyle = TCS_TOOLTIPS | WS_TABSTOP; // start with this; we will alternate between this and WS_EX_CONTROLPARENT as needed (see main.c and msgHasTabStops above and the toggling functions below) hInstance, NULL,
p.hInstance = hInstance; TRUE);
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onDestroy = onDestroy;
p.onDestroyData = t;
uiWindowsMakeControl(uiControl(t), &p);
t->hwnd = (HWND) uiControlHandle(uiControl(t));
uiWindowsRegisterWM_NOTIFYHandler(t->hwnd, onWM_NOTIFY, uiControl(t)); uiWindowsRegisterWM_NOTIFYHandler(t->hwnd, onWM_NOTIFY, uiControl(t));
t->pages = newPtrArray(); t->pages = newPtrArray();
@ -221,6 +220,8 @@ uiTab *uiNewTab(void)
uiControl(t)->PreferredSize = tabPreferredSize; uiControl(t)->PreferredSize = tabPreferredSize;
t->baseResize = uiControl(t)->Resize; t->baseResize = uiControl(t)->Resize;
uiControl(t)->Resize = tabResize; uiControl(t)->Resize = tabResize;
t->baseCommitDestroy = uiControl(t)->CommitDestroy;
uiControl(t)->CommitDestroy = tabCommitDestroy;
uiTab(t)->Append = tabAppend; uiTab(t)->Append = tabAppend;
uiTab(t)->InsertAt = tabInsertAt; uiTab(t)->InsertAt = tabInsertAt;