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 <2geom/matrix.h>
33 #include <2geom/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 SPCSSAttr;
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 class SPDesktop : public Inkscape::UI::View::View
88 {
89 public:
90 Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
91 SPNamedView *namedview;
92 SPCanvas *canvas;
93 /// current selection; will never generally be NULL
94 Inkscape::Selection *selection;
95 SPEventContext *event_context;
96 Inkscape::LayerManager *layer_manager;
97 Inkscape::EventLog *event_log;
99 Inkscape::Display::TemporaryItemList *temporary_item_list;
100 Inkscape::Display::SnapIndicator *snapindicator;
102 SPCanvasItem *acetate;
103 SPCanvasGroup *main;
104 SPCanvasGroup *gridgroup;
105 SPCanvasGroup *guides;
106 SPCanvasItem *drawing;
107 SPCanvasGroup *sketch;
108 SPCanvasGroup *controls;
109 SPCanvasGroup *tempgroup; ///< contains temporary canvas items
110 SPCanvasItem *table; ///< outside-of-page background
111 SPCanvasItem *page; ///< page background
112 SPCanvasItem *page_border; ///< page border
113 SPCSSAttr *current; ///< current style
114 bool _focusMode; ///< Whether we're focused working or general working
116 GList *zooms_past;
117 GList *zooms_future;
118 bool _quick_zoom_enabled; ///< Signifies that currently we're in quick zoom mode
119 Geom::Rect _quick_zoom_stored_area; ///< The area of the screen before quick zoom
120 unsigned int dkey;
121 unsigned int number;
122 guint window_state;
123 unsigned int interaction_disabled_counter;
124 bool waiting_cursor;
126 /// \todo fixme: This has to be implemented in different way */
127 guint guides_active : 1;
129 // storage for selected dragger used by GrDrag as it's
130 // created and deleted by tools
131 SPItem *gr_item;
132 guint gr_point_type;
133 guint gr_point_i;
134 bool gr_fill_or_stroke;
137 Inkscape::ObjectHierarchy *_layer_hierarchy;
138 gchar * _reconstruction_old_layer_id;
140 sigc::signal<void, sp_verb_t> _tool_changed;
141 sigc::signal<void, SPObject *> _layer_changed_signal;
142 sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
143 sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
145 /// Emitted when the zoom factor changes (not emitted when scrolling).
146 /// The parameter is the new zoom factor
147 sigc::signal<void, double> signal_zoom_changed;
149 sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
150 {
151 return _document_replaced_signal.connect (slot);
152 }
154 sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
155 {
156 return _event_context_changed_signal.connect (slot);
157 }
158 sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
159 {
160 return _set_style_signal.connect (slot);
161 }
162 sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
163 {
164 return _query_style_signal.connect (slot);
165 }
166 // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
167 sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
168 return _tool_subselection_changed.connect(slot);
169 }
170 void emitToolSubselectionChanged(gpointer data);
171 sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
172 return _layer_changed_signal.connect(slot);
173 }
175 // Whiteboard changes
177 #ifdef WITH_INKBOARD
178 Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
179 return _whiteboard_session_manager;
180 }
182 Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
183 #endif
185 SPDesktop();
186 void init (SPNamedView* nv, SPCanvas* canvas, Inkscape::UI::View::EditWidgetInterface *widget);
187 virtual ~SPDesktop();
188 void destroy();
190 Inkscape::MessageContext *guidesMessageContext() const {
191 return _guides_message_context;
192 }
194 Inkscape::Display::TemporaryItem * add_temporary_canvasitem (SPCanvasItem *item, guint lifetime, bool move_to_bottom = true);
195 void remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem);
197 void _setDisplayMode(Inkscape::RenderMode mode);
198 void setDisplayModeNormal() {
199 _setDisplayMode(Inkscape::RENDERMODE_NORMAL);
200 }
201 void setDisplayModeNoFilters() {
202 _setDisplayMode(Inkscape::RENDERMODE_NO_FILTERS);
203 }
204 void setDisplayModeOutline() {
205 _setDisplayMode(Inkscape::RENDERMODE_OUTLINE);
206 }
207 void setDisplayModePrintColorsPreview() {
208 _setDisplayMode(Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW);
209 }
210 void displayModeToggle();
211 Inkscape::RenderMode _display_mode;
212 Inkscape::RenderMode getMode() const { return _display_mode; }
214 Inkscape::UI::Widget::Dock* getDock() { return _widget->getDock(); }
216 void set_active (bool new_active);
217 SPObject *currentRoot() const;
218 SPObject *currentLayer() const;
219 void setCurrentLayer(SPObject *object);
220 void toggleLayerSolo(SPObject *object);
221 SPObject *layerForObject(SPObject *object);
222 bool isLayer(SPObject *object) const;
223 bool isWithinViewport(SPItem *item) const;
224 bool itemIsHidden(SPItem const *item) const;
226 void activate_guides (bool activate);
227 void change_document (SPDocument *document);
229 void set_event_context (GtkType type, const gchar *config);
230 void push_event_context (GtkType type, const gchar *config, unsigned int key);
232 void set_coordinate_status (Geom::Point p);
233 SPItem *item_from_list_at_point_bottom (const GSList *list, Geom::Point const p) const;
234 SPItem *item_at_point (Geom::Point const p, bool into_groups, SPItem *upto = NULL) const;
235 SPItem *group_at_point (Geom::Point const p) const;
236 Geom::Point point() const;
238 Geom::Rect get_display_area() const;
239 void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
240 void set_display_area(Geom::Rect const &a, Geom::Coord border, bool log = true);
241 void zoom_absolute (double cx, double cy, double zoom);
242 void zoom_relative (double cx, double cy, double zoom);
243 void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
244 void zoom_relative_keep_point (double cx, double cy, double zoom);
245 void zoom_relative_keep_point (Geom::Point const &c, double const zoom)
246 {
247 zoom_relative_keep_point (c[Geom::X], c[Geom::Y], zoom);
248 }
250 void zoom_page();
251 void zoom_page_width();
252 void zoom_drawing();
253 void zoom_selection();
254 void zoom_grab_focus();
255 double current_zoom() const { return _d2w.descrim(); }
256 void prev_zoom();
257 void next_zoom();
258 void zoom_quick(bool enable = true);
259 /** \brief Returns whether the desktop is in quick zoom mode or not */
260 bool quick_zoomed(void) { return _quick_zoom_enabled; }
262 bool scroll_to_point (Geom::Point const &s_dt, gdouble autoscrollspeed = 0);
263 void scroll_world (double dx, double dy, bool is_scrolling = false);
264 void scroll_world (Geom::Point const scroll, bool is_scrolling = false)
265 {
266 scroll_world(scroll[Geom::X], scroll[Geom::Y], is_scrolling);
267 }
268 void scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling = false);
270 void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
271 void setWindowPosition (Geom::Point p);
272 void setWindowSize (gint w, gint h);
273 void setWindowTransient (void* p, int transient_policy=1);
274 Gtk::Window* getToplevel();
275 void presentWindow();
276 bool warnDialog (gchar *text);
277 void toggleRulers();
278 void toggleScrollbars();
279 void layoutWidget();
280 void destroyWidget();
281 void setToolboxFocusTo (gchar const* label);
282 void setToolboxAdjustmentValue (gchar const* id, double val);
283 void setToolboxSelectOneValue (gchar const* id, gint val);
284 bool isToolboxButtonActive (gchar const *id);
285 void updateNow();
286 void updateCanvasNow();
288 void enableInteraction();
289 void disableInteraction();
291 void setWaitingCursor();
292 void clearWaitingCursor();
293 bool isWaitingCursor() const { return waiting_cursor; };
295 void toggleColorProfAdjust();
297 void toggleGrids();
298 void toggleSnapGlobal();
299 bool gridsEnabled() const { return grids_visible; };
300 void showGrids(bool show, bool dirty_document = true);
302 bool is_iconified();
303 bool is_maximized();
304 bool is_fullscreen();
305 bool is_focusMode();
307 void iconify();
308 void maximize();
309 void fullscreen();
310 void focusMode(bool mode = true);
312 Geom::Matrix w2d() const; //transformation from window to desktop coordinates (used for zooming)
313 Geom::Point w2d(Geom::Point const &p) const;
314 Geom::Point d2w(Geom::Point const &p) const;
315 Geom::Matrix doc2dt() const;
316 Geom::Matrix dt2doc() const;
317 Geom::Point doc2dt(Geom::Point const &p) const;
318 Geom::Point dt2doc(Geom::Point const &p) const;
320 virtual void setDocument (SPDocument* doc);
321 virtual bool shutdown();
322 virtual void mouseover() {}
323 virtual void mouseout() {}
325 virtual bool onDeleteUI (GdkEventAny*);
326 virtual bool onWindowStateEvent (GdkEventWindowState* event);
328 void applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text);
330 private:
331 Inkscape::UI::View::EditWidgetInterface *_widget;
332 Inkscape::Application *_inkscape;
333 Inkscape::MessageContext *_guides_message_context;
334 bool _active;
335 Geom::Matrix _w2d;
336 Geom::Matrix _d2w;
337 Geom::Matrix _doc2dt;
339 bool grids_visible; /* don't set this variable directly, use the method below */
340 void set_grids_visible(bool visible);
342 void push_current_zoom (GList**);
344 sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal;
345 sigc::signal<void> _activate_signal;
346 sigc::signal<void> _deactivate_signal;
347 sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
348 sigc::signal<void, gpointer> _tool_subselection_changed;
350 sigc::connection _activate_connection;
351 sigc::connection _deactivate_connection;
352 sigc::connection _sel_modified_connection;
353 sigc::connection _sel_changed_connection;
354 sigc::connection _reconstruction_start_connection;
355 sigc::connection _reconstruction_finish_connection;
356 sigc::connection _commit_connection;
357 sigc::connection _modified_connection;
359 virtual void onPositionSet (double, double);
360 virtual void onResized (double, double);
361 virtual void onRedrawRequested();
362 virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
363 virtual void onDocumentURISet (gchar const* uri);
364 virtual void onDocumentResized (double, double);
366 static void _onActivate (SPDesktop* dt);
367 static void _onDeactivate (SPDesktop* dt);
368 static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
369 };
371 #endif // SEEN_SP_DESKTOP_H
373 /*
374 Local Variables:
375 mode:c++
376 c-file-style:"stroustrup"
377 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
378 indent-tabs-mode:nil
379 fill-column:99
380 End:
381 */
382 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :