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 test_init_of_theme (void) { GtkStyleContext *context; GtkCssProvider *provider; GtkWidgetPath *path; GdkRGBA before, after; char *css; /* Test that a style context actually uses the theme loaded for the * screen it is using. If no screen is set, it's the default one. */ context = gtk_style_context_new (); path = gtk_widget_path_new (); /* Set a path that will have a color set. * (This could actually fail if style classes change, so if this test * fails, make sure to have this path represent something sane.) */ gtk_widget_path_append_type (path, GTK_TYPE_WINDOW); gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND); gtk_style_context_set_path (context, path); gtk_widget_path_free (path); /* Get the color. This should be initialized by the theme and not be * the default. */ gtk_style_context_get_color (context, gtk_style_context_get_state (context), &before); /* Add a style that sets a different color for this widget. * This style has a higher priority than fallback, but a lower * priority than the theme. */ css = g_strdup_printf (".background { color: %s; }", before.alpha < 0.5 ? "black" : "transparent"); provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider, css, -1, NULL); gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1); g_object_unref (provider); /* Get the color again. */ gtk_style_context_get_color (context, gtk_style_context_get_state (context), &after); /* Because the style we added does not influence the color, * the before and after colors should be identical. */ g_assert (gdk_rgba_equal (&before, &after)); g_object_unref (context); }
GtkStyleContext* ClaimStyleContext(WidgetNodeType aNodeType, GtkTextDirection aDirection, GtkStateFlags aStateFlags, StyleFlags aFlags) { MOZ_ASSERT(!sStyleContextNeedsRestore); GtkStyleContext* style = GetStyleInternal(aNodeType); #ifdef DEBUG MOZ_ASSERT(!sCurrentStyleContext); sCurrentStyleContext = style; #endif GtkStateFlags oldState = gtk_style_context_get_state(style); GtkTextDirection oldDirection = gtk_style_context_get_direction(style); if (oldState != aStateFlags || oldDirection != aDirection) { // From GTK 3.8, set_state() will overwrite the direction, so set // direction after state. gtk_style_context_set_state(style, aStateFlags); gtk_style_context_set_direction(style, aDirection); // This invalidate is necessary for unsaved style contexts from GtkWidgets // in pre-3.18 GTK, because automatic invalidation of such contexts // was delayed until a resize event runs. // // https://bugzilla.mozilla.org/show_bug.cgi?id=1272194#c7 // // Avoid calling invalidate on saved contexts to avoid performing // build_properties() (in 3.16 stylecontext.c) unnecessarily early. if (!sStyleContextNeedsRestore) { gtk_style_context_invalidate(style); } } return style; }
JNIEXPORT jint JNICALL Java_org_gnome_gtk_GtkStyleContext_gtk_1style_1context_1get_1state ( JNIEnv* env, jclass cls, jlong _self ) { GtkStateFlags result; jint _result; GtkStyleContext* self; // convert parameter self self = (GtkStyleContext*) _self; // call function result = gtk_style_context_get_state(self); // cleanup parameter self // translate return value to JNI type _result = (jint) result; // and finally return _result; }
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 apply_subtitle_style_to_layout (GtkStyleContext *context, PangoLayout *layout, GtkStateFlags flags) { PangoFontDescription *desc; PangoAttrList *layout_attr; PangoAttribute *attr_alpha; gtk_style_context_save (context); gtk_style_context_set_state (context, flags); gtk_style_context_get (context, gtk_style_context_get_state (context), "font", &desc, NULL); gtk_style_context_restore (context); /* Set the font size */ pango_font_description_set_size (desc, pango_font_description_get_size (desc) * SUBTITLE_SIZE_PERCENTAGE); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); /* Set the font alpha */ layout_attr = pango_attr_list_new (); attr_alpha = pango_attr_foreground_alpha_new (SUBTITLE_DIM_PERCENTAGE * 65535); pango_attr_list_insert (layout_attr, attr_alpha); pango_layout_set_attributes (layout, layout_attr); pango_attr_list_unref (layout_attr); }
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); }
static void style_context_changed (GtkStyleContext *style_context, GbTerminalView *self) { GtkStateFlags state; GdkRGBA fg; GdkRGBA bg; g_assert (GTK_IS_STYLE_CONTEXT (style_context)); g_assert (GB_IS_TERMINAL_VIEW (self)); state = gtk_style_context_get_state (style_context); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; gtk_style_context_get_color (style_context, state, &fg); gtk_style_context_get_background_color (style_context, state, &bg); G_GNUC_END_IGNORE_DEPRECATIONS; if (bg.alpha == 0.0) { gdk_rgba_parse (&bg, "#f6f7f8"); } vte_terminal_set_colors (self->terminal_top, &fg, &bg, solarized_palette, G_N_ELEMENTS (solarized_palette)); if (self->terminal_bottom) vte_terminal_set_colors (self->terminal_bottom, &fg, &bg, solarized_palette, G_N_ELEMENTS (solarized_palette)); }
static gboolean gb_preferences_switch_draw (GtkWidget *widget, cairo_t *cr) { GbPreferencesSwitch *self = (GbPreferencesSwitch *)widget; GtkStyleContext *style_context; GtkStateFlags flags; gboolean ret = FALSE; g_assert (GB_IS_PREFERENCES_SWITCH (self)); style_context = gtk_widget_get_style_context (widget); gtk_style_context_save (style_context); if (self->in_widget) { flags = gtk_style_context_get_state (style_context); gtk_style_context_set_state (style_context, flags | GTK_STATE_FLAG_PRELIGHT); } ret = GTK_WIDGET_CLASS (gb_preferences_switch_parent_class)->draw (widget, cr); gtk_style_context_restore (style_context); return ret; }
static void gtk_switch_get_preferred_width (GtkWidget *widget, gint *minimum, gint *natural) { GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; gint width, slider_width, focus_width, focus_pad; PangoLayout *layout; PangoRectangle logical_rect; 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, GTK_STYLE_CLASS_SLIDER); gtk_style_context_get_padding (context, state, &padding); width = padding.left + padding.right; gtk_style_context_restore (context); gtk_widget_style_get (widget, "slider-width", &slider_width, "focus-line-width", &focus_width, "focus-padding", &focus_pad, NULL); slider_width = MAX (slider_width, 3 * (focus_width + focus_pad)); /* Translators: if the "on" state label requires more than three * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for * the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON")); pango_layout_get_extents (layout, NULL, &logical_rect); pango_extents_to_pixels (&logical_rect, NULL); width += MAX (logical_rect.width, slider_width); /* Translators: if the "off" state label requires more than three * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state */ pango_layout_set_text (layout, C_("switch", "OFF"), -1); pango_layout_get_extents (layout, NULL, &logical_rect); pango_extents_to_pixels (&logical_rect, NULL); width += MAX (logical_rect.width, slider_width); g_object_unref (layout); if (minimum) *minimum = width; if (natural) *natural = width; }
static void cheese_widget_spinner_invert (GtkWidget *spinner, GtkWidget *parent) { GtkStyleContext *context; guint i; for (i = GTK_STATE_NORMAL; i <= GTK_STATE_INSENSITIVE; i++) { GdkRGBA fg, bg; context = gtk_widget_get_style_context (spinner); gtk_style_context_get_color (context, gtk_style_context_get_state (context), &fg); gtk_style_context_get_background_color (context, gtk_style_context_get_state (context), &bg); gtk_widget_override_color (spinner, i, &bg); gtk_widget_override_background_color (spinner, i, &fg); gtk_widget_override_color (parent, i, &bg); gtk_widget_override_background_color (parent, i, &fg); } }
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); }
static void cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, GladeEditorProperty *eprop) { GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop); gboolean dummy; GdkRGBA color; gtk_tree_model_get (model, iter, COLUMN_DUMMY, &dummy, -1); if (GTK_IS_CELL_RENDERER_TEXT (renderer)) { GtkStyleContext* context = gtk_widget_get_style_context (eprop_string_list->view); if (dummy) { gtk_style_context_save (context); gtk_style_context_set_state (context, gtk_style_context_get_state (context) | GTK_STATE_FLAG_INSENSITIVE); gtk_style_context_get_color (context, gtk_style_context_get_state (context), &color); gtk_style_context_restore (context); g_object_set (renderer, "style", PANGO_STYLE_ITALIC, "foreground-rgba", &color, NULL); } else { gtk_style_context_get_color (context, gtk_style_context_get_state (context), &color); g_object_set (renderer, "style", PANGO_STYLE_NORMAL, "foreground-rgba", &color, NULL); } } else if (GLADE_IS_CELL_RENDERER_ICON (renderer)) g_object_set (renderer, "visible", !dummy && eprop_string_list->translatable, NULL); }
static void gtk_revealer_get_padding (GtkRevealer *revealer, GtkBorder *padding) { GtkWidget *widget = GTK_WIDGET (revealer); GtkStyleContext *context; GtkStateFlags state; context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); gtk_style_context_get_padding (context, state, padding); }
static void gtk_switch_get_preferred_height (GtkWidget *widget, gint *minimum, gint *natural) { GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; gint height, focus_width, focus_pad, slider_width, min_height; PangoLayout *layout; PangoRectangle logical_rect; gchar *str; 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, GTK_STYLE_CLASS_SLIDER); gtk_style_context_get_padding (context, state, &padding); height = padding.top + padding.bottom; gtk_style_context_restore (context); gtk_widget_style_get (widget, "slider-width", &slider_width, "focus-line-width", &focus_width, "focus-padding", &focus_pad, NULL); min_height = MAX (slider_width * 0.6, 3 * (focus_width + focus_pad)); str = g_strdup_printf ("%s%s", C_("switch", "ON"), C_("switch", "OFF")); layout = gtk_widget_create_pango_layout (widget, str); pango_layout_get_extents (layout, NULL, &logical_rect); pango_extents_to_pixels (&logical_rect, NULL); height += MAX (min_height, logical_rect.height); g_object_unref (layout); g_free (str); if (minimum) *minimum = height; if (natural) *natural = height; }
static void gctt_combott_menu_position (GtkMenu *menu, gint *x, gint *y, gint *push_in, gpointer user_data) { GncCombott *combott = GNC_COMBOTT (user_data); GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott); gint sx, sy; GtkWidget *child; GtkRequisition req; GtkAllocation alloc; GtkBorder padding; GtkStyleContext *sc = gtk_widget_get_style_context (GTK_WIDGET (priv->button)); GtkStateFlags state_flags = gtk_style_context_get_state (sc); child = gtk_bin_get_child (GTK_BIN (priv->button)); sx = sy = 0; if (!gtk_widget_get_has_window (child)) { gtk_widget_get_allocation (child, &alloc); sx += alloc.x; sy += alloc.y; } gdk_window_get_root_coords (gtk_widget_get_window (child), sx, sy, &sx, &sy); gtk_style_context_get_padding (sc, state_flags, &padding); sx -= padding.left; gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); if (gtk_widget_get_direction (GTK_WIDGET (priv->button)) == GTK_TEXT_DIR_LTR) *x = sx; else { gtk_widget_get_allocation (child, &alloc); *x = sx + alloc.width - req.width; } if(priv->active == -1 || priv->active == 0) *y = sy; else *y = sy - ((req.height / priv->num_items) * (priv->active - 1)); *push_in = FALSE; }
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 _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 ide_omni_bar_popover_closed (IdeOmniBar *self, GtkPopover *popover) { GtkStyleContext *style_context; GtkStateFlags state_flags; g_assert (IDE_IS_OMNI_BAR (self)); g_assert (GTK_IS_POPOVER (popover)); style_context = gtk_widget_get_style_context (GTK_WIDGET (self)); state_flags = gtk_style_context_get_state (style_context); gtk_style_context_set_state (style_context, state_flags & ~GTK_STATE_FLAG_ACTIVE); }
static gboolean check_invalidate_pixbuf (GtkIconHelper *self, GtkStyleContext *context) { GtkStateFlags state; state = gtk_style_context_get_state (context); if ((self->priv->rendered_pixbuf != NULL) && (self->priv->last_rendered_state == state)) return FALSE; self->priv->last_rendered_state = state; g_clear_object (&self->priv->rendered_pixbuf); return TRUE; }
static gboolean gstyle_slidein_draw (GtkWidget *widget, cairo_t *cr) { GstyleSlidein *self = (GstyleSlidein *)widget; GtkStyleContext *context; GtkAllocation shade_box; GtkWidget *child; GdkRGBA rgba; g_assert (GSTYLE_IS_SLIDEIN (self)); g_assert (cr != NULL); /* To draw the shade effect in between the regular child and the slides, * we bypass gtk_event_box_draw (we use a windowless one so not a problem), * and provide your own container draw implementation. */ child = gtk_bin_get_child (GTK_BIN (self)); if (child == NULL) return GDK_EVENT_STOP; gtk_container_propagate_draw (GTK_CONTAINER (self), child, cr); if (self->offset > 0.0) { context = gtk_widget_get_style_context (widget); gtk_style_context_save (context); gtk_style_context_add_class (context, "shade"); gtk_style_context_get_color (context, gtk_style_context_get_state (context), &rgba); gtk_style_context_restore (context); rgba.alpha = rgba.alpha * self->offset; /* We shade the whole surface in case of slide tranparency */ gtk_widget_get_allocated_size (widget, &shade_box, NULL); cairo_rectangle (cr, shade_box.x, shade_box.y, shade_box.width, shade_box.height); gdk_cairo_set_source_rgba (cr, &rgba); cairo_fill (cr); } if (self->overlay_child != NULL) gtk_container_propagate_draw (GTK_CONTAINER (self), self->overlay_child, cr); return GDK_EVENT_STOP; }
static void apply_style (GtkSourceGutter *gutter, GtkSourceView *view, GtkStyleContext *style_context, cairo_t *cr) { const gchar *class; GdkRGBA fg_color; switch (gutter->priv->window_type) { case GTK_TEXT_WINDOW_TOP: class = GTK_STYLE_CLASS_TOP; break; case GTK_TEXT_WINDOW_RIGHT: class = GTK_STYLE_CLASS_RIGHT; break; case GTK_TEXT_WINDOW_BOTTOM: class = GTK_STYLE_CLASS_BOTTOM; break; case GTK_TEXT_WINDOW_LEFT: class = GTK_STYLE_CLASS_LEFT; break; case GTK_TEXT_WINDOW_PRIVATE: case GTK_TEXT_WINDOW_WIDGET: case GTK_TEXT_WINDOW_TEXT: default: g_return_if_reached (); } /* Apply classes ourselves, since we are in connect_after and so they * are not set by gtk. */ gtk_style_context_add_class (style_context, class); gtk_style_context_get_color (style_context, gtk_style_context_get_state (style_context), &fg_color); gdk_cairo_set_source_rgba (cr, &fg_color); }
static gboolean event_box_leave_notify (IdeOmniBar *self, GdkEvent *event, GtkEventBox *event_box) { GtkStyleContext *style_context; GtkStateFlags state_flags; g_assert (IDE_IS_OMNI_BAR (self)); g_assert (event != NULL); g_assert (GTK_IS_EVENT_BOX (event_box)); style_context = gtk_widget_get_style_context (GTK_WIDGET (self)); state_flags = gtk_style_context_get_state (style_context); gtk_style_context_set_state (style_context, state_flags & ~GTK_STATE_FLAG_PRELIGHT); return GDK_EVENT_PROPAGATE; }
static void update_toggle_state (NemoContextMenuMenuItem *item, gboolean from_event, gboolean on_item) { gboolean complex_mode = g_settings_get_boolean (nemo_preferences, NEMO_PREFERENCES_CONTEXT_MENUS_SHOW_ALL_ACTIONS); /* const */ gchar *tip_text = complex_mode ? _("Show less actions") : _("Show more actions"); gchar *markup = g_strdup_printf ("<small><i>%s</i></small>", tip_text); gtk_label_set_markup (GTK_LABEL (item->toggle_label_widget), markup); g_free (markup); if (item->on_toggle) { set_action_image_temporary_visibility (item, FALSE); gtk_stack_set_visible_child_name (GTK_STACK (item->stack), "toggle"); } else { set_action_image_temporary_visibility (item, TRUE); gtk_stack_set_visible_child_name (GTK_STACK (item->stack), "action"); } GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (item)); if (on_item) { gtk_image_set_from_icon_name (GTK_IMAGE (item->toggle_widget), complex_mode ? "collapse-menu-hover-symbolic" : "expand-menu-hover-symbolic", GTK_ICON_SIZE_MENU); } else { gtk_image_set_from_icon_name (GTK_IMAGE (item->toggle_widget), complex_mode ? "collapse-menu-symbolic" : "expand-menu-symbolic", GTK_ICON_SIZE_MENU); } GtkStateFlags default_item_state = from_event ? GTK_STATE_FLAG_PRELIGHT : gtk_style_context_get_state (context); gtk_style_context_set_state (context, item->on_toggle ? GTK_STATE_FLAG_NORMAL : default_item_state); gtk_widget_queue_draw (GTK_WIDGET (item)); }
static void multipress_pressed_cb (GtkGestureMultiPress *gesture, guint n_press, gdouble x, gdouble y, IdeOmniBar *self) { GtkStyleContext *style_context; GtkStateFlags state_flags; g_assert (IDE_IS_OMNI_BAR (self)); gtk_popover_popup (self->popover); style_context = gtk_widget_get_style_context (GTK_WIDGET (self)); state_flags = gtk_style_context_get_state (style_context); gtk_style_context_set_state (style_context, state_flags | GTK_STATE_FLAG_ACTIVE); gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); }
/** * gstyle_slidein_reveal_slide: * @reveal: %TRUE to reveal or %FALSE to close the slide * * Reveal or close the slide. * * Returns: #TRUE if the action can be executed, otherwise, %FALSE if the slide is already * in its final position, that is revealed or closed. */ gboolean gstyle_slidein_reveal_slide (GstyleSlidein *self, gboolean reveal) { GtkStyleContext *context; GtkStateFlags state; g_return_val_if_fail (GSTYLE_IS_SLIDEIN (self), FALSE); context = gtk_widget_get_style_context (GTK_WIDGET (self)); state = gtk_style_context_get_state (context); if (get_orientation (self) == GTK_ORIENTATION_HORIZONTAL) self->real_direction = (!!(state & GTK_STATE_FLAG_DIR_LTR)) ? self->direction_type : self->direction_type_reverse; else self->real_direction = self->direction_type; return animate (self, reveal ? 1.0 : 0.0); }
static void gtk_do_render_check (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { GtkStateFlags state; GtkCssImageBuiltinType image_type; state = gtk_style_context_get_state (context); if (state & GTK_STATE_FLAG_INCONSISTENT) image_type = GTK_CSS_IMAGE_BUILTIN_CHECK_INCONSISTENT; else if (state & GTK_STATE_FLAG_CHECKED) image_type = GTK_CSS_IMAGE_BUILTIN_CHECK_CHECKED; else image_type = GTK_CSS_IMAGE_BUILTIN_CHECK; gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, width, height, image_type); }
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 GtkIconLookupFlags get_icon_lookup_flags (GtkIconHelper *self, GtkStyleContext *context) { GtkIconLookupFlags flags; GtkCssIconStyle icon_style; GtkStateFlags state; state = gtk_style_context_get_state (context); flags = GTK_ICON_LOOKUP_USE_BUILTIN; if (self->priv->use_fallback) flags |= GTK_ICON_LOOKUP_GENERIC_FALLBACK; if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf) flags |= GTK_ICON_LOOKUP_FORCE_SIZE; icon_style = _gtk_css_icon_style_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_STYLE)); switch (icon_style) { case GTK_CSS_ICON_STYLE_REGULAR: flags |= GTK_ICON_LOOKUP_FORCE_REGULAR; break; case GTK_CSS_ICON_STYLE_SYMBOLIC: flags |= GTK_ICON_LOOKUP_FORCE_SYMBOLIC; break; case GTK_CSS_ICON_STYLE_REQUESTED: break; default: g_assert_not_reached (); return 0; } if (state & GTK_STATE_FLAG_DIR_LTR) flags |= GTK_ICON_LOOKUP_DIR_LTR; else if (state & GTK_STATE_FLAG_DIR_RTL) flags |= GTK_ICON_LOOKUP_DIR_RTL; return flags; }
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; } } }