diff --git a/common/control.c b/common/control.c index 5ba1b04a..3e00db78 100644 --- a/common/control.c +++ b/common/control.c @@ -149,11 +149,11 @@ void controlUpdateState(uiControl *c) #define uiControlSignature 0x7569436F // TODO should this be public? -uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typename) +uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr) { uiControl *c; - c = (uiControl *) uiAlloc(size, typename); + c = (uiControl *) uiAlloc(size, typenamestr); c->Signature = uiControlSignature; c->OSSignature = OSsig; c->TypeSignature = typesig; diff --git a/common/uipriv.h b/common/uipriv.h index b7e00cbe..83ce6e74 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -25,7 +25,7 @@ extern void osCommitEnable(uiControl *); extern void osCommitDisable(uiControl *); // control.c -extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typename); +extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); // ptrarray.c struct ptrArray { diff --git a/darwin/control.m b/darwin/control.m index 3d3bd082..3abeebd9 100644 --- a/darwin/control.m +++ b/darwin/control.m @@ -65,7 +65,7 @@ void uiDarwinSetControlFont(NSControl *c, NSControlSize size) #define uiDarwinControlSignature 0x44617277 -uiDarwinControl *uiDarwinNewControl(size_t n, uint32_t typesig, const char *typename) +uiDarwinControl *uiDarwinNewControl(size_t n, uint32_t typesig, const char *typenamestr) { - return uiDarwinControl(newControl(n, uiDarwinControlSignature, typesig, typename)); + return uiDarwinControl(newControl(n, uiDarwinControlSignature, typesig, typenamestr)); } diff --git a/ui_darwin.h b/ui_darwin.h index b47675c1..1d8a2115 100644 --- a/ui_darwin.h +++ b/ui_darwin.h @@ -46,7 +46,7 @@ _UI_EXTERN void uiDarwinControlTriggerRelayout(uiDarwinControl *); // TODO document #define uiNewControl(type) uiDarwinNewControl(sizeof (type), type ## Signature, #type) -_UI_EXTERN uiDarwinControl *uiDarwinNewControl(size_t n, uint32_t typesig, const char *typename); +_UI_EXTERN uiDarwinControl *uiDarwinNewControl(size_t n, uint32_t typesig, const char *typenamestr); #define uiDarwinFinishNewControl(variable, type) \ uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \ diff --git a/ui_unix.h b/ui_unix.h index f9682ae9..d3c456f8 100644 --- a/ui_unix.h +++ b/ui_unix.h @@ -39,7 +39,7 @@ struct uiUnixControl { // TODO document #define uiNewControl(type) uiUnixNewControl(sizeof (type), type ## Signature, #type) -_UI_EXTERN uiUnixControl *uiUnixNewControl(size_t n, uint32_t typesig, const char *typename); +_UI_EXTERN uiUnixControl *uiUnixNewControl(size_t n, uint32_t typesig, const char *typenamestr); #define uiUnixFinishNewControl(variable, type) \ uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \ diff --git a/ui_windows.h b/ui_windows.h index 099b7f84..7f5f50a7 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -65,6 +65,11 @@ _UI_EXTERN void uiWindowsControlQueueRelayout(uiWindowsControl *); #define uiWindowsDefineControl(type) \ uiWindowsDefineControlWithOnDestroy(type, (void) me;) +// TODO document +// TODO rename the macro? +#define uiNewControl(type) uiWindowsNewControl(sizeof (type), type ## Signature, #type) +_UI_EXTERN uiWindowsControl *uiWindowsNewControl(size_t n, uint32_t typesig, const char *typenamestr); + #define uiWindowsFinishNewControl(variable, type) \ uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \ uiControl(variable)->Handle = _ ## type ## Handle; \ diff --git a/unix/control.c b/unix/control.c index 611361e9..59b59241 100644 --- a/unix/control.c +++ b/unix/control.c @@ -32,7 +32,7 @@ void uiUnixFinishControl(uiControl *c) #define uiUnixControlSignature 0x556E6978 -uiUnixControl *uiUnixNewControl(size_t n, uint32_t typesig, const char *typename) +uiUnixControl *uiUnixNewControl(size_t n, uint32_t typesig, const char *typenamestr) { - return uiUnixControl(newControl(n, uiUnixControlSignature, typesig, typename)); + return uiUnixControl(newControl(n, uiUnixControlSignature, typesig, typenamestr)); } diff --git a/windows/area.cpp b/windows/area.cpp index 8fa8975a..7801c770 100644 --- a/windows/area.cpp +++ b/windows/area.cpp @@ -105,7 +105,7 @@ uiArea *uiNewArea(uiAreaHandler *ah) { uiArea *a; - a = (uiArea *) uiNewControl(uiAreaType()); + a = (uiArea *) uiNewControl(uiArea); a->ah = ah; a->scrolling = FALSE; @@ -127,7 +127,7 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, intmax_t width, intmax_t height) { uiArea *a; - a = (uiArea *) uiNewControl(uiAreaType()); + a = (uiArea *) uiNewControl(uiArea); a->ah = ah; a->scrolling = TRUE; diff --git a/windows/box.cpp b/windows/box.cpp index 341615f8..95fd991d 100644 --- a/windows/box.cpp +++ b/windows/box.cpp @@ -275,7 +275,7 @@ static uiBox *finishNewBox(int vertical) { uiBox *b; - b = (uiBox *) uiNewControl(uiBoxType()); + b = (uiBox *) uiNewControl(uiBox); b->hwnd = newContainer(); diff --git a/windows/button.cpp b/windows/button.cpp index 1aaf6fe8..fe46366f 100644 --- a/windows/button.cpp +++ b/windows/button.cpp @@ -76,7 +76,7 @@ uiButton *uiNewButton(const char *text) uiButton *b; WCHAR *wtext; - b = (uiButton *) uiNewControl(uiButtonType()); + b = (uiButton *) uiNewControl(uiButton); wtext = toUTF16(text); b->hwnd = uiWindowsEnsureCreateControlHWND(0, diff --git a/windows/checkbox.cpp b/windows/checkbox.cpp index f3371768..e874bac7 100644 --- a/windows/checkbox.cpp +++ b/windows/checkbox.cpp @@ -88,7 +88,7 @@ uiCheckbox *uiNewCheckbox(const char *text) uiCheckbox *c; WCHAR *wtext; - c = (uiCheckbox *) uiNewControl(uiCheckboxType()); + c = (uiCheckbox *) uiNewControl(uiCheckbox); wtext = toUTF16(text); c->hwnd = uiWindowsEnsureCreateControlHWND(0, diff --git a/windows/combobox.cpp b/windows/combobox.cpp index 7c9b6efb..4308ad20 100644 --- a/windows/combobox.cpp +++ b/windows/combobox.cpp @@ -85,7 +85,7 @@ static uiCombobox *finishNewCombobox(DWORD style) { uiCombobox *c; - c = (uiCombobox *) uiNewControl(uiComboboxType()); + c = (uiCombobox *) uiNewControl(uiCombobox); c->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, L"combobox", L"", diff --git a/windows/control.cpp b/windows/control.cpp index 3a153ee5..7ee64813 100644 --- a/windows/control.cpp +++ b/windows/control.cpp @@ -24,16 +24,6 @@ HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCW return hwnd; } -// TODO make this unnecessary -static uintmax_t type_uiWindowsControl = 0; - -uintmax_t uiWindowsControlType(void) -{ - if (type_uiWindowsControl == 0) - type_uiWindowsControl = uiRegisterType("uiWindowsControl", uiControlType(), sizeof (uiWindowsControl)); - return type_uiWindowsControl; -} - static void defaultCommitShow(uiControl *c) { ShowWindow((HWND) uiControlHandle(c), SW_SHOW); @@ -70,3 +60,11 @@ void uiWindowsRearrangeControlIDsZOrder(uiControl *c) wc = uiWindowsControl(c); (*(wc->ArrangeChildrenControlIDsZOrder))(wc); } + +// choose a value distinct from uiWindowSignature +#define uiWindowsControlSignature 0x4D53576E + +uiWindowsControl *uiWindowsNewControl(size_t n, uint32_t typesig, const char *typenamestr) +{ + return uiWindowsControl(newControl(n, uiWindowsControlSignature, typesig, typenamestr)); +} diff --git a/windows/datetimepicker.cpp b/windows/datetimepicker.cpp index 174d8400..1d1fc583 100644 --- a/windows/datetimepicker.cpp +++ b/windows/datetimepicker.cpp @@ -123,7 +123,7 @@ static uiDateTimePicker *finishNewDateTimePicker(DWORD style) { uiDateTimePicker *d; - d = (uiDateTimePicker *) uiNewControl(uiDateTimePickerType()); + d = (uiDateTimePicker *) uiNewControl(uiDateTimePicker); d->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, DATETIMEPICK_CLASSW, L"", diff --git a/windows/entry.cpp b/windows/entry.cpp index 93fe14e9..4aeaf6d5 100644 --- a/windows/entry.cpp +++ b/windows/entry.cpp @@ -82,7 +82,7 @@ uiEntry *uiNewEntry(void) { uiEntry *e; - e = (uiEntry *) uiNewControl(uiEntryType()); + e = (uiEntry *) uiNewControl(uiEntry); e->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, L"edit", L"", diff --git a/windows/fontbutton.cpp b/windows/fontbutton.cpp index 051999d7..5c71770f 100644 --- a/windows/fontbutton.cpp +++ b/windows/fontbutton.cpp @@ -102,7 +102,7 @@ uiFontButton *uiNewFontButton(void) { uiFontButton *b; - b = (uiFontButton *) uiNewControl(uiFontButtonType()); + b = (uiFontButton *) uiNewControl(uiFontButton); b->hwnd = uiWindowsEnsureCreateControlHWND(0, L"button", L"you should not be seeing this", diff --git a/windows/group.cpp b/windows/group.cpp index c0ba9ca8..c6927a6a 100644 --- a/windows/group.cpp +++ b/windows/group.cpp @@ -148,7 +148,7 @@ uiGroup *uiNewGroup(const char *text) uiGroup *g; WCHAR *wtext; - g = (uiGroup *) uiNewControl(uiGroupType()); + g = (uiGroup *) uiNewControl(uiGroup); wtext = toUTF16(text); g->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT, diff --git a/windows/label.cpp b/windows/label.cpp index 565d0964..7239996e 100644 --- a/windows/label.cpp +++ b/windows/label.cpp @@ -38,7 +38,7 @@ uiLabel *uiNewLabel(const char *text) uiLabel *l; WCHAR *wtext; - l = (uiLabel *) uiNewControl(uiLabelType()); + l = (uiLabel *) uiNewControl(uiLabel); wtext = toUTF16(text); l->hwnd = uiWindowsEnsureCreateControlHWND(0, diff --git a/windows/menu.cpp b/windows/menu.cpp index 6a262cd5..89406d7f 100644 --- a/windows/menu.cpp +++ b/windows/menu.cpp @@ -13,7 +13,6 @@ static BOOL hasPreferences = FALSE; static BOOL hasAbout = FALSE; struct uiMenu { - uiTyped t; WCHAR *name; uiMenuItem **items; uintmax_t len; @@ -21,7 +20,6 @@ struct uiMenu { }; struct uiMenuItem { - uiTyped t; WCHAR *name; int type; WORD id; @@ -121,7 +119,6 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) } item = uiNew(uiMenuItem); - uiTyped(item)->Type = uiMenuItemType(); m->items[m->len] = item; m->len++; @@ -211,7 +208,6 @@ uiMenu *uiNewMenu(const char *name) } m = uiNew(uiMenu); - uiTyped(m)->Type = uiMenuType(); menus[len] = m; len++; diff --git a/windows/multilineentry.cpp b/windows/multilineentry.cpp index 34377a5a..7c05a2e9 100644 --- a/windows/multilineentry.cpp +++ b/windows/multilineentry.cpp @@ -101,7 +101,7 @@ uiMultilineEntry *uiNewMultilineEntry(void) { uiMultilineEntry *e; - e = (uiMultilineEntry *) uiNewControl(uiMultilineEntryType()); + e = (uiMultilineEntry *) uiNewControl(uiMultilineEntry); e->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, L"edit", L"", diff --git a/windows/progressbar.cpp b/windows/progressbar.cpp index 4487d57f..9e63b458 100644 --- a/windows/progressbar.cpp +++ b/windows/progressbar.cpp @@ -43,7 +43,7 @@ uiProgressBar *uiNewProgressBar(void) { uiProgressBar *p; - p = (uiProgressBar *) uiNewControl(uiProgressBarType()); + p = (uiProgressBar *) uiNewControl(uiProgressBar); p->hwnd = uiWindowsEnsureCreateControlHWND(0, PROGRESS_CLASSW, L"", diff --git a/windows/radiobuttons.cpp b/windows/radiobuttons.cpp index 65deb6cc..b02972b0 100644 --- a/windows/radiobuttons.cpp +++ b/windows/radiobuttons.cpp @@ -142,7 +142,7 @@ uiRadioButtons *uiNewRadioButtons(void) { uiRadioButtons *r; - r = (uiRadioButtons *) uiNewControl(uiRadioButtonsType()); + r = (uiRadioButtons *) uiNewControl(uiRadioButtons); r->hwnd = newContainer(); diff --git a/windows/separator.cpp b/windows/separator.cpp index edb83d44..d3c03fae 100644 --- a/windows/separator.cpp +++ b/windows/separator.cpp @@ -27,7 +27,7 @@ uiSeparator *uiNewHorizontalSeparator(void) { uiSeparator *s; - s = (uiSeparator *) uiNewControl(uiSeparatorType()); + s = (uiSeparator *) uiNewControl(uiSeparator); s->hwnd = uiWindowsEnsureCreateControlHWND(0, L"static", L"", diff --git a/windows/slider.cpp b/windows/slider.cpp index 496f2434..f76664f8 100644 --- a/windows/slider.cpp +++ b/windows/slider.cpp @@ -58,7 +58,7 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max) { uiSlider *s; - s = (uiSlider *) uiNewControl(uiSliderType()); + s = (uiSlider *) uiNewControl(uiSlider); s->hwnd = uiWindowsEnsureCreateControlHWND(0, TRACKBAR_CLASSW, L"", diff --git a/windows/spinbox.cpp b/windows/spinbox.cpp index 1c56bdac..fc986ec8 100644 --- a/windows/spinbox.cpp +++ b/windows/spinbox.cpp @@ -176,7 +176,7 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max) if (min >= max) complain("error: min >= max in uiNewSpinbox()"); - s = (uiSpinbox *) uiNewControl(uiSpinboxType()); + s = (uiSpinbox *) uiNewControl(uiSpinbox); s->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, L"edit", L"", diff --git a/windows/tab.cpp b/windows/tab.cpp index 653dd22d..133039f3 100644 --- a/windows/tab.cpp +++ b/windows/tab.cpp @@ -241,7 +241,7 @@ uiTab *uiNewTab(void) { uiTab *t; - t = (uiTab *) uiNewControl(uiTabType()); + t = (uiTab *) uiNewControl(uiTab); t->hwnd = uiWindowsEnsureCreateControlHWND(0, WC_TABCONTROLW, L"", diff --git a/windows/window.cpp b/windows/window.cpp index 6e0e7879..eafa4615 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -261,7 +261,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) WCHAR *wtitle; BOOL hasMenubarBOOL; - w = (uiWindow *) uiNewControl(uiWindowType()); + w = (uiWindow *) uiNewControl(uiWindow); hasMenubarBOOL = FALSE; if (hasMenubar)