widget/gtk/gtkdrawing.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gtk/gtkdrawing.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,447 @@
     1.4 +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/**
    1.10 + * gtkdrawing.h: GTK widget rendering utilities
    1.11 + *
    1.12 + * gtkdrawing provides an API for rendering GTK widgets in the
    1.13 + * current theme to a pixmap or window, without requiring an actual
    1.14 + * widget instantiation, similar to the Macintosh Appearance Manager
    1.15 + * or Windows XP's DrawThemeBackground() API.
    1.16 + */
    1.17 +
    1.18 +#ifndef _GTK_DRAWING_H_
    1.19 +#define _GTK_DRAWING_H_
    1.20 +
    1.21 +#include <gdk/gdk.h>
    1.22 +#include <gtk/gtk.h>
    1.23 +
    1.24 +#ifdef __cplusplus
    1.25 +extern "C" {
    1.26 +#endif /* __cplusplus */
    1.27 +
    1.28 +/*** type definitions ***/
    1.29 +typedef struct {
    1.30 +  guint8 active;
    1.31 +  guint8 focused;
    1.32 +  guint8 inHover;
    1.33 +  guint8 disabled;
    1.34 +  guint8 isDefault;
    1.35 +  guint8 canDefault;
    1.36 +  /* The depressed state is for buttons which remain active for a longer period:
    1.37 +   * activated toggle buttons or buttons showing a popup menu. */
    1.38 +  guint8 depressed;
    1.39 +  gint32 curpos; /* curpos and maxpos are used for scrollbars */
    1.40 +  gint32 maxpos;
    1.41 +} GtkWidgetState;
    1.42 +
    1.43 +typedef struct {
    1.44 +  gint slider_width;
    1.45 +  gint trough_border;
    1.46 +  gint stepper_size;
    1.47 +  gint stepper_spacing;
    1.48 +  gint min_slider_size;
    1.49 +} MozGtkScrollbarMetrics;
    1.50 +
    1.51 +typedef enum {
    1.52 +  MOZ_GTK_STEPPER_DOWN        = 1 << 0,
    1.53 +  MOZ_GTK_STEPPER_BOTTOM      = 1 << 1,
    1.54 +  MOZ_GTK_STEPPER_VERTICAL    = 1 << 2
    1.55 +} GtkScrollbarButtonFlags;
    1.56 +
    1.57 +/** flags for tab state **/
    1.58 +typedef enum {
    1.59 +  /* first eight bits are used to pass a margin */
    1.60 +  MOZ_GTK_TAB_MARGIN_MASK     = 0xFF,
    1.61 +  /* bottom tabs */
    1.62 +  MOZ_GTK_TAB_BOTTOM          = 1 << 8,
    1.63 +  /* the first tab in the group */
    1.64 +  MOZ_GTK_TAB_FIRST           = 1 << 9,
    1.65 +  /* the selected tab */
    1.66 +  MOZ_GTK_TAB_SELECTED        = 1 << 10
    1.67 +} GtkTabFlags;
    1.68 +
    1.69 +/** flags for menuitems **/
    1.70 +typedef enum {
    1.71 +  /* menuitem is part of the menubar */
    1.72 +  MOZ_TOPLEVEL_MENU_ITEM      = 1 << 0
    1.73 +} GtkMenuItemFlags;
    1.74 +
    1.75 +/* function type for moz_gtk_enable_style_props */
    1.76 +typedef gint (*style_prop_t)(GtkStyle*, const gchar*, gint);
    1.77 +
    1.78 +/*** result/error codes ***/
    1.79 +#define MOZ_GTK_SUCCESS 0
    1.80 +#define MOZ_GTK_UNKNOWN_WIDGET -1
    1.81 +#define MOZ_GTK_UNSAFE_THEME -2
    1.82 +
    1.83 +/*** checkbox/radio flags ***/
    1.84 +#define MOZ_GTK_WIDGET_CHECKED 1
    1.85 +#define MOZ_GTK_WIDGET_INCONSISTENT (1 << 1)
    1.86 +
    1.87 +/*** widget type constants ***/
    1.88 +typedef enum {
    1.89 +  /* Paints a GtkButton. flags is a GtkReliefStyle. */
    1.90 +  MOZ_GTK_BUTTON,
    1.91 +  /* Paints a GtkCheckButton. flags is a boolean, 1=checked, 0=not checked. */
    1.92 +  MOZ_GTK_CHECKBUTTON,
    1.93 +  /* Paints a GtkRadioButton. flags is a boolean, 1=checked, 0=not checked. */
    1.94 +  MOZ_GTK_RADIOBUTTON,
    1.95 +  /**
    1.96 +   * Paints the button of a GtkScrollbar. flags is a GtkArrowType giving
    1.97 +   * the arrow direction.
    1.98 +   */
    1.99 +  MOZ_GTK_SCROLLBAR_BUTTON,
   1.100 +  /* Paints the trough (track) of a GtkScrollbar. */
   1.101 +  MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL,
   1.102 +  MOZ_GTK_SCROLLBAR_TRACK_VERTICAL,
   1.103 +  /* Paints the slider (thumb) of a GtkScrollbar. */
   1.104 +  MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL,
   1.105 +  MOZ_GTK_SCROLLBAR_THUMB_VERTICAL,
   1.106 +  /* Paints a GtkScale. */
   1.107 +  MOZ_GTK_SCALE_HORIZONTAL,
   1.108 +  MOZ_GTK_SCALE_VERTICAL,
   1.109 +  /* Paints a GtkScale thumb. */
   1.110 +  MOZ_GTK_SCALE_THUMB_HORIZONTAL,
   1.111 +  MOZ_GTK_SCALE_THUMB_VERTICAL,
   1.112 +  /* Paints a GtkSpinButton */
   1.113 +  MOZ_GTK_SPINBUTTON,
   1.114 +  MOZ_GTK_SPINBUTTON_UP,
   1.115 +  MOZ_GTK_SPINBUTTON_DOWN,
   1.116 +  MOZ_GTK_SPINBUTTON_ENTRY,
   1.117 +  /* Paints the gripper of a GtkHandleBox. */
   1.118 +  MOZ_GTK_GRIPPER,
   1.119 +  /* Paints a GtkEntry. */
   1.120 +  MOZ_GTK_ENTRY,
   1.121 +  /* Paints a GtkOptionMenu. */
   1.122 +  MOZ_GTK_DROPDOWN,
   1.123 +  /* Paints a dropdown arrow (a GtkButton containing a down GtkArrow). */
   1.124 +  MOZ_GTK_DROPDOWN_ARROW,
   1.125 +  /* Paints an entry in an editable option menu */
   1.126 +  MOZ_GTK_DROPDOWN_ENTRY,
   1.127 +  /* Paints the container part of a GtkCheckButton. */
   1.128 +  MOZ_GTK_CHECKBUTTON_CONTAINER,
   1.129 +  /* Paints the container part of a GtkRadioButton. */
   1.130 +  MOZ_GTK_RADIOBUTTON_CONTAINER,
   1.131 +  /* Paints the label of a GtkCheckButton (focus outline) */
   1.132 +  MOZ_GTK_CHECKBUTTON_LABEL,
   1.133 +  /* Paints the label of a GtkRadioButton (focus outline) */
   1.134 +  MOZ_GTK_RADIOBUTTON_LABEL,
   1.135 +  /* Paints the background of a GtkHandleBox. */
   1.136 +  MOZ_GTK_TOOLBAR,
   1.137 +  /* Paints a toolbar separator */
   1.138 +  MOZ_GTK_TOOLBAR_SEPARATOR,
   1.139 +  /* Paints a GtkToolTip */
   1.140 +  MOZ_GTK_TOOLTIP,
   1.141 +  /* Paints a GtkFrame (e.g. a status bar panel). */
   1.142 +  MOZ_GTK_FRAME,
   1.143 +  /* Paints a resize grip for a GtkWindow */
   1.144 +  MOZ_GTK_RESIZER,
   1.145 +  /* Paints a GtkProgressBar. */
   1.146 +  MOZ_GTK_PROGRESSBAR,
   1.147 +  /* Paints a progress chunk of a GtkProgressBar. */
   1.148 +  MOZ_GTK_PROGRESS_CHUNK,
   1.149 +  /* Paints a progress chunk of an indeterminated GtkProgressBar. */
   1.150 +  MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE,
   1.151 +  /* Paints a progress chunk of a vertical indeterminated GtkProgressBar. */
   1.152 +  MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE,
   1.153 +  /* Paints a tab of a GtkNotebook. flags is a GtkTabFlags, defined above. */
   1.154 +  MOZ_GTK_TAB,
   1.155 +  /* Paints the background and border of a GtkNotebook. */
   1.156 +  MOZ_GTK_TABPANELS,
   1.157 +  /* Paints a GtkArrow for a GtkNotebook. flags is a GtkArrowType. */
   1.158 +  MOZ_GTK_TAB_SCROLLARROW,
   1.159 +  /* Paints the background and border of a GtkTreeView */
   1.160 +  MOZ_GTK_TREEVIEW,
   1.161 +  /* Paints treeheader cells */
   1.162 +  MOZ_GTK_TREE_HEADER_CELL,
   1.163 +  /* Paints sort arrows in treeheader cells */
   1.164 +  MOZ_GTK_TREE_HEADER_SORTARROW,
   1.165 +  /* Paints an expander for a GtkTreeView */
   1.166 +  MOZ_GTK_TREEVIEW_EXPANDER,
   1.167 +  /* Paints the background of the menu bar. */
   1.168 +  MOZ_GTK_MENUBAR,
   1.169 +  /* Paints the background of menus, context menus. */
   1.170 +  MOZ_GTK_MENUPOPUP,
   1.171 +  /* Paints the arrow of menuitems that contain submenus */
   1.172 +  MOZ_GTK_MENUARROW,
   1.173 +  /* Paints an arrow in a toolbar button. flags is a GtkArrowType. */
   1.174 +  MOZ_GTK_TOOLBARBUTTON_ARROW,
   1.175 +  /* Paints items of menubar and popups. */
   1.176 +  MOZ_GTK_MENUITEM,
   1.177 +  MOZ_GTK_CHECKMENUITEM,
   1.178 +  MOZ_GTK_RADIOMENUITEM,
   1.179 +  MOZ_GTK_MENUSEPARATOR,
   1.180 +  /* Paints a GtkVPaned separator */
   1.181 +  MOZ_GTK_SPLITTER_HORIZONTAL,
   1.182 +  /* Paints a GtkHPaned separator */
   1.183 +  MOZ_GTK_SPLITTER_VERTICAL,
   1.184 +  /* Paints the background of a window, dialog or page. */
   1.185 +  MOZ_GTK_WINDOW
   1.186 +} GtkThemeWidgetType;
   1.187 +
   1.188 +/*** General library functions ***/
   1.189 +/**
   1.190 + * Initializes the drawing library.  You must call this function
   1.191 + * prior to using any other functionality.
   1.192 + * returns: MOZ_GTK_SUCCESS if there were no errors
   1.193 + *          MOZ_GTK_UNSAFE_THEME if the current theme engine is known
   1.194 + *                               to crash with gtkdrawing.
   1.195 + */
   1.196 +gint moz_gtk_init();
   1.197 +
   1.198 +/**
   1.199 + * Enable GTK+ 1.2.9+ theme enhancements. You must provide a pointer
   1.200 + * to the GTK+ 1.2.9+ function "gtk_style_get_prop_experimental".
   1.201 + * styleGetProp:  pointer to gtk_style_get_prop_experimental
   1.202 + * 
   1.203 + * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.204 + */
   1.205 +gint moz_gtk_enable_style_props(style_prop_t styleGetProp);
   1.206 +
   1.207 +/**
   1.208 + * Perform cleanup of the drawing library. You should call this function
   1.209 + * when your program exits, or you no longer need the library.
   1.210 + *
   1.211 + * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.212 + */
   1.213 +gint moz_gtk_shutdown();
   1.214 +
   1.215 +#if (MOZ_WIDGET_GTK == 2)
   1.216 +/**
   1.217 + * Retrieves the colormap to use for drawables passed to moz_gtk_widget_paint.
   1.218 + */
   1.219 +GdkColormap* moz_gtk_widget_get_colormap();
   1.220 +#endif
   1.221 +
   1.222 +/*** Widget drawing ***/
   1.223 +#if (MOZ_WIDGET_GTK == 2)
   1.224 +/**
   1.225 + * Paint a widget in the current theme.
   1.226 + * widget:    a constant giving the widget to paint
   1.227 + * drawable:  the drawable to paint to;
   1.228 + *            it's colormap must be moz_gtk_widget_get_colormap().
   1.229 + * rect:      the bounding rectangle for the widget
   1.230 + * cliprect:  a clipprect rectangle for this painting operation
   1.231 + * state:     the state of the widget.  ignored for some widgets.
   1.232 + * flags:     widget-dependant flags; see the GtkThemeWidgetType definition.
   1.233 + * direction: the text direction, to draw the widget correctly LTR and RTL.
   1.234 + */
   1.235 +gint
   1.236 +moz_gtk_widget_paint(GtkThemeWidgetType widget, GdkDrawable* drawable,
   1.237 +                     GdkRectangle* rect, GdkRectangle* cliprect,
   1.238 +                     GtkWidgetState* state, gint flags,
   1.239 +                     GtkTextDirection direction);
   1.240 +#else
   1.241 +gint
   1.242 +moz_gtk_widget_paint(GtkThemeWidgetType widget, cairo_t *cr,
   1.243 +                     GdkRectangle* rect,
   1.244 +                     GtkWidgetState* state, gint flags,
   1.245 +                     GtkTextDirection direction);
   1.246 +#endif
   1.247 +
   1.248 +
   1.249 +/*** Widget metrics ***/
   1.250 +/**
   1.251 + * Get the border size of a widget
   1.252 + * left/right:  [OUT] the widget's left/right border
   1.253 + * top/bottom:  [OUT] the widget's top/bottom border
   1.254 + * direction:   the text direction for the widget
   1.255 + * inhtml:      boolean indicating whether this widget will be drawn as a HTML form control,
   1.256 + *              in order to workaround a size issue (MOZ_GTK_BUTTON only, ignored otherwise)
   1.257 + *
   1.258 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.259 + */
   1.260 +gint moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* left, gint* top, 
   1.261 +                               gint* right, gint* bottom, GtkTextDirection direction,
   1.262 +                               gboolean inhtml);
   1.263 +
   1.264 +/**
   1.265 + * Get the desired size of a GtkCheckButton
   1.266 + * indicator_size:     [OUT] the indicator size
   1.267 + * indicator_spacing:  [OUT] the spacing between the indicator and its
   1.268 + *                     container
   1.269 + *
   1.270 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.271 + */
   1.272 +gint
   1.273 +moz_gtk_checkbox_get_metrics(gint* indicator_size, gint* indicator_spacing);
   1.274 +
   1.275 +/**
   1.276 + * Get the desired size of a GtkRadioButton
   1.277 + * indicator_size:     [OUT] the indicator size
   1.278 + * indicator_spacing:  [OUT] the spacing between the indicator and its
   1.279 + *                     container
   1.280 + *
   1.281 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.282 + */
   1.283 +gint
   1.284 +moz_gtk_radio_get_metrics(gint* indicator_size, gint* indicator_spacing);
   1.285 +
   1.286 +/**
   1.287 + * Get the inner-border value for a GtkButton widget (button or tree header)
   1.288 + * widget:             [IN]  the widget to get the border value for 
   1.289 + * inner_border:       [OUT] the inner border
   1.290 + *
   1.291 + * returns:   MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.292 + */
   1.293 +gint
   1.294 +moz_gtk_button_get_inner_border(GtkWidget* widget, GtkBorder* inner_border);
   1.295 +
   1.296 +/** Get the focus metrics for a treeheadercell, button, checkbox, or radio button.
   1.297 + * widget:             [IN]  the widget to get the focus metrics for    
   1.298 + * interior_focus:     [OUT] whether the focus is drawn around the
   1.299 + *                           label (TRUE) or around the whole container (FALSE)
   1.300 + * focus_width:        [OUT] the width of the focus line
   1.301 + * focus_pad:          [OUT] the padding between the focus line and children
   1.302 + *
   1.303 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.304 + */
   1.305 +gint
   1.306 +moz_gtk_widget_get_focus(GtkWidget* widget, gboolean* interior_focus,
   1.307 +                         gint* focus_width, gint* focus_pad);
   1.308 +
   1.309 +/** Get the horizontal padding for the menuitem widget or checkmenuitem widget.
   1.310 + * horizontal_padding: [OUT] The left and right padding of the menuitem or checkmenuitem
   1.311 + *
   1.312 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.313 + */
   1.314 +gint
   1.315 +moz_gtk_menuitem_get_horizontal_padding(gint* horizontal_padding);
   1.316 +
   1.317 +gint
   1.318 +moz_gtk_checkmenuitem_get_horizontal_padding(gint* horizontal_padding);
   1.319 +
   1.320 +/**
   1.321 + * Some GTK themes draw their indication for the default button outside
   1.322 + * the button (e.g. the glow in New Wave). This gets the extra space necessary.
   1.323 + *
   1.324 + * border_top:  [OUT] extra space to add above
   1.325 + * border_left:  [OUT] extra space to add to the left
   1.326 + * border_bottom:  [OUT] extra space to add underneath
   1.327 + * border_right:  [OUT] extra space to add to the right
   1.328 + *
   1.329 + * returns:   MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.330 + */
   1.331 +gint
   1.332 +moz_gtk_button_get_default_overflow(gint* border_top, gint* border_left,
   1.333 +                                    gint* border_bottom, gint* border_right);
   1.334 +
   1.335 +/**
   1.336 + * Get the desired size of a GtkScale thumb
   1.337 + * orient:           [IN] the scale orientation
   1.338 + * thumb_length:     [OUT] the length of the thumb
   1.339 + * thumb_height:     [OUT] the height of the thumb
   1.340 + *
   1.341 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.342 + */
   1.343 +gint
   1.344 +moz_gtk_get_scalethumb_metrics(GtkOrientation orient, gint* thumb_length, gint* thumb_height);
   1.345 +
   1.346 +/**
   1.347 + * Get the desired metrics for a GtkScrollbar
   1.348 + * metrics:          [IN]  struct which will contain the metrics
   1.349 + *
   1.350 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.351 + */
   1.352 +gint
   1.353 +moz_gtk_get_scrollbar_metrics(MozGtkScrollbarMetrics* metrics);
   1.354 +
   1.355 +/**
   1.356 + * Get the desired size of a dropdown arrow button
   1.357 + * width:   [OUT] the desired width
   1.358 + * height:  [OUT] the desired height
   1.359 + *
   1.360 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.361 + */
   1.362 +gint moz_gtk_get_combo_box_entry_button_size(gint* width, gint* height);
   1.363 +
   1.364 +/**
   1.365 + * Get the desired size of a scroll arrow widget
   1.366 + * width:   [OUT] the desired width
   1.367 + * height:  [OUT] the desired height
   1.368 + *
   1.369 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.370 + */
   1.371 +gint moz_gtk_get_tab_scroll_arrow_size(gint* width, gint* height);
   1.372 +
   1.373 +/**
   1.374 + * Get the desired size of an arrow in a button
   1.375 + * width:   [OUT] the desired width
   1.376 + * height:  [OUT] the desired height
   1.377 + *
   1.378 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.379 + */
   1.380 +gint moz_gtk_get_arrow_size(gint* width, gint* height);
   1.381 +
   1.382 +/**
   1.383 + * Get the desired size of a toolbar separator
   1.384 + * size:    [OUT] the desired width
   1.385 + *
   1.386 + * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.387 + */
   1.388 +gint moz_gtk_get_toolbar_separator_width(gint* size);
   1.389 +
   1.390 +/**
   1.391 + * Get the size of a regular GTK expander that shows/hides content
   1.392 + * size:    [OUT] the size of the GTK expander, size = width = height.
   1.393 + *
   1.394 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.395 + */
   1.396 +gint moz_gtk_get_expander_size(gint* size);
   1.397 +
   1.398 +/**
   1.399 + * Get the size of a treeview's expander (we call them twisties)
   1.400 + * size:    [OUT] the size of the GTK expander, size = width = height.
   1.401 + *
   1.402 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.403 + */
   1.404 +gint moz_gtk_get_treeview_expander_size(gint* size);
   1.405 +
   1.406 +/**
   1.407 + * Get the desired height of a menu separator
   1.408 + * size:    [OUT] the desired height
   1.409 + *
   1.410 + * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.411 + */
   1.412 +gint moz_gtk_get_menu_separator_height(gint* size);
   1.413 +
   1.414 +/**
   1.415 + * Get the desired size of a splitter
   1.416 + * orientation:   [IN]  GTK_ORIENTATION_HORIZONTAL or GTK_ORIENTATION_VERTICAL
   1.417 + * size:          [OUT] width or height of the splitter handle
   1.418 + *
   1.419 + * returns:    MOZ_GTK_SUCCESS if there was no error, an error code otherwise
   1.420 + */
   1.421 +gint moz_gtk_splitter_get_metrics(gint orientation, gint* size);
   1.422 +
   1.423 +/**
   1.424 + * Retrieve an actual GTK scrollbar widget for style analysis. It will not
   1.425 + * be modified.
   1.426 + */
   1.427 +GtkWidget* moz_gtk_get_scrollbar_widget(void);
   1.428 +
   1.429 +/**
   1.430 + * Get the YTHICKNESS of a tab (notebook extension).
   1.431 + */
   1.432 +gint moz_gtk_get_tab_thickness(void);
   1.433 +
   1.434 +/**
   1.435 + * Get a boolean which indicates whether or not to use images in menus.
   1.436 + * If TRUE, use images in menus.
   1.437 + */
   1.438 +gboolean moz_gtk_images_in_menus(void);
   1.439 +
   1.440 +/**
   1.441 + * Get a boolean which indicates whether or not to use images in buttons.
   1.442 + * If TRUE, use images in buttons.
   1.443 + */
   1.444 +gboolean moz_gtk_images_in_buttons(void);
   1.445 +
   1.446 +#ifdef __cplusplus
   1.447 +}
   1.448 +#endif /* __cplusplus */
   1.449 +
   1.450 +#endif

mercurial