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