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;
}
Ejemplo n.º 2
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
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;
}
Ejemplo n.º 4
0
void iupDrawFocusRect(IdrawCanvas* dc, int x, int y, int w, int h)
{
#if GTK_CHECK_VERSION(3, 0, 0)
  GtkStyleContext* context = gtk_widget_get_style_context(dc->ih->handle);
  gtk_render_focus(context, dc->image_cr, x, y, w, h);
#else
  GtkStyle *style = gtk_widget_get_style(dc->ih->handle);
  gtk_paint_focus(style, dc->window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, w, h);
#endif
}
Ejemplo n.º 5
0
static gboolean
draw_cb_focus (GtkWidget *widget, cairo_t *cr)
{
  GtkStyleContext *context;

  context = gtk_widget_get_style_context (widget);

  gtk_style_context_save (context);

  gtk_render_focus (context, cr, 12, 12, 50, 50);

  gtk_style_context_restore (context);

  return TRUE;
}
Ejemplo n.º 6
0
static gboolean
gtk_switch_draw (GtkWidget *widget,
                 cairo_t   *cr)
{
  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
  GtkStyleContext *context;
  GdkRectangle handle;
  PangoLayout *layout;
  PangoRectangle rect;
  gint label_x, label_y;
  GtkBorder padding;
  GtkStateFlags state;
  gint x, y, width, height;

  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);

  x = 0;
  y = 0;
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);

  gtk_render_background (context, cr, x, y, width, height);
  gtk_render_frame (context, cr, x, y, width, height);

  width -= padding.left + padding.right;
  height -= padding.top + padding.bottom;

  x += padding.left;
  y += padding.top;

  handle.y = y;
  handle.width = width / 2;
  handle.height = height;

  /* 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, &rect);
  pango_extents_to_pixels (&rect, NULL);

  label_x = x +  ((width / 2) - rect.width) / 2;
  label_y = y + (height - rect.height) / 2;

  gtk_render_layout (context, cr, label_x, label_y, layout);

  g_object_unref (layout);

  /* Translators: if the "off" state label requires more than three
   * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
   */
  layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF"));

  pango_layout_get_extents (layout, NULL, &rect);
  pango_extents_to_pixels (&rect, NULL);

  label_x = x +  (width / 2) + ((width / 2) - rect.width) / 2;
  label_y = y + (height - rect.height) / 2;

  gtk_render_layout (context, cr, label_x, label_y, layout);

  g_object_unref (layout);

  if (priv->is_dragging)
    handle.x = x + priv->handle_x;
  else if (priv->is_active)
    handle.x = x + width - handle.width;
  else
    handle.x = x;

  gtk_style_context_restore (context);

  gtk_switch_paint_handle (widget, cr, &handle);

  if (gtk_widget_has_visible_focus (widget))
    {
      gint focus_width, focus_pad, pad;

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

      pad = focus_pad + focus_width;

      gtk_render_focus (context, cr,
                        handle.x + pad, handle.y + pad,
                        handle.width - pad*2, handle.height - pad*2);
    }

  return FALSE;
}
static void
photos_print_preview_draw (PhotosPrintPreview *preview, cairo_t *cr)
{
	PhotosPrintPreviewPrivate *priv;
	GtkWidget *area;
	GtkAllocation allocation;
	gint x0, y0;
	gboolean has_focus;

	priv = preview->priv;
	area = priv->area;

	has_focus = gtk_widget_has_focus (area);

	gtk_widget_get_allocation (area, &allocation);

	/* draw the page */
	cairo_set_source_rgb (cr, 1., 1., 1.);
 	cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
 	cairo_fill (cr);

	/* draw the page margins */
	cairo_set_source_rgb (cr, 0., 0., 0.);
	cairo_set_line_width (cr, 0.1);
	cairo_rectangle (cr,
			 priv->l_rmargin, priv->t_rmargin,
			 allocation.width - priv->l_rmargin - priv->r_rmargin,
			 allocation.height - priv->t_rmargin - priv->b_rmargin);
	cairo_stroke (cr);

	get_current_image_coordinates (preview, &x0, &y0);

	if (priv->flag_create_surface) {
		create_surface (preview);
	}

	if (priv->surface) {
		cairo_set_source_surface (cr, priv->surface, x0, y0);
		cairo_paint (cr);
	} else if (priv->pixbuf_scaled) {
		/* just in the remote case we don't have the surface */

		/* adjust (x0, y0) to the new scale */
		gdouble scale = priv->i_scale * priv->p_scale *
			gdk_pixbuf_get_width (priv->pixbuf) / gdk_pixbuf_get_width (priv->pixbuf_scaled);
		x0 /= scale;
		y0 /= scale;

		cairo_scale (cr, scale, scale);
		gdk_cairo_set_source_pixbuf (cr, priv->pixbuf_scaled, x0, y0);
		cairo_paint (cr);
	} else if (priv->pixbuf) {
		/* just in the remote case we don't have the surface */

		/* adjust (x0, y0) to the new scale */
		x0 /=  priv->i_scale * priv->p_scale;
		y0 /=  priv->i_scale * priv->p_scale;

		cairo_scale (cr, priv->i_scale*priv->p_scale, priv->i_scale*priv->p_scale);
		gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, x0, y0);
		cairo_paint (cr);
	}

	if (has_focus) {
		GtkStyleContext *ctx;

		ctx = gtk_widget_get_style_context (area);
		gtk_render_focus (ctx, cr, x0, y0,
				  priv->r_width, priv->r_height);
	}
}
Ejemplo n.º 8
0
static gboolean
swatch_draw (GtkWidget *widget,
             cairo_t   *cr)
{
  GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
  gdouble width, height;
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkIconTheme *theme;
  GtkBorder border, padding;
  GdkRectangle rect;
  GtkIconInfo *icon_info = NULL;

  theme = gtk_icon_theme_get_default ();
  context = gtk_widget_get_style_context (widget);
  state = gtk_style_context_get_state (context);
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  gtk_render_background (context, cr, 0, 0, width, height);

  if (swatch->priv->has_color)
    {
      cairo_pattern_t *pattern;
      cairo_matrix_t matrix;

      gtk_render_content_path (context, cr, 0, 0, width, height);

      if (swatch->priv->use_alpha)
        {
          cairo_save (cr);

          cairo_clip_preserve (cr);

          cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
          cairo_fill_preserve (cr);

          pattern = _gtk_color_chooser_get_checkered_pattern ();
          cairo_matrix_init_scale (&matrix, 0.125, 0.125);
          cairo_pattern_set_matrix (pattern, &matrix);

          cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
          cairo_mask (cr, pattern);
          cairo_pattern_destroy (pattern);

          cairo_restore (cr);

          gdk_cairo_set_source_rgba (cr, &swatch->priv->color);
        }
      else
        {
          cairo_set_source_rgb (cr,
                                swatch->priv->color.red,
                                swatch->priv->color.green,
                                swatch->priv->color.blue);
        }

      cairo_fill (cr);
    }

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

  if (swatch->priv->icon)
    {
      icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, PIXBUF_SIZE,
                                              GTK_ICON_LOOKUP_GENERIC_FALLBACK
                                              | GTK_ICON_LOOKUP_USE_BUILTIN);
    }
  else if ((state & GTK_STATE_FLAG_SELECTED) != 0)
    {
      GIcon *gicon;

      gicon = g_themed_icon_new ("object-select-symbolic");
      /* fallback for themes that don't have object-select-symbolic */
      g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply");

      icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, PIXBUF_SIZE,
                                                  GTK_ICON_LOOKUP_GENERIC_FALLBACK
                                                  | GTK_ICON_LOOKUP_USE_BUILTIN);
      g_object_unref (gicon);
    }

  /* now draw the overlay image */
  gtk_style_context_get_border (context, state, &border);
  gtk_style_context_get_padding (context, state, &padding);
  rect.width = width - (border.left + border.right + padding.left + padding.right);
  rect.height = height - (border.top + border.bottom + padding.top + padding.bottom);
  rect.x = border.left + padding.left;
  rect.y = border.top + padding.top;

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, "overlay");
  
  gtk_render_background (context, cr, rect.x, rect.y, rect.width, rect.height);
  gtk_render_frame (context, cr, rect.x, rect.y, rect.width, rect.height);

  if (icon_info != NULL)
    {
      GdkPixbuf *pixbuf;

      pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context,
                                                        NULL, NULL);

      if (pixbuf != NULL)
        {
          gtk_render_icon (context, cr, pixbuf,
                           rect.x + (rect.width - gdk_pixbuf_get_width (pixbuf)) / 2,
                           rect.y + (rect.height - gdk_pixbuf_get_height (pixbuf)) / 2);
          g_object_unref (pixbuf);
        }

      g_object_unref (icon_info);
    }

  if (gtk_widget_has_visible_focus (widget))
    {
      gtk_render_focus (context, cr, 0, 0, width, height);
    }

  gtk_style_context_restore (context);

  return FALSE;
}
Ejemplo n.º 9
0
static gboolean
panel_applet_draw (GtkWidget *widget,
                   cairo_t   *cr)
{
	PanelApplet *applet = PANEL_APPLET (widget);
	GtkStyleContext *context;
	int border_width = 0;
	int focus_width = 0;
	gdouble x, y, width, height;
	
	GTK_WIDGET_CLASS (panel_applet_parent_class)->draw (widget, cr);

	if (applet->priv->has_handle) {
		GdkRectangle rect = applet->priv->handle_rect;
		GdkRGBA bg = { 1.0, 1.0, 1.0, .2 };
		GdkRGBA lighter = { .0, .0, .0, .2 };
		GdkRGBA darker = { .0, .0, .0, .4 };
		gint xx;
		gint yy;

		cairo_save (cr);
		
		// bg
		cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
		gdk_cairo_set_source_rgba (cr, &bg);
        cairo_fill(cr);

		// dots
		for (yy = rect.y; yy < rect.y + rect.height; yy += 3) {
			for (xx = rect.x; xx < rect.x + rect.width; xx += 6) {
		        render_dot (cr, &lighter, &darker, xx, yy, 2);
		        render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
			}
		}

		cairo_restore (cr);
	}

    if (!gtk_widget_has_focus (widget))
		return FALSE;

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

	/*
	 * We are deliberately ignoring focus-padding here to
	 * save valuable panel real estate.
	 */
	gtk_widget_style_get (widget,
			      "focus-line-width", &focus_width,
			      NULL);

	border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));

	x = 0; // FIXME: border_width ?
	y = 0; // FIXME: border_width ?
	width  -= 2 * border_width;
	height -= 2 * border_width;

        context = gtk_widget_get_style_context (widget);
        gtk_style_context_save (context);

        cairo_save (cr);
        gtk_render_focus (context, cr, x, y, width, height);
        cairo_restore (cr);

        gtk_style_context_restore (context);

	return FALSE;
}
Ejemplo n.º 10
0
static void
marlin_text_renderer_render (GtkCellRenderer    *cell,
                             cairo_t            *cr,
                             GtkWidget          *widget,
                             const GdkRectangle *background_area,
                             const GdkRectangle *cell_area,
                             GtkCellRendererState flags)
{
    MarlinTextRenderer *text_renderer = MARLIN_TEXT_RENDERER (cell);
    GtkStyleContext *context;
    GtkStateFlags state;
    gint x0, x1, y0, y1;
    gint text_width;
    gint text_height;
    gint x_offset;
    gint y_offset;
    gint xpad, ypad;
    gfloat xalign, yalign;
    gboolean selected;

    /* setup the new widget */
    marlin_text_renderer_set_widget (text_renderer, widget);

    state = gtk_widget_get_state_flags (widget);
    if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
    {
        state |= GTK_STATE_FLAG_SELECTED;
    }
    else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT
             && gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
    {
        state = GTK_STATE_PRELIGHT;
    }
    else
    {
        state = gtk_widget_get_sensitive (widget) ? GTK_STATE_FLAG_NORMAL : GTK_STATE_INSENSITIVE;
    }

    /* render small/normal text depending on the zoom_level */
    if (text_renderer->zoom_level < MARLIN_ZOOM_LEVEL_NORMAL)
    {
        if (text_renderer->follow_prelit && (flags & GTK_CELL_RENDERER_PRELIT) != 0)
            pango_layout_set_attributes (text_renderer->layout, eel_pango_attr_list_small_underline_single ());
        else
            pango_layout_set_attributes (text_renderer->layout, eel_pango_attr_list_small ());
    } else {
        if (text_renderer->follow_prelit && (flags & GTK_CELL_RENDERER_PRELIT) != 0)
            pango_layout_set_attributes (text_renderer->layout, eel_pango_attr_list_underline_single ());
        else
            pango_layout_set_attributes (text_renderer->layout, NULL);
    }

    /* setup the wrapping */
    if (text_renderer->wrap_width < 0)
    {
        pango_layout_set_width (text_renderer->layout, -1);
        pango_layout_set_wrap (text_renderer->layout, PANGO_WRAP_CHAR);
    }
    else
    {
        pango_layout_set_width (text_renderer->layout, text_renderer->wrap_width * PANGO_SCALE);
        pango_layout_set_wrap (text_renderer->layout, text_renderer->wrap_mode);
    }

    /* ellipsize to max lines except for selected or prelit items */
    pango_layout_set_ellipsize (text_renderer->layout, PANGO_ELLIPSIZE_END);
    pango_layout_set_height (text_renderer->layout, -3);
    if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED ||
            (flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT) {
        pango_layout_set_ellipsize (text_renderer->layout, PANGO_ELLIPSIZE_NONE);
    }

    gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
    if (xalign == 0.5f)
        pango_layout_set_alignment (text_renderer->layout, PANGO_ALIGN_CENTER);

    pango_layout_set_text (text_renderer->layout, text_renderer->text, -1);

    /* calculate the real text dimension */
    pango_layout_get_pixel_size (text_renderer->layout, &text_width, &text_height);


    /* take into account the state indicator (required for calculation) */
    if (text_renderer->follow_state)
    {
        text_width += 2 * text_renderer->focus_width;
        text_height += 2 * text_renderer->focus_width;
    }

    gtk_cell_renderer_get_padding (cell, &xpad, &ypad);

    /* calculate the real x-offset */
    x_offset = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? (1.0 - xalign) : xalign)
               * (cell_area->width - text_width - (2 * xpad));
    x_offset = MAX (x_offset, 0);

    /* calculate the real y-offset */
    y_offset = yalign * (cell_area->height - text_height - (2 * ypad));
    y_offset = MAX (y_offset, 0);

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

    selected = ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED && text_renderer->follow_state);

    /* render the state indicator */
    if (selected || text_renderer->background != NULL)
    {
        /* calculate the text bounding box (including the focus padding/width) */
        x0 = cell_area->x + x_offset;
        y0 = cell_area->y + y_offset;
        x1 = x0 + text_width;
        y1 = y0 + text_height;

        cairo_move_to (cr, x0 + 5, y0);
        cairo_line_to (cr, x1 - 5, y0);
        cairo_curve_to (cr, x1 - 5, y0, x1, y0, x1, y0 + 5);
        cairo_line_to (cr, x1, y1 - 5);
        cairo_curve_to (cr, x1, y1 - 5, x1, y1, x1 - 5, y1);
        cairo_line_to (cr, x0 + 5, y1);
        cairo_curve_to (cr, x0 + 5, y1, x0, y1, x0, y1 - 5);
        cairo_line_to (cr, x0, y0 + 5);
        cairo_curve_to (cr, x0, y0 + 5, x0, y0, x0 + 5, y0);

        GdkRGBA color;

        if(text_renderer->background != NULL && !selected)
        {
            if(!gdk_rgba_parse(&color, text_renderer->background))
            {
                g_critical("Can't parse this color value: %s", text_renderer->background);
                gtk_style_context_get_background_color (context, state, &color);
            }

        }
        else
        {
            gtk_style_context_get_background_color (context, state, &color);
        }
        gdk_cairo_set_source_rgba (cr, &color);
        cairo_fill (cr);
    }

    /* draw the focus indicator */
    if (text_renderer->follow_state && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
    {
        gtk_render_focus (context, cr, cell_area->x + x_offset, cell_area->y + y_offset, text_width, text_height);
    }

    /* get proper sizing for the layout drawing */
    if (text_renderer->follow_state)
    {
        text_width -= 2 * text_renderer->focus_width;
        text_height -= 2 * text_renderer->focus_width;
        x_offset += text_renderer->focus_width;
        y_offset += text_renderer->focus_width;
    }

    /* draw the text */
    if (xalign == 0.5f)
        x_offset = (cell_area->width - text_renderer->wrap_width)/2;

    gtk_render_layout (context, cr,
                       cell_area->x + x_offset + xpad,
                       cell_area->y + y_offset + ypad,
                       text_renderer->layout);

    gtk_style_context_restore (context);
}
Ejemplo n.º 11
0
static gboolean
gtk_switch_draw (GtkWidget *widget,
                 cairo_t   *cr)
{
  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
  GtkStyleContext *context;
  GdkRectangle handle;
  PangoLayout *layout;
  PangoFontDescription *desc;
  const PangoFontDescription *style_desc;
  PangoRectangle rect;
  gint label_x, label_y;
  GtkStateFlags state;
  GtkBorder padding;
  gint focus_width, focus_pad;
  gint x, y, width, height;
  gint font_size, style_font_size;

  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);

  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);

  gtk_style_context_restore (context);

  x = 0;
  y = 0;
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  if (gtk_widget_has_focus (widget))
    gtk_render_focus (context, cr, x, y, width, height);

  x += focus_width + focus_pad;
  y += focus_width + focus_pad;
  width -= 2 * (focus_width + focus_pad);
  height -= 2 * (focus_width + focus_pad);

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

  gtk_render_background (context, cr, x, y, width, height);
  gtk_render_frame (context, cr, x, y, width, height);

  width -= padding.left + padding.right;
  height -= padding.top + padding.bottom;

  x += padding.left;
  y += padding.top;

  handle.y = y;
  handle.width = width / 2;
  handle.height = height;

  /* 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"));

  /* FIXME: this should be really done in the theme, but overriding font size
   * from it doesn't currently work. So we have to hardcode this here and
   * below for the "OFF" label.
   */
  desc = pango_font_description_new ();

  style_desc = gtk_style_context_get_font (context, state);
  style_font_size = pango_font_description_get_size (style_desc);
  font_size = MAX (style_font_size - 1 * PANGO_SCALE, ceil (style_font_size * PANGO_SCALE_SMALL));

  pango_font_description_set_size (desc, font_size);

  pango_layout_set_font_description (layout, desc);

  pango_layout_get_extents (layout, NULL, &rect);
  pango_extents_to_pixels (&rect, NULL);

  label_x = x +  ((width / 2) - rect.width) / 2;
  label_y = y + (height - rect.height) / 2;

  gtk_render_layout (context, cr, label_x, label_y, layout);

  g_object_unref (layout);

  /* Translators: if the "off" state label requires more than three
   * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
   */
  layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF"));
  pango_layout_set_font_description (layout, desc);

  pango_layout_get_extents (layout, NULL, &rect);
  pango_extents_to_pixels (&rect, NULL);

  label_x = x +  (width / 2) + ((width / 2) - rect.width) / 2;
  label_y = y + (height - rect.height) / 2;

  gtk_render_layout (context, cr, label_x, label_y, layout);

  g_object_unref (layout);

  if (priv->is_dragging)
    handle.x = x + priv->handle_x;
  else if (priv->is_active)
    handle.x = x + width - handle.width;
  else
    handle.x = x;

  gtk_style_context_restore (context);

  gtk_switch_paint_handle (widget, cr, &handle);

  pango_font_description_free (desc);

  return FALSE;
}
Ejemplo n.º 12
0
static void
anjuta_tabber_draw_tab (AnjutaTabber* tabber, cairo_t* cr, GList* child)
{
	GtkWidget* widget = GTK_WIDGET (tabber);
	GtkWidget* tab = GTK_WIDGET (child->data);

	gboolean current;
	gint focus_width;
	gint focus_pad;
	gint tab_curvature;
	gint tab_overlap;
	gint focus_space;
	gint tab_begin;
	gint tab_end;

	GtkStateFlags state;
	GtkRegionFlags region_flags;
	GtkBorder tab_padding;
	GtkAllocation alloc;
	GtkAllocation widget_alloc;

	GtkStyleContext* context = gtk_widget_get_style_context (widget);

	current = g_list_position (tabber->priv->children, child) == tabber->priv->active_page;

	gtk_widget_style_get (widget,
	                      "focus-line-width", &focus_width,
	                      "focus-padding", &focus_pad,
	                      "tab-curvature", &tab_curvature,
	                      "tab-overlap", &tab_overlap,
	                      NULL);

	focus_space = focus_pad + focus_width;

	/* Get border/padding for tab */
	gtk_style_context_save (context);
	anjuta_tabber_setup_style_context (tabber, context, child, &state, &region_flags);
	gtk_style_context_get_padding (context, state, &tab_padding);
		
	gtk_widget_get_allocation (widget, &widget_alloc);
	gtk_widget_get_allocation (tab, &alloc);

	tab_begin = tab_curvature - tab_overlap;
	tab_end = tab_curvature - tab_overlap;

	if (region_flags | GTK_REGION_FIRST)
		tab_begin += tab_overlap;
	if (region_flags | GTK_REGION_LAST)
		tab_end += tab_overlap;
	
	alloc.x -= widget_alloc.x;
	alloc.x -= tab_begin;
	alloc.x -= focus_space + tab_padding.left;
	alloc.y -= widget_alloc.y;
	alloc.y -= focus_space + tab_padding.top;
	alloc.width += 2 * focus_space + tab_padding.left + tab_padding.right
		+ tab_begin + tab_end;
	alloc.height += 2 * focus_space + tab_padding.top + tab_padding.bottom;
	
	gtk_render_extension (context,
	                      cr,
	                      alloc.x, 
	                      alloc.y,
	                      alloc.width, 
	                      alloc.height,
	                      GTK_POS_BOTTOM);

	if (gtk_widget_has_focus (widget) &&
	    current)
	{
		GtkAllocation allocation;
		
		gtk_widget_get_allocation (tab, &allocation);

		gtk_render_focus (context, cr,
		                  allocation.x - focus_space,
		                  allocation.y - focus_space,
		                  allocation.width + 2 * focus_space,
		                  allocation.height + 2 * focus_space);
	}
	
	gtk_style_context_restore (context);
}
Ejemplo n.º 13
0
static void
anjuta_tabber_render_tab (GtkWidget* widget,
                          GtkWidget* tab,
                          cairo_t* cr,
                          gboolean current,
                          GtkRegionFlags region_flags)
{
	AnjutaTabber* tabber = ANJUTA_TABBER (widget);
	GtkAllocation alloc;
	GtkAllocation widget_alloc;

	gint focus_width;
	gint tab_curvature;
	gint tab_overlap;
	gint tab_begin;
	gint tab_end;

	gint xpadding;
	gint ypadding;
	GtkStyleContext* context = gtk_widget_get_style_context (widget);

	if (current)
		gtk_widget_set_state_flags (tab, GTK_STATE_FLAG_ACTIVE, TRUE);
	else
		gtk_widget_unset_state_flags (tab, GTK_STATE_FLAG_ACTIVE);		
	
	gtk_widget_style_get (widget,
	                      "focus-line-width", &focus_width,
	                      "tab-curvature", &tab_curvature,
	                      "tab-overlap", &tab_overlap,
	                      NULL);

	 /* Get border/padding for tab */
	gtk_style_context_save (context);
	gtk_style_context_add_class (context, GTK_STYLE_CLASS_NOTEBOOK);
	gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB,
	                              region_flags);
	if (current)
		gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
	if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
		gtk_style_context_set_junction_sides (context,
			                                  GTK_JUNCTION_CORNER_TOPLEFT);
	else
		gtk_style_context_set_junction_sides (context,
			                                  GTK_JUNCTION_CORNER_TOPRIGHT);		
	
	gtk_widget_get_allocation (widget, &widget_alloc);
	gtk_widget_get_allocation (tab, &alloc);

	xpadding = focus_width + tabber->priv->tab_hborder;
	ypadding = focus_width + tabber->priv->tab_vborder;

	tab_begin = tab_curvature - tab_overlap;
	tab_end = tab_curvature - tab_overlap;

	if (region_flags | GTK_REGION_FIRST)
		tab_begin += tab_overlap;
	if (region_flags | GTK_REGION_LAST)
		tab_end += tab_overlap;
	
	alloc.x -= widget_alloc.x;
	alloc.x -= tab_begin;
	alloc.x -= xpadding;
	alloc.y -= widget_alloc.y;
	alloc.y -= ypadding;
	alloc.width += 2 * (xpadding) + tab_begin + tab_end;
	alloc.height += 2 * ypadding;
	
	gtk_render_extension (context,
	                      cr,
	                      alloc.x, 
	                      alloc.y,
	                      alloc.width, 
	                      alloc.height,
	                      GTK_POS_BOTTOM);

	if (gtk_widget_has_focus (widget) &&
	    current)
	{
		GtkAllocation allocation;
		
		gtk_widget_get_allocation (tab, &allocation);

		gtk_render_focus (context, cr,
		                  allocation.x - focus_width,
		                  allocation.y - focus_width,
		                  allocation.width + 2 * focus_width,
		                  allocation.height + 2 * focus_width);
	}
	
	gtk_style_context_restore (context);
}
Ejemplo n.º 14
0
static void fm_cell_renderer_text_render(GtkCellRenderer *cell,
                                         GdkDrawable *window,
                                         GtkWidget *widget,
                                         GdkRectangle *background_area,
                                         GdkRectangle *cell_area,
                                         GdkRectangle *expose_area,
                                         GtkCellRendererState flags)
#endif
{
    FmCellRendererText *self = FM_CELL_RENDERER_TEXT(cell);
#if GTK_CHECK_VERSION(3, 0, 0)
    GtkStyleContext* style;
    GtkStateFlags state;
#else
    GtkStyle* style;
    GtkStateType state;
#endif
    gchar* text;
    gint text_width;
    gint text_height;
    gint x_offset;
    gint y_offset;
    gint x_align_offset;
    GdkRectangle rect;
    PangoWrapMode wrap_mode;
    gint wrap_width;
    PangoAlignment alignment;
    gfloat xalign, yalign;
    gint xpad, ypad;

    /* FIXME: this is time-consuming since it invokes pango_layout.
     *        if we want to fix this, we must implement the whole cell
     *        renderer ourselves instead of derived from GtkCellRendererText. */
    PangoContext* context = gtk_widget_get_pango_context(widget);

    PangoLayout* layout = pango_layout_new(context);

    g_object_get(G_OBJECT(cell),
                 "wrap-mode" , &wrap_mode,
                 "wrap-width", &wrap_width,
                 "alignment" , &alignment,
                 "text", &text,
                 NULL);

    pango_layout_set_alignment(layout, alignment);

    /* Setup the wrapping. */
    if (wrap_width < 0)
    {
        pango_layout_set_width(layout, -1);
        pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
    }
    else
    {
        pango_layout_set_width(layout, wrap_width * PANGO_SCALE);
        pango_layout_set_wrap(layout, wrap_mode);
        if(self->height > 0)
        {
            /* FIXME: add custom ellipsize from object? */
            pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
            pango_layout_set_height(layout, self->height * PANGO_SCALE);
        }
        else
            pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
    }

    pango_layout_set_text(layout, text, -1);

    pango_layout_set_auto_dir(layout, TRUE);

    pango_layout_get_pixel_size(layout, &text_width, &text_height);

    gtk_cell_renderer_get_alignment(cell, &xalign, &yalign);
    gtk_cell_renderer_get_padding(cell, &xpad, &ypad);
    /* Calculate the real x and y offsets. */
    x_offset = ((gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) ? (1.0 - xalign) : xalign)
             * (cell_area->width - text_width - (2 * xpad));
    x_offset = MAX(x_offset, 0);

    y_offset = yalign * (cell_area->height - text_height - (2 * ypad));
    y_offset = MAX (y_offset, 0);

    if(flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_FOCUSED))
    {
        rect.x = cell_area->x + x_offset;
        rect.y = cell_area->y + y_offset;
        rect.width = text_width + (2 * xpad);
        rect.height = text_height + (2 * ypad);
    }

#if GTK_CHECK_VERSION(3, 0, 0)
    style = gtk_widget_get_style_context(widget);
#else
    style = gtk_widget_get_style(widget);
#endif
    if(flags & GTK_CELL_RENDERER_SELECTED) /* item is selected */
    {
#if GTK_CHECK_VERSION(3, 0, 0)
        GdkRGBA clr;

        if(flags & GTK_CELL_RENDERER_INSENSITIVE) /* insensitive */
            state = GTK_STATE_FLAG_INSENSITIVE;
        else
            state = GTK_STATE_FLAG_SELECTED;

        gtk_style_context_get_background_color(style, state, &clr);
        gdk_cairo_rectangle(cr, &rect);
        gdk_cairo_set_source_rgba(cr, &clr);
#else
        cairo_t *cr = gdk_cairo_create (window);
        GdkColor clr;

        if(flags & GTK_CELL_RENDERER_INSENSITIVE) /* insensitive */
            state = GTK_STATE_INSENSITIVE;
        else
            state = GTK_STATE_SELECTED;

        clr = style->bg[state];

        /* paint the background */
        if(expose_area)
        {
            gdk_cairo_rectangle(cr, expose_area);
            cairo_clip(cr);
        }
        gdk_cairo_rectangle(cr, &rect);

        cairo_set_source_rgb(cr, clr.red / 65535., clr.green / 65535., clr.blue / 65535.);
#endif
        cairo_fill (cr);

#if !GTK_CHECK_VERSION(3, 0, 0)
        cairo_destroy (cr);
#endif
    }
#if !GTK_CHECK_VERSION(3, 0, 0)
    else
        state = GTK_STATE_NORMAL;
#endif

    x_align_offset = (alignment == PANGO_ALIGN_CENTER) ? (wrap_width - text_width) / 2 : 0;

#if GTK_CHECK_VERSION(3, 0, 0)
    gtk_render_layout(style, cr,
                      cell_area->x + x_offset + xpad - x_align_offset,
                      cell_area->y + y_offset + ypad, layout);
#else
    gtk_paint_layout(style, window, state, TRUE,
                     expose_area, widget, "cellrenderertext",
                     cell_area->x + x_offset + xpad - x_align_offset,
                     cell_area->y + y_offset + ypad, layout);
#endif

    g_object_unref(layout);

    if(G_UNLIKELY( flags & GTK_CELL_RENDERER_FOCUSED) ) /* focused */
    {
#if GTK_CHECK_VERSION(3, 0, 0)
        gtk_render_focus(style, cr, rect.x, rect.y, rect.width, rect.height);
#else
        gtk_paint_focus(style, window, state, background_area,
                        widget, "cellrenderertext", rect.x, rect.y,
                        rect.width, rect.height);
#endif
    }

    if(flags & GTK_CELL_RENDERER_PRELIT) /* hovered */
        g_object_set(G_OBJECT(widget), "tooltip-text", text, NULL);
    else
        g_object_set(G_OBJECT(widget), "tooltip-text", NULL, NULL);
    g_free(text);
}
Ejemplo n.º 15
0
Archivo: gtkswitch.c Proyecto: BYC/gtk
static gboolean
gtk_switch_draw (GtkWidget *widget,
                 cairo_t   *cr)
{
  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
  GtkStyleContext *context;
  GdkRectangle handle;
  PangoLayout *layout;
  PangoRectangle rect;
  gint label_x, label_y;
  GtkStateFlags state;
  GtkBorder padding;
  gint focus_width, focus_pad;
  gint x, y, width, height;

  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);

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

  gtk_style_context_get_padding (context, state, &padding);

  x = 0;
  y = 0;
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  if (gtk_widget_has_focus (widget))
    gtk_render_focus (context, cr, x, y, width, height);

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

  x += focus_width + focus_pad;
  y += focus_width + focus_pad;
  width -= 2 * (focus_width + focus_pad);
  height -= 2 * (focus_width + focus_pad);

  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);

  gtk_render_background (context, cr, x, y, width, height);
  gtk_render_frame (context, cr, x, y, width, height);

  /* XXX the +1/-1 it's pixel wriggling after checking with the default
   * theme and xmag
   */
  handle.y = y + padding.top + 1;
  handle.width = (width - padding.left - padding.right) / 2;
  handle.height = (height - padding.top - padding.bottom) - 1;

  /* 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, &rect);
  pango_extents_to_pixels (&rect, NULL);

  label_x = x + padding.left
          + ((width / 2) - rect.width - padding.left - padding.right) / 2;
  label_y = y + padding.top
          + (height - rect.height - padding.top - padding.bottom) / 2;

  gtk_render_layout (context, cr, label_x, label_y, layout);

  g_object_unref (layout);

  /* Translators: if the "off" state label requires more than three
   * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
   */
  layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF"));
  pango_layout_get_extents (layout, NULL, &rect);
  pango_extents_to_pixels (&rect, NULL);

  label_x = x + padding.left
          + (width / 2)
          + ((width / 2) - rect.width - padding.left - padding.right) / 2;
  label_y = y + padding.top
          + (height - rect.height - padding.top - padding.bottom) / 2;

  gtk_render_layout (context, cr, label_x, label_y, layout);

  g_object_unref (layout);

  if (priv->is_dragging)
    handle.x = x + priv->handle_x;
  else if (priv->is_active)
    handle.x = x + width - handle.width - padding.right;
  else
    handle.x = x + padding.left;

  gtk_style_context_restore (context);

  gtk_switch_paint_handle (widget, cr, &handle);

  return FALSE;
}