1 /* 2 * GooCanvas. Copyright (C) 2005 Damon Chaplin. 3 * Released under the GNU LGPL license. See COPYING for details. 4 * 5 * goocanvas.h - the main canvas widget. 6 */ 7 #ifndef __GOO_CANVAS_H__ 8 #define __GOO_CANVAS_H__ 9 10 #include <gtk/gtk.h> 11 #include <goocanvasenumtypes.h> 12 #include <goocanvasellipse.h> 13 #include <goocanvasgrid.h> 14 #include <goocanvasgroup.h> 15 #include <goocanvasimage.h> 16 #include <goocanvaspath.h> 17 #include <goocanvaspolyline.h> 18 #include <goocanvasrect.h> 19 #include <goocanvastable.h> 20 #include <goocanvastext.h> 21 #include <goocanvaswidget.h> 22 23 G_BEGIN_DECLS 24 25 26 #define GOO_TYPE_CANVAS (goo_canvas_get_type ()) 27 #define GOO_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS, GooCanvas)) 28 #define GOO_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS, GooCanvasClass)) 29 #define GOO_IS_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS)) 30 #define GOO_IS_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS)) 31 #define GOO_CANVAS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS, GooCanvasClass)) 32 33 34 typedef struct _GooCanvasClass GooCanvasClass; 35 36 /** 37 * GooCanvas: 38 * 39 * The #GooCanvas-struct struct contains private data only. 40 */ 41 struct _GooCanvas 42 { 43 GtkContainer container; 44 45 /* The model for the root item, in model/view mode. */ 46 GooCanvasItemModel *root_item_model; 47 48 /* The root canvas item. */ 49 GooCanvasItem *root_item; 50 51 /* The bounds of the canvas, in canvas units (not pixels). */ 52 GooCanvasBounds bounds; 53 54 /* The scale/zoom factors of the canvas. */ 55 gdouble scale_x, scale_y; 56 57 /* The minimum of scale_x and scale_y, to compare with items' visibility 58 thresholds. */ 59 gdouble scale; 60 61 /* Where the canvas is anchored (where it is displayed when it is smaller 62 than the entire window). */ 63 GooCanvasAnchorType anchor; 64 65 /* Idle handler ID, for processing updates. */ 66 guint idle_id; 67 68 /* This is TRUE if some item in the canvas needs an update. */ 69 guint need_update : 1; 70 71 /* This is TRUE if all items in the canvas need to be updated. */ 72 guint need_entire_subtree_update : 1; 73 74 /* This is TRUE if all layout should be done to the nearest integer. */ 75 guint integer_layout : 1; 76 77 /* This is TRUE if the bounds are calculated automatically, using the bounds 78 of all the items in the canvas. */ 79 guint automatic_bounds : 1; 80 81 /* This is TRUE if the automatic bounds are calculated from the origin. */ 82 guint bounds_from_origin : 1; 83 84 /* This is TRUE if the background is cleared before painting the canvas. */ 85 guint clear_background : 1; 86 87 /* This is TRUE if the canvas is completely redrawn when scrolled. It is 88 useful when there are sticky items to reduce flicker, but is slower. */ 89 guint redraw_when_scrolled : 1; 90 91 /* If the canvas hasn't received the initial draw signal yet. */ 92 guint before_initial_draw : 1; 93 94 /* GtkScrollablePolicy for each adjustment. */ 95 guint hscroll_policy : 1; 96 guint vscroll_policy : 1; 97 98 /* This is the padding around the automatic bounds. */ 99 gdouble bounds_padding; 100 101 /* The item that the mouse is over. */ 102 GooCanvasItem *pointer_item; 103 104 /* The item that has the pointer grab, or NULL. */ 105 GooCanvasItem *pointer_grab_item; 106 107 /* This is the item that the grab was started from. When the grab ends 108 we synthesize enter/leave notify events from this item. */ 109 GooCanvasItem *pointer_grab_initial_item; 110 111 /* This is the mouse button that started an implicit pointer grab. 112 When the same button is released the implicit grab ends. */ 113 guint pointer_grab_button; 114 115 /* The item that has the keyboard focus, or NULL. */ 116 GooCanvasItem *focused_item; 117 118 /* The item that has the keyboard grab, or NULL. */ 119 GooCanvasItem *keyboard_grab_item; 120 121 /* The synthesized event used for sending enter-notify and leave-notify 122 events to items. */ 123 GdkEventCrossing crossing_event; 124 125 /* The main canvas window, which gets scrolled around. */ 126 GdkWindow *canvas_window; 127 128 /* The offsets of the canvas within the canvas window, in pixels. These are 129 used when the canvas is smaller than the window size and the anchor is not 130 NORTH_WEST. */ 131 gint canvas_x_offset; 132 gint canvas_y_offset; 133 134 /* The adjustments used for scrolling. */ 135 GtkAdjustment *hadjustment; 136 GtkAdjustment *vadjustment; 137 138 /* Freezes any movement of the canvas window, until thawed. This is used 139 when we need to set both adjustments and don't want it to scroll twice. */ 140 gint freeze_count; 141 142 /* A window temporarily mapped above the canvas to stop X from scrolling 143 the contents unnecessarily (i.e. when we zoom in/out). */ 144 GdkWindow *tmp_window; 145 146 /* A hash table mapping canvas item models to canvas items. */ 147 GHashTable *model_to_item; 148 149 /* The units of the canvas, which applies to all item coords. */ 150 GtkUnit units; 151 152 /* The horizontal and vertical resolution of the display, in dots per inch. 153 This is only needed when units other than pixels are used. */ 154 gdouble resolution_x, resolution_y; 155 156 /* The multiplers to convert from device units to pixels, taking into account 157 the canvas scale, the units setting and the display resolution. */ 158 gdouble device_to_pixels_x, device_to_pixels_y; 159 160 /* The list of child widgets (using GooCanvasWidget items). */ 161 GList *widget_items; 162 }; 163 164 /** 165 * GooCanvasClass: 166 * @create_item: a virtual method that subclasses may override to create custom 167 * canvas items for item models. 168 * @item_created: signal emitted when a new canvas item has been created. 169 * Applications can connect to this to setup signal handlers for the new item. 170 * 171 * The #GooCanvasClass-struct struct contains one virtual method that 172 * subclasses may override. 173 */ 174 struct _GooCanvasClass 175 { 176 /*< private >*/ 177 GtkContainerClass parent_class; 178 179 /* Virtual methods. */ 180 /*< public >*/ 181 GooCanvasItem* (* create_item) (GooCanvas *canvas, 182 GooCanvasItemModel *model); 183 184 /* Signals. */ 185 void (* item_created) (GooCanvas *canvas, 186 GooCanvasItem *item, 187 GooCanvasItemModel *model); 188 189 /*< private >*/ 190 191 /* Padding for future expansion */ 192 void (*_goo_canvas_reserved1) (void); 193 void (*_goo_canvas_reserved2) (void); 194 void (*_goo_canvas_reserved3) (void); 195 void (*_goo_canvas_reserved4) (void); 196 void (*_goo_canvas_reserved5) (void); 197 void (*_goo_canvas_reserved6) (void); 198 void (*_goo_canvas_reserved7) (void); 199 void (*_goo_canvas_reserved8) (void); 200 }; 201 202 203 GType goo_canvas_get_type (void) G_GNUC_CONST; 204 GtkWidget* goo_canvas_new (void); 205 206 GooCanvasItem* goo_canvas_get_root_item (GooCanvas *canvas); 207 void goo_canvas_set_root_item (GooCanvas *canvas, 208 GooCanvasItem *item); 209 210 GooCanvasItemModel* goo_canvas_get_root_item_model (GooCanvas *canvas); 211 void goo_canvas_set_root_item_model (GooCanvas *canvas, 212 GooCanvasItemModel *model); 213 214 GooCanvasItem* goo_canvas_get_static_root_item (GooCanvas *canvas); 215 void goo_canvas_set_static_root_item (GooCanvas *canvas, 216 GooCanvasItem *item); 217 218 GooCanvasItemModel* goo_canvas_get_static_root_item_model (GooCanvas *canvas); 219 void goo_canvas_set_static_root_item_model (GooCanvas *canvas, 220 GooCanvasItemModel *model); 221 222 GooCanvasItem* goo_canvas_get_item (GooCanvas *canvas, 223 GooCanvasItemModel *model); 224 GooCanvasItem* goo_canvas_get_item_at (GooCanvas *canvas, 225 gdouble x, 226 gdouble y, 227 gboolean is_pointer_event); 228 GList* goo_canvas_get_items_at (GooCanvas *canvas, 229 gdouble x, 230 gdouble y, 231 gboolean is_pointer_event); 232 GList* goo_canvas_get_items_in_area(GooCanvas *canvas, 233 const GooCanvasBounds *area, 234 gboolean inside_area, 235 gboolean allow_overlaps, 236 gboolean include_containers); 237 238 gdouble goo_canvas_get_scale (GooCanvas *canvas); 239 void goo_canvas_set_scale (GooCanvas *canvas, 240 gdouble scale); 241 242 void goo_canvas_get_bounds (GooCanvas *canvas, 243 gdouble *left, 244 gdouble *top, 245 gdouble *right, 246 gdouble *bottom); 247 void goo_canvas_set_bounds (GooCanvas *canvas, 248 gdouble left, 249 gdouble top, 250 gdouble right, 251 gdouble bottom); 252 253 void goo_canvas_scroll_to (GooCanvas *canvas, 254 gdouble left, 255 gdouble top); 256 257 void goo_canvas_grab_focus (GooCanvas *canvas, 258 GooCanvasItem *item); 259 260 void goo_canvas_render (GooCanvas *canvas, 261 cairo_t *cr, 262 const GooCanvasBounds *bounds, 263 gdouble scale); 264 265 /* 266 * Coordinate conversion. 267 */ 268 void goo_canvas_convert_to_pixels (GooCanvas *canvas, 269 gdouble *x, 270 gdouble *y); 271 void goo_canvas_convert_from_pixels (GooCanvas *canvas, 272 gdouble *x, 273 gdouble *y); 274 275 void goo_canvas_convert_units_to_pixels (GooCanvas *canvas, 276 gdouble *x, 277 gdouble *y); 278 void goo_canvas_convert_units_from_pixels (GooCanvas *canvas, 279 gdouble *x, 280 gdouble *y); 281 282 void goo_canvas_convert_to_item_space (GooCanvas *canvas, 283 GooCanvasItem *item, 284 gdouble *x, 285 gdouble *y); 286 void goo_canvas_convert_from_item_space (GooCanvas *canvas, 287 GooCanvasItem *item, 288 gdouble *x, 289 gdouble *y); 290 void goo_canvas_convert_bounds_to_item_space (GooCanvas *canvas, 291 GooCanvasItem *item, 292 GooCanvasBounds *bounds); 293 294 295 /* 296 * Pointer/keyboard grabbing & ungrabbing. 297 */ 298 GdkGrabStatus goo_canvas_pointer_grab (GooCanvas *canvas, 299 GooCanvasItem *item, 300 GdkEventMask event_mask, 301 GdkCursor *cursor, 302 guint32 time); 303 void goo_canvas_pointer_ungrab (GooCanvas *canvas, 304 GooCanvasItem *item, 305 guint32 time); 306 GdkGrabStatus goo_canvas_keyboard_grab (GooCanvas *canvas, 307 GooCanvasItem *item, 308 gboolean owner_events, 309 guint32 time); 310 void goo_canvas_keyboard_ungrab (GooCanvas *canvas, 311 GooCanvasItem *item, 312 guint32 time); 313 314 315 /* 316 * Internal functions, mainly for canvas subclasses and item implementations. 317 */ 318 cairo_t* goo_canvas_create_cairo_context (GooCanvas *canvas); 319 GooCanvasItem* goo_canvas_create_item (GooCanvas *canvas, 320 GooCanvasItemModel *model); 321 void goo_canvas_unregister_item (GooCanvas *canvas, 322 GooCanvasItemModel *model); 323 void goo_canvas_update (GooCanvas *canvas); 324 void goo_canvas_request_update (GooCanvas *canvas); 325 void goo_canvas_request_redraw (GooCanvas *canvas, 326 const GooCanvasBounds *bounds); 327 void goo_canvas_request_item_redraw (GooCanvas *canvas, 328 const GooCanvasBounds *bounds, 329 gboolean is_static); 330 gdouble goo_canvas_get_default_line_width (GooCanvas *canvas); 331 332 333 void goo_canvas_register_widget_item (GooCanvas *canvas, 334 GooCanvasWidget *witem); 335 void goo_canvas_unregister_widget_item (GooCanvas *canvas, 336 GooCanvasWidget *witem); 337 338 339 G_END_DECLS 340 341 #endif /* __GOO_CANVAS_H__ */ 342