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
|
<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 30. Recommended Techniques</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-multithread-example.html" title="Example">
<link rel="next" href="sec-using-a-gtkmm-widget.html" title="Using a gtkmm widget">
</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 30. Recommended Techniques</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-multithread-example.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-using-a-gtkmm-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="chapter-recommended-techniques"></a>Chapter 30. Recommended Techniques</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="section"><a href="chapter-recommended-techniques.html#sec-application-lifetime">Application Lifetime</a></span></li>
<li><span class="section"><a href="sec-using-a-gtkmm-widget.html">Using a <span class="application">gtkmm</span> widget</a></span></li>
</ul>
</div>
<p>This section is simply a gathering of wisdom, general style guidelines
and hints for creating <span class="application">gtkmm</span> applications.
</p>
<p>Use <span class="application">Meson</span>! It is your friend :)
It examines C and C++ files, determines how they depend on each other,
and generates <code class="filename">build.ninja</code> or an equivalent file so the
files can be compiled in the correct order. <span class="application">Meson</span>
permits automatic configuration of software installation, handling a large
number of system quirks to increase portability.
</p>
<p>Subclass Widgets to better organize your code. You should probably
subclass your main <code class="classname">Window</code> at least. Then you can
make your child Widgets and signal handlers members of that class.
</p>
<p>Create your own signals instead of passing pointers around. Objects can
communicate with each other via signals and signal handlers. This is much
simpler than objects holding pointers to each other and calling each
other's methods. <span class="application">gtkmm</span>'s classes use special versions of
<code class="classname">sigc::signal</code>, but you should use normal
<code class="classname">sigc::signal</code>s, as described in the
<span class="application">libsigc++</span> documentation.</p>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-application-lifetime"></a>Application Lifetime</h2></div></div></div>
<p>Most applications will have only one <code class="classname">Window</code>, or
only one main window. These applications can use
<code class="methodname">Gtk::Application::make_window_and_run(int argc, char** argv, T_Args&&... args)</code>.
It creates and shows a window. When the window is hidden, <code class="methodname">make_window_and_run()</code>
deletes the window and returns to the caller.
This might happen when the user closes the window, or when your code decides to
hide the window with <code class="methodname">set_visible(false)</code>. You can prevent the user from
closing the window (for instance, if there are unsaved changes) by
overriding <code class="methodname">Gtk::Window::on_close_request()</code>.</p>
<p>Most of our examples use this technique.</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-multithread-example.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-using-a-gtkmm-widget.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Example </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"> Using a <span class="application">gtkmm</span> widget</td>
</tr>
</table>
</div>
</body>
</html>
|