Changed the various OS-side control creation functions to use Make like uiMakeContainer() does instead of New.

This commit is contained in:
Pietro Gagliardi 2015-05-02 20:51:00 -04:00
parent 57bc11d67c
commit 454b3ecb03
22 changed files with 33 additions and 34 deletions

View File

@ -78,7 +78,7 @@ uiButton *uiNewButton(const char *text)
b = uiNew(struct button); b = uiNew(struct button);
uiDarwinNewControl(uiControl(b), [NSButton class], NO, NO, destroy, b); uiDarwinMakeControl(uiControl(b), [NSButton class], NO, NO, destroy, b);
b->button = (NSButton *) uiControlHandle(uiControl(b)); b->button = (NSButton *) uiControlHandle(uiControl(b));

View File

@ -96,7 +96,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
c = uiNew(struct checkbox); c = uiNew(struct checkbox);
uiDarwinNewControl(uiControl(c), [NSButton class], NO, NO, destroy, c); uiDarwinMakeControl(uiControl(c), [NSButton class], NO, NO, destroy, c);
c->checkbox = (NSButton *) uiControlHandle(uiControl(c)); c->checkbox = (NSButton *) uiControlHandle(uiControl(c));

View File

@ -49,7 +49,7 @@ uiEntry *uiNewEntry(void)
e = uiNew(struct entry); e = uiNew(struct entry);
uiDarwinNewControl(uiControl(e), [NSTextField class], NO, NO, destroy, e); uiDarwinMakeControl(uiControl(e), [NSTextField class], NO, NO, destroy, e);
e->textfield = (NSTextField *) uiControlHandle(uiControl(e)); e->textfield = (NSTextField *) uiControlHandle(uiControl(e));

View File

@ -33,7 +33,7 @@ uiLabel *uiNewLabel(const char *text)
l = uiNew(struct label); l = uiNew(struct label);
uiDarwinNewControl(uiControl(l), [NSTextField class], NO, NO, destroy, l); uiDarwinMakeControl(uiControl(l), [NSTextField class], NO, NO, destroy, l);
l->label = (NSTextField *) uiControlHandle(uiControl(l)); l->label = (NSTextField *) uiControlHandle(uiControl(l));

View File

@ -124,7 +124,7 @@ static void singleDisable(uiControl *c)
[((NSControl *) (s->view)) setEnabled:NO]; [((NSControl *) (s->view)) setEnabled:NO];
} }
void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData) void uiDarwinMakeControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData)
{ {
singleView *s; singleView *s;

View File

@ -131,7 +131,7 @@ uiTab *uiNewTab(void)
t = uiNew(struct tab); t = uiNew(struct tab);
uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, t); uiDarwinMakeControl(uiControl(t), [NSTabView class], NO, NO, destroy, t);
t->tabview = (NSTabView *) uiControlHandle(uiControl(t)); t->tabview = (NSTabView *) uiControlHandle(uiControl(t));

1
ui.idl
View File

@ -56,7 +56,6 @@ interface Container from Control {
func ResizeChildren(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing); func ResizeChildren(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing);
func Update(void); func Update(void);
}; };
// TODO change the various OS-side control functions to be Make
func MakeContainer(c *Container); func MakeContainer(c *Container);
interface Window from Control { interface Window from Control {

View File

@ -7,11 +7,11 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
#ifndef __UI_UI_DARWIN_H__ #ifndef __UI_UI_DARWIN_H__
#define __UI_UI_DARWIN_H__ #define __UI_UI_DARWIN_H__
// uiDarwinNewControl() initializes the given uiControl with the given Cocoa control inside. // uiDarwinMakeControl() initializes the given uiControl with the given Cocoa control inside.
// The second parameter should come from [RealControlType class]. // The second parameter should come from [RealControlType class].
// The two scrollView parameters allow placing scrollbars on the new control. // The two scrollView parameters allow placing scrollbars on the new control.
// The two onDestroy parameters define a function and its parameter to call when the widget is destroyed. // The two onDestroy parameters define a function and its parameter to call when the widget is destroyed.
extern void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData); extern void uiDarwinMakeControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData);
// You can use this function from within your control implementations to return text strings that can be freed with uiTextFree(). // You can use this function from within your control implementations to return text strings that can be freed with uiTextFree().
extern char *uiDarwinNSStringToText(NSString *); extern char *uiDarwinNSStringToText(NSString *);

View File

@ -7,12 +7,12 @@ This file assumes that you have included <gtk/gtk.h> and "ui.h" beforehand. It p
#ifndef __UI_UI_UNIX_H__ #ifndef __UI_UI_UNIX_H__
#define __UI_UI_UNIX_H__ #define __UI_UI_UNIX_H__
// uiUnixNewControl() creates a new uiControl with the given GTK+ control inside, storing it in the uiControl at c. // uiUnixMakeControl() creates a new uiControl with the given GTK+ control inside, storing it in the uiControl at c.
// The second parameter is the type of the control, as passed to the first argument of g_object_new(). // The second parameter is the type of the control, as passed to the first argument of g_object_new().
// The two scrolledWindow parameters allow placing scrollbars on the new control. // The two scrolledWindow parameters allow placing scrollbars on the new control.
// The destroy parameters are for a function that should be called when destroying the widget. // The destroy parameters are for a function that should be called when destroying the widget.
// The firstProperty parameter and beyond allow passing construct properties to the new control, as with g_object_new(); end this list with NULL. // The firstProperty parameter and beyond allow passing construct properties to the new control, as with g_object_new(); end this list with NULL.
_UI_EXTERN void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(void *), void *onDestroyData, const char *firstProperty, ...); _UI_EXTERN void uiUnixMakeControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(void *), void *onDestroyData, const char *firstProperty, ...);
// uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText(). // uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText().
extern char *uiUnixStrdupText(const char *); extern char *uiUnixStrdupText(const char *);

View File

@ -7,10 +7,10 @@ This file assumes that you have included <windows.h> and "ui.h" beforehand. It p
#ifndef __UI_UI_WINDOWS_H__ #ifndef __UI_UI_WINDOWS_H__
#define __UI_UI_WINDOWS_H__ #define __UI_UI_WINDOWS_H__
// uiWindowsNewControl() initializes the given uiControl with the given Windows API control inside. // uiWindowsMakeControl() initializes the given uiControl with the given Windows API control inside.
// You will need to provide the preferredSize() method yourself. // You will need to provide the preferredSize() method yourself.
typedef struct uiWindowsNewControlParams uiWindowsNewControlParams; typedef struct uiWindowsMakeControlParams uiWindowsMakeControlParams;
struct uiWindowsNewControlParams { struct uiWindowsMakeControlParams {
// These match the CreateWindowExW() function. // These match the CreateWindowExW() function.
DWORD dwExStyle; DWORD dwExStyle;
LPCWSTR lpClassName; LPCWSTR lpClassName;
@ -33,7 +33,7 @@ struct uiWindowsNewControlParams {
void (*onDestroy)(void *data); void (*onDestroy)(void *data);
void *onDestroyData; void *onDestroyData;
}; };
void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p); void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p);
// This contains the Windows-specific parts of the uiSizing structure. // This contains the Windows-specific parts of the uiSizing structure.
// baseX and baseY are the dialog base units. // baseX and baseY are the dialog base units.

View File

@ -56,7 +56,7 @@ uiButton *uiNewButton(const char *text)
b = uiNew(struct button); b = uiNew(struct button);
uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON, uiUnixMakeControl(uiControl(b), GTK_TYPE_BUTTON,
FALSE, FALSE, onDestroy, b, FALSE, FALSE, onDestroy, b,
"label", text, "label", text,
NULL); NULL);

View File

@ -80,7 +80,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
c = uiNew(struct checkbox); c = uiNew(struct checkbox);
uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON, uiUnixMakeControl(uiControl(c), GTK_TYPE_CHECK_BUTTON,
FALSE, FALSE, onDestroy, c, FALSE, FALSE, onDestroy, c,
"label", text, "label", text,
NULL); NULL);

View File

@ -34,7 +34,7 @@ uiEntry *uiNewEntry(void)
e = uiNew(struct entry); e = uiNew(struct entry);
uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY, uiUnixMakeControl(uiControl(e), GTK_TYPE_ENTRY,
FALSE, FALSE, onDestroy, e, FALSE, FALSE, onDestroy, e,
NULL); NULL);

View File

@ -34,7 +34,7 @@ uiLabel *uiNewLabel(const char *text)
l = uiNew(struct label); l = uiNew(struct label);
uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL, uiUnixMakeControl(uiControl(l), GTK_TYPE_LABEL,
FALSE, FALSE, onDestroy, l, FALSE, FALSE, onDestroy, l,
"label", text, "label", text,
"xalign", 0.0, // note: must be a float constant, otherwise the ... will turn it into an int and we get segfaults on some platforms (thanks ebassi in irc.gimp.net/#gtk+) "xalign", 0.0, // note: must be a float constant, otherwise the ... will turn it into an int and we get segfaults on some platforms (thanks ebassi in irc.gimp.net/#gtk+)

View File

@ -124,7 +124,7 @@ static void singleDisable(uiControl *c)
gtk_widget_set_sensitive(s->immediate, FALSE); gtk_widget_set_sensitive(s->immediate, FALSE);
} }
void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(void *), void *onDestroyData, const char *firstProperty, ...) void uiUnixMakeControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(void *), void *onDestroyData, const char *firstProperty, ...)
{ {
singleWidget *s; singleWidget *s;
va_list ap; va_list ap;

View File

@ -112,7 +112,7 @@ uiTab *uiNewTab(void)
t = uiNew(struct tab); t = uiNew(struct tab);
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK, uiUnixMakeControl(uiControl(t), GTK_TYPE_NOTEBOOK,
FALSE, FALSE, onDestroy, t, FALSE, FALSE, onDestroy, t,
NULL); NULL);

View File

@ -81,7 +81,7 @@ static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *d
uiButton *uiNewButton(const char *text) uiButton *uiNewButton(const char *text)
{ {
struct button *b; struct button *b;
uiWindowsNewControlParams p; uiWindowsMakeControlParams p;
WCHAR *wtext; WCHAR *wtext;
b = uiNew(struct button); b = uiNew(struct button);
@ -97,7 +97,7 @@ uiButton *uiNewButton(const char *text)
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy; p.onDestroy = onDestroy;
p.onDestroyData = b; p.onDestroyData = b;
uiWindowsNewControl(uiControl(b), &p); uiWindowsMakeControl(uiControl(b), &p);
uiFree(wtext); uiFree(wtext);
b->hwnd = (HWND) uiControlHandle(uiControl(b)); b->hwnd = (HWND) uiControlHandle(uiControl(b));

View File

@ -96,7 +96,7 @@ static void checkboxSetChecked(uiCheckbox *cc, int checked)
uiCheckbox *uiNewCheckbox(const char *text) uiCheckbox *uiNewCheckbox(const char *text)
{ {
struct checkbox *c; struct checkbox *c;
uiWindowsNewControlParams p; uiWindowsMakeControlParams p;
WCHAR *wtext; WCHAR *wtext;
c = uiNew(struct checkbox); c = uiNew(struct checkbox);
@ -112,7 +112,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy; p.onDestroy = onDestroy;
p.onDestroyData = c; p.onDestroyData = c;
uiWindowsNewControl(uiControl(c), &p); uiWindowsMakeControl(uiControl(c), &p);
uiFree(wtext); uiFree(wtext);
c->hwnd = (HWND) uiControlHandle(uiControl(c)); c->hwnd = (HWND) uiControlHandle(uiControl(c));

View File

@ -46,7 +46,7 @@ static void entrySetText(uiEntry *e, const char *text)
uiEntry *uiNewEntry(void) uiEntry *uiNewEntry(void)
{ {
struct entry *e; struct entry *e;
uiWindowsNewControlParams p; uiWindowsMakeControlParams p;
e = uiNew(struct entry); e = uiNew(struct entry);
@ -60,7 +60,7 @@ uiEntry *uiNewEntry(void)
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy; p.onDestroy = onDestroy;
p.onDestroyData = e; p.onDestroyData = e;
uiWindowsNewControl(uiControl(e), &p); uiWindowsMakeControl(uiControl(e), &p);
e->hwnd = (HWND) uiControlHandle(uiControl(e)); e->hwnd = (HWND) uiControlHandle(uiControl(e));

View File

@ -47,7 +47,7 @@ static void labelSetText(uiLabel *l, const char *text)
uiLabel *uiNewLabel(const char *text) uiLabel *uiNewLabel(const char *text)
{ {
struct label *l; struct label *l;
uiWindowsNewControlParams p; uiWindowsMakeControlParams p;
WCHAR *wtext; WCHAR *wtext;
l = uiNew(struct label); l = uiNew(struct label);
@ -65,7 +65,7 @@ uiLabel *uiNewLabel(const char *text)
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy; p.onDestroy = onDestroy;
p.onDestroyData = l; p.onDestroyData = l;
uiWindowsNewControl(uiControl(l), &p); uiWindowsMakeControl(uiControl(l), &p);
uiFree(wtext); uiFree(wtext);
l->hwnd = (HWND) uiControlHandle(uiControl(l)); l->hwnd = (HWND) uiControlHandle(uiControl(l));

View File

@ -124,7 +124,7 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
} }
void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p) void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p)
{ {
singleHWND *s; singleHWND *s;
@ -137,7 +137,7 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
100, 100, 100, 100,
initialParent, NULL, p->hInstance, NULL); initialParent, NULL, p->hInstance, NULL);
if (s->hwnd == NULL) if (s->hwnd == NULL)
logLastError("error creating control in uiWindowsNewControl()"); logLastError("error creating control in uiWindowsMakeControl()");
s->onWM_COMMAND = p->onWM_COMMAND; s->onWM_COMMAND = p->onWM_COMMAND;
s->onWM_NOTIFY = p->onWM_NOTIFY; s->onWM_NOTIFY = p->onWM_NOTIFY;
@ -149,7 +149,7 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
// this handles redirected notification messages // this handles redirected notification messages
if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE) if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE)
logLastError("error subclassing Windows control in uiWindowsNewControl()"); logLastError("error subclassing Windows control in uiWindowsMakeControl()");
c->Internal = s; c->Internal = s;
c->Destroy = singleDestroy; c->Destroy = singleDestroy;

View File

@ -226,7 +226,7 @@ static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
uiTab *uiNewTab(void) uiTab *uiNewTab(void)
{ {
struct tab *t; struct tab *t;
uiWindowsNewControlParams p; uiWindowsMakeControlParams p;
t = uiNew(struct tab); t = uiNew(struct tab);
@ -240,7 +240,7 @@ uiTab *uiNewTab(void)
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy; p.onDestroy = onDestroy;
p.onDestroyData = t; p.onDestroyData = t;
uiWindowsNewControl(uiControl(t), &p); uiWindowsMakeControl(uiControl(t), &p);
t->hwnd = (HWND) uiControlHandle(uiControl(t)); t->hwnd = (HWND) uiControlHandle(uiControl(t));