forked from AuroraMiddleware/gtk
Merge branch 'wip/otte/listview2' into 'main'
listview: GtkListTile See merge request GNOME/gtk!5584
This commit is contained in:
commit
c823432eef
@ -477,6 +477,8 @@ gtk_column_view_dispose (GObject *object)
|
||||
{
|
||||
GtkColumnView *self = GTK_COLUMN_VIEW (object);
|
||||
|
||||
gtk_column_view_sorter_clear (GTK_COLUMN_VIEW_SORTER (self->sorter));
|
||||
|
||||
while (g_list_model_get_n_items (G_LIST_MODEL (self->columns)) > 0)
|
||||
{
|
||||
GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), 0);
|
||||
|
@ -82,9 +82,6 @@
|
||||
* use the %GTK_ACCESSIBLE_ROLE_GRID_CELL role.
|
||||
*/
|
||||
|
||||
typedef struct _Cell Cell;
|
||||
typedef struct _CellAugment CellAugment;
|
||||
|
||||
struct _GtkGridView
|
||||
{
|
||||
GtkListBase parent_instance;
|
||||
@ -94,7 +91,6 @@ struct _GtkGridView
|
||||
guint max_columns;
|
||||
/* set in size_allocate */
|
||||
guint n_columns;
|
||||
int unknown_row_height;
|
||||
double column_width;
|
||||
};
|
||||
|
||||
@ -103,18 +99,6 @@ struct _GtkGridViewClass
|
||||
GtkListBaseClass parent_class;
|
||||
};
|
||||
|
||||
struct _Cell
|
||||
{
|
||||
GtkListItemManagerItem parent;
|
||||
guint size; /* total, only counting cells in first column */
|
||||
};
|
||||
|
||||
struct _CellAugment
|
||||
{
|
||||
GtkListItemManagerItemAugment parent;
|
||||
guint size; /* total, only counting first column */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
@ -141,333 +125,216 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
||||
static void G_GNUC_UNUSED
|
||||
dump (GtkGridView *self)
|
||||
{
|
||||
Cell *cell;
|
||||
GtkListTile *tile;
|
||||
guint n_widgets, n_list_rows, n_items;
|
||||
|
||||
n_widgets = 0;
|
||||
n_list_rows = 0;
|
||||
n_items = 0;
|
||||
//g_print ("ANCHOR: %u - %u\n", self->anchor_start, self->anchor_end);
|
||||
for (cell = gtk_list_item_manager_get_first (self->item_manager);
|
||||
cell;
|
||||
cell = gtk_rb_tree_node_get_next (cell))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (cell->parent.widget)
|
||||
if (tile->widget)
|
||||
n_widgets++;
|
||||
n_list_rows++;
|
||||
n_items += cell->parent.n_items;
|
||||
g_print ("%6u%6u %5ux%3u %s (%upx)\n",
|
||||
cell->parent.n_items, n_items,
|
||||
n_items += tile->n_items;
|
||||
g_print ("%6u%6u %5ux%3u %s (%d,%d,%d,%d)\n",
|
||||
tile->n_items, n_items,
|
||||
n_items / (self->n_columns ? self->n_columns : self->min_columns),
|
||||
n_items % (self->n_columns ? self->n_columns : self->min_columns),
|
||||
cell->parent.widget ? " (widget)" : "", cell->size);
|
||||
tile->widget ? " (widget)" : "",
|
||||
tile->area.x, tile->area.y, tile->area.width, tile->area.height);
|
||||
}
|
||||
|
||||
g_print (" => %u widgets in %u list rows\n", n_widgets, n_list_rows);
|
||||
}
|
||||
|
||||
static void
|
||||
cell_augment (GtkRbTree *tree,
|
||||
gpointer node_augment,
|
||||
gpointer node,
|
||||
gpointer left,
|
||||
gpointer right)
|
||||
static GtkListTile *
|
||||
gtk_grid_view_split (GtkListBase *base,
|
||||
GtkListTile *tile,
|
||||
guint n_items)
|
||||
{
|
||||
Cell *cell = node;
|
||||
CellAugment *aug = node_augment;
|
||||
GtkGridView *self = GTK_GRID_VIEW (base);
|
||||
GtkListTile *split;
|
||||
guint col, row_height;
|
||||
|
||||
gtk_list_item_manager_augment_node (tree, node_augment, node, left, right);
|
||||
row_height = tile->area.height / MAX (tile->n_items / self->n_columns, 1);
|
||||
|
||||
aug->size = cell->size;
|
||||
|
||||
if (left)
|
||||
/* split off the multirow at the top */
|
||||
if (n_items >= self->n_columns)
|
||||
{
|
||||
CellAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
|
||||
guint top_rows = n_items / self->n_columns;
|
||||
guint top_items = top_rows * self->n_columns;
|
||||
|
||||
aug->size += left_aug->size;
|
||||
split = tile;
|
||||
tile = gtk_list_tile_split (self->item_manager, tile, top_items);
|
||||
gtk_list_tile_set_area (self->item_manager,
|
||||
tile,
|
||||
&(GdkRectangle) {
|
||||
split->area.x,
|
||||
split->area.y + row_height * top_rows,
|
||||
split->area.width,
|
||||
split->area.height - row_height * top_rows,
|
||||
});
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
split,
|
||||
split->area.width,
|
||||
row_height * top_rows);
|
||||
n_items -= top_items;
|
||||
if (n_items == 0)
|
||||
return tile;
|
||||
}
|
||||
|
||||
if (right)
|
||||
/* split off the multirow at the bottom */
|
||||
if (tile->n_items > self->n_columns)
|
||||
{
|
||||
CellAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
|
||||
|
||||
aug->size += right_aug->size;
|
||||
}
|
||||
}
|
||||
|
||||
/*<private>
|
||||
* gtk_grid_view_get_cell_at_y:
|
||||
* @self: a `GtkGridView`
|
||||
* @y: an offset in direction of @self's orientation
|
||||
* @position: (out caller-allocates) (optional): stores the position
|
||||
* index of the returned row
|
||||
* @offset: (out caller-allocates) (optional): stores the offset
|
||||
* in pixels between y and top of cell.
|
||||
* @size: (out caller-allocates) (optional): stores the height
|
||||
* of the cell
|
||||
*
|
||||
* Gets the Cell that occupies the leftmost position in the row at offset
|
||||
* @y into the primary direction.
|
||||
*
|
||||
* If y is larger than the height of all cells, %NULL will be returned.
|
||||
* In particular that means that for an empty grid, %NULL is returned
|
||||
* for any value.
|
||||
*
|
||||
* Returns: (nullable): The first cell at offset y
|
||||
**/
|
||||
static Cell *
|
||||
gtk_grid_view_get_cell_at_y (GtkGridView *self,
|
||||
int y,
|
||||
guint *position,
|
||||
int *offset,
|
||||
int *size)
|
||||
{
|
||||
Cell *cell, *tmp;
|
||||
guint pos;
|
||||
|
||||
cell = gtk_list_item_manager_get_root (self->item_manager);
|
||||
pos = 0;
|
||||
|
||||
while (cell)
|
||||
{
|
||||
tmp = gtk_rb_tree_node_get_left (cell);
|
||||
if (tmp)
|
||||
{
|
||||
CellAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, tmp);
|
||||
if (y < aug->size)
|
||||
{
|
||||
cell = tmp;
|
||||
continue;
|
||||
}
|
||||
y -= aug->size;
|
||||
pos += aug->parent.n_items;
|
||||
}
|
||||
|
||||
if (y < cell->size)
|
||||
break;
|
||||
y -= cell->size;
|
||||
pos += cell->parent.n_items;
|
||||
|
||||
cell = gtk_rb_tree_node_get_right (cell);
|
||||
split = gtk_list_tile_split (self->item_manager, tile, self->n_columns);
|
||||
gtk_list_tile_set_area (self->item_manager,
|
||||
split,
|
||||
&(GdkRectangle) {
|
||||
tile->area.x,
|
||||
tile->area.y + row_height,
|
||||
tile->area.width,
|
||||
tile->area.height - row_height,
|
||||
});
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
tile,
|
||||
tile->area.width,
|
||||
row_height);
|
||||
}
|
||||
|
||||
if (cell == NULL)
|
||||
{
|
||||
if (position)
|
||||
*position = 0;
|
||||
if (offset)
|
||||
*offset = 0;
|
||||
if (size)
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
g_assert (n_items < tile->n_items);
|
||||
g_assert (tile->n_items <= self->n_columns);
|
||||
|
||||
/* We know have the (range of) cell(s) that contains this offset.
|
||||
* Now for the hard part of computing which index this actually is.
|
||||
*/
|
||||
if (offset || position || size)
|
||||
{
|
||||
guint n_items = cell->parent.n_items;
|
||||
guint no_widget_rows, skip;
|
||||
|
||||
/* skip remaining items at end of row */
|
||||
if (pos % self->n_columns)
|
||||
{
|
||||
skip = self->n_columns - pos % self->n_columns;
|
||||
if (n_items <= skip)
|
||||
{
|
||||
g_warning ("ran out of items");
|
||||
if (position)
|
||||
*position = 0;
|
||||
if (offset)
|
||||
*offset = 0;
|
||||
if (size)
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
n_items -= skip;
|
||||
pos += skip;
|
||||
}
|
||||
|
||||
/* Skip all the rows this index doesn't go into */
|
||||
no_widget_rows = (n_items - 1) / self->n_columns;
|
||||
skip = MIN (y / self->unknown_row_height, no_widget_rows);
|
||||
y -= skip * self->unknown_row_height;
|
||||
pos += self->n_columns * skip;
|
||||
|
||||
if (position)
|
||||
*position = pos;
|
||||
if (offset)
|
||||
*offset = y;
|
||||
if (size)
|
||||
{
|
||||
if (skip < no_widget_rows)
|
||||
*size = self->unknown_row_height;
|
||||
else
|
||||
*size = cell->size - no_widget_rows * self->unknown_row_height;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
/* now it's a single row, do a split at the column boundary */
|
||||
col = tile->area.x / self->column_width;
|
||||
split = gtk_list_tile_split (self->item_manager, tile, n_items);
|
||||
gtk_list_tile_set_area (self->item_manager,
|
||||
split,
|
||||
&(GdkRectangle) {
|
||||
ceil ((col + n_items) * self->column_width),
|
||||
tile->area.y,
|
||||
ceil ((col + n_items + split->n_items) * self->column_width),
|
||||
tile->area.height,
|
||||
});
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
tile,
|
||||
ceil ((col + n_items) * self->column_width) - tile->area.x,
|
||||
tile->area.height);
|
||||
|
||||
return split;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_grid_view_get_allocation_along (GtkListBase *base,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size)
|
||||
gtk_grid_view_get_allocation (GtkListBase *base,
|
||||
guint pos,
|
||||
GdkRectangle *area)
|
||||
{
|
||||
GtkGridView *self = GTK_GRID_VIEW (base);
|
||||
Cell *cell, *tmp;
|
||||
int y;
|
||||
GtkListTile *tile;
|
||||
guint offset;
|
||||
|
||||
cell = gtk_list_item_manager_get_root (self->item_manager);
|
||||
y = 0;
|
||||
pos -= pos % self->n_columns;
|
||||
tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &offset);
|
||||
if (tile == NULL || tile->area.width <= 0 || tile->area.height <= 0)
|
||||
return FALSE;
|
||||
|
||||
while (cell)
|
||||
*area = tile->area;
|
||||
|
||||
if (tile->n_items > self->n_columns)
|
||||
{
|
||||
tmp = gtk_rb_tree_node_get_left (cell);
|
||||
if (tmp)
|
||||
{
|
||||
CellAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, tmp);
|
||||
if (pos < aug->parent.n_items)
|
||||
{
|
||||
cell = tmp;
|
||||
continue;
|
||||
}
|
||||
pos -= aug->parent.n_items;
|
||||
y += aug->size;
|
||||
}
|
||||
|
||||
if (pos < cell->parent.n_items)
|
||||
break;
|
||||
y += cell->size;
|
||||
pos -= cell->parent.n_items;
|
||||
|
||||
cell = gtk_rb_tree_node_get_right (cell);
|
||||
area->height /= (tile->n_items / self->n_columns);
|
||||
area->y += (offset / self->n_columns) * area->height;
|
||||
offset %= self->n_columns;
|
||||
}
|
||||
|
||||
if (cell == NULL)
|
||||
if (tile->n_items > 1)
|
||||
{
|
||||
if (offset)
|
||||
*offset = 0;
|
||||
if (size)
|
||||
*size = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We know have the (range of) cell(s) that contains this offset.
|
||||
* Now for the hard part of computing which index this actually is.
|
||||
*/
|
||||
if (offset || size)
|
||||
{
|
||||
guint n_items = cell->parent.n_items;
|
||||
guint skip;
|
||||
|
||||
/* skip remaining items at end of row */
|
||||
if (pos % self->n_columns)
|
||||
{
|
||||
skip = pos % self->n_columns;
|
||||
n_items -= skip;
|
||||
pos -= skip;
|
||||
}
|
||||
|
||||
/* Skip all the rows this index doesn't go into */
|
||||
skip = pos / self->n_columns;
|
||||
n_items -= skip * self->n_columns;
|
||||
y += skip * self->unknown_row_height;
|
||||
|
||||
if (offset)
|
||||
*offset = y;
|
||||
if (size)
|
||||
{
|
||||
if (n_items > self->n_columns)
|
||||
*size = self->unknown_row_height;
|
||||
else
|
||||
*size = cell->size - skip * self->unknown_row_height;
|
||||
}
|
||||
guint col = area->x / self->column_width;
|
||||
area->x = ceil ((col + offset) * self->column_width);
|
||||
area->width = ceil ((col + offset + 1) * self->column_width) - area->x;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_grid_view_get_allocation_across (GtkListBase *base,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size)
|
||||
{
|
||||
GtkGridView *self = GTK_GRID_VIEW (base);
|
||||
guint start;
|
||||
|
||||
pos %= self->n_columns;
|
||||
start = ceil (self->column_width * pos);
|
||||
|
||||
if (offset)
|
||||
*offset = start;
|
||||
if (size)
|
||||
*size = ceil (self->column_width * (pos + 1)) - start;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
gtk_grid_view_compute_total_height (GtkGridView *self)
|
||||
{
|
||||
Cell *cell;
|
||||
CellAugment *aug;
|
||||
|
||||
cell = gtk_list_item_manager_get_root (self->item_manager);
|
||||
if (cell == NULL)
|
||||
return 0;
|
||||
aug = gtk_list_item_manager_get_item_augment (self->item_manager, cell);
|
||||
return aug->size;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_grid_view_get_position_from_allocation (GtkListBase *base,
|
||||
int across,
|
||||
int along,
|
||||
int x,
|
||||
int y,
|
||||
guint *position,
|
||||
cairo_rectangle_int_t *area)
|
||||
{
|
||||
GtkGridView *self = GTK_GRID_VIEW (base);
|
||||
int offset, size;
|
||||
guint pos, n_items;
|
||||
GtkListTile *tile;
|
||||
guint pos;
|
||||
GdkRectangle bounds;
|
||||
|
||||
if (across >= self->column_width * self->n_columns)
|
||||
gtk_list_item_manager_get_tile_bounds (self->item_manager, &bounds);
|
||||
if (bounds.width <= 0 || bounds.height <= 0)
|
||||
return FALSE;
|
||||
x = CLAMP (x, bounds.x, bounds.x + bounds.width - 1);
|
||||
y = CLAMP (y, bounds.y, bounds.y + bounds.height - 1);
|
||||
|
||||
tile = gtk_list_item_manager_get_tile_at (self->item_manager, x, y);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
|
||||
n_items = gtk_list_base_get_n_items (base);
|
||||
along = CLAMP (along, 0, gtk_grid_view_compute_total_height (self) - 1);
|
||||
across = across < 0 ? 0 : across;
|
||||
|
||||
if (!gtk_grid_view_get_cell_at_y (self,
|
||||
along,
|
||||
&pos,
|
||||
&offset,
|
||||
&size))
|
||||
return FALSE;
|
||||
|
||||
pos += floor (across / self->column_width);
|
||||
|
||||
if (pos >= n_items)
|
||||
while (tile && tile->n_items == 0)
|
||||
tile = gtk_rb_tree_node_get_previous (tile);
|
||||
if (tile == NULL)
|
||||
{
|
||||
/* Ugh, we're in the last row and don't have enough items
|
||||
* to fill the row.
|
||||
* Do it the hard way then... */
|
||||
pos = n_items - 1;
|
||||
tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
while (tile && tile->n_items == 0)
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pos = gtk_list_tile_get_position (self->item_manager, tile);
|
||||
if (tile->n_items > 1)
|
||||
{
|
||||
/* offset in x direction */
|
||||
pos += (x - tile->area.x) / self->column_width;
|
||||
if (area)
|
||||
{
|
||||
guint col = MIN (x / self->column_width, self->n_columns - 1);
|
||||
area->x = ceil (col * self->column_width);
|
||||
area->width = ceil ((col + 1) * self->column_width) - area->x;
|
||||
}
|
||||
|
||||
/* offset in y direction */
|
||||
if (tile->n_items > self->n_columns)
|
||||
{
|
||||
guint rows_in_tile = tile->n_items / self->n_columns;
|
||||
guint row_height = tile->area.height / rows_in_tile;
|
||||
guint row_index = (y - tile->area.y) / row_height;
|
||||
pos += self->n_columns * row_index;
|
||||
|
||||
if (area)
|
||||
{
|
||||
area->y = tile->area.y + row_index * row_height;
|
||||
area->height = row_height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (area)
|
||||
{
|
||||
area->y = tile->area.y;
|
||||
area->height = tile->area.height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (area)
|
||||
*area = tile->area;
|
||||
}
|
||||
|
||||
*position = pos;
|
||||
if (area)
|
||||
{
|
||||
area->x = ceil (self->column_width * (pos % self->n_columns));
|
||||
area->width = ceil (self->column_width * (1 + pos % self->n_columns)) - area->x;
|
||||
area->y = along - offset;
|
||||
area->height = size;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -477,24 +344,24 @@ gtk_grid_view_get_items_in_rect (GtkListBase *base,
|
||||
const GdkRectangle *rect)
|
||||
{
|
||||
GtkGridView *self = GTK_GRID_VIEW (base);
|
||||
guint first_row, last_row, first_column, last_column, n_items;
|
||||
guint first_row, last_row, first_column, last_column;
|
||||
GdkRectangle bounds;
|
||||
GtkBitset *result;
|
||||
|
||||
result = gtk_bitset_new_empty ();
|
||||
|
||||
if (rect->y >= gtk_grid_view_compute_total_height (self))
|
||||
/* limit rect to the region that actually overlaps items */
|
||||
gtk_list_item_manager_get_tile_bounds (self->item_manager, &bounds);
|
||||
if (!gdk_rectangle_intersect (&bounds, rect, &bounds))
|
||||
return result;
|
||||
|
||||
n_items = gtk_list_base_get_n_items (base);
|
||||
if (n_items == 0)
|
||||
return result;
|
||||
|
||||
first_column = fmax (floor (rect->x / self->column_width), 0);
|
||||
last_column = fmin (floor ((rect->x + rect->width) / self->column_width), self->n_columns - 1);
|
||||
if (!gtk_grid_view_get_cell_at_y (self, rect->y, &first_row, NULL, NULL))
|
||||
first_row = rect->y < 0 ? 0 : n_items - 1;
|
||||
if (!gtk_grid_view_get_cell_at_y (self, rect->y + rect->height, &last_row, NULL, NULL))
|
||||
last_row = rect->y + rect->height < 0 ? 0 : n_items - 1;
|
||||
first_column = fmax (floor (bounds.x / self->column_width), 0);
|
||||
last_column = fmin (floor ((bounds.x + bounds.width) / self->column_width), self->n_columns - 1);
|
||||
/* match y = 0 here because we care about the rows, not the cells */
|
||||
if (!gtk_grid_view_get_position_from_allocation (base, 0, bounds.y, &first_row, NULL))
|
||||
g_return_val_if_reached (result);
|
||||
if (!gtk_grid_view_get_position_from_allocation (base, 0, bounds.y + bounds.height - 1, &last_row, NULL))
|
||||
g_return_val_if_reached (result);
|
||||
|
||||
gtk_bitset_add_rectangle (result,
|
||||
first_row + first_column,
|
||||
@ -570,22 +437,21 @@ gtk_grid_view_measure_column_size (GtkGridView *self,
|
||||
int *natural)
|
||||
{
|
||||
GtkOrientation opposite;
|
||||
Cell *cell;
|
||||
GtkListTile *tile;
|
||||
int min, nat, child_min, child_nat;
|
||||
|
||||
min = 0;
|
||||
nat = 0;
|
||||
opposite = gtk_list_base_get_opposite_orientation (GTK_LIST_BASE (self));
|
||||
|
||||
for (cell = gtk_list_item_manager_get_first (self->item_manager);
|
||||
cell != NULL;
|
||||
cell = gtk_rb_tree_node_get_next (cell))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
/* ignore unavailable cells */
|
||||
if (cell->parent.widget == NULL)
|
||||
if (tile->widget == NULL)
|
||||
continue;
|
||||
|
||||
gtk_widget_measure (cell->parent.widget,
|
||||
gtk_widget_measure (tile->widget,
|
||||
opposite, -1,
|
||||
&child_min, &child_nat, NULL, NULL);
|
||||
min = MAX (min, child_min);
|
||||
@ -640,7 +506,7 @@ gtk_grid_view_measure_list (GtkWidget *widget,
|
||||
{
|
||||
GtkGridView *self = GTK_GRID_VIEW (widget);
|
||||
GtkScrollablePolicy scroll_policy;
|
||||
Cell *cell;
|
||||
GtkListTile *tile;
|
||||
int height, row_height, child_min, child_nat, column_size, col_min, col_nat;
|
||||
gboolean measured;
|
||||
GArray *heights;
|
||||
@ -660,13 +526,13 @@ gtk_grid_view_measure_list (GtkWidget *widget,
|
||||
i = 0;
|
||||
row_height = 0;
|
||||
measured = FALSE;
|
||||
for (cell = gtk_list_item_manager_get_first (self->item_manager);
|
||||
cell != NULL;
|
||||
cell = gtk_rb_tree_node_get_next (cell))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (cell->parent.widget)
|
||||
if (tile->widget)
|
||||
{
|
||||
gtk_widget_measure (cell->parent.widget,
|
||||
gtk_widget_measure (tile->widget,
|
||||
gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
|
||||
column_size,
|
||||
&child_min, &child_nat, NULL, NULL);
|
||||
@ -677,7 +543,7 @@ gtk_grid_view_measure_list (GtkWidget *widget,
|
||||
measured = TRUE;
|
||||
}
|
||||
|
||||
i += cell->parent.n_items;
|
||||
i += tile->n_items;
|
||||
|
||||
if (i >= n_columns)
|
||||
{
|
||||
@ -731,17 +597,6 @@ gtk_grid_view_measure (GtkWidget *widget,
|
||||
gtk_grid_view_measure_across (widget, for_size, minimum, natural);
|
||||
}
|
||||
|
||||
static void
|
||||
cell_set_size (Cell *cell,
|
||||
guint size)
|
||||
{
|
||||
if (cell->size == size)
|
||||
return;
|
||||
|
||||
cell->size = size;
|
||||
gtk_rb_tree_node_mark_dirty (cell);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_grid_view_size_allocate (GtkWidget *widget,
|
||||
int width,
|
||||
@ -749,24 +604,23 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
|
||||
int baseline)
|
||||
{
|
||||
GtkGridView *self = GTK_GRID_VIEW (widget);
|
||||
Cell *cell, *start;
|
||||
GtkListTile *tile, *start;
|
||||
GArray *heights;
|
||||
int min_row_height, row_height, col_min, col_nat;
|
||||
GtkOrientation orientation, opposite_orientation;
|
||||
int min_row_height, unknown_row_height, row_height, col_min, col_nat;
|
||||
GtkOrientation orientation;
|
||||
GtkScrollablePolicy scroll_policy;
|
||||
gboolean known;
|
||||
int x, y;
|
||||
int y;
|
||||
guint i;
|
||||
|
||||
orientation = gtk_list_base_get_orientation (GTK_LIST_BASE (self));
|
||||
scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), orientation);
|
||||
opposite_orientation = OPPOSITE_ORIENTATION (orientation);
|
||||
min_row_height = ceil ((double) height / GTK_GRID_VIEW_MAX_VISIBLE_ROWS);
|
||||
|
||||
/* step 0: exit early if list is empty */
|
||||
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
|
||||
tile = gtk_list_tile_gc (self->item_manager, gtk_list_item_manager_get_first (self->item_manager));
|
||||
if (tile == NULL)
|
||||
{
|
||||
gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
|
||||
gtk_list_base_allocate (GTK_LIST_BASE (self));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -781,149 +635,126 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
|
||||
/* step 2: determine height of known rows */
|
||||
heights = g_array_new (FALSE, FALSE, sizeof (int));
|
||||
|
||||
i = 0;
|
||||
row_height = 0;
|
||||
start = NULL;
|
||||
for (cell = gtk_list_item_manager_get_first (self->item_manager);
|
||||
cell != NULL;
|
||||
cell = gtk_rb_tree_node_get_next (cell))
|
||||
for (;
|
||||
tile != NULL;
|
||||
tile = gtk_list_tile_gc (self->item_manager, tile))
|
||||
{
|
||||
if (i == 0)
|
||||
start = cell;
|
||||
|
||||
if (cell->parent.widget)
|
||||
/* if it's a multirow tile, handle it here */
|
||||
if (tile->n_items > 1 && tile->n_items >= self->n_columns)
|
||||
{
|
||||
int min, nat, size;
|
||||
gtk_widget_measure (cell->parent.widget,
|
||||
gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
|
||||
self->column_width,
|
||||
&min, &nat, NULL, NULL);
|
||||
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
||||
size = min;
|
||||
else
|
||||
size = nat;
|
||||
size = MAX (size, min_row_height);
|
||||
g_array_append_val (heights, size);
|
||||
row_height = MAX (row_height, size);
|
||||
if (tile->n_items % self->n_columns)
|
||||
gtk_list_tile_split (self->item_manager, tile, tile->n_items / self->n_columns * self->n_columns);
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
continue;
|
||||
}
|
||||
cell_set_size (cell, 0);
|
||||
i += cell->parent.n_items;
|
||||
|
||||
if (i >= self->n_columns)
|
||||
/* Not a multirow tile */
|
||||
i = 0;
|
||||
row_height = 0;
|
||||
|
||||
for (i = 0, start = tile;
|
||||
i < self->n_columns && tile != NULL;
|
||||
tile = gtk_list_tile_gc (self->item_manager, gtk_rb_tree_node_get_next (tile)))
|
||||
{
|
||||
i %= self->n_columns;
|
||||
|
||||
cell_set_size (start, start->size + row_height);
|
||||
start = cell;
|
||||
row_height = 0;
|
||||
if (tile->widget)
|
||||
{
|
||||
int min, nat, size;
|
||||
gtk_widget_measure (tile->widget,
|
||||
gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
|
||||
self->column_width,
|
||||
&min, &nat, NULL, NULL);
|
||||
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
||||
size = min;
|
||||
else
|
||||
size = nat;
|
||||
size = MAX (size, min_row_height);
|
||||
g_array_append_val (heights, size);
|
||||
row_height = MAX (row_height, size);
|
||||
}
|
||||
if (tile->n_items > self->n_columns - i)
|
||||
gtk_list_tile_split (self->item_manager, tile, self->n_columns - i);
|
||||
i += tile->n_items;
|
||||
}
|
||||
if (row_height > 0)
|
||||
{
|
||||
for (i = 0;
|
||||
start != tile;
|
||||
start = gtk_rb_tree_node_get_next (start))
|
||||
{
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
start,
|
||||
ceil (self->column_width * (i + start->n_items)) - ceil (self->column_width * i),
|
||||
row_height);
|
||||
i += start->n_items;
|
||||
}
|
||||
g_assert (i <= self->n_columns);
|
||||
}
|
||||
}
|
||||
if (i > 0)
|
||||
cell_set_size (start, start->size + row_height);
|
||||
|
||||
/* step 3: determine height of rows with only unknown items */
|
||||
self->unknown_row_height = gtk_grid_view_get_unknown_row_size (self, heights);
|
||||
unknown_row_height = gtk_grid_view_get_unknown_row_size (self, heights);
|
||||
g_array_free (heights, TRUE);
|
||||
|
||||
/* step 4: determine height for remaining rows and set each row's position */
|
||||
y = 0;
|
||||
i = 0;
|
||||
known = FALSE;
|
||||
for (start = cell = gtk_list_item_manager_get_first (self->item_manager);
|
||||
cell != NULL;
|
||||
cell = gtk_rb_tree_node_get_next (cell))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (i == 0)
|
||||
start = cell;
|
||||
|
||||
if (cell->parent.widget)
|
||||
known = TRUE;
|
||||
|
||||
i += cell->parent.n_items;
|
||||
if (i >= self->n_columns)
|
||||
gtk_list_tile_set_area_position (self->item_manager,
|
||||
tile,
|
||||
ceil (self->column_width * i),
|
||||
y);
|
||||
if (tile->n_items >= self->n_columns && tile->widget == NULL)
|
||||
{
|
||||
if (!known)
|
||||
cell_set_size (start, start->size + self->unknown_row_height);
|
||||
|
||||
i -= self->n_columns;
|
||||
known = FALSE;
|
||||
|
||||
if (i >= self->n_columns)
|
||||
{
|
||||
cell_set_size (cell, cell->size + self->unknown_row_height * (i / self->n_columns));
|
||||
i %= self->n_columns;
|
||||
}
|
||||
start = cell;
|
||||
}
|
||||
}
|
||||
if (i > 0 && !known)
|
||||
cell_set_size (start, start->size + self->unknown_row_height);
|
||||
|
||||
/* step 4: update the adjustments */
|
||||
gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
|
||||
self->column_width * self->n_columns,
|
||||
gtk_grid_view_compute_total_height (self),
|
||||
gtk_widget_get_size (widget, opposite_orientation),
|
||||
gtk_widget_get_size (widget, orientation),
|
||||
&x, &y);
|
||||
|
||||
/* step 5: run the size_allocate loop */
|
||||
x = -x;
|
||||
y = -y;
|
||||
i = 0;
|
||||
row_height = 0;
|
||||
|
||||
g_assert (self->n_columns > 0);
|
||||
|
||||
for (cell = gtk_list_item_manager_get_first (self->item_manager);
|
||||
cell != NULL;
|
||||
cell = gtk_rb_tree_node_get_next (cell))
|
||||
{
|
||||
if (cell->parent.widget)
|
||||
{
|
||||
row_height += cell->size;
|
||||
|
||||
gtk_list_base_size_allocate_child (GTK_LIST_BASE (self),
|
||||
cell->parent.widget,
|
||||
x + ceil (self->column_width * i),
|
||||
y,
|
||||
ceil (self->column_width * (i + 1)) - ceil (self->column_width * i),
|
||||
row_height);
|
||||
i++;
|
||||
if (i >= self->n_columns)
|
||||
{
|
||||
y += row_height;
|
||||
i -= self->n_columns;
|
||||
row_height = 0;
|
||||
}
|
||||
g_assert (i == 0);
|
||||
g_assert (tile->n_items % self->n_columns == 0);
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
tile,
|
||||
ceil (self->column_width * self->n_columns),
|
||||
unknown_row_height * (tile->n_items / self->n_columns));
|
||||
y += tile->area.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
i += cell->parent.n_items;
|
||||
/* skip remaining row if we didn't start one */
|
||||
if (i > cell->parent.n_items && i >= self->n_columns)
|
||||
if (tile->area.height == 0)
|
||||
{
|
||||
i -= self->n_columns;
|
||||
y += row_height;
|
||||
row_height = 0;
|
||||
/* this case is for the last row - it may not be a full row so it won't
|
||||
* be a multirow tile but it may have no widgets either */
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
tile,
|
||||
ceil (self->column_width * (i + tile->n_items)) - ceil (self->column_width * i),
|
||||
unknown_row_height);
|
||||
}
|
||||
i += tile->n_items;
|
||||
}
|
||||
|
||||
row_height += cell->size;
|
||||
|
||||
/* skip rows that are completely contained by this cell */
|
||||
if (i >= self->n_columns)
|
||||
{
|
||||
guint unknown_rows, unknown_height;
|
||||
|
||||
unknown_rows = i / self->n_columns;
|
||||
unknown_height = unknown_rows * self->unknown_row_height;
|
||||
row_height -= unknown_height;
|
||||
y += unknown_height;
|
||||
i %= self->n_columns;
|
||||
g_assert (row_height >= 0);
|
||||
}
|
||||
if (i >= self->n_columns)
|
||||
{
|
||||
g_assert (i == self->n_columns);
|
||||
y += tile->area.height;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
/* Add a filler tile for empty space in the bottom right */
|
||||
if (i < self->n_columns)
|
||||
{
|
||||
GtkListTile *filler;
|
||||
tile = gtk_list_item_manager_get_last (self->item_manager);
|
||||
filler = gtk_list_tile_split (self->item_manager, tile, tile->n_items);
|
||||
gtk_list_tile_set_area_position (self->item_manager,
|
||||
filler,
|
||||
ceil (self->column_width * i),
|
||||
y);
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
filler,
|
||||
ceil (self->column_width * self->n_columns) - filler->area.x,
|
||||
tile->area.height);
|
||||
}
|
||||
|
||||
gtk_list_base_allocate_rubberband (GTK_LIST_BASE (widget));
|
||||
/* step 4: allocate the rest */
|
||||
gtk_list_base_allocate (GTK_LIST_BASE (self));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1043,11 +874,8 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
|
||||
|
||||
list_base_class->list_item_name = "child";
|
||||
list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_GRID_CELL;
|
||||
list_base_class->list_item_size = sizeof (Cell);
|
||||
list_base_class->list_item_augment_size = sizeof (CellAugment);
|
||||
list_base_class->list_item_augment_func = cell_augment;
|
||||
list_base_class->get_allocation_along = gtk_grid_view_get_allocation_along;
|
||||
list_base_class->get_allocation_across = gtk_grid_view_get_allocation_across;
|
||||
list_base_class->split = gtk_grid_view_split;
|
||||
list_base_class->get_allocation = gtk_grid_view_get_allocation;
|
||||
list_base_class->get_items_in_rect = gtk_grid_view_get_items_in_rect;
|
||||
list_base_class->get_position_from_allocation = gtk_grid_view_get_position_from_allocation;
|
||||
list_base_class->move_focus_along = gtk_grid_view_move_focus_along;
|
||||
|
@ -327,49 +327,22 @@ gtk_list_base_move_focus (GtkListBase *self,
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_list_base_get_allocation_along:
|
||||
* gtk_list_base_get_allocation:
|
||||
* @self: a `GtkListBase`
|
||||
* @pos: item to get the size of
|
||||
* @offset: (out caller-allocates) (optional): set to the offset
|
||||
* of the top/left of the item
|
||||
* @size: (out caller-allocates) (optional): set to the size of
|
||||
* the item in the direction
|
||||
* @pos: item to get the area of
|
||||
* @area: (out caller-allocates): set to the area
|
||||
* occupied by the item
|
||||
*
|
||||
* Computes the allocation of the item in the direction along the sizing
|
||||
* axis.
|
||||
* Computes the allocation of the item in the given position
|
||||
*
|
||||
* Returns: %TRUE if the item exists and has an allocation, %FALSE otherwise
|
||||
**/
|
||||
static gboolean
|
||||
gtk_list_base_get_allocation_along (GtkListBase *self,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size)
|
||||
gtk_list_base_get_allocation (GtkListBase *self,
|
||||
guint pos,
|
||||
GdkRectangle *area)
|
||||
{
|
||||
return GTK_LIST_BASE_GET_CLASS (self)->get_allocation_along (self, pos, offset, size);
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_list_base_get_allocation_across:
|
||||
* @self: a `GtkListBase`
|
||||
* @pos: item to get the size of
|
||||
* @offset: (out caller-allocates) (optional): set to the offset
|
||||
* of the top/left of the item
|
||||
* @size: (out caller-allocates) (optional): set to the size of
|
||||
* the item in the direction
|
||||
*
|
||||
* Computes the allocation of the item in the direction across to the sizing
|
||||
* axis.
|
||||
*
|
||||
* Returns: %TRUE if the item exists and has an allocation, %FALSE otherwise
|
||||
**/
|
||||
static gboolean
|
||||
gtk_list_base_get_allocation_across (GtkListBase *self,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size)
|
||||
{
|
||||
return GTK_LIST_BASE_GET_CLASS (self)->get_allocation_across (self, pos, offset, size);
|
||||
return GTK_LIST_BASE_GET_CLASS (self)->get_allocation (self, pos, area);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -492,7 +465,7 @@ gtk_list_base_focus (GtkWidget *widget,
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
guint old, pos, n_items;
|
||||
GtkWidget *focus_child;
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
|
||||
focus_child = gtk_widget_get_focus_child (widget);
|
||||
/* focus is moving around fine inside the focus child, don't disturb it */
|
||||
@ -558,15 +531,15 @@ gtk_list_base_focus (GtkWidget *widget,
|
||||
if (old == pos)
|
||||
return TRUE;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (priv->item_manager, pos, NULL);
|
||||
if (item == NULL)
|
||||
tile = gtk_list_item_manager_get_nth (priv->item_manager, pos, NULL);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* This shouldn't really happen, but if it does, oh well */
|
||||
if (item->widget == NULL)
|
||||
if (tile->widget == NULL)
|
||||
return gtk_list_base_grab_focus_on_item (GTK_LIST_BASE (self), pos, TRUE, FALSE, FALSE);
|
||||
|
||||
return gtk_widget_child_focus (item->widget, direction);
|
||||
return gtk_widget_child_focus (tile->widget, direction);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -807,29 +780,22 @@ gtk_list_base_scroll_to_item (GtkListBase *self,
|
||||
guint pos)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
int start, end;
|
||||
double align_along, align_across;
|
||||
GtkPackType side_along, side_across;
|
||||
GdkRectangle area;
|
||||
|
||||
/* figure out primary orientation and if position is valid */
|
||||
if (!gtk_list_base_get_allocation_along (GTK_LIST_BASE (self), pos, &start, &end))
|
||||
if (!gtk_list_base_get_allocation (GTK_LIST_BASE (self), pos, &area))
|
||||
return;
|
||||
|
||||
end += start;
|
||||
gtk_list_base_compute_scroll_align (self,
|
||||
gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
|
||||
start, end,
|
||||
area.y, area.y + area.height,
|
||||
priv->anchor_align_along, priv->anchor_side_along,
|
||||
&align_along, &side_along);
|
||||
|
||||
/* now do the same thing with the other orientation */
|
||||
if (!gtk_list_base_get_allocation_across (GTK_LIST_BASE (self), pos, &start, &end))
|
||||
return;
|
||||
|
||||
end += start;
|
||||
gtk_list_base_compute_scroll_align (self,
|
||||
gtk_list_base_get_opposite_orientation (GTK_LIST_BASE (self)),
|
||||
start, end,
|
||||
area.x, area.x + area.width,
|
||||
priv->anchor_align_across, priv->anchor_side_across,
|
||||
&align_across, &side_across);
|
||||
|
||||
@ -959,8 +925,7 @@ gtk_list_base_move_cursor_page_up (GtkWidget *widget,
|
||||
|
||||
pos = gtk_list_base_get_focus_position (self);
|
||||
page_size = gtk_adjustment_get_page_size (priv->adjustment[priv->orientation]);
|
||||
if (!gtk_list_base_get_allocation_along (self, pos, &area.y, &area.height) ||
|
||||
!gtk_list_base_get_allocation_across (self, pos, &area.x, &area.width))
|
||||
if (!gtk_list_base_get_allocation (self, pos, &area))
|
||||
return TRUE;
|
||||
if (!gtk_list_base_get_position_from_allocation (self,
|
||||
area.x + area.width / 2,
|
||||
@ -1005,8 +970,7 @@ gtk_list_base_move_cursor_page_down (GtkWidget *widget,
|
||||
if (end == 0)
|
||||
return TRUE;
|
||||
|
||||
if (!gtk_list_base_get_allocation_along (self, pos, &area.y, &area.height) ||
|
||||
!gtk_list_base_get_allocation_across (self, pos, &area.x, &area.width))
|
||||
if (!gtk_list_base_get_allocation (self, pos, &area))
|
||||
return TRUE;
|
||||
|
||||
if (!gtk_list_base_get_position_from_allocation (self,
|
||||
@ -1355,7 +1319,7 @@ update_autoscroll (GtkListBase *self,
|
||||
remove_autoscroll (self);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* gtk_list_base_size_allocate_child:
|
||||
* @self: The listbase
|
||||
* @child: The child
|
||||
@ -1368,7 +1332,7 @@ update_autoscroll (GtkListBase *self,
|
||||
* but with the coordinates already offset by the scroll
|
||||
* offset.
|
||||
**/
|
||||
void
|
||||
static void
|
||||
gtk_list_base_size_allocate_child (GtkListBase *self,
|
||||
GtkWidget *child,
|
||||
int x,
|
||||
@ -1432,6 +1396,32 @@ gtk_list_base_size_allocate_child (GtkListBase *self,
|
||||
gtk_widget_size_allocate (child, &child_allocation, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_base_allocate_children (GtkListBase *self)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
GtkListTile *tile;
|
||||
int dx, dy;
|
||||
|
||||
gtk_list_base_get_adjustment_values (self, OPPOSITE_ORIENTATION (priv->orientation), &dx, NULL, NULL);
|
||||
gtk_list_base_get_adjustment_values (self, priv->orientation, &dy, NULL, NULL);
|
||||
|
||||
for (tile = gtk_list_item_manager_get_first (priv->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (tile->widget)
|
||||
{
|
||||
gtk_list_base_size_allocate_child (GTK_LIST_BASE (self),
|
||||
tile->widget,
|
||||
tile->area.x - dx,
|
||||
tile->area.y - dy,
|
||||
tile->area.width,
|
||||
tile->area.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_base_widget_to_list (GtkListBase *self,
|
||||
double x_widget,
|
||||
@ -1484,13 +1474,13 @@ gtk_list_base_get_rubberband_coords (GtkListBase *self,
|
||||
}
|
||||
else
|
||||
{
|
||||
GdkRectangle area;
|
||||
guint pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->rubberband->start_tracker);
|
||||
|
||||
if (gtk_list_base_get_allocation_along (self, pos, &y1, &y2) &&
|
||||
gtk_list_base_get_allocation_across (self, pos, &x1, &x2))
|
||||
if (gtk_list_base_get_allocation (self, pos, &area))
|
||||
{
|
||||
x1 += x2 * priv->rubberband->start_align_across;
|
||||
y1 += y2 * priv->rubberband->start_align_along;
|
||||
x1 = area.x + area.width * priv->rubberband->start_align_across;
|
||||
y1 = area.y + area.height * priv->rubberband->start_align_along;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1511,7 +1501,7 @@ gtk_list_base_get_rubberband_coords (GtkListBase *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
gtk_list_base_allocate_rubberband (GtkListBase *self)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
@ -1648,17 +1638,17 @@ static void
|
||||
gtk_list_base_stop_rubberband (GtkListBase *self)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
|
||||
if (!priv->rubberband)
|
||||
return;
|
||||
|
||||
for (item = gtk_list_item_manager_get_first (priv->item_manager);
|
||||
item != NULL;
|
||||
item = gtk_rb_tree_node_get_next (item))
|
||||
for (tile = gtk_list_item_manager_get_first (priv->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (item->widget)
|
||||
gtk_widget_unset_state_flags (item->widget, GTK_STATE_FLAG_ACTIVE);
|
||||
if (tile->widget)
|
||||
gtk_widget_unset_state_flags (tile->widget, GTK_STATE_FLAG_ACTIVE);
|
||||
}
|
||||
|
||||
gtk_list_item_tracker_free (priv->item_manager, priv->rubberband->start_tracker);
|
||||
@ -1673,7 +1663,7 @@ static void
|
||||
gtk_list_base_update_rubberband_selection (GtkListBase *self)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
GdkRectangle rect;
|
||||
guint pos;
|
||||
GtkBitset *rubberband_selection;
|
||||
@ -1684,19 +1674,19 @@ gtk_list_base_update_rubberband_selection (GtkListBase *self)
|
||||
rubberband_selection = gtk_list_base_get_items_in_rect (self, &rect);
|
||||
|
||||
pos = 0;
|
||||
for (item = gtk_list_item_manager_get_first (priv->item_manager);
|
||||
item != NULL;
|
||||
item = gtk_rb_tree_node_get_next (item))
|
||||
for (tile = gtk_list_item_manager_get_first (priv->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (item->widget)
|
||||
if (tile->widget)
|
||||
{
|
||||
if (gtk_bitset_contains (rubberband_selection, pos))
|
||||
gtk_widget_set_state_flags (item->widget, GTK_STATE_FLAG_ACTIVE, FALSE);
|
||||
gtk_widget_set_state_flags (tile->widget, GTK_STATE_FLAG_ACTIVE, FALSE);
|
||||
else
|
||||
gtk_widget_unset_state_flags (item->widget, GTK_STATE_FLAG_ACTIVE);
|
||||
gtk_widget_unset_state_flags (tile->widget, GTK_STATE_FLAG_ACTIVE);
|
||||
}
|
||||
|
||||
pos += item->n_items;
|
||||
pos += tile->n_items;
|
||||
}
|
||||
|
||||
gtk_bitset_unref (rubberband_selection);
|
||||
@ -1844,6 +1834,14 @@ gtk_list_base_drag_leave (GtkDropControllerMotion *motion,
|
||||
remove_autoscroll (GTK_LIST_BASE (widget));
|
||||
}
|
||||
|
||||
static GtkListTile *
|
||||
gtk_list_base_split_func (gpointer data,
|
||||
GtkListTile *tile,
|
||||
guint n_items)
|
||||
{
|
||||
return GTK_LIST_BASE_GET_CLASS (data)->split (data, tile, n_items);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_base_init_real (GtkListBase *self,
|
||||
GtkListBaseClass *g_class)
|
||||
@ -1851,12 +1849,11 @@ gtk_list_base_init_real (GtkListBase *self,
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
GtkEventController *controller;
|
||||
|
||||
priv->item_manager = gtk_list_item_manager_new_for_size (GTK_WIDGET (self),
|
||||
g_class->list_item_name,
|
||||
g_class->list_item_role,
|
||||
g_class->list_item_size,
|
||||
g_class->list_item_augment_size,
|
||||
g_class->list_item_augment_func);
|
||||
priv->item_manager = gtk_list_item_manager_new (GTK_WIDGET (self),
|
||||
g_class->list_item_name,
|
||||
g_class->list_item_role,
|
||||
gtk_list_base_split_func,
|
||||
self);
|
||||
priv->anchor = gtk_list_item_tracker_new (priv->item_manager);
|
||||
priv->anchor_side_along = GTK_PACK_START;
|
||||
priv->anchor_side_across = GTK_PACK_START;
|
||||
@ -1879,7 +1876,7 @@ gtk_list_base_init_real (GtkListBase *self,
|
||||
gtk_widget_add_controller (GTK_WIDGET (self), controller);
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
gtk_list_base_set_adjustment_values (GtkListBase *self,
|
||||
GtkOrientation orientation,
|
||||
int value,
|
||||
@ -1907,23 +1904,24 @@ gtk_list_base_set_adjustment_values (GtkListBase *self,
|
||||
g_signal_handlers_unblock_by_func (priv->adjustment[orientation],
|
||||
gtk_list_base_adjustment_value_changed_cb,
|
||||
self);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_base_update_adjustments (GtkListBase *self,
|
||||
int total_across,
|
||||
int total_along,
|
||||
int page_across,
|
||||
int page_along,
|
||||
int *across,
|
||||
int *along)
|
||||
static void
|
||||
gtk_list_base_update_adjustments (GtkListBase *self)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
int value_along, value_across, size;
|
||||
GdkRectangle bounds;
|
||||
int value_along, value_across;
|
||||
int page_along, page_across;
|
||||
guint pos;
|
||||
|
||||
gtk_list_item_manager_get_tile_bounds (priv->item_manager, &bounds);
|
||||
g_assert (bounds.x == 0);
|
||||
g_assert (bounds.y == 0);
|
||||
|
||||
page_across = gtk_widget_get_size (GTK_WIDGET (self), OPPOSITE_ORIENTATION (priv->orientation));
|
||||
page_along = gtk_widget_get_size (GTK_WIDGET (self), priv->orientation);
|
||||
|
||||
pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->anchor);
|
||||
if (pos == GTK_INVALID_LIST_POSITION)
|
||||
{
|
||||
@ -1932,38 +1930,45 @@ gtk_list_base_update_adjustments (GtkListBase *self,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gtk_list_base_get_allocation_across (self, pos, &value_across, &size))
|
||||
GdkRectangle area;
|
||||
|
||||
if (gtk_list_base_get_allocation (self, pos, &area))
|
||||
{
|
||||
value_across = area.x;
|
||||
value_along = area.y;
|
||||
if (priv->anchor_side_across == GTK_PACK_END)
|
||||
value_across += size;
|
||||
value_across -= priv->anchor_align_across * page_across;
|
||||
}
|
||||
else
|
||||
{
|
||||
value_along = 0;
|
||||
}
|
||||
if (gtk_list_base_get_allocation_along (self, pos, &value_along, &size))
|
||||
{
|
||||
value_across += area.width;
|
||||
if (priv->anchor_side_along == GTK_PACK_END)
|
||||
value_along += size;
|
||||
value_along += area.height;
|
||||
value_across -= priv->anchor_align_across * page_across;
|
||||
value_along -= priv->anchor_align_along * page_along;
|
||||
}
|
||||
else
|
||||
{
|
||||
value_across = 0;
|
||||
value_along = 0;
|
||||
}
|
||||
}
|
||||
|
||||
*across = gtk_list_base_set_adjustment_values (self,
|
||||
OPPOSITE_ORIENTATION (priv->orientation),
|
||||
value_across,
|
||||
total_across,
|
||||
page_across);
|
||||
*along = gtk_list_base_set_adjustment_values (self,
|
||||
priv->orientation,
|
||||
value_along,
|
||||
total_along,
|
||||
page_along);
|
||||
gtk_list_base_set_adjustment_values (self,
|
||||
OPPOSITE_ORIENTATION (priv->orientation),
|
||||
value_across,
|
||||
bounds.width,
|
||||
page_across);
|
||||
gtk_list_base_set_adjustment_values (self,
|
||||
priv->orientation,
|
||||
value_along,
|
||||
bounds.height,
|
||||
page_along);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_base_allocate (GtkListBase *self)
|
||||
{
|
||||
gtk_list_base_update_adjustments (self);
|
||||
|
||||
gtk_list_base_allocate_children (self);
|
||||
gtk_list_base_allocate_rubberband (self);
|
||||
}
|
||||
|
||||
GtkScrollablePolicy
|
||||
@ -2124,14 +2129,14 @@ gtk_list_base_grab_focus_on_item (GtkListBase *self,
|
||||
gboolean extend)
|
||||
{
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
gboolean success;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (priv->item_manager, pos, NULL);
|
||||
if (item == NULL)
|
||||
tile = gtk_list_item_manager_get_nth (priv->item_manager, pos, NULL);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (!item->widget)
|
||||
if (!tile->widget)
|
||||
{
|
||||
GtkListItemTracker *tracker = gtk_list_item_tracker_new (priv->item_manager);
|
||||
|
||||
@ -2141,16 +2146,16 @@ gtk_list_base_grab_focus_on_item (GtkListBase *self,
|
||||
* so we create a temporary one. */
|
||||
gtk_list_item_tracker_set_position (priv->item_manager, tracker, pos, 0, 0);
|
||||
|
||||
item = gtk_list_item_manager_get_nth (priv->item_manager, pos, NULL);
|
||||
g_assert (item->widget);
|
||||
tile = gtk_list_item_manager_get_nth (priv->item_manager, pos, NULL);
|
||||
g_assert (tile->widget);
|
||||
|
||||
success = gtk_widget_grab_focus (item->widget);
|
||||
success = gtk_widget_grab_focus (tile->widget);
|
||||
|
||||
gtk_list_item_tracker_free (priv->item_manager, tracker);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = gtk_widget_grab_focus (item->widget);
|
||||
success = gtk_widget_grab_focus (tile->widget);
|
||||
}
|
||||
|
||||
if (!success)
|
||||
|
@ -36,20 +36,14 @@ struct _GtkListBaseClass
|
||||
|
||||
const char * list_item_name;
|
||||
GtkAccessibleRole list_item_role;
|
||||
gsize list_item_size;
|
||||
gsize list_item_augment_size;
|
||||
GtkRbTreeAugmentFunc list_item_augment_func;
|
||||
|
||||
void (* adjustment_value_changed) (GtkListBase *self,
|
||||
GtkOrientation orientation);
|
||||
gboolean (* get_allocation_along) (GtkListBase *self,
|
||||
GtkListTile * (* split) (GtkListBase *self,
|
||||
GtkListTile *tile,
|
||||
guint n_items);
|
||||
|
||||
gboolean (* get_allocation) (GtkListBase *self,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size);
|
||||
gboolean (* get_allocation_across) (GtkListBase *self,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size);
|
||||
GdkRectangle *area);
|
||||
gboolean (* get_position_from_allocation) (GtkListBase *self,
|
||||
int across,
|
||||
int along,
|
||||
@ -75,13 +69,6 @@ guint gtk_list_base_get_n_items (GtkListBase
|
||||
GtkSelectionModel * gtk_list_base_get_model (GtkListBase *self);
|
||||
gboolean gtk_list_base_set_model (GtkListBase *self,
|
||||
GtkSelectionModel *model);
|
||||
void gtk_list_base_update_adjustments (GtkListBase *self,
|
||||
int total_across,
|
||||
int total_along,
|
||||
int page_across,
|
||||
int page_along,
|
||||
int *across,
|
||||
int *along);
|
||||
|
||||
guint gtk_list_base_get_anchor (GtkListBase *self);
|
||||
void gtk_list_base_set_anchor (GtkListBase *self,
|
||||
@ -106,13 +93,7 @@ gboolean gtk_list_base_grab_focus_on_item (GtkListBase
|
||||
void gtk_list_base_set_enable_rubberband (GtkListBase *self,
|
||||
gboolean enable);
|
||||
gboolean gtk_list_base_get_enable_rubberband (GtkListBase *self);
|
||||
void gtk_list_base_allocate_rubberband (GtkListBase *self);
|
||||
|
||||
void gtk_list_base_size_allocate_child (GtkListBase *self,
|
||||
GtkWidget *child,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height);
|
||||
void gtk_list_base_allocate (GtkListBase *self);
|
||||
|
||||
#endif /* __GTK_LIST_BASE_PRIVATE_H__ */
|
||||
|
@ -39,6 +39,9 @@ struct _GtkListItemManager
|
||||
|
||||
GtkRbTree *items;
|
||||
GSList *trackers;
|
||||
|
||||
GtkListTile * (* split_func) (gpointer, GtkListTile *, guint);
|
||||
gpointer user_data;
|
||||
};
|
||||
|
||||
struct _GtkListItemManagerClass
|
||||
@ -74,54 +77,70 @@ static void gtk_list_item_manager_release_list_item (GtkListItemMana
|
||||
GtkWidget *widget);
|
||||
G_DEFINE_TYPE (GtkListItemManager, gtk_list_item_manager, G_TYPE_OBJECT)
|
||||
|
||||
void
|
||||
static void
|
||||
potentially_empty_rectangle_union (cairo_rectangle_int_t *self,
|
||||
const cairo_rectangle_int_t *area)
|
||||
{
|
||||
if (area->width <= 0 || area->height <= 0)
|
||||
return;
|
||||
|
||||
if (self->width <= 0 || self->height <= 0)
|
||||
{
|
||||
*self = *area;
|
||||
return;
|
||||
}
|
||||
|
||||
gdk_rectangle_union (self, area, self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_manager_augment_node (GtkRbTree *tree,
|
||||
gpointer node_augment,
|
||||
gpointer node,
|
||||
gpointer left,
|
||||
gpointer right)
|
||||
{
|
||||
GtkListItemManagerItem *item = node;
|
||||
GtkListItemManagerItemAugment *aug = node_augment;
|
||||
GtkListTile *tile = node;
|
||||
GtkListTileAugment *aug = node_augment;
|
||||
|
||||
aug->n_items = item->n_items;
|
||||
aug->n_items = tile->n_items;
|
||||
aug->area = tile->area;
|
||||
|
||||
if (left)
|
||||
{
|
||||
GtkListItemManagerItemAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
|
||||
GtkListTileAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
|
||||
|
||||
aug->n_items += left_aug->n_items;
|
||||
potentially_empty_rectangle_union (&aug->area, &left_aug->area);
|
||||
}
|
||||
|
||||
if (right)
|
||||
{
|
||||
GtkListItemManagerItemAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
|
||||
GtkListTileAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
|
||||
|
||||
aug->n_items += right_aug->n_items;
|
||||
potentially_empty_rectangle_union (&aug->area, &right_aug->area);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_manager_clear_node (gpointer _item)
|
||||
gtk_list_item_manager_clear_node (gpointer _tile)
|
||||
{
|
||||
GtkListItemManagerItem *item G_GNUC_UNUSED = _item;
|
||||
GtkListTile *tile G_GNUC_UNUSED = _tile;
|
||||
|
||||
g_assert (item->widget == NULL);
|
||||
g_assert (tile->widget == NULL);
|
||||
}
|
||||
|
||||
GtkListItemManager *
|
||||
gtk_list_item_manager_new_for_size (GtkWidget *widget,
|
||||
const char *item_css_name,
|
||||
GtkAccessibleRole item_role,
|
||||
gsize element_size,
|
||||
gsize augment_size,
|
||||
GtkRbTreeAugmentFunc augment_func)
|
||||
gtk_list_item_manager_new (GtkWidget *widget,
|
||||
const char *item_css_name,
|
||||
GtkAccessibleRole item_role,
|
||||
GtkListTile * (* split_func) (gpointer, GtkListTile *, guint),
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkListItemManager *self;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
||||
g_return_val_if_fail (element_size >= sizeof (GtkListItemManagerItem), NULL);
|
||||
g_return_val_if_fail (augment_size >= sizeof (GtkListItemManagerItemAugment), NULL);
|
||||
|
||||
self = g_object_new (GTK_TYPE_LIST_ITEM_MANAGER, NULL);
|
||||
|
||||
@ -129,22 +148,48 @@ gtk_list_item_manager_new_for_size (GtkWidget *widget,
|
||||
self->widget = widget;
|
||||
self->item_css_name = g_intern_string (item_css_name);
|
||||
self->item_role = item_role;
|
||||
self->split_func = split_func;
|
||||
self->user_data = user_data;
|
||||
|
||||
self->items = gtk_rb_tree_new_for_size (element_size,
|
||||
augment_size,
|
||||
augment_func,
|
||||
self->items = gtk_rb_tree_new_for_size (sizeof (GtkListTile),
|
||||
sizeof (GtkListTileAugment),
|
||||
gtk_list_item_manager_augment_node,
|
||||
gtk_list_item_manager_clear_node,
|
||||
NULL);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_item_manager_get_tile_bounds (GtkListItemManager *self,
|
||||
GdkRectangle *out_bounds)
|
||||
{
|
||||
GtkListTile *tile;
|
||||
GtkListTileAugment *aug;
|
||||
|
||||
tile = gtk_rb_tree_get_root (self->items);
|
||||
if (tile == NULL)
|
||||
{
|
||||
*out_bounds = (GdkRectangle) { 0, 0, 0, 0 };
|
||||
return;
|
||||
}
|
||||
|
||||
aug = gtk_rb_tree_get_augment (self->items, tile);
|
||||
*out_bounds = aug->area;
|
||||
}
|
||||
|
||||
gpointer
|
||||
gtk_list_item_manager_get_first (GtkListItemManager *self)
|
||||
{
|
||||
return gtk_rb_tree_get_first (self->items);
|
||||
}
|
||||
|
||||
gpointer
|
||||
gtk_list_item_manager_get_last (GtkListItemManager *self)
|
||||
{
|
||||
return gtk_rb_tree_get_last (self->items);
|
||||
}
|
||||
|
||||
gpointer
|
||||
gtk_list_item_manager_get_root (GtkListItemManager *self)
|
||||
{
|
||||
@ -155,15 +200,15 @@ gtk_list_item_manager_get_root (GtkListItemManager *self)
|
||||
* gtk_list_item_manager_get_nth:
|
||||
* @self: a `GtkListItemManager`
|
||||
* @position: position of the item
|
||||
* @offset: (out): offset into the returned item
|
||||
* @offset: (out): offset into the returned tile
|
||||
*
|
||||
* Looks up the GtkListItemManagerItem that represents @position.
|
||||
* Looks up the GtkListTile that represents @position.
|
||||
*
|
||||
* If a the returned item represents multiple rows, the @offset into
|
||||
* the returned item for @position will be set. If the returned item
|
||||
* If a the returned tile represents multiple rows, the @offset into
|
||||
* the returned tile for @position will be set. If the returned tile
|
||||
* represents a row with an existing widget, @offset will always be 0.
|
||||
*
|
||||
* Returns: (type GtkListItemManagerItem): the item for @position or
|
||||
* Returns: (type GtkListTile): the tile for @position or
|
||||
* %NULL if position is out of range
|
||||
**/
|
||||
gpointer
|
||||
@ -171,48 +216,103 @@ gtk_list_item_manager_get_nth (GtkListItemManager *self,
|
||||
guint position,
|
||||
guint *offset)
|
||||
{
|
||||
GtkListItemManagerItem *item, *tmp;
|
||||
GtkListTile *tile, *tmp;
|
||||
|
||||
item = gtk_rb_tree_get_root (self->items);
|
||||
tile = gtk_rb_tree_get_root (self->items);
|
||||
|
||||
while (item)
|
||||
while (tile)
|
||||
{
|
||||
tmp = gtk_rb_tree_node_get_left (item);
|
||||
tmp = gtk_rb_tree_node_get_left (tile);
|
||||
if (tmp)
|
||||
{
|
||||
GtkListItemManagerItemAugment *aug = gtk_rb_tree_get_augment (self->items, tmp);
|
||||
GtkListTileAugment *aug = gtk_rb_tree_get_augment (self->items, tmp);
|
||||
if (position < aug->n_items)
|
||||
{
|
||||
item = tmp;
|
||||
tile = tmp;
|
||||
continue;
|
||||
}
|
||||
position -= aug->n_items;
|
||||
}
|
||||
|
||||
if (position < item->n_items)
|
||||
if (position < tile->n_items)
|
||||
break;
|
||||
position -= item->n_items;
|
||||
position -= tile->n_items;
|
||||
|
||||
item = gtk_rb_tree_node_get_right (item);
|
||||
tile = gtk_rb_tree_node_get_right (tile);
|
||||
}
|
||||
|
||||
if (offset)
|
||||
*offset = item ? position : 0;
|
||||
*offset = tile ? position : 0;
|
||||
|
||||
return item;
|
||||
return tile;
|
||||
}
|
||||
|
||||
static GtkListTile *
|
||||
gtk_list_tile_get_tile_at (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
GtkListTileAugment *aug;
|
||||
GtkListTile *subtile;
|
||||
|
||||
aug = gtk_list_tile_get_augment (self, tile);
|
||||
if (!gdk_rectangle_contains_point (&aug->area, x, y))
|
||||
return NULL;
|
||||
|
||||
subtile = gtk_rb_tree_node_get_left (tile);
|
||||
if (subtile)
|
||||
{
|
||||
subtile = gtk_list_tile_get_tile_at (self, subtile, x, y);
|
||||
if (subtile)
|
||||
return subtile;
|
||||
}
|
||||
|
||||
if (gdk_rectangle_contains_point (&tile->area, x, y))
|
||||
return tile;
|
||||
|
||||
subtile = gtk_rb_tree_node_get_right (tile);
|
||||
if (subtile)
|
||||
{
|
||||
subtile = gtk_list_tile_get_tile_at (self, subtile, x, y);
|
||||
if (subtile)
|
||||
return subtile;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_list_item_manager_get_tile_at:
|
||||
* @self: a GtkListItemManager
|
||||
* @x: x coordinate of tile
|
||||
* @y: y coordinate of tile
|
||||
*
|
||||
* Finds the tile occupying the coordinates at (x, y). If no
|
||||
* tile occupies the coordinates (for example, if the tile is out of bounds),
|
||||
* NULL is returned.
|
||||
*
|
||||
* Returns: (nullable): The tile at (x, y) or NULL
|
||||
**/
|
||||
GtkListTile *
|
||||
gtk_list_item_manager_get_tile_at (GtkListItemManager *self,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
return gtk_list_tile_get_tile_at (self, gtk_list_item_manager_get_root (self), x, y);
|
||||
}
|
||||
|
||||
guint
|
||||
gtk_list_item_manager_get_item_position (GtkListItemManager *self,
|
||||
gpointer item)
|
||||
gtk_list_tile_get_position (GtkListItemManager *self,
|
||||
GtkListTile *tile)
|
||||
{
|
||||
GtkListItemManagerItem *parent, *left;
|
||||
GtkListTile *parent, *left;
|
||||
int pos;
|
||||
|
||||
left = gtk_rb_tree_node_get_left (item);
|
||||
left = gtk_rb_tree_node_get_left (tile);
|
||||
if (left)
|
||||
{
|
||||
GtkListItemManagerItemAugment *aug = gtk_rb_tree_get_augment (self->items, left);
|
||||
GtkListTileAugment *aug = gtk_rb_tree_get_augment (self->items, left);
|
||||
pos = aug->n_items;
|
||||
}
|
||||
else
|
||||
@ -220,33 +320,93 @@ gtk_list_item_manager_get_item_position (GtkListItemManager *self,
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
for (parent = gtk_rb_tree_node_get_parent (item);
|
||||
for (parent = gtk_rb_tree_node_get_parent (tile);
|
||||
parent != NULL;
|
||||
parent = gtk_rb_tree_node_get_parent (item))
|
||||
parent = gtk_rb_tree_node_get_parent (tile))
|
||||
{
|
||||
left = gtk_rb_tree_node_get_left (parent);
|
||||
|
||||
if (left != item)
|
||||
if (left != tile)
|
||||
{
|
||||
if (left)
|
||||
{
|
||||
GtkListItemManagerItemAugment *aug = gtk_rb_tree_get_augment (self->items, left);
|
||||
GtkListTileAugment *aug = gtk_rb_tree_get_augment (self->items, left);
|
||||
pos += aug->n_items;
|
||||
}
|
||||
pos += parent->n_items;
|
||||
}
|
||||
|
||||
item = parent;
|
||||
tile = parent;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
gpointer
|
||||
gtk_list_item_manager_get_item_augment (GtkListItemManager *self,
|
||||
gpointer item)
|
||||
gtk_list_tile_get_augment (GtkListItemManager *self,
|
||||
GtkListTile *tile)
|
||||
{
|
||||
return gtk_rb_tree_get_augment (self->items, item);
|
||||
return gtk_rb_tree_get_augment (self->items, tile);
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_list_tile_set_area:
|
||||
* @self: the list item manager
|
||||
* @tile: tile to set area for
|
||||
* @area: (nullable): area to set or NULL to clear
|
||||
* the area
|
||||
*
|
||||
* Updates the area of the tile.
|
||||
*
|
||||
* The area is given in the internal coordinate system,
|
||||
* so the x/y flip due to orientation and the left/right
|
||||
* flip for RTL languages will happen later.
|
||||
*
|
||||
* This function should only be called from inside size_allocate().
|
||||
**/
|
||||
void
|
||||
gtk_list_tile_set_area (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
const cairo_rectangle_int_t *area)
|
||||
{
|
||||
cairo_rectangle_int_t empty_area = { 0, 0, 0, 0 };
|
||||
|
||||
if (!area)
|
||||
area = &empty_area;
|
||||
|
||||
if (gdk_rectangle_equal (&tile->area, area))
|
||||
return;
|
||||
|
||||
tile->area = *area;
|
||||
gtk_rb_tree_node_mark_dirty (tile);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_tile_set_area_position (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
if (tile->area.x == x && tile->area.y == y)
|
||||
return;
|
||||
|
||||
tile->area.x = x;
|
||||
tile->area.y = y;
|
||||
gtk_rb_tree_node_mark_dirty (tile);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_tile_set_area_size (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
if (tile->area.width == width && tile->area.height == height)
|
||||
return;
|
||||
|
||||
tile->area.width = width;
|
||||
tile->area.height = height;
|
||||
gtk_rb_tree_node_mark_dirty (tile);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -347,37 +507,47 @@ restart:
|
||||
}
|
||||
}
|
||||
|
||||
static GtkListTile *
|
||||
gtk_list_item_manager_ensure_split (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
guint n_items)
|
||||
{
|
||||
return self->split_func (self->user_data, tile, n_items);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_manager_remove_items (GtkListItemManager *self,
|
||||
GHashTable *change,
|
||||
guint position,
|
||||
guint n_items)
|
||||
{
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile, *next;
|
||||
guint offset;
|
||||
|
||||
if (n_items == 0)
|
||||
return;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, NULL);
|
||||
tile = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
if (offset)
|
||||
tile = gtk_list_item_manager_ensure_split (self, tile, offset);
|
||||
|
||||
while (n_items > 0)
|
||||
{
|
||||
if (item->n_items > n_items)
|
||||
if (tile->n_items > n_items)
|
||||
{
|
||||
item->n_items -= n_items;
|
||||
gtk_rb_tree_node_mark_dirty (item);
|
||||
n_items = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkListItemManagerItem *next = gtk_rb_tree_node_get_next (item);
|
||||
if (item->widget)
|
||||
gtk_list_item_manager_release_list_item (self, change, item->widget);
|
||||
item->widget = NULL;
|
||||
n_items -= item->n_items;
|
||||
gtk_rb_tree_remove (self->items, item);
|
||||
item = next;
|
||||
gtk_list_item_manager_ensure_split (self, tile, n_items);
|
||||
g_assert (tile->n_items <= n_items);
|
||||
}
|
||||
|
||||
next = gtk_rb_tree_node_get_next (tile);
|
||||
if (tile->widget)
|
||||
gtk_list_item_manager_release_list_item (self, change, tile->widget);
|
||||
tile->widget = NULL;
|
||||
n_items -= tile->n_items;
|
||||
tile->n_items = 0;
|
||||
gtk_rb_tree_node_mark_dirty (tile);
|
||||
|
||||
tile = next;
|
||||
}
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self->widget));
|
||||
@ -388,26 +558,27 @@ gtk_list_item_manager_add_items (GtkListItemManager *self,
|
||||
guint position,
|
||||
guint n_items)
|
||||
{
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
guint offset;
|
||||
|
||||
if (n_items == 0)
|
||||
return;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
tile = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
if (offset)
|
||||
tile = gtk_list_item_manager_ensure_split (self, tile, offset);
|
||||
|
||||
if (item == NULL || item->widget)
|
||||
item = gtk_rb_tree_insert_before (self->items, item);
|
||||
item->n_items += n_items;
|
||||
gtk_rb_tree_node_mark_dirty (item);
|
||||
tile = gtk_rb_tree_insert_before (self->items, tile);
|
||||
tile->n_items = n_items;
|
||||
gtk_rb_tree_node_mark_dirty (tile);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self->widget));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_list_item_manager_merge_list_items (GtkListItemManager *self,
|
||||
GtkListItemManagerItem *first,
|
||||
GtkListItemManagerItem *second)
|
||||
gtk_list_item_manager_merge_list_items (GtkListItemManager *self,
|
||||
GtkListTile *first,
|
||||
GtkListTile *second)
|
||||
{
|
||||
if (first->widget || second->widget)
|
||||
return FALSE;
|
||||
@ -419,11 +590,86 @@ gtk_list_item_manager_merge_list_items (GtkListItemManager *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_list_tile_split:
|
||||
* @self: the listitemmanager
|
||||
* @tile: a tile to split into two
|
||||
* @n_items: nuber of items to keep in tile
|
||||
*
|
||||
* Splits the given tile into two tiles. The original
|
||||
* tile will remain with @n_items items, the remaining
|
||||
* items will be given to the new tile, which will be
|
||||
* nserted after the tile.
|
||||
*
|
||||
* It is valid for either tile to have 0 items after
|
||||
* the split.
|
||||
*
|
||||
* Returns: The new tile
|
||||
**/
|
||||
GtkListTile *
|
||||
gtk_list_tile_split (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
guint n_items)
|
||||
{
|
||||
GtkListTile *result;
|
||||
|
||||
g_assert (n_items <= tile->n_items);
|
||||
|
||||
result = gtk_rb_tree_insert_after (self->items, tile);
|
||||
result->n_items = tile->n_items - n_items;
|
||||
tile->n_items = n_items;
|
||||
gtk_rb_tree_node_mark_dirty (tile);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_list_tile_gc:
|
||||
* @self: the listitemmanager
|
||||
* @tile: a tile
|
||||
*
|
||||
* Tries to get rid of tiles when they aren't needed anymore,
|
||||
* either because their referenced listitems were deleted or
|
||||
* because they can be merged with the next item(s).
|
||||
*
|
||||
* Note that this only looks forward, but never backward.
|
||||
*
|
||||
* Returns: The next tile
|
||||
**/
|
||||
GtkListTile *
|
||||
gtk_list_tile_gc (GtkListItemManager *self,
|
||||
GtkListTile *tile)
|
||||
{
|
||||
GtkListTile *next;
|
||||
|
||||
while (tile)
|
||||
{
|
||||
next = gtk_rb_tree_node_get_next (tile);
|
||||
|
||||
if (tile->n_items == 0)
|
||||
{
|
||||
gtk_rb_tree_remove (self->items, tile);
|
||||
tile = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next == NULL)
|
||||
break;
|
||||
|
||||
if (gtk_list_item_manager_merge_list_items (self, tile, next))
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_manager_release_items (GtkListItemManager *self,
|
||||
GQueue *released)
|
||||
{
|
||||
GtkListItemManagerItem *item, *prev, *next;
|
||||
GtkListTile *tile;
|
||||
guint position, i, n_items, query_n_items;
|
||||
gboolean tracked;
|
||||
|
||||
@ -439,37 +685,18 @@ gtk_list_item_manager_release_items (GtkListItemManager *self,
|
||||
continue;
|
||||
}
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, &i);
|
||||
tile = gtk_list_item_manager_get_nth (self, position, &i);
|
||||
i = position - i;
|
||||
while (i < position + query_n_items)
|
||||
{
|
||||
g_assert (item != NULL);
|
||||
if (item->widget)
|
||||
g_assert (tile != NULL);
|
||||
if (tile->widget)
|
||||
{
|
||||
g_queue_push_tail (released, item->widget);
|
||||
item->widget = NULL;
|
||||
i++;
|
||||
prev = gtk_rb_tree_node_get_previous (item);
|
||||
if (prev && gtk_list_item_manager_merge_list_items (self, prev, item))
|
||||
item = prev;
|
||||
next = gtk_rb_tree_node_get_next (item);
|
||||
if (next && next->widget == NULL)
|
||||
{
|
||||
i += next->n_items;
|
||||
if (!gtk_list_item_manager_merge_list_items (self, next, item))
|
||||
g_assert_not_reached ();
|
||||
item = gtk_rb_tree_node_get_next (next);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i += item->n_items;
|
||||
item = gtk_rb_tree_node_get_next (item);
|
||||
g_queue_push_tail (released, tile->widget);
|
||||
tile->widget = NULL;
|
||||
}
|
||||
i += tile->n_items;
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
}
|
||||
position += query_n_items;
|
||||
}
|
||||
@ -480,7 +707,7 @@ gtk_list_item_manager_ensure_items (GtkListItemManager *self,
|
||||
GHashTable *change,
|
||||
guint update_start)
|
||||
{
|
||||
GtkListItemManagerItem *item, *new_item;
|
||||
GtkListTile *tile, *other_tile;
|
||||
GtkWidget *widget, *insert_after;
|
||||
guint position, i, n_items, query_n_items, offset;
|
||||
GQueue released = G_QUEUE_INIT;
|
||||
@ -503,70 +730,61 @@ gtk_list_item_manager_ensure_items (GtkListItemManager *self,
|
||||
continue;
|
||||
}
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
for (new_item = item;
|
||||
new_item && new_item->widget == NULL;
|
||||
new_item = gtk_rb_tree_node_get_previous (new_item))
|
||||
tile = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
for (other_tile = tile;
|
||||
other_tile && other_tile->widget == NULL;
|
||||
other_tile = gtk_rb_tree_node_get_previous (other_tile))
|
||||
{ /* do nothing */ }
|
||||
insert_after = new_item ? new_item->widget : NULL;
|
||||
insert_after = other_tile ? other_tile->widget : NULL;
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
g_assert (item != NULL);
|
||||
new_item = gtk_rb_tree_insert_before (self->items, item);
|
||||
new_item->n_items = offset;
|
||||
item->n_items -= offset;
|
||||
gtk_rb_tree_node_mark_dirty (item);
|
||||
}
|
||||
tile = gtk_list_item_manager_ensure_split (self, tile, offset);
|
||||
|
||||
for (i = 0; i < query_n_items; i++)
|
||||
{
|
||||
g_assert (item != NULL);
|
||||
if (item->n_items > 1)
|
||||
{
|
||||
new_item = gtk_rb_tree_insert_before (self->items, item);
|
||||
new_item->n_items = 1;
|
||||
item->n_items--;
|
||||
gtk_rb_tree_node_mark_dirty (item);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_item = item;
|
||||
item = gtk_rb_tree_node_get_next (item);
|
||||
}
|
||||
if (new_item->widget == NULL)
|
||||
g_assert (tile != NULL);
|
||||
|
||||
while (tile->n_items == 0)
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
|
||||
if (tile->n_items > 1)
|
||||
gtk_list_item_manager_ensure_split (self, tile, 1);
|
||||
|
||||
if (tile->widget == NULL)
|
||||
{
|
||||
if (change)
|
||||
{
|
||||
new_item->widget = gtk_list_item_manager_try_reacquire_list_item (self,
|
||||
change,
|
||||
position + i,
|
||||
insert_after);
|
||||
tile->widget = gtk_list_item_manager_try_reacquire_list_item (self,
|
||||
change,
|
||||
position + i,
|
||||
insert_after);
|
||||
}
|
||||
if (new_item->widget == NULL)
|
||||
if (tile->widget == NULL)
|
||||
{
|
||||
new_item->widget = g_queue_pop_head (&released);
|
||||
if (new_item->widget)
|
||||
tile->widget = g_queue_pop_head (&released);
|
||||
if (tile->widget)
|
||||
{
|
||||
gtk_list_item_manager_move_list_item (self,
|
||||
new_item->widget,
|
||||
tile->widget,
|
||||
position + i,
|
||||
insert_after);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_item->widget = gtk_list_item_manager_acquire_list_item (self,
|
||||
position + i,
|
||||
insert_after);
|
||||
tile->widget = gtk_list_item_manager_acquire_list_item (self,
|
||||
position + i,
|
||||
insert_after);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (update_start <= position + i)
|
||||
gtk_list_item_manager_update_list_item (self, new_item->widget, position + i);
|
||||
gtk_list_item_manager_update_list_item (self, tile->widget, position + i);
|
||||
}
|
||||
insert_after = new_item->widget;
|
||||
insert_after = tile->widget;
|
||||
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
}
|
||||
position += query_n_items;
|
||||
}
|
||||
@ -608,17 +826,17 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model,
|
||||
* trying to find where it moved */
|
||||
if (l)
|
||||
{
|
||||
GtkListItemManagerItem *item, *new_item;
|
||||
GtkListTile *tile, *new_tile;
|
||||
GtkWidget *insert_after;
|
||||
guint i, offset;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
for (new_item = item ? gtk_rb_tree_node_get_previous (item) : gtk_rb_tree_get_last (self->items);
|
||||
new_item && new_item->widget == NULL;
|
||||
new_item = gtk_rb_tree_node_get_previous (new_item))
|
||||
tile = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
for (new_tile = tile ? gtk_rb_tree_node_get_previous (tile) : gtk_rb_tree_get_last (self->items);
|
||||
new_tile && new_tile->widget == NULL;
|
||||
new_tile = gtk_rb_tree_node_get_previous (new_tile))
|
||||
{ }
|
||||
if (new_item)
|
||||
insert_after = new_item->widget;
|
||||
if (new_tile)
|
||||
insert_after = new_tile->widget;
|
||||
else
|
||||
insert_after = NULL; /* we're at the start */
|
||||
|
||||
@ -636,29 +854,24 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model,
|
||||
continue;
|
||||
}
|
||||
|
||||
while (offset >= tile->n_items)
|
||||
{
|
||||
offset -= tile->n_items;
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
}
|
||||
if (offset > 0)
|
||||
{
|
||||
new_item = gtk_rb_tree_insert_before (self->items, item);
|
||||
new_item->n_items = offset;
|
||||
item->n_items -= offset;
|
||||
tile = gtk_list_item_manager_ensure_split (self, tile, offset);
|
||||
offset = 0;
|
||||
gtk_rb_tree_node_mark_dirty (item);
|
||||
}
|
||||
|
||||
if (item->n_items == 1)
|
||||
{
|
||||
new_item = item;
|
||||
item = gtk_rb_tree_node_get_next (item);
|
||||
}
|
||||
new_tile = tile;
|
||||
if (tile->n_items == 1)
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
else
|
||||
{
|
||||
new_item = gtk_rb_tree_insert_before (self->items, item);
|
||||
new_item->n_items = 1;
|
||||
item->n_items--;
|
||||
gtk_rb_tree_node_mark_dirty (item);
|
||||
}
|
||||
tile = gtk_list_item_manager_ensure_split (self, tile, 1);
|
||||
|
||||
new_item->widget = widget;
|
||||
new_tile->widget = widget;
|
||||
insert_after = widget;
|
||||
}
|
||||
}
|
||||
@ -719,16 +932,16 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model,
|
||||
for (l = self->trackers; l; l = l->next)
|
||||
{
|
||||
GtkListItemTracker *tracker = l->data;
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
|
||||
if (tracker->widget != NULL ||
|
||||
tracker->position == GTK_INVALID_LIST_POSITION)
|
||||
continue;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, tracker->position, NULL);
|
||||
g_assert (item != NULL);
|
||||
g_assert (item->widget);
|
||||
tracker->widget = GTK_LIST_ITEM_WIDGET (item->widget);
|
||||
tile = gtk_list_item_manager_get_nth (self, tracker->position, NULL);
|
||||
g_assert (tile != NULL);
|
||||
g_assert (tile->widget);
|
||||
tracker->widget = GTK_LIST_ITEM_WIDGET (tile->widget);
|
||||
}
|
||||
|
||||
g_hash_table_unref (change);
|
||||
@ -742,28 +955,28 @@ gtk_list_item_manager_model_selection_changed_cb (GListModel *model,
|
||||
guint n_items,
|
||||
GtkListItemManager *self)
|
||||
{
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
guint offset;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
tile = gtk_list_item_manager_get_nth (self, position, &offset);
|
||||
|
||||
if (offset)
|
||||
{
|
||||
position += item->n_items - offset;
|
||||
if (item->n_items - offset > n_items)
|
||||
position += tile->n_items - offset;
|
||||
if (tile->n_items - offset > n_items)
|
||||
n_items = 0;
|
||||
else
|
||||
n_items -= item->n_items - offset;
|
||||
item = gtk_rb_tree_node_get_next (item);
|
||||
n_items -= tile->n_items - offset;
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
}
|
||||
|
||||
while (n_items > 0)
|
||||
{
|
||||
if (item->widget)
|
||||
gtk_list_item_manager_update_list_item (self, item->widget, position);
|
||||
position += item->n_items;
|
||||
n_items -= MIN (n_items, item->n_items);
|
||||
item = gtk_rb_tree_node_get_next (item);
|
||||
if (tile->widget)
|
||||
gtk_list_item_manager_update_list_item (self, tile->widget, position);
|
||||
position += tile->n_items;
|
||||
n_items -= MIN (n_items, tile->n_items);
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -842,14 +1055,14 @@ gtk_list_item_manager_set_factory (GtkListItemManager *self,
|
||||
for (l = self->trackers; l; l = l->next)
|
||||
{
|
||||
GtkListItemTracker *tracker = l->data;
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
|
||||
if (tracker->widget == NULL)
|
||||
continue;
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, tracker->position, NULL);
|
||||
g_assert (item);
|
||||
tracker->widget = GTK_LIST_ITEM_WIDGET (item->widget);
|
||||
tile = gtk_list_item_manager_get_nth (self, tracker->position, NULL);
|
||||
g_assert (tile);
|
||||
tracker->widget = GTK_LIST_ITEM_WIDGET (tile->widget);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1087,18 +1300,18 @@ void
|
||||
gtk_list_item_manager_set_single_click_activate (GtkListItemManager *self,
|
||||
gboolean single_click_activate)
|
||||
{
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
|
||||
g_return_if_fail (GTK_IS_LIST_ITEM_MANAGER (self));
|
||||
|
||||
self->single_click_activate = single_click_activate;
|
||||
|
||||
for (item = gtk_rb_tree_get_first (self->items);
|
||||
item != NULL;
|
||||
item = gtk_rb_tree_node_get_next (item))
|
||||
for (tile = gtk_rb_tree_get_first (self->items);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (item->widget)
|
||||
gtk_list_item_widget_set_single_click_activate (GTK_LIST_ITEM_WIDGET (item->widget), single_click_activate);
|
||||
if (tile->widget)
|
||||
gtk_list_item_widget_set_single_click_activate (GTK_LIST_ITEM_WIDGET (tile->widget), single_click_activate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1148,7 +1361,7 @@ gtk_list_item_tracker_set_position (GtkListItemManager *self,
|
||||
guint n_before,
|
||||
guint n_after)
|
||||
{
|
||||
GtkListItemManagerItem *item;
|
||||
GtkListTile *tile;
|
||||
guint n_items;
|
||||
|
||||
gtk_list_item_tracker_unset_position (self, tracker);
|
||||
@ -1166,9 +1379,9 @@ gtk_list_item_tracker_set_position (GtkListItemManager *self,
|
||||
|
||||
gtk_list_item_manager_ensure_items (self, NULL, G_MAXUINT);
|
||||
|
||||
item = gtk_list_item_manager_get_nth (self, position, NULL);
|
||||
if (item)
|
||||
tracker->widget = GTK_LIST_ITEM_WIDGET (item->widget);
|
||||
tile = gtk_list_item_manager_get_nth (self, position, NULL);
|
||||
if (tile)
|
||||
tracker->widget = GTK_LIST_ITEM_WIDGET (tile->widget);
|
||||
|
||||
gtk_widget_queue_resize (self->widget);
|
||||
}
|
||||
|
@ -39,47 +39,67 @@ G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GtkListItemManager GtkListItemManager;
|
||||
typedef struct _GtkListItemManagerClass GtkListItemManagerClass;
|
||||
typedef struct _GtkListItemManagerItem GtkListItemManagerItem; /* sorry */
|
||||
typedef struct _GtkListItemManagerItemAugment GtkListItemManagerItemAugment;
|
||||
typedef struct _GtkListTile GtkListTile;
|
||||
typedef struct _GtkListTileAugment GtkListTileAugment;
|
||||
typedef struct _GtkListItemTracker GtkListItemTracker;
|
||||
|
||||
struct _GtkListItemManagerItem
|
||||
struct _GtkListTile
|
||||
{
|
||||
GtkWidget *widget;
|
||||
guint n_items;
|
||||
/* area occupied by tile. May be empty if tile has no allcoation */
|
||||
cairo_rectangle_int_t area;
|
||||
};
|
||||
|
||||
struct _GtkListItemManagerItemAugment
|
||||
struct _GtkListTileAugment
|
||||
{
|
||||
guint n_items;
|
||||
/* union of all areas of tile and children */
|
||||
cairo_rectangle_int_t area;
|
||||
};
|
||||
|
||||
|
||||
GType gtk_list_item_manager_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkListItemManager * gtk_list_item_manager_new_for_size (GtkWidget *widget,
|
||||
GtkListItemManager * gtk_list_item_manager_new (GtkWidget *widget,
|
||||
const char *item_css_name,
|
||||
GtkAccessibleRole item_role,
|
||||
gsize element_size,
|
||||
gsize augment_size,
|
||||
GtkRbTreeAugmentFunc augment_func);
|
||||
#define gtk_list_item_manager_new(widget, item_css_name, type, augment_type, augment_func) \
|
||||
gtk_list_item_manager_new_for_size (widget, item_css_name, sizeof (type), sizeof (augment_type), (augment_func))
|
||||
GtkListTile * (* split_func) (gpointer, GtkListTile *, guint),
|
||||
gpointer user_data);
|
||||
|
||||
void gtk_list_item_manager_augment_node (GtkRbTree *tree,
|
||||
gpointer node_augment,
|
||||
gpointer node,
|
||||
gpointer left,
|
||||
gpointer right);
|
||||
void gtk_list_item_manager_get_tile_bounds (GtkListItemManager *self,
|
||||
GdkRectangle *out_bounds);
|
||||
gpointer gtk_list_item_manager_get_root (GtkListItemManager *self);
|
||||
gpointer gtk_list_item_manager_get_first (GtkListItemManager *self);
|
||||
gpointer gtk_list_item_manager_get_last (GtkListItemManager *self);
|
||||
gpointer gtk_list_item_manager_get_nth (GtkListItemManager *self,
|
||||
guint position,
|
||||
guint *offset);
|
||||
guint gtk_list_item_manager_get_item_position (GtkListItemManager *self,
|
||||
gpointer item);
|
||||
gpointer gtk_list_item_manager_get_item_augment (GtkListItemManager *self,
|
||||
gpointer item);
|
||||
GtkListTile * gtk_list_item_manager_get_tile_at (GtkListItemManager *self,
|
||||
int x,
|
||||
int y);
|
||||
|
||||
guint gtk_list_tile_get_position (GtkListItemManager *self,
|
||||
GtkListTile *tile);
|
||||
gpointer gtk_list_tile_get_augment (GtkListItemManager *self,
|
||||
GtkListTile *tile);
|
||||
void gtk_list_tile_set_area (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
const cairo_rectangle_int_t *area);
|
||||
void gtk_list_tile_set_area_position (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
int x,
|
||||
int y);
|
||||
void gtk_list_tile_set_area_size (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
GtkListTile * gtk_list_tile_split (GtkListItemManager *self,
|
||||
GtkListTile *tile,
|
||||
guint n_items);
|
||||
GtkListTile * gtk_list_tile_gc (GtkListItemManager *self,
|
||||
GtkListTile *tile);
|
||||
|
||||
void gtk_list_item_manager_set_factory (GtkListItemManager *self,
|
||||
GtkListItemFactory *factory);
|
||||
|
@ -141,21 +141,6 @@
|
||||
* items use the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
|
||||
*/
|
||||
|
||||
typedef struct _ListRow ListRow;
|
||||
typedef struct _ListRowAugment ListRowAugment;
|
||||
|
||||
struct _ListRow
|
||||
{
|
||||
GtkListItemManagerItem parent;
|
||||
guint height; /* per row */
|
||||
};
|
||||
|
||||
struct _ListRowAugment
|
||||
{
|
||||
GtkListItemManagerItemAugment parent;
|
||||
guint height; /* total */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
@ -181,188 +166,88 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
||||
static void G_GNUC_UNUSED
|
||||
dump (GtkListView *self)
|
||||
{
|
||||
ListRow *row;
|
||||
GtkListTile *tile;
|
||||
guint n_widgets, n_list_rows;
|
||||
|
||||
n_widgets = 0;
|
||||
n_list_rows = 0;
|
||||
//g_print ("ANCHOR: %u - %u\n", self->anchor_start, self->anchor_end);
|
||||
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
||||
row;
|
||||
row = gtk_rb_tree_node_get_next (row))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (row->parent.widget)
|
||||
if (tile->widget)
|
||||
n_widgets++;
|
||||
n_list_rows++;
|
||||
g_print (" %4u%s (%upx)\n", row->parent.n_items, row->parent.widget ? " (widget)" : "", row->height);
|
||||
g_print (" %4u%s %d,%d,%d,%d\n", tile->n_items, tile->widget ? " (widget)" : "",
|
||||
tile->area.x, tile->area.y, tile->area.width, tile->area.height);
|
||||
}
|
||||
|
||||
g_print (" => %u widgets in %u list rows\n", n_widgets, n_list_rows);
|
||||
}
|
||||
|
||||
static void
|
||||
list_row_augment (GtkRbTree *tree,
|
||||
gpointer node_augment,
|
||||
gpointer node,
|
||||
gpointer left,
|
||||
gpointer right)
|
||||
{
|
||||
ListRow *row = node;
|
||||
ListRowAugment *aug = node_augment;
|
||||
|
||||
gtk_list_item_manager_augment_node (tree, node_augment, node, left, right);
|
||||
|
||||
aug->height = row->height * row->parent.n_items;
|
||||
|
||||
if (left)
|
||||
{
|
||||
ListRowAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
|
||||
|
||||
aug->height += left_aug->height;
|
||||
}
|
||||
|
||||
if (right)
|
||||
{
|
||||
ListRowAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
|
||||
|
||||
aug->height += right_aug->height;
|
||||
}
|
||||
}
|
||||
|
||||
static ListRow *
|
||||
gtk_list_view_get_row_at_y (GtkListView *self,
|
||||
int y,
|
||||
int *offset)
|
||||
{
|
||||
ListRow *row, *tmp;
|
||||
|
||||
row = gtk_list_item_manager_get_root (self->item_manager);
|
||||
|
||||
while (row)
|
||||
{
|
||||
tmp = gtk_rb_tree_node_get_left (row);
|
||||
if (tmp)
|
||||
{
|
||||
ListRowAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, tmp);
|
||||
if (y < aug->height)
|
||||
{
|
||||
row = tmp;
|
||||
continue;
|
||||
}
|
||||
y -= aug->height;
|
||||
}
|
||||
|
||||
if (y < row->height * row->parent.n_items)
|
||||
break;
|
||||
y -= row->height * row->parent.n_items;
|
||||
|
||||
row = gtk_rb_tree_node_get_right (row);
|
||||
}
|
||||
|
||||
if (offset)
|
||||
*offset = row ? y : 0;
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
static int
|
||||
list_row_get_y (GtkListView *self,
|
||||
ListRow *row)
|
||||
{
|
||||
ListRow *parent, *left;
|
||||
int y;
|
||||
|
||||
left = gtk_rb_tree_node_get_left (row);
|
||||
if (left)
|
||||
{
|
||||
ListRowAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, left);
|
||||
y = aug->height;
|
||||
}
|
||||
else
|
||||
y = 0;
|
||||
|
||||
for (parent = gtk_rb_tree_node_get_parent (row);
|
||||
parent != NULL;
|
||||
parent = gtk_rb_tree_node_get_parent (row))
|
||||
{
|
||||
left = gtk_rb_tree_node_get_left (parent);
|
||||
|
||||
if (left != row)
|
||||
{
|
||||
if (left)
|
||||
{
|
||||
ListRowAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, left);
|
||||
y += aug->height;
|
||||
}
|
||||
y += parent->height * parent->parent.n_items;
|
||||
}
|
||||
|
||||
row = parent;
|
||||
}
|
||||
|
||||
return y ;
|
||||
}
|
||||
|
||||
static int
|
||||
gtk_list_view_get_list_height (GtkListView *self)
|
||||
{
|
||||
ListRow *row;
|
||||
ListRowAugment *aug;
|
||||
GtkListTile *tile;
|
||||
GtkListTileAugment *aug;
|
||||
|
||||
row = gtk_list_item_manager_get_root (self->item_manager);
|
||||
if (row == NULL)
|
||||
tile = gtk_list_item_manager_get_root (self->item_manager);
|
||||
if (tile == NULL)
|
||||
return 0;
|
||||
|
||||
aug = gtk_list_item_manager_get_item_augment (self->item_manager, row);
|
||||
return aug->height;
|
||||
aug = gtk_list_tile_get_augment (self->item_manager, tile);
|
||||
return aug->area.height;
|
||||
}
|
||||
|
||||
static GtkListTile *
|
||||
gtk_list_view_split (GtkListBase *base,
|
||||
GtkListTile *tile,
|
||||
guint n_items)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (base);
|
||||
GtkListTile *new_tile;
|
||||
guint row_height;
|
||||
|
||||
row_height = tile->area.height / tile->n_items;
|
||||
|
||||
new_tile = gtk_list_tile_split (self->item_manager, tile, n_items);
|
||||
gtk_list_tile_set_area_size (self->item_manager,
|
||||
tile,
|
||||
tile->area.width,
|
||||
row_height * tile->n_items);
|
||||
gtk_list_tile_set_area (self->item_manager,
|
||||
new_tile,
|
||||
&(GdkRectangle) {
|
||||
tile->area.x,
|
||||
tile->area.y + tile->area.height,
|
||||
tile->area.width,
|
||||
row_height * new_tile->n_items
|
||||
});
|
||||
|
||||
return new_tile;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_list_view_get_allocation_along (GtkListBase *base,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size)
|
||||
gtk_list_view_get_allocation (GtkListBase *base,
|
||||
guint pos,
|
||||
GdkRectangle *area)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (base);
|
||||
ListRow *row;
|
||||
guint skip;
|
||||
int y;
|
||||
GtkListTile *tile;
|
||||
guint offset;
|
||||
|
||||
row = gtk_list_item_manager_get_nth (self->item_manager, pos, &skip);
|
||||
if (row == NULL)
|
||||
{
|
||||
if (offset)
|
||||
*offset = 0;
|
||||
if (size)
|
||||
*size = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
y = list_row_get_y (self, row);
|
||||
y += skip * row->height;
|
||||
tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &offset);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
|
||||
*area = tile->area;
|
||||
if (tile->n_items)
|
||||
area->height /= tile->n_items;
|
||||
if (offset)
|
||||
*offset = y;
|
||||
if (size)
|
||||
*size = row->height;
|
||||
area->y += offset * area->height;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_list_view_get_allocation_across (GtkListBase *base,
|
||||
guint pos,
|
||||
int *offset,
|
||||
int *size)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (base);
|
||||
|
||||
if (offset)
|
||||
*offset = 0;
|
||||
if (size)
|
||||
*size = self->list_width;
|
||||
|
||||
return TRUE;
|
||||
return area->width > 0 && area->height > 0;
|
||||
}
|
||||
|
||||
static GtkBitset *
|
||||
@ -372,7 +257,7 @@ gtk_list_view_get_items_in_rect (GtkListBase *base,
|
||||
GtkListView *self = GTK_LIST_VIEW (base);
|
||||
guint first, last, n_items;
|
||||
GtkBitset *result;
|
||||
ListRow *row;
|
||||
GtkListTile *tile;
|
||||
|
||||
result = gtk_bitset_new_empty ();
|
||||
|
||||
@ -383,14 +268,14 @@ gtk_list_view_get_items_in_rect (GtkListBase *base,
|
||||
if (n_items == 0)
|
||||
return result;
|
||||
|
||||
row = gtk_list_view_get_row_at_y (self, rect->y, NULL);
|
||||
if (row)
|
||||
first = gtk_list_item_manager_get_item_position (self->item_manager, row);
|
||||
tile = gtk_list_item_manager_get_tile_at (self->item_manager, 0, rect->y);
|
||||
if (tile)
|
||||
first = gtk_list_tile_get_position (self->item_manager, tile);
|
||||
else
|
||||
first = rect->y < 0 ? 0 : n_items - 1;
|
||||
row = gtk_list_view_get_row_at_y (self, rect->y + rect->height, NULL);
|
||||
if (row)
|
||||
last = gtk_list_item_manager_get_item_position (self->item_manager, row);
|
||||
tile = gtk_list_item_manager_get_tile_at (self->item_manager, 0, rect->y + rect->height);
|
||||
if (tile)
|
||||
last = gtk_list_tile_get_position (self->item_manager, tile);
|
||||
else
|
||||
last = rect->y + rect->height < 0 ? 0 : n_items - 1;
|
||||
|
||||
@ -415,34 +300,42 @@ gtk_list_view_move_focus_along (GtkListBase *base,
|
||||
|
||||
static gboolean
|
||||
gtk_list_view_get_position_from_allocation (GtkListBase *base,
|
||||
int across,
|
||||
int along,
|
||||
int x,
|
||||
int y,
|
||||
guint *pos,
|
||||
cairo_rectangle_int_t *area)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (base);
|
||||
ListRow *row;
|
||||
int remaining;
|
||||
GtkListTile *tile;
|
||||
int row_height, tile_pos;
|
||||
|
||||
if (across >= self->list_width)
|
||||
tile = gtk_list_item_manager_get_tile_at (self->item_manager, x, y);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
|
||||
along = CLAMP (along, 0, gtk_list_view_get_list_height (self) - 1);
|
||||
while (tile && tile->n_items == 0)
|
||||
tile = gtk_rb_tree_node_get_previous (tile);
|
||||
if (tile == NULL)
|
||||
{
|
||||
tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
while (tile && tile->n_items == 0)
|
||||
tile = gtk_rb_tree_node_get_next (tile);
|
||||
if (tile == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
row = gtk_list_view_get_row_at_y (self, along, &remaining);
|
||||
if (row == NULL)
|
||||
return FALSE;
|
||||
*pos = gtk_list_tile_get_position (self->item_manager, tile);
|
||||
row_height = (tile->area.height / tile->n_items);
|
||||
tile_pos = (y - tile->area.y) / row_height;
|
||||
|
||||
*pos = gtk_list_item_manager_get_item_position (self->item_manager, row);
|
||||
g_assert (remaining < row->height * row->parent.n_items);
|
||||
*pos += remaining / row->height;
|
||||
*pos += tile_pos;
|
||||
|
||||
if (area)
|
||||
{
|
||||
area->x = 0;
|
||||
area->width = self->list_width;
|
||||
area->y = along - remaining % row->height;
|
||||
area->height = row->height;
|
||||
area->x = tile->area.x;
|
||||
area->width = tile->area.width;
|
||||
area->y = tile->area.y + tile_pos * row_height;
|
||||
area->height = row_height;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -483,7 +376,7 @@ gtk_list_view_measure_across (GtkWidget *widget,
|
||||
int *natural)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (widget);
|
||||
ListRow *row;
|
||||
GtkListTile *tile;
|
||||
int min, nat, child_min, child_nat;
|
||||
/* XXX: Figure out how to split a given height into per-row heights.
|
||||
* Good luck! */
|
||||
@ -492,15 +385,15 @@ gtk_list_view_measure_across (GtkWidget *widget,
|
||||
min = 0;
|
||||
nat = 0;
|
||||
|
||||
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
||||
row != NULL;
|
||||
row = gtk_rb_tree_node_get_next (row))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
/* ignore unavailable rows */
|
||||
if (row->parent.widget == NULL)
|
||||
if (tile->widget == NULL)
|
||||
continue;
|
||||
|
||||
gtk_widget_measure (row->parent.widget,
|
||||
gtk_widget_measure (tile->widget,
|
||||
orientation, for_size,
|
||||
&child_min, &child_nat, NULL, NULL);
|
||||
min = MAX (min, child_min);
|
||||
@ -519,7 +412,7 @@ gtk_list_view_measure_list (GtkWidget *widget,
|
||||
int *natural)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (widget);
|
||||
ListRow *row;
|
||||
GtkListTile *tile;
|
||||
int min, nat, child_min, child_nat;
|
||||
GArray *min_heights, *nat_heights;
|
||||
guint n_unknown;
|
||||
@ -530,13 +423,13 @@ gtk_list_view_measure_list (GtkWidget *widget,
|
||||
min = 0;
|
||||
nat = 0;
|
||||
|
||||
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
||||
row != NULL;
|
||||
row = gtk_rb_tree_node_get_next (row))
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (row->parent.widget)
|
||||
if (tile->widget)
|
||||
{
|
||||
gtk_widget_measure (row->parent.widget,
|
||||
gtk_widget_measure (tile->widget,
|
||||
orientation, for_size,
|
||||
&child_min, &child_nat, NULL, NULL);
|
||||
g_array_append_val (min_heights, child_min);
|
||||
@ -546,7 +439,7 @@ gtk_list_view_measure_list (GtkWidget *widget,
|
||||
}
|
||||
else
|
||||
{
|
||||
n_unknown += row->parent.n_items;
|
||||
n_unknown += tile->n_items;
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,10 +479,9 @@ gtk_list_view_size_allocate (GtkWidget *widget,
|
||||
int baseline)
|
||||
{
|
||||
GtkListView *self = GTK_LIST_VIEW (widget);
|
||||
ListRow *row;
|
||||
GtkListTile *tile;
|
||||
GArray *heights;
|
||||
int min, nat, row_height;
|
||||
int x, y;
|
||||
int min, nat, row_height, y, list_width;
|
||||
GtkOrientation orientation, opposite_orientation;
|
||||
GtkScrollablePolicy scroll_policy, opposite_scroll_policy;
|
||||
|
||||
@ -599,9 +491,10 @@ gtk_list_view_size_allocate (GtkWidget *widget,
|
||||
opposite_scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), opposite_orientation);
|
||||
|
||||
/* step 0: exit early if list is empty */
|
||||
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
|
||||
tile = gtk_list_tile_gc (self->item_manager, gtk_list_item_manager_get_first (self->item_manager));
|
||||
if (tile == NULL)
|
||||
{
|
||||
gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
|
||||
gtk_list_base_allocate (GTK_LIST_BASE (self));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -609,85 +502,51 @@ gtk_list_view_size_allocate (GtkWidget *widget,
|
||||
gtk_list_view_measure_across (widget, opposite_orientation,
|
||||
-1,
|
||||
&min, &nat);
|
||||
self->list_width = orientation == GTK_ORIENTATION_VERTICAL ? width : height;
|
||||
list_width = orientation == GTK_ORIENTATION_VERTICAL ? width : height;
|
||||
if (opposite_scroll_policy == GTK_SCROLL_MINIMUM)
|
||||
self->list_width = MAX (min, self->list_width);
|
||||
list_width = MAX (min, list_width);
|
||||
else
|
||||
self->list_width = MAX (nat, self->list_width);
|
||||
list_width = MAX (nat, list_width);
|
||||
|
||||
/* step 2: determine height of known list items */
|
||||
/* step 2: determine height of known list items and gc the list */
|
||||
heights = g_array_new (FALSE, FALSE, sizeof (int));
|
||||
|
||||
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
||||
row != NULL;
|
||||
row = gtk_rb_tree_node_get_next (row))
|
||||
for (;
|
||||
tile != NULL;
|
||||
tile = gtk_list_tile_gc (self->item_manager, gtk_rb_tree_node_get_next (tile)))
|
||||
{
|
||||
if (row->parent.widget == NULL)
|
||||
if (tile->widget == NULL)
|
||||
continue;
|
||||
|
||||
gtk_widget_measure (row->parent.widget, orientation,
|
||||
self->list_width,
|
||||
gtk_widget_measure (tile->widget, orientation,
|
||||
list_width,
|
||||
&min, &nat, NULL, NULL);
|
||||
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
||||
row_height = min;
|
||||
else
|
||||
row_height = nat;
|
||||
if (row->height != row_height)
|
||||
{
|
||||
row->height = row_height;
|
||||
gtk_rb_tree_node_mark_dirty (row);
|
||||
}
|
||||
gtk_list_tile_set_area_size (self->item_manager, tile, list_width, row_height);
|
||||
g_array_append_val (heights, row_height);
|
||||
}
|
||||
|
||||
/* step 3: determine height of unknown items */
|
||||
/* step 3: determine height of unknown items and set the positions */
|
||||
row_height = gtk_list_view_get_unknown_row_height (self, heights);
|
||||
g_array_free (heights, TRUE);
|
||||
|
||||
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
||||
row != NULL;
|
||||
row = gtk_rb_tree_node_get_next (row))
|
||||
y = 0;
|
||||
for (tile = gtk_list_item_manager_get_first (self->item_manager);
|
||||
tile != NULL;
|
||||
tile = gtk_rb_tree_node_get_next (tile))
|
||||
{
|
||||
if (row->parent.widget)
|
||||
continue;
|
||||
gtk_list_tile_set_area_position (self->item_manager, tile, 0, y);
|
||||
if (tile->widget == NULL)
|
||||
gtk_list_tile_set_area_size (self->item_manager, tile, list_width, row_height * tile->n_items);
|
||||
|
||||
if (row->height != row_height)
|
||||
{
|
||||
row->height = row_height;
|
||||
gtk_rb_tree_node_mark_dirty (row);
|
||||
}
|
||||
y += tile->area.height;
|
||||
}
|
||||
|
||||
/* step 3: update the adjustments */
|
||||
gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
|
||||
self->list_width,
|
||||
gtk_list_view_get_list_height (self),
|
||||
gtk_widget_get_size (widget, opposite_orientation),
|
||||
gtk_widget_get_size (widget, orientation),
|
||||
&x, &y);
|
||||
x = -x;
|
||||
y = -y;
|
||||
|
||||
/* step 4: actually allocate the widgets */
|
||||
|
||||
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
||||
row != NULL;
|
||||
row = gtk_rb_tree_node_get_next (row))
|
||||
{
|
||||
if (row->parent.widget)
|
||||
{
|
||||
gtk_list_base_size_allocate_child (GTK_LIST_BASE (self),
|
||||
row->parent.widget,
|
||||
x,
|
||||
y,
|
||||
self->list_width,
|
||||
row->height);
|
||||
}
|
||||
|
||||
y += row->height * row->parent.n_items;
|
||||
}
|
||||
|
||||
gtk_list_base_allocate_rubberband (GTK_LIST_BASE (self));
|
||||
/* step 4: allocate the rest */
|
||||
gtk_list_base_allocate (GTK_LIST_BASE (self));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -799,11 +658,8 @@ gtk_list_view_class_init (GtkListViewClass *klass)
|
||||
|
||||
list_base_class->list_item_name = "row";
|
||||
list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_LIST_ITEM;
|
||||
list_base_class->list_item_size = sizeof (ListRow);
|
||||
list_base_class->list_item_augment_size = sizeof (ListRowAugment);
|
||||
list_base_class->list_item_augment_func = list_row_augment;
|
||||
list_base_class->get_allocation_along = gtk_list_view_get_allocation_along;
|
||||
list_base_class->get_allocation_across = gtk_list_view_get_allocation_across;
|
||||
list_base_class->split = gtk_list_view_split;
|
||||
list_base_class->get_allocation = gtk_list_view_get_allocation;
|
||||
list_base_class->get_items_in_rect = gtk_list_view_get_items_in_rect;
|
||||
list_base_class->get_position_from_allocation = gtk_list_view_get_position_from_allocation;
|
||||
list_base_class->move_focus_along = gtk_list_view_move_focus_along;
|
||||
|
@ -31,8 +31,6 @@ struct _GtkListView
|
||||
|
||||
GtkListItemManager *item_manager;
|
||||
gboolean show_separators;
|
||||
|
||||
int list_width;
|
||||
};
|
||||
|
||||
struct _GtkListViewClass
|
||||
|
@ -45,7 +45,8 @@ gtk_render_node_paintable_paintable_snapshot (GdkPaintable *paintable,
|
||||
GtkRenderNodePaintable *self = GTK_RENDER_NODE_PAINTABLE (paintable);
|
||||
|
||||
if (self->bounds.size.width <= 0 ||
|
||||
self->bounds.size.height <= 0)
|
||||
self->bounds.size.height <= 0 ||
|
||||
self->node == NULL)
|
||||
return;
|
||||
|
||||
gtk_snapshot_save (snapshot);
|
||||
@ -141,12 +142,12 @@ gtk_render_node_paintable_new (GskRenderNode *node,
|
||||
{
|
||||
GtkRenderNodePaintable *self;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL);
|
||||
g_return_val_if_fail (node == NULL || GSK_IS_RENDER_NODE (node), NULL);
|
||||
g_return_val_if_fail (bounds != NULL, NULL);
|
||||
|
||||
self = g_object_new (GTK_TYPE_RENDER_NODE_PAINTABLE, NULL);
|
||||
|
||||
self->node = gsk_render_node_ref (node);
|
||||
self->node = node ? gsk_render_node_ref (node) : NULL;
|
||||
self->bounds = *bounds;
|
||||
|
||||
return GDK_PAINTABLE (self);
|
||||
|
@ -1623,17 +1623,22 @@ gtk_snapshot_to_paintable (GtkSnapshot *snapshot,
|
||||
{
|
||||
graphene_size_init_from_size (&bounds.size, size);
|
||||
}
|
||||
else
|
||||
else if (node)
|
||||
{
|
||||
gsk_render_node_get_bounds (node, &bounds);
|
||||
bounds.size.width += bounds.origin.x;
|
||||
bounds.size.height += bounds.origin.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
bounds.size.width = 0;
|
||||
bounds.size.height = 0;
|
||||
}
|
||||
bounds.origin.x = 0;
|
||||
bounds.origin.y = 0;
|
||||
|
||||
paintable = gtk_render_node_paintable_new (node, &bounds);
|
||||
gsk_render_node_unref (node);
|
||||
g_clear_pointer (&node, gsk_render_node_unref);
|
||||
|
||||
return paintable;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user