summaryrefslogtreecommitdiffstats
path: root/src/ui/view
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-11-06 18:25:30 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-11-06 18:25:30 +0000
commit77f8d590d64320f587907322eb2aa9f88457e8c6 (patch)
treed67777bb24f895f71528b1ff28971adb788d768f /src/ui/view
parentsimple fix in french translation (diff)
downloadinkscape-77f8d590d64320f587907322eb2aa9f88457e8c6.tar.gz
inkscape-77f8d590d64320f587907322eb2aa9f88457e8c6.zip
C++ify SVGViewWidget. Remove unused code.
Diffstat (limited to 'src/ui/view')
-rw-r--r--src/ui/view/svg-view-widget.cpp80
-rw-r--r--src/ui/view/svg-view-widget.h57
-rw-r--r--src/ui/view/svg-view.cpp238
-rw-r--r--src/ui/view/svg-view.h100
-rw-r--r--src/ui/view/view-widget.h2
5 files changed, 476 insertions, 1 deletions
diff --git a/src/ui/view/svg-view-widget.cpp b/src/ui/view/svg-view-widget.cpp
new file mode 100644
index 000000000..81589abb2
--- /dev/null
+++ b/src/ui/view/svg-view-widget.cpp
@@ -0,0 +1,80 @@
+/*
+ * Author:
+ * Tavmjong Bah <tavmjong@free.fr>
+ *
+ * Copyright (C) 2018 Tavmong Bah
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#include "svg-view-widget.h"
+#include "svg-view.h"
+
+#include "document.h"
+
+#include "display/sp-canvas.h"
+#include "display/sp-canvas-group.h"
+#include "display/sp-canvas-item.h"
+
+
+namespace Inkscape {
+namespace UI {
+namespace View {
+
+/**
+ * A light-weight widget containing an SPCanvas with a View for rendering an SVG.
+ * It's derived from a Gtk::ScrolledWindow like the previous C version, but that doesn't seem to be
+ * too useful.
+ */
+SVGViewWidget::SVGViewWidget(SPDocument* document)
+{
+ _canvas = SPCanvas::createAA();
+ add(*Glib::wrap(_canvas));
+
+ SPCanvasItem* parent =
+ sp_canvas_item_new(SP_CANVAS(_canvas)->getRoot(), SP_TYPE_CANVAS_GROUP, nullptr);
+ _view = new SVGView(SP_CANVAS_GROUP(parent));
+ _view->setDocument(document);
+
+ signal_size_allocate().connect(sigc::mem_fun(*this, &SVGViewWidget::size_allocate));
+}
+
+SVGViewWidget::~SVGViewWidget()
+{
+ delete _view;
+ delete _canvas;
+}
+
+void
+SVGViewWidget::setDocument(SPDocument* document)
+{
+ _view->setDocument(document);
+}
+
+void
+SVGViewWidget::setResize(int width, int height)
+{
+ set_size_request(width, height);
+ queue_resize();
+}
+
+void
+SVGViewWidget::size_allocate(Gtk::Allocation& allocation)
+{
+ _view->setRescale(true, true, allocation.get_width(), allocation.get_height());
+}
+
+} // Namespace View
+} // Namespace UI
+} // Namespace Inkscape
+
+/*
+ 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 :
diff --git a/src/ui/view/svg-view-widget.h b/src/ui/view/svg-view-widget.h
new file mode 100644
index 000000000..11bbba827
--- /dev/null
+++ b/src/ui/view/svg-view-widget.h
@@ -0,0 +1,57 @@
+/*
+ * Author:
+ * Tavmjong Bah <tavmjong@free.fr>
+ *
+ * Copyright (C) 2018 Tavmong Bah
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_SVG_VIEW_WIDGET_VARIATIONS_H
+#define INKSCAPE_UI_SVG_VIEW_WIDGET_VARIATIONS_H
+
+
+#include <gtkmm.h>
+
+class SPDocument;
+
+namespace Inkscape {
+namespace UI {
+namespace View {
+
+class SVGView;
+
+/**
+ * A light-weight widget containing an SPCanvas with an SVGView for rendering an SVG.
+ */
+class SVGViewWidget : public Gtk::ScrolledWindow {
+
+public:
+ SVGViewWidget(SPDocument* document);
+ ~SVGViewWidget();
+ void setDocument( SPDocument* document);
+ void setResize( int width, int height);
+
+private:
+ void size_allocate(Gtk::Allocation& allocation);
+
+ SVGView* _view;
+ GtkWidget* _canvas;
+};
+
+} // Namespace View
+} // Namespace UI
+} // Namespace Inkscape
+
+#endif // INKSCAPE_UI_SVG_VIEW_WIDGET
+
+/*
+ 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 :
diff --git a/src/ui/view/svg-view.cpp b/src/ui/view/svg-view.cpp
new file mode 100644
index 000000000..6b90e8ccd
--- /dev/null
+++ b/src/ui/view/svg-view.cpp
@@ -0,0 +1,238 @@
+/*
+ * Functions and callbacks for generic SVG view and widget.
+ *
+ * Authors:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ * Ralf Stephan <ralf@ark.in-berlin.de>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
+ *
+ * Copyright (C) 2001-2002 Lauris Kaplinski
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <2geom/transforms.h>
+
+#include "ui/view/svg-view.h"
+
+#include "document.h"
+
+#include "display/canvas-arena.h"
+#include "display/drawing-group.h"
+
+#include "object/sp-item.h"
+#include "object/sp-root.h"
+
+#include "util/units.h"
+
+namespace Inkscape {
+namespace UI {
+namespace View {
+
+SVGView::SVGView(SPCanvasGroup *parent)
+{
+ _hscale = 1.0;
+ _vscale = 1.0;
+ _rescale = FALSE;
+ _keepaspect = FALSE;
+ _width = 0.0;
+ _height = 0.0;
+
+ _dkey = 0;
+ _drawing = nullptr;
+ _parent = parent;
+}
+
+SVGView::~SVGView()
+{
+ if (doc() && _drawing)
+ {
+ doc()->getRoot()->invoke_hide(_dkey);
+ _drawing = nullptr;
+ }
+}
+
+void SVGView::setScale(gdouble hscale, gdouble vscale)
+{
+ if (!_rescale && ((hscale != _hscale) || (vscale != _vscale))) {
+ _hscale = hscale;
+ _vscale = vscale;
+ doRescale (true);
+ }
+}
+
+void SVGView::setRescale(bool rescale, bool keepaspect, gdouble width, gdouble height)
+{
+ g_return_if_fail (!rescale || (width >= 0.0));
+ g_return_if_fail (!rescale || (height >= 0.0));
+
+ _rescale = rescale;
+ _keepaspect = keepaspect;
+ _width = width;
+ _height = height;
+
+ doRescale (true);
+}
+
+void SVGView::doRescale(bool event)
+{
+ if (!doc()) {
+ return;
+ }
+ if (doc()->getWidth().value("px") < 1e-9) {
+ return;
+ }
+ if (doc()->getHeight().value("px") < 1e-9) {
+ return;
+ }
+
+ double x_offset = 0.0;
+ double y_offset = 0.0;
+ if (_rescale) {
+ _hscale = _width / doc()->getWidth().value("px");
+ _vscale = _height / doc()->getHeight().value("px");
+ if (_keepaspect) {
+ if (_hscale > _vscale) {
+ _hscale = _vscale;
+ x_offset = (_width - doc()->getWidth().value("px") * _vscale)/2.0;
+ } else {
+ _vscale = _hscale;
+ y_offset = (_height - doc()->getHeight().value("px") * _hscale)/2.0;
+ }
+ }
+ }
+
+ if (_drawing) {
+ sp_canvas_item_affine_absolute (_drawing, Geom::Scale(_hscale, _vscale) * Geom::Translate(x_offset, y_offset));
+ }
+
+ if (event) {
+ emitResized (doc()->getWidth().value("px") * _hscale,
+ doc()->getHeight().value("px") * _vscale);
+ }
+}
+
+void SVGView::mouseover()
+{
+ GdkDisplay *display = gdk_display_get_default();
+ GdkCursor *cursor = gdk_cursor_new_for_display(display, GDK_HAND2);
+ GdkWindow *window = gtk_widget_get_window (GTK_WIDGET(SP_CANVAS_ITEM(_drawing)->canvas));
+ gdk_window_set_cursor(window, cursor);
+ g_object_unref(cursor);
+}
+
+void SVGView::mouseout()
+{
+ GdkWindow *window = gtk_widget_get_window (GTK_WIDGET(SP_CANVAS_ITEM(_drawing)->canvas));
+ gdk_window_set_cursor(window, nullptr);
+}
+
+//----------------------------------------------------------------
+/**
+ * Callback connected with arena_event.
+ */
+/// \todo fixme.
+static gint arena_handler(SPCanvasArena */*arena*/, Inkscape::DrawingItem *ai, GdkEvent *event, SVGView *svgview)
+{
+ static gdouble x, y;
+ static gboolean active = FALSE;
+ SPEvent spev;
+
+ SPItem *spitem = (ai) ? (static_cast<SPItem*>(ai->data())) : nullptr;
+
+ switch (event->type) {
+ case GDK_BUTTON_PRESS:
+ if (event->button.button == 1) {
+ active = TRUE;
+ x = event->button.x;
+ y = event->button.y;
+ }
+ break;
+ case GDK_BUTTON_RELEASE:
+ if (event->button.button == 1) {
+ if (active && (event->button.x == x) &&
+ (event->button.y == y)) {
+ spev.type = SP_EVENT_ACTIVATE;
+ if ( spitem != nullptr )
+ {
+ spitem->emitEvent (spev);
+ }
+ }
+ }
+ active = FALSE;
+ break;
+ case GDK_MOTION_NOTIFY:
+ active = FALSE;
+ break;
+ case GDK_ENTER_NOTIFY:
+ spev.type = SP_EVENT_MOUSEOVER;
+ spev.data = svgview;
+ if ( spitem != nullptr )
+ {
+ spitem->emitEvent (spev);
+ }
+ break;
+ case GDK_LEAVE_NOTIFY:
+ spev.type = SP_EVENT_MOUSEOUT;
+ spev.data = svgview;
+ if ( spitem != nullptr )
+ {
+ spitem->emitEvent (spev);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+void SVGView::setDocument(SPDocument *document)
+{
+ if (doc()) {
+ doc()->getRoot()->invoke_hide(_dkey);
+ }
+
+ if (!_drawing) {
+ _drawing = sp_canvas_item_new (_parent, SP_TYPE_CANVAS_ARENA, nullptr);
+ g_signal_connect (G_OBJECT (_drawing), "arena_event", G_CALLBACK (arena_handler), this);
+ }
+
+ View::setDocument (document);
+
+ if (document) {
+ Inkscape::DrawingItem *ai = document->getRoot()->invoke_show(
+ SP_CANVAS_ARENA (_drawing)->drawing,
+ _dkey,
+ SP_ITEM_SHOW_DISPLAY);
+
+ if (ai) {
+ SP_CANVAS_ARENA (_drawing)->drawing.root()->prependChild(ai);
+ }
+
+ doRescale (!_rescale);
+ }
+}
+
+void SVGView::onDocumentResized(gdouble width, gdouble height)
+{
+ setScale (width, height);
+ doRescale (!_rescale);
+}
+
+}
+}
+}
+
+/*
+ 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 :
diff --git a/src/ui/view/svg-view.h b/src/ui/view/svg-view.h
new file mode 100644
index 000000000..23698eb36
--- /dev/null
+++ b/src/ui/view/svg-view.h
@@ -0,0 +1,100 @@
+#ifndef SEEN_SVG_VIEW_H
+#define SEEN_SVG_VIEW_H
+/*
+ * Authors:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ * Ralf Stephan <ralf@ark.in-berlin.de>
+ *
+ * Copyright (C) 2001-2002 Lauris Kaplinski
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "ui/view/view.h"
+
+struct SPCanvasGroup;
+struct SPCanvasItem;
+
+namespace Inkscape {
+namespace UI {
+namespace View {
+
+/**
+ * Generic SVG view.
+ */
+class SVGView : public View {
+public:
+ unsigned int _dkey;
+ SPCanvasGroup *_parent;
+ SPCanvasItem *_drawing;
+ double _hscale; ///< horizontal scale
+ double _vscale; ///< vertical scale
+ bool _rescale; ///< whether to rescale automatically
+ bool _keepaspect;
+ double _width;
+ double _height;
+
+
+ /**
+ * Constructs new SPSVGView object and returns pointer to it.
+ */
+ SVGView(SPCanvasGroup* parent);
+
+ ~SVGView() override;
+
+ /**
+ * Rescales SPSVGView to given proportions.
+ */
+ void setScale(double hscale, double vscale);
+
+ /**
+ * Rescales SPSVGView and keeps aspect ratio.
+ */
+ void setRescale(bool rescale, bool keepaspect, double width, double height);
+
+ /**
+ * Helper function that sets rescale ratio and emits resize event.
+ */
+ void doRescale(bool event);
+
+ /**
+ * Callback connected with set_document signal.
+ */
+ void setDocument(SPDocument *document) override;
+
+ void mouseover() override;
+
+ void mouseout() override;
+
+ bool shutdown() override { return true; }
+
+private:
+ virtual void onPositionSet(double, double) {}
+ void onResized(double, double) override {}
+ void onRedrawRequested() override {}
+ void onStatusMessage(Inkscape::MessageType /*type*/, gchar const */*message*/) override {}
+ void onDocumentURISet(gchar const* /*uri*/) override {}
+
+ /**
+ * Callback connected with document_resized signal.
+ */
+ void onDocumentResized(double, double) override;
+};
+
+}
+}
+}
+
+#endif // SEEN_SVG_VIEW_H
+
+/*
+ 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 :
diff --git a/src/ui/view/view-widget.h b/src/ui/view/view-widget.h
index 661b7b342..7c299972a 100644
--- a/src/ui/view/view-widget.h
+++ b/src/ui/view/view-widget.h
@@ -61,7 +61,7 @@ SPViewWidget *sp_desktop_widget_new(SPNamedView *namedview);
*/
class SPViewWidget {
public:
- GtkEventBox eventbox;
+ GtkEventBox eventbox; // NOT USED!
Inkscape::UI::View::View *view;