[nautilus-actions] base_gtk_utils_table_to_grid(): new function
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] base_gtk_utils_table_to_grid(): new function
- Date: Mon, 6 Feb 2012 20:08:40 +0000 (UTC)
commit c4585d363d66aefb3e6768b03b949bf011b3cd3b
Author: Pierre Wieser <pwieser trychlos org>
Date: Sat Feb 4 18:59:06 2012 +0100
base_gtk_utils_table_to_grid(): new function
ChangeLog | 3 ++
src/nact/base-gtk-utils.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
src/nact/base-gtk-utils.h | 4 ++
3 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3fc49bd..fe6fbed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2012-02-04 Pierre Wieser <pwieser trychlos org>
+ * src/nact/base-gtk-utils.c:
+ * src/nact/base-gtk-utils.h (base_gtk_utils_table_to_grid): New function.
+
* src/core/na-gtk-utils.c (na_gtk_utils_find_widget_by_name):
Also search inside of unnamed widgets.
diff --git a/src/nact/base-gtk-utils.c b/src/nact/base-gtk-utils.c
index 984031e..f7e8600 100644
--- a/src/nact/base-gtk-utils.c
+++ b/src/nact/base-gtk-utils.c
@@ -41,6 +41,20 @@
#define DEFAULT_WIDTH 22
+typedef struct {
+ GtkWidget *table;
+ guint rows;
+ guint ir;
+ guint columns;
+ guint ic;
+ GtkWidget *grid;
+}
+ TableToGridData;
+
+#if GTK_CHECK_VERSION( 3,0,0 )
+static void table_to_grid_foreach_cb( GtkWidget *widget, TableToGridData *ttg );
+#endif
+
/**
* base_gtk_utils_position_window:
* @window: this #BaseWindow-derived window.
@@ -503,3 +517,67 @@ base_gtk_utils_select_dir( BaseWindow *window,
gtk_widget_destroy( dialog );
}
+
+/*
+ * base_gtk_utils_table_to_grid:
+ * @window: the #BaseWindow container.
+ * @table_name: the name of the #GtkTable to be replaced.
+ *
+ * Dynamically replaces a GtkTable with a GtkGrid, doing its best in order
+ * to preserve order and name of all children.
+ *
+ * The caller has to take care of calling this function for Gtk 3.x, only
+ * replacing valuable GtkTables.
+ *
+ * This function should be called from on_base_initialize_gtk().
+ */
+void
+base_gtk_utils_table_to_grid( BaseWindow *window, const gchar *table_name )
+{
+#if GTK_CHECK_VERSION( 3,0,0 )
+ static const gchar *thisfn = "base_gtk_utils_table_to_grid";
+ TableToGridData ttg;
+ GtkWidget *parent;
+
+ memset( &ttg, '\0', sizeof( TableToGridData ));
+
+ ttg.table = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( base_window_get_gtk_toplevel( window )), table_name );
+ g_return_if_fail( ttg.table );
+ g_return_if_fail( GTK_IS_TABLE( ttg.table ));
+ g_debug( "%s: table=%p (%s)", thisfn, ( void * ) ttg.table, gtk_buildable_get_name( GTK_BUILDABLE( ttg.table )));
+
+ parent = gtk_widget_get_parent( ttg.table );
+ na_gtk_utils_dump_children( GTK_CONTAINER( parent ));
+
+ gtk_table_get_size( GTK_TABLE( ttg.table ), &ttg.rows, &ttg.columns );
+
+ ttg.grid = gtk_grid_new();
+
+ gtk_container_foreach( GTK_CONTAINER( ttg.table ), ( GtkCallback ) table_to_grid_foreach_cb, &ttg );
+ /*gtk_widget_unparent( ttg.table );*/
+
+ if( GTK_IS_ALIGNMENT( parent )){
+ gtk_container_remove( GTK_CONTAINER( parent ), ttg.table );
+ gtk_container_add( GTK_CONTAINER( parent ), ttg.grid );
+ } else {
+ g_warning( "%s: untreated parent of class %s", thisfn, G_OBJECT_TYPE_NAME( parent ));
+ }
+
+ na_gtk_utils_dump_children( GTK_CONTAINER( parent ));
+#endif
+}
+
+#if GTK_CHECK_VERSION( 3,0,0 )
+static void
+table_to_grid_foreach_cb( GtkWidget *widget, TableToGridData *ttg )
+{
+ static const gchar *thisfn = "base_gtk_utils_table_to_grid_foreach_cb";
+ guint left, top;
+
+ g_debug( "%s: widget=%p (%s)", thisfn, ( void * ) widget, gtk_buildable_get_name( GTK_BUILDABLE( widget )));
+
+ gtk_container_child_get( GTK_CONTAINER( ttg->table ), widget, "left-attach", &left, "top-attach", &top, NULL );
+ gtk_widget_unparent( widget );
+ gtk_grid_attach( GTK_GRID( ttg->grid ), widget, left, top, 1, 1 );
+}
+#endif
diff --git a/src/nact/base-gtk-utils.h b/src/nact/base-gtk-utils.h
index 95e606d..620608f 100644
--- a/src/nact/base-gtk-utils.h
+++ b/src/nact/base-gtk-utils.h
@@ -83,6 +83,10 @@ void base_gtk_utils_select_dir( BaseWindow *window,
const gchar *title, const gchar *wsp_name,
GtkWidget *entry, const gchar *entry_name );
+/* try to dynamically convert a GtkTable to a GtkGrid
+ */
+void base_gtk_utils_table_to_grid( BaseWindow *window, const gchar *table_name );
+
G_END_DECLS
#endif /* __BASE_GTK_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]