Use accessor functions to access GtkCellRendererText

This commit is contained in:
Javier Jardón 2010-06-01 21:01:33 +02:00
parent b71d539fd0
commit 6736c085b3
4 changed files with 121 additions and 46 deletions

View File

@ -585,6 +585,7 @@ gtk_cell_renderer_accel_start_editing (GtkCellRenderer *cell,
GtkWidget *label; GtkWidget *label;
GtkWidget *eventbox; GtkWidget *eventbox;
GdkDevice *device, *keyb, *pointer; GdkDevice *device, *keyb, *pointer;
gboolean editable;
guint32 time; guint32 time;
celltext = GTK_CELL_RENDERER_TEXT (cell); celltext = GTK_CELL_RENDERER_TEXT (cell);
@ -592,7 +593,8 @@ gtk_cell_renderer_accel_start_editing (GtkCellRenderer *cell,
priv = accel->priv; priv = accel->priv;
/* If the cell isn't editable we return NULL. */ /* If the cell isn't editable we return NULL. */
if (celltext->editable == FALSE) g_object_get (celltext, "editable", &editable, NULL);
if (editable == FALSE)
return NULL; return NULL;
g_return_val_if_fail (widget->window != NULL, NULL); g_return_val_if_fail (widget->window != NULL, NULL);

View File

@ -399,18 +399,21 @@ find_text (GtkTreeModel *model,
{ {
GtkCellRendererComboPriv *priv; GtkCellRendererComboPriv *priv;
SearchData *search_data = (SearchData *)data; SearchData *search_data = (SearchData *)data;
gchar *text; gchar *text, *cell_text;
priv = search_data->cell->priv; priv = search_data->cell->priv;
gtk_tree_model_get (model, iter, priv->text_column, &text, -1); gtk_tree_model_get (model, iter, priv->text_column, &text, -1);
if (text && GTK_CELL_RENDERER_TEXT (search_data->cell)->text && g_object_get (GTK_CELL_RENDERER_TEXT (search_data->cell),
strcmp (text, GTK_CELL_RENDERER_TEXT (search_data->cell)->text) == 0) "text", &cell_text,
NULL);
if (text && cell_text && g_strcmp0 (text, cell_text) == 0)
{ {
search_data->iter = *iter; search_data->iter = *iter;
search_data->found = TRUE; search_data->found = TRUE;
} }
g_free (cell_text);
g_free (text); g_free (text);
return search_data->found; return search_data->found;
@ -430,9 +433,12 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
GtkWidget *combo; GtkWidget *combo;
SearchData search_data; SearchData search_data;
GtkCellRendererComboPriv *priv; GtkCellRendererComboPriv *priv;
gboolean editable;
gchar *text;
cell_text = GTK_CELL_RENDERER_TEXT (cell); cell_text = GTK_CELL_RENDERER_TEXT (cell);
if (cell_text->editable == FALSE) g_object_get (cell_text, "editable", &editable, NULL);
if (editable == FALSE)
return NULL; return NULL;
cell_combo = GTK_CELL_RENDERER_COMBO (cell); cell_combo = GTK_CELL_RENDERER_COMBO (cell);
@ -450,9 +456,11 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo), gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo),
priv->text_column); priv->text_column);
if (cell_text->text) g_object_get (cell_text, "text", &text, NULL);
if (text)
gtk_entry_set_text (GTK_ENTRY (GTK_BIN (combo)->child), gtk_entry_set_text (GTK_ENTRY (GTK_BIN (combo)->child),
cell_text->text); text);
g_free (text);
} }
else else
{ {

View File

@ -301,11 +301,14 @@ gtk_cell_renderer_spin_start_editing (GtkCellRenderer *cell,
GtkCellRendererSpinPrivate *priv; GtkCellRendererSpinPrivate *priv;
GtkCellRendererText *cell_text; GtkCellRendererText *cell_text;
GtkWidget *spin; GtkWidget *spin;
gboolean editable;
gchar *text;
cell_text = GTK_CELL_RENDERER_TEXT (cell); cell_text = GTK_CELL_RENDERER_TEXT (cell);
priv = GTK_CELL_RENDERER_SPIN (cell)->priv; priv = GTK_CELL_RENDERER_SPIN (cell)->priv;
if (!cell_text->editable) g_object_get (cell_text, "editable", &editable, NULL);
if (!editable)
return NULL; return NULL;
if (!priv->adjustment) if (!priv->adjustment)
@ -318,9 +321,11 @@ gtk_cell_renderer_spin_start_editing (GtkCellRenderer *cell,
G_CALLBACK (gtk_cell_renderer_spin_button_press_event), G_CALLBACK (gtk_cell_renderer_spin_button_press_event),
NULL); NULL);
if (cell_text->text) g_object_get (cell_text, "text", &text, NULL);
if (text)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin),
g_ascii_strtod (cell_text->text, NULL)); g_ascii_strtod (text, NULL));
g_free (text);
g_object_set_data_full (G_OBJECT (spin), GTK_CELL_RENDERER_SPIN_PATH, g_object_set_data_full (G_OBJECT (spin), GTK_CELL_RENDERER_SPIN_PATH,
g_strdup (path), g_free); g_strdup (path), g_free);

View File

@ -390,6 +390,7 @@ gail_text_cell_get_run_attributes (AtkText *text,
PangoLayout *layout; PangoLayout *layout;
AtkObject *parent; AtkObject *parent;
GtkWidget *widget; GtkWidget *widget;
gchar *renderer_text;
gail_renderer = GAIL_RENDERER_CELL (text); gail_renderer = GAIL_RENDERER_CELL (text);
gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer); gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer);
@ -400,12 +401,14 @@ gail_text_cell_get_run_attributes (AtkText *text,
g_return_val_if_fail (GAIL_IS_CELL_PARENT (parent), NULL); g_return_val_if_fail (GAIL_IS_CELL_PARENT (parent), NULL);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
layout = create_pango_layout (gtk_renderer, widget), layout = create_pango_layout (gtk_renderer, widget),
g_object_get (gtk_renderer, "text", &renderer_text, NULL);
attrib_set = gail_misc_layout_get_run_attributes (attrib_set, attrib_set = gail_misc_layout_get_run_attributes (attrib_set,
layout, layout,
gtk_renderer->text, renderer_text,
offset, offset,
start_offset, start_offset,
end_offset); end_offset);
g_free (renderer_text);
g_object_unref (G_OBJECT (layout)); g_object_unref (G_OBJECT (layout));
return attrib_set; return attrib_set;
@ -448,71 +451,97 @@ static PangoLayout*
create_pango_layout(GtkCellRendererText *gtk_renderer, create_pango_layout(GtkCellRendererText *gtk_renderer,
GtkWidget *widget) GtkWidget *widget)
{ {
PangoAttrList *attr_list; GdkColor *foreground_gdk;
PangoAttrList *attr_list, *attributes;
PangoLayout *layout; PangoLayout *layout;
PangoUnderline uline; PangoUnderline uline, underline;
PangoFontMask mask; 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;
layout = gtk_widget_create_pango_layout (widget, gtk_renderer->text); g_object_get (gtk_renderer,
"text", &renderer_text,
"attributes", &attributes,
"foreground-set", &foreground_set,
"foreground-gdk", &foreground_gdk,
"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);
if (gtk_renderer->extra_attrs) layout = gtk_widget_create_pango_layout (widget, renderer_text);
attr_list = pango_attr_list_copy (gtk_renderer->extra_attrs);
if (attributes)
attr_list = pango_attr_list_copy (attributes);
else else
attr_list = pango_attr_list_new (); attr_list = pango_attr_list_new ();
if (gtk_renderer->foreground_set) if (foreground_set)
{ {
PangoColor color; add_attr (attr_list, pango_attr_foreground_new (foreground_gdk->red,
color = gtk_renderer->foreground; foreground_gdk->green,
add_attr (attr_list, pango_attr_foreground_new (color.red, foreground_gdk->blue));
color.green, color.blue));
} }
if (gtk_renderer->strikethrough_set) if (strikethrough_set)
add_attr (attr_list, add_attr (attr_list,
pango_attr_strikethrough_new (gtk_renderer->strikethrough)); pango_attr_strikethrough_new (strikethrough));
mask = pango_font_description_get_set_fields (gtk_renderer->font); mask = pango_font_description_get_set_fields (font_desc);
if (mask & PANGO_FONT_MASK_FAMILY) if (mask & PANGO_FONT_MASK_FAMILY)
add_attr (attr_list, add_attr (attr_list,
pango_attr_family_new (pango_font_description_get_family (gtk_renderer->font))); pango_attr_family_new (pango_font_description_get_family (font_desc)));
if (mask & PANGO_FONT_MASK_STYLE) if (mask & PANGO_FONT_MASK_STYLE)
add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (gtk_renderer->font))); add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (font_desc)));
if (mask & PANGO_FONT_MASK_VARIANT) if (mask & PANGO_FONT_MASK_VARIANT)
add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (gtk_renderer->font))); add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (font_desc)));
if (mask & PANGO_FONT_MASK_WEIGHT) if (mask & PANGO_FONT_MASK_WEIGHT)
add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (gtk_renderer->font))); add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (font_desc)));
if (mask & PANGO_FONT_MASK_STRETCH) if (mask & PANGO_FONT_MASK_STRETCH)
add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (gtk_renderer->font))); add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (font_desc)));
if (mask & PANGO_FONT_MASK_SIZE) if (mask & PANGO_FONT_MASK_SIZE)
add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (gtk_renderer->font))); add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (font_desc)));
if (gtk_renderer->scale_set && if (scale_set && scale != 1.0)
gtk_renderer->font_scale != 1.0) add_attr (attr_list, pango_attr_scale_new (scale));
add_attr (attr_list, pango_attr_scale_new (gtk_renderer->font_scale));
if (gtk_renderer->underline_set) if (underline_set)
uline = gtk_renderer->underline_style; uline = underline;
else else
uline = PANGO_UNDERLINE_NONE; uline = PANGO_UNDERLINE_NONE;
if (uline != PANGO_UNDERLINE_NONE) if (uline != PANGO_UNDERLINE_NONE)
add_attr (attr_list, add_attr (attr_list,
pango_attr_underline_new (gtk_renderer->underline_style)); pango_attr_underline_new (underline));
if (gtk_renderer->rise_set) if (rise_set)
add_attr (attr_list, pango_attr_rise_new (gtk_renderer->rise)); add_attr (attr_list, pango_attr_rise_new (rise));
pango_layout_set_attributes (layout, attr_list); pango_layout_set_attributes (layout, attr_list);
pango_layout_set_width (layout, -1); pango_layout_set_width (layout, -1);
pango_attr_list_unref (attr_list); pango_attr_list_unref (attr_list);
pango_font_description_free (font_desc);
g_free (foreground_gdk);
pango_attr_list_unref (attributes);
g_free (renderer_text);
return layout; return layout;
} }
@ -541,6 +570,7 @@ gail_text_cell_get_character_extents (AtkText *text,
AtkObject *parent; AtkObject *parent;
PangoRectangle char_rect; PangoRectangle char_rect;
PangoLayout *layout; PangoLayout *layout;
gchar *renderer_text;
gint x_offset, y_offset, index, cell_height, cell_width; gint x_offset, y_offset, index, cell_height, cell_width;
gint xpad, ypad; gint xpad, ypad;
@ -559,7 +589,12 @@ gail_text_cell_get_character_extents (AtkText *text,
/* /*
* Thus would be inconsistent with the cache * Thus would be inconsistent with the cache
*/ */
gail_return_if_fail (gtk_renderer->text); g_object_get (gtk_renderer, "text", &renderer_text, NULL);
if (text == NULL)
{
g_free (renderer_text);
return;
}
parent = atk_object_get_parent (ATK_OBJECT (text)); parent = atk_object_get_parent (ATK_OBJECT (text));
if (GAIL_IS_CONTAINER_CELL (parent)) if (GAIL_IS_CONTAINER_CELL (parent))
@ -573,8 +608,7 @@ gail_text_cell_get_character_extents (AtkText *text,
&rendered_rect, &x_offset, &y_offset, &cell_width, &cell_height); &rendered_rect, &x_offset, &y_offset, &cell_width, &cell_height);
layout = create_pango_layout (gtk_renderer, widget); layout = create_pango_layout (gtk_renderer, widget);
index = g_utf8_offset_to_pointer (gtk_renderer->text, index = g_utf8_offset_to_pointer (renderer_text, offset) - renderer_text;
offset) - gtk_renderer->text;
pango_layout_index_to_pos (layout, index, &char_rect); pango_layout_index_to_pos (layout, index, &char_rect);
gtk_cell_renderer_get_padding (gail_renderer->renderer, &xpad, &ypad); gtk_cell_renderer_get_padding (gail_renderer->renderer, &xpad, &ypad);
@ -583,7 +617,10 @@ gail_text_cell_get_character_extents (AtkText *text,
x_offset + rendered_rect.x + xpad, x_offset + rendered_rect.x + xpad,
y_offset + rendered_rect.y + ypad, y_offset + rendered_rect.y + ypad,
x, y, width, height, coords); x, y, width, height, coords);
g_free (renderer_text);
g_object_unref (layout); g_object_unref (layout);
return; return;
} }
@ -599,6 +636,7 @@ gail_text_cell_get_offset_at_point (AtkText *text,
GtkWidget *widget; GtkWidget *widget;
GdkRectangle rendered_rect; GdkRectangle rendered_rect;
PangoLayout *layout; PangoLayout *layout;
gchar *renderer_text;
gint x_offset, y_offset, index; gint x_offset, y_offset, index;
gint xpad, ypad; gint xpad, ypad;
@ -609,7 +647,13 @@ gail_text_cell_get_offset_at_point (AtkText *text,
gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer); gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer);
parent = atk_object_get_parent (ATK_OBJECT (text)); parent = atk_object_get_parent (ATK_OBJECT (text));
g_return_val_if_fail (gtk_renderer->text, -1); g_object_get (gtk_renderer, "text", &renderer_text, NULL);
if (text == NULL)
{
g_free (renderer_text);
return -1;
}
if (GAIL_IS_CONTAINER_CELL (parent)) if (GAIL_IS_CONTAINER_CELL (parent))
parent = atk_object_get_parent (parent); parent = atk_object_get_parent (parent);
@ -632,13 +676,29 @@ gail_text_cell_get_offset_at_point (AtkText *text,
if (index == -1) if (index == -1)
{ {
if (coords == ATK_XY_WINDOW || coords == ATK_XY_SCREEN) if (coords == ATK_XY_WINDOW || coords == ATK_XY_SCREEN)
return g_utf8_strlen (gtk_renderer->text, -1); {
glong length;
length = g_utf8_strlen (renderer_text, -1);
g_free (renderer_text);
return length;
}
g_free (renderer_text);
return index; return index;
} }
else else
return g_utf8_pointer_to_offset (gtk_renderer->text, {
gtk_renderer->text + index); glong offset;
offset = g_utf8_pointer_to_offset (renderer_text,
renderer_text + index);
g_free (renderer_text);
return offset;
}
} }
static gunichar static gunichar