Code

c2ac1b12f4a1321d6367a8e3e9e13a3eaf32a32e
[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  *
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;
141 /**
142  * \brief  Make the argument dialog transient to the currently active document
143            window.
144  */
145 void
146 sp_transientize (GtkWidget *dialog)
148 #ifndef WIN32  // FIXME: Temporary Win32 special code to enable transient dialogs
149     // _set_skip_taskbar_hint makes transient dialogs NON-transient! When dialogs
150     // are made transient (_set_transient_for), they are already removed from
151     // the taskbar in Win32.
152     if (prefs_get_int_attribute ( "options.dialogsskiptaskbar", "value", 0)) {
153         gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
154     }           
155 #endif    
157     gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2 );
159 #ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
160     if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
161         transient_policy = 2;
162     else    
163         transient_policy = 0;
164 #endif        
166     if (transient_policy) {
167    
168     // if there's an active document window, attach dialog to it as a transient:
169     
170         if ( SP_ACTIVE_DESKTOP )
171         {
172             SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
173         }
174     }
175 } // end of sp_transientize()
177 void on_transientize (SPDesktop *desktop, win_data *wd )
179     sp_transientize_callback (0, desktop, wd);
182 void
183 sp_transientize_callback ( Inkscape::Application * /*inkscape*/, 
184                            SPDesktop *desktop, win_data *wd )
186     gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
188 #ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
189     if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
190         transient_policy = 2;
191     else    
192         return;
193 #endif        
195     if (!transient_policy) 
196         return;
198     if (wd->stop) { 
199         /* 
200          * if retransientizing of this dialog is still forbidden after 
201          * previous call warning turned off because it was confusingly fired 
202          * when loading many files from command line
203          */
204          // g_warning("Retranzientize aborted! You're switching windows too fast!"); 
205         return;
206     }
207     
208     if (wd->win)
209     {
210         wd->stop = 1; // disallow other attempts to retranzientize this dialog
211         desktop->setWindowTransient (wd->win, transient_policy);
212     }
213     
214     // we're done, allow next retransientizing not sooner than after 6 msec
215     gtk_timeout_add (6, (GtkFunction) sp_allow_again, (gpointer) wd);  
218 void on_dialog_hide (GtkWidget *w)
220     if (w)
221         gtk_widget_hide (w);
224 void on_dialog_unhide (GtkWidget *w)
226     if (w)
227         gtk_widget_show (w);
230 gboolean
231 sp_dialog_hide (GtkObject *object, gpointer data)
233     GtkWidget *dlg = (GtkWidget *) data;
235     if (dlg)
236         gtk_widget_hide (dlg);
238     return TRUE;
243 gboolean
244 sp_dialog_unhide (GtkObject *object, gpointer data)
246     GtkWidget *dlg = (GtkWidget *) data;
248     if (dlg)
249         gtk_widget_show (dlg);
251     return TRUE;
255 /*
256   Local Variables:
257   mode:c++
258   c-file-style:"stroustrup"
259   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
260   indent-tabs-mode:nil
261   fill-column:99
262   End:
263 */
264 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :