GtkOL Reference Manual

2.2. GtkOL signals handling

    When an event occurs on a widget, the appropriate message is internally emitted. Each widget as different set of signals. To catch those specific events, most of GUI toolkits offer signal handlers API. Gtk+ enables signal specific connections by specifying an event string identifier and an associated call back such as a "clicked" event on a button.

    GtkOL overlays the libgenerics object listener abstraction. Each of the widgets are associated to a potential specific widget listener i.e. each GUI component class may be associated to a specific listener class. GtkOL automatically performs all of the signal connections on the widgets and calls the associated listeners virtual functions if any is attached. So, in order to catch specific widget signals, the developper has to derive the associated generic listener definition and overload the desired functions.

    As an example, let's consider a button events handler :

// define a specific button listener class, deriving the given generic button listener interface and overloading the desired functions
class CSampleButtonListener : public CButtonListener
{
   // called when the inSender button is about to be shown
   virtual void OnShow (CObject *inSender)
   {
      std::cout << "OnShow" << std::endl;
   }

   // called when the inSender button has been clicked
   virtual void OnClick (CObject *inSender)
   {
      std::cout << "OnClick" << std::endl;
   }
};

// instanciate a button giving it its specific listener
CButton *aButton = new CButton (aOwner, new CSampleButtonListener());

// or instanciate another button without specifying its listener
CButton *anotherButton = new CButton (aOwner);

// and then later, assign its listener
anotherButton -> AssignListener (new CSampleButtonListener());

    Of course, you are not limited to the given listeners API to handle your specific signals. You can directly use the pure Gtk+ API and perform the connections "manualy" if you want to do so.