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 <libnr/nr-matrix.h>
25 #include <libnr/nr-rect.h>
27 class SPGuideConstraint;
28 struct SPClipPathReference;
29 struct SPMaskReference;
30 struct SPAvoidRef;
31 struct SPPrintContext;
32 namespace Inkscape { class URIReference; }
34 enum {
35 SP_EVENT_INVALID,
36 SP_EVENT_NONE,
37 SP_EVENT_ACTIVATE,
38 SP_EVENT_MOUSEOVER,
39 SP_EVENT_MOUSEOUT
40 };
42 /**
43 * Event structure.
44 *
45 * \todo This is just placeholder. Plan:
46 * We do extensible event structure, that hold applicable (ui, non-ui)
47 * data pointers. So it is up to given object/arena implementation
48 * to process correct ones in meaningful way.
49 * Also, this probably goes to SPObject base class.
50 *
51 */
52 struct SPEvent {
53 unsigned int type;
54 gpointer data;
55 };
57 class SPItemView;
59 /// SPItemView
60 struct SPItemView {
61 SPItemView *next;
62 unsigned int flags;
63 unsigned int key;
64 NRArenaItem *arenaitem;
65 };
67 /* flags */
69 #define SP_ITEM_BBOX_VISUAL 1
71 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
73 /**
74 * Flag for referenced views (i.e. clippaths, masks and patterns); always display
75 */
76 #define SP_ITEM_REFERENCE_FLAGS SP_ITEM_SHOW_DISPLAY
78 class SPItemCtx;
80 /// Contains transformations to document/viewport and the viewport size.
81 struct SPItemCtx {
82 SPCtx ctx;
83 /** Item to document transformation */
84 NR::Matrix i2doc;
85 /** Viewport size */
86 NRRect vp;
87 /** Item to viewport transformation */
88 NR::Matrix i2vp;
89 };
91 /** Abstract base class for all visible shapes. */
92 struct SPItem : public SPObject {
93 unsigned int sensitive : 1;
94 unsigned int stop_paint: 1;
95 double transform_center_x;
96 double transform_center_y;
98 NR::Matrix transform;
100 SPClipPathReference *clip_ref;
101 SPMaskReference *mask_ref;
103 // Used for object-avoiding connectors
104 SPAvoidRef *avoidRef;
106 SPItemView *display;
108 std::vector<SPGuideConstraint> constraints;
110 sigc::signal<void, NR::Matrix const *, SPItem *> _transformed_signal;
112 void init();
113 bool isLocked() const;
114 void setLocked(bool lock);
116 bool isHidden() const;
117 void setHidden(bool hidden);
119 bool isEvaluated() const;
120 void setEvaluated(bool visible);
121 void resetEvaluated();
123 bool isHidden(unsigned display_key) const;
125 bool isExplicitlyHidden() const;
127 void setExplicitlyHidden(bool val);
129 void setCenter(NR::Point object_centre);
130 void unsetCenter();
131 bool isCenterSet();
132 NR::Point getCenter();
134 bool isVisibleAndUnlocked() const;
136 bool isVisibleAndUnlocked(unsigned display_key) const;
138 NR::Matrix getRelativeTransform(SPObject const *obj) const;
140 void raiseOne();
141 void lowerOne();
142 void raiseToTop();
143 void lowerToBottom();
145 NR::Rect invokeBbox(NR::Matrix const &transform) const;
147 sigc::connection _clip_ref_connection;
148 sigc::connection _mask_ref_connection;
150 sigc::connection connectTransformed(sigc::slot<void, NR::Matrix const *, SPItem *> slot) {
151 return _transformed_signal.connect(slot);
152 }
154 private:
155 enum EvaluatedStatus
156 {
157 StatusUnknown, StatusCalculated, StatusSet
158 };
160 mutable bool _is_evaluated;
161 mutable EvaluatedStatus _evaluated_status;
162 };
164 typedef std::back_insert_iterator<std::vector<NR::Point> > SnapPointsIter;
166 /// The SPItem vtable.
167 struct SPItemClass {
168 SPObjectClass parent_class;
170 /** BBox union in given coordinate system */
171 void (* bbox) (SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
173 /** Printing method. Assumes ctm is set to item affine matrix */
174 /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
175 void (* print) (SPItem *item, SPPrintContext *ctx);
177 /** Give short description of item (for status display) */
178 gchar * (* description) (SPItem * item);
180 NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
181 void (* hide) (SPItem *item, unsigned int key);
183 /** Write to an iterator the points that should be considered for snapping
184 * as the item's `nodes'.
185 */
186 void (* snappoints) (SPItem const *item, SnapPointsIter p);
188 /** Apply the transform optimally, and return any residual transformation */
189 NR::Matrix (* set_transform)(SPItem *item, NR::Matrix const &transform);
191 /** Emit event, if applicable */
192 gint (* event) (SPItem *item, SPEvent *event);
193 };
195 /* Flag testing macros */
197 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
199 /* Methods */
201 void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear);
202 void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear);
204 unsigned sp_item_pos_in_parent(SPItem *item);
206 gchar *sp_item_description(SPItem * item);
207 void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
209 /** Shows/Hides item on given arena display list */
210 unsigned int sp_item_display_key_new(unsigned int numkeys);
211 NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
212 void sp_item_invoke_hide(SPItem *item, unsigned int key);
214 void sp_item_snappoints(SPItem const *item, SnapPointsIter p);
216 void sp_item_adjust_pattern(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
217 void sp_item_adjust_gradient(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
218 void sp_item_adjust_stroke(SPItem *item, gdouble ex);
219 void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
220 void sp_item_adjust_paint_recursive(SPItem *item, NR::Matrix advertized_transform, NR::Matrix t_ancestors, bool is_pattern);
222 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NRMatrix const *transform, NR::Matrix const *adv = NULL);
223 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const &transform, NR::Matrix const *adv = NULL, bool compensate = true);
225 void sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform);
227 gint sp_item_event (SPItem *item, SPEvent *event);
229 /* Utility */
231 NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
233 void sp_item_bbox_desktop(SPItem *item, NRRect *bbox) __attribute__ ((deprecated));
234 NR::Rect sp_item_bbox_desktop(SPItem *item);
236 NR::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
237 NR::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
239 NR::Matrix sp_item_i2doc_affine(SPItem const *item);
240 NR::Matrix sp_item_i2root_affine(SPItem const *item);
242 NR::Matrix matrix_to_desktop (NR::Matrix m, SPItem const *item);
243 NR::Matrix matrix_from_desktop (NR::Matrix m, SPItem const *item);
245 /* fixme: - these are evil, but OK */
247 /* Fill *TRANSFORM with the item-to-desktop transform. See doc/coordinates.txt
248 * for a description of `Desktop coordinates'; though see also mental's comment
249 * at the top of that file.
250 *
251 * \return TRANSFORM.
252 */
253 NR::Matrix sp_item_i2d_affine(SPItem const *item);
254 NR::Matrix sp_item_i2r_affine(SPItem const *item);
255 void sp_item_set_i2d_affine(SPItem *item, NR::Matrix const &transform);
256 NR::Matrix sp_item_dt2i_affine(SPItem const *item);
257 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
258 SPItem *sp_item_first_item_child (SPObject *obj);
260 #endif
262 /*
263 Local Variables:
264 mode:c++
265 c-file-style:"stroustrup"
266 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
267 indent-tabs-mode:nil
268 fill-column:99
269 End:
270 */
271 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :