2011-02-11 12:46:35 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_button_clicked (GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
g_print ("Button %d clicked\n", GPOINTER_TO_INT (data));
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static gboolean done = FALSE;
|
|
|
|
|
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
2020-03-06 17:05:43 +00:00
|
|
|
gpointer user_data)
|
2020-02-10 03:24:47 +00:00
|
|
|
{
|
2020-03-06 17:05:43 +00:00
|
|
|
gboolean *is_done = user_data;
|
2020-02-10 03:24:47 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
*is_done = TRUE;
|
2020-02-10 03:24:47 +00:00
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2011-02-11 12:46:35 +00:00
|
|
|
static void
|
|
|
|
kinetic_scrolling (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *swindow, *grid;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *button_grid, *button;
|
|
|
|
GtkWidget *treeview;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkWidget *textview;
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *targets;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2011-02-11 12:46:35 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2011-02-11 12:46:35 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
|
|
|
|
label = gtk_label_new ("Non scrollable widget using viewport");
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
|
|
|
|
label = gtk_label_new ("Scrollable widget: TreeView");
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
|
|
|
|
label = gtk_label_new ("Scrollable widget: TextView");
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 2, 0, 1, 1);
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
|
|
|
|
button_grid = gtk_grid_new ();
|
|
|
|
for (i = 0; i < 80; i++)
|
|
|
|
{
|
2020-03-06 17:05:43 +00:00
|
|
|
char *button_label = g_strdup_printf ("Button number %d", i);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
button = gtk_button_new_with_label (button_label);
|
2011-02-11 12:46:35 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (button_grid), button, 0, i, 1, 1);
|
|
|
|
gtk_widget_set_hexpand (button, TRUE);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (on_button_clicked),
|
|
|
|
GINT_TO_POINTER (i));
|
2020-03-06 17:05:43 +00:00
|
|
|
g_free (button_label);
|
2011-02-11 12:46:35 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
swindow = gtk_scrolled_window_new ();
|
2011-02-11 12:46:35 +00:00
|
|
|
gtk_scrolled_window_set_kinetic_scrolling (GTK_SCROLLED_WINDOW (swindow), TRUE);
|
|
|
|
gtk_scrolled_window_set_capture_button_press (GTK_SCROLLED_WINDOW (swindow), TRUE);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (swindow), button_grid);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), swindow, 0, 1, 1, 1);
|
|
|
|
|
|
|
|
treeview = gtk_tree_view_new ();
|
2020-02-18 00:41:42 +00:00
|
|
|
targets = gdk_content_formats_new_for_gtype (GTK_TYPE_TREE_ROW_DATA);
|
2011-02-11 12:46:35 +00:00
|
|
|
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview),
|
|
|
|
GDK_BUTTON1_MASK,
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2011-02-11 12:46:35 +00:00
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY);
|
|
|
|
gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (treeview),
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2011-02-11 12:46:35 +00:00
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY);
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_unref (targets);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (renderer, "editable", TRUE, NULL);
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
|
|
|
0, "Title",
|
|
|
|
renderer,
|
|
|
|
"text", 0,
|
|
|
|
NULL);
|
|
|
|
store = gtk_list_store_new (1, G_TYPE_STRING);
|
|
|
|
for (i = 0; i < 80; i++)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *iter_label = g_strdup_printf ("Row number %d", i);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
2020-03-06 17:05:43 +00:00
|
|
|
gtk_list_store_set (store, &iter, 0, iter_label, -1);
|
2020-05-03 15:51:12 +00:00
|
|
|
g_free (iter_label);
|
2011-02-11 12:46:35 +00:00
|
|
|
}
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
|
|
|
|
g_object_unref (store);
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
swindow = gtk_scrolled_window_new ();
|
2011-02-11 12:46:35 +00:00
|
|
|
gtk_scrolled_window_set_kinetic_scrolling (GTK_SCROLLED_WINDOW (swindow), TRUE);
|
|
|
|
gtk_scrolled_window_set_capture_button_press (GTK_SCROLLED_WINDOW (swindow), TRUE);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (swindow), treeview);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), swindow, 1, 1, 1, 1);
|
|
|
|
gtk_widget_set_hexpand (swindow, TRUE);
|
|
|
|
gtk_widget_set_vexpand (swindow, TRUE);
|
|
|
|
|
|
|
|
textview = gtk_text_view_new ();
|
2020-06-24 15:25:09 +00:00
|
|
|
swindow = gtk_scrolled_window_new ();
|
2011-02-11 12:46:35 +00:00
|
|
|
gtk_scrolled_window_set_kinetic_scrolling (GTK_SCROLLED_WINDOW (swindow), TRUE);
|
|
|
|
gtk_scrolled_window_set_capture_button_press (GTK_SCROLLED_WINDOW (swindow), TRUE);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (swindow), textview);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), swindow, 2, 1, 1, 1);
|
|
|
|
gtk_widget_set_hexpand (swindow, TRUE);
|
|
|
|
gtk_widget_set_vexpand (swindow, TRUE);
|
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), grid);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
kinetic_scrolling ();
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2011-02-11 12:46:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|