summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/svg-canvas.cpp
blob: 34724ece73f807eac0ab5b7d067604603a110765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Authors:
 *   Ralf Stephan <ralf@ark.in-berlin.de>
 *   Jon A. Cruz <jon@joncruz.org>
 *
 * Copyright (C) 2005 The Authors
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include <gtkmm/widget.h>
#include "desktop.h"
#include "desktop-events.h"
#include "display/sp-canvas.h"
#include "display/canvas-arena.h"
#include "ui/widget/svg-canvas.h"

namespace Inkscape {
namespace UI {
namespace Widget {

SVGCanvas::SVGCanvas()
{
    void *canvas = g_object_new(SPCanvas::getType(), NULL);
    _spcanvas = static_cast<SPCanvas*>(canvas);
    _widget = Glib::wrap (static_cast<GtkWidget*> (canvas));
    _dt = 0;
}

SVGCanvas::~SVGCanvas()
{
}

void
SVGCanvas::init (SPDesktop *dt)
{
    _dt = dt;
    _widget->set_can_focus();

    // Set background to white
#if WITH_GTKMM_3_0
    // TODO: Use Gtk::StyleContext instead
    GtkWidget *c_widget = _widget->gobj();
    GtkStyle *style = gtk_widget_get_style(c_widget);
    style->bg[GTK_STATE_NORMAL] = style->white;
    gtk_widget_set_style(c_widget, style);
#else
    Glib::RefPtr<Gtk::Style> style = _widget->get_style();
    style->set_bg(Gtk::STATE_NORMAL, style->get_white());
    _widget->set_style(style);
    
    // extension_events stuff is handled internally in GTK+ 3
    // TODO: Needs testing
    _widget->set_extension_events(Gdk::EXTENSION_EVENTS_ALL);
#endif
    
    _widget->signal_event().connect(sigc::mem_fun(*this, &SVGCanvas::onEvent));
}

bool
SVGCanvas::onEvent (GdkEvent * ev) const
{
    g_assert (_dt);

    // Gdk::Event doesn't appear to be fully usable for this atm
    if (ev->type == GDK_BUTTON_PRESS) {
        // defocus any spinbuttons
        _widget->grab_focus();
    }

    if ((ev->type == GDK_BUTTON_PRESS) && (ev->button.button == 3)) {
        if (ev->button.state & GDK_SHIFT_MASK) {
            sp_canvas_arena_set_sticky(SP_CANVAS_ARENA(_dt->drawing), true);
        } else {
            sp_canvas_arena_set_sticky(SP_CANVAS_ARENA(_dt->drawing), false);
        }
    }

    // The keypress events need to be passed to desktop handler explicitly,
    // because otherwise the event contexts only receive keypresses when the mouse cursor
    // is over the canvas. This redirection is only done for keypresses and only if there's no
    // current item on the canvas, because item events and all mouse events are caught
    // and passed on by the canvas acetate (I think). --bb

    if (ev->type == GDK_KEY_PRESS && !_spcanvas->current_item) {
        return sp_desktop_root_handler(0, ev, _dt);
    }

    return false;
}

}}}

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :