Code

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