static void draw_radio (GtkWidget *widget, cairo_t *cr, gint x, gint y, GtkStateFlags state, gint *width, gint *height) { GtkStyleContext *button_context; GtkStyleContext *check_context; gint contents_x, contents_y, contents_width, contents_height; /* This information is taken from the GtkRadioButton docs, see "CSS nodes" */ button_context = get_style (NULL, "radiobutton"); check_context = get_style (button_context, "radio"); gtk_style_context_set_state (check_context, state); *width = *height = 0; query_size (button_context, width, height); query_size (check_context, width, height); draw_style_common (button_context, cr, x, y, *width, *height, NULL, NULL, NULL, NULL); draw_style_common (check_context, cr, x, y, *width, *height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_check (check_context, cr, contents_x, contents_y, contents_width, contents_height); g_object_unref (check_context); g_object_unref (button_context); }
static void draw_check (GtkWidget *widget, cairo_t *cr, gint x, gint y, GtkStateFlags state) { GtkStyleContext *button_context; GtkStyleContext *check_context; /* This information is taken from the GtkCheckButton docs, see "CSS nodes" */ const char *path[2] = { "checkbutton", "check" }; button_context = get_style (NULL, path[0]); check_context = get_style (button_context, path[1]); gtk_style_context_set_state (check_context, state); gtk_render_background (check_context, cr, x, y, 20, 20); gtk_render_frame (check_context, cr, x, y, 20, 20); gtk_render_check (check_context, cr, x, y, 20, 20); g_object_unref (check_context); g_object_unref (button_context); }
static gboolean draw_cb_checks (GtkWidget *widget, cairo_t *cr) { GtkStyleContext *context; context = gtk_widget_get_style_context (widget); gtk_style_context_save (context); gtk_style_context_add_class (context, "check"); gtk_style_context_set_state (context, 0); gtk_render_check (context, cr, 12, 12, 12, 12); gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE); gtk_render_check (context, cr, 36, 12, 12, 12); gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT); gtk_render_check (context, cr, 60, 12, 12, 12); gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE); gtk_render_check (context, cr, 84, 12, 12, 12); gtk_style_context_restore (context); return TRUE; }
static void draw_menu (GtkWidget *widget, cairo_t *cr, gint x, gint y, gint width, gint *height) { GtkStyleContext *menu_context; GtkStyleContext *menuitem_context; GtkStyleContext *hovermenuitem_context; GtkStyleContext *hoveredarrowmenuitem_context; GtkStyleContext *arrowmenuitem_context; GtkStyleContext *checkmenuitem_context; GtkStyleContext *disabledarrowmenuitem_context; GtkStyleContext *disabledcheckmenuitem_context; GtkStyleContext *radiomenuitem_context; GtkStyleContext *disablemenuitem_context; GtkStyleContext *disabledradiomenuitem_context; GtkStyleContext *separatormenuitem_context; gint menuitem1_height, menuitem2_height, menuitem3_height, menuitem4_height, menuitem5_height; gint contents_x, contents_y, contents_width, contents_height; gint menu_x, menu_y, menu_width, menu_height; gint arrow_width, arrow_height, arrow_size; gint toggle_x, toggle_y, toggle_width, toggle_height; /* This information is taken from the GtkMenu docs, see "CSS nodes" */ menu_context = get_style (gtk_widget_get_style_context(widget), "menu"); hovermenuitem_context = get_style (menu_context, "menuitem:hover"); hoveredarrowmenuitem_context = get_style (hovermenuitem_context, "arrow.right:dir(ltr)"); menuitem_context = get_style (menu_context, "menuitem"); arrowmenuitem_context = get_style (menuitem_context, "arrow:dir(rtl)"); disablemenuitem_context = get_style (menu_context, "menuitem:disabled"); disabledarrowmenuitem_context = get_style (disablemenuitem_context, "arrow:dir(rtl)"); checkmenuitem_context = get_style (menuitem_context, "check:checked"); disabledcheckmenuitem_context = get_style (disablemenuitem_context, "check"); separatormenuitem_context = get_style (menu_context, "separator:disabled"); radiomenuitem_context = get_style (menuitem_context, "radio:checked"); disabledradiomenuitem_context = get_style (disablemenuitem_context, "radio"); *height = 0; query_size (menu_context, NULL, height); menuitem1_height = 0; query_size (hovermenuitem_context, NULL, &menuitem1_height); query_size (hoveredarrowmenuitem_context, NULL, &menuitem1_height); *height += menuitem1_height; menuitem2_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (menuitem_context, NULL, &menuitem2_height); query_size (arrowmenuitem_context, NULL, &menuitem2_height); query_size (disabledarrowmenuitem_context, NULL, &menuitem2_height); *height += menuitem2_height; menuitem3_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (menuitem_context, NULL, &menuitem3_height); query_size (checkmenuitem_context, NULL, &menuitem3_height); query_size (disabledcheckmenuitem_context, NULL, &menuitem3_height); *height += menuitem3_height; menuitem4_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (separatormenuitem_context, NULL, &menuitem4_height); *height += menuitem4_height; menuitem5_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (menuitem_context, NULL, &menuitem5_height); query_size (radiomenuitem_context, NULL, &menuitem5_height); query_size (disabledradiomenuitem_context, NULL, &menuitem5_height); *height += menuitem5_height; draw_style_common (menu_context, cr, x, y, width, *height, &menu_x, &menu_y, &menu_width, &menu_height); /* Hovered with right arrow */ gtk_style_context_get (hoveredarrowmenuitem_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); draw_style_common (hovermenuitem_context, cr, menu_x, menu_y, menu_width, menuitem1_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_arrow (hoveredarrowmenuitem_context, cr, G_PI / 2, contents_x + contents_width - arrow_size, contents_y + (contents_height - arrow_size) / 2, arrow_size); /* Left arrow sensitive, and right arrow insensitive */ draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height, menu_width, menuitem2_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_style_context_get (arrowmenuitem_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); gtk_render_arrow (arrowmenuitem_context, cr, G_PI / 2, contents_x, contents_y + (contents_height - arrow_size) / 2, arrow_size); gtk_style_context_get (disabledarrowmenuitem_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); gtk_render_arrow (disabledarrowmenuitem_context, cr, G_PI / 2, contents_x + contents_width - arrow_size, contents_y + (contents_height - arrow_size) / 2, arrow_size); /* Left check enabled, sensitive, and right check unchecked, insensitive */ draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height, menu_width, menuitem3_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_style_context_get (checkmenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (checkmenuitem_context, cr, contents_x, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (checkmenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); gtk_style_context_get (disabledcheckmenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (disabledcheckmenuitem_context, cr, contents_x + contents_width - toggle_width, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (disabledcheckmenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); /* Separator */ draw_style_common (separatormenuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height + menuitem3_height, menu_width, menuitem4_height, NULL, NULL, NULL, NULL); /* Left check enabled, sensitive, and right check unchecked, insensitive */ draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height + menuitem3_height + menuitem4_height, menu_width, menuitem5_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_style_context_get (radiomenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (radiomenuitem_context, cr, contents_x, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (radiomenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); gtk_style_context_get (disabledradiomenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (disabledradiomenuitem_context, cr, contents_x + contents_width - toggle_width, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (disabledradiomenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); g_object_unref (menu_context); g_object_unref (menuitem_context); g_object_unref (hovermenuitem_context); g_object_unref (hoveredarrowmenuitem_context); g_object_unref (arrowmenuitem_context); g_object_unref (checkmenuitem_context); g_object_unref (disabledarrowmenuitem_context); g_object_unref (disabledcheckmenuitem_context); g_object_unref (radiomenuitem_context); g_object_unref (disablemenuitem_context); g_object_unref (disabledradiomenuitem_context); g_object_unref (separatormenuitem_context); }
static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr) { GtkCheckMenuItemPrivate *priv = check_menu_item->priv; GtkWidget *widget; gint x, y; widget = GTK_WIDGET (check_menu_item); if (gtk_widget_is_drawable (widget)) { GtkAllocation allocation; GtkStyleContext *context; guint border_width; guint offset; guint toggle_size; guint toggle_spacing; guint horizontal_padding; guint indicator_size; GtkStateFlags state; GtkBorder padding; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_padding (context, state, &padding); gtk_widget_get_allocation (widget, &allocation); gtk_widget_style_get (widget, "toggle-spacing", &toggle_spacing, "horizontal-padding", &horizontal_padding, "indicator-size", &indicator_size, NULL); toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size; border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); offset = border_width + padding.left + 2; if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) { x = offset + horizontal_padding + (toggle_size - toggle_spacing - indicator_size) / 2; } else { x = allocation.width - offset - horizontal_padding - toggle_size + toggle_spacing + (toggle_size - toggle_spacing - indicator_size) / 2; } y = (allocation.height - indicator_size) / 2; if (priv->active || priv->always_show_toggle || (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_PRELIGHT)) { gtk_style_context_save (context); if (priv->inconsistent) state |= GTK_STATE_FLAG_INCONSISTENT; else if (priv->active) state |= GTK_STATE_FLAG_ACTIVE; if (!gtk_widget_is_sensitive (widget)) state |= GTK_STATE_FLAG_INSENSITIVE; gtk_style_context_set_state (context, state); if (priv->draw_as_radio) { gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO); gtk_render_option (context, cr, x, y, indicator_size, indicator_size); } else { gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK); gtk_render_check (context, cr, x, y, indicator_size, indicator_size); } gtk_style_context_restore (context); } } }
static void ag_chart_renderer_render(GtkCellRenderer *renderer, cairo_t *cr, GtkWidget *widget, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) { AgChartRendererPrivate *priv = ag_chart_renderer_get_instance_private( AG_CHART_RENDERER(renderer) ); int margin; GtkStyleContext *context = gtk_widget_get_style_context(widget); GdkPixbuf *pixbuf; gtk_style_context_save(context); gtk_style_context_add_class(context, "ag-chart-renderer"); if (priv->css_class) { gtk_style_context_add_class(context, priv->css_class); } cairo_save(cr); gdk_cairo_rectangle(cr, cell_area); cairo_clip(cr); cairo_translate(cr, cell_area->x, cell_area->y); margin = MAX( AG_CHART_RENDERER_TILE_MARGIN, (int)((cell_area->width - AG_CHART_RENDERER_TILE_SIZE) / 2) ); g_object_get(renderer, "pixbuf", &pixbuf, NULL); if (pixbuf != NULL) { GdkRectangle area = { margin, margin, AG_CHART_RENDERER_TILE_SIZE, AG_CHART_RENDERER_TILE_SIZE }; GTK_CELL_RENDERER_CLASS(ag_chart_renderer_parent_class)->render( renderer, cr, widget, &area, &area, flags ); } else { gtk_render_frame( context, cr, margin, margin, AG_CHART_RENDERER_TILE_SIZE, AG_CHART_RENDERER_TILE_SIZE ); gtk_render_background( context, cr, margin, margin, AG_CHART_RENDERER_TILE_SIZE, AG_CHART_RENDERER_TILE_SIZE ); } gtk_style_context_restore(context); if (priv->toggle_visible) { gint xpad, ypad, x_offset, check_x, check_y; gtk_cell_renderer_get_padding( GTK_CELL_RENDERER(renderer), &xpad, &ypad ); if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) { x_offset = xpad; } else { x_offset = cell_area->width - AG_CHART_RENDERER_CHECK_ICON_SIZE - xpad; } check_x = x_offset; check_y = cell_area->height - AG_CHART_RENDERER_CHECK_ICON_SIZE - ypad; gtk_style_context_save(context); gtk_style_context_add_class(context, GTK_STYLE_CLASS_CHECK); if (priv->checked) { gtk_style_context_set_state(context, GTK_STATE_FLAG_CHECKED); } gtk_render_background( context, cr, check_x, check_y, AG_CHART_RENDERER_CHECK_ICON_SIZE, AG_CHART_RENDERER_CHECK_ICON_SIZE ); gtk_render_frame( context, cr, check_x, check_y, AG_CHART_RENDERER_CHECK_ICON_SIZE, AG_CHART_RENDERER_CHECK_ICON_SIZE ); gtk_render_check( context, cr, check_x, check_y, AG_CHART_RENDERER_CHECK_ICON_SIZE, AG_CHART_RENDERER_CHECK_ICON_SIZE ); gtk_style_context_restore(context); } cairo_restore(cr); }
static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr) { GtkCheckMenuItemPrivate *priv = check_menu_item->priv; GtkWidget *widget; gint x, y; widget = GTK_WIDGET (check_menu_item); if (gtk_widget_is_drawable (widget)) { GtkAllocation allocation; GtkStyleContext *context; guint border_width; guint offset; guint toggle_size; guint toggle_spacing; guint horizontal_padding; guint indicator_size; GtkStateFlags state; GtkBorder padding; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_padding (context, state, &padding); gtk_widget_get_allocation (widget, &allocation); gtk_widget_style_get (widget, "toggle-spacing", &toggle_spacing, "horizontal-padding", &horizontal_padding, "indicator-size", &indicator_size, NULL); toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size; border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); offset = border_width + padding.left + 2; if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) { x = offset + horizontal_padding + (toggle_size - toggle_spacing - indicator_size) / 2; } else { x = allocation.width - offset - horizontal_padding - toggle_size + toggle_spacing + (toggle_size - toggle_spacing - indicator_size) / 2; } y = (allocation.height - indicator_size) / 2; gtk_style_context_save_to_node (context, priv->indicator_node); if (priv->draw_as_radio) gtk_render_option (context, cr, x, y, indicator_size, indicator_size); else gtk_render_check (context, cr, x, y, indicator_size, indicator_size); gtk_style_context_restore (context); } }