summaryrefslogtreecommitdiff
path: root/libslab
diff options
context:
space:
mode:
authorzhuyaliang <[email protected]>2021-07-22 07:32:23 +0800
committerVictor Kareh <[email protected]>2021-07-28 12:19:22 -0400
commit0a3001cce9c68769ddb9cbf381bedbd2ae5a1850 (patch)
tree990c4eff6b71518b70c2973248b965536069d17b /libslab
parent99d2942c83b8e1f2c0278bff284543c5ba825c23 (diff)
downloadmate-control-center-0a3001cce9c68769ddb9cbf381bedbd2ae5a1850.tar.bz2
mate-control-center-0a3001cce9c68769ddb9cbf381bedbd2ae5a1850.tar.xz
Replace the deprecated GtkTable with GtkGrid
Diffstat (limited to 'libslab')
-rw-r--r--libslab/app-resizer.c45
-rw-r--r--libslab/app-resizer.h4
-rw-r--r--libslab/app-shell.c12
3 files changed, 24 insertions, 37 deletions
diff --git a/libslab/app-resizer.c b/libslab/app-resizer.c
index e53132fc..f32ab85e 100644
--- a/libslab/app-resizer.c
+++ b/libslab/app-resizer.c
@@ -62,33 +62,22 @@ remove_container_entries (GtkContainer * widget)
}
static void
-resize_table (GtkTable * table, gint columns, GList * launcher_list)
+resize_table (AppResizer *widget, GtkGrid * table, gint columns)
{
- float rows, remainder;
-
remove_container_entries (GTK_CONTAINER (table));
-
- rows = ((float) g_list_length (launcher_list)) / (float) columns;
- remainder = rows - ((int) rows);
- if (remainder != 0.0)
- rows += 1;
-
- gtk_table_resize (table, (int) rows, columns);
+ widget->column = columns;
}
static void
-relayout_table (GtkTable * table, GList * element_list)
+relayout_table (AppResizer *widget, GtkGrid * table, GList * element_list)
{
- guint maxcols, maxrows;
- gtk_table_get_size (GTK_TABLE (table), &maxrows, &maxcols);
gint row = 0, col = 0;
do
{
GtkWidget *element = GTK_WIDGET (element_list->data);
- gtk_table_attach (table, element, col, col + 1, row, row + 1, GTK_EXPAND | GTK_FILL,
- GTK_EXPAND | GTK_FILL, 0, 0);
+ gtk_grid_attach (table, element, col, row, 1, 1);
col++;
- if (col == maxcols)
+ if (col == widget->column)
{
col = 0;
row++;
@@ -98,26 +87,26 @@ relayout_table (GtkTable * table, GList * element_list)
}
void
-app_resizer_layout_table_default (AppResizer * widget, GtkTable * table, GList * element_list)
+app_resizer_layout_table_default (AppResizer * widget, GtkGrid * table, GList * element_list)
{
- resize_table (table, widget->cur_num_cols, element_list);
- relayout_table (table, element_list);
+ resize_table (widget, table, widget->cur_num_cols);
+ relayout_table (widget, table, element_list);
}
static void
relayout_tables (AppResizer * widget, gint num_cols)
{
- GtkTable *table;
+ GtkGrid *table;
GList *table_list, *launcher_list;
for (table_list = widget->cached_tables_list; table_list != NULL;
table_list = g_list_next (table_list))
{
- table = GTK_TABLE (table_list->data);
+ table = GTK_GRID (table_list->data);
launcher_list = gtk_container_get_children (GTK_CONTAINER (table));
launcher_list = g_list_reverse (launcher_list); /* Fixme - ugly hack because table stores prepend */
- resize_table (table, num_cols, launcher_list);
- relayout_table (table, launcher_list);
+ resize_table (widget, table, num_cols);
+ relayout_table (widget, table, launcher_list);
g_list_free (launcher_list);
}
}
@@ -131,7 +120,7 @@ calculate_num_cols (AppResizer * resizer, gint avail_width)
if (resizer->cached_element_width == -1)
{
- GtkTable *table = GTK_TABLE (resizer->cached_tables_list->data);
+ GtkGrid *table = GTK_GRID (resizer->cached_tables_list->data);
GList *children = gtk_container_get_children (GTK_CONTAINER (table));
GtkWidget *table_element = GTK_WIDGET (children->data);
gint natural_width;
@@ -139,7 +128,7 @@ calculate_num_cols (AppResizer * resizer, gint avail_width)
gtk_widget_get_preferred_width (table_element, NULL, &natural_width);
resizer->cached_element_width = natural_width;
- resizer->cached_table_spacing = gtk_table_get_default_col_spacing (table);
+ resizer->cached_table_spacing = gtk_grid_get_column_spacing (table);
}
num_cols =
@@ -185,7 +174,6 @@ app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
static gboolean first_time = TRUE;
gint new_num_cols;
- gint useable_area;
if (first_time)
{
@@ -223,11 +211,8 @@ app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
GtkRequisition other_requisiton;
gtk_widget_get_preferred_size (GTK_WIDGET (resizer->cached_tables_list->data), &other_requisiton, NULL);
- useable_area =
- allocation->width - (child_requisition.width -
- other_requisiton.width);
new_num_cols =
- relayout_tables_if_needed (APP_RESIZER (resizer), useable_area,
+ relayout_tables_if_needed (APP_RESIZER (resizer), allocation->width,
resizer->cur_num_cols);
if (resizer->cur_num_cols != new_num_cols)
{
diff --git a/libslab/app-resizer.h b/libslab/app-resizer.h
index 652ab712..1c65f533 100644
--- a/libslab/app-resizer.h
+++ b/libslab/app-resizer.h
@@ -50,6 +50,8 @@ struct _AppResizer
gboolean table_elements_homogeneous;
gint cur_num_cols;
gboolean setting_style;
+
+ guint column;
AppShellData *app_data;
};
@@ -64,7 +66,7 @@ GType app_resizer_get_type (void);
GtkWidget *app_resizer_new (GtkBox * child, gint initial_num_columns, gboolean homogeneous,
AppShellData * app_data);
void app_resizer_set_table_cache (AppResizer * widget, GList * cache_list);
-void app_resizer_layout_table_default (AppResizer * widget, GtkTable * table, GList * element_list);
+void app_resizer_layout_table_default (AppResizer * widget, GtkGrid * table, GList * element_list);
void app_resizer_set_vadjustment_value (GtkWidget * widget, gdouble value);
G_END_DECLS
diff --git a/libslab/app-shell.c b/libslab/app-shell.c
index 6b421c74..6ca880bc 100644
--- a/libslab/app-shell.c
+++ b/libslab/app-shell.c
@@ -723,9 +723,9 @@ create_application_category_sections (AppShellData * app_data)
g_free (markup);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- table = gtk_table_new (0, 0, TRUE);
- gtk_table_set_col_spacings (GTK_TABLE (table), 5);
- gtk_table_set_row_spacings (GTK_TABLE (table), 5);
+ table = gtk_grid_new ();
+ gtk_grid_set_column_spacing (GTK_GRID (table), 5);
+ gtk_grid_set_row_spacing (GTK_GRID (table), 5);
gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 15);
slab_section_set_contents (SLAB_SECTION (data->section), hbox);
}
@@ -804,7 +804,7 @@ populate_application_category_section (AppShellData * app_data, SlabSection * se
GList * launcher_list)
{
GtkWidget *hbox;
- GtkTable *table;
+ GtkGrid *table;
GList *children;
hbox = GTK_WIDGET (section->contents);
@@ -813,8 +813,8 @@ populate_application_category_section (AppShellData * app_data, SlabSection * se
table = children->data;
g_list_free (children);
- /* Make sure our implementation has not changed and it's still a GtkTable */
- g_assert (GTK_IS_TABLE (table));
+ /* Make sure our implementation has not changed and it's still a GtkGrid */
+ g_assert (GTK_IS_GRID (table));
app_data->cached_tables_list = g_list_append (app_data->cached_tables_list, table);