---
Hi,

I just propose a patch below, on gtk core, to illustrate the issue I will talk 
about. I have probably missed
how to derivate from GtkMenuItem properly to fit my use case.

While playing around a GtkStatusIcon, so with GtkMenuShell/GtkMenu and 
GtkMenuItem afterwards, I wanted to
get a new widget as a derivative of GtkMenuItem, let's say: a menu item 
proposing GtkSwitch called GtkSwitchMenuItem.
The main difference is that, the control below is fully async: until a reply 
has not come up,
it would set it as non sensitive, and then: depending on reply would set the 
right active value for the switch. That works, it's easy.

But in addition to that I want such behavior so the menu itself does not 
popdown when I click on a GtkSwitchMenuItem.
Looking at GtkMenuItem I saw this property hide_on_activate. Ok, by default it 
is set to true: I set it to false in my GtkSwitchMenuItem code.
Still no luck.

Went further in the code, and in gtkmenushell.c: gtk_menu_shell_activate_item() 
is supposed to take into account hide_on_activate property if
force_deactivate is FALSE. But in gtk_menu_shell_button_release() which is the 
function called when an item is clicked: it always
call gtk_menu_shell_activate_item() with force_deactivate set to TRUE (when the 
item has no submenu like my GtkSwitchMenuItem).

Due to that, whatever is the value of hide_on_activate, whatever does a 
replacement of GtkMenuItem activate function: the menu is always poped down.

So I quickly changed this TRUE to FALSE in 
gtkmenushell.c:gtk_menu_shell_button_release () for 
gtk_menu_shell_activate_item () and then: hide_on_activate
is taken care of properly, and I got the behavior I was expecting in setting 
hide_on_activate to FALSE.

I don't think it is a valid bug, since doing so: would make all 
GtkCheckMenuItem behaving like my GtkSwitchMenuItem. (see the patch below, 
witch remove the
hide_on_activate set to FALSE, it was just for testing). As you can expect: 
changing such property on GtkCheckMenuItem makes gtk_menu_shell_activate_item() 
behaving
always the same, whatever force_deactivate is. Which is probably wrong then.

So my question is: how to get this behavior for my GtkSwitchMenuItem, properly 
done with existing GtkMenuShell/GtkMenuItem functions/signals?
What signals should I catch or which function should I override? 

Thanks,

Tomasz

 gtk/gtkcheckmenuitem.c |    1 -
 gtk/gtkmenushell.c     |    2 +-
 2 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/gtk/gtkcheckmenuitem.c b/gtk/gtkcheckmenuitem.c
index 343565d..10bae0e 100644
--- a/gtk/gtkcheckmenuitem.c
+++ b/gtk/gtkcheckmenuitem.c
@@ -152,7 +152,6 @@ gtk_check_menu_item_class_init (GtkCheckMenuItemClass 
*klass)
   gtk_widget_class_set_accessible_type (widget_class, 
GTK_TYPE_CHECK_MENU_ITEM_ACCESSIBLE);
 
   menu_item_class->activate = gtk_check_menu_item_activate;
-  menu_item_class->hide_on_activate = FALSE;
   menu_item_class->toggle_size_request = 
gtk_check_menu_item_toggle_size_request;
   
   klass->toggled = NULL;
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index 5099179..0db79e5 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -827,7 +827,7 @@ gtk_menu_shell_button_release (GtkWidget      *widget,
 
               if (submenu == NULL)
                 {
-                  gtk_menu_shell_activate_item (menu_shell, menu_item, TRUE);
+                  gtk_menu_shell_activate_item (menu_shell, menu_item, FALSE);
                   deactivate = FALSE;
                 }
               else if (GTK_MENU_SHELL_GET_CLASS 
(menu_shell)->submenu_placement != GTK_TOP_BOTTOM ||
-- 
1.7.8.6

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to