1 #ifndef __SP_KNOT_H__
2 #define __SP_KNOT_H__
4 /** \file
5 * Declarations for SPKnot: Desktop-bound visual control object.
6 */
7 /*
8 * Authors:
9 * Lauris Kaplinski <lauris@kaplinski.com>
10 *
11 * Copyright (C) 1999-2002 authors
12 * Copyright (C) 2001-2002 Ximian, Inc.
13 *
14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */
17 #include <gdk/gdk.h>
18 #include <gtk/gtkenums.h>
19 #include "display/display-forward.h"
20 #include "forward.h"
21 #include <libnr/nr-point.h>
22 #include "knot-enums.h"
24 class SPKnot;
25 class SPKnotClass;
27 #define SP_TYPE_KNOT (sp_knot_get_type())
28 #define SP_KNOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_KNOT, SPKnot))
29 #define SP_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_KNOT, SPKnotClass))
30 #define SP_IS_KNOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_KNOT))
31 #define SP_IS_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_KNOT))
33 /**
34 * Desktop-bound visual control object.
35 *
36 * A knot is a draggable object, with callbacks to change something by
37 * dragging it, visuably represented by a canvas item (mostly square).
38 */
39 struct SPKnot {
40 GObject object;
41 SPDesktop *desktop; /**< Desktop we are on. */
42 SPCanvasItem *item; /**< Our CanvasItem. */
43 guint flags;
45 guint size; /**< Always square. */
46 NR::Point pos; /**< Our desktop coordinates. */
47 NR::Point grabbed_rel_pos; /**< Grabbed relative position. */
48 NR::Point drag_origin; /**< Origin of drag. */
49 GtkAnchorType anchor; /**< Anchor. */
51 SPKnotShapeType shape; /**< Shape type. */
52 SPKnotModeType mode;
54 guint32 fill[SP_KNOT_VISIBLE_STATES];
55 guint32 stroke[SP_KNOT_VISIBLE_STATES];
56 guchar *image[SP_KNOT_VISIBLE_STATES];
58 GdkCursor *cursor[SP_KNOT_VISIBLE_STATES];
60 GdkCursor *saved_cursor;
61 gpointer pixbuf;
63 gchar *tip;
65 //TODO: all the members above should eventualle become private, accessible via setters/getters
66 void inline setSize (guint i) {size = i;}
67 void inline setShape (guint i) {shape = (SPKnotShapeType) i;}
68 void inline setAnchor (guint i) {anchor = (GtkAnchorType) i;}
69 void inline setMode (guint i) {mode = (SPKnotModeType) i;}
70 void inline setPixbuf (gpointer p) {pixbuf = p;}
71 void inline setFill (guint32 normal, guint32 mouseover, guint32 dragging) {
72 fill[SP_KNOT_STATE_NORMAL] = normal;
73 fill[SP_KNOT_STATE_MOUSEOVER] = mouseover;
74 fill[SP_KNOT_STATE_DRAGGING] = dragging;
75 }
76 void inline setStroke (guint32 normal, guint32 mouseover, guint32 dragging) {
77 stroke[SP_KNOT_STATE_NORMAL] = normal;
78 stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover;
79 stroke[SP_KNOT_STATE_DRAGGING] = dragging;
80 }
81 void inline setImage (guchar* normal, guchar* mouseover, guchar* dragging) {
82 image[SP_KNOT_STATE_NORMAL] = normal;
83 image[SP_KNOT_STATE_MOUSEOVER] = mouseover;
84 image[SP_KNOT_STATE_DRAGGING] = dragging;
85 }
86 void inline setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) {
87 if (cursor[SP_KNOT_STATE_NORMAL]) {
88 gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]);
89 }
90 cursor[SP_KNOT_STATE_NORMAL] = normal;
91 if (normal) {
92 gdk_cursor_ref(normal);
93 }
95 if (cursor[SP_KNOT_STATE_MOUSEOVER]) {
96 gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
97 }
98 cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover;
99 if (mouseover) {
100 gdk_cursor_ref(mouseover);
101 }
103 if (cursor[SP_KNOT_STATE_DRAGGING]) {
104 gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]);
105 }
106 cursor[SP_KNOT_STATE_DRAGGING] = dragging;
107 if (dragging) {
108 gdk_cursor_ref(dragging);
109 }
110 }
112 };
114 /// The SPKnot vtable.
115 struct SPKnotClass {
116 GObjectClass parent_class;
118 gint (* event) (SPKnot *knot, GdkEvent *event);
120 /*
121 * These are unconditional.
122 */
124 void (* clicked) (SPKnot *knot, guint state);
125 void (* doubleclicked) (SPKnot *knot, guint state);
126 void (* grabbed) (SPKnot *knot, guint state);
127 void (* ungrabbed) (SPKnot *knot, guint state);
128 void (* moved) (SPKnot *knot, NR::Point *position, guint state);
129 void (* stamped) (SPKnot *know, guint state);
131 /** Request knot to move to absolute position. */
132 bool (* request) (SPKnot *knot, NR::Point *pos, guint state);
134 /** Find complex distance from knot to point. */
135 gdouble (* distance) (SPKnot *knot, NR::Point *pos, guint state);
136 };
138 GType sp_knot_get_type();
140 SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL);
142 #define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0)
143 #define SP_KNOT_IS_MOSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0)
144 #define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0)
145 #define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0)
147 void sp_knot_show(SPKnot *knot);
148 void sp_knot_hide(SPKnot *knot);
150 void sp_knot_update_ctrl(SPKnot *knot);
152 void sp_knot_request_position(SPKnot *knot, NR::Point *pos, guint state);
153 gdouble sp_knot_distance(SPKnot *knot, NR::Point *p, guint state);
155 void sp_knot_start_dragging(SPKnot *knot, NR::Point p, gint x, gint y, guint32 etime);
157 /** Moves knot and emits "moved" signal. */
158 void sp_knot_set_position(SPKnot *knot, NR::Point *p, guint state);
160 /** Moves knot without any signal. */
161 void sp_knot_moveto(SPKnot *knot, NR::Point *p);
163 NR::Point sp_knot_position(SPKnot const *knot);
166 #endif /* !__SP_KNOT_H__ */
168 /*
169 Local Variables:
170 mode:c++
171 c-file-style:"stroustrup"
172 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
173 indent-tabs-mode:nil
174 fill-column:99
175 End:
176 */
177 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :