c++-gtk-utils
Public Member Functions | List of all members
Cgu::MainWidgetBase Class Reference

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)
 
virtual ~MainWidgetBase ()
 

Detailed Description

This is a class to manage the lifetime of widgets which are not top-level widgets (ie which are not derived from GtkWindow).

See also
WinBase GobjHandle

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.

Constructor & Destructor Documentation

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.

Parameters
widgetThe GtkWidget object to be managed by this class.
virtual Cgu::MainWidgetBase::~MainWidgetBase ( )
virtual

The destructor will not throw. It calls g_object_unref() to relinquish ownership of the managed object.

Member Function Documentation

GtkWidget* Cgu::MainWidgetBase::get_main_widget ( ) const
inline

Returns the GtkWidget object managed by this class. This method will not throw.

Returns
The managed GtkWidget object.

The documentation for this class was generated from the following file: