summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--new/button_unix.c56
-rw-r--r--new/button_windows.c1
-rw-r--r--new/container_unix.c3
3 files changed, 59 insertions, 1 deletions
diff --git a/new/button_unix.c b/new/button_unix.c
new file mode 100644
index 0000000..2d341cc
--- /dev/null
+++ b/new/button_unix.c
@@ -0,0 +1,56 @@
+// 7 april 2015
+#include "uipriv_unix.h"
+
+struct button {
+ uiControl *c;
+ void (*onClicked)(uiControl *, void *);
+ void *onClickedData;
+};
+
+#define B(x) ((struct button *) (x))
+
+static void onClicked(GtkButton *b, gpointer data)
+{
+ (*(B(data)->onClicked))(B(data)->c, B(data)->onClickedData);
+}
+
+static void defaultOnClicked(uiControl *c, void *data)
+{
+ // do nothing
+}
+
+// TODO destruction
+uiControl *uiNewButton(const char *text)
+{
+ struct button *b;
+ GParameter props[1];
+ GtkWidget *widget;
+
+ b = g_new0(struct button, 1);
+
+ props[0].name = "label";
+ g_value_init(&(props[0].value), G_TYPE_STRING);
+ g_value_set_string(&(props[0].value), text);
+ b->c = uiUnixNewControl(GTK_TYPE_BUTTON,
+ 1, props,
+ FALSE, FALSE, FALSE, b);
+ g_value_unset(&(props[0].value)); // thanks to gregier in irc.gimp.net/#gtk+
+
+ widget = GTK_WIDGET(uiControlHandle(b->c));
+ g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);
+
+ b->onClicked = defaultOnClicked;
+
+ return b->c;
+}
+
+// TODO text
+
+void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
+{
+ struct button *b;
+
+ b = (struct button *) uiUnixControlData(c);
+ b->onClicked = f;
+ b->onClickedData = data;
+}
diff --git a/new/button_windows.c b/new/button_windows.c
index d7921ad..3725287 100644
--- a/new/button_windows.c
+++ b/new/button_windows.c
@@ -33,6 +33,7 @@ static void defaultOnClicked(uiControl *c, void *data)
// do nothing
}
+// TODO destruction
uiControl *uiNewButton(const char *text)
{
struct button *b;
diff --git a/new/container_unix.c b/new/container_unix.c
index d961d02..099944b 100644
--- a/new/container_unix.c
+++ b/new/container_unix.c
@@ -39,7 +39,8 @@ static void uiContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocati
gtk_widget_set_allocation(widget, allocation);
c = uiContainer(widget)->child;
- (*(c->resize))(c, allocation->x, allocation->y, allocation->width, allocation->height, &d);
+ if (c != NULL)
+ (*(c->resize))(c, allocation->x, allocation->y, allocation->width, allocation->height, &d);
}
struct forall {