More dynamic typing work.

This commit is contained in:
Pietro Gagliardi 2015-05-17 18:33:18 -04:00
parent efe5b952cf
commit 1307bbdfcc
13 changed files with 30 additions and 7 deletions

View File

@ -270,6 +270,7 @@ uiBox *uiNewHorizontalBox(void)
b->controls = newPtrArray();
uiControl(b)->Type = uiTypeBox();
b->baseDestroy = uiControl(b)->Destroy;
uiControl(b)->Destroy = boxDestroy;
b->baseSetParent = uiControl(b)->SetParent;

View File

@ -94,6 +94,8 @@ func geniface(i *pgidl.Interface, prefix string) {
fmt.Printf("struct %s%s {\n", prefix, i.Name)
if i.From != "" {
fmt.Printf("\t%s%s base;\n", prefix, i.From)
} else {
fmt.Printf("\tuintmax_t Type;\n")
}
for _, f := range i.Fields {
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("};\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,
prefix, i.Name)
fmt.Printf("#define %sIs%s(this) (%sIsA((this), %sType%s(), 0) != NULL)\n",
prefix, i.Name,
prefix,
prefix, i.Name)
}

View File

@ -25,7 +25,7 @@ uintmax_t uiRegisterType(const char *name, uintmax_t parent)
return types->len - 1;
}
void *uiIsA(void *p, uintmax_t id)
void *uiIsA(void *p, uintmax_t id, int fail)
{
uiTyped *t;
struct typeinfo *ti;
@ -45,9 +45,11 @@ void *uiIsA(void *p, uintmax_t id)
break;
compareTo = ti->parent;
}
ti = ptrArrayIndex(types, struct typeInfo *, t->Type);
complain("object %p not a %s in uiIsA()", t, ti->name);
return NULL; // make compiler happy
if (fail) {
ti = ptrArrayIndex(types, struct typeInfo *, t->Type);
complain("object %p not a %s in uiIsA()", t, ti->name);
}
return NULL;
}
// TODO free type info

View File

@ -29,8 +29,8 @@ func OnShouldQuit(f *func(data *void) int, data *void);
func FreeText(text *char);
func RegisterType(name *const char, parent uintmax_t);
func IsA(p *void, type uintmax_t);
struct uiTyped {
func IsA(p *void, type uintmax_t, fail int);
struct Typed {
field Type uintmax_t;
};

View File

@ -110,6 +110,7 @@ uiGroup *uiNewGroup(const char *text)
g->hwnd = (HWND) uiControlHandle(uiControl(g));
uiControl(g)->Type = uiTypeGroup();
uiControl(g)->PreferredSize = groupPreferredSize;
g->baseResize = uiControl(g)->Resize;
uiControl(g)->Resize = groupResize;

View File

@ -349,6 +349,7 @@ uiTab *uiNewTab(void)
if (SetWindowSubclass(t->hwnd, tabSubProc, 0, (DWORD_PTR) t) == FALSE)
logLastError("error subclassing Tab to give it its own resize handler in uiNewTab()");
uiControl(t)->Type = uiTypeTab();
uiControl(t)->PreferredSize = tabPreferredSize;
t->baseResize = uiControl(t)->Resize;
uiControl(t)->Resize = tabResize;

View File

@ -105,6 +105,7 @@ uiButton *uiNewButton(const char *text)
b->onClicked = defaultOnClicked;
uiControl(b)->Type = uiTypeButton();
uiControl(b)->PreferredSize = buttonPreferredSize;
uiButton(b)->Text = buttonText;

View File

@ -120,6 +120,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
c->onToggled = defaultOnToggled;
uiControl(c)->Type = uiTypeCheckbox();
uiControl(c)->PreferredSize = checkboxPreferredSize;
uiCheckbox(c)->Text = checkboxText;

View File

@ -115,6 +115,7 @@ uiEntry *uiNewEntry(void)
e->onChanged = defaultOnChanged;
uiControl(e)->Type = uiTypeEntry();
uiControl(e)->PreferredSize = entryPreferredSize;
uiEntry(e)->Text = entryText;

View File

@ -56,6 +56,7 @@ uiGroup *uiNewGroup(const char *text)
g->hwnd = (HWND) uiControlHandle(uiControl(g));
uiControl(g)->Type = uiTypeGroup();
uiControl(g)->PreferredSize = groupPreferredSize;
uiGroup(g)->SetChild = groupSetChild;

View File

@ -71,6 +71,7 @@ uiLabel *uiNewLabel(const char *text)
l->hwnd = (HWND) uiControlHandle(uiControl(l));
uiControl(l)->Type = uiTypeLabel();
uiControl(l)->PreferredSize = labelPreferredSize;
uiLabel(l)->Text = labelText;

View File

@ -74,6 +74,7 @@ uiTab *uiNewTab(void)
t->hwnd = (HWND) uiControlHandle(uiControl(t));
uiControl(t)->Type = uiTypeTab();
uiControl(t)->PreferredSize = tabPreferredSize;
uiTab(t)->AppendPage = tabAppendPage;

View File

@ -355,6 +355,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
w->onClosing = defaultOnClosing;
uiControl(w)->Type = uiTypeWindow();
uiControl(w)->Destroy = windowDestroy;
uiControl(w)->Handle = windowHandle;
uiControl(w)->Parent = windowParent;