list + (check|radio)menuitem bugs again.



Hello again, everyone.

Here's the second installment of my patch for the bugs I reported on
before. This time it's cut up in two patches.

First off, a patch (let's call it patch-971101-johannes-0) for GtkList
selection with the keyboard. This doesn't work properly without this
patch. This is exactly the same as part of my previous patch (which I'm
guessing wasn't accepted).

Secondly, a patch (patch-971101-johannes-1, of course) for the check-
and radio menu items. This time, the change in behaviour is selectable
on a per-widget basis. It adds a field to the checkmenuitem, and a
function gtk_check_menu_item_set_show_toggle (GtkCheckMenuItem
*menu_item, gboolean always). I've tried to stick to the naming scheme,
yet still keep the name acceptably short. If called with FALSE (which is
default), we get the old gtk behaviour. If called with TRUE, we get
Motif-like behaviour; the toggle thingie is always shown, and not shown
differently when under the mouse.

I hope that these are more acceptable!

Regards,

Johannes.
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/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	Sat Nov  1 19:02:30 1997
@@ -103,6 +103,16 @@
 }
 
 void
+gtk_check_menu_item_set_show_toggle (GtkCheckMenuItem *menu_item, 
+				     gboolean          always)
+{
+  g_return_if_fail (menu_item != NULL);
+  g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (menu_item));
+
+  menu_item->always_show_toggle = always;
+}
+
+void
 gtk_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item)
 {
   gtk_signal_emit (GTK_OBJECT (check_menu_item), check_menu_item_signals[TOGGLED]);
@@ -146,6 +156,7 @@
 gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item)
 {
   check_menu_item->active = FALSE;
+  check_menu_item->always_show_toggle = FALSE;
 }
 
 static void
@@ -230,14 +241,25 @@
 
       gdk_window_clear_area (widget->window, x, y, width, height);
 
-      if (check_menu_item->active ||
+      if (check_menu_item->active || 
+	  check_menu_item->always_show_toggle ||
 	  (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;
+	  if (check_menu_item->always_show_toggle)
+	    {
+	      shadow_type = GTK_SHADOW_OUT;
+	      if (check_menu_item->active)
+		shadow_type = GTK_SHADOW_IN;
+	    }
+	  else
+	    {
+	      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],
diff -ru gtk+971025.old/gtk/gtkcheckmenuitem.h gtk+971025/gtk/gtkcheckmenuitem.h
--- gtk+971025.old/gtk/gtkcheckmenuitem.h	Thu Sep 25 03:29:12 1997
+++ gtk+971025/gtk/gtkcheckmenuitem.h	Sat Nov  1 18:59:22 1997
@@ -41,6 +41,7 @@
   GtkMenuItem menu_item;
 
   guint active : 1;
+  guint always_show_toggle : 1;
 };
 
 struct _GtkCheckMenuItemClass
@@ -58,6 +59,8 @@
 GtkWidget* gtk_check_menu_item_new_with_label (const gchar      *label);
 void       gtk_check_menu_item_set_state      (GtkCheckMenuItem *check_menu_item,
 					       gint              state);
+void       gtk_check_menu_item_set_show_toggle (GtkCheckMenuItem   *menu_item,
+						gboolean            always);
 void       gtk_check_menu_item_toggled        (GtkCheckMenuItem *check_menu_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	Sat Nov  1 18:59:57 1997
@@ -214,11 +214,16 @@
 
       gdk_window_clear_area (widget->window, x, y, width, height);
 
-      if (check_menu_item->active ||
+      if (check_menu_item->active || 
+	  check_menu_item->always_show_toggle ||
 	  (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 || 
+	      !check_menu_item->always_show_toggle)
+	    shadow_type = GTK_SHADOW_IN;
+	  else
+	    shadow_type = GTK_SHADOW_OUT;
 
 	  pts[0].x = x + width / 2;
 	  pts[0].y = y;
diff -ru gtk+971025.old/gtk/testgtk.c gtk+971025/gtk/testgtk.c
--- gtk+971025.old/gtk/testgtk.c	Sun Oct 26 11:55:57 1997
+++ gtk+971025/gtk/testgtk.c	Sat Nov  1 19:06:31 1997
@@ -855,6 +855,9 @@
       sprintf (buf, "item %2d - %d", depth, j);
       menuitem = gtk_radio_menu_item_new_with_label (group, buf);
       group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
+      if (depth % 2)
+	gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menuitem), 
+					     TRUE);
       gtk_menu_append (GTK_MENU (menu), menuitem);
       gtk_widget_show (menuitem);
 


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