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 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
14 *
15 * Copyright (C) 2007 Johan Engelen
16 * Copyright (C) 2006 John Bintz
17 * Copyright (C) 1999-2005 authors
18 * Copyright (C) 2000-2001 Ximian, Inc.
19 *
20 * Released under GNU GPL, read the file 'COPYING' for more information
21 *
22 */
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include <gtk/gtktypeutils.h>
29 #include <sigc++/sigc++.h>
30 #include "libnr/nr-matrix.h"
31 #include "libnr/nr-matrix-fns.h"
32 #include "libnr/nr-rect.h"
33 #include "ui/view/view.h"
34 #include "ui/view/edit-widget-interface.h"
36 class NRRect;
37 class SPCSSAttr;
38 struct _GtkWidget;
39 typedef struct _GtkWidget GtkWidget;
40 struct SPCanvas;
41 struct SPCanvasItem;
42 struct SPCanvasGroup;
43 struct SPDesktopWidget;
44 struct SPEventContext;
45 struct SPItem;
46 struct SPNamedView;
47 struct SPObject;
48 struct SPStyle;
49 struct SPViewWidget;
51 typedef int sp_verb_t;
53 namespace Inkscape {
54 class Application;
55 class MessageContext;
56 class Selection;
57 class ObjectHierarchy;
58 class LayerManager;
59 class EventLog;
60 namespace UI {
61 namespace Dialog {
62 class DialogManager;
63 }
64 }
65 namespace Whiteboard {
66 class SessionManager;
67 }
68 }
70 /**
71 * Editable view.
72 *
73 * @see \ref desktop-handles.h for desktop macros.
74 */
75 struct SPDesktop : public Inkscape::UI::View::View
76 {
77 Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
78 SPNamedView *namedview;
79 SPCanvas *canvas;
80 /// current selection; will never generally be NULL
81 Inkscape::Selection *selection;
82 SPEventContext *event_context;
83 Inkscape::LayerManager *layer_manager;
84 Inkscape::EventLog *event_log;
86 SPCanvasItem *acetate;
87 SPCanvasGroup *main;
88 SPCanvasGroup *gridgroup;
89 SPCanvasGroup *guides;
90 SPCanvasItem *drawing;
91 SPCanvasGroup *sketch;
92 SPCanvasGroup *controls;
93 SPCanvasItem *table; ///< outside-of-page background
94 SPCanvasItem *page; ///< page background
95 SPCanvasItem *page_border; ///< page border
96 SPCSSAttr *current; ///< current style
98 GList *zooms_past;
99 GList *zooms_future;
100 unsigned int dkey;
101 unsigned int number;
102 bool is_fullscreen;
103 unsigned int interaction_disabled_counter;
104 bool waiting_cursor;
106 /// \todo fixme: This has to be implemented in different way */
107 guint guides_active : 1;
109 // storage for selected dragger used by GrDrag as it's
110 // created and deleted by tools
111 SPItem *gr_item;
112 guint gr_point_type;
113 guint gr_point_i;
114 bool gr_fill_or_stroke;
117 Inkscape::ObjectHierarchy *_layer_hierarchy;
118 gchar * _reconstruction_old_layer_id;
120 sigc::signal<void, sp_verb_t> _tool_changed;
121 sigc::signal<void, SPObject *> _layer_changed_signal;
122 sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
123 sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
124 sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
125 {
126 return _document_replaced_signal.connect (slot);
127 }
129 sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
130 {
131 return _event_context_changed_signal.connect (slot);
132 }
133 sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
134 {
135 return _set_style_signal.connect (slot);
136 }
137 sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
138 {
139 return _query_style_signal.connect (slot);
140 }
141 // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
142 sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
143 return _tool_subselection_changed.connect(slot);
144 }
145 void emitToolSubselectionChanged(gpointer data);
146 sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
147 return _layer_changed_signal.connect(slot);
148 }
150 // Whiteboard changes
152 #ifdef WITH_INKBOARD
153 Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
154 return _whiteboard_session_manager;
155 }
157 Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
158 #endif
160 SPDesktop();
161 void init (SPNamedView* nv, SPCanvas* canvas);
162 ~SPDesktop();
163 void destroy();
165 Inkscape::MessageContext *guidesMessageContext() const {
166 return _guides_message_context;
167 }
169 void setDisplayModeNormal();
170 void setDisplayModeOutline();
171 void displayModeToggle();
172 int displayMode;
173 int getMode() const { return displayMode; }
175 void set_active (bool new_active);
176 SPObject *currentRoot() const;
177 SPObject *currentLayer() const;
178 void setCurrentLayer(SPObject *object);
179 SPObject *layerForObject(SPObject *object);
180 bool isLayer(SPObject *object) const;
181 bool isWithinViewport(SPItem *item) const;
182 bool itemIsHidden(SPItem const *item) const;
184 void activate_guides (bool activate);
185 void change_document (SPDocument *document);
187 void set_event_context (GtkType type, const gchar *config);
188 void push_event_context (GtkType type, const gchar *config, unsigned int key);
190 void set_coordinate_status (NR::Point p);
191 SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
192 SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
193 SPItem *group_at_point (NR::Point const p) const;
194 NR::Point point() const;
196 NR::Rect get_display_area() const;
197 void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
198 void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
199 void zoom_absolute (double cx, double cy, double zoom);
200 void zoom_relative (double cx, double cy, double zoom);
201 void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
202 void zoom_relative_keep_point (double cx, double cy, double zoom);
203 void zoom_relative_keep_point (NR::Point const &c, double const zoom)
204 {
205 using NR::X;
206 using NR::Y;
207 zoom_relative_keep_point (c[X], c[Y], zoom);
208 }
210 void zoom_page();
211 void zoom_page_width();
212 void zoom_drawing();
213 void zoom_selection();
214 void zoom_grab_focus();
215 double current_zoom() const { return _d2w.expansion(); }
216 void prev_zoom();
217 void next_zoom();
219 bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
220 void scroll_world (double dx, double dy, bool is_scrolling = false);
221 void scroll_world (NR::Point const scroll, bool is_scrolling = false)
222 {
223 using NR::X;
224 using NR::Y;
225 scroll_world(scroll[X], scroll[Y], is_scrolling);
226 }
228 void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
229 void setWindowPosition (NR::Point p);
230 void setWindowSize (gint w, gint h);
231 void setWindowTransient (void* p, int transient_policy=1);
232 void getToplevel( GtkWidget*& toplevel );
233 void presentWindow();
234 bool warnDialog (gchar *text);
235 void toggleRulers();
236 void toggleScrollbars();
237 void layoutWidget();
238 void destroyWidget();
239 void setToolboxFocusTo (gchar const* label);
240 void setToolboxAdjustmentValue (gchar const* id, double val);
241 bool isToolboxButtonActive (gchar const *id);
242 void updateNow();
243 void updateCanvasNow();
245 void enableInteraction();
246 void disableInteraction();
248 void setWaitingCursor();
249 void clearWaitingCursor();
251 void toggleGrid();
252 bool gridsEnabled() { return grids_visible; }
254 void fullscreen();
256 void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
257 { _widget = widget; }
259 NR::Matrix w2d() const;
260 NR::Point w2d(NR::Point const &p) const;
261 NR::Point d2w(NR::Point const &p) const;
262 NR::Matrix doc2dt() const;
263 NR::Point doc2dt(NR::Point const &p) const;
264 NR::Point dt2doc(NR::Point const &p) const;
266 virtual void setDocument (SPDocument* doc);
267 virtual bool shutdown();
268 virtual void mouseover() {}
269 virtual void mouseout() {}
271 private:
272 Inkscape::UI::View::EditWidgetInterface *_widget;
273 Inkscape::Application *_inkscape;
274 Inkscape::MessageContext *_guides_message_context;
275 bool _active;
276 NR::Matrix _w2d;
277 NR::Matrix _d2w;
278 NR::Matrix _doc2dt;
280 bool grids_visible;
282 void push_current_zoom (GList**);
284 sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal;
285 sigc::signal<void> _activate_signal;
286 sigc::signal<void> _deactivate_signal;
287 sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
288 sigc::signal<void, gpointer> _tool_subselection_changed;
290 sigc::connection _activate_connection;
291 sigc::connection _deactivate_connection;
292 sigc::connection _sel_modified_connection;
293 sigc::connection _sel_changed_connection;
294 sigc::connection _reconstruction_start_connection;
295 sigc::connection _reconstruction_finish_connection;
296 sigc::connection _commit_connection;
297 sigc::connection _modified_connection;
299 virtual void onPositionSet (double, double);
300 virtual void onResized (double, double);
301 virtual void onRedrawRequested();
302 virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
303 virtual void onDocumentURISet (gchar const* uri);
304 virtual void onDocumentResized (double, double);
306 static void _onActivate (SPDesktop* dt);
307 static void _onDeactivate (SPDesktop* dt);
308 static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
309 };
311 #endif
313 /*
314 Local Variables:
315 mode:c++
316 c-file-style:"stroustrup"
317 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
318 indent-tabs-mode:nil
319 fill-column:99
320 End:
321 */
322 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :