gitkcallback.c

Go to the documentation of this file.
00001 
00012 #define GITK_LIB_C
00013 #define GITK_CALLBACK_C
00014 
00015 #include "gitkincludes.h"
00016 
00020 static gchar *callback_names[]={
00021   "onClose",
00022   "onShow",
00023   "onHide",
00024   "onClicked",
00025   "onChanged"
00026 };
00027 
00028 
00035 static GitkCallbackNodePtr gitk_get_callback_node(GitkDialogPtr const dialog,gchar * const widget_id,const GitkEventType type) {
00036   GList* node;
00037   GitkCallbackNodePtr result_node=NULL,callback_node=NULL;
00038 
00039   //-- use global_callbacks when dialog==NULL
00040   if(!dialog) {
00041     node=g_list_first(gitk_global_callback_list);
00042   }
00043   else {
00044     node=g_list_first(dialog->callback_list);
00045   }
00046   //-- search callback node
00047   while(node) {
00048     callback_node=(GitkCallbackNodePtr)node->data;
00049     if((callback_node->type==type)
00050       && ((widget_id && callback_node->widget_id && !strcmp(widget_id,callback_node->widget_id))
00051         || (!widget_id && !callback_node->widget_id)
00052         )
00053       ) {
00054       result_node=callback_node;break;
00055     }
00056     node=g_list_next(node);
00057   }
00058   return(result_node);
00059 }
00060 
00061 
00073 void gitk__dialog_attach_callback(GitkDialogPtr const dialog,gchar * const widget_id,const GitkEventType type,gpointer const user_data, GitkCallbackPtr const callback,gchar * const callback_name) {
00074   GitkCallbackNodePtr callback_node=g_new(GitkCallbackNode,1);
00075   xmlNodePtr node;
00076   gchar *qstr;
00077 
00078   gitk_log2("gitk_dialog_attach_callback(\"%s\",\"%s\")",gitk_save_get_string(widget_id),callback_name);
00079   if(widget_id) callback_node->widget_id=g_strdup(widget_id);
00080   else { callback_node->widget_id=NULL; }
00081   callback_node->type=type;
00082   callback_node->user_data=user_data;
00083   callback_node->callback=callback;
00084   callback_node->callback_name=g_strdup(callback_name);
00085   //gitk_log("gitk_dialog_attach_callback().step1");
00086   //-- use global_callbacks when dialog==NULL
00088   if((!dialog) && (!widget_id)) {
00089     //-- add the event to dialog element
00090     if(gitk_dialog_list) {
00091       GList* list_node=g_list_first(gitk_dialog_list);
00092       GitkDialogPtr any_dialog;
00093       qstr="//"GITK_NS_PREFIX":dialog";
00094       while(list_node) {
00095         any_dialog=(GitkDialogPtr)list_node->data;
00096         if((node=gitk__xpath_get_node(any_dialog,GITK_DIALOG_ACCESS_RENDERER,qstr,NULL))) {
00097           if(!xmlNodeIsText(node)) xmlSetProp(node,callback_names[type],callback_name);
00098         }
00099         if((node=gitk__xpath_get_node(any_dialog,GITK_DIALOG_ACCESS_CLIENT,qstr,NULL))) {
00100           if(!xmlNodeIsText(node)) xmlSetProp(node,callback_names[type],callback_name);
00101         }
00102         list_node=g_list_next(list_node);
00103       }
00104     }
00105     gitk_global_callback_list=g_list_append(gitk_global_callback_list,callback_node);
00106   }
00107   else {
00108     g_assert(dialog);
00109     g_assert(widget_id);
00110     //-- add the event to widget element
00111     qstr=gitk_get_widget_xpath_expression(widget_id);
00112     if((node=gitk__xpath_get_node(dialog,GITK_DIALOG_ACCESS_RENDERER,qstr,NULL))) {
00113       if(!xmlNodeIsText(node)) xmlSetProp(node,callback_names[type],callback_name);
00114     }
00115     if((node=gitk__xpath_get_node(dialog,GITK_DIALOG_ACCESS_CLIENT,qstr,NULL))) {
00116       if(!xmlNodeIsText(node)) xmlSetProp(node,callback_names[type],callback_name);
00117     }
00118     dialog->callback_list=g_list_append(dialog->callback_list,callback_node);
00119   }
00120   //gitk_log("gitk_dialog_attach_callback().step2");
00121   //-- invoke callback for ON_CHANGED events to initialize data
00122   if(type==GITK_EVENT_TYPE_ON_CHANGED) {
00123     callback_node->callback(dialog,widget_id,NULL,callback_node->user_data);
00124   }
00125   //gitk_log("gitk_dialog_attach_callback() end");
00126 }
00127 
00134 void gitk_dialog_detach_callback(GitkDialogPtr const dialog,gchar * const widget_id,const GitkEventType type) {
00135   GitkCallbackNodePtr callback_node;
00136   xmlNodePtr node;
00137   gchar *qstr;
00138 
00139   if((callback_node=gitk_get_callback_node(dialog,widget_id,type))) {
00140     //-- use global_callbacks when dialog==NULL
00141     if(!dialog) {
00142       //-- remove the event from the dialog element
00143       if(gitk_dialog_list) {
00144         GList* list_node=g_list_first(gitk_dialog_list);
00145         GitkDialogPtr any_dialog;
00146         qstr="//"GITK_NS_PREFIX":dialog";
00147         while(list_node) {
00148           any_dialog=(GitkDialogPtr)list_node->data;
00149           if((node=gitk__xpath_get_node(any_dialog,GITK_DIALOG_ACCESS_RENDERER,qstr,NULL))) {
00150             if(!xmlNodeIsText(node)) xmlUnsetProp(node,callback_names[type]);
00151           }
00152           if((node=gitk__xpath_get_node(any_dialog,GITK_DIALOG_ACCESS_CLIENT,qstr,NULL))) {
00153             if(!xmlNodeIsText(node)) xmlUnsetProp(node,callback_names[type]);
00154           }
00155           list_node=g_list_next(list_node);
00156         }
00157       }
00158       gitk_global_callback_list=g_list_remove(gitk_global_callback_list,callback_node);
00159     }
00160     else {
00161       //-- remove the event from the widget element
00162       qstr=gitk_get_widget_xpath_expression(widget_id);
00163       if((node=gitk__xpath_get_node(dialog,GITK_DIALOG_ACCESS_RENDERER,qstr,NULL))) {
00164         if(!xmlNodeIsText(node)) xmlUnsetProp(node,callback_names[type]);
00165       }
00166       if((node=gitk__xpath_get_node(dialog,GITK_DIALOG_ACCESS_CLIENT,qstr,NULL))) {
00167         if(!xmlNodeIsText(node)) xmlUnsetProp(node,callback_names[type]);
00168       }
00169       dialog->callback_list=g_list_remove(dialog->callback_list,callback_node);
00170     }
00171     g_free(callback_node->widget_id);
00172     g_free(callback_node->callback_name);
00173     g_free(callback_node);
00174   }
00175 }
00176 
00186 gboolean gitk_dialog_process_event(GitkDialogPtr const dialog,gchar * const widget_id,GitkEventPtr const event) {
00187   GitkCallbackNodePtr callback_node;
00188   gboolean res=TRUE;
00189 
00190   g_assert(event!=NULL);
00191 
00192   if((callback_node=gitk_get_callback_node(dialog,widget_id,event->type))) {
00193     gitk_log1("found local callback: \"%s\"",callback_node->callback_name);
00194     res=callback_node->callback(dialog,widget_id,event,callback_node->user_data);
00195   }
00196   else {
00197     if((callback_node=gitk_get_callback_node(NULL,widget_id,event->type))) {
00198       gitk_log1("found global callback: \"%s\"",callback_node->callback_name);
00199       res=callback_node->callback(dialog,widget_id,event,callback_node->user_data);
00200     }
00201   }
00202   return(res);
00203 }
00204 
00210 void gitk_dialog_trans_callback(GitkDialogPtr dialog) {
00211   gchar *qstr="//"GITK_NS_PREFIX":dialog";
00212   xmlNodePtr node;
00213   GList* list_node=g_list_first(gitk_global_callback_list);
00214   GitkCallbackNodePtr callback_node=NULL;
00215   
00216   //-- search callback node
00217   while(list_node) {
00218     callback_node=(GitkCallbackNodePtr)list_node->data;
00219     if((node=gitk__xpath_get_node(dialog,GITK_DIALOG_ACCESS_RENDERER,qstr,NULL))) {
00220       if(!xmlNodeIsText(node)) xmlSetProp(node,callback_names[callback_node->type],callback_node->callback_name);
00221     }
00222     if((node=gitk__xpath_get_node(dialog,GITK_DIALOG_ACCESS_CLIENT,qstr,NULL))) {
00223       if(!xmlNodeIsText(node)) xmlSetProp(node,callback_names[callback_node->type],callback_node->callback_name);
00224     }
00225     list_node=g_list_next(list_node);
00226   }
00227 }
00228 

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