5f4c429fa694c398a4f960888804914eaadfe7a3
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 "prefs-utils.h"
25 #include "event-context.h"
27 #include "dialog-events.h"
31 /**
32 * \brief This function is called to zero the transientize semaphore by a
33 * timeout.
34 */
35 gboolean
36 sp_allow_again (gpointer *wd)
37 {
38 ((win_data *) wd)->stop = 0;
39 return FALSE; // so that it is only called once
40 }
44 /**
45 * \brief Remove focus from window to whoever it is transient for...
46 *
47 */
48 void
49 sp_dialog_defocus (GtkWindow *win)
50 {
51 GtkWindow *w;
52 //find out the document window we're transient for
53 w = gtk_window_get_transient_for ((GtkWindow *) win);
54 //switch to it
56 if (w) {
57 gtk_window_present (w);
58 }
59 }
63 /**
64 * \brief Callback to defocus a widget's parent dialog.
65 *
66 */
67 void
68 sp_dialog_defocus_callback (GtkWindow *win, gpointer data)
69 {
70 sp_dialog_defocus ((GtkWindow *)
71 gtk_widget_get_toplevel ((GtkWidget *) data));
72 }
76 void
77 sp_dialog_defocus_on_enter (GtkWidget *w)
78 {
79 g_signal_connect ( G_OBJECT (w), "activate",
80 G_CALLBACK (sp_dialog_defocus_callback), w );
81 }
85 gboolean
86 sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data)
87 {
89 // if the focus is inside the Text and Font textview, do nothing
90 GObject *dlg = (GObject *) data;
91 if (g_object_get_data (dlg, "eatkeys")) {
92 return FALSE;
93 }
95 gboolean ret = FALSE;
97 switch (event->type) {
99 case GDK_KEY_PRESS:
101 switch (get_group0_keyval (&event->key)) {
102 case GDK_Escape:
103 sp_dialog_defocus (win);
104 ret = TRUE;
105 break;
106 case GDK_F4:
107 case GDK_w:
108 case GDK_W:
109 // close dialog
110 if (MOD__CTRL_ONLY) {
112 /* this code sends a delete_event to the dialog,
113 * instead of just destroying it, so that the
114 * dialog can do some housekeeping, such as remember
115 * its position.
116 */
117 GdkEventAny event;
118 GtkWidget *widget = (GtkWidget *) win;
119 event.type = GDK_DELETE;
120 event.window = widget->window;
121 event.send_event = TRUE;
122 g_object_ref (G_OBJECT (event.window));
123 gtk_main_do_event ((GdkEvent*)&event);
124 g_object_unref (G_OBJECT (event.window));
126 ret = TRUE;
127 }
128 break;
129 default: // pass keypress to the canvas
130 break;
131 }
132 default:
133 ;
134 }
136 return ret;
138 }
142 /**
143 * \brief Make the argument dialog transient to the currently active document
144 window.
145 */
146 void
147 sp_transientize (GtkWidget *dialog)
148 {
149 #ifndef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
150 // _set_skip_taskbar_hint makes transient dialogs NON-transient! When dialogs
151 // are made transient (_set_transient_for), they are already removed from
152 // the taskbar in Win32.
153 if (prefs_get_int_attribute ( "options.dialogsskiptaskbar", "value", 0)) {
154 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
155 }
156 #endif
158 gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2 );
160 #ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
161 if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
162 transient_policy = 2;
163 else
164 transient_policy = 0;
165 #endif
167 if (transient_policy) {
169 // if there's an active document window, attach dialog to it as a transient:
171 if ( SP_ACTIVE_DESKTOP )
172 {
173 SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
174 }
175 }
176 } // end of sp_transientize()
178 void on_transientize (SPDesktop *desktop, win_data *wd )
179 {
180 sp_transientize_callback (0, desktop, wd);
181 }
183 void
184 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
185 SPDesktop *desktop, win_data *wd )
186 {
187 gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
189 #ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
190 if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
191 transient_policy = 2;
192 else
193 return;
194 #endif
196 if (!transient_policy)
197 return;
199 if (wd->stop) {
200 /*
201 * if retransientizing of this dialog is still forbidden after
202 * previous call warning turned off because it was confusingly fired
203 * when loading many files from command line
204 */
205 // g_warning("Retranzientize aborted! You're switching windows too fast!");
206 return;
207 }
209 if (wd->win)
210 {
211 wd->stop = 1; // disallow other attempts to retranzientize this dialog
212 desktop->setWindowTransient (wd->win, transient_policy);
213 }
215 // we're done, allow next retransientizing not sooner than after 6 msec
216 gtk_timeout_add (6, (GtkFunction) sp_allow_again, (gpointer) wd);
217 }
219 void on_dialog_hide (GtkWidget *w)
220 {
221 if (w)
222 gtk_widget_hide (w);
223 }
225 void on_dialog_unhide (GtkWidget *w)
226 {
227 if (w)
228 gtk_widget_show (w);
229 }
231 gboolean
232 sp_dialog_hide (GtkObject *object, gpointer data)
233 {
234 GtkWidget *dlg = (GtkWidget *) data;
236 if (dlg)
237 gtk_widget_hide (dlg);
239 return TRUE;
240 }
244 gboolean
245 sp_dialog_unhide (GtkObject *object, gpointer data)
246 {
247 GtkWidget *dlg = (GtkWidget *) data;
249 if (dlg)
250 gtk_widget_show (dlg);
252 return TRUE;
253 }
256 /*
257 Local Variables:
258 mode:c++
259 c-file-style:"stroustrup"
260 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
261 indent-tabs-mode:nil
262 fill-column:99
263 End:
264 */
265 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :