More dynamic typing work.
This commit is contained in:
parent
efe5b952cf
commit
1307bbdfcc
|
@ -270,6 +270,7 @@ uiBox *uiNewHorizontalBox(void)
|
||||||
|
|
||||||
b->controls = newPtrArray();
|
b->controls = newPtrArray();
|
||||||
|
|
||||||
|
uiControl(b)->Type = uiTypeBox();
|
||||||
b->baseDestroy = uiControl(b)->Destroy;
|
b->baseDestroy = uiControl(b)->Destroy;
|
||||||
uiControl(b)->Destroy = boxDestroy;
|
uiControl(b)->Destroy = boxDestroy;
|
||||||
b->baseSetParent = uiControl(b)->SetParent;
|
b->baseSetParent = uiControl(b)->SetParent;
|
||||||
|
|
|
@ -94,6 +94,8 @@ func geniface(i *pgidl.Interface, prefix string) {
|
||||||
fmt.Printf("struct %s%s {\n", prefix, i.Name)
|
fmt.Printf("struct %s%s {\n", prefix, i.Name)
|
||||||
if i.From != "" {
|
if i.From != "" {
|
||||||
fmt.Printf("\t%s%s base;\n", prefix, i.From)
|
fmt.Printf("\t%s%s base;\n", prefix, i.From)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\tuintmax_t Type;\n")
|
||||||
}
|
}
|
||||||
for _, f := range i.Fields {
|
for _, f := range i.Fields {
|
||||||
fmt.Printf("\t%s;\n", typedecl(f.Type, f.Name))
|
fmt.Printf("\t%s;\n", typedecl(f.Type, f.Name))
|
||||||
|
@ -113,8 +115,17 @@ func geniface(i *pgidl.Interface, prefix string) {
|
||||||
fmt.Printf("%s\n", cmethodmacro(m, prefix + i.Name))
|
fmt.Printf("%s\n", cmethodmacro(m, prefix + i.Name))
|
||||||
}
|
}
|
||||||
fmt.Printf("};\n")
|
fmt.Printf("};\n")
|
||||||
fmt.Printf("#define %s%s(this) ((%s%s *) (this))\n",
|
fmt.Printf("%s uintmax_t %sType%s(void);\n",
|
||||||
|
*extern,
|
||||||
|
prefix, i.Name)
|
||||||
|
fmt.Printf("#define %s%s(this) ((%s%s *) %sIsA((this), %sType%s(), 1))\n",
|
||||||
prefix, i.Name,
|
prefix, i.Name,
|
||||||
|
prefix, i.Name,
|
||||||
|
prefix,
|
||||||
|
prefix, i.Name)
|
||||||
|
fmt.Printf("#define %sIs%s(this) (%sIsA((this), %sType%s(), 0) != NULL)\n",
|
||||||
|
prefix, i.Name,
|
||||||
|
prefix,
|
||||||
prefix, i.Name)
|
prefix, i.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ uintmax_t uiRegisterType(const char *name, uintmax_t parent)
|
||||||
return types->len - 1;
|
return types->len - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *uiIsA(void *p, uintmax_t id)
|
void *uiIsA(void *p, uintmax_t id, int fail)
|
||||||
{
|
{
|
||||||
uiTyped *t;
|
uiTyped *t;
|
||||||
struct typeinfo *ti;
|
struct typeinfo *ti;
|
||||||
|
@ -45,9 +45,11 @@ void *uiIsA(void *p, uintmax_t id)
|
||||||
break;
|
break;
|
||||||
compareTo = ti->parent;
|
compareTo = ti->parent;
|
||||||
}
|
}
|
||||||
|
if (fail) {
|
||||||
ti = ptrArrayIndex(types, struct typeInfo *, t->Type);
|
ti = ptrArrayIndex(types, struct typeInfo *, t->Type);
|
||||||
complain("object %p not a %s in uiIsA()", t, ti->name);
|
complain("object %p not a %s in uiIsA()", t, ti->name);
|
||||||
return NULL; // make compiler happy
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO free type info
|
// TODO free type info
|
||||||
|
|
|
@ -29,8 +29,8 @@ func OnShouldQuit(f *func(data *void) int, data *void);
|
||||||
func FreeText(text *char);
|
func FreeText(text *char);
|
||||||
|
|
||||||
func RegisterType(name *const char, parent uintmax_t);
|
func RegisterType(name *const char, parent uintmax_t);
|
||||||
func IsA(p *void, type uintmax_t);
|
func IsA(p *void, type uintmax_t, fail int);
|
||||||
struct uiTyped {
|
struct Typed {
|
||||||
field Type uintmax_t;
|
field Type uintmax_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ uiGroup *uiNewGroup(const char *text)
|
||||||
|
|
||||||
g->hwnd = (HWND) uiControlHandle(uiControl(g));
|
g->hwnd = (HWND) uiControlHandle(uiControl(g));
|
||||||
|
|
||||||
|
uiControl(g)->Type = uiTypeGroup();
|
||||||
uiControl(g)->PreferredSize = groupPreferredSize;
|
uiControl(g)->PreferredSize = groupPreferredSize;
|
||||||
g->baseResize = uiControl(g)->Resize;
|
g->baseResize = uiControl(g)->Resize;
|
||||||
uiControl(g)->Resize = groupResize;
|
uiControl(g)->Resize = groupResize;
|
||||||
|
|
|
@ -349,6 +349,7 @@ uiTab *uiNewTab(void)
|
||||||
if (SetWindowSubclass(t->hwnd, tabSubProc, 0, (DWORD_PTR) t) == FALSE)
|
if (SetWindowSubclass(t->hwnd, tabSubProc, 0, (DWORD_PTR) t) == FALSE)
|
||||||
logLastError("error subclassing Tab to give it its own resize handler in uiNewTab()");
|
logLastError("error subclassing Tab to give it its own resize handler in uiNewTab()");
|
||||||
|
|
||||||
|
uiControl(t)->Type = uiTypeTab();
|
||||||
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;
|
||||||
|
|
|
@ -105,6 +105,7 @@ uiButton *uiNewButton(const char *text)
|
||||||
|
|
||||||
b->onClicked = defaultOnClicked;
|
b->onClicked = defaultOnClicked;
|
||||||
|
|
||||||
|
uiControl(b)->Type = uiTypeButton();
|
||||||
uiControl(b)->PreferredSize = buttonPreferredSize;
|
uiControl(b)->PreferredSize = buttonPreferredSize;
|
||||||
|
|
||||||
uiButton(b)->Text = buttonText;
|
uiButton(b)->Text = buttonText;
|
||||||
|
|
|
@ -120,6 +120,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
|
|
||||||
c->onToggled = defaultOnToggled;
|
c->onToggled = defaultOnToggled;
|
||||||
|
|
||||||
|
uiControl(c)->Type = uiTypeCheckbox();
|
||||||
uiControl(c)->PreferredSize = checkboxPreferredSize;
|
uiControl(c)->PreferredSize = checkboxPreferredSize;
|
||||||
|
|
||||||
uiCheckbox(c)->Text = checkboxText;
|
uiCheckbox(c)->Text = checkboxText;
|
||||||
|
|
|
@ -115,6 +115,7 @@ uiEntry *uiNewEntry(void)
|
||||||
|
|
||||||
e->onChanged = defaultOnChanged;
|
e->onChanged = defaultOnChanged;
|
||||||
|
|
||||||
|
uiControl(e)->Type = uiTypeEntry();
|
||||||
uiControl(e)->PreferredSize = entryPreferredSize;
|
uiControl(e)->PreferredSize = entryPreferredSize;
|
||||||
|
|
||||||
uiEntry(e)->Text = entryText;
|
uiEntry(e)->Text = entryText;
|
||||||
|
|
|
@ -56,6 +56,7 @@ uiGroup *uiNewGroup(const char *text)
|
||||||
|
|
||||||
g->hwnd = (HWND) uiControlHandle(uiControl(g));
|
g->hwnd = (HWND) uiControlHandle(uiControl(g));
|
||||||
|
|
||||||
|
uiControl(g)->Type = uiTypeGroup();
|
||||||
uiControl(g)->PreferredSize = groupPreferredSize;
|
uiControl(g)->PreferredSize = groupPreferredSize;
|
||||||
|
|
||||||
uiGroup(g)->SetChild = groupSetChild;
|
uiGroup(g)->SetChild = groupSetChild;
|
||||||
|
|
|
@ -71,6 +71,7 @@ uiLabel *uiNewLabel(const char *text)
|
||||||
|
|
||||||
l->hwnd = (HWND) uiControlHandle(uiControl(l));
|
l->hwnd = (HWND) uiControlHandle(uiControl(l));
|
||||||
|
|
||||||
|
uiControl(l)->Type = uiTypeLabel();
|
||||||
uiControl(l)->PreferredSize = labelPreferredSize;
|
uiControl(l)->PreferredSize = labelPreferredSize;
|
||||||
|
|
||||||
uiLabel(l)->Text = labelText;
|
uiLabel(l)->Text = labelText;
|
||||||
|
|
|
@ -74,6 +74,7 @@ uiTab *uiNewTab(void)
|
||||||
|
|
||||||
t->hwnd = (HWND) uiControlHandle(uiControl(t));
|
t->hwnd = (HWND) uiControlHandle(uiControl(t));
|
||||||
|
|
||||||
|
uiControl(t)->Type = uiTypeTab();
|
||||||
uiControl(t)->PreferredSize = tabPreferredSize;
|
uiControl(t)->PreferredSize = tabPreferredSize;
|
||||||
|
|
||||||
uiTab(t)->AppendPage = tabAppendPage;
|
uiTab(t)->AppendPage = tabAppendPage;
|
||||||
|
|
|
@ -355,6 +355,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
|
|
||||||
w->onClosing = defaultOnClosing;
|
w->onClosing = defaultOnClosing;
|
||||||
|
|
||||||
|
uiControl(w)->Type = uiTypeWindow();
|
||||||
uiControl(w)->Destroy = windowDestroy;
|
uiControl(w)->Destroy = windowDestroy;
|
||||||
uiControl(w)->Handle = windowHandle;
|
uiControl(w)->Handle = windowHandle;
|
||||||
uiControl(w)->Parent = windowParent;
|
uiControl(w)->Parent = windowParent;
|
||||||
|
|
Loading…
Reference in New Issue