Patch: (radio|check)menuitem, list.



Hello everyone,

This patch (to gtk+971025) fixes two aesthetic glitches and one bug:

1 & 2): radiomenuitems and checkmenuitems would only show their `dimple' when 
they're either selected or prelighted (i.e. have the mouse over them) in the 
current version of gtk+. This patch makes them always show their dimple, and 
the appropriate one (i.e. in or out) when they are prelighted.

3): With this patch, keyboard manipulation of lists now works properly. Before 
this patch, regardless of the selection mode of the list, one could use the 
keyboard to make all items selected (and besides, no appropriate signals would 
be emitted, I believe). This patch only has an effect if the listitem in 
question has a parent and that parent is a list. (Though why you would want to 
use a listitem in any other situation is beyond me.)

Regards,

Johannes.

--8<--CUT-HERE--8<--

diff -ru gtk+971025.old/gtk/gtkcheckmenuitem.c gtk+971025/gtk/gtkcheckmenuitem.c
--- gtk+971025.old/gtk/gtkcheckmenuitem.c	Thu Sep 25 03:29:12 1997
+++ gtk+971025/gtk/gtkcheckmenuitem.c	Fri Oct 24 21:13:39 1997
@@ -214,6 +214,7 @@
   GtkShadowType shadow_type;
   gint width, height;
   gint x, y;
+  gboolean in_out;
 
   g_return_if_fail (check_menu_item != NULL);
   g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
@@ -230,21 +231,21 @@
 
       gdk_window_clear_area (widget->window, x, y, width, height);
 
-      if (check_menu_item->active ||
-	  (GTK_WIDGET_STATE (check_menu_item) == GTK_STATE_PRELIGHT))
-	{
-	  state_type = GTK_WIDGET_STATE (widget);
-
-	  shadow_type = GTK_SHADOW_IN;
-	  if (check_menu_item->active && (state_type == GTK_STATE_PRELIGHT))
-	    shadow_type = GTK_SHADOW_OUT;
-
-	  gdk_draw_rectangle (widget->window,
-			      widget->style->bg_gc[state_type],
-			      TRUE, x, y, width, height);
-	  gtk_draw_shadow (widget->style, widget->window,
-			   state_type, shadow_type,
-			   x, y, width, height);
-	}
+      state_type = GTK_WIDGET_STATE (widget);
+      
+      in_out = check_menu_item->active;
+      if (state_type == GTK_STATE_PRELIGHT)
+	in_out = !in_out;
+      if (in_out)
+	shadow_type = GTK_SHADOW_IN;
+      else
+	shadow_type = GTK_SHADOW_OUT;
+      
+      gdk_draw_rectangle (widget->window,
+			  widget->style->bg_gc[state_type],
+			  TRUE, x, y, width, height);
+      gtk_draw_shadow (widget->style, widget->window,
+		       state_type, shadow_type,
+		       x, y, width, height);
     }
 }
diff -ru gtk+971025.old/gtk/gtklistitem.c gtk+971025/gtk/gtklistitem.c
--- gtk+971025.old/gtk/gtklistitem.c	Thu Sep 25 03:29:12 1997
+++ gtk+971025/gtk/gtklistitem.c	Sun Oct 26 14:09:40 1997
@@ -17,7 +17,7 @@
  */
 #include "gtklabel.h"
 #include "gtklistitem.h"
-
+#include "gtklist.h"
 
 static void gtk_list_item_class_init    (GtkListItemClass *klass);
 static void gtk_list_item_init          (GtkListItem      *list_item);
@@ -375,10 +375,16 @@
   g_return_if_fail (item != NULL);
   g_return_if_fail (GTK_IS_LIST_ITEM (item));
 
-  if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
-    gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
+  if (GTK_WIDGET (item)->parent && GTK_IS_LIST (GTK_WIDGET (item)->parent))
+    gtk_list_select_child (GTK_LIST (GTK_WIDGET (item)->parent), 
+			   GTK_WIDGET (item));
   else
-    gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
-
-  gtk_widget_queue_draw (GTK_WIDGET (item));
+    {
+      /* Should we really bother with this bit? A listitem not in a list? */
+      if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
+	gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
+      else
+	gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
+      gtk_widget_queue_draw (GTK_WIDGET (item));
+    }
 }
diff -ru gtk+971025.old/gtk/gtkradiomenuitem.c gtk+971025/gtk/gtkradiomenuitem.c
--- gtk+971025.old/gtk/gtkradiomenuitem.c	Thu Sep 25 03:29:12 1997
+++ gtk+971025/gtk/gtkradiomenuitem.c	Fri Oct 24 20:57:29 1997
@@ -214,27 +214,27 @@
 
       gdk_window_clear_area (widget->window, x, y, width, height);
 
-      if (check_menu_item->active ||
+      state_type = GTK_WIDGET_STATE (widget);
+      if (check_menu_item->active || 
 	  (GTK_WIDGET_STATE (check_menu_item) == GTK_STATE_PRELIGHT))
-	{
-	  state_type = GTK_WIDGET_STATE (widget);
-	  shadow_type = GTK_SHADOW_IN;
-
-	  pts[0].x = x + width / 2;
-	  pts[0].y = y;
-	  pts[1].x = x + width;
-	  pts[1].y = y + height / 2;
-	  pts[2].x = pts[0].x;
-	  pts[2].y = y + height;
-	  pts[3].x = x;
-	  pts[3].y = pts[1].y;
-
-	  gdk_draw_polygon (widget->window,
-			    widget->style->bg_gc[state_type],
-			    TRUE, pts, 4);
-	  gtk_draw_diamond (widget->style, widget->window,
-			    state_type, shadow_type,
-			    x, y, width, height);
-	}
+	shadow_type = GTK_SHADOW_IN;
+      else
+	shadow_type = GTK_SHADOW_OUT;
+      
+      pts[0].x = x + width / 2;
+      pts[0].y = y;
+      pts[1].x = x + width;
+      pts[1].y = y + height / 2;
+      pts[2].x = pts[0].x;
+      pts[2].y = y + height;
+      pts[3].x = x;
+      pts[3].y = pts[1].y;
+      
+      gdk_draw_polygon (widget->window,
+			widget->style->bg_gc[state_type],
+			TRUE, pts, 4);
+      gtk_draw_diamond (widget->style, widget->window,
+			state_type, shadow_type,
+			x, y, width, height);
     }
 }

--
A busstation is where a bus stops. A trainstation is where a train stops.
On my desk, I have a workstation...

How do I connect to that real-life thing I keep hearing about?




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