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_RESERVED_3 = 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_RC_STYLE(wid) (GTK_WIDGET_FLAGS (wid) & GTK_RC_STYLE)
91 /* Macros for setting and clearing widget flags.
93 #define GTK_WIDGET_SET_FLAGS(wid,flag) G_STMT_START{ (GTK_WIDGET_FLAGS (wid) |= (flag)); }G_STMT_END
94 #define GTK_WIDGET_UNSET_FLAGS(wid,flag) G_STMT_START{ (GTK_WIDGET_FLAGS (wid) &= ~(flag)); }G_STMT_END
96 /* Macros for testing whether "wid" is of type GtkWidget.
98 #define GTK_IS_WIDGET(wid) GTK_CHECK_TYPE ((wid), GTK_TYPE_WIDGET)
99 #define GTK_TYPE_WIDGET (gtk_widget_get_type ())
103 typedef struct _GtkRequisition GtkRequisition;
104 typedef struct _GtkAllocation GtkAllocation;
105 typedef struct _GtkSelectionData GtkSelectionData;
106 typedef struct _GtkWidget GtkWidget;
107 typedef struct _GtkWidgetClass GtkWidgetClass;
108 typedef struct _GtkWidgetAuxInfo GtkWidgetAuxInfo;
109 typedef struct _GtkWidgetShapeInfo GtkWidgetShapeInfo;
111 typedef void (*GtkCallback) (GtkWidget *widget,
114 /* A requisition is a desired amount of space which a
115 * widget may request.
117 struct _GtkRequisition
123 /* An allocation is a size and position. Where a widget
124 * can ask for a desired size, it is actually given
125 * this amount of space at the specified position.
127 struct _GtkAllocation
135 /* The contents of a selection are returned in a GtkSelectionData
136 structure. selection/target identify the request.
137 type specifies the type of the return; if length < 0, and
138 the data should be ignored. This structure has object semantics -
139 no fields should be modified directly, they should not be created
140 directly, and pointers to them should not be stored beyond the duration of
141 a callback. (If the last is changed, we'll need to add reference
144 struct _GtkSelectionData
154 /* The widget is the base of the tree for displayable objects.
155 * (A displayable object is one which takes up some amount
156 * of screen real estate). It provides a common base and interface
157 * which actual widgets must adhere to.
161 /* The object structure needs to be the first
162 * element in the widget structure in order for
163 * the object mechanism to work correctly. This
164 * allows a GtkWidget pointer to be cast to a
169 /* 16 bits of internally used private flags.
170 * this will be packed into the same 4 byte alignment frame that
171 * state and saved_state go. we therefore don't waste any new
174 guint16 private_flags;
176 /* The state of the widget. There are actually only
177 * 5 widget states (defined in "gtkenums.h").
181 /* The saved state of the widget. When a widgets state
182 * is changed to GTK_STATE_INSENSITIVE via
183 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
184 * the old state is kept around in this field. The state
185 * will be restored once the widget gets sensitive again.
189 /* The widgets name. If the widget does not have a name
190 * (the name is NULL), then its name (as returned by
191 * "gtk_widget_get_name") is its classes name.
192 * Among other things, the widget name is used to determine
193 * the style to use for a widget.
197 /* The style for the widget. The style contains the
198 * colors the widget should be drawn in for each state
199 * along with graphics contexts used to draw with and
200 * the font to use for text.
204 /* The widgets desired size.
206 GtkRequisition requisition;
208 /* The widgets allocated size.
210 GtkAllocation allocation;
212 /* The widgets window or its parent window if it does
213 * not have a window. (Which will be indicated by the
214 * GTK_NO_WINDOW flag being set).
218 /* The widgets parent.
223 struct _GtkWidgetClass
225 /* The object class structure needs to be the first
226 * element in the widget class structure in order for
227 * the class mechanism to work correctly. This allows a
228 * GtkWidgetClass pointer to be cast to a GtkObjectClass
231 GtkObjectClass parent_class;
233 /* The signal to emit when an object of this class is activated.
234 * This is used when activating the current focus widget and
235 * the default widget.
237 gint activate_signal;
240 void (* show) (GtkWidget *widget);
241 void (* hide) (GtkWidget *widget);
242 void (* show_all) (GtkWidget *widget);
243 void (* hide_all) (GtkWidget *widget);
244 void (* map) (GtkWidget *widget);
245 void (* unmap) (GtkWidget *widget);
246 void (* realize) (GtkWidget *widget);
247 void (* unrealize) (GtkWidget *widget);
248 void (* draw) (GtkWidget *widget,
250 void (* draw_focus) (GtkWidget *widget);
251 void (* draw_default) (GtkWidget *widget);
252 void (* size_request) (GtkWidget *widget,
253 GtkRequisition *requisition);
254 void (* size_allocate) (GtkWidget *widget,
255 GtkAllocation *allocation);
256 void (* state_changed) (GtkWidget *widget,
257 guint previous_state);
258 void (* parent_set) (GtkWidget *widget,
259 GtkWidget *previous_parent);
260 void (* style_set) (GtkWidget *widget,
261 GtkStyle *previous_style);
264 gint (* install_accelerator) (GtkWidget *widget,
265 const gchar *signal_name,
268 void (* remove_accelerator) (GtkWidget *widget,
269 const gchar *signal_name);
272 gint (* event) (GtkWidget *widget,
274 gint (* button_press_event) (GtkWidget *widget,
275 GdkEventButton *event);
276 gint (* button_release_event) (GtkWidget *widget,
277 GdkEventButton *event);
278 gint (* motion_notify_event) (GtkWidget *widget,
279 GdkEventMotion *event);
280 gint (* delete_event) (GtkWidget *widget,
282 gint (* destroy_event) (GtkWidget *widget,
284 gint (* expose_event) (GtkWidget *widget,
285 GdkEventExpose *event);
286 gint (* key_press_event) (GtkWidget *widget,
288 gint (* key_release_event) (GtkWidget *widget,
290 gint (* enter_notify_event) (GtkWidget *widget,
291 GdkEventCrossing *event);
292 gint (* leave_notify_event) (GtkWidget *widget,
293 GdkEventCrossing *event);
294 gint (* configure_event) (GtkWidget *widget,
295 GdkEventConfigure *event);
296 gint (* focus_in_event) (GtkWidget *widget,
297 GdkEventFocus *event);
298 gint (* focus_out_event) (GtkWidget *widget,
299 GdkEventFocus *event);
300 gint (* map_event) (GtkWidget *widget,
302 gint (* unmap_event) (GtkWidget *widget,
304 gint (* property_notify_event) (GtkWidget *widget,
305 GdkEventProperty *event);
306 gint (* selection_clear_event) (GtkWidget *widget,
307 GdkEventSelection *event);
308 gint (* selection_request_event) (GtkWidget *widget,
309 GdkEventSelection *event);
310 gint (* selection_notify_event) (GtkWidget *widget,
311 GdkEventSelection *event);
312 gint (* proximity_in_event) (GtkWidget *widget,
313 GdkEventProximity *event);
314 gint (* proximity_out_event) (GtkWidget *widget,
315 GdkEventProximity *event);
316 gint (* drag_begin_event) (GtkWidget *widget,
317 GdkEventDragBegin *event);
318 gint (* drag_request_event) (GtkWidget *widget,
319 GdkEventDragRequest *event);
320 gint (* drop_enter_event) (GtkWidget *widget,
321 GdkEventDropEnter *event);
322 gint (* drop_leave_event) (GtkWidget *widget,
323 GdkEventDropLeave *event);
324 gint (* drop_data_available_event) (GtkWidget *widget,
325 GdkEventDropDataAvailable *event);
326 gint (* other_event) (GtkWidget *widget,
327 GdkEventOther *event);
330 void (* selection_received) (GtkWidget *widget,
331 GtkSelectionData *selection_data);
333 gint (* client_event) (GtkWidget *widget,
334 GdkEventClient *event);
335 gint (* no_expose_event) (GtkWidget *widget,
339 struct _GtkWidgetAuxInfo
347 struct _GtkWidgetShapeInfo
351 GdkBitmap *shape_mask;
355 guint gtk_widget_get_type (void);
356 GtkWidget* gtk_widget_new (guint type,
358 GtkWidget* gtk_widget_newv (guint type,
361 void gtk_widget_ref (GtkWidget *widget);
362 void gtk_widget_unref (GtkWidget *widget);
363 void gtk_widget_destroy (GtkWidget *widget);
364 void gtk_widget_destroyed (GtkWidget *widget,
365 GtkWidget **widget_pointer);
366 void gtk_widget_get (GtkWidget *widget,
368 void gtk_widget_getv (GtkWidget *widget,
371 void gtk_widget_set (GtkWidget *widget,
373 void gtk_widget_setv (GtkWidget *widget,
376 void gtk_widget_unparent (GtkWidget *widget);
377 void gtk_widget_show (GtkWidget *widget);
378 void gtk_widget_hide (GtkWidget *widget);
379 void gtk_widget_show_all (GtkWidget *widget);
380 void gtk_widget_hide_all (GtkWidget *widget);
381 void gtk_widget_map (GtkWidget *widget);
382 void gtk_widget_unmap (GtkWidget *widget);
383 void gtk_widget_realize (GtkWidget *widget);
384 void gtk_widget_unrealize (GtkWidget *widget);
385 void gtk_widget_queue_draw (GtkWidget *widget);
386 void gtk_widget_queue_resize (GtkWidget *widget);
387 void gtk_widget_draw (GtkWidget *widget,
389 void gtk_widget_draw_focus (GtkWidget *widget);
390 void gtk_widget_draw_default (GtkWidget *widget);
391 void gtk_widget_draw_children (GtkWidget *widget);
392 void gtk_widget_size_request (GtkWidget *widget,
393 GtkRequisition *requisition);
394 void gtk_widget_size_allocate (GtkWidget *widget,
395 GtkAllocation *allocation);
396 void gtk_widget_install_accelerator (GtkWidget *widget,
397 GtkAcceleratorTable *table,
398 const gchar *signal_name,
401 void gtk_widget_remove_accelerator (GtkWidget *widget,
402 GtkAcceleratorTable *table,
403 const gchar *signal_name);
404 gint gtk_widget_event (GtkWidget *widget,
407 void gtk_widget_activate (GtkWidget *widget);
408 void gtk_widget_reparent (GtkWidget *widget,
409 GtkWidget *new_parent);
410 void gtk_widget_popup (GtkWidget *widget,
413 gint gtk_widget_intersect (GtkWidget *widget,
415 GdkRectangle *intersection);
416 gint gtk_widget_basic (GtkWidget *widget);
418 void gtk_widget_grab_focus (GtkWidget *widget);
419 void gtk_widget_grab_default (GtkWidget *widget);
421 void gtk_widget_set_name (GtkWidget *widget,
423 gchar* gtk_widget_get_name (GtkWidget *widget);
424 void gtk_widget_set_state (GtkWidget *widget,
426 void gtk_widget_set_sensitive (GtkWidget *widget,
428 void gtk_widget_set_parent (GtkWidget *widget,
430 void gtk_widget_set_parent_window (GtkWidget *widget,
431 GdkWindow *parent_window);
432 GdkWindow *gtk_widget_get_parent_window (GtkWidget *widget);
433 void gtk_widget_set_uposition (GtkWidget *widget,
436 void gtk_widget_set_usize (GtkWidget *widget,
439 void gtk_widget_set_events (GtkWidget *widget,
441 void gtk_widget_set_extension_events (GtkWidget *widget,
442 GdkExtensionMode mode);
444 GdkExtensionMode gtk_widget_get_extension_events (GtkWidget *widget);
445 GtkWidget* gtk_widget_get_toplevel (GtkWidget *widget);
446 GtkWidget* gtk_widget_get_ancestor (GtkWidget *widget,
448 GdkColormap* gtk_widget_get_colormap (GtkWidget *widget);
449 GdkVisual* gtk_widget_get_visual (GtkWidget *widget);
450 gint gtk_widget_get_events (GtkWidget *widget);
451 void gtk_widget_get_pointer (GtkWidget *widget,
455 gint gtk_widget_is_ancestor (GtkWidget *widget,
456 GtkWidget *ancestor);
457 gint gtk_widget_is_child (GtkWidget *widget,
462 void gtk_widget_set_style (GtkWidget *widget,
464 void gtk_widget_set_rc_style (GtkWidget *widget);
465 void gtk_widget_ensure_style (GtkWidget *widget);
466 GtkStyle* gtk_widget_get_style (GtkWidget *widget);
468 /* Tell other Gtk applications to use the same default colors.
470 void gtk_widget_propagate_default_style (void);
472 /* Push/pop pairs, to change default values upon a widget's creation.
473 * This will override the values that got set by the
474 * gtk_widget_set_default_* () functions.
476 void gtk_widget_push_style (GtkStyle *style);
477 void gtk_widget_push_colormap (GdkColormap *cmap);
478 void gtk_widget_push_visual (GdkVisual *visual);
479 void gtk_widget_pop_style (void);
480 void gtk_widget_pop_colormap (void);
481 void gtk_widget_pop_visual (void);
483 /* Set certain default values to be used at widget creation time.
485 void gtk_widget_set_default_style (GtkStyle *style);
486 void gtk_widget_set_default_colormap (GdkColormap *colormap);
487 void gtk_widget_set_default_visual (GdkVisual *visual);
488 GtkStyle* gtk_widget_get_default_style (void);
489 GdkColormap* gtk_widget_get_default_colormap (void);
490 GdkVisual* gtk_widget_get_default_visual (void);
492 /* Counterpart to gdk_window_shape_combine_mask.
494 void gtk_widget_shape_combine_mask (GtkWidget *widget,
495 GdkBitmap *shape_mask,
499 /* When you get a drag_enter event, you can use this to tell Gtk of other
500 * items that are to be dragged as well...
502 void gtk_widget_dnd_drag_add (GtkWidget *widget);
504 /* These two functions enable drag and/or drop on a widget,
505 * and also let Gtk know what data types will be accepted (use MIME
506 * type naming, plus tacking "URL:" on the front for link dragging)
508 void gtk_widget_dnd_drag_set (GtkWidget *widget,
510 gchar **type_accept_list,
512 void gtk_widget_dnd_drop_set (GtkWidget *widget,
514 gchar **type_accept_list,
516 guint8 is_destructive_operation);
518 /* Used to reply to a DRAG_REQUEST event - if you don't want to
519 * give the data then pass in NULL for it
521 void gtk_widget_dnd_data_set (GtkWidget *widget,
524 gulong data_numbytes);
526 #if defined (GTK_TRACE_OBJECTS) && defined (__GNUC__)
527 # define gtk_widget_ref gtk_object_ref
528 # define gtk_widget_unref gtk_object_unref
529 #endif /* GTK_TRACE_OBJECTS && __GNUC__ */
534 #endif /* __cplusplus */
537 #endif /* __GTK_WIDGET_H__ */