ui/gtk/container.c

changeset 74
55718d4ed227
parent 66
8d490d97aab8
child 75
efe2f65bea17
--- a/ui/gtk/container.c	Wed Jan 21 16:02:30 2015 +0100
+++ b/ui/gtk/container.c	Wed Jan 21 11:21:47 2015 +0100
@@ -104,9 +104,14 @@
             sizeof(UiGridContainer));
     ct->container.widget = grid;
     ct->container.add = ui_grid_container_add;
+#ifdef UI_GTK2
+    ct->width = 0;
+    ct->height = 1;
+#endif
     return (UiContainer*)ct;
 }
 
+#ifdef UI_GTK3
 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
     UiGridContainer *grid = (UiGridContainer*)ct;
     
@@ -121,6 +126,27 @@
     
     ui_reset_layout(ct->layout);
 }
+#endif
+#ifdef UI_GTK2
+void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    UiGridContainer *grid = (UiGridContainer*)ct;
+    
+    if(ct->layout.newline) {
+        grid->x = 0;
+        grid->y++;
+        ct->layout.newline = FALSE;
+    }
+    
+    gtk_table_attach(GTK_TABLE(ct->widget), widget, grid->x, grid->x+1, grid->y, grid->y+1, GTK_FILL, GTK_FILL, 0, 0);
+    grid->x++;
+    int nw = grid->x > grid->width ? grid->x : grid->width;
+    if(grid->x > grid->width || grid->y > grid->height) {
+        grid->width = nw;
+        grid->height = grid->y + 1;
+        gtk_table_resize(GTK_TABLE(ct->widget), grid->width, grid->height);
+    }
+}
+#endif
 
 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) {
     UiTabViewContainer *ct = ucx_mempool_calloc(
@@ -169,7 +195,11 @@
 UIWIDGET ui_grid(UiObject *obj) {
     UiContainer *ct = uic_get_current_container(obj);
     
+#ifdef UI_GTK3
     GtkWidget *grid = gtk_grid_new();
+#elif defined(UI_GTK2)
+    GtkWidget *grid = gtk_table_new(1, 1, FALSE);
+#endif
     ct->add(ct, grid, TRUE);
     
     UiObject *newobj = uic_object_new(obj, grid);

mercurial