1 #ifndef __SP_DESKTOP_H__
2 #define __SP_DESKTOP_H__
4 /** \file
5 * SPDesktop: an editable view.
6 *
7 * Author:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Frank Felfe <innerspace@iname.com>
10 * bulia byak <buliabyak@users.sf.net>
11 * Ralf Stephan <ralf@ark.in-berlin.de>
12 * John Bintz <jcoswell@coswellproductions.org>
13 *
14 * Copyright (C) 2006 John Bintz
15 * Copyright (C) 1999-2005 authors
16 * Copyright (C) 2000-2001 Ximian, Inc.
17 *
18 * Released under GNU GPL, read the file 'COPYING' for more information
19 *
20 */
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include <gtk/gtktypeutils.h>
27 #include <sigc++/sigc++.h>
28 #include "libnr/nr-matrix.h"
29 #include "libnr/nr-matrix-fns.h"
30 #include "libnr/nr-rect.h"
31 #include "ui/view/view.h"
32 #include "ui/view/edit-widget-interface.h"
34 class NRRect;
35 class SPCSSAttr;
36 struct SPCanvas;
37 struct SPCanvasItem;
38 struct SPCanvasGroup;
39 struct SPDesktopWidget;
40 struct SPEventContext;
41 struct SPItem;
42 struct SPNamedView;
43 struct SPObject;
44 struct SPStyle;
45 struct SPViewWidget;
47 typedef int sp_verb_t;
49 namespace Inkscape {
50 class Application;
51 class MessageContext;
52 class Selection;
53 class ObjectHierarchy;
54 class LayerManager;
55 namespace UI {
56 namespace Dialog {
57 class DialogManager;
58 }
59 }
60 namespace Whiteboard {
61 class SessionManager;
62 }
63 }
65 /**
66 * Editable view.
67 *
68 * @see \ref desktop-handles.h for desktop macros.
69 */
70 struct SPDesktop : public Inkscape::UI::View::View
71 {
72 Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
73 SPNamedView *namedview;
74 SPCanvas *canvas;
75 /// current selection; will never generally be NULL
76 Inkscape::Selection *selection;
77 SPEventContext *event_context;
78 Inkscape::LayerManager *layer_manager;
80 SPCanvasItem *acetate;
81 SPCanvasGroup *main;
82 SPCanvasGroup *grid;
83 SPCanvasGroup *guides;
84 SPCanvasItem *drawing;
85 SPCanvasGroup *sketch;
86 SPCanvasGroup *controls;
87 SPCanvasItem *table; ///< outside-of-page background
88 SPCanvasItem *page; ///< page background
89 SPCanvasItem *page_border; ///< page border
90 SPCSSAttr *current; ///< current style
92 GList *zooms_past;
93 GList *zooms_future;
94 unsigned int dkey;
95 unsigned int number;
96 bool is_fullscreen;
97 unsigned int interaction_disabled_counter;
99 /// \todo fixme: This has to be implemented in different way */
100 guint guides_active : 1;
102 // storage for selected dragger used by GrDrag as it's
103 // created and deleted by tools
104 SPItem *gr_item;
105 guint gr_point_num;
106 bool gr_fill_or_stroke;
108 Inkscape::ObjectHierarchy *_layer_hierarchy;
109 gchar * _reconstruction_old_layer_id;
111 sigc::signal<void, sp_verb_t> _tool_changed;
112 sigc::signal<void, SPObject *> _layer_changed_signal;
113 sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
114 sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
115 sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
116 {
117 return _document_replaced_signal.connect (slot);
118 }
120 sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
121 {
122 return _event_context_changed_signal.connect (slot);
123 }
124 sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
125 {
126 return _set_style_signal.connect (slot);
127 }
128 sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
129 {
130 return _query_style_signal.connect (slot);
131 }
132 // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
133 sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
134 return _tool_subselection_changed.connect(slot);
135 }
136 void emitToolSubselectionChanged(gpointer data);
137 sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
138 return _layer_changed_signal.connect(slot);
139 }
141 // Whiteboard changes
143 #ifdef WITH_INKBOARD
144 Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
145 return _whiteboard_session_manager;
146 }
148 Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
149 #endif
151 SPDesktop();
152 void init (SPNamedView* nv, SPCanvas* canvas);
153 ~SPDesktop();
154 void destroy();
156 Inkscape::MessageContext *guidesMessageContext() const {
157 return _guides_message_context;
158 }
160 void setDisplayModeNormal();
161 void setDisplayModeOutline();
163 void set_active (bool new_active);
164 SPObject *currentRoot() const;
165 SPObject *currentLayer() const;
166 void setCurrentLayer(SPObject *object);
167 SPObject *layerForObject(SPObject *object);
168 bool isLayer(SPObject *object) const;
169 bool isWithinViewport(SPItem *item) const;
170 bool itemIsHidden(SPItem const *item) const;
172 void activate_guides (bool activate);
173 void change_document (SPDocument *document);
175 void set_event_context (GtkType type, const gchar *config);
176 void push_event_context (GtkType type, const gchar *config, unsigned int key);
178 void set_coordinate_status (NR::Point p);
179 SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
180 SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
181 SPItem *group_at_point (NR::Point const p) const;
182 NR::Point point() const;
184 NR::Rect get_display_area() const;
185 void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
186 void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
187 void zoom_absolute (double cx, double cy, double zoom);
188 void zoom_relative (double cx, double cy, double zoom);
189 void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
190 void zoom_relative_keep_point (double cx, double cy, double zoom);
191 void zoom_relative_keep_point (NR::Point const &c, double const zoom)
192 {
193 using NR::X;
194 using NR::Y;
195 zoom_relative_keep_point (c[X], c[Y], zoom);
196 }
198 void zoom_page();
199 void zoom_page_width();
200 void zoom_drawing();
201 void zoom_selection();
202 void zoom_grab_focus();
203 double current_zoom() const { return _d2w.expansion(); }
204 void prev_zoom();
205 void next_zoom();
207 bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
208 void scroll_world (double dx, double dy);
209 void scroll_world (NR::Point const scroll)
210 {
211 using NR::X;
212 using NR::Y;
213 scroll_world(scroll[X], scroll[Y]);
214 }
216 void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
217 void setWindowPosition (NR::Point p);
218 void setWindowSize (gint w, gint h);
219 void setWindowTransient (void* p, int transient_policy=1);
220 void presentWindow();
221 bool warnDialog (gchar *text);
222 void toggleRulers();
223 void toggleScrollbars();
224 void layoutWidget();
225 void destroyWidget();
226 void setToolboxFocusTo (gchar const* label);
227 void setToolboxAdjustmentValue (gchar const* id, double val);
228 bool isToolboxButtonActive (gchar const *id);
229 void updateNow();
230 void updateCanvasNow();
232 void enableInteraction();
233 void disableInteraction();
235 void fullscreen();
237 void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
238 { _widget = widget; }
240 NR::Matrix w2d() const;
241 NR::Point w2d(NR::Point const &p) const;
242 NR::Point d2w(NR::Point const &p) const;
243 NR::Matrix doc2dt() const;
244 NR::Point doc2dt(NR::Point const &p) const;
245 NR::Point dt2doc(NR::Point const &p) const;
247 virtual void setDocument (SPDocument* doc);
248 virtual bool shutdown();
249 virtual void mouseover() {}
250 virtual void mouseout() {}
252 private:
253 Inkscape::UI::View::EditWidgetInterface *_widget;
254 Inkscape::Application *_inkscape;
255 Inkscape::MessageContext *_guides_message_context;
256 bool _active;
257 NR::Matrix _w2d;
258 NR::Matrix _d2w;
259 NR::Matrix _doc2dt;
261 void push_current_zoom (GList**);
263 sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal;
264 sigc::signal<void> _activate_signal;
265 sigc::signal<void> _deactivate_signal;
266 sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
267 sigc::signal<void, gpointer> _tool_subselection_changed;
269 sigc::connection _activate_connection;
270 sigc::connection _deactivate_connection;
271 sigc::connection _sel_modified_connection;
272 sigc::connection _sel_changed_connection;
273 sigc::connection _reconstruction_start_connection;
274 sigc::connection _reconstruction_finish_connection;
275 sigc::connection _commit_connection;
276 sigc::connection _modified_connection;
278 virtual void onPositionSet (double, double);
279 virtual void onResized (double, double);
280 virtual void onRedrawRequested();
281 virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
282 virtual void onDocumentURISet (gchar const* uri);
283 virtual void onDocumentResized (double, double);
285 static void _onActivate (SPDesktop* dt);
286 static void _onDeactivate (SPDesktop* dt);
287 static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
288 };
290 #endif
292 /*
293 Local Variables:
294 mode:c++
295 c-file-style:"stroustrup"
296 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
297 indent-tabs-mode:nil
298 fill-column:99
299 End:
300 */
301 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :