Exemplo n.º 1
0
static void
ig_reload_style (GnmItemGrid *ig)
{
	GocItem *item = GOC_ITEM (ig);
	GtkStyleContext *context = goc_item_get_style_context (item);
	GtkBorder border;
	GtkStateFlags state = GTK_STATE_FLAG_NORMAL;
	GnmPane *pane = GNM_PANE (item->canvas);

	gtk_style_context_save (context);
	gtk_style_context_add_region (context, "function-marker", 0);
	gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
				     &ig->function_marker_color);
	gtk_style_context_get_border_color (context, state,
					    &ig->function_marker_border_color);
	gtk_style_context_restore (context);

	gtk_style_context_save (context);
	gtk_style_context_add_region (context, "pane-divider", 0);
	gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
				     &ig->pane_divider_color);
	gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border);
	ig->pane_divider_width = border.top;  /* Hack? */
	gtk_style_context_restore (context);

	/* ---------------------------------------- */

	context = gtk_widget_get_style_context (GTK_WIDGET (pane));
	gtk_widget_style_get (GTK_WIDGET (pane),
			      "function-indicator-size",
			      &ig->function_marker_size,
			      NULL);
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
static gboolean
gtk_source_map_draw (GtkWidget *widget,
                     cairo_t   *cr)
{
	GtkSourceMap *map = GTK_SOURCE_MAP (widget);
	GtkSourceMapPrivate *priv;
	GtkStyleContext *style_context;

	priv = gtk_source_map_get_instance_private (map);

	if (GTK_WIDGET_CLASS (gtk_source_map_parent_class)->draw (widget, cr))
	{
		return TRUE;
	}

	style_context = gtk_widget_get_style_context (widget);

	gtk_style_context_save (style_context);
	gtk_style_context_add_class (style_context, "scrubber");
	gtk_render_background (style_context, cr,
	                       priv->scrubber_area.x, priv->scrubber_area.y,
	                       priv->scrubber_area.width, priv->scrubber_area.height);
	gtk_style_context_restore (style_context);

	return FALSE;
}
Exemplo n.º 4
0
static void
anjuta_tabber_get_preferred_width (GtkWidget* widget, 
                                    gint* minimum,
                                    gint* preferred)
{
	g_return_if_fail (ANJUTA_IS_TABBER (widget));

	AnjutaTabber* tabber = ANJUTA_TABBER (widget);
	GtkStyleContext* context;
	GList* child;
	gint focus_width;
	gint focus_pad;
	gint tab_curvature;
	gint tab_overlap;

	*minimum = 0;
	*preferred = 0;
	
	gtk_widget_style_get (GTK_WIDGET (tabber->priv->notebook),
	                      "focus-line-width", &focus_width,
	                      "focus-padding", &focus_pad,
	                      "tab-curvature", &tab_curvature,
	                      "tab-overlap", &tab_overlap,
	                      NULL);

	context = gtk_widget_get_style_context (widget);

	for (child = tabber->priv->children; child != NULL; child = g_list_next (child))
	{
		GtkStateFlags state;
		GtkBorder tab_padding;
		gint xpadding;
		gint child_min;
		gint child_preferred;
		gint extra_space = 2 * (tab_curvature - tab_overlap);

		/* Get the padding of the tab */
		gtk_style_context_save (context);
		anjuta_tabber_setup_style_context (tabber, context, child, &state, NULL);
		gtk_style_context_get_padding (context, state, &tab_padding);
		gtk_style_context_restore (context);

		xpadding =  2 * (focus_width + focus_pad) + tab_padding.left + tab_padding.right;
		
		if (child->prev == NULL)
			extra_space += tab_overlap;
		if (child->next == NULL)
			extra_space += tab_overlap;
		
		gtk_widget_get_preferred_width (GTK_WIDGET (child->data), &child_min, &child_preferred);
		if (minimum)
		{
			*minimum += child_min + xpadding + extra_space;
		}
		if (preferred)
		{
			*preferred += child_preferred + xpadding + extra_space;
		}
	}
}
Exemplo n.º 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);
}
Exemplo n.º 6
0
static gboolean
nemo_search_bar_draw (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, GTK_STYLE_CLASS_INFO);

	gtk_render_background (context, cr, 0, 0,
			       gtk_widget_get_allocated_width (widget),
			       gtk_widget_get_allocated_height (widget));

	gtk_render_frame (context, cr, 0, 0,
			  gtk_widget_get_allocated_width (widget),
			  gtk_widget_get_allocated_height (widget));

	gtk_style_context_restore (context);

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

	return FALSE;
}
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;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
static gboolean
rg_graph_draw (GtkWidget *widget,
               cairo_t   *cr)
{
  RgGraph *self = (RgGraph *)widget;
  RgGraphPrivate *priv = rg_graph_get_instance_private (self);
  GtkStyleContext *style_context;
  GtkAllocation alloc;

  g_assert (RG_IS_GRAPH (self));

  gtk_widget_get_allocation (widget, &alloc);

  style_context = gtk_widget_get_style_context (widget);

  rg_graph_ensure_surface (self);

  gtk_style_context_save (style_context);
  gtk_style_context_add_class (style_context, "view");
  gtk_render_background (style_context, cr, 0, 0, alloc.width, alloc.height);
  gtk_style_context_restore (style_context);

  cairo_save (cr);
  cairo_set_source_surface (cr, priv->surface, priv->x_offset, 0);
  cairo_rectangle (cr, 0, 0, alloc.width, alloc.height);
  cairo_fill (cr);
  cairo_restore (cr);

  return GDK_EVENT_PROPAGATE;
}
static gboolean
highlight_draw (GtkWidget *widget,
                cairo_t   *cr,
                gpointer data)
{
    GdkWindow *bin_window;
    int width;
    int height;
    GtkStyleContext *style;

    /* FIXMEchpe: is bin window right here??? */
    bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget));

    width = gdk_window_get_width (bin_window);
    height = gdk_window_get_height (bin_window);

    style = gtk_widget_get_style_context (widget);

    gtk_style_context_save (style);
    gtk_style_context_add_class (style, "treeview-drop-indicator");

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

    gtk_style_context_restore (style);

    return FALSE;
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
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 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;
}
Exemplo n.º 16
0
static gboolean
draw_cb_frame (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, "frame1");
  gtk_style_context_set_junction_sides (context, 0);
  gtk_render_frame (context, cr, 12, 12, 50, 50);
  gtk_style_context_remove_class (context, "frame1");

  gtk_style_context_add_class (context, "frame2");
  gtk_render_frame (context, cr, 74, 12, 50, 50);
  gtk_style_context_remove_class (context, "frame2");

  gtk_style_context_add_class (context, "frame3");
  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_RIGHT);
  gtk_render_frame (context, cr, 12, 74, 56, 50);
  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_LEFT);
  gtk_render_frame (context, cr, 68, 74, 56, 50);
  gtk_style_context_remove_class (context, "frame3");

  gtk_style_context_restore (context);

  return TRUE;
}
Exemplo n.º 17
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;
}
static gboolean
select_window_draw (GtkWidget *window, cairo_t *cr, gpointer unused)
{
  GtkStyleContext *style;

  style = gtk_widget_get_style_context (window);

  if (gtk_widget_get_app_paintable (window))
    {
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
      cairo_set_source_rgba (cr, 0, 0, 0, 0);
      cairo_paint (cr);

      gtk_style_context_save (style);
      gtk_style_context_add_class (style, GTK_STYLE_CLASS_RUBBERBAND);

      gtk_render_background (style, cr,
                             0, 0,
                             gtk_widget_get_allocated_width (window),
                             gtk_widget_get_allocated_height (window));
      gtk_render_frame (style, cr,
                        0, 0,
                        gtk_widget_get_allocated_width (window),
                        gtk_widget_get_allocated_height (window));

      gtk_style_context_restore (style);
    }

  return TRUE;
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
static cairo_surface_t *
ev_document_misc_render_thumbnail_frame (GtkWidget       *widget,
        int              width,
        int              height,
        gboolean         inverted_colors,
        GdkPixbuf       *source_pixbuf,
        cairo_surface_t *source_surface)
{
    GtkStyleContext *context = gtk_widget_get_style_context (widget);
    GtkStateFlags    state = gtk_widget_get_state_flags (widget);
    int              width_r, height_r;
    int              width_f, height_f;
    cairo_surface_t *surface;
    cairo_t         *cr;
    GtkBorder        border = {0, };

    if (source_surface) {
        width_r = cairo_image_surface_get_width (source_surface);
        height_r = cairo_image_surface_get_height (source_surface);
    } else if (source_pixbuf) {
        g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);

        width_r = gdk_pixbuf_get_width (source_pixbuf);
        height_r = gdk_pixbuf_get_height (source_pixbuf);
    } else {
        width_r = width;
        height_r = height;
    }

    gtk_style_context_save (context);

    gtk_style_context_add_class (context, "page-thumbnail");
    if (inverted_colors)
        gtk_style_context_add_class (context, "inverted");

    gtk_style_context_get_border (context, state, &border);
    width_f = width_r + border.left + border.right;
    height_f = height_r + border.top + border.bottom;

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                          width_f, height_f);

    cr = cairo_create (surface);
    if (source_surface) {
        cairo_set_source_surface (cr, source_surface, border.left, border.top);
        cairo_paint (cr);
    } else if (source_pixbuf) {
        gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
        cairo_paint (cr);
    } else {
        gtk_render_background (context, cr, 0, 0, width_f, height_f);
    }
    gtk_render_frame (context, cr, 0, 0, width_f, height_f);
    cairo_destroy (cr);

    gtk_style_context_restore (context);

    return surface;
}
Exemplo n.º 22
0
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;
}
Exemplo n.º 23
0
static gboolean
gtk_switch_motion (GtkWidget      *widget,
                   GdkEventMotion *event)
{
  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;

  /* if this is a direct toggle we don't handle motion */
  if (priv->in_press)
    return GDK_EVENT_PROPAGATE;

  if (ABS (event->x - priv->drag_start) < priv->drag_threshold)
    return GDK_EVENT_STOP;

  if (event->state & GDK_BUTTON1_MASK)
    {
      gint position = event->x - priv->offset;
      GtkAllocation allocation;
      GtkStyleContext *context;
      GtkStateFlags state;
      GtkBorder padding;
      gint width, focus_width, focus_pad;

      gtk_widget_style_get (widget,
                            "focus-line-width", &focus_width,
                            "focus-padding", &focus_pad,
                            NULL);

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

      gtk_style_context_save (context);
      gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
      gtk_style_context_get_padding (context, state, &padding);
      gtk_style_context_restore (context);
      
      gtk_widget_get_allocation (widget, &allocation);

      width = allocation.width - 2 * (focus_width + focus_pad);

      /* constrain the handle within the trough width */
      if (position > (width / 2) - padding.right)
        priv->handle_x = width / 2 - padding.right;
      else if (position < padding.left)
        priv->handle_x = 0;
      else
        priv->handle_x = position;

      priv->is_dragging = TRUE;

      /* we need to redraw the handle */
      gtk_widget_queue_draw (widget);

      return GDK_EVENT_STOP;
    }

  return GDK_EVENT_PROPAGATE;
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
{
    GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    gtk_style_context_save(styleContext);

    applyScrollbarStyleContextClasses(styleContext, scrollbar->orientation());
    gtk_style_context_add_class(styleContext, "scrolled-window");
    gtk_render_frame(styleContext, context->platformContext()->cr(), scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());

    gtk_style_context_restore(styleContext);
}
Exemplo n.º 26
0
static void
gd_two_lines_renderer_prepare_layouts (GdTwoLinesRenderer *self,
                                       const GdkRectangle *cell_area,
                                       GtkWidget *widget,
                                       PangoLayout **layout_one,
                                       PangoLayout **layout_two)
{
  PangoLayout *line_one;
  PangoLayout *line_two = NULL;
  gchar *text = NULL;

  g_object_get (self,
                "text", &text,
                NULL);

  line_one = create_layout_with_attrs (widget, cell_area,
                                       self, PANGO_ELLIPSIZE_MIDDLE);

  if (self->priv->line_two == NULL ||
      g_strcmp0 (self->priv->line_two, "") == 0)
    {
      pango_layout_set_height (line_one, - (self->priv->text_lines));

      if (text != NULL)
        pango_layout_set_text (line_one, text, -1);
    }
  else
    {
      GtkStyleContext *context;

      line_two = create_layout_with_attrs (widget, cell_area,
                                           self, PANGO_ELLIPSIZE_END);

      context = gtk_widget_get_style_context (widget);
      gtk_style_context_save (context);
      apply_subtitle_style_to_layout (context, line_two, GTK_STATE_FLAG_NORMAL);
      gtk_style_context_restore (context);

      pango_layout_set_height (line_one, - (self->priv->text_lines - 1));
      pango_layout_set_height (line_two, -1);
      pango_layout_set_text (line_two, self->priv->line_two, -1);

      if (text != NULL)
        pango_layout_set_text (line_one, text, -1);
    }

  if (layout_one)
    *layout_one = line_one;
  if (layout_two)
    *layout_two = line_two;

  g_free (text);
}
Exemplo n.º 27
0
void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
    wxPaintDC dc(this);

#ifdef __WXGTK20__
    // Draw grip first
    if ( ShowsSizeGrip() )
    {
        const wxRect& rc = GetSizeGripRect();
#ifdef __WXGTK3__
        GtkWidget* toplevel = gtk_widget_get_toplevel(m_widget);
        GdkRectangle rect;
        if (toplevel && (!gtk_window_get_resize_grip_area(GTK_WINDOW(toplevel), &rect) ||
            rect.width == 0 || rect.height == 0))
        {
            GtkStyleContext* sc = gtk_widget_get_style_context(toplevel);
            gtk_style_context_save(sc);
            gtk_style_context_add_class(sc, GTK_STYLE_CLASS_GRIP);
            GtkJunctionSides sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
            if (GetLayoutDirection() == wxLayout_RightToLeft)
                sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
            gtk_style_context_set_junction_sides(sc, sides);
            gtk_render_handle(sc,
                static_cast<cairo_t*>(dc.GetImpl()->GetCairoContext()),
                rc.x, rc.y, rc.width, rc.height);
            gtk_style_context_restore(sc);
        }
#else
        GdkWindowEdge edge =
            GetLayoutDirection() == wxLayout_RightToLeft ? GDK_WINDOW_EDGE_SOUTH_WEST :
                                                           GDK_WINDOW_EDGE_SOUTH_EAST;
        gtk_paint_resize_grip(gtk_widget_get_style(m_widget),
                            GTKGetDrawingWindow(),
                            gtk_widget_get_state(m_widget),
                            NULL,
                            m_widget,
                            "statusbar",
                            edge,
                            rc.x, rc.y, rc.width, rc.height );
#endif
    }
#endif // __WXGTK20__

    if (GetFont().IsOk())
        dc.SetFont(GetFont());

    // compute char height only once for all panes:
    int textHeight = dc.GetCharHeight();

    dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
    for (size_t i = 0; i < m_panes.GetCount(); i ++)
        DrawField(dc, i, textHeight);
}
Exemplo n.º 28
0
void
ReleaseStyleContext(GtkStyleContext* aStyleContext)
{
  if (sStyleContextNeedsRestore) {
    gtk_style_context_restore(aStyleContext);
  }
  sStyleContextNeedsRestore = false;
#ifdef DEBUG
  MOZ_ASSERT(sCurrentStyleContext == aStyleContext);
  sCurrentStyleContext = nullptr;
#endif
}
Exemplo n.º 29
0
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);
}
Exemplo n.º 30
0
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;
}