gitkrwoptionchoice.c

Go to the documentation of this file.
00001 
00011 #define GITK_RENDERER_C
00012 #define GITKR_WIDGET_OPTIONCHOICE_C
00013 
00014 #include "gitkrincludes.h"
00015 
00017 void gitkr_widget_optionchoice_new(GitkrGtkWidgetPtr widget,gchar *id,GitkDialogPtr dialog,gchar *label,GtkContainer *container,gboolean box_vert,xmlNodePtr node) {
00018   GtkWidget *sub_container;
00019   GtkWidget *widget_label;
00020   GtkWidget *widget_menu;
00021   gchar *value=gitk_widget_get_value(dialog,id,"value");
00022   GList *choices;
00023   GList *choice;
00024   gint cur_value;
00025 
00026   //-- determine selected entry
00027   cur_value=(value?atoi(value):0);
00028   g_free(value);
00029 
00030   gitkr_widget_new(widget,id,dialog);
00031 
00032   //if(box_vert) sub_container=gtk_vbox_new(FALSE, /*spacing=*/3);
00033   //else sub_container=gtk_hbox_new(FALSE, /*spacing=*/3);
00034   sub_container=gtk_hbox_new(FALSE, /*spacing=*/3);
00035   //gtk_box_pack_start_defaults(GTK_BOX(container),sub_container);
00036   gtk_container_add(container,sub_container);
00037 
00038   widget_label=gtk_label_new(label);
00039   //gtk_box_pack_start_defaults(GTK_BOX(sub_container),widget->impl);
00040   gtk_container_add(GTK_CONTAINER(sub_container),widget_label);
00041 
00042   widget_menu=gtk_menu_new();
00043   //-- build list of values
00044   choices=gitkr_widget_optionchoice_get_choices(widget,node);
00045   gitk_log1("  combo entries %2d",g_list_length(choices));
00046   choice=g_list_first(choices);
00047   while(choice) {
00048     GtkWidget *menu_item=gtk_menu_item_new_with_label(choice->data);
00049     gtk_menu_shell_append(GTK_MENU_SHELL(widget_menu),menu_item);
00050     choice=g_list_next(choice);
00051   }
00052 
00053   widget->impl=gtk_option_menu_new();
00054   gtk_option_menu_set_menu(GTK_OPTION_MENU(widget->impl),widget_menu);
00055   //-- set initial value
00056   gtk_option_menu_set_history(GTK_OPTION_MENU(widget->impl),cur_value);
00057 
00058   //-- signal handler
00059   gtk_signal_connect(GTK_OBJECT(widget->impl),"changed",GTK_SIGNAL_FUNC(sighandler_option_widget_on_changed),widget);
00060 
00061   //gtk_box_pack_start_defaults(GTK_BOX(sub_container),widget->impl);
00062   gtk_container_add(GTK_CONTAINER(sub_container),widget->impl);
00063 }
00064 
00066 GList *gitkr_widget_optionchoice_get_choices(GitkrGtkWidgetPtr widget,xmlNodePtr node) {
00067   GList *choices=NULL;
00068   xmlXPathObjectPtr options_xpoptr;
00069 
00070   gitk_log("  trace");
00071 
00072   //-- get all options
00073   if((options_xpoptr=gitk_xpath_type_filter(
00074       gitk_xpath_get_object(widget->dialog,"./"GITK_NS_PREFIX":options/"GITK_NS_PREFIX":option",node),
00075       XPATH_NODESET))) {
00076     gint i;
00077     xmlNodePtr choice;
00078     xmlNodeSetPtr ns=(xmlNodeSetPtr)options_xpoptr->nodesetval;
00079 
00080     //-- iterate over nodeset
00081     for(i=0;i<xmlXPathNodeSetGetLength(ns);i++) {
00082       choice=xmlXPathNodeSetItem(ns,i);
00083       if(!xmlNodeIsText(choice)) {
00084         gitk_log2("  choice %d=\"%s\"",i,xmlNodeGetContent(choice));
00085         choices=g_list_append(choices,xmlNodeGetContent(choice));
00086       }
00087       else {
00088         gitk_err("unexpected textnode in dialog definition");
00089       }
00090     }
00091     xmlXPathFreeObject(options_xpoptr);
00092   }
00093   else { gitk_err("failed to get options"); }
00094   return(choices);
00095 }
00096 
00098 void gitkr_widget_optionchoice_free_choices(GList *choices) {
00099   GList *choice;
00100 
00101   g_assert(choices!=NULL);
00102 
00103   choice=g_list_first(choices);
00104   while(choice) {
00105     free(choice->data);
00106     choice=g_list_next(choice);
00107   }
00108   g_list_free(choices);
00109 }

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