GtkWidget * hitori_create_interface (Hitori *hitori) { GtkBuilder *builder; GtkStyleContext *style_context; GtkCssProvider *css_provider; const PangoFontDescription *font; GAction *action; builder = gtk_builder_new_from_resource ("/org/gnome/Hitori/ui/hitori.ui"); gtk_builder_set_translation_domain (builder, PACKAGE); gtk_builder_connect_signals (builder, hitori); /* Setup the main window */ hitori->window = GTK_WIDGET (gtk_builder_get_object (builder, "hitori_main_window")); hitori->drawing_area = GTK_WIDGET (gtk_builder_get_object (builder, "hitori_drawing_area")); hitori->timer_label = GTK_LABEL (gtk_builder_get_object (builder, "hitori_timer")); g_object_unref (builder); /* Set up actions */ g_action_map_add_action_entries (G_ACTION_MAP (hitori), app_entries, G_N_ELEMENTS (app_entries), hitori); g_action_map_add_action_entries (G_ACTION_MAP (hitori->window), win_entries, G_N_ELEMENTS (win_entries), hitori); action = g_settings_create_action (hitori->settings, "board-size"); g_action_map_add_action (G_ACTION_MAP (hitori), action); g_signal_connect (G_OBJECT (action), "notify::state", (GCallback) board_size_change_cb, hitori); g_object_unref (action); hitori->undo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "undo")); hitori->redo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "redo")); hitori->hint_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "hint")); /* Set up font descriptions for the drawing area */ style_context = gtk_widget_get_style_context (hitori->drawing_area); gtk_style_context_get (style_context, gtk_style_context_get_state (style_context), GTK_STYLE_PROPERTY_FONT, &font, NULL); hitori->normal_font_desc = pango_font_description_copy (font); hitori->painted_font_desc = pango_font_description_copy (font); /* Load CSS for the drawing area */ css_provider = gtk_css_provider_new (); gtk_css_provider_load_from_resource (css_provider, "/org/gnome/Hitori/ui/hitori.css"); gtk_style_context_add_provider (style_context, GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref (css_provider); /* Reset the timer */ hitori_reset_timer (hitori); /* Disable undo/redo until a cell has been clicked. */ g_simple_action_set_enabled (hitori->undo_action, FALSE); g_simple_action_set_enabled (hitori->redo_action, FALSE); return hitori->window; }
static void gm_cell_renderer_bitext_update_style (GmCellRendererBitext* renderer, GtkWidget* widget) { GtkStyleContext *style = NULL; GtkStateFlags state; PangoAttrList *attr_list = NULL; PangoAttribute *attr_size = NULL; const PangoFontDescription* font = NULL; style = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); attr_list = pango_attr_list_new (); /* we want the secondary text smaller */ gtk_style_context_get (style, state, "font", &font, NULL); attr_size = pango_attr_size_new ((int) (pango_font_description_get_size (font) * 0.8)); attr_size->start_index = strlen (renderer->priv->primary_text) + 1; attr_size->end_index = (guint) - 1; pango_attr_list_insert (attr_list, attr_size); g_object_set (renderer, "visible", TRUE, "weight", PANGO_WEIGHT_NORMAL, "attributes", attr_list, NULL); pango_attr_list_unref (attr_list); }
static void bg(GtkStyleContext* sc, wxColour& color, int state = GTK_STATE_FLAG_NORMAL) { GdkRGBA* rgba; cairo_pattern_t* pattern = NULL; gtk_style_context_set_state(sc, GtkStateFlags(state)); gtk_style_context_get(sc, GtkStateFlags(state), "background-color", &rgba, "background-image", &pattern, NULL); color = wxColour(*rgba); gdk_rgba_free(rgba); // "background-image" takes precedence over "background-color". // If there is an image, try to get a color out of it. if (pattern) { if (cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SURFACE) { cairo_surface_t* surf; cairo_pattern_get_surface(pattern, &surf); if (cairo_surface_get_type(surf) == CAIRO_SURFACE_TYPE_IMAGE) { const guchar* data = cairo_image_surface_get_data(surf); const int stride = cairo_image_surface_get_stride(surf); // choose a pixel in the middle vertically, // images often have a vertical gradient const int i = stride * (cairo_image_surface_get_height(surf) / 2); const unsigned* p = reinterpret_cast<const unsigned*>(data + i); const unsigned pixel = *p; guchar r, g, b, a = 0xff; switch (cairo_image_surface_get_format(surf)) { case CAIRO_FORMAT_ARGB32: a = guchar(pixel >> 24); // fallthrough case CAIRO_FORMAT_RGB24: r = guchar(pixel >> 16); g = guchar(pixel >> 8); b = guchar(pixel); break; default: a = 0; break; } if (a != 0) { if (a != 0xff) { // un-premultiply r = guchar((r * 0xff) / a); g = guchar((g * 0xff) / a); b = guchar((b * 0xff) / a); } color.Set(r, g, b, a); } } } cairo_pattern_destroy(pattern); }
static void update_hours_sidebar_size (GcalWeekView *self) { GtkStyleContext *context; GtkStateFlags state; GtkSizeGroup *sidebar_sizegroup; GtkWidget *widget; GtkBorder padding; PangoLayout *layout; PangoFontDescription *font_desc; gint hours_12_width, hours_24_width, sidebar_width; gint hours_12_height, hours_24_height, cell_height; widget = GTK_WIDGET (self); context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); gtk_style_context_save (context); gtk_style_context_add_class (context, "hours"); gtk_style_context_get (context, state, "font", &font_desc, NULL); gtk_style_context_get_padding (context, state, &padding); layout = pango_layout_new (gtk_widget_get_pango_context (widget)); pango_layout_set_font_description (layout, font_desc); pango_layout_set_text (layout, _("00 AM"), -1); pango_layout_get_pixel_size (layout, &hours_12_width, &hours_12_height); pango_layout_set_text (layout, _("00:00"), -1); pango_layout_get_pixel_size (layout, &hours_24_width, &hours_24_height); sidebar_width = MAX (hours_12_width, hours_24_width) + padding.left + padding.right; cell_height = MAX (hours_12_height, hours_24_height) + padding.top + padding.bottom + 1; gtk_style_context_restore (context); /* Update the size requests */ gtk_widget_set_size_request (self->hours_bar, sidebar_width, 48 * cell_height); /* Sync with the week header sidebar */ sidebar_sizegroup = gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header)); gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar); pango_font_description_free (font_desc); g_object_unref (layout); }
wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) { wxFont font; switch (index) { case wxSYS_OEM_FIXED_FONT: case wxSYS_ANSI_FIXED_FONT: case wxSYS_SYSTEM_FIXED_FONT: font = *wxNORMAL_FONT; break; case wxSYS_ANSI_VAR_FONT: case wxSYS_SYSTEM_FONT: case wxSYS_DEVICE_DEFAULT_FONT: case wxSYS_DEFAULT_GUI_FONT: if (!gs_fontSystem.IsOk()) { wxNativeFontInfo info; #ifdef __WXGTK3__ GtkStyleContext* sc = gtk_widget_get_style_context(ButtonWidget()); gtk_style_context_set_state(sc, GTK_STATE_FLAG_NORMAL); gtk_style_context_get(sc, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_FONT, &info.description, NULL); #else info.description = ButtonStyle()->font_desc; #endif gs_fontSystem = wxFont(info); #if wxUSE_FONTENUM // (try to) heal the default font (on some common systems e.g. Ubuntu // it's "Sans Serif" but the real font is called "Sans"): if (!wxFontEnumerator::IsValidFacename(gs_fontSystem.GetFaceName()) && gs_fontSystem.GetFaceName() == "Sans Serif") { gs_fontSystem.SetFaceName("Sans"); } #endif // wxUSE_FONTENUM #ifndef __WXGTK3__ info.description = NULL; #endif } font = gs_fontSystem; break; default: break; } wxASSERT( font.IsOk() ); return font; }
static gboolean _lib_darktable_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_darktable_t *d = (dt_lib_darktable_t *)self->data; /* get the current style */ GdkRGBA color; PangoFontDescription *font_desc = NULL; GtkStateFlags state = gtk_widget_get_state_flags(widget); GtkStyleContext *context = gtk_widget_get_style_context(widget); gtk_style_context_get_background_color(context, state, &color); gtk_style_context_get(context, state, "font", &font_desc, NULL); /* fill background */ gdk_cairo_set_source_rgba(cr, &color); cairo_paint(cr); /* paint icon image */ if(d->image) { cairo_set_source_surface(cr, d->image, 0, (int)DT_PIXEL_APPLY_DPI(7)); cairo_rectangle(cr, 0, 0, d->image_width + (int)DT_PIXEL_APPLY_DPI(8), d->image_height + (int)DT_PIXEL_APPLY_DPI(8)); cairo_fill(cr); } /* create a pango layout and print fancy name/version string */ PangoLayout *layout; layout = gtk_widget_create_pango_layout(widget, NULL); pango_font_description_set_weight(font_desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(font_desc, DT_PIXEL_APPLY_DPI(25) * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); pango_layout_set_text(layout, PACKAGE_NAME, -1); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); cairo_move_to(cr, d->image_width + DT_PIXEL_APPLY_DPI(2.0), DT_PIXEL_APPLY_DPI(5.0)); pango_cairo_show_layout(cr, layout); /* print version */ pango_font_description_set_absolute_size(font_desc, DT_PIXEL_APPLY_DPI(10) * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); pango_layout_set_text(layout, PACKAGE_VERSION, -1); cairo_move_to(cr, d->image_width + DT_PIXEL_APPLY_DPI(4.0), DT_PIXEL_APPLY_DPI(30.0)); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.3); pango_cairo_show_layout(cr, layout); /* cleanup */ g_object_unref(layout); return TRUE; }
/** @brief setup @a cr for usage @param cr cairo context for @a widget @param widget to be drawn upon @return */ static void _e2_gesture_dialog_cairo_setup (cairo_t *cr, GtkWidget *widget) { GdkRGBA *color; GtkStyleContext *context; cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); //enable display of dots ? cairo_set_line_width (cr, 1.0); //approx 1 pixel cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); context = gtk_widget_get_style_context (widget); gtk_style_context_get (context, GTK_STATE_NORMAL, GTK_STYLE_PROPERTY_COLOR, &color, NULL); cairo_set_source_rgb (cr, color->red, color->green, color->blue); gdk_rgba_free (color); }
static int get_text_height (GtkWidget *widget, GtkStyleContext *style) { PangoFontDescription *font_desc; int text_height; gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL); text_height = meta_pango_font_desc_get_text_height (font_desc, gtk_widget_get_pango_context (widget)); pango_font_description_free (font_desc); return text_height; }
void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, MetaFrameBorders *borders) { int text_height; GtkStyleContext *style = NULL; PangoContext *context; const PangoFontDescription *font_desc; PangoFontDescription *free_font_desc = NULL; if (meta_ui_have_a_theme ()) { context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay); GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen)); GtkWidgetPath *widget_path; style = gtk_style_context_new (); gtk_style_context_set_screen (style, screen); widget_path = gtk_widget_path_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); gtk_style_context_set_path (style, widget_path); gtk_widget_path_free (widget_path); gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, borders); if (free_font_desc) pango_font_description_free (free_font_desc); } else { meta_frame_borders_clear (borders); } if (style != NULL) g_object_unref (style); }
/* draw callback for the drawing area */ static gboolean draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data) { GtkStyleContext *context; GdkRGBA *bg; context = gtk_widget_get_style_context (widget); gtk_style_context_get (context, 0, "background-color", &bg, NULL); gdk_cairo_set_source_rgba (cr, bg); cairo_paint (cr); gdk_rgba_free (bg); return TRUE; }
static void get_background_color (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *color) { GdkRGBA *c; g_return_if_fail (color != NULL); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); gtk_style_context_get (context, state, "background-color", &c, NULL); *color = *c; gdk_rgba_free (c); }
/** Wrapper to get the border color of a widget for a given state * * @param context Style context of widget. * * @param state The stateflag of the widget. * * @param color The returned border color of the widget. */ void gnc_style_context_get_border_color (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *color) { GdkRGBA *c; g_return_if_fail (color != NULL); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); gtk_style_context_get (context, state, GTK_STYLE_PROPERTY_BORDER_COLOR, &c, NULL); *color = *c; gdk_rgba_free (c); }
static void draw_horizontal_scrollbar (GtkWidget *widget, cairo_t *cr, gint x, gint y, gint width, gint position, GtkStateFlags state, gint *height) { GtkStyleContext *scrollbar_context; GtkStyleContext *contents_context; GtkStyleContext *trough_context; GtkStyleContext *slider_context; gint slider_width; /* This information is taken from the GtkScrollbar docs, see "CSS nodes" */ scrollbar_context = get_style (NULL, "scrollbar.horizontal.bottom"); contents_context = get_style (scrollbar_context, "contents"); trough_context = get_style (contents_context, "trough"); slider_context = get_style (trough_context, "slider"); gtk_style_context_set_state (scrollbar_context, state); gtk_style_context_set_state (contents_context, state); gtk_style_context_set_state (trough_context, state); gtk_style_context_set_state (slider_context, state); *height = 0; query_size (scrollbar_context, NULL, height); query_size (contents_context, NULL, height); query_size (trough_context, NULL, height); query_size (slider_context, NULL, height); gtk_style_context_get (slider_context, "min-width", &slider_width, NULL); draw_style_common (scrollbar_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); draw_style_common (contents_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); draw_style_common (trough_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); draw_style_common (slider_context, cr, x + position, y, slider_width, *height, NULL, NULL, NULL, NULL); g_object_unref (slider_context); g_object_unref (trough_context); g_object_unref (contents_context); g_object_unref (scrollbar_context); }
static void gcal_year_view_get_preferred_width (GtkWidget *widget, gint *minimum, gint *natural) { GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (widget)->priv; gint padding_left; gtk_style_context_get (gtk_widget_get_style_context (priv->navigator), gtk_widget_get_state_flags (priv->navigator), "padding-left", &padding_left, NULL); if (minimum != NULL) *minimum = NAVIGATOR_CELL_WIDTH * 4 + padding_left * 8; if (natural != NULL) *natural = NAVIGATOR_CELL_WIDTH * 4 + padding_left * 8 + SIDEBAR_PREFERRED_WIDTH; }
static void gcal_year_view_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum, gint *natural) { GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (widget)->priv; gint padding_top; gtk_style_context_get (gtk_widget_get_style_context (priv->navigator), gtk_widget_get_state_flags (priv->navigator), "padding-top", &padding_top, NULL); if (minimum != NULL) *minimum = NAVIGATOR_CELL_HEIGHT * 3 + padding_top * 6; if (natural != NULL) *natural = NAVIGATOR_CELL_HEIGHT * 3 + padding_top * 6; }
static void gcal_year_view_size_allocate (GtkWidget *widget, GtkAllocation *alloc) { GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (widget)->priv; GtkStyleContext *context; gint padding_left; context = gtk_widget_get_style_context (widget); gtk_style_context_save (context); gtk_style_context_add_class (context, "year-navigator"); gtk_style_context_get (context, gtk_widget_get_state_flags (widget), "padding-left", &padding_left, NULL); gtk_style_context_restore (context); priv->popover_mode = (alloc->width < NAVIGATOR_CELL_WIDTH * 4 + padding_left * 8 + SIDEBAR_PREFERRED_WIDTH); if (priv->popover_mode && !gtk_widget_is_ancestor (priv->events_sidebar, priv->popover)) { g_object_ref (priv->sidebar); gtk_container_remove (GTK_CONTAINER (widget), priv->sidebar); gtk_container_add (GTK_CONTAINER (priv->popover), priv->sidebar); g_object_unref (priv->sidebar); gtk_widget_show_all (priv->sidebar); popover_closed_cb (GCAL_YEAR_VIEW (widget), GTK_POPOVER (priv->popover)); } else if (!priv->popover_mode && gtk_widget_is_ancestor (priv->events_sidebar, priv->popover)) { g_object_ref (priv->sidebar); gtk_container_remove (GTK_CONTAINER (priv->popover), priv->sidebar); gtk_box_pack_end (GTK_BOX (widget), priv->sidebar, FALSE, TRUE, 0); g_object_unref (priv->sidebar); gtk_widget_show (priv->sidebar); g_signal_handlers_block_by_func (priv->popover, popover_closed_cb, widget); gtk_widget_hide (priv->popover); g_signal_handlers_unblock_by_func (priv->popover, popover_closed_cb, widget); } GTK_WIDGET_CLASS (gcal_year_view_parent_class)->size_allocate (widget, alloc); }
/* * frame_update_titlebar_font * * Returns: void * Description: updates the titlebar font from the pango context, should * be called whenever the gtk style or font has changed */ void frame_update_titlebar_font (decor_frame_t *frame) { const PangoFontDescription *font_desc; PangoFontDescription *free_font_desc; PangoFontMetrics *metrics; PangoLanguage *lang; free_font_desc = NULL; frame = gwd_decor_frame_ref (frame); font_desc = get_titlebar_font (frame); if (!font_desc) { GtkCssProvider *provider = gtk_css_provider_get_default (); GtkStyleContext *context = gtk_style_context_new (); GtkWidgetPath *path = gtk_widget_path_new (); gtk_widget_path_prepend_type (path, GTK_TYPE_WIDGET); gtk_style_context_set_path (context, path); gtk_widget_path_free (path); gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK); gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; } pango_context_set_font_description (frame->pango_context, font_desc); lang = pango_context_get_language (frame->pango_context); metrics = pango_context_get_metrics (frame->pango_context, font_desc, lang); frame->text_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); gwd_decor_frame_unref (frame); pango_font_metrics_unref (metrics); if (free_font_desc) pango_font_description_free (free_font_desc); }
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 gboolean label_draw(GtkWidget *label, cairo_t *cr, gpointer data) { UIMCandWinHorizontalGtk *horizontal_cwin = data; struct index_button *selected; GtkWidget *selected_label = NULL; GdkRGBA *bg_color, *fg_color; GtkStyleContext *context; PangoLayout *layout; gint x, y; GtkStateFlags state; selected = horizontal_cwin->selected; if (selected) selected_label = gtk_bin_get_child(GTK_BIN(selected->button)); layout = gtk_label_get_layout(GTK_LABEL(label)); gtk_label_get_layout_offsets(GTK_LABEL(label), &x, &y); context = gtk_widget_get_style_context(label); if (label == selected_label) state = GTK_STATE_FLAG_SELECTED; else state = GTK_STATE_FLAG_NORMAL; gtk_style_context_get (context, state, "background-color", &bg_color, "color", &fg_color, NULL); cairo_save(cr); gdk_cairo_set_source_rgba(cr, bg_color); cairo_paint(cr); cairo_restore(cr); gdk_rgba_free(bg_color); gdk_rgba_free(fg_color); gtk_style_context_set_state (context, state); gtk_render_layout (context, cr, x, y, layout); return FALSE; }
void PanelPaletteManager::updatePalette() { GtkStyleContext* context = PanelStyle::instance()->styleContext(); gtk_style_context_invalidate(context); // Without this line, it seems the GtkStyleContext is not correctly // initialized and we get some uninitialized pixels in the background // brush. gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, NULL); QPalette pal; if (DashClient::instance()->activeInScreen(m_panel->screen()) || HUDClient::instance()->activeInScreen(m_panel->screen())) { /* The background color is the same as in the launcher */ QColor wallpaperColor(unity2dConfiguration().property("averageBgColor").toString()); QColor backgroundColor(wallpaperColor.red(), wallpaperColor.green(), wallpaperColor.blue(), 168); backgroundColor = backgroundColor.darker(800); pal.setBrush(QPalette::Window, backgroundColor); } else { pal.setBrush(QPalette::Window, generateBackgroundBrush()); } m_panel->setPalette(pal); }
static gint wnck_selector_get_width (GtkWidget *widget, const char *text) { GtkStyleContext *style_context; GtkStateFlags state; PangoContext *context; PangoFontMetrics *metrics; PangoFontDescription *description; gint char_width; PangoLayout *layout; PangoRectangle natural; gint max_width; gint screen_width; gint width; state = gtk_widget_get_state_flags (widget); style_context = gtk_widget_get_style_context (widget); gtk_style_context_get (style_context, state, GTK_STYLE_PROPERTY_FONT, &description, NULL); context = gtk_widget_get_pango_context (widget); metrics = pango_context_get_metrics (context, description, pango_context_get_language (context)); char_width = pango_font_metrics_get_approximate_char_width (metrics); pango_font_metrics_unref (metrics); max_width = PANGO_PIXELS (SELECTOR_MAX_WIDTH * char_width); layout = gtk_widget_create_pango_layout (widget, text); pango_layout_get_pixel_extents (layout, NULL, &natural); g_object_unref (G_OBJECT (layout)); screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget)); width = MIN (natural.width, max_width); width = MIN (width, 3 * (screen_width / 4)); return width; }
/* * static applet config functions */ static void matekbd_indicator_config_load_font (MatekbdIndicatorConfig * ind_config) { ind_config->font_family = g_settings_get_string (ind_config->settings, MATEKBD_INDICATOR_CONFIG_KEY_FONT_FAMILY); if (ind_config->font_family == NULL || ind_config->font_family[0] == '\0') { PangoFontDescription *fd = NULL; GtkWidgetPath *widget_path = gtk_widget_path_new (); GtkStyleContext *context = gtk_style_context_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); gtk_widget_path_iter_set_name (widget_path, -1 , "PanelWidget"); gtk_style_context_set_path (context, widget_path); gtk_style_context_set_screen (context, gdk_screen_get_default ()); gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL); gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT); gtk_style_context_add_class (context, "gnome-panel-menu-bar"); gtk_style_context_add_class (context, "mate-panel-menu-bar"); gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_FONT, &fd, NULL); if (fd != NULL) { ind_config->font_family = g_strdup (pango_font_description_to_string(fd)); } g_object_unref (G_OBJECT (context)); gtk_widget_path_unref (widget_path); } xkl_debug (150, "font: [%s]\n", ind_config->font_family); }
static gboolean draw_navigator (GcalYearView *year_view, cairo_t *cr, GtkWidget *widget) { GcalYearViewPrivate *priv; GtkStyleContext *context; GtkStateFlags state_flags; gint header_padding_left, header_padding_top, header_height, layout_width, layout_height; gint width, height, box_side, real_padding_left, real_padding_top, i, sw, weeks_counter; gchar *header_str; PangoLayout *header_layout; PangoFontDescription *font_desc; priv = year_view->priv; context = gtk_widget_get_style_context (GTK_WIDGET (year_view)); state_flags = gtk_widget_get_state_flags (GTK_WIDGET (year_view)); sw = 1 - 2 * priv->k; width = gtk_widget_get_allocated_width (widget); /* read header from CSS code related to the view */ gtk_style_context_save (context); gtk_style_context_add_class (context, "first-view-header"); header_str = g_strdup_printf ("%d", priv->date->year); gtk_style_context_get (context, state_flags, "padding-left", &header_padding_left, "padding-top", &header_padding_top, "font", &font_desc, NULL); gtk_style_context_restore (context); /* draw header on navigator */ context = gtk_widget_get_style_context (widget); state_flags = gtk_widget_get_state_flags (GTK_WIDGET (year_view)); header_layout = gtk_widget_create_pango_layout (widget, header_str); pango_layout_set_font_description (header_layout, font_desc); pango_layout_get_pixel_size (header_layout, &layout_width, &layout_height); /* XXX: here the color of the text isn't read from year-view but from navigator widget, * which has the same color on the CSS file */ gtk_render_layout (context, cr, priv->k * (width - layout_width) + sw * header_padding_left, header_padding_top, header_layout); pango_font_description_free (font_desc); g_object_unref (header_layout); g_free (header_str); header_height = header_padding_top * 2 + layout_height; height = gtk_widget_get_allocated_height (widget) - header_height; if (((width / 4) / 8) < ((height / 3) / 7)) box_side = (width / 4) / 8; else box_side = (height / 3) / 7; real_padding_left = (width - (8 * 4 * box_side)) / 5; real_padding_top = (height - (7 * 3 * box_side)) / 4; priv->navigator_grid->box_side = box_side; weeks_counter = 1; for (i = 0; i < 12; i++) { gint row = i / 4; gint column = priv->k * 3 + sw * (i % 4); priv->navigator_grid->coordinates[i].x = (column + 1) * real_padding_left + column * box_side * 8; priv->navigator_grid->coordinates[i].y = (row + 1) * real_padding_top + row * box_side * 7 + header_height; draw_month_grid (year_view, widget, cr, i, &weeks_counter); } return FALSE; }
static void draw_month_grid (GcalYearView *year_view, GtkWidget *widget, cairo_t *cr, gint month_nr, gint *weeks_counter) { GcalYearViewPrivate *priv = year_view->priv; GtkStyleContext *context; GtkStateFlags state_flags; PangoLayout *layout, *slayout; PangoFontDescription *font_desc, *sfont_desc; GdkRGBA color; gint layout_width, layout_height, i, j, sw; gint x, y, column, row, box_side, box_padding_top, box_padding_start; gint days_delay, days, shown_rows, sunday_idx; gchar *str, *nr_day, *nr_week; gboolean selected_day; cairo_save (cr); context = gtk_widget_get_style_context (widget); state_flags = gtk_widget_get_state_flags (widget); sw = 1 - 2 * priv->k; box_side = priv->navigator_grid->box_side; x = priv->navigator_grid->coordinates[month_nr].x; y = priv->navigator_grid->coordinates[month_nr].y; gtk_style_context_get (context, state_flags | GTK_STATE_FLAG_SELECTED, "font", &sfont_desc, NULL); slayout = gtk_widget_create_pango_layout (widget, NULL); pango_layout_set_font_description (slayout, sfont_desc); /* header */ gtk_style_context_save (context); gtk_style_context_add_class (context, "header"); str = g_strdup (gcal_get_month_name (month_nr)); gtk_style_context_get (context, state_flags, "font", &font_desc, NULL); layout = gtk_widget_create_pango_layout (widget, str); pango_layout_set_font_description (layout, font_desc); pango_layout_get_pixel_size (layout, &layout_width, &layout_height); gtk_render_layout (context, cr, x + (box_side * 8 - layout_width) / 2, y + (box_side - layout_height) / 2, layout); gtk_render_background (context, cr, x + (box_side * 8 - layout_width) / 2, y + (box_side - layout_height) / 2, layout_width, layout_width); pango_font_description_free (font_desc); g_free (str); gtk_style_context_restore (context); /* separator line */ gtk_style_context_save (context); gtk_style_context_add_class (context, "lines"); gtk_style_context_get_color (context, state_flags, &color); cairo_set_line_width (cr, 0.2); gdk_cairo_set_source_rgba (cr, &color); cairo_move_to (cr, x + box_side / 2, y + box_side + 0.4); cairo_rel_line_to (cr, 7 * box_side, 0); cairo_stroke (cr); gtk_style_context_restore (context); /* days */ gtk_style_context_save (context); gtk_style_context_add_class (context, "days"); gtk_style_context_get (context, state_flags, "font", &font_desc, NULL); pango_layout_set_font_description (layout, font_desc); days_delay = (time_day_of_week (1, month_nr, priv->date->year) - priv->first_weekday + 7) % 7; days = days_delay + icaltime_days_in_month (month_nr + 1, priv->date->year); shown_rows = ceil (days / 7.0); sunday_idx = priv->k * 6 + sw * ((7 - priv->first_weekday) % 7); for (i = 0; i < 7 * shown_rows; i++) { column = i % 7; row = i / 7; j = 7 * ((i + 7 * priv->k) / 7) + sw * (i % 7) + (1 - priv->k); if (j <= days_delay) continue; else if (j > days) continue; j -= days_delay; nr_day = g_strdup_printf ("%d", j); pango_layout_set_text (layout, nr_day, -1); pango_layout_get_pixel_size (layout, &layout_width, &layout_height); box_padding_top = (box_side - layout_height) / 2 > 0 ? (box_side - layout_height) / 2 : 0; box_padding_start = (box_side - layout_width) / 2 > 0 ? (box_side - layout_width) / 2 : 0; selected_day = FALSE; if (priv->selected_data->start_day != 0) { ButtonData selected_data = *(priv->selected_data); order_selected_data (&selected_data); if (month_nr > selected_data.start_month && month_nr < selected_data.end_month) { selected_day = TRUE; } else if (month_nr == selected_data.start_month && month_nr == selected_data.end_month) { selected_day = j >= selected_data.start_day && j <= selected_data.end_day; } else if (month_nr == selected_data.start_month && j >= selected_data.start_day) { selected_day = TRUE; } else if (month_nr == selected_data.end_month && j <= selected_data.end_day) { selected_day = TRUE; } } if (priv->date->year == priv->current_date->year && month_nr + 1 == priv->current_date->month && j == priv->current_date->day) { PangoLayout *clayout; PangoFontDescription *cfont_desc; gtk_style_context_save (context); gtk_style_context_add_class (context, "current"); clayout = gtk_widget_create_pango_layout (widget, nr_day); gtk_style_context_get (context, state_flags, "font", &cfont_desc, NULL); pango_layout_set_font_description (clayout, cfont_desc); pango_layout_get_pixel_size (clayout, &layout_width, &layout_height); box_padding_top = (box_side - layout_height) / 2 > 0 ? (box_side - layout_height) / 2 : 0; box_padding_start = (box_side - layout_width) / 2 > 0 ? (box_side - layout_width) / 2 : 0; /* FIXME: hardcoded padding of the number background */ gtk_render_background (context, cr, box_side * (column + 0.5 + priv->k) + x + sw * box_padding_start - priv->k * layout_width - 2.0, box_side * (row + 1) + y + box_padding_top - 1.0, layout_width + 4.0, layout_height + 2.0); gtk_render_layout (context, cr, box_side * (column + 0.5 + priv->k) + x + sw * box_padding_start - priv->k * layout_width, box_side * (row + 1) + y + box_padding_top, clayout); gtk_style_context_restore (context); pango_font_description_free (cfont_desc); g_object_unref (clayout); } else if (selected_day) { gtk_style_context_set_state (context, state_flags | GTK_STATE_FLAG_SELECTED); pango_layout_set_text (slayout, nr_day, -1); pango_layout_get_pixel_size (slayout, &layout_width, &layout_height); box_padding_top = (box_side - layout_height) / 2 > 0 ? (box_side - layout_height) / 2 : 0; box_padding_start = (box_side - layout_width) / 2 > 0 ? (box_side - layout_width) / 2 : 0; gtk_render_layout (context, cr, box_side * (column + 0.5 + priv->k) + x + sw * box_padding_start - priv->k * layout_width, box_side * (row + 1) + y + box_padding_top, slayout); gtk_style_context_set_state (context, state_flags); } else if (column == sunday_idx) { gtk_style_context_save (context); gtk_style_context_add_class (context, "sunday"); gtk_render_layout (context, cr, box_side * (column + 0.5 + priv->k) + x + sw * box_padding_start - priv->k * layout_width, box_side * (row + 1) + y + box_padding_top, layout); gtk_style_context_restore (context); } else { gtk_render_layout (context, cr, box_side * (column + 0.5 + priv->k) + x + sw * box_padding_start - priv->k * layout_width, box_side * (row + 1) + y + box_padding_top, layout); } g_free (nr_day); } pango_font_description_free (font_desc); gtk_style_context_restore (context); /* week numbers */ gtk_style_context_save (context); gtk_style_context_add_class (context, "week-numbers"); gtk_style_context_get (context, state_flags, "font", &font_desc, NULL); pango_layout_set_font_description (layout, font_desc); for (i = 0; i < shown_rows; i++) { if (i == 0) { if (days_delay == 0) *weeks_counter = *weeks_counter + 1; } else *weeks_counter = *weeks_counter + 1; nr_week = g_strdup_printf ("%d", *weeks_counter); pango_layout_set_text (layout, nr_week, -1); pango_layout_get_pixel_size (layout, &layout_width, &layout_height); box_padding_top = (box_side - layout_height) / 2 > 0 ? (box_side - layout_height) / 2 : 0; box_padding_start = ((box_side / 2) - layout_width) / 2 > 0 ? ((box_side / 2) - layout_width) / 2 : 0; gtk_render_layout (context, cr, x + sw * box_padding_start + priv->k * (8 * box_side - layout_width), box_side * (i + 1) + y + box_padding_top, layout); g_free (nr_week); } gtk_style_context_restore (context); pango_font_description_free (sfont_desc); g_object_unref (slayout); pango_font_description_free (font_desc); g_object_unref (layout); cairo_restore (cr); }
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 draw_spinbutton (GtkWidget *widget, cairo_t *cr, gint x, gint y, gint width, gint *height) { GtkStyleContext *spin_context; GtkStyleContext *entry_context; GtkStyleContext *up_context; GtkStyleContext *down_context; GtkIconTheme *icon_theme; GtkIconInfo *icon_info; GdkPixbuf *pixbuf; GdkTexture *texture; gint icon_width, icon_height, icon_size; gint button_width; gint contents_x, contents_y, contents_width, contents_height; /* This information is taken from the GtkSpinButton docs, see "CSS nodes" */ spin_context = get_style (NULL, "spinbutton.horizontal:focus"); entry_context = get_style (spin_context, "entry:focus"); up_context = get_style (spin_context, "button.up:focus:active"); down_context = get_style (spin_context, "button.down:focus"); *height = 0; query_size (spin_context, NULL, height); query_size (entry_context, NULL, height); query_size (up_context, NULL, height); query_size (down_context, NULL, height); button_width = *height; draw_style_common (spin_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); draw_style_common (entry_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget)); gtk_style_context_get (up_context, "min-width", &icon_width, "min-height", &icon_height, NULL); icon_size = MIN (icon_width, icon_height); icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-add-symbolic", icon_size, 0); pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, up_context, NULL, NULL); texture = gdk_texture_new_for_pixbuf (pixbuf); g_object_unref (icon_info); draw_style_common (up_context, cr, x + width - button_width, y, button_width, *height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_icon (up_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2); g_object_unref (pixbuf); g_object_unref (texture); gtk_style_context_get (down_context, "min-width", &icon_width, "min-height", &icon_height, NULL); icon_size = MIN (icon_width, icon_height); icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-remove-symbolic", icon_size, 0); pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, down_context, NULL, NULL); texture = gdk_texture_new_for_pixbuf (pixbuf); g_object_unref (icon_info); draw_style_common (down_context, cr, x + width - 2 * button_width, y, button_width, *height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_icon (down_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2); g_object_unref (pixbuf); g_object_unref (texture); g_object_unref (down_context); g_object_unref (up_context); g_object_unref (entry_context); g_object_unref (spin_context); }
static gboolean video_area_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data) { GthMediaViewerPage *self = user_data; GtkAllocation allocation; GtkStyleContext *style_context; if (self->priv->xwin_assigned && self->priv->has_video) return FALSE; gtk_widget_get_allocation (widget, &allocation); style_context = gtk_widget_get_style_context (widget); if (self->priv->icon == NULL) { char *type; GIcon *icon; int size; type = NULL; if (self->priv->file_data != NULL) type = g_content_type_from_mime_type (gth_file_data_get_mime_type (self->priv->file_data)); if (type == NULL) type = g_content_type_from_mime_type ("text/plain"); icon = g_content_type_get_icon (type); size = allocation.width; if (size > allocation.height) size = allocation.height; size = size / 3; self->priv->icon = _g_icon_get_pixbuf (icon, size, _gtk_widget_get_icon_theme (widget)); g_object_unref (icon); g_free (type); } cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); cairo_rectangle (cr, 0, 0, allocation.width, allocation.height); cairo_fill (cr); if (self->priv->icon != NULL) { int icon_w, icon_h; int text_w; int icon_x, icon_y; PangoRectangle logical_rect; int x, y; PangoFontDescription *font; icon_w = gdk_pixbuf_get_width (self->priv->icon); icon_h = gdk_pixbuf_get_height (self->priv->icon); text_w = (icon_w * 3 / 2); pango_layout_set_width (self->priv->caption_layout, PANGO_SCALE * text_w); pango_layout_get_extents (self->priv->caption_layout, NULL, &logical_rect); icon_x = (allocation.width - icon_w) / 2; x = (allocation.width - text_w) / 2; icon_y = (allocation.height - (icon_h + PANGO_PIXELS (logical_rect.height))) / 2; y = icon_y + icon_h; gdk_cairo_set_source_pixbuf (cr, self->priv->icon, icon_x, icon_y); cairo_rectangle (cr, icon_x, icon_y, icon_w, icon_h); cairo_fill (cr); cairo_move_to (cr, x, y); gtk_style_context_get (style_context, gtk_widget_get_state_flags (widget), "font", &font, NULL); pango_layout_set_font_description (self->priv->caption_layout, font); pango_cairo_layout_path (cr, self->priv->caption_layout); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_fill (cr); } return TRUE; }
// static wxVisualAttributes wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, bool WXUNUSED_IN_GTK3(useBase), int state) { wxVisualAttributes attr; GtkWidget* tlw = NULL; if (gtk_widget_get_parent(widget) == NULL) { tlw = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_add(GTK_CONTAINER(tlw), widget); } #ifdef __WXGTK3__ GtkStateFlags stateFlag = GTK_STATE_FLAG_NORMAL; if (state) { wxASSERT(state == GTK_STATE_ACTIVE); stateFlag = GTK_STATE_FLAG_ACTIVE; } GtkStyleContext* sc = gtk_widget_get_style_context(widget); GdkRGBA c; gtk_style_context_get_color(sc, stateFlag, &c); attr.colFg = wxColour(c); gtk_style_context_get_background_color(sc, stateFlag, &c); attr.colBg = wxColour(c); wxNativeFontInfo info; gtk_style_context_get( sc, stateFlag, GTK_STYLE_PROPERTY_FONT, &info.description, NULL); attr.font = wxFont(info); #else GtkStyle* style; style = gtk_rc_get_style(widget); if (!style) style = gtk_widget_get_default_style(); if (style) { // get the style's colours attr.colFg = wxColour(style->fg[state]); if (useBase) attr.colBg = wxColour(style->base[state]); else attr.colBg = wxColour(style->bg[state]); // get the style's font if (!style->font_desc) style = gtk_widget_get_default_style(); if (style && style->font_desc) { wxNativeFontInfo info; info.description = style->font_desc; attr.font = wxFont(info); info.description = NULL; } } else attr = wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); #endif if (!attr.font.IsOk()) { GtkSettings *settings = gtk_settings_get_default(); gchar *font_name = NULL; g_object_get ( settings, "gtk-font-name", &font_name, NULL); if (!font_name) attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); else { attr.font = wxFont(wxString::FromUTF8(font_name)); g_free(font_name); } } if (tlw) gtk_widget_destroy(tlw); return attr; }
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 draw_combobox (GtkWidget *widget, cairo_t *cr, gint x, gint y, gint width, gboolean has_entry, gint *height) { GtkStyleContext *combo_context; GtkStyleContext *box_context; GtkStyleContext *button_context; GtkStyleContext *button_box_context; GtkStyleContext *entry_context; GtkStyleContext *arrow_context; gint contents_x, contents_y, contents_width, contents_height; gint button_width; gint arrow_width, arrow_height, arrow_size; /* This information is taken from the GtkComboBox docs, see "CSS nodes" */ combo_context = get_style (NULL, "combobox:focus"); box_context = get_style (combo_context, "box.horizontal.linked"); if (has_entry) { const char *siblings[3] = { "entry.combo:focus", "button.combo" , NULL }; entry_context = get_style_with_siblings (box_context, "entry.combo:focus", siblings, 0); button_context = get_style_with_siblings (box_context, "button.combo", siblings, 1); } else { const char *siblings[2] = { "button.combo" , NULL }; button_context = get_style_with_siblings (box_context, "button.combo", siblings, 0); } button_box_context = get_style (button_context, "box.horizontal"); arrow_context = get_style (button_box_context, "arrow"); *height = 0; query_size (combo_context, NULL, height); query_size (box_context, NULL, height); if (has_entry) query_size (entry_context, NULL, height); query_size (button_context, NULL, height); query_size (button_box_context, NULL, height); query_size (arrow_context, NULL, height); gtk_style_context_get (arrow_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); draw_style_common (combo_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); draw_style_common (box_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL); if (has_entry) { button_width = *height; draw_style_common (entry_context, cr, x, y, width - button_width, *height, NULL, NULL, NULL, NULL); draw_style_common (button_context, cr, x + width - button_width, y, button_width, *height, &contents_x, &contents_y, &contents_width, &contents_height); } else { button_width = width; draw_style_common (button_context, cr, x, y, width, *height, &contents_x, &contents_y, &contents_width, &contents_height); } draw_style_common (button_box_context, cr, contents_x, contents_y, contents_width, contents_height, NULL, NULL, NULL, NULL); draw_style_common (arrow_context, cr, contents_x, contents_y, contents_width, contents_height, NULL, NULL, NULL, NULL); gtk_render_arrow (arrow_context, cr, G_PI / 2, contents_x + contents_width - arrow_size, contents_y + (contents_height - arrow_size) / 2, arrow_size); g_object_unref (arrow_context); if (has_entry) g_object_unref (entry_context); g_object_unref (button_context); g_object_unref (combo_context); }