Code

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