00001
00012 #define GITK_RENDERER_C
00013 #define GITKR_EVENTLOOP_C
00014
00015 #include "gitkrincludes.h"
00016
00019 GitkDialogPtr cur_context;
00020
00025 void gitkr_event_loop_start(void) {
00026 GitkrPhoneLayoutPtr layout;
00027
00028 gitk_log_intro();
00029
00030 restart_event_loop=TRUE;
00031
00032 while(restart_event_loop) {
00033 run=TRUE;
00034 restart_event_loop=FALSE;
00035
00036 while(!capi_incoming_connected) {
00037
00038 #ifdef HAVE_CAPI20
00039 capi_wait_for_incoming_calls(capiinfo);
00040 #endif //HAVE_CAPI20
00041
00042 capi_incoming_connected = (TRUE);
00043 gitk_log("incoming call detected");
00044
00045
00046 capi_text_output(capiinfo,welcome,ftinfo);
00047
00048
00049 gitkr_welcome_help();
00050 }
00051
00052 if(!(cur_context=gitk_context_get_current())) {
00053 gitk_log("no current context");
00054 return;
00055 }
00056 if(!(layout=(GitkrPhoneLayoutPtr)cur_context->layout)) {
00057 gitk_log("current context without layout");
00058 return;
00059 }
00060
00061 switch(layout->focus) {
00062 case GITK_FOCUS_TYPE_MAIN:
00063 handle_dialog_main_widgets(layout);
00064 gitk_log("layout->focus=handle_dialog_main_widgets");
00065 break;
00066 case GITK_FOCUS_TYPE_CTRL:
00067 handle_dialog_ctrl_widgets(layout);
00068 gitk_log("layout->focus=handle_dialog_crtl_widgets");
00069 break;
00070 default:
00071 gitk_log1("unexpected default : %d",layout->focus);
00072 }
00073 gitk_log("leaving event-loop");
00074 if(restart_event_loop) gitk_relayout();
00075 }
00076 gitk_log_outro();
00077 }
00078
00083 void gitkr_event_loop_end(void) {
00084 gitk_log_intro();
00085
00086 run=FALSE;
00087 gitk_log_outro();
00088 }
00089
00094 void gitkr_event_loop_restart(void) {
00095 gitk_log_intro();
00096 restart_event_loop=TRUE;
00097 gitkr_event_loop_end();
00098 }
00099
00100
00101
00105 void next_widget(GitkrPhoneLayoutPtr layout) {
00106 GitkrPhoneWidgetPtr old_widget,new_widget;
00107
00108 old_widget=&layout->pages[layout->currentPage].widgets[layout->currentWidget];
00109 if(layout->currentWidget<((layout->pages[layout->currentPage].widgetsPerPage)-1)) {
00110 layout->currentWidget++;
00111 }
00112 else {
00113 layout->currentWidget=0;
00114 }
00115 new_widget=&layout->pages[layout->currentPage].widgets[layout->currentWidget];
00116 gitk_dialog_move_focus((GitkWidgetPtr)old_widget,(GitkWidgetPtr)new_widget);
00117
00118 }
00119
00123 void prev_widget(GitkrPhoneLayoutPtr layout) {
00124 GitkrPhoneWidgetPtr old_widget,new_widget;
00125
00126 old_widget=&layout->pages[layout->currentPage].widgets[layout->currentWidget];
00127 if(layout->currentWidget>0) {
00128 layout->currentWidget--;
00129 }
00130 else {
00131 layout->currentWidget=(layout->pages[layout->currentPage].widgetsPerPage)-1;
00132 }
00133 new_widget=&layout->pages[layout->currentPage].widgets[layout->currentWidget];
00134 gitk_dialog_move_focus((GitkWidgetPtr)old_widget,(GitkWidgetPtr)new_widget);
00135
00136 }
00137
00138
00142 void next_page(GitkrPhoneLayoutPtr layout) {
00143 if(layout->currentPage<(layout->numberOfPages-1)) {
00144 layout->currentPage++;
00145 layout->currentWidget=0;
00146
00147 }
00148 else capi_sound_beep(capiinfo, ftinfo);
00149 }
00150
00154 void prev_page(GitkrPhoneLayoutPtr layout) {
00155 if(layout->currentPage>0) {
00156 layout->currentPage--;
00157 layout->currentWidget=0;
00158
00159 }
00160 else capi_sound_beep(capiinfo, ftinfo);
00161 }
00162
00163
00167 void handle_dialog_main_widgets(GitkrPhoneLayoutPtr layout) {
00168 gint key;
00169 GitkEvent event;
00170 GitkrPhoneWidgetPtr widget;
00171 gchar res[10];
00172
00173 gitk_log_intro();
00174
00175 while(run) {
00176
00177 capi_text_output(capiinfo,_("content"),ftinfo);
00178
00179
00180 #ifdef HAVE_CAPI20
00181
00182 key=capi_dtmf_input_arrow(capiinfo, res);
00183 gitk_log1("handle_dialog_main_widgets() res=%c", key);
00184
00185
00186
00187 switch(key) {
00188
00189 case Key_Escape:
00190 gitk_log3("Key_Escape: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00191 event.type=GITK_EVENT_TYPE_ON_CLOSE;
00192 event.data=NULL;
00193 if(gitk_dialog_process_event(NULL,NULL,&event)) run=FALSE;
00194 break;
00195 case Key_F2:
00196 gitk_log3("Key_F2/KEY_SELECT: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00197 handle_dialog_ctrl_widgets(layout);
00198 break;
00199
00200 case Key_Down:
00201 case Key_Right:
00202 gitk_log3("Key_Down/Right: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00203 next_widget(layout);
00204 break;
00205 case Key_Up:
00206 case Key_Left:
00207 gitk_log3("Key_Up/Left: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00208 prev_widget(layout);
00209 break;
00210 case Key_PageDown:
00211 gitk_log3("Key_PageDown: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00212 next_page(layout);
00213 break;
00214 case Key_PageUp:
00215 gitk_log3("Key_PageUp: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00216 prev_page(layout);
00217 break;
00218 case Key_Home:
00219 gitk_log3("Key_Home: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00220 break;
00221 case Key_End:
00222 gitk_log3("Key_End: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00223 break;
00224 case Key_Backspace:
00225 case Key_Delete:
00226 gitk_log3("Key_Delete/Backspace: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00227 break;
00228
00229 case Key_Return:
00230 case Key_Enter:
00231 gitk_log3("Key_Enter/Return : %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00232 if((widget=gitkr_layout_get_current_widget(layout))) {
00233 switch(widget->type) {
00234 case GITK_WIDGET_TYPE_ACTION:
00235 if(widget->handle && widget->handle(widget)) {
00236 event.type=GITK_EVENT_TYPE_ON_CLICKED;
00237 event.data=NULL;
00238 gitk_dialog_process_event(widget->dialog,widget->id,&event);
00239 next_widget(layout);
00240 }
00241 break;
00242 case GITK_WIDGET_TYPE_CHARACTERINPUT:
00243 case GITK_WIDGET_TYPE_CHARACTERINPUT_ALPHABETIC:
00244 case GITK_WIDGET_TYPE_OPTIONCHOICE:
00245 case GITK_WIDGET_TYPE_OPTIONCHOICE_SINGLE:
00246 case GITK_WIDGET_TYPE_OPTIONCHOICE_SINGLE_COMPACT:
00247 case GITK_WIDGET_TYPE_OPTIONCHOICE_BOOLEAN:
00248 if(widget->handle && widget->handle(widget)) {
00249 event.type=GITK_EVENT_TYPE_ON_CHANGED;
00250 event.data=NULL;
00251 gitk_dialog_process_event(widget->dialog,widget->id,&event);
00252 next_widget(layout);
00253 }
00254 break;
00255 default:
00256 gitk_log2("!!!!!!!!!!! unhandled widget_type %d (widget_id=\"%s\")",widget->type,widget->id);
00257 break;
00258 }
00259 }
00260 break;
00261
00262 default:
00263 if(key) {
00264 gitk_log3("? : %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00265 gitkr_dialog_output_layout(cur_context);
00266 }
00267 }
00268 }
00269
00270 #else
00271
00272 if((key=gitkr_event_loop_getkey())==ERR) continue;
00273
00274 gitk_log1("handle_dialog_main_widgets() res=%c", key);
00275
00276
00277
00278 switch(key) {
00279
00280 case '0':
00281 gitk_log3("Key_Escape: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00282 event.type=GITK_EVENT_TYPE_ON_CLOSE;
00283 event.data=NULL;
00284 if(gitk_dialog_process_event(NULL,NULL,&event)) run=FALSE;
00285 break;
00286 case '5':
00287 gitk_log3("Key_F2/KEY_SELECT: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00288 handle_dialog_ctrl_widgets(layout);
00289
00290 break;
00291
00292 case '2':
00293 case '6':
00294 gitk_log3("Key_Down/Right: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00295 next_widget(layout);
00296 break;
00297 case '8':
00298 case '4':
00299 gitk_log3("Key_Up/Left: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00300 prev_widget(layout);
00301 break;
00302 case '3':
00303 gitk_log3("Key_PageDown: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00304 next_page(layout);
00305 break;
00306 case '9':
00307 gitk_log3("Key_PageUp: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00308 prev_page(layout);
00309 break;
00310 case '7':
00311 gitk_log3("Key_Home: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00312 break;
00313 case '1':
00314 gitk_log3("Key_End: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00315 break;
00316 case ',':
00317
00318 gitk_log3("Key_Delete/Backspace: %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00319 break;
00320
00321 case 13:
00322 case '\n':
00323 gitk_log3("Key_Enter/Return : %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00324 if((widget=gitkr_layout_get_current_widget(layout))) {
00325 switch(widget->type) {
00326 case GITK_WIDGET_TYPE_ACTION:
00327 if(widget->handle && widget->handle(widget)) {
00328 event.type=GITK_EVENT_TYPE_ON_CLICKED;
00329 event.data=NULL;
00330 gitk_dialog_process_event(widget->dialog,widget->id,&event);
00331 next_widget(layout);
00332 }
00333 break;
00334 case GITK_WIDGET_TYPE_CHARACTERINPUT:
00335 case GITK_WIDGET_TYPE_CHARACTERINPUT_ALPHABETIC:
00336 case GITK_WIDGET_TYPE_OPTIONCHOICE:
00337 case GITK_WIDGET_TYPE_OPTIONCHOICE_SINGLE:
00338 case GITK_WIDGET_TYPE_OPTIONCHOICE_SINGLE_COMPACT:
00339 case GITK_WIDGET_TYPE_OPTIONCHOICE_BOOLEAN:
00340 if(widget->handle && widget->handle(widget)) {
00341 event.type=GITK_EVENT_TYPE_ON_CHANGED;
00342 event.data=NULL;
00343 gitk_dialog_process_event(widget->dialog,widget->id,&event);
00344 next_widget(layout);
00345 }
00346 break;
00347 default:
00348 gitk_log2("!!!!!!!!!!! unhandled widget_type %d (widget_id=\"%s\")",widget->type,widget->id);
00349 break;
00350 }
00351 }
00352 break;
00353
00354 default:
00355 if(key) {
00356 gitk_log3("? : %4d 0x%03x '%c'",key,key,KEYCODE_TO_ASCII(key));
00357
00358 capi_text_output(capiinfo, _("unhandled key"), ftinfo);
00359 }
00360 }
00361 }
00362
00363 #endif //HAVE_CAPI20
00364
00365 gitk_log_outro();
00366 }
00367
00371 void handle_dialog_ctrl_widgets(GitkrPhoneLayoutPtr layout) {
00372 gint currentWidget;
00373 GitkrPhoneWidgetPtr widget;
00374
00375 gitk_log_intro();
00376
00377 capi_text_output(capiinfo,_("control"),ftinfo);
00378
00379 currentWidget=layout->currentWidget;
00380 layout->currentWidget=GITKR_TEXT_NAVIGATION;
00381
00382 widget=&layout->ctrl.widgets[0];
00383 if(widget && widget->handle && widget->handle(widget)) {
00384 gchar *value=gitkr_widget_get_value(widget->dialog,widget->id,"value");
00385 gint cur_value=(value?atoi(value):0);
00386 GList *ids=gitkr_widget_optionchoice_get_ids(widget);
00387 gchar *id=g_list_nth_data(ids,cur_value);
00388
00389 gitk_log1("dialog control : id=\"%s\"",id);
00390
00391 if(!strncmp(id,"Prev",4)) prev_page(layout);
00392 else if(!strncmp(id,"Next",4)) next_page(layout);
00393 else {
00394 GitkEvent event;
00395
00396 event.type=GITK_EVENT_TYPE_ON_CLICKED;
00397 event.data=NULL;
00398 gitk_dialog_process_event(widget->dialog,id,&event);
00399 if(run) {
00400 gitk_log1("dialogcontrol [%s] not yet implemented",id);
00401 layout->currentWidget=currentWidget;
00402 gitkr_dialog_output_layout(cur_context);
00403 }
00404 }
00405 gitkr_widget_optionchoice_free_ids(ids);
00406 }
00407 else {
00408 layout->currentWidget=currentWidget;
00409 gitkr_dialog_output_layout(cur_context);
00410 }
00411 gitk_log_outro();
00412 }
00413
00414
00419 gint gitkr_event_loop_getkey(void) {
00420 gint key=ERR;
00421
00422 gitk_log_intro();
00423
00424 nodelay(stdscr, TRUE);
00425 while(run && (key==ERR)) {
00426 key=getch();
00428 }
00429 nodelay(stdscr, FALSE);
00430
00431
00432
00433
00434 gitk_log_outro();
00435
00436 return(key);
00437 }
00438
00439 void gitkr_welcome_help() {
00440
00441 gitk_log_intro();
00442
00443 gitk_log_outro();
00444 }