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 gulong _event_handler_id;
67 //TODO: all the members above should eventualle become private, accessible via setters/getters
68 inline void setSize (guint i) {size = i;}
69 inline void setShape (guint i) {shape = (SPKnotShapeType) i;}
70 inline void setAnchor (guint i) {anchor = (GtkAnchorType) i;}
71 inline void setMode (guint i) {mode = (SPKnotModeType) i;}
72 inline void setPixbuf (gpointer p) {pixbuf = p;}
73 inline void setFill (guint32 normal, guint32 mouseover, guint32 dragging) {
74 fill[SP_KNOT_STATE_NORMAL] = normal;
75 fill[SP_KNOT_STATE_MOUSEOVER] = mouseover;
76 fill[SP_KNOT_STATE_DRAGGING] = dragging;
77 }
78 inline void setStroke (guint32 normal, guint32 mouseover, guint32 dragging) {
79 stroke[SP_KNOT_STATE_NORMAL] = normal;
80 stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover;
81 stroke[SP_KNOT_STATE_DRAGGING] = dragging;
82 }
83 inline void setImage (guchar* normal, guchar* mouseover, guchar* dragging) {
84 image[SP_KNOT_STATE_NORMAL] = normal;
85 image[SP_KNOT_STATE_MOUSEOVER] = mouseover;
86 image[SP_KNOT_STATE_DRAGGING] = dragging;
87 }
88 inline void setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) {
89 if (cursor[SP_KNOT_STATE_NORMAL]) {
90 gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]);
91 }
92 cursor[SP_KNOT_STATE_NORMAL] = normal;
93 if (normal) {
94 gdk_cursor_ref(normal);
95 }
97 if (cursor[SP_KNOT_STATE_MOUSEOVER]) {
98 gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
99 }
100 cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover;
101 if (mouseover) {
102 gdk_cursor_ref(mouseover);
103 }
105 if (cursor[SP_KNOT_STATE_DRAGGING]) {
106 gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]);
107 }
108 cursor[SP_KNOT_STATE_DRAGGING] = dragging;
109 if (dragging) {
110 gdk_cursor_ref(dragging);
111 }
112 }
114 };
116 /// The SPKnot vtable.
117 struct SPKnotClass {
118 GObjectClass parent_class;
120 gint (* event) (SPKnot *knot, GdkEvent *event);
122 /*
123 * These are unconditional.
124 */
126 void (* clicked) (SPKnot *knot, guint state);
127 void (* doubleclicked) (SPKnot *knot, guint state);
128 void (* grabbed) (SPKnot *knot, guint state);
129 void (* ungrabbed) (SPKnot *knot, guint state);
130 void (* moved) (SPKnot *knot, NR::Point *position, guint state);
131 void (* stamped) (SPKnot *know, guint state);
133 /** Request knot to move to absolute position. */
134 bool (* request) (SPKnot *knot, NR::Point *pos, guint state);
136 /** Find complex distance from knot to point. */
137 gdouble (* distance) (SPKnot *knot, NR::Point *pos, guint state);
138 };
140 GType sp_knot_get_type();
142 SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL);
144 #define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0)
145 #define SP_KNOT_IS_MOSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0)
146 #define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0)
147 #define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0)
149 void sp_knot_show(SPKnot *knot);
150 void sp_knot_hide(SPKnot *knot);
152 void sp_knot_update_ctrl(SPKnot *knot);
154 void sp_knot_request_position(SPKnot *knot, NR::Point *pos, guint state);
155 gdouble sp_knot_distance(SPKnot *knot, NR::Point *p, guint state);
157 void sp_knot_start_dragging(SPKnot *knot, NR::Point p, gint x, gint y, guint32 etime);
159 /** Moves knot and emits "moved" signal. */
160 void sp_knot_set_position(SPKnot *knot, NR::Point *p, guint state);
162 /** Moves knot without any signal. */
163 void sp_knot_moveto(SPKnot *knot, NR::Point *p);
165 NR::Point sp_knot_position(SPKnot const *knot);
168 #endif /* !__SP_KNOT_H__ */
170 /*
171 Local Variables:
172 mode:c++
173 c-file-style:"stroustrup"
174 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
175 indent-tabs-mode:nil
176 fill-column:99
177 End:
178 */
179 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :