Code

NR:: => Geom:: for much of src/ui and src/widgets
[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"
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;
142 /**
143  * \brief  Make the argument dialog transient to the currently active document
144            window.
145  */
146 void
147 sp_transientize (GtkWidget *dialog)
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 // Win32 special code to enable transient dialogs
161     transient_policy = 2;
162 #endif
164     if (transient_policy) {
166     // if there's an active document window, attach dialog to it as a transient:
168         if ( SP_ACTIVE_DESKTOP )
169         {
170             SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
171         }
172     }
173 } // end of sp_transientize()
175 void on_transientize (SPDesktop *desktop, win_data *wd )
177     sp_transientize_callback (0, desktop, wd);
180 void
181 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
182                            SPDesktop *desktop, win_data *wd )
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)
191         return;
193     if (wd->stop) {
194         /*
195          * if retransientizing of this dialog is still forbidden after
196          * previous call warning turned off because it was confusingly fired
197          * when loading many files from command line
198          */
199          // g_warning("Retranzientize aborted! You're switching windows too fast!");
200         return;
201     }
203     if (wd->win)
204     {
205         wd->stop = 1; // disallow other attempts to retranzientize this dialog
206         desktop->setWindowTransient (wd->win, transient_policy);
207     }
209     // we're done, allow next retransientizing not sooner than after 6 msec
210     gtk_timeout_add (6, (GtkFunction) sp_allow_again, (gpointer) wd);
213 void on_dialog_hide (GtkWidget *w)
215     if (w)
216         gtk_widget_hide (w);
219 void on_dialog_unhide (GtkWidget *w)
221     if (w)
222         gtk_widget_show (w);
225 gboolean
226 sp_dialog_hide (GtkObject */*object*/, gpointer data)
228     GtkWidget *dlg = (GtkWidget *) data;
230     if (dlg)
231         gtk_widget_hide (dlg);
233     return TRUE;
238 gboolean
239 sp_dialog_unhide (GtkObject */*object*/, gpointer data)
241     GtkWidget *dlg = (GtkWidget *) data;
243     if (dlg)
244         gtk_widget_show (dlg);
246     return TRUE;
250 /*
251   Local Variables:
252   mode:c++
253   c-file-style:"stroustrup"
254   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
255   indent-tabs-mode:nil
256   fill-column:99
257   End:
258 */
259 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :