コード例 #1
0
ファイル: gnm-notebook.c プロジェクト: nzinfo/gnumeric
static void
gnm_notebook_button_set_property (GObject      *obj,
				  guint         prop_id,
				  const GValue *value,
				  GParamSpec   *pspec)
{
	GnmNotebookButton *nbb = GNM_NOTEBOOK_BUTTON (obj);

	switch (prop_id) {
	case NBB_PROP_BACKGROUND_COLOR:
		gdk_rgba_free (nbb->bg);
		nbb->bg = g_value_dup_boxed (value);
		gtk_widget_queue_draw (GTK_WIDGET (obj));
		g_clear_object (&nbb->layout);
		g_clear_object (&nbb->layout_active);
		break;
	case NBB_PROP_TEXT_COLOR:
		gdk_rgba_free (nbb->fg);
		nbb->fg = g_value_dup_boxed (value);
		gtk_widget_queue_draw (GTK_WIDGET (obj));
		gtk_widget_override_color (GTK_WIDGET (obj),
					   GTK_STATE_FLAG_NORMAL,
					   nbb->fg);
		gtk_widget_override_color (GTK_WIDGET (obj),
					   GTK_STATE_FLAG_ACTIVE,
					   nbb->fg);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
		break;
	}
}
コード例 #2
0
ファイル: gtktextattributes.c プロジェクト: Pfiver/gtk
/**
 * gtk_text_attributes_unref:
 * @values: a #GtkTextAttributes
 * 
 * Decrements the reference count on @values, freeing the structure
 * if the reference count reaches 0.
 **/
void
gtk_text_attributes_unref (GtkTextAttributes *values)
{
  g_return_if_fail (values != NULL);
  g_return_if_fail (values->refcount > 0);

  values->refcount -= 1;

  if (values->refcount == 0)
    {
      if (values->tabs)
        pango_tab_array_free (values->tabs);

      if (values->font)
	pango_font_description_free (values->font);

      if (values->pg_bg_color)
	gdk_color_free (values->pg_bg_color);

      if (values->pg_bg_rgba)
	gdk_rgba_free (values->pg_bg_rgba);

      if (values->appearance.rgba[0])
	gdk_rgba_free (values->appearance.rgba[0]);

      if (values->appearance.rgba[1])
	gdk_rgba_free (values->appearance.rgba[1]);

      g_slice_free (GtkTextAttributes, values);
    }
}
コード例 #3
0
ファイル: gtkmodifierstyle.c プロジェクト: BYC/gtk
static void
modifier_style_set_color (GtkModifierStyle *style,
                          const gchar      *prop,
                          GtkStateFlags     state,
                          const GdkRGBA    *color)
{
  GtkModifierStylePrivate *priv;
  GdkRGBA *old_color;

  g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));

  priv = style->priv;
  gtk_style_properties_get (priv->style, state,
                            prop, &old_color,
                            NULL);

  if ((!color && !old_color) ||
      (color && old_color && gdk_rgba_equal (color, old_color)))
    {
      gdk_rgba_free (old_color);
      return;
    }

  if (color)
    gtk_style_properties_set (priv->style, state,
                              prop, color,
                              NULL);
  else
    gtk_style_properties_unset_property (priv->style, prop, state);

  g_signal_emit (style, signals[CHANGED], 0);
  gdk_rgba_free (old_color);
}
コード例 #4
0
ファイル: unico-draw.c プロジェクト: Distrotech/unico
static void
unico_draw_focus (DRAW_ARGS)
{
  GdkRGBA *fill_color, *border_color;
  GtkStateFlags state;
  gint focus_pad, line_width;
  gint radius;

  state = gtk_theming_engine_get_state (engine);

  gtk_theming_engine_get_style (engine,
                                "focus-padding", &focus_pad,
                                "focus-line-width", &line_width,
                                NULL);

  /* Skip rendering if focus-line-width is 0 or less. */
  if (line_width < 1)
    return;

  /* Use the outline attributes for the focus properties to avoid using
   * custom attributes. Outlines don't have a fill, so hardcode the fill
   * color to be the same color as the border, but with 20% of its alpha.
   */
  gtk_theming_engine_get (engine, state,
                          "outline-color", &border_color,
                          "outline-offset", &radius,
                          NULL);

  fill_color = gdk_rgba_copy (border_color);
  fill_color->alpha = border_color->alpha * 0.2;

  x += focus_pad;
  y += focus_pad;
  width -= focus_pad * 2;
  height -= focus_pad * 2;

  cairo_save (cr);

  cairo_set_line_width (cr, line_width);

  /* first layer, background */
  unico_cairo_round_rect (cr, x, y,
                              width, height,
                              radius, SIDE_ALL, GTK_JUNCTION_NONE);
  gdk_cairo_set_source_rgba (cr, fill_color);
  cairo_fill (cr);

  /* second layer, border */
  unico_cairo_round_rect_inner (cr, x, y,
                                    width, height,
                                    radius, SIDE_ALL, GTK_JUNCTION_NONE);
  gdk_cairo_set_source_rgba (cr, border_color);
  cairo_stroke (cr);

  cairo_restore (cr);

  gdk_rgba_free (border_color);
  gdk_rgba_free (fill_color);
}
コード例 #5
0
ファイル: gnm-notebook.c プロジェクト: nzinfo/gnumeric
static void
gnm_notebook_button_finalize (GObject *obj)
{
	GnmNotebookButton *nbb = GNM_NOTEBOOK_BUTTON (obj);
	g_clear_object (&nbb->layout);
	g_clear_object (&nbb->layout_active);
	gdk_rgba_free (nbb->fg);
	gdk_rgba_free (nbb->bg);
	gnm_notebook_button_parent_class->finalize (obj);
}
コード例 #6
0
ファイル: gtktextattributes.c プロジェクト: Pfiver/gtk
/**
 * gtk_text_attributes_copy_values:
 * @src: a #GtkTextAttributes
 * @dest: another #GtkTextAttributes
 *
 * Copies the values from @src to @dest so that @dest has
 * the same values as @src. Frees existing values in @dest.
 */
void
gtk_text_attributes_copy_values (GtkTextAttributes *src,
                                 GtkTextAttributes *dest)
{
  guint orig_refcount;

  if (src == dest)
    return;

  /* Remove refs */
  if (dest->tabs)
    pango_tab_array_free (dest->tabs);

  if (dest->font)
    pango_font_description_free (dest->font);

  if (dest->pg_bg_color)
    gdk_color_free (dest->pg_bg_color);

  if (dest->pg_bg_rgba)
    gdk_rgba_free (dest->pg_bg_rgba);

  if (dest->appearance.rgba[0])
    gdk_rgba_free (dest->appearance.rgba[0]);

  if (dest->appearance.rgba[1])
    gdk_rgba_free (dest->appearance.rgba[1]);

  /* Copy */
  orig_refcount = dest->refcount;

  *dest = *src;

  if (src->tabs)
    dest->tabs = pango_tab_array_copy (src->tabs);

  dest->language = src->language;

  if (src->font)
    dest->font = pango_font_description_copy (src->font);

  if (src->pg_bg_color)
    dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);

  if (src->pg_bg_rgba)
    dest->pg_bg_rgba = gdk_rgba_copy (src->pg_bg_rgba);

  if (src->appearance.rgba[0])
    dest->appearance.rgba[0] = gdk_rgba_copy (src->appearance.rgba[0]);

  if (src->appearance.rgba[1])
    dest->appearance.rgba[1] = gdk_rgba_copy (src->appearance.rgba[1]);

  dest->refcount = orig_refcount;
}
コード例 #7
0
ファイル: xmrlabel.c プロジェクト: EmbolismSoil/xmradio
void
xmr_label_set_color(XmrLabel *label,
			const gchar *color)
{
	GdkRGBA gdk_color;
	XmrLabelPrivate *priv;

	g_return_if_fail(label != NULL);

	priv = label->priv;
	if (color == NULL)
	{
		gdk_rgba_free(priv->current_color);
		priv->current_color = gdk_rgba_copy(&priv->default_color);
	}
	else
	{
		if (gdk_rgba_parse(&gdk_color, color))
		{
			priv->current_color->red = gdk_color.red;
			priv->current_color->green = gdk_color.green;
			priv->current_color->blue = gdk_color.blue;
			// always set to 1.0
			priv->current_color->alpha = 1.0;
		}
	}

	gtk_widget_queue_draw(GTK_WIDGET(label));
}
コード例 #8
0
ファイル: biji-note-obj.c プロジェクト: Abdillah/bijiben
static void
biji_note_obj_finalize (GObject *object)
{
  BijiNoteObj        *self = BIJI_NOTE_OBJ(object);
  BijiNoteObjPrivate *priv = self->priv;

  if (priv->timeout)
    g_object_unref (priv->timeout);

  if (priv->needs_save)
    on_save_timeout (self);

  g_clear_object (&priv->id);

  g_hash_table_destroy (priv->labels);

  if (priv->icon)
    g_object_unref (priv->icon);

  if (priv->emblem)
    g_object_unref (priv->emblem);

  if (priv->pristine)
    g_object_unref (priv->pristine);

  gdk_rgba_free (priv->color);

  G_OBJECT_CLASS (biji_note_obj_parent_class)->finalize (object);
}
コード例 #9
0
ファイル: gtknumerableicon.c プロジェクト: BoozzyAmdJin/gtk-
static void
gtk_numerable_icon_finalize (GObject *object)
{
  GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);

  g_free (self->priv->label);
  g_free (self->priv->rendered_string);

  gdk_rgba_free (self->priv->background);
  gdk_rgba_free (self->priv->foreground);

  pango_font_description_free (self->priv->font);

  cairo_pattern_destroy (self->priv->background_image);

  G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->finalize (object);
}
コード例 #10
0
ファイル: settings.cpp プロジェクト: MaartenBent/wxWidgets
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);
    }
コード例 #11
0
ファイル: tile-preview.c プロジェクト: adzymaniac/muffin
void
meta_tile_preview_free (MetaTilePreview *preview)
{
  gtk_widget_destroy (preview->preview_window);

  if (preview->preview_color)
    gdk_rgba_free (preview->preview_color);

  g_free (preview);
}
コード例 #12
0
static gboolean
label_draw(GtkWidget *label, cairo_t *cr, gpointer data)
{
  UIMCandWinHorizontalGtk *horizontal_cwin = data;
  struct index_button *selected;
  GtkWidget *selected_label = NULL;
  GdkRGBA *bg_color, *fg_color;
  GtkStyleContext *context;
  PangoLayout *layout;
  gint x, y;
  GtkStateFlags state;

  selected = horizontal_cwin->selected;
  if (selected)
    selected_label = gtk_bin_get_child(GTK_BIN(selected->button));

  layout = gtk_label_get_layout(GTK_LABEL(label));
  gtk_label_get_layout_offsets(GTK_LABEL(label), &x, &y);

  context = gtk_widget_get_style_context(label);

  if (label == selected_label)
    state = GTK_STATE_FLAG_SELECTED;
  else
    state = GTK_STATE_FLAG_NORMAL;

  gtk_style_context_get (context, state, "background-color", &bg_color, "color", &fg_color, NULL);

  cairo_save(cr);
  gdk_cairo_set_source_rgba(cr, bg_color);
  cairo_paint(cr);
  cairo_restore(cr);
  gdk_rgba_free(bg_color);
  gdk_rgba_free(fg_color);

  gtk_style_context_set_state (context, state);
  gtk_render_layout (context, cr, x, y, layout);

  return FALSE;
}
コード例 #13
0
/**
@brief setup @a cr for usage
@param cr cairo context for @a widget
@param widget to be drawn upon

@return
*/
static void _e2_gesture_dialog_cairo_setup (cairo_t *cr, GtkWidget *widget)
{
	GdkRGBA *color;
	GtkStyleContext *context;
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); //enable display of dots ?
	cairo_set_line_width (cr, 1.0); //approx 1 pixel
	cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
	context = gtk_widget_get_style_context (widget);
	gtk_style_context_get (context, GTK_STATE_NORMAL, GTK_STYLE_PROPERTY_COLOR,
		&color, NULL);
	cairo_set_source_rgb (cr, color->red, color->green, color->blue);
	gdk_rgba_free (color);
}
コード例 #14
0
ファイル: biji-note-obj.c プロジェクト: curiousDTU/bijiben
void
biji_note_obj_set_rgba(BijiNoteObj *n,GdkRGBA *rgba)
{
  if (!n->priv->color)
  {    
    biji_note_obj_set_rgba_internal (n, rgba);
    return;
  }

  if (!gdk_rgba_equal (n->priv->color,rgba))
  {
    gdk_rgba_free (n->priv->color);
    biji_note_obj_set_rgba_internal (n, rgba);
  }
}
コード例 #15
0
static void lunar_calendar_finalize (GObject *gobject)
{
	LunarCalendar *calendar;

	calendar = LUNAR_CALENDAR (gobject);

	if (calendar->date != NULL)
	{
		lunar_date_free(calendar->date);
	}

	if (calendar->rgba != NULL)
		gdk_rgba_free(calendar->rgba);
	G_OBJECT_CLASS (lunar_calendar_parent_class)->finalize(gobject);
}
コード例 #16
0
ファイル: colorsel.c プロジェクト: BYC/gtk
/* draw callback for the drawing area
 */
static gboolean
draw_callback (GtkWidget *widget,
               cairo_t   *cr,
               gpointer   data)
{
  GtkStyleContext *context;
  GdkRGBA *bg;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_get (context, 0, "background-color", &bg, NULL);
  gdk_cairo_set_source_rgba (cr, bg);
  cairo_paint (cr);
  gdk_rgba_free (bg);

  return TRUE;
}
コード例 #17
0
ファイル: biji-note-obj.c プロジェクト: Abdillah/bijiben
void
biji_note_obj_set_rgba (BijiNoteObj *n, GdkRGBA *rgba)
{
  if (!n->priv->color)
    biji_note_obj_set_rgba_internal (n, rgba);

  else if (!gdk_rgba_equal (n->priv->color,rgba))
  {
    gdk_rgba_free (n->priv->color);
    biji_note_obj_clear_icons (n);
    biji_note_obj_set_rgba_internal (n, rgba);

    biji_note_id_set_last_metadata_change_date (n->priv->id, g_get_real_time () / G_USEC_PER_SEC);
    biji_note_obj_save_note (n);
  }
}
コード例 #18
0
ファイル: theme.c プロジェクト: dnk/mate-notification-daemon
static void
get_background_color (GtkStyleContext *context,
                      GtkStateFlags    state,
                      GdkRGBA         *color)
{
    GdkRGBA *c;

    g_return_if_fail (color != NULL);
    g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));

    gtk_style_context_get (context,
                           state,
                           "background-color", &c,
                           NULL);
    *color = *c;
    gdk_rgba_free (c);
}
コード例 #19
0
ファイル: gnc-gtk-utils.c プロジェクト: Gnucash/gnucash
/** Wrapper to get the border color of a widget for a given state
 *
 *  @param context Style context of widget.
 *
 *  @param state The stateflag of the widget.
 *
 *  @param color The returned border color of the widget.
 */
void
gnc_style_context_get_border_color (GtkStyleContext *context,
                                    GtkStateFlags    state,
                                    GdkRGBA         *color)
{
    GdkRGBA *c;

    g_return_if_fail (color != NULL);
    g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));

    gtk_style_context_get (context,
                           state,
                           GTK_STYLE_PROPERTY_BORDER_COLOR, &c,
                           NULL);
    *color = *c;
    gdk_rgba_free (c);
}
コード例 #20
0
ファイル: xmrlabel.c プロジェクト: EmbolismSoil/xmradio
static void
xmr_label_finalize(GObject *object)
{
	XmrLabel *label = XMR_LABEL(object);
	XmrLabelPrivate *priv = label->priv;

	g_free(priv->text);

	if (priv->timeout_id != 0)
		g_source_remove(priv->timeout_id);

	if(priv->layout)
		g_object_unref(priv->layout);

	gdk_rgba_free(priv->current_color);

	G_OBJECT_CLASS(xmr_label_parent_class)->finalize(object);
}
コード例 #21
0
ファイル: zonesystem.c プロジェクト: AdamMajer/darktable
static gboolean dt_iop_zonesystem_preview_draw(GtkWidget *widget, cairo_t *crf, dt_iop_module_t *self)
{
  const int inset = DT_PIXEL_APPLY_DPI(2);
  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);
  int width = allocation.width, height = allocation.height;

  dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data;
  dt_iop_zonesystem_params_t *p = (dt_iop_zonesystem_params_t *)self->params;

  cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(cst);

  /* clear background */
  GtkStyleContext *context = gtk_widget_get_style_context(self->expander);
  gtk_render_background(context, cr, 0, 0, allocation.width, allocation.height);

  width -= 2 * inset;
  height -= 2 * inset;
  cairo_translate(cr, inset, inset);

  dt_pthread_mutex_lock(&g->lock);
  if(g->in_preview_buffer && g->out_preview_buffer && self->enabled)
  {
    /* calculate the zonemap */
    float zonemap[MAX_ZONE_SYSTEM_SIZE] = { -1 };
    _iop_zonesystem_calculate_zonemap(p, zonemap);

    /* let's generate a pixbuf from pixel zone buffer */
    guchar *image = g_malloc_n((size_t)4 * g->preview_width * g->preview_height, sizeof(guchar));
    guchar *buffer = g->mouse_over_output_zones ? g->out_preview_buffer : g->in_preview_buffer;
    for(int k = 0; k < g->preview_width * g->preview_height; k++)
    {
      int zone = 255 * CLIP(((1.0 / (p->size - 1)) * buffer[k]));
      image[4 * k + 2] = (g->hilite_zone && buffer[k] == g->zone_under_mouse) ? 255 : zone;
      image[4 * k + 1] = (g->hilite_zone && buffer[k] == g->zone_under_mouse) ? 255 : zone;
      image[4 * k + 0] = (g->hilite_zone && buffer[k] == g->zone_under_mouse) ? 0 : zone;
    }
    dt_pthread_mutex_unlock(&g->lock);

    const int wd = g->preview_width, ht = g->preview_height;
    const float scale = fminf(width / (float)wd, height / (float)ht);
    const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, wd);
    cairo_surface_t *surface = cairo_image_surface_create_for_data(image, CAIRO_FORMAT_RGB24, wd, ht, stride);
    cairo_translate(cr, width / 2.0, height / 2.0f);
    cairo_scale(cr, scale, scale);
    cairo_translate(cr, -.5f * wd, -.5f * ht);

    cairo_rectangle(cr, DT_PIXEL_APPLY_DPI(1), DT_PIXEL_APPLY_DPI(1), wd - DT_PIXEL_APPLY_DPI(2),
                    ht - DT_PIXEL_APPLY_DPI(2));
    cairo_set_source_surface(cr, surface, 0, 0);
    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);
    cairo_fill_preserve(cr);
    cairo_surface_destroy(surface);

    cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0));
    cairo_set_source_rgb(cr, .1, .1, .1);
    cairo_stroke(cr);

    g_free(image);
  }
  else
  {
    dt_pthread_mutex_unlock(&g->lock);
    // draw a big, subdued dt logo
    if(g->image)
    {
      GdkRGBA *color;
      gtk_style_context_get(context, gtk_widget_get_state_flags(self->expander), "background-color", &color,
                            NULL);

      cairo_set_source_surface(cr, g->image, (width - g->image_width) * 0.5, (height - g->image_height) * 0.5);
      cairo_rectangle(cr, 0, 0, width, height);
      cairo_set_operator(cr, CAIRO_OPERATOR_HSL_LUMINOSITY);
      cairo_fill_preserve(cr);
      cairo_set_operator(cr, CAIRO_OPERATOR_DARKEN);
      cairo_set_source_rgb(cr, color->red + 0.02, color->green + 0.02, color->blue + 0.02);
      cairo_fill_preserve(cr);
      cairo_set_operator(cr, CAIRO_OPERATOR_LIGHTEN);
      cairo_set_source_rgb(cr, color->red - 0.02, color->green - 0.02, color->blue - 0.02);
      cairo_fill(cr);

      gdk_rgba_free(color);
    }
  }

  cairo_destroy(cr);
  cairo_set_source_surface(crf, cst, 0, 0);
  cairo_paint(crf);
  cairo_surface_destroy(cst);

  return TRUE;
}
コード例 #22
0
/* This function is used by gtk_text_cell_accessible_get_offset_at_point()
 * and gtk_text_cell_accessible_get_character_extents(). There is no
 * cached PangoLayout so we must create a temporary one using this function.
 */
static PangoLayout *
create_pango_layout (GtkTextCellAccessible *text)
{
  GdkRGBA *foreground_rgba;
  PangoAttrList *attr_list, *attributes;
  PangoLayout *layout;
  PangoUnderline uline, underline;
  PangoFontMask mask;
  PangoFontDescription *font_desc;
  gboolean foreground_set, strikethrough_set, strikethrough;
  gboolean scale_set, underline_set, rise_set;
  gchar *renderer_text;
  gdouble scale;
  gint rise;
  GtkRendererCellAccessible *gail_renderer;
  GtkCellRendererText *gtk_renderer;

  gail_renderer = GTK_RENDERER_CELL_ACCESSIBLE (text);
  gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer);

  g_object_get (gtk_renderer,
                "text", &renderer_text,
                "attributes", &attributes,
                "foreground-set", &foreground_set,
                "foreground-rgba", &foreground_rgba,
                "strikethrough-set", &strikethrough_set,
                "strikethrough", &strikethrough,
                "font-desc", &font_desc,
                "scale-set", &scale_set,
                "scale", &scale,
                "underline-set", &underline_set,
                "underline", &underline,
                "rise-set", &rise_set,
                "rise", &rise,
                NULL);

  layout = gtk_widget_create_pango_layout (get_widget (text), renderer_text);

  if (attributes)
    attr_list = pango_attr_list_copy (attributes);
  else
    attr_list = pango_attr_list_new ();

  if (foreground_set)
    {
      add_attr (attr_list, pango_attr_foreground_new (foreground_rgba->red * 65535,
                                                      foreground_rgba->green * 65535,
                                                      foreground_rgba->blue * 65535));
    }

  if (strikethrough_set)
    add_attr (attr_list,
              pango_attr_strikethrough_new (strikethrough));

  mask = pango_font_description_get_set_fields (font_desc);

  if (mask & PANGO_FONT_MASK_FAMILY)
    add_attr (attr_list,
      pango_attr_family_new (pango_font_description_get_family (font_desc)));

  if (mask & PANGO_FONT_MASK_STYLE)
    add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (font_desc)));

  if (mask & PANGO_FONT_MASK_VARIANT)
    add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (font_desc)));

  if (mask & PANGO_FONT_MASK_WEIGHT)
    add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (font_desc)));

  if (mask & PANGO_FONT_MASK_STRETCH)
    add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (font_desc)));

  if (mask & PANGO_FONT_MASK_SIZE)
    add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (font_desc)));

  if (scale_set && scale != 1.0)
    add_attr (attr_list, pango_attr_scale_new (scale));

  if (underline_set)
    uline = underline;
  else
    uline = PANGO_UNDERLINE_NONE;

  if (uline != PANGO_UNDERLINE_NONE)
    add_attr (attr_list,
              pango_attr_underline_new (underline));

  if (rise_set)
    add_attr (attr_list, pango_attr_rise_new (rise));

  pango_layout_set_attributes (layout, attr_list);
  pango_layout_set_width (layout, -1);
  pango_attr_list_unref (attr_list);

  pango_font_description_free (font_desc);
  pango_attr_list_unref (attributes);
  g_free (renderer_text);
  gdk_rgba_free (foreground_rgba);

  return layout;
}
コード例 #23
0
ファイル: dialog-sheet-order.c プロジェクト: GNOME/gnumeric
static void
dialog_sheet_order_update_sheet_order (SheetManager *state)
{
	GtkTreeIter iter;
	Workbook *wb = wb_control_get_workbook (GNM_WBC (state->wbcg));
	int i, n_sheets, n_children;
	GtkTreeModel *model = GTK_TREE_MODEL (state->model);
	GtkTreeSelection *sel = gtk_tree_view_get_selection (state->sheet_list);

	n_sheets = workbook_sheet_count (wb);
	n_children = gtk_tree_model_iter_n_children (model, NULL);

	if (n_sheets != n_children) {
	  /* This signal also occurs when sheets are added or deleted. We handle this */
	  /* when those signals arrive.                                               */
	  return;
	}

	for (i = 0; i < n_sheets; i++) {
		gchar *name, *new_name;
		gboolean is_locked;
		gboolean is_visible;
		gboolean is_rtl;
		GdkRGBA *back, *fore;
		Sheet *sheet_wb = workbook_sheet_by_index (wb, i);
		Sheet *sheet_model;
		gboolean selected;
		int j, row_max, col_max;

		for (j = i; j < n_children; j++) {
			if (!gtk_tree_model_iter_nth_child (model, &iter,
							    NULL, j))
				break;
			gtk_tree_model_get (model, &iter, SHEET_POINTER,
					    &sheet_model, -1);
			if (sheet_model == sheet_wb)
				break;
		}
		if (j == i)
			continue;

		if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, j))
			break;
		selected = gtk_tree_selection_iter_is_selected (sel, &iter);
		gtk_tree_model_get (model, &iter,
				    SHEET_LOCKED, &is_locked,
				    SHEET_VISIBLE, &is_visible,
				    SHEET_ROW_MAX, &row_max,
				    SHEET_COL_MAX, &col_max,
				    SHEET_NAME, &name,
				    SHEET_NEW_NAME, &new_name,
				    SHEET_POINTER, &sheet_model,
				    BACKGROUND_COLOUR, &back,
				    FOREGROUND_COLOUR, &fore,
				    SHEET_DIRECTION, &is_rtl,
				    -1);
		gtk_list_store_remove (state->model, &iter);
		g_signal_handler_block (state->model, state->model_row_insertion_listener);
		gtk_list_store_insert (state->model, &iter, i);
		g_signal_handler_unblock (state->model, state->model_row_insertion_listener);
		gtk_list_store_set (state->model, &iter,
				    SHEET_LOCKED, is_locked,
				    SHEET_LOCK_IMAGE, is_locked ?
				    state->image_padlock : state->image_padlock_no,
				    SHEET_VISIBLE, is_visible,
				    SHEET_VISIBLE_IMAGE, is_visible ?
				    state->image_visible : NULL,
				    SHEET_ROW_MAX, row_max,
				    SHEET_COL_MAX, col_max,
				    SHEET_NAME, name,
				    SHEET_NEW_NAME, new_name,
				    SHEET_POINTER, sheet_model,
				    BACKGROUND_COLOUR, back,
				    FOREGROUND_COLOUR, fore,
				    SHEET_DIRECTION, is_rtl,
				    SHEET_DIRECTION_IMAGE,
					    is_rtl ? state->image_rtl : state->image_ltr,
				    -1);
		if (back)
			gdk_rgba_free (back);
		if (fore)
			gdk_rgba_free (fore);
		g_free (name);
		g_free (new_name);
		if (selected)
			gtk_tree_selection_select_iter (sel, &iter);
	}

	cb_selection_changed (NULL, state);
}
コード例 #24
0
void XAP_UnixDialog_FontChooser::runModal(XAP_Frame * pFrame)
{
	m_pFrame = static_cast<XAP_Frame *>(pFrame);

	// used similarly to convert between text and numeric arguments
	static char sizeString[50];

	// build the dialog
	GtkWidget * cf = constructWindow();

	// freeze updates of the preview
	m_blockUpdate = true;

	// to sort out dupes
    std::set<std::string> fontSet;

	GtkTreeModel* model;
	GtkTreeIter iter;

	model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_fontList));
	gtk_list_store_clear(GTK_LIST_STORE(model));

	GR_GraphicsFactory * pGF = XAP_App::getApp()->getGraphicsFactory();
	if(!pGF)
	{
		return;
	}

	const std::vector<std::string> & names = GR_CairoGraphics::getAllFontNames();
	
	for (std::vector<std::string>::const_iterator  i = names.begin();
		 i != names.end(); ++i)
	{
		const std::string & fName = *i;
			
		if (fontSet.find(fName) == fontSet.end())
		{
            fontSet.insert(fName);

		    gtk_list_store_append(GTK_LIST_STORE(model), &iter);
		    gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, 
                               fName.c_str(), -1);
		    
		  }
	}

	// Set the defaults in the list boxes according to dialog data
	gint foundAt = 0;

	const std::string sFontFamily = getVal("font-family");
	foundAt = searchTreeView(GTK_TREE_VIEW(m_fontList), sFontFamily.c_str());

	// select and scroll to font name
	if (foundAt >= 0) {
		GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1);
		gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_fontList), path, NULL, FALSE);
		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_fontList), path, NULL, TRUE, 0.5 , 0.0);
		gtk_tree_path_free(path);
	}

	// this is pretty messy
	listStyle st = LIST_STYLE_NORMAL;
	const std::string sWeight = getVal("font-weight");
	const std::string sStyle = getVal("font-style");
	if (sStyle.empty() || sWeight.empty())
		st = LIST_STYLE_NONE;
	else {
		bool isBold = !g_ascii_strcasecmp(sWeight.c_str(), "bold");
		bool isItalic = !g_ascii_strcasecmp(sStyle.c_str(), "italic");
		if (!isBold && !isItalic) {
			st = LIST_STYLE_NORMAL;
		}
		else if (!isItalic && isBold) {
			st = LIST_STYLE_BOLD;
		}
		else if (isItalic && !isBold) {
			st = LIST_STYLE_ITALIC;
		}
		else if (isItalic && isBold) {
			st = LIST_STYLE_BOLD_ITALIC;
		}
		else {
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
		}
	}

	// select and scroll to style name
	if (st != LIST_STYLE_NONE) {
		GtkTreePath* path = gtk_tree_path_new_from_indices(st, -1);
		gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_styleList), path, NULL, FALSE);
		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_styleList), path, NULL, TRUE, 0.5 , 0.0);
		gtk_tree_path_free(path);
	}

	g_snprintf(sizeString, 60, "%s", std_size_string(UT_convertToPoints(getVal("font-size").c_str())));
	foundAt = searchTreeView(GTK_TREE_VIEW(m_sizeList), 
				 XAP_EncodingManager::fontsizes_mapping.lookupBySource(sizeString));

	// select and scroll to size name
	if (foundAt >= 0) {
		GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1);
		gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_sizeList), path, NULL, FALSE);
		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_sizeList), path, NULL, TRUE, 0.5 , 0.0);
		gtk_tree_path_free(path);	
	}

	// Set color in the color selector
	const std::string sColor = getVal("color");
	if (!sColor.empty())
	{
		UT_RGBColor c;
		UT_parseColor(sColor.c_str(), c);

		GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c);
		m_currentFGColor = *color;
		gdk_rgba_free(color);
		gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_currentFGColor);
	}
	else
	{
		// if we have no color, use a placeholder of funky values
		// the user can't pick interactively.  This catches ALL
		// the cases except where the user specifically enters -1 for
		// all Red, Green and Blue attributes manually.  This user
		// should expect it not to touch the color.  :)
		gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_funkyColor);
	}

	// Set color in the color selector
	const std::string sBGCol = getVal("bgcolor");
	if (!sBGCol.empty() && strcmp(sBGCol.c_str(),"transparent") != 0)
	{
		UT_RGBColor c;
		UT_parseColor(sBGCol.c_str(), c);

		GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c);
		m_currentBGColor = *color;
		gdk_rgba_free(color);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), FALSE);
		gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_bgcolorSelector), &m_currentBGColor);
	}
	else
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), TRUE);

	// fix for GTK's questionable gtk_toggle_set_active behaviour (emits when setting TRUE)
	m_bChangedStrikeOut = m_bStrikeout;
	m_bChangedUnderline = m_bUnderline;
	m_bChangedOverline = m_bOverline;
	m_bChangedHidden = m_bHidden;
	m_bChangedSubScript = m_bSubScript;
	m_bChangedSuperScript = m_bSuperScript;

	// set the strikeout, underline, overline, and hidden check buttons
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkStrikeOut), m_bStrikeout);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkUnderline), m_bUnderline);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkOverline), m_bOverline);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkHidden), m_bHidden);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSubScript), m_bSubScript);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSuperScript), m_bSuperScript);

	m_doneFirstFont = true;

	// attach a new graphics context
	gtk_widget_show ( cf ) ;
	
	GR_UnixCairoAllocInfo ai(m_preview);
	m_gc = (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai);
	GtkAllocation alloc;

	gtk_widget_get_allocation(m_preview, &alloc);
	_createFontPreviewFromGC(m_gc,alloc.width,alloc.height);
