eggthreegrid: port to GTK 4

This commit is contained in:
Christian Hergert
2021-09-30 18:39:16 -07:00
parent 6cc12c0779
commit 997477c031
3 changed files with 118 additions and 254 deletions

View File

@ -29,11 +29,11 @@ typedef struct
{ {
GtkWidget *widget; GtkWidget *widget;
EggThreeGridColumn column; EggThreeGridColumn column;
gint row; int row;
gint min_height; int min_height;
gint nat_height; int nat_height;
gint min_baseline; int min_baseline;
gint nat_baseline; int nat_baseline;
} EggThreeGridChild; } EggThreeGridChild;
typedef struct typedef struct
@ -46,14 +46,14 @@ typedef struct
typedef struct typedef struct
{ {
gint row; int row;
gint min_above_baseline; int min_above_baseline;
gint min_below_baseline; int min_below_baseline;
gint nat_above_baseline; int nat_above_baseline;
gint nat_below_baseline; int nat_below_baseline;
} EggThreeGridRowInfo; } EggThreeGridRowInfo;
G_DEFINE_TYPE_WITH_PRIVATE (EggThreeGrid, egg_three_grid, GTK_TYPE_CONTAINER) G_DEFINE_TYPE_WITH_PRIVATE (EggThreeGrid, egg_three_grid, GTK_TYPE_WIDGET)
enum { enum {
PROP_0, PROP_0,
@ -70,8 +70,6 @@ enum {
}; };
static GParamSpec *properties [N_PROPS]; static GParamSpec *properties [N_PROPS];
static GParamSpec *child_properties [N_CHILD_PROPS];
static EggThreeGridChild dummy;
static EggThreeGridChild * static EggThreeGridChild *
egg_three_grid_child_new (void) egg_three_grid_child_new (void)
@ -88,32 +86,13 @@ egg_three_grid_child_free (gpointer data)
g_slice_free (EggThreeGridChild, child); g_slice_free (EggThreeGridChild, child);
} }
static EggThreeGridChild * void
egg_three_grid_find_child (EggThreeGrid *self, egg_three_grid_add (EggThreeGrid *self,
GtkWidget *widget) GtkWidget *widget,
guint row,
EggThreeGridColumn column)
{ {
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
g_assert (EGG_IS_THREE_GRID (self));
g_assert (GTK_IS_WIDGET (widget));
for (guint i = 0; i < priv->children->len; i++)
{
EggThreeGridChild *child = g_ptr_array_index (priv->children, i);
if (child->widget == widget)
return child;
}
return &dummy;
}
static void
egg_three_grid_add (GtkContainer *container,
GtkWidget *widget)
{
EggThreeGrid *self = (EggThreeGrid *)container;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
EggThreeGridChild *child; EggThreeGridChild *child;
g_assert (EGG_IS_THREE_GRID (self)); g_assert (EGG_IS_THREE_GRID (self));
@ -121,16 +100,22 @@ egg_three_grid_add (GtkContainer *container,
child = egg_three_grid_child_new (); child = egg_three_grid_child_new ();
child->widget = g_object_ref_sink (widget); child->widget = g_object_ref_sink (widget);
child->column = column;
child->row = row;
child->min_height = -1;
child->nat_height = -1;
child->min_baseline = -1;
child->nat_baseline = -1;
g_ptr_array_add (priv->children, child); g_ptr_array_add (priv->children, child);
gtk_widget_set_parent (widget, GTK_WIDGET (self)); gtk_widget_set_parent (widget, GTK_WIDGET (self));
} }
static void void
egg_three_grid_remove (GtkContainer *container, egg_three_grid_remove (EggThreeGrid *self,
GtkWidget *widget) GtkWidget *widget)
{ {
EggThreeGrid *self = (EggThreeGrid *)container;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
g_assert (EGG_IS_THREE_GRID (self)); g_assert (EGG_IS_THREE_GRID (self));
@ -159,12 +144,12 @@ egg_three_grid_get_request_mode (GtkWidget *widget)
static void static void
egg_three_grid_get_column_width (EggThreeGrid *self, egg_three_grid_get_column_width (EggThreeGrid *self,
EggThreeGridColumn column, EggThreeGridColumn column,
gint *min_width, int *min_width,
gint *nat_width) int *nat_width)
{ {
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
gint real_min_width = 0; int real_min_width = 0;
gint real_nat_width = 0; int real_nat_width = 0;
g_assert (EGG_IS_THREE_GRID (self)); g_assert (EGG_IS_THREE_GRID (self));
g_assert (column >= EGG_THREE_GRID_COLUMN_LEFT); g_assert (column >= EGG_THREE_GRID_COLUMN_LEFT);
@ -178,10 +163,10 @@ egg_three_grid_get_column_width (EggThreeGrid *self,
if (child->column == column) if (child->column == column)
{ {
gint child_min_width; int child_min_width;
gint child_nat_width; int child_nat_width;
gtk_widget_get_preferred_width (child->widget, &child_min_width, &child_nat_width); gtk_widget_measure (child->widget, GTK_ORIENTATION_HORIZONTAL, -1, &child_min_width, &child_nat_width, NULL, NULL);
real_min_width = MAX (real_min_width, child_min_width); real_min_width = MAX (real_min_width, child_min_width);
real_nat_width = MAX (real_nat_width, child_nat_width); real_nat_width = MAX (real_nat_width, child_nat_width);
@ -194,33 +179,23 @@ egg_three_grid_get_column_width (EggThreeGrid *self,
static void static void
egg_three_grid_get_preferred_width (GtkWidget *widget, egg_three_grid_get_preferred_width (GtkWidget *widget,
gint *min_width, int *min_width,
gint *nat_width) int *nat_width)
{ {
EggThreeGrid *self = (EggThreeGrid *)widget; EggThreeGrid *self = (EggThreeGrid *)widget;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
GtkStyleContext *style_context; int min_widths[3];
GtkBorder margin; int nat_widths[3];
gint min_widths[3];
gint nat_widths[3];
gint border_width;
GtkStateFlags state;
g_assert (EGG_IS_THREE_GRID (self)); g_assert (EGG_IS_THREE_GRID (self));
g_assert (min_width != NULL); g_assert (min_width != NULL);
g_assert (nat_width != NULL); g_assert (nat_width != NULL);
style_context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (style_context);
gtk_style_context_get_margin (style_context, state, &margin);
for (guint i = 0; i < 3; i++) for (guint i = 0; i < 3; i++)
egg_three_grid_get_column_width (self, i, &min_widths[i], &nat_widths[i]); egg_three_grid_get_column_width (self, i, &min_widths[i], &nat_widths[i]);
border_width = gtk_container_get_border_width (GTK_CONTAINER (self)); *min_width = MAX (min_widths[0], min_widths[2]) * 2 + min_widths[1] + (priv->column_spacing * 2);
*nat_width = MAX (nat_widths[0], nat_widths[2]) * 2 + nat_widths[1] + (priv->column_spacing * 2);
*min_width = MAX (min_widths[0], min_widths[2]) * 2 + min_widths[1] + margin.left + margin.right + (border_width * 2) + (priv->column_spacing * 2);
*nat_width = MAX (nat_widths[0], nat_widths[2]) * 2 + nat_widths[1] + margin.left + margin.right + (border_width * 2) + (priv->column_spacing * 2);
} }
static void static void
@ -292,39 +267,28 @@ update_row_info (GHashTable *hashtable,
static void static void
egg_three_grid_get_preferred_height_for_width (GtkWidget *widget, egg_three_grid_get_preferred_height_for_width (GtkWidget *widget,
gint width, int width,
gint *min_height, int *min_height,
gint *nat_height) int *nat_height)
{ {
EggThreeGrid *self = (EggThreeGrid *)widget; EggThreeGrid *self = (EggThreeGrid *)widget;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
g_autoptr(GHashTable) row_infos = NULL; g_autoptr(GHashTable) row_infos = NULL;
EggThreeGridRowInfo *row_info; EggThreeGridRowInfo *row_info;
GtkStyleContext *style_context;
GHashTableIter iter; GHashTableIter iter;
GtkStateFlags state; int real_min_height = 0;
GtkBorder margin; int real_nat_height = 0;
gint real_min_height = 0; int column_min_widths[3];
gint real_nat_height = 0; int column_nat_widths[3];
gint column_min_widths[3]; int widths[3];
gint column_nat_widths[3]; int n_rows;
gint widths[3];
gint border_width;
gint n_rows;
g_assert (EGG_IS_THREE_GRID (self)); g_assert (EGG_IS_THREE_GRID (self));
g_assert (min_height != NULL); g_assert (min_height != NULL);
g_assert (nat_height != NULL); g_assert (nat_height != NULL);
border_width = gtk_container_get_border_width (GTK_CONTAINER (self));
width -= border_width * 2;
width -= priv->column_spacing * 2; width -= priv->column_spacing * 2;
style_context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (style_context);
gtk_style_context_get_margin (style_context, state, &margin);
width -= margin.left + margin.right;
egg_three_grid_get_column_width (self, EGG_THREE_GRID_COLUMN_LEFT, &column_min_widths[0], &column_nat_widths[0]); egg_three_grid_get_column_width (self, EGG_THREE_GRID_COLUMN_LEFT, &column_min_widths[0], &column_nat_widths[0]);
egg_three_grid_get_column_width (self, EGG_THREE_GRID_COLUMN_CENTER, &column_min_widths[1], &column_nat_widths[1]); egg_three_grid_get_column_width (self, EGG_THREE_GRID_COLUMN_CENTER, &column_min_widths[1], &column_nat_widths[1]);
egg_three_grid_get_column_width (self, EGG_THREE_GRID_COLUMN_RIGHT, &column_min_widths[2], &column_nat_widths[2]); egg_three_grid_get_column_width (self, EGG_THREE_GRID_COLUMN_RIGHT, &column_min_widths[2], &column_nat_widths[2]);
@ -353,12 +317,10 @@ egg_three_grid_get_preferred_height_for_width (GtkWidget *widget,
!gtk_widget_get_child_visible (child->widget)) !gtk_widget_get_child_visible (child->widget))
continue; continue;
gtk_widget_get_preferred_height_and_baseline_for_width (child->widget, gtk_widget_measure (child->widget, GTK_ORIENTATION_VERTICAL, widths[child->column],
widths[child->column], &child->min_height, &child->nat_height,
&child->min_height, &child->min_baseline, &child->nat_baseline);
&child->nat_height,
&child->min_baseline,
&child->nat_baseline);
update_row_info (row_infos, child); update_row_info (row_infos, child);
} }
@ -378,12 +340,6 @@ egg_three_grid_get_preferred_height_for_width (GtkWidget *widget,
real_nat_height += row_info->nat_above_baseline + row_info->nat_below_baseline; real_nat_height += row_info->nat_above_baseline + row_info->nat_below_baseline;
} }
real_min_height += border_width * 2;
real_nat_height += border_width * 2;
real_min_height += margin.top + margin.bottom;
real_nat_height += margin.top + margin.bottom;
n_rows = g_hash_table_size (row_infos); n_rows = g_hash_table_size (row_infos);
if (n_rows > 1) if (n_rows > 1)
@ -406,7 +362,7 @@ egg_three_grid_get_preferred_height_for_width (GtkWidget *widget,
priv->row_infos = g_steal_pointer (&row_infos); priv->row_infos = g_steal_pointer (&row_infos);
} }
static gint static int
sort_by_row (gconstpointer a, sort_by_row (gconstpointer a,
gconstpointer b) gconstpointer b)
{ {
@ -419,9 +375,9 @@ sort_by_row (gconstpointer a,
static void static void
egg_three_grid_size_allocate_children (EggThreeGrid *self, egg_three_grid_size_allocate_children (EggThreeGrid *self,
EggThreeGridColumn column, EggThreeGridColumn column,
gint row, int row,
GtkAllocation *allocation, GtkAllocation *allocation,
gint baseline) int baseline)
{ {
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
@ -435,69 +391,52 @@ egg_three_grid_size_allocate_children (EggThreeGrid *self,
if (child->row == row && child->column == column) if (child->row == row && child->column == column)
{ {
GtkAllocation copy = *allocation; GtkAllocation copy = *allocation;
gtk_widget_size_allocate_with_baseline (child->widget, &copy, baseline); gtk_widget_size_allocate (child->widget, &copy, baseline);
} }
} }
} }
static void static void
egg_three_grid_size_allocate (GtkWidget *widget, egg_three_grid_size_allocate (GtkWidget *widget,
GtkAllocation *allocation) int width,
int height,
int baseline)
{ {
EggThreeGrid *self = (EggThreeGrid *)widget; EggThreeGrid *self = (EggThreeGrid *)widget;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
g_autofree GtkRequestedSize *rows = NULL; g_autofree GtkRequestedSize *rows = NULL;
const GList *iter; const GList *iter;
GtkStyleContext *style_context;
GtkAllocation area; GtkAllocation area;
GtkTextDirection dir; GtkTextDirection dir;
GList *values; GList *values;
GtkStateFlags state;
GtkBorder margin;
guint i; guint i;
guint n_rows; guint n_rows;
gint min_height; int min_height;
gint nat_height; int nat_height;
gint border_width; int left_min_width;
gint left_min_width; int left_nat_width;
gint left_nat_width; int center_min_width;
gint center_min_width; int center_nat_width;
gint center_nat_width; int right_min_width;
gint right_min_width; int right_nat_width;
gint right_nat_width; int left;
gint left; int center;
gint center; int right;
gint right;
g_assert (EGG_IS_THREE_GRID (self)); g_assert (EGG_IS_THREE_GRID (self));
g_assert (allocation != NULL);
area = *allocation; area.x = 0;
area.y = 0;
style_context = gtk_widget_get_style_context (widget); area.width = width;
state = gtk_style_context_get_state (style_context); area.height = height;
gtk_style_context_get_margin (style_context, state, &margin);
border_width = gtk_container_get_border_width (GTK_CONTAINER (self));
area.x += border_width;
area.y += border_width;
area.width -= border_width * 2;
area.height -= border_width * 2;
area.x += margin.left;
area.width -= margin.right + margin.left;
area.y += margin.top;
area.height -= margin.top + margin.bottom;
gtk_widget_set_allocation (widget, &area);
dir = gtk_widget_get_direction (widget); dir = gtk_widget_get_direction (widget);
egg_three_grid_get_preferred_height_for_width (widget, allocation->width, &min_height, &nat_height); egg_three_grid_get_preferred_height_for_width (widget, width, &min_height, &nat_height);
if (min_height > allocation->height) if (min_height > height)
g_warning ("%s requested a minimum height of %d and got %d", g_warning ("%s requested a minimum height of %d and got %d",
G_OBJECT_TYPE_NAME (widget), min_height, allocation->height); G_OBJECT_TYPE_NAME (widget), min_height, height);
if (priv->row_infos == NULL) if (priv->row_infos == NULL)
return; return;
@ -559,36 +498,36 @@ egg_three_grid_size_allocate (GtkWidget *widget,
GtkRequestedSize *size = &rows[i]; GtkRequestedSize *size = &rows[i];
EggThreeGridRowInfo *row_info = size->data; EggThreeGridRowInfo *row_info = size->data;
GtkAllocation child_alloc; GtkAllocation child_alloc;
gint baseline; int child_baseline;
if (row_info->nat_above_baseline + row_info->nat_below_baseline < size->minimum_size) if (row_info->nat_above_baseline + row_info->nat_below_baseline < size->minimum_size)
baseline = row_info->nat_above_baseline; child_baseline = row_info->nat_above_baseline;
else else
baseline = row_info->min_above_baseline; child_baseline = row_info->min_above_baseline;
child_alloc.x = area.x; child_alloc.x = area.x;
child_alloc.width = left; child_alloc.width = left;
child_alloc.y = area.y; child_alloc.y = area.y;
child_alloc.height = size->minimum_size; child_alloc.height = size->minimum_size;
if (dir == GTK_TEXT_DIR_LTR) if (dir == GTK_TEXT_DIR_LTR)
egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_LEFT, row_info->row, &child_alloc, baseline); egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_LEFT, row_info->row, &child_alloc, child_baseline);
else else
egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_RIGHT, row_info->row, &child_alloc, baseline); egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_RIGHT, row_info->row, &child_alloc, child_baseline);
child_alloc.x = area.x + left + priv->column_spacing; child_alloc.x = area.x + left + priv->column_spacing;
child_alloc.width = center; child_alloc.width = center;
child_alloc.y = area.y; child_alloc.y = area.y;
child_alloc.height = size->minimum_size; child_alloc.height = size->minimum_size;
egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_CENTER, row_info->row, &child_alloc, baseline); egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_CENTER, row_info->row, &child_alloc, child_baseline);
child_alloc.x = area.x + area.width - right; child_alloc.x = area.x + area.width - right;
child_alloc.width = right; child_alloc.width = right;
child_alloc.y = area.y; child_alloc.y = area.y;
child_alloc.height = size->minimum_size; child_alloc.height = size->minimum_size;
if (dir == GTK_TEXT_DIR_LTR) if (dir == GTK_TEXT_DIR_LTR)
egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_RIGHT, row_info->row, &child_alloc, baseline); egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_RIGHT, row_info->row, &child_alloc, child_baseline);
else else
egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_LEFT, row_info->row, &child_alloc, baseline); egg_three_grid_size_allocate_children (self, EGG_THREE_GRID_COLUMN_LEFT, row_info->row, &child_alloc, child_baseline);
area.y += child_alloc.height + priv->row_spacing; area.y += child_alloc.height + priv->row_spacing;
area.height -= child_alloc.height + priv->row_spacing; area.height -= child_alloc.height + priv->row_spacing;
@ -598,87 +537,41 @@ egg_three_grid_size_allocate (GtkWidget *widget,
} }
static void static void
egg_three_grid_forall (GtkContainer *container, egg_three_grid_measure (GtkWidget *widget,
gboolean include_internals, GtkOrientation orientation,
GtkCallback callback, int for_size,
gpointer user_data) int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{ {
EggThreeGrid *self = (EggThreeGrid *)container; EggThreeGrid *self = (EggThreeGrid *)widget;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
g_assert (GTK_IS_CONTAINER (self)); g_assert (EGG_IS_THREE_GRID (self));
g_assert (callback != NULL);
for (guint i = priv->children->len; i > 0; i--) *minimum_baseline = -1;
{ *natural_baseline = -1;
EggThreeGridChild *child = g_ptr_array_index (priv->children, i - 1);
callback (child->widget, user_data); if (orientation == GTK_ORIENTATION_HORIZONTAL)
} egg_three_grid_get_preferred_width (widget, minimum, natural);
else
egg_three_grid_get_preferred_height_for_width (widget, for_size, minimum, natural);
} }
static void static void
egg_three_grid_get_child_property (GtkContainer *container, egg_three_grid_dispose (GObject *object)
GtkWidget *widget,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EggThreeGrid *self = (EggThreeGrid *)container;
EggThreeGridChild *child = egg_three_grid_find_child (self, widget);
switch (prop_id)
{
case CHILD_PROP_COLUMN:
g_value_set_enum (value, child->column);
break;
case CHILD_PROP_ROW:
g_value_set_uint (value, child->row);
break;
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
}
}
static void
egg_three_grid_set_child_property (GtkContainer *container,
GtkWidget *widget,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EggThreeGrid *self = (EggThreeGrid *)container;
EggThreeGridChild *child = egg_three_grid_find_child (self, widget);
switch (prop_id)
{
case CHILD_PROP_COLUMN:
child->column = g_value_get_enum (value);
break;
case CHILD_PROP_ROW:
child->row = g_value_get_uint (value);
break;
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
}
gtk_widget_queue_resize (GTK_WIDGET (container));
}
static void
egg_three_grid_finalize (GObject *object)
{ {
EggThreeGrid *self = (EggThreeGrid *)object; EggThreeGrid *self = (EggThreeGrid *)object;
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
GtkWidget *child;
while ((child = gtk_widget_get_first_child (GTK_WIDGET (self))))
egg_three_grid_remove (self, child);
g_clear_pointer (&priv->row_infos, g_hash_table_unref); g_clear_pointer (&priv->row_infos, g_hash_table_unref);
g_clear_pointer (&priv->children, g_ptr_array_unref); g_clear_pointer (&priv->children, g_ptr_array_unref);
G_OBJECT_CLASS (egg_three_grid_parent_class)->finalize (object); G_OBJECT_CLASS (egg_three_grid_parent_class)->dispose (object);
} }
static void static void
@ -736,23 +629,15 @@ egg_three_grid_class_init (EggThreeGridClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
object_class->finalize = egg_three_grid_finalize; object_class->dispose = egg_three_grid_dispose;
object_class->get_property = egg_three_grid_get_property; object_class->get_property = egg_three_grid_get_property;
object_class->set_property = egg_three_grid_set_property; object_class->set_property = egg_three_grid_set_property;
widget_class->get_request_mode = egg_three_grid_get_request_mode; widget_class->get_request_mode = egg_three_grid_get_request_mode;
widget_class->get_preferred_height_for_width = egg_three_grid_get_preferred_height_for_width; widget_class->measure = egg_three_grid_measure;
widget_class->get_preferred_width = egg_three_grid_get_preferred_width;
widget_class->size_allocate = egg_three_grid_size_allocate; widget_class->size_allocate = egg_three_grid_size_allocate;
container_class->add = egg_three_grid_add;
container_class->forall = egg_three_grid_forall;
container_class->get_child_property = egg_three_grid_get_child_property;
container_class->remove = egg_three_grid_remove;
container_class->set_child_property = egg_three_grid_set_child_property;
properties [PROP_COLUMN_SPACING] = properties [PROP_COLUMN_SPACING] =
g_param_spec_uint ("column-spacing", g_param_spec_uint ("column-spacing",
"Column Spacing", "Column Spacing",
@ -773,25 +658,6 @@ egg_three_grid_class_init (EggThreeGridClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
child_properties [CHILD_PROP_COLUMN] =
g_param_spec_enum ("column",
"Column",
"Column",
EGG_TYPE_THREE_GRID_COLUMN,
EGG_THREE_GRID_COLUMN_LEFT,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
child_properties [CHILD_PROP_ROW] =
g_param_spec_uint ("row",
"Row",
"Row",
0,
G_MAXUINT,
0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gtk_container_class_install_child_properties (container_class, N_CHILD_PROPS, child_properties);
gtk_widget_class_set_css_name (widget_class, "threegrid"); gtk_widget_class_set_css_name (widget_class, "threegrid");
} }
@ -801,8 +667,6 @@ egg_three_grid_init (EggThreeGrid *self)
EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self); EggThreeGridPrivate *priv = egg_three_grid_get_instance_private (self);
priv->children = g_ptr_array_new_with_free_func (egg_three_grid_child_free); priv->children = g_ptr_array_new_with_free_func (egg_three_grid_child_free);
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
} }
GtkWidget * GtkWidget *

View File

@ -25,11 +25,11 @@ G_BEGIN_DECLS
#define EGG_TYPE_THREE_GRID (egg_three_grid_get_type()) #define EGG_TYPE_THREE_GRID (egg_three_grid_get_type())
#define EGG_TYPE_THREE_GRID_COLUMN (egg_three_grid_column_get_type()) #define EGG_TYPE_THREE_GRID_COLUMN (egg_three_grid_column_get_type())
G_DECLARE_DERIVABLE_TYPE (EggThreeGrid, egg_three_grid, EGG, THREE_GRID, GtkContainer) G_DECLARE_DERIVABLE_TYPE (EggThreeGrid, egg_three_grid, EGG, THREE_GRID, GtkWidget)
struct _EggThreeGridClass struct _EggThreeGridClass
{ {
GtkContainerClass parent_class; GtkWidgetClass parent_class;
}; };
typedef enum typedef enum
@ -41,5 +41,11 @@ typedef enum
GType egg_three_grid_column_get_type (void); GType egg_three_grid_column_get_type (void);
GtkWidget *egg_three_grid_new (void); GtkWidget *egg_three_grid_new (void);
void egg_three_grid_add (EggThreeGrid *self,
GtkWidget *child,
guint row,
EggThreeGridColumn column);
void egg_three_grid_remove (EggThreeGrid *self,
GtkWidget *child);
G_END_DECLS G_END_DECLS

View File

@ -266,16 +266,10 @@ sysprof_details_page_add_item (SysprofDetailsPage *self,
g_return_if_fail (!center || GTK_IS_WIDGET (center)); g_return_if_fail (!center || GTK_IS_WIDGET (center));
if (left) if (left)
gtk_container_add_with_properties (GTK_CONTAINER (self->three_grid), left, egg_three_grid_add (self->three_grid, left, self->next_row, EGG_THREE_GRID_COLUMN_LEFT);
"row", self->next_row,
"column", EGG_THREE_GRID_COLUMN_LEFT,
NULL);
if (center) if (center)
gtk_container_add_with_properties (GTK_CONTAINER (self->three_grid), center, egg_three_grid_add (self->three_grid, center, self->next_row, EGG_THREE_GRID_COLUMN_CENTER);
"row", self->next_row,
"column", EGG_THREE_GRID_COLUMN_CENTER,
NULL);
self->next_row++; self->next_row++;
} }