2010-10-26 02:35:04 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
horizontal_policy_changed (GtkComboBox *combo_box,
|
|
|
|
GtkViewport *viewport)
|
|
|
|
{
|
|
|
|
GtkScrollablePolicy policy = gtk_combo_box_get_active (combo_box);
|
|
|
|
|
|
|
|
gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (viewport), policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vertical_policy_changed (GtkComboBox *combo_box,
|
|
|
|
GtkViewport *viewport)
|
|
|
|
{
|
|
|
|
GtkScrollablePolicy policy = gtk_combo_box_get_active (combo_box);
|
|
|
|
|
|
|
|
gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (viewport), policy);
|
|
|
|
}
|
|
|
|
|
2010-10-31 18:09:48 +00:00
|
|
|
static void
|
|
|
|
content_width_changed (GtkSpinButton *spin_button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkScrolledWindow *swindow = data;
|
2020-07-24 20:32:16 +00:00
|
|
|
double value;
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
value = gtk_spin_button_get_value (spin_button);
|
2020-07-24 13:54:49 +00:00
|
|
|
gtk_scrolled_window_set_min_content_width (swindow, (int)value);
|
2010-10-31 18:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
content_height_changed (GtkSpinButton *spin_button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkScrolledWindow *swindow = data;
|
2020-07-24 20:32:16 +00:00
|
|
|
double value;
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
value = gtk_spin_button_get_value (spin_button);
|
2020-07-24 13:54:49 +00:00
|
|
|
gtk_scrolled_window_set_min_content_height (swindow, (int)value);
|
2010-10-31 18:09:48 +00:00
|
|
|
}
|
2010-10-26 02:35:04 +00:00
|
|
|
|
2011-02-11 12:45:21 +00:00
|
|
|
static void
|
|
|
|
kinetic_scrolling_changed (GtkToggleButton *toggle_button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkScrolledWindow *swindow = data;
|
|
|
|
gboolean enabled = gtk_toggle_button_get_active (toggle_button);
|
|
|
|
|
|
|
|
gtk_scrolled_window_set_kinetic_scrolling (swindow, enabled);
|
|
|
|
}
|
|
|
|
|
2016-06-02 02:32:35 +00:00
|
|
|
static void
|
|
|
|
add_row (GtkButton *button,
|
|
|
|
GtkListBox *listbox)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
|
2016-10-09 00:32:00 +00:00
|
|
|
row = g_object_new (GTK_TYPE_LIST_BOX_ROW, NULL);
|
2020-05-08 06:19:18 +00:00
|
|
|
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), gtk_label_new ("test"));
|
|
|
|
gtk_list_box_insert (GTK_LIST_BOX (listbox), row, -1);
|
2016-06-02 02:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_row (GtkButton *button,
|
|
|
|
GtkListBox *listbox)
|
|
|
|
{
|
2020-05-08 06:19:18 +00:00
|
|
|
GtkWidget *last;
|
2016-06-02 02:32:35 +00:00
|
|
|
|
2020-05-08 06:19:18 +00:00
|
|
|
last = gtk_widget_get_last_child (GTK_WIDGET (listbox));
|
2016-06-02 02:32:35 +00:00
|
|
|
if (last)
|
2020-05-08 06:19:18 +00:00
|
|
|
gtk_list_box_remove (GTK_LIST_BOX (listbox), last);
|
2016-06-02 02:32:35 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 02:35:04 +00:00
|
|
|
static void
|
|
|
|
scrollable_policy (void)
|
|
|
|
{
|
2016-06-02 02:32:35 +00:00
|
|
|
GtkWidget *window, *swindow, *hbox, *vbox, *frame, *cntl, *listbox;
|
|
|
|
GtkWidget *viewport, *label, *expander, *widget, *popover;
|
2010-10-26 02:35:04 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
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);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new ("Scrolled Window");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (frame, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), frame);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
swindow = gtk_scrolled_window_new ();
|
2010-10-26 02:35:04 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), swindow);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
viewport = gtk_viewport_new (NULL, NULL);
|
|
|
|
label = gtk_label_new ("Here is a wrapping label with a minimum width-chars of 40 and "
|
|
|
|
"a natural max-width-chars of 100 to demonstrate the usage of "
|
|
|
|
"scrollable widgets \"hscroll-policy\" and \"vscroll-policy\" "
|
|
|
|
"properties. Note also that when playing with the window height, "
|
|
|
|
"one can observe that the vscrollbar disappears as soon as there "
|
|
|
|
"is enough height to fit the content vertically if the window were "
|
|
|
|
"to be allocated a width without a vscrollbar present");
|
|
|
|
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2010-10-26 02:35:04 +00:00
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), 40);
|
|
|
|
gtk_label_set_max_width_chars (GTK_LABEL (label), 100);
|
|
|
|
|
2020-05-01 19:43:09 +00:00
|
|
|
gtk_viewport_set_child (GTK_VIEWPORT (viewport), label);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (swindow), viewport);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
/* Add controls here */
|
|
|
|
expander = gtk_expander_new ("Controls");
|
|
|
|
gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
|
2010-10-31 17:07:20 +00:00
|
|
|
cntl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2020-05-07 04:05:51 +00:00
|
|
|
gtk_expander_set_child (GTK_EXPANDER (expander), cntl);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), expander);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
/* Add Horizontal policy control here */
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
widget = gtk_label_new ("hscroll-policy");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Minimum");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Natural");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (cntl), hbox);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (horizontal_policy_changed), viewport);
|
|
|
|
|
|
|
|
/* Add Vertical policy control here */
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
widget = gtk_label_new ("vscroll-policy");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Minimum");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Natural");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (cntl), hbox);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (vertical_policy_changed), viewport);
|
|
|
|
|
2010-10-31 18:09:48 +00:00
|
|
|
/* Content size controls */
|
2010-10-31 19:00:38 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
widget = gtk_label_new ("min-content-width");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (100.0, 1000.0, 10.0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (cntl), hbox);
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
|
|
|
G_CALLBACK (content_width_changed), swindow);
|
|
|
|
|
2010-10-31 19:00:38 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
widget = gtk_label_new ("min-content-height");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (100.0, 1000.0, 10.0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (cntl), hbox);
|
2010-10-31 18:09:48 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
|
|
|
G_CALLBACK (content_height_changed), swindow);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
2011-02-11 12:45:21 +00:00
|
|
|
/* Add Kinetic scrolling control here */
|
|
|
|
widget = gtk_check_button_new_with_label ("Kinetic scrolling");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (cntl), widget);
|
2011-02-11 12:45:21 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
|
|
|
G_CALLBACK (kinetic_scrolling_changed), swindow);
|
|
|
|
|
2010-10-26 02:35:04 +00:00
|
|
|
gtk_widget_show (window);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
/* Popover */
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = gtk_popover_new ();
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
widget = gtk_menu_button_new ();
|
|
|
|
gtk_menu_button_set_popover (GTK_MENU_BUTTON (widget), popover);
|
2019-05-21 20:19:40 +00:00
|
|
|
gtk_menu_button_set_label (GTK_MENU_BUTTON (widget), "Popover");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (cntl), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-05-02 02:22:20 +00:00
|
|
|
gtk_popover_set_child (GTK_POPOVER (popover), vbox);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
/* Popover's scrolled window */
|
2020-06-24 15:25:09 +00:00
|
|
|
swindow = gtk_scrolled_window_new ();
|
2016-06-02 02:32:35 +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 (vbox), swindow);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
/* Listbox */
|
|
|
|
listbox = gtk_list_box_new ();
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (swindow), listbox);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
/* Min content */
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
|
|
|
|
widget = gtk_label_new ("min-content-width");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0.0, 150.0, 10.0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
g_object_bind_property (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)),
|
|
|
|
"value",
|
|
|
|
swindow,
|
|
|
|
"min-content-width",
|
|
|
|
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
widget = gtk_label_new ("min-content-height");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0.0, 150.0, 10.0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
g_object_bind_property (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)),
|
|
|
|
"value",
|
|
|
|
swindow,
|
|
|
|
"min-content-height",
|
|
|
|
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
/* Max content */
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
|
|
|
|
widget = gtk_label_new ("max-content-width");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (250.0, 1000.0, 10.0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
g_object_bind_property (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)),
|
|
|
|
"value",
|
|
|
|
swindow,
|
|
|
|
"max-content-width",
|
|
|
|
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
widget = gtk_label_new ("max-content-height");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (250.0, 1000.0, 10.0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
g_object_bind_property (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)),
|
|
|
|
"value",
|
|
|
|
swindow,
|
|
|
|
"max-content-height",
|
|
|
|
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
/* Add and Remove buttons */
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
|
|
|
|
widget = gtk_button_new_with_label ("Remove");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
g_signal_connect (widget, "clicked",
|
|
|
|
G_CALLBACK (remove_row), listbox);
|
|
|
|
|
|
|
|
widget = gtk_button_new_with_label ("Add");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2016-06-02 02:32:35 +00:00
|
|
|
|
|
|
|
g_signal_connect (widget, "clicked",
|
|
|
|
G_CALLBACK (add_row), listbox);
|
2010-10-26 02:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
scrollable_policy ();
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2010-10-26 02:35:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|