c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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)
| MainWidgetBase (const MainWidgetBase &)=delete
MainWidgetBase & | operator= (const MainWidgetBase &)=delete
| MainWidgetBase ()=delete
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

  widget | The GtkWidget object to be managed by this class.

Cgu::MainWidgetBase::MainWidgetBase | ( | const MainWidgetBase & |  | ) |
| delete

This class cannot be copied. The copy constructor is deleted.

Cgu::MainWidgetBase::MainWidgetBase | ( |  | ) |
| delete

This class requires initialisation with a GtkWidget object. The default constructor is deleted.

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.

MainWidgetBase& Cgu::MainWidgetBase::operator= | ( | const MainWidgetBase & |  | ) |
| delete

This class cannot be copied. The assignment operator is deleted.

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

- widget.h