Code

Add a warning to sp-object.h to not use some of the new methods
[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>
32 /**
33  * \brief  Remove focus from window to whoever it is transient for...
34  *
35  */
36 void
37 sp_dialog_defocus_cpp (Gtk::Window *win)
38 {
39     Gtk::Window *w;
40     //find out the document window we're transient for
41     w = win->get_transient_for();
43     //switch to it
44     if (w) {
45         w->present();
46     }
47 }
49 void
50 sp_dialog_defocus (GtkWindow *win)
51 {
52     GtkWindow *w;
53     //find out the document window we're transient for
54     w = gtk_window_get_transient_for ((GtkWindow *) win);
55     //switch to it
57     if (w) {
58         gtk_window_present (w);
59     }
60 }
63 /**
64  * \brief Callback to defocus a widget's parent dialog.
65  *
66  */
67 void
68 sp_dialog_defocus_callback_cpp (Gtk::Entry *e)
69 {
70     sp_dialog_defocus_cpp(dynamic_cast<Gtk::Window *>(e->get_toplevel()));
71 }
73 void
74 sp_dialog_defocus_callback (GtkWindow */*win*/, gpointer data)
75 {
76     sp_dialog_defocus ((GtkWindow *)
77         gtk_widget_get_toplevel ((GtkWidget *) data));
78 }
82 void
83 sp_dialog_defocus_on_enter_cpp (Gtk::Entry *e)
84 {
85     e->signal_activate().connect(sigc::bind(sigc::ptr_fun(&sp_dialog_defocus_callback_cpp), e));
86 }
88 void
89 sp_dialog_defocus_on_enter (GtkWidget *w)
90 {
91     g_signal_connect ( G_OBJECT (w), "activate",
92                        G_CALLBACK (sp_dialog_defocus_callback), w );
93 }
97 gboolean
98 sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data)
99 {
101 // if the focus is inside the Text and Font textview, do nothing
102     GObject *dlg = (GObject *) data;
103     if (g_object_get_data (dlg, "eatkeys")) {
104         return FALSE;
105     }
107     gboolean ret = FALSE;
109     switch (event->type) {
111         case GDK_KEY_PRESS:
113             switch (get_group0_keyval (&event->key)) {
114                 case GDK_Escape:
115                     sp_dialog_defocus (win);
116                     ret = TRUE;
117                     break;
118                 case GDK_F4:
119                 case GDK_w:
120                 case GDK_W:
121                     // close dialog
122                     if (MOD__CTRL_ONLY) {
124                         /* this code sends a delete_event to the dialog,
125                          * instead of just destroying it, so that the
126                          * dialog can do some housekeeping, such as remember
127                          * its position.
128                          */
129                         GdkEventAny event;
130                         GtkWidget *widget = (GtkWidget *) win;
131                         event.type = GDK_DELETE;
132                         event.window = widget->window;
133                         event.send_event = TRUE;
134                         g_object_ref (G_OBJECT (event.window));
135                         gtk_main_do_event ((GdkEvent*)&event);
136                         g_object_unref (G_OBJECT (event.window));
138                         ret = TRUE;
139                     }
140                     break;
141                 default: // pass keypress to the canvas
142                     break;
143             }
144     default:
145         ;
146     }
148     return ret;
154 /**
155  * \brief  Make the argument dialog transient to the currently active document
156            window.
157  */
158 void
159 sp_transientize (GtkWidget *dialog)
161     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
162 #ifndef WIN32  // FIXME: Temporary Win32 special code to enable transient dialogs
163     // _set_skip_taskbar_hint makes transient dialogs NON-transient! When dialogs
164     // are made transient (_set_transient_for), they are already removed from
165     // the taskbar in Win32.
166     if (prefs->getBool( "/options/dialogsskiptaskbar/value")) {
167         gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
168     }
169 #endif
171     gint transient_policy = prefs->getIntLimited("/options/transientpolicy/value", 1, 0, 2);
173 #ifdef WIN32 // Win32 special code to enable transient dialogs
174     transient_policy = 2;
175 #endif
177     if (transient_policy) {
179     // if there's an active document window, attach dialog to it as a transient:
181         if ( SP_ACTIVE_DESKTOP )
182         {
183             SP_ACTIVE_DESKTOP->setWindowTransient (dialog, transient_policy);
184         }
185     }
186 } // end of sp_transientize()
188 void on_transientize (SPDesktop *desktop, win_data *wd )
190     sp_transientize_callback (0, desktop, wd);
193 void
194 sp_transientize_callback ( Inkscape::Application * /*inkscape*/,
195                            SPDesktop *desktop, win_data *wd )
197     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
198     gint transient_policy = prefs->getIntLimited( "/options/transientpolicy/value", 1, 0, 2);
200 #ifdef WIN32 // Win32 special code to enable transient dialogs
201     transient_policy = 1;
202 #endif
204     if (!transient_policy)
205         return;
207     if (wd->win)
208     {
209         desktop->setWindowTransient (wd->win, transient_policy);
210     }
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:fileencoding=utf-8:textwidth=99 :