diff options
| author | gustav_b <gustav_b@users.sourceforge.net> | 2007-08-29 21:27:07 +0000 |
|---|---|---|
| committer | gustav_b <gustav_b@users.sourceforge.net> | 2007-08-29 21:27:07 +0000 |
| commit | 731f2b5adbb6f9e9fc853a6506c695fd2fcec320 (patch) | |
| tree | 6e7775c500ffc41d1376d7496c9334840b0f065f /src/ui/dialog/dialog.cpp | |
| parent | Don't snap node handles to the parent path, plus a small string change (diff) | |
| download | inkscape-731f2b5adbb6f9e9fc853a6506c695fd2fcec320.tar.gz inkscape-731f2b5adbb6f9e9fc853a6506c695fd2fcec320.zip | |
Dockable dialogs patch applied
(https://sourceforge.net/tracker/?func=detail&atid=604308&aid=1688508&group_id=93438)
(bzr r3613)
Diffstat (limited to 'src/ui/dialog/dialog.cpp')
| -rw-r--r-- | src/ui/dialog/dialog.cpp | 250 |
1 files changed, 115 insertions, 135 deletions
diff --git a/src/ui/dialog/dialog.cpp b/src/ui/dialog/dialog.cpp index ac147d656..16124d9f5 100644 --- a/src/ui/dialog/dialog.cpp +++ b/src/ui/dialog/dialog.cpp @@ -2,12 +2,13 @@ * \brief Base class for dialogs in Inkscape. This class provides certain * common behaviors and styles wanted of all dialogs in the application. * - * Author: + * Authors: * Bryce W. Harrington <bryce@bryceharrington.org> * buliabyak@gmail.com * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> + * Gustav Broberg <broberg@kth.se> * - * Copyright (C) 2004-2007 Authors + * Copyright (C) 2004--2007 Authors * * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -32,23 +33,13 @@ #include "interface.h" #include "verbs.h" - #define MIN_ONSCREEN_DISTANCE 50 - namespace Inkscape { namespace UI { namespace Dialog { -static gboolean -sp_retransientize_again (gpointer dlgPtr) -{ - Dialog *dlg = (Dialog *)dlgPtr; - dlg->retransientize_suppress = false; - return FALSE; // so that it is only called once -} - static void sp_retransientize (Inkscape::Application *inkscape, SPDesktop *desktop, gpointer dlgPtr) { @@ -63,13 +54,6 @@ sp_dialog_shutdown (GtkObject *object, gpointer dlgPtr) dlg->onShutdown(); } -void -Dialog::present() -{ - _user_hidden = false; - Gtk::Dialog::present(); -} - void Dialog::save_geometry() { @@ -78,7 +62,7 @@ Dialog::save_geometry() get_position(x, y); get_size(w, h); -// g_print ("write %d %d %d %d\n", x, y, w, h); + // g_print ("write %d %d %d %d\n", x, y, w, h); if (x<0) x=0; if (y<0) y=0; @@ -87,8 +71,27 @@ Dialog::save_geometry() 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 hideCallback(GtkObject *object, gpointer dlgPtr) +{ + g_return_if_fail( dlgPtr != NULL ); + + Dialog *dlg = (Dialog *)dlgPtr; + dlg->onHideF12(); +} + +void unhideCallback(GtkObject *object, gpointer dlgPtr) +{ + g_return_if_fail( dlgPtr != NULL ); + + Dialog *dlg = (Dialog *)dlgPtr; + dlg->onShowF12(); +} + + + void Dialog::read_geometry() { @@ -99,12 +102,12 @@ Dialog::read_geometry() 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); + // 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); + resize(w, h); } // If there are stored values for where the dialog should be @@ -116,22 +119,47 @@ Dialog::read_geometry() // ...otherwise just put it in the middle of the screen set_position(Gtk::WIN_POS_CENTER); } -} - -void hideCallback(GtkObject *object, gpointer dlgPtr) -{ - g_return_if_fail( dlgPtr != NULL ); - Dialog *dlg = (Dialog *)dlgPtr; - dlg->onHideF12(); } -void unhideCallback(GtkObject *object, gpointer dlgPtr) +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<void> Dialog::signal_show () { return _behavior->signal_show(); } +Glib::SignalProxy0<void> Dialog::signal_hide () { return _behavior->signal_hide(); } +Glib::SignalProxy1<void, int> 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) { - g_return_if_fail( dlgPtr != NULL ); - Dialog *dlg = (Dialog *)dlgPtr; - dlg->onShowF12(); } //===================================================================== @@ -146,34 +174,24 @@ void unhideCallback(GtkObject *object, gpointer dlgPtr) * It also provides some general purpose signal handlers for things like * showing and hiding all dialogs. */ -Dialog::Dialog(const char *prefs_path, int verb_num, const char *apply_label) +Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_path, int verb_num, + const char *apply_label) + : _hiddenF12 (false), + _prefs_path (prefs_path), + _verb_num(verb_num), + _apply_label (apply_label) { - hide(); - set_has_separator(false); - - _prefs_path = prefs_path; - - if (prefs_get_int_attribute ("dialogs", "showclose", 0) || apply_label) { - // TODO: make the order of buttons obey the global preference - if (apply_label) { - add_button(Glib::ustring(apply_label), Gtk::RESPONSE_APPLY); - set_default_response(Gtk::RESPONSE_APPLY); - } - add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); - } - - GtkWidget *dlg = GTK_WIDGET(gobj()); + gchar title[500]; if (verb_num) - { - gchar title[500]; sp_ui_dialog_title_string (Inkscape::Verb::get(verb_num), title); - set_title(title); - } - gtk_signal_connect( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC(sp_dialog_event_handler), dlg ); + _title = title; + + _behavior = behavior_factory(*this); + + gtk_signal_connect( GTK_OBJECT (gobj()), "event", GTK_SIGNAL_FUNC(sp_dialog_event_handler), gobj() ); - _hiddenF12 = false; if (Inkscape::NSApplication::Application::getNewGui()) { _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*this, &Dialog::onDesktopActivated)); @@ -183,23 +201,25 @@ Dialog::Dialog(const char *prefs_path, int verb_num, const char *apply_label) } 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); + 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); } - g_signal_connect_after( gobj(), "key_press_event", (GCallback)windowKeyPress, NULL ); + Glib::wrap(gobj())->signal_key_press_event().connect(sigc::ptr_fun(&windowKeyPress)); + + if (prefs_get_int_attribute ("dialogs", "showclose", 0) || apply_label) { + // TODO: make the order of buttons obey the global preference + if (apply_label) { + add_button(Glib::ustring(apply_label), Gtk::RESPONSE_APPLY); + set_default_response(Gtk::RESPONSE_APPLY); + } + add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); + } read_geometry(); present(); - sp_transientize(dlg); - retransientize_suppress = false; -} - -Dialog::Dialog(BaseObjectType *gobj) - : Gtk::Dialog(gobj) -{ } Dialog::~Dialog() @@ -213,10 +233,11 @@ Dialog::~Dialog() } save_geometry(); + delete _behavior; } -bool Dialog::windowKeyPress( GtkWidget *widget, GdkEventKey *event ) +bool Dialog::windowKeyPress(GdkEventKey *event) { unsigned int shortcut = 0; shortcut = get_group0_keyval (event) | @@ -226,6 +247,7 @@ bool Dialog::windowKeyPress( GtkWidget *widget, GdkEventKey *event ) SP_SHORTCUT_CONTROL_MASK : 0 ) | ( event->state & GDK_MOD1_MASK ? SP_SHORTCUT_ALT_MASK : 0 ); + return sp_shortcut_invoke( shortcut, SP_ACTIVE_DESKTOP ); } @@ -259,8 +281,7 @@ void Dialog::onHideF12() { _hiddenF12 = true; - save_geometry(); - hide(); + _behavior->onHideF12(); } void @@ -270,8 +291,7 @@ Dialog::onShowF12() return; if (_hiddenF12) { - show(); - read_geometry(); + _behavior->onShowF12(); } _hiddenF12 = false; @@ -282,61 +302,15 @@ Dialog::onShutdown() { save_geometry(); _user_hidden = true; + _behavior->onShutdown(); } void -Dialog::onDesktopActivated (SPDesktop *desktop) +Dialog::onDesktopActivated(SPDesktop *desktop) { - gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2); - -#ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs - if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0)) - transient_policy = 2; - else - return; -#endif - - if (!transient_policy) - return; - - - - GtkWindow *dialog_win = GTK_WINDOW(gobj()); - - if (retransientize_suppress) { - /* if retransientizing of this dialog is still forbidden after - * previous call warning turned off because it was confusingly fired - * when loading many files from command line - */ - - // g_warning("Retranzientize aborted! You're switching windows too fast!"); - return; - } - - if (dialog_win) - { - retransientize_suppress = true; // disallow other attempts to retranzientize this dialog - - desktop->setWindowTransient (dialog_win); - - /* - * This enables "aggressive" transientization, - * i.e. dialogs always emerging on top when you switch documents. Note - * however that this breaks "click to raise" policy of a window - * manager because the switched-to document will be raised at once - * (so that its transients also could raise) - */ - if (transient_policy == 2 && !_hiddenF12 && !_user_hidden) { - // without this, a transient window not always emerges on top - gtk_window_present (dialog_win); - } - } - - // we're done, allow next retransientizing not sooner than after 120 msec - gtk_timeout_add (120, (GtkFunction) sp_retransientize_again, (gpointer) this); + _behavior->onDesktopActivated(desktop); } - Inkscape::Selection* Dialog::_getSelection() { @@ -352,20 +326,26 @@ Dialog::_apply() void Dialog::_close() { - GtkWidget *dlg = GTK_WIDGET(gobj()); - - /* this code sends a delete_event to the dialog, - * instead of just destroying it, so that the - * dialog can do some housekeeping, such as remember - * its position. - */ - GdkEventAny event; - event.type = GDK_DELETE; - event.window = dlg->window; - event.send_event = TRUE; - g_object_ref (G_OBJECT (event.window)); - gtk_main_do_event ((GdkEvent*)&event); - g_object_unref (G_OBJECT (event.window)); + GtkWidget *dlg = GTK_WIDGET(_behavior->gobj()); + + /* this code sends a delete_event to the dialog, + * instead of just destroying it, so that the + * dialog can do some housekeeping, such as remember + * its position. + */ + + GdkEventAny event; + event.type = GDK_DELETE; + event.window = dlg->window; + event.send_event = TRUE; + + if (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)); } } // namespace Dialog |
