Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / ui / widget / svg-canvas.cpp
1 /** \file
2  * Gtkmm facade/wrapper around SPCanvas.
3  *
4  * Authors:
5  *   Ralf Stephan <ralf@ark.in-berlin.de>
6  *
7  * Copyright (C) 2005 The Authors
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #include <gtkmm/widget.h>
13 #include "desktop.h"
14 #include "desktop-events.h"
15 #include "display/sp-canvas.h"
16 #include "display/canvas-arena.h"
17 #include "ui/widget/svg-canvas.h"
19 namespace Inkscape {
20 namespace UI {
21 namespace Widget {
23 SVGCanvas::SVGCanvas()
24 {
25     void *canvas = gtk_type_new (sp_canvas_get_type ());
26     _spcanvas = static_cast<SPCanvas*>(canvas);
27     _widget = Glib::wrap (static_cast<GtkWidget*> (canvas));
28     _dt = 0;
29 }
31 SVGCanvas::~SVGCanvas()
32 {
33 }
35 void
36 SVGCanvas::init (SPDesktop *dt)
37 {
38     _dt = dt;
39     _widget->set_flags(Gtk::CAN_FOCUS);
41     // Set background to white
42     Glib::RefPtr<Gtk::Style> style = _widget->get_style();
43     style->set_bg(Gtk::STATE_NORMAL, style->get_white());
44     _widget->set_style(style);
45     _widget->set_extension_events(Gdk::EXTENSION_EVENTS_ALL);
46     _widget->signal_event().connect(sigc::mem_fun(*this, &SVGCanvas::onEvent));
47 }
49 bool
50 SVGCanvas::onEvent (GdkEvent * ev) const
51 {
52     g_assert (_dt);
54     // Gdk::Event doesn't appear to be fully usable for this atm
55     if (ev->type == GDK_BUTTON_PRESS) {
56         // defocus any spinbuttons
57         _widget->grab_focus();
58     }
60     if ((ev->type == GDK_BUTTON_PRESS) && (ev->button.button == 3)) {
61         if (ev->button.state & GDK_SHIFT_MASK) {
62             sp_canvas_arena_set_sticky(SP_CANVAS_ARENA(_dt->drawing), true);
63         } else {
64             sp_canvas_arena_set_sticky(SP_CANVAS_ARENA(_dt->drawing), false);
65         }
66     }
68     // The keypress events need to be passed to desktop handler explicitly,
69     // because otherwise the event contexts only receive keypresses when the mouse cursor
70     // is over the canvas. This redirection is only done for keypresses and only if there's no
71     // current item on the canvas, because item events and all mouse events are caught
72     // and passed on by the canvas acetate (I think). --bb
74     if (ev->type == GDK_KEY_PRESS && !_spcanvas->current_item) {
75         return sp_desktop_root_handler(0, ev, _dt);
76     }
78     return false;
79 }
81 }}}
83 /*
84   Local Variables:
85   mode:c++
86   c-file-style:"stroustrup"
87   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
88   indent-tabs-mode:nil
89   fill-column:99
90   End:
91 */
92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :