c++-gtk-utils: Cgu::MainWidgetBase Class Reference

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

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.

Parameters

  obj | The MainWidgetBase object to be moved.

Since 2.0.19/2.2.2

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 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.

Parameters

  obj | The MainWidgetBase object to be moved.

Since 2.0.19/2.2.2

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

- widget.h