]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkbutton.c
fontchooser: Only create font descriptions on demand
[~andy/gtk] / gtk / gtkbutton.c
index 3ae3e998cb15b661ad6956b6bf1cfeb8e11d1e88..d48eea49fc7459da8038acd08da7de06aead2170 100644 (file)
@@ -49,8 +49,7 @@
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkimage.h"
-#include "gtkhbox.h"
-#include "gtkvbox.h"
+#include "gtkbox.h"
 #include "gtkstock.h"
 #include "gtkiconfactory.h"
 #include "gtkactivatable.h"
@@ -58,6 +57,7 @@
 #include "gtktypebuiltins.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
+#include "a11y/gtkbuttonaccessible.h"
 
 
 static const GtkBorder default_default_border = { 1, 1, 1, 1 };
@@ -266,7 +266,7 @@ gtk_button_class_init (GtkButtonClass *klass)
    * GtkButton:xalign:
    *
    * If the child of the button is a #GtkMisc or #GtkAlignment, this property 
-   * can be used to control it's horizontal alignment. 0.0 is left aligned, 
+   * can be used to control its horizontal alignment. 0.0 is left aligned, 
    * 1.0 is right aligned.
    *
    * Since: 2.4
@@ -285,7 +285,7 @@ gtk_button_class_init (GtkButtonClass *klass)
    * GtkButton:yalign:
    *
    * If the child of the button is a #GtkMisc or #GtkAlignment, this property 
-   * can be used to control it's vertical alignment. 0.0 is top aligned, 
+   * can be used to control its vertical alignment. 0.0 is top aligned, 
    * 1.0 is bottom aligned.
    *
    * Since: 2.4
@@ -528,6 +528,8 @@ gtk_button_class_init (GtkButtonClass *klass)
                                                             GTK_PARAM_READABLE));
 
   g_type_class_add_private (gobject_class, sizeof (GtkButtonPrivate));
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_BUTTON_ACCESSIBLE);
 }
 
 static void
@@ -1398,12 +1400,15 @@ gtk_button_get_props (GtkButton *button,
                      GtkBorder *default_border,
                      GtkBorder *default_outside_border,
                       GtkBorder *inner_border,
+                      GtkBorder *padding,
                      gboolean  *interior_focus)
 {
   GtkStyleContext *context;
+  GtkStateFlags state;
   GtkBorder *tmp_border;
 
   context = gtk_widget_get_style_context (GTK_WIDGET (button));
+  state = gtk_style_context_get_state (context);
 
   if (default_border)
     {
@@ -1456,6 +1461,9 @@ gtk_button_get_props (GtkButton *button,
                                    "interior-focus", interior_focus,
                                    NULL);
     }
+
+  if (padding)
+    gtk_style_context_get_padding (context, state, padding);
 }
 
 static void
@@ -1466,27 +1474,21 @@ gtk_button_size_allocate (GtkWidget     *widget,
   GtkButtonPrivate *priv = button->priv;
   GtkAllocation child_allocation;
   GtkStyleContext *context;
-  GtkStateFlags state;
   GtkWidget *child;
   GtkBorder default_border;
   GtkBorder inner_border;
-  GtkBorder *border;
+  GtkBorder padding;
   gint focus_width;
   gint focus_pad;
 
   context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
 
-  gtk_button_get_props (button, &default_border, NULL, &inner_border, NULL);
+  gtk_button_get_props (button, &default_border, NULL, &inner_border, &padding, NULL);
   gtk_style_context_get_style (context,
                               "focus-line-width", &focus_width,
                               "focus-padding", &focus_pad,
                               NULL);
 
-  gtk_style_context_get (context, state,
-                         "border-width", &border,
-                         NULL);
-
   gtk_widget_set_allocation (widget, allocation);
 
   if (gtk_widget_get_realized (widget))
@@ -1499,18 +1501,18 @@ gtk_button_size_allocate (GtkWidget     *widget,
   child = gtk_bin_get_child (GTK_BIN (button));
   if (child && gtk_widget_get_visible (child))
     {
-      child_allocation.x = allocation->x + inner_border.left + border->left;
-      child_allocation.y = allocation->y + inner_border.top + border->top;
+      child_allocation.x = allocation->x + inner_border.left + padding.left;
+      child_allocation.y = allocation->y + inner_border.top + padding.top;
 
       child_allocation.width =
        allocation->width -
-       (border->left + border->right) -
+        (padding.left + padding.right) -
        inner_border.left -
        inner_border.right;
 
       child_allocation.height = 
        allocation->height -
-       (border->top + border->bottom) -
+        (padding.top + padding.bottom) -
        inner_border.top -
        inner_border.bottom;
 
@@ -1548,8 +1550,6 @@ gtk_button_size_allocate (GtkWidget     *widget,
 
       gtk_widget_size_allocate (child, &child_allocation);
     }
-
-  gtk_border_free (border);
 }
 
 void
@@ -1569,6 +1569,7 @@ _gtk_button_paint (GtkButton          *button,
   gint focus_pad;
   GtkAllocation allocation;
   GtkStyleContext *context;
+  gboolean draw_focus;
 
   widget = GTK_WIDGET (button);
   context = gtk_widget_get_style_context (widget);
@@ -1576,7 +1577,7 @@ _gtk_button_paint (GtkButton          *button,
   gtk_style_context_save (context);
   gtk_style_context_set_state (context, state);
 
-  gtk_button_get_props (button, &default_border, &default_outside_border, NULL, &interior_focus);
+  gtk_button_get_props (button, &default_border, &default_outside_border, NULL, NULL, &interior_focus);
   gtk_style_context_get_style (context,
                                "focus-line-width", &focus_width,
                                "focus-padding", &focus_pad,
@@ -1604,8 +1605,11 @@ _gtk_button_paint (GtkButton          *button,
       width -= default_outside_border.left + default_outside_border.right;
       height -= default_outside_border.top + default_outside_border.bottom;
     }
-   
-  if (!interior_focus && gtk_widget_has_focus (widget))
+
+  draw_focus = gtk_widget_has_visible_focus (widget);
+
+
+  if (!interior_focus && draw_focus)
     {
       x += focus_width + focus_pad;
       y += focus_width + focus_pad;
@@ -1622,29 +1626,26 @@ _gtk_button_paint (GtkButton          *button,
                        x, y, width, height);
     }
 
-  if (gtk_widget_has_focus (widget))
+  if (draw_focus)
     {
       gint child_displacement_x;
       gint child_displacement_y;
       gboolean displace_focus;
-      GtkBorder *border;
+      GtkBorder border;
 
       gtk_style_context_get_style (context,
                                    "child-displacement-y", &child_displacement_y,
                                    "child-displacement-x", &child_displacement_x,
                                    "displace-focus", &displace_focus,
                                    NULL);
-
-      gtk_style_context_get (context, state,
-                             "border-width", &border,
-                             NULL);
+      gtk_style_context_get_border (context, state, &border);
 
       if (interior_focus)
         {
-          x += border->left + focus_pad;
-          y += border->top + focus_pad;
-          width -= (2 * focus_pad) + border->left + border->right;
-          height -=  (2 * focus_pad) + border->top + border->bottom;
+          x += border.left + focus_pad;
+          y += border.top + focus_pad;
+          width -= (2 * focus_pad) + border.left + border.right;
+          height -=  (2 * focus_pad) + border.top + border.bottom;
         }
       else
         {
@@ -1660,10 +1661,7 @@ _gtk_button_paint (GtkButton          *button,
           y += child_displacement_y;
         }
 
-      gtk_render_focus (context, cr,
-                       x, y, width, height);
-
-      gtk_border_free (border);
+      gtk_render_focus (context, cr, x, y, width, height);
     }
 
   gtk_style_context_restore (context);
@@ -1871,7 +1869,7 @@ gtk_real_button_activate (GtkButton *button)
        {
          if (gdk_device_grab (device, priv->event_window,
                               GDK_OWNERSHIP_WINDOW, TRUE,
-                              GDK_KEY_PRESS | GDK_KEY_RELEASE,
+                              GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
                               NULL, time) == GDK_GRAB_SUCCESS)
            {
              gtk_device_grab_add (widget, device, TRUE);
@@ -1924,40 +1922,32 @@ gtk_button_get_size (GtkWidget      *widget,
 {
   GtkButton *button = GTK_BUTTON (widget);
   GtkStyleContext *context;
-  GtkStateFlags state;
   GtkWidget *child;
   GtkBorder default_border;
   GtkBorder inner_border;
-  GtkBorder *border;
+  GtkBorder padding;
   gint focus_width;
   gint focus_pad;
   gint minimum, natural;
 
   context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
 
-  gtk_button_get_props (button, &default_border, NULL, &inner_border, NULL);
+  gtk_button_get_props (button, &default_border, NULL, &inner_border, &padding, NULL);
   gtk_style_context_get_style (context,
                                "focus-line-width", &focus_width,
                                "focus-padding", &focus_pad,
                                NULL);
 
-  gtk_style_context_get (context, state,
-                         "border-width", &border,
-                         NULL);
-
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      minimum = (border->left + border->right +
-                inner_border.left + inner_border.right);
+      minimum = inner_border.left + inner_border.right + padding.left + padding.right;
 
       if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
        minimum += default_border.left + default_border.right;
     }
   else
     {
-      minimum = (border->top + border->bottom +
-                inner_border.top + inner_border.bottom);
+      minimum = inner_border.top + inner_border.bottom + padding.top + padding.bottom;
 
       if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
        minimum += default_border.top + default_border.bottom;
@@ -1985,8 +1975,6 @@ gtk_button_get_size (GtkWidget      *widget,
 
   if (natural_size)
     *natural_size = natural;
-
-  gtk_border_free (border);
 }
 
 static void 
@@ -2049,7 +2037,7 @@ gtk_button_set_label (GtkButton   *button,
  * Return value: The text of the label widget. This string is owned
  * by the widget and must not be modified or freed.
  **/
-G_CONST_RETURN gchar *
+const gchar *
 gtk_button_get_label (GtkButton *button)
 {
   g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);