patch #59456, #59456-2, #64977 -- menu stuff
- From: Kristian Rietveld <kristian planet nl>
- To: GTK Development list <gtk-devel-list gnome org>
- Subject: patch #59456, #59456-2, #64977 -- menu stuff
- Date: 27 Nov 2001 19:28:10 +0100
Hi all,
This patch implements some GtkMenu stuff, which makes the menu work
somewhat saner. ChangeLog has been appended, patch has been attached.
regards,
Kris
Tue Nov 27 18:52:34 2001 Kristian Rietveld <kristian planet nl>
* gtk/gtkmenu.c (gtk_menu_motion_notify): add checks for
empty menu items to behave like insensitive items (#59456)
* gtk/gtkmenuitem.c (gtk_real_menu_item_activate_item): select
next item if the first item in the menu is a tear off item
(#59456-2, suggestion by Matthias Clasen)
* gtk/gtkmenushell.c (gtk_menu_shell_button_press),
(gtk_menu_shell_button_release), (gtk_menu_shell_entry_notify),
(gtk_menu_shell_leave_notify),
(gtk_real_menu_shell_move_current),
(gtk_real_menu_shell_activate_current): add check, so empty
menu items behave like insensitive items
(gtk_menu_shell_is_selectable_menu_item): convenience function
for
the mentioned check (#59456)
* gtk/gtkmenushell.c (gtk_menu_shell_button_press),
(gtk_menu_shell_button_release): causes the menu to dropdown if
the
caption is clicked again (#64977)
Index: gtkmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.c,v
retrieving revision 1.76
diff -u -r1.76 gtkmenu.c
--- gtkmenu.c 2001/11/20 23:43:02 1.76
+++ gtkmenu.c 2001/11/27 17:43:44
@@ -33,6 +33,7 @@
#include "gtkmain.h"
#include "gtkmenu.h"
#include "gtkmenuitem.h"
+#include "gtkseparatormenuitem.h"
#include "gtksignal.h"
#include "gtkwindow.h"
#include "gtkhbox.h"
@@ -1716,7 +1717,11 @@
* which may be different from 'widget'.
*/
menu_item = gtk_get_event_widget ((GdkEvent*) event);
- if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) || !GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+ if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) ||
+ !GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+ (!GTK_BIN (menu_item)->child &&
+ G_OBJECT_TYPE (menu_item) == GTK_TYPE_MENU_ITEM) ||
+ GTK_IS_SEPARATOR_MENU_ITEM (menu_item) ||
!GTK_IS_MENU (menu_item->parent))
return FALSE;
Index: gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.62
diff -u -r1.62 gtkmenuitem.c
--- gtkmenuitem.c 2001/11/17 23:28:50 1.62
+++ gtkmenuitem.c 2001/11/27 17:43:45
@@ -31,6 +31,7 @@
#include "gtkmenu.h"
#include "gtkmenubar.h"
#include "gtkmenuitem.h"
+#include "gtktearoffmenuitem.h"
#include "gtksignal.h"
@@ -757,7 +758,13 @@
submenu = GTK_MENU_SHELL (menu_item->submenu);
if (submenu->children)
- gtk_menu_shell_select_item (submenu, submenu->children->data);
+ {
+ if (submenu->children->next &&
+ GTK_IS_TEAROFF_MENU_ITEM (submenu->children->data))
+ gtk_menu_shell_select_item (submenu, submenu->children->next->data);
+ else
+ gtk_menu_shell_select_item (submenu, submenu->children->data);
+ }
}
}
}
Index: gtkmenushell.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenushell.c,v
retrieving revision 1.49
diff -u -r1.49 gtkmenushell.c
--- gtkmenushell.c 2001/11/24 21:05:10 1.49
+++ gtkmenushell.c 2001/11/27 17:43:46
@@ -30,6 +30,7 @@
#include "gtkmarshalers.h"
#include "gtkmenuitem.h"
#include "gtktearoffmenuitem.h" /* FIXME */
+#include "gtkseparatormenuitem.h"
#include "gtkmenushell.h"
#include "gtksignal.h"
#include "gtkwindow.h"
@@ -147,6 +148,7 @@
static void gtk_real_menu_shell_activate_current (GtkMenuShell *menu_shell,
gboolean force_hide);
static void gtk_real_menu_shell_cancel (GtkMenuShell *menu_shell);
+static gboolean gtk_menu_shell_is_selectable_menu_item (GtkWidget *menu_item);
static GtkContainerClass *parent_class = NULL;
static guint menu_shell_signals[LAST_SIGNAL] = { 0 };
@@ -412,11 +414,19 @@
menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent *)event);
if (menu_item &&
- GTK_WIDGET_IS_SENSITIVE (menu_item))
+ (GTK_WIDGET_IS_SENSITIVE (menu_item) &&
+ gtk_menu_shell_is_selectable_menu_item (menu_item)))
{
if ((menu_item->parent == widget) &&
(menu_item != menu_shell->active_menu_item))
- gtk_menu_shell_select_item (menu_shell, menu_item);
+ {
+ if (menu_item &&
+ GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement == GTK_TOP_BOTTOM)
+ gtk_object_set_data (GTK_OBJECT (menu_shell),
+ "gtk-menushell-just-activated",
+ 0x1);
+ gtk_menu_shell_select_item (menu_shell, menu_item);
+ }
}
}
else
@@ -460,8 +470,24 @@
if ((event->time - menu_shell->activate_time) > MENU_SHELL_TIMEOUT)
{
+ if (menu_item &&
+ GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement == GTK_TOP_BOTTOM)
+ {
+ if (gtk_object_get_data (GTK_OBJECT (menu_shell), "gtk-menushell-just-activated") == 0x1)
+ {
+ gtk_object_remove_data (GTK_OBJECT (menu_shell), "gtk-menushell-just-activated");
+ }
+ else
+ {
+ gtk_menu_shell_deactivate (menu_shell);
+ /* we didn't do a selection -> don't emit a signal */
+ return TRUE;
+ }
+ }
+
if (menu_item && (menu_shell->active_menu_item == menu_item) &&
- GTK_WIDGET_IS_SENSITIVE (menu_item))
+ (GTK_WIDGET_IS_SENSITIVE (menu_item) &&
+ gtk_menu_shell_is_selectable_menu_item (menu_item)))
{
if (GTK_MENU_ITEM (menu_item)->submenu == NULL)
{
@@ -469,7 +495,9 @@
return TRUE;
}
}
- else if (menu_item && !GTK_WIDGET_IS_SENSITIVE (menu_item))
+ else if (menu_item &&
+ (!GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+ !gtk_menu_shell_is_selectable_menu_item (menu_item)))
deactivate = FALSE;
else if (menu_shell->parent_menu_shell)
{
@@ -562,7 +590,9 @@
{
menu_item = gtk_get_event_widget ((GdkEvent*) event);
- if (!menu_item || !GTK_WIDGET_IS_SENSITIVE (menu_item))
+ if (!menu_item || !GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+ (GTK_IS_MENU_ITEM (menu_item) &&
+ !gtk_menu_shell_is_selectable_menu_item (menu_item)))
return TRUE;
if ((menu_item->parent == widget) &&
@@ -614,7 +644,8 @@
return TRUE;
}
- if (!GTK_WIDGET_IS_SENSITIVE (menu_item))
+ if (!GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+ !gtk_menu_shell_is_selectable_menu_item (event_widget))
return TRUE;
if ((menu_shell->active_menu_item == event_widget) &&
@@ -785,7 +816,7 @@
GtkWidget *menu_item)
{
gtk_menu_shell_deselect (menu_shell);
-
+
menu_shell->active_menu_item = menu_item;
_gtk_menu_item_set_placement (GTK_MENU_ITEM (menu_shell->active_menu_item),
GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement);
@@ -876,7 +907,8 @@
while (node != start_node &&
(!node ||
!GTK_WIDGET_IS_SENSITIVE (node->data) ||
- !GTK_WIDGET_VISIBLE (node->data) ))
+ !GTK_WIDGET_VISIBLE (node->data) ||
+ !gtk_menu_shell_is_selectable_menu_item (node->data)))
{
if (!node)
node = menu_shell->children;
@@ -890,7 +922,8 @@
while (node != start_node &&
(!node ||
!GTK_WIDGET_IS_SENSITIVE (node->data) ||
- !GTK_WIDGET_VISIBLE (node->data) ))
+ !GTK_WIDGET_VISIBLE (node->data) ||
+ !gtk_menu_shell_is_selectable_menu_item (node->data)))
{
if (!node)
node = g_list_last (menu_shell->children);
@@ -949,7 +982,7 @@
case GTK_MENU_DIR_CHILD:
if (menu_shell->active_menu_item &&
- GTK_BIN (menu_shell->active_menu_item)->child &&
+ gtk_menu_shell_is_selectable_menu_item (menu_shell->active_menu_item) &&
GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu)
{
menu_shell = GTK_MENU_SHELL (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu);
@@ -996,6 +1029,7 @@
{
if (menu_shell->active_menu_item &&
GTK_WIDGET_IS_SENSITIVE (menu_shell->active_menu_item) &&
+ gtk_menu_shell_is_selectable_menu_item (menu_shell->active_menu_item) &&
GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu == NULL)
{
gtk_menu_shell_activate_item (menu_shell,
@@ -1015,3 +1049,13 @@
gtk_signal_emit (GTK_OBJECT (menu_shell), menu_shell_signals[SELECTION_DONE]);
}
+static gboolean
+gtk_menu_shell_is_selectable_menu_item (GtkWidget *menu_item)
+{
+ if ((!GTK_BIN (menu_item)->child &&
+ G_OBJECT_TYPE (menu_item) == GTK_TYPE_MENU_ITEM) ||
+ GTK_IS_SEPARATOR_MENU_ITEM (menu_item))
+ return FALSE;
+
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]