]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkbutton.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtkbutton.c
index 43ec81853b3838c993203a7dc7424fb28f5ed0d5..8b44900a0703a2a99ba69849a5c038cf004b3101 100644 (file)
@@ -428,17 +428,33 @@ gtk_button_class_init (GtkButtonClass *klass)
                  G_TYPE_NONE, 0);
   widget_class->activate_signal = button_signals[ACTIVATE];
 
+  /**
+   * GtkButton:default-border:
+   *
+   * The "default-border" style property defines the extra space to add
+   * around a button that can become the default widget of its window.
+   * For more information about default widgets, see gtk_widget_grab_default().
+   */
+
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_boxed ("default-border",
                                                               P_("Default Spacing"),
-                                                              P_("Extra space to add for CAN_DEFAULT buttons"),
+                                                              P_("Extra space to add for GTK_CAN_DEFAULT buttons"),
                                                               GTK_TYPE_BORDER,
                                                               GTK_PARAM_READABLE));
 
+  /**
+   * GtkButton:default-outside-border:
+   *
+   * The "default-outside-border" style property defines the extra outside
+   * space to add around a button that can become the default widget of its
+   * window. Extra outside space is always drawn outside the button border.
+   * For more information about default widgets, see gtk_widget_grab_default().
+   */
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_boxed ("default-outside-border",
                                                               P_("Default Outside Spacing"),
-                                                              P_("Extra space to add for CAN_DEFAULT buttons that is always drawn outside the border"),
+                                                              P_("Extra space to add for GTK_CAN_DEFAULT buttons that is always drawn outside the border"),
                                                               GTK_TYPE_BORDER,
                                                               GTK_PARAM_READABLE));
   gtk_widget_class_install_style_property (widget_class,
@@ -934,15 +950,15 @@ gtk_button_construct_child (GtkButton *button)
   GtkWidget *image = NULL;
   gchar *label_text = NULL;
   gint image_spacing;
-  
+
   if (!button->constructed)
     return;
+
   if (!button->label_text && !priv->image)
     return;
-  
-  gtk_widget_style_get (GTK_WIDGET (button), 
-                       "image-spacing", &image_spacing, 
+
+  gtk_widget_style_get (GTK_WIDGET (button),
+                       "image-spacing", &image_spacing,
                        NULL);
 
   if (priv->image && !priv->image_is_stock)
@@ -951,7 +967,7 @@ gtk_button_construct_child (GtkButton *button)
       if (image->parent)
        gtk_container_remove (GTK_CONTAINER (image->parent), image);
     }
-  
+
   priv->image = NULL;
 
   if (GTK_BIN (button)->child)
@@ -973,7 +989,7 @@ gtk_button_construct_child (GtkButton *button)
   if (image)
     {
       priv->image = image;
-      g_object_set (priv->image, 
+      g_object_set (priv->image,
                    "visible", show_image (button),
                    "no-show-all", TRUE,
                    NULL);
@@ -997,7 +1013,7 @@ gtk_button_construct_child (GtkButton *button)
 
       if (label_text)
        {
-          if (button->use_underline)
+          if (button->use_underline || button->use_stock)
             {
              label = gtk_label_new_with_mnemonic (label_text);
              gtk_label_set_mnemonic_widget (GTK_LABEL (label),
@@ -1012,7 +1028,7 @@ gtk_button_construct_child (GtkButton *button)
          else
            gtk_box_pack_end (GTK_BOX (box), label, FALSE, FALSE, 0);
        }
-      
+
       gtk_container_add (GTK_CONTAINER (button), align);
       gtk_container_add (GTK_CONTAINER (align), box);
       gtk_widget_show_all (align);
@@ -1021,18 +1037,18 @@ gtk_button_construct_child (GtkButton *button)
 
       return;
     }
-  
-  if (button->use_underline)
+
+  if (button->use_underline || button->use_stock)
     {
       label = gtk_label_new_with_mnemonic (button->label_text);
       gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
     }
   else
     label = gtk_label_new (button->label_text);
-  
+
   if (priv->align_set)
     gtk_misc_set_alignment (GTK_MISC (label), priv->xalign, priv->yalign);
-  
+
   gtk_widget_show (label);
   gtk_container_add (GTK_CONTAINER (button), label);
 }
@@ -1338,13 +1354,13 @@ gtk_button_size_request (GtkWidget      *widget,
                           GTK_WIDGET (widget)->style->ythickness) * 2 +
                          inner_border.top + inner_border.bottom);
 
-  if (GTK_WIDGET_CAN_DEFAULT (widget))
+  if (gtk_widget_get_can_default (widget))
     {
       requisition->width += default_border.left + default_border.right;
       requisition->height += default_border.top + default_border.bottom;
     }
 
-  if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
+  if (GTK_BIN (button)->child && gtk_widget_get_visible (GTK_BIN (button)->child))
     {
       GtkRequisition child_requisition;
 
@@ -1389,7 +1405,7 @@ gtk_button_size_allocate (GtkWidget     *widget,
                            widget->allocation.width - border_width * 2,
                            widget->allocation.height - border_width * 2);
 
-  if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
+  if (GTK_BIN (button)->child && gtk_widget_get_visible (GTK_BIN (button)->child))
     {
       child_allocation.x = widget->allocation.x + border_width + inner_border.left + xthickness;
       child_allocation.y = widget->allocation.y + border_width + inner_border.top + ythickness;
@@ -1405,7 +1421,7 @@ gtk_button_size_allocate (GtkWidget     *widget,
                                      inner_border.bottom -
                                     border_width * 2);
 
-      if (GTK_WIDGET_CAN_DEFAULT (button))
+      if (gtk_widget_get_can_default (GTK_WIDGET (button)))
        {
          child_allocation.x += default_border.left;
          child_allocation.y += default_border.top;
@@ -1413,7 +1429,7 @@ gtk_button_size_allocate (GtkWidget     *widget,
          child_allocation.height = MAX (1, child_allocation.height - default_border.top - default_border.bottom);
        }
 
-      if (GTK_WIDGET_CAN_FOCUS (button))
+      if (gtk_widget_get_can_focus (GTK_WIDGET (button)))
        {
          child_allocation.x += focus_width + focus_pad;
          child_allocation.y += focus_width + focus_pad;
@@ -1455,14 +1471,15 @@ _gtk_button_paint (GtkButton          *button,
   gboolean interior_focus;
   gint focus_width;
   gint focus_pad;
-   
-  if (GTK_WIDGET_DRAWABLE (button))
+
+  widget = GTK_WIDGET (button);
+
+  if (gtk_widget_is_drawable (widget))
     {
-      widget = GTK_WIDGET (button);
       border_width = GTK_CONTAINER (widget)->border_width;
 
       gtk_button_get_props (button, &default_border, &default_outside_border, NULL, &interior_focus);
-      gtk_widget_style_get (GTK_WIDGET (widget),
+      gtk_widget_style_get (widget,
                            "focus-line-width", &focus_width,
                            "focus-padding", &focus_pad,
                            NULL); 
@@ -1472,7 +1489,7 @@ _gtk_button_paint (GtkButton          *button,
       width = widget->allocation.width - border_width * 2;
       height = widget->allocation.height - border_width * 2;
 
-      if (GTK_WIDGET_HAS_DEFAULT (widget) &&
+      if (gtk_widget_has_default (widget) &&
          GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
        {
          gtk_paint_box (widget->style, widget->window,
@@ -1485,7 +1502,7 @@ _gtk_button_paint (GtkButton          *button,
          width -= default_border.left + default_border.right;
          height -= default_border.top + default_border.bottom;
        }
-      else if (GTK_WIDGET_CAN_DEFAULT (widget))
+      else if (gtk_widget_get_can_default (widget))
        {
          x += default_outside_border.left;
          y += default_outside_border.top;
@@ -1493,7 +1510,7 @@ _gtk_button_paint (GtkButton          *button,
          height -= default_outside_border.top + default_outside_border.bottom;
        }
        
-      if (!interior_focus && GTK_WIDGET_HAS_FOCUS (widget))
+      if (!interior_focus && gtk_widget_has_focus (widget))
        {
          x += focus_width + focus_pad;
          y += focus_width + focus_pad;
@@ -1508,13 +1525,13 @@ _gtk_button_paint (GtkButton          *button,
                       shadow_type, area, widget, "button",
                       x, y, width, height);
        
-      if (GTK_WIDGET_HAS_FOCUS (widget))
+      if (gtk_widget_has_focus (widget))
        {
          gint child_displacement_x;
          gint child_displacement_y;
          gboolean displace_focus;
          
-         gtk_widget_style_get (GTK_WIDGET (widget),
+         gtk_widget_style_get (widget,
                                "child-displacement-y", &child_displacement_y,
                                "child-displacement-x", &child_displacement_x,
                                "displace-focus", &displace_focus,
@@ -1552,7 +1569,7 @@ static gboolean
 gtk_button_expose (GtkWidget      *widget,
                   GdkEventExpose *event)
 {
-  if (GTK_WIDGET_DRAWABLE (widget))
+  if (gtk_widget_is_drawable (widget))
     {
       GtkButton *button = GTK_BUTTON (widget);
       
@@ -1577,7 +1594,7 @@ gtk_button_button_press (GtkWidget      *widget,
     {
       button = GTK_BUTTON (widget);
 
-      if (button->focus_on_click && !GTK_WIDGET_HAS_FOCUS (widget))
+      if (button->focus_on_click && !gtk_widget_has_focus (widget))
        gtk_widget_grab_focus (widget);
 
       if (event->button == 1)
@@ -1674,7 +1691,7 @@ gtk_button_leave_notify (GtkWidget        *widget,
 
   if ((event_widget == widget) &&
       (event->detail != GDK_NOTIFY_INFERIOR) &&
-      (GTK_WIDGET_SENSITIVE (event_widget)))
+      (gtk_widget_get_sensitive (event_widget)))
     {
       button->in_button = FALSE;
       gtk_button_leave (button);
@@ -2121,12 +2138,23 @@ static void
 gtk_button_screen_changed (GtkWidget *widget,
                           GdkScreen *previous_screen)
 {
+  GtkButton *button;
   GtkSettings *settings;
   guint show_image_connection;
 
   if (!gtk_widget_has_screen (widget))
     return;
 
+  button = GTK_BUTTON (widget);
+
+  /* If the button is being pressed while the screen changes the
+    release might never occur, so we reset the state. */
+  if (button->button_down)
+    {
+      button->button_down = FALSE;
+      gtk_button_update_state (button);
+    }
+
   settings = gtk_widget_get_settings (widget);
 
   show_image_connection = 
@@ -2143,7 +2171,7 @@ gtk_button_screen_changed (GtkWidget *widget,
                     I_("gtk-button-connection"),
                     GUINT_TO_POINTER (show_image_connection));
 
-  show_image_change_notify (GTK_BUTTON (widget));
+  show_image_change_notify (button);
 }
 
 static void
@@ -2152,7 +2180,7 @@ gtk_button_state_changed (GtkWidget    *widget,
 {
   GtkButton *button = GTK_BUTTON (widget);
 
-  if (!GTK_WIDGET_IS_SENSITIVE (widget))
+  if (!gtk_widget_is_sensitive (widget))
     {
       button->in_button = FALSE;
       gtk_real_button_released (button);