void ScrollbarThemeGtk::paintButton(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part) { GtkStyleContext* styleContext = gtkScrollbarStyleContext(); gtk_style_context_save(styleContext); ScrollbarOrientation orientation = scrollbar->orientation(); applyScrollbarStyleContextClasses(styleContext, orientation); guint flags = 0; if ((BackButtonStartPart == part && scrollbar->currentPos()) || (BackButtonEndPart == part && scrollbar->currentPos()) || (ForwardButtonEndPart == part && scrollbar->currentPos() != scrollbar->maximum()) || (ForwardButtonStartPart == part && scrollbar->currentPos() != scrollbar->maximum())) { if (part == scrollbar->pressedPart()) flags |= GTK_STATE_FLAG_ACTIVE; if (part == scrollbar->hoveredPart()) flags |= GTK_STATE_FLAG_PRELIGHT; } else flags |= GTK_STATE_FLAG_INSENSITIVE; gtk_style_context_set_state(styleContext, static_cast<GtkStateFlags>(flags)); gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BUTTON); gtk_render_background(styleContext, context->platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height()); gtk_render_frame(styleContext, context->platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height()); gfloat arrowScaling; gtk_style_context_get_style(styleContext, "arrow-scaling", &arrowScaling, nullptr); double arrowSize = std::min(rect.width(), rect.height()) * arrowScaling; FloatPoint arrowPoint( rect.x() + (rect.width() - arrowSize) / 2, rect.y() + (rect.height() - arrowSize) / 2); if (flags & GTK_STATE_FLAG_ACTIVE) { gint arrowDisplacementX, arrowDisplacementY; gtk_style_context_get_style(styleContext, "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr); arrowPoint.move(arrowDisplacementX, arrowDisplacementY); } gdouble angle; if (orientation == VerticalScrollbar) angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI : 0; else angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2); gtk_render_arrow(styleContext, context->platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize); gtk_style_context_restore(styleContext); }
/* When can_focus is true, GtkButton allocates larger size than requested * * and causes the panel image to grow indefinitely. * * This workaround compensates for this difference. * * Details in https://bugzilla.gnome.org/show_bug.cgi?id=698030 * */ static gint xfce_panel_image_padding_correction (GtkWidget *widget) { GtkWidget *parent; GtkStyleContext *context; gint focus_width; gint focus_pad; gint correction; parent = gtk_widget_get_parent (widget); if (parent != NULL && GTK_IS_BUTTON (parent) && !gtk_widget_get_can_focus (parent)) { context = gtk_widget_get_style_context (parent); gtk_style_context_get_style (context, "focus-line-width", &focus_width, "focus-padding", &focus_pad, NULL); correction = (focus_width + focus_pad) * 2; } else { correction = 0; } return correction; }
void ScrollbarThemeGtk::updateThemeProperties() { gtk_style_context_get_style( gtkScrollbarStyleContext(), "min-slider-length", &m_minThumbLength, "slider-width", &m_thumbFatness, "trough-border", &m_troughBorderWidth, "stepper-size", &m_stepperSize, "stepper-spacing", &m_stepperSpacing, "trough-under-steppers", &m_troughUnderSteppers, "has-backward-stepper", &m_hasBackButtonStartPart, "has-forward-stepper", &m_hasForwardButtonEndPart, "has-secondary-backward-stepper", &m_hasBackButtonEndPart, "has-secondary-forward-stepper", &m_hasForwardButtonStartPart, nullptr); updateScrollbarsFrameThickness(); }
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 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); }
MetaTilePreview * meta_tile_preview_new (int screen_number, gboolean composited) { MetaTilePreview *preview; GdkScreen *screen; screen = gdk_display_get_screen (gdk_display_get_default (), screen_number); preview = g_new (MetaTilePreview, 1); preview->preview_window = gtk_window_new (GTK_WINDOW_POPUP); gtk_window_set_screen (GTK_WINDOW (preview->preview_window), screen); gtk_widget_set_app_paintable (preview->preview_window, TRUE); preview->preview_color = NULL; preview->tile_rect.x = preview->tile_rect.y = 0; preview->tile_rect.width = preview->tile_rect.height = 0; preview->has_alpha = composited && (gdk_screen_get_rgba_visual (screen) != NULL); if (preview->has_alpha) { GtkStyleContext *context; GtkWidgetPath *path; guchar selection_alpha = 0xFF; gtk_widget_set_visual (preview->preview_window, gdk_screen_get_rgba_visual (screen)); path = gtk_widget_path_new (); gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW); context = gtk_style_context_new (); gtk_style_context_set_path (context, path); gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND); gtk_widget_path_free (path); gtk_style_context_get (context, GTK_STATE_FLAG_SELECTED, "background-color", &preview->preview_color, NULL); /* The background-color for the .rubberband class should probably * contain the correct alpha value - unfortunately, at least for now * it doesn't. Hopefully the following workaround can be removed * when GtkIconView gets ported to GtkStyleContext. */ gtk_style_context_get_style (context, "selection-box-alpha", &selection_alpha, NULL); preview->preview_color->alpha = (double)selection_alpha / 0xFF; g_object_unref (context); } /* We make an assumption that XCreateWindow will be the first operation * when calling gtk_widget_realize() (via gdk_window_new()), or that it * is at least "close enough". */ preview->create_serial = XNextRequest (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); gtk_widget_realize (preview->preview_window); g_signal_connect (preview->preview_window, "draw", G_CALLBACK (meta_tile_preview_draw), preview); return preview; }
static void nemo_cell_renderer_disk_render (GtkCellRenderer *cell, cairo_t *cr, GtkWidget *widget, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) { NemoCellRendererDisk *cellprogress = NEMO_CELL_RENDERER_DISK (cell); gint x, y, w; gint xpad, ypad; gint full; gboolean show = cellprogress->show_disk_full_percent; GtkStyleContext *context; if (show) { context = gtk_widget_get_style_context (widget); GdkColor *gdk_bg_color, *gdk_fg_color; GdkRGBA bg_color, fg_color; gint bar_width, bar_radius, bottom_padding, max_length; gtk_style_context_get_style (context, "disk-full-bg-color", &gdk_bg_color, "disk-full-fg-color", &gdk_fg_color, "disk-full-bar-width", &bar_width, "disk-full-bar-radius", &bar_radius, "disk-full-bottom-padding", &bottom_padding, "disk-full-max-length", &max_length, NULL); if (gdk_bg_color) { convert_color (gdk_bg_color, &bg_color); gdk_color_free (gdk_bg_color); } else { use_default_color (&bg_color); } if (gdk_fg_color) { convert_color (gdk_fg_color, &fg_color); gdk_color_free (gdk_fg_color); } else { use_default_color (&fg_color); } gtk_cell_renderer_get_padding (cell, &xpad, &ypad); x = cell_area->x + xpad; y = cell_area->y + cell_area->height - bar_width - bottom_padding; w = cell_area->width - xpad * 2; w = w < max_length ? w : max_length; full = (int) (((float) cellprogress->disk_full_percent / 100.0) * (float) w); gtk_style_context_save (context); cairo_save (cr); gdk_cairo_set_source_rgba (cr, &bg_color); cairo_rectangle_with_radius_corners (cr, x, y, w, bar_width, bar_radius); cairo_fill (cr); cairo_restore (cr); cairo_save (cr); gdk_cairo_set_source_rgba (cr, &fg_color); cairo_rectangle_with_radius_corners (cr, x, y, full, bar_width, bar_radius); cairo_fill (cr); cairo_restore (cr); gtk_style_context_restore (context); } GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, cr, widget, background_area, cell_area, flags); }
static void update_icon(ShowDesktopData* sdd) { GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; int width, height; GdkPixbuf* icon; GdkPixbuf* scaled; int icon_size; GError* error; #if !GTK_CHECK_VERSION (3, 20, 0) int focus_width = 0; int focus_pad = 0; #endif int thickness = 0; if (!sdd->icon_theme) return; state = gtk_widget_get_state_flags (sdd->button); context = gtk_widget_get_style_context (sdd->button); gtk_style_context_get_padding (context, state, &padding); #if !GTK_CHECK_VERSION (3, 20, 0) gtk_style_context_get_style (context, "focus-line-width", &focus_width, "focus-padding", &focus_pad, NULL); #endif switch (sdd->orient) { case GTK_ORIENTATION_HORIZONTAL: thickness = padding.top + padding.bottom; break; case GTK_ORIENTATION_VERTICAL: thickness = padding.left + padding.right; break; } #if GTK_CHECK_VERSION (3, 20, 0) icon_size = sdd->size - thickness; #else icon_size = sdd->size - 2 * (focus_width + focus_pad) - thickness; #endif if (icon_size < 22) icon_size = 16; else if (icon_size < 32) icon_size = 22; else if (icon_size < 48) icon_size = 32; error = NULL; icon = gtk_icon_theme_load_icon (sdd->icon_theme, SHOW_DESKTOP_ICON, icon_size, 0, &error); if (icon == NULL) { g_printerr(_("Failed to load %s: %s\n"), SHOW_DESKTOP_ICON, error ? error->message : _("Icon not found")); if (error) { g_error_free(error); error = NULL; } gtk_image_set_from_icon_name (GTK_IMAGE (sdd->image), "image-missing", GTK_ICON_SIZE_SMALL_TOOLBAR); return; } width = gdk_pixbuf_get_width(icon); height = gdk_pixbuf_get_height(icon); scaled = NULL; /* Make it fit on the given panel */ switch (sdd->orient) { case GTK_ORIENTATION_HORIZONTAL: width = (icon_size * width) / height; height = icon_size; break; case GTK_ORIENTATION_VERTICAL: height = (icon_size * height) / width; width = icon_size; break; } scaled = gdk_pixbuf_scale_simple(icon, width, height, GDK_INTERP_BILINEAR); if (scaled != NULL) { gtk_image_set_from_pixbuf(GTK_IMAGE(sdd->image), scaled); g_object_unref(scaled); } else { gtk_image_set_from_pixbuf (GTK_IMAGE (sdd->image), icon); } g_object_unref (icon); }