]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcheckbutton.c
Typo fix.
[~andy/gtk] / gtk / gtkcheckbutton.c
index d5748770236d547c4b424a9ba91255023964dd23..5e3ef30d5139be1edb5b949a7a9cfb97269afdf9 100644 (file)
@@ -114,6 +114,7 @@ gtk_check_button_init (GtkCheckButton *check_button)
   GTK_WIDGET_SET_FLAGS (check_button, GTK_NO_WINDOW);
   GTK_WIDGET_UNSET_FLAGS (check_button, GTK_RECEIVES_DEFAULT);
   GTK_TOGGLE_BUTTON (check_button)->draw_indicator = TRUE;
+  GTK_BUTTON (check_button)->depress_on_activate = FALSE;
 }
 
 GtkWidget*
@@ -159,8 +160,14 @@ gtk_check_button_paint (GtkWidget    *widget,
     {
       gint border_width;
       gint interior_focus;
+      gint focus_width;
+      gint focus_pad;
          
-      gtk_widget_style_get (widget, "interior_focus", &interior_focus, NULL);
+      gtk_widget_style_get (widget,
+                           "interior-focus", &interior_focus,
+                           "focus-line-width", &focus_width,
+                           "focus-padding", &focus_pad,
+                           NULL);
 
       gtk_check_button_draw_indicator (check_button, area);
       
@@ -170,22 +177,22 @@ gtk_check_button_paint (GtkWidget    *widget,
          if (interior_focus)
            {
              GtkWidget *child = GTK_BIN (widget)->child;
-
+             
              if (child && GTK_WIDGET_VISIBLE (child))
-               gtk_paint_focus (widget->style, widget->window,
+               gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
                                 NULL, widget, "checkbutton",
-                                child->allocation.x - 1,
-                                child->allocation.y - 1,
-                                child->allocation.width + 1,
-                                child->allocation.height + 1);
+                                child->allocation.x - focus_width - focus_pad,
+                                child->allocation.y - focus_width - focus_pad,
+                                child->allocation.width + 2 * (focus_width + focus_pad),
+                                child->allocation.height + 2 * (focus_width + focus_pad));
            }
          else
-           gtk_paint_focus (widget->style, widget->window,
+           gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), 
                             NULL, widget, "checkbutton",
                             border_width + widget->allocation.x,
                             border_width + widget->allocation.y,
-                            widget->allocation.width - 2 * border_width - 1,
-                            widget->allocation.height - 2 * border_width - 1);
+                            widget->allocation.width - 2 * border_width,
+                            widget->allocation.height - 2 * border_width);
        }
     }
 }
@@ -208,12 +215,7 @@ static void
 gtk_check_button_size_request (GtkWidget      *widget,
                               GtkRequisition *requisition)
 {
-  GtkToggleButton *toggle_button;
-  
-  g_return_if_fail (GTK_IS_CHECK_BUTTON (widget));
-  g_return_if_fail (requisition != NULL);
-  
-  toggle_button = GTK_TOGGLE_BUTTON (widget);
+  GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (widget);
   
   if (toggle_button->draw_indicator)
     {
@@ -222,9 +224,16 @@ gtk_check_button_size_request (GtkWidget      *widget,
       gint indicator_size;
       gint indicator_spacing;
       gint border_width = GTK_CONTAINER (widget)->border_width;
-      
-      requisition->width = border_width * 2 + 2;
-      requisition->height = border_width * 2 + 2;
+      gint focus_width;
+      gint focus_pad;
+
+      gtk_widget_style_get (GTK_WIDGET (widget),
+                           "focus-line-width", &focus_width,
+                           "focus-padding", &focus_pad,
+                           NULL);
+      requisition->width = border_width * 2;
+      requisition->height = border_width * 2;
 
       child = GTK_BIN (widget)->child;
       if (child && GTK_WIDGET_VISIBLE (child))
@@ -240,10 +249,10 @@ gtk_check_button_size_request (GtkWidget      *widget,
       _gtk_check_button_get_props (GTK_CHECK_BUTTON (widget),
                                   &indicator_size, &indicator_spacing);
       
-      requisition->width += (indicator_size + indicator_spacing * 3 + 2);
+      requisition->width += (indicator_size + indicator_spacing * 3 + 2 * (focus_width + focus_pad));
       
-      temp = (indicator_size + indicator_spacing * 2);
-      requisition->height = MAX (requisition->height, temp) + 2;
+      temp = indicator_size + indicator_spacing * 2;
+      requisition->height = MAX (requisition->height, temp) + 2 * (focus_width + focus_pad);
     }
   else
     (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);
@@ -257,10 +266,8 @@ gtk_check_button_size_allocate (GtkWidget     *widget,
   GtkToggleButton *toggle_button;
   GtkButton *button;
   GtkAllocation child_allocation;
-  
-  g_return_if_fail (GTK_IS_CHECK_BUTTON (widget));
-  g_return_if_fail (allocation != NULL);
-  
+
+  button = GTK_BUTTON (widget);
   check_button = GTK_CHECK_BUTTON (widget);
   toggle_button = GTK_TOGGLE_BUTTON (widget);
 
@@ -268,30 +275,43 @@ gtk_check_button_size_allocate (GtkWidget     *widget,
     {
       gint indicator_size;
       gint indicator_spacing;
+      gint focus_width;
+      gint focus_pad;
       
       _gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
+      gtk_widget_style_get (widget,
+                           "focus-line-width", &focus_width,
+                           "focus-padding", &focus_pad,
+                           NULL);
                                                    
       widget->allocation = *allocation;
       if (GTK_WIDGET_REALIZED (widget))
-       gdk_window_move_resize (toggle_button->event_window,
+       gdk_window_move_resize (button->event_window,
                                allocation->x, allocation->y,
                                allocation->width, allocation->height);
       
-      button = GTK_BUTTON (widget);
-      
       if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
        {
+         GtkRequisition child_requisition;
          gint border_width = GTK_CONTAINER (widget)->border_width;
+
+         gtk_widget_get_child_requisition (GTK_BIN (button)->child, &child_requisition);
  
-         child_allocation.x = (border_width + indicator_size + indicator_spacing * 3 + 1 +
-                               widget->allocation.x);
-         child_allocation.y = border_width + 1 + widget->allocation.y;
-         child_allocation.width = MIN (GTK_BIN (button)->child->requisition.width,
+         child_allocation.width = MIN (child_requisition.width,
                                        allocation->width -
-                                       ((border_width + 1) * 2 + indicator_size + indicator_spacing * 3));
-         child_allocation.height = MIN (GTK_BIN (button)->child->requisition.height,
-                                        allocation->height - (border_width + 1) * 2);
+                                       ((border_width + focus_width + focus_pad) * 2
+                                        + indicator_size + indicator_spacing * 3));
+         child_allocation.width = MAX (child_allocation.width, 1);
+
+         child_allocation.height = MIN (child_requisition.height,
+                                        allocation->height - (border_width + focus_width + focus_pad) * 2);
+         child_allocation.height = MAX (child_allocation.height, 1);
          
+         child_allocation.x = (border_width + indicator_size + indicator_spacing * 3 +
+                               widget->allocation.x + focus_width + focus_pad);
+         child_allocation.y = widget->allocation.y +
+                 (allocation->height - child_allocation.height) / 2;
+
          if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
            child_allocation.x = allocation->x + allocation->width
              - (child_allocation.x - allocation->x + child_allocation.width);
@@ -311,10 +331,6 @@ gtk_check_button_expose (GtkWidget      *widget,
   GtkToggleButton *toggle_button;
   GtkBin *bin;
   
-  g_return_val_if_fail (widget != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_CHECK_BUTTON (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
-  
   check_button = GTK_CHECK_BUTTON (widget);
   toggle_button = GTK_TOGGLE_BUTTON (widget);
   bin = GTK_BIN (widget);
@@ -357,67 +373,75 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
                                      GdkRectangle   *area)
 {
   GtkWidget *widget;
+  GtkButton *button;
   GtkToggleButton *toggle_button;
   GtkStateType state_type;
   GtkShadowType shadow_type;
-  GdkRectangle restrict_area;
-  GdkRectangle new_area;
-  gint width, height;
   gint x, y;
   gint indicator_size;
   gint indicator_spacing;
-  GdkWindow *window;
-  
-  g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
-  
-  widget = GTK_WIDGET (check_button);
-  toggle_button = GTK_TOGGLE_BUTTON (check_button);
+  gint focus_width;
+  gint focus_pad;
+  gboolean interior_focus;
   
   if (GTK_WIDGET_DRAWABLE (check_button))
     {
-      window = widget->window;
-      
+      widget = GTK_WIDGET (check_button);
+      button = GTK_BUTTON (check_button);
+      toggle_button = GTK_TOGGLE_BUTTON (check_button);
+  
+      gtk_widget_style_get (widget, "interior_focus", &interior_focus,
+                           "focus-line-width", &focus_width, 
+                           "focus-padding", &focus_pad, NULL);
+
       _gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
-                                                   
-      state_type = GTK_WIDGET_STATE (widget);
-      if (state_type != GTK_STATE_NORMAL &&
-         state_type != GTK_STATE_PRELIGHT)
-       state_type = GTK_STATE_NORMAL;
-      
-      restrict_area.x = widget->allocation.x + GTK_CONTAINER (widget)->border_width;
-      restrict_area.y = widget->allocation.y + GTK_CONTAINER (widget)->border_width;
-      restrict_area.width = widget->allocation.width - ( 2 * GTK_CONTAINER (widget)->border_width);
-      restrict_area.height = widget->allocation.height - ( 2 * GTK_CONTAINER (widget)->border_width);
-      
-      if (gdk_rectangle_intersect (area, &restrict_area, &new_area))
-       {
-         if (state_type != GTK_STATE_NORMAL)
-           gtk_paint_flat_box (widget->style, window, state_type, 
-                               GTK_SHADOW_ETCHED_OUT, 
-                               area, widget, "checkbutton",
-                               new_area.x, new_area.y,
-                               new_area.width, new_area.height);
-       }
-      
+
       x = widget->allocation.x + indicator_spacing + GTK_CONTAINER (widget)->border_width;
       y = widget->allocation.y + (widget->allocation.height - indicator_size) / 2;
-      width = indicator_size;
-      height = indicator_size;
 
-      state_type = GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE ? GTK_STATE_NORMAL : GTK_WIDGET_STATE (widget);
-      if (GTK_TOGGLE_BUTTON (widget)->inconsistent)
+      if (!interior_focus)
+       x += focus_width + focus_pad;      
+
+      if (toggle_button->inconsistent)
        shadow_type = GTK_SHADOW_ETCHED_IN;
-      else if (GTK_TOGGLE_BUTTON (widget)->active)
+      else if (toggle_button->active)
        shadow_type = GTK_SHADOW_IN;
       else
        shadow_type = GTK_SHADOW_OUT;
 
+      if (button->activate_timeout || (button->button_down && button->in_button))
+       state_type = GTK_STATE_ACTIVE;
+      else if (button->in_button)
+       state_type = GTK_STATE_PRELIGHT;
+      else
+       state_type = GTK_STATE_NORMAL;
+      
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-       x = widget->allocation.x + widget->allocation.width - (width + x - widget->allocation.x);
+       x = widget->allocation.x + widget->allocation.width - (indicator_size + x - widget->allocation.x);
 
-      gtk_paint_check (widget->style, window,
+      if (GTK_WIDGET_STATE (toggle_button) == GTK_STATE_PRELIGHT)
+       {
+         GdkRectangle restrict_area;
+         GdkRectangle new_area;
+             
+         restrict_area.x = widget->allocation.x + GTK_CONTAINER (widget)->border_width;
+         restrict_area.y = widget->allocation.y + GTK_CONTAINER (widget)->border_width;
+         restrict_area.width = widget->allocation.width - (2 * GTK_CONTAINER (widget)->border_width);
+         restrict_area.height = widget->allocation.height - (2 * GTK_CONTAINER (widget)->border_width);
+         
+         if (gdk_rectangle_intersect (area, &restrict_area, &new_area))
+           {
+             gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_PRELIGHT,
+                                 GTK_SHADOW_ETCHED_OUT, 
+                                 area, widget, "checkbutton",
+                                 new_area.x, new_area.y,
+                                 new_area.width, new_area.height);
+           }
+       }
+      
+      gtk_paint_check (widget->style, widget->window,
                       state_type, shadow_type,
                       area, widget, "checkbutton",
-                      x, y, width, height);
+                      x, y, indicator_size, indicator_size);
     }
 }