2001-05-18 18:30:59 +00:00
|
|
|
/* Size Groups
|
|
|
|
*
|
|
|
|
* GtkSizeGroup provides a mechanism for grouping a number of
|
|
|
|
* widgets together so they all request the same amount of space.
|
2011-09-02 03:55:47 +00:00
|
|
|
* This is typically useful when you want a column of widgets to
|
2001-05-18 18:30:59 +00:00
|
|
|
* have the same size, but you can't use a GtkTable widget.
|
2011-09-02 03:55:47 +00:00
|
|
|
*
|
2001-05-18 18:30:59 +00:00
|
|
|
* Note that size groups only affect the amount of space requested,
|
|
|
|
* not the size that the widgets finally receive. If you want the
|
|
|
|
* widgets in a GtkSizeGroup to actually be the same size, you need
|
|
|
|
* to pack them in such a way that they get the size they request
|
|
|
|
* and not more. For example, if you are packing your widgets
|
|
|
|
* into a table, you would not include the GTK_FILL flag.
|
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2001-05-18 18:30:59 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2003-10-10 17:18:34 +00:00
|
|
|
/* Convenience function to create a combo box holding a number of strings
|
2001-05-18 18:30:59 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2003-10-10 17:18:34 +00:00
|
|
|
create_combo_box (const char **strings)
|
2001-05-18 18:30:59 +00:00
|
|
|
{
|
2003-10-10 17:18:34 +00:00
|
|
|
GtkWidget *combo_box;
|
2001-05-18 18:30:59 +00:00
|
|
|
const char **str;
|
|
|
|
|
2010-10-02 16:19:46 +00:00
|
|
|
combo_box = gtk_combo_box_text_new ();
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-05-18 18:30:59 +00:00
|
|
|
for (str = strings; *str; str++)
|
2010-10-02 16:19:46 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), *str);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
2003-10-10 17:18:34 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
2003-10-10 17:18:34 +00:00
|
|
|
return combo_box;
|
2001-05-18 18:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-31 15:10:19 +00:00
|
|
|
add_row (GtkGrid *table,
|
2011-09-02 03:55:47 +00:00
|
|
|
int row,
|
|
|
|
GtkSizeGroup *size_group,
|
|
|
|
const char *label_text,
|
|
|
|
const char **options)
|
2001-05-18 18:30:59 +00:00
|
|
|
{
|
2003-10-10 17:18:34 +00:00
|
|
|
GtkWidget *combo_box;
|
2001-05-18 18:30:59 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
|
2001-09-25 16:44:39 +00:00
|
|
|
label = gtk_label_new_with_mnemonic (label_text);
|
2011-06-12 23:28:48 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_grid_attach (table, label, 0, row, 1, 1);
|
|
|
|
|
2003-10-10 17:18:34 +00:00
|
|
|
combo_box = create_combo_box (options);
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo_box);
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_set_halign (combo_box, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (combo_box, GTK_ALIGN_BASELINE);
|
2003-10-10 17:18:34 +00:00
|
|
|
gtk_size_group_add_widget (size_group, combo_box);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (table, combo_box, 1, row, 1, 1);
|
2001-05-18 18:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
toggle_grouping (GtkToggleButton *check_button,
|
2011-09-02 03:55:47 +00:00
|
|
|
GtkSizeGroup *size_group)
|
2001-05-18 18:30:59 +00:00
|
|
|
{
|
|
|
|
GtkSizeGroupMode new_mode;
|
|
|
|
|
|
|
|
/* GTK_SIZE_GROUP_NONE is not generally useful, but is useful
|
|
|
|
* here to show the effect of GTK_SIZE_GROUP_HORIZONTAL by
|
|
|
|
* contrast.
|
|
|
|
*/
|
|
|
|
if (gtk_toggle_button_get_active (check_button))
|
|
|
|
new_mode = GTK_SIZE_GROUP_HORIZONTAL;
|
|
|
|
else
|
|
|
|
new_mode = GTK_SIZE_GROUP_NONE;
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-05-18 18:30:59 +00:00
|
|
|
gtk_size_group_set_mode (size_group, new_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2003-11-08 22:08:05 +00:00
|
|
|
do_sizegroup (GtkWidget *do_widget)
|
2001-05-18 18:30:59 +00:00
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
2001-05-18 18:30:59 +00:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *check_button;
|
|
|
|
GtkSizeGroup *size_group;
|
|
|
|
|
|
|
|
static const char *color_options[] = {
|
|
|
|
"Red", "Green", "Blue", NULL
|
|
|
|
};
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-05-18 18:30:59 +00:00
|
|
|
static const char *dash_options[] = {
|
|
|
|
"Solid", "Dashed", "Dotted", NULL
|
|
|
|
};
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-05-18 18:30:59 +00:00
|
|
|
static const char *end_options[] = {
|
2015-06-28 13:23:28 +00:00
|
|
|
"Square", "Round", "Double Arrow", NULL
|
2001-05-18 18:30:59 +00:00
|
|
|
};
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-05-18 18:30:59 +00:00
|
|
|
if (!window)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Size Groups");
|
2001-06-25 23:48:51 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2011-09-02 03:55:47 +00:00
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (vbox, "margin", 5, NULL);
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
|
|
|
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
2014-05-13 19:50:23 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (window), "size-group", size_group, g_object_unref);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
|
|
|
/* Create one frame holding color options */
|
2001-05-18 18:30:59 +00:00
|
|
|
frame = gtk_frame_new ("Color Options");
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), frame);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
table = gtk_grid_new ();
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (table, "margin", 5, NULL);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (table), 5);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (table), 10);
|
2001-05-18 18:30:59 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
add_row (GTK_GRID (table), 0, size_group, "_Foreground", color_options);
|
|
|
|
add_row (GTK_GRID (table), 1, size_group, "_Background", color_options);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
/* And another frame holding line style options */
|
2001-05-18 18:30:59 +00:00
|
|
|
frame = gtk_frame_new ("Line Options");
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), frame);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
table = gtk_grid_new ();
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (table, "margin", 5, NULL);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (table), 5);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (table), 10);
|
2001-05-18 18:30:59 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
add_row (GTK_GRID (table), 0, size_group, "_Dashing", dash_options);
|
|
|
|
add_row (GTK_GRID (table), 1, size_group, "_Line ends", end_options);
|
2001-05-18 18:30:59 +00:00
|
|
|
|
|
|
|
/* And a check button to turn grouping on and off */
|
2001-09-25 16:44:39 +00:00
|
|
|
check_button = gtk_check_button_new_with_mnemonic ("_Enable grouping");
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), check_button);
|
2011-08-31 15:10:19 +00:00
|
|
|
|
2001-05-18 18:30:59 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (check_button, "toggled",
|
2011-09-02 03:55:47 +00:00
|
|
|
G_CALLBACK (toggle_grouping), size_group);
|
2001-05-18 18:30:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2001-05-18 18:30:59 +00:00
|
|
|
else
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|