summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2015-07-23 22:05:32 +0200
committerinfirit <[email protected]>2015-08-31 22:35:17 +0200
commit5f23729c16860703ca8e7343927009f03b39b6ba (patch)
tree377c67762b8fbb14dc2f1e92cf87f6b949a5c976
parentc66a5fa6cadb49ee9ca43da098df0176a37883c5 (diff)
downloadeom-5f23729c16860703ca8e7343927009f03b39b6ba.tar.bz2
eom-5f23729c16860703ca8e7343927009f03b39b6ba.tar.xz
GTK3: toolbareditor, use GtkGrid instead of GtkTable
taken from: https://git.gnome.org/browse/eog/commit/?id=1a382d8
-rw-r--r--cut-n-paste/toolbar-editor/egg-toolbar-editor.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/cut-n-paste/toolbar-editor/egg-toolbar-editor.c b/cut-n-paste/toolbar-editor/egg-toolbar-editor.c
index fbd2b40..204aa1a 100644
--- a/cut-n-paste/toolbar-editor/egg-toolbar-editor.c
+++ b/cut-n-paste/toolbar-editor/egg-toolbar-editor.c
@@ -67,7 +67,11 @@ struct EggToolbarEditorPrivate
GtkUIManager *manager;
EggToolbarsModel *model;
+#if GTK_CHECK_VERSION (3, 4, 0)
+ GtkWidget *grid;
+#else
GtkWidget *table;
+#endif
GtkWidget *scrolled_window;
GList *actions_list;
GList *factory_list;
@@ -539,6 +543,51 @@ editor_create_item_from_name (EggToolbarEditor *editor,
}
static gint
+#if GTK_CHECK_VERSION (3, 4, 0)
+append_grid (GtkGrid *grid, GList *items, gint y, gint width)
+{
+ if (items != NULL)
+ {
+ gint x = 0;
+ GtkWidget *alignment;
+ GtkWidget *item;
+
+ if (y > 0)
+ {
+ item = gtk_hseparator_new ();
+ alignment = gtk_alignment_new (0.5, 0.5, 1.0, 0.0);
+ g_object_set (G_OBJECT (alignment), "expand", TRUE, NULL);
+ gtk_container_add (GTK_CONTAINER (alignment), item);
+ gtk_widget_show (alignment);
+ gtk_widget_show (item);
+
+ gtk_grid_attach (grid, alignment, 0, y, width, 1);
+ y++;
+ }
+
+ for (; items != NULL; items = items->next)
+ {
+ item = items->data;
+ alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ g_object_set (G_OBJECT (alignment), "expand", TRUE, NULL);
+ gtk_container_add (GTK_CONTAINER (alignment), item);
+ gtk_widget_show (alignment);
+ gtk_widget_show (item);
+
+ if (x >= width)
+ {
+ x = 0;
+ y++;
+ }
+ gtk_grid_attach (grid, alignment, x, y, 1, 1);
+ x++;
+ }
+
+ y++;
+ }
+ return y;
+}
+#else
append_table (GtkTable *table, GList *items, gint y, gint width)
{
if (items != NULL)
@@ -582,6 +631,7 @@ append_table (GtkTable *table, GList *items, gint y, gint width)
}
return y;
}
+#endif
static void
update_editor_sheet (EggToolbarEditor *editor)
@@ -589,6 +639,20 @@ update_editor_sheet (EggToolbarEditor *editor)
gint y;
GPtrArray *items;
GList *to_move = NULL, *to_copy = NULL;
+#if GTK_CHECK_VERSION (3, 4, 0)
+ GtkWidget *grid;
+ GtkWidget *viewport;
+
+ g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor));
+
+ /* Create new grid. */
+ grid = gtk_grid_new ();
+ editor->priv->grid = grid;
+ gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 24);
+ gtk_widget_show (grid);
+ gtk_drag_dest_set (grid, GTK_DEST_DEFAULT_ALL,
+#else
GtkWidget *table;
GtkWidget *viewport;
@@ -601,6 +665,7 @@ update_editor_sheet (EggToolbarEditor *editor)
gtk_table_set_row_spacings (GTK_TABLE (table), 24);
gtk_widget_show (table);
gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL,
+#endif
dest_drag_types, G_N_ELEMENTS (dest_drag_types),
GDK_ACTION_MOVE | GDK_ACTION_COPY);
@@ -632,14 +697,19 @@ update_editor_sheet (EggToolbarEditor *editor)
/* Add them to the sheet. */
y = 0;
+#if GTK_CHECK_VERSION (3, 4, 0)
+ y = append_grid (GTK_GRID (grid), to_move, y, 4);
+ y = append_grid (GTK_GRID (grid), to_copy, y, 4);
+#else
y = append_table (GTK_TABLE (table), to_move, y, 4);
y = append_table (GTK_TABLE (table), to_copy, y, 4);
+#endif
g_list_free (to_move);
g_list_free (to_copy);
g_ptr_array_free (items, TRUE);
- /* Delete old table. */
+ /* Delete old table/grid. */
viewport = gtk_bin_get_child (GTK_BIN (editor->priv->scrolled_window));
if (viewport)
{
@@ -647,9 +717,15 @@ update_editor_sheet (EggToolbarEditor *editor)
gtk_bin_get_child (GTK_BIN (viewport)));
}
+#if GTK_CHECK_VERSION (3, 4, 0)
+ /* Add grid to window. */
+ gtk_scrolled_window_add_with_viewport
+ (GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), grid);
+#else
/* Add table to window. */
gtk_scrolled_window_add_with_viewport
(GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), table);
+#endif
}