1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * gtkdrawing.h: GTK widget rendering utilities
9 * gtkdrawing provides an API for rendering GTK widgets in the
10 * current theme to a pixmap or window, without requiring an actual
11 * widget instantiation, similar to the Macintosh Appearance Manager
12 * or Windows XP's DrawThemeBackground() API.
15 #ifndef _GTK_DRAWING_H_
16 #define _GTK_DRAWING_H_
22 /*** type definitions ***/
31 /* The depressed state is for buttons which remain active for a longer period:
32 * activated toggle buttons or buttons showing a popup menu. */
35 gint32 curpos
; /* curpos and maxpos are used for scrollbars */
37 gint32 scale
; /* actual widget scale */
41 * A size in the same GTK pixel units as GtkBorder and GdkRectangle.
47 MozGtkSize
& operator+=(const GtkBorder
& aBorder
) {
48 width
+= aBorder
.left
+ aBorder
.right
;
49 height
+= aBorder
.top
+ aBorder
.bottom
;
52 MozGtkSize
operator+(const GtkBorder
& aBorder
) const {
53 MozGtkSize result
= *this;
54 return result
+= aBorder
;
56 bool operator<(const MozGtkSize
& aOther
) const {
57 return (width
< aOther
.width
&& height
<= aOther
.height
) ||
58 (width
<= aOther
.width
&& height
< aOther
.height
);
60 void Include(MozGtkSize aOther
) {
61 width
= std::max(width
, aOther
.width
);
62 height
= std::max(height
, aOther
.height
);
85 } ScrollbarGTKMetrics
;
89 MozGtkSize minSizeWithBorder
;
90 GtkBorder borderAndPadding
;
94 MozGtkSize minSizeWithBorderMargin
;
95 GtkBorder buttonMargin
;
101 } ToolbarButtonGTKMetrics
;
103 #define TOOLBAR_BUTTONS 3
106 ToolbarButtonGTKMetrics button
[TOOLBAR_BUTTONS
];
111 GtkBorder decorationSize
;
112 } CSDWindowDecorationSize
;
115 MOZ_GTK_STEPPER_DOWN
= 1 << 0,
116 MOZ_GTK_STEPPER_BOTTOM
= 1 << 1,
117 MOZ_GTK_STEPPER_VERTICAL
= 1 << 2
118 } GtkScrollbarButtonFlags
;
120 typedef enum { MOZ_GTK_TRACK_OPAQUE
= 1 << 0 } GtkScrollbarTrackFlags
;
122 /** flags for tab state **/
124 /* first eight bits are used to pass a margin */
125 MOZ_GTK_TAB_MARGIN_MASK
= 0xFF,
126 /* the first tab in the group */
127 MOZ_GTK_TAB_FIRST
= 1 << 9,
128 /* the selected tab */
129 MOZ_GTK_TAB_SELECTED
= 1 << 10
132 /*** result/error codes ***/
133 #define MOZ_GTK_SUCCESS 0
134 #define MOZ_GTK_UNKNOWN_WIDGET -1
135 #define MOZ_GTK_UNSAFE_THEME -2
137 /*** checkbox/radio flags ***/
138 #define MOZ_GTK_WIDGET_CHECKED 1
139 #define MOZ_GTK_WIDGET_INCONSISTENT (1 << 1)
141 /*** widget type constants ***/
143 /* Paints a GtkButton. flags is a GtkReliefStyle. */
145 /* Paints a button with image and no text */
146 MOZ_GTK_TOOLBAR_BUTTON
,
147 /* Paints a toggle button */
148 MOZ_GTK_TOGGLE_BUTTON
,
149 /* Paints a button arrow */
150 MOZ_GTK_BUTTON_ARROW
,
152 /* Paints the container part of a GtkCheckButton. */
153 MOZ_GTK_CHECKBUTTON_CONTAINER
,
154 /* Paints a GtkCheckButton. flags is a boolean, 1=checked, 0=not checked. */
156 /* Paints the label of a GtkCheckButton (focus outline) */
157 MOZ_GTK_CHECKBUTTON_LABEL
,
159 /* Paints the container part of a GtkRadioButton. */
160 MOZ_GTK_RADIOBUTTON_CONTAINER
,
161 /* Paints a GtkRadioButton. flags is a boolean, 1=checked, 0=not checked. */
163 /* Paints the label of a GtkRadioButton (focus outline) */
164 MOZ_GTK_RADIOBUTTON_LABEL
,
166 * Paints the button of a GtkScrollbar. flags is a GtkArrowType giving
167 * the arrow direction.
169 MOZ_GTK_SCROLLBAR_BUTTON
,
171 /* Horizontal GtkScrollbar counterparts */
172 MOZ_GTK_SCROLLBAR_HORIZONTAL
,
173 MOZ_GTK_SCROLLBAR_CONTENTS_HORIZONTAL
,
174 /* Paints the trough (track) of a GtkScrollbar. */
175 MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL
,
176 /* Paints the slider (thumb) of a GtkScrollbar. */
177 MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL
,
179 /* Vertical GtkScrollbar counterparts */
180 MOZ_GTK_SCROLLBAR_VERTICAL
,
181 MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL
,
182 MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL
,
183 MOZ_GTK_SCROLLBAR_THUMB_VERTICAL
,
185 /* Paints a GtkScale. */
186 MOZ_GTK_SCALE_HORIZONTAL
,
187 MOZ_GTK_SCALE_VERTICAL
,
188 /* Paints a GtkScale trough. */
189 MOZ_GTK_SCALE_CONTENTS_HORIZONTAL
,
190 MOZ_GTK_SCALE_CONTENTS_VERTICAL
,
191 MOZ_GTK_SCALE_TROUGH_HORIZONTAL
,
192 MOZ_GTK_SCALE_TROUGH_VERTICAL
,
193 /* Paints a GtkScale thumb. */
194 MOZ_GTK_SCALE_THUMB_HORIZONTAL
,
195 MOZ_GTK_SCALE_THUMB_VERTICAL
,
196 /* Paints a GtkSpinButton */
197 MOZ_GTK_INNER_SPIN_BUTTON
,
199 MOZ_GTK_SPINBUTTON_UP
,
200 MOZ_GTK_SPINBUTTON_DOWN
,
201 MOZ_GTK_SPINBUTTON_ENTRY
,
202 /* Paints the gripper of a GtkHandleBox. */
204 /* Paints a GtkEntry. */
206 /* Paints a GtkExpander. */
208 /* Paints a GtkTextView or gets the style context corresponding to the
209 root node of a GtkTextView. */
211 /* The "text" window or node of a GtkTextView */
212 MOZ_GTK_TEXT_VIEW_TEXT
,
213 /* Paints a GtkOptionMenu. */
215 /* Paints a dropdown arrow (a GtkButton containing a down GtkArrow). */
216 MOZ_GTK_DROPDOWN_ARROW
,
217 /* Paints an entry in an editable option menu */
218 MOZ_GTK_DROPDOWN_ENTRY
,
220 /* Paints the background of a GtkHandleBox. */
222 /* Paints a toolbar separator */
223 MOZ_GTK_TOOLBAR_SEPARATOR
,
224 /* Paints a GtkToolTip */
226 /* Paints a GtkBox from GtkToolTip */
228 /* Paints a GtkLabel of GtkToolTip */
229 MOZ_GTK_TOOLTIP_BOX_LABEL
,
230 /* Paints a GtkFrame (e.g. a status bar panel). */
232 /* Paints the border of a GtkFrame */
233 MOZ_GTK_FRAME_BORDER
,
234 /* Paints a resize grip for a GtkTextView */
236 /* Paints a GtkProgressBar. */
238 /* Paints a trough (track) of a GtkProgressBar */
239 MOZ_GTK_PROGRESS_TROUGH
,
240 /* Paints a progress chunk of a GtkProgressBar. */
241 MOZ_GTK_PROGRESS_CHUNK
,
242 /* Paints a progress chunk of an indeterminated GtkProgressBar. */
243 MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE
,
244 /* Paints a progress chunk of a vertical indeterminated GtkProgressBar. */
245 MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE
,
246 /* Used as root style of whole GtkNotebook widget */
248 /* Used as root style of active GtkNotebook area which contains tabs and
250 MOZ_GTK_NOTEBOOK_HEADER
,
251 /* Paints a tab of a GtkNotebook. flags is a GtkTabFlags, defined above. */
253 /* Paints a tab of a GtkNotebook. flags is a GtkTabFlags, defined above. */
255 /* Paints the background and border of a GtkNotebook. */
257 /* Paints a GtkArrow for a GtkNotebook. flags is a GtkArrowType. */
258 MOZ_GTK_TAB_SCROLLARROW
,
259 /* Paints the expander and border of a GtkTreeView */
261 /* Paints the border of a GtkTreeView */
262 MOZ_GTK_TREEVIEW_VIEW
,
263 /* Paints treeheader cells */
264 MOZ_GTK_TREE_HEADER_CELL
,
265 /* Paints sort arrows in treeheader cells */
266 MOZ_GTK_TREE_HEADER_SORTARROW
,
267 /* Paints an expander for a GtkTreeView */
268 MOZ_GTK_TREEVIEW_EXPANDER
,
269 /* Paints the background of the menu bar. */
271 /* Paints the background of menus, context menus. */
273 /* Paints the arrow of menuitems that contain submenus */
275 /* Paints an arrow in a toolbar button. flags is a GtkArrowType. */
276 MOZ_GTK_TOOLBARBUTTON_ARROW
,
277 /* Paints items of menubar. */
279 /* Paints items of popup menus. */
281 /* Paints a menuitem with check indicator, or the gets the style context for
282 a menuitem that contains a checkbox. */
283 MOZ_GTK_CHECKMENUITEM
,
284 /* Gets the style context for a checkbox in a check menuitem. */
285 MOZ_GTK_CHECKMENUITEM_INDICATOR
,
286 MOZ_GTK_RADIOMENUITEM
,
287 MOZ_GTK_RADIOMENUITEM_INDICATOR
,
288 MOZ_GTK_MENUSEPARATOR
,
289 /* GtkVPaned base class */
290 MOZ_GTK_SPLITTER_HORIZONTAL
,
291 /* GtkHPaned base class */
292 MOZ_GTK_SPLITTER_VERTICAL
,
293 /* Paints a GtkVPaned separator */
294 MOZ_GTK_SPLITTER_SEPARATOR_HORIZONTAL
,
295 /* Paints a GtkHPaned separator */
296 MOZ_GTK_SPLITTER_SEPARATOR_VERTICAL
,
297 /* Paints the background of a window, dialog or page. */
299 /* Used only as a container for MOZ_GTK_HEADER_BAR. */
300 MOZ_GTK_HEADERBAR_WINDOW
,
301 /* Used only as a container for MOZ_GTK_HEADER_BAR_MAXIMIZED. */
302 MOZ_GTK_HEADERBAR_WINDOW_MAXIMIZED
,
303 /* Window container for all widgets */
304 MOZ_GTK_WINDOW_CONTAINER
,
305 /* Paints a GtkInfoBar, for notifications. */
307 /* Used for widget tree construction. */
309 /* Paints a GtkComboBox button widget. */
310 MOZ_GTK_COMBOBOX_BUTTON
,
311 /* Paints a GtkComboBox arrow widget. */
312 MOZ_GTK_COMBOBOX_ARROW
,
313 /* Paints a GtkComboBox separator widget. */
314 MOZ_GTK_COMBOBOX_SEPARATOR
,
315 /* Used for widget tree construction. */
316 MOZ_GTK_COMBOBOX_ENTRY
,
317 /* Paints a GtkComboBox entry widget. */
318 MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA
,
319 /* Paints a GtkComboBox entry button widget. */
320 MOZ_GTK_COMBOBOX_ENTRY_BUTTON
,
321 /* Paints a GtkComboBox entry arrow widget. */
322 MOZ_GTK_COMBOBOX_ENTRY_ARROW
,
323 /* Used for scrolled window shell. */
324 MOZ_GTK_SCROLLED_WINDOW
,
325 /* Paints a GtkHeaderBar */
327 /* Paints a GtkHeaderBar in maximized state */
328 MOZ_GTK_HEADER_BAR_MAXIMIZED
,
329 /* Container for GtkHeaderBar buttons */
330 MOZ_GTK_HEADER_BAR_BUTTON_BOX
,
331 /* Paints GtkHeaderBar title buttons.
332 * Keep the order here as MOZ_GTK_HEADER_BAR_BUTTON_* are processed
333 * as an array from MOZ_GTK_HEADER_BAR_BUTTON_CLOSE to the last one.
335 MOZ_GTK_HEADER_BAR_BUTTON_CLOSE
,
336 MOZ_GTK_HEADER_BAR_BUTTON_MINIMIZE
,
337 MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE
,
339 /* MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE_RESTORE is a state of
340 * MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE button and it's used as
341 * an icon placeholder only.
343 MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE_RESTORE
,
345 /* Client-side window decoration node. Available on GTK 3.20+. */
346 MOZ_GTK_WINDOW_DECORATION
,
347 MOZ_GTK_WINDOW_DECORATION_SOLID
,
349 MOZ_GTK_WIDGET_NODE_COUNT
352 /*** General library functions ***/
354 * Initializes the drawing library. You must call this function
355 * prior to using any other functionality.
356 * returns: MOZ_GTK_SUCCESS if there were no errors
357 * MOZ_GTK_UNSAFE_THEME if the current theme engine is known
358 * to crash with gtkdrawing.
363 * Updates the drawing library when the theme changes.
365 void moz_gtk_refresh();
368 * Perform cleanup of the drawing library. You should call this function
369 * when your program exits, or you no longer need the library.
371 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
373 gint
moz_gtk_shutdown();
375 /*** Widget drawing ***/
377 * Paint a widget in the current theme.
378 * widget: a constant giving the widget to paint
379 * drawable: the drawable to paint to;
380 * it's colormap must be moz_gtk_widget_get_colormap().
381 * rect: the bounding rectangle for the widget
382 * state: the state of the widget. ignored for some widgets.
383 * flags: widget-dependant flags; see the WidgetNodeType definition.
384 * direction: the text direction, to draw the widget correctly LTR and RTL.
386 gint
moz_gtk_widget_paint(WidgetNodeType widget
, cairo_t
* cr
,
387 GdkRectangle
* rect
, GtkWidgetState
* state
, gint flags
,
388 GtkTextDirection direction
);
390 /*** Widget metrics ***/
392 * Get the border size of a widget
393 * left/right: [OUT] the widget's left/right border
394 * top/bottom: [OUT] the widget's top/bottom border
395 * direction: the text direction for the widget. Callers depend on this
396 * being used only for MOZ_GTK_DROPDOWN widgets, and cache
397 * results for other widget types across direction values.
399 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
401 gint
moz_gtk_get_widget_border(WidgetNodeType widget
, gint
* left
, gint
* top
,
402 gint
* right
, gint
* bottom
,
403 GtkTextDirection direction
);
406 * Get the border size of a notebook tab
407 * left/right: [OUT] the tab's left/right border
408 * top/bottom: [OUT] the tab's top/bottom border
409 * direction: the text direction for the widget
410 * flags: tab-dependant flags; see the GtkTabFlags definition.
413 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
415 gint
moz_gtk_get_tab_border(gint
* left
, gint
* top
, gint
* right
, gint
* bottom
,
416 GtkTextDirection direction
, GtkTabFlags flags
,
417 WidgetNodeType widget
);
420 * Get the desired size of a GtkCheckButton
421 * indicator_size: [OUT] the indicator size
422 * indicator_spacing: [OUT] the spacing between the indicator and its
425 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
427 gint
moz_gtk_checkbox_get_metrics(gint
* indicator_size
,
428 gint
* indicator_spacing
);
431 * Get metrics of the toggle (radio or checkbox)
432 * isRadio: [IN] true when requesting metrics for the radio button
433 * returns: pointer to ToggleGTKMetrics struct
435 const ToggleGTKMetrics
* GetToggleMetrics(WidgetNodeType aWidgetType
);
438 * Get the desired size of a GtkRadioButton
439 * indicator_size: [OUT] the indicator size
440 * indicator_spacing: [OUT] the spacing between the indicator and its
443 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
445 gint
moz_gtk_radio_get_metrics(gint
* indicator_size
, gint
* indicator_spacing
);
447 /** Get the extra size for the focus ring for outline:auto.
448 * widget: [IN] the widget to get the focus metrics for
449 * focus_h_width: [OUT] the horizontal width
450 * focus_v_width: [OUT] the vertical width
452 * returns: MOZ_GTK_SUCCESS
454 gint
moz_gtk_get_focus_outline_size(gint
* focus_h_width
, gint
* focus_v_width
);
456 /** Get the horizontal padding for the menuitem widget or checkmenuitem widget.
457 * horizontal_padding: [OUT] The left and right padding of the menuitem or
460 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
462 gint
moz_gtk_menuitem_get_horizontal_padding(gint
* horizontal_padding
);
464 gint
moz_gtk_checkmenuitem_get_horizontal_padding(gint
* horizontal_padding
);
467 * Some GTK themes draw their indication for the default button outside
468 * the button (e.g. the glow in New Wave). This gets the extra space necessary.
470 * border_top: [OUT] extra space to add above
471 * border_left: [OUT] extra space to add to the left
472 * border_bottom: [OUT] extra space to add underneath
473 * border_right: [OUT] extra space to add to the right
475 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
477 gint
moz_gtk_button_get_default_overflow(gint
* border_top
, gint
* border_left
,
482 * Gets the minimum size of a GtkScale.
483 * orient: [IN] the scale orientation
484 * scale_width: [OUT] the width of the scale
485 * scale_height: [OUT] the height of the scale
487 void moz_gtk_get_scale_metrics(GtkOrientation orient
, gint
* scale_width
,
491 * Get the desired size of a GtkScale thumb
492 * orient: [IN] the scale orientation
493 * thumb_length: [OUT] the length of the thumb
494 * thumb_height: [OUT] the height of the thumb
496 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
498 gint
moz_gtk_get_scalethumb_metrics(GtkOrientation orient
, gint
* thumb_length
,
502 * Get the metrics in GTK pixels for a scrollbar.
503 * aOrientation: [IN] the scrollbar orientation
505 const ScrollbarGTKMetrics
* GetScrollbarMetrics(GtkOrientation aOrientation
);
508 * Get the metrics in GTK pixels for a scrollbar which is active
509 * (selected by mouse pointer).
510 * aOrientation: [IN] the scrollbar orientation
512 const ScrollbarGTKMetrics
* GetActiveScrollbarMetrics(
513 GtkOrientation aOrientation
);
516 * Get the desired size of a dropdown arrow button
517 * width: [OUT] the desired width
518 * height: [OUT] the desired height
520 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
522 gint
moz_gtk_get_combo_box_entry_button_size(gint
* width
, gint
* height
);
525 * Get the desired size of a scroll arrow widget
526 * width: [OUT] the desired width
527 * height: [OUT] the desired height
529 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
531 gint
moz_gtk_get_tab_scroll_arrow_size(gint
* width
, gint
* height
);
534 * Get the desired size of an arrow in a button
536 * widgetType: [IN] the widget for which to get the arrow size
537 * width: [OUT] the desired width
538 * height: [OUT] the desired height
540 void moz_gtk_get_arrow_size(WidgetNodeType widgetType
, gint
* width
,
544 * Get the minimum height of a entry widget
545 * size: [OUT] the minimum height
548 void moz_gtk_get_entry_min_height(gint
* height
);
551 * Get the desired size of a toolbar separator
552 * size: [OUT] the desired width
554 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
556 gint
moz_gtk_get_toolbar_separator_width(gint
* size
);
559 * Get the size of a regular GTK expander that shows/hides content
560 * size: [OUT] the size of the GTK expander, size = width = height.
562 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
564 gint
moz_gtk_get_expander_size(gint
* size
);
567 * Get the size of a treeview's expander (we call them twisties)
568 * size: [OUT] the size of the GTK expander, size = width = height.
570 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
572 gint
moz_gtk_get_treeview_expander_size(gint
* size
);
575 * Get the desired height of a menu separator
576 * size: [OUT] the desired height
578 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
580 gint
moz_gtk_get_menu_separator_height(gint
* size
);
583 * Get the desired size of a splitter
584 * orientation: [IN] GTK_ORIENTATION_HORIZONTAL or GTK_ORIENTATION_VERTICAL
585 * size: [OUT] width or height of the splitter handle
587 * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
589 gint
moz_gtk_splitter_get_metrics(gint orientation
, gint
* size
);
592 * Get the YTHICKNESS of a tab (notebook extension).
594 gint
moz_gtk_get_tab_thickness(WidgetNodeType aNodeType
);
597 * Get ToolbarButtonGTKMetrics for recent theme.
599 const ToolbarButtonGTKMetrics
* GetToolbarButtonMetrics(
600 WidgetNodeType aAppearance
);
603 * Get toolbar button layout.
604 * aButtonLayout: [IN][OUT] An array which will be filled by WidgetNodeType
605 * references to visible titlebar buttons.
606 * Must contains at least TOOLBAR_BUTTONS entries.
607 * aMaxButtonNums: [IN] Allocated aButtonLayout entries. Must be at least
608 * TOOLBAR_BUTTONS wide.
609 * aReversedButtonsPlacement: [OUT] True if the buttons are placed in opposite
612 * returns: Number of returned entries at aButtonLayout.
614 int GetGtkHeaderBarButtonLayout(WidgetNodeType
* aButtonLayout
,
616 bool* aReversedButtonsPlacement
);
619 * Get size of CSD window extents.
621 * aIsPopup: [IN] Get decoration size for popup or toplevel window.
623 * returns: Calculated (or estimated) decoration size of given aGtkWindow.
625 GtkBorder
GetCSDDecorationSize(bool aIsPopup
);