//
// This enables callbacks on the preview area with a widget pointer to
// access this dialog.
//
	g_object_set_data(G_OBJECT(m_preview), "user-data", this);

	// unfreeze updates of the preview
	m_blockUpdate = false;
	// manually trigger an update
	updatePreview();


	switch ( abiRunModalDialog ( GTK_DIALOG(cf), pFrame, this, BUTTON_CANCEL, true ) )
	  {
	  case BUTTON_OK:
	    {
	      m_answer = a_OK;
	      break ;
	    }
	  default:
	    {
	      m_answer = a_CANCEL;
	      break;
	    }
	  }

	// these dialogs are cached around through the dialog framework,
	// and this variable needs to get set back
	m_doneFirstFont = false;

	UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s] SubScript[%d%s] SuperScript[%d%s]\n",
				 getVal("font-family").c_str(),			((m_bChangedFontFamily) ? "(chg)" : ""),
				 getVal("font-size").c_str(),			((m_bChangedFontSize) ? "(chg)" : ""),
				 getVal("font-weight").c_str(),			((m_bChangedFontWeight) ? "(chg)" : ""),
				 getVal("font-style").c_str(),			((m_bChangedFontStyle) ? "(chg)" : ""),
				 getVal("color").c_str(),				((m_bChangedColor) ? "(chg)" : ""),
				 m_bUnderline,							((m_bChangedUnderline) ? "(chg)" : ""),
				 m_bStrikeout,							((m_bChangedStrikeOut) ? "(chg)" : ""),
				 m_bSubScript,							((m_bChangedSubScript) ? "(chg)" : ""),
				 m_bSuperScript,						((m_bChangedSuperScript) ? "(chg)" : "")
	            ));

	// answer should be set by the appropriate callback
	// the caller can get the answer from getAnswer().

	m_pFrame = NULL;
}
コード例 #25
0
ファイル: gtktextattributes.c プロジェクト: Pfiver/gtk
void
_gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
                                     GtkTextTag**       tags,
                                     guint              n_tags)
{
  guint n = 0;

  guint left_margin_accumulative = 0;
  guint right_margin_accumulative = 0;

  while (n < n_tags)
    {
      GtkTextTag *tag = tags[n];
      GtkTextAttributes *vals = tag->priv->values;

      g_assert (tag->priv->table != NULL);
      if (n > 0)
        g_assert (tags[n]->priv->priority > tags[n-1]->priv->priority);

      if (tag->priv->bg_color_set)
        {
	  if (dest->appearance.rgba[0])
	    {
	      gdk_rgba_free (dest->appearance.rgba[0]);
	      dest->appearance.rgba[0] = NULL;
	    }

	  if (vals->appearance.rgba[0])
	    dest->appearance.rgba[0] = gdk_rgba_copy (vals->appearance.rgba[0]);

          dest->appearance.draw_bg = TRUE;
        }

      if (tag->priv->fg_color_set)
	{
	  if (dest->appearance.rgba[1])
	    {
	      gdk_rgba_free (dest->appearance.rgba[1]);
	      dest->appearance.rgba[1] = NULL;
	    }

	  if (vals->appearance.rgba[1])
	    dest->appearance.rgba[1] = gdk_rgba_copy (vals->appearance.rgba[1]);
	}

      if (tag->priv->pg_bg_color_set)
        {
	  if (dest->pg_bg_rgba)
	    {
	      gdk_rgba_free (dest->pg_bg_rgba);
	      dest->pg_bg_rgba = NULL;
	    }

	  if (dest->pg_bg_color)
	    {
	      gdk_color_free (dest->pg_bg_color);
	      dest->pg_bg_color = NULL;
	    }

	  if (vals->pg_bg_rgba)
	    dest->pg_bg_rgba = gdk_rgba_copy (vals->pg_bg_rgba);

	  if (vals->pg_bg_color)
	    dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
        }

      if (vals->font)
	{
	  if (dest->font)
	    pango_font_description_merge (dest->font, vals->font, TRUE);
	  else
	    dest->font = pango_font_description_copy (vals->font);
	}

      /* multiply all the scales together to get a composite */
      if (tag->priv->scale_set)
        dest->font_scale *= vals->font_scale;

      if (tag->priv->justification_set)
        dest->justification = vals->justification;

      if (vals->direction != GTK_TEXT_DIR_NONE)
        dest->direction = vals->direction;

      if (tag->priv->left_margin_set)
        {
          if (tag->priv->accumulative_margin)
            left_margin_accumulative += vals->left_margin;
          else
            dest->left_margin = vals->left_margin;
        }

      if (tag->priv->indent_set)
        dest->indent = vals->indent;

      if (tag->priv->rise_set)
        dest->appearance.rise = vals->appearance.rise;

      if (tag->priv->right_margin_set)
        {
          if (tag->priv->accumulative_margin)
            right_margin_accumulative += vals->right_margin;
          else
            dest->right_margin = vals->right_margin;
        }

      if (tag->priv->pixels_above_lines_set)
        dest->pixels_above_lines = vals->pixels_above_lines;

      if (tag->priv->pixels_below_lines_set)
        dest->pixels_below_lines = vals->pixels_below_lines;

      if (tag->priv->pixels_inside_wrap_set)
        dest->pixels_inside_wrap = vals->pixels_inside_wrap;

      if (tag->priv->tabs_set)
        {
          if (dest->tabs)
            pango_tab_array_free (dest->tabs);
          dest->tabs = pango_tab_array_copy (vals->tabs);
        }

      if (tag->priv->wrap_mode_set)
        dest->wrap_mode = vals->wrap_mode;

      if (tag->priv->underline_set)
        dest->appearance.underline = vals->appearance.underline;

      if (tag->priv->strikethrough_set)
        dest->appearance.strikethrough = vals->appearance.strikethrough;

      if (tag->priv->invisible_set)
        dest->invisible = vals->invisible;

      if (tag->priv->editable_set)
        dest->editable = vals->editable;

      if (tag->priv->bg_full_height_set)
        dest->bg_full_height = vals->bg_full_height;

      if (tag->priv->language_set)
	dest->language = vals->language;

      ++n;
    }

  dest->left_margin += left_margin_accumulative;
  dest->right_margin += right_margin_accumulative;
}
コード例 #26
0
ファイル: gailmisc.c プロジェクト: 3dfxmadscientist/gtk
/**
 * gail_misc_buffer_get_run_attributes:
 * @buffer: The #GtkTextBuffer for which the attributes will be obtained
 * @offset: The offset at which the attributes are required
 * @start_offset: The start offset of the current run
 * @end_offset: The end offset of the current run
 *
 * Creates an AtkAttributeSet which contains the attributes for the 
 * run starting at offset.
 *
 * Returns: A pointer to the #AtkAttributeSet.
 **/
