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