Code

Merge and cleanup of GSoC C++-ification project.
[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  *   Jon A. Cruz <jon@joncruz.org>get
15  *   Abhishek Sharma
16  *
17  * Copyright (C) 2007 Johan Engelen
18  * Copyright (C) 2006 John Bintz
19  * Copyright (C) 1999-2005 authors
20  * Copyright (C) 2000-2001 Ximian, Inc.
21  *
22  * Released under GNU GPL, read the file 'COPYING' for more information
23  *
24  */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
30 #include <gdk/gdkevents.h>
31 #include <gtk/gtktypeutils.h>
32 #include <sigc++/sigc++.h>
34 #include <2geom/matrix.h>
35 #include <2geom/rect.h>
37 #include "ui/view/view.h"
38 #include "ui/view/edit-widget-interface.h"
40 #include "display/rendermode.h"
41 #include "display/snap-indicator.h"
43 class SPCSSAttr;
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 class SPDesktop : public Inkscape::UI::View::View
90 {
91 public:
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
116     bool           _focusMode;  ///< Whether we're focused working or general working
118     GList *zooms_past;
119     GList *zooms_future;
120     bool _quick_zoom_enabled; ///< Signifies that currently we're in quick zoom mode
121     Geom::Rect _quick_zoom_stored_area;  ///< The area of the screen before quick zoom
122     unsigned int dkey;
123     unsigned int number;
124     guint window_state;
125     unsigned int interaction_disabled_counter;
126     bool waiting_cursor;
128     /// \todo fixme: This has to be implemented in different way */
129     guint guides_active : 1;
131     // storage for selected dragger used by GrDrag as it's
132     // created and deleted by tools
133     SPItem *gr_item;
134     guint  gr_point_type;
135     guint  gr_point_i;
136     bool   gr_fill_or_stroke;
139     Inkscape::ObjectHierarchy *_layer_hierarchy;
140     gchar * _reconstruction_old_layer_id;
142     sigc::signal<void, sp_verb_t>      _tool_changed;
143     sigc::signal<void, SPObject *>     _layer_changed_signal;
144     sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
145     sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
146     
147     /// Emitted when the zoom factor changes (not emitted when scrolling).
148     /// The parameter is the new zoom factor
149     sigc::signal<void, double> signal_zoom_changed;
150     
151     sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
152     {
153         return _document_replaced_signal.connect (slot);
154     }
156     sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot)
157     {
158         return _event_context_changed_signal.connect (slot);
159     }
160     sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot)
161     {
162         return _set_style_signal.connect (slot);
163     }
164     sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot)
165     {
166         return _query_style_signal.connect (slot);
167     }
168      // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
169     sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
170         return _tool_subselection_changed.connect(slot);
171     }
172     void emitToolSubselectionChanged(gpointer data);
173     sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
174         return _layer_changed_signal.connect(slot);
175     }
177     // Whiteboard changes
179 #ifdef WITH_INKBOARD
180     Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
181         return _whiteboard_session_manager;
182     }
184     Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
185 #endif
187     SPDesktop();
188     void init (SPNamedView* nv, SPCanvas* canvas, Inkscape::UI::View::EditWidgetInterface *widget);
189     virtual ~SPDesktop();
190     void destroy();
192     Inkscape::MessageContext *guidesMessageContext() const {
193         return _guides_message_context;
194     }
196     Inkscape::Display::TemporaryItem * add_temporary_canvasitem (SPCanvasItem *item, guint lifetime, bool move_to_bottom = true);
197     void remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem);
199     void _setDisplayMode(Inkscape::RenderMode mode);
200     void setDisplayModeNormal() {
201         _setDisplayMode(Inkscape::RENDERMODE_NORMAL);
202     }
203     void setDisplayModeNoFilters() {
204         _setDisplayMode(Inkscape::RENDERMODE_NO_FILTERS);
205     }
206     void setDisplayModeOutline() {
207         _setDisplayMode(Inkscape::RENDERMODE_OUTLINE);
208     }
209 //    void setDisplayModePrintColorsPreview() {
210 //        _setDisplayMode(Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW);
211 //    }
212     void displayModeToggle();
213     Inkscape::RenderMode _display_mode;
214     Inkscape::RenderMode getMode() const { return _display_mode; }
216     Inkscape::UI::Widget::Dock* getDock() { return _widget->getDock(); }
218     void set_active (bool new_active);
219     SPObject *currentRoot() const;
220     SPObject *currentLayer() const;
221     void setCurrentLayer(SPObject *object);
222     void toggleLayerSolo(SPObject *object);
223     SPObject *layerForObject(SPObject *object);
224     bool isLayer(SPObject *object) const;
225     bool isWithinViewport(SPItem *item) const;
226     bool itemIsHidden(SPItem const *item) const;
228     void activate_guides (bool activate);
229     void change_document (SPDocument *document);
231     void set_event_context (GtkType type, const gchar *config);
232     void push_event_context (GtkType type, const gchar *config, unsigned int key);
234     void set_coordinate_status (Geom::Point p);
235     SPItem *getItemFromListAtPointBottom(const GSList *list, Geom::Point const p) const;
236     SPItem *getItemAtPoint(Geom::Point const p, bool into_groups, SPItem *upto = NULL) const;
237     SPItem *getGroupAtPoint(Geom::Point const p) const;
238     Geom::Point point() const;
240     Geom::Rect get_display_area() const;
241     void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
242     void set_display_area(Geom::Rect const &a, Geom::Coord border, bool log = true);
243     void zoom_absolute (double cx, double cy, double zoom);
244     void zoom_relative (double cx, double cy, double zoom);
245     void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
246     void zoom_relative_keep_point (double cx, double cy, double zoom);
247     void zoom_relative_keep_point (Geom::Point const &c, double const zoom)
248     {
249             zoom_relative_keep_point (c[Geom::X], c[Geom::Y], zoom);
250     }
252     void zoom_page();
253     void zoom_page_width();
254     void zoom_drawing();
255     void zoom_selection();
256     void zoom_grab_focus();
257     double current_zoom() const  { return _d2w.descrim(); }
258     void prev_zoom();
259     void next_zoom();
260     void zoom_quick(bool enable = true);
262     /** \brief  Returns whether the desktop is in quick zoom mode or not */
263     bool quick_zoomed(void) { return _quick_zoom_enabled; }
265     bool scroll_to_point (Geom::Point const &s_dt, gdouble autoscrollspeed = 0);
266     void scroll_world (double dx, double dy, bool is_scrolling = false);
267     void scroll_world (Geom::Point const scroll, bool is_scrolling = false)
268     {
269         scroll_world(scroll[Geom::X], scroll[Geom::Y], is_scrolling);
270     }
271     void scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling = false);
273     void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
274     void setWindowPosition (Geom::Point p);
275     void setWindowSize (gint w, gint h);
276     void setWindowTransient (void* p, int transient_policy=1);
277     Gtk::Window* getToplevel();
278     void presentWindow();
279     bool warnDialog (gchar *text);
280     void toggleRulers();
281     void toggleScrollbars();
282     void layoutWidget();
283     void destroyWidget();
284     void setToolboxFocusTo (gchar const* label);
285     void setToolboxAdjustmentValue (gchar const* id, double val);
286     void setToolboxSelectOneValue (gchar const* id, gint val);
287     bool isToolboxButtonActive (gchar const *id);
288     void updateNow();
289     void updateCanvasNow();
291     void enableInteraction();
292     void disableInteraction();
294     void setWaitingCursor();
295     void clearWaitingCursor();
296     bool isWaitingCursor() const { return waiting_cursor; };
298     void toggleColorProfAdjust();
300     void toggleGrids();
301     void toggleSnapGlobal();
302     bool gridsEnabled() const { return grids_visible; };
303     void showGrids(bool show, bool dirty_document = true);
305     bool is_iconified();
306     bool is_maximized();
307     bool is_fullscreen();
308     bool is_focusMode();
310     void iconify();
311     void maximize();
312     void fullscreen();
313     void focusMode(bool mode = true);
315     Geom::Matrix w2d() const; //transformation from window to desktop coordinates (used for zooming)
316     Geom::Point w2d(Geom::Point const &p) const;
317     Geom::Point d2w(Geom::Point const &p) const;
318     Geom::Matrix doc2dt() const;
319     Geom::Matrix dt2doc() const;
320     Geom::Point doc2dt(Geom::Point const &p) const;
321     Geom::Point dt2doc(Geom::Point const &p) const;
323     virtual void setDocument (SPDocument* doc);
324     virtual bool shutdown();
325     virtual void mouseover() {}
326     virtual void mouseout() {}
328     virtual bool onDeleteUI (GdkEventAny*);
329     virtual bool onWindowStateEvent (GdkEventWindowState* event);
331     void applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text);
333 private:
334     Inkscape::UI::View::EditWidgetInterface       *_widget;
335     Inkscape::Application     *_inkscape;
336     Inkscape::MessageContext  *_guides_message_context;
337     bool _active;
338     Geom::Matrix _w2d;
339     Geom::Matrix _d2w;
340     Geom::Matrix _doc2dt;
342     bool grids_visible; /* don't set this variable directly, use the method below */
343     void set_grids_visible(bool visible);
345     void push_current_zoom (GList**);
347     sigc::signal<void,SPDesktop*,SPDocument*>     _document_replaced_signal;
348     sigc::signal<void>                 _activate_signal;
349     sigc::signal<void>                 _deactivate_signal;
350     sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
351     sigc::signal<void, gpointer>       _tool_subselection_changed;
353     sigc::connection _activate_connection;
354     sigc::connection _deactivate_connection;
355     sigc::connection _sel_modified_connection;
356     sigc::connection _sel_changed_connection;
357     sigc::connection _reconstruction_start_connection;
358     sigc::connection _reconstruction_finish_connection;
359     sigc::connection _commit_connection;
360     sigc::connection _modified_connection;
362     virtual void onPositionSet (double, double);
363     virtual void onResized (double, double);
364     virtual void onRedrawRequested();
365     virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
366     virtual void onDocumentURISet (gchar const* uri);
367     virtual void onDocumentResized (double, double);
369     static void _onActivate (SPDesktop* dt);
370     static void _onDeactivate (SPDesktop* dt);
371     static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
372 };
374 #endif // SEEN_SP_DESKTOP_H
376 /*
377   Local Variables:
378   mode:c++
379   c-file-style:"stroustrup"
380   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
381   indent-tabs-mode:nil
382   fill-column:99
383   End:
384 */
385 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :