1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef INKSCAPE_SP_NAMEDVIEW_H
3 #define INKSCAPE_SP_NAMEDVIEW_H
4 
5 /*
6  * <sodipodi:namedview> implementation
7  *
8  * Authors:
9  *   Lauris Kaplinski <lauris@kaplinski.com>
10  *   Abhishek Sharma
11  *
12  * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
13  * Copyright (C) Lauris Kaplinski 2000-2002
14  *
15  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16  */
17 
18 #define SP_NAMEDVIEW(obj) (dynamic_cast<SPNamedView*>((SPObject*)obj))
19 #define SP_IS_NAMEDVIEW(obj) (dynamic_cast<const SPNamedView*>((SPObject*)obj) != NULL)
20 
21 #include "sp-object-group.h"
22 #include "snap.h"
23 #include "document.h"
24 #include "util/units.h"
25 #include <vector>
26 
27 namespace Inkscape {
28     class CanvasGrid;
29     namespace Util {
30         class Unit;
31     }
32 }
33 
34 typedef unsigned int guint32;
35 typedef guint32 GQuark;
36 
37 enum {
38     SP_BORDER_LAYER_BOTTOM,
39     SP_BORDER_LAYER_TOP
40 };
41 
42 class SPNamedView : public SPObjectGroup {
43 public:
44     SPNamedView();
45     ~SPNamedView() override;
46 
47     unsigned int editable : 1;
48     unsigned int showguides : 1;
49     unsigned int lockguides : 1;
50     unsigned int pagecheckerboard : 1;
51     unsigned int showborder : 1;
52     unsigned int showpageshadow : 1;
53     unsigned int borderlayer : 2;
54 
55     double zoom;
56     double rotation; // Document rotation in degrees (positive is clockwise)
57     double cx;
58     double cy;
59     int window_width;
60     int window_height;
61     int window_x;
62     int window_y;
63     int window_maximized;
64 
65     SnapManager snap_manager;
66     std::vector<Inkscape::CanvasGrid *> grids;
67     bool grids_visible;
68 
69     Inkscape::Util::Unit const *display_units;   // Units used for the UI (*not* the same as units of SVG coordinates)
70     Inkscape::Util::Unit const *page_size_units; // Only used in "Custom size" part of Document Properties dialog
71 
72     GQuark default_layer_id;
73 
74     double connector_spacing;
75 
76     guint32 guidecolor;
77     guint32 guidehicolor;
78     guint32 bordercolor;
79     guint32 pagecolor;
80     guint32 pageshadow;
81 
82     std::vector<SPGuide *> guides;
83     std::vector<SPDesktop *> views;
84 
85     int viewcount;
86 
87     void show(SPDesktop *desktop);
88     void hide(SPDesktop const *desktop);
89     void setDefaultAttribute(std::string attribute, std::string preference, std::string fallback);
90     void activateGuides(void* desktop, bool active);
91     char const *getName() const;
92     unsigned int getViewCount();
93     std::vector<SPDesktop *> const getViewList() const;
94     Inkscape::Util::Unit const * getDisplayUnit() const;
95 
96     void translateGuides(Geom::Translate const &translation);
97     void translateGrids(Geom::Translate const &translation);
98     void scrollAllDesktops(double dx, double dy, bool is_scrolling);
99     void writeNewGrid(SPDocument *document,int gridtype);
100     void setGuides(bool v);
101     bool getGuides();
102     void lockGuides();
103 
104 private:
105     double getMarginLength(gchar const * const key,Inkscape::Util::Unit const * const margin_units,Inkscape::Util::Unit const * const return_units,double const width,double const height,bool const use_width);
106     friend class SPDocument;
107 
108 protected:
109 	void build(SPDocument *document, Inkscape::XML::Node *repr) override;
110 	void release() override;
111 	void set(SPAttr key, char const* value) override;
112 
113 	void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) override;
114 	void remove_child(Inkscape::XML::Node* child) override;
115 
116 	Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override;
117 };
118 
119 
120 SPNamedView *sp_document_namedview(SPDocument *document, char const *name);
121 SPNamedView const *sp_document_namedview(SPDocument const *document, char const *name);
122 
123 void sp_namedview_window_from_document(SPDesktop *desktop);
124 void sp_namedview_zoom_and_view_from_document(SPDesktop *desktop);
125 void sp_namedview_document_from_window(SPDesktop *desktop);
126 void sp_namedview_update_layers_from_document (SPDesktop *desktop);
127 
128 void sp_namedview_toggle_guides(SPDocument *doc, SPNamedView *namedview);
129 void sp_namedview_guides_toggle_lock(SPDocument *doc, SPNamedView *namedview);
130 void sp_namedview_show_grids(SPNamedView *namedview, bool show, bool dirty_document);
131 Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview);
132 
133 
134 #endif /* !INKSCAPE_SP_NAMEDVIEW_H */
135 
136 
137 /*
138   Local Variables:
139   mode:c++
140   c-file-style:"stroustrup"
141   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
142   indent-tabs-mode:nil
143   fill-column:99
144   End:
145 */
146 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
147