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 class EventLog;
56 namespace UI {
57 namespace Dialog {
58 class DialogManager;
59 }
60 }
61 namespace Whiteboard {
62 class SessionManager;
63 }
64 }
66 /**
67 * Editable view.
68 *
69 * @see \ref desktop-handles.h for desktop macros.
70 */
71 struct SPDesktop : public Inkscape::UI::View::View
72 {
73 Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
74 SPNamedView *namedview;
75 SPCanvas *canvas;
76 /// current selection; will never generally be NULL
77 Inkscape::Selection *selection;
78 SPEventContext *event_context;
79 Inkscape::LayerManager *layer_manager;
80 Inkscape::EventLog *event_log;
82 SPCanvasItem *acetate;
83 SPCanvasGroup *main;
84 SPCanvasGroup *grid;
85 SPCanvasGroup *guides;
86 SPCanvasItem *drawing;
87 SPCanvasGroup *sketch;
88 SPCanvasGroup *controls;
89 SPCanvasItem *table; ///< outside-of-page background
90 SPCanvasItem *page; ///< page background
91 SPCanvasItem *page_border; ///< page border
92 SPCSSAttr *current; ///< current style
94 GList *zooms_past;
95 GList *zooms_future;
96 unsigned int dkey;
97 unsigned int number;
98 bool is_fullscreen;
99 unsigned int interaction_disabled_counter;
101 /// \todo fixme: This has to be implemented in different way */
102 guint guides_active : 1;
104 // storage for selected dragger used by GrDrag as it's
105 // created and deleted by tools
106 SPItem *gr_item;
107 guint gr_point_type;
108 guint gr_point_i;
109 bool gr_fill_or_stroke;
112 Inkscape::ObjectHierarchy *_layer_hierarchy;
113 gchar * _reconstruction_old_layer_id;
115 sigc::signal<void, sp_verb_t> _tool_changed;
116 sigc::signal<void, SPObject *> _layer_changed_signal;
117 sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
118 sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
119 sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
120 {
121 return _document_replaced_signal.connect (slot);
122 }
124 sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
125 {
126 return _event_context_changed_signal.connect (slot);
127 }
128 sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
129 {
130 return _set_style_signal.connect (slot);
131 }
132 sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
133 {
134 return _query_style_signal.connect (slot);
135 }
136 // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
137 sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
138 return _tool_subselection_changed.connect(slot);
139 }
140 void emitToolSubselectionChanged(gpointer data);
141 sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
142 return _layer_changed_signal.connect(slot);
143 }
145 // Whiteboard changes
147 #ifdef WITH_INKBOARD
148 Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
149 return _whiteboard_session_manager;
150 }
152 Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
153 #endif
155 SPDesktop();
156 void init (SPNamedView* nv, SPCanvas* canvas);
157 ~SPDesktop();
158 void destroy();
160 Inkscape::MessageContext *guidesMessageContext() const {
161 return _guides_message_context;
162 }
164 void setDisplayModeNormal();
165 void setDisplayModeOutline();
166 void displayModeToggle();
167 int displayMode;
168 int getMode() const { return displayMode; }
170 void set_active (bool new_active);
171 SPObject *currentRoot() const;
172 SPObject *currentLayer() const;
173 void setCurrentLayer(SPObject *object);
174 SPObject *layerForObject(SPObject *object);
175 bool isLayer(SPObject *object) const;
176 bool isWithinViewport(SPItem *item) const;
177 bool itemIsHidden(SPItem const *item) const;
179 void activate_guides (bool activate);
180 void change_document (SPDocument *document);
182 void set_event_context (GtkType type, const gchar *config);
183 void push_event_context (GtkType type, const gchar *config, unsigned int key);
185 void set_coordinate_status (NR::Point p);
186 SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
187 SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
188 SPItem *group_at_point (NR::Point const p) const;
189 NR::Point point() const;
191 NR::Rect get_display_area() const;
192 void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
193 void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
194 void zoom_absolute (double cx, double cy, double zoom);
195 void zoom_relative (double cx, double cy, double zoom);
196 void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
197 void zoom_relative_keep_point (double cx, double cy, double zoom);
198 void zoom_relative_keep_point (NR::Point const &c, double const zoom)
199 {
200 using NR::X;
201 using NR::Y;
202 zoom_relative_keep_point (c[X], c[Y], zoom);
203 }
205 void zoom_page();
206 void zoom_page_width();
207 void zoom_drawing();
208 void zoom_selection();
209 void zoom_grab_focus();
210 double current_zoom() const { return _d2w.expansion(); }
211 void prev_zoom();
212 void next_zoom();
214 bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
215 void scroll_world (double dx, double dy);
216 void scroll_world (NR::Point const scroll)
217 {
218 using NR::X;
219 using NR::Y;
220 scroll_world(scroll[X], scroll[Y]);
221 }
223 void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
224 void setWindowPosition (NR::Point p);
225 void setWindowSize (gint w, gint h);
226 void setWindowTransient (void* p, int transient_policy=1);
227 void presentWindow();
228 bool warnDialog (gchar *text);
229 void toggleRulers();
230 void toggleScrollbars();
231 void layoutWidget();
232 void destroyWidget();
233 void setToolboxFocusTo (gchar const* label);
234 void setToolboxAdjustmentValue (gchar const* id, double val);
235 bool isToolboxButtonActive (gchar const *id);
236 void updateNow();
237 void updateCanvasNow();
239 void enableInteraction();
240 void disableInteraction();
242 void fullscreen();
244 void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
245 { _widget = widget; }
247 NR::Matrix w2d() const;
248 NR::Point w2d(NR::Point const &p) const;
249 NR::Point d2w(NR::Point const &p) const;
250 NR::Matrix doc2dt() const;
251 NR::Point doc2dt(NR::Point const &p) const;
252 NR::Point dt2doc(NR::Point const &p) const;
254 virtual void setDocument (SPDocument* doc);
255 virtual bool shutdown();
256 virtual void mouseover() {}
257 virtual void mouseout() {}
259 private:
260 Inkscape::UI::View::EditWidgetInterface *_widget;
261 Inkscape::Application *_inkscape;
262 Inkscape::MessageContext *_guides_message_context;
263 bool _active;
264 NR::Matrix _w2d;
265 NR::Matrix _d2w;
266 NR::Matrix _doc2dt;
268 void push_current_zoom (GList**);
270 sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal;
271 sigc::signal<void> _activate_signal;
272 sigc::signal<void> _deactivate_signal;
273 sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
274 sigc::signal<void, gpointer> _tool_subselection_changed;
276 sigc::connection _activate_connection;
277 sigc::connection _deactivate_connection;
278 sigc::connection _sel_modified_connection;
279 sigc::connection _sel_changed_connection;
280 sigc::connection _reconstruction_start_connection;
281 sigc::connection _reconstruction_finish_connection;
282 sigc::connection _commit_connection;
283 sigc::connection _modified_connection;
285 virtual void onPositionSet (double, double);
286 virtual void onResized (double, double);
287 virtual void onRedrawRequested();
288 virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
289 virtual void onDocumentURISet (gchar const* uri);
290 virtual void onDocumentResized (double, double);
292 static void _onActivate (SPDesktop* dt);
293 static void _onDeactivate (SPDesktop* dt);
294 static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
295 };
297 #endif
299 /*
300 Local Variables:
301 mode:c++
302 c-file-style:"stroustrup"
303 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
304 indent-tabs-mode:nil
305 fill-column:99
306 End:
307 */
308 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :