type=menubar factorys

The contents of a factorys of type=menubar specify the x::w::menubarfactory methods that get invoked when generating the contents of a menu bar.

uigenerator6.C gives an example of using a menu bar factory to create its menus from uigenerator6.xml:

<?xml version="1.0" encoding="utf-8"?>
<theme version="1"
       xmlns:xi="http://www.w3.org/2003/XInclude">

  <dim id="cell-padding">20</dim>

  <layout id="main-window-grid" type="grid">
    <append_row>
      <name>main-window-contents</name>
    </append_row>
  </layout>

  <factory id="main-window-contents" type="grid">
    <padding>
      <side>all</side>
      <padding>cell-padding</padding>
    </padding>

    <!-- Put an input field element in the window -->

    <element id="input-field">
      <input_field />
      <config>
	<columns>20</columns>
      </config>

      <!-- Right pointer button context popup menu for the input field -->

      <context>
	<menu>
	  <append_items>
	    <items>
	      <label>Reset</label>
	    </items>
	  </append_items>
	  <append_copy_cut_paste>
	    <parent>input-field</parent>
	  </append_copy_cut_paste>
	</menu>

	<!-- Context popup's optional keyboard shortcut -->

	<shortcut>Alt-I</shortcut>
      </context>
    </element>
  </factory>

  <!-- Start building the window's menu bar -->

  <layout type="menubar" id="main-window-menu">
    <append_menus>
      <name>main-window-menus</name>
    </append_menus>

    <append_right_menus>
      <name>main-window-right-menus</name>
    </append_right_menus>
  </layout>

  <factory type="menubar" id="main-window-menus">

    <!--
	File menu. The code finishes the menu bar setup by installing a
	callback that update()s the main menu's copy/cut/paste items whenever
	file_menu pops up.
    -->

    <add id="file_menu">
      <title>
	<element>
	  <label type="theme_text">File</label>
	</element>
      </title>
      <menu>

	<!--
	    List layout manager methods. <name> labels each menu item
	    so that the code can find it and install the appropriate
	    callback that gets invoked for each menu item.
	-->

	<append_items>
	  <items>
	    <name>file_new</name>
	    <label type="theme_text">New</label>
	    <name>file_open</name>
	    <label type="theme_text">Open</label>
	    <name>file_close</name>
	    <label type="theme_text">Close</label>
	    <name>file_recent</name>

	    <!-- Submenu -->

	    <submenu>
	      <append_items>
		<items>
		  <name>file_recent_file_1</name>
		  <label type="theme_text">File 1</label>
		  <name>file_recent_file_2</name>
		  <label type="theme_text">File 2</label>
		</items>
	      </append_items>
	    </submenu>
	    <label type="theme_text">Recent</label>

	    <!-- Menu option followed by a separator -->

	    <name>file_automatic_close</name>
	    <menuoption />
	    <label type="theme_text">Automatic Close</label>
	    <separator />
	  </items>
	</append_items>

	<!-- Append copy/cut/paste menu items, for the "main" window -->

	<append_copy_cut_paste>
	  <parent>main</parent>
	</append_copy_cut_paste>
      </menu>
    </add>
  </factory>

  <!-- "Help" menu on the right -->

  <factory type="menubar" id="main-window-right-menus">
    <add>
      <title>
	<element>
	  <label type="theme_text">Help</label>
	</element>
      </title>
      <menu>
	<append_items>
	  <items>
	    <name>help_about</name>
	    <label type="theme_text">About...</label>
	  </items>
	</append_items>
      </menu>
    </add>
  </factory>
</theme>

Adding menus

add in a factorys of type=menubar create a new menu, and must have a title and a menu element.

title sets the new menu's title, and contains any element that's valid in a generic factory. The traditional menu title is a label element.

The menu element contains type=list layout elements.

In the general case, it's typically a single append_items element, specifying a name of each menuitem. uigenerator6.xml provides an example of generate()ing a menu and then using get_list_itemhandle to retrive a x::w::listitemhandle for each named menu itema and installing a callback that gets invoked by selecting the menu item.