Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 197

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<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&lt;Gtk::UIManager&gt; m_refUIManager =
    Gtk::UIManager::create();
m_refUIManager-&gt;insert_action_group(m_refActionGroup);
add_accel_group(m_refUIManager-&gt;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 =
    "&lt;ui&gt;"
    "  &lt;menubar name='MenuBar'&gt;"
    "    &lt;menu action='MenuFile'&gt;"
    "      &lt;menuitem action='New'/&gt;"
    "      &lt;menuitem action='Open'/&gt;"
    "      &lt;separator/&gt;"
    "      &lt;menuitem action='Quit'/&gt;"
    "    &lt;/menu&gt;"
    "    &lt;menu action='MenuEdit'&gt;"
    "      &lt;menuitem action='Cut'/&gt;"
    "      &lt;menuitem action='Copy'/&gt;"
    "      &lt;menuitem action='Paste'/&gt;"
    "    &lt;/menu&gt;"
    "  &lt;/menubar&gt;"
    "  &lt;toolbar  name='ToolBar'&gt;"
    "    &lt;toolitem action='Open'/&gt;"
    "    &lt;toolitem action='Quit'/&gt;"
    "  &lt;/toolbar&gt;"
    "&lt;/ui&gt;";

m_refUIManager-&gt;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-&gt;get_widget("/MenuBar");
pBox-&gt;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>