summaryrefslogtreecommitdiff
path: root/new/newcontrol_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'new/newcontrol_unix.c')
-rw-r--r--new/newcontrol_unix.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/new/newcontrol_unix.c b/new/newcontrol_unix.c
index 870406c..14c1988 100644
--- a/new/newcontrol_unix.c
+++ b/new/newcontrol_unix.c
@@ -1,32 +1,32 @@
// 7 april 2015
#include "uipriv_unix.h"
-typedef struct uiSingleWidgetControl uiSingleWidgetControl;
+typedef struct singleWidget singleWidget;
-struct uiSingleWidgetControl {
- uiControl control;
+struct singleWidget {
GtkWidget *widget;
GtkWidget *scrolledWindow;
GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow
- void *data;
uintptr_t parent;
};
-#define S(c) ((uiSingleWidgetControl *) (c))
-
static void singleDestroy(uiControl *c)
{
- gtk_widget_destroy(S(c)->immediate);
+ singleWidget *s = (singleWidget *) (c->internal);
+
+ gtk_widget_destroy(s->immediate);
}
static uintptr_t singleHandle(uiControl *c)
{
- return (uintptr_t) (S(c)->widget);
+ singleWidget *s = (singleWidget *) (c->internal);
+
+ return (uintptr_t) (s->widget);
}
static void singleSetParent(uiControl *c, uintptr_t parent)
{
- uiSingleWidgetControl *s = S(c);
+ singleWidget *s = (singleWidget *) (c->internal);
s->parent = parent;
gtk_container_add(GTK_CONTAINER(s->parent), s->immediate);
@@ -35,7 +35,7 @@ static void singleSetParent(uiControl *c, uintptr_t parent)
static void singleRemoveParent(uiControl *c)
{
- uiSingleWidgetControl *s = S(c);
+ singleWidget *s = (singleWidget *) (c->internal);
uintptr_t oldparent;
oldparent = s->parent;
@@ -44,59 +44,62 @@ static void singleRemoveParent(uiControl *c)
updateParent(oldparent);
}
-static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
+static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{
- uiSize size;
+ singleWidget *s = (singleWidget *) (c->internal);
GtkRequisition natural;
// use the natural size as the minimum size is an *absolute* minimum
// for example, if a label has ellipsizing on, it can be the width of the ellipses, not the text
// there is a warning about height-for-width sizing, but in my tests this isn't an issue
- gtk_widget_get_preferred_size(S(c)->widget, NULL, &natural);
- size.width = natural.width;
- size.height = natural.height;
- return size;
+ gtk_widget_get_preferred_size(s->widget, NULL, &natural);
+ *width = natural.width;
+ *height = natural.height;
}
static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{
+ singleWidget *s = (singleWidget *) (c->internal);
GtkAllocation a;
a.x = x;
a.y = y;
a.width = width;
a.height = height;
- gtk_widget_size_allocate(S(c)->immediate, &a);
+ gtk_widget_size_allocate(s->immediate, &a);
}
static void onDestroy(GtkWidget *widget, gpointer data)
{
- uiSingleWidgetControl *c = (uiSingleWidgetControl *) data;
+ uiControl *c = (uiControl *) data;
+ singleWidget *s = (singleWidget *) (c->internal);
+ uiFree(s);
uiFree(c);
}
-uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void *data, const char *firstProperty, ...)
+uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, const char *firstProperty, ...)
{
- uiSingleWidgetControl *c;
+ uiControl *c;
+ singleWidget *s;
va_list ap;
- c = uiNew(uiSingleWidgetControl);
+ s = uiNew(singleWidget);
va_start(ap, firstProperty);
- c->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap));
+ s->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap));
va_end(ap);
- c->immediate = c->widget;
+ s->immediate = s->widget;
if (inScrolledWindow) {
- c->scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
- if (!GTK_IS_SCROLLABLE(c->widget))
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(c->scrolledWindow), c->widget);
+ s->scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
+ if (!GTK_IS_SCROLLABLE(s->widget))
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(s->scrolledWindow), s->widget);
else
- gtk_container_add(GTK_CONTAINER(c->scrolledWindow), c->widget);
+ gtk_container_add(GTK_CONTAINER(s->scrolledWindow), s->widget);
if (scrolledWindowHasBorder)
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(c->scrolledWindow), GTK_SHADOW_IN);
- c->immediate = c->scrolledWindow;
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(s->scrolledWindow), GTK_SHADOW_IN);
+ s->immediate = s->scrolledWindow;
}
// we need to keep an extra reference on the immediate widget
@@ -108,23 +111,20 @@ uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean scro
// - end user call works (shoudn't be in any container)
// - call in uiContainer works (both refs freed)
// this also ensures singleRemoveParent() works properly
- g_object_ref_sink(c->immediate);
- // and let's free the uiSingleWidgetControl with it
- g_signal_connect(c->immediate, "destroy", G_CALLBACK(onDestroy), c);
+ g_object_ref_sink(s->immediate);
- c->control.destroy = singleDestroy;
- c->control.handle = singleHandle;
- c->control.setParent = singleSetParent;
- c->control.removeParent = singleRemoveParent;
- c->control.preferredSize = singlePreferredSize;
- c->control.resize = singleResize;
+ c = uiNew(uiControl);
+ // assign s later; we still need it for one more thing
+ c->destroy = singleDestroy;
+ c->handle = singleHandle;
+ c->setParent = singleSetParent;
+ c->removeParent = singleRemoveParent;
+ c->preferredSize = singlePreferredSize;
+ c->resize = singleResize;
- c->data = data;
+ // and let's free everything with the immediate widget
+ g_signal_connect(s->immediate, "destroy", G_CALLBACK(onDestroy), c);
- return (uiControl *) c;
-}
-
-void *uiUnixControlData(uiControl *c)
-{
- return S(c)->data;
+ c->internal = s;
+ return c;
}