Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / sp-item.h
1 #ifndef SEEN_SP_ITEM_H
2 #define SEEN_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  *   Abhishek Sharma
14  *
15  * Copyright (C) 1999-2006 authors
16  * Copyright (C) 2001-2002 Ximian, Inc.
17  * Copyright (C) 2004 Monash University
18  *
19  * Released under GNU GPL, read the file 'COPYING' for more information
20  */
21 #include <vector>
23 #include "display/nr-arena-forward.h"
24 #include "sp-object.h"
25 #include <2geom/matrix.h>
26 #include <libnr/nr-rect.h>
27 #include <2geom/forward.h>
28 #include <libnr/nr-convert2geom.h>
29 #include <snap-preferences.h>
30 #include "snap-candidate.h"
32 class SPGuideConstraint;
33 struct SPClipPathReference;
34 struct SPMaskReference;
35 struct SPAvoidRef;
36 struct SPPrintContext;
37 namespace Inkscape { class URIReference;}
39 enum {
40     SP_EVENT_INVALID,
41     SP_EVENT_NONE,
42     SP_EVENT_ACTIVATE,
43     SP_EVENT_MOUSEOVER,
44     SP_EVENT_MOUSEOUT
45 };
47 /**
48  * Event structure.
49  *
50  * \todo This is just placeholder. Plan:
51  * We do extensible event structure, that hold applicable (ui, non-ui)
52  * data pointers. So it is up to given object/arena implementation
53  * to process correct ones in meaningful way.
54  * Also, this probably goes to SPObject base class.
55  *
56  */
57 class SPEvent {
58 public:
59     unsigned int type;
60     gpointer data;
61 };
63 /// SPItemView
64 class SPItemView {
65 public:
66     SPItemView *next;
67     unsigned int flags;
68     unsigned int key;
69     NRArenaItem *arenaitem;
70 };
72 /* flags */
74 #define SP_ITEM_BBOX_VISUAL 1
76 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
78 /**
79  * Flag for referenced views (i.e. markers, clippaths, masks and patterns);
80    currently unused, does the same as DISPLAY
81  */
82 #define SP_ITEM_REFERENCE_FLAGS (1 << 1)
84 /// Contains transformations to document/viewport and the viewport size.
85 class SPItemCtx {
86 public:
87     SPCtx ctx;
88     /** Item to document transformation */
89     Geom::Matrix i2doc;
90     /** Viewport size */
91     NRRect vp;
92     /** Item to viewport transformation */
93     Geom::Matrix i2vp;
94 };
96 class SPItem;
97 class SPItemClass;
99 #define SP_TYPE_ITEM (SPItem::getType ())
100 #define SP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_ITEM, SPItem))
101 #define SP_ITEM_CLASS(clazz) (G_TYPE_CHECK_CLASS_CAST((clazz), SP_TYPE_ITEM, SPItemClass))
102 #define SP_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ITEM))
105 /** Abstract base class for all visible shapes. */
106 class SPItem : public SPObject {
107 public:
108     static GType getType();
109     enum BBoxType {
110         // legacy behavior: includes crude stroke, markers; excludes long miters, blur margin; is known to be wrong for caps
111         APPROXIMATE_BBOX,
112         // includes only the bare path bbox, no stroke, no nothing
113         GEOMETRIC_BBOX,
114         // includes everything: correctly done stroke (with proper miters and caps), markers, filter margins (e.g. blur)
115         RENDERING_BBOX
116     };
118     unsigned int sensitive : 1;
119     unsigned int stop_paint: 1;
120     double transform_center_x;
121     double transform_center_y;
123     Geom::Matrix transform;
125     SPClipPathReference *clip_ref;
126     SPMaskReference *mask_ref;
128     // Used for object-avoiding connectors
129     SPAvoidRef *avoidRef;
131     SPItemView *display;
133     std::vector<SPGuideConstraint> constraints;
135     sigc::signal<void, Geom::Matrix const *, SPItem *> _transformed_signal;
137     void init();
138     bool isLocked() const;
139     void setLocked(bool lock);
141     bool isHidden() const;
142     void setHidden(bool hidden);
144     bool isEvaluated() const;
145     void setEvaluated(bool visible);
146     void resetEvaluated();
148     bool isHidden(unsigned display_key) const;
150     bool isExplicitlyHidden() const;
152     void setExplicitlyHidden(bool val);
154     void setCenter(Geom::Point object_centre);
155     void unsetCenter();
156     bool isCenterSet();
157     Geom::Point getCenter() const;
159     bool isVisibleAndUnlocked() const;
161     bool isVisibleAndUnlocked(unsigned display_key) const;
163     Geom::Matrix getRelativeTransform(SPObject const *obj) const;
165     void raiseOne();
166     void lowerOne();
167     void raiseToTop();
168     void lowerToBottom();
170     Geom::OptRect getBounds(Geom::Matrix const &transform, BBoxType type=APPROXIMATE_BBOX, unsigned int dkey=0) const;
172     sigc::connection _clip_ref_connection;
173     sigc::connection _mask_ref_connection;
175     sigc::connection connectTransformed(sigc::slot<void, Geom::Matrix const *, SPItem *> slot)  {
176         return _transformed_signal.connect(slot);
177     }
178     void invoke_bbox( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
179     void invoke_bbox( NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
180     void invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) const;
181     void invoke_bbox_full( NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) __attribute__ ((deprecated));
183     unsigned pos_in_parent();
184     gchar *description();
185     void invoke_print(SPPrintContext *ctx);
186     static unsigned int display_key_new(unsigned int numkeys);
187     NRArenaItem *invoke_show(NRArena *arena, unsigned int key, unsigned int flags);
188     void invoke_hide(unsigned int key);
189     void getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs=0) const;
190     void adjust_pattern(/* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
191     void adjust_gradient(/* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
192     void adjust_stroke(gdouble ex);
193     void adjust_stroke_width_recursive(gdouble ex);
194     void adjust_paint_recursive(Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern);
195     void adjust_livepatheffect(Geom::Matrix const &postmul, bool set = false);
196     void doWriteTransform(Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv = NULL, bool compensate = true);
197     void set_item_transform(Geom::Matrix const &transform_matrix);
198     void convert_item_to_guides();
199     gint emitEvent (SPEvent &event);
200     NRArenaItem *get_arenaitem(unsigned int key);
201     void getBboxDesktop(NRRect *bbox, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
202     Geom::OptRect getBboxDesktop(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
203     Geom::Matrix i2doc_affine() const;
204     Geom::Matrix i2d_affine() const;
205     void set_i2d_affine(Geom::Matrix const &transform);
206     Geom::Matrix dt2i_affine() const;
207     void convert_to_guides();
209 private:
210     enum EvaluatedStatus
211     {
212         StatusUnknown, StatusCalculated, StatusSet
213     };
215     mutable bool _is_evaluated;
216     mutable EvaluatedStatus _evaluated_status;
218     static void sp_item_init(SPItem *item);
220     static void sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
221     static void sp_item_release(SPObject *object);
222     static void sp_item_set(SPObject *object, unsigned key, gchar const *value);
223     static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
224     static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
226     static gchar *sp_item_private_description(SPItem *item);
227     static void sp_item_private_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
229     static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
230     static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
231     static void clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item);
232     static void mask_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item);
234     friend class SPItemClass;
235 };
237 /// The SPItem vtable.
238 class SPItemClass {
239 public:
240     SPObjectClass parent_class;
242     /** BBox union in given coordinate system */
243     void (* bbox) (SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
245     /** Printing method. Assumes ctm is set to item affine matrix */
246     /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
247     void (* print) (SPItem *item, SPPrintContext *ctx);
249     /** Give short description of item (for status display) */
250     gchar * (* description) (SPItem * item);
252     NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
253     void (* hide) (SPItem *item, unsigned int key);
255     /** Write to an iterator the points that should be considered for snapping
256      * as the item's `nodes'.
257      */
258     void (* snappoints) (SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
260     /** Apply the transform optimally, and return any residual transformation */
261     Geom::Matrix (* set_transform)(SPItem *item, Geom::Matrix const &transform);
263     /** Convert the item to guidelines */
264     void (* convert_to_guides)(SPItem *item);
266     /** Emit event, if applicable */
267     gint (* event) (SPItem *item, SPEvent *event);
269         private:
270         static SPObjectClass *static_parent_class;
271         static void sp_item_class_init(SPItemClass *klass);
273         friend class SPItem;
274 };
276 // Utility
278 Geom::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
279 Geom::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
281 /* fixme: - these are evil, but OK */
283 /* Fill *TRANSFORM with the item-to-desktop transform.  See doc/coordinates.txt
284  * for a description of `Desktop coordinates'; though see also mental's comment
285  * at the top of that file.
286  *
287  * \return TRANSFORM.
288  */
289 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
290 SPItem *sp_item_first_item_child (SPObject *obj);
292 #endif // SEEN_SP_ITEM_H
294 /*
295   Local Variables:
296   mode:c++
297   c-file-style:"stroustrup"
298   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
299   indent-tabs-mode:nil
300   fill-column:99
301   End:
302 */
303 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :