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_num;
108 bool gr_fill_or_stroke;
110 Inkscape::ObjectHierarchy *_layer_hierarchy;
111 gchar * _reconstruction_old_layer_id;
113 sigc::signal<void, sp_verb_t> _tool_changed;
114 sigc::signal<void, SPObject *> _layer_changed_signal;
115 sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
116 sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
117 sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
118 {
119 return _document_replaced_signal.connect (slot);
120 }
122 sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
123 {
124 return _event_context_changed_signal.connect (slot);
125 }
126 sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
127 {
128 return _set_style_signal.connect (slot);
129 }
130 sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
131 {
132 return _query_style_signal.connect (slot);
133 }
134 // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
135 sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
136 return _tool_subselection_changed.connect(slot);
137 }
138 void emitToolSubselectionChanged(gpointer data);
139 sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
140 return _layer_changed_signal.connect(slot);
141 }
143 // Whiteboard changes
145 #ifdef WITH_INKBOARD
146 Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
147 return _whiteboard_session_manager;
148 }
150 Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
151 #endif
153 SPDesktop();
154 void init (SPNamedView* nv, SPCanvas* canvas);
155 ~SPDesktop();
156 void destroy();
158 Inkscape::MessageContext *guidesMessageContext() const {
159 return _guides_message_context;
160 }
162 void setDisplayModeNormal();
163 void setDisplayModeOutline();
164 void displayModeToggle();
165 int displayMode;
166 int getMode() const { return displayMode; }
168 void set_active (bool new_active);
169 SPObject *currentRoot() const;
170 SPObject *currentLayer() const;
171 void setCurrentLayer(SPObject *object);
172 SPObject *layerForObject(SPObject *object);
173 bool isLayer(SPObject *object) const;
174 bool isWithinViewport(SPItem *item) const;
175 bool itemIsHidden(SPItem const *item) const;
177 void activate_guides (bool activate);
178 void change_document (SPDocument *document);
180 void set_event_context (GtkType type, const gchar *config);
181 void push_event_context (GtkType type, const gchar *config, unsigned int key);
183 void set_coordinate_status (NR::Point p);
184 SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
185 SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
186 SPItem *group_at_point (NR::Point const p) const;
187 NR::Point point() const;
189 NR::Rect get_display_area() const;
190 void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
191 void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
192 void zoom_absolute (double cx, double cy, double zoom);
193 void zoom_relative (double cx, double cy, double zoom);
194 void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
195 void zoom_relative_keep_point (double cx, double cy, double zoom);
196 void zoom_relative_keep_point (NR::Point const &c, double const zoom)
197 {
198 using NR::X;
199 using NR::Y;
200 zoom_relative_keep_point (c[X], c[Y], zoom);
201 }
203 void zoom_page();
204 void zoom_page_width();
205 void zoom_drawing();
206 void zoom_selection();
207 void zoom_grab_focus();
208 double current_zoom() const { return _d2w.expansion(); }
209 void prev_zoom();
210 void next_zoom();
212 bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
213 void scroll_world (double dx, double dy);
214 void scroll_world (NR::Point const scroll)
215 {
216 using NR::X;
217 using NR::Y;
218 scroll_world(scroll[X], scroll[Y]);
219 }
221 void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
222 void setWindowPosition (NR::Point p);
223 void setWindowSize (gint w, gint h);
224 void setWindowTransient (void* p, int transient_policy=1);
225 void presentWindow();
226 bool warnDialog (gchar *text);
227 void toggleRulers();
228 void toggleScrollbars();
229 void layoutWidget();
230 void destroyWidget();
231 void setToolboxFocusTo (gchar const* label);
232 void setToolboxAdjustmentValue (gchar const* id, double val);
233 bool isToolboxButtonActive (gchar const *id);
234 void updateNow();
235 void updateCanvasNow();
237 void enableInteraction();
238 void disableInteraction();
240 void fullscreen();
242 void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
243 { _widget = widget; }
245 NR::Matrix w2d() const;
246 NR::Point w2d(NR::Point const &p) const;
247 NR::Point d2w(NR::Point const &p) const;
248 NR::Matrix doc2dt() const;
249 NR::Point doc2dt(NR::Point const &p) const;
250 NR::Point dt2doc(NR::Point const &p) const;
252 virtual void setDocument (SPDocument* doc);
253 virtual bool shutdown();
254 virtual void mouseover() {}
255 virtual void mouseout() {}
257 private:
258 Inkscape::UI::View::EditWidgetInterface *_widget;
259 Inkscape::Application *_inkscape;
260 Inkscape::MessageContext *_guides_message_context;
261 bool _active;
262 NR::Matrix _w2d;
263 NR::Matrix _d2w;
264 NR::Matrix _doc2dt;
266 void push_current_zoom (GList**);
268 sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal;
269 sigc::signal<void> _activate_signal;
270 sigc::signal<void> _deactivate_signal;
271 sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
272 sigc::signal<void, gpointer> _tool_subselection_changed;
274 sigc::connection _activate_connection;
275 sigc::connection _deactivate_connection;
276 sigc::connection _sel_modified_connection;
277 sigc::connection _sel_changed_connection;
278 sigc::connection _reconstruction_start_connection;
279 sigc::connection _reconstruction_finish_connection;
280 sigc::connection _commit_connection;
281 sigc::connection _modified_connection;
283 virtual void onPositionSet (double, double);
284 virtual void onResized (double, double);
285 virtual void onRedrawRequested();
286 virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
287 virtual void onDocumentURISet (gchar const* uri);
288 virtual void onDocumentResized (double, double);
290 static void _onActivate (SPDesktop* dt);
291 static void _onDeactivate (SPDesktop* dt);
292 static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
293 };
295 #endif
297 /*
298 Local Variables:
299 mode:c++
300 c-file-style:"stroustrup"
301 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
302 indent-tabs-mode:nil
303 fill-column:99
304 End:
305 */
306 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :