Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > e40b0b2b839eccdb3c85993a7b738115 > files > 25

gtkmm-documentation-3.24.0-1.mga7.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 12. Menus and Toolbars</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Programming with gtkmm 3">
<link rel="up" href="index.html" title="Programming with gtkmm 3">
<link rel="prev" href="sec-textview-examples.html" title="Examples">
<link rel="next" href="sec-menubar-and-toolbar.html" title="Menubar and Toolbar">
</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">Chapter 12. Menus and Toolbars</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-textview-examples.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-menubar-and-toolbar.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="chapter-menus-and-toolbars"></a>Chapter 12. Menus and Toolbars</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="sect1"><a href="chapter-menus-and-toolbars.html#sec-actions">Actions</a></span></li>
<li><span class="sect1"><a href="sec-menubar-and-toolbar.html">Menubar and Toolbar</a></span></li>
<li><span class="sect1"><a href="sec-menus-popup.html">Popup Menus</a></span></li>
<li><span class="sect1"><a href="sec-gio-resource.html">Gio::Resource and glib-compile-resources</a></span></li>
<li><span class="sect1"><a href="sec-menus-examples.html">Examples</a></span></li>
</ul>
</div>
<p>
There are specific APIs for menus and toolbars, but you should usually deal
with them together, creating <code class="classname">Gio::SimpleAction</code>s that
you can refer to in both menus and toolbars. In this way you can handle
activation of the action instead of responding to the menu and toolbar items
separately. And you can enable or disable both the menu and toolbar item via
the action. <code class="classname">Gtk::Builder</code> can create menus and toolbars.
</p>
<p>
This involves the use of the <code class="classname">Gio::SimpleActionGroup</code>,
<code class="classname">Gio::SimpleAction</code> and <code class="classname">Gtk::Builder</code>
classes, all of which should be instantiated via their <code class="methodname">create()</code>
methods, which return <code class="classname">RefPtr</code>s.
</p>
<p>
<code class="classname">Gtk::ActionGroup</code>, <code class="classname">Gtk::Action</code> with
its subclasses and <code class="classname">Gtk::UIManager</code> has been an alternative.
These classes are deprecated from <span class="application">gtkmm</span> version 3.22 and should not be used in
newly-written code.
</p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-actions"></a>Actions</h2></div></div></div>
<p>
First create the <code class="classname">Gio::SimpleAction</code>s and add them to a
<code class="classname">Gio::SimpleActionGroup</code>, with
<code class="methodname">Gio::ActionMap::add_action()</code>.
(<code class="classname">Gio::ActionMap</code> is a base class of
<code class="classname">Gio::SimpleActionGroup</code>.) Then add the action group to
your window with <code class="methodname">Gtk::Widget::insert_action_group()</code>.
</p>
<p>
The arguments to <code class="methodname">add_action()</code> specify the action's
name, which is used in the menu items and toolbar buttons. You can also specify
a signal handler when calling <code class="methodname">add_action()</code>. This signal
handler will be called when the action is activated via either a menu item or
a toolbar button.
</p>
<p>For instance:
</p>
<pre class="programlisting">
m_refActionGroup = Gio::SimpleActionGroup::create();

m_refActionGroup-&gt;add_action("new", sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_new));
m_refActionGroup-&gt;add_action("open", sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_open));
m_refActionGroup-&gt;add_action("quit", sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_quit));

insert_action_group("example", m_refActionGroup);
</pre>
<p>
If you use an <code class="classname">Gtk::ApplicationWindow</code>, you don't have to
create your own action group. <code class="classname">Gio::ActionGroup</code> and
<code class="classname">Gio::ActionMap</code> are base classes of
<code class="classname">Gtk::ApplicationWindow</code>.
</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-textview-examples.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-menubar-and-toolbar.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Examples </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"> Menubar and Toolbar</td>
</tr>
</table>
</div>
</body>
</html>