static void _gtk_theming_background_init_context (GtkThemingBackground *bg, double width, double height, GtkJunctionSides junction) { GtkStateFlags flags = gtk_style_context_get_state (bg->context); GtkBorder border, padding; gtk_style_context_get_border (bg->context, flags, &border); gtk_style_context_get_padding (bg->context, flags, &padding); /* In the CSS box model, by default the background positioning area is * the padding-box, i.e. all the border-box minus the borders themselves, * which determines also its default size, see * http://dev.w3.org/csswg/css3-background/#background-origin * * In the future we might want to support different origins or clips, but * right now we just shrink to the default. */ _gtk_rounded_box_init_rect (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], 0, 0, width, height); _gtk_rounded_box_apply_border_radius_for_context (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], bg->context, junction); bg->boxes[GTK_CSS_AREA_PADDING_BOX] = bg->boxes[GTK_CSS_AREA_BORDER_BOX]; _gtk_rounded_box_shrink (&bg->boxes[GTK_CSS_AREA_PADDING_BOX], border.top, border.right, border.bottom, border.left); bg->boxes[GTK_CSS_AREA_CONTENT_BOX] = bg->boxes[GTK_CSS_AREA_PADDING_BOX]; _gtk_rounded_box_shrink (&bg->boxes[GTK_CSS_AREA_CONTENT_BOX], padding.top, padding.right, padding.bottom, padding.left); }
static void image_menuitem_set_size_request (GtkWidget *menuitem, GtkIconSize icon_size) { GtkStyleContext *context; GtkStateFlags state; GtkBorder padding, border; int border_width; int icon_height; int req_height; if (!gtk_icon_size_lookup (icon_size, NULL, &icon_height)) return; /* If we don't have a pixmap for this menuitem * at least make sure its the same height as * the rest. * This is a bit ugly, since we should keep this in sync with what's in * gtk_menu_item_size_request() */ context = gtk_widget_get_style_context (menuitem); state = gtk_widget_get_state_flags (menuitem); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_get_border (context, state, &border); border_width = gtk_container_get_border_width (GTK_CONTAINER (menuitem)); req_height = icon_height; req_height += (border_width * 2) + padding.top + padding.bottom + border.top + border.bottom; gtk_widget_set_size_request (menuitem, -1, req_height); }
static void _gtk_theming_background_init_context (GtkThemingBackground *bg) { bg->flags = gtk_style_context_get_state (bg->context); gtk_style_context_get_border (bg->context, bg->flags, &bg->border); gtk_style_context_get_padding (bg->context, bg->flags, &bg->padding); gtk_style_context_get_background_color (bg->context, bg->flags, &bg->bg_color); /* In the CSS box model, by default the background positioning area is * the padding-box, i.e. all the border-box minus the borders themselves, * which determines also its default size, see * http://dev.w3.org/csswg/css3-background/#background-origin * * In the future we might want to support different origins or clips, but * right now we just shrink to the default. */ _gtk_rounded_box_init_rect (&bg->border_box, 0, 0, bg->paint_area.width, bg->paint_area.height); _gtk_rounded_box_apply_border_radius_for_context (&bg->border_box, bg->context, bg->junction); bg->padding_box = bg->border_box; _gtk_rounded_box_shrink (&bg->padding_box, bg->border.top, bg->border.right, bg->border.bottom, bg->border.left); }
void wxPizza::get_border(GtkBorder& border) { #ifndef __WXUNIVERSAL__ if (m_windowStyle & wxBORDER_SIMPLE) border.left = border.right = border.top = border.bottom = 1; else if (m_windowStyle & (wxBORDER_RAISED | wxBORDER_SUNKEN | wxBORDER_THEME)) { #ifdef __WXGTK3__ GtkStyleContext* sc; if (m_windowStyle & (wxHSCROLL | wxVSCROLL)) sc = gtk_widget_get_style_context(wxGTKPrivate::GetTreeWidget()); else sc = gtk_widget_get_style_context(wxGTKPrivate::GetEntryWidget()); gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &border); #else // !__WXGTK3__ GtkStyle* style; if (m_windowStyle & (wxHSCROLL | wxVSCROLL)) style = gtk_widget_get_style(wxGTKPrivate::GetTreeWidget()); else style = gtk_widget_get_style(wxGTKPrivate::GetEntryWidget()); border.left = border.right = style->xthickness; border.top = border.bottom = style->ythickness; #endif // !__WXGTK3__ } else #endif // !__WXUNIVERSAL__ { border.left = border.right = border.top = border.bottom = 0; } }
static void ig_reload_style (GnmItemGrid *ig) { GocItem *item = GOC_ITEM (ig); GtkStyleContext *context = goc_item_get_style_context (item); GtkBorder border; GtkStateFlags state = GTK_STATE_FLAG_NORMAL; GnmPane *pane = GNM_PANE (item->canvas); gtk_style_context_save (context); gtk_style_context_add_region (context, "function-marker", 0); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &ig->function_marker_color); gtk_style_context_get_border_color (context, state, &ig->function_marker_border_color); gtk_style_context_restore (context); gtk_style_context_save (context); gtk_style_context_add_region (context, "pane-divider", 0); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &ig->pane_divider_color); gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border); ig->pane_divider_width = border.top; /* Hack? */ gtk_style_context_restore (context); /* ---------------------------------------- */ context = gtk_widget_get_style_context (GTK_WIDGET (pane)); gtk_widget_style_get (GTK_WIDGET (pane), "function-indicator-size", &ig->function_marker_size, NULL); }
static void query_size (GtkStyleContext *context, gint *width, gint *height) { GtkBorder margin, border, padding; int min_width, min_height; gtk_style_context_get_margin (context, &margin); gtk_style_context_get_border (context, &border); gtk_style_context_get_padding (context, &padding); gtk_style_context_get (context, "min-width", &min_width, "min-height", &min_height, NULL); min_width += margin.left + margin.right + border.left + border.right + padding.left + padding.right; min_height += margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom; if (width) *width = MAX (*width, min_width); if (height) *height = MAX (*height, min_height); }
static void gimp_ruler_size_request (GtkWidget *widget, GtkRequisition *requisition) { GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget); GtkStyleContext *context = gtk_widget_get_style_context (widget); PangoLayout *layout; PangoRectangle ink_rect; GtkBorder border; gint size; layout = gimp_ruler_get_layout (widget, "0123456789"); pango_layout_get_pixel_extents (layout, &ink_rect, NULL); size = 2 + ink_rect.height * 1.7; gtk_style_context_get_border (context, 0, &border); requisition->width = border.left + border.right; requisition->height = border.top + border.bottom; if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { requisition->width += 1; requisition->height += size; } else { requisition->width += size; requisition->height += 1; } }
static cairo_surface_t * ev_document_misc_render_thumbnail_frame (GtkWidget *widget, int width, int height, gboolean inverted_colors, GdkPixbuf *source_pixbuf, cairo_surface_t *source_surface) { GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags state = gtk_widget_get_state_flags (widget); int width_r, height_r; int width_f, height_f; cairo_surface_t *surface; cairo_t *cr; GtkBorder border = {0, }; if (source_surface) { width_r = cairo_image_surface_get_width (source_surface); height_r = cairo_image_surface_get_height (source_surface); } else if (source_pixbuf) { g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL); width_r = gdk_pixbuf_get_width (source_pixbuf); height_r = gdk_pixbuf_get_height (source_pixbuf); } else { width_r = width; height_r = height; } gtk_style_context_save (context); gtk_style_context_add_class (context, "page-thumbnail"); if (inverted_colors) gtk_style_context_add_class (context, "inverted"); gtk_style_context_get_border (context, state, &border); width_f = width_r + border.left + border.right; height_f = height_r + border.top + border.bottom; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width_f, height_f); cr = cairo_create (surface); if (source_surface) { cairo_set_source_surface (cr, source_surface, border.left, border.top); cairo_paint (cr); } else if (source_pixbuf) { gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top); cairo_paint (cr); } else { gtk_render_background (context, cr, 0, 0, width_f, height_f); } gtk_render_frame (context, cr, 0, 0, width_f, height_f); cairo_destroy (cr); gtk_style_context_restore (context); return surface; }
static GdkRectangle gimp_ruler_get_pos_rect (GimpRuler *ruler, gdouble position) { GtkWidget *widget = GTK_WIDGET (ruler); GtkStyleContext *context = gtk_widget_get_style_context (widget); GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler); GtkAllocation allocation; GtkBorder border; gint width, height; gdouble upper, lower; gdouble increment; GdkRectangle rect = { 0, }; if (! gtk_widget_is_drawable (widget)) return rect; gtk_widget_get_allocation (widget, &allocation); gtk_style_context_get_border (context, 0, &border); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { width = allocation.width; height = allocation.height - (border.top + border.bottom); rect.width = height / 2 + 2; rect.width |= 1; /* make sure it's odd */ rect.height = rect.width / 2 + 1; } else { width = allocation.width - (border.left + border.right); height = allocation.height; rect.height = width / 2 + 2; rect.height |= 1; /* make sure it's odd */ rect.width = rect.height / 2 + 1; } gimp_ruler_get_range (ruler, &lower, &upper, NULL); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { increment = (gdouble) width / (upper - lower); rect.x = ROUND ((position - lower) * increment) + (border.left + border.right - rect.width) / 2 - 1; rect.y = (height + rect.height) / 2 + border.top; } else { increment = (gdouble) height / (upper - lower); rect.x = (width + rect.width) / 2 + border.left; rect.y = ROUND ((position - lower) * increment) + (border.top + border.bottom - rect.height) / 2 - 1; } return rect; }
static void _style_get_borders (GtkStyleContext *context, GtkBorder *border_out) { GtkBorder padding, border; GtkStateFlags state; state = gtk_style_context_get_state (context); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_get_border (context, state, &border); border_out->top = padding.top + border.top; border_out->bottom = padding.bottom + border.bottom; border_out->left = padding.left + border.left; border_out->right = padding.right + border.right; }
static void update_border_and_margin (GstyleColorWidget *self) { GtkStyleContext *style_context; GtkStateFlags state; g_assert (GSTYLE_IS_COLOR_WIDGET (self)); style_context = gtk_widget_get_style_context (GTK_WIDGET (self)); state = gtk_style_context_get_state (style_context); gtk_style_context_get_margin (style_context, state, &self->cached_margin); gtk_style_context_get_border (style_context, state, &self->cached_border); }
static void xfce_arrow_button_get_thickness (GtkStyleContext *context, xfce_arrow_button_thickness *thickness) { GtkBorder border; GtkBorder margin; GtkBorder padding; gint xthickness; gint ythickness; gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border); gtk_style_context_get_margin (context, GTK_STATE_FLAG_NORMAL, &margin); gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &padding); thickness->x = MAX (border.left + margin.left + padding.left, border.right + margin.right + padding.right); thickness->y = MAX (border.top + margin.top + padding.top, border.bottom + margin.bottom + padding.bottom); }
static void get_padding_and_border (GtkWidget *widget, GtkBorder *border) { GtkStyleContext *context; GtkStateFlags state; GtkBorder tmp; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_padding (context, state, border); gtk_style_context_get_border (context, state, &tmp); border->top += tmp.top; border->right += tmp.right; border->bottom += tmp.bottom; border->left += tmp.left; }
static void draw_style_common (GtkStyleContext *context, cairo_t *cr, gint x, gint y, gint width, gint height, gint *contents_x, gint *contents_y, gint *contents_width, gint *contents_height) { GtkBorder margin, border, padding; int min_width, min_height; gtk_style_context_get_margin (context, &margin); gtk_style_context_get_border (context, &border); gtk_style_context_get_padding (context, &padding); gtk_style_context_get (context, "min-width", &min_width, "min-height", &min_height, NULL); x += margin.left; y += margin.top; width -= margin.left + margin.right; height -= margin.top + margin.bottom; width = MAX (width, min_width); height = MAX (height, min_height); gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); if (contents_x) *contents_x = x + border.left + padding.left; if (contents_y) *contents_y = y + border.top + padding.top; if (contents_width) *contents_width = width - border.left - border.right - padding.left - padding.right; if (contents_height) *contents_height = height - border.top - border.bottom - padding.top - padding.bottom; }
static void get_padding_and_border (GdNotification *notification, GtkBorder *border) { GtkStyleContext *context; GtkStateFlags state; GtkBorder tmp; context = gtk_widget_get_style_context (GTK_WIDGET (notification)); state = gtk_widget_get_state_flags (GTK_WIDGET (notification)); gtk_style_context_get_padding (context, state, border); gtk_style_context_get_border (context, state, &tmp); border->top += tmp.top; border->right += tmp.right; border->bottom += tmp.bottom; border->left += tmp.left; }
static void gtk_level_bar_get_min_block_size (GtkLevelBar *self, gint *block_width, gint *block_height) { GtkWidget *widget = GTK_WIDGET (self); GtkStyleContext *context; GtkStateFlags state; GtkBorder border, tmp, tmp2; gint min_width, min_height; context = gtk_widget_get_style_context (widget); gtk_style_context_save_to_node (context, self->priv->block_node[0]); state = gtk_style_context_get_state (context); gtk_style_context_get_border (context, state, &border); gtk_style_context_get_padding (context, state, &tmp); gtk_style_context_get_margin (context, state, &tmp2); gtk_style_context_restore (context); gtk_style_context_get_style (context, "min-block-width", &min_width, "min-block-height", &min_height, NULL); border.top += tmp.top; border.right += tmp.right; border.bottom += tmp.bottom; border.left += tmp.left; border.top += tmp2.top; border.right += tmp2.right; border.bottom += tmp2.bottom; border.left += tmp2.left; if (block_width) *block_width = MAX (border.left + border.right, min_width); if (block_height) *block_height = MAX (border.top + border.bottom, min_height); }
static gint gd_tagged_entry_tag_get_width (GdTaggedEntryTag *tag, GdTaggedEntry *entry) { GtkBorder button_padding, button_border, button_margin; GtkStyleContext *context; GtkStateFlags state; gint layout_width; gint button_width; gint scale_factor; gd_tagged_entry_tag_ensure_layout (tag, entry); pango_layout_get_pixel_size (tag->layout, &layout_width, NULL); context = gd_tagged_entry_tag_get_context (tag, entry); state = gd_tagged_entry_tag_get_state (tag, entry); gtk_style_context_get_padding (context, state, &button_padding); gtk_style_context_get_border (context, state, &button_border); gtk_style_context_get_margin (context, state, &button_margin); gd_tagged_entry_tag_ensure_close_surface (tag, context); g_object_unref (context); button_width = 0; if (entry->button_visible && tag->has_close_button) { scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (entry)); button_width = cairo_image_surface_get_width (tag->close_surface) / scale_factor + BUTTON_INTERNAL_SPACING; } return layout_width + button_padding.left + button_padding.right + button_border.left + button_border.right + button_margin.left + button_margin.right + button_width; }
static void gtk_level_bar_get_min_block_size (GtkLevelBar *self, gint *block_width, gint *block_height) { GtkWidget *widget = GTK_WIDGET (self); GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags flags = gtk_widget_get_state_flags (widget); GtkBorder border, tmp, tmp2; gint min_width, min_height; gtk_style_context_save (context); gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK); gtk_style_context_get_border (context, flags, &border); gtk_style_context_get_padding (context, flags, &tmp); gtk_style_context_get_margin (context, flags, &tmp2); gtk_style_context_restore (context); gtk_style_context_get_style (context, "min-block-width", &min_width, "min-block-height", &min_height, NULL); border.top += tmp.top; border.right += tmp.right; border.bottom += tmp.bottom; border.left += tmp.left; border.top += tmp2.top; border.right += tmp2.right; border.bottom += tmp2.bottom; border.left += tmp2.left; if (block_width) *block_width = MAX (border.left + border.right, min_width); if (block_height) *block_height = MAX (border.top + border.bottom, min_height); }
static void egg_scrolled_window_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height) { EggScrolledWindow *self = (EggScrolledWindow *)widget; EggScrolledWindowPrivate *priv = egg_scrolled_window_get_instance_private (self); g_return_if_fail (EGG_IS_SCROLLED_WINDOW (self)); GTK_WIDGET_CLASS (egg_scrolled_window_parent_class)->get_preferred_height_for_width (widget, width, minimum_height, natural_height); if (natural_height) { if (priv->max_content_height > -1) { GtkWidget *child; GtkStyleContext *style; GtkBorder border; gint child_min_height; gint child_nat_height; gint additional; if (!(child = gtk_bin_get_child (GTK_BIN (widget)))) return; style = gtk_widget_get_style_context (widget); gtk_style_context_get_border (style, gtk_style_context_get_state (style), &border); additional = border.top + border.bottom; gtk_widget_get_preferred_height_for_width (child, width, &child_min_height, &child_nat_height); if ((child_nat_height > *natural_height) && (priv->max_content_height > *natural_height)) *natural_height = MIN (priv->max_content_height, child_nat_height) + additional; } } }
static void gtk_level_bar_get_borders (GtkLevelBar *self, GtkBorder *borders_out) { GtkWidget *widget = GTK_WIDGET (self); GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags flags = gtk_widget_get_state_flags (widget); GtkBorder border, tmp; gtk_style_context_save (context); gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH); gtk_style_context_get_border (context, flags, &border); gtk_style_context_get_padding (context, flags, &tmp); gtk_style_context_restore (context); border.top += tmp.top; border.right += tmp.right; border.bottom += tmp.bottom; border.left += tmp.left; if (borders_out) *borders_out = border; }
static void gb_scrolled_window_get_preferred_width (GtkWidget *widget, gint *minimum_width, gint *natural_width) { GbScrolledWindow *self = (GbScrolledWindow *)widget; GbScrolledWindowPrivate *priv = gb_scrolled_window_get_instance_private (self); g_return_if_fail (GB_IS_SCROLLED_WINDOW (self)); GTK_WIDGET_CLASS (gb_scrolled_window_parent_class)->get_preferred_width (widget, minimum_width, natural_width); if (natural_width) { if (priv->max_content_width > -1) { GtkWidget *child; GtkStyleContext *style; GtkBorder border; gint child_min_width; gint child_nat_width; gint additional; if (!(child = gtk_bin_get_child (GTK_BIN (widget)))) return; style = gtk_widget_get_style_context (widget); gtk_style_context_get_border (style, gtk_widget_get_state_flags (widget), &border); additional = border.left = border.right + 1; gtk_widget_get_preferred_width (child, &child_min_width, &child_nat_width); if ((child_nat_width > *natural_width) && (priv->max_content_width > *natural_width)) *natural_width = MIN (priv->max_content_width, child_nat_width) + additional; } } }
static void gtk_level_bar_get_borders (GtkLevelBar *self, GtkBorder *borders_out) { GtkWidget *widget = GTK_WIDGET (self); GtkStyleContext *context; GtkStateFlags state; GtkBorder border, tmp; context = gtk_widget_get_style_context (widget); gtk_style_context_save_to_node (context, self->priv->trough_node); state = gtk_style_context_get_state (context); gtk_style_context_get_border (context, state, &border); gtk_style_context_get_padding (context, state, &tmp); gtk_style_context_restore (context); border.top += tmp.top; border.right += tmp.right; border.bottom += tmp.bottom; border.left += tmp.left; if (borders_out) *borders_out = border; }
/** * gd_create_collection_icon: * @base_size: * @pixbufs: (element-type GdkPixbuf): * * Returns: (transfer full): */ GIcon * gd_create_collection_icon (gint base_size, GList *pixbufs) { cairo_surface_t *surface; GIcon *retval; cairo_t *cr; GtkStyleContext *context; GtkWidgetPath *path; GtkBorder tile_border; gint padding, tile_size; gint idx, cur_x, cur_y; GList *l; context = gtk_style_context_new (); gtk_style_context_add_class (context, "documents-collection-icon"); path = gtk_widget_path_new (); gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW); gtk_style_context_set_path (context, path); gtk_widget_path_unref (path); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, base_size, base_size); cr = cairo_create (surface); /* Render the thumbnail itself */ gtk_render_background (context, cr, 0, 0, base_size, base_size); gtk_render_frame (context, cr, 0, 0, base_size, base_size); /* Now, render the tiles inside */ gtk_style_context_remove_class (context, "documents-collection-icon"); gtk_style_context_add_class (context, "documents-collection-icon-tile"); /* TODO: do not hardcode 4, but scale to another layout if more * pixbufs are provided. */ padding = MAX (floor (base_size / 10), 4); gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &tile_border); tile_size = (base_size - (3 * padding)) / 2 - MAX (tile_border.left + tile_border.right, tile_border.top + tile_border.bottom); l = pixbufs; idx = 0; cur_x = padding; cur_y = padding; while (l != NULL && idx < 4) { GdkPixbuf *pix; gboolean is_thumbnail; gint pix_width, pix_height, scale_size; pix = l->data; is_thumbnail = (gdk_pixbuf_get_option (pix, "-documents-has-thumb") != NULL); /* Only draw a box for thumbnails */ if (is_thumbnail) { gtk_render_background (context, cr, cur_x, cur_y, tile_size + tile_border.left + tile_border.right, tile_size + tile_border.top + tile_border.bottom); gtk_render_frame (context, cr, cur_x, cur_y, tile_size + tile_border.left + tile_border.right, tile_size + tile_border.top + tile_border.bottom); } pix_width = gdk_pixbuf_get_width (pix); pix_height = gdk_pixbuf_get_height (pix); scale_size = MIN (pix_width, pix_height); cairo_save (cr); cairo_translate (cr, cur_x + tile_border.left, cur_y + tile_border.top); cairo_rectangle (cr, 0, 0, tile_size, tile_size); cairo_clip (cr); cairo_scale (cr, (gdouble) tile_size / (gdouble) scale_size, (gdouble) tile_size / (gdouble) scale_size); gdk_cairo_set_source_pixbuf (cr, pix, 0, 0); cairo_paint (cr); cairo_restore (cr); if ((idx % 2) == 0) { cur_x += tile_size + padding + tile_border.left + tile_border.right; } else { cur_x = padding; cur_y += tile_size + padding + tile_border.top + tile_border.bottom; } idx++; l = l->next; } retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, base_size, base_size)); cairo_surface_destroy (surface); cairo_destroy (cr); g_object_unref (context); return retval; }
static void draw_cell (Hitori *hitori, GtkStyleContext *style_context, cairo_t *cr, gfloat cell_size, gdouble x_pos, gdouble y_pos, HitoriVector iter) { gchar *text; PangoLayout *layout; gint text_width, text_height; GtkStateFlags state; gboolean painted = FALSE; PangoFontDescription *font_desc; GtkBorder border; GdkRGBA colour = {0.0, 0.0, 0.0, 0.0}; state = gtk_style_context_get_state (style_context); if (hitori->board[iter.x][iter.y].status & CELL_PAINTED) { painted = TRUE; state = GTK_STATE_FLAG_INSENSITIVE; gtk_style_context_set_state (style_context, state); } /* Set up the border */ gtk_style_context_get_border (style_context, state, &border); border.left = BORDER_LEFT; /* Hack! */ /* Draw the fill */ if (hitori->debug == TRUE) { g_debug ("State: %u", state); } if (painted) { lookup_color (style_context, "painted-bg-color", &colour); } else { lookup_color (style_context, "unpainted-bg-color", &colour); } gdk_cairo_set_source_rgba (cr, &colour); cairo_rectangle (cr, x_pos, y_pos, cell_size, cell_size); cairo_fill (cr); /* If the cell is tagged, draw the tag dots */ if (hitori->board[iter.x][iter.y].status & CELL_TAG1) { if (painted) { lookup_color (style_context, "tag1-painted-color", &colour); } else { lookup_color (style_context, "tag1-unpainted-color", &colour); } gdk_cairo_set_source_rgba (cr, &colour); cairo_move_to (cr, x_pos, y_pos + TAG_OFFSET); cairo_line_to (cr, x_pos, y_pos); cairo_line_to (cr, x_pos + TAG_OFFSET, y_pos); cairo_arc (cr, x_pos + TAG_OFFSET, y_pos + TAG_OFFSET, TAG_RADIUS * cell_size, 0.0, 0.5 * M_PI); cairo_fill (cr); } if (hitori->board[iter.x][iter.y].status & CELL_TAG2) { if (painted) { lookup_color (style_context, "tag2-painted-color", &colour); } else { lookup_color (style_context, "tag2-unpainted-color", &colour); } gdk_cairo_set_source_rgba (cr, &colour); cairo_move_to (cr, x_pos + cell_size - TAG_OFFSET, y_pos); cairo_line_to (cr, x_pos + cell_size, y_pos); cairo_line_to (cr, x_pos + cell_size, y_pos + TAG_OFFSET); cairo_arc (cr, x_pos + cell_size - TAG_OFFSET, y_pos + TAG_OFFSET, TAG_RADIUS * cell_size, 0.5 * M_PI, 1.0 * M_PI); cairo_fill (cr); } /* Draw the border */ if (painted) { lookup_color (style_context, "painted-border-color", &colour); } else { lookup_color (style_context, "unpainted-border-color", &colour); } gdk_cairo_set_source_rgba (cr, &colour); cairo_set_line_width (cr, border.left); cairo_rectangle (cr, x_pos, y_pos, cell_size, cell_size); cairo_stroke (cr); /* Draw the text */ text = g_strdup_printf ("%u", hitori->board[iter.x][iter.y].num); layout = pango_cairo_create_layout (cr); pango_layout_set_text (layout, text, -1); font_desc = (painted == TRUE) ? hitori->painted_font_desc : hitori->normal_font_desc; if (hitori->board[iter.x][iter.y].status & CELL_ERROR) { lookup_color (style_context, "mistaken-number-color", &colour); gdk_cairo_set_source_rgba (cr, &colour); pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); } else if (painted) { lookup_color (style_context, "painted-number-color", &colour); gdk_cairo_set_source_rgba (cr, &colour); pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL); } else { g_assert (!painted); lookup_color (style_context, "unpainted-number-color", &colour); gdk_cairo_set_source_rgba (cr, &colour); pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL); } pango_layout_set_font_description (layout, font_desc); pango_layout_get_pixel_size (layout, &text_width, &text_height); cairo_move_to (cr, x_pos + (cell_size - text_width) / 2, y_pos + (cell_size - text_height) / 2); pango_cairo_show_layout (cr, layout); g_free (text); g_object_unref (layout); }
static void gimp_ruler_draw_ticks (GimpRuler *ruler) { GtkWidget *widget = GTK_WIDGET (ruler); GtkStyleContext *context = gtk_widget_get_style_context (widget); GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler); GtkAllocation allocation; GtkBorder border; GdkRGBA color; cairo_t *cr; gint i; gint width, height; gint length, ideal_length; gdouble lower, upper; /* Upper and lower limits, in ruler units */ gdouble increment; /* Number of pixels per unit */ gint scale; /* Number of units per major unit */ gdouble start, end, cur; gchar unit_str[32]; gint digit_height; gint digit_offset; gint text_size; gint pos; gdouble max_size; GimpUnit unit; PangoLayout *layout; PangoRectangle logical_rect, ink_rect; if (! gtk_widget_is_drawable (widget)) return; gtk_widget_get_allocation (widget, &allocation); gtk_style_context_get_border (context, 0, &border); layout = gimp_ruler_get_layout (widget, "0123456789"); pango_layout_get_extents (layout, &ink_rect, &logical_rect); digit_height = PANGO_PIXELS (ink_rect.height) + 2; digit_offset = ink_rect.y; if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { width = allocation.width; height = allocation.height - (border.top + border.bottom); } else { width = allocation.height; height = allocation.width - (border.top + border.bottom); } cr = cairo_create (priv->backing_store); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color); gdk_cairo_set_source_rgba (cr, &color); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_rectangle (cr, border.left, height + border.top, allocation.width - (border.left + border.right), 1); } else { cairo_rectangle (cr, height + border.left, border.top, 1, allocation.height - (border.top + border.bottom)); } gimp_ruler_get_range (ruler, &lower, &upper, &max_size); if ((upper - lower) == 0) goto out; increment = (gdouble) width / (upper - lower); /* determine the scale * use the maximum extents of the ruler to determine the largest * possible number to be displayed. Calculate the height in pixels * of this displayed text. Use this height to find a scale which * leaves sufficient room for drawing the ruler. * * We calculate the text size as for the vruler instead of * actually measuring the text width, so that the result for the * scale looks consistent with an accompanying vruler. */ scale = ceil (max_size); g_snprintf (unit_str, sizeof (unit_str), "%d", scale); text_size = strlen (unit_str) * digit_height + 1; for (scale = 0; scale < (gint)G_N_ELEMENTS (ruler_metric.ruler_scale); scale++) if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_size) break; if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale)) scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1; unit = gimp_ruler_get_unit (ruler); /* drawing starts here */ length = 0; for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--) { gdouble subd_incr; /* hack to get proper subdivisions at full pixels */ if (unit == GIMP_UNIT_PIXEL && scale == 1 && i == 1) subd_incr = 1.0; else subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / (gdouble) ruler_metric.subdivide[i]); if (subd_incr * fabs (increment) <= MINIMUM_INCR) continue; /* don't subdivide pixels */ if (unit == GIMP_UNIT_PIXEL && subd_incr < 1.0) continue; /* Calculate the length of the tickmarks. Make sure that * this length increases for each set of ticks */ ideal_length = height / (i + 1) - 1; if (ideal_length > ++length) length = ideal_length; if (lower < upper) { start = floor (lower / subd_incr) * subd_incr; end = ceil (upper / subd_incr) * subd_incr; } else { start = floor (upper / subd_incr) * subd_incr; end = ceil (lower / subd_incr) * subd_incr; } for (cur = start; cur <= end; cur += subd_incr) { pos = ROUND ((cur - lower) * increment); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_rectangle (cr, pos, height + border.top - length, 1, length); } else { cairo_rectangle (cr, height + border.left - length, pos, length, 1); } /* draw label */ if (i == 0) { g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { pango_layout_set_text (layout, unit_str, -1); pango_layout_get_extents (layout, &logical_rect, NULL); cairo_move_to (cr, pos + 2, border.top + PANGO_PIXELS (logical_rect.y - digit_offset)); pango_cairo_show_layout (cr, layout); } else { gint j; for (j = 0; j < (int) strlen (unit_str); j++) { pango_layout_set_text (layout, unit_str + j, 1); pango_layout_get_extents (layout, NULL, &logical_rect); cairo_move_to (cr, border.left + 1, pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); pango_cairo_show_layout (cr, layout); } } } } } cairo_fill (cr); priv->backing_store_valid = TRUE; out: cairo_destroy (cr); }
static gboolean gtk_bubble_window_draw (GtkWidget *widget, cairo_t *cr) { GtkStyleContext *context; GtkAllocation allocation; GtkWidget *child; GtkBorder border; GdkRGBA border_color; gint rect_x1, rect_x2, rect_y1, rect_y2; gint initial_x, initial_y, final_x, final_y; gint gap_start, gap_end; GtkPositionType gap_side; GtkStateFlags state; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_widget_get_allocation (widget, &allocation); if (gtk_widget_is_composited (widget)) { cairo_save (cr); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba (cr, 0, 0, 0, 0); cairo_paint (cr); cairo_restore (cr); } gtk_bubble_window_get_rect_coords (GTK_BUBBLE_WINDOW (widget), &rect_x1, &rect_y1, &rect_x2, &rect_y2); /* Render the rect background */ gtk_render_background (context, cr, rect_x1, rect_y1, rect_x2 - rect_x1, rect_y2 - rect_y1); gtk_bubble_window_get_gap_coords (GTK_BUBBLE_WINDOW (widget), &initial_x, &initial_y, NULL, NULL, &final_x, &final_y, &gap_side); if (POS_IS_VERTICAL (gap_side)) { gap_start = initial_x; gap_end = final_x; } else { gap_start = initial_y; gap_end = final_y; } /* Now render the frame, without the gap for the arrow tip */ gtk_render_frame_gap (context, cr, rect_x1, rect_y1, rect_x2 - rect_x1, rect_y2 - rect_y1, gap_side, gap_start, gap_end); /* Clip to the arrow shape */ cairo_save (cr); gtk_bubble_window_apply_tail_path (GTK_BUBBLE_WINDOW (widget), cr); cairo_clip (cr); /* Render the arrow background */ gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); /* Render the border of the arrow tip */ gtk_style_context_get_border (context, state, &border); if (border.bottom > 0) { gtk_style_context_get_border_color (context, state, &border_color); gtk_bubble_window_apply_tail_path (GTK_BUBBLE_WINDOW (widget), cr); gdk_cairo_set_source_rgba (cr, &border_color); cairo_set_line_width (cr, border.bottom); cairo_stroke (cr); } /* We're done */ cairo_restore (cr); child = gtk_bin_get_child (GTK_BIN (widget)); if (child) gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr); return TRUE; }
static void greeter_menu_bar_size_allocate(GtkWidget* widget, GtkAllocation* allocation) { GList* item; GList* shell_children; GList* expand_nums = NULL; guint visible_count = 0, expand_count = 0; g_return_if_fail(allocation != NULL); g_return_if_fail(GREETER_IS_MENU_BAR(widget)); gtk_widget_set_allocation(widget, allocation); GtkPackDirection pack_direction = gtk_menu_bar_get_pack_direction(GTK_MENU_BAR(widget)); g_return_if_fail(pack_direction == GTK_PACK_DIRECTION_LTR || pack_direction == GTK_PACK_DIRECTION_RTL); shell_children = gtk_container_get_children(GTK_CONTAINER(widget)); for(item = shell_children; item; item = g_list_next(item)) if(gtk_widget_get_visible(item->data)) { if(gtk_widget_compute_expand(item->data, GTK_ORIENTATION_HORIZONTAL)) { expand_nums = g_list_prepend(expand_nums, GINT_TO_POINTER(visible_count)); expand_count++; } visible_count++; } if(gtk_widget_get_realized(widget)) gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height); if(visible_count > 0) { GtkAllocation remaining_space; GtkStyleContext* context = gtk_widget_get_style_context(widget); GtkStateFlags flags = gtk_widget_get_state_flags(widget); GtkRequestedSize* requested_sizes = g_newa(GtkRequestedSize, visible_count); guint border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); GtkShadowType shadow_type = GTK_SHADOW_OUT; GtkBorder border; gint toggle_size; gtk_style_context_get_padding(context, flags, &border); gtk_widget_style_get(widget, "shadow-type", &shadow_type, NULL); remaining_space.x = (border_width + border.left); remaining_space.y = (border_width + border.top); remaining_space.width = allocation->width - 2 * border_width - border.left - border.right; remaining_space.height = allocation->height - 2 * border_width - border.top - border.bottom; if (shadow_type != GTK_SHADOW_NONE) { gtk_style_context_get_border(context, flags, &border); remaining_space.x += border.left; remaining_space.y += border.top; remaining_space.width -= border.left + border.right; remaining_space.height -= border.top + border.bottom; } GtkRequestedSize* request = requested_sizes; int size = remaining_space.width; gboolean ltr = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_LTR) == (pack_direction == GTK_PACK_DIRECTION_LTR); for(item = shell_children; item; item = g_list_next(item)) { if (!gtk_widget_get_visible(item->data)) continue; request->data = item->data; gtk_widget_get_preferred_width_for_height(item->data, remaining_space.height, &request->minimum_size, &request->natural_size); gtk_menu_item_toggle_size_request(GTK_MENU_ITEM(item->data), &toggle_size); request->minimum_size += toggle_size; request->natural_size += toggle_size; gtk_menu_item_toggle_size_allocate(GTK_MENU_ITEM(item->data), toggle_size); size -= request->minimum_size; request++; } size = gtk_distribute_natural_allocation(size, visible_count, requested_sizes); /* Distribution extra space for widgets with expand=True */ if(size > 0 && expand_nums) { expand_nums = g_list_sort_with_data(expand_nums, (GCompareDataFunc)sort_minimal_size, requested_sizes); GList* first_item = expand_nums; gint needed_size = -1; gint max_size = requested_sizes[GPOINTER_TO_INT(first_item->data)].natural_size; gint total_needed_size = 0; /* Free space that all widgets need to have the same (max_size) width * [___max_width___][widget ][widget____ ] * total_needed_size := [] + [ ] + [ ] * total_needed_size = [ ] */ for(item = g_list_next(expand_nums); item; item = g_list_next(item)) total_needed_size += max_size - requested_sizes[GPOINTER_TO_INT(item->data)].natural_size; while(first_item) { if(size >= total_needed_size) { /* total_needed_size is enough for all remaining widgets */ needed_size = max_size + (size - total_needed_size)/expand_count; break; } /* Removing current maximal widget from list */ total_needed_size -= max_size - requested_sizes[GPOINTER_TO_INT(item->data)].natural_size; first_item = g_list_next(first_item); if(first_item) max_size = requested_sizes[GPOINTER_TO_INT(first_item->data)].natural_size; } for(item = first_item; item; item = g_list_next(item)) { request = &requested_sizes[GPOINTER_TO_INT(item->data)]; gint dsize = needed_size - request->natural_size; if(size < dsize) dsize = size; size -= dsize; request->natural_size += dsize; } } gint i; for(i = 0; i < visible_count; i++) { GtkAllocation child_allocation = remaining_space; request = &requested_sizes[i]; child_allocation.width = request->natural_size; remaining_space.width -= request->natural_size; if (ltr) remaining_space.x += request->natural_size; else child_allocation.x += remaining_space.width; gtk_widget_size_allocate(request->data, &child_allocation); } g_list_free(expand_nums); } g_list_free(shell_children); }
static gboolean swatch_draw (GtkWidget *widget, cairo_t *cr) { GtkColorSwatch *swatch = (GtkColorSwatch*)widget; gdouble width, height; GtkStyleContext *context; GtkStateFlags state; GtkIconTheme *theme; GtkBorder border, padding; GdkRectangle rect; GtkIconInfo *icon_info = NULL; theme = gtk_icon_theme_get_default (); context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); gtk_render_background (context, cr, 0, 0, width, height); if (swatch->priv->has_color) { cairo_pattern_t *pattern; cairo_matrix_t matrix; gtk_render_content_path (context, cr, 0, 0, width, height); if (swatch->priv->use_alpha) { cairo_save (cr); cairo_clip_preserve (cr); cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); cairo_fill_preserve (cr); pattern = _gtk_color_chooser_get_checkered_pattern (); cairo_matrix_init_scale (&matrix, 0.125, 0.125); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); cairo_mask (cr, pattern); cairo_pattern_destroy (pattern); cairo_restore (cr); gdk_cairo_set_source_rgba (cr, &swatch->priv->color); } else { cairo_set_source_rgb (cr, swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue); } cairo_fill (cr); } gtk_render_frame (context, cr, 0, 0, width, height); if (swatch->priv->icon) { icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, PIXBUF_SIZE, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); } else if ((state & GTK_STATE_FLAG_SELECTED) != 0) { GIcon *gicon; gicon = g_themed_icon_new ("object-select-symbolic"); /* fallback for themes that don't have object-select-symbolic */ g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, PIXBUF_SIZE, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); g_object_unref (gicon); } /* now draw the overlay image */ gtk_style_context_get_border (context, state, &border); gtk_style_context_get_padding (context, state, &padding); rect.width = width - (border.left + border.right + padding.left + padding.right); rect.height = height - (border.top + border.bottom + padding.top + padding.bottom); rect.x = border.left + padding.left; rect.y = border.top + padding.top; gtk_style_context_save (context); gtk_style_context_add_class (context, "overlay"); gtk_render_background (context, cr, rect.x, rect.y, rect.width, rect.height); gtk_render_frame (context, cr, rect.x, rect.y, rect.width, rect.height); if (icon_info != NULL) { GdkPixbuf *pixbuf; pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL); if (pixbuf != NULL) { gtk_render_icon (context, cr, pixbuf, rect.x + (rect.width - gdk_pixbuf_get_width (pixbuf)) / 2, rect.y + (rect.height - gdk_pixbuf_get_height (pixbuf)) / 2); g_object_unref (pixbuf); } g_object_unref (icon_info); } if (gtk_widget_has_visible_focus (widget)) { gtk_render_focus (context, cr, 0, 0, width, height); } gtk_style_context_restore (context); return FALSE; }
static void gimp_cell_renderer_toggle_render (GtkCellRenderer *cell, cairo_t *cr, GtkWidget *widget, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) { GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell); GdkRectangle toggle_rect; GdkRectangle draw_rect; GtkStyleContext *context = gtk_widget_get_style_context (widget); GdkRectangle clip_rect; GtkStateFlags state; gboolean active; gint xpad; gint ypad; if (! toggle->stock_id) { GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, cr, widget, background_area, cell_area, flags); return; } gtk_cell_renderer_get_size (cell, widget, cell_area, &toggle_rect.x, &toggle_rect.y, &toggle_rect.width, &toggle_rect.height); gtk_cell_renderer_get_padding (cell, &xpad, &ypad); toggle_rect.x += cell_area->x + xpad; toggle_rect.y += cell_area->y + ypad; toggle_rect.width -= xpad * 2; toggle_rect.height -= ypad * 2; if (toggle_rect.width <= 0 || toggle_rect.height <= 0) return; active = gtk_cell_renderer_toggle_get_active (GTK_CELL_RENDERER_TOGGLE (cell)); if (!gtk_cell_renderer_get_sensitive (cell)) { state = GTK_STATE_FLAG_INSENSITIVE; } else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED) { if (gtk_widget_has_focus (widget)) state = GTK_STATE_FLAG_SELECTED; else state = GTK_STATE_FLAG_ACTIVE; } else { if (gtk_cell_renderer_toggle_get_activatable (GTK_CELL_RENDERER_TOGGLE (cell))) state = GTK_STATE_FLAG_NORMAL; else state = GTK_STATE_FLAG_INSENSITIVE; } if ((flags & GTK_CELL_RENDERER_PRELIT) && gdk_cairo_get_clip_rectangle(cr, &clip_rect) && gdk_rectangle_intersect (&clip_rect, cell_area, &draw_rect)) { cairo_save (cr); gdk_cairo_rectangle (cr, &draw_rect); cairo_clip (cr); gtk_render_frame (context, //gtk_widget_get_style_context (widget), cr, toggle_rect.x, toggle_rect.y, toggle_rect.width, toggle_rect.height); gtk_style_context_restore (context); cairo_restore (cr); } if (active) { GdkPixbuf *insensitive = NULL; GdkPixbuf *pixbuf = toggle->pixbuf; GtkBorder border = { 1, 1, 1, 1 }; #if 0 /* FIXME: for some reason calling gtk_style_context_get_border * makes the icon only visible on hover, so use border = 1 * for now as a workaround */ gtk_style_context_get_border (context, state, &border); #endif toggle_rect.x += border.left; toggle_rect.y += border.top; toggle_rect.width -= (border.left + border.right); toggle_rect.height -= (border.top + border.bottom); if (state & GTK_STATE_FLAG_INSENSITIVE) { GtkIconSource *source; source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, pixbuf); /* The size here is arbitrary; since size isn't * wildcarded in the source, it isn't supposed to be * scaled by the engine function */ gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_icon_source_set_size_wildcarded (source, FALSE); gtk_style_context_save (context); gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE); insensitive = gtk_render_icon_pixbuf (context, source, (GtkIconSize)-1); gtk_style_context_restore (context); gtk_icon_source_free (source); pixbuf = insensitive; } if (gdk_rectangle_intersect (&draw_rect, &toggle_rect, &draw_rect)) { gdk_cairo_set_source_pixbuf (cr, pixbuf, toggle_rect.x, toggle_rect.y); gdk_cairo_rectangle (cr, &draw_rect); cairo_fill (cr); } if (insensitive) g_object_unref (insensitive); } }
static void gimp_cell_renderer_toggle_get_size (GtkCellRenderer *cell, GtkWidget *widget, const GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height) { GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell); GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkBorder border; gint calc_width; gint calc_height; gint pixbuf_width; gint pixbuf_height; gfloat xalign; gfloat yalign; gint xpad; gint ypad; if (! toggle->stock_id) { GTK_CELL_RENDERER_CLASS (parent_class)->get_size (cell, widget, cell_area, x_offset, y_offset, width, height); return; } gtk_cell_renderer_get_alignment (cell, &xalign, &yalign); gtk_cell_renderer_get_padding (cell, &xpad, &ypad); gtk_style_context_get_border (context, 0, &border); if (! toggle->pixbuf) gimp_cell_renderer_toggle_create_pixbuf (toggle, widget); pixbuf_width = gdk_pixbuf_get_width (toggle->pixbuf); pixbuf_height = gdk_pixbuf_get_height (toggle->pixbuf); calc_width = (pixbuf_width + (gint) xpad * 2 + (border.left + border.right)); calc_height = (pixbuf_height + (gint) ypad * 2 + (border.top + border.bottom)); if (width) *width = calc_width; if (height) *height = calc_height; if (cell_area) { if (x_offset) { *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? (1.0 - xalign) : xalign) * (cell_area->width - calc_width)); *x_offset = MAX (*x_offset, 0); } if (y_offset) { *y_offset = yalign * (cell_area->height - calc_height); *y_offset = MAX (*y_offset, 0); } } }