Code

dc9f4ac2a2ae6db58e933a0ead32028d6f926dec
[inkscape.git] / src / dialogs / dialog-events.cpp
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"
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));
102 void
103 sp_dialog_defocus_on_enter (GtkWidget *w)
105     g_signal_connect ( G_OBJECT (w), "activate",
106                        G_CALLBACK (sp_dialog_defocus_callback), w );
111 gboolean
112 sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data)
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;
168 /**
169  * \brief  Make the argument dialog transient to the currently active document
170            window.
171  */
172 void
173 sp_transientize (GtkWidget *dialog)
175 #ifndef WIN32  // FIXME: Temporary Win32 special code to enable transient dialogs
176     // _set_skip_taskbar_hint makes transient dialogs NON-transient! When dialogs
177     // are made transient (_set_transient_for), they are already removed from
178     // the taskbar in Win32.
179     if (prefs_get_int_attribute ( "options.dialogsskiptaskbar", "value", 0)) {
180         gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
181     }
182 #endif
184     gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2 );
186 #ifdef WIN32 // Win32 special code to enable transient dialogs
187     transient_policy = 2;
188 #endif
190     if (transient_policy) {
192     // if there's an active document window, attach dialog to it as a transient:
194         if ( SP_ACTIVE_DESKTOP )
195         {
196             SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
197         }
198     }
199 } // end of sp_transientize()
201 void on_transientize (SPDesktop *desktop, win_data *wd )
203     sp_transientize_callback (0, desktop, wd);
206 void
207 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
208                            SPDesktop *desktop, win_data *wd )
210     gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
212 #ifdef WIN32 // Win32 special code to enable transient dialogs
213     transient_policy = 2;
214 #endif
216     if (!transient_policy)
217         return;
219     if (wd->stop) {
220         /*
221          * if retransientizing of this dialog is still forbidden after
222          * previous call warning turned off because it was confusingly fired
223          * when loading many files from command line
224          */
225          // g_warning("Retranzientize aborted! You're switching windows too fast!");
226         return;
227     }
229     if (wd->win)
230     {
231         wd->stop = 1; // disallow other attempts to retranzientize this dialog
232         desktop->setWindowTransient (wd->win, transient_policy);
233     }
235     // we're done, allow next retransientizing not sooner than after 6 msec
236     gtk_timeout_add (6, (GtkFunction) sp_allow_again, (gpointer) wd);
239 void on_dialog_hide (GtkWidget *w)
241     if (w)
242         gtk_widget_hide (w);
245 void on_dialog_unhide (GtkWidget *w)
247     if (w)
248         gtk_widget_show (w);
251 gboolean
252 sp_dialog_hide (GtkObject */*object*/, gpointer data)
254     GtkWidget *dlg = (GtkWidget *) data;
256     if (dlg)
257         gtk_widget_hide (dlg);
259     return TRUE;
264 gboolean
265 sp_dialog_unhide (GtkObject */*object*/, gpointer data)
267     GtkWidget *dlg = (GtkWidget *) data;
269     if (dlg)
270         gtk_widget_show (dlg);
272     return TRUE;
276 /*
277   Local Variables:
278   mode:c++
279   c-file-style:"stroustrup"
280   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
281   indent-tabs-mode:nil
282   fill-column:99
283   End:
284 */
285 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :