Example #1
0
static void border(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA)
{
    GtkStyleContext* sc = gtk_widget_get_style_context(widget);
    gtk_style_context_set_state(sc, state);
    gtk_style_context_get_border_color(sc, state, &gdkRGBA);
    if (gdkRGBA.alpha <= 0)
    {
        widget = gtk_widget_get_parent(GTK_WIDGET(ContainerWidget()));
        sc = gtk_widget_get_style_context(widget);
        gtk_style_context_set_state(sc, state);
        gtk_style_context_get_border_color(sc, state, &gdkRGBA);
    }
}
Example #2
0
static gboolean
gnm_notebook_button_draw (GtkWidget *widget, cairo_t *cr)
{
	GnmNotebookButton *nbb = GNM_NOTEBOOK_BUTTON (widget);
	GnmNotebook *nb = GNM_NOTEBOOK (gtk_widget_get_parent (widget));
	GtkStyleContext *context = gtk_widget_get_style_context (widget);
	gboolean is_active = (widget == gnm_notebook_get_current_label (nb));
	GtkStateFlags state =
		is_active ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL;
	GtkBorder padding;

	gtk_style_context_save (context);
	gtk_style_context_set_state (context, state);

	gtk_style_context_get_padding (context, state, &padding);

	gnm_notebook_button_ensure_layout (nbb);

	gtk_render_layout (context, cr,
			   padding.left + (is_active ? nbb->x_offset_active : nbb->x_offset),
			   0,
			   is_active ? nbb->layout_active : nbb->layout);

	gtk_style_context_restore (context);
	return FALSE;
}
Example #3
0
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;
}
Example #4
0
JNIEXPORT void JNICALL
Java_org_gnome_gtk_GtkStyleContext_gtk_1style_1context_1set_1state
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jint _flags
)
{
	GtkStyleContext* self;
	GtkStateFlags flags;

	// convert parameter self
	self = (GtkStyleContext*) _self;

	// convert parameter flags
	flags = (GtkStateFlags) _flags;

	// call function
	gtk_style_context_set_state(self, flags);

	// cleanup parameter self

	// cleanup parameter flags
}
Example #5
0
static void
on_preview_draw (GtkWidget      *drawing_area,
                 cairo_t        *cr,
                 gpointer        data)
{
  ScreenshotDialog *dialog = data;
  GtkStyleContext *context;
  int width, height;

  width = gtk_widget_get_allocated_width (drawing_area);
  height = gtk_widget_get_allocated_height (drawing_area);

  if (!dialog->preview_image ||
      gdk_pixbuf_get_width (dialog->preview_image) != width ||
      gdk_pixbuf_get_height (dialog->preview_image) != height)
    {
      g_clear_object (&dialog->preview_image);
      dialog->preview_image = gdk_pixbuf_scale_simple (dialog->screenshot,
                                                       width,
                                                       height,
                                                       GDK_INTERP_BILINEAR);
    }

  context = gtk_widget_get_style_context (drawing_area);
  gtk_style_context_save (context);

  gtk_style_context_set_state (context, gtk_widget_get_state_flags (drawing_area));
  gtk_render_icon (context, cr, dialog->preview_image, 0, 0);

  gtk_style_context_restore (context);
}
Example #6
0
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);
}
void styleContext_estimateBackColor(GtkStyleContext* a_StyleContext, GdkRGBA* a_BackColor)
{
	GtkStateFlags state = GTK_STATE_FLAG_NORMAL;

	unsigned char imageBytes[4];
	{
		gtk_style_context_save(a_StyleContext);
		gtk_style_context_set_state(a_StyleContext, state);
		cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
		cairo_t* cairo = cairo_create(surface);

		renderAllBackgrounds(a_StyleContext, cairo);
		cairo_surface_flush(surface);
		memcpy(imageBytes, cairo_image_surface_get_data(surface), sizeof(imageBytes));

		cairo_surface_destroy(surface);
		cairo_destroy(cairo);
		gtk_style_context_restore(a_StyleContext);
	}

	const unsigned char a = imageBytes[3];
	const unsigned char r = imageBytes[2];
	const unsigned char g = imageBytes[1];
	const unsigned char b = imageBytes[0];

	a_BackColor->alpha = a / 255.0;
	a_BackColor->red   = inversePremultipliedColor(r, a) / 255.0;
	a_BackColor->green = inversePremultipliedColor(g, a) / 255.0;
	a_BackColor->blue  = inversePremultipliedColor(b, a) / 255.0;
}
Example #8
0
static gboolean
draw_callback (GtkWidget *widget,
               cairo_t *cr,
               gpointer data)
{
  RenderGradientFunc func = data;
  GtkAllocation allocation;
  GtkStyleContext *style;
  GdkRGBA color;

  style = gtk_widget_get_style_context (widget);

  gtk_style_context_save (style);
  gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget));
  gtk_style_context_lookup_color (style, "foreground-color", &color);
  gtk_style_context_restore (style);

  gtk_widget_get_allocation (widget, &allocation);

  cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);

  (* func) (
            cr,
            allocation.width,
            allocation.height);

  return FALSE;
}
Example #9
0
/* FIXME: this doesn't work */
static gboolean
draw_cb_activity (GtkWidget *widget, cairo_t *cr)
{
  GtkStyleContext *context;
  GtkWidgetPath *path;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_notify_state_change (context,
                                         gtk_widget_get_window (widget),
                                         NULL,
                                         GTK_STATE_FLAG_ACTIVE,
                                         TRUE);

  gtk_style_context_save (context);

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_SPINNER);
  gtk_widget_path_iter_add_class (path, 0, "spinner");
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);

  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
  gtk_render_activity (context, cr, 12, 12, 12, 12);

  gtk_style_context_restore (context);

  return TRUE;
}
Example #10
0
static inline void
gtk_switch_paint_handle (GtkWidget    *widget,
                         cairo_t      *cr,
                         GdkRectangle *box)
{
  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
  GtkStyleContext *context = gtk_widget_get_style_context (widget);
  GtkStateFlags state;

  state = gtk_widget_get_state_flags (widget);

  if (priv->is_active)
    state |= GTK_STATE_FLAG_ACTIVE;

  gtk_style_context_save (context);
  gtk_style_context_set_state (context, state);
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);

  gtk_render_slider (context, cr,
                     box->x, box->y,
                     box->width, box->height,
                     GTK_ORIENTATION_HORIZONTAL);

  gtk_style_context_restore (context);
}
Example #11
0
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);

}
Example #12
0
static void
gdl_dock_tablabel_paint (GtkWidget      *widget,
                         cairo_t *cr)
{
    GtkBin          *bin;
    GtkAllocation    widget_allocation;
    GdlDockTablabel *tablabel;
    gint             border_width;
    cairo_rectangle_int_t rect;

    bin = GTK_BIN (widget);
    tablabel = GDL_DOCK_TABLABEL (widget);
    border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));

    gtk_widget_get_allocation (widget, &widget_allocation);
    rect.x = widget_allocation.x + border_width;
    rect.y = widget_allocation.y + border_width;
    rect.width = tablabel->drag_handle_size * HANDLE_RATIO;
    rect.height = widget_allocation.height - 2*border_width;

    if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
    {
        GtkStyleContext* context = gtk_widget_get_style_context (widget);
        gtk_style_context_set_state (context,
                                     tablabel->active ? 0 : GTK_STATE_FLAG_ACTIVE);

        gtk_render_handle (gtk_widget_get_style_context (widget),
                           cr, rect.x, rect.y, rect.width, rect.height);
    };
}
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;
}
Example #14
0
static gboolean
xfce_arrow_button_draw (GtkWidget      *widget,
                        cairo_t        *cr)
{
    gint x, y, w;
    GtkStyleContext *context;
    xfce_arrow_button_thickness thickness;
    GtkAllocation allocation;

    if (G_LIKELY (gtk_widget_is_drawable (widget)))
    {
        context = gtk_widget_get_style_context (widget);
        xfce_arrow_button_get_thickness (context, &thickness);
        gtk_widget_get_allocation (widget, &allocation);

        w = MIN (allocation.height - 2 * thickness.y,
                 allocation.width  - 2 * thickness.x);
        w = MIN (w, ARROW_WIDTH);

        x = (allocation.width - w) / 2;
        y = (allocation.height - w) / 2;

        GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);

        gtk_style_context_save (context);
        gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));

        gtk_render_arrow (context, cr, G_PI, x, y, w);

        gtk_style_context_restore (context);
    }

    return TRUE;
}
Example #15
0
static void
draw_radio (GtkWidget     *widget,
            cairo_t       *cr,
            gint           x,
            gint           y,
            GtkStateFlags  state)
{
  GtkStyleContext *button_context;
  GtkStyleContext *check_context;

  /* This information is taken from the GtkRadioButton docs, see "CSS nodes" */
  const char *path[2] = {
    "radiobutton",
    "radio"
  };

  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_option (check_context, cr, x, y, 20, 20);

  g_object_unref (check_context);
  g_object_unref (button_context);

}
static void
gossip_cell_renderer_expander_render (GtkCellRenderer      *cell,
				      cairo_t              *cr,
				      GtkWidget            *widget,
				      const GdkRectangle   *background_area,
				      const GdkRectangle   *cell_area,
				      GtkCellRendererState  flags)
{
	GossipCellRendererExpander     *expander;
	GossipCellRendererExpanderPriv *priv;
	GtkStyleContext                *style_context;
	gint                            x_offset, y_offset;
	gint                            xpad, ypad;

	expander = (GossipCellRendererExpander*) cell;
	priv = GET_PRIV (expander);

	gossip_cell_renderer_expander_get_size (cell, widget, cell_area,
						&x_offset, &y_offset,
						NULL, NULL);
	gtk_cell_renderer_get_padding (cell, &xpad, &ypad);

	style_context = gtk_widget_get_style_context (widget);
	gtk_style_context_set_state (style_context, priv->style_flags);

	gtk_render_expander (gtk_widget_get_style_context (widget),
			     cr,
			     cell_area->x + x_offset + xpad,
			     cell_area->y + y_offset + ypad,
			     priv->expander_size,
			     priv->expander_size);
}
Example #17
0
static gboolean
window_menu_on_draw (GtkWidget *widget,
                     cairo_t   *cr,
                     gpointer   data)
{
        GtkStyleContext *context;
        GtkStateFlags    state;
        WindowMenu      *window_menu = data;

	if (!gtk_widget_has_focus (window_menu->applet))
                return FALSE;

        state = gtk_widget_get_state_flags (widget);
        context = gtk_widget_get_style_context (widget);
        gtk_style_context_save (context);
        gtk_style_context_set_state (context, state);

        cairo_save (cr);
        gtk_render_focus (context, cr,
                          0., 0.,
                          gtk_widget_get_allocated_width (widget),
                          gtk_widget_get_allocated_height (widget));
        cairo_restore (cr);

        gtk_style_context_restore (context);

	return FALSE;
}
static gboolean
panel_menu_bar_object_on_draw (GtkWidget *widget,
                               cairo_t   *cr,
                               gpointer   data)
{
    PanelMenuBarObject *menubar = data;

    if (gtk_widget_has_focus (GTK_WIDGET (menubar))) {
        GtkStyleContext *context;

        context = gtk_widget_get_style_context (widget);
        gtk_style_context_save (context);
        gtk_style_context_set_state (context,
                                     gtk_widget_get_state_flags (widget));

        cairo_save (cr);
        gtk_render_focus (context, cr,
                          0, 0,
                          gtk_widget_get_allocated_width (widget),
                          gtk_widget_get_allocated_height (widget));
        cairo_restore (cr);

        gtk_style_context_restore (context);
    }

    return FALSE;
}
Example #19
0
static gboolean
drag_highlight_draw (GtkWidget *widget,
                     cairo_t   *cr,
                     gpointer   user_data)
{
	gint width, height;
	GdkWindow *window;
	GtkStyleContext *style;
	
        window = gtk_widget_get_window (widget);
        width = gdk_window_get_width (window);
        height = gdk_window_get_height (window);

	style = gtk_widget_get_style_context (widget);

	gtk_style_context_save (style);
	gtk_style_context_add_class (style, GTK_STYLE_CLASS_DND);
	gtk_style_context_set_state (style, GTK_STATE_FLAG_FOCUSED);

	gtk_render_frame (style,
			  cr,
			  0, 0, width, height);

	gtk_style_context_restore (style);

	return FALSE;
}
Example #20
0
static gboolean
panel_toggle_button_draw (GtkWidget *widget, cairo_t *cr)
{
  GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
  GtkStateType state_type;
  GtkShadowType shadow_type;
  GtkAllocation allocation;
  GtkStyleContext *context = gtk_widget_get_style_context (widget);
  GtkStateFlags flags = 0;

  state_type = gtk_widget_get_state (widget);
    
  /* FIXME: someone make this layout work nicely for all themes
   * Currently I'm trying to imitate the volume applet's widget */
  if (gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget))) {
    if (state_type == GTK_STATE_ACTIVE)
      state_type = GTK_STATE_NORMAL;
    shadow_type = GTK_SHADOW_ETCHED_IN;
  } else {
    shadow_type = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
  }
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    state_type = GTK_STATE_SELECTED;
  /* FIXME: better detail? */
  gtk_widget_get_allocation (widget, &allocation);
  gtk_style_context_add_class (context, "togglebutton");
  switch (state_type)
    {
    case GTK_STATE_PRELIGHT:
      flags |= GTK_STATE_FLAG_PRELIGHT;
      break;
    case GTK_STATE_SELECTED:
      flags |= GTK_STATE_FLAG_SELECTED;
      break;
    case GTK_STATE_INSENSITIVE:
      flags |= GTK_STATE_FLAG_INSENSITIVE;
      break;
    case GTK_STATE_ACTIVE:
      flags |= GTK_STATE_FLAG_ACTIVE;
      break;
    case GTK_STATE_FOCUSED:
      flags |= GTK_STATE_FLAG_FOCUSED;
      break;
    case GTK_STATE_NORMAL:
    case GTK_STATE_INCONSISTENT:
    default:
      break;
  }

  gtk_style_context_set_state (context, flags);
  gtk_render_background (context, cr, (gdouble) allocation.x, (gdouble) allocation.y,
                                 (gdouble) allocation.width, (gdouble) allocation.height);
  (void) shadow_type;

  if (child)
    gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
  
  return FALSE;
}
Example #21
0
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);
}
Example #22
0
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);
    }
Example #23
0
static void
gtk_switch_get_preferred_height (GtkWidget *widget,
                                 gint      *minimum,
                                 gint      *natural)
{
  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkBorder padding;
  gint height, focus_width, focus_pad;
  PangoLayout *layout;
  PangoRectangle logical_rect;
  gchar *str;

  context = gtk_widget_get_style_context (widget);
  state = gtk_widget_get_state_flags (widget);

  if (priv->is_active)
    state |= GTK_STATE_FLAG_ACTIVE;

  gtk_style_context_save (context);

  gtk_style_context_set_state (context, state);
  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,
                        "focus-line-width", &focus_width,
                        "focus-padding", &focus_pad,
                        NULL);

  height += 2 * (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 (DEFAULT_SLIDER_HEIGHT, logical_rect.height);

  g_object_unref (layout);
  g_free (str);

  if (minimum)
    *minimum = height;

  if (natural)
    *natural = height;
}
Example #24
0
static void
set_color_from_style (GdkRGBA               *color,
                      GtkStyleContext       *context,
                      GtkStateFlags          state,
                      MetaGtkColorComponent  component)
{
    GdkRGBA other;

    gtk_style_context_set_state (context, state);

    switch (component)
    {
    case META_GTK_COLOR_BG:
    case META_GTK_COLOR_BASE:
        meta_color_get_background_color (context, state, color);
        break;

    case META_GTK_COLOR_FG:
    case META_GTK_COLOR_TEXT:
        gtk_style_context_get_color (context, state, color);
        break;

    case META_GTK_COLOR_TEXT_AA:
        gtk_style_context_get_color (context, state, color);
        set_color_from_style (&other, context, state, META_GTK_COLOR_BASE);

        color->red = (color->red + other.red) / 2;
        color->green = (color->green + other.green) / 2;
        color->blue = (color->blue + other.blue) / 2;
        break;

    case META_GTK_COLOR_MID:
        meta_color_get_light_color (context, state, color);
        meta_color_get_dark_color (context, state, &other);

        color->red = (color->red + other.red) / 2;
        color->green = (color->green + other.green) / 2;
        color->blue = (color->blue + other.blue) / 2;
        break;

    case META_GTK_COLOR_LIGHT:
        meta_color_get_light_color (context, state, color);
        break;

    case META_GTK_COLOR_DARK:
        meta_color_get_dark_color (context, state, color);
        break;

    case META_GTK_COLOR_LAST:
    default:
        g_assert_not_reached ();
        break;
    }
}
Example #25
0
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;
}
Example #26
0
static void
gm_cell_renderer_expander_render (GtkCellRenderer                    *cell,
				  cairo_t                            *cr,
				  GtkWidget                          *widget,
				  G_GNUC_UNUSED const GdkRectangle   *background_area,
				  const GdkRectangle                 *cell_area,
				  GtkCellRendererState               flags)
{
	GmCellRendererExpander     *expander;
	GmCellRendererExpanderPriv *priv;
	gint                            x_offset, y_offset;
	guint                           xpad, ypad;
	GtkStyleContext                 *style;
	GtkStateFlags                    state;

	expander = (GmCellRendererExpander *) cell;
	priv = expander->priv;

	gm_cell_renderer_expander_get_size (cell, widget,
						(GdkRectangle *) cell_area,
						&x_offset, &y_offset,
						NULL, NULL);

	g_object_get (cell,
		      "xpad", &xpad,
		      "ypad", &ypad,
		      NULL);

	style = gtk_widget_get_style_context (widget);

	gtk_style_context_save (style);
	gtk_style_context_add_class (style, GTK_STYLE_CLASS_EXPANDER);

	state = gtk_cell_renderer_get_state (cell, widget, flags);

	if (priv->expander_style == GTK_EXPANDER_COLLAPSED)
		state |= GTK_STATE_FLAG_NORMAL;
	else
		state |= GTK_STATE_FLAG_ACTIVE;

	gtk_style_context_set_state (style, state);

	gtk_render_expander (style,
			     cr,
			     cell_area->x + x_offset + xpad,
			     cell_area->y + y_offset + ypad,
			     priv->expander_size,
			     priv->expander_size);

	gtk_style_context_restore (style);
}
Example #27
0
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);
}
Example #28
0
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;
}
Example #29
0
static gboolean
draw_cb_expanders (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, "expander");
  gtk_style_context_set_state (context, 0);
  gtk_render_expander (context, cr, 12, 12, 12, 12);
  gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT);
  gtk_render_expander (context, cr, 36, 12, 12, 12);
  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
  gtk_render_expander (context, cr, 60, 12, 12, 12);
  gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE);
  gtk_render_expander (context, cr, 84, 12, 12, 12);

  gtk_style_context_restore (context);

  return TRUE;
}
Example #30
0
static void
draw_horizontal_scrollbar (GtkWidget     *widget,
                           cairo_t       *cr,
                           gint           x,
                           gint           y,
                           gint           width,
                           gint           height,
                           gint           position,
                           GtkStateFlags  state)
{
  GtkStyleContext *scrollbar_context;
  GtkStyleContext *trough_context;
  GtkStyleContext *slider_context;

  /* This information is taken from the GtkScrollbar docs, see "CSS nodes" */
  const char *path[3] = {
    "scrollbar.horizontal",
    "trough",
    "slider"
  };

  scrollbar_context = get_style (NULL, path[0]);
  trough_context = get_style (scrollbar_context, path[1]);
  slider_context = get_style (trough_context, path[2]);

  gtk_style_context_set_state (scrollbar_context, state);
  gtk_style_context_set_state (trough_context, state);
  gtk_style_context_set_state (slider_context, state);

  gtk_render_background (trough_context, cr, x, y, width, height);
  gtk_render_frame (trough_context, cr, x, y, width, height);
  gtk_render_slider (slider_context, cr, x + position, y + 1, 30, height - 2, GTK_ORIENTATION_HORIZONTAL);

  g_object_unref (slider_context);
  g_object_unref (trough_context);
  g_object_unref (scrollbar_context);
}