1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #ifndef __GTK_WIDGET_H__
19 #define __GTK_WIDGET_H__
23 #include <gtk/gtkaccelerator.h>
24 #include <gtk/gtkobject.h>
25 #include <gtk/gtkstyle.h>
30 #endif /* __cplusplus */
33 /* The flags that are used by GtkWidget on top of the
34 * flags field of GtkObject.
38 GTK_TOPLEVEL = 1 << 4,
39 GTK_NO_WINDOW = 1 << 5,
40 GTK_REALIZED = 1 << 6,
43 GTK_SENSITIVE = 1 << 9,
44 GTK_PARENT_SENSITIVE = 1 << 10,
45 GTK_CAN_FOCUS = 1 << 11,
46 GTK_HAS_FOCUS = 1 << 12,
47 GTK_CAN_DEFAULT = 1 << 13,
48 GTK_HAS_DEFAULT = 1 << 14,
49 GTK_HAS_GRAB = 1 << 15,
51 GTK_EXCLUSIVE_GRAB = 1 << 17,
52 GTK_RC_STYLE = 1 << 18
56 /* Macro for casting a pointer to a GtkWidget pointer.
58 #define GTK_WIDGET(wid) GTK_CHECK_CAST ((wid), gtk_widget_get_type (), GtkWidget)
60 /* Macro for casting the klass field of a widget to a GtkWidgetClass pointer.
62 #define GTK_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST ((klass), gtk_widget_get_type (), GtkWidgetClass)
64 /* Macros for extracting various fields from GtkWidget and GtkWidgetClass.
66 #define GTK_WIDGET_TYPE(wid) (GTK_OBJECT_TYPE (wid))
67 #define GTK_WIDGET_STATE(wid) (GTK_WIDGET (wid)->state)
68 #define GTK_WIDGET_SAVED_STATE(wid) (GTK_WIDGET (wid)->saved_state)
70 /* Macros for extracting the widget flags from GtkWidget.
72 #define GTK_WIDGET_FLAGS(wid) (GTK_OBJECT_FLAGS (wid))
73 #define GTK_WIDGET_TOPLEVEL(wid) (GTK_WIDGET_FLAGS (wid) & GTK_TOPLEVEL)
74 #define GTK_WIDGET_NO_WINDOW(wid) (GTK_WIDGET_FLAGS (wid) & GTK_NO_WINDOW)
75 #define GTK_WIDGET_REALIZED(wid) (GTK_WIDGET_FLAGS (wid) & GTK_REALIZED)
76 #define GTK_WIDGET_MAPPED(wid) (GTK_WIDGET_FLAGS (wid) & GTK_MAPPED)
77 #define GTK_WIDGET_VISIBLE(wid) (GTK_WIDGET_FLAGS (wid) & GTK_VISIBLE)
78 #define GTK_WIDGET_DRAWABLE(wid) (GTK_WIDGET_VISIBLE (wid) && GTK_WIDGET_MAPPED (wid))
79 #define GTK_WIDGET_SENSITIVE(wid) (GTK_WIDGET_FLAGS (wid) & GTK_SENSITIVE)
80 #define GTK_WIDGET_PARENT_SENSITIVE(wid) (GTK_WIDGET_FLAGS (wid) & GTK_PARENT_SENSITIVE)
81 #define GTK_WIDGET_IS_SENSITIVE(wid) ((GTK_WIDGET_SENSITIVE (wid) && \
82 GTK_WIDGET_PARENT_SENSITIVE (wid)) != 0)
83 #define GTK_WIDGET_CAN_FOCUS(wid) (GTK_WIDGET_FLAGS (wid) & GTK_CAN_FOCUS)
84 #define GTK_WIDGET_HAS_FOCUS(wid) (GTK_WIDGET_FLAGS (wid) & GTK_HAS_FOCUS)
85 #define GTK_WIDGET_CAN_DEFAULT(wid) (GTK_WIDGET_FLAGS (wid) & GTK_CAN_DEFAULT)
86 #define GTK_WIDGET_HAS_DEFAULT(wid) (GTK_WIDGET_FLAGS (wid) & GTK_HAS_DEFAULT)
87 #define GTK_WIDGET_HAS_GRAB(wid) (GTK_WIDGET_FLAGS (wid) & GTK_HAS_GRAB)
88 #define GTK_WIDGET_BASIC(wid) (GTK_WIDGET_FLAGS (wid) & GTK_BASIC)
89 #define GTK_WIDGET_EXCLUSIVE_GRAB(wid) (GTK_WIDGET_FLAGS (wid) & GTK_EXCLUSIVE_GRAB)
90 #define GTK_WIDGET_RC_STYLE(wid) (GTK_WIDGET_FLAGS (wid) & GTK_RC_STYLE)
92 /* Macros for setting and clearing widget flags.
94 #define GTK_WIDGET_SET_FLAGS(wid,flag) G_STMT_START{ (GTK_WIDGET_FLAGS (wid) |= (flag)); }G_STMT_END
95 #define GTK_WIDGET_UNSET_FLAGS(wid,flag) G_STMT_START{ (GTK_WIDGET_FLAGS (wid) &= ~(flag)); }G_STMT_END
97 /* Macros for testing whether "wid" is of type GtkWidget.
99 #define GTK_IS_WIDGET(wid) GTK_CHECK_TYPE ((wid), GTK_TYPE_WIDGET)
100 #define GTK_TYPE_WIDGET (gtk_widget_get_type ())
104 typedef struct _GtkRequisition GtkRequisition;
105 typedef struct _GtkAllocation GtkAllocation;
106 typedef struct _GtkSelectionData GtkSelectionData;
107 typedef struct _GtkWidget GtkWidget;
108 typedef struct _GtkWidgetClass GtkWidgetClass;
109 typedef struct _GtkWidgetAuxInfo GtkWidgetAuxInfo;
110 typedef struct _GtkWidgetShapeInfo GtkWidgetShapeInfo;
112 typedef void (*GtkCallback) (GtkWidget *widget,
115 /* A requisition is a desired amount of space which a
116 * widget may request.
118 struct _GtkRequisition
124 /* An allocation is a size and position. Where a widget
125 * can ask for a desired size, it is actually given
126 * this amount of space at the specified position.
128 struct _GtkAllocation
136 /* The contents of a selection are returned in a GtkSelectionData
137 structure. selection/target identify the request.
138 type specifies the type of the return; if length < 0, and
139 the data should be ignored. This structure has object semantics -
140 no fields should be modified directly, they should not be created
141 directly, and pointers to them should not be stored beyond the duration of
142 a callback. (If the last is changed, we'll need to add reference
145 struct _GtkSelectionData
155 /* The widget is the base of the tree for displayable objects.
156 * (A displayable object is one which takes up some amount
157 * of screen real estate). It provides a common base and interface
158 * which actual widgets must adhere to.
162 /* The object structure needs to be the first
163 * element in the widget structure in order for
164 * the object mechanism to work correctly. This
165 * allows a GtkWidget pointer to be cast to a
170 /* 16 bits of internally used private flags.
171 * this will be packed into the same 4 byte alignment frame that
172 * state and saved_state go. we therefore don't waste any new
175 guint16 private_flags;
177 /* The state of the widget. There are actually only
178 * 5 widget states (defined in "gtkenums.h").
182 /* The saved state of the widget. When a widgets state
183 * is changed to GTK_STATE_INSENSITIVE via
184 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
185 * the old state is kept around in this field. The state
186 * will be restored once the widget gets sensitive again.
190 /* The widgets name. If the widget does not have a name
191 * (the name is NULL), then its name (as returned by
192 * "gtk_widget_get_name") is its classes name.
193 * Among other things, the widget name is used to determine
194 * the style to use for a widget.
198 /* The style for the widget. The style contains the
199 * colors the widget should be drawn in for each state
200 * along with graphics contexts used to draw with and
201 * the font to use for text.
205 /* The widgets desired size.
207 GtkRequisition requisition;
209 /* The widgets allocated size.
211 GtkAllocation allocation;
213 /* The widgets window or its parent window if it does
214 * not have a window. (Which will be indicated by the
215 * GTK_NO_WINDOW flag being set).
219 /* The widgets parent.
224 struct _GtkWidgetClass
226 /* The object class structure needs to be the first
227 * element in the widget class structure in order for
228 * the class mechanism to work correctly. This allows a
229 * GtkWidgetClass pointer to be cast to a GtkObjectClass
232 GtkObjectClass parent_class;
234 /* The signal to emit when an object of this class is activated.
235 * This is used when activating the current focus widget and
236 * the default widget.
238 guint activate_signal;
241 void (* show) (GtkWidget *widget);
242 void (* hide) (GtkWidget *widget);
243 void (* show_all) (GtkWidget *widget);
244 void (* hide_all) (GtkWidget *widget);
245 void (* map) (GtkWidget *widget);
246 void (* unmap) (GtkWidget *widget);
247 void (* realize) (GtkWidget *widget);
248 void (* unrealize) (GtkWidget *widget);
249 void (* draw) (GtkWidget *widget,
251 void (* draw_focus) (GtkWidget *widget);
252 void (* draw_default) (GtkWidget *widget);
253 void (* size_request) (GtkWidget *widget,
254 GtkRequisition *requisition);
255 void (* size_allocate) (GtkWidget *widget,
256 GtkAllocation *allocation);
257 void (* state_changed) (GtkWidget *widget,
258 guint previous_state);
259 void (* parent_set) (GtkWidget *widget,
260 GtkWidget *previous_parent);
261 void (* style_set) (GtkWidget *widget,
262 GtkStyle *previous_style);
265 gint (* install_accelerator) (GtkWidget *widget,
266 const gchar *signal_name,
269 void (* remove_accelerator) (GtkWidget *widget,
270 const gchar *signal_name);
273 gint (* event) (GtkWidget *widget,
275 gint (* button_press_event) (GtkWidget *widget,
276 GdkEventButton *event);
277 gint (* button_release_event) (GtkWidget *widget,
278 GdkEventButton *event);
279 gint (* motion_notify_event) (GtkWidget *widget,
280 GdkEventMotion *event);
281 gint (* delete_event) (GtkWidget *widget,
283 gint (* destroy_event) (GtkWidget *widget,
285 gint (* expose_event) (GtkWidget *widget,
286 GdkEventExpose *event);
287 gint (* key_press_event) (GtkWidget *widget,
289 gint (* key_release_event) (GtkWidget *widget,
291 gint (* enter_notify_event) (GtkWidget *widget,
292 GdkEventCrossing *event);
293 gint (* leave_notify_event) (GtkWidget *widget,
294 GdkEventCrossing *event);
295 gint (* configure_event) (GtkWidget *widget,
296 GdkEventConfigure *event);
297 gint (* focus_in_event) (GtkWidget *widget,
298 GdkEventFocus *event);
299 gint (* focus_out_event) (GtkWidget *widget,
300 GdkEventFocus *event);
301 gint (* map_event) (GtkWidget *widget,
303 gint (* unmap_event) (GtkWidget *widget,
305 gint (* property_notify_event) (GtkWidget *widget,
306 GdkEventProperty *event);
307 gint (* selection_clear_event) (GtkWidget *widget,
308 GdkEventSelection *event);
309 gint (* selection_request_event) (GtkWidget *widget,
310 GdkEventSelection *event);
311 gint (* selection_notify_event) (GtkWidget *widget,
312 GdkEventSelection *event);
313 gint (* proximity_in_event) (GtkWidget *widget,
314 GdkEventProximity *event);
315 gint (* proximity_out_event) (GtkWidget *widget,
316 GdkEventProximity *event);
317 gint (* drag_begin_event) (GtkWidget *widget,
318 GdkEventDragBegin *event);
319 gint (* drag_request_event) (GtkWidget *widget,
320 GdkEventDragRequest *event);
321 gint (* drag_end_event) (GtkWidget *widget,
323 gint (* drop_enter_event) (GtkWidget *widget,
324 GdkEventDropEnter *event);
325 gint (* drop_leave_event) (GtkWidget *widget,
326 GdkEventDropLeave *event);
327 gint (* drop_data_available_event) (GtkWidget *widget,
328 GdkEventDropDataAvailable *event);
329 gint (* other_event) (GtkWidget *widget,
330 GdkEventOther *event);
333 void (* selection_received) (GtkWidget *widget,
334 GtkSelectionData *selection_data);
336 gint (* client_event) (GtkWidget *widget,
337 GdkEventClient *event);
338 gint (* no_expose_event) (GtkWidget *widget,
342 struct _GtkWidgetAuxInfo
350 struct _GtkWidgetShapeInfo
354 GdkBitmap *shape_mask;
358 guint gtk_widget_get_type (void);
359 GtkWidget* gtk_widget_new (guint type,
361 GtkWidget* gtk_widget_newv (guint type,
364 void gtk_widget_ref (GtkWidget *widget);
365 void gtk_widget_unref (GtkWidget *widget);
366 void gtk_widget_destroy (GtkWidget *widget);
367 void gtk_widget_destroyed (GtkWidget *widget,
368 GtkWidget **widget_pointer);
369 void gtk_widget_get (GtkWidget *widget,
371 void gtk_widget_getv (GtkWidget *widget,
374 void gtk_widget_set (GtkWidget *widget,
376 void gtk_widget_setv (GtkWidget *widget,
379 void gtk_widget_unparent (GtkWidget *widget);
380 void gtk_widget_show (GtkWidget *widget);
381 void gtk_widget_hide (GtkWidget *widget);
382 void gtk_widget_show_all (GtkWidget *widget);
383 void gtk_widget_hide_all (GtkWidget *widget);
384 void gtk_widget_map (GtkWidget *widget);
385 void gtk_widget_unmap (GtkWidget *widget);
386 void gtk_widget_realize (GtkWidget *widget);
387 void gtk_widget_unrealize (GtkWidget *widget);
388 void gtk_widget_queue_draw (GtkWidget *widget);
389 void gtk_widget_queue_resize (GtkWidget *widget);
390 void gtk_widget_draw (GtkWidget *widget,
392 void gtk_widget_draw_focus (GtkWidget *widget);
393 void gtk_widget_draw_default (GtkWidget *widget);
394 void gtk_widget_draw_children (GtkWidget *widget);
395 void gtk_widget_size_request (GtkWidget *widget,
396 GtkRequisition *requisition);
397 void gtk_widget_size_allocate (GtkWidget *widget,
398 GtkAllocation *allocation);
399 void gtk_widget_install_accelerator (GtkWidget *widget,
400 GtkAcceleratorTable *table,
401 const gchar *signal_name,
404 void gtk_widget_remove_accelerator (GtkWidget *widget,
405 GtkAcceleratorTable *table,
406 const gchar *signal_name);
407 gint gtk_widget_event (GtkWidget *widget,
410 void gtk_widget_activate (GtkWidget *widget);
411 void gtk_widget_reparent (GtkWidget *widget,
412 GtkWidget *new_parent);
413 void gtk_widget_popup (GtkWidget *widget,
416 gint gtk_widget_intersect (GtkWidget *widget,
418 GdkRectangle *intersection);
419 gint gtk_widget_basic (GtkWidget *widget);
421 void gtk_widget_grab_focus (GtkWidget *widget);
422 void gtk_widget_grab_default (GtkWidget *widget);
424 void gtk_widget_set_name (GtkWidget *widget,
426 gchar* gtk_widget_get_name (GtkWidget *widget);
427 void gtk_widget_set_state (GtkWidget *widget,
429 void gtk_widget_set_sensitive (GtkWidget *widget,
431 void gtk_widget_set_parent (GtkWidget *widget,
433 void gtk_widget_set_parent_window (GtkWidget *widget,
434 GdkWindow *parent_window);
435 GdkWindow *gtk_widget_get_parent_window (GtkWidget *widget);
436 void gtk_widget_set_uposition (GtkWidget *widget,
439 void gtk_widget_set_usize (GtkWidget *widget,
442 void gtk_widget_set_events (GtkWidget *widget,
444 void gtk_widget_set_extension_events (GtkWidget *widget,
445 GdkExtensionMode mode);
447 GdkExtensionMode gtk_widget_get_extension_events (GtkWidget *widget);
448 GtkWidget* gtk_widget_get_toplevel (GtkWidget *widget);
449 GtkWidget* gtk_widget_get_ancestor (GtkWidget *widget,
450 GtkType widget_type);
451 GdkColormap* gtk_widget_get_colormap (GtkWidget *widget);
452 GdkVisual* gtk_widget_get_visual (GtkWidget *widget);
453 gint gtk_widget_get_events (GtkWidget *widget);
454 void gtk_widget_get_pointer (GtkWidget *widget,
458 gint gtk_widget_is_ancestor (GtkWidget *widget,
459 GtkWidget *ancestor);
460 gint gtk_widget_is_child (GtkWidget *widget,
463 /* Hide widget and return TRUE.
465 gint gtk_widget_hide_on_delete (GtkWidget *widget);
469 void gtk_widget_set_style (GtkWidget *widget,
471 void gtk_widget_set_rc_style (GtkWidget *widget);
472 void gtk_widget_ensure_style (GtkWidget *widget);
473 GtkStyle* gtk_widget_get_style (GtkWidget *widget);
474 void gtk_widget_restore_default_style (GtkWidget *widget);
476 /* Tell other Gtk applications to use the same default colors.
478 void gtk_widget_propagate_default_style (void);
480 /* Push/pop pairs, to change default values upon a widget's creation.
481 * This will override the values that got set by the
482 * gtk_widget_set_default_* () functions.
484 void gtk_widget_push_style (GtkStyle *style);
485 void gtk_widget_push_colormap (GdkColormap *cmap);
486 void gtk_widget_push_visual (GdkVisual *visual);
487 void gtk_widget_pop_style (void);
488 void gtk_widget_pop_colormap (void);
489 void gtk_widget_pop_visual (void);
491 /* Set certain default values to be used at widget creation time.
493 void gtk_widget_set_default_style (GtkStyle *style);
494 void gtk_widget_set_default_colormap (GdkColormap *colormap);
495 void gtk_widget_set_default_visual (GdkVisual *visual);
496 GtkStyle* gtk_widget_get_default_style (void);
497 GdkColormap* gtk_widget_get_default_colormap (void);
498 GdkVisual* gtk_widget_get_default_visual (void);
500 /* Counterpart to gdk_window_shape_combine_mask.
502 void gtk_widget_shape_combine_mask (GtkWidget *widget,
503 GdkBitmap *shape_mask,
507 /* When you get a drag_enter event, you can use this to tell Gtk of other
508 * items that are to be dragged as well...
510 void gtk_widget_dnd_drag_add (GtkWidget *widget);
512 /* These two functions enable drag and/or drop on a widget,
513 * and also let Gtk know what data types will be accepted (use MIME
514 * type naming, plus tacking "URL:" on the front for link dragging)
516 void gtk_widget_dnd_drag_set (GtkWidget *widget,
518 gchar **type_accept_list,
520 void gtk_widget_dnd_drop_set (GtkWidget *widget,
522 gchar **type_accept_list,
524 guint8 is_destructive_operation);
526 /* Used to reply to a DRAG_REQUEST event - if you don't want to
527 * give the data then pass in NULL for it
529 void gtk_widget_dnd_data_set (GtkWidget *widget,
532 gulong data_numbytes);
534 #if defined (GTK_TRACE_OBJECTS) && defined (__GNUC__)
535 # define gtk_widget_ref gtk_object_ref
536 # define gtk_widget_unref gtk_object_unref
537 #endif /* GTK_TRACE_OBJECTS && __GNUC__ */
542 #endif /* __cplusplus */
545 #endif /* __GTK_WIDGET_H__ */