Code

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