Code

implement GEOMETRIC_BBOX
[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;
102     bool waiting_cursor;
104     /// \todo fixme: This has to be implemented in different way */
105     guint guides_active : 1;
107     // storage for selected dragger used by GrDrag as it's 
108     // created and deleted by tools
109     SPItem *gr_item;
110     guint  gr_point_type;
111     guint  gr_point_i;
112     bool   gr_fill_or_stroke;   
113     
115     Inkscape::ObjectHierarchy *_layer_hierarchy;
116     gchar * _reconstruction_old_layer_id;
118     sigc::signal<void, sp_verb_t>      _tool_changed;
119     sigc::signal<void, SPObject *>     _layer_changed_signal;
120     sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
121     sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
122     sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
123     {
124         return _document_replaced_signal.connect (slot);
125     }
126     
127     sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot) 
128     {
129         return _event_context_changed_signal.connect (slot);
130     }
131     sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot) 
132     {
133         return _set_style_signal.connect (slot);
134     }
135     sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot) 
136     {
137         return _query_style_signal.connect (slot);
138     }
139      // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
140     sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
141         return _tool_subselection_changed.connect(slot);
142     }
143     void emitToolSubselectionChanged(gpointer data); 
144     sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
145         return _layer_changed_signal.connect(slot);
146     }
147     
148         // Whiteboard changes
150 #ifdef WITH_INKBOARD
151         Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
152         return _whiteboard_session_manager;
153         }
155         Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
156 #endif
157    
158     SPDesktop();
159     void init (SPNamedView* nv, SPCanvas* canvas);
160     ~SPDesktop();
161     void destroy();
163     Inkscape::MessageContext *guidesMessageContext() const {
164         return _guides_message_context;
165     }
167     void setDisplayModeNormal();
168     void setDisplayModeOutline();
169     void displayModeToggle();
170     int displayMode;
171     int getMode() const { return displayMode; }
173     void set_active (bool new_active);
174     SPObject *currentRoot() const;
175     SPObject *currentLayer() const;
176     void setCurrentLayer(SPObject *object);
177     SPObject *layerForObject(SPObject *object);
178     bool isLayer(SPObject *object) const;
179     bool isWithinViewport(SPItem *item) const;
180     bool itemIsHidden(SPItem const *item) const;
181     
182     void activate_guides (bool activate);
183     void change_document (SPDocument *document);
185     void set_event_context (GtkType type, const gchar *config);
186     void push_event_context (GtkType type, const gchar *config, unsigned int key);
188     void set_coordinate_status (NR::Point p);
189     SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
190     SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
191     SPItem *group_at_point (NR::Point const p) const;
192     NR::Point point() const;
194     NR::Rect get_display_area() const;
195     void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
196     void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
197     void zoom_absolute (double cx, double cy, double zoom);
198     void zoom_relative (double cx, double cy, double zoom);
199     void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
200     void zoom_relative_keep_point (double cx, double cy, double zoom);
201     void zoom_relative_keep_point (NR::Point const &c, double const zoom)
202     {
203             using NR::X;
204             using NR::Y;
205             zoom_relative_keep_point (c[X], c[Y], zoom);
206     }
208     void zoom_page();
209     void zoom_page_width();
210     void zoom_drawing();
211     void zoom_selection();
212     void zoom_grab_focus();
213     double current_zoom() const  { return _d2w.expansion(); }
214     void prev_zoom();
215     void next_zoom();
217     bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
218     void scroll_world (double dx, double dy, bool is_scrolling = false);
219     void scroll_world (NR::Point const scroll, bool is_scrolling = false)
220     {
221         using NR::X;
222         using NR::Y;
223         scroll_world(scroll[X], scroll[Y], is_scrolling);
224     }
226     void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
227     void setWindowPosition (NR::Point p);
228     void setWindowSize (gint w, gint h);
229     void setWindowTransient (void* p, int transient_policy=1);
230     void presentWindow();
231     bool warnDialog (gchar *text);
232     void toggleRulers();
233     void toggleScrollbars();
234     void layoutWidget();
235     void destroyWidget();
236     void setToolboxFocusTo (gchar const* label);
237     void setToolboxAdjustmentValue (gchar const* id, double val);
238     bool isToolboxButtonActive (gchar const *id);
239     void updateNow();
240     void updateCanvasNow();
241     
242     void enableInteraction();
243     void disableInteraction();
245     void setWaitingCursor();
246     void clearWaitingCursor();
247     
248     void toggleGrid();
249     
250     void fullscreen();
252     void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
253     { _widget = widget; }
255     NR::Matrix w2d() const;
256     NR::Point w2d(NR::Point const &p) const;
257     NR::Point d2w(NR::Point const &p) const;
258     NR::Matrix doc2dt() const;
259     NR::Point doc2dt(NR::Point const &p) const;
260     NR::Point dt2doc(NR::Point const &p) const;
262     virtual void setDocument (SPDocument* doc);
263     virtual bool shutdown();
264     virtual void mouseover() {}
265     virtual void mouseout() {}
267 private:
268     Inkscape::UI::View::EditWidgetInterface       *_widget;
269     Inkscape::Application     *_inkscape;
270     Inkscape::MessageContext  *_guides_message_context;
271     bool _active;
272     NR::Matrix _w2d;
273     NR::Matrix _d2w;
274     NR::Matrix _doc2dt;
275     
276     void push_current_zoom (GList**);
278     sigc::signal<void,SPDesktop*,SPDocument*>     _document_replaced_signal;
279     sigc::signal<void>                 _activate_signal;
280     sigc::signal<void>                 _deactivate_signal;
281     sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
282     sigc::signal<void, gpointer>       _tool_subselection_changed;
283   
284     sigc::connection _activate_connection;
285     sigc::connection _deactivate_connection;
286     sigc::connection _sel_modified_connection;
287     sigc::connection _sel_changed_connection;
288     sigc::connection _reconstruction_start_connection;
289     sigc::connection _reconstruction_finish_connection;
290     sigc::connection _commit_connection;
291     sigc::connection _modified_connection;
292     
293     virtual void onPositionSet (double, double);
294     virtual void onResized (double, double);
295     virtual void onRedrawRequested();
296     virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
297     virtual void onDocumentURISet (gchar const* uri);
298     virtual void onDocumentResized (double, double);
300     static void _onActivate (SPDesktop* dt);
301     static void _onDeactivate (SPDesktop* dt);
302     static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
303 };
305 #endif
307 /*
308   Local Variables:
309   mode:c++
310   c-file-style:"stroustrup"
311   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
312   indent-tabs-mode:nil
313   fill-column:99
314   End:
315 */
316 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :