]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkexpander.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtkexpander.c
index 5e38ec980ecd9f2bb029c0c0eb5cda6f73372e32..2362a2d3dfcb69e7443cf589e2ee4873ddcdd7c4 100644 (file)
  *     Mark McLoughlin <mark@skynet.ie>
  */
 
-#include <config.h>
-
+#include "config.h"
+#include <string.h>
 #include "gtkexpander.h"
 
 #include "gtklabel.h"
+#include "gtkbuildable.h"
 #include "gtkcontainer.h"
 #include "gtkmarshalers.h"
 #include "gtkmain.h"
@@ -126,7 +127,16 @@ static void gtk_expander_activate (GtkExpander *expander);
 static void get_expander_bounds (GtkExpander  *expander,
                                 GdkRectangle *rect);
 
-G_DEFINE_TYPE (GtkExpander, gtk_expander, GTK_TYPE_BIN)
+/* GtkBuildable */
+static void gtk_expander_buildable_init           (GtkBuildableIface *iface);
+static void gtk_expander_buildable_add_child      (GtkBuildable *buildable,
+                                                  GtkBuilder   *builder,
+                                                  GObject      *child,
+                                                  const gchar  *type);
+
+G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_BIN,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_expander_buildable_init))
 
 static void
 gtk_expander_class_init (GtkExpanderClass *klass)
@@ -277,6 +287,26 @@ gtk_expander_init (GtkExpander *expander)
   gtk_drag_dest_set_track_motion (GTK_WIDGET (expander), TRUE);
 }
 
