1 /* This file is part of Ganv.
2  * Copyright 2007-2016 David Robillard <http://drobilla.net>
3  *
4  * Ganv is free software: you can redistribute it and/or modify it under the
5  * terms of the GNU General Public License as published by the Free Software
6  * Foundation, either version 3 of the License, or any later version.
7  *
8  * Ganv is distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with Ganv.  If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 /* Based on GnomeCanvas, by Federico Mena <federico@nuclecu.unam.mx>
17  * and Raph Levien <raph@gimp.org>
18  * Copyright 1997-2000 Free Software Foundation
19  */
20 
21 #ifndef GANV_ITEM_H
22 #define GANV_ITEM_H
23 
24 #include <cairo.h>
25 #include <gdk/gdk.h>
26 #include <glib-object.h>
27 #include <glib.h>
28 #include <gtk/gtk.h>
29 
30 #include <stdarg.h>
31 
32 G_BEGIN_DECLS
33 
34 struct _GanvItem;
35 struct _GanvItemClass;
36 
37 typedef struct _GanvItem        GanvItem;
38 typedef struct _GanvItemPrivate GanvItemPrivate;
39 typedef struct _GanvItemClass   GanvItemClass;
40 
41 /* Object flags for items */
42 enum {
43 	GANV_ITEM_REALIZED      = 1 << 1,
44 	GANV_ITEM_MAPPED        = 1 << 2,
45 	GANV_ITEM_ALWAYS_REDRAW = 1 << 3,
46 	GANV_ITEM_VISIBLE       = 1 << 4,
47 	GANV_ITEM_NEED_UPDATE   = 1 << 5,
48 	GANV_ITEM_NEED_VIS      = 1 << 6
49 };
50 
51 #define GANV_TYPE_ITEM            (ganv_item_get_type())
52 #define GANV_ITEM(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GANV_TYPE_ITEM, GanvItem))
53 #define GANV_ITEM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GANV_TYPE_ITEM, GanvItemClass))
54 #define GANV_IS_ITEM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GANV_TYPE_ITEM))
55 #define GANV_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GANV_TYPE_ITEM))
56 #define GANV_ITEM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GANV_TYPE_ITEM, GanvItemClass))
57 
58 struct _GanvItem {
59 	GtkObject        object;
60 	GanvItemPrivate* impl;
61 };
62 
63 struct _GanvItemClass {
64 	GtkObjectClass parent_class;
65 
66 	/* Add a child to this item (optional). */
67 	void (*add)(GanvItem* item, GanvItem* child);
68 
69 	/* Remove a child from this item (optional). */
70 	void (*remove)(GanvItem* item, GanvItem* child);
71 
72 	/* Tell the item to update itself.
73 	 *
74 	 * The flags are from the update flags defined above.  The item should
75 	 * update its internal state from its queued state, and recompute and
76 	 * request its repaint area.  The update method also recomputes the
77 	 * bounding box of the item.
78 	 */
79 	void (*update)(GanvItem* item, int flags);
80 
81 	/* Realize an item (create GCs, etc.). */
82 	void (*realize)(GanvItem* item);
83 
84 	/* Unrealize an item. */
85 	void (*unrealize)(GanvItem* item);
86 
87 	/* Map an item - normally only need by items with their own GdkWindows. */
88 	void (*map)(GanvItem* item);
89 
90 	/* Unmap an item */
91 	void (*unmap)(GanvItem* item);
92 
93 	/* Draw an item of this type.
94 	 *
95 	 * (cx, cy) and (width, height) describe the rectangle being drawn in
96 	 * world-relative coordinates.
97 	 */
98 	void (*draw)(GanvItem* item,
99 	             cairo_t*  cr,
100 	             double    cx,
101 	             double    cy,
102 	             double    cw,
103 	             double    ch);
104 
105 	/* Calculate the distance from an item to the specified point.
106 	 *
107 	 * It also returns a canvas item which is actual item the point is within,
108 	 * which may not be equal to @item if @item has children.
109 	 * (x, y) are item-relative coordinates.
110 	 */
111 	double (*point)(GanvItem*  item,
112 	                double     x,
113 	                double     y,
114 	                GanvItem** actual_item);
115 
116 	/* Fetch the item's bounding box (need not be exactly tight).
117 	 *
118 	 * This should be in item-relative coordinates.
119 	 */
120 	void (*bounds)(GanvItem* item, double* x1, double* y1, double* x2, double* y2);
121 
122 	/* Signal: an event occurred for an item of this type.
123 	 *
124 	 * The (x, y) coordinates are in the canvas world coordinate system.
125 	 */
126 	gboolean (*event)(GanvItem* item, GdkEvent* event);
127 
128 	/* Reserved for future expansion */
129 	gpointer spare_vmethods[4];
130 };
131 
132 GType ganv_item_get_type(void) G_GNUC_CONST;
133 
134 GanvItem* ganv_item_new(GanvItem* parent, GType type,
135                         const gchar* first_arg_name, ...);
136 
137 void ganv_item_construct(GanvItem* item, GanvItem* parent,
138                          const gchar* first_arg_name, va_list args);
139 
140 void ganv_item_set(GanvItem* item, const gchar* first_arg_name, ...);
141 
142 void ganv_item_set_valist(GanvItem* item,
143                           const gchar* first_arg_name, va_list args);
144 
145 /**
146  * ganv_item_get_canvas:
147  * @item: The item.
148  *
149  * Return value: (transfer none): The canvas @item is on.
150  */
151 struct _GanvCanvas* ganv_item_get_canvas(GanvItem* item);
152 
153 /**
154  * ganv_item_get_parent:
155  * @item: The item.
156  *
157  * Return value: (transfer none): The parent of @item.
158  */
159 GanvItem* ganv_item_get_parent(GanvItem* item);
160 
161 void ganv_item_raise(GanvItem* item);
162 
163 void ganv_item_lower(GanvItem* item);
164 
165 void ganv_item_move(GanvItem* item, double dx, double dy);
166 
167 void ganv_item_show(GanvItem* item);
168 
169 void ganv_item_hide(GanvItem* item);
170 
171 void ganv_item_i2w(GanvItem* item, double* x, double* y);
172 
173 void ganv_item_w2i(GanvItem* item, double* x, double* y);
174 
175 void ganv_item_grab_focus(GanvItem* item);
176 
177 void ganv_item_get_bounds(GanvItem* item,
178                           double* x1, double* y1, double* x2, double* y2);
179 
180 void ganv_item_request_update(GanvItem* item);
181 
182 void ganv_item_set_wrapper(GanvItem* item, void* wrapper);
183 
184 void* ganv_item_get_wrapper(GanvItem* item);
185 
186 G_END_DECLS
187 
188 #endif  /* GANV_ITEM_H */
189