c++-gtk-utils
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
c++-gtk-utils
widget.h
Go to the documentation of this file.
1
/* Copyright (C) 2005 to 2011 and 2013 Chris Vine
2
3
The library comprised in this file or of which this file is part is
4
distributed by Chris Vine under the GNU Lesser General Public
5
License as follows:
6
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public License
9
as published by the Free Software Foundation; either version 2.1 of
10
the License, or (at your option) any later version.
11
12
This library is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License, version 2.1, for more details.
16
17
You should have received a copy of the GNU Lesser General Public
18
License, version 2.1, along with this library (see the file LGPL.TXT
19
which came with this source code package in the c++-gtk-utils
20
sub-directory); if not, write to the Free Software Foundation, Inc.,
21
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23
*/
24
25
#ifndef CGU_WIDGET_H
26
#define CGU_WIDGET_H
27
28
#include <
c++-gtk-utils/cgu_config.h
>
29
30
#ifdef CGU_USE_GTK
31
#include <gtk/gtk.h>
32
#endif
33
34
namespace
Cgu
{
35
36
#if defined(DOXYGEN_PARSING) || defined(CGU_USE_GTK)
37
38
/**
39
* @class MainWidgetBase widget.h c++-gtk-utils/widget.h
40
* @brief This is a class to manage the lifetime of widgets which are
41
* not top-level widgets (ie which are not derived from GtkWindow).
42
* @sa WinBase GobjHandle
43
*
44
* Normally you will not need this class, because the GObject
45
* reference counting system coupled with the WinBase class will
46
* provide for lifetime management and exception safety, provided that
47
* widgets are placed in their containers on a "top-down" basis and
48
* the top-level window is managed by a WinBase object.
49
*
50
* However, sometimes it is convenient for a class to encapsulate only
51
* part of the implementation of a top level window, and for there to
52
* be automatic lifetime management of a widget before it is placed in
53
* a GTK+ container.
54
*
55
* The MainWidgetBase class is intended to achieve this, by managing
56
* references with g_object_ref_sink() such that the widget managed by
57
* the class and its children are correctly destroyed when the
58
* MainWidgetBase class goes out of scope or is deleted even if they
59
* are not subsequently placed in another GTK+ container object which
60
* calls g_object_ref_sink() on the widget.
61
*
62
* This class therefore represents a safety feature which can be used
63
* simply by inheriting from it. It also enables a widget to be
64
* placed in and removed from a GTK+ container without it being
65
* destroyed by the removal, since it is owned by the MainWidgetBase
66
* class object.
67
*
68
* A similar effect could be achieved by managing a widget with
69
* GobjHandle, but MainWidgetBase enables, by inheritance,
70
* encapsulation of supplementary operations on the contained widget.
71
*
72
* See @ref Threading for particulars about GTK+ thread safety (and so
73
* MainWidgetBase thread safety).
74
*
75
* MainWidgetBase objects can be used with widget heirarchies created
76
* using GtkBuilder. See @ref GtkBuilder for particulars about that.
77
*
78
* This class is not compiled into the library if the library is built
79
* with the \--without-gtk configuration option.
80
*/
81
82
class
MainWidgetBase
{
83
// main widget object
84
GtkWidget* g_widget_p;
85
86
// MainWidgetBase cannot be copied
87
MainWidgetBase
(
const
MainWidgetBase
&);
88
MainWidgetBase
& operator=(
const
MainWidgetBase
&);
89
public
:
90
/**
91
* Returns the GtkWidget object managed by this class. This method
92
* will not throw.
93
* @return The managed GtkWidget object.
94
*/
95
GtkWidget*
get_main_widget
()
const
{
return
g_widget_p;}
96
97
/**
98
* The constructor will not throw. It calls g_object_ref_sink() to
99
* take ownership of the object to be managed.
100
* @param widget The GtkWidget object to be managed by this class.
101
*/
102
MainWidgetBase
(GtkWidget* widget);
103
104
/**
105
* The destructor will not throw. It calls g_object_unref() to
106
* relinquish ownership of the managed object.
107
*/
108
virtual
~MainWidgetBase
();
109
110
/* Only has effect if --with-glib-memory-slices-compat or
111
* --with-glib-memory-slices-no-compat option picked */
112
CGU_GLIB_MEMORY_SLICES_FUNCS
113
};
114
115
#endif // CGU_USE_GTK
116
117
}
// namespace Cgu
118
119
#endif // CGU_WIDGET_H
Cgu
Definition:
application.h:45
Cgu::MainWidgetBase::~MainWidgetBase
virtual ~MainWidgetBase()
Cgu::MainWidgetBase
This is a class to manage the lifetime of widgets which are not top-level widgets (ie which are not d...
Definition:
widget.h:82
CGU_GLIB_MEMORY_SLICES_FUNCS
#define CGU_GLIB_MEMORY_SLICES_FUNCS
Definition:
cgu_config.h:84
Cgu::MainWidgetBase::get_main_widget
GtkWidget * get_main_widget() const
Definition:
widget.h:95
cgu_config.h
Generated on Mon Jan 27 2020 10:40:51 for c++-gtk-utils by
1.8.17