00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <string.h>
00033 #include <stdlib.h>
00034 #include <unistd.h>
00035 #include <stdio.h>
00036
00037 #include <gtk/gtk.h>
00038 #include <gdk/gdk.h>
00039 #include <glib.h>
00040
00041 #include <libergtk/ergtk.h>
00042
00043 #include "i18n.h"
00044 #include "log.h"
00045 #include "ipc.h"
00046 #include "settings.h"
00047 #include "settings_utils.h"
00048 #include "settings_style.h"
00049 #include "stylus.h"
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 static GtkWidget* g_calibrate_button = NULL ;
00066
00067
00068
00069
00070
00071 static GtkWidget* create_stylus_widgets (GtkBox* parent);
00072
00073 static gboolean on_calibrate_button_clicked (GtkWidget *widget, gpointer data);
00074 static void init_widgets_with_settings (void);
00075 static void on_listview_row_activated ( GtkTreeView *view,
00076 GtkTreePath *path,
00077 GtkTreeViewColumn *column,
00078 gpointer user_data );
00079
00080 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00081 erGtkListViewKeyPress keycode,
00082 gpointer user_data );
00083
00084 static gboolean on_focus_in(GtkWidget* widget, gpointer data );
00085 static gboolean on_focus_out(GtkWidget* widget, gpointer data );
00086
00087
00088
00089
00090
00091 GtkWidget* create_stylus_window(GtkWidget* parent)
00092 {
00093
00094 GtkWidget* top_window = parent;
00095 gtk_window_maximize(GTK_WINDOW(top_window));
00096 gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
00097 gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING );
00098 gtk_window_set_modal(GTK_WINDOW(top_window), TRUE);
00099
00100
00101 GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00102 gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00103
00104
00105 create_title(GTK_VBOX(vboxtop), _("Settings"), _("Stylus Calibration"));
00106
00107
00108 GtkWidget* view = create_settingsview();
00109 gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 );
00110 g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ;
00111 g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ;
00112 g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL );
00113 g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL );
00114
00115
00116 GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0);
00117 gtk_container_add(GTK_CONTAINER(vboxtop), alignment);
00118
00119
00120 GtkWidget* frame = gtk_frame_new(NULL);
00121 gtk_widget_set_name(frame, "irex-margins-frame");
00122 gtk_container_add(GTK_CONTAINER(alignment), frame);
00123 gtk_container_set_border_width(GTK_CONTAINER(frame), 3);
00124
00125
00126 GtkWidget* alignment2 = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
00127 gtk_container_add(GTK_CONTAINER(frame), alignment2);
00128 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment2),
00129 WINDOW_TOP_ALT_PADDING,
00130 WINDOW_BOTTOM_PADDING,
00131 WINDOW_H_PADDING,
00132 WINDOW_H_PADDING);
00133
00134
00135 GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING);
00136 gtk_container_add(GTK_CONTAINER(alignment2), innervbox);
00137
00138
00139 create_stylus_widgets(GTK_BOX(innervbox));
00140
00141
00142 init_widgets_with_settings();
00143
00144 gtk_widget_grab_focus(view);
00145
00146 gtk_widget_show_all(top_window);
00147 return top_window;
00148 }
00149
00150
00151 void load_stylus_settings()
00152 {
00153 LOGPRINTF("Loading stylus settings\n");
00154 }
00155
00156
00157 void save_stylus_settings()
00158 {
00159 LOGPRINTF("Saving stylus settings, done.\n");
00160
00161 }
00162
00163
00164
00165
00166
00167
00168 static void on_listview_row_activated ( GtkTreeView *view,
00169 GtkTreePath *path,
00170 GtkTreeViewColumn *column,
00171 gpointer user_data )
00172 {
00173 main_quit();
00174 return;
00175 }
00176
00177 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00178 erGtkListViewKeyPress keycode,
00179 gpointer user_data )
00180 {
00181 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00182 g_assert( my_selection != NULL ) ;
00183
00184
00185 switch (keycode)
00186 {
00187 case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN:
00188 case ERGTK_LIST_VIEW_PRESS_LONG_DOWN:
00189 gtk_widget_grab_focus(GTK_WIDGET(g_calibrate_button));
00190 gtk_tree_selection_unselect_all(my_selection);
00191 break;
00192 default:
00193 LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00194 ;
00195 break;
00196 }
00197
00198 }
00199
00200 static GtkWidget* create_stylus_widgets(GtkBox* parent)
00201 {
00202
00203 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00204 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00205
00206
00207 GtkWidget* subject = subject_create();
00208 gtk_label_set_label(GTK_LABEL(subject),
00209 _("Calibration"));
00210 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00211
00212
00213 GtkWidget* desc = description_create();
00214 gtk_label_set_label(GTK_LABEL(desc),
00215 _("Calibrating the stylus improves accuracy, a particularly useful tool if you are left-handed."));
00216 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00217
00218
00219 GtkWidget* button_box = gtk_hbutton_box_new();
00220 gtk_box_pack_start(GTK_BOX(top_level_vbox), button_box, FALSE, FALSE, 9);
00221 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
00222
00223 g_calibrate_button = gtk_button_new_with_label( _("Begin Calibration"));
00224 gtk_box_pack_start(GTK_BOX(button_box), g_calibrate_button, FALSE, FALSE, 0);
00225
00226
00227 g_signal_connect(G_OBJECT(g_calibrate_button),
00228 "clicked",
00229 G_CALLBACK(on_calibrate_button_clicked ),
00230 (gpointer) NULL );
00231
00232 return top_level_vbox;
00233 }
00234
00235 static gboolean on_calibrate_button_clicked(GtkWidget *widget, gpointer data)
00236 {
00237
00238 LOGPRINTF("entry");
00239
00240 ipc_menu_popup("block");
00241
00242
00243 system("/usr/bin/gtktscal");
00244
00245 ipc_menu_popup("unblock");
00246
00247 return FALSE;
00248 }
00249
00250 static void init_widgets_with_settings()
00251 {
00252 return;
00253 }
00254
00255 static gboolean on_focus_in(GtkWidget* widget, gpointer data )
00256 {
00257 g_assert(widget != NULL ) ;
00258 ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0);
00259 return FALSE;
00260 }
00261
00262 static gboolean on_focus_out(GtkWidget* widget, gpointer data )
00263 {
00264 g_assert(widget != NULL ) ;
00265 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget);
00266 g_assert( my_selection != NULL ) ;
00267 gtk_tree_selection_unselect_all(my_selection);
00268 return FALSE;
00269 }