X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fdialog%2Fdialog.cpp;h=4fbc217abefb59b856b14195cf219dfc75db7d88;hb=4533e5e378aae1df5a980a1dd6b2359d02891513;hp=16124d9f534b31c964e73cf5ecc1f7b1cb29d01f;hpb=a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799;p=inkscape.git diff --git a/src/ui/dialog/dialog.cpp b/src/ui/dialog/dialog.cpp index 16124d9f5..4fbc217ab 100644 --- a/src/ui/dialog/dialog.cpp +++ b/src/ui/dialog/dialog.cpp @@ -19,6 +19,7 @@ #include #include +#include #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" @@ -40,40 +41,29 @@ namespace Inkscape { namespace UI { namespace Dialog { -static void +void sp_retransientize (Inkscape::Application *inkscape, SPDesktop *desktop, gpointer dlgPtr) { Dialog *dlg = (Dialog *)dlgPtr; dlg->onDesktopActivated (desktop); } -static void -sp_dialog_shutdown (GtkObject *object, gpointer dlgPtr) +gboolean +sp_retransientize_again (gpointer dlgPtr) { Dialog *dlg = (Dialog *)dlgPtr; - dlg->onShutdown(); + dlg->retransientize_suppress = false; + return FALSE; // so that it is only called once } void -Dialog::save_geometry() +sp_dialog_shutdown (GtkObject *object, gpointer dlgPtr) { - int y, x, w, h; - - get_position(x, y); - get_size(w, h); - - // g_print ("write %d %d %d %d\n", x, y, w, h); - - if (x<0) x=0; - if (y<0) y=0; - - prefs_set_int_attribute (_prefs_path, "x", x); - prefs_set_int_attribute (_prefs_path, "y", y); - prefs_set_int_attribute (_prefs_path, "w", w); - prefs_set_int_attribute (_prefs_path, "h", h); - + Dialog *dlg = (Dialog *)dlgPtr; + dlg->onShutdown(); } + void hideCallback(GtkObject *object, gpointer dlgPtr) { g_return_if_fail( dlgPtr != NULL ); @@ -91,77 +81,6 @@ void unhideCallback(GtkObject *object, gpointer dlgPtr) } - -void -Dialog::read_geometry() -{ - _user_hidden = false; - - int x = prefs_get_int_attribute (_prefs_path, "x", -1000); - int y = prefs_get_int_attribute (_prefs_path, "y", -1000); - int w = prefs_get_int_attribute (_prefs_path, "w", 0); - int h = prefs_get_int_attribute (_prefs_path, "h", 0); - - // g_print ("read %d %d %d %d\n", x, y, w, h); - - // If there are stored height and width values for the dialog, - // resize the window to match; otherwise we leave it at its default - if (w != 0 && h != 0) { - resize(w, h); - } - - // If there are stored values for where the dialog should be - // located, then restore the dialog to that position. - // also check if (x,y) is actually onscreen with the current screen dimensions - if ( (x >= 0) && (y >= 0) && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE)) ) { - move(x, y); - } else { - // ...otherwise just put it in the middle of the screen - set_position(Gtk::WIN_POS_CENTER); - } - -} - -inline Dialog::operator Gtk::Widget&() { return *_behavior; } -inline GtkWidget *Dialog::gobj() { return _behavior->gobj(); } -inline void Dialog::present() { _behavior->present(); } -inline Gtk::VBox *Dialog::get_vbox() { return _behavior->get_vbox(); } -inline void Dialog::show_all_children() { _behavior->show_all_children(); } -inline void Dialog::hide() { _behavior->hide(); } -inline void Dialog::show() { _behavior->show(); } -inline void Dialog::set_size_request(int width, int height) { _behavior->set_size_request(width, height); } -inline void Dialog::size_request(Gtk::Requisition& requisition) { _behavior->size_request(requisition); } -inline void Dialog::get_position(int& x, int& y) { _behavior->get_position(x, y); } -inline void Dialog::get_size(int& width, int& height) { _behavior->get_size(width, height); } -inline void Dialog::resize(int width, int height) { _behavior->resize(width, height); } -inline void Dialog::move(int x, int y) { _behavior->move(x, y); } -inline void Dialog::set_position(Gtk::WindowPosition position) { _behavior->set_position(position); } -inline void Dialog::set_title(Glib::ustring title) { _behavior->set_title(title); } -inline void Dialog::set_sensitive(bool sensitive) { _behavior->set_sensitive(sensitive); } - -inline void Dialog::set_response_sensitive(int response_id, bool setting) -{ _behavior->set_response_sensitive(response_id, setting); } - -void Dialog::set_resizable(bool) { } -void Dialog::set_default(Gtk::Widget&) { } - -inline void Dialog::set_default_response(int response_id) { _behavior->set_default_response(response_id); } - -Glib::SignalProxy0 Dialog::signal_show () { return _behavior->signal_show(); } -Glib::SignalProxy0 Dialog::signal_hide () { return _behavior->signal_hide(); } -Glib::SignalProxy1 Dialog::signal_response () { return _behavior->signal_response(); } - -Gtk::Button* Dialog::add_button (const Glib::ustring& button_text, int response_id) -{ return _behavior->add_button(button_text, response_id); } - -Gtk::Button* Dialog::add_button (const Gtk::StockID& stock_id, int response_id) -{ return _behavior->add_button(stock_id, response_id); } - -Dialog::Dialog(const char *prefs_path, int verb_num, const char *apply_label) -{ - -} - //===================================================================== /** @@ -174,6 +93,7 @@ Dialog::Dialog(const char *prefs_path, int verb_num, const char *apply_label) * It also provides some general purpose signal handlers for things like * showing and hiding all dialogs. */ + Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_path, int verb_num, const char *apply_label) : _hiddenF12 (false), @@ -189,25 +109,21 @@ Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_pat _title = title; _behavior = behavior_factory(*this); - - gtk_signal_connect( GTK_OBJECT (gobj()), "event", GTK_SIGNAL_FUNC(sp_dialog_event_handler), gobj() ); - - if (Inkscape::NSApplication::Application::getNewGui()) - { + + 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)); _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::mem_fun (*this, &Dialog::onShowF12)); _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (sigc::mem_fun (*this, &Dialog::onShutdown)); - } - else - { - g_signal_connect (G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_retransientize), (void *)this); - g_signal_connect ( G_OBJECT(INKSCAPE), "dialogs_hide", G_CALLBACK(hideCallback), (void *)this ); - g_signal_connect ( G_OBJECT(INKSCAPE), "dialogs_unhide", G_CALLBACK(unhideCallback), (void *)this ); - g_signal_connect (G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (sp_dialog_shutdown), (void *)this); + } else { + g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(sp_retransientize), (void *)this); + g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_hide", G_CALLBACK(hideCallback), (void *)this); + g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_unhide", G_CALLBACK(unhideCallback), (void *)this); + 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 @@ -219,7 +135,6 @@ Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_pat } read_geometry(); - present(); } Dialog::~Dialog() @@ -237,44 +152,21 @@ 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::on_response(int response_id) +Dialog::onDesktopActivated(SPDesktop *desktop) { - switch (response_id) { - case Gtk::RESPONSE_APPLY: { - _apply(); - break; - } - case Gtk::RESPONSE_CLOSE: { - _close(); - break; - } - } + _behavior->onDesktopActivated(desktop); } -bool -Dialog::on_delete_event (GdkEventAny *event) +void +Dialog::onShutdown() { save_geometry(); _user_hidden = true; - - return false; + _behavior->onShutdown(); } void @@ -297,24 +189,164 @@ Dialog::onShowF12() _hiddenF12 = false; } -void -Dialog::onShutdown() + +inline Dialog::operator Gtk::Widget&() { return *_behavior; } +inline GtkWidget *Dialog::gobj() { return _behavior->gobj(); } +inline void Dialog::present() { _behavior->present(); } +inline Gtk::VBox *Dialog::get_vbox() { return _behavior->get_vbox(); } +inline void Dialog::hide() { _behavior->hide(); } +inline void Dialog::show() { _behavior->show(); } +inline void Dialog::show_all_children() { _behavior->show_all_children(); } +inline void Dialog::set_size_request(int width, int height) { _behavior->set_size_request(width, height); } +inline void Dialog::size_request(Gtk::Requisition& requisition) { _behavior->size_request(requisition); } +inline void Dialog::get_position(int& x, int& y) { _behavior->get_position(x, y); } +inline void Dialog::get_size(int& width, int& height) { _behavior->get_size(width, height); } +inline void Dialog::resize(int width, int height) { _behavior->resize(width, height); } +inline void Dialog::move(int x, int y) { _behavior->move(x, y); } +inline void Dialog::set_position(Gtk::WindowPosition position) { _behavior->set_position(position); } +inline void Dialog::set_title(Glib::ustring title) { _behavior->set_title(title); } +inline void Dialog::set_sensitive(bool sensitive) { _behavior->set_sensitive(sensitive); } + +inline void Dialog::set_response_sensitive(int response_id, bool setting) +{ _behavior->set_response_sensitive(response_id, setting); } + +void Dialog::set_resizable(bool) { } +void Dialog::set_default(Gtk::Widget&) { } + +inline void Dialog::set_default_response(int response_id) { _behavior->set_default_response(response_id); } + +Glib::SignalProxy0 Dialog::signal_show () { return _behavior->signal_show(); } +Glib::SignalProxy0 Dialog::signal_hide () { return _behavior->signal_hide(); } +Glib::SignalProxy1 Dialog::signal_response () { return _behavior->signal_response(); } + +Gtk::Button* Dialog::add_button (const Glib::ustring& button_text, int response_id) +{ return _behavior->add_button(button_text, response_id); } + +Gtk::Button* Dialog::add_button (const Gtk::StockID& stock_id, int response_id) +{ return _behavior->add_button(stock_id, response_id); } + + +void +Dialog::read_geometry() +{ + _user_hidden = false; + + int x = prefs_get_int_attribute (_prefs_path, "x", -1000); + int y = prefs_get_int_attribute (_prefs_path, "y", -1000); + int w = prefs_get_int_attribute (_prefs_path, "w", 0); + int h = prefs_get_int_attribute (_prefs_path, "h", 0); + + // g_print ("read %d %d %d %d\n", x, y, w, h); + + // If there are stored height and width values for the dialog, + // resize the window to match; otherwise we leave it at its default + if (w != 0 && h != 0) { + resize(w, h); + } + + // If there are stored values for where the dialog should be + // located, then restore the dialog to that position. + // also check if (x,y) is actually onscreen with the current screen dimensions + if ( (x >= 0) && (y >= 0) && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE)) ) { + move(x, y); + } else { + // ...otherwise just put it in the middle of the screen + set_position(Gtk::WIN_POS_CENTER); + } + +} + + +void +Dialog::save_geometry() +{ + int y, x, w, h; + + get_position(x, y); + get_size(w, h); + + // g_print ("write %d %d %d %d\n", x, y, w, h); + + if (x<0) x=0; + if (y<0) y=0; + + prefs_set_int_attribute (_prefs_path, "x", x); + prefs_set_int_attribute (_prefs_path, "y", y); + prefs_set_int_attribute (_prefs_path, "w", w); + prefs_set_int_attribute (_prefs_path, "h", h); + +} + +void +Dialog::_onResponse(int response_id) +{ + switch (response_id) { + case Gtk::RESPONSE_APPLY: { + _apply(); + break; + } + case Gtk::RESPONSE_CLOSE: { + _close(); + break; + } + } +} + +bool +Dialog::_onDeleteEvent(GdkEventAny *event) { save_geometry(); _user_hidden = true; - _behavior->onShutdown(); + + return false; } -void -Dialog::onDesktopActivated(SPDesktop *desktop) +bool +Dialog::_onEvent(GdkEvent *event) { - _behavior->onDesktopActivated(desktop); + bool ret = false; + + switch (event->type) { + case GDK_KEY_PRESS: { + switch (get_group0_keyval (&event->key)) { + case GDK_Escape: { + _defocus(); + ret = true; + break; + } + case GDK_F4: + case GDK_w: + case GDK_W: { + if (mod_ctrl_only(event->key.state)) { + _close(); + ret = true; + } + break; + } + default: { // pass keypress to the canvas + break; + } + } + } + default: + ; + } + + return ret; } -Inkscape::Selection* -Dialog::_getSelection() +bool +Dialog::_onKeyPress(GdkEventKey *event) { - return sp_desktop_selection(SP_ACTIVE_DESKTOP); + 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 ); + return sp_shortcut_invoke(shortcut, SP_ACTIVE_DESKTOP); } void @@ -340,12 +372,35 @@ Dialog::_close() event.send_event = TRUE; if (event.window) - g_object_ref (G_OBJECT (event.window)); + g_object_ref(G_OBJECT(event.window)); gtk_main_do_event ((GdkEvent*)&event); if (event.window) - g_object_unref (G_OBJECT (event.window)); + 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(canvas->get_toplevel()); + if (toplevel_window) + toplevel_window->present(); + + canvas->grab_focus(); + } +} + +Inkscape::Selection* +Dialog::_getSelection() +{ + return sp_desktop_selection(SP_ACTIVE_DESKTOP); } } // namespace Dialog