Code

fa6602651bc1b8c8dd2b8fc4ade2a99146e7fe22
[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 <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"
37 #include "perspective3d.h"
39 class NRRect;
40 class SPCSSAttr;
41 struct _GtkWidget;
42 typedef struct _GtkWidget GtkWidget;
43 struct SPCanvas;
44 struct SPCanvasItem;
45 struct SPCanvasGroup;
46 struct SPDesktopWidget;
47 struct SPEventContext;
48 struct SPItem;
49 struct SPNamedView;
50 struct SPObject;
51 struct SPStyle;
52 struct SPViewWidget;
54 namespace Gtk
55 {
56   class Window;
57 }
59 typedef int sp_verb_t;
63 namespace Inkscape { 
64   class Application;
65   class MessageContext;
66   class Selection; 
67   class ObjectHierarchy;
68   class LayerManager;
69   class EventLog;
70   namespace UI { 
71       namespace Dialog { 
72           class DialogManager; 
73       }
74   }
75   namespace Whiteboard {
76       class SessionManager;
77   }
78 }
80 /**
81  * Editable view.
82  *
83  * @see \ref desktop-handles.h for desktop macros.
84  */
85 struct SPDesktop : public Inkscape::UI::View::View
86 {
87     Inkscape::UI::Dialog::DialogManager *_dlg_mgr;
88     SPNamedView               *namedview;
89     SPCanvas                  *canvas;
90     /// current selection; will never generally be NULL
91     Inkscape::Selection       *selection;
92     SPEventContext            *event_context;
93     Inkscape::LayerManager    *layer_manager;
94     Inkscape::EventLog        *event_log;
96     SPCanvasItem  *acetate;
97     SPCanvasGroup *main;
98     SPCanvasGroup *gridgroup;
99     SPCanvasGroup *guides;
100     SPCanvasItem  *drawing;
101     SPCanvasGroup *sketch;
102     SPCanvasGroup *controls;
103     SPCanvasItem  *table;       ///< outside-of-page background
104     SPCanvasItem  *page;        ///< page background
105     SPCanvasItem  *page_border; ///< page border
106     SPCSSAttr     *current;     ///< current style
108     GList *zooms_past;
109     GList *zooms_future;
110     unsigned int dkey;
111     unsigned int number;
112     guint window_state;
113     unsigned int interaction_disabled_counter;
114     bool waiting_cursor;
116     // All 3D perspectives that are present in the current desktop
117     GSList *perspectives;
119     /// \todo fixme: This has to be implemented in different way */
120     guint guides_active : 1;
122     // storage for selected dragger used by GrDrag as it's 
123     // created and deleted by tools
124     SPItem *gr_item;
125     guint  gr_point_type;
126     guint  gr_point_i;
127     bool   gr_fill_or_stroke;   
128     
130     Inkscape::ObjectHierarchy *_layer_hierarchy;
131     gchar * _reconstruction_old_layer_id;
133     sigc::signal<void, sp_verb_t>      _tool_changed;
134     sigc::signal<void, SPObject *>     _layer_changed_signal;
135     sigc::signal<bool, const SPCSSAttr *>::accumulated<StopOnTrue> _set_style_signal;
136     sigc::signal<int, SPStyle *, int>::accumulated<StopOnNonZero> _query_style_signal;
137     sigc::connection connectDocumentReplaced (const sigc::slot<void,SPDesktop*,SPDocument*> & slot)
138     {
139         return _document_replaced_signal.connect (slot);
140     }
141     
142     sigc::connection connectEventContextChanged (const sigc::slot<void,SPDesktop*,SPEventContext*> & slot) 
143     {
144         return _event_context_changed_signal.connect (slot);
145     }
146     sigc::connection connectSetStyle (const sigc::slot<bool, const SPCSSAttr *> & slot) 
147     {
148         return _set_style_signal.connect (slot);
149     }
150     sigc::connection connectQueryStyle (const sigc::slot<int, SPStyle *, int> & slot) 
151     {
152         return _query_style_signal.connect (slot);
153     }
154      // subselection is some sort of selection which is specific to the tool, such as a handle in gradient tool, or a text selection
155     sigc::connection connectToolSubselectionChanged(const sigc::slot<void, gpointer> & slot) {
156         return _tool_subselection_changed.connect(slot);
157     }
158     void emitToolSubselectionChanged(gpointer data); 
159     sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
160         return _layer_changed_signal.connect(slot);
161     }
162     
163         // Whiteboard changes
165 #ifdef WITH_INKBOARD
166         Inkscape::Whiteboard::SessionManager* whiteboard_session_manager() {
167         return _whiteboard_session_manager;
168         }
170         Inkscape::Whiteboard::SessionManager* _whiteboard_session_manager;
171 #endif
172    
173     SPDesktop();
174     void init (SPNamedView* nv, SPCanvas* canvas);
175     ~SPDesktop();
176     void destroy();
178     Inkscape::MessageContext *guidesMessageContext() const {
179         return _guides_message_context;
180     }
182     void setDisplayModeNormal();
183     void setDisplayModeOutline();
184     void displayModeToggle();
185     int displayMode;
186     int getMode() const { return displayMode; }
188     void set_active (bool new_active);
189     SPObject *currentRoot() const;
190     SPObject *currentLayer() const;
191     void setCurrentLayer(SPObject *object);
192     SPObject *layerForObject(SPObject *object);
193     bool isLayer(SPObject *object) const;
194     bool isWithinViewport(SPItem *item) const;
195     bool itemIsHidden(SPItem const *item) const;
196     
197     void activate_guides (bool activate);
198     void change_document (SPDocument *document);
200     void set_event_context (GtkType type, const gchar *config);
201     void push_event_context (GtkType type, const gchar *config, unsigned int key);
203     void set_coordinate_status (NR::Point p);
204     SPItem *item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const;
205     SPItem *item_at_point (NR::Point const p, bool into_groups, SPItem *upto = NULL) const;
206     SPItem *group_at_point (NR::Point const p) const;
207     NR::Point point() const;
209     // Methods to handle 3D perspective
210     void add_perspective (Box3D::Perspective3D * const persp);
211     void remove_perspective (Box3D::Perspective3D * const persp);
213     NR::Rect get_display_area() const;
214     void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
215     void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
216     void zoom_absolute (double cx, double cy, double zoom);
217     void zoom_relative (double cx, double cy, double zoom);
218     void zoom_absolute_keep_point (double cx, double cy, double px, double py, double zoom);
219     void zoom_relative_keep_point (double cx, double cy, double zoom);
220     void zoom_relative_keep_point (NR::Point const &c, double const zoom)
221     {
222             using NR::X;
223             using NR::Y;
224             zoom_relative_keep_point (c[X], c[Y], zoom);
225     }
227     void zoom_page();
228     void zoom_page_width();
229     void zoom_drawing();
230     void zoom_selection();
231     void zoom_grab_focus();
232     double current_zoom() const  { return _d2w.expansion(); }
233     void prev_zoom();
234     void next_zoom();
236     bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0);
237     void scroll_world (double dx, double dy, bool is_scrolling = false);
238     void scroll_world (NR::Point const scroll, bool is_scrolling = false)
239     {
240         using NR::X;
241         using NR::Y;
242         scroll_world(scroll[X], scroll[Y], is_scrolling);
243     }
245     void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
246     void setWindowPosition (NR::Point p);
247     void setWindowSize (gint w, gint h);
248     void setWindowTransient (void* p, int transient_policy=1);
249     Gtk::Window* getToplevel();
250     void presentWindow();
251     bool warnDialog (gchar *text);
252     void toggleRulers();
253     void toggleScrollbars();
254     void layoutWidget();
255     void destroyWidget();
256     void setToolboxFocusTo (gchar const* label);
257     void setToolboxAdjustmentValue (gchar const* id, double val);
258     bool isToolboxButtonActive (gchar const *id);
259     void updateNow();
260     void updateCanvasNow();
261     
262     void enableInteraction();
263     void disableInteraction();
265     void setWaitingCursor();
266     void clearWaitingCursor();
267     
268     void toggleGrid();
269     bool gridsEnabled() { return grids_visible; }
270     
271     bool is_iconified();
272     bool is_maximized();
273     bool is_fullscreen();
275     void iconify();
276     void maximize();
277     void fullscreen();
279     void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
280     { _widget = widget; }
282     NR::Matrix w2d() const; //transformation from window to desktop coordinates (used for zooming)
283     NR::Point w2d(NR::Point const &p) const;
284     NR::Point d2w(NR::Point const &p) const;
285     NR::Matrix doc2dt() const;
286     NR::Point doc2dt(NR::Point const &p) const;
287     NR::Point dt2doc(NR::Point const &p) const;
289     virtual void setDocument (SPDocument* doc);
290     virtual bool shutdown();
291     virtual void mouseover() {}
292     virtual void mouseout() {}
294         virtual bool onDeleteUI (GdkEventAny*);
295         virtual bool onWindowStateEvent (GdkEventWindowState* event);
297 private:
298     Inkscape::UI::View::EditWidgetInterface       *_widget;
299     Inkscape::Application     *_inkscape;
300     Inkscape::MessageContext  *_guides_message_context;
301     bool _active;
302     NR::Matrix _w2d;
303     NR::Matrix _d2w;
304     NR::Matrix _doc2dt;
305     
306     bool grids_visible;
307     
308     void push_current_zoom (GList**);
310     sigc::signal<void,SPDesktop*,SPDocument*>     _document_replaced_signal;
311     sigc::signal<void>                 _activate_signal;
312     sigc::signal<void>                 _deactivate_signal;
313     sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
314     sigc::signal<void, gpointer>       _tool_subselection_changed;
315   
316     sigc::connection _activate_connection;
317     sigc::connection _deactivate_connection;
318     sigc::connection _sel_modified_connection;
319     sigc::connection _sel_changed_connection;
320     sigc::connection _reconstruction_start_connection;
321     sigc::connection _reconstruction_finish_connection;
322     sigc::connection _commit_connection;
323     sigc::connection _modified_connection;
324     
325     virtual void onPositionSet (double, double);
326     virtual void onResized (double, double);
327     virtual void onRedrawRequested();
328     virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message);
329     virtual void onDocumentURISet (gchar const* uri);
330     virtual void onDocumentResized (double, double);
332     static void _onActivate (SPDesktop* dt);
333     static void _onDeactivate (SPDesktop* dt);
334     static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt);
335 };
337 #endif
339 /*
340   Local Variables:
341   mode:c++
342   c-file-style:"stroustrup"
343   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
344   indent-tabs-mode:nil
345   fill-column:99
346   End:
347 */
348 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :