1 #define __DIALOG_EVENTS_C__
3 /**
4 * \brief Event handler for dialog windows
5 *
6 * Authors:
7 * bulia byak <bulia@dr.com>
8 *
9 * Copyright (C) 2003 authors
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
12 */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
18 #include <gdk/gdkkeysyms.h>
19 #include "macros.h"
20 #include <gtk/gtk.h>
21 #include "desktop.h"
22 #include "inkscape-private.h"
23 #include "prefs-utils.h"
24 #include "event-context.h"
26 #include "dialog-events.h"
30 /**
31 * \brief This function is called to zero the transientize semaphore by a
32 * timeout.
33 */
34 gboolean
35 sp_allow_again (gpointer *wd)
36 {
37 ((win_data *) wd)->stop = 0;
38 return FALSE; // so that it is only called once
39 }
43 /**
44 * \brief Remove focus from window to whoever it is transient for...
45 *
46 */
47 void
48 sp_dialog_defocus (GtkWindow *win)
49 {
50 GtkWindow *w;
51 //find out the document window we're transient for
52 w = gtk_window_get_transient_for ((GtkWindow *) win);
53 //switch to it
55 if (w) {
56 gtk_window_present (w);
57 }
58 }
62 /**
63 * \brief Callback to defocus a widget's parent dialog.
64 *
65 */
66 void
67 sp_dialog_defocus_callback (GtkWindow *win, gpointer data)
68 {
69 sp_dialog_defocus ((GtkWindow *)
70 gtk_widget_get_toplevel ((GtkWidget *) data));
71 }
75 void
76 sp_dialog_defocus_on_enter (GtkWidget *w)
77 {
78 g_signal_connect ( G_OBJECT (w), "activate",
79 G_CALLBACK (sp_dialog_defocus_callback), w );
80 }
84 gboolean
85 sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data)
86 {
88 // if the focus is inside the Text and Font textview, do nothing
89 GObject *dlg = (GObject *) data;
90 if (g_object_get_data (dlg, "eatkeys")) {
91 return FALSE;
92 }
94 gboolean ret = FALSE;
96 switch (event->type) {
98 case GDK_KEY_PRESS:
100 switch (get_group0_keyval (&event->key)) {
101 case GDK_Escape:
102 sp_dialog_defocus (win);
103 ret = TRUE;
104 break;
105 case GDK_F4:
106 case GDK_w:
107 case GDK_W:
108 // close dialog
109 if (MOD__CTRL_ONLY) {
111 /* this code sends a delete_event to the dialog,
112 * instead of just destroying it, so that the
113 * dialog can do some housekeeping, such as remember
114 * its position.
115 */
116 GdkEventAny event;
117 GtkWidget *widget = (GtkWidget *) win;
118 event.type = GDK_DELETE;
119 event.window = widget->window;
120 event.send_event = TRUE;
121 g_object_ref (G_OBJECT (event.window));
122 gtk_main_do_event ((GdkEvent*)&event);
123 g_object_unref (G_OBJECT (event.window));
125 ret = TRUE;
126 }
127 break;
128 default: // pass keypress to the canvas
129 break;
130 }
131 default:
132 ;
133 }
135 return ret;
137 }
141 /**
142 * \brief Make the argument dialog transient to the currently active document
143 window.
144 */
145 void
146 sp_transientize (GtkWidget *dialog)
147 {
148 if (prefs_get_int_attribute ( "options.dialogsskiptaskbar", "value", 0)) {
149 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
150 }
152 gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2 );
154 if (transient_policy) {
156 // if there's an active document window, attach dialog to it as a transient:
158 if ( SP_ACTIVE_DESKTOP )
159 {
160 SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
161 }
162 }
163 } // end of sp_transientize()
165 void on_transientize (SPDesktop *desktop, win_data *wd )
166 {
167 sp_transientize_callback (0, desktop, wd);
168 }
170 void
171 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
172 SPDesktop *desktop, win_data *wd )
173 {
174 gint transient_policy =
175 prefs_get_int_attribute_limited ( "options.transientpolicy", "value",
176 1, 0, 2);
178 if (!transient_policy)
179 return;
181 if (wd->stop) {
182 /*
183 * if retransientizing of this dialog is still forbidden after
184 * previous call warning turned off because it was confusingly fired
185 * when loading many files from command line
186 */
187 // g_warning("Retranzientize aborted! You're switching windows too fast!");
188 return;
189 }
191 if (wd->win)
192 {
193 wd->stop = 1; // disallow other attempts to retranzientize this dialog
194 desktop->setWindowTransient (wd->win, transient_policy);
195 }
197 // we're done, allow next retransientizing not sooner than after 6 msec
198 gtk_timeout_add (6, (GtkFunction) sp_allow_again, (gpointer) wd);
199 }
201 void on_dialog_hide (GtkWidget *w)
202 {
203 if (w)
204 gtk_widget_hide (w);
205 }
207 void on_dialog_unhide (GtkWidget *w)
208 {
209 if (w)
210 gtk_widget_show (w);
211 }
213 gboolean
214 sp_dialog_hide (GtkObject *object, gpointer data)
215 {
216 GtkWidget *dlg = (GtkWidget *) data;
218 if (dlg)
219 gtk_widget_hide (dlg);
221 return TRUE;
222 }
226 gboolean
227 sp_dialog_unhide (GtkObject *object, gpointer data)
228 {
229 GtkWidget *dlg = (GtkWidget *) data;
231 if (dlg)
232 gtk_widget_show (dlg);
234 return TRUE;
235 }
238 /*
239 Local Variables:
240 mode:c++
241 c-file-style:"stroustrup"
242 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
243 indent-tabs-mode:nil
244 fill-column:99
245 End:
246 */
247 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :