summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 261bc49)
raw | patch | inline | side by side (parent: 261bc49)
author | gustav_b <gustav_b@users.sourceforge.net> | |
Wed, 19 Sep 2007 01:37:56 +0000 (01:37 +0000) | ||
committer | gustav_b <gustav_b@users.sourceforge.net> | |
Wed, 19 Sep 2007 01:37:56 +0000 (01:37 +0000) |
focus issues.
src/ui/dialog/dialog.cpp | patch | blob | history | |
src/ui/dialog/dialog.h | patch | blob | history |
index e7f1a7e135b8f979589d340ea07b351395ccf96e..cb9ea02262c7ff3aaf371d2ee1d2672a25bbe08d 100644 (file)
--- a/src/ui/dialog/dialog.cpp
+++ b/src/ui/dialog/dialog.cpp
#include <gtkmm/stock.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include "application/application.h"
#include "application/editor.h"
#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
//---------------------------------------------------------------------
-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)
{
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()
{
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 2d1ef7af3b4bd10565a62d3ae21cb2d3308b4ff1..5a9e656457e3b7138231cf17dbb1d2098dae2165 100644 (file)
--- a/src/ui/dialog/dialog.h
+++ b/src/ui/dialog/dialog.h
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();