+static void
+gtk_expander_buildable_add_child (GtkBuildable  *buildable,
+                                 GtkBuilder    *builder,
+                                 GObject       *child,
+                                 const gchar   *type)
+{
+  if (!type)
+    gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+  else if (strcmp (type, "label") == 0)
+    gtk_expander_set_label_widget (GTK_EXPANDER (buildable), GTK_WIDGET (child));
+  else
+    GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_EXPANDER (buildable), type);
+}
+
+static void
+gtk_expander_buildable_init (GtkBuildableIface *iface)
+{
+  iface->add_child = gtk_expander_buildable_add_child;
+}
+
 static void
 gtk_expander_set_property (GObject      *object,
                           guint         prop_id,
@@ -379,7 +409,7 @@ gtk_expander_realize (GtkWidget *widget)
 
   get_expander_bounds (GTK_EXPANDER (widget), &expander_rect);
   
-  if (priv->label_widget && GTK_WIDGET_VISIBLE (priv->label_widget))
+  if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
     {
       GtkRequisition label_requisition;
 
@@ -411,7 +441,6 @@ gtk_expander_realize (GtkWidget *widget)
   gdk_window_set_user_data (priv->event_window, widget);
 
   widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
 }
 
 static void
@@ -461,7 +490,7 @@ gtk_expander_size_request (GtkWidget      *widget,
                       2 * focus_width + 2 * focus_pad;
   requisition->height = interior_focus ? (2 * focus_width + 2 * focus_pad) : 0;
 
-  if (priv->label_widget && GTK_WIDGET_VISIBLE (priv->label_widget))
+  if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
     {
       GtkRequisition label_requisition;
 
@@ -528,7 +557,7 @@ get_expander_bounds (GtkExpander  *expander,
     rect->x += widget->allocation.width - 2 * border_width -
                expander_spacing - expander_size;
 
-  if (priv->label_widget && GTK_WIDGET_VISIBLE (priv->label_widget))
+  if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
     {
       GtkAllocation label_allocation;
 
@@ -597,7 +626,7 @@ gtk_expander_size_allocate (GtkWidget     *widget,
 
   widget->allocation = *allocation;
 
-  if (priv->label_widget && GTK_WIDGET_VISIBLE (priv->label_widget))
+  if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
     {
       GtkAllocation label_allocation;
       GtkRequisition label_requisition;
@@ -736,7 +765,7 @@ gtk_expander_paint_prelight (GtkExpander *expander)
   area.y = widget->allocation.y + container->border_width;
   area.width = widget->allocation.width - (2 * container->border_width);
 
-  if (priv->label_widget && GTK_WIDGET_VISIBLE (priv->label_widget))
+  if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
     area.height = priv->label_widget->allocation.height;
   else
     area.height = 0;
@@ -818,7 +847,7 @@ gtk_expander_paint_focus (GtkExpander  *expander,
 
   if (priv->label_widget)
     {
-      if (GTK_WIDGET_VISIBLE (priv->label_widget))
+      if (gtk_widget_get_visible (priv->label_widget))
        {
          GtkAllocation label_allocation = priv->label_widget->allocation;
 
@@ -868,13 +897,13 @@ static gboolean
 gtk_expander_expose (GtkWidget      *widget,
                     GdkEventExpose *event)
 {
-  if (GTK_WIDGET_DRAWABLE (widget))
+  if (gtk_widget_is_drawable (widget))
     {
       GtkExpander *expander = GTK_EXPANDER (widget);
 
       gtk_expander_paint (expander);
 
-      if (GTK_WIDGET_HAS_FOCUS (expander))
+      if (gtk_widget_has_focus (widget))
        gtk_expander_paint_focus (expander, &event->area);
 
       GTK_WIDGET_CLASS (gtk_expander_parent_class)->expose_event (widget, event);
@@ -926,7 +955,7 @@ static void
 gtk_expander_state_changed (GtkWidget    *widget,
                            GtkStateType  previous_state)
 {
-  if (!GTK_WIDGET_IS_SENSITIVE (widget))
+  if (!gtk_widget_is_sensitive (widget))
     GTK_EXPANDER (widget)->priv->button_down = FALSE;
 }
 
@@ -1259,9 +1288,9 @@ gtk_expander_new (const gchar *label)
 
 /**
  * gtk_expander_new_with_mnemonic:
- * @label: the text of the label with an underscore in front of the
+ * @label: (allow-none): the text of the label with an underscore in front of the
  *         mnemonic character
- * 
+ *
  * Creates a new expander using @label as the text of the label.
  * If characters in @label are preceded by an underscore, they are underlined.
  * If you need a literal underscore character in a label, use '__' (two 
@@ -1466,7 +1495,7 @@ gtk_expander_get_spacing (GtkExpander *expander)
 /**
  * gtk_expander_set_label:
  * @expander: a #GtkExpander
- * @label: a string
+ * @label: (allow-none): a string
  *
  * Sets the text of the label of the expander to @label.
  *
@@ -1503,11 +1532,17 @@ gtk_expander_set_label (GtkExpander *expander,
  * gtk_expander_get_label:
  * @expander: a #GtkExpander
  *
- * Fetches the text from the label of the expander, as set by
- * gtk_expander_set_label(). If the label text has not
- * been set the return value will be %NULL. This will be the
- * case if you create an empty button with gtk_button_new() to
- * use as a container.
+ * Fetches the text from a label widget including any embedded
+ * underlines indicating mnemonics and Pango markup, as set by
+ * gtk_expander_set_label(). If the label text has not been set the
+ * return value will be %NULL. This will be the case if you create an
+ * empty button with gtk_button_new() to use as a container.
+ *
+ * Note that this function behaved differently in versions prior to
+ * 2.14 and used to return the label text stripped of embedded
+ * underlines indicating mnemonics and Pango markup. This problem can
+ * be avoided by fetching the label text directly from the label
+ * widget.
  *
  * Return value: The text of the label widget. This string is owned
  * by the widget and must not be modified or freed.
@@ -1523,8 +1558,8 @@ gtk_expander_get_label (GtkExpander *expander)
 
   priv = expander->priv;
 
-  if (priv->label_widget && GTK_IS_LABEL (priv->label_widget))
-    return gtk_label_get_text (GTK_LABEL (priv->label_widget));
+  if (GTK_IS_LABEL (priv->label_widget))
+    return gtk_label_get_label (GTK_LABEL (priv->label_widget));
   else
     return NULL;
 }
@@ -1555,7 +1590,7 @@ gtk_expander_set_use_underline (GtkExpander *expander,
     {
       priv->use_underline = use_underline;
 
-      if (priv->label_widget && GTK_IS_LABEL (priv->label_widget))
+      if (GTK_IS_LABEL (priv->label_widget))
        gtk_label_set_use_underline (GTK_LABEL (priv->label_widget), use_underline);
 
       g_object_notify (G_OBJECT (expander), "use-underline");
@@ -1609,7 +1644,7 @@ gtk_expander_set_use_markup (GtkExpander *expander,
     {
       priv->use_markup = use_markup;
 
-      if (priv->label_widget && GTK_IS_LABEL (priv->label_widget))
+      if (GTK_IS_LABEL (priv->label_widget))
        gtk_label_set_use_markup (GTK_LABEL (priv->label_widget), use_markup);
 
       g_object_notify (G_OBJECT (expander), "use-markup");
@@ -1639,7 +1674,7 @@ gtk_expander_get_use_markup (GtkExpander *expander)
 /**
  * gtk_expander_set_label_widget:
  * @expander: a #GtkExpander
- * @label_widget: the new label widget
+ * @label_widget: (allow-none): the new label widget
  *
  * Set the label widget for the expander. This is the widget
  * that will appear embedded alongside the expander arrow.
@@ -1651,6 +1686,7 @@ gtk_expander_set_label_widget (GtkExpander *expander,
                               GtkWidget   *label_widget)
 {
   GtkExpanderPrivate *priv;
+  GtkWidget          *widget;
 
   g_return_if_fail (GTK_IS_EXPANDER (expander));
   g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
@@ -1668,19 +1704,20 @@ gtk_expander_set_label_widget (GtkExpander *expander,
     }
 
   priv->label_widget = label_widget;
+  widget = GTK_WIDGET (expander);
 
   if (label_widget)
     {
       priv->label_widget = label_widget;
 
-      gtk_widget_set_parent (label_widget, GTK_WIDGET (expander));
+      gtk_widget_set_parent (label_widget, widget);
 
       if (priv->prelight)
        gtk_widget_set_state (label_widget, GTK_STATE_PRELIGHT);
     }
 
-  if (GTK_WIDGET_VISIBLE (expander))
-    gtk_widget_queue_resize (GTK_WIDGET (expander));
+  if (gtk_widget_get_visible (widget))
+    gtk_widget_queue_resize (widget);
 
   g_object_freeze_notify (G_OBJECT (expander));
   g_object_notify (G_OBJECT (expander), "label-widget");