Code

42e059db20a0e3bd1305f401d7aacc6d82de7c46
[inkscape.git] / src / desktop.h
1 #ifndef __SP_DESKTOP_H__
2 #define __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 <gtk/gtktypeutils.h>
29 #include <sigc++/sigc++.h>
30 #include "libnr/nr-matrix.h"
31 #include "libnr/nr-matrix-fns.h"
32 #include "libnr/nr-rect.h"
33 #include "ui/view/view.h"
34 #include "ui/view/edit-widget-interface.h"
36 class NRRect;
37 class SPCSSAttr;
38 struct SPCanvas;
39 struct SPCanvasItem;
40 struct SPCanvasGroup;
41 struct SPDesktopWidget;
42 struct SPEventContext;
43 struct SPItem;
44 struct SPNamedView;
45 struct SPObject;
46 struct SPStyle;
47 struct SPViewWidget;
49 typedef int sp_verb_t;
51 namespace Inkscape { 
52   class Application;
53   class MessageContext;
54   class Selection; 
55   class ObjectHierarchy;
56   class LayerManager;
57   class EventLog;
58   namespace UI { 
59       namespace Dialog { 
60           class DialogManager; 
61       }
62   }
63   namespace Whiteboard {
64       class SessionManager;
65   }
66 }
68 /**
69  * Editable view.
70  *
71  * @see \ref desktop-handles.h for desktop macros.
72  */
73 struct SPDesktop : public Inkscape::UI::View::View
74 {
75     Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
76     SPNamedView               *namedview;
77     SPCanvas                  *canvas;
78     /// current selection; will never generally be NULL
79     Inkscape::Selection       *selection;
80     SPEventContext            *event_context;
81     Inkscape::LayerManager    *layer_manager;
82     Inkscape::EventLog        *event_log;
84     SPCanvasItem  *acetate;
85     SPCanvasGroup *main;
86     SPCanvasGroup *grid;
87     SPCanvasGroup *guides;
88     SPCanvasItem  *drawing;
89     SPCanvasGroup *sketch;
90     SPCanvasGroup *controls;
91     SPCanvasItem  *table;       ///< outside-of-page background
92     SPCanvasItem  *page;        ///< page background
93     SPCanvasItem  *page_border; ///< page border
94     SPCSSAttr     *current;     ///< current style
96     GList *zooms_past;
97     GList *zooms_future;
98     unsigned int dkey;
99     unsigned int number;
100     bool is_fullscreen;
101     unsigned int interaction_disabled_counter;
103     /// \todo fixme: This has to be implemented in different way */
104     guint guides_active : 1;
106     // storage for selected dragger used by GrDrag as it's 
107     // created and deleted by tools
108     SPItem *gr_item;
109     guint  gr_point_type;
110     guint  gr_point_i;
111     bool   gr_fill_or_stroke;   
112     
114     Inkscape::ObjectHierarchy *_layer_hierarchy;
115     gchar * _reconstruction_old_layer_id;
117     sigc::signal<void, sp_verb_t>      _tool_changed;
118     sigc::signal<void, SPObject *>     _layer_changed_signal;
119     sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
120     sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
121     sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
122     {
123         return _document_replaced_signal.connect (slot);
124     }
125     
126     sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot) 
127     {
128         return _event_context_changed_signal.connect (slot);
129     }
130     sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot) 
131     {
132         return _set_style_signal.connect (slot);
133     }
134     sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot) 
135     {
136         return _query_style_signal.connect (slot);
137     }
138      // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
139     sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
140         return _tool_subselection_changed.connect(slot);
141     }
142     void emitToolSubselectionChanged(gpointer data); 
143     sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
144         return _layer_changed_signal.connect(slot);
145     }
146     
147         // Whiteboard changes
149 #ifdef WITH_INKBOARD
150         Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
151         return _whiteboard_session_manager;
152         }
154         Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
155 #endif
156    
157     SPDesktop();
158     void init (SPNamedView* nv, SPCanvas* canvas);
159     ~SPDesktop();
160     void destroy();
162     Inkscape::MessageContext *guidesMessageContext() const {
163         return _guides_message_context;
164     }
166     void setDisplayModeNormal();
167     void setDisplayModeOutline();
168     void displayModeToggle();
169     int displayMode;
170     int getMode() const { return displayMode; }
172     void set_active (bool new_active);
173     SPObject *currentRoot() const;
174     SPObject *currentLayer() const;
175     void setCurrentLayer(SPObject *object);
176     SPObject *layerForObject(SPObject *object);
177     bool isLayer(SPObject *object) const;
178     bool isWithinViewport(SPItem *item) const;
179     bool itemIsHidden(SPItem const *item) const;
180     
181     void activate_guides (bool activate);
182     void change_document (SPDocument *document);
184     void set_event_context (GtkType type, const gchar *config);
185     void push_event_context (GtkType type, const gchar *config, unsigned int key);
187     void set_coordinate_status (NR::Point p);
188     SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
189     SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
190     SPItem *group_at_point (NR::Point const p) const;
191     NR::Point point() const;
193     NR::Rect get_display_area() const;
194     void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
195     void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
196     void zoom_absolute (double cx, double cy, double zoom);
197     void zoom_relative (double cx, double cy, double zoom);
198     void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
199     void zoom_relative_keep_point (double cx, double cy, double zoom);
200     void zoom_relative_keep_point (NR::Point const &c, double const zoom)
201     {
202             using NR::X;
203             using NR::Y;
204             zoom_relative_keep_point (c[X], c[Y], zoom);
205     }
207     void zoom_page();
208     void zoom_page_width();
209     void zoom_drawing();
210     void zoom_selection();
211     void zoom_grab_focus();
212     double current_zoom() const  { return _d2w.expansion(); }
213     void prev_zoom();
214     void next_zoom();
216     bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
217     void scroll_world (double dx, double dy);
218     void scroll_world (NR::Point const scroll)
219     {
220         using NR::X;
221         using NR::Y;
222         scroll_world(scroll[X], scroll[Y]);
223     }
225     void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
226     void setWindowPosition (NR::Point p);
227     void setWindowSize (gint w, gint h);
228     void setWindowTransient (void* p, int transient_policy=1);
229     void presentWindow();
230     bool warnDialog (gchar *text);
231     void toggleRulers();
232     void toggleScrollbars();
233     void layoutWidget();
234     void destroyWidget();
235     void setToolboxFocusTo (gchar const* label);
236     void setToolboxAdjustmentValue (gchar const* id, double val);
237     bool isToolboxButtonActive (gchar const *id);
238     void updateNow();
239     void updateCanvasNow();
240     
241     void enableInteraction();
242     void disableInteraction();
243     
244     void fullscreen();
246     void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
247     { _widget = widget; }
249     NR::Matrix w2d() const;
250     NR::Point w2d(NR::Point const &p) const;
251     NR::Point d2w(NR::Point const &p) const;
252     NR::Matrix doc2dt() const;
253     NR::Point doc2dt(NR::Point const &p) const;
254     NR::Point dt2doc(NR::Point const &p) const;
256     virtual void setDocument (SPDocument* doc);
257     virtual bool shutdown();
258     virtual void mouseover() {}
259     virtual void mouseout() {}
261 private:
262     Inkscape::UI::View::EditWidgetInterface       *_widget;
263     Inkscape::Application     *_inkscape;
264     Inkscape::MessageContext  *_guides_message_context;
265     bool _active;
266     NR::Matrix _w2d;
267     NR::Matrix _d2w;
268     NR::Matrix _doc2dt;
269     
270     void push_current_zoom (GList**);
272     sigc::signal<void,SPDesktop*,SPDocument*>     _document_replaced_signal;
273     sigc::signal<void>                 _activate_signal;
274     sigc::signal<void>                 _deactivate_signal;
275     sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
276     sigc::signal<void, gpointer>       _tool_subselection_changed;
277   
278     sigc::connection _activate_connection;
279     sigc::connection _deactivate_connection;
280     sigc::connection _sel_modified_connection;
281     sigc::connection _sel_changed_connection;
282     sigc::connection _reconstruction_start_connection;
283     sigc::connection _reconstruction_finish_connection;
284     sigc::connection _commit_connection;
285     sigc::connection _modified_connection;
286     
287     virtual void onPositionSet (double, double);
288     virtual void onResized (double, double);
289     virtual void onRedrawRequested();
290     virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
291     virtual void onDocumentURISet (gchar const* uri);
292     virtual void onDocumentResized (double, double);
294     static void _onActivate (SPDesktop* dt);
295     static void _onDeactivate (SPDesktop* dt);
296     static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
297 };
299 #endif
301 /*
302   Local Variables:
303   mode:c++
304   c-file-style:"stroustrup"
305   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
306   indent-tabs-mode:nil
307   fill-column:99
308   End:
309 */
310 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :