Menu changes

[ Cc'd to gtkdev since I suspect most people aren't subscribed
  to the new list yet ]

I've been working on extensive changes to menus in GTK+. 

The two major areas I've worked on so far are:

 - tearoff menus. (You add a GtkTearoffMenuItem as the first item
   in the menu)

 - Keyboard navigation. (Both with arrow keys, and using "underline

A preview patch is at:

I haven't commited it yet, because I don't like everything
about the way things work yet.

Particular things I think need improvement:

 * Unless they make sense (as in the GIMP), changing entries to have
   no-modifier accelerators should be disabled, because they are
   too easy to set accidentally while navigating the menus.

 * Currently, underline patterns are set by the AccelLabel code,
   which watches for accelerators in a given accelerator group
   with given modifiers. But this gets wrong "Save &As" displaying
   it as "S_ave As" instead of "Save _As". I think the ItemFactory
   code should probably just be setting a pattern for the AccelLabel,
   and then not set the VISIBLE flag for the corresponding 

 [ I'm using '&' instead of '_' because I think it is probably
   less common in actual menu text. ]

 * The way that menu items are activated and pop up their submenus
   is pretty screwy:

   - There is an "activate_item" signal that is triggered by the
     underline style accelerators. This does some special 
     handling with respect to submenus.

   - There is a gtk_menu_shell_activate_item() function which is
     used when the user hits Space or Return on an entry

   - There is a gtk_menu_show_select_item() function which is called
     when the user arrows onto an entry, which takes care of popping
     up submenus.

   - The default handler for GtkMenuItem::activate also has code
     to popup a submenu. (I think this could be removed now...)

   I need to rework this to be a bit more consistent and unified.

  * Currently, there is a that problem when menus pop up underneath
    the cursor, they get selected. This needs to be fixed.

I also plan on working on displaying menus that are too big to
display on the screen. My current plan is that such menus will
pop up as array menus (multiple columns), and then if they
are torn off, change back to a single column with a scrollbar.

I'd appreciate if those who know GtkItemFactory and the menuing
code (in particular, Tim) would take a look at the patch and
see if they like what it is doing. Also, if people want to
try it out in a --disable-shared tree and see if they like
the way the keyboard navigation works. (The new "Item Factory"
test is a good place to look)


The complete ChangeLog entry follows:

Tue Jul 21 12:42:01 1998  Owen Taylor  <>

	* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - 
	  too calculate all the metrics at once of a string, including
	  things which weren't calculated before.

	* gtk/ gtk/gtk.h gtk/gtktearoffmenu.[ch]: New
	  MenuItem type, that when put as the first thing in a
	  menu, makes the menu tearoff. Currently drawn as a
	  dashed line.

	* gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag
	  "hide_on_activate" to the MenuItem class structure to allow
	  check and radio buttons to be changed with <Space> without
	  hiding the menu.

	* gtk/gtkaccellabel.[ch]: Added new capabilities to set
	  a underline_group and underline_mods for the label - 
	  accelerators added in the underline group matching
	  underline_mods will be displayed as an underline character.

	  This doesn't work - Save As needs to be underlined 
	  as Save _As.
	* gtk/gtkitemfactory.c: 
	  - Create a AccelGroup for each MenuShell we create.
	  - If an '&' appears before a  character 'c' in the path,
	    then make 'c' an accelerator in the menu's accel group,
	    and if the menuitem is menubar <alt>C an accelerator 
	    in the itemfactory's accel group.

	* gtk/gtklabel.[ch]: Add support for a pattern arg - 
          which is a string. If an '_' appears in this string,
	  the corresponding position in the label is underlined.

	* gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget.
	  Instead, they create a GtkWindow and add themselves
	  to that. (When torn off, another new feature, they
	  create another GtkWindow to hold the torn off menu)

	  New function gtk_menu_set_tearoff_state()
	* gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: 
	  Added action signals  for keyboard navigation of menus.

	* gtk/gtkmenushell.c: Key press handler which activates
          bindings for navigation, and accelerators, for handling
	  underline accelerators. Exported functions to select 
	  and activate menu items in a menushell.

	* gtk/testgtk.c: Added a new "Item Factory" test which
	  tests GtkItemFactory and the new keyboard navigation
	  of menus.

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