2013-04-21 11:51:14 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2022-10-08 00:59:10 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
GtkWidget *stack;
|
|
|
|
GtkWidget *switcher;
|
2014-08-23 16:38:42 +00:00
|
|
|
GtkWidget *sidebar;
|
2013-04-21 11:51:14 +00:00
|
|
|
GtkWidget *w1;
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_visible_child (GtkWidget *button, gpointer data)
|
|
|
|
{
|
|
|
|
gtk_stack_set_visible_child (GTK_STACK (stack), GTK_WIDGET (data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_visible_child_name (GtkWidget *button, gpointer data)
|
|
|
|
{
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), (const char *)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-10-26 19:07:26 +00:00
|
|
|
toggle_hhomogeneous (GtkWidget *button, gpointer data)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-08-30 23:36:27 +00:00
|
|
|
gboolean active = gtk_check_button_get_active (GTK_CHECK_BUTTON (button));
|
2014-10-26 19:07:26 +00:00
|
|
|
gtk_stack_set_hhomogeneous (GTK_STACK (stack), active);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
toggle_vhomogeneous (GtkWidget *button, gpointer data)
|
|
|
|
{
|
2020-08-30 23:36:27 +00:00
|
|
|
gboolean active = gtk_check_button_get_active (GTK_CHECK_BUTTON (button));
|
2014-10-26 19:07:26 +00:00
|
|
|
gtk_stack_set_vhomogeneous (GTK_STACK (stack), active);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
toggle_icon_name (GtkWidget *button, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
|
2019-04-03 15:10:10 +00:00
|
|
|
GtkStackPage *page;
|
|
|
|
|
2020-05-11 14:27:41 +00:00
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), w1);
|
2019-04-03 15:10:10 +00:00
|
|
|
g_object_set (page, "icon-name", active ? "edit-find-symbolic" : NULL, NULL);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
toggle_transitions (GtkWidget *combo, gpointer data)
|
|
|
|
{
|
|
|
|
int id = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
|
|
|
|
gtk_stack_set_transition_type (GTK_STACK (stack), id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-06 17:05:43 +00:00
|
|
|
on_back_button_clicked (GtkButton *button, gpointer user_data)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *seq[] = { "1", "2", "3" };
|
|
|
|
const char *vis;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
vis = gtk_stack_get_visible_child_name (GTK_STACK (stack));
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
for (i = 1; i < G_N_ELEMENTS (seq); i++)
|
|
|
|
{
|
2013-04-22 00:17:40 +00:00
|
|
|
if (g_strcmp0 (vis, seq[i]) == 0)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-03-06 17:05:43 +00:00
|
|
|
gtk_stack_set_visible_child_full (GTK_STACK (stack), seq[i - 1], GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT);
|
2013-04-21 11:51:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-06 17:05:43 +00:00
|
|
|
on_forward_button_clicked (GtkButton *button, gpointer user_data)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *seq[] = { "1", "2", "3" };
|
|
|
|
const char *vis;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
vis = gtk_stack_get_visible_child_name (GTK_STACK (stack));
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (seq) - 1; i++)
|
|
|
|
{
|
2013-04-22 00:17:40 +00:00
|
|
|
if (g_strcmp0 (vis, seq[i]) == 0)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-03-06 17:05:43 +00:00
|
|
|
gtk_stack_set_visible_child_full (GTK_STACK (stack), seq[i + 1], GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT);
|
2013-04-21 11:51:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-06 17:05:43 +00:00
|
|
|
update_back_button_sensitivity (GtkStack *_stack, GParamSpec *pspec, GtkWidget *button)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *vis;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
vis = gtk_stack_get_visible_child_name (GTK_STACK (stack));
|
2013-04-22 00:17:40 +00:00
|
|
|
gtk_widget_set_sensitive (button, g_strcmp0 (vis, "1") != 0);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-06 17:05:43 +00:00
|
|
|
update_forward_button_sensitivity (GtkStack *_stack, GParamSpec *pspec, GtkWidget *button)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *vis;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
vis = gtk_stack_get_visible_child_name (GTK_STACK (stack));
|
2013-04-22 00:17:40 +00:00
|
|
|
gtk_widget_set_sensitive (button, g_strcmp0 (vis, "3") != 0);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
int
|
|
|
|
main (int argc,
|
2020-07-24 18:40:36 +00:00
|
|
|
char ** argv)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2014-08-23 16:38:42 +00:00
|
|
|
GtkWidget *window, *box, *button, *hbox, *combo, *layout;
|
2013-04-21 11:51:14 +00:00
|
|
|
GtkWidget *w2, *w3;
|
|
|
|
GtkListStore* store;
|
|
|
|
GtkWidget *tree_view;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkWidget *scrolled_win;
|
|
|
|
int i;
|
|
|
|
GtkTreeIter iter;
|
2014-05-02 21:43:18 +00:00
|
|
|
GEnumClass *class;
|
2019-04-03 15:10:10 +00:00
|
|
|
GtkStackPage *page;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-04-21 11:51:14 +00:00
|
|
|
gtk_widget_set_size_request (window, 300, 300);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
switcher = gtk_stack_switcher_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), switcher);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
stack = gtk_stack_new ();
|
|
|
|
|
|
|
|
/* Make transitions longer so we can see that they work */
|
2013-08-31 15:59:19 +00:00
|
|
|
gtk_stack_set_transition_duration (GTK_STACK (stack), 1500);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
gtk_widget_set_halign (stack, GTK_ALIGN_START);
|
2015-11-04 18:10:16 +00:00
|
|
|
gtk_widget_set_vexpand (stack, TRUE);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
/* Add sidebar before stack */
|
2015-02-12 17:09:13 +00:00
|
|
|
sidebar = gtk_stack_sidebar_new ();
|
|
|
|
gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar), GTK_STACK (stack));
|
2014-08-23 16:38:42 +00:00
|
|
|
layout = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (layout), sidebar);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (stack, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (layout), stack);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), layout);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (stack));
|
|
|
|
|
|
|
|
w1 = gtk_text_view_new ();
|
|
|
|
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (w1)),
|
|
|
|
"This is a\nTest\nBalh!", -1);
|
|
|
|
|
2019-04-03 15:10:10 +00:00
|
|
|
gtk_stack_add_titled (GTK_STACK (stack), w1, "1", "1");
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
w2 = gtk_button_new_with_label ("Gazoooooooooooooooonk");
|
2019-04-03 15:10:10 +00:00
|
|
|
gtk_stack_add_titled (GTK_STACK (stack), w2, "2", "2");
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), w2);
|
|
|
|
g_object_set (page, "needs-attention", TRUE, NULL);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_win = gtk_scrolled_window_new ();
|
2013-04-21 11:51:14 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_widget_set_size_request (scrolled_win, 100, 200);
|
|
|
|
|
|
|
|
|
|
|
|
store = gtk_list_store_new (1, G_TYPE_STRING);
|
|
|
|
|
|
|
|
for (i = 0; i < 40; i++)
|
|
|
|
gtk_list_store_insert_with_values (store, &iter, i, 0, "Testvalule", -1);
|
|
|
|
|
|
|
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
|
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_win), tree_view);
|
2013-04-21 11:51:14 +00:00
|
|
|
w3 = scrolled_win;
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Target", renderer,
|
|
|
|
"text", 0, NULL);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
|
|
|
|
|
|
|
gtk_stack_add_titled (GTK_STACK (stack), w3, "3", "3");
|
|
|
|
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), hbox);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("1");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) set_visible_child, w1);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("2");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) set_visible_child, w2);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("3");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) set_visible_child, w3);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("1");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) set_visible_child_name, (gpointer) "1");
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("2");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) set_visible_child_name, (gpointer) "2");
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("3");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) set_visible_child_name, (gpointer) "3");
|
|
|
|
|
2014-10-26 19:07:26 +00:00
|
|
|
button = gtk_check_button_new ();
|
2020-08-30 23:36:27 +00:00
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (button),
|
|
|
|
gtk_stack_get_hhomogeneous (GTK_STACK (stack)));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2014-10-26 19:07:26 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) toggle_hhomogeneous, NULL);
|
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
button = gtk_check_button_new_with_label ("homogeneous");
|
2020-08-30 23:36:27 +00:00
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (button),
|
|
|
|
gtk_stack_get_vhomogeneous (GTK_STACK (stack)));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2014-10-26 19:07:26 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) toggle_vhomogeneous, NULL);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
button = gtk_toggle_button_new_with_label ("Add icon");
|
|
|
|
g_signal_connect (button, "toggled", (GCallback) toggle_icon_name, NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
combo = gtk_combo_box_text_new ();
|
2014-05-02 21:43:18 +00:00
|
|
|
class = g_type_class_ref (GTK_TYPE_STACK_TRANSITION_TYPE);
|
|
|
|
for (i = 0; i < class->n_values; i++)
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), class->values[i].value_nick);
|
|
|
|
g_type_class_unref (class);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), combo);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (combo, "changed", (GCallback) toggle_transitions, NULL);
|
2014-05-02 21:43:18 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), hbox);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("<");
|
|
|
|
g_signal_connect (button, "clicked", (GCallback) on_back_button_clicked, stack);
|
|
|
|
g_signal_connect (stack, "notify::visible-child-name",
|
|
|
|
(GCallback)update_back_button_sensitivity, button);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label (">");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2013-04-21 11:51:14 +00:00
|
|
|
g_signal_connect (button, "clicked", (GCallback) on_forward_button_clicked, stack);
|
|
|
|
g_signal_connect (stack, "notify::visible-child-name",
|
|
|
|
(GCallback)update_forward_button_sensitivity, button);
|
|
|
|
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|