1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser 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.
8  *
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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
20  * file for a list of people on the GTK+ Team.  See the ChangeLog
21  * files for a list of changes.  These files are distributed with
22  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23  */
24 
25 #ifndef __GTK_WIDGET_PRIVATE_H__
26 #define __GTK_WIDGET_PRIVATE_H__
27 
28 #include "gtkcsstypesprivate.h"
29 #include "gtkwidget.h"
30 #include "gtkcontainer.h"
31 #include "gtkeventcontroller.h"
32 #include "gtkactionmuxer.h"
33 #include "gtksizerequestcacheprivate.h"
34 
35 G_BEGIN_DECLS
36 
37 #define GTK_STATE_FLAGS_BITS 13
38 
39 struct _GtkWidgetPrivate
40 {
41   /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
42    * (defined in "gtkenums.h").
43    */
44   guint state_flags : GTK_STATE_FLAGS_BITS;
45 
46   guint direction             : 2;
47 
48 #ifdef G_ENABLE_DEBUG
49   guint highlight_resize      : 1;
50 #endif
51 
52   guint in_destruction        : 1;
53   guint toplevel              : 1;
54   guint anchored              : 1;
55   guint composite_child       : 1;
56   guint no_window             : 1;
57   guint realized              : 1;
58   guint mapped                : 1;
59   guint visible               : 1;
60   guint sensitive             : 1;
61   guint can_focus             : 1;
62   guint has_focus             : 1;
63   guint focus_on_click        : 1;
64   guint can_default           : 1;
65   guint has_default           : 1;
66   guint receives_default      : 1;
67   guint has_grab              : 1;
68   guint shadowed              : 1;
69   guint app_paintable         : 1;
70   guint double_buffered       : 1;
71   guint redraw_on_alloc       : 1;
72   guint no_show_all           : 1;
73   guint child_visible         : 1;
74   guint multidevice           : 1;
75   guint has_shape_mask        : 1;
76   guint in_reparent           : 1;
77 
78   /* Queue-resize related flags */
79   guint resize_needed         : 1; /* queue_resize() has been called but no get_preferred_size() yet */
80   guint alloc_needed          : 1; /* this widget needs a size_allocate() call */
81   guint alloc_needed_on_child : 1; /* 0 or more children - or this widget - need a size_allocate() call */
82 
83   /* Expand-related flags */
84   guint need_compute_expand   : 1; /* Need to recompute computed_[hv]_expand */
85   guint computed_hexpand      : 1; /* computed results (composite of child flags) */
86   guint computed_vexpand      : 1;
87   guint hexpand               : 1; /* application-forced expand */
88   guint vexpand               : 1;
89   guint hexpand_set           : 1; /* whether to use application-forced  */
90   guint vexpand_set           : 1; /* instead of computing from children */
91   guint has_tooltip           : 1;
92   guint frameclock_connected  : 1;
93 
94   /* SizeGroup related flags */
95   guint have_size_groups      : 1;
96 
97   /* Alignment */
98   guint   halign              : 4;
99   guint   valign              : 4;
100 
101   guint8 alpha;
102   guint8 user_alpha;
103 
104 #ifdef G_ENABLE_CONSISTENCY_CHECKS
105   /* Number of gtk_widget_push_verify_invariants () */
106   guint8 verifying_invariants_count;
107 #endif
108 
109   gint width;
110   gint height;
111   GtkBorder margin;
112 
113   /* Animations and other things to update on clock ticks */
114   guint clock_tick_id;
115   GList *tick_callbacks;
116 
117   /* The widget's name. If the widget does not have a name
118    * (the name is NULL), then its name (as returned by
119    * "gtk_widget_get_name") is its class's name.
120    * Among other things, the widget name is used to determine
121    * the style to use for a widget.
122    */
123   gchar *name;
124 
125   /* The list of attached windows to this widget.
126    * We keep a list in order to call reset_style to all of them,
127    * recursively.
128    */
129   GList *attached_windows;
130 
131   /* The style for the widget. The style contains the
132    * colors the widget should be drawn in for each state
133    * along with graphics contexts used to draw with and
134    * the font to use for text.
135    */
136   GtkStyle *style;
137   GtkCssNode *cssnode;
138   GtkStyleContext *context;
139 
140   /* The widget's allocated size */
141   GtkAllocation allocated_size;
142   gint allocated_size_baseline;
143   GtkAllocation allocation;
144   GtkAllocation clip;
145   gint allocated_baseline;
146 
147   /* The widget's requested sizes */
148   SizeRequestCache requests;
149 
150   /* The widget's window or its parent window if it does
151    * not have a window. (Which will be indicated by the
152    * no_window field being set).
153    */
154   GdkWindow *window;
155   GList *registered_windows;
156 
157   /* The widget's parent */
158   GtkWidget *parent;
159 
160   GList *event_controllers;
161 
162   AtkObject *accessible;
163 };
164 
165 GtkCssNode *  gtk_widget_get_css_node       (GtkWidget *widget);
166 void         _gtk_widget_set_visible_flag   (GtkWidget *widget,
167                                              gboolean   visible);
168 gboolean     _gtk_widget_get_in_reparent    (GtkWidget *widget);
169 void         _gtk_widget_set_in_reparent    (GtkWidget *widget,
170                                              gboolean   in_reparent);
171 gboolean     _gtk_widget_get_anchored       (GtkWidget *widget);
172 void         _gtk_widget_set_anchored       (GtkWidget *widget,
173                                              gboolean   anchored);
174 gboolean     _gtk_widget_get_shadowed       (GtkWidget *widget);
175 void         _gtk_widget_set_shadowed       (GtkWidget *widget,
176                                              gboolean   shadowed);
177 gboolean     _gtk_widget_get_alloc_needed   (GtkWidget *widget);
178 gboolean     gtk_widget_needs_allocate      (GtkWidget *widget);
179 void         gtk_widget_queue_resize_on_widget (GtkWidget *widget);
180 void         gtk_widget_ensure_resize       (GtkWidget *widget);
181 void         gtk_widget_ensure_allocate     (GtkWidget *widget);
182 void         gtk_widget_draw_internal       (GtkWidget *widget,
183 					     cairo_t   *cr,
184                                              gboolean   do_clip);
185 void          _gtk_widget_scale_changed     (GtkWidget *widget);
186 
187 
188 void         _gtk_widget_add_sizegroup         (GtkWidget    *widget,
189 						gpointer      group);
190 void         _gtk_widget_remove_sizegroup      (GtkWidget    *widget,
191 						gpointer      group);
192 GSList      *_gtk_widget_get_sizegroups        (GtkWidget    *widget);
193 
194 void         _gtk_widget_add_attached_window    (GtkWidget    *widget,
195                                                  GtkWindow    *window);
196 void         _gtk_widget_remove_attached_window (GtkWidget    *widget,
197                                                  GtkWindow    *window);
198 
199 void _gtk_widget_get_preferred_size_for_size   (GtkWidget         *widget,
200                                                 GtkOrientation     orientation,
201                                                 gint               size,
202                                                 gint              *minimum,
203                                                 gint              *natural,
204                                                 gint              *minimum_baseline,
205                                                 gint              *natural_baseline);
206 void _gtk_widget_get_preferred_size_and_baseline(GtkWidget        *widget,
207                                                 GtkRequisition    *minimum_size,
208                                                 GtkRequisition    *natural_size,
209                                                 gint              *minimum_baseline,
210                                                 gint              *natural_baseline);
211 gboolean _gtk_widget_has_baseline_support (GtkWidget *widget);
212 
213 const gchar*      _gtk_widget_get_accel_path               (GtkWidget *widget,
214                                                             gboolean  *locked);
215 
216 AtkObject *       _gtk_widget_peek_accessible              (GtkWidget *widget);
217 
218 void              _gtk_widget_set_has_default              (GtkWidget *widget,
219                                                             gboolean   has_default);
220 void              _gtk_widget_set_has_grab                 (GtkWidget *widget,
221                                                             gboolean   has_grab);
222 void              _gtk_widget_set_is_toplevel              (GtkWidget *widget,
223                                                             gboolean   is_toplevel);
224 
225 void              _gtk_widget_grab_notify                  (GtkWidget *widget,
226                                                             gboolean   was_grabbed);
227 
228 void              _gtk_widget_propagate_hierarchy_changed  (GtkWidget *widget,
229                                                             GtkWidget *previous_toplevel);
230 void              _gtk_widget_propagate_screen_changed     (GtkWidget *widget,
231                                                             GdkScreen *previous_screen);
232 void              _gtk_widget_propagate_composited_changed (GtkWidget *widget);
233 
234 void              _gtk_widget_set_device_window            (GtkWidget *widget,
235                                                             GdkDevice *device,
236                                                             GdkWindow *pointer_window);
237 GdkWindow *       _gtk_widget_get_device_window            (GtkWidget *widget,
238                                                             GdkDevice *device);
239 GList *           _gtk_widget_list_devices                 (GtkWidget *widget);
240 
241 void              _gtk_widget_synthesize_crossing          (GtkWidget       *from,
242                                                             GtkWidget       *to,
243                                                             GdkDevice       *device,
244                                                             GdkCrossingMode  mode);
245 
246 static inline gpointer _gtk_widget_peek_request_cache           (GtkWidget *widget);
247 
248 void              _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
249                                                             GtkWidget *toplevel,
250                                                             gpointer   user_data);
251 GtkStyleContext * _gtk_widget_peek_style_context           (GtkWidget *widget);
252 GtkStyle *        _gtk_widget_get_style                    (GtkWidget *widget);
253 void              _gtk_widget_set_style                    (GtkWidget *widget,
254                                                             GtkStyle  *style);
255 gboolean          _gtk_widget_supports_clip                (GtkWidget *widget);
256 void              _gtk_widget_set_simple_clip              (GtkWidget *widget,
257                                                             GtkAllocation *content_clip);
258 
259 typedef gboolean (*GtkCapturedEventHandler) (GtkWidget *widget, GdkEvent *event);
260 
261 void              _gtk_widget_set_captured_event_handler (GtkWidget               *widget,
262                                                           GtkCapturedEventHandler  handler);
263 
264 gboolean          _gtk_widget_captured_event               (GtkWidget *widget,
265                                                             GdkEvent  *event);
266 
267 GtkWidgetPath *   _gtk_widget_create_path                  (GtkWidget    *widget);
268 void              gtk_widget_clear_path                    (GtkWidget    *widget);
269 void              _gtk_widget_invalidate_style_context     (GtkWidget    *widget,
270                                                             GtkCssChange  change);
271 void              _gtk_widget_style_context_invalidated    (GtkWidget    *widget);
272 
273 void              _gtk_widget_update_parent_muxer          (GtkWidget    *widget);
274 GtkActionMuxer *  _gtk_widget_get_action_muxer             (GtkWidget    *widget,
275                                                             gboolean      create);
276 
277 void              _gtk_widget_add_controller               (GtkWidget           *widget,
278                                                             GtkEventController  *controller);
279 void              _gtk_widget_remove_controller            (GtkWidget           *widget,
280                                                             GtkEventController  *controller);
281 GList *           _gtk_widget_list_controllers             (GtkWidget           *widget,
282                                                             GtkPropagationPhase  phase);
283 gboolean          _gtk_widget_consumes_motion              (GtkWidget           *widget,
284                                                             GdkEventSequence    *sequence);
285 
286 gboolean          gtk_widget_has_tick_callback             (GtkWidget *widget);
287 
288 void              gtk_widget_set_csd_input_shape           (GtkWidget            *widget,
289                                                             const cairo_region_t *region);
290 
291 gboolean          gtk_widget_has_size_request              (GtkWidget *widget);
292 
293 void              gtk_widget_reset_controllers             (GtkWidget *widget);
294 
295 gboolean          gtk_widget_query_tooltip                 (GtkWidget  *widget,
296                                                             gint        x,
297                                                             gint        y,
298                                                             gboolean    keyboard_mode,
299                                                             GtkTooltip *tooltip);
300 
301 void              gtk_widget_render                        (GtkWidget            *widget,
302                                                             GdkWindow            *window,
303                                                             const cairo_region_t *region);
304 
305 
306 /* inline getters */
307 
308 static inline gboolean
gtk_widget_get_resize_needed(GtkWidget * widget)309 gtk_widget_get_resize_needed (GtkWidget *widget)
310 {
311   return widget->priv->resize_needed;
312 }
313 
314 static inline GtkWidget *
_gtk_widget_get_parent(GtkWidget * widget)315 _gtk_widget_get_parent (GtkWidget *widget)
316 {
317   return widget->priv->parent;
318 }
319 
320 static inline gboolean
_gtk_widget_get_visible(GtkWidget * widget)321 _gtk_widget_get_visible (GtkWidget *widget)
322 {
323   return widget->priv->visible;
324 }
325 
326 static inline gboolean
_gtk_widget_get_child_visible(GtkWidget * widget)327 _gtk_widget_get_child_visible (GtkWidget *widget)
328 {
329   return widget->priv->child_visible;
330 }
331 
332 static inline gboolean
_gtk_widget_get_mapped(GtkWidget * widget)333 _gtk_widget_get_mapped (GtkWidget *widget)
334 {
335   return widget->priv->mapped;
336 }
337 
338 static inline gboolean
_gtk_widget_is_drawable(GtkWidget * widget)339 _gtk_widget_is_drawable (GtkWidget *widget)
340 {
341   return widget->priv->visible && widget->priv->mapped;
342 }
343 
344 static inline gboolean
_gtk_widget_get_has_window(GtkWidget * widget)345 _gtk_widget_get_has_window (GtkWidget *widget)
346 {
347   return !widget->priv->no_window;
348 }
349 
350 static inline gboolean
_gtk_widget_get_realized(GtkWidget * widget)351 _gtk_widget_get_realized (GtkWidget *widget)
352 {
353   return widget->priv->realized;
354 }
355 
356 static inline gboolean
_gtk_widget_is_toplevel(GtkWidget * widget)357 _gtk_widget_is_toplevel (GtkWidget *widget)
358 {
359   return widget->priv->toplevel;
360 }
361 
362 static inline GtkStateFlags
_gtk_widget_get_state_flags(GtkWidget * widget)363 _gtk_widget_get_state_flags (GtkWidget *widget)
364 {
365   return widget->priv->state_flags;
366 }
367 
368 extern GtkTextDirection gtk_default_direction;
369 
370 static inline GtkTextDirection
_gtk_widget_get_direction(GtkWidget * widget)371 _gtk_widget_get_direction (GtkWidget *widget)
372 {
373   if (widget->priv->direction == GTK_TEXT_DIR_NONE)
374     return gtk_default_direction;
375   else
376     return widget->priv->direction;
377 }
378 
379 static inline GtkWidget *
_gtk_widget_get_toplevel(GtkWidget * widget)380 _gtk_widget_get_toplevel (GtkWidget *widget)
381 {
382   while (widget->priv->parent)
383     widget = widget->priv->parent;
384 
385   return widget;
386 }
387 
388 static inline GtkStyleContext *
_gtk_widget_get_style_context(GtkWidget * widget)389 _gtk_widget_get_style_context (GtkWidget *widget)
390 {
391   if (G_LIKELY (widget->priv->context))
392     return widget->priv->context;
393 
394   return gtk_widget_get_style_context (widget);
395 }
396 
397 static inline gpointer
_gtk_widget_peek_request_cache(GtkWidget * widget)398 _gtk_widget_peek_request_cache (GtkWidget *widget)
399 {
400   return &widget->priv->requests;
401 }
402 
403 static inline GdkWindow *
_gtk_widget_get_window(GtkWidget * widget)404 _gtk_widget_get_window (GtkWidget *widget)
405 {
406   return widget->priv->window;
407 }
408 
409 static inline void
_gtk_widget_get_allocation(GtkWidget * widget,GtkAllocation * allocation)410 _gtk_widget_get_allocation (GtkWidget     *widget,
411                             GtkAllocation *allocation)
412 {
413   *allocation = widget->priv->allocation;
414 }
415 
416 G_END_DECLS
417 
418 #endif /* __GTK_WIDGET_PRIVATE_H__ */
419