[balsa/gtk4: 97/196] misc: Replace libbalsa_button_box_button()




commit 36b8ac83742f1f4c40429de5f92803e7516c4203
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Aug 29 17:01:07 2020 -0400

    misc: Replace libbalsa_button_box_button()
    
    with libbalsa_add_button_to_box(), to hide most of the GtkSizeGroup stuff.

 libbalsa/misc.c | 34 ++++++++++++++++++++++------------
 libbalsa/misc.h |  6 +++---
 2 files changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 170b9dd35..4cf5b0fd5 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -1254,16 +1254,14 @@ libbalsa_parser_options(void)
 }
 
 /*
- * libbalsa_button_box_button
+ * libbalsa_add_button_to_box
  *
- * Create a button widget that can be added to a GtkBox with the same
- * look as a regular button in a GtkButtonBox
+ * Create a button widget and add it to a GtkBox with the same
+ * look as a regular button in a GtkButtonBox; returns the button.
  *
- * markup:     mnemonic text for the button;
- * size_group: managed by the caller, to make buttons the same size;
- *             could be created as gtk_size_group_new(GTK_SIZE_GROUP_BOTH),
- *             to ensure common widths and heights;
- * align:      how to align the button in its allocated space.
+ * markup: mnemonic text for the button;
+ * box:    the box;
+ * align:  how to align the button in its allocated space.
  *
  * To replace a GtkButtonBox with the default GTK_BUTTONBOX_EDGE style,
  * align should be GTK_ALIGN_START for the first button, GTK_ALIGN_END
@@ -1273,7 +1271,7 @@ libbalsa_parser_options(void)
  * To replace a GtkButtonBox with style GTK_BUTTONBOX_EXPAND,
  * align should be GTK_ALIGN_FILL for all buttons.
  *
- * In the EDGE case with more than two buttons, and in the SPREAD case,
+ * In the EDGE case with more than three buttons, and in the SPREAD case,
  * the spacing is not identical to GtkButtonBox's.
  */
 
@@ -1281,14 +1279,23 @@ libbalsa_parser_options(void)
  * of a GtkButtonBox; may be a pixel or two too small: */
 #define LIBBALSA_LABEL_MARGIN 12
 
+#define LIBBALSA_SIZE_GROUP_KEY "libbalsa-size-group-key"
+
 GtkWidget *
-libbalsa_button_box_button(const gchar  *markup,
-                           GtkSizeGroup *size_group,
-                           GtkAlign      align)
+libbalsa_add_button_to_box(const gchar *markup,
+                           GtkWidget   *box,
+                           GtkAlign     align)
 {
+    GtkSizeGroup *size_group;
     GtkWidget *label;
     GtkWidget *button;
 
+    size_group = g_object_get_data(G_OBJECT(box), LIBBALSA_SIZE_GROUP_KEY);
+    if (size_group == NULL) {
+        size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
+        g_object_set_data(G_OBJECT(box), LIBBALSA_SIZE_GROUP_KEY, size_group);
+    }
+
     label = gtk_label_new(NULL);
     gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), markup);
     gtk_widget_set_margin_start(label, LIBBALSA_LABEL_MARGIN);
@@ -1300,6 +1307,9 @@ libbalsa_button_box_button(const gchar  *markup,
     gtk_container_add(GTK_CONTAINER(button), label);
     gtk_widget_set_hexpand(button, TRUE);
     gtk_widget_set_halign(button, align);
+    gtk_widget_show(button);
+
+    gtk_container_add(GTK_CONTAINER(box), button);
 
     return button;
 }
diff --git a/libbalsa/misc.h b/libbalsa/misc.h
index e8d3e6491..fd69e9706 100644
--- a/libbalsa/misc.h
+++ b/libbalsa/misc.h
@@ -163,9 +163,9 @@ gchar *libbalsa_font_string_to_css(const gchar * font_string, const gchar * name
 void libbalsa_parser_options_init(void);
 GMimeParserOptions *libbalsa_parser_options(void);
 
-GtkWidget * libbalsa_button_box_button(const gchar  *markup,
-                                       GtkSizeGroup *size_group,
-                                       GtkAlign      align);
+GtkWidget * libbalsa_add_button_to_box(const gchar *markup,
+                                       GtkWidget   *box,
+                                       GtkAlign     align);
 
 
 #endif                         /* __LIBBALSA_MISC_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]