Code

disconnect mask/ref connections when item is destroyed
[inkscape.git] / src / sp-item.h
1 #ifndef __SP_ITEM_H__
2 #define __SP_ITEM_H__
4 /** \file
5  * Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx, SPItemClass, SPEvent.
6  */
8 /*
9  * Authors:
10  *   Lauris Kaplinski <lauris@kaplinski.com>
11  *   bulia byak <buliabyak@users.sf.net>
12  *
13  * Copyright (C) 1999-2005 authors
14  * Copyright (C) 2001-2002 Ximian, Inc.
15  * Copyright (C) 2004 Monash University
16  *
17  * Released under GNU GPL, read the file 'COPYING' for more information
18  */
19 #include <vector>
21 #include "display/nr-arena-forward.h"
22 #include "sp-object.h"
23 #include <libnr/nr-matrix.h>
24 #include <libnr/nr-rect.h>
26 class SPGuideConstraint;
27 struct SPClipPathReference;
28 struct SPMaskReference;
29 struct SPAvoidRef;
30 struct SPPrintContext;
31 namespace Inkscape { class URIReference; }
32  
33 enum {
34     SP_EVENT_INVALID,
35     SP_EVENT_NONE,
36     SP_EVENT_ACTIVATE,
37     SP_EVENT_MOUSEOVER,
38     SP_EVENT_MOUSEOUT
39 };
41 /**
42  * Event structure.
43  *
44  * \todo This is just placeholder. Plan:
45  * We do extensible event structure, that hold applicable (ui, non-ui)
46  * data pointers. So it is up to given object/arena implementation
47  * to process correct ones in meaningful way.
48  * Also, this probably goes to SPObject base class.
49  *
50  */
51 struct SPEvent {
52     unsigned int type;
53     gpointer data;
54 };
56 class SPItemView;
58 /// SPItemView
59 struct SPItemView {
60     SPItemView *next;
61     unsigned int flags;
62     unsigned int key;
63     NRArenaItem *arenaitem;
64 };
66 /* flags */
68 #define SP_ITEM_BBOX_VISUAL 1
70 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
72 /**
73  * Flag for referenced views (i.e. clippaths, masks and patterns); always display
74  */
75 #define SP_ITEM_REFERENCE_FLAGS SP_ITEM_SHOW_DISPLAY
77 class SPItemCtx;
79 /// Contains transformations to document/viewport and the viewport size.
80 struct SPItemCtx {
81     SPCtx ctx;
82     /** Item to document transformation */
83     NR::Matrix i2doc;
84     /** Viewport size */
85     NRRect vp;
86     /** Item to viewport transformation */
87     NR::Matrix i2vp;
88 };
90 /** Abstract base class for all visible shapes. */
91 struct SPItem : public SPObject {
92     unsigned int sensitive : 1;
93     unsigned int stop_paint: 1;
94     double transform_center_x;
95     double transform_center_y;
97     NR::Matrix transform;
98     
99     SPClipPathReference *clip_ref;
100     SPMaskReference *mask_ref;
101     
102     // Used for object-avoiding connectors
103     SPAvoidRef *avoidRef;
104     
105     SPItemView *display;
106     
107     std::vector<SPGuideConstraint> constraints;
108     
109     sigc::signal<void, NR::Matrix const *, SPItem *> _transformed_signal;
111     void init();    
112     bool isLocked() const;
113     void setLocked(bool lock);
114     
115     bool isHidden() const;
116     void setHidden(bool hidden);
118     bool isEvaluated() const;
119     void setEvaluated(bool visible);
120     void resetEvaluated();
121     
122     bool isHidden(unsigned display_key) const;
123     
124     bool isExplicitlyHidden() const;
125     
126     void setExplicitlyHidden(bool val);
128     void setCenter(NR::Point object_centre);
129     void unsetCenter();
130     bool isCenterSet();
131     NR::Point getCenter();
133     bool isVisibleAndUnlocked() const;
134     
135     bool isVisibleAndUnlocked(unsigned display_key) const;
136     
137     NR::Matrix getRelativeTransform(SPObject const *obj) const;
138     
139     void raiseOne();
140     void lowerOne();
141     void raiseToTop();
142     void lowerToBottom();
144     NR::Rect invokeBbox(NR::Matrix const &transform) const;
146     sigc::connection _clip_ref_connection;
147     sigc::connection _mask_ref_connection;
149     sigc::connection connectTransformed(sigc::slot<void, NR::Matrix const *, SPItem *> slot)  {
150         return _transformed_signal.connect(slot);
151     }
153 private:
154     enum EvaluatedStatus
155     {
156         StatusUnknown, StatusCalculated, StatusSet
157     };
159     mutable bool _is_evaluated;
160     mutable EvaluatedStatus _evaluated_status;
161 };
163 typedef std::back_insert_iterator<std::vector<NR::Point> > SnapPointsIter;
165 /// The SPItem vtable.
166 struct SPItemClass {
167     SPObjectClass parent_class;
169     /** BBox union in given coordinate system */
170     void (* bbox) (SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
171     
172     /** Printing method. Assumes ctm is set to item affine matrix */
173     /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
174     void (* print) (SPItem *item, SPPrintContext *ctx);
175     
176     /** Give short description of item (for status display) */
177     gchar * (* description) (SPItem * item);
178     
179     NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
180     void (* hide) (SPItem *item, unsigned int key);
181     
182     /** Write to an iterator the points that should be considered for snapping
183      * as the item's `nodes'.
184      */
185     void (* snappoints) (SPItem const *item, SnapPointsIter p);
186     
187     /** Apply the transform optimally, and return any residual transformation */
188     NR::Matrix (* set_transform)(SPItem *item, NR::Matrix const &transform);
189     
190     /** Emit event, if applicable */
191     gint (* event) (SPItem *item, SPEvent *event);
192 };
194 /* Flag testing macros */
196 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
198 /* Methods */
200 void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear);
201 void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear);
203 unsigned sp_item_pos_in_parent(SPItem *item);
205 gchar *sp_item_description(SPItem * item);
206 void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
208 /** Shows/Hides item on given arena display list */
209 unsigned int sp_item_display_key_new(unsigned int numkeys);
210 NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
211 void sp_item_invoke_hide(SPItem *item, unsigned int key);
213 void sp_item_snappoints(SPItem const *item, SnapPointsIter p);
215 void sp_item_adjust_pattern(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
216 void sp_item_adjust_gradient(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
217 void sp_item_adjust_stroke(SPItem *item, gdouble ex);
218 void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
219 void sp_item_adjust_paint_recursive(SPItem *item, NR::Matrix advertized_transform, NR::Matrix t_ancestors, bool is_pattern);
221 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NRMatrix const *transform, NR::Matrix const *adv = NULL);
222 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const &transform, NR::Matrix const *adv = NULL);
224 void sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform);
226 gint sp_item_event (SPItem *item, SPEvent *event);
228 /* Utility */
230 NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
232 void sp_item_bbox_desktop(SPItem *item, NRRect *bbox) __attribute__ ((deprecated));
233 NR::Rect sp_item_bbox_desktop(SPItem *item);
235 NR::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
236 NR::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
238 NR::Matrix sp_item_i2doc_affine(SPItem const *item);
239 NR::Matrix sp_item_i2root_affine(SPItem const *item);
241 NR::Matrix matrix_to_desktop (NR::Matrix m, SPItem const *item);
242 NR::Matrix matrix_from_desktop (NR::Matrix m, SPItem const *item);
244 /* fixme: - these are evil, but OK */
246 /* Fill *TRANSFORM with the item-to-desktop transform.  See doc/coordinates.txt
247  * for a description of `Desktop coordinates'; though see also mental's comment
248  * at the top of that file.
249  *
250  * \return TRANSFORM.
251  */
252 NR::Matrix sp_item_i2d_affine(SPItem const *item);
253 NR::Matrix sp_item_i2r_affine(SPItem const *item);
254 void sp_item_set_i2d_affine(SPItem *item, NR::Matrix const &transform);
255 NR::Matrix sp_item_dt2i_affine(SPItem const *item);
256 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
257 SPItem *sp_item_first_item_child (SPObject *obj);
259 #endif
261 /*
262   Local Variables:
263   mode:c++
264   c-file-style:"stroustrup"
265   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
266   indent-tabs-mode:nil
267   fill-column:99
268   End:
269 */
270 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :