Test pagebar functions. More...
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "erGtkPageBar.h"
Go to the source code of this file.
Functions | |
static void | on_destroy (GtkWidget *widget, gpointer data) |
static gboolean | on_configured (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) |
static void | on_page_selected (GtkWidget *widget, gint page, gpointer data) |
static gboolean | key_release_callback (GtkWidget *widget, GdkEventKey *event, gpointer data) |
void | test_assertions (GtkPagebar *pagebar) |
int | main (int argc, char *argv[]) |
Variables | |
static GtkWidget * | thePagebar |
static gint | g_current_page = 0 |
static gint | g_number_of_pages = 1 |
Test pagebar functions.
Definition in file test_pagebar.c.
static gboolean key_release_callback | ( | GtkWidget * | widget, | |
GdkEventKey * | event, | |||
gpointer | data | |||
) | [static] |
Definition at line 55 of file test_pagebar.c.
References g_current_page, g_number_of_pages, GTK_PAGEBAR, and gtk_pagebar_set_current_page().
Referenced by main().
00056 { 00057 switch (event->keyval) 00058 { 00059 case GDK_KP_Left: 00060 case GDK_Left: 00061 g_current_page--; 00062 break; 00063 00064 case GDK_KP_Right: 00065 case GDK_Right: 00066 g_current_page++; 00067 break; 00068 00069 case GDK_Page_Up: 00070 g_current_page = g_current_page + 5; 00071 break; 00072 00073 case GDK_Page_Down: 00074 g_current_page = g_current_page - 5; 00075 break; 00076 00077 default: 00078 return FALSE; 00079 } 00080 if (g_current_page > g_number_of_pages) 00081 { 00082 g_current_page = g_number_of_pages; 00083 } 00084 else if (g_current_page < 0) 00085 { 00086 g_current_page = 0; 00087 } 00088 gtk_pagebar_set_current_page(GTK_PAGEBAR(data), g_current_page); 00089 return TRUE; 00090 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 110 of file test_pagebar.c.
References g_current_page, g_number_of_pages, GTK_PAGEBAR, gtk_pagebar_get_bookmarks(), gtk_pagebar_new(), gtk_pagebar_set_bookmark(), gtk_pagebar_set_current_page(), gtk_pagebar_set_number_of_pages(), key_release_callback(), on_configured(), on_destroy(), on_page_selected(), test_assertions(), and thePagebar.
00111 { 00112 GtkWidget *window; 00113 GtkWidget *layout_box; 00114 00115 unsigned int num_pages = 300; 00116 unsigned int selected_page = 10; 00117 00118 if (argc == 3) 00119 { 00120 num_pages = atoi(argv[1]); 00121 selected_page = atoi(argv[2]); 00122 } 00123 00124 g_current_page = selected_page; 00125 g_number_of_pages = num_pages; 00126 00127 /* init threads */ 00128 g_thread_init(NULL); 00129 gdk_threads_init(); 00130 gdk_threads_enter(); 00131 gtk_init(&argc, &argv); 00132 00133 // create the main, top level, window 00134 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 00135 00136 gtk_window_set_title(GTK_WINDOW(window), "pagebar_test"); 00137 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); 00138 gtk_container_set_border_width(GTK_CONTAINER(window), 0); 00139 gtk_window_set_modal(GTK_WINDOW(window), TRUE); 00140 gtk_widget_set_size_request(GTK_WIDGET(window), 1024, 60); 00141 00142 // Construct layout. 00143 layout_box = gtk_vbox_new(FALSE, 0); 00144 thePagebar = gtk_pagebar_new(); 00145 00146 // Test erGtkPageBar assertions 00147 test_assertions(GTK_PAGEBAR(thePagebar)); 00148 00149 g_signal_connect(G_OBJECT(window), "destroy", 00150 G_CALLBACK(on_destroy), thePagebar); 00151 g_signal_connect(G_OBJECT (window), "key_release_event", 00152 G_CALLBACK (key_release_callback), thePagebar); 00153 00154 gtk_pagebar_set_number_of_pages(GTK_PAGEBAR(thePagebar), num_pages); 00155 gtk_pagebar_set_current_page(GTK_PAGEBAR(thePagebar), selected_page); 00156 00157 // TODO Yehong 00158 gtk_pagebar_set_bookmark(GTK_PAGEBAR(thePagebar), selected_page); 00159 gtk_pagebar_set_bookmark(GTK_PAGEBAR(thePagebar), (int)(selected_page/2)+1); 00160 gtk_pagebar_set_bookmark(GTK_PAGEBAR(thePagebar), (int)(selected_page/4)+1); 00161 00162 int idx = 0; 00163 for (; idx < (g_number_of_pages >> 1); ++idx) 00164 { 00165 gtk_pagebar_set_bookmark(GTK_PAGEBAR(thePagebar), idx); 00166 } 00167 00168 00169 g_signal_connect(G_OBJECT(thePagebar), "pagebar_page_selected", 00170 G_CALLBACK(on_page_selected), NULL); 00171 00172 g_signal_connect(G_OBJECT(window), 00173 "configure-event", 00174 G_CALLBACK(on_configured), 00175 thePagebar); 00176 00177 // gtk_container_add(GTK_CONTAINER(fixedContainer), thePagebar); 00178 gtk_box_pack_start(GTK_BOX(layout_box), thePagebar, TRUE, TRUE, 0); 00179 gtk_container_add(GTK_CONTAINER(window), layout_box); 00180 00181 gtk_widget_show_all(layout_box); 00182 gtk_widget_show(window); 00183 00184 // test get bookmarks 00185 const GArray * bookmarks = gtk_pagebar_get_bookmarks(GTK_PAGEBAR(thePagebar)); 00186 if (bookmarks != NULL) 00187 { 00188 g_print("bookmarks number:%d\n", bookmarks->len); 00189 int i = 0; 00190 for (; i < bookmarks->len; ++i) 00191 { 00192 int mark_page = g_array_index(bookmarks, guint, i); 00193 g_print("current bookmark:%d\n", mark_page); 00194 } 00195 } 00196 00197 gtk_main(); 00198 gdk_threads_leave(); 00199 00200 return 0; 00201 }
static gboolean on_configured | ( | GtkWidget * | widget, | |
GdkEventConfigure * | event, | |||
gpointer | user_data | |||
) | [static] |
Definition at line 42 of file test_pagebar.c.
Referenced by main().
static void on_destroy | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 37 of file test_pagebar.c.
Referenced by main().
static void on_page_selected | ( | GtkWidget * | widget, | |
gint | page, | |||
gpointer | data | |||
) | [static] |
Definition at line 49 of file test_pagebar.c.
References g_current_page.
Referenced by main().
00050 { 00051 g_print("page %d has been selected!\n", page); 00052 g_current_page = page; 00053 }
void test_assertions | ( | GtkPagebar * | pagebar | ) |
Definition at line 92 of file test_pagebar.c.
References gtk_pagebar_get_bookmarks(), gtk_pagebar_get_current_page(), gtk_pagebar_get_minimal_height(), gtk_pagebar_get_number_of_pages(), gtk_pagebar_reset(), gtk_pagebar_set_bookmark(), gtk_pagebar_set_current_page(), and gtk_pagebar_set_number_of_pages().
Referenced by main().
00093 { 00094 g_print("--- Test assertions ---\n"); 00095 g_print("** The assertions below are expected behavior:"); 00096 gtk_pagebar_set_number_of_pages(NULL, -1); 00097 gtk_pagebar_set_number_of_pages(pagebar, -1); 00098 gtk_pagebar_get_number_of_pages(NULL); 00099 gtk_pagebar_set_current_page(NULL, -1); 00100 gtk_pagebar_set_current_page(pagebar, -1); 00101 gtk_pagebar_get_current_page(NULL); 00102 gtk_pagebar_set_bookmark(NULL, 0); 00103 gtk_pagebar_set_bookmark(pagebar, 0); 00104 gtk_pagebar_get_bookmarks(NULL); 00105 gtk_pagebar_reset(NULL); 00106 gtk_pagebar_get_minimal_height(NULL); 00107 g_print("--- End test assertions ---\n\n"); 00108 }
gint g_current_page = 0 [static] |
Definition at line 34 of file test_pagebar.c.
Referenced by key_release_callback(), main(), and on_page_selected().
gint g_number_of_pages = 1 [static] |
Definition at line 35 of file test_pagebar.c.
Referenced by key_release_callback(), and main().
GtkWidget* thePagebar [static] |
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 33 of file test_pagebar.c.
Referenced by main().