[gtk+] gtk-demo: replace uses of GtkTable by GtkGrid
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk-demo: replace uses of GtkTable by GtkGrid
- Date: Wed, 31 Aug 2011 17:32:37 +0000 (UTC)
commit a6899f2a9d90317d6445f68710c1c659220f5942
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Aug 31 11:10:19 2011 -0400
gtk-demo: replace uses of GtkTable by GtkGrid
demos/gtk-demo/appwindow.c | 47 ++++++++-----------------
demos/gtk-demo/dialog.c | 42 +++++++++--------------
demos/gtk-demo/panes.c | 81 +++++++++++++++++++------------------------
demos/gtk-demo/pickers.c | 30 +++++++++-------
demos/gtk-demo/sizegroup.c | 37 +++++++++-----------
5 files changed, 100 insertions(+), 137 deletions(-)
---
diff --git a/demos/gtk-demo/appwindow.c b/demos/gtk-demo/appwindow.c
index b5003e5..bfb96a5 100644
--- a/demos/gtk-demo/appwindow.c
+++ b/demos/gtk-demo/appwindow.c
@@ -416,7 +416,7 @@ do_appwindow (GtkWidget *do_widget)
G_CALLBACK (gtk_widget_destroyed),
&window);
- table = gtk_table_new (1, 5, FALSE);
+ table = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), table);
@@ -464,21 +464,13 @@ do_appwindow (GtkWidget *do_widget)
bar = gtk_ui_manager_get_widget (merge, "/MenuBar");
gtk_widget_show (bar);
- gtk_table_attach (GTK_TABLE (table),
- bar,
- /* X direction */ /* Y direction */
- 0, 1, 0, 1,
- GTK_EXPAND | GTK_FILL, 0,
- 0, 0);
+ gtk_widget_set_halign (bar, GTK_ALIGN_FILL);
+ gtk_grid_attach (GTK_GRID (table), bar, 0, 0, 1, 1);
bar = gtk_ui_manager_get_widget (merge, "/ToolBar");
gtk_widget_show (bar);
- gtk_table_attach (GTK_TABLE (table),
- bar,
- /* X direction */ /* Y direction */
- 0, 1, 1, 2,
- GTK_EXPAND | GTK_FILL, 0,
- 0, 0);
+ gtk_widget_set_halign (bar, GTK_ALIGN_FILL);
+ gtk_grid_attach (GTK_GRID (table), bar, 0, 1, 1, 1);
/* Create document
*/
@@ -495,12 +487,8 @@ do_appwindow (GtkWidget *do_widget)
g_signal_connect (infobar, "response",
G_CALLBACK (gtk_widget_hide), NULL);
- gtk_table_attach (GTK_TABLE (table),
- infobar,
- /* X direction */ /* Y direction */
- 0, 1, 2, 3,
- GTK_EXPAND | GTK_FILL, 0,
- 0, 0);
+ gtk_widget_set_halign (infobar, GTK_ALIGN_FILL);
+ gtk_grid_attach (GTK_GRID (table), infobar, 0, 2, 1, 1);
sw = gtk_scrolled_window_new (NULL, NULL);
@@ -511,12 +499,11 @@ do_appwindow (GtkWidget *do_widget)
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_IN);
- gtk_table_attach (GTK_TABLE (table),
- sw,
- /* X direction */ /* Y direction */
- 0, 1, 3, 4,
- GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
- 0, 0);
+ gtk_widget_set_halign (sw, GTK_ALIGN_FILL);
+ gtk_widget_set_valign (sw, GTK_ALIGN_FILL);
+ gtk_widget_set_hexpand (sw, TRUE);
+ gtk_widget_set_vexpand (sw, TRUE);
+ gtk_grid_attach (GTK_GRID (table), sw, 0, 3, 1, 1);
gtk_window_set_default_size (GTK_WINDOW (window),
200, 200);
@@ -530,16 +517,12 @@ do_appwindow (GtkWidget *do_widget)
/* Create statusbar */
statusbar = gtk_statusbar_new ();
- gtk_table_attach (GTK_TABLE (table),
- statusbar,
- /* X direction */ /* Y direction */
- 0, 1, 4, 5,
- GTK_EXPAND | GTK_FILL, 0,
- 0, 0);
+ gtk_widget_set_halign (sw, GTK_ALIGN_FILL);
+ gtk_grid_attach (GTK_GRID (table), statusbar, 0, 4, 1, 1);
/* Show text widget info in the statusbar */
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (contents));
-
+
g_signal_connect_object (buffer,
"changed",
G_CALLBACK (update_statusbar),
diff --git a/demos/gtk-demo/dialog.c b/demos/gtk-demo/dialog.c
index 1b86ce2..64772ae 100644
--- a/demos/gtk-demo/dialog.c
+++ b/demos/gtk-demo/dialog.c
@@ -61,29 +61,25 @@ interactive_dialog_clicked (GtkButton *button,
stock = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start (GTK_BOX (hbox), stock, FALSE, FALSE, 0);
- table = gtk_table_new (2, 2, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 4);
- gtk_table_set_col_spacings (GTK_TABLE (table), 4);
+ table = gtk_grid_new ();
+ gtk_grid_set_row_spacing (GTK_GRID (table), 4);
+ gtk_grid_set_column_spacing (GTK_GRID (table), 4);
gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0);
label = gtk_label_new_with_mnemonic ("_Entry 1");
- gtk_table_attach_defaults (GTK_TABLE (table),
- label,
- 0, 1, 0, 1);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
local_entry1 = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (local_entry1), gtk_entry_get_text (GTK_ENTRY (entry1)));
- gtk_table_attach_defaults (GTK_TABLE (table), local_entry1, 1, 2, 0, 1);
+ gtk_grid_attach (GTK_GRID (table), local_entry1, 1, 0, 1, 1);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), local_entry1);
label = gtk_label_new_with_mnemonic ("E_ntry 2");
- gtk_table_attach_defaults (GTK_TABLE (table),
- label,
- 0, 1, 1, 2);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
local_entry2 = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (local_entry2), gtk_entry_get_text (GTK_ENTRY (entry2)));
- gtk_table_attach_defaults (GTK_TABLE (table), local_entry2, 1, 2, 1, 2);
+ gtk_grid_attach (GTK_GRID (table), local_entry2, 1, 1, 1, 1);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), local_entry2);
-
+
gtk_widget_show_all (hbox);
response = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -146,29 +142,23 @@ do_dialog (GtkWidget *do_widget)
gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
- table = gtk_table_new (2, 2, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 4);
- gtk_table_set_col_spacings (GTK_TABLE (table), 4);
+ table = gtk_grid_new ();
+ gtk_grid_set_row_spacing (GTK_GRID (table), 4);
+ gtk_grid_set_column_spacing (GTK_GRID (table), 4);
gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 0);
label = gtk_label_new_with_mnemonic ("_Entry 1");
- gtk_table_attach_defaults (GTK_TABLE (table),
- label,
- 0, 1, 0, 1);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
entry1 = gtk_entry_new ();
- gtk_table_attach_defaults (GTK_TABLE (table), entry1, 1, 2, 0, 1);
+ gtk_grid_attach (GTK_GRID (table), entry1, 1, 0, 1, 1);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry1);
label = gtk_label_new_with_mnemonic ("E_ntry 2");
-
- gtk_table_attach_defaults (GTK_TABLE (table),
- label,
- 0, 1, 1, 2);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
entry2 = gtk_entry_new ();
- gtk_table_attach_defaults (GTK_TABLE (table), entry2, 1, 2, 1, 2);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry2);
+ gtk_grid_attach (GTK_GRID (table), entry2, 1, 1, 1, 1);
}
if (!gtk_widget_get_visible (window))
@@ -176,7 +166,7 @@ do_dialog (GtkWidget *do_widget)
gtk_widget_show_all (window);
}
else
- {
+ {
gtk_widget_destroy (window);
window = NULL;
}
diff --git a/demos/gtk-demo/panes.c b/demos/gtk-demo/panes.c
index 63ac757..2f6df22 100644
--- a/demos/gtk-demo/panes.c
+++ b/demos/gtk-demo/panes.c
@@ -15,7 +15,7 @@
void
toggle_resize (GtkWidget *widget,
- GtkWidget *child)
+ GtkWidget *child)
{
GtkWidget *parent;
GtkPaned *paned;
@@ -43,7 +43,7 @@ toggle_resize (GtkWidget *widget,
void
toggle_shrink (GtkWidget *widget,
- GtkWidget *child)
+ GtkWidget *child)
{
GtkWidget *parent;
GtkPaned *paned;
@@ -70,10 +70,10 @@ toggle_shrink (GtkWidget *widget,
}
GtkWidget *
-create_pane_options (GtkPaned *paned,
- const gchar *frame_label,
- const gchar *label1,
- const gchar *label2)
+create_pane_options (GtkPaned *paned,
+ const gchar *frame_label,
+ const gchar *label1,
+ const gchar *label2)
{
GtkWidget *child1, *child2;
GtkWidget *frame;
@@ -86,47 +86,38 @@ create_pane_options (GtkPaned *paned,
frame = gtk_frame_new (frame_label);
gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
-
- table = gtk_table_new (3, 2, TRUE);
+
+ table = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (frame), table);
-
+
label = gtk_label_new (label1);
- gtk_table_attach_defaults (GTK_TABLE (table), label,
- 0, 1, 0, 1);
-
+ gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
+
check_button = gtk_check_button_new_with_mnemonic ("_Resize");
- gtk_table_attach_defaults (GTK_TABLE (table), check_button,
- 0, 1, 1, 2);
+ gtk_grid_attach (GTK_GRID (table), check_button, 0, 1, 1, 1);
g_signal_connect (check_button, "toggled",
- G_CALLBACK (toggle_resize), child1);
+ G_CALLBACK (toggle_resize), child1);
check_button = gtk_check_button_new_with_mnemonic ("_Shrink");
- gtk_table_attach_defaults (GTK_TABLE (table), check_button,
- 0, 1, 2, 3);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
- TRUE);
+ gtk_grid_attach (GTK_GRID (table), check_button, 0, 2, 1, 1);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
g_signal_connect (check_button, "toggled",
- G_CALLBACK (toggle_shrink), child1);
+ G_CALLBACK (toggle_shrink), child1);
label = gtk_label_new (label2);
- gtk_table_attach_defaults (GTK_TABLE (table), label,
- 1, 2, 0, 1);
-
+ gtk_grid_attach (GTK_GRID (table), label, 1, 0, 1, 1);
+
check_button = gtk_check_button_new_with_mnemonic ("_Resize");
- gtk_table_attach_defaults (GTK_TABLE (table), check_button,
- 1, 2, 1, 2);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
- TRUE);
+ gtk_grid_attach (GTK_GRID (table), check_button, 1, 1, 1, 1);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
g_signal_connect (check_button, "toggled",
- G_CALLBACK (toggle_resize), child2);
+ G_CALLBACK (toggle_resize), child2);
check_button = gtk_check_button_new_with_mnemonic ("_Shrink");
- gtk_table_attach_defaults (GTK_TABLE (table), check_button,
- 1, 2, 2, 3);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
- TRUE);
+ gtk_grid_attach (GTK_GRID (table), check_button, 1, 2, 1, 1);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
g_signal_connect (check_button, "toggled",
- G_CALLBACK (toggle_shrink), child2);
+ G_CALLBACK (toggle_shrink), child2);
return frame;
}
@@ -145,10 +136,10 @@ do_panes (GtkWidget *do_widget)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
- gtk_widget_get_screen (do_widget));
+ gtk_widget_get_screen (do_widget));
g_signal_connect (window, "destroy",
- G_CALLBACK (gtk_widget_destroyed), &window);
+ G_CALLBACK (gtk_widget_destroyed), &window);
gtk_window_set_title (GTK_WINDOW (window), "Panes");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
@@ -184,18 +175,18 @@ do_panes (GtkWidget *do_widget)
/* Now create toggle buttons to control sizing */
gtk_box_pack_start (GTK_BOX (vbox),
- create_pane_options (GTK_PANED (hpaned),
- "Horizontal",
- "Left",
- "Right"),
- FALSE, FALSE, 0);
+ create_pane_options (GTK_PANED (hpaned),
+ "Horizontal",
+ "Left",
+ "Right"),
+ FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox),
- create_pane_options (GTK_PANED (vpaned),
- "Vertical",
- "Top",
- "Bottom"),
- FALSE, FALSE, 0);
+ create_pane_options (GTK_PANED (vpaned),
+ "Vertical",
+ "Top",
+ "Bottom"),
+ FALSE, FALSE, 0);
gtk_widget_show_all (vbox);
}
diff --git a/demos/gtk-demo/pickers.c b/demos/gtk-demo/pickers.c
index b7754b5..46826b5 100644
--- a/demos/gtk-demo/pickers.c
+++ b/demos/gtk-demo/pickers.c
@@ -25,9 +25,9 @@ do_pickers (GtkWidget *do_widget)
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
- table = gtk_table_new (5, 2, FALSE);
- gtk_table_set_col_spacing (GTK_TABLE (table), 0, 10);
- gtk_table_set_row_spacings (GTK_TABLE (table), 3);
+ table = gtk_grid_new ();
+ gtk_grid_set_row_spacing (GTK_GRID (table), 3);
+ gtk_grid_set_column_spacing (GTK_GRID (table), 10);
gtk_container_add (GTK_CONTAINER (window), table);
gtk_container_set_border_width (GTK_CONTAINER (table), 10);
@@ -35,40 +35,44 @@ do_pickers (GtkWidget *do_widget)
label = gtk_label_new ("Color:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand (label, TRUE);
picker = gtk_color_button_new ();
- gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
- gtk_table_attach_defaults (GTK_TABLE (table), picker, 1, 2, 0, 1);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (table), picker, 1, 0, 1, 1);
label = gtk_label_new ("Font:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand (label, TRUE);
picker = gtk_font_button_new ();
- gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
- gtk_table_attach_defaults (GTK_TABLE (table), picker, 1, 2, 1, 2);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (table), picker, 1, 1, 1, 1);
label = gtk_label_new ("File:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand (label, TRUE);
picker = gtk_file_chooser_button_new ("Pick a File",
GTK_FILE_CHOOSER_ACTION_OPEN);
- gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
- gtk_table_attach_defaults (GTK_TABLE (table), picker, 1, 2, 2, 3);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
+ gtk_grid_attach (GTK_GRID (table), picker, 1, 2, 1, 1);
label = gtk_label_new ("Folder:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
picker = gtk_file_chooser_button_new ("Pick a Folder",
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
- gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4);
- gtk_table_attach_defaults (GTK_TABLE (table), picker, 1, 2, 3, 4);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
+ gtk_grid_attach (GTK_GRID (table), picker, 1, 3, 1, 1);
label = gtk_label_new ("Mail:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand (label, TRUE);
picker = gtk_app_chooser_button_new ("x-scheme-handler/mailto");
gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (picker), TRUE);
- gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 4, 5);
- gtk_table_attach_defaults (GTK_TABLE (table), picker, 1, 2, 4, 5);
+ gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
+ gtk_grid_attach (GTK_GRID (table), picker, 1, 4, 1, 1);
}
if (!gtk_widget_get_visible (window))
diff --git a/demos/gtk-demo/sizegroup.c b/demos/gtk-demo/sizegroup.c
index 5bc95b7..cffe2bb 100644
--- a/demos/gtk-demo/sizegroup.c
+++ b/demos/gtk-demo/sizegroup.c
@@ -36,7 +36,7 @@ create_combo_box (const char **strings)
}
static void
-add_row (GtkTable *table,
+add_row (GtkGrid *table,
int row,
GtkSizeGroup *size_group,
const char *label_text,
@@ -48,18 +48,13 @@ add_row (GtkTable *table,
label = gtk_label_new_with_mnemonic (label_text);
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_END);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1, row, row + 1,
- GTK_EXPAND | GTK_FILL, 0,
- 0, 0);
-
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_grid_attach (table, label, 0, row, 1, 1);
+
combo_box = create_combo_box (options);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo_box);
gtk_size_group_add_widget (size_group, combo_box);
- gtk_table_attach (GTK_TABLE (table), combo_box,
- 1, 2, row, row + 1,
- 0, 0,
- 0, 0);
+ gtk_grid_attach (table, combo_box, 1, row, 1, 1);
}
static void
@@ -130,33 +125,33 @@ do_sizegroup (GtkWidget *do_widget)
frame = gtk_frame_new ("Color Options");
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
- table = gtk_table_new (2, 2, FALSE);
+ table = gtk_grid_new ();
gtk_container_set_border_width (GTK_CONTAINER (table), 5);
- gtk_table_set_row_spacings (GTK_TABLE (table), 5);
- gtk_table_set_col_spacings (GTK_TABLE (table), 10);
+ gtk_grid_set_row_spacing (GTK_GRID (table), 5);
+ gtk_grid_set_column_spacing (GTK_GRID (table), 10);
gtk_container_add (GTK_CONTAINER (frame), table);
- add_row (GTK_TABLE (table), 0, size_group, "_Foreground", color_options);
- add_row (GTK_TABLE (table), 1, size_group, "_Background", color_options);
+ add_row (GTK_GRID (table), 0, size_group, "_Foreground", color_options);
+ add_row (GTK_GRID (table), 1, size_group, "_Background", color_options);
/* And another frame holding line style options
*/
frame = gtk_frame_new ("Line Options");
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
- table = gtk_table_new (2, 2, FALSE);
+ table = gtk_grid_new ();
gtk_container_set_border_width (GTK_CONTAINER (table), 5);
- gtk_table_set_row_spacings (GTK_TABLE (table), 5);
- gtk_table_set_col_spacings (GTK_TABLE (table), 10);
+ gtk_grid_set_row_spacing (GTK_GRID (table), 5);
+ gtk_grid_set_column_spacing (GTK_GRID (table), 10);
gtk_container_add (GTK_CONTAINER (frame), table);
- add_row (GTK_TABLE (table), 0, size_group, "_Dashing", dash_options);
- add_row (GTK_TABLE (table), 1, size_group, "_Line ends", end_options);
+ add_row (GTK_GRID (table), 0, size_group, "_Dashing", dash_options);
+ add_row (GTK_GRID (table), 1, size_group, "_Line ends", end_options);
/* And a check button to turn grouping on and off */
check_button = gtk_check_button_new_with_mnemonic ("_Enable grouping");
gtk_box_pack_start (GTK_BOX (vbox), check_button, FALSE, FALSE, 0);
-
+
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
g_signal_connect (check_button, "toggled",
G_CALLBACK (toggle_grouping), size_group);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]