gitkrwoptionchoice.c

Go to the documentation of this file.
00001 
00012 #define GITK_RENDERER_C
00013 #define GITKR_WIDGET_OPTIONCHOICE_C
00014 
00015 #include "gitkrincludes.h"
00016 
00018 void gitkr_widget_optionchoice_new(GitkrPhoneWidgetPtr widget,GitkDialogPtr dialog,xmlNodePtr node) {
00019   gitkr_widget_new(widget,dialog,node);
00020   widget->type=GITK_WIDGET_TYPE_OPTIONCHOICE;
00021   widget->output=gitkr_widget_optionchoice_output;
00022   widget->handle=gitkr_widget_optionchoice_handle;
00023 }
00024 
00026 void gitkr_widget_optionchoice_output(GitkrPhoneWidgetPtr widget,gboolean active) {
00027   gint col;
00028   gchar *value=gitkr_widget_get_value(widget->dialog,widget->id,"value");
00029   GList *choices=gitkr_widget_optionchoice_get_choices(widget);
00030 
00031   gitk_log("gitkr_widget_optionchoice_output() beg");
00032   capi_text_output(capiinfo,IconOptionChoice,ftinfo);
00033   //-- display label
00034   if(widget->label && widget->label != "") {
00035     capi_text_output(capiinfo, widget->label, ftinfo);
00036   }
00037   else {
00038     capi_text_output(capiinfo, widget->id, ftinfo);
00039   }
00040   if(active)capi_text_output(capiinfo, selected, ftinfo);
00041   gitk_log1("********************** value ist %s", value);
00042   col=gitkr_widget_optionchoice_value_output((value?atoi(value):0),choices,FALSE);
00043   
00044   //free(value);
00045   gitkr_widget_optionchoice_free_choices(choices);
00046   
00047 }
00048 
00050 gboolean gitkr_widget_optionchoice_handle(GitkrPhoneWidgetPtr widget) {
00051   gint key;
00052   gint xmin,xpos;
00053   gboolean sub_run=TRUE,result=TRUE;
00054   gchar *value=gitkr_widget_get_value(widget->dialog,widget->id,"value");
00055   GList *choices=gitkr_widget_optionchoice_get_choices(widget);
00056   gint cur_value=(value?atoi(value):0);  //-- determine selected entry
00057   char res[100];  //-- temporary buffer for setting the result
00058   
00059   capi_text_output(capiinfo,IconOptionChoice,ftinfo);
00060   if(widget->label) {
00061     capi_text_output(capiinfo, widget->label, ftinfo);
00062   }
00063   else {
00064     capi_text_output(capiinfo, widget->id, ftinfo);
00065   }
00066 
00067   capi_text_output(capiinfo, g_list_nth_data(choices,cur_value), ftinfo);
00068   //-- now run the sub-event-loop
00069   while(run && sub_run) {
00070     
00071 #ifdef HAVE_CAPI20    
00072 
00073     key=capi_dtmf_input_arrow(capiinfo, res);
00074     //-- pre-process escape keys
00075     //if(key==KEY_ESCAPE) key=gitkr_event_loop_unescape_key();
00076     //-- process the key-code
00077     switch(key) {
00078     //case KEY_F10:    // cancel edit
00079     case Key_Escape:
00080       sub_run=FALSE;result=FALSE;
00081       break;
00082     //case KEY_RETURN: // submit edit
00083     case Key_Enter:
00084       sprintf(res,"%d",cur_value);
00089       gitkr_widget_set_value(widget->dialog,widget->id,"value",res);
00090       sub_run=FALSE;
00091       break;
00092     case Key_Left:
00093       if(cur_value) {
00094         cur_value--;
00095         gitk_log1(" !!!!!!!!!!!!!!!!!!cur_value|value = %s|", g_list_nth_data(choices,cur_value));
00096         capi_text_output(capiinfo, g_list_nth_data(choices,cur_value), ftinfo);
00097       }
00098       else capi_sound_beep(capiinfo, ftinfo);
00099       break;
00100     case Key_Right:
00101       if(cur_value<(g_list_length(choices)-1)) {
00102         cur_value++;
00103         gitk_log1(" !!!!!!!!!!!!!!!!!!cur_value|value = %s|", g_list_nth_data(choices,cur_value));
00104         capi_text_output(capiinfo, g_list_nth_data(choices,cur_value), ftinfo);
00105       }
00106       else capi_sound_beep(capiinfo, ftinfo);
00107       break;
00108     case Key_F2:
00109             if(widget->dialog->layout->focus==GITK_FOCUS_TYPE_CTRL){
00110         widget->dialog->layout->focus==GITK_FOCUS_TYPE_MAIN;
00111         sub_run=FALSE;result=FALSE;
00112       }
00113             break;
00114 
00115     }
00116   }
00117   
00118 #else
00119 
00120   if((key=gitkr_event_loop_getkey())==ERR) continue;
00121   //key=getch();
00122     //-- pre-process escape keys
00123     //if(key==KEY_ESCAPE) key=gitkr_event_loop_unescape_key();
00124     //-- process the key-code
00125     switch(key) {
00126     //case KEY_F10:    // cancel edit
00127     case '0':
00128       sub_run=FALSE;result=FALSE;
00129       break;
00130     //case KEY_RETURN: // submit edit
00131     case '\n':
00132     case 13:
00133       sprintf(res,"%d",cur_value);
00138       gitkr_widget_set_value(widget->dialog,widget->id,"value",res);
00139       sub_run=FALSE;
00140       break;
00141     case '4':
00142     case '8':
00143       if(cur_value) {
00144         cur_value--;
00145         gitk_log1(" !!!!!!!!!!!!!!!!!!cur_value|value = %s|", g_list_nth_data(choices,cur_value));
00146         capi_text_output(capiinfo, g_list_nth_data(choices,cur_value), ftinfo);
00147       }
00148       else capi_sound_beep(capiinfo, ftinfo);
00149       
00150       //sub_run=FALSE;
00151       break;
00152     case '6':
00153     case '2':
00154       if(cur_value<(g_list_length(choices)-1)) {
00155         cur_value++;
00156         gitk_log1(" !!!!!!!!!!!!!!!!!!cur_value|value = %s|", g_list_nth_data(choices,cur_value));
00157         capi_text_output(capiinfo, g_list_nth_data(choices,cur_value), ftinfo);
00158       }
00159       else capi_sound_beep(capiinfo, ftinfo);
00160       
00161       //sub_run=FALSE;
00162       break;
00163     case '5':
00164             if(widget->dialog->layout->focus==GITK_FOCUS_TYPE_CTRL){
00165         widget->dialog->layout->focus==GITK_FOCUS_TYPE_MAIN;
00166         sub_run=FALSE;result=FALSE;
00167       }
00168             break;
00169     }
00170   }
00171     
00172 #endif //HAVE_CAPI20
00173   
00174   return(result);
00175 }
00176 
00178 gint gitkr_widget_optionchoice_value_output(gint value,GList *choices,gboolean all) {
00179 gint i, col=0;
00180 GList *choice;
00181 
00182 gitk_log("gitkr_widget_optionchoice_value_output() beg");
00183 g_assert(choices!=NULL);
00184 
00185 for(i=0,choice=g_list_first(choices);choice;i++,choice=g_list_next(choice)) {
00186   if(value!=i) {
00187     if(all) capi_text_output(capiinfo, choice->data, ftinfo);
00188     col++;
00189   }
00190   else { //-- selected
00191     capi_text_output(capiinfo, choice->data, ftinfo);
00192     capi_text_output(capiinfo, _("is choosen"), ftinfo);
00193     col++;
00194   }
00195 }
00196 gitk_log("gitkr_widget_optionchoice_value_output() end");
00197 return(col);
00198 }
00199 
00201 GList *gitkr_widget_optionchoice_get_choices(GitkrPhoneWidgetPtr widget) {
00202   GList *choices=NULL;
00203   xmlXPathObjectPtr options_xpoptr;
00204   xmlNodePtr node=gitk_dialog_get_widget(widget->dialog,widget->id);
00205 
00206   //-- get all options
00207   if((options_xpoptr=gitk_xpath_type_filter(
00208       gitk_xpath_get_object(widget->dialog,"./"GITK_NS_PREFIX":options/"GITK_NS_PREFIX":option",node),
00209       XPATH_NODESET))) {
00210     gint i;
00211     gchar *str;
00212     xmlNodePtr choice;
00213     xmlNodeSetPtr ns=(xmlNodeSetPtr)options_xpoptr->nodesetval;
00214     //-- iterate over nodeset
00215     for(i=0;i<xmlXPathNodeSetGetLength(ns);i++) {
00216       choice=xmlXPathNodeSetItem(ns,i);
00217       if(!xmlNodeIsText(choice)) {
00218         str=xmlNodeGetContent(choice);
00219         choices=g_list_append(choices,g_convert(str,-1,code_set,"UTF-8",NULL,NULL,NULL));
00220         g_free(str);//xmlFree(str);
00221       }
00222       else {
00223         gitk_err("unexpected textnode in dialog definition");
00224       }
00225     }
00226     xmlXPathFreeObject(options_xpoptr);
00227   }
00228   else { gitk_err("failed to get options"); }
00229   return(choices);
00230 }
00231 
00235 void gitkr_widget_optionchoice_free_choices(GList *choices) {
00236   gitkr_widget_optionchoice_free_list(choices);
00237 }
00238 
00240 gint gitkr_widget_optionchoice_get_position(GList *choices,gint value) {
00241   gint i,col=0;
00242   GList *choice;
00243 
00244   g_assert(choices!=NULL);
00245 
00246   for(i=0,choice=g_list_first(choices);(i<value && choice);i++,choice=g_list_next(choice)) {
00247     col+=(strlen(choice->data)+2);
00248   }
00249   return(col);
00250 }
00251 
00253 GList *gitkr_widget_optionchoice_get_ids(GitkrPhoneWidgetPtr widget) {
00254   GList *items=NULL;
00255   xmlXPathObjectPtr options_xpoptr;
00256   xmlNodePtr node=gitk_dialog_get_widget(widget->dialog,widget->id);
00257 
00258   //-- get all options
00259   if((options_xpoptr=gitk_xpath_type_filter(
00260       gitk_xpath_get_object(widget->dialog,"./"GITK_NS_PREFIX":options/"GITK_NS_PREFIX":option",node),
00261       XPATH_NODESET))) {
00262     gint i;
00263     xmlNodePtr item;
00264     xmlNodeSetPtr ns=(xmlNodeSetPtr)options_xpoptr->nodesetval;
00265     //-- iterate over nodeset
00266     for(i=0;i<xmlXPathNodeSetGetLength(ns);i++) {
00267       item=xmlXPathNodeSetItem(ns,i);
00268       if(!xmlNodeIsText(item)) {
00269         items=g_list_append(items,xmlGetProp(item,"id"));
00270       }
00271       else {
00272         gitk_err("unexpected textnode in dialog definition");
00273       }
00274     }
00275     xmlXPathFreeObject(options_xpoptr);
00276   }
00277   else { gitk_err("failed to get options"); }
00278   return(items);
00279 }
00280 
00284 void gitkr_widget_optionchoice_free_ids(GList *ids) {
00285   gitkr_widget_optionchoice_free_list(ids);
00286 }
00287 
00291 void gitkr_widget_optionchoice_free_list(GList *items) {
00292   GList *item;
00293 
00294   g_assert(items!=NULL);
00295 
00296   item=g_list_first(items);
00297   while(item) {
00298     free(item->data);
00299     item=g_list_next(item);
00300   }
00301   g_list_free(items);
00302 }
00303 

Generated on Thu Oct 28 10:59:14 2004 for gitk by doxygen 1.3.6