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 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
13 *
14 * Copyright (C) 1999-2006 authors
15 * Copyright (C) 2001-2002 Ximian, Inc.
16 * Copyright (C) 2004 Monash University
17 *
18 * Released under GNU GPL, read the file 'COPYING' for more information
19 */
20 #include <vector>
22 #include "display/nr-arena-forward.h"
23 #include "sp-object.h"
24 #include <2geom/matrix.h>
25 #include <libnr/nr-rect.h>
26 #include <2geom/forward.h>
27 #include <libnr/nr-convert2geom.h>
28 #include <snap-preferences.h>
29 #include "snap-candidate.h"
31 class SPGuideConstraint;
32 struct SPClipPathReference;
33 struct SPMaskReference;
34 struct SPAvoidRef;
35 struct SPPrintContext;
36 namespace Inkscape { class URIReference;}
38 enum {
39 SP_EVENT_INVALID,
40 SP_EVENT_NONE,
41 SP_EVENT_ACTIVATE,
42 SP_EVENT_MOUSEOVER,
43 SP_EVENT_MOUSEOUT
44 };
46 /**
47 * Event structure.
48 *
49 * \todo This is just placeholder. Plan:
50 * We do extensible event structure, that hold applicable (ui, non-ui)
51 * data pointers. So it is up to given object/arena implementation
52 * to process correct ones in meaningful way.
53 * Also, this probably goes to SPObject base class.
54 *
55 */
56 //struct SPEvent {
57 class SPEvent {
58 public:
59 unsigned int type;
60 gpointer data;
61 };
63 /// SPItemView
64 //struct SPItemView {
65 class SPItemView {
66 public:
67 SPItemView *next;
68 unsigned int flags;
69 unsigned int key;
70 NRArenaItem *arenaitem;
71 };
73 /* flags */
75 #define SP_ITEM_BBOX_VISUAL 1
77 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
79 /**
80 * Flag for referenced views (i.e. markers, clippaths, masks and patterns);
81 currently unused, does the same as DISPLAY
82 */
83 #define SP_ITEM_REFERENCE_FLAGS (1 << 1)
85 /// Contains transformations to document/viewport and the viewport size.
86 //struct SPItemCtx {
87 class SPItemCtx {
88 public:
89 SPCtx ctx;
90 /** Item to document transformation */
91 Geom::Matrix i2doc;
92 /** Viewport size */
93 NRRect vp;
94 /** Item to viewport transformation */
95 Geom::Matrix i2vp;
96 };
98 class SPItem;
99 class SPItemClass;
101 #define SP_TYPE_ITEM (SPItem::getType ())
102 #define SP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_ITEM, SPItem))
103 #define SP_ITEM_CLASS(clazz) (G_TYPE_CHECK_CLASS_CAST((clazz), SP_TYPE_ITEM, SPItemClass))
104 #define SP_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ITEM))
107 /** Abstract base class for all visible shapes. */
108 //struct SPItem : public SPObject {
109 class SPItem : public SPObject {
110 public:
111 static GType getType ();
112 enum BBoxType {
113 // legacy behavior: includes crude stroke, markers; excludes long miters, blur margin; is known to be wrong for caps
114 APPROXIMATE_BBOX,
115 // includes only the bare path bbox, no stroke, no nothing
116 GEOMETRIC_BBOX,
117 // includes everything: correctly done stroke (with proper miters and caps), markers, filter margins (e.g. blur)
118 RENDERING_BBOX
119 };
121 unsigned int sensitive : 1;
122 unsigned int stop_paint: 1;
123 double transform_center_x;
124 double transform_center_y;
126 Geom::Matrix transform;
128 SPClipPathReference *clip_ref;
129 SPMaskReference *mask_ref;
131 // Used for object-avoiding connectors
132 SPAvoidRef *avoidRef;
134 SPItemView *display;
136 std::vector<SPGuideConstraint> constraints;
138 sigc::signal<void, Geom::Matrix const *, SPItem *> _transformed_signal;
140 void init();
141 bool isLocked() const;
142 void setLocked(bool lock);
144 bool isHidden() const;
145 void setHidden(bool hidden);
147 bool isEvaluated() const;
148 void setEvaluated(bool visible);
149 void resetEvaluated();
151 bool isHidden(unsigned display_key) const;
153 bool isExplicitlyHidden() const;
155 void setExplicitlyHidden(bool val);
157 void setCenter(Geom::Point object_centre);
158 void unsetCenter();
159 bool isCenterSet();
160 Geom::Point getCenter() const;
162 bool isVisibleAndUnlocked() const;
164 bool isVisibleAndUnlocked(unsigned display_key) const;
166 Geom::Matrix getRelativeTransform(SPObject const *obj) const;
168 void raiseOne();
169 void lowerOne();
170 void raiseToTop();
171 void lowerToBottom();
173 Geom::OptRect getBounds(Geom::Matrix const &transform, BBoxType type=APPROXIMATE_BBOX, unsigned int dkey=0) const;
175 sigc::connection _clip_ref_connection;
176 sigc::connection _mask_ref_connection;
178 sigc::connection connectTransformed(sigc::slot<void, Geom::Matrix const *, SPItem *> slot) {
179 return _transformed_signal.connect(slot);
180 }
181 void invoke_bbox( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
182 void invoke_bbox( NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
183 void invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear);
184 void invoke_bbox_full( NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) __attribute__ ((deprecated));
186 unsigned pos_in_parent();
187 gchar *description();
188 void invoke_print(SPPrintContext *ctx);
189 static unsigned int display_key_new(unsigned int numkeys);
190 NRArenaItem *invoke_show(NRArena *arena, unsigned int key, unsigned int flags);
191 void invoke_hide(unsigned int key);
192 void getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs=0) const;
193 void adjust_pattern(/* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
194 void adjust_gradient(/* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
195 void adjust_stroke(gdouble ex);
196 void adjust_stroke_width_recursive(gdouble ex);
197 void adjust_paint_recursive(Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern);
198 void adjust_livepatheffect(Geom::Matrix const &postmul, bool set = false);
199 void doWriteTransform(Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv = NULL, bool compensate = true);
200 void set_item_transform(Geom::Matrix const &transform_matrix);
201 void convert_item_to_guides();
202 gint emitEvent (SPEvent &event);
203 NRArenaItem *get_arenaitem(unsigned int key);
204 void getBboxDesktop(NRRect *bbox, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
205 Geom::OptRect getBboxDesktop(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
206 Geom::Matrix i2doc_affine() const;
207 Geom::Matrix i2d_affine() const;
208 void set_i2d_affine(Geom::Matrix const &transform);
209 Geom::Matrix dt2i_affine() const;
210 void convert_to_guides();
211 private:
212 enum EvaluatedStatus
213 {
214 StatusUnknown, StatusCalculated, StatusSet
215 };
217 mutable bool _is_evaluated;
218 mutable EvaluatedStatus _evaluated_status;
220 static void sp_item_init(SPItem *item);
222 static void sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
223 static void sp_item_release(SPObject *object);
224 static void sp_item_set(SPObject *object, unsigned key, gchar const *value);
225 static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
226 static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
228 static gchar *sp_item_private_description(SPItem *item);
229 static void sp_item_private_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
231 static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
232 static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
233 static void clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item);
234 static void mask_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item);
236 friend class SPItemClass;
237 };
239 /// The SPItem vtable.
240 //struct SPItemClass {
241 class SPItemClass {
242 public:
243 SPObjectClass parent_class;
245 /** BBox union in given coordinate system */
246 void (* bbox) (SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
248 /** Printing method. Assumes ctm is set to item affine matrix */
249 /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
250 void (* print) (SPItem *item, SPPrintContext *ctx);
252 /** Give short description of item (for status display) */
253 gchar * (* description) (SPItem * item);
255 NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
256 void (* hide) (SPItem *item, unsigned int key);
258 /** Write to an iterator the points that should be considered for snapping
259 * as the item's `nodes'.
260 */
261 void (* snappoints) (SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
263 /** Apply the transform optimally, and return any residual transformation */
264 Geom::Matrix (* set_transform)(SPItem *item, Geom::Matrix const &transform);
266 /** Convert the item to guidelines */
267 void (* convert_to_guides)(SPItem *item);
269 /** Emit event, if applicable */
270 gint (* event) (SPItem *item, SPEvent *event);
272 private:
273 static SPObjectClass *static_parent_class;
274 static void sp_item_class_init(SPItemClass *klass);
276 friend class SPItem;
277 };
279 /* Flag testing macros */
281 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
283 /* Methods */
285 //void sp_item_invoke_bbox(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
286 //void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
287 //void sp_item_invoke_bbox_full(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear);
288 //void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) __attribute__ ((deprecated));
290 //unsigned sp_item_pos_in_parent(SPItem *item);
292 //gchar *sp_item_description(SPItem * item);
293 //void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
295 /** Shows/Hides item on given arena display list */
296 //unsigned int sp_item_display_key_new(unsigned int numkeys);
297 //NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
298 //void sp_item_invoke_hide(SPItem *item, unsigned int key);
300 //void sp_item_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
302 //void sp_item_adjust_pattern(SPItem *item, /* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
303 //void sp_item_adjust_gradient(SPItem *item, /* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
304 //void sp_item_adjust_stroke(SPItem *item, gdouble ex);
305 //void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
306 //void sp_item_adjust_paint_recursive(SPItem *item, Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern);
307 //void sp_item_adjust_livepatheffect(SPItem *item, Geom::Matrix const &postmul, bool set = false);
309 //void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv = NULL, bool compensate = true);
311 //void sp_item_set_item_transform(SPItem *item, Geom::Matrix const &transform);
313 //void sp_item_convert_item_to_guides(SPItem *item);
315 //gint sp_item_event (SPItem *item, SPEvent *event);
317 /* Utility */
319 //NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
321 //void sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
322 //Geom::OptRect sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
324 Geom::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
325 Geom::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
327 //Geom::Matrix sp_item_i2doc_affine(SPItem const *item);
329 /* fixme: - these are evil, but OK */
331 /* Fill *TRANSFORM with the item-to-desktop transform. See doc/coordinates.txt
332 * for a description of `Desktop coordinates'; though see also mental's comment
333 * at the top of that file.
334 *
335 * \return TRANSFORM.
336 */
337 //Geom::Matrix sp_item_i2d_affine(SPItem const *item);
338 //void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &transform);
339 //Geom::Matrix sp_item_dt2i_affine(SPItem const *item);
340 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
341 SPItem *sp_item_first_item_child (SPObject *obj);
343 //void sp_item_convert_to_guides(SPItem *item);
345 #endif
347 /*
348 Local Variables:
349 mode:c++
350 c-file-style:"stroustrup"
351 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
352 indent-tabs-mode:nil
353 fill-column:99
354 End:
355 */
356 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :