Removed cell margin apis and now deal with "focus-line-width".

This commit is contained in:
Tristan Van Berkom 2010-11-23 16:26:46 +09:00
parent 7105d02a13
commit d56babefb4
4 changed files with 31 additions and 258 deletions

View File

@ -111,7 +111,7 @@ typedef struct {
} CellAttribute;
typedef struct {
GSList *attributes;
GSList *attributes;
GtkCellLayoutDataFunc func;
gpointer data;
@ -161,11 +161,6 @@ struct _GtkCellAreaPrivate
*/
GHashTable *cell_info;
/* The cell border decides how much space to reserve
* around each cell for the background_area
*/
GtkBorder cell_border;
/* Current path is saved as a side-effect
* of gtk_cell_area_apply_attributes() */
gchar *current_path;
@ -189,10 +184,6 @@ struct _GtkCellAreaPrivate
enum {
PROP_0,
PROP_CELL_MARGIN_LEFT,
PROP_CELL_MARGIN_RIGHT,
PROP_CELL_MARGIN_TOP,
PROP_CELL_MARGIN_BOTTOM,
PROP_FOCUS_CELL,
PROP_EDITED_CELL,
PROP_EDIT_WIDGET
@ -238,11 +229,6 @@ gtk_cell_area_init (GtkCellArea *area)
NULL,
(GDestroyNotify)g_list_free);
priv->cell_border.left = 0;
priv->cell_border.right = 0;
priv->cell_border.top = 0;
priv->cell_border.bottom = 0;
priv->focus_cell = NULL;
priv->edited_cell = NULL;
priv->edit_widget = NULL;
@ -356,50 +342,6 @@ gtk_cell_area_class_init (GtkCellAreaClass *class)
G_TYPE_STRING);
/* Properties */
g_object_class_install_property (object_class,
PROP_CELL_MARGIN_LEFT,
g_param_spec_int
("cell-margin-left",
P_("Margin on Left"),
P_("Pixels of extra space on the left side of each cell"),
0,
G_MAXINT16,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CELL_MARGIN_RIGHT,
g_param_spec_int
("cell-margin-right",
P_("Margin on Right"),
P_("Pixels of extra space on the right side of each cell"),
0,
G_MAXINT16,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CELL_MARGIN_TOP,
g_param_spec_int
("cell-margin-top",
P_("Margin on Top"),
P_("Pixels of extra space on the top side of each cell"),
0,
G_MAXINT16,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CELL_MARGIN_BOTTOM,
g_param_spec_int
("cell-margin-bottom",
P_("Margin on Bottom"),
P_("Pixels of extra space on the bottom side of each cell"),
0,
G_MAXINT16,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FOCUS_CELL,
g_param_spec_object
@ -442,12 +384,11 @@ cell_info_new (GtkCellLayoutDataFunc func,
gpointer data,
GDestroyNotify destroy)
{
CellInfo *info = g_slice_new (CellInfo);
info->attributes = NULL;
info->func = func;
info->data = data;
info->destroy = destroy;
CellInfo *info = g_slice_new0 (CellInfo);
info->func = func;
info->data = data;
info->destroy = destroy;
return info;
}
@ -552,18 +493,6 @@ gtk_cell_area_set_property (GObject *object,
switch (prop_id)
{
case PROP_CELL_MARGIN_LEFT:
gtk_cell_area_set_cell_margin_left (area, g_value_get_int (value));
break;
case PROP_CELL_MARGIN_RIGHT:
gtk_cell_area_set_cell_margin_right (area, g_value_get_int (value));
break;
case PROP_CELL_MARGIN_TOP:
gtk_cell_area_set_cell_margin_top (area, g_value_get_int (value));
break;
case PROP_CELL_MARGIN_BOTTOM:
gtk_cell_area_set_cell_margin_bottom (area, g_value_get_int (value));
break;
case PROP_FOCUS_CELL:
gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
break;
@ -584,18 +513,6 @@ gtk_cell_area_get_property (GObject *object,
switch (prop_id)
{
case PROP_CELL_MARGIN_LEFT:
g_value_set_int (value, priv->cell_border.left);
break;
case PROP_CELL_MARGIN_RIGHT:
g_value_set_int (value, priv->cell_border.right);
break;
case PROP_CELL_MARGIN_TOP:
g_value_set_int (value, priv->cell_border.top);
break;
case PROP_CELL_MARGIN_BOTTOM:
g_value_set_int (value, priv->cell_border.bottom);
break;
case PROP_FOCUS_CELL:
g_value_set_object (value, priv->focus_cell);
break;
@ -2581,7 +2498,7 @@ gtk_cell_area_activate_cell (GtkCellArea *area,
*
* XXX Maybe have to do some rtl mode treatment here...
*/
gtk_cell_area_inner_cell_area (area, cell_area, &inner_area);
gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
g_object_get (renderer, "mode", &mode, NULL);
@ -2687,131 +2604,30 @@ gtk_cell_area_stop_editing (GtkCellArea *area,
}
/*************************************************************
* API: Margins *
* API: Convenience for area implementations *
*************************************************************/
gint
gtk_cell_area_get_cell_margin_left (GtkCellArea *area)
{
g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
return area->priv->cell_border.left;
}
void
gtk_cell_area_set_cell_margin_left (GtkCellArea *area,
gint margin)
{
GtkCellAreaPrivate *priv;
g_return_if_fail (GTK_IS_CELL_AREA (area));
priv = area->priv;
if (priv->cell_border.left != margin)
{
priv->cell_border.left = margin;
g_object_notify (G_OBJECT (area), "cell-margin-left");
}
}
gint
gtk_cell_area_get_cell_margin_right (GtkCellArea *area)
{
g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
return area->priv->cell_border.right;
}
void
gtk_cell_area_set_cell_margin_right (GtkCellArea *area,
gint margin)
{
GtkCellAreaPrivate *priv;
g_return_if_fail (GTK_IS_CELL_AREA (area));
priv = area->priv;
if (priv->cell_border.right != margin)
{
priv->cell_border.right = margin;
g_object_notify (G_OBJECT (area), "cell-margin-right");
}
}
gint
gtk_cell_area_get_cell_margin_top (GtkCellArea *area)
{
g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
return area->priv->cell_border.top;
}
void
gtk_cell_area_set_cell_margin_top (GtkCellArea *area,
gint margin)
{
GtkCellAreaPrivate *priv;
g_return_if_fail (GTK_IS_CELL_AREA (area));
priv = area->priv;
if (priv->cell_border.top != margin)
{
priv->cell_border.top = margin;
g_object_notify (G_OBJECT (area), "cell-margin-top");
}
}
gint
gtk_cell_area_get_cell_margin_bottom (GtkCellArea *area)
{
g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
return area->priv->cell_border.bottom;
}
void
gtk_cell_area_set_cell_margin_bottom (GtkCellArea *area,
gint margin)
{
GtkCellAreaPrivate *priv;
g_return_if_fail (GTK_IS_CELL_AREA (area));
priv = area->priv;
if (priv->cell_border.bottom != margin)
{
priv->cell_border.bottom = margin;
g_object_notify (G_OBJECT (area), "cell-margin-bottom");
}
}
void
gtk_cell_area_inner_cell_area (GtkCellArea *area,
GtkWidget *widget,
const GdkRectangle *cell_area,
GdkRectangle *inner_area)
{
GtkCellAreaPrivate *priv;
gint focus_line_width;
g_return_if_fail (GTK_IS_CELL_AREA (area));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cell_area != NULL);
g_return_if_fail (inner_area != NULL);
priv = area->priv;
gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
*inner_area = *cell_area;
inner_area->x += priv->cell_border.left;
inner_area->width -= (priv->cell_border.left + priv->cell_border.right);
inner_area->y += priv->cell_border.top;
inner_area->height -= (priv->cell_border.top + priv->cell_border.bottom);
inner_area->x += focus_line_width;
inner_area->width -= focus_line_width * 2;
inner_area->y += focus_line_width;
inner_area->height -= focus_line_width * 2;
}
void
@ -2873,6 +2689,7 @@ gtk_cell_area_request_renderer (GtkCellArea *area,
gint *natural_size)
{
GtkCellAreaPrivate *priv;
gint focus_line_width;
g_return_if_fail (GTK_IS_CELL_AREA (area));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
@ -2882,20 +2699,21 @@ gtk_cell_area_request_renderer (GtkCellArea *area,
priv = area->priv;
gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
focus_line_width *= 2;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (for_size < 0)
gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
else
{
for_size = MAX (0, for_size - (priv->cell_border.top + priv->cell_border.bottom));
for_size = MAX (0, for_size - focus_line_width);
gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
minimum_size, natural_size);
}
*minimum_size += (priv->cell_border.left + priv->cell_border.right);
*natural_size += (priv->cell_border.left + priv->cell_border.right);
}
else /* GTK_ORIENTATION_VERTICAL */
{
@ -2903,13 +2721,13 @@ gtk_cell_area_request_renderer (GtkCellArea *area,
gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
else
{
for_size = MAX (0, for_size - (priv->cell_border.left + priv->cell_border.right));
for_size = MAX (0, for_size - focus_line_width);
gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
minimum_size, natural_size);
}
*minimum_size += (priv->cell_border.top + priv->cell_border.bottom);
*natural_size += (priv->cell_border.top + priv->cell_border.bottom);
}
*minimum_size += focus_line_width;
*natural_size += focus_line_width;
}

View File

@ -320,24 +320,11 @@ gboolean gtk_cell_area_activate_cell (GtkCellArea
void gtk_cell_area_stop_editing (GtkCellArea *area,
gboolean canceled);
/* Margins */
gint gtk_cell_area_get_cell_margin_left (GtkCellArea *area);
void gtk_cell_area_set_cell_margin_left (GtkCellArea *area,
gint margin);
gint gtk_cell_area_get_cell_margin_right (GtkCellArea *area);
void gtk_cell_area_set_cell_margin_right (GtkCellArea *area,
gint margin);
gint gtk_cell_area_get_cell_margin_top (GtkCellArea *area);
void gtk_cell_area_set_cell_margin_top (GtkCellArea *area,
gint margin);
gint gtk_cell_area_get_cell_margin_bottom (GtkCellArea *area);
void gtk_cell_area_set_cell_margin_bottom (GtkCellArea *area,
gint margin);
/* Functions for area implementations */
/* Distinguish the inner cell area from the whole requested area including margins */
void gtk_cell_area_inner_cell_area (GtkCellArea *area,
GtkWidget *widget,
const GdkRectangle *cell_area,
GdkRectangle *inner_area);

View File

@ -933,7 +933,7 @@ gtk_cell_area_box_event (GtkCellArea *area,
/* Remove margins from the background area to produce the cell area
*/
gtk_cell_area_inner_cell_area (area, &cell_background, &inner_area);
gtk_cell_area_inner_cell_area (area, widget, &cell_background, &inner_area);
if (event_x >= inner_area.x && event_x <= inner_area.x + inner_area.width &&
event_y >= inner_area.y && event_y <= inner_area.y + inner_area.height)
@ -968,7 +968,7 @@ gtk_cell_area_box_event (GtkCellArea *area,
/* If we are activating via a focus sibling, we need to fix the
* cell area */
if (event_renderer != cell->renderer)
gtk_cell_area_inner_cell_area (area, cell_area, &cell_background);
gtk_cell_area_inner_cell_area (area, widget, cell_area, &cell_background);
gtk_cell_area_set_focus_cell (area, event_renderer);
@ -1037,7 +1037,7 @@ gtk_cell_area_box_render (GtkCellArea *area,
/* Remove margins from the background area to produce the cell area
*/
gtk_cell_area_inner_cell_area (area, &cell_background, &inner_area);
gtk_cell_area_inner_cell_area (area, widget, &cell_background, &inner_area);
/* Add portions of the background_area to the cell_background
* to create the render_background */

View File

@ -498,24 +498,6 @@ row_spacing_changed (GtkSpinButton *spin_button,
cell_area_scaffold_set_row_spacing (scaffold, value);
}
static void
cell_margins_changed (GtkSpinButton *spin_button,
CellAreaScaffold *scaffold)
{
GtkCellArea *area = cell_area_scaffold_get_area (scaffold);
gint value;
value = (gint)gtk_spin_button_get_value (spin_button);
gtk_cell_area_set_cell_margin_left (area, value);
gtk_cell_area_set_cell_margin_right (area, value);
gtk_cell_area_set_cell_margin_top (area, value);
gtk_cell_area_set_cell_margin_bottom (area, value);
gtk_widget_queue_resize (GTK_WIDGET (scaffold));
}
static void
indentation_changed (GtkSpinButton *spin_button,
CellAreaScaffold *scaffold)
@ -544,8 +526,7 @@ background_area (void)
label = gtk_label_new ("In this example, row spacing gets devided into the background area, "
"column spacing is added between each background area, indentation is "
"prepended space distributed to the background area, individual cell margins "
"are also distributed to the background area for every cell.");
"prepended space distributed to the background area.");
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_width_chars (GTK_LABEL (label), 40);
gtk_widget_show (label);
@ -606,19 +587,6 @@ background_area (void)
g_signal_connect (G_OBJECT (widget), "value-changed",
G_CALLBACK (row_spacing_changed), scaffold);
widget = gtk_spin_button_new_with_range (0, 10, 1);
label = gtk_label_new ("Cell Margins");
hbox = gtk_hbox_new (FALSE, 4);
gtk_widget_show (hbox);
gtk_widget_show (label);
gtk_widget_show (widget);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (widget), "value-changed",
G_CALLBACK (cell_margins_changed), scaffold);
widget = gtk_spin_button_new_with_range (0, 30, 1);
label = gtk_label_new ("Intentation");
hbox = gtk_hbox_new (FALSE, 4);