]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkstatusbar.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkstatusbar.c
index 704b3b6940837818c33be04b87f9711c7173537a..47350376ad2cbe885e0c107f983abb09f326339e 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  */
 
 #include "config.h"
+
+#include "gtkstatusbar.h"
+
+#include "gtkboxprivate.h"
 #include "gtkframe.h"
 #include "gtklabel.h"
 #include "gtkmarshalers.h"
-#include "gtkstatusbar.h"
 #include "gtkwindow.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 #include "gtkbuildable.h"
+#include "gtkorientable.h"
+#include "gtktypebuiltins.h"
+#include "a11y/gtkstatusbaraccessible.h"
 
 /**
  * SECTION:gtkstatusbar
@@ -106,6 +110,7 @@ static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *builda
 static void     gtk_statusbar_update            (GtkStatusbar      *statusbar,
                                                 guint              context_id,
                                                 const gchar       *text);
+static void     gtk_statusbar_realize           (GtkWidget         *widget);
 static void     gtk_statusbar_destroy           (GtkWidget         *widget);
 static void     gtk_statusbar_size_allocate     (GtkWidget         *widget,
                                                  GtkAllocation     *allocation);
@@ -115,19 +120,18 @@ static void     gtk_statusbar_hierarchy_changed (GtkWidget         *widget,
 
 static guint              statusbar_signals[SIGNAL_LAST] = { 0 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX,
+G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_BOX,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                 gtk_statusbar_buildable_interface_init));
 
 static void
 gtk_statusbar_class_init (GtkStatusbarClass *class)
 {
-  GObjectClass *gobject_class;
   GtkWidgetClass *widget_class;
 
-  gobject_class = (GObjectClass *) class;
   widget_class = (GtkWidgetClass *) class;
 
+  widget_class->realize = gtk_statusbar_realize;
   widget_class->destroy = gtk_statusbar_destroy;
   widget_class->size_allocate = gtk_statusbar_size_allocate;
   widget_class->hierarchy_changed = gtk_statusbar_hierarchy_changed;
@@ -135,12 +139,12 @@ gtk_statusbar_class_init (GtkStatusbarClass *class)
   class->text_pushed = gtk_statusbar_update;
   class->text_popped = gtk_statusbar_update;
 
-  /** 
+  /**
    * GtkStatusbar::text-pushed:
-   * @statusbar: the object which received the signal.
-   * @context_id: the context id of the relevant message/statusbar.
-   * @text: the message that was pushed.
-   * 
+   * @statusbar: the object which received the signal
+   * @context_id: the context id of the relevant message/statusbar
+   * @text: the message that was pushed
+   *
    * Is emitted whenever a new message gets pushed onto a statusbar's stack.
    */
   statusbar_signals[SIGNAL_TEXT_PUSHED] =
@@ -156,9 +160,9 @@ gtk_statusbar_class_init (GtkStatusbarClass *class)
 
   /**
    * GtkStatusbar::text-popped:
-   * @statusbar: the object which received the signal.
-   * @context_id: the context id of the relevant message/statusbar.
-   * @text: the message that was just popped.
+   * @statusbar: the object which received the signal
+   * @context_id: the context id of the relevant message/statusbar
+   * @text: the message that was just popped
    *
    * Is emitted whenever a new message is popped off a statusbar's stack.
    */
@@ -182,6 +186,8 @@ gtk_statusbar_class_init (GtkStatusbarClass *class)
                                                               GTK_PARAM_READABLE));
 
    g_type_class_add_private (class, sizeof (GtkStatusbarPrivate));
+
+   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_STATUSBAR_ACCESSIBLE);
 }
 
 static void
@@ -209,13 +215,14 @@ gtk_statusbar_init (GtkStatusbar *statusbar)
   gtk_box_pack_start (box, priv->frame, TRUE, TRUE, 0);
   gtk_widget_show (priv->frame);
 
-  message_area = gtk_hbox_new (FALSE, 4);
+  message_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
   gtk_container_add (GTK_CONTAINER (priv->frame), message_area);
   gtk_widget_show (message_area);
 
   priv->label = gtk_label_new ("");
   gtk_label_set_single_line_mode (GTK_LABEL (priv->label), TRUE);
-  gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
+  gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
+  gtk_widget_set_valign (priv->label, GTK_ALIGN_CENTER);
   gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
   gtk_container_add (GTK_CONTAINER (message_area), priv->label);
   gtk_widget_show (priv->label);
@@ -322,6 +329,28 @@ gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
   return id;
 }
 
+static GtkStatusbarMsg *
+gtk_statusbar_msg_create (GtkStatusbar *statusbar,
+                         guint         context_id,
+                         const gchar  *text)
+{
+  GtkStatusbarMsg *msg;
+
+  msg = g_slice_new (GtkStatusbarMsg);
+  msg->text = g_strdup (text);
+  msg->context_id = context_id;
+  msg->message_id = statusbar->priv->seq_message_id++;
+
+  return msg;
+}
+
+static void
+gtk_statusbar_msg_free (GtkStatusbarMsg *msg)
+{
+  g_free (msg->text);
+  g_slice_free (GtkStatusbarMsg, msg);
+}
+
 /**
  * gtk_statusbar_push:
  * @statusbar: a #GtkStatusbar
@@ -347,11 +376,7 @@ gtk_statusbar_push (GtkStatusbar *statusbar,
 
   priv = statusbar->priv;
 
-  msg = g_slice_new (GtkStatusbarMsg);
-  msg->text = g_strdup (text);
-  msg->context_id = context_id;
-  msg->message_id = priv->seq_message_id++;
-
+  msg = gtk_statusbar_msg_create (statusbar, context_id, text);
   priv->messages = g_slist_prepend (priv->messages, msg);
 
   g_signal_emit (statusbar,
@@ -365,10 +390,10 @@ gtk_statusbar_push (GtkStatusbar *statusbar,
 
 /**
  * gtk_statusbar_pop:
- * @statusbar: a #GtkStatusBar
+ * @statusbar: a #GtkStatusbar
  * @context_id: a context identifier
  * 
- * Removes the first message in the #GtkStatusBar's stack
+ * Removes the first message in the #GtkStatusbar's stack
  * with the given context id. 
  *
  * Note that this may not change the displayed message, if 
@@ -396,10 +421,8 @@ gtk_statusbar_pop (GtkStatusbar *statusbar,
 
          if (msg->context_id == context_id)
            {
-             priv->messages = g_slist_remove_link (priv->messages,
-                                                        list);
-             g_free (msg->text);
-              g_slice_free (GtkStatusbarMsg, msg);
+             priv->messages = g_slist_remove_link (priv->messages, list);
+             gtk_statusbar_msg_free (msg);
              g_slist_free_1 (list);
              break;
            }
@@ -417,7 +440,7 @@ gtk_statusbar_pop (GtkStatusbar *statusbar,
 
 /**
  * gtk_statusbar_remove:
- * @statusbar: a #GtkStatusBar
+ * @statusbar: a #GtkStatusbar
  * @context_id: a context identifier
  * @message_id: a message identifier, as returned by gtk_statusbar_push()
  *
@@ -458,8 +481,7 @@ gtk_statusbar_remove (GtkStatusbar *statusbar,
              msg->message_id == message_id)
            {
              priv->messages = g_slist_remove_link (priv->messages, list);
-             g_free (msg->text);
-              g_slice_free (GtkStatusbarMsg, msg);
+             gtk_statusbar_msg_free (msg);
              g_slist_free_1 (list);
              
              break;
@@ -470,7 +492,7 @@ gtk_statusbar_remove (GtkStatusbar *statusbar,
 
 /**
  * gtk_statusbar_remove_all:
- * @statusbar: a #GtkStatusBar
+ * @statusbar: a #GtkStatusbar
  * @context_id: a context identifier
  *
  * Forces the removal of all messages from a statusbar's
@@ -520,14 +542,16 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
           else
             prev->next = list->next;
 
-          g_free (msg->text);
-          g_slice_free (GtkStatusbarMsg, msg);
+          gtk_statusbar_msg_free (msg);
           g_slist_free_1 (list);
 
           if (prev == NULL)
             prev = priv->messages;
 
-          list = prev->next;
+          if (prev)
+            list = prev->next;
+          else
+            list = NULL;
         }
       else
         {
@@ -539,7 +563,7 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
 
 /**
  * gtk_statusbar_get_message_area:
- * @statusbar: a #GtkStatusBar
+ * @statusbar: a #GtkStatusbar
  *
  * Retrieves the box containing the label widget.
  *
@@ -564,22 +588,11 @@ gtk_statusbar_destroy (GtkWidget *widget)
 {
   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
   GtkStatusbarPrivate *priv = statusbar->priv;
-  GSList *list;
 
-  for (list = priv->messages; list; list = list->next)
-    {
-      GtkStatusbarMsg *msg;
-
-      msg = list->data;
-      g_free (msg->text);
-      g_slice_free (GtkStatusbarMsg, msg);
-    }
-  g_slist_free (priv->messages);
+  g_slist_free_full (priv->messages, (GDestroyNotify) gtk_statusbar_msg_free);
   priv->messages = NULL;
 
-  for (list = priv->keys; list; list = list->next)
-    g_free (list->data);
-  g_slist_free (priv->keys);
+  g_slist_free_full (priv->keys, g_free);
   priv->keys = NULL;
 
   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->destroy (widget);
@@ -646,17 +659,12 @@ gtk_statusbar_size_allocate (GtkWidget     *widget,
   GdkRectangle translated_rect;
 
   window = gtk_widget_get_toplevel (widget);
+
   if (GTK_IS_WINDOW (window) &&
       gtk_window_resize_grip_is_visible (GTK_WINDOW (window)))
     {
       gtk_window_get_resize_grip_area (GTK_WINDOW (window), &rect);
-
-      if (gtk_widget_translate_coordinates (gtk_widget_get_parent (widget),
-                                            window,
-                                            allocation->x,
-                                            allocation->y,
-                                            &x,
-                                            &y))
+      if (gtk_widget_translate_coordinates (widget, window, 0, 0, &x, &y))
         {
           translated_rect.x = x;
           translated_rect.y = y;
@@ -733,9 +741,9 @@ resize_grip_visible_changed (GObject    *object,
   GtkStatusbar *statusbar = GTK_STATUSBAR (user_data);
   GtkStatusbarPrivate *priv = statusbar->priv;
 
-  gtk_widget_queue_resize (GTK_WIDGET (statusbar));
   gtk_widget_queue_resize (priv->label);
   gtk_widget_queue_resize (priv->frame);
+  gtk_widget_queue_resize (GTK_WIDGET (statusbar));
 }
 
 static void
@@ -752,4 +760,14 @@ gtk_statusbar_hierarchy_changed (GtkWidget *widget,
   if (GTK_IS_WINDOW (window))
     g_signal_connect (window, "notify::resize-grip-visible",
                       G_CALLBACK (resize_grip_visible_changed), widget);
+
+  resize_grip_visible_changed (NULL, NULL, widget);
+}
+
+static void
+gtk_statusbar_realize (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
+
+  resize_grip_visible_changed (NULL, NULL, widget);
 }