AtkAttributeSet*
gail_misc_buffer_get_run_attributes (GtkTextBuffer *buffer,
                                     gint          offset,
                                     gint	    *start_offset,
                                     gint          *end_offset)
{
  GtkTextIter iter;
  AtkAttributeSet *attrib_set = NULL;
  AtkAttribute *at;
  GSList *tags, *temp_tags;
  gdouble scale = 1;
  gboolean val_set = FALSE;

  gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);

  gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
  *end_offset = gtk_text_iter_get_offset (&iter);

  gtk_text_iter_backward_to_tag_toggle (&iter, NULL);
  *start_offset = gtk_text_iter_get_offset (&iter);

  gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);

  tags = gtk_text_iter_get_tags (&iter);
  tags = g_slist_reverse (tags);

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "style-set", &val_set, NULL);
      if (val_set)
        {
          PangoStyle style;
          gchar *value;

          g_object_get (tag, "style", &style, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STYLE, style));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STYLE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "variant-set", &val_set, NULL);
      if (val_set)
        {
          PangoVariant variant;
          gchar *value;

          g_object_get (tag, "variant", &variant, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_VARIANT, variant));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_VARIANT, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "stretch-set", &val_set, NULL);
      if (val_set)
        {
          PangoStretch stretch;
          gchar *value;

          g_object_get (tag, "stretch", &stretch, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRETCH, stretch));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRETCH, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "justification-set", &val_set, NULL);
      if (val_set)
        {
          GtkJustification justification;
          gchar *value;

          g_object_get (tag, "justification", &justification, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_JUSTIFICATION, justification));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_JUSTIFICATION, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
      GtkTextDirection direction;

      g_object_get (tag, "direction", &direction, NULL);

      if (direction != GTK_TEXT_DIR_NONE)
        {
          gchar *value;
          val_set = TRUE;
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, direction));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_DIRECTION, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "wrap-mode-set", &val_set, NULL);
      if (val_set)
        {
          GtkWrapMode wrap_mode;
          gchar *value;

          g_object_get (tag, "wrap-mode", &wrap_mode, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_WRAP_MODE, wrap_mode));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WRAP_MODE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "foreground-set", &val_set, NULL);
      if (val_set)
        {
          GdkRGBA *rgba;
          gchar *value;

          g_object_get (tag, "foreground-rgba", &rgba, NULL);
          value = g_strdup_printf ("%u,%u,%u",
                                   (guint) rgba->red * 65535,
                                   (guint) rgba->green * 65535,
                                   (guint) rgba->blue * 65535);
          gdk_rgba_free (rgba);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_COLOR, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "background-set", &val_set, NULL);
      if (val_set)
        {
          GdkRGBA *rgba;
          gchar *value;

          g_object_get (tag, "background-rgba", &rgba, NULL);
          value = g_strdup_printf ("%u,%u,%u",
                                   (guint) rgba->red * 65535,
                                   (guint) rgba->green * 65535,
                                   (guint) rgba->blue * 65535);
          gdk_rgba_free (rgba);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_COLOR, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "family-set", &val_set, NULL);

      if (val_set)
        {
          gchar *value;
          g_object_get (tag, "family", &value, NULL);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FAMILY_NAME, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "language-set", &val_set, NULL);

      if (val_set)
        {
          gchar *value;
          g_object_get (tag, "language", &value, NULL);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LANGUAGE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "weight-set", &val_set, NULL);

      if (val_set)
        {
          gint weight;
          gchar *value;

          g_object_get (tag, "weight", &weight, NULL);
          value = g_strdup_printf ("%d", weight);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WEIGHT, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;


  /*
   * scale is special as the scale is the product of all scale values
   * specified.
   */
  temp_tags = tags;
  while (temp_tags)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
      gboolean scale_set;

      g_object_get (tag, "scale-set", &scale_set, NULL);
      if (scale_set)
        {
          gdouble font_scale;

          g_object_get (tag, "scale", &font_scale, NULL);
          val_set = TRUE;
          scale *= font_scale;
        }
      temp_tags = temp_tags->next;
    }
  if (val_set)
    {
      at = g_malloc(sizeof(AtkAttribute));
      at->name = g_strdup(atk_text_attribute_get_name (ATK_TEXT_ATTR_SCALE));
      at->value = g_strdup_printf("%g", scale);
      attrib_set = g_slist_prepend(attrib_set, at);
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "size-set", &val_set, NULL);
      if (val_set)
        {
          gint size;
          gchar *value;
          g_object_get (tag, "size", &size, NULL);
          value = g_strdup_printf ("%i", size);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SIZE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "strikethrough-set", &val_set, NULL);
      if (val_set)
        {
          gboolean strikethrough;
          gchar *value;
          g_object_get (tag, "strikethrough", &strikethrough, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRIKETHROUGH, strikethrough));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRIKETHROUGH, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "underline-set", &val_set, NULL);
      if (val_set)
        {
          PangoUnderline underline;
          gchar *value;
          g_object_get (tag, "underline", &underline, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_UNDERLINE, underline));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_UNDERLINE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "rise-set", &val_set, NULL);
      if (val_set)
        {
          gint rise;
          gchar *value;
          g_object_get (tag, "rise", &rise, NULL);
          value = g_strdup_printf ("%i", rise);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RISE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "background-full-height-set", &val_set, NULL);
      if (val_set)
        {
          gboolean bg_full_height;
          gchar *value;
          g_object_get (tag, "background-full-height", &bg_full_height, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_BG_FULL_HEIGHT, bg_full_height));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_FULL_HEIGHT, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "pixels-inside-wrap-set", &val_set, NULL);
      if (val_set)
        {
          gint pixels;
          gchar *value;
          g_object_get (tag, "pixels-inside-wrap", &pixels, NULL);
          value = g_strdup_printf ("%i", pixels);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "pixels-below-lines-set", &val_set, NULL);
      if (val_set)
        {
          gint pixels;
          gchar *value;
          g_object_get (tag, "pixels-below-lines", &pixels, NULL);
          value = g_strdup_printf ("%i", pixels);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_BELOW_LINES, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "pixels-above-lines-set", &val_set, NULL);
      if (val_set)
        {
          gint pixels;
          gchar *value;
          g_object_get (tag, "pixels-above-lines", &pixels, NULL);
          value = g_strdup_printf ("%i", pixels);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_ABOVE_LINES, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "editable-set", &val_set, NULL);
      if (val_set)
        {
          gboolean editable;
          gchar *value;
          g_object_get (tag, "editable", &editable, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_EDITABLE, editable));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_EDITABLE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "invisible-set", &val_set, NULL);
      if (val_set)
        {
          gboolean invisible;
          gchar *value;
          g_object_get (tag, "invisible", &invisible, NULL);
          value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_INVISIBLE, invisible));
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INVISIBLE, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "indent-set", &val_set, NULL);
      if (val_set)
        {
          gint indent;
          gchar *value;
          g_object_get (tag, "indent", &indent, NULL);
          value = g_strdup_printf ("%i", indent);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INDENT, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "right-margin-set", &val_set, NULL);
      if (val_set)
        {
          gint margin;
          gchar *value;
          g_object_get (tag, "right-margin", &margin, NULL);
          value = g_strdup_printf ("%i", margin);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RIGHT_MARGIN, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  temp_tags = tags;
  while (temp_tags && !val_set)
    {
      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);

      g_object_get (tag, "left-margin-set", &val_set, NULL);
      if (val_set)
        {
          gint margin;
          gchar *value;
          g_object_get (tag, "left-margin", &margin, NULL);
          value = g_strdup_printf ("%i", margin);
          attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LEFT_MARGIN, value);
        }
      temp_tags = temp_tags->next;
    }
  val_set = FALSE;

  g_slist_free (tags);
  return attrib_set;
}
コード例 #27
0
static void
save_filter_foreach_func (gpointer key, gpointer value, gpointer user_data)
{
  GPtrArray *filters;
  const gchar *name;
  LogviewFilter *filter;
  GdkRGBA  *foreground;
  gboolean foreground_set;
  GdkRGBA  *background;
  gboolean background_set;
  gchar *regex, *color;
  gboolean invisible;
  GtkTextTag *tag;
  GString *prefs_string;

  filters = user_data;
  filter = LOGVIEW_FILTER (value);
  name = key;
  color = NULL;

  prefs_string = g_string_new (name);
  g_string_append (prefs_string, DELIMITER);

  g_object_get (filter,
                "regex", &regex,
                "texttag", &tag,
                NULL);
  g_object_get (tag,
                "foreground-set", &foreground_set,
                "foreground-rgba", &foreground,
                "paragraph-background-set", &background_set,
                "paragraph-background-rgba", &background,
                "invisible", &invisible, NULL);

  if (invisible) {
    g_string_append (prefs_string, "1" DELIMITER);
  } else {
    g_string_append (prefs_string, "0" DELIMITER);
  }

  if (foreground_set) {
    color = gdk_rgba_to_string (foreground);
    g_string_append (prefs_string, color);
    g_free (color);
  }

  if (foreground) {
    gdk_rgba_free (foreground);
  }

  g_string_append (prefs_string, DELIMITER);

  if (background_set) {
    color = gdk_rgba_to_string (background);
    g_string_append (prefs_string, color);
    g_free (color);
  }

  if (background) {
    gdk_rgba_free (background);
  }

  g_string_append (prefs_string, DELIMITER);
  g_string_append (prefs_string, regex);

  g_free (regex);
  g_object_unref (tag);
  
  g_ptr_array_add (filters, g_string_free (prefs_string, FALSE));
}
コード例 #28
0
ファイル: dialog-sheet-order.c プロジェクト: GNOME/gnumeric
/*
 * Refreshes the buttons on a row (un)selection and selects the chosen sheet
 * for this view.
 */
static void
cb_selection_changed (G_GNUC_UNUSED GtkTreeSelection *ignored,
		      SheetManager *state)
{
	GtkTreeIter  iter;
	Sheet *sheet;
	gboolean has_iter;
	GdkRGBA *fore, *back;
	GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list);
	GList *selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
	gboolean multiple = gtk_tree_model_iter_n_children(GTK_TREE_MODEL (state->model), NULL) > 1;
	int cnt_sel = g_list_length (selected_rows);
	gboolean single_sel = (cnt_sel < 2);

	gtk_widget_set_sensitive (state->sort_asc_btn, multiple);
	gtk_widget_set_sensitive (state->sort_desc_btn, multiple);

	if (selected_rows == NULL) {
		gtk_widget_set_sensitive (state->up_btn, FALSE);
		gtk_widget_set_sensitive (state->down_btn, FALSE);
		gtk_widget_set_sensitive (state->delete_btn, FALSE);
		gtk_widget_set_sensitive (state->ccombo_back, FALSE);
		gtk_widget_set_sensitive (state->ccombo_fore, FALSE);
		gtk_widget_set_sensitive (state->add_btn, FALSE);
		gtk_widget_set_sensitive (state->duplicate_btn, FALSE);
		return;
	}

	gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model),
				 &iter, (GtkTreePath *) selected_rows->data);

	gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
			    SHEET_POINTER, &sheet,
			    BACKGROUND_COLOUR, &back,
			    FOREGROUND_COLOUR, &fore,
			    -1);
	if (!state->initial_colors_set) {
		go_combo_color_set_color_gdk (GO_COMBO_COLOR (state->ccombo_back), back);
		go_combo_color_set_color_gdk (GO_COMBO_COLOR (state->ccombo_fore), fore);
		state->initial_colors_set = TRUE;
	}
	if (back != NULL)
		gdk_rgba_free (back);
	if (fore != NULL)
		gdk_rgba_free (fore);

	gtk_widget_set_sensitive (state->ccombo_back, TRUE);
	gtk_widget_set_sensitive (state->ccombo_fore, TRUE);
	gtk_widget_set_sensitive (state->delete_btn, sheet_order_cnt_visible (state) > cnt_sel);
	gtk_widget_set_sensitive (state->add_btn, single_sel);
	gtk_widget_set_sensitive (state->duplicate_btn, single_sel);

	has_iter = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (state->model), &iter);
	g_return_if_fail (has_iter);
	gtk_widget_set_sensitive (state->up_btn,
				  single_sel &&
				  !gtk_tree_selection_iter_is_selected (selection, &iter));
	gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model), &iter, NULL,
				       gtk_tree_model_iter_n_children
				       (GTK_TREE_MODEL (state->model), NULL) - 1);
	gtk_widget_set_sensitive (state->down_btn,
				  single_sel &&
				  !gtk_tree_selection_iter_is_selected (selection, &iter));

	if (sheet != NULL)
		wb_view_sheet_focus (
			wb_control_view (GNM_WBC (state->wbcg)), sheet);

	g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
}
コード例 #29
0
ファイル: control.cpp プロジェクト: Jiang0Ke/wxWidgets
// static
wxVisualAttributes
wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
                                             bool WXUNUSED_IN_GTK3(useBase),
                                             int state)
{
    wxVisualAttributes attr;

    GtkWidget* tlw = NULL;
    if (gtk_widget_get_parent(widget) == NULL)
    {
        tlw = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_add(GTK_CONTAINER(tlw), widget);
    }

#ifdef __WXGTK3__
    GtkStateFlags stateFlag = GTK_STATE_FLAG_NORMAL;
    if (state)
    {
        wxASSERT(state == GTK_STATE_ACTIVE);
        stateFlag = GTK_STATE_FLAG_ACTIVE;
    }
    GtkStyleContext* sc = gtk_widget_get_style_context(widget);
    GdkRGBA *fc, *bc;
    wxNativeFontInfo info;
    gtk_style_context_get(sc, stateFlag,
        "color", &fc, "background-color", &bc,
        GTK_STYLE_PROPERTY_FONT, &info.description, NULL);
    attr.colFg = wxColour(*fc);
    attr.colBg = wxColour(*bc);
    attr.font = wxFont(info);
    gdk_rgba_free(fc);
    gdk_rgba_free(bc);
#else
    GtkStyle* style;

    style = gtk_rc_get_style(widget);
    if (!style)
        style = gtk_widget_get_default_style();

    if (style)
    {
        // get the style's colours
        attr.colFg = wxColour(style->fg[state]);
        if (useBase)
            attr.colBg = wxColour(style->base[state]);
        else
            attr.colBg = wxColour(style->bg[state]);

        // get the style's font
        if (!style->font_desc)
            style = gtk_widget_get_default_style();
        if (style && style->font_desc)
        {
            wxNativeFontInfo info;
            info.description = style->font_desc;
            attr.font = wxFont(info);
            info.description = NULL;
        }
    }
    else
        attr = wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL);
#endif

    if (!attr.font.IsOk())
    {
        GtkSettings *settings = gtk_settings_get_default();
        gchar *font_name = NULL;
        g_object_get ( settings,
                       "gtk-font-name",
                       &font_name,
                       NULL);
        if (!font_name)
            attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
        else
        {
            attr.font = wxFont(wxString::FromUTF8(font_name));
            g_free(font_name);
        }
    }

    if (tlw)
        gtk_widget_destroy(tlw);

    return attr;
}
コード例 #30
0
ファイル: gtknumerableicon.c プロジェクト: BoozzyAmdJin/gtk-
static void
gtk_numerable_icon_update_properties_from_style (GtkNumerableIcon *self)
{
  GtkStyleContext *style = self->priv->style;
  GtkWidgetPath *path, *saved;
  cairo_pattern_t *pattern = NULL;
  GdkRGBA background, foreground;
  PangoFontDescription *font = NULL;

  /* save an unmodified copy of the original widget path, in order
   * to restore it later */
  path = gtk_widget_path_copy (gtk_style_context_get_path (style));
  saved = gtk_widget_path_copy (path);

  if (!gtk_widget_path_is_type (path, GTK_TYPE_NUMERABLE_ICON))
    {
      /* append our GType to the style context to fetch appropriate colors */
      gtk_widget_path_append_type (path, GTK_TYPE_NUMERABLE_ICON);
      gtk_style_context_set_path (style, path);
    }

  gtk_style_context_get_background_color (style, gtk_style_context_get_state (style),
                                          &background);
  gtk_style_context_get_color (style, gtk_style_context_get_state (style),
                               &foreground);

  if (self->priv->background != NULL)
    gdk_rgba_free (self->priv->background);

  self->priv->background = gdk_rgba_copy (&background);

  if (self->priv->foreground != NULL)
    gdk_rgba_free (self->priv->foreground);

  self->priv->foreground = gdk_rgba_copy (&foreground);

  gtk_style_context_get (style, gtk_style_context_get_state (style),
                         GTK_STYLE_PROPERTY_BACKGROUND_IMAGE, &pattern,
                         NULL);

  if (pattern != NULL)
    {
      if (self->priv->background_image != NULL)
        cairo_pattern_destroy (self->priv->background_image);

      self->priv->background_image = pattern;
    }

  gtk_style_context_get (style, gtk_style_context_get_state (style),
                         GTK_STYLE_PROPERTY_FONT, &font,
                         NULL);

  if (font != NULL)
    {
      if (self->priv->font != NULL)
        pango_font_description_free (self->priv->font);

      self->priv->font = font;
    }

  gtk_numerable_icon_ensure_emblem (self);

  /* restore original widget path */
  gtk_style_context_set_path (style, saved);

  gtk_widget_path_free (path);
  gtk_widget_path_free (saved);
}