1 #ifndef SEEN_SP_DESKTOP_H
2 #define SEEN_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 <gdk/gdkevents.h>
29 #include <gtk/gtktypeutils.h>
30 #include <sigc++/sigc++.h>
32 #include "libnr/nr-matrix.h"
33 #include "libnr/nr-matrix-fns.h"
34 #include "libnr/nr-rect.h"
35 #include "ui/view/view.h"
36 #include "ui/view/edit-widget-interface.h"
38 #include "display/rendermode.h"
39 #include "display/snap-indicator.h"
41 class NRRect;
42 class SPCSSAttr;
43 struct _GtkWidget;
44 typedef struct _GtkWidget GtkWidget;
45 struct SPCanvas;
46 struct SPCanvasItem;
47 struct SPCanvasGroup;
48 struct SPEventContext;
49 struct SPItem;
50 struct SPNamedView;
51 struct SPObject;
52 struct SPStyle;
54 namespace Gtk
55 {
56 class Window;
57 }
59 typedef int sp_verb_t;
63 namespace Inkscape {
64 class Application;
65 class MessageContext;
66 class Selection;
67 class ObjectHierarchy;
68 class LayerManager;
69 class EventLog;
70 namespace UI {
71 namespace Dialog {
72 class DialogManager;
73 }
74 }
75 namespace Whiteboard {
76 class SessionManager;
77 }
78 namespace Display {
79 class TemporaryItemList;
80 class TemporaryItem;
81 //class SnapIndicator;
82 }
83 }
85 /**
86 * Editable view.
87 *
88 * @see \ref desktop-handles.h for desktop macros.
89 */
90 struct SPDesktop : public Inkscape::UI::View::View
91 {
92 Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
93 SPNamedView *namedview;
94 SPCanvas *canvas;
95 /// current selection; will never generally be NULL
96 Inkscape::Selection *selection;
97 SPEventContext *event_context;
98 Inkscape::LayerManager *layer_manager;
99 Inkscape::EventLog *event_log;
101 Inkscape::Display::TemporaryItemList *temporary_item_list;
102 Inkscape::Display::SnapIndicator *snapindicator;
104 SPCanvasItem *acetate;
105 SPCanvasGroup *main;
106 SPCanvasGroup *gridgroup;
107 SPCanvasGroup *guides;
108 SPCanvasItem *drawing;
109 SPCanvasGroup *sketch;
110 SPCanvasGroup *controls;
111 SPCanvasGroup *tempgroup; ///< contains temporary canvas items
112 SPCanvasItem *table; ///< outside-of-page background
113 SPCanvasItem *page; ///< page background
114 SPCanvasItem *page_border; ///< page border
115 SPCSSAttr *current; ///< current style
117 GList *zooms_past;
118 GList *zooms_future;
119 unsigned int dkey;
120 unsigned int number;
121 guint window_state;
122 unsigned int interaction_disabled_counter;
123 bool waiting_cursor;
125 /// \todo fixme: This has to be implemented in different way */
126 guint guides_active : 1;
128 // storage for selected dragger used by GrDrag as it's
129 // created and deleted by tools
130 SPItem *gr_item;
131 guint gr_point_type;
132 guint gr_point_i;
133 bool gr_fill_or_stroke;
136 Inkscape::ObjectHierarchy *_layer_hierarchy;
137 gchar * _reconstruction_old_layer_id;
139 sigc::signal<void, sp_verb_t> _tool_changed;
140 sigc::signal<void, SPObject *> _layer_changed_signal;
141 sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
142 sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
143 sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
144 {
145 return _document_replaced_signal.connect (slot);
146 }
148 sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
149 {
150 return _event_context_changed_signal.connect (slot);
151 }
152 sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
153 {
154 return _set_style_signal.connect (slot);
155 }
156 sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
157 {
158 return _query_style_signal.connect (slot);
159 }
160 // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
161 sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
162 return _tool_subselection_changed.connect(slot);
163 }
164 void emitToolSubselectionChanged(gpointer data);
165 sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
166 return _layer_changed_signal.connect(slot);
167 }
169 // Whiteboard changes
171 #ifdef WITH_INKBOARD
172 Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
173 return _whiteboard_session_manager;
174 }
176 Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
177 #endif
179 SPDesktop();
180 void init (SPNamedView* nv, SPCanvas* canvas);
181 virtual ~SPDesktop();
182 void destroy();
184 Inkscape::MessageContext *guidesMessageContext() const {
185 return _guides_message_context;
186 }
188 Inkscape::Display::TemporaryItem * add_temporary_canvasitem (SPCanvasItem *item, guint lifetime, bool move_to_bottom = true);
189 void remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem);
191 void _setDisplayMode(Inkscape::RenderMode mode);
192 void setDisplayModeNormal() {
193 _setDisplayMode(Inkscape::RENDERMODE_NORMAL);
194 }
195 void setDisplayModeNoFilters() {
196 _setDisplayMode(Inkscape::RENDERMODE_NO_FILTERS);
197 }
198 void setDisplayModeOutline() {
199 _setDisplayMode(Inkscape::RENDERMODE_OUTLINE);
200 }
201 void displayModeToggle();
202 Inkscape::RenderMode _display_mode;
203 Inkscape::RenderMode _saved_display_mode;
204 Inkscape::RenderMode getMode() const { return _display_mode; }
206 Inkscape::UI::Widget::Dock* getDock() { return _widget->getDock(); }
208 void set_active (bool new_active);
209 SPObject *currentRoot() const;
210 SPObject *currentLayer() const;
211 void setCurrentLayer(SPObject *object);
212 void toggleLayerSolo(SPObject *object);
213 SPObject *layerForObject(SPObject *object);
214 bool isLayer(SPObject *object) const;
215 bool isWithinViewport(SPItem *item) const;
216 bool itemIsHidden(SPItem const *item) const;
218 void activate_guides (bool activate);
219 void change_document (SPDocument *document);
221 void set_event_context (GtkType type, const gchar *config);
222 void push_event_context (GtkType type, const gchar *config, unsigned int key);
224 void set_coordinate_status (NR::Point p);
225 SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
226 SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
227 SPItem *group_at_point (NR::Point const p) const;
228 NR::Point point() const;
230 NR::Rect get_display_area() const;
231 void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
232 void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
233 void zoom_absolute (double cx, double cy, double zoom);
234 void zoom_relative (double cx, double cy, double zoom);
235 void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
236 void zoom_relative_keep_point (double cx, double cy, double zoom);
237 void zoom_relative_keep_point (NR::Point const &c, double const zoom)
238 {
239 using NR::X;
240 using NR::Y;
241 zoom_relative_keep_point (c[X], c[Y], zoom);
242 }
244 void zoom_page();
245 void zoom_page_width();
246 void zoom_drawing();
247 void zoom_selection();
248 void zoom_grab_focus();
249 double current_zoom() const { return NR::expansion(_d2w); }
250 void prev_zoom();
251 void next_zoom();
253 bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
254 void scroll_world (double dx, double dy, bool is_scrolling = false);
255 void scroll_world (NR::Point const scroll, bool is_scrolling = false)
256 {
257 using NR::X;
258 using NR::Y;
259 scroll_world(scroll[X], scroll[Y], is_scrolling);
260 }
261 void scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling = false);
263 void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
264 void setWindowPosition (NR::Point p);
265 void setWindowSize (gint w, gint h);
266 void setWindowTransient (void* p, int transient_policy=1);
267 Gtk::Window* getToplevel();
268 void presentWindow();
269 bool warnDialog (gchar *text);
270 void toggleRulers();
271 void toggleScrollbars();
272 void layoutWidget();
273 void destroyWidget();
274 void setToolboxFocusTo (gchar const* label);
275 void setToolboxAdjustmentValue (gchar const* id, double val);
276 void setToolboxSelectOneValue (gchar const* id, gint val);
277 bool isToolboxButtonActive (gchar const *id);
278 void updateNow();
279 void updateCanvasNow();
281 void enableInteraction();
282 void disableInteraction();
284 void setWaitingCursor();
285 void clearWaitingCursor();
287 void toggleColorProfAdjust();
289 void toggleGrids();
290 void toggleSnapping();
291 bool gridsEnabled() { return grids_visible; }
292 void showGrids(bool show, bool dirty_document = true);
294 bool is_iconified();
295 bool is_maximized();
296 bool is_fullscreen();
298 void iconify();
299 void maximize();
300 void fullscreen();
302 void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
303 { _widget = widget; }
305 NR::Matrix w2d() const; //transformation from window to desktop coordinates (used for zooming)
306 NR::Point w2d(NR::Point const &p) const;
307 NR::Point d2w(NR::Point const &p) const;
308 NR::Matrix doc2dt() const;
309 NR::Point doc2dt(NR::Point const &p) const;
310 NR::Point dt2doc(NR::Point const &p) const;
312 virtual void setDocument (SPDocument* doc);
313 virtual bool shutdown();
314 virtual void mouseover() {}
315 virtual void mouseout() {}
317 virtual bool onDeleteUI (GdkEventAny*);
318 virtual bool onWindowStateEvent (GdkEventWindowState* event);
320 private:
321 Inkscape::UI::View::EditWidgetInterface *_widget;
322 Inkscape::Application *_inkscape;
323 Inkscape::MessageContext *_guides_message_context;
324 bool _active;
325 NR::Matrix _w2d;
326 NR::Matrix _d2w;
327 NR::Matrix _doc2dt;
329 bool grids_visible; /* don't set this variable directly, use the method below */
330 void set_grids_visible(bool visible);
332 void push_current_zoom (GList**);
334 sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal;
335 sigc::signal<void> _activate_signal;
336 sigc::signal<void> _deactivate_signal;
337 sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
338 sigc::signal<void, gpointer> _tool_subselection_changed;
340 sigc::connection _activate_connection;
341 sigc::connection _deactivate_connection;
342 sigc::connection _sel_modified_connection;
343 sigc::connection _sel_changed_connection;
344 sigc::connection _reconstruction_start_connection;
345 sigc::connection _reconstruction_finish_connection;
346 sigc::connection _commit_connection;
347 sigc::connection _modified_connection;
349 virtual void onPositionSet (double, double);
350 virtual void onResized (double, double);
351 virtual void onRedrawRequested();
352 virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
353 virtual void onDocumentURISet (gchar const* uri);
354 virtual void onDocumentResized (double, double);
356 static void _onActivate (SPDesktop* dt);
357 static void _onDeactivate (SPDesktop* dt);
358 static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
359 };
361 #endif // SEEN_SP_DESKTOP_H
363 /*
364 Local Variables:
365 mode:c++
366 c-file-style:"stroustrup"
367 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
368 indent-tabs-mode:nil
369 fill-column:99
370 End:
371 */
372 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :