Feedback when checkbuttons are depressed



Here is a patch that adds visual feedback when check- and radiobuttons
are depressed.  It also simplifies the logic in
gtk_{real_check, radio}_button_draw_indicator.

Inconsistent buttons are not drawn any different from normal buttons;
I have marked this with FIXME's.


Søren


Mon Dec  3 01:24:15 2001  Soeren Sandmann  <sandmann daimi au dk>

	* gtk/gtkcheckbutton.c (gtk_real_check_button_draw_indicator):
	Simplify logic and use GTK_STATE_ACTIVE when the check button is
	depressed

	* gtk/gtkradiobutton.c (gtk_radio_button_draw_indicator): same
	here
	
	* gtk/gtkstyle.c (gtk_default_draw_check,
	gtk_default_draw_option): draw base with bg_gc when state is
	active

	* gtk/gtktogglebutton.c (gtk_toggle_button_update_state): 
	Use GTK_STATE_ACTIVE when an inconsistent button is depressed

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2650
diff -u -p -r1.2650 ChangeLog
--- ChangeLog	2001/11/30 23:17:28	1.2650
+++ ChangeLog	2001/12/03 00:25:19
@@ -1,3 +1,19 @@
+Mon Dec  3 01:24:15 2001  Soeren Sandmann  <sandmann daimi au dk>
+
+	* gtk/gtkcheckbutton.c (gtk_real_check_button_draw_indicator):
+	Simplify logic and use GTK_STATE_ACTIVE when the check button is
+	depressed
+
+	* gtk/gtkradiobutton.c (gtk_radio_button_draw_indicator): same
+	here
+	
+	* gtk/gtkstyle.c (gtk_default_draw_check,
+	gtk_default_draw_option): draw base with bg_gc when state is
+	active
+
+	* gtk/gtktogglebutton.c (gtk_toggle_button_update_state): 
+	Use GTK_STATE_ACTIVE when an inconsistent button is depressed
+
 2001-11-30  jacob berkman  <jacob ximian com>
 
 	* gtk/gtknotebook.c (gtk_notebook_remove_tab_label): set the
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.88
diff -u -p -r1.88 gtkstyle.c
--- gtk/gtkstyle.c	2001/11/16 15:20:27	1.88
+++ gtk/gtkstyle.c	2001/12/03 00:25:20
@@ -3061,17 +3061,26 @@ gtk_default_draw_check (GtkStyle      *s
 	}
       else
 	{
+	  GdkGC *base_gc = style->base_gc[state_type];
+
+	  if (state_type == GTK_STATE_ACTIVE)
+	    base_gc = style->bg_gc[state_type];
+
+	  draw_part (window, base_gc, area, x, y, CHECK_BASE);
 	  draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
 	  draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
 	  draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
 	  draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
-	  draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
 	  
 	  if (shadow_type == GTK_SHADOW_IN)
 	    {
 	      draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
 	      draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
 	    }
+	  else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
+	    {
+	      /* FIXME */
+	    }
 	}
     }
 
@@ -3124,14 +3133,21 @@ gtk_default_draw_option (GtkStyle      *
 	}
       else
 	{
+	  GdkGC *base_gc = style->base_gc[state_type];
+
+	  if (state_type == GTK_STATE_ACTIVE)
+	    base_gc = style->bg_gc[state_type];
+
+	  draw_part (window, base_gc, area, x, y, RADIO_BASE);
 	  draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
 	  draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
 	  draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
 	  draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
-	  draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
 	  
 	  if (shadow_type == GTK_SHADOW_IN)
 	    draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
+	  else if (shadow_type == GTK_SHADOW_ETCHED_IN)
+	    /* FIXME */;
 	}
     }
 }
Index: gtk/gtkcheckbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcheckbutton.c,v
retrieving revision 1.36
diff -u -p -r1.36 gtkcheckbutton.c
--- gtk/gtkcheckbutton.c	2001/11/15 21:04:47	1.36
+++ gtk/gtkcheckbutton.c	2001/12/03 00:25:20
@@ -363,11 +363,9 @@ gtk_real_check_button_draw_indicator (Gt
   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));
   
@@ -376,49 +374,53 @@ gtk_real_check_button_draw_indicator (Gt
   
   if (GTK_WIDGET_DRAWABLE (check_button))
     {
-      window = widget->window;
-      
       _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 (GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
 	{
-	  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);
+	  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);
+	    }
 	}
       
       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)
-	shadow_type = GTK_SHADOW_ETCHED_IN;
-      else if (GTK_TOGGLE_BUTTON (widget)->active)
-	shadow_type = GTK_SHADOW_IN;
+      if (toggle_button->inconsistent)
+	{
+	  shadow_type = GTK_SHADOW_ETCHED_IN;
+	  state_type = GTK_WIDGET_STATE (widget);
+	}
+      else if (toggle_button->active)
+	{
+	  shadow_type = GTK_SHADOW_IN;
+	  if (GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE)
+	    state_type = GTK_STATE_NORMAL;
+	  else if (GTK_WIDGET_STATE (widget) == GTK_STATE_NORMAL)
+	    state_type = GTK_STATE_ACTIVE;
+	}
       else
-	shadow_type = GTK_SHADOW_OUT;
+	{
+	  shadow_type = GTK_SHADOW_OUT;
+	  state_type = GTK_WIDGET_STATE (widget);
+	}
 
       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,
+      gtk_paint_check (widget->style, widget->window,
 		       state_type, shadow_type,
 		       area, widget, "checkbutton",
-		       x, y, width, height);
+		       x, y, indicator_size, indicator_size);
     }
 }
Index: gtk/gtktogglebutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktogglebutton.c,v
retrieving revision 1.43
diff -u -p -r1.43 gtktogglebutton.c
--- gtk/gtktogglebutton.c	2001/11/17 23:28:51	1.43
+++ gtk/gtktogglebutton.c	2001/12/03 00:25:20
@@ -534,8 +534,10 @@ gtk_toggle_button_update_state (GtkButto
       
   if (!button->button_down && button->in_button)
     new_state = GTK_STATE_PRELIGHT;
+  else if (depressed || (toggle_button->inconsistent && button->in_button && button->button_down))
+    new_state = GTK_STATE_ACTIVE;
   else
-    new_state = depressed ? GTK_STATE_ACTIVE: GTK_STATE_NORMAL;
+    new_state = GTK_STATE_NORMAL;
 
   _gtk_button_set_depressed (button, depressed); 
   gtk_widget_set_state (GTK_WIDGET (toggle_button), new_state);
Index: gtk/gtkradiobutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkradiobutton.c,v
retrieving revision 1.37
diff -u -p -r1.37 gtkradiobutton.c
--- gtk/gtkradiobutton.c	2001/11/19 22:39:03	1.37
+++ gtk/gtkradiobutton.c	2001/12/03 00:25:20
@@ -579,7 +579,6 @@ gtk_radio_button_draw_indicator (GtkChec
 				 GdkRectangle   *area)
 {
   GtkWidget *widget;
-  GtkButton *button;
   GtkToggleButton *toggle_button;
   GtkStateType state_type;
   GtkShadowType shadow_type;
@@ -590,49 +589,55 @@ gtk_radio_button_draw_indicator (GtkChec
 
   g_return_if_fail (GTK_IS_RADIO_BUTTON (check_button));
 
-  if (GTK_WIDGET_VISIBLE (check_button) && GTK_WIDGET_MAPPED (check_button))
-    {
-      widget = GTK_WIDGET (check_button);
-      button = GTK_BUTTON (check_button);
-      toggle_button = GTK_TOGGLE_BUTTON (check_button);
-
-      state_type = GTK_WIDGET_STATE (widget);
-      if ((state_type != GTK_STATE_NORMAL) &&
-	  (state_type != GTK_STATE_PRELIGHT))
-	state_type = GTK_STATE_NORMAL;
+  widget = GTK_WIDGET (check_button);
+  toggle_button = GTK_TOGGLE_BUTTON (check_button);
 
-      _gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
-
-      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 (GTK_WIDGET_DRAWABLE (widget))
+    {
+       _gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
 
-      if (gdk_rectangle_intersect (area, &restrict_area, &new_area))
+       if (GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
 	{
-	   if (state_type != GTK_STATE_NORMAL)
-	     gtk_paint_flat_box(widget->style, widget->window, state_type, 
-				GTK_SHADOW_ETCHED_OUT,
-				area, widget, "radiobutton",
-				new_area.x, new_area.y,
-				new_area.width, new_area.height);
+	  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, "radiobutton",
+				  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;
-      
-      state_type = GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE ? GTK_STATE_NORMAL : GTK_WIDGET_STATE (widget);
-      if (GTK_TOGGLE_BUTTON (widget)->active)
-	shadow_type = GTK_SHADOW_IN;
-      else
-	shadow_type = GTK_SHADOW_OUT;
 
-      if (GTK_TOGGLE_BUTTON (widget)->inconsistent)
-        shadow_type = GTK_SHADOW_ETCHED_IN;
+      if (toggle_button->inconsistent)
+	{
+	  shadow_type = GTK_SHADOW_ETCHED_IN;
+	  state_type = GTK_WIDGET_STATE (widget);
+	}
+      else if (toggle_button->active)
+	{
+	  shadow_type = GTK_SHADOW_IN;
+	  if (GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE)
+	    state_type = GTK_STATE_NORMAL;
+	  else if (GTK_WIDGET_STATE (widget) == GTK_STATE_NORMAL)
+	    state_type = GTK_STATE_ACTIVE;
+	}
+      else
+	{
+	  shadow_type = GTK_SHADOW_OUT;
+	  state_type = GTK_WIDGET_STATE (widget);
+	}
       
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
 	x = widget->allocation.x + widget->allocation.width - (indicator_size + x - widget->allocation.x);
-
+      
       gtk_paint_option (widget->style, widget->window,
 			state_type, shadow_type,
 			area, widget, "radiobutton",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]