File: chapter-menus-and-toolbars.html

package info (click to toggle)
gtkmm-documentation 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,772 kB
  • sloc: cpp: 15,541; javascript: 1,208; makefile: 1,080; python: 401; xml: 106; perl: 67; sh: 8
file content (129 lines) | stat: -rw-r--r-- 5,334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
      hljs.configure({languages: ['cpp']});
      hljs.highlightAll();
    </script><title>Chapter 15. Menus and Toolbars</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="index.html" title="Programming with gtkmm 4">
<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 15. 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 15. Menus and Toolbars</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="section"><a href="chapter-menus-and-toolbars.html#sec-actions">Actions</a></span></li>
<li><span class="section"><a href="sec-menubar-and-toolbar.html">Menubar and Toolbar</a></span></li>
<li><span class="section"><a href="sec-menus-popup.html">Popup Menus</a></span></li>
<li><span class="section"><a href="sec-gio-resource.html">Gio::Resource and glib-compile-resources</a></span></li>
<li><span class="section"><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>

<div class="section">
<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"><code class="code">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);
</code></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>