Remove <gtk/gtk.h> from gtkutil/nonmodal.h
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 22 Jul 2017 06:51:43 +0000 (16:51 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 31 Jul 2017 12:35:47 +0000 (22:35 +1000)
libs/gtkutil/CMakeLists.txt
libs/gtkutil/nonmodal.cpp [new file with mode: 0644]
libs/gtkutil/nonmodal.h

index 0bce430..962b6aa 100644 (file)
@@ -15,7 +15,7 @@ add_library(gtkutil
         image.cpp image.h
         menu.cpp menu.h
         messagebox.cpp messagebox.h
-        nonmodal.h
+        nonmodal.cpp nonmodal.h
         paned.cpp paned.h
         pointer.h
         toolbar.cpp toolbar.h
diff --git a/libs/gtkutil/nonmodal.cpp b/libs/gtkutil/nonmodal.cpp
new file mode 100644 (file)
index 0000000..f14d72d
--- /dev/null
@@ -0,0 +1,112 @@
+#include "nonmodal.h"
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+gboolean escape_clear_focus_widget(ui::Widget widget, GdkEventKey *event, gpointer data)
+{
+    if (event->keyval == GDK_KEY_Escape) {
+        gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), NULL);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+void widget_connect_escape_clear_focus_widget(ui::Widget widget)
+{
+    g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(escape_clear_focus_widget), 0);
+}
+
+gboolean NonModalEntry::focus_in(ui::Entry entry, GdkEventFocus *event, NonModalEntry *self)
+{
+    self->m_editing = false;
+    return FALSE;
+}
+
+gboolean NonModalEntry::focus_out(ui::Entry entry, GdkEventFocus *event, NonModalEntry *self)
+{
+    if (self->m_editing && gtk_widget_get_visible(GTK_WIDGET(entry))) {
+        self->m_apply();
+    }
+    self->m_editing = false;
+    return FALSE;
+}
+
+gboolean NonModalEntry::changed(ui::Entry entry, NonModalEntry *self)
+{
+    self->m_editing = true;
+    return FALSE;
+}
+
+gboolean NonModalEntry::enter(ui::Entry entry, GdkEventKey *event, NonModalEntry *self)
+{
+    if (event->keyval == GDK_Return) {
+        self->m_apply();
+        self->m_editing = false;
+        gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(entry))), NULL);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+gboolean NonModalEntry::escape(ui::Entry entry, GdkEventKey *event, NonModalEntry *self)
+{
+    if (event->keyval == GDK_Escape) {
+        self->m_cancel();
+        self->m_editing = false;
+        gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(entry))), NULL);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+void NonModalEntry::connect(ui::Entry entry)
+{
+    g_signal_connect(G_OBJECT(entry), "focus_in_event", G_CALLBACK(focus_in), this);
+    g_signal_connect(G_OBJECT(entry), "focus_out_event", G_CALLBACK(focus_out), this);
+    g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(enter), this);
+    g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(escape), this);
+    g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(changed), this);
+}
+
+gboolean NonModalSpinner::changed(ui::SpinButton spin, NonModalSpinner *self)
+{
+    self->m_apply();
+    return FALSE;
+}
+
+gboolean NonModalSpinner::enter(ui::SpinButton spin, GdkEventKey *event, NonModalSpinner *self)
+{
+    if (event->keyval == GDK_Return) {
+        gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(spin))), NULL);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+gboolean NonModalSpinner::escape(ui::SpinButton spin, GdkEventKey *event, NonModalSpinner *self)
+{
+    if (event->keyval == GDK_Escape) {
+        self->m_cancel();
+        gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(spin))), NULL);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+void NonModalSpinner::connect(ui::SpinButton spin)
+{
+    guint handler = g_signal_connect(G_OBJECT(gtk_spin_button_get_adjustment(spin)), "value_changed",
+                                     G_CALLBACK(changed), this);
+    g_object_set_data(G_OBJECT(spin), "handler", gint_to_pointer(handler));
+    g_signal_connect(G_OBJECT(spin), "key_press_event", G_CALLBACK(enter), this);
+    g_signal_connect(G_OBJECT(spin), "key_press_event", G_CALLBACK(escape), this);
+}
+
+void NonModalRadio::connect(ui::RadioButton radio)
+{
+    GSList *group = gtk_radio_button_get_group(radio);
+    for (; group != 0; group = g_slist_next(group)) {
+        toggle_button_connect_callback(ui::ToggleButton(GTK_TOGGLE_BUTTON(group->data)), m_changed);
+    }
+}
index 98f05b1..6fc043c 100644 (file)
 #if !defined( INCLUDED_GTKUTIL_NONMODAL_H )
 #define INCLUDED_GTKUTIL_NONMODAL_H
 
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-
+#include <gdk/gdk.h>
 #include "generic/callback.h"
 
 #include "pointer.h"
 #include "button.h"
 
-inline gboolean escape_clear_focus_widget( ui::Widget widget, GdkEventKey* event, gpointer data ){
-       if ( event->keyval == GDK_KEY_Escape ) {
-               gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
-               return TRUE;
-       }
-       return FALSE;
-}
-
-inline void widget_connect_escape_clear_focus_widget( ui::Widget widget ){
-       g_signal_connect( G_OBJECT( widget ), "key_press_event", G_CALLBACK( escape_clear_focus_widget ), 0 );
-}
-
-
-class NonModalEntry
-{
-bool m_editing;
-Callback m_apply;
-Callback m_cancel;
-
-static gboolean focus_in( ui::Entry entry, GdkEventFocus *event, NonModalEntry* self ){
-       self->m_editing = false;
-       return FALSE;
-}
-
-static gboolean focus_out( ui::Entry entry, GdkEventFocus *event, NonModalEntry* self ){
-       if ( self->m_editing && gtk_widget_get_visible( GTK_WIDGET(entry) ) ) {
-               self->m_apply();
-       }
-       self->m_editing = false;
-       return FALSE;
-}
-
-static gboolean changed( ui::Entry entry, NonModalEntry* self ){
-       self->m_editing = true;
-       return FALSE;
-}
-
-static gboolean enter( ui::Entry entry, GdkEventKey* event, NonModalEntry* self ){
-       if ( event->keyval == GDK_Return ) {
-               self->m_apply();
-               self->m_editing = false;
-               gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( entry ) ) ), NULL );
-               return TRUE;
-       }
-       return FALSE;
-}
-
-static gboolean escape( ui::Entry entry, GdkEventKey* event, NonModalEntry* self ){
-       if ( event->keyval == GDK_Escape ) {
-               self->m_cancel();
-               self->m_editing = false;
-               gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( entry ) ) ), NULL );
-               return TRUE;
-       }
-       return FALSE;
-}
+gboolean escape_clear_focus_widget(ui::Widget widget, GdkEventKey *event, gpointer data);
+
+void widget_connect_escape_clear_focus_widget(ui::Widget widget);
+
+class NonModalEntry {
+    bool m_editing;
+    Callback m_apply;
+    Callback m_cancel;
+
+    static gboolean focus_in(ui::Entry entry, GdkEventFocus *event, NonModalEntry *self);
+
+    static gboolean focus_out(ui::Entry entry, GdkEventFocus *event, NonModalEntry *self);
+
+    static gboolean changed(ui::Entry entry, NonModalEntry *self);
+
+    static gboolean enter(ui::Entry entry, GdkEventKey *event, NonModalEntry *self);
+
+    static gboolean escape(ui::Entry entry, GdkEventKey *event, NonModalEntry *self);
 
 public:
-NonModalEntry( const Callback& apply, const Callback& cancel ) : m_editing( false ), m_apply( apply ), m_cancel( cancel ){
-}
-void connect( ui::Entry entry ){
-       g_signal_connect( G_OBJECT( entry ), "focus_in_event", G_CALLBACK( focus_in ), this );
-       g_signal_connect( G_OBJECT( entry ), "focus_out_event", G_CALLBACK( focus_out ), this );
-       g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( enter ), this );
-       g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( escape ), this );
-       g_signal_connect( G_OBJECT( entry ), "changed", G_CALLBACK( changed ), this );
-}
+    NonModalEntry(const Callback &apply, const Callback &cancel) : m_editing(false), m_apply(apply), m_cancel(cancel)
+    {
+    }
+
+    void connect(ui::Entry entry);
 };
 
 
-class NonModalSpinner
-{
-Callback m_apply;
-Callback m_cancel;
-
-static gboolean changed( ui::SpinButton spin, NonModalSpinner* self ){
-       self->m_apply();
-       return FALSE;
-}
-
-static gboolean enter( ui::SpinButton spin, GdkEventKey* event, NonModalSpinner* self ){
-       if ( event->keyval == GDK_Return ) {
-               gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( spin ) ) ), NULL );
-               return TRUE;
-       }
-       return FALSE;
-}
-
-static gboolean escape( ui::SpinButton spin, GdkEventKey* event, NonModalSpinner* self ){
-       if ( event->keyval == GDK_Escape ) {
-               self->m_cancel();
-               gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( spin ) ) ), NULL );
-               return TRUE;
-       }
-       return FALSE;
-}
+class NonModalSpinner {
+    Callback m_apply;
+    Callback m_cancel;
+
+    static gboolean changed(ui::SpinButton spin, NonModalSpinner *self);
+
+    static gboolean enter(ui::SpinButton spin, GdkEventKey *event, NonModalSpinner *self);
+
+    static gboolean escape(ui::SpinButton spin, GdkEventKey *event, NonModalSpinner *self);
 
 public:
-NonModalSpinner( const Callback& apply, const Callback& cancel ) : m_apply( apply ), m_cancel( cancel ){
-}
-void connect( ui::SpinButton spin ){
-       guint handler = g_signal_connect( G_OBJECT( gtk_spin_button_get_adjustment( spin ) ), "value_changed", G_CALLBACK( changed ), this );
-       g_object_set_data( G_OBJECT( spin ), "handler", gint_to_pointer( handler ) );
-       g_signal_connect( G_OBJECT( spin ), "key_press_event", G_CALLBACK( enter ), this );
-       g_signal_connect( G_OBJECT( spin ), "key_press_event", G_CALLBACK( escape ), this );
-}
+    NonModalSpinner(const Callback &apply, const Callback &cancel) : m_apply(apply), m_cancel(cancel)
+    {
+    }
+
+    void connect(ui::SpinButton spin);
 };
 
 
-class NonModalRadio
-{
-Callback m_changed;
+class NonModalRadio {
+    Callback m_changed;
 
 public:
-NonModalRadio( const Callback& changed ) : m_changed( changed ){
-}
-void connect( ui::RadioButton radio ){
-       GSList* group = gtk_radio_button_get_group( radio );
-       for (; group != 0; group = g_slist_next( group ) )
-       {
-               toggle_button_connect_callback( ui::ToggleButton(GTK_TOGGLE_BUTTON( group->data )), m_changed );
-       }
-}
+    NonModalRadio(const Callback &changed) : m_changed(changed)
+    {
+    }
+
+    void connect(ui::RadioButton radio);
 };