Got rid of unix/container.c.

This commit is contained in:
Pietro Gagliardi 2015-06-30 01:17:52 -04:00
parent 21319201f2
commit b8c69fc733
3 changed files with 0 additions and 204 deletions

View File

@ -7,7 +7,6 @@ osCFILES = \
unix/checkbox.c \
unix/combobox.c \
unix/control.c \
unix/container.c \
unix/datetimepicker.c \
unix/entry.c \
unix/group.c \

View File

@ -1,199 +0,0 @@
// 28 april 2015
#include "uipriv_unix.h"
// TODO this is a wreck; describe what's going on here
#define containerWidgetType (containerWidget_get_type())
#define containerWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), containerWidgetType, containerWidget))
#define IscontainerWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), containerWidgetType))
#define containerWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), containerWidgetType, containerWidgetClass))
#define IscontainerWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), containerWidget))
#define GetcontainerWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), containerWidgetType, containerWidgetClass))
typedef struct containerWidget containerWidget;
typedef struct containerWidgetClass containerWidgetClass;
struct containerWidget {
GtkContainer parent_instance;
uiControl *c;
GPtrArray *widgets; // for for_each()/for_all()
int margined;
};
struct containerWidgetClass {
GtkContainerClass parent_class;
};
G_DEFINE_TYPE(containerWidget, containerWidget, GTK_TYPE_CONTAINER)
static void containerWidget_init(containerWidget *c)
{
c->widgets = g_ptr_array_new();
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
}
static void containerWidget_dispose(GObject *obj)
{
G_OBJECT_CLASS(containerWidget_parent_class)->dispose(obj);
}
static void containerWidget_finalize(GObject *obj)
{
containerWidget *c = containerWidget(obj);
g_ptr_array_unref(c->widgets);
G_OBJECT_CLASS(containerWidget_parent_class)->finalize(obj);
}
static void containerWidget_add(GtkContainer *container, GtkWidget *widget)
{
containerWidget *c = containerWidget(container);
gtk_widget_set_parent(widget, GTK_WIDGET(c));
g_ptr_array_add(c->widgets, widget);
}
static void containerWidget_remove(GtkContainer *container, GtkWidget *widget)
{
containerWidget *c = containerWidget(container);
gtk_widget_unparent(widget);
if (g_ptr_array_remove(c->widgets, widget) == FALSE)
complain("widget %p not found in containerWidget gtk_container_remove()", widget);
}
static void containerWidget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
containerWidget *c = containerWidget(widget);
uiSizing *d;
intmax_t x, y, width, height;
gtk_widget_set_allocation(GTK_WIDGET(c), allocation);
x = allocation->x;
y = allocation->y;
width = allocation->width;
height = allocation->height;
if (c->margined) {
x += gtkXMargin;
y += gtkYMargin;
width -= 2 * gtkXMargin;
height -= 2 * gtkYMargin;
}
d = uiUnixNewSizing();
uiControlResize(c->c, x, y, width, height, d);
uiFreeSizing(d);
}
static void containerWidget_get_preferred_height(GtkWidget *widget, gint *minimum, gint *natural)
{
containerWidget *c = containerWidget(widget);
intmax_t width, height;
uiSizing *d;
d = uiUnixNewSizing();
uiControlPreferredSize(uiControl(c->c), d, &width, &height);
uiFreeSizing(d);
*minimum = 0; // allow arbitrary resize
*natural = height;
}
static void containerWidget_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
{
containerWidget *c = containerWidget(widget);
intmax_t width, height;
uiSizing *d;
d = uiUnixNewSizing();
uiControlPreferredSize(uiControl(c->c), d, &width, &height);
uiFreeSizing(d);
*minimum = 0; // allow arbitrary resize
*natural = width;
}
struct forall {
GtkCallback callback;
gpointer data;
};
static void doforall(gpointer obj, gpointer data)
{
struct forall *s = (struct forall *) data;
(*(s->callback))(GTK_WIDGET(obj), s->data);
}
static void containerWidget_forall(GtkContainer *container, gboolean includeInternals, GtkCallback callback, gpointer data)
{
containerWidget *c = containerWidget(container);
struct forall s;
s.callback = callback;
s.data = data;
g_ptr_array_foreach(c->widgets, doforall, &s);
}
static void containerWidget_class_init(containerWidgetClass *class)
{
G_OBJECT_CLASS(class)->dispose = containerWidget_dispose;
G_OBJECT_CLASS(class)->finalize = containerWidget_finalize;
GTK_WIDGET_CLASS(class)->size_allocate = containerWidget_size_allocate;
GTK_WIDGET_CLASS(class)->get_preferred_height = containerWidget_get_preferred_height;
GTK_WIDGET_CLASS(class)->get_preferred_width = containerWidget_get_preferred_width;
GTK_CONTAINER_CLASS(class)->add = containerWidget_add;
GTK_CONTAINER_CLASS(class)->remove = containerWidget_remove;
GTK_CONTAINER_CLASS(class)->forall = containerWidget_forall;
}
uintptr_t uiMakeContainer(uiControl *c)
{
GtkWidget *widget;
widget = GTK_WIDGET(g_object_new(containerWidgetType, NULL));
uiUnixMakeSingleWidgetControl(c, widget);
containerWidget(widget)->c = c;
return (uintptr_t) widget;
}
// A holder wraps a uiControl in a single GtkWidget.
// It is used for things like GtkWindow, GtkNotebook, etc..
// The containerWidget's c is the wrapped uiControl.
// TODO what happens when destroying these and regular containerWidgets?
struct holder {
uiControl c;
containerWidget *cw;
};
uiDefineControlType(holder, holderType, struct holder)
static uintptr_t holderHandle(uiControl *c)
{
struct holder *h = (struct holder *) c;
return (uintptr_t) (h->cw);
}
uiControl *newHolder(void)
{
struct holder *h;
h = (struct holder *) uiNewControl(holderType());
h->cw = containerWidget(uiMakeContainer(uiControl(h)));
h->cw->c = NULL; // but don't make it manage ourselves
uiControl(h)->Handle = holderHandle;
return uiControl(h);
}
void holderSetChild(uiControl *hh, uiControl *c)
{
struct holder *h = (struct holder *) hh;
if (h->cw->c != NULL)
uiControlSetParent(h->cw->c, NULL);
h->cw->c = c;
if (c != NULL)
uiControlSetParent(h->cw->c, uiControl(h));
}

View File

@ -22,9 +22,5 @@ extern void uninitMenus(void);
extern void initAlloc(void);
extern void uninitAlloc(void);
// container.c
extern uiControl *newHolder(void);
extern void holderSetChild(uiControl *, uiControl *);
// TODO
#define PUT_CODE_HERE 0