[gtk+] GtkAssistant: Add a way to have pages without padding



commit c3a0880cd6d839efdeb4a52ca64d27e2bb0aaff0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 14 21:29:09 2015 -0400

    GtkAssistant: Add a way to have pages without padding
    
    This can be useful when embedding complex widgets like
    a file chooser as a page.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=750631

 docs/reference/gtk/gtk3-sections.txt |    2 +
 gtk/gtkassistant.c                   |   86 +++++++++++++++++++++++++++++++++-
 gtk/gtkassistant.h                   |    8 +++
 3 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 6491778..a62c7d0 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -381,6 +381,8 @@ gtk_assistant_set_page_side_image
 gtk_assistant_get_page_side_image
 gtk_assistant_set_page_complete
 gtk_assistant_get_page_complete
+gtk_assistant_set_page_has_padding
+gtk_assistant_get_page_has_padding
 gtk_assistant_add_action_widget
 gtk_assistant_remove_action_widget
 gtk_assistant_update_buttons_state
diff --git a/gtk/gtkassistant.c b/gtk/gtkassistant.c
index 21746a9..3d98963 100644
--- a/gtk/gtkassistant.c
+++ b/gtk/gtkassistant.c
@@ -84,6 +84,7 @@ struct _GtkAssistantPage
   GtkAssistantPageType type;
   guint      complete     : 1;
   guint      complete_set : 1;
+  guint      has_padding  : 1;
 
   gchar *title;
 
@@ -196,7 +197,8 @@ enum
   CHILD_PROP_PAGE_TITLE,
   CHILD_PROP_PAGE_HEADER_IMAGE,
   CHILD_PROP_PAGE_SIDEBAR_IMAGE,
-  CHILD_PROP_PAGE_COMPLETE
+  CHILD_PROP_PAGE_COMPLETE,
+  CHILD_PROP_HAS_PADDING
 };
 
 enum
@@ -622,6 +624,10 @@ gtk_assistant_class_init (GtkAssistantClass *class)
                                                                     FALSE,
                                                                     G_PARAM_READWRITE));
 
+  gtk_container_class_install_child_property (container_class, CHILD_PROP_HAS_PADDING,
+      g_param_spec_boolean ("has-padding", P_("Has padding"), P_("Whether the assistant adds padding around 
the page"),
+                            TRUE, G_PARAM_READWRITE));
+
   /* Bind class to template
    */
   gtk_widget_class_set_template_from_resource (widget_class,
@@ -1245,6 +1251,10 @@ gtk_assistant_set_child_property (GtkContainer *container,
       gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
                                        g_value_get_boolean (value));
       break;
+    case CHILD_PROP_HAS_PADDING:
+      gtk_assistant_set_page_has_padding (GTK_ASSISTANT (container), child,
+                                          g_value_get_boolean (value));
+      break;
     default:
       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
       break;
@@ -1286,6 +1296,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
       g_value_set_boolean (value,
                            gtk_assistant_get_page_complete (assistant, child));
       break;
+    case CHILD_PROP_HAS_PADDING:
+      g_value_set_boolean (value,
+                           gtk_assistant_get_page_has_padding (assistant, child));
+      break;
     default:
       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
       break;
@@ -1766,6 +1780,7 @@ gtk_assistant_insert_page (GtkAssistant *assistant,
   page_info = g_slice_new0 (GtkAssistantPage);
   page_info->page  = page;
   page_info->regular_title = gtk_label_new (NULL);
+  page_info->has_padding = TRUE;
   gtk_widget_set_no_show_all (page_info->regular_title, TRUE);
   page_info->current_title = gtk_label_new (NULL);
   gtk_widget_set_no_show_all (page_info->current_title, TRUE);
@@ -2370,6 +2385,75 @@ gtk_assistant_get_page_complete (GtkAssistant *assistant,
 }
 
 /**
+ * gtk_assistant_set_page_has_padding:
+ * @assistant: a #GtkAssistant
+ * @page: a page of @assistant
+ * @has_padding: whether this page has padding
+ *
+ * Sets whether the assistant is adding padding around
+ * the page.
+ *
+ * Since: 3.18
+ */
+void
+gtk_assistant_set_page_has_padding (GtkAssistant *assistant,
+                                    GtkWidget    *page,
+                                    gboolean      has_padding)
+{
+  GtkAssistantPage *page_info;
+  GList *child;
+
+  g_return_if_fail (GTK_IS_ASSISTANT (assistant));
+  g_return_if_fail (GTK_IS_WIDGET (page));
+
+  child = find_page (assistant, page);
+
+  g_return_if_fail (child != NULL);
+
+  page_info = (GtkAssistantPage*) child->data;
+
+  if (page_info->has_padding != has_padding)
+    {
+      page_info->has_padding = has_padding;
+
+      g_object_set (gtk_widget_get_parent (page),
+                    "margin", has_padding ? 12 : 0,
+                    NULL);
+
+      gtk_container_child_notify (GTK_CONTAINER (assistant), page, "has-padding");
+    }
+}
+
+/**
+ * gtk_assistant_get_page_has_padding:
+ * @assistant: a #GtkAssistant
+ * @page: a page of @assistant
+ *
+ * Gets whether page has padding.
+ *
+ * Returns: %TRUE if @page has padding
+ * Since: 3.18
+ */
+gboolean
+gtk_assistant_get_page_has_padding (GtkAssistant *assistant,
+                                    GtkWidget    *page)
+{
+  GtkAssistantPage *page_info;
+  GList *child;
+
+  g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
+  g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
+
+  child = find_page (assistant, page);
+
+  g_return_val_if_fail (child != NULL, TRUE);
+
+  page_info = (GtkAssistantPage*) child->data;
+
+  return page_info->has_padding;
+}
+
+/**
  * gtk_assistant_update_buttons_state:
  * @assistant: a #GtkAssistant
  *
diff --git a/gtk/gtkassistant.h b/gtk/gtkassistant.h
index a5a5459..06dfbf8 100644
--- a/gtk/gtkassistant.h
+++ b/gtk/gtkassistant.h
@@ -217,6 +217,14 @@ void                  gtk_assistant_update_buttons_state  (GtkAssistant *assista
 GDK_AVAILABLE_IN_ALL
 void                  gtk_assistant_commit                (GtkAssistant *assistant);
 
+GDK_AVAILABLE_IN_3_18
+void                  gtk_assistant_set_page_has_padding  (GtkAssistant *assistant,
+                                                           GtkWidget    *page,
+                                                           gboolean      has_padding);
+GDK_AVAILABLE_IN_3_18
+gboolean              gtk_assistant_get_page_has_padding  (GtkAssistant *assistant,
+                                                           GtkWidget    *page);
+
 G_END_DECLS
 
 #endif /* __GTK_ASSISTANT_H__ */


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