[Xfce4-commits] [xfce/libxfce4ui] 27/28: XfceTitledDialog: Add _create_action_area, _add_button and _add_action_widget

noreply at xfce.org noreply at xfce.org
Thu Jan 9 23:32:10 CET 2020


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

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/libxfce4ui.

commit 707cf22d489fdab3a0c614cbf60b6515b001406b
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Wed Jan 8 23:53:07 2020 +0100

    XfceTitledDialog: Add _create_action_area, _add_button and
    _add_action_widget
    
    Three new API calls have been introduced in this commit to make it
    easier to use the XfceTitledDialogClass directly to create dialogs while
    still maintaining the layout of having both headerbar and action area in
    the dialog.
    
    * xfce_titled_dialog_create_action_area (to initially set up the
    dialog's custom action area)
    * xfce_titled_dialog_add_button (as a replacement for
    gtk_dialog_add_button)
    * xfce_titled_dialog_add_action_widget (as a replacement for
    gtk_dialog_add_action_widget)
---
 docs/libxfce4ui-sections.txt    |   3 +
 libxfce4ui/xfce-titled-dialog.c | 169 ++++++++++++++++++++++++++++++++++++----
 libxfce4ui/xfce-titled-dialog.h |   7 ++
 3 files changed, 163 insertions(+), 16 deletions(-)

diff --git a/docs/libxfce4ui-sections.txt b/docs/libxfce4ui-sections.txt
index 6664471..8886c9d 100644
--- a/docs/libxfce4ui-sections.txt
+++ b/docs/libxfce4ui-sections.txt
@@ -59,6 +59,9 @@ XfceTitledDialog
 xfce_titled_dialog_new
 xfce_titled_dialog_new_with_buttons
 xfce_titled_dialog_new_with_mixed_buttons
+xfce_titled_dialog_create_action_area
+xfce_titled_dialog_add_button
+xfce_titled_dialog_add_action_widget
 xfce_titled_dialog_set_default_response
 xfce_titled_dialog_get_subtitle
 xfce_titled_dialog_set_subtitle
diff --git a/libxfce4ui/xfce-titled-dialog.c b/libxfce4ui/xfce-titled-dialog.c
index 649112b..fa030c5 100644
--- a/libxfce4ui/xfce-titled-dialog.c
+++ b/libxfce4ui/xfce-titled-dialog.c
@@ -78,6 +78,7 @@ struct _XfceTitledDialogPrivate
 {
   GtkWidget *headerbar;
   GtkWidget *icon;
+  GtkWidget *action_area;
   gchar     *subtitle;
 };
 
@@ -106,7 +107,6 @@ xfce_titled_dialog_class_init (XfceTitledDialogClass *klass)
 
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->constructor = xfce_titled_dialog_constructor;
-  gobject_class->constructed = xfce_titled_dialog_constructed;
   gobject_class->get_property = xfce_titled_dialog_get_property;
   gobject_class->set_property = xfce_titled_dialog_set_property;
   gobject_class->finalize = xfce_titled_dialog_finalize;
@@ -153,18 +153,6 @@ xfce_titled_dialog_constructor (GType                  type,
 
 
 
-/*
- * Block GtkDialog's constructed function which only repacks all items
- * from the dialog's action area to its headerbar if use-header-bar is TRUE.
- */
-static void
-xfce_titled_dialog_constructed (GObject *object)
-{
-  G_OBJECT_CLASS (xfce_titled_dialog_parent_class)->constructed (object);
-}
-
-
-
 static void
 xfce_titled_dialog_init (XfceTitledDialog *titled_dialog)
 {
@@ -277,7 +265,7 @@ xfce_titled_dialog_update_icon (XfceTitledDialog *titled_dialog)
 }
 
 
-
+/* Borrowed from gtkdialog.c */
 static void
 response_data_free (gpointer data)
 {
@@ -300,7 +288,7 @@ get_response_data (GtkWidget *widget,
       g_object_set_data_full (G_OBJECT (widget),
                               I_("gtk-dialog-response-data"),
                               ad,
-      response_data_free);
+                              response_data_free);
     }
 
   return ad;
@@ -308,6 +296,49 @@ get_response_data (GtkWidget *widget,
 
 
 
+static void
+action_widget_activated (GtkWidget *widget, GtkDialog *dialog)
+{
+  gint response_id;
+
+  response_id = gtk_dialog_get_response_for_widget (dialog, widget);
+
+  gtk_dialog_response (dialog, response_id);
+}
+
+
+
+static void
+add_response_data (GtkDialog *dialog,
+                   GtkWidget *child,
+                   gint       response_id)
+{
+  ResponseData *ad;
+  guint signal_id;
+
+  ad = get_response_data (child, TRUE);
+  ad->response_id = response_id;
+
+  if (GTK_IS_BUTTON (child))
+    signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
+  else
+    signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
+
+  if (signal_id)
+    {
+      GClosure *closure;
+
+      closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
+                                       G_OBJECT (dialog));
+      g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
+    }
+  else
+    g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkDialog");
+}
+/* End: Borrowed from gtkdialog.c */
+
+
+
 /* Repack all the buttons that would normally end up in the headerbar to the action area */
 static void
 xfce_titled_dialog_repack_dialog (GtkWidget *action_area,
@@ -499,9 +530,115 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
 
 /**
+ * xfce_titled_dialog_create_action_area:
+ * @titled_dialog : a #XfceTitledDialog.
+ *
+ * This function creates a custom action area (of type #GtkButtonBox) and has to
+ * be used in combination with #xfce_titled_dialog_add_action_widget.
+ *
+ * When using the XfceTitledDialogClass directly to create dialogs this function is
+ * useful to keep action widgets out of the #GtkHeaderBar in which they would
+ * normally end up by calling #gtk_dialog_add_action_widget.
+ *
+ * Since: 4.16
+ *
+ **/
+void
+xfce_titled_dialog_create_action_area (XfceTitledDialog *titled_dialog)
+{
+  GtkWidget *dialog_vbox;
+
+  g_return_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog));
+
+  /* Create new buttonbox to act as custom action area for the dialog */
+  titled_dialog->priv->action_area = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+  gtk_button_box_set_layout (GTK_BUTTON_BOX (titled_dialog->priv->action_area), GTK_BUTTONBOX_END);
+  gtk_box_set_spacing (GTK_BOX (titled_dialog->priv->action_area), 6);
+
+  /* Pack the buttonbox in the dialog's main vbox */
+  dialog_vbox = gtk_bin_get_child (GTK_BIN (titled_dialog));
+  gtk_box_pack_end (GTK_BOX (dialog_vbox), titled_dialog->priv->action_area, FALSE, TRUE, 0);
+  gtk_box_reorder_child (GTK_BOX (dialog_vbox), titled_dialog->priv->action_area, 0);
+  gtk_widget_show (titled_dialog->priv->action_area);
+}
+
+
+
+/**
+ * xfce_titled_dialog_add_button:
+ * @titled_dialog : a #XfceTitledDialog.
+ * @button_text   : text of button.
+ * @response_id   : response ID for @child.
+ *
+ * This function is a replacement for #gtk_dialog_add_button and assumes that
+ * you have called #xfce_titled_dialog_create_action_area before.
+ *
+ * Buttons with #GTK_RESPONSE_HELP will be added to the secondary group of children
+ * (see #gtk_button_box_set_child_secondary for reference).
+ *
+ * Since: 4.16
+ *
+ **/
+GtkWidget *
+xfce_titled_dialog_add_button (XfceTitledDialog *titled_dialog,
+                               const gchar      *button_text,
+                               gint              response_id)
+{
+  GtkWidget *button;
+
+  g_return_val_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog), NULL);
+  g_return_val_if_fail (GTK_IS_WIDGET (titled_dialog->priv->action_area), NULL);
+  g_return_val_if_fail (button_text != NULL, NULL);
+
+  button = gtk_button_new_with_label (button_text);
+  gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
+
+  xfce_titled_dialog_add_action_widget (titled_dialog, button, response_id);
+
+  return button;
+}
+
+
+
+/**
+ * xfce_titled_dialog_add_action_widget:
+ * @titled_dialog : a #XfceTitledDialog.
+ * @child         : an activatable widget.
+ * @response_id   : response ID for @child.
+ *
+ * This function is a replacement for #gtk_dialog_add_action_widget and assumes that
+ * you have called #xfce_titled_dialog_create_action_area before.
+ *
+ * Children with #GTK_RESPONSE_HELP will be added to the secondary group of children
+ * (see #gtk_button_box_set_child_secondary for reference).
+ *
+ * Since: 4.16
+ *
+ **/
+void
+xfce_titled_dialog_add_action_widget (XfceTitledDialog *titled_dialog,
+                                      GtkWidget        *child,
+                                      gint              response_id)
+{
+  g_return_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog));
+  g_return_if_fail (GTK_IS_WIDGET (titled_dialog->priv->action_area));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+
+  add_response_data (GTK_DIALOG (titled_dialog), child, response_id);
+
+  gtk_box_pack_start (GTK_BOX (titled_dialog->priv->action_area), child, FALSE, TRUE, 0);
+  gtk_widget_show (child);
+
+  if (response_id == GTK_RESPONSE_HELP)
+    gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (titled_dialog->priv->action_area), child, TRUE);
+}
+
+
+
+/**
  * xfce_titled_dialog_set_default_response:
  * @titled_dialog : a #XfceTitledDialog.
- * @response_id: a response ID
+ * @response_id   : a response ID
  *
  * Sets the last widget in the dialog’s action area with the given @response_id
  * as the default widget for the dialog. Pressing “Enter” normally activates
diff --git a/libxfce4ui/xfce-titled-dialog.h b/libxfce4ui/xfce-titled-dialog.h
index 5f99e2d..4f436ca 100644
--- a/libxfce4ui/xfce-titled-dialog.h
+++ b/libxfce4ui/xfce-titled-dialog.h
@@ -81,6 +81,13 @@ GtkWidget            *xfce_titled_dialog_new_with_mixed_buttons (const gchar
                                                                  const gchar    *first_button_text,
                                                                  ...) G_GNUC_MALLOC;
 
+void                  xfce_titled_dialog_create_action_area   (XfceTitledDialog *titled_dialog);
+GtkWidget            *xfce_titled_dialog_add_button           (XfceTitledDialog *titled_dialog,
+                                                               const gchar      *button_text,
+                                                               gint              response_id);
+void                  xfce_titled_dialog_add_action_widget    (XfceTitledDialog *titled_dialog,
+                                                               GtkWidget        *child,
+                                                               gint              response_id);
 void                  xfce_titled_dialog_set_default_response (XfceTitledDialog *titled_dialog,
                                                                gint              response_id);
 const gchar          *xfce_titled_dialog_get_subtitle         (XfceTitledDialog *titled_dialog);

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


More information about the Xfce4-commits mailing list