gtk::GtkEventSource< T > Class Template Reference

Enable caller to handle GTK events without inheriting from any class. One-one connection. It's better to use template based technology. By GtkEventSource caller is able to handle multiple widgets' events. More...

#include <test_gtk_source.h>

Inheritance diagram for gtk::GtkEventSource< T >:
Inheritance graph
[legend]
Collaboration diagram for gtk::GtkEventSource< T >:
Collaboration graph
[legend]

Public Types

enum  EventType {
  EVENT_EXPOSE = 0, EVENT_CONFIG, EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE,
  EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS, EVENT_KEY_RELEASE, EVENT_DELETE,
  EVENT_FD_INPUT, EVENT_UNDEFINED, EVENT_EXPOSE = 0, EVENT_CONFIG,
  EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE, EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS,
  EVENT_KEY_RELEASE, EVENT_DELETE, EVENT_FD_INPUT, EVENT_UNDEFINED,
  EVENT_EXPOSE = 0, EVENT_VISIBILITY_NOTIFY, EVENT_CONFIG, EVENT_BUTTON_PRESS,
  EVENT_BUTTON_RELEASE, EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS, EVENT_KEY_RELEASE,
  EVENT_DELETE, EVENT_MAX
}
enum  EventType {
  EVENT_EXPOSE = 0, EVENT_CONFIG, EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE,
  EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS, EVENT_KEY_RELEASE, EVENT_DELETE,
  EVENT_FD_INPUT, EVENT_UNDEFINED, EVENT_EXPOSE = 0, EVENT_CONFIG,
  EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE, EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS,
  EVENT_KEY_RELEASE, EVENT_DELETE, EVENT_FD_INPUT, EVENT_UNDEFINED,
  EVENT_EXPOSE = 0, EVENT_VISIBILITY_NOTIFY, EVENT_CONFIG, EVENT_BUTTON_PRESS,
  EVENT_BUTTON_RELEASE, EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS, EVENT_KEY_RELEASE,
  EVENT_DELETE, EVENT_MAX
}
enum  EventType {
  EVENT_EXPOSE = 0, EVENT_CONFIG, EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE,
  EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS, EVENT_KEY_RELEASE, EVENT_DELETE,
  EVENT_FD_INPUT, EVENT_UNDEFINED, EVENT_EXPOSE = 0, EVENT_CONFIG,
  EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE, EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS,
  EVENT_KEY_RELEASE, EVENT_DELETE, EVENT_FD_INPUT, EVENT_UNDEFINED,
  EVENT_EXPOSE = 0, EVENT_VISIBILITY_NOTIFY, EVENT_CONFIG, EVENT_BUTTON_PRESS,
  EVENT_BUTTON_RELEASE, EVENT_MOTION_NOTIFY, EVENT_KEY_PRESS, EVENT_KEY_RELEASE,
  EVENT_DELETE, EVENT_MAX
}

Public Member Functions

 GtkEventSource (T *r)
 ~GtkEventSource ()
void connect_event_handlers (GtkWidget *widget)
 Connect the event handler(slot) with the gtk event(signal).
void set_fd_event_watcher (int fd, gboolean(T::*func)(GtkWidget *widget, GdkEvent *event))
 Set event handler of File Descriptor.
void set_event_handler (EventType type, gboolean(T::*func)(GtkWidget *widget, GdkEvent *event))
 Set event handler of gtk event (from event loop).
 GtkEventSource (T *r)
 ~GtkEventSource ()
void clear (GtkWidget *widget)
 Disconnect all connected signal handlers.
void connect_event_handlers (GtkWidget *widget)
 Connect the event handler(slot) with the gtk event(signal).
void set_fd_event_watcher (int fd, gboolean(T::*func)(GtkWidget *widget, GdkEvent *event))
 Set event handler of File Descriptor.
void set_event_handler (EventType type, gboolean(T::*func)(GtkWidget *widget, GdkEvent *event))
 Set event handler of gtk event (from event loop).
 GtkEventSource (T *r)
 ~GtkEventSource ()
void disconnect_event_handlers (GtkWidget *widget)
 Disconnect all connected signal handlers.
void connect_event_handlers (GtkWidget *widget)
 Connect the event handler(slot) with the gtk event(signal).
