<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>UIManager</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Programming with gtkmm"> <link rel="up" href="chapter-menus-and-toolbars.html" title="Chapter 11. Menus and Toolbars"> <link rel="prev" href="chapter-menus-and-toolbars.html" title="Chapter 11. Menus and Toolbars"> <link rel="next" href="sec-menus-popup.html" title="Popup Menus"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">UIManager</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="chapter-menus-and-toolbars.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 11. Menus and Toolbars</th> <td width="20%" align="right"> <a accesskey="n" href="sec-menus-popup.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" title="UIManager"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-uimanager"></a>UIManager</h2></div></div></div> <p> Next you should create a <code class="classname">UIManager</code> and add the <code class="classname">ActionGroup</code> to the <code class="classname">UIManager</code> with <code class="methodname">insert_action_group()</code> At this point is also a good idea to tell the parent window to respond to the specified keyboard shortcuts, by using <code class="methodname">add_accel_group()</code>. </p> <p>For instance, </p> <pre class="programlisting">Glib::RefPtr<Gtk::UIManager> m_refUIManager = Gtk::UIManager::create(); m_refUIManager->insert_action_group(m_refActionGroup); add_accel_group(m_refUIManager->get_accel_group());</pre> <p> Then, you can define the actual visible layout of the menus and toolbars, and add the UI layout to the <code class="classname">UIManager</code>. This "ui string" uses an XML format, in which you should mention the names of the actions that you have already created. For instance: </p> <pre class="programlisting">Glib::ustring ui_info = "<ui>" " <menubar name='MenuBar'>" " <menu action='MenuFile'>" " <menuitem action='New'/>" " <menuitem action='Open'/>" " <separator/>" " <menuitem action='Quit'/>" " </menu>" " <menu action='MenuEdit'>" " <menuitem action='Cut'/>" " <menuitem action='Copy'/>" " <menuitem action='Paste'/>" " </menu>" " </menubar>" " <toolbar name='ToolBar'>" " <toolitem action='Open'/>" " <toolitem action='Quit'/>" " </toolbar>" "</ui>"; m_refUIManager->add_ui_from_string(ui_info);</pre> <p>Remember that these names are just the identifiers that we used when creating the actions. They are not the text that the user will see in the menus and toolbars. We provided those human-readable names when we created the actions.</p> <p> To instantiate a <code class="classname">Gtk::MenuBar</code> or <code class="classname">Gtk::Toolbar</code> which you can actually show, you should use the <code class="methodname">UIManager::get_widget()</code> method, and then add the widget to a container. For instance: </p> <pre class="programlisting">Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar"); pBox->add(*pMenuBar, Gtk::PACK_SHRINK);</pre> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="chapter-menus-and-toolbars.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-menus-and-toolbars.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="sec-menus-popup.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Chapter 11. Menus and Toolbars </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> Popup Menus</td> </tr> </table> </div> </body> </html>