ereader gtk library - GtkDialog used to jump to a specific page More...
#include <stdlib.h>
#include <gtk/gtk.h>
#include "eri18n.h"
#include "ergtk_log.h"
#include "erGtkDialogJumpToPage.h"
Go to the source code of this file.
Defines | |
#define | UNUSED(x) (void)(x) |
Functions | |
static void | ergtk_jump_to_page_dialog_class_init (erGtkJumpToPageDialogClass *klass) |
static void | on_number_clicked (GtkWidget *widget, gpointer data) |
static void | on_backspace_clicked (GtkWidget *widget, gpointer data) |
static void | on_enter_clicked (GtkWidget *widget, gpointer data) |
static void | on_focus_out (GtkWidget *widget, gpointer data) |
static void | ergtk_jump_to_page_dialog_init (erGtkJumpToPageDialog *dialog) |
GtkWidget * | ergtk_jump_to_page_dialog_new () |
ereader gtk library - GtkDialog used to jump to a specific page
Definition in file erGtkDialogJumpToPage.c.
#define UNUSED | ( | x | ) | (void)(x) |
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 35 of file erGtkDialogJumpToPage.c.
static void ergtk_jump_to_page_dialog_class_init | ( | erGtkJumpToPageDialogClass * | klass | ) | [static] |
Definition at line 40 of file erGtkDialogJumpToPage.c.
References UNUSED.
00041 { 00042 UNUSED(klass); 00043 }
static void ergtk_jump_to_page_dialog_init | ( | erGtkJumpToPageDialog * | dialog | ) | [static] |
Definition at line 112 of file erGtkDialogJumpToPage.c.
References _erGtkJumpToPageDialog::entry, ERGTK_IS_JUMP_TO_PAGE_DIALOG, LOGPRINTF, on_backspace_clicked(), on_enter_clicked(), on_focus_out(), and on_number_clicked().
00113 { 00114 GtkWidget *button; 00115 GtkWidget *table; 00116 GtkWidget *vbox; 00117 gint i, row, col; 00118 gchar buf[4]; 00119 00120 LOGPRINTF("entry"); 00121 00122 g_return_if_fail(ERGTK_IS_JUMP_TO_PAGE_DIALOG(dialog)); 00123 00124 /* Create a new dialog */ 00125 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); 00126 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); 00127 gtk_widget_hide (GTK_DIALOG(dialog)->action_area); 00128 00129 /* Set the window title */ 00130 gtk_window_set_title (GTK_WINDOW (dialog), ""); 00131 00132 /* Set the window properties */ 00133 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); 00134 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); 00135 00136 /* Sets the border width of the window. */ 00137 //gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); 00138 00139 /* Create a 4x3 table */ 00140 table = gtk_table_new (4, 3, TRUE); 00141 gtk_table_set_row_spacings(GTK_TABLE(table), 2); 00142 gtk_table_set_col_spacings(GTK_TABLE(table), 2); 00143 00144 /* Put the table in the main window */ 00145 vbox = gtk_vbox_new(FALSE, 0); 00146 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox); 00147 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); 00148 00149 row = 0; 00150 00151 /* Create and add the entry field into the table */ 00152 dialog->entry = gtk_entry_new_with_max_length(6); 00153 g_object_set(G_OBJECT(dialog->entry), "im-context-inhibit", TRUE, NULL); // disable input method 00154 g_object_set(G_OBJECT(dialog->entry), "activates-default", TRUE, NULL ); 00155 gtk_widget_set_size_request(dialog->entry, 50, -1); 00156 gtk_table_attach_defaults (GTK_TABLE (table), dialog->entry, 0, 1, row, row + 1); 00157 gtk_widget_show(dialog->entry); 00158 00159 /* Create and add the 'Go to page' button */ 00160 button = gtk_button_new_with_label(_("Go to Page")); 00161 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK (on_enter_clicked), (gpointer) dialog); 00162 gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 3, row, row + 1); 00163 gtk_widget_show(button); 00164 00165 /* Make the 'Go to page' button the default action */ 00166 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); 00167 gtk_window_set_default(GTK_WINDOW(dialog), button); 00168 00169 /* Loop through all numbers */ 00170 for (i = 0; i <= 9; i++) 00171 { 00172 g_snprintf(buf, sizeof(buf), " %d ", i); 00173 button = gtk_button_new_with_label(buf); 00174 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK (on_number_clicked), (gpointer) dialog); 00175 00176 if (i == 0) 00177 { 00178 /* Number 0 is in the last row, first column */ 00179 row = 4; 00180 col = 0; 00181 } 00182 else 00183 { 00184 /* Determine row and column for numbers 1 through 9 */ 00185 row = (i - 1) / 3; 00186 col = (i - 1) % 3; 00187 /* Offset one row: the input field and Goto button are above */ 00188 row += 1; 00189 } 00190 00191 /* Insert numbered button into the table */ 00192 gtk_table_attach_defaults (GTK_TABLE (table), button, col, col + 1, row, row + 1); 00193 gtk_widget_show (button); 00194 dialog->numeric_btns[i] = button; 00195 } 00196 00197 row = 4; 00198 00199 /* Add a backspace button to remove a char */ 00200 button = gtk_button_new_with_label(_("Backspace")); 00201 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK (on_backspace_clicked), (gpointer) dialog); 00202 gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 3, row, row + 1); 00203 gtk_widget_show (button); 00204 00205 gtk_widget_show (table); 00206 gtk_widget_show (vbox); 00207 00208 g_signal_connect(G_OBJECT(dialog), "focus-out-event", G_CALLBACK (on_focus_out), NULL); 00209 }
GtkWidget* ergtk_jump_to_page_dialog_new | ( | ) |
Definition at line 211 of file erGtkDialogJumpToPage.c.
References ERGTK_TYPE_JUMP_TO_PAGE_DIALOG, and LOGPRINTF.
Referenced by notepad::CNotepadWindow::goto_page(), pagebar_hit_test_details(), and pagebar_hit_test_on_cpi_overview().
00212 { 00213 erGtkJumpToPageDialog* dialog; 00214 00215 LOGPRINTF("entry"); 00216 00217 dialog = g_object_new (ERGTK_TYPE_JUMP_TO_PAGE_DIALOG, NULL); 00218 00219 return GTK_WIDGET (dialog); 00220 }
static void on_backspace_clicked | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 70 of file erGtkDialogJumpToPage.c.
References _erGtkJumpToPageDialog::entry, ERGTK_IS_JUMP_TO_PAGE_DIALOG, ERGTK_JUMP_TO_PAGE_DIALOG, and UNUSED.
Referenced by ergtk_jump_to_page_dialog_init().
00071 { 00072 UNUSED(widget); 00073 00074 g_return_if_fail(ERGTK_IS_JUMP_TO_PAGE_DIALOG(data)); 00075 erGtkJumpToPageDialog* dialog = ERGTK_JUMP_TO_PAGE_DIALOG(data); 00076 00077 gint pos = gtk_editable_get_position(GTK_EDITABLE(dialog->entry)); 00078 gtk_editable_delete_text(GTK_EDITABLE(dialog->entry), pos - 1, pos); 00079 }
static void on_enter_clicked | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 81 of file erGtkDialogJumpToPage.c.
References _erGtkJumpToPageDialog::entry, ERGTK_IS_JUMP_TO_PAGE_DIALOG, ERGTK_JUMP_TO_PAGE_DIALOG, LOGPRINTF, and UNUSED.
Referenced by ergtk_jump_to_page_dialog_init().
00082 { 00083 UNUSED(widget); 00084 LOGPRINTF("entry"); 00085 00086 g_return_if_fail(ERGTK_IS_JUMP_TO_PAGE_DIALOG(data)); 00087 erGtkJumpToPageDialog* dialog = ERGTK_JUMP_TO_PAGE_DIALOG(data); 00088 00089 gint page = atoi(gtk_entry_get_text(GTK_ENTRY(dialog->entry))); 00090 if (page > 0) 00091 { 00092 /* Return the page number in the entry field */ 00093 gtk_dialog_response(GTK_DIALOG(dialog), page); 00094 } 00095 else 00096 { 00097 /* Return CANCEL if no page in entry field */ 00098 gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL); 00099 } 00100 }
static void on_focus_out | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 102 of file erGtkDialogJumpToPage.c.
References LOGPRINTF, and UNUSED.
Referenced by ergtk_jump_to_page_dialog_init().
00103 { 00104 UNUSED(data); 00105 LOGPRINTF("entry"); 00106 00107 /* Return CANCEL when dialog looses focus */ 00108 gtk_dialog_response(GTK_DIALOG(widget), GTK_RESPONSE_CANCEL); 00109 }
static void on_number_clicked | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 45 of file erGtkDialogJumpToPage.c.
References _erGtkJumpToPageDialog::entry, ERGTK_IS_JUMP_TO_PAGE_DIALOG, ERGTK_JUMP_TO_PAGE_DIALOG, _erGtkJumpToPageDialog::numeric_btns, and TOTAL_NUMERIC_BUTTONS.
Referenced by ergtk_jump_to_page_dialog_init().
00046 { 00047 gchar buf[3]; 00048 gint len, pos; 00049 gint i = 0; 00050 00051 g_return_if_fail(ERGTK_IS_JUMP_TO_PAGE_DIALOG(data)); 00052 erGtkJumpToPageDialog* dialog = ERGTK_JUMP_TO_PAGE_DIALOG(data); 00053 00054 for (i = 0; i < TOTAL_NUMERIC_BUTTONS; i++) 00055 { 00056 if (dialog->numeric_btns[i] == widget) 00057 { 00058 break; 00059 } 00060 } 00061 00062 g_assert(i != TOTAL_NUMERIC_BUTTONS); 00063 00064 len = g_snprintf(buf, sizeof(buf), "%d", i); 00065 pos = gtk_editable_get_position(GTK_EDITABLE(dialog->entry)); 00066 gtk_editable_insert_text(GTK_EDITABLE(dialog->entry), buf, len, &pos); 00067 gtk_editable_set_position(GTK_EDITABLE(dialog->entry), pos); 00068 }