b306e42d6245ff2e4f1a05affdd1d1caa68644f0
1 #define __DIALOG_EVENTS_C__
3 /**
4 * \brief Event handler for dialog windows
5 *
6 * Authors:
7 * bulia byak <bulia@dr.com>
8 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
9 *
10 * Copyright (C) 2003-2007 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #include <gdk/gdkkeysyms.h>
20 #include "macros.h"
21 #include <gtk/gtk.h>
22 #include "desktop.h"
23 #include "inkscape-private.h"
24 #include "preferences.h"
25 #include "event-context.h"
27 #include "dialog-events.h"
30 #include <gtkmm/entry.h>
33 /**
34 * \brief This function is called to zero the transientize semaphore by a
35 * timeout.
36 */
37 gboolean
38 sp_allow_again (gpointer *wd)
39 {
40 ((win_data *) wd)->stop = 0;
41 return FALSE; // so that it is only called once
42 }
46 /**
47 * \brief Remove focus from window to whoever it is transient for...
48 *
49 */
50 void
51 sp_dialog_defocus_cpp (Gtk::Window *win)
52 {
53 Gtk::Window *w;
54 //find out the document window we're transient for
55 w = win->get_transient_for();
57 //switch to it
58 if (w) {
59 w->present();
60 }
61 }
63 void
64 sp_dialog_defocus (GtkWindow *win)
65 {
66 GtkWindow *w;
67 //find out the document window we're transient for
68 w = gtk_window_get_transient_for ((GtkWindow *) win);
69 //switch to it
71 if (w) {
72 gtk_window_present (w);
73 }
74 }
77 /**
78 * \brief Callback to defocus a widget's parent dialog.
79 *
80 */
81 void
82 sp_dialog_defocus_callback_cpp (Gtk::Entry *e)
83 {
84 sp_dialog_defocus_cpp(dynamic_cast<Gtk::Window *>(e->get_toplevel()));
85 }
87 void
88 sp_dialog_defocus_callback (GtkWindow */*win*/, gpointer data)
89 {
90 sp_dialog_defocus ((GtkWindow *)
91 gtk_widget_get_toplevel ((GtkWidget *) data));
92 }
96 void
97 sp_dialog_defocus_on_enter_cpp (Gtk::Entry *e)
98 {
99 e->signal_activate().connect(sigc::bind(sigc::ptr_fun(&sp_dialog_defocus_callback_cpp), e));
100 }
102 void
103 sp_dialog_defocus_on_enter (GtkWidget *w)
104 {
105 g_signal_connect ( G_OBJECT (w), "activate",
106 G_CALLBACK (sp_dialog_defocus_callback), w );
107 }
111 gboolean
112 sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data)
113 {
115 // if the focus is inside the Text and Font textview, do nothing
116 GObject *dlg = (GObject *) data;
117 if (g_object_get_data (dlg, "eatkeys")) {
118 return FALSE;
119 }
121 gboolean ret = FALSE;
123 switch (event->type) {
125 case GDK_KEY_PRESS:
127 switch (get_group0_keyval (&event->key)) {
128 case GDK_Escape:
129 sp_dialog_defocus (win);
130 ret = TRUE;
131 break;
132 case GDK_F4:
133 case GDK_w:
134 case GDK_W:
135 // close dialog
136 if (MOD__CTRL_ONLY) {
138 /* this code sends a delete_event to the dialog,
139 * instead of just destroying it, so that the
140 * dialog can do some housekeeping, such as remember
141 * its position.
142 */
143 GdkEventAny event;
144 GtkWidget *widget = (GtkWidget *) win;
145 event.type = GDK_DELETE;
146 event.window = widget->window;
147 event.send_event = TRUE;
148 g_object_ref (G_OBJECT (event.window));
149 gtk_main_do_event ((GdkEvent*)&event);
150 g_object_unref (G_OBJECT (event.window));
152 ret = TRUE;
153 }
154 break;
155 default: // pass keypress to the canvas
156 break;
157 }
158 default:
159 ;
160 }
162 return ret;
164 }
168 /**
169 * \brief Make the argument dialog transient to the currently active document
170 window.
171 */
172 void
173 sp_transientize (GtkWidget *dialog)
174 {
175 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
176 #ifndef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
177 // _set_skip_taskbar_hint makes transient dialogs NON-transient! When dialogs
178 // are made transient (_set_transient_for), they are already removed from
179 // the taskbar in Win32.
180 if (prefs->getBool( "/options/dialogsskiptaskbar/value")) {
181 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
182 }
183 #endif
185 gint transient_policy = prefs->getIntLimited("/options/transientpolicy/value", 1, 0, 2);
187 #ifdef WIN32 // Win32 special code to enable transient dialogs
188 transient_policy = 2;
189 #endif
191 if (transient_policy) {
193 // if there's an active document window, attach dialog to it as a transient:
195 if ( SP_ACTIVE_DESKTOP )
196 {
197 SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
198 }
199 }
200 } // end of sp_transientize()
202 void on_transientize (SPDesktop *desktop, win_data *wd )
203 {
204 sp_transientize_callback (0, desktop, wd);
205 }
207 void
208 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
209 SPDesktop *desktop, win_data *wd )
210 {
211 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
212 gint transient_policy = prefs->getIntLimited( "/options/transientpolicy/value", 1, 0, 2);
214 #ifdef WIN32 // Win32 special code to enable transient dialogs
215 transient_policy = 2;
216 #endif
218 if (!transient_policy)
219 return;
221 if (wd->stop) {
222 /*
223 * if retransientizing of this dialog is still forbidden after
224 * previous call warning turned off because it was confusingly fired
225 * when loading many files from command line
226 */
227 // g_warning("Retranzientize aborted! You're switching windows too fast!");
228 return;
229 }
231 if (wd->win)
232 {
233 wd->stop = 1; // disallow other attempts to retranzientize this dialog
234 desktop->setWindowTransient (wd->win, transient_policy);
235 }
237 // we're done, allow next retransientizing not sooner than after 6 msec
238 gtk_timeout_add (6, (GtkFunction) sp_allow_again, (gpointer) wd);
239 }
241 void on_dialog_hide (GtkWidget *w)
242 {
243 if (w)
244 gtk_widget_hide (w);
245 }
247 void on_dialog_unhide (GtkWidget *w)
248 {
249 if (w)
250 gtk_widget_show (w);
251 }
253 gboolean
254 sp_dialog_hide (GtkObject */*object*/, gpointer data)
255 {
256 GtkWidget *dlg = (GtkWidget *) data;
258 if (dlg)
259 gtk_widget_hide (dlg);
261 return TRUE;
262 }
266 gboolean
267 sp_dialog_unhide (GtkObject */*object*/, gpointer data)
268 {
269 GtkWidget *dlg = (GtkWidget *) data;
271 if (dlg)
272 gtk_widget_show (dlg);
274 return TRUE;
275 }
278 /*
279 Local Variables:
280 mode:c++
281 c-file-style:"stroustrup"
282 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
283 indent-tabs-mode:nil
284 fill-column:99
285 End:
286 */
287 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :