diff --git a/ChangeLog b/ChangeLog index c6c6972715..e826a87c6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index c6c6972715..e826a87c6f 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index c6c6972715..e826a87c6f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index c6c6972715..e826a87c6f 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index c6c6972715..e826a87c6f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index c6c6972715..e826a87c6f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index c6c6972715..e826a87c6f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,64 @@ +2000-11-08 Alexander Larsson + + * docs/Changes-2.0.txt: Add note about GtkMenuPositionFunc + API changes. + + * gtk/gtkmenu.c: Add support for scrolling menus. + Remove gtk_menu_append/prepend/insert, these have been moved to + gtkcompat.h as #defines. + + * gtk/gtkcompat.h.in: + Add compatibility #defines for gtk_menu_append/prepend/insert + + * gtk/gtkmenu.h: Add data needed for scrolling menus. + GtkMenuPositionFunc gets an extra argument push_in. + gtk_menu_append/prepend/insert removed. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Change menu + positioning behaviour to fit to scrolling menus. + + * gtk/gtkmenuitem.c (gtk_menu_item_forall): Don't recurse + into menuitem->submeny. That is wrong, and broke torn + off submenus of torn off menus, since they were unrealized + when the first menu was unrealized. + + * gtk/gtkmenushell.[ch]: Virtualize gtk_menu_shell_insert() and + gtk_menu_shell_select_item() since these need to be overridden in + GtkMenu. + + * gtk/gtkoptionmenu.c (gtk_opttion_menu_position): Change menu + positioning behaviour to fit to scrolling menus. + (gtk_option_menu_key_press, gtk_option_menu_button_press): Select + the current item so that it is prelighted when the menu pops up. + This is a workaround to the fact that the menu doesn't get the + initial enter event (due to grabs). + + * gtk/gtkfilesel.c, gtk/gtkinputdialog.c, gtk/testgtk.c: + s/gtk_menu_append/gtk_menu_shell_append/ + + * gtk/gtknotebook.c: + s/gtk_menu_insert/gtk_menu_shell_insert/ + + * gtk/testgtk.c (create_menu, create_menus): + Create the first menu with 50 items so that menu scrolling + can be tested. + + + Patch from Jonathan Blandford + + * gtk/gtkmenuitem.[ch] (gtk_menu_item_toggle_size_request): new + system to handle size requests. First, we ask what the size of + the toggle is. Then, when allocating the size, we allocate the + toggle_size first. This way we can have multiple menu-item + classes w/o needing a seperate class for each. + + * gtk/gtkmenu.c (gtk_menu_size_request): Actually use the new system. + * gtk/gtkmenu.c (gtk_menu_size_allocate): Use the new system. + + * gtk/gtkcheckmenuitem.c + (gtk_check_menu_item_toggle_size_request): New function to handle + the toggle size-request. + 2000-11-07 Havoc Pennington * gtk/gtktextlayout.c (gtk_text_layout_get_iter_location): diff --git a/docs/Changes-2.0.txt b/docs/Changes-2.0.txt index c6460a6c1a..e45d331a6f 100644 --- a/docs/Changes-2.0.txt +++ b/docs/Changes-2.0.txt @@ -256,3 +256,14 @@ Incompatible Changes from GTK+-1.2 to GTK+-2.0: GtkProgressBarOrientation orientation); +- GtkMenuPositionFunc has a new parameter push_in which controls how + menus placed outside the screen is handled. If this is set to true and + part of the menu is outside the screen then Gtk+ pushes it into the visible + area. Otherwise the menu is cut of at the end of the visible screen area. + + Regardles of what happens to the size of the menu, the result is always + that the items are placed in the same place as if the menu was placed + outside the screen, using menu scrolling if necessary. + + + diff --git a/gtk/gtkcheckmenuitem.c b/gtk/gtkcheckmenuitem.c index 3d3b707e24..cf6a517e88 100644 --- a/gtk/gtkcheckmenuitem.c +++ b/gtk/gtkcheckmenuitem.c @@ -28,7 +28,7 @@ #include "gtkaccellabel.h" #include "gtksignal.h" - +#define CHECK_TOGGLE_SIZE 12 enum { TOGGLED, @@ -36,17 +36,19 @@ enum { }; -static void gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass); -static void gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item); -static void gtk_check_menu_item_draw (GtkWidget *widget, - GdkRectangle *area); -static gint gtk_check_menu_item_expose (GtkWidget *widget, - GdkEventExpose *event); -static void gtk_check_menu_item_activate (GtkMenuItem *menu_item); -static void gtk_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, - GdkRectangle *area); -static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, - GdkRectangle *area); +static void gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass); +static void gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item); +static void gtk_check_menu_item_draw (GtkWidget *widget, + GdkRectangle *area); +static gint gtk_check_menu_item_expose (GtkWidget *widget, + GdkEventExpose *event); +static void gtk_check_menu_item_activate (GtkMenuItem *menu_item); +static void gtk_check_menu_item_toggle_size_request (GtkMenuItem *menu_item, + guint16 *requisition); +static void gtk_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, + GdkRectangle *area); +static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, + GdkRectangle *area); static GtkMenuItemClass *parent_class = NULL; @@ -95,8 +97,8 @@ gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass) widget_class->expose_event = gtk_check_menu_item_expose; menu_item_class->activate = gtk_check_menu_item_activate; - menu_item_class->toggle_size = 12; menu_item_class->hide_on_activate = FALSE; + menu_item_class->toggle_size_request = gtk_check_menu_item_toggle_size_request; klass->toggled = NULL; klass->draw_indicator = gtk_real_check_menu_item_draw_indicator; @@ -147,6 +149,16 @@ gtk_check_menu_item_set_active (GtkCheckMenuItem *check_menu_item, gtk_menu_item_activate (GTK_MENU_ITEM (check_menu_item)); } +static void +gtk_check_menu_item_toggle_size_request (GtkMenuItem *menu_item, + guint16 *requisition) +{ + g_return_if_fail (menu_item != NULL); + g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (menu_item)); + + *requisition = CHECK_TOGGLE_SIZE; +} + void gtk_check_menu_item_set_show_toggle (GtkCheckMenuItem *menu_item, gboolean always) diff --git a/gtk/gtkcompat.h.in b/gtk/gtkcompat.h.in index 84eaf17b93..0b33f1fbb8 100644 --- a/gtk/gtkcompat.h.in +++ b/gtk/gtkcompat.h.in @@ -71,6 +71,9 @@ extern "C" { #define gtk_window_position gtk_window_set_position #define gtk_toggle_button_set_state gtk_toggle_button_set_active #define gtk_check_menu_item_set_state gtk_check_menu_item_set_active +#define gtk_menu_append gtk_menu_shell_append +#define gtk_menu_prepend gtk_menu_shell_prepend +#define gtk_menu_insert gtk_menu_shell_insert /* strongly deprecated, very likely to be removed in the future: diff --git a/gtk/gtkfilesel.c b/gtk/gtkfilesel.c index ae80fbf0d6..c58c6a167c 100644 --- a/gtk/gtkfilesel.c +++ b/gtk/gtkfilesel.c @@ -1341,7 +1341,7 @@ gtk_file_selection_update_history_menu (GtkFileSelection *fs, gtk_signal_connect (GTK_OBJECT (menu_item), "activate", (GtkSignalFunc) gtk_file_selection_history_callback, (gpointer) fs); - gtk_menu_append (GTK_MENU (fs->history_menu), menu_item); + gtk_menu_shell_append (GTK_MENU_SHELL (fs->history_menu), menu_item); gtk_widget_show (menu_item); } } diff --git a/gtk/gtkinputdialog.c b/gtk/gtkinputdialog.c index cf0e969098..8732921893 100644 --- a/gtk/gtkinputdialog.c +++ b/gtk/gtkinputdialog.c @@ -207,8 +207,8 @@ gtk_input_dialog_init (GtkInputDialog *inputd) { menuitem = gtk_menu_item_new_with_label(info->name); - gtk_menu_append(GTK_MENU(device_menu),menuitem); - gtk_widget_show(menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (device_menu), menuitem); + gtk_widget_show (menuitem); gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", (GtkSignalFunc) gtk_input_dialog_set_device, @@ -236,25 +236,25 @@ gtk_input_dialog_init (GtkInputDialog *inputd) mapping_menu = gtk_menu_new (); menuitem = gtk_menu_item_new_with_label(_("Disabled")); - gtk_menu_append(GTK_MENU(mapping_menu),menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (mapping_menu), menuitem); gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); - gtk_widget_show(menuitem); + gtk_widget_show (menuitem); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", (GtkSignalFunc) gtk_input_dialog_set_mapping_mode, GINT_TO_POINTER (GDK_MODE_DISABLED)); menuitem = gtk_menu_item_new_with_label(_("Screen")); - gtk_menu_append(GTK_MENU(mapping_menu),menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (mapping_menu), menuitem); gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); - gtk_widget_show(menuitem); + gtk_widget_show (menuitem); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", (GtkSignalFunc) gtk_input_dialog_set_mapping_mode, GINT_TO_POINTER (GDK_MODE_SCREEN)); menuitem = gtk_menu_item_new_with_label(_("Window")); - gtk_menu_append(GTK_MENU(mapping_menu),menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (mapping_menu), menuitem); gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); - gtk_widget_show(menuitem); + gtk_widget_show (menuitem); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", (GtkSignalFunc) gtk_input_dialog_set_mapping_mode, GINT_TO_POINTER (GDK_MODE_WINDOW)); @@ -524,7 +524,7 @@ gtk_input_dialog_fill_axes(GtkInputDialog *inputd, GdkDevice *info) (GtkSignalFunc) gtk_input_dialog_set_axis, GINT_TO_POINTER (0x10000 * (j + 1) + i)); gtk_widget_show (menu_item); - gtk_menu_append (GTK_MENU (menu), menu_item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); } inputd->axis_items[i] = option_menu = gtk_option_menu_new (); diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index 9d3d5e36b3..7d3f2e879b 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -33,6 +33,8 @@ #include "gtkmenuitem.h" #include "gtksignal.h" #include "gtkwindow.h" +#include "gtkhbox.h" +#include "gtkvscrollbar.h" #define MENU_ITEM_CLASS(w) GTK_MENU_ITEM_GET_CLASS (w) @@ -41,6 +43,12 @@ #define SUBMENU_NAV_REGION_PADDING 2 #define SUBMENU_NAV_HYSTERESIS_TIMEOUT 333 +#define MENU_SCROLL_STEP 10 +#define MENU_SCROLL_ARROW_HEIGHT 16 +#define MENU_SCROLL_FAST_ZONE 4 +#define MENU_SCROLL_TIMEOUT1 150 +#define MENU_SCROLL_TIMEOUT2 50 + typedef struct _GtkMenuAttachData GtkMenuAttachData; struct _GtkMenuAttachData @@ -50,27 +58,43 @@ struct _GtkMenuAttachData }; -static void gtk_menu_class_init (GtkMenuClass *klass); -static void gtk_menu_init (GtkMenu *menu); -static void gtk_menu_destroy (GtkObject *object); -static void gtk_menu_realize (GtkWidget *widget); -static void gtk_menu_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void gtk_menu_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void gtk_menu_paint (GtkWidget *widget); -static void gtk_menu_draw (GtkWidget *widget, - GdkRectangle *area); -static gboolean gtk_menu_expose (GtkWidget *widget, - GdkEventExpose *event); -static gboolean gtk_menu_key_press (GtkWidget *widget, - GdkEventKey *event); -static gboolean gtk_menu_motion_notify (GtkWidget *widget, - GdkEventMotion *event); -static gboolean gtk_menu_enter_notify (GtkWidget *widget, - GdkEventCrossing *event); -static gboolean gtk_menu_leave_notify (GtkWidget *widget, - GdkEventCrossing *event); +static void gtk_menu_class_init (GtkMenuClass *klass); +static void gtk_menu_init (GtkMenu *menu); +static void gtk_menu_destroy (GtkObject *object); +static void gtk_menu_realize (GtkWidget *widget); +static void gtk_menu_unrealize (GtkWidget *widget); +static void gtk_menu_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static void gtk_menu_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static void gtk_menu_paint (GtkWidget *widget); +static void gtk_menu_draw (GtkWidget *widget, + GdkRectangle *area); +static gboolean gtk_menu_expose (GtkWidget *widget, + GdkEventExpose *event); +static gboolean gtk_menu_key_press (GtkWidget *widget, + GdkEventKey *event); +static gboolean gtk_menu_motion_notify (GtkWidget *widget, + GdkEventMotion *event); +static gboolean gtk_menu_enter_notify (GtkWidget *widget, + GdkEventCrossing *event); +static gboolean gtk_menu_leave_notify (GtkWidget *widget, + GdkEventCrossing *event); +static void gtk_menu_scroll_to (GtkMenu *menu, + gint offset); +static void gtk_menu_stop_scrolling (GtkMenu *menu); +static gboolean gtk_menu_scroll_timeout (gpointer data); +static void gtk_menu_select_item (GtkMenuShell *menu_shell, + GtkWidget *menu_item); +static void gtk_menu_insert (GtkMenuShell *menu_shell, + GtkWidget *child, + gint position); +static void gtk_menu_scrollbar_changed (GtkAdjustment *adjustment, + GtkMenu *menu); +static void gtk_menu_handle_scrolling (GtkMenu *menu, + gboolean enter); +static void gtk_menu_set_tearoff_hints (GtkMenu *menu, + gint width); static void gtk_menu_stop_navigating_submenu (GtkMenu *menu); static gboolean gtk_menu_stop_navigating_submenu_cb (gpointer user_data); @@ -137,6 +161,7 @@ gtk_menu_class_init (GtkMenuClass *class) object_class->destroy = gtk_menu_destroy; widget_class->realize = gtk_menu_realize; + widget_class->unrealize = gtk_menu_unrealize; widget_class->draw = gtk_menu_draw; widget_class->size_request = gtk_menu_size_request; widget_class->size_allocate = gtk_menu_size_allocate; @@ -150,6 +175,8 @@ gtk_menu_class_init (GtkMenuClass *class) menu_shell_class->submenu_placement = GTK_LEFT_RIGHT; menu_shell_class->deactivate = gtk_menu_deactivate; + menu_shell_class->select_item = gtk_menu_select_item; + menu_shell_class->insert = gtk_menu_insert; binding_set = gtk_binding_set_by_class (class); gtk_binding_entry_add_signal (binding_set, @@ -188,8 +215,7 @@ gtk_menu_window_event (GtkWidget *window, { case GDK_KEY_PRESS: case GDK_KEY_RELEASE: - gtk_widget_event (menu, event); - handled = TRUE; + handled = gtk_widget_event (menu, event); break; default: break; @@ -209,6 +235,7 @@ gtk_menu_init (GtkMenu *menu) menu->accel_group = NULL; menu->position_func = NULL; menu->position_func_data = NULL; + menu->toggle_size = 0; menu->toplevel = gtk_widget_new (GTK_TYPE_WINDOW, "type", GTK_WINDOW_POPUP, @@ -225,9 +252,26 @@ gtk_menu_init (GtkMenu *menu) GTK_WIDGET_SET_FLAGS (menu, GTK_FLOATING); menu->needs_destruction_ref_count = TRUE; - menu->tearoff_window = NULL; - menu->torn_off = FALSE; + menu->view_window = NULL; + menu->bin_window = NULL; + menu->scroll_offset = 0; + menu->scroll_step = 0; + menu->timeout_id = 0; + menu->scroll_fast = FALSE; + + menu->tearoff_window = NULL; + menu->tearoff_hbox = NULL; + menu->torn_off = FALSE; + menu->tearoff_active = FALSE; + menu->tearoff_adjustment = NULL; + menu->tearoff_scrollbar = NULL; + + menu->upper_arrow_visible = FALSE; + menu->lower_arrow_visible = FALSE; + menu->upper_arrow_prelight = FALSE; + menu->lower_arrow_prelight = FALSE; + MENU_NEEDS_RESIZE (menu) = TRUE; } @@ -236,10 +280,12 @@ gtk_menu_destroy (GtkObject *object) { GtkMenu *menu; GtkMenuAttachData *data; - + g_return_if_fail (GTK_IS_MENU (object)); menu = GTK_MENU (object); + + gtk_menu_stop_scrolling (menu); data = gtk_object_get_data (object, attach_data_key); if (data) @@ -359,32 +405,21 @@ gtk_menu_new (void) return GTK_WIDGET (gtk_type_new (gtk_menu_get_type ())); } -void -gtk_menu_append (GtkMenu *menu, - GtkWidget *child) +static void +gtk_menu_insert (GtkMenuShell *menu_shell, + GtkWidget *child, + gint position) { - gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); -} - -void -gtk_menu_prepend (GtkMenu *menu, - GtkWidget *child) -{ - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), child); -} - -void -gtk_menu_insert (GtkMenu *menu, - GtkWidget *child, - gint position) -{ - gtk_menu_shell_insert (GTK_MENU_SHELL (menu), child, position); + GTK_MENU_SHELL_CLASS (parent_class)->insert (menu_shell, child, position); + + gtk_widget_set_parent_window (child, GTK_MENU (menu_shell)->bin_window); } static void gtk_menu_tearoff_bg_copy (GtkMenu *menu) { GtkWidget *widget; + gint width, height; widget = GTK_WIDGET (menu); @@ -393,25 +428,30 @@ gtk_menu_tearoff_bg_copy (GtkMenu *menu) GdkPixmap *pixmap; GdkGC *gc; GdkGCValues gc_values; + + menu->tearoff_active = FALSE; + menu->saved_scroll_offset = menu->scroll_offset; gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS; gc = gdk_gc_new_with_values (widget->window, &gc_values, GDK_GC_SUBWINDOW); - pixmap = gdk_pixmap_new (widget->window, - widget->requisition.width, - widget->requisition.height, + gdk_window_get_size (menu->tearoff_window->window, &width, &height); + + pixmap = gdk_pixmap_new (menu->tearoff_window->window, + width, + height, -1); gdk_draw_pixmap (pixmap, gc, - widget->window, + menu->tearoff_window->window, 0, 0, 0, 0, -1, -1); gdk_gc_unref (gc); - + gtk_widget_set_usize (menu->tearoff_window, - widget->requisition.width, - widget->requisition.height); - + width, + height); + gdk_window_set_back_pixmap (menu->tearoff_window->window, pixmap, FALSE); gdk_pixmap_unref (pixmap); } @@ -431,7 +471,7 @@ gtk_menu_popup (GtkMenu *menu, GtkWidget *parent; GdkEvent *current_event; GtkMenuShell *menu_shell; - + g_return_if_fail (menu != NULL); g_return_if_fail (GTK_IS_MENU (menu)); @@ -460,10 +500,7 @@ gtk_menu_popup (GtkMenu *menu, { gtk_menu_tearoff_bg_copy (menu); - /* We force an unrealize here so that we don't trigger redrawing/ - * clearing code - we just want to reveal our backing pixmap. - */ - gtk_menu_reparent (menu, menu->toplevel, TRUE); + gtk_menu_reparent (menu, menu->toplevel, FALSE); } menu->parent_menu_item = parent_menu_item; @@ -479,7 +516,7 @@ gtk_menu_popup (GtkMenu *menu, */ gtk_widget_show (GTK_WIDGET (menu)); gtk_widget_show (menu->toplevel); - + /* Find the last viewable ancestor, and make an X grab on it */ parent = GTK_WIDGET (menu); @@ -526,7 +563,9 @@ gtk_menu_popup (GtkMenu *menu, gdk_cursor_destroy (cursor); } - + + gtk_menu_scroll_to (menu, menu->scroll_offset); + gtk_grab_add (GTK_WIDGET (menu)); } @@ -534,7 +573,7 @@ void gtk_menu_popdown (GtkMenu *menu) { GtkMenuShell *menu_shell; - + g_return_if_fail (menu != NULL); g_return_if_fail (GTK_IS_MENU (menu)); @@ -543,6 +582,8 @@ gtk_menu_popdown (GtkMenu *menu) menu_shell->parent_menu_shell = NULL; menu_shell->active = FALSE; menu_shell->ignore_enter = FALSE; + + gtk_menu_stop_scrolling (menu); gtk_menu_stop_navigating_submenu (menu); @@ -562,9 +603,15 @@ gtk_menu_popdown (GtkMenu *menu) if (menu->torn_off) { + gint width, height; + gdk_window_get_size (menu->tearoff_window->window, &width, &height); + gtk_widget_set_usize (menu->tearoff_window, + -1, + height); + if (GTK_BIN (menu->toplevel)->child) { - gtk_menu_reparent (menu, menu->tearoff_window, FALSE); + gtk_menu_reparent (menu, menu->tearoff_hbox, TRUE); } else { @@ -577,6 +624,14 @@ gtk_menu_popdown (GtkMenu *menu) gdk_keyboard_ungrab (GDK_CURRENT_TIME); } } + + /* gtk_menu_popdown is called each time a menu item is selected from + * a torn off menu. Only scroll back to the saved position if the + * non-tearoff menu was popped down. + */ + if (!menu->tearoff_active) + gtk_menu_scroll_to (menu, menu->saved_scroll_offset); + menu->tearoff_active = TRUE; } else gtk_widget_hide (GTK_WIDGET (menu)); @@ -707,17 +762,51 @@ gtk_menu_reposition (GtkMenu *menu) gtk_menu_position (menu); } +static void +gtk_menu_scrollbar_changed (GtkAdjustment *adjustment, + GtkMenu *menu) +{ + g_return_if_fail (menu != NULL); + g_return_if_fail (GTK_IS_MENU (menu)); + + if (adjustment->value != menu->scroll_offset) + gtk_menu_scroll_to (menu, adjustment->value); +} + +static void +gtk_menu_set_tearoff_hints(GtkMenu *menu, + gint width) +{ + GdkGeometry geometry_hints; + + if (!menu->tearoff_window) + return; + + geometry_hints.min_width = width; + geometry_hints.max_width = width; + + geometry_hints.min_height = 0; + geometry_hints.max_height = GTK_WIDGET (menu)->requisition.height; + gtk_window_set_geometry_hints (GTK_WINDOW (menu->tearoff_window), + NULL, + &geometry_hints, + GDK_HINT_MAX_SIZE|GDK_HINT_MIN_SIZE); +} + void gtk_menu_set_tearoff_state (GtkMenu *menu, gboolean torn_off) { + gint width, height; + g_return_if_fail (menu != NULL); g_return_if_fail (GTK_IS_MENU (menu)); if (menu->torn_off != torn_off) { menu->torn_off = torn_off; + menu->tearoff_active = torn_off; if (menu->torn_off) { @@ -762,13 +851,49 @@ gtk_menu_set_tearoff_state (GtkMenu *menu, GDK_DECOR_MAXIMIZE); gtk_window_set_policy (GTK_WINDOW (menu->tearoff_window), FALSE, FALSE, TRUE); - } - gtk_menu_reparent (menu, menu->tearoff_window, FALSE); + menu->tearoff_hbox = gtk_hbox_new (FALSE, FALSE); + gtk_container_add (GTK_CONTAINER (menu->tearoff_window), menu->tearoff_hbox); + + gdk_window_get_size (GTK_WIDGET (menu)->window, &width, &height); + menu->tearoff_adjustment = + GTK_ADJUSTMENT (gtk_adjustment_new (0, + 0, + GTK_WIDGET (menu)->requisition.height, + MENU_SCROLL_STEP, + height/2, + height)); + gtk_signal_connect (GTK_OBJECT (menu->tearoff_adjustment), "value_changed", + gtk_menu_scrollbar_changed, + menu); + menu->tearoff_scrollbar = gtk_vscrollbar_new (menu->tearoff_adjustment); + + gtk_box_pack_end (GTK_BOX (menu->tearoff_hbox), + menu->tearoff_scrollbar, + FALSE, FALSE, 0); + + if (menu->tearoff_adjustment->upper > height) + gtk_widget_show (menu->tearoff_scrollbar); + + gtk_widget_show (menu->tearoff_hbox); + } + + gtk_menu_reparent (menu, menu->tearoff_hbox, FALSE); + + gdk_window_get_size (GTK_WIDGET (menu)->window, &width, &height); + if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar)) + width += menu->tearoff_scrollbar->requisition.width; + + gtk_menu_set_tearoff_hints (menu, width); + + gtk_widget_realize (menu->tearoff_window); gtk_menu_position (menu); gtk_widget_show (GTK_WIDGET (menu)); gtk_widget_show (menu->tearoff_window); + + gtk_menu_scroll_to (menu, 0); + } else { @@ -812,9 +937,15 @@ gtk_menu_realize (GtkWidget *widget) { GdkWindowAttr attributes; gint attributes_mask; - + gint border_width; + GtkMenu *menu; + GtkWidget *child; + GList *children; + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_MENU (widget)); + + menu = GTK_MENU (widget); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); @@ -826,16 +957,79 @@ gtk_menu_realize (GtkWidget *widget) attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); + attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK); + attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK | + GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK ); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, widget); + border_width = GTK_CONTAINER (widget)->border_width; + + attributes.x = border_width + widget->style->xthickness; + attributes.y = border_width + widget->style->ythickness; + attributes.width = MAX (1, widget->allocation.width - attributes.x * 2); + attributes.height = MAX (1, widget->allocation.height - attributes.y * 2); + + if (menu->upper_arrow_visible) + { + attributes.y += MENU_SCROLL_ARROW_HEIGHT; + attributes.height -= MENU_SCROLL_ARROW_HEIGHT; + } + if (menu->lower_arrow_visible) + attributes.height -= MENU_SCROLL_ARROW_HEIGHT; + + menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask); + gdk_window_set_user_data (menu->view_window, menu); + + attributes.x = 0; + attributes.y = 0; + attributes.height = MAX (1, widget->requisition.height - (border_width + widget->style->ythickness) * 2); + + menu->bin_window = gdk_window_new (menu->view_window, &attributes, attributes_mask); + gdk_window_set_user_data (menu->bin_window, menu); + + children = GTK_MENU_SHELL (menu)->children; + while (children) + { + child = children->data; + children = children->next; + + gtk_widget_set_parent_window (child, menu->bin_window); + } + widget->style = gtk_style_attach (widget->style, widget->window); + gtk_style_set_background (widget->style, menu->bin_window, GTK_STATE_NORMAL); + gtk_style_set_background (widget->style, menu->view_window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); - gtk_menu_paint(widget); + + gtk_menu_paint (widget); + + gdk_window_show (menu->bin_window); + gdk_window_show (menu->view_window); +} + +static void +gtk_menu_unrealize (GtkWidget *widget) +{ + GtkMenu *menu; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_MENU (widget)); + + menu = GTK_MENU (widget); + + gdk_window_set_user_data (menu->view_window, NULL); + gdk_window_destroy (menu->view_window); + menu->view_window = NULL; + + gdk_window_set_user_data (menu->bin_window, NULL); + gdk_window_destroy (menu->bin_window); + menu->bin_window = NULL; + + (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); } static void @@ -849,6 +1043,7 @@ gtk_menu_size_request (GtkWidget *widget, guint max_toggle_size; guint max_accel_width; GtkRequisition child_requisition; + gint width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_MENU (widget)); @@ -871,13 +1066,16 @@ gtk_menu_size_request (GtkWidget *widget, if (GTK_WIDGET_VISIBLE (child)) { + guint16 toggle_size; + GTK_MENU_ITEM (child)->show_submenu_indicator = TRUE; gtk_widget_size_request (child, &child_requisition); requisition->width = MAX (requisition->width, child_requisition.width); requisition->height += child_requisition.height; - - max_toggle_size = MAX (max_toggle_size, MENU_ITEM_CLASS (child)->toggle_size); + + gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child), &toggle_size); + max_toggle_size = MAX (max_toggle_size, toggle_size); max_accel_width = MAX (max_accel_width, GTK_MENU_ITEM (child)->accelerator_width); } } @@ -888,13 +1086,18 @@ gtk_menu_size_request (GtkWidget *widget, requisition->height += (GTK_CONTAINER (menu)->border_width + widget->style->ythickness) * 2; - children = menu_shell->children; - while (children) + menu->toggle_size = max_toggle_size; + + /* If the requested width was different than the allocated width, we need to change + * the geometry hints for the tear off window so that the window can actually be resized. + * Don't resize the tearoff if it is not active, beacuse it won't redraw (it is only a background pixmap). + */ + if ((requisition->width != GTK_WIDGET (menu)->allocation.width) && menu->tearoff_active) { - child = children->data; - children = children->next; - - GTK_MENU_ITEM (child)->toggle_size = max_toggle_size; + width = requisition->width; + if (menu->tearoff_scrollbar && GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar)) + width += menu->tearoff_scrollbar->requisition.width; + gtk_menu_set_tearoff_hints (menu, width); } } @@ -907,28 +1110,51 @@ gtk_menu_size_allocate (GtkWidget *widget, GtkWidget *child; GtkAllocation child_allocation; GList *children; - + gint x, y; + gint width, height; + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_MENU (widget)); g_return_if_fail (allocation != NULL); menu = GTK_MENU (widget); menu_shell = GTK_MENU_SHELL (widget); - - widget->allocation = *allocation; - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); + widget->allocation = *allocation; + + x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness; + y = GTK_CONTAINER (menu)->border_width + widget->style->ythickness; + + width = MAX (1, allocation->width - x * 2); + height = MAX (1, allocation->height - y * 2); + + if (menu->upper_arrow_visible && !menu->tearoff_active) + { + y += MENU_SCROLL_ARROW_HEIGHT; + height -= MENU_SCROLL_ARROW_HEIGHT; + } + + if (menu->lower_arrow_visible && !menu->tearoff_active) + height -= MENU_SCROLL_ARROW_HEIGHT; + + if (GTK_WIDGET_REALIZED (widget)) + { + gdk_window_move_resize (widget->window, + allocation->x, allocation->y, + allocation->width, allocation->height); + + gdk_window_move_resize (menu->view_window, + x, + y, + width, + height); + } if (menu_shell->children) { - child_allocation.x = (GTK_CONTAINER (menu)->border_width + - widget->style->xthickness); - child_allocation.y = (GTK_CONTAINER (menu)->border_width + - widget->style->ythickness); - child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2); + child_allocation.x = 0; + child_allocation.y = 0; + child_allocation.width = width; children = menu_shell->children; while (children) @@ -942,21 +1168,81 @@ gtk_menu_size_allocate (GtkWidget *widget, gtk_widget_get_child_requisition (child, &child_requisition); child_allocation.height = child_requisition.height; - + + gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), + menu->toggle_size); gtk_widget_size_allocate (child, &child_allocation); gtk_widget_queue_draw (child); child_allocation.y += child_allocation.height; } } + + /* Resize the item window */ + if (GTK_WIDGET_REALIZED (widget)) + { + gdk_window_resize (menu->bin_window, + child_allocation.width, + child_allocation.y); + } + + + if (menu->tearoff_active) + { + if (allocation->height >= widget->requisition.height) + { + if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar)) + { + gtk_widget_hide (menu->tearoff_scrollbar); + gtk_menu_set_tearoff_hints (menu, allocation->width); + gtk_widget_set_usize (menu->tearoff_window, -1, allocation->height); + + gtk_menu_scroll_to (menu, 0); + } + } + else + { + menu->tearoff_adjustment->upper = widget->requisition.height; + menu->tearoff_adjustment->page_size = allocation->height; + + if (menu->tearoff_adjustment->value + menu->tearoff_adjustment->page_size > + menu->tearoff_adjustment->upper) + { + gint value; + value = menu->tearoff_adjustment->upper - menu->tearoff_adjustment->page_size; + if (value < 0) + value = 0; + gtk_menu_scroll_to (menu, value); + } + + gtk_adjustment_changed (menu->tearoff_adjustment); + + if (!GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar)) + { + gtk_menu_set_tearoff_hints (menu, + allocation->width + menu->tearoff_scrollbar->requisition.width); + gtk_widget_show (menu->tearoff_scrollbar); + gtk_widget_set_usize (menu->tearoff_window, -1, allocation->height); + } + } + } } } static void gtk_menu_paint (GtkWidget *widget) { + gint border_x; + gint border_y; + gint width, height; + gint menu_height; + gint top_pos; + GtkMenu *menu; + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_MENU (widget)); + + menu = GTK_MENU (widget); if (GTK_WIDGET_DRAWABLE (widget)) { @@ -966,6 +1252,88 @@ gtk_menu_paint (GtkWidget *widget) GTK_SHADOW_OUT, NULL, widget, "menu", 0, 0, -1, -1); + + border_x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness; + border_y = GTK_CONTAINER (widget)->border_width + widget->style->ythickness; + gdk_window_get_size (widget->window, &width, &height); + + if (menu->upper_arrow_visible && !menu->tearoff_active) + { + gtk_paint_box (widget->style, + widget->window, + menu->upper_arrow_prelight ? + GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, + GTK_SHADOW_OUT, + NULL, widget, "menu", + border_x, + border_y, + width - 2*border_x, + MENU_SCROLL_ARROW_HEIGHT); + + gtk_paint_arrow (widget->style, + widget->window, + menu->upper_arrow_prelight ? + GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, + GTK_SHADOW_OUT, + NULL, widget, "menu", + GTK_ARROW_UP, + TRUE, + width / 2 - MENU_SCROLL_ARROW_HEIGHT / 2 + 1, + 2 * border_y + 1, + MENU_SCROLL_ARROW_HEIGHT - 2 * border_y - 2, + MENU_SCROLL_ARROW_HEIGHT - 2 * border_y - 2); + } + + if (menu->lower_arrow_visible && !menu->tearoff_active) + { + gtk_paint_box (widget->style, + widget->window, + menu->lower_arrow_prelight ? + GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, + GTK_SHADOW_OUT, + NULL, widget, "menu", + border_x, + height - border_y - MENU_SCROLL_ARROW_HEIGHT + 1, + width - 2*border_x, + MENU_SCROLL_ARROW_HEIGHT); + + gtk_paint_arrow (widget->style, + widget->window, + menu->lower_arrow_prelight ? + GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, + GTK_SHADOW_OUT, + NULL, widget, "menu", + GTK_ARROW_DOWN, + TRUE, + width / 2 - MENU_SCROLL_ARROW_HEIGHT / 2 + 1, + height - MENU_SCROLL_ARROW_HEIGHT + 1, + MENU_SCROLL_ARROW_HEIGHT - 2 * border_y - 2, + MENU_SCROLL_ARROW_HEIGHT - 2 * border_y - 2); + } + + if (menu->scroll_offset < 0) + gtk_paint_box (widget->style, + menu->view_window, + GTK_STATE_ACTIVE, + GTK_SHADOW_IN, + NULL, widget, "menu", + 0, 0, + -1, + -menu->scroll_offset); + + menu_height = widget->requisition.height - 2*border_y; + top_pos = height - 2*border_y - (menu->upper_arrow_visible ? MENU_SCROLL_ARROW_HEIGHT : 0); + + if (menu_height - menu->scroll_offset < top_pos) + gtk_paint_box (widget->style, + menu->view_window, + GTK_STATE_ACTIVE, + GTK_SHADOW_IN, + NULL, widget, "menu", + 0, + menu_height - menu->scroll_offset, + -1, + top_pos - (menu_height - menu->scroll_offset)); } } @@ -1044,7 +1412,7 @@ gtk_menu_key_press (GtkWidget *widget, { GtkMenuShell *menu_shell; gboolean delete = FALSE; - + g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_MENU (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); @@ -1136,6 +1504,10 @@ gtk_menu_motion_notify (GtkWidget *widget, gboolean need_enter; + + if (GTK_IS_MENU (widget)) + gtk_menu_handle_scrolling (GTK_MENU (widget), TRUE); + /* We received the event for one of two reasons: * * a) We are the active menu, and did gtk_grab_add() @@ -1145,7 +1517,6 @@ gtk_menu_motion_notify (GtkWidget *widget, * is the parent of the menu item, for a), we need to find that menu, * 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) || !GTK_IS_MENU (menu_item->parent)) @@ -1198,12 +1569,154 @@ gtk_menu_motion_notify (GtkWidget *widget, return FALSE; } +static gboolean +gtk_menu_scroll_timeout (gpointer data) +{ + GtkMenu *menu; + GtkWidget *widget; + gint offset; + gint view_width, view_height; + + menu = GTK_MENU (data); + widget = GTK_WIDGET (menu); + + offset = menu->scroll_offset + menu->scroll_step; + + /* If we scroll upward and the non-visible top part + * is smaller than the scroll arrow it would be + * pretty stupid to show the arrow and taking more + * screen space than just scrolling to the top. + */ + if ((menu->scroll_step < 0) && (offset < MENU_SCROLL_ARROW_HEIGHT)) + offset = 0; + + /* Don't scroll over the top if we weren't before: */ + if ((menu->scroll_offset >= 0) && (offset < 0)) + offset = 0; + + gdk_window_get_size (widget->window, &view_width, &view_height); + + /* Don't scroll past the bottom if we weren't before: */ + if (menu->scroll_offset > 0) + view_height -= MENU_SCROLL_ARROW_HEIGHT; + + if ((menu->scroll_offset + view_height <= widget->requisition.height) && + (offset + view_height > widget->requisition.height)) + offset = widget->requisition.height - view_height; + + gtk_menu_scroll_to (menu, offset); + + return TRUE; +} + +static void +gtk_menu_handle_scrolling (GtkMenu *menu, gboolean enter) +{ + GtkMenuShell *menu_shell; + gint width, height; + gint x, y; + gint border; + GdkRectangle rect; + gboolean in_arrow; + gboolean scroll_fast = FALSE; + + menu_shell = GTK_MENU_SHELL (menu); + + gdk_window_get_pointer (GTK_WIDGET (menu)->window, &x, &y, NULL); + gdk_window_get_size (GTK_WIDGET (menu)->window, &width, &height); + + border = GTK_CONTAINER (menu)->border_width + GTK_WIDGET (menu)->style->ythickness; + + if (menu->upper_arrow_visible && !menu->tearoff_active) + { + rect.x = 0; + rect.y = 0; + rect.width = width; + rect.height = MENU_SCROLL_ARROW_HEIGHT + border; + + in_arrow = FALSE; + if ((x >= rect.x) && (x < rect.x + rect.width) && + (y >= rect.y) && (y < rect.y + rect.height)) + { + in_arrow = TRUE; + scroll_fast = (y < rect.y + MENU_SCROLL_FAST_ZONE); + } + + if (enter && in_arrow && + (!menu->upper_arrow_prelight || menu->scroll_fast != scroll_fast)) + { + menu->upper_arrow_prelight = TRUE; + menu->scroll_fast = scroll_fast; + gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE); + + /* Deselect the active item so that any submenus are poped down */ + gtk_menu_shell_deselect (menu_shell); + + gtk_menu_stop_scrolling (menu); + menu->scroll_step = -MENU_SCROLL_STEP; + menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1, + gtk_menu_scroll_timeout, + menu); + } + else if (!enter && !in_arrow && menu->upper_arrow_prelight) + { + menu->upper_arrow_prelight = FALSE; + gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE); + + gtk_menu_stop_scrolling (menu); + } + } + + if (menu->lower_arrow_visible && !menu->tearoff_active) + { + rect.x = 0; + rect.y = height - border - MENU_SCROLL_ARROW_HEIGHT; + rect.width = width; + rect.height = MENU_SCROLL_ARROW_HEIGHT + border; + + in_arrow = FALSE; + if ((x >= rect.x) && (x < rect.x + rect.width) && + (y >= rect.y) && (y < rect.y + rect.height)) + { + in_arrow = TRUE; + scroll_fast = (y > rect.y + rect.height - MENU_SCROLL_FAST_ZONE); + } + + if (enter && in_arrow && + (!menu->lower_arrow_prelight || menu->scroll_fast != scroll_fast)) + { + menu->lower_arrow_prelight = TRUE; + menu->scroll_fast = scroll_fast; + gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE); + + /* Deselect the active item so that any submenus are poped down */ + gtk_menu_shell_deselect (menu_shell); + + gtk_menu_stop_scrolling (menu); + menu->scroll_step = MENU_SCROLL_STEP; + menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1, + gtk_menu_scroll_timeout, + menu); + } + else if (!enter && !in_arrow && menu->lower_arrow_prelight) + { + menu->lower_arrow_prelight = FALSE; + gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE); + + gtk_menu_stop_scrolling (menu); + } + } +} + static gboolean gtk_menu_enter_notify (GtkWidget *widget, GdkEventCrossing *event) { GtkWidget *menu_item; + if (widget && GTK_IS_MENU (widget)) + gtk_menu_handle_scrolling (GTK_MENU (widget), TRUE); + /* If this is a faked enter (see gtk_menu_motion_notify), 'widget' * will not correspond to the event widget's parent. Check to see * if we are in the parent's navigation region. @@ -1211,7 +1724,7 @@ gtk_menu_enter_notify (GtkWidget *widget, menu_item = gtk_get_event_widget ((GdkEvent*) event); if (menu_item && GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) && gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent), event->x_root, event->y_root)) - return TRUE; + return TRUE; return GTK_WIDGET_CLASS (parent_class)->enter_notify_event (widget, event); } @@ -1223,13 +1736,15 @@ gtk_menu_leave_notify (GtkWidget *widget, GtkMenuShell *menu_shell; GtkMenu *menu; GtkMenuItem *menu_item; - GtkWidget *event_widget; + GtkWidget *event_widget; menu = GTK_MENU (widget); menu_shell = GTK_MENU_SHELL (widget); if (gtk_menu_navigating_submenu (menu, event->x_root, event->y_root)) return TRUE; + + gtk_menu_handle_scrolling (menu, FALSE); event_widget = gtk_get_event_widget ((GdkEvent*) event); @@ -1416,12 +1931,20 @@ gtk_menu_position (GtkMenu *menu) GtkWidget *widget; GtkRequisition requisition; gint x, y; - + gint screen_width; + gint screen_height; + gint scroll_offset; + gint menu_height; + gboolean push_in; + g_return_if_fail (menu != NULL); g_return_if_fail (GTK_IS_MENU (menu)); widget = GTK_WIDGET (menu); + screen_width = gdk_screen_width (); + screen_height = gdk_screen_height (); + gdk_window_get_pointer (NULL, &x, &y, NULL); /* We need the requisition to figure out the right place to @@ -1430,31 +1953,281 @@ gtk_menu_position (GtkMenu *menu) * the requisition won't have been recomputed yet. */ gtk_widget_size_request (widget, &requisition); - + + push_in = FALSE; + if (menu->position_func) - (* menu->position_func) (menu, &x, &y, menu->position_func_data); + (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data); else { - gint screen_width; - gint screen_height; - - screen_width = gdk_screen_width (); - screen_height = gdk_screen_height (); - x = CLAMP (x - 2, 0, MAX (0, screen_width - requisition.width)); y = CLAMP (y - 2, 0, MAX (0, screen_height - requisition.height)); } + scroll_offset = 0; + + if (push_in) + { + menu_height = GTK_WIDGET (menu)->requisition.height; + + if (y + menu_height > screen_height) + { + scroll_offset -= y + menu_height - screen_height; + y = screen_height - menu_height; + } + + if (y < 0) + { + scroll_offset -= y; + y = 0; + } + } + + if (y + requisition.height > screen_height) + requisition.height = screen_height - y; + + if (y < 0) + { + scroll_offset -= y; + requisition.height -= -y; + y = 0; + } + + if (scroll_offset > 0) + scroll_offset += MENU_SCROLL_ARROW_HEIGHT; + /* FIXME: The MAX() here is because gtk_widget_set_uposition * is broken. Once we provide an alternate interface that * allows negative values, then we can remove them. */ + x = MAX (x, 0); gtk_widget_set_uposition (GTK_MENU_SHELL (menu)->active ? - menu->toplevel : menu->tearoff_window, - MAX (x, 0), MAX (y, 0)); + menu->toplevel : menu->tearoff_window, + x, y); + gtk_widget_set_usize (GTK_MENU_SHELL (menu)->active ? + menu->toplevel : menu->tearoff_hbox, + -1, requisition.height); + menu->scroll_offset = scroll_offset; } +static void +gtk_menu_stop_scrolling (GtkMenu *menu) +{ + if (menu->timeout_id) + { + g_source_remove (menu->timeout_id); + menu->timeout_id = 0; + } +} + + +static void +gtk_menu_scroll_to (GtkMenu *menu, + gint offset) +{ + GtkWidget *widget; + gint x, y; + gint view_width, view_height; + gint border_width; + gboolean last_visible; + gint menu_height; + + widget = GTK_WIDGET (menu); + + if (menu->tearoff_active && + menu->tearoff_adjustment && + (menu->tearoff_adjustment->value != offset)) + { + menu->tearoff_adjustment->value = offset; + gtk_adjustment_value_changed (menu->tearoff_adjustment); + } + + /* Scroll the menu: */ + gdk_window_move (menu->bin_window, 0, -offset); + + /* Move/resize the viewport according to arrows: */ + gdk_window_get_size (widget->window, &view_width, &view_height); + + border_width = GTK_CONTAINER (menu)->border_width; + view_width -= (border_width + widget->style->xthickness) * 2; + view_height -= (border_width + widget->style->ythickness) * 2; + menu_height = widget->requisition.height - (border_width + widget->style->ythickness) * 2; + + x = border_width + widget->style->xthickness; + y = border_width + widget->style->ythickness; + + if (!menu->tearoff_active) + { + last_visible = menu->upper_arrow_visible; + menu->upper_arrow_visible = (offset > 0); + + if (menu->upper_arrow_visible) + view_height -= MENU_SCROLL_ARROW_HEIGHT; + + if ( (last_visible != menu->upper_arrow_visible) && + !menu->upper_arrow_visible) + { + menu->upper_arrow_prelight = FALSE; + + /* If we hid the upper arrow, possibly remove timeout */ + if (menu->scroll_step < 0) + gtk_menu_stop_scrolling (menu); + } + + last_visible = menu->lower_arrow_visible; + menu->lower_arrow_visible = (view_height + offset < menu_height); + + if (menu->lower_arrow_visible) + view_height -= MENU_SCROLL_ARROW_HEIGHT; + + if ( (last_visible != menu->lower_arrow_visible) && + !menu->lower_arrow_visible) + { + menu->lower_arrow_prelight = FALSE; + + /* If we hid the lower arrow, possibly remove timeout */ + if (menu->scroll_step > 0) + gtk_menu_stop_scrolling (menu); + } + + if (menu->upper_arrow_visible) + y += MENU_SCROLL_ARROW_HEIGHT; + } + + + gdk_window_move_resize (menu->view_window, + x, + y, + view_width, + view_height); + + menu->scroll_offset = offset; +} + +static void +gtk_menu_select_item (GtkMenuShell *menu_shell, + GtkWidget *menu_item) +{ + GtkMenu *menu; + GtkWidget *child; + GList *children; + GtkRequisition child_requisition; + gint child_offset, child_height; + gint width, height; + gint y; + gint arrow_height; + gboolean last_child = 0; + + g_return_if_fail (menu_shell != NULL); + g_return_if_fail (GTK_IS_MENU (menu_shell)); + + menu = GTK_MENU (menu_shell); + + /* We need to check if the selected item fully visible. + * If not we need to scroll the menu so that it becomes fully + * visible. + */ + + child = NULL; + child_offset = 0; + child_height = 0; + children = menu_shell->children; + while (children) + { + child = children->data; + children = children->next; + + if (GTK_WIDGET_VISIBLE (child)) + { + gtk_widget_size_request (child, &child_requisition); + child_offset += child_height; + child_height = child_requisition.height; + } + + if (child == menu_item) + { + last_child = (children == NULL); + break; + } + } + + if (child == menu_item) + { + y = menu->scroll_offset; + gdk_window_get_size (GTK_WIDGET (menu)->window, &width, &height); + + height -= 2*GTK_CONTAINER (menu)->border_width + 2*GTK_WIDGET (menu)->style->ythickness; + + if (child_offset + child_height <= y) + { + /* Ignore the enter event we might get if the pointer is on the menu + */ + menu_shell->ignore_enter = TRUE; + gtk_menu_scroll_to (menu, child_offset); + } + else + { + arrow_height = 0; + if (menu->upper_arrow_visible && !menu->tearoff_active) + arrow_height += MENU_SCROLL_ARROW_HEIGHT; + if (menu->lower_arrow_visible && !menu->tearoff_active) + arrow_height += MENU_SCROLL_ARROW_HEIGHT; + + if (child_offset >= y + height - arrow_height) + { + arrow_height = 0; + if (!last_child && !menu->tearoff_active) + arrow_height += MENU_SCROLL_ARROW_HEIGHT; + + y = child_offset + child_height - height + arrow_height; + if ((y > 0) && !menu->tearoff_active) + { + /* Need upper arrow */ + arrow_height += MENU_SCROLL_ARROW_HEIGHT; + y = child_offset + child_height - height + arrow_height; + } + /* Ignore the enter event we might get if the pointer is on the menu + */ + menu_shell->ignore_enter = TRUE; + gtk_menu_scroll_to (menu, y); + } + } + + } + + GTK_MENU_SHELL_CLASS (parent_class)->select_item (menu_shell, menu_item); +} + + /* Reparent the menu, taking care of the refcounting + * + * If unrealize is true we force a unrealize while reparenting the parent. + * This can help eliminate flicker in some cases. + * + * What happens is that when the menu is unrealized and then re-realized, + * the allocations are as follows: + * + * parent - 1x1 at (0,0) + * child1 - 100x20 at (0,0) + * child2 - 100x20 at (0,20) + * child3 - 100x20 at (0,40) + * + * That is, the parent is small but the children are full sized. Then, + * when the queued_resize gets processed, the parent gets resized to + * full size. + * + * But in order to eliminate flicker when scrolling, gdkgeometry-x11.c + * contains the following logic: + * + * - if a move or resize operation on a window would change the clip + * region on the children, then before the window is resized + * the background for children is temporarily set to None, the + * move/resize done, and the background for the children restored. + * + * So, at the point where the parent is resized to final size, the + * background for the children is temporarily None, and thus they + * are not cleared to the background color and the previous background + * (the image of the menu) is left in place. */ static void gtk_menu_reparent (GtkMenu *menu, @@ -1477,7 +2250,6 @@ gtk_menu_reparent (GtkMenu *menu, } else gtk_widget_reparent (GTK_WIDGET (menu), new_parent); - gtk_widget_set_usize (new_parent, -1, -1); if (was_floating) GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING); @@ -1506,3 +2278,4 @@ gtk_menu_hide_all (GtkWidget *widget) gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_hide_all, NULL); } + diff --git a/gtk/gtkmenu.h b/gtk/gtkmenu.h index 741a37ea54..1d478c30dd 100644 --- a/gtk/gtkmenu.h +++ b/gtk/gtkmenu.h @@ -37,7 +37,6 @@ extern "C" { #endif /* __cplusplus */ - #define GTK_TYPE_MENU (gtk_menu_get_type ()) #define GTK_MENU(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_MENU, GtkMenu)) #define GTK_MENU_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU, GtkMenuClass)) @@ -52,6 +51,7 @@ typedef struct _GtkMenuClass GtkMenuClass; typedef void (*GtkMenuPositionFunc) (GtkMenu *menu, gint *x, gint *y, + gboolean *push_in, gpointer user_data); typedef void (*GtkMenuDetachFunc) (GtkWidget *attach_widget, GtkMenu *menu); @@ -62,18 +62,31 @@ struct _GtkMenu GtkWidget *parent_menu_item; GtkWidget *old_active_menu_item; - + GtkAccelGroup *accel_group; GtkMenuPositionFunc position_func; gpointer position_func_data; + guint toggle_size; /* Do _not_ touch these widgets directly. We hide the reference * count from the toplevel to the menu, so it must be restored * before operating on these widgets */ GtkWidget *toplevel; + GtkWidget *tearoff_window; + GtkWidget *tearoff_hbox; + GtkWidget *tearoff_scrollbar; + GtkAdjustment *tearoff_adjustment; + GdkWindow *view_window; + GdkWindow *bin_window; + + gint scroll_offset; + gint saved_scroll_offset; + gint scroll_step; + guint timeout_id; + /* When a submenu of this menu is popped up, motion in this * region is ignored */ @@ -82,6 +95,17 @@ struct _GtkMenu guint needs_destruction_ref_count : 1; guint torn_off : 1; + /* The tearoff is active when it is torn off and the not-torn-off + * menu is not popped up. + */ + guint tearoff_active : 1; + + guint scroll_fast : 1; + + guint upper_arrow_visible : 1; + guint lower_arrow_visible : 1; + guint upper_arrow_prelight : 1; + guint lower_arrow_prelight : 1; }; struct _GtkMenuClass @@ -93,15 +117,6 @@ struct _GtkMenuClass GtkType gtk_menu_get_type (void) G_GNUC_CONST; GtkWidget* gtk_menu_new (void); -/* Wrappers for the Menu Shell operations */ -void gtk_menu_append (GtkMenu *menu, - GtkWidget *child); -void gtk_menu_prepend (GtkMenu *menu, - GtkWidget *child); -void gtk_menu_insert (GtkMenu *menu, - GtkWidget *child, - gint position); - /* Display the menu onscreen */ void gtk_menu_popup (GtkMenu *menu, GtkWidget *parent_menu_shell, diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index b4e0ba4540..bb80966a18 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -42,6 +42,8 @@ enum { ACTIVATE, ACTIVATE_ITEM, + TOGGLE_SIZE_REQUEST, + TOGGLE_SIZE_ALLOCATE, LAST_SIGNAL }; @@ -59,14 +61,21 @@ static void gtk_menu_item_draw (GtkWidget *widget, GdkRectangle *area); static gint gtk_menu_item_expose (GtkWidget *widget, GdkEventExpose *event); -static void gtk_real_menu_item_select (GtkItem *item); -static void gtk_real_menu_item_deselect (GtkItem *item); -static void gtk_real_menu_item_activate_item (GtkMenuItem *item); + +static void gtk_real_menu_item_select (GtkItem *item); +static void gtk_real_menu_item_deselect (GtkItem *item); +static void gtk_real_menu_item_activate_item (GtkMenuItem *item); +static void gtk_real_menu_item_toggle_size_request (GtkMenuItem *menu_item, + guint16 *requisition); +static void gtk_real_menu_item_toggle_size_allocate (GtkMenuItem *menu_item, + guint16 allocation); + static gint gtk_menu_item_select_timeout (gpointer data); static void gtk_menu_item_popup_submenu (gpointer data); static void gtk_menu_item_position_menu (GtkMenu *menu, gint *x, gint *y, + gboolean *push_in, gpointer user_data); static void gtk_menu_item_show_all (GtkWidget *widget); static void gtk_menu_item_hide_all (GtkWidget *widget); @@ -138,6 +147,24 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass) gtk_signal_default_marshaller, GTK_TYPE_NONE, 0); + menu_item_signals[TOGGLE_SIZE_REQUEST] = + gtk_signal_new ("toggle_size_request", + GTK_RUN_FIRST, + GTK_CLASS_TYPE (object_class), + GTK_SIGNAL_OFFSET (GtkMenuItemClass, toggle_size_request), + gtk_marshal_NONE__POINTER, + GTK_TYPE_NONE, 1, + GTK_TYPE_POINTER); + + menu_item_signals[TOGGLE_SIZE_ALLOCATE] = + gtk_signal_new ("toggle_size_allocate", + GTK_RUN_FIRST, + GTK_CLASS_TYPE (object_class), + GTK_SIGNAL_OFFSET (GtkMenuItemClass, toggle_size_allocate), + gtk_marshal_NONE__UINT, + GTK_TYPE_NONE, 1, + GTK_TYPE_UINT); + gtk_object_class_add_signals (object_class, menu_item_signals, LAST_SIGNAL); object_class->destroy = gtk_menu_item_destroy; @@ -157,8 +184,9 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass) klass->activate = NULL; klass->activate_item = gtk_real_menu_item_activate_item; + klass->toggle_size_request = gtk_real_menu_item_toggle_size_request; + klass->toggle_size_allocate = gtk_real_menu_item_toggle_size_allocate; - klass->toggle_size = 0; klass->hide_on_activate = TRUE; } @@ -313,6 +341,26 @@ gtk_menu_item_activate (GtkMenuItem *menu_item) gtk_signal_emit (GTK_OBJECT (menu_item), menu_item_signals[ACTIVATE]); } +void +gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item, + guint16 *requisition) +{ + g_return_if_fail (menu_item != NULL); + g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); + + gtk_signal_emit (GTK_OBJECT (menu_item), menu_item_signals[TOGGLE_SIZE_REQUEST], requisition); +} + +void +gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item, + guint16 allocation) +{ + g_return_if_fail (menu_item != NULL); + g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); + + gtk_signal_emit (GTK_OBJECT (menu_item), menu_item_signals[TOGGLE_SIZE_ALLOCATE], allocation); +} + static void gtk_menu_item_accel_width_foreach (GtkWidget *widget, gpointer data) @@ -631,6 +679,25 @@ gtk_real_menu_item_activate_item (GtkMenuItem *menu_item) } } } +static void +gtk_real_menu_item_toggle_size_request (GtkMenuItem *menu_item, + guint16 *requisition) +{ + g_return_if_fail (menu_item != NULL); + g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); + + *requisition = 0; +} + +static void +gtk_real_menu_item_toggle_size_allocate (GtkMenuItem *menu_item, + guint16 allocation) +{ + g_return_if_fail (menu_item != NULL); + g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); + + menu_item->toggle_size = allocation; +} static gint gtk_menu_item_select_timeout (gpointer data) @@ -668,6 +735,7 @@ static void gtk_menu_item_position_menu (GtkMenu *menu, gint *x, gint *y, + gboolean *push_in, gpointer user_data) { GtkMenuItem *menu_item; @@ -702,9 +770,10 @@ gtk_menu_item_position_menu (GtkMenu *menu, ty += GTK_WIDGET (menu_item)->allocation.height; else if ((ty - theight) >= 0) ty -= theight; - else + else if (screen_height - (ty + GTK_WIDGET (menu_item)->allocation.height) > ty) ty += GTK_WIDGET (menu_item)->allocation.height; - + else + ty -= theight; break; case GTK_LEFT_RIGHT: @@ -738,14 +807,16 @@ gtk_menu_item_position_menu (GtkMenu *menu, ty += GTK_WIDGET (menu_item)->allocation.height / 4; + /* If the height of the menu doesn't fit we move it upward. */ + ty = CLAMP (ty, 0, MAX (0, screen_height - theight)); break; } - /* If we have negative, tx, ty here it is because we can't get - * the menu all the way on screen. Favor the upper-left portion. + /* If we have negative, tx, here it is because we can't get + * the menu all the way on screen. Favor the left portion. */ *x = CLAMP (tx, 0, MAX (0, screen_width - twidth)); - *y = CLAMP (ty, 0, MAX (0, screen_height - theight)); + *y = ty; } void @@ -812,6 +883,4 @@ gtk_menu_item_forall (GtkContainer *container, if (bin->child) (* callback) (bin->child, callback_data); - if (include_internals && menu_item->submenu) - (* callback) (menu_item->submenu, callback_data); } diff --git a/gtk/gtkmenuitem.h b/gtk/gtkmenuitem.h index 2f59c0c9f2..df52e516b2 100644 --- a/gtk/gtkmenuitem.h +++ b/gtk/gtkmenuitem.h @@ -70,7 +70,6 @@ struct _GtkMenuItemClass { GtkItemClass parent_class; - guint toggle_size; /* If the following flag is true, then we should always hide * the menu when the MenuItem is activated. Otherwise, the * it is up to the caller. For instance, when navigating @@ -79,26 +78,35 @@ struct _GtkMenuItemClass */ guint hide_on_activate : 1; - void (* activate) (GtkMenuItem *menu_item); - void (* activate_item) (GtkMenuItem *menu_item); + void (* activate) (GtkMenuItem *menu_item); + void (* activate_item) (GtkMenuItem *menu_item); + void (* toggle_size_request) (GtkMenuItem *menu_item, + guint16 *requisition); + void (* toggle_size_allocate) (GtkMenuItem *menu_item, + guint16 allocation); }; -GtkType gtk_menu_item_get_type (void) G_GNUC_CONST; -GtkWidget* gtk_menu_item_new (void); -GtkWidget* gtk_menu_item_new_with_label (const gchar *label); -void gtk_menu_item_set_submenu (GtkMenuItem *menu_item, - GtkWidget *submenu); -void gtk_menu_item_remove_submenu (GtkMenuItem *menu_item); -void gtk_menu_item_set_placement (GtkMenuItem *menu_item, - GtkSubmenuPlacement placement); -void gtk_menu_item_configure (GtkMenuItem *menu_item, - gint show_toggle_indicator, - gint show_submenu_indicator); -void gtk_menu_item_select (GtkMenuItem *menu_item); -void gtk_menu_item_deselect (GtkMenuItem *menu_item); -void gtk_menu_item_activate (GtkMenuItem *menu_item); -void gtk_menu_item_right_justify (GtkMenuItem *menu_item); +GtkType gtk_menu_item_get_type (void) G_GNUC_CONST; +GtkWidget* gtk_menu_item_new (void); +GtkWidget* gtk_menu_item_new_with_label (const gchar *label); +void gtk_menu_item_set_submenu (GtkMenuItem *menu_item, + GtkWidget *submenu); +void gtk_menu_item_remove_submenu (GtkMenuItem *menu_item); +void gtk_menu_item_set_placement (GtkMenuItem *menu_item, + GtkSubmenuPlacement placement); +void gtk_menu_item_configure (GtkMenuItem *menu_item, + gint show_toggle_indicator, + gint show_submenu_indicator); +void gtk_menu_item_select (GtkMenuItem *menu_item); +void gtk_menu_item_deselect (GtkMenuItem *menu_item); +void gtk_menu_item_activate (GtkMenuItem *menu_item); +void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item, + guint16 *requisition); +void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item, + guint16 allocation); +void gtk_menu_item_right_justify (GtkMenuItem *menu_item); + #ifdef __cplusplus diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c index a8ced1698e..bb3e7f7894 100644 --- a/gtk/gtkmenushell.c +++ b/gtk/gtkmenushell.c @@ -129,12 +129,17 @@ static void gtk_menu_shell_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); +static void gtk_menu_shell_real_insert (GtkMenuShell *menu_shell, + GtkWidget *child, + gint position); static void gtk_real_menu_shell_deactivate (GtkMenuShell *menu_shell); static gint gtk_menu_shell_is_item (GtkMenuShell *menu_shell, GtkWidget *child); static GtkWidget *gtk_menu_shell_get_item (GtkMenuShell *menu_shell, GdkEvent *event); static GtkType gtk_menu_shell_child_type (GtkContainer *container); +static void gtk_menu_shell_real_select_item (GtkMenuShell *menu_shell, + GtkWidget *menu_item); static void gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell); static void gtk_real_menu_shell_move_current (GtkMenuShell *menu_shell, @@ -246,6 +251,8 @@ gtk_menu_shell_class_init (GtkMenuShellClass *klass) klass->move_current = gtk_real_menu_shell_move_current; klass->activate_current = gtk_real_menu_shell_activate_current; klass->cancel = gtk_real_menu_shell_cancel; + klass->select_item = gtk_menu_shell_real_select_item; + klass->insert = gtk_menu_shell_real_insert; binding_set = gtk_binding_set_by_class (klass); gtk_binding_entry_add_signal (binding_set, @@ -303,11 +310,24 @@ gtk_menu_shell_insert (GtkMenuShell *menu_shell, GtkWidget *child, gint position) { + GtkMenuShellClass *class; + g_return_if_fail (menu_shell != NULL); g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); g_return_if_fail (child != NULL); g_return_if_fail (GTK_IS_MENU_ITEM (child)); + class = GTK_MENU_SHELL_GET_CLASS (menu_shell); + + if (class->insert) + class->insert (menu_shell, child, position); +} + +static void +gtk_menu_shell_real_insert (GtkMenuShell *menu_shell, + GtkWidget *child, + gint position) +{ menu_shell->children = g_list_insert (menu_shell->children, child, position); gtk_widget_set_parent (child, GTK_WIDGET (menu_shell)); @@ -573,7 +593,7 @@ gtk_menu_shell_enter_notify (GtkWidget *widget, if (!menu_item || !GTK_WIDGET_IS_SENSITIVE (menu_item)) return TRUE; - + if ((menu_item->parent == widget) && (menu_shell->active_menu_item != menu_item) && GTK_IS_MENU_ITEM (menu_item)) @@ -704,9 +724,6 @@ gtk_menu_shell_forall (GtkContainer *container, static void gtk_real_menu_shell_deactivate (GtkMenuShell *menu_shell) { - g_return_if_fail (menu_shell != NULL); - g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); - if (menu_shell->active) { menu_shell->button = 0; @@ -776,11 +793,24 @@ void gtk_menu_shell_select_item (GtkMenuShell *menu_shell, GtkWidget *menu_item) { + GtkMenuShellClass *class; + g_return_if_fail (menu_shell != NULL); g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); g_return_if_fail (menu_item != NULL); g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); + class = GTK_MENU_SHELL_GET_CLASS (menu_shell); + + if (class->select_item) + class->select_item (menu_shell, menu_item); +} + + +static void +gtk_menu_shell_real_select_item (GtkMenuShell *menu_shell, + GtkWidget *menu_item) +{ gtk_menu_shell_deselect (menu_shell); menu_shell->active_menu_item = menu_item; diff --git a/gtk/gtkmenushell.h b/gtk/gtkmenushell.h index 6470cddf19..15aafc6d80 100644 --- a/gtk/gtkmenushell.h +++ b/gtk/gtkmenushell.h @@ -81,6 +81,11 @@ struct _GtkMenuShellClass void (*activate_current) (GtkMenuShell *menu_shell, gboolean force_hide); void (*cancel) (GtkMenuShell *menu_shell); + void (*select_item) (GtkMenuShell *menu_shell, + GtkWidget *menu_item); + void (*insert) (GtkMenuShell *menu_shell, + GtkWidget *child, + gint position); }; diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 0cb79802e7..0082272bb7 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -3502,8 +3502,8 @@ gtk_notebook_menu_item_create (GtkNotebook *notebook, menu_item = gtk_menu_item_new (); gtk_widget_lock_accelerators (menu_item); gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label); - gtk_menu_insert (GTK_MENU (notebook->menu), menu_item, - gtk_notebook_real_page_position (notebook, list)); + gtk_menu_shell_insert (GTK_MENU_SHELL (notebook->menu), menu_item, + gtk_notebook_real_page_position (notebook, list)); gtk_signal_connect (GTK_OBJECT (menu_item), "activate", GTK_SIGNAL_FUNC (gtk_notebook_menu_switch_page), page); if (GTK_WIDGET_VISIBLE (page->child)) diff --git a/gtk/gtkoptionmenu.c b/gtk/gtkoptionmenu.c index cca763d1a7..db1a4f4b6e 100644 --- a/gtk/gtkoptionmenu.c +++ b/gtk/gtkoptionmenu.c @@ -65,6 +65,7 @@ static void gtk_option_menu_calc_size (GtkOptionMenu *option_menu); static void gtk_option_menu_position (GtkMenu *menu, gint *x, gint *y, + gint *scroll_offet, gpointer user_data); static void gtk_option_menu_show_all (GtkWidget *widget); static void gtk_option_menu_hide_all (GtkWidget *widget); @@ -498,6 +499,7 @@ gtk_option_menu_button_press (GtkWidget *widget, GdkEventButton *event) { GtkOptionMenu *option_menu; + GtkWidget *menu_item; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_OPTION_MENU (widget), FALSE); @@ -512,6 +514,9 @@ gtk_option_menu_button_press (GtkWidget *widget, gtk_menu_popup (GTK_MENU (option_menu->menu), NULL, NULL, gtk_option_menu_position, option_menu, event->button, event->time); + menu_item = gtk_menu_get_active (GTK_MENU (option_menu->menu)); + if (menu_item) + gtk_menu_shell_select_item (GTK_MENU_SHELL (option_menu->menu), menu_item); return TRUE; } @@ -523,6 +528,7 @@ gtk_option_menu_key_press (GtkWidget *widget, GdkEventKey *event) { GtkOptionMenu *option_menu; + GtkWidget *menu_item; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_OPTION_MENU (widget), FALSE); @@ -537,6 +543,9 @@ gtk_option_menu_key_press (GtkWidget *widget, gtk_menu_popup (GTK_MENU (option_menu->menu), NULL, NULL, gtk_option_menu_position, option_menu, 0, event->time); + menu_item = gtk_menu_get_active (GTK_MENU (option_menu->menu)); + if (menu_item) + gtk_menu_shell_select_item (GTK_MENU_SHELL (option_menu->menu), menu_item); return TRUE; } @@ -650,6 +659,7 @@ static void gtk_option_menu_position (GtkMenu *menu, gint *x, gint *y, + gboolean *push_in, gpointer user_data) { GtkOptionMenu *option_menu; @@ -657,13 +667,10 @@ gtk_option_menu_position (GtkMenu *menu, GtkWidget *child; GtkRequisition requisition; GList *children; - gint shift_menu; gint screen_width; - gint screen_height; gint menu_xpos; gint menu_ypos; - gint width; - gint height; + gint menu_width; g_return_if_fail (user_data != NULL); g_return_if_fail (GTK_IS_OPTION_MENU (user_data)); @@ -671,11 +678,9 @@ gtk_option_menu_position (GtkMenu *menu, option_menu = GTK_OPTION_MENU (user_data); gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition); - width = requisition.width; - height = requisition.height; + menu_width = requisition.width; active = gtk_menu_get_active (GTK_MENU (option_menu->menu)); - children = GTK_MENU_SHELL (option_menu->menu)->children; gdk_window_get_origin (GTK_WIDGET (option_menu)->window, &menu_xpos, &menu_ypos); menu_ypos += GTK_WIDGET (option_menu)->allocation.height / 2 - 2; @@ -686,6 +691,7 @@ gtk_option_menu_position (GtkMenu *menu, menu_ypos -= requisition.height / 2; } + children = GTK_MENU_SHELL (option_menu->menu)->children; while (children) { child = children->data; @@ -703,35 +709,15 @@ gtk_option_menu_position (GtkMenu *menu, } screen_width = gdk_screen_width (); - screen_height = gdk_screen_height (); - - shift_menu = FALSE; - if (menu_ypos < 0) - { - menu_ypos = 0; - shift_menu = TRUE; - } - else if ((menu_ypos + height) > screen_height) - { - menu_ypos -= ((menu_ypos + height) - screen_height); - shift_menu = TRUE; - } - - if (shift_menu) - { - if ((menu_xpos + GTK_WIDGET (option_menu)->allocation.width + width) <= screen_width) - menu_xpos += GTK_WIDGET (option_menu)->allocation.width; - else - menu_xpos -= width; - } - + if (menu_xpos < 0) menu_xpos = 0; - else if ((menu_xpos + width) > screen_width) - menu_xpos -= ((menu_xpos + width) - screen_width); + else if ((menu_xpos + menu_width) > screen_width) + menu_xpos -= ((menu_xpos + menu_width) - screen_width); *x = menu_xpos; *y = menu_ypos; + *push_in = TRUE; } diff --git a/gtk/testgtk.c b/gtk/testgtk.c index 126cf04aa1..cf36663f28 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -121,7 +121,7 @@ build_option_menu (OptionMenuItem items[], menu_item = gtk_menu_item_new_with_label (items[i].name); gtk_signal_connect (GTK_OBJECT (menu_item), "activate", (GtkSignalFunc) items[i].func, data); - gtk_menu_append (GTK_MENU (menu), menu_item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); gtk_widget_show (menu_item); } @@ -2659,7 +2659,7 @@ create_image (void) */ static GtkWidget* -create_menu (gint depth, gboolean tearoff) +create_menu (gint depth, gint length, gboolean tearoff) { GtkWidget *menu; GtkWidget *menuitem; @@ -2676,23 +2676,24 @@ create_menu (gint depth, gboolean tearoff) if (tearoff) { menuitem = gtk_tearoff_menu_item_new (); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); } - for (i = 0, j = 1; i < 5; i++, j++) + for (i = 0, j = 1; i < length; i++, j++) { 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_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); if (i == 3) gtk_widget_set_sensitive (menuitem, FALSE); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE)); + if (i < 5) + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, 5, TRUE)); } return menu; @@ -2739,7 +2740,7 @@ create_menus (void) gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0); gtk_widget_show (menubar); - menu = create_menu (2, TRUE); + menu = create_menu (2, 50, TRUE); menuitem = gtk_menu_item_new_with_label ("test\nline2"); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu); @@ -2747,12 +2748,12 @@ create_menus (void) gtk_widget_show (menuitem); menuitem = gtk_menu_item_new_with_label ("foo"); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, TRUE)); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, 5, TRUE)); gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); gtk_widget_show (menuitem); menuitem = gtk_menu_item_new_with_label ("bar"); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, TRUE)); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, 5, TRUE)); gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem)); gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); gtk_widget_show (menuitem); @@ -2762,11 +2763,11 @@ create_menus (void) gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); gtk_widget_show (box2); - menu = create_menu (1, FALSE); + menu = create_menu (1, 5, FALSE); gtk_menu_set_accel_group (GTK_MENU (menu), accel_group); menuitem = gtk_check_menu_item_new_with_label ("Accelerate Me"); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); gtk_widget_add_accelerator (menuitem, "activate", @@ -2775,7 +2776,7 @@ create_menus (void) 0, GTK_ACCEL_VISIBLE | GTK_ACCEL_SIGNAL_VISIBLE); menuitem = gtk_check_menu_item_new_with_label ("Accelerator Locked"); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); gtk_widget_add_accelerator (menuitem, "activate", @@ -2784,7 +2785,7 @@ create_menus (void) 0, GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); menuitem = gtk_check_menu_item_new_with_label ("Accelerators Frozen"); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); gtk_widget_add_accelerator (menuitem, "activate", diff --git a/tests/testgtk.c b/tests/testgtk.c index 126cf04aa1..cf36663f28 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -121,7 +121,7 @@ build_option_menu (OptionMenuItem items[], menu_item = gtk_menu_item_new_with_label (items[i].name); gtk_signal_connect (GTK_OBJECT (menu_item), "activate", (GtkSignalFunc) items[i].func, data); - gtk_menu_append (GTK_MENU (menu), menu_item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); gtk_widget_show (menu_item); } @@ -2659,7 +2659,7 @@ create_image (void) */ static GtkWidget* -create_menu (gint depth, gboolean tearoff) +create_menu (gint depth, gint length, gboolean tearoff) { GtkWidget *menu; GtkWidget *menuitem; @@ -2676,23 +2676,24 @@ create_menu (gint depth, gboolean tearoff) if (tearoff) { menuitem = gtk_tearoff_menu_item_new (); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); } - for (i = 0, j = 1; i < 5; i++, j++) + for (i = 0, j = 1; i < length; i++, j++) { 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_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); if (i == 3) gtk_widget_set_sensitive (menuitem, FALSE); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE)); + if (i < 5) + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, 5, TRUE)); } return menu; @@ -2739,7 +2740,7 @@ create_menus (void) gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0); gtk_widget_show (menubar); - menu = create_menu (2, TRUE); + menu = create_menu (2, 50, TRUE); menuitem = gtk_menu_item_new_with_label ("test\nline2"); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu); @@ -2747,12 +2748,12 @@ create_menus (void) gtk_widget_show (menuitem); menuitem = gtk_menu_item_new_with_label ("foo"); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, TRUE)); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, 5, TRUE)); gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); gtk_widget_show (menuitem); menuitem = gtk_menu_item_new_with_label ("bar"); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, TRUE)); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, 5, TRUE)); gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem)); gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); gtk_widget_show (menuitem); @@ -2762,11 +2763,11 @@ create_menus (void) gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); gtk_widget_show (box2); - menu = create_menu (1, FALSE); + menu = create_menu (1, 5, FALSE); gtk_menu_set_accel_group (GTK_MENU (menu), accel_group); menuitem = gtk_check_menu_item_new_with_label ("Accelerate Me"); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); gtk_widget_add_accelerator (menuitem, "activate", @@ -2775,7 +2776,7 @@ create_menus (void) 0, GTK_ACCEL_VISIBLE | GTK_ACCEL_SIGNAL_VISIBLE); menuitem = gtk_check_menu_item_new_with_label ("Accelerator Locked"); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); gtk_widget_add_accelerator (menuitem, "activate", @@ -2784,7 +2785,7 @@ create_menus (void) 0, GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); menuitem = gtk_check_menu_item_new_with_label ("Accelerators Frozen"); - gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); gtk_widget_add_accelerator (menuitem, "activate",