Code

get rid of a lot of no longer needed "libnr/nr-..." includes.
[inkscape.git] / src / dialogs / dialog-events.cpp
1 /** @file
2  * @brief  Event handler for dialog windows
3  */
4 /* Authors:
5  *   bulia byak <bulia@dr.com>
6  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
7  *
8  * Copyright (C) 2003-2007 Authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
17 #include <gdk/gdkkeysyms.h>
18 #include "macros.h"
19 #include <gtk/gtk.h>
20 #include "desktop.h"
21 #include "inkscape-private.h"
22 #include "preferences.h"
23 #include "event-context.h"
25 #include "dialog-events.h"
28 #include <gtkmm/entry.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_cpp (Gtk::Window *win)
50 {
51     Gtk::Window *w;
52     //find out the document window we're transient for
53     w = win->get_transient_for();
55     //switch to it
56     if (w) {
57         w->present();
58     }
59 }
61 void
62 sp_dialog_defocus (GtkWindow *win)
63 {
64     GtkWindow *w;
65     //find out the document window we're transient for
66     w = gtk_window_get_transient_for ((GtkWindow *) win);
67     //switch to it
69     if (w) {
70         gtk_window_present (w);
71     }
72 }
75 /**
76  * \brief Callback to defocus a widget's parent dialog.
77  *
78  */
79 void
80 sp_dialog_defocus_callback_cpp (Gtk::Entry *e)
81 {
82     sp_dialog_defocus_cpp(dynamic_cast<Gtk::Window *>(e->get_toplevel()));
83 }
85 void
86 sp_dialog_defocus_callback (GtkWindow */*win*/, gpointer data)
87 {
88     sp_dialog_defocus ((GtkWindow *)
89         gtk_widget_get_toplevel ((GtkWidget *) data));
90 }
94 void
95 sp_dialog_defocus_on_enter_cpp (Gtk::Entry *e)
96 {
97     e->signal_activate().connect(sigc::bind(sigc::ptr_fun(&sp_dialog_defocus_callback_cpp), e));
98 }
100 void
101 sp_dialog_defocus_on_enter (GtkWidget *w)
103     g_signal_connect ( G_OBJECT (w), "activate",
104                        G_CALLBACK (sp_dialog_defocus_callback), w );
109 gboolean
110 sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data)
113 // if the focus is inside the Text and Font textview, do nothing
114     GObject *dlg = (GObject *) data;
115     if (g_object_get_data (dlg, "eatkeys")) {
116         return FALSE;
117     }
119     gboolean ret = FALSE;
121     switch (event->type) {
123         case GDK_KEY_PRESS:
125             switch (get_group0_keyval (&event->key)) {
126                 case GDK_Escape:
127                     sp_dialog_defocus (win);
128                     ret = TRUE;
129                     break;
130                 case GDK_F4:
131                 case GDK_w:
132                 case GDK_W:
133                     // close dialog
134                     if (MOD__CTRL_ONLY) {
136                         /* this code sends a delete_event to the dialog,
137                          * instead of just destroying it, so that the
138                          * dialog can do some housekeeping, such as remember
139                          * its position.
140                          */
141                         GdkEventAny event;
142                         GtkWidget *widget = (GtkWidget *) win;
143                         event.type = GDK_DELETE;
144                         event.window = widget->window;
145                         event.send_event = TRUE;
146                         g_object_ref (G_OBJECT (event.window));
147                         gtk_main_do_event ((GdkEvent*)&event);
148                         g_object_unref (G_OBJECT (event.window));
150                         ret = TRUE;
151                     }
152                     break;
153                 default: // pass keypress to the canvas
154                     break;
155             }
156     default:
157         ;
158     }
160     return ret;
166 /**
167  * \brief  Make the argument dialog transient to the currently active document
168            window.
169  */
170 void
171 sp_transientize (GtkWidget *dialog)
173     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
174 #ifndef WIN32  // FIXME: Temporary Win32 special code to enable transient dialogs
175     // _set_skip_taskbar_hint makes transient dialogs NON-transient! When dialogs
176     // are made transient (_set_transient_for), they are already removed from
177     // the taskbar in Win32.
178     if (prefs->getBool( "/options/dialogsskiptaskbar/value")) {
179         gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
180     }
181 #endif
183     gint transient_policy = prefs->getIntLimited("/options/transientpolicy/value", 1, 0, 2);
185 #ifdef WIN32 // Win32 special code to enable transient dialogs
186     transient_policy = 2;
187 #endif
189     if (transient_policy) {
191     // if there's an active document window, attach dialog to it as a transient:
193         if ( SP_ACTIVE_DESKTOP )
194         {
195             SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
196         }
197     }
198 } // end of sp_transientize()
200 void on_transientize (SPDesktop *desktop, win_data *wd )
202     sp_transientize_callback (0, desktop, wd);
205 void
206 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
207                            SPDesktop *desktop, win_data *wd )
209     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
210     gint transient_policy = prefs->getIntLimited( "/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 :