2013-09-29 17:43:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Openismus GmbH
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2014-01-12 12:56:49 +00:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2013-09-29 17:43:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SIMPLE_ITEMS = 0,
|
|
|
|
FOCUS_ITEMS,
|
|
|
|
WRAPPY_ITEMS,
|
2015-08-26 23:48:29 +00:00
|
|
|
IMAGE_ITEMS,
|
|
|
|
BUTTON_ITEMS
|
2013-09-29 17:43:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define INITIAL_HALIGN GTK_ALIGN_FILL
|
|
|
|
#define INITIAL_VALIGN GTK_ALIGN_START
|
|
|
|
#define INITIAL_MINIMUM_LENGTH 3
|
|
|
|
#define INITIAL_MAXIMUM_LENGTH 6
|
|
|
|
#define INITIAL_CSPACING 2
|
|
|
|
#define INITIAL_RSPACING 2
|
|
|
|
#define N_ITEMS 1000
|
|
|
|
|
|
|
|
static GtkFlowBox *the_flowbox = NULL;
|
|
|
|
static gint items_type = SIMPLE_ITEMS;
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_flowbox_simple (GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkWidget *widget, *frame;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < N_ITEMS; i++)
|
|
|
|
{
|
|
|
|
gchar *text = g_strdup_printf ("Item %02d", i);
|
|
|
|
|
|
|
|
widget = gtk_label_new (text);
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (frame), "id", (gpointer)g_strdup (text), g_free);
|
2020-05-08 03:24:58 +00:00
|
|
|
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_flowbox_focus (GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkWidget *widget, *frame, *box;
|
|
|
|
gint i;
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
for (i = 0; i < 200; i++)
|
|
|
|
{
|
|
|
|
sensitive = TRUE;
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), box);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
widget = gtk_label_new ("Label");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
switch (i % 4)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
widget = gtk_entry_new ();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
widget = gtk_button_new_with_label ("Button");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
widget = gtk_label_new ("bla");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
widget = gtk_label_new ("bla");
|
|
|
|
sensitive = FALSE;
|
|
|
|
break;
|
2020-03-06 17:05:43 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2013-09-29 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
if (i % 5 == 0)
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), gtk_switch_new ());
|
2013-09-29 17:43:27 +00:00
|
|
|
|
2020-05-08 03:24:58 +00:00
|
|
|
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
|
2013-09-29 17:43:27 +00:00
|
|
|
if (!sensitive)
|
|
|
|
gtk_widget_set_sensitive (gtk_widget_get_parent (frame), FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-26 23:48:29 +00:00
|
|
|
static void
|
|
|
|
populate_flowbox_buttons (GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 50; i++)
|
|
|
|
{
|
|
|
|
widget = gtk_button_new_with_label ("Button");
|
2020-05-08 03:24:58 +00:00
|
|
|
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), widget, -1);
|
2015-08-26 23:48:29 +00:00
|
|
|
widget = gtk_widget_get_parent (widget);
|
|
|
|
gtk_widget_set_can_focus (widget, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-29 17:43:27 +00:00
|
|
|
static void
|
|
|
|
populate_flowbox_wrappy (GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkWidget *widget, *frame;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
const gchar *strings[] = {
|
|
|
|
"These are", "some wrappy label", "texts", "of various", "lengths.",
|
|
|
|
"They should always be", "shown", "consecutively. Except it's",
|
|
|
|
"hard to say", "where exactly the", "label", "will wrap", "and where exactly",
|
|
|
|
"the actual", "container", "will wrap.", "This label is really really really long !",
|
|
|
|
"Let's add some more", "labels to the",
|
|
|
|
"mix. Just to", "make sure we", "got something to work", "with here."
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (strings); i++)
|
|
|
|
{
|
|
|
|
widget = gtk_label_new (strings[i]);
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (widget), TRUE);
|
|
|
|
gtk_label_set_wrap_mode (GTK_LABEL (widget), PANGO_WRAP_WORD);
|
2013-09-29 17:43:27 +00:00
|
|
|
gtk_label_set_width_chars (GTK_LABEL (widget), 10);
|
|
|
|
g_object_set_data_full (G_OBJECT (frame), "id", (gpointer)g_strdup (strings[i]), g_free);
|
|
|
|
|
2020-05-08 03:24:58 +00:00
|
|
|
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
|
2013-09-29 17:43:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_flowbox_images (GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkWidget *widget, *image, *label;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < N_ITEMS; i++)
|
|
|
|
{
|
|
|
|
gchar *text = g_strdup_printf ("Item %02d", i);
|
|
|
|
|
|
|
|
widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
|
|
|
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("face-wink");
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2013-09-29 17:43:27 +00:00
|
|
|
gtk_widget_set_hexpand (image, TRUE);
|
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (image), 256);
|
|
|
|
|
|
|
|
label = gtk_label_new (text);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (widget), image);
|
|
|
|
gtk_box_append (GTK_BOX (widget), label);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (widget), "id", (gpointer)g_strdup (text), g_free);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_items (GtkFlowBox *flowbox)
|
|
|
|
{
|
2020-05-08 03:24:58 +00:00
|
|
|
GtkWidget *child;
|
2013-09-29 17:43:27 +00:00
|
|
|
|
2020-05-08 03:24:58 +00:00
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (flowbox))))
|
|
|
|
gtk_flow_box_remove (flowbox, child);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
if (items_type == SIMPLE_ITEMS)
|
|
|
|
populate_flowbox_simple (flowbox);
|
|
|
|
else if (items_type == FOCUS_ITEMS)
|
|
|
|
populate_flowbox_focus (flowbox);
|
|
|
|
else if (items_type == WRAPPY_ITEMS)
|
|
|
|
populate_flowbox_wrappy (flowbox);
|
|
|
|
else if (items_type == IMAGE_ITEMS)
|
|
|
|
populate_flowbox_images (flowbox);
|
2015-08-26 23:48:29 +00:00
|
|
|
else if (items_type == BUTTON_ITEMS)
|
|
|
|
populate_flowbox_buttons (flowbox);
|
2013-09-29 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
horizontal_alignment_changed (GtkComboBox *box,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkAlign alignment = gtk_combo_box_get_active (box);
|
|
|
|
|
|
|
|
gtk_widget_set_halign (GTK_WIDGET (flowbox), alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vertical_alignment_changed (GtkComboBox *box,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkAlign alignment = gtk_combo_box_get_active (box);
|
|
|
|
|
|
|
|
gtk_widget_set_valign (GTK_WIDGET (flowbox), alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
orientation_changed (GtkComboBox *box,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkOrientation orientation = gtk_combo_box_get_active (box);
|
|
|
|
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (flowbox), orientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_mode_changed (GtkComboBox *box,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
GtkSelectionMode mode = gtk_combo_box_get_active (box);
|
|
|
|
|
|
|
|
gtk_flow_box_set_selection_mode (flowbox, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_length_changed (GtkSpinButton *spin,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
gint length = gtk_spin_button_get_value_as_int (spin);
|
|
|
|
|
|
|
|
gtk_flow_box_set_min_children_per_line (flowbox, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
max_line_length_changed (GtkSpinButton *spin,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
gint length = gtk_spin_button_get_value_as_int (spin);
|
|
|
|
|
|
|
|
gtk_flow_box_set_max_children_per_line (flowbox, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spacing_changed (GtkSpinButton *button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkOrientation orientation = GPOINTER_TO_INT (data);
|
|
|
|
gint state = gtk_spin_button_get_value_as_int (button);
|
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
gtk_flow_box_set_column_spacing (the_flowbox, state);
|
|
|
|
else
|
|
|
|
gtk_flow_box_set_row_spacing (the_flowbox, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
items_changed (GtkComboBox *box,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
items_type = gtk_combo_box_get_active (box);
|
|
|
|
|
|
|
|
populate_items (flowbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
homogeneous_toggled (GtkToggleButton *button,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
gboolean state = gtk_toggle_button_get_active (button);
|
|
|
|
|
|
|
|
gtk_flow_box_set_homogeneous (flowbox, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_child_activated (GtkFlowBox *self,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
const char *id;
|
2020-05-03 00:53:40 +00:00
|
|
|
id = g_object_get_data (G_OBJECT (gtk_flow_box_child_get_child (GTK_FLOW_BOX_CHILD (child))), "id");
|
2013-09-29 17:43:27 +00:00
|
|
|
g_message ("Child activated %p: %s", child, id);
|
|
|
|
}
|
|
|
|
|
2013-10-16 13:40:40 +00:00
|
|
|
static G_GNUC_UNUSED void
|
2013-09-29 17:43:27 +00:00
|
|
|
selection_foreach (GtkFlowBox *self,
|
|
|
|
GtkFlowBoxChild *child_info,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
const char *id;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
2020-05-03 00:53:40 +00:00
|
|
|
child = gtk_flow_box_child_get_child (child_info);
|
2013-09-29 17:43:27 +00:00
|
|
|
id = g_object_get_data (G_OBJECT (child), "id");
|
|
|
|
g_message ("Child selected %p: %s", child, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_selected_children_changed (GtkFlowBox *self)
|
|
|
|
{
|
|
|
|
g_message ("Selection changed");
|
|
|
|
//gtk_flow_box_selected_foreach (self, selection_foreach, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
filter_func (GtkFlowBoxChild *child, gpointer user_data)
|
|
|
|
{
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
index = gtk_flow_box_child_get_index (child);
|
|
|
|
|
|
|
|
return (index % 3) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filter_toggled (GtkToggleButton *button,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
gboolean state = gtk_toggle_button_get_active (button);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
gtk_flow_box_set_filter_func (flowbox, filter_func, NULL, NULL);
|
|
|
|
else
|
|
|
|
gtk_flow_box_set_filter_func (flowbox, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
sort_func (GtkFlowBoxChild *a,
|
|
|
|
GtkFlowBoxChild *b,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gchar *ida, *idb;
|
|
|
|
|
2020-05-03 00:53:40 +00:00
|
|
|
ida = (gchar *)g_object_get_data (G_OBJECT (gtk_flow_box_child_get_child (a)), "id");
|
|
|
|
idb = (gchar *)g_object_get_data (G_OBJECT (gtk_flow_box_child_get_child (b)), "id");
|
2013-09-29 17:43:27 +00:00
|
|
|
return g_strcmp0 (ida, idb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sort_toggled (GtkToggleButton *button,
|
|
|
|
GtkFlowBox *flowbox)
|
|
|
|
{
|
|
|
|
gboolean state = gtk_toggle_button_get_active (button);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
gtk_flow_box_set_sort_func (flowbox, sort_func, NULL, NULL);
|
|
|
|
else
|
|
|
|
gtk_flow_box_set_sort_func (flowbox, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
create_window (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *hbox, *vbox, *flowbox_cntl, *items_cntl;
|
|
|
|
GtkWidget *flowbox, *widget, *expander, *swindow;
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-09-29 17:43:27 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), hbox);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
swindow = gtk_scrolled_window_new ();
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (swindow, TRUE);
|
2013-09-29 17:43:27 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), swindow);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
flowbox = gtk_flow_box_new ();
|
|
|
|
gtk_widget_set_halign (flowbox, GTK_ALIGN_END);
|
|
|
|
the_flowbox = (GtkFlowBox *)flowbox;
|
|
|
|
gtk_widget_set_halign (flowbox, INITIAL_HALIGN);
|
|
|
|
gtk_widget_set_valign (flowbox, INITIAL_VALIGN);
|
|
|
|
gtk_flow_box_set_column_spacing (GTK_FLOW_BOX (flowbox), INITIAL_CSPACING);
|
|
|
|
gtk_flow_box_set_row_spacing (GTK_FLOW_BOX (flowbox), INITIAL_RSPACING);
|
|
|
|
gtk_flow_box_set_min_children_per_line (GTK_FLOW_BOX (flowbox), INITIAL_MINIMUM_LENGTH);
|
|
|
|
gtk_flow_box_set_max_children_per_line (GTK_FLOW_BOX (flowbox), INITIAL_MAXIMUM_LENGTH);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (swindow), flowbox);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
gtk_flow_box_set_hadjustment (GTK_FLOW_BOX (flowbox),
|
|
|
|
gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (swindow)));
|
|
|
|
gtk_flow_box_set_vadjustment (GTK_FLOW_BOX (flowbox),
|
|
|
|
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (swindow)));
|
|
|
|
|
|
|
|
g_signal_connect (flowbox, "child-activated", G_CALLBACK (on_child_activated), NULL);
|
|
|
|
g_signal_connect (flowbox, "selected-children-changed", G_CALLBACK (on_selected_children_changed), NULL);
|
|
|
|
|
|
|
|
/* Add Flowbox test control frame */
|
|
|
|
expander = gtk_expander_new ("Flow Box controls");
|
|
|
|
gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
|
|
|
|
flowbox_cntl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2020-05-07 04:05:51 +00:00
|
|
|
gtk_expander_set_child (GTK_EXPANDER (expander), flowbox_cntl);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), expander);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Homogeneous");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set whether the items should be displayed at the same size");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
|
|
|
G_CALLBACK (homogeneous_toggled), flowbox);
|
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Activate on single click");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
|
|
|
g_object_bind_property (widget, "active",
|
|
|
|
flowbox, "activate-on-single-click",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
/* Add alignment controls */
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Fill");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Start");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "End");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Center");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), INITIAL_HALIGN);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the horizontal alignment policy");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (horizontal_alignment_changed), flowbox);
|
|
|
|
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Fill");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Start");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "End");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Center");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), INITIAL_VALIGN);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the vertical alignment policy");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (vertical_alignment_changed), flowbox);
|
|
|
|
|
|
|
|
/* Add Orientation control */
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the flowbox orientation");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (orientation_changed), flowbox);
|
|
|
|
|
|
|
|
/* Add selection mode control */
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "None");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Single");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Browse");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Multiple");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the selection mode");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (selection_mode_changed), flowbox);
|
|
|
|
|
|
|
|
/* Add minimum line length in items control */
|
|
|
|
widget = gtk_spin_button_new_with_range (1, 10, 1);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_MINIMUM_LENGTH);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the minimum amount of items per line before wrapping");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (line_length_changed), flowbox);
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
|
|
|
G_CALLBACK (line_length_changed), flowbox);
|
|
|
|
|
|
|
|
/* Add natural line length in items control */
|
|
|
|
widget = gtk_spin_button_new_with_range (1, 10, 1);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_MAXIMUM_LENGTH);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the natural amount of items per line ");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (max_line_length_changed), flowbox);
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
|
|
|
G_CALLBACK (max_line_length_changed), flowbox);
|
|
|
|
|
|
|
|
/* Add horizontal/vertical spacing controls */
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
|
|
|
|
widget = gtk_label_new ("H Spacing");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0, 30, 1);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_CSPACING);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the horizontal spacing between children");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_HORIZONTAL));
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
|
|
|
G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_HORIZONTAL));
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), hbox);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
|
|
|
|
widget = gtk_label_new ("V Spacing");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0, 30, 1);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_RSPACING);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the vertical spacing between children");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_VERTICAL));
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
|
|
|
G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_VERTICAL));
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), hbox);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
/* filtering and sorting */
|
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Filter");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set whether some items should be filtered out");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
|
|
|
G_CALLBACK (filter_toggled), flowbox);
|
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Sort");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set whether items should be sorted");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (flowbox_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
|
|
|
G_CALLBACK (sort_toggled), flowbox);
|
|
|
|
|
|
|
|
|
|
|
|
/* Add test items control frame */
|
|
|
|
expander = gtk_expander_new ("Test item controls");
|
|
|
|
gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
|
|
|
|
items_cntl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2020-05-07 04:05:51 +00:00
|
|
|
gtk_expander_set_child (GTK_EXPANDER (expander), items_cntl);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), expander);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
/* Add Items control */
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Simple");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Focus");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Wrappy");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Images");
|
2015-08-26 23:48:29 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Buttons");
|
2013-09-29 17:43:27 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (widget, "Set the item set to use");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (items_cntl), widget);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (items_changed), flowbox);
|
|
|
|
|
|
|
|
populate_items (GTK_FLOW_BOX (flowbox));
|
|
|
|
|
|
|
|
/* This line was added only for the convenience of reproducing
|
|
|
|
* a height-for-width inside GtkScrolledWindow bug (bug 629778).
|
|
|
|
* -Tristan
|
|
|
|
*/
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 390, -1);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2013-09-29 17:43:27 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2013-09-29 17:43:27 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
window = create_window ();
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-09-29 17:43:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|