2013-04-21 20:05:40 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "frame-stats.h"
|
|
|
|
|
2016-05-30 06:59:46 +00:00
|
|
|
|
|
|
|
/* Stub definition of MyTextView which is used in the
|
|
|
|
* widget-factory.ui file. We just need this so the
|
|
|
|
* test keeps working
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkTextView tv;
|
|
|
|
} MyTextView;
|
|
|
|
|
|
|
|
typedef GtkTextViewClass MyTextViewClass;
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static GType my_text_view_get_type (void);
|
2016-05-30 06:59:46 +00:00
|
|
|
G_DEFINE_TYPE (MyTextView, my_text_view, GTK_TYPE_TEXT_VIEW)
|
|
|
|
|
|
|
|
static void
|
|
|
|
my_text_view_init (MyTextView *tv) {}
|
|
|
|
|
|
|
|
static void
|
|
|
|
my_text_view_class_init (MyTextViewClass *tv_class) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static GtkWidget *
|
2013-04-21 20:05:40 +00:00
|
|
|
create_widget_factory_content (void)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWidget *result;
|
|
|
|
|
2016-05-30 06:59:46 +00:00
|
|
|
g_type_ensure (my_text_view_get_type ());
|
2013-04-21 20:05:40 +00:00
|
|
|
builder = gtk_builder_new ();
|
2020-05-13 21:10:00 +00:00
|
|
|
gtk_builder_add_from_file (builder, "./testsuite/gtk/focus-chain/widget-factory.ui", &error);
|
2013-04-21 20:05:40 +00:00
|
|
|
if (error != NULL)
|
2016-02-28 17:21:29 +00:00
|
|
|
g_error ("Failed to create widgets: %s", error->message);
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
result = GTK_WIDGET (gtk_builder_get_object (builder, "box1"));
|
|
|
|
g_object_ref (result);
|
2020-05-13 21:10:00 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (gtk_widget_get_parent (result)), NULL);
|
2013-04-21 20:05:40 +00:00
|
|
|
g_object_unref (builder);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_adjustment_to_fraction (GtkAdjustment *adjustment,
|
2020-07-24 20:32:16 +00:00
|
|
|
double fraction)
|
2013-04-21 20:05:40 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double upper = gtk_adjustment_get_upper (adjustment);
|
|
|
|
double lower = gtk_adjustment_get_lower (adjustment);
|
|
|
|
double page_size = gtk_adjustment_get_page_size (adjustment);
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
gtk_adjustment_set_value (adjustment,
|
|
|
|
(1 - fraction) * lower +
|
|
|
|
fraction * (upper - page_size));
|
|
|
|
}
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static gboolean
|
2013-04-21 20:05:40 +00:00
|
|
|
scroll_viewport (GtkWidget *viewport,
|
|
|
|
GdkFrameClock *frame_clock,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
static gint64 start_time;
|
|
|
|
gint64 now = gdk_frame_clock_get_frame_time (frame_clock);
|
2020-07-24 20:32:16 +00:00
|
|
|
double elapsed;
|
2013-04-21 20:05:40 +00:00
|
|
|
GtkAdjustment *hadjustment, *vadjustment;
|
|
|
|
|
|
|
|
if (start_time == 0)
|
|
|
|
start_time = now;
|
|
|
|
|
|
|
|
elapsed = (now - start_time) / 1000000.;
|
|
|
|
|
|
|
|
hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (viewport));
|
|
|
|
vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (viewport));
|
|
|
|
|
|
|
|
set_adjustment_to_fraction (hadjustment, 0.5 + 0.5 * sin (elapsed));
|
|
|
|
set_adjustment_to_fraction (vadjustment, 0.5 + 0.5 * cos (elapsed));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GOptionEntry options[] = {
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
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-04-21 20:05:40 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *viewport;
|
|
|
|
GtkWidget *grid;
|
|
|
|
GError *error = NULL;
|
|
|
|
int i;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
GOptionContext *context = g_option_context_new (NULL);
|
|
|
|
g_option_context_add_main_entries (context, options, NULL);
|
|
|
|
frame_stats_add_options (g_option_context_get_main_group (context));
|
|
|
|
|
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error))
|
|
|
|
{
|
|
|
|
g_printerr ("Option parsing failed: %s\n", error->message);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-04-21 20:05:40 +00:00
|
|
|
frame_stats_ensure (GTK_WINDOW (window));
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_window = gtk_scrolled_window_new ();
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), scrolled_window);
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
viewport = gtk_viewport_new (NULL, NULL);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), viewport);
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
grid = gtk_grid_new ();
|
2020-05-01 19:43:09 +00:00
|
|
|
gtk_viewport_set_child (GTK_VIEWPORT (viewport), grid);
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
GtkWidget *content = create_widget_factory_content ();
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), content,
|
|
|
|
i % 2, i / 2, 1, 1);
|
|
|
|
g_object_unref (content);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_add_tick_callback (viewport,
|
|
|
|
scroll_viewport,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-04-21 20:05:40 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2020-02-10 03:24:47 +00:00
|
|
|
G_CALLBACK (quit_cb), &done);
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-04-21 20:05:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|