File: changes-gtkmm4.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 (246 lines) | stat: -rw-r--r-- 15,477 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<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 5. Changes in gtkmm-4.0 and glibmm-2.68</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="changes-gtkmm3.html" title="Chapter 4. Changes in gtkmm 3">
<link rel="next" href="chapter-button-widget.html" title="Chapter 6. Buttons">
</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 5. Changes in <span class="application">gtkmm</span>-4.0 and <span class="application">glibmm-2.68</span>
</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="changes-gtkmm3.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="chapter-button-widget.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="changes-gtkmm4"></a>Chapter 5. Changes in <span class="application">gtkmm</span>-4.0 and <span class="application">glibmm-2.68</span>
</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc"><li><span class="section"><a href="changes-gtkmm4.html#sec-deprecations-4-10">Deprecations in <span class="application">gtkmm</span> 4.10</a></span></li></ul>
</div>


<p><span class="application">gtkmm</span>-4.0 is a new version of the <span class="application">gtkmm</span> API that installs in parallel with the
older <span class="application">gtkmm</span>-2.4 and <span class="application">gtkmm</span>-3.0 APIs. The last version of the <span class="application">gtkmm</span>-3.0 API
is <span class="application">gtkmm</span> 3.24. <span class="application">gtkmm</span> 4 has no major fundamental differences to <span class="application">gtkmm</span> 3 but
does make several changes (both small and large ones) that were not possible while
maintaining binary compatibility. If you never used the <span class="application">gtkmm</span>-3.0 API then you
can safely ignore this chapter.
</p>

<p><span class="application">gtkmm</span> 4's library is called <code class="literal">libgtkmm-4.0</code> rather than
<code class="literal">libgtkmm-3.0</code> and installs its headers in a similarly-versioned
directory, so your <span class="application">pkg-config</span> check should ask for
<code class="literal">gtkmm-4.0</code> rather than <code class="literal">gtkmm-3.0</code>.
</p>

<p><span class="application">gtkmm</span>-4.0 is used in combination with <span class="application">glibmm-2.68</span>,
which sets the global locale for your program. The older <span class="application">glibmm-2.4</span>
does not do that, and <span class="application">gtkmm</span>-3.0 does it only to some extent. What this means is
briefly that if your <span class="application">gtkmm</span>-3.0 program contains a call to
<code class="function">std::locale::global(std::locale(""))</code>, you can probably remove it.
If you don't want <span class="application">glibmm</span> or <span class="application">gtkmm</span>
to set the global locale for you, you should add a call to
<code class="function">Glib::set_init_to_users_preferred_locale(false)</code> before any call to
<code class="function">Glib::init()</code> or <code class="methodname">Gtk::Application::create()</code>.
See the <span class="application">glibmm</span> <a class="ulink" href="https://gnome.pages.gitlab.gnome.org/glibmm/namespaceGlib.html" target="_top">
reference</a>.</p>

<p>There are lots and lots of differences between <span class="application">gtkmm</span>-3.0 and <span class="application">gtkmm</span>-4.0.
The following lists are not complete.</p>

<p>There are some important behavioural changes, to which you must adapt when migrating:</p>
<p>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Whereas in <span class="application">gtkmm</span>-3.0, destruction of a non-managed C++ widget wrapper caused the wrapped GtkWidget
to be destroyed, changes in GTK4 mean that in <span class="application">gtkmm</span>-4.0 this canʼt always be the case. GTK4 has no
uniform way to remove a widget from a parent, as GTK3 did with <code class="methodname">Gtk::Container::remove()</code>,
so <span class="application">gtkmm</span>-4.0 canʼt do the removal for you as <span class="application">gtkmm</span>-3.0 did. Hence, if a non-managed C++ widget
instance is destructed while the widget is a child of another, <span class="application">gtkmm</span>-4.0 wonʼt remove it from the
parent, the parent retains a ref that stops the child being disposed, and the GtkWidget stays alive.
The end result is that to destroy a non-managed widget with its C++ wrapper you must first remove it
from its parent (however that parent allows) so the C++ wrapperʼs dtor can drop the final reference.
</li></ul></div>
<p>
</p>

<p>Some new classes were added in <span class="application">gtkmm</span> 4 and <span class="application">glibmm</span> 2.68:</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<code class="classname">Glib::ExtraClassInit</code> and <code class="classname">Gtk::Snapshot</code>:
  These classes are needed only for writing custom widgets. See the
  <a class="link" href="sec-custom-widgets.html" title="Custom Widgets">Custom Widgets</a> section.</li>
<li class="listitem">
<code class="classname">Gtk::EventControllerKey</code>,
  <code class="classname">Gtk::EventControllerMotion</code>, <code class="classname">Gtk::EventControllerScroll</code>
  and <code class="classname">Gtk::GestureStylus</code>
</li>
<li class="listitem">
<code class="classname">Gdk::Paintable</code>, <code class="classname">Gdk::Texture</code>,
  <code class="classname">Gtk::Picture</code> and <code class="classname">Gtk::WidgetPaintable</code>
  </li>
<li class="listitem">
<code class="classname">Gdk::Window</code> has been renamed to <code class="classname">Gdk::Surface</code>.
  (<code class="classname">Gtk::Window</code> keeps its name.)</li>
<li class="listitem">
<code class="classname">Gdk::DrawContext</code> and <code class="classname">Gdk::CairoContext</code>
  are new. <code class="classname">Gdk::DrawingContext</code> has been removed.</li>
<li class="listitem">
<code class="classname">Gtk::Clipboard</code> has been replaced by the new
  <code class="classname">Gdk::Clipboard</code>.</li>
<li class="listitem">
<code class="classname">Gdk::DragContext</code> has been split into
  <code class="classname">Gdk::Drag</code> and <code class="classname">Gdk::Drop</code>.</li>
</ol></div>

<p>There have also been several changes to the API, which you will probably encounter
when porting code that used <span class="application">gtkmm</span>-3.0 and <span class="application">glibmm</span>-2.4. Here is a short list:</p>
<p>
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">A C++17 compiler is required.</li>
<li class="listitem">
<code class="classname">Gtk::Button</code>, <code class="classname">Gtk::ToolButton</code>,
  <code class="classname">Gtk::MenuItem</code> and <code class="classname">Gtk::Switch</code>
  implement the <code class="classname">Gtk::Actionable</code> interface instead of the removed
  <code class="classname">Gtk::Activatable</code> interface.</li>
<li class="listitem">
<code class="classname">Gtk::FontButton</code> implements the <code class="classname">Gtk::FontChooser</code> interface.</li>
<li class="listitem">
<code class="classname">Gtk::Widget</code>: The <code class="methodname">get_preferred_*_vfunc()</code>s
  have been replaced by <code class="methodname">measure_vfunc()</code>. This change only affects
  custom widgets.</li>
<li class="listitem">
<code class="classname">sigc::slot</code>s use the <code class="classname">sigc::slot&lt;R(Args...)&gt;</code> syntax.
  Example: <code class="classname">sigc::slot&lt;void(int, int)&gt;</code> instead of <code class="classname">sigc::slot&lt;void, int, int&gt;</code>.</li>
<li class="listitem">
<code class="classname">Gtk::DrawingArea</code> uses a draw function instead of the draw signal.</li>
<li class="listitem">
<code class="classname">Glib::ArrayHandle</code>, <code class="classname">Glib::StringArrayHandle</code>,
  <code class="classname">Glib::ListHandle</code> and <code class="classname">Glib::SListHandle</code> have been removed.
  They were used in <span class="application">glibmm</span>-2.4, but not used in <span class="application">gtkmm</span>-3.0.
  If you've ever used these classes, replace them with a standard C++ container, such as <code class="classname">std::vector</code>.</li>
<li class="listitem">
<code class="classname">Gtk::Container</code> has been removed.</li>
<li class="listitem">
<code class="methodname">Gtk::Widget::show_all()</code> has been removed. The default value
  of <code class="methodname">Gtk::Widget::property_visible()</code> has been changed from
  <code class="literal">false</code> to <code class="literal">true</code>.</li>
<li class="listitem">All event signals have been removed from <code class="classname">Gtk::Widget</code>.
  In most cases you can use one of the subclasses of <code class="classname">Gtk::EventController</code>
  as a replacement. For instance, use <code class="classname">Gtk::GestureMultiPress</code>
  instead of <code class="methodname">signal_button_press_event()</code> and
  <code class="methodname">signal_button_release_event()</code>, and <code class="classname">Gtk::EventControllerKey</code>
  instead of <code class="methodname">signal_key_press_event()</code> and
  <code class="methodname">signal_key_release_event()</code>.</li>
<li class="listitem">
<code class="classname">Glib::RefPtr</code> is an alias for <code class="classname">std::shared_ptr</code>.
  If you make your own <code class="classname">Glib::ObjectBase</code>-derived classes with
  <code class="methodname">create()</code> methods that return a <code class="classname">Glib::RefPtr</code>,
  you must use <code class="methodname">Glib::make_refptr_for_instance()</code> in your
  <code class="methodname">create()</code> methods.</li>
<li class="listitem">
<code class="methodname">Gtk::Box::pack_start()</code> and <code class="methodname">Gtk::Box::pack_end()</code>
  have been removed. Use the new <code class="classname">Gtk::Box</code> methods
  <code class="methodname">append()</code>, <code class="methodname">prepend()</code>,
  <code class="methodname">insert_child_after()</code> and <code class="methodname">insert_child_at_start()</code>.
  </li>
<li class="listitem">
<code class="classname">Gtk::ButtonBox</code> has been removed.</li>
<li class="listitem">
<code class="classname">Gtk::RadioButton</code> and <code class="classname">Gtk::RadioButtonGroup</code>
  have been removed. Use <code class="classname">Gtk::CheckButton</code> or <code class="classname">Gtk::ToggleButton</code>
  with <code class="methodname">set_group()</code>.</li>
</ol></div>
<p>
</p>
<p>All deprecated API was removed in <span class="application">gtkmm</span> 4.0 and <span class="application">glibmm</span> 2.68,
  though there will be new deprecations in future versions.</p>

<p>As a first step to porting your source code to <span class="application">gtkmm</span>-4.0 you should probably ensure
that your application builds with the deprecated <span class="application">gtkmm</span>-3.0 and <span class="application">glibmm-2.4</span>
API disabled, by defining the macros GTKMM_DISABLE_DEPRECATED, GDKMM_DISABLE_DEPRECATED,
GLIBMM_DISABLE_DEPRECATED and GIOMM_DISABLE_DEPRECATED. There are some autotools macros
that can help with this by defining them optionally at build time. See the
<a class="ulink" href="https://wiki.gnome.org/Projects/gtkmm/PortingToGtkmm3" target="_top">Porting from
gtkmm-2.4 to gtkmm-3.0</a> wiki page for more details.</p>
<p>See also <a class="ulink" href="https://docs.gtk.org/gtk4/migrating-3to4.html" target="_top">
Migrating from GTK 3.x to GTK 4</a>.</p>

<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-deprecations-4-10"></a>Deprecations in <span class="application">gtkmm</span> 4.10</h2></div></div></div>

<p>Many classes are deprecated since <span class="application">gtkmm</span> 4.10. They can still be used in
<span class="application">gtkmm</span>4 applications, provided GTKMM_DISABLE_DEPRECATED and GDKMM_DISABLE_DEPRECATED
are not defined. There are also many new classes in <span class="application">gtkmm</span> 4.10, which replace
some of the deprecated classes. Some example programs in this tutorial use classes
deprecated since <span class="application">gtkmm</span> 4.10. Some other programs use classes available since <span class="application">gtkmm</span> 4.10.
</p>
<p>Deprecated classes:
  AppChooser, AppChooserButton, AppChooserDialog,
  AppChooserWidget, CellArea, CellAreaBox, CellAreaContext,
  CellLayout, CellRenderer, CellRendererAccel, CellRendererCombo,
  CellRendererPixbuf, CellRendererProgress, CellRendererSpin,
  CellRendererSpinner, CellRendererText, CellRendererToggle, CellView,
  ComboBox, ComboBoxText, EntryCompletion, IconView, ListStore,
  ListViewText, StyleContext, TreeDragDest, TreeDragSource,
  TreeIter and other classes in treeiter.h,
  TreeModel, TreeModelFilter, TreeModelSort, TreePath, TreeRowReference,
  TreeSelection, TreeSortable, TreeStore, TreeView, TreeViewColumn,
  namespace CellRenderer_Generation, namespace TreeView_Private,
  ColorButton, ColorChooser, ColorChooserDialog,
  FileChooser, FileChooserDialog, FileChooserNative, FileChooserWidget,
  FontButton, FontChooser, FontChooserDialog, FontChooserWidget,
  MessageDialog, TreeModelColumn, TreeModelColumnRecord, InfoBar,
  Assistant, AssistantPage, LockButton, Statusbar, VolumeButton.
</p>
<p>New classes and enums:
  AlertDialog, ColorDialog, ColorDialogButton, ColumnViewSorter, FileDialog,
  FontDialog, FontDialogButton, FileLauncher, UriLauncher, ATContext,
  enums DialogError, FontLevel, Collation.
</p>
<p>In most cases there are replacements for the deprecated classes.
See the reference documentation.
</p>
</div>

</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="changes-gtkmm3.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="chapter-button-widget.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 4. Changes in <span class="application">gtkmm</span> 3 </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"> Chapter 6. Buttons</td>
</tr>
</table>
</div>
</body>
</html>