Rewrote the GTK+ container to work for package ui.
This commit is contained in:
parent
c1e1b0549c
commit
9cad7bf60b
|
@ -1,65 +1,71 @@
|
||||||
// 13 august 2014
|
/* 13 august 2014 */
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
#define CUSTOM_CONTAINER_TYPE (customContainer_get_type())
|
#include "gtk_unix.h"
|
||||||
#define CUSTOM_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CUSTOM_CONTAINER_TYPE, CustomContainer))
|
#include "_cgo_export.h"
|
||||||
#define IS_CUSTOM_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CUSTOM_CONTAINER_TYPE))
|
|
||||||
#define CUSTOM_CONTAINER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST((class), CUSTOM_CONTAINER_TYPE, CustomContainerClass))
|
|
||||||
#define IS_CUSTOM_CONTAINER_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE((class), CUSTOM_CONTAINER_TYPE))
|
|
||||||
#define CUSTOM_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CUSTOM_CONTAINER_TYPE, CustomContainerClass))
|
|
||||||
|
|
||||||
typedef struct CustomContainer CustomContainer;
|
#define GOCONTAINER_TYPE (goContainer_get_type())
|
||||||
typedef struct CustomContainerClass CustomContainerClass;
|
#define GOCONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GOCONTAINER_TYPE, goContainer))
|
||||||
|
#define IS_GOCONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GOCONTAINER_TYPE))
|
||||||
|
#define GOCONTAINER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST((class), GOCONTAINER_TYPE, goContainerClass))
|
||||||
|
#define IS_GOCONTAINER_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE((class), GOCONTAINER_TYPE))
|
||||||
|
#define GOCONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GOCONTAINER_TYPE, goContainerClass))
|
||||||
|
|
||||||
struct CustomContainer {
|
typedef struct goContainer goContainer;
|
||||||
|
typedef struct goContainerClass goContainerClass;
|
||||||
|
|
||||||
|
struct goContainer {
|
||||||
GtkContainer parent_instance;
|
GtkContainer parent_instance;
|
||||||
GtkWidget *child;
|
void *gocontainer;
|
||||||
|
GPtrArray *children; /* for forall() */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CustomContainerClass {
|
struct goContainerClass {
|
||||||
GtkContainerClass parent_class;
|
GtkContainerClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(CustomContainer, customContainer, GTK_TYPE_CONTAINER)
|
G_DEFINE_TYPE(goContainer, goContainer, GTK_TYPE_CONTAINER)
|
||||||
|
|
||||||
static void customContainer_init(CustomContainer *c)
|
static void goContainer_init(goContainer *c)
|
||||||
{
|
{
|
||||||
|
c->children = g_ptr_array_new();
|
||||||
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
|
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_dispose(GObject *obj)
|
static void goContainer_dispose(GObject *obj)
|
||||||
{
|
{
|
||||||
G_OBJECT_CLASS(customContainer_parent_class)->dispose(obj);
|
g_ptr_array_unref(c->children);
|
||||||
|
G_OBJECT_CLASS(goContainer_parent_class)->dispose(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_finalize(GObject *obj)
|
static void goContainer_finalize(GObject *obj)
|
||||||
{
|
{
|
||||||
G_OBJECT_CLASS(customContainer_parent_class)->finalize(obj);
|
G_OBJECT_CLASS(goContainer_parent_class)->finalize(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_add(GtkContainer *container, GtkWidget *widget)
|
static void goContainer_add(GtkContainer *container, GtkWidget *widget)
|
||||||
{
|
{
|
||||||
gtk_widget_set_parent(widget, GTK_WIDGET(container));
|
gtk_widget_set_parent(widget, GTK_WIDGET(container));
|
||||||
CUSTOM_CONTAINER(container)->child = widget;
|
g_ptr_array_add(GOCONTAINER(container)->children, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_remove(GtkContainer *container, GtkWidget *widget)
|
static void goContainer_remove(GtkContainer *container, GtkWidget *widget)
|
||||||
{
|
{
|
||||||
gtk_widget_unparent(widget);
|
gtk_widget_unparent(widget);
|
||||||
CUSTOM_CONTAINER(container)->child = NULL;
|
/* TODO this won't guarantee order preservation; important if we ever actually use this */
|
||||||
|
g_ptr_array_remove(GOCONTAINER(container)->children, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
static void goContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
||||||
{
|
{
|
||||||
gtk_widget_set_allocation(widget, allocation);
|
gtk_widget_set_allocation(widget, allocation);
|
||||||
if (CUSTOM_CONTAINER(widget)->child != NULL)
|
containerResized(GOCONTAINER(widget)->gocontainer, allocation);
|
||||||
gtk_widget_size_allocate(CUSTOM_CONTAINER(widget)->child, allocation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_get_preferred_width(GtkWidget *widget, gint *min, gint *nat)
|
/*
|
||||||
|
static void goContainer_get_preferred_width(GtkWidget *widget, gint *min, gint *nat)
|
||||||
{
|
{
|
||||||
if (CUSTOM_CONTAINER(widget)->child != NULL) {
|
if (GOCONTAINER(widget)->child != NULL) {
|
||||||
gtk_widget_get_preferred_width(CUSTOM_CONTAINER(widget)->child, min, nat);
|
gtk_widget_get_preferred_width(GOCONTAINER(widget)->child, min, nat);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (min != NULL)
|
if (min != NULL)
|
||||||
|
@ -68,10 +74,10 @@ static void customContainer_get_preferred_width(GtkWidget *widget, gint *min, gi
|
||||||
*nat = 0;
|
*nat = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_get_preferred_height(GtkWidget *widget, gint *min, gint *nat)
|
static void goContainer_get_preferred_height(GtkWidget *widget, gint *min, gint *nat)
|
||||||
{
|
{
|
||||||
if (CUSTOM_CONTAINER(widget)->child != NULL) {
|
if (GOCONTAINER(widget)->child != NULL) {
|
||||||
gtk_widget_get_preferred_height(CUSTOM_CONTAINER(widget)->child, min, nat);
|
gtk_widget_get_preferred_height(GOCONTAINER(widget)->child, min, nat);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (min != NULL)
|
if (min != NULL)
|
||||||
|
@ -79,33 +85,31 @@ static void customContainer_get_preferred_height(GtkWidget *widget, gint *min, g
|
||||||
if (nat != NULL)
|
if (nat != NULL)
|
||||||
*nat = 0;
|
*nat = 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static void customContainer_forall(GtkContainer *container, gboolean includeInternals, GtkCallback callback, gpointer data)
|
static void goContainer_forall(GtkContainer *container, gboolean includeInternals, GtkCallback callback, gpointer data)
|
||||||
{
|
{
|
||||||
if (CUSTOM_CONTAINER(container)->child != NULL)
|
/* TODO is this safe? */
|
||||||
(*callback)(CUSTOM_CONTAINER(container)->child, data);
|
g_ptr_array_foreach(GOCONTAINER(container)->children, callback, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void customContainer_class_init(CustomContainerClass *class)
|
static void goContainer_class_init(goContainerClass *class)
|
||||||
{
|
{
|
||||||
G_OBJECT_CLASS(class)->dispose = customContainer_dispose;
|
G_OBJECT_CLASS(class)->dispose = goContainer_dispose;
|
||||||
G_OBJECT_CLASS(class)->finalize = customContainer_finalize;
|
G_OBJECT_CLASS(class)->finalize = goContainer_finalize;
|
||||||
GTK_WIDGET_CLASS(class)->size_allocate = customContainer_size_allocate;
|
GTK_WIDGET_CLASS(class)->size_allocate = goContainer_size_allocate;
|
||||||
// GTK_WIDGET_CLASS(class)->get_preferred_width = customContainer_get_preferred_width;
|
// GTK_WIDGET_CLASS(class)->get_preferred_width = goContainer_get_preferred_width;
|
||||||
// GTK_WIDGET_CLASS(class)->get_preferred_height = customContainer_get_preferred_height;
|
// GTK_WIDGET_CLASS(class)->get_preferred_height = goContainer_get_preferred_height;
|
||||||
GTK_CONTAINER_CLASS(class)->add = customContainer_add;
|
GTK_CONTAINER_CLASS(class)->add = goContainer_add;
|
||||||
GTK_CONTAINER_CLASS(class)->remove = customContainer_remove;
|
GTK_CONTAINER_CLASS(class)->remove = goContainer_remove;
|
||||||
GTK_CONTAINER_CLASS(class)->forall = customContainer_forall;
|
GTK_CONTAINER_CLASS(class)->forall = goContainer_forall;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
GtkWidget *newContainer(void *gocontianer)
|
||||||
{
|
{
|
||||||
gtk_init(NULL, NULL);
|
GoContainer *c;
|
||||||
GtkWidget *mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
||||||
GtkWidget *cc = g_object_new(CUSTOM_CONTAINER_TYPE, NULL);
|
c = (goContainer *) g_object_new(GOCONTAINER_TYPE, NULL);
|
||||||
gtk_container_add(GTK_CONTAINER(cc), gtk_button_new_with_label("Test"));
|
c->gocontainer = gocontainer;
|
||||||
gtk_container_add(GTK_CONTAINER(mainwin), cc);
|
return GTK_WIDGET(c);
|
||||||
gtk_widget_show_all(mainwin);
|
|
||||||
gtk_main();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,4 +36,7 @@ struct goTableModelClass {
|
||||||
extern goTableModel *newTableModel(void *);
|
extern goTableModel *newTableModel(void *);
|
||||||
extern void tableUpdate(goTableModel *, gint, gint);
|
extern void tableUpdate(goTableModel *, gint, gint);
|
||||||
|
|
||||||
|
/* container_unix.c */
|
||||||
|
extern GtkWidget *newContainer(void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue