[Xfce4-commits] [xfce/libxfce4ui] 04/04: New function: xfce_widget_reparent

noreply at xfce.org noreply at xfce.org
Tue Jun 7 15:05:02 CEST 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/libxfce4ui.

commit 6c99eee3a6440617adda7015c78e0f1dd263485c
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Tue Jun 7 16:03:17 2016 +0300

    New function: xfce_widget_reparent
    
    This is a simple helper function. Taken from:
    https://github.com/bluesabre/xfce4-settings-gtk3/blob/master/dialogs/appearance-settings/main.c#L133
---
 libxfce4ui/libxfce4ui.symbols    |  1 +
 libxfce4ui/xfce-gtk-extensions.c | 38 ++++++++++++++++++++++++++++++++++++++
 libxfce4ui/xfce-gtk-extensions.h |  3 +++
 3 files changed, 42 insertions(+)

diff --git a/libxfce4ui/libxfce4ui.symbols b/libxfce4ui/libxfce4ui.symbols
index 11c0877..bd87d5f 100644
--- a/libxfce4ui/libxfce4ui.symbols
+++ b/libxfce4ui/libxfce4ui.symbols
@@ -84,6 +84,7 @@ xfce_gtk_frame_box_new G_GNUC_MALLOC
 xfce_gtk_frame_box_new_with_content G_GNUC_MALLOC
 xfce_gtk_window_center_on_active_screen
 xfce_gtk_menu_popup_until_mapped
+xfce_widget_reparent
 #endif
 #endif
 
diff --git a/libxfce4ui/xfce-gtk-extensions.c b/libxfce4ui/xfce-gtk-extensions.c
index e80a12c..20ea464 100644
--- a/libxfce4ui/xfce-gtk-extensions.c
+++ b/libxfce4ui/xfce-gtk-extensions.c
@@ -264,5 +264,43 @@ xfce_gtk_menu_popup_until_mapped (GtkMenu *menu,
   return gtk_widget_get_mapped (GTK_WIDGET (menu));
 }
 
+
+
+/**
+ * xfce_widget_reparent:
+ * @widget: a #GtkWidget.
+ * @new_parent: a #GtkContainer to move the widget into
+ *
+ * Moves a widget from one GtkContainer to another, handling reference
+ * count issues to avoid destroying the widget.
+ *
+ * Return value: %TRUE if the widget could be moved, %FALSE otherwise.
+ */
+gboolean
+xfce_widget_reparent (GtkWidget *widget,
+                      GtkWidget *new_parent)
+{
+  GtkWidget *parent;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+  g_return_val_if_fail (GTK_IS_WIDGET (new_parent), FALSE);
+
+  if (!GTK_IS_CONTAINER (new_parent))
+    return FALSE;
+
+  parent = gtk_widget_get_parent(widget);
+  if (parent)
+    {
+      g_object_ref (widget);
+      gtk_container_remove (GTK_CONTAINER(parent), widget);
+      gtk_container_add (GTK_CONTAINER(new_parent), widget);
+      g_object_unref (widget);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 #define __XFCE_GTK_EXTENSIONS_C__
 #include <libxfce4ui/libxfce4ui-aliasdef.c>
diff --git a/libxfce4ui/xfce-gtk-extensions.h b/libxfce4ui/xfce-gtk-extensions.h
index babca0b..e075375 100644
--- a/libxfce4ui/xfce-gtk-extensions.h
+++ b/libxfce4ui/xfce-gtk-extensions.h
@@ -47,6 +47,9 @@ gboolean   xfce_gtk_menu_popup_until_mapped        (GtkMenu             *menu,
                                                     guint                button,
                                                     guint32              activate_time);
 
+gboolean   xfce_widget_reparent                    (GtkWidget           *widget,
+                                                    GtkWidget           *new_parent);
+
 G_END_DECLS
 
 #endif /* !__XFCE_GTK_EXTENSIONS_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list