2014-10-12 12:29:24 +00:00
|
|
|
/* testscrolledge.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Matthias Clasen <mclasen@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static guint add_rows_id = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_list (GtkListBox *list)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
2014-10-12 12:29:24 +00:00
|
|
|
GtkWidget *row, *label;
|
2020-07-24 13:54:49 +00:00
|
|
|
int n;
|
2020-05-08 06:19:18 +00:00
|
|
|
GtkWidget *child;
|
2014-10-12 12:29:24 +00:00
|
|
|
|
2020-05-08 06:19:18 +00:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (list)), n = 0;
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child), n++) ;
|
2014-10-12 12:29:24 +00:00
|
|
|
|
|
|
|
for (i = 1; i <= 50; i++)
|
|
|
|
{
|
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
text = g_strdup_printf ("List row %d", i + n);
|
|
|
|
label = gtk_label_new (text);
|
|
|
|
g_free (text);
|
|
|
|
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (label, 10);
|
|
|
|
gtk_widget_set_margin_end (label, 10);
|
|
|
|
gtk_widget_set_margin_top (label, 10);
|
|
|
|
gtk_widget_set_margin_bottom (label, 10);
|
2014-10-12 12:29:24 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2020-05-03 04:09:18 +00:00
|
|
|
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), label);
|
2020-05-08 06:19:18 +00:00
|
|
|
gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
|
2014-10-12 12:29:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *popup;
|
|
|
|
static GtkWidget *spinner;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
add_rows (gpointer data)
|
|
|
|
{
|
|
|
|
GtkListBox *list = data;
|
|
|
|
|
|
|
|
gtk_widget_hide (popup);
|
|
|
|
gtk_spinner_stop (GTK_SPINNER (spinner));
|
|
|
|
|
|
|
|
populate_list (list);
|
|
|
|
add_rows_id = 0;
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
edge_overshot (GtkScrolledWindow *sw,
|
|
|
|
GtkPositionType pos,
|
|
|
|
GtkListBox *list)
|
|
|
|
{
|
|
|
|
if (pos == GTK_POS_BOTTOM)
|
|
|
|
{
|
|
|
|
gtk_spinner_start (GTK_SPINNER (spinner));
|
|
|
|
gtk_widget_show (popup);
|
|
|
|
|
|
|
|
if (add_rows_id == 0)
|
|
|
|
add_rows_id = g_timeout_add (2000, add_rows, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-25 11:53:49 +00:00
|
|
|
static void
|
|
|
|
edge_reached (GtkScrolledWindow *sw,
|
|
|
|
GtkPositionType pos,
|
|
|
|
GtkListBox *list)
|
|
|
|
{
|
|
|
|
g_print ("Reached the edge at pos %d!\n", pos);
|
|
|
|
}
|
|
|
|
|
2014-10-12 12:29:24 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *win;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *list;
|
|
|
|
GtkWidget *overlay;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2014-10-12 12:29:24 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
win = gtk_window_new ();
|
2014-10-12 12:29:24 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (win), 600, 400);
|
|
|
|
|
|
|
|
overlay = gtk_overlay_new ();
|
|
|
|
popup = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_widget_set_halign (popup, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (popup, GTK_ALIGN_END);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (popup, 40);
|
|
|
|
gtk_widget_set_margin_end (popup, 40);
|
|
|
|
gtk_widget_set_margin_top (popup, 40);
|
|
|
|
gtk_widget_set_margin_bottom (popup, 40);
|
2014-10-12 12:29:24 +00:00
|
|
|
label = gtk_label_new ("Getting more rows...");
|
|
|
|
spinner = gtk_spinner_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (popup), label);
|
|
|
|
gtk_box_append (GTK_BOX (popup), spinner);
|
2014-10-12 12:29:24 +00:00
|
|
|
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), popup);
|
2017-01-19 09:31:03 +00:00
|
|
|
gtk_widget_hide (popup);
|
2014-10-12 12:29:24 +00:00
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
sw = gtk_scrolled_window_new ();
|
2014-10-12 12:29:24 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
list = gtk_list_box_new ();
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
|
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (win), overlay);
|
2020-05-03 14:32:24 +00:00
|
|
|
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
|
2014-10-12 12:29:24 +00:00
|
|
|
populate_list (GTK_LIST_BOX (list));
|
|
|
|
|
|
|
|
g_signal_connect (sw, "edge-overshot", G_CALLBACK (edge_overshot), list);
|
2015-01-25 11:53:49 +00:00
|
|
|
g_signal_connect (sw, "edge-reached", G_CALLBACK (edge_reached), list);
|
2014-10-12 12:29:24 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (win);
|
2014-10-12 12:29:24 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2014-10-12 12:29:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|