Code

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