c++-gtk-utils
|
This is a class to manage the lifetime of widgets which are not top-level widgets (ie which are not derived from GtkWindow). More...
#include <c++-gtk-utils/widget.h>
Public Member Functions | |
GtkWidget * | get_main_widget () const |
MainWidgetBase (GtkWidget *widget) | |
MainWidgetBase (const MainWidgetBase &)=delete | |
MainWidgetBase & | operator= (const MainWidgetBase &)=delete |
MainWidgetBase ()=delete | |
MainWidgetBase (MainWidgetBase &&obj) | |
MainWidgetBase & | operator= (MainWidgetBase &&obj) |
virtual | ~MainWidgetBase () |
This is a class to manage the lifetime of widgets which are not top-level widgets (ie which are not derived from GtkWindow).
Normally you will not need this class, because the GObject reference counting system coupled with the WinBase class will provide for lifetime management and exception safety, provided that widgets are placed in their containers on a "top-down" basis and the top-level window is managed by a WinBase object.
However, sometimes it is convenient for a class to encapsulate only part of the implementation of a top level window, and for there to be automatic lifetime management of a widget before it is placed in a GTK+ container.
The MainWidgetBase class is intended to achieve this, by managing references with g_object_ref_sink() such that the widget managed by the class and its children are correctly destroyed when the MainWidgetBase class goes out of scope or is deleted even if they are not subsequently placed in another GTK+ container object which calls g_object_ref_sink() on the widget.
This class therefore represents a safety feature which can be used simply by inheriting from it. It also enables a widget to be placed in and removed from a GTK+ container without it being destroyed by the removal, since it is owned by the MainWidgetBase class object.
A similar effect could be achieved by managing a widget with GobjHandle, but MainWidgetBase enables, by inheritance, encapsulation of supplementary operations on the contained widget.
See Writing multi-threaded programs using c++-gtk-utils for particulars about GTK+ thread safety (and so MainWidgetBase thread safety).
MainWidgetBase objects can be used with widget heirarchies created using GtkBuilder. See Using c++-gtk-utils with GtkBuilder for particulars about that.
This class is not compiled into the library if the library is built with the --without-gtk configuration option.
Cgu::MainWidgetBase::MainWidgetBase | ( | GtkWidget * | widget | ) |
The constructor will not throw. It calls g_object_ref_sink() to take ownership of the object to be managed.
widget | The GtkWidget object to be managed by this class. |
|
delete |
This class cannot be copied. The copy constructor is deleted.
|
delete |
The default constructor is deleted. This class requires initialisation with a GtkWidget object or to be moved to - it is intended that a MainWidgetBase object will always be managing a valid GtkWidget object unless it has been moved from and is therefore awaiting destruction.
Cgu::MainWidgetBase::MainWidgetBase | ( | MainWidgetBase && | obj | ) |
The move constructor will not throw.
obj | The MainWidgetBase object to be moved. |
Since 2.0.19
|
virtual |
The destructor will not throw. It calls g_object_unref() to relinquish ownership of the managed object.
|
inline |
Returns the GtkWidget object managed by this class. This method will not throw.
|
delete |
This class cannot be copied. The copy assignment operator is deleted.
MainWidgetBase& Cgu::MainWidgetBase::operator= | ( | MainWidgetBase && | obj | ) |
The move assignment operator will not throw. It will call g_object_unref() on the previously managed GtkWidget object, if any.
obj | The MainWidgetBase object to be moved. |
Since 2.0.19