void set_event_handler (EventType type, void(T::*func)(GdkEvent *event))
 Set event handler of gtk event (from event loop).

Detailed Description

template<class T>
class gtk::GtkEventSource< T >

Enable caller to handle GTK events without inheriting from any class. One-one connection. It's better to use template based technology. By GtkEventSource caller is able to handle multiple widgets' events.

Definition at line 40 of file test_gtk_source.h.


Member Enumeration Documentation

template<class T>
enum gtk::GtkEventSource::EventType
Enumerator:
EVENT_EXPOSE 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_FD_INPUT 
EVENT_UNDEFINED 
EVENT_EXPOSE 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_FD_INPUT 
EVENT_UNDEFINED 
EVENT_EXPOSE 
EVENT_VISIBILITY_NOTIFY 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_MAX 

Definition at line 41 of file notepad_gtk_source.h.

00042         {
00043             EVENT_EXPOSE = 0,       // signal expose_event
00044             EVENT_VISIBILITY_NOTIFY,// signal visibility_notify_event
00045             EVENT_CONFIG,           // signal configure_event
00046             EVENT_BUTTON_PRESS,     // signal button_press_event
00047             EVENT_BUTTON_RELEASE,   // signal button_release_event
00048             EVENT_MOTION_NOTIFY,    // signal motion_notify_event
00049             EVENT_KEY_PRESS,        // signal key_press_event
00050             EVENT_KEY_RELEASE,      // signal key_release_event
00051             EVENT_DELETE,           // signal delete_event
00052             EVENT_MAX,          // number of events
00053         };

template<class T>
enum gtk::GtkEventSource::EventType
Enumerator:
EVENT_EXPOSE 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_FD_INPUT 
EVENT_UNDEFINED 
EVENT_EXPOSE 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_FD_INPUT 
EVENT_UNDEFINED 
EVENT_EXPOSE 
EVENT_VISIBILITY_NOTIFY 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_MAX 

Definition at line 45 of file gtk_source.h.

template<class T>
enum gtk::GtkEventSource::EventType
Enumerator:
EVENT_EXPOSE 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_FD_INPUT 
EVENT_UNDEFINED 
EVENT_EXPOSE 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_FD_INPUT 
EVENT_UNDEFINED 
EVENT_EXPOSE 
EVENT_VISIBILITY_NOTIFY 
EVENT_CONFIG 
EVENT_BUTTON_PRESS 
EVENT_BUTTON_RELEASE 
EVENT_MOTION_NOTIFY 
EVENT_KEY_PRESS 
EVENT_KEY_RELEASE 
EVENT_DELETE 
EVENT_MAX 

Definition at line 43 of file test_gtk_source.h.


Constructor & Destructor Documentation

template<class T>
gtk::GtkEventSource< T >::GtkEventSource ( T *  r  )  [inline]

Definition at line 58 of file test_gtk_source.h.

00058                               : receiver(r)
00059         {
00060             memset(&callbacks[0], 0, sizeof(callbacks));
00061         }

template<class T>
gtk::GtkEventSource< T >::~GtkEventSource (  )  [inline]

Definition at line 63 of file test_gtk_source.h.

00064         {
00065         }

template<class T>
gtk::GtkEventSource< T >::GtkEventSource ( T *  r  )  [inline]

Definition at line 60 of file gtk_source.h.

00061             : receiver(r)
00062         {
00063             memset(&callbacks[0], 0, sizeof(callbacks));
00064         }

template<class T>
gtk::GtkEventSource< T >::~GtkEventSource (  )  [inline]

Definition at line 66 of file gtk_source.h.

00067         {
00068         }

template<class T>
gtk::GtkEventSource< T >::GtkEventSource ( T *  r  )  [inline]

Definition at line 56 of file notepad_gtk_source.h.

00057             : receiver(r)
00058         {
00059             memset(&callbacks[0], 0, sizeof(callbacks));
00060         }

template<class T>
gtk::GtkEventSource< T >::~GtkEventSource (  )  [inline]

Definition at line 62 of file notepad_gtk_source.h.

00063         {
00064         }


Member Function Documentation

template<class T>
void gtk::GtkEventSource< T >::clear ( GtkWidget *  widget  )  [inline]

Disconnect all connected signal handlers.

Definition at line 71 of file gtk_source.h.

00072         {
00073             for(size_t i = 0; i < handler_ids.size(); ++i)
00074             {
00075                 gtk_signal_disconnect(GTK_OBJECT (widget), handler_ids[i]);
00076             }
00077 
00078             handler_ids.clear();
00079             receiver = 0;
00080             memset(&callbacks[0], 0, sizeof(callbacks));
00081         }

template<class T>
void gtk::GtkEventSource< T >::connect_event_handlers ( GtkWidget *  widget  )  [inline]

Connect the event handler(slot) with the gtk event(signal).

Definition at line 80 of file notepad_gtk_source.h.

00081         {
00082             // events 
00083             gtk_widget_set_events (widget,
00084                 GDK_EXPOSURE_MASK | GDK_BUTTON_MOTION_MASK |
00085                 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
00086                 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_VISIBILITY_NOTIFY_MASK);
00087 
00088             // install event handlers.
00089             handler_ids[EVENT_EXPOSE] = 
00090                 g_signal_connect( GTK_OBJECT(widget), "expose_event",
00091                 G_CALLBACK(widget_event_handler), this);
00092 
00093             handler_ids[EVENT_VISIBILITY_NOTIFY] = 
00094                 g_signal_connect( GTK_OBJECT(widget), "visibility_notify_event",
00095                 G_CALLBACK(widget_event_handler), this);
00096 
00097             handler_ids[EVENT_CONFIG] =
00098                 g_signal_connect( GTK_OBJECT(widget), "configure_event",
00099                 G_CALLBACK(widget_event_handler), this);
00100 
00101             handler_ids[EVENT_BUTTON_PRESS] =
00102                 g_signal_connect( GTK_OBJECT(widget), "button_press_event",
00103                 G_CALLBACK(widget_event_handler), this);
00104 
00105             handler_ids[EVENT_BUTTON_RELEASE] = 
00106                 g_signal_connect( GTK_OBJECT(widget), "button_release_event",
00107                 G_CALLBACK(widget_event_handler), this);
00108 
00109             handler_ids[EVENT_MOTION_NOTIFY] =
00110                 g_signal_connect( GTK_OBJECT(widget), "motion_notify_event",
00111                 G_CALLBACK(widget_event_handler), this);
00112 
00113             handler_ids[EVENT_KEY_PRESS] =
00114                 g_signal_connect( GTK_OBJECT(widget), "key_press_event",
00115                 G_CALLBACK(widget_event_handler), this);
00116 
00117             handler_ids[EVENT_KEY_RELEASE] =
00118                 g_signal_connect( GTK_OBJECT(widget), "key_release_event",
00119                 G_CALLBACK(widget_event_handler), this);
00120 
00121             handler_ids[EVENT_DELETE] =
00122                 g_signal_connect( GTK_OBJECT(widget), "delete_event",
00123                 G_CALLBACK(widget_event_handler), this);
00124         }

template<class T>
void gtk::GtkEventSource< T >::connect_event_handlers ( GtkWidget *  widget  )  [inline]

Connect the event handler(slot) with the gtk event(signal).

Definition at line 84 of file gtk_source.h.

00085         {
00086             // events 
00087             gtk_widget_set_events (widget,
00088                 GDK_EXPOSURE_MASK | GDK_BUTTON_MOTION_MASK |
00089                 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
00090                 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
00091 
00092             // install event handlers.
00093             handler_ids.push_back(
00094                 gtk_signal_connect (GTK_OBJECT (widget), "expose_event",
00095                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00096 
00097             handler_ids.push_back(
00098                 gtk_signal_connect (GTK_OBJECT (widget), "configure_event",
00099                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00100 
00101             handler_ids.push_back(
00102                 gtk_signal_connect (GTK_OBJECT (widget), "button_press_event",
00103                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00104 
00105             handler_ids.push_back(
00106                 gtk_signal_connect (GTK_OBJECT (widget), "button_release_event",
00107                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00108 
00109             handler_ids.push_back(
00110                 gtk_signal_connect (GTK_OBJECT (widget), "motion_notify_event",
00111                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00112 
00113             handler_ids.push_back(
00114                 gtk_signal_connect (GTK_OBJECT (widget), "key_press_event",
00115                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00116 
00117             handler_ids.push_back(
00118                 gtk_signal_connect (GTK_OBJECT (widget), "key_release_event",
00119                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00120 
00121             handler_ids.push_back(
00122                 gtk_signal_connect (GTK_OBJECT (widget), "delete_event",
00123                 GTK_SIGNAL_FUNC (widget_event_handler), this));
00124         }

template<class T>
void gtk::GtkEventSource< T >::connect_event_handlers ( GtkWidget *  widget  )  [inline]

Connect the event handler(slot) with the gtk event(signal).

Definition at line 68 of file test_gtk_source.h.

00069         {
00070             // events 
00071             gtk_widget_set_events (widget,
00072                 GDK_EXPOSURE_MASK | GDK_BUTTON_MOTION_MASK |
00073                 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
00074                 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
00075 
00076             // install event handlers
00077             gtk_signal_connect (GTK_OBJECT (widget), "expose_event",
00078                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00079 
00080             gtk_signal_connect (GTK_OBJECT (widget), "configure_event",
00081                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00082 
00083             gtk_signal_connect (GTK_OBJECT (widget), "button_press_event",
00084                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00085 
00086             gtk_signal_connect (GTK_OBJECT (widget), "button_release_event",
00087                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00088 
00089             gtk_signal_connect (GTK_OBJECT (widget), "motion_notify_event",
00090                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00091 
00092             gtk_signal_connect (GTK_OBJECT (widget), "key_press_event",
00093                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00094 
00095             gtk_signal_connect (GTK_OBJECT (widget), "key_release_event",
00096                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00097 
00098             gtk_signal_connect (GTK_OBJECT (widget), "delete_event",
00099                 GTK_SIGNAL_FUNC (widget_event_handler), this);
00100         }

template<class T>
void gtk::GtkEventSource< T >::disconnect_event_handlers ( GtkWidget *  widget  )  [inline]

Disconnect all connected signal handlers.

Definition at line 67 of file notepad_gtk_source.h.

00068         {
00069             for(int i = 0; i < EVENT_MAX; i++)
00070             {
00071                 if ( handler_ids[i] )
00072                     g_signal_handler_disconnect(GTK_OBJECT (widget), handler_ids[i]);
00073             }
00074 
00075             receiver = 0;
00076             memset(&callbacks[0], 0, sizeof(callbacks));
00077         }

template<class T>
void gtk::GtkEventSource< T >::set_event_handler ( EventType  type,
void(T::*)(GdkEvent *event func 
) [inline]

Set event handler of gtk event (from event loop).

Definition at line 128 of file notepad_gtk_source.h.

00130         {
00131             callbacks[type] = func;
00132         }

template<class T>
void gtk::GtkEventSource< T >::set_event_handler ( EventType  type,
gboolean(T::*)(GtkWidget *widget, GdkEvent *event func 
) [inline]

Set event handler of gtk event (from event loop).

Definition at line 139 of file gtk_source.h.

00142         {
00143             callbacks[type] = func;
00144         }

template<class T>
void gtk::GtkEventSource< T >::set_event_handler ( EventType  type,
gboolean(T::*)(GtkWidget *widget, GdkEvent *event func 
) [inline]

Set event handler of gtk event (from event loop).

Definition at line 115 of file test_gtk_source.h.

00118         {
00119             callbacks[type] = func;
00120         }

template<class T>
void gtk::GtkEventSource< T >::set_fd_event_watcher ( int  fd,
gboolean(T::*)(GtkWidget *widget, GdkEvent *event func 
) [inline]

Set event handler of File Descriptor.

Definition at line 127 of file gtk_source.h.

00130         {
00131             gdk_input_add(fd, GDK_INPUT_READ,
00132                           (GdkInputFunction)fd_event_handler,
00133                           (gpointer)this);
00134 
00135             callbacks[EVENT_FD_INPUT] = func;
00136         }

template<class T>
void gtk::GtkEventSource< T >::set_fd_event_watcher ( int  fd,
gboolean(T::*)(GtkWidget *widget, GdkEvent *event func 
) [inline]

Set event handler of File Descriptor.

Definition at line 103 of file test_gtk_source.h.

00106         {
00107             gdk_input_add(fd, GDK_INPUT_READ,
00108                           (GdkInputFunction)fd_event_handler,
00109                           (gpointer)this);
00110 
00111             callbacks[EVENT_FD_INPUT] = func;
00112         }


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208