2
* @brief Base class for dialogs in Inkscape - implementation
5
* Bryce W. Harrington <bryce@bryceharrington.org>
7
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
8
* Gustav Broberg <broberg@kth.se>
10
* Copyright (C) 2004--2007 Authors
12
* Released under GNU GPL. Read the file 'COPYING' for more information.
19
#include <gtkmm/stock.h>
21
#include <gdk/gdkkeysyms.h>
23
#include "application/application.h"
24
#include "application/editor.h"
26
#include "event-context.h"
28
#include "desktop-handles.h"
29
#include "dialog-manager.h"
30
#include "modifier-fns.h"
31
#include "shortcuts.h"
32
#include "preferences.h"
33
#include "interface.h"
36
#define MIN_ONSCREEN_DISTANCE 50
44
sp_retransientize(Inkscape::Application */*inkscape*/, SPDesktop *desktop, gpointer dlgPtr)
46
Dialog *dlg = (Dialog *)dlgPtr;
47
dlg->onDesktopActivated (desktop);
51
sp_retransientize_again(gpointer dlgPtr)
53
Dialog *dlg = (Dialog *)dlgPtr;
54
dlg->retransientize_suppress = false;
55
return FALSE; // so that it is only called once
59
sp_dialog_shutdown(GtkObject */*object*/, gpointer dlgPtr)
61
Dialog *dlg = (Dialog *)dlgPtr;
66
void hideCallback(GtkObject */*object*/, gpointer dlgPtr)
68
g_return_if_fail( dlgPtr != NULL );
70
Dialog *dlg = (Dialog *)dlgPtr;
74
void unhideCallback(GtkObject */*object*/, gpointer dlgPtr)
76
g_return_if_fail( dlgPtr != NULL );
78
Dialog *dlg = (Dialog *)dlgPtr;
83
//=====================================================================
86
* UI::Dialog::Dialog is a base class for all dialogs in Inkscape. The
87
* purpose of this class is to provide a unified place for ensuring
88
* style and behavior. Specifically, this class provides functionality
89
* for saving and restoring the size and position of dialogs (through
90
* the user's preferences file).
92
* It also provides some general purpose signal handlers for things like
93
* showing and hiding all dialogs.
96
Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_path, int verb_num,
97
Glib::ustring const &apply_label)
99
_prefs_path (prefs_path),
101
_apply_label (apply_label)
106
sp_ui_dialog_title_string (Inkscape::Verb::get(verb_num), title);
110
_behavior = behavior_factory(*this);
112
if (Inkscape::NSApplication::Application::getNewGui()) {
113
_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*this, &Dialog::onDesktopActivated));
114
_dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::mem_fun (*this, &Dialog::onHideF12));
115
_dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::mem_fun (*this, &Dialog::onShowF12));
116
_shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (sigc::mem_fun (*this, &Dialog::onShutdown));
118
g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(sp_retransientize), (void *)this);
119
g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_hide", G_CALLBACK(hideCallback), (void *)this);
120
g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_unhide", G_CALLBACK(unhideCallback), (void *)this);
121
g_signal_connect(G_OBJECT(INKSCAPE), "shut_down", G_CALLBACK(sp_dialog_shutdown), (void *)this);
124
Glib::wrap(gobj())->signal_event().connect(sigc::mem_fun(*this, &Dialog::_onEvent));
125
Glib::wrap(gobj())->signal_key_press_event().connect(sigc::mem_fun(*this, &Dialog::_onKeyPress));
132
if (Inkscape::NSApplication::Application::getNewGui())
134
_desktop_activated_connection.disconnect();
135
_dialogs_hidden_connection.disconnect();
136
_dialogs_unhidden_connection.disconnect();
137
_shutdown_connection.disconnect();
145
//---------------------------------------------------------------------
149
Dialog::onDesktopActivated(SPDesktop *desktop)
151
_behavior->onDesktopActivated(desktop);
159
_behavior->onShutdown();
166
_behavior->onHideF12();
176
_behavior->onShowF12();
183
inline Dialog::operator Gtk::Widget &() { return *_behavior; }
184
inline GtkWidget *Dialog::gobj() { return _behavior->gobj(); }
185
inline void Dialog::present() { _behavior->present(); }
186
inline Gtk::VBox *Dialog::get_vbox() { return _behavior->get_vbox(); }
187
inline void Dialog::hide() { _behavior->hide(); }
188
inline void Dialog::show() { _behavior->show(); }
189
inline void Dialog::show_all_children() { _behavior->show_all_children(); }
190
inline void Dialog::set_size_request(int width, int height) { _behavior->set_size_request(width, height); }
191
inline void Dialog::size_request(Gtk::Requisition &requisition) { _behavior->size_request(requisition); }
192
inline void Dialog::get_position(int &x, int &y) { _behavior->get_position(x, y); }
193
inline void Dialog::get_size(int &width, int &height) { _behavior->get_size(width, height); }
194
inline void Dialog::resize(int width, int height) { _behavior->resize(width, height); }
195
inline void Dialog::move(int x, int y) { _behavior->move(x, y); }
196
inline void Dialog::set_position(Gtk::WindowPosition position) { _behavior->set_position(position); }
197
inline void Dialog::set_title(Glib::ustring title) { _behavior->set_title(title); }
198
inline void Dialog::set_sensitive(bool sensitive) { _behavior->set_sensitive(sensitive); }
200
Glib::SignalProxy0<void> Dialog::signal_show() { return _behavior->signal_show(); }
201
Glib::SignalProxy0<void> Dialog::signal_hide() { return _behavior->signal_hide(); }
204
Dialog::read_geometry()
206
_user_hidden = false;
208
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
209
int x = prefs->getInt(_prefs_path + "/x", -1000);
210
int y = prefs->getInt(_prefs_path + "/y", -1000);
211
int w = prefs->getInt(_prefs_path + "/w", 0);
212
int h = prefs->getInt(_prefs_path + "/h", 0);
214
// g_print ("read %d %d %d %d\n", x, y, w, h);
216
// If there are stored height and width values for the dialog,
217
// resize the window to match; otherwise we leave it at its default
218
if (w != 0 && h != 0) {
222
// If there are stored values for where the dialog should be
223
// located, then restore the dialog to that position.
224
// also check if (x,y) is actually onscreen with the current screen dimensions
225
if ( (x >= 0) && (y >= 0) && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE)) ) {
228
// ...otherwise just put it in the middle of the screen
229
set_position(Gtk::WIN_POS_CENTER);
236
Dialog::save_geometry()
243
// g_print ("write %d %d %d %d\n", x, y, w, h);
248
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
249
prefs->setInt(_prefs_path + "/x", x);
250
prefs->setInt(_prefs_path + "/y", y);
251
prefs->setInt(_prefs_path + "/w", w);
252
prefs->setInt(_prefs_path + "/h", h);
257
Dialog::_handleResponse(int response_id)
259
switch (response_id) {
260
case Gtk::RESPONSE_CLOSE: {
268
Dialog::_onDeleteEvent(GdkEventAny */*event*/)
277
Dialog::_onEvent(GdkEvent *event)
281
switch (event->type) {
282
case GDK_KEY_PRESS: {
283
switch (get_group0_keyval (&event->key)) {
292
if (mod_ctrl_only(event->key.state)) {
298
default: { // pass keypress to the canvas
311
Dialog::_onKeyPress(GdkEventKey *event)
313
unsigned int shortcut;
314
shortcut = get_group0_keyval(event) |
315
( event->state & GDK_SHIFT_MASK ?
316
SP_SHORTCUT_SHIFT_MASK : 0 ) |
317
( event->state & GDK_CONTROL_MASK ?
318
SP_SHORTCUT_CONTROL_MASK : 0 ) |
319
( event->state & GDK_MOD1_MASK ?
320
SP_SHORTCUT_ALT_MASK : 0 );
321
return sp_shortcut_invoke(shortcut, SP_ACTIVE_DESKTOP);
327
g_warning("Apply button clicked for dialog [Dialog::_apply()]");
333
GtkWidget *dlg = GTK_WIDGET(_behavior->gobj());
335
/* this code sends a delete_event to the dialog,
336
* instead of just destroying it, so that the
337
* dialog can do some housekeeping, such as remember
342
event.type = GDK_DELETE;
343
event.window = dlg->window;
344
event.send_event = TRUE;
347
g_object_ref(G_OBJECT(event.window));
349
gtk_main_do_event ((GdkEvent*)&event);
352
g_object_unref(G_OBJECT(event.window));
358
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
361
Gtk::Widget *canvas = Glib::wrap(GTK_WIDGET(desktop->canvas));
363
// make sure the canvas window is present before giving it focus
364
Gtk::Window *toplevel_window = dynamic_cast<Gtk::Window *>(canvas->get_toplevel());
366
toplevel_window->present();
368
canvas->grab_focus();
373
Dialog::_getSelection()
375
return sp_desktop_selection(SP_ACTIVE_DESKTOP);
378
} // namespace Dialog
380
} // namespace Inkscape
385
c-file-style:"stroustrup"
386
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
391
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :