summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgustav_b <gustav_b@users.sourceforge.net>2007-09-19 01:37:56 +0000
committergustav_b <gustav_b@users.sourceforge.net>2007-09-19 01:37:56 +0000
commitfb94087914ce11cae8892b1ac3845b9d5ae4052a (patch)
tree1a038bd0bbc98e7eaa95bf98be1186b29bc16d73 /src
parentCleaned up Dialog class, coding style, unused code, etc. (only (diff)
downloadinkscape-fb94087914ce11cae8892b1ac3845b9d5ae4052a.tar.gz
inkscape-fb94087914ce11cae8892b1ac3845b9d5ae4052a.zip
Move more dialog event handling into Dialog class, work in progress on
focus issues. (bzr r3767)
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/dialog.cpp92
-rw-r--r--src/ui/dialog/dialog.h5
2 files changed, 77 insertions, 20 deletions
diff --git a/src/ui/dialog/dialog.cpp b/src/ui/dialog/dialog.cpp
index e7f1a7e13..cb9ea0226 100644
--- a/src/ui/dialog/dialog.cpp
+++ b/src/ui/dialog/dialog.cpp
@@ -19,6 +19,7 @@
#include <gtkmm/stock.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include "application/application.h"
#include "application/editor.h"
@@ -27,7 +28,7 @@
#include "desktop.h"
#include "desktop-handles.h"
#include "dialog-manager.h"
-#include "dialogs/dialog-events.h"
+#include "modifier-fns.h"
#include "shortcuts.h"
#include "prefs-utils.h"
#include "interface.h"
@@ -109,8 +110,6 @@ Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_pat
_behavior = behavior_factory(*this);
- gtk_signal_connect( GTK_OBJECT (gobj()), "event", GTK_SIGNAL_FUNC(sp_dialog_event_handler), gobj() );
-
if (Inkscape::NSApplication::Application::getNewGui()) {
_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*this, &Dialog::onDesktopActivated));
_dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::mem_fun (*this, &Dialog::onHideF12));
@@ -123,7 +122,8 @@ Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_pat
g_signal_connect(G_OBJECT(INKSCAPE), "shut_down", G_CALLBACK(sp_dialog_shutdown), (void *)this);
}
- Glib::wrap(gobj())->signal_key_press_event().connect(sigc::ptr_fun(&windowKeyPress));
+ Glib::wrap(gobj())->signal_event().connect(sigc::mem_fun(*this, &Dialog::_onEvent));
+ Glib::wrap(gobj())->signal_key_press_event().connect(sigc::mem_fun(*this, &Dialog::_onKeyPress));
if (prefs_get_int_attribute ("dialogs", "showclose", 0) || apply_label) {
// TODO: make the order of buttons obey the global preference
@@ -155,20 +155,6 @@ Dialog::~Dialog()
//---------------------------------------------------------------------
-bool Dialog::windowKeyPress(GdkEventKey *event)
-{
- unsigned int shortcut = 0;
- shortcut = get_group0_keyval (event) |
- ( event->state & GDK_SHIFT_MASK ?
- SP_SHORTCUT_SHIFT_MASK : 0 ) |
- ( event->state & GDK_CONTROL_MASK ?
- SP_SHORTCUT_CONTROL_MASK : 0 ) |
- ( event->state & GDK_MOD1_MASK ?
- SP_SHORTCUT_ALT_MASK : 0 );
- return sp_shortcut_invoke( shortcut, SP_ACTIVE_DESKTOP );
-
-}
-
void
Dialog::onDesktopActivated(SPDesktop *desktop)
{
@@ -315,6 +301,59 @@ Dialog::_onDeleteEvent(GdkEventAny *event)
return false;
}
+bool
+Dialog::_onEvent(GdkEvent *event)
+{
+ bool ret = false;
+
+ switch (event->type) {
+ case GDK_KEY_PRESS: {
+ ret = _onKeyPress(&event->key);
+ break;
+ }
+ default:
+ ;
+ }
+
+ return ret;
+}
+
+bool
+Dialog::_onKeyPress(GdkEventKey *event)
+{
+ bool ret = false;
+ switch (get_group0_keyval (event)) {
+ case GDK_Escape: {
+ _defocus();
+ ret = true;
+ break;
+ }
+ case GDK_F4:
+ case GDK_w:
+ case GDK_W: {
+ if (mod_ctrl_only(event->state)) {
+ _close();
+ ret = true;
+ }
+ break;
+ }
+ default: { // pass keypress to the canvas
+ unsigned int shortcut;
+ shortcut = get_group0_keyval (event) |
+ ( event->state & GDK_SHIFT_MASK ?
+ SP_SHORTCUT_SHIFT_MASK : 0 ) |
+ ( event->state & GDK_CONTROL_MASK ?
+ SP_SHORTCUT_CONTROL_MASK : 0 ) |
+ ( event->state & GDK_MOD1_MASK ?
+ SP_SHORTCUT_ALT_MASK : 0 );
+ sp_shortcut_invoke( shortcut, SP_ACTIVE_DESKTOP );
+ break;
+ }
+ }
+
+ return ret;
+}
+
void
Dialog::_apply()
{
@@ -346,6 +385,23 @@ Dialog::_close()
g_object_unref(G_OBJECT(event.window));
}
+void
+Dialog::_defocus()
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+
+ if (desktop) {
+ Gtk::Widget *canvas = Glib::wrap(GTK_WIDGET(desktop->canvas));
+
+ // make sure the canvas window is present before giving it focus
+ Gtk::Window *toplevel_window = dynamic_cast<Gtk::Window *>(canvas->get_toplevel());
+ if (toplevel_window)
+ toplevel_window->present();
+
+ canvas->grab_focus();
+ }
+}
+
Inkscape::Selection*
Dialog::_getSelection()
{
diff --git a/src/ui/dialog/dialog.h b/src/ui/dialog/dialog.h
index 2d1ef7af3..5a9e65645 100644
--- a/src/ui/dialog/dialog.h
+++ b/src/ui/dialog/dialog.h
@@ -104,11 +104,12 @@ protected:
virtual void _onResponse(int response_id);
virtual bool _onDeleteEvent (GdkEventAny*);
+ virtual bool _onEvent(GdkEvent *event);
+ virtual bool _onKeyPress(GdkEventKey *event);
virtual void _apply();
virtual void _close();
-
- static bool windowKeyPress(GdkEventKey *event);
+ virtual void _defocus();
Inkscape::Selection* _getSelection();