Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

Gadget.c

Go to the documentation of this file.
00001 /*
00002  *    gui - [gega user interface] the flexible solution for user interface problems
00003  *    Copyright (C) 2002  Gergely Gati
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; version 2 of the License.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License
00015  *    along with this program; if not, write to the Free Software
00016  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  *    Gergely Gati
00019  *      email:           g.gati@freemail.hu
00020  *      AIM screenname:  GatiGergely
00021  *      ICQ number:      93131690
00022  *
00023  */
00024 /*
00025  *  gadget.c
00026  */
00027 #include <string.h>
00028 
00029 #include "debug.h"
00030 #include "Memory.h"
00031 #include "Crc.h"
00032 #include "Common.h"
00033 #include "Skin.h"
00034 #include "Window.h"
00035 #include "Gadget.h"
00036 #include "Prefs.h"
00037 #include "Net.h"
00038 #include "Locale.h"
00039 #include "gadgets/gadget_Group.h"
00040 
00041 
00042 static u32 gadget_SetFont(Gadget_t *this_gadget, tag *taglist);
00043 static u32 gadget_SetHint(Gadget_t *this_gadget, tag *taglist);
00044 
00045 //Declare call_vector[]
00046 static u32 (*call_vector[GADGET_FUNC_DONE-GADGET_FUNCBASE+1])(tag *);
00047 
00048 static List_t *class_list=NULL;           //SEMAPHORE PROTECTED!
00049 static gadget_Method_t no_methods[]={ GADGET_METHOD_DONE };
00050 static gadget_Binding_t common_bind[]=
00051 {
00052   {"font-name",TAG_GAD_FONTNAME,GADGET_STRING,""},
00053   {"font-size",TAG_GAD_FONTSIZE,GADGET_INT,NULL},
00054   {"font-style",TAG_GAD_FONTSTYLE,GADGET_SELECT,"normal|italic"},
00055   {"font-weight",TAG_GAD_FONTWEIGHT,GADGET_SELECT,"normal|bold"},
00056   {"font-decoration",TAG_GAD_FONTDECORATION,GADGET_SELECT,"normal|underline|line-through"},
00057   {"skin",TAG_GAD_SKIN,GADGET_STRING,""},
00058   {"hint",TAG_GAD_HINT,GADGET_STRING,""},
00059   {"width",TAG_GAD_WIDTH,GADGET_INT,NULL},            // pixel-ertek (ha <min -> min, ha >max -> max)
00060   {"height",TAG_GAD_HEIGHT,GADGET_INT,NULL},          // pixel-ertek (ha <min -> min, ha >max -> max)
00061   {"layout",TAG_GAD_LAYOUT,GADGET_SELECT,"free|fixed|square"},
00062   GADGET_BINDING_DONE
00063 };
00064 static gadget_Method_t gadget_methods[]=
00065 {
00066   {"set_font",gadget_SetFont,0L},
00067   {"set_hint",gadget_SetHint,0L},
00068   GADGET_METHOD_DONE
00069 };
00070 static char *state_names[]=
00071 {
00072   "Normal",
00073   "Pressed",
00074   "Disabled",
00075   "Focused",
00076   "Default",
00077   NULL
00078 };
00079 
00080 
00084 u32 gadget_Bind(u32 firsttag, ...)
00085 {
00086   return(gadget_BindTL((tag *)&firsttag));
00087 }
00088 u32 gadget_BindTL(tag *taglist)
00089 {
00090   Locale_t *locale;
00091   gadget_Binding_t *binding;
00092   char *name;
00093   char *value;
00094   u32 *tagname;
00095   u32 *tagvalue;
00096 
00097   int ret=-1;
00098   u32 tnam,tval=0L;
00099   gadget_Binding_t *cbind=NULL;
00100   int i;
00101   char *here;
00102 
00103   debug_Begin();
00104 
00105   locale=(Locale_t *)tag_GetTagData(taglist,TAG_GADGET_LOCALE,0L);
00106   binding=(gadget_Binding_t *)tag_GetTagData(taglist,TAG_GADGET_BINDING,0L);
00107   name=(char *)tag_GetTagData(taglist,TAG_GADGET_NAME,0L);
00108   value=(char *)tag_GetTagData(taglist,TAG_GADGET_VALUE,0L);
00109   tagname=(u32 *)tag_GetTagData(taglist,TAG_GADGET_TAGNAME,0L);
00110   tagvalue=(u32 *)tag_GetTagData(taglist,TAG_GADGET_TAGVALUE,0L);
00111 
00112   if(binding!=NULL&&name!=NULL&&value!=NULL)
00113   {
00114     for(i=0;binding[i].name!=NULL;i++) if(strcmp(binding[i].name,name)==0) { cbind=&binding[i]; break; }
00115     if(cbind!=NULL)
00116     {
00117       ret=0;
00118       tnam=cbind->tagname;
00119       switch(cbind->datatype)
00120       {
00121         case GADGET_INT:
00122         {
00123           // decimal (atoi), hexa (0x, #, $)
00124           if(strlen(value)>1)
00125           {
00126             if(value[0]=='0'&&value[1]=='x') sscanf(&value[2],"%lx",&tval);
00127             else if(value[0]=='#'||value[0]=='$') sscanf(&value[1],"%lx",&tval);
00128             else tval=atoi(value);
00129           }
00130           else tval=atoi(value);
00131           break;
00132         }
00133         case GADGET_STRING:
00134         {
00135           here=value;
00136           if(here[0]=='#'&&strlen(here)>1)
00137           {
00138             here++;
00139             if(here[0]!='#'&&locale!=NULL) here=(char *)locale_GetString(TAG_LOCALE_LOCALE,locale,TAG_LOCALE_MSG,here,TAG_DONE);
00140           }
00141           tval=(u32)here;
00142           break;
00143         }
00144         case GADGET_SELECT:
00145         {
00146           if(NULL!=(here=strstr(cbind->value_mask,value)))
00147           {
00148             for(tval=0L;here!=cbind->value_mask;here--) if(*here=='|') tval++;
00149           }
00150           break;
00151         }
00152         case GADGET_BOOL:
00153         {
00154           if(strcmp(value,"true")==0) tval=TRUE;
00155           else if(strcmp(value,"false")==0) tval=FALSE;
00156           else if(strcmp(value,"t")==0) tval=TRUE;
00157           else if(strcmp(value,"f")==0) tval=FALSE;
00158           else if(strcmp(value,"yes")==0) tval=TRUE;
00159           else if(strcmp(value,"no")==0) tval=FALSE;
00160           else if(strcmp(value,"on")==0) tval=TRUE;
00161           else if(strcmp(value,"off")==0) tval=FALSE;
00162           else { tnam=TAG_SKIP; debug_Error("Unknown boolean value"); }
00163           break;
00164         }
00165         default:
00166         {
00167           tnam=TAG_SKIP;
00168           ret=-1;
00169           debug_Error("Unknown datatype");
00170           break;
00171         }
00172       }
00173       if(tagname!=NULL) *tagname=tnam;
00174       if(tagvalue!=NULL) *tagvalue=tval;
00175     }
00176   }
00177 
00178   debug_End();
00179 
00180   return((u32)ret);
00181 }
00182 
00183 
00187 u32 gadget_GetStateName(u32 firsttag, ...)
00188 {
00189   return(gadget_GetStateNameTL((tag *)&firsttag));
00190 }
00191 u32 gadget_GetStateNameTL(tag *taglist)
00192 {
00193   char *state_name;
00194 
00195   int ret=GADST_NONE,i;
00196 
00197   debug_Begin();
00198 
00199   state_name=(char *)tag_GetTagData(taglist,TAG_GADGET_STATE_NAME,0L);
00200 
00201   if(state_name!=NULL)
00202   {
00203     for(i=0;state_names[i]!=NULL;i++)
00204     {
00205       if(strcmp(state_name,state_names[i])==0)
00206       {
00207         ret=i;
00208         break;
00209       }
00210     }
00211   }
00212 
00213   debug_End();
00214 
00215   return((u32)ret);
00216 }
00217 
00218 
00219 
00220 static u32 gadget_SetFont(Gadget_t *this_gadget, tag *taglist)
00221 {
00222   u32 ret=~0;
00223   char *font_name;
00224   int font_size;
00225   int font_style;
00226   int font_weight;
00227   int font_decoration;
00228   u32 font_flags=0L;
00229   u32 new_font=0L;
00230 
00231   debug_Begin();
00232 
00233   if(this_gadget!=NULL&&taglist!=NULL)
00234   {
00235     font_name=(char *)tag_GetTagData(taglist,TAG_GAD_FONTNAME,0L);
00236     font_size=(int)tag_GetTagData(taglist,TAG_GAD_FONTSIZE,GADGET_DEFAULT_FONTSIZE);
00237     font_style=(int)tag_GetTagData(taglist,TAG_GAD_FONTSTYLE,0L);
00238     font_weight=(int)tag_GetTagData(taglist,TAG_GAD_FONTWEIGHT,0L);
00239     font_decoration=(int)tag_GetTagData(taglist,TAG_GAD_FONTDECORATION,0L);
00240     if(font_style==GADGET_FONTSTYLE_ITALIC) font_flags|=GLWFS_ITALIC;
00241     if(font_weight==GADGET_FONTWEIGHT_BOLD) font_flags|=GLWFS_BOLD;
00242     if(font_decoration==GADGET_FONTDECORATION_UNDERLINED) font_flags|=GLWFS_UNDERLINE;
00243     if(font_name!=NULL) new_font=glw_OpenFont(TAG_GLW_CONN,window_GetConnection(this_gadget->window),TAG_GLW_FACE,font_name,TAG_GLW_SIZE,font_size,TAG_GLW_STYLE,font_flags,TAG_DONE);
00244     if(new_font!=0L&&this_gadget->font!=0L) glw_CloseFont(TAG_GLW_FONT,this_gadget->font,TAG_DONE);
00245     if(new_font!=0L)
00246     {
00247       this_gadget->font=new_font;
00248       ret=0L;
00249     }
00250   }
00251 
00252   debug_End();
00253 
00254   return(ret);
00255 }
00256 static u32 gadget_SetHint(Gadget_t *this_gadget, tag *taglist)
00257 {
00258   return(0L);
00259 }
00260 
00261 
00262 gadget_Binding_t *gadget_GetCommonBind(void)
00263 {
00264   return(common_bind);
00265 }
00266 
00267 
00268 int gadget_Init(void)
00269 {
00270   int ret=-1;
00271 
00272   debug_Begin();
00273 
00274 //Initialize call vector BEGIN - put this into the init function of this module
00275   call_vector[GADGET_GET_STATE_NAME-GADGET_FUNCBASE]=gadget_GetStateNameTL;
00276   call_vector[GADGET_REGISTER_CLASS-GADGET_FUNCBASE]=gadget_RegisterClassTL;
00277   call_vector[GADGET_FIND_CLASS-GADGET_FUNCBASE]=gadget_FindClassTL;
00278   call_vector[GADGET_FIND_CLASS_BY_NAME-GADGET_FUNCBASE]=gadget_FindClassByNameTL;
00279   call_vector[GADGET_FATHER-GADGET_FUNCBASE]=gadget_FatherTL;
00280   call_vector[GADGET_FIRST_CHILD-GADGET_FUNCBASE]=gadget_FirstChildTL;
00281   call_vector[GADGET_LAST_CHILD-GADGET_FUNCBASE]=gadget_LastChildTL;
00282   call_vector[GADGET_NTH_CHILD-GADGET_FUNCBASE]=gadget_NthChildTL;
00283   call_vector[GADGET_LEFT_BROTHER-GADGET_FUNCBASE]=gadget_LeftBrotherTL;
00284   call_vector[GADGET_RIGHT_BROTHER-GADGET_FUNCBASE]=gadget_RightBrotherTL;
00285   call_vector[GADGET_FIRST_BROTHER-GADGET_FUNCBASE]=gadget_FirstBrotherTL;
00286   call_vector[GADGET_LAST_BROTHER-GADGET_FUNCBASE]=gadget_LastBrotherTL;
00287   call_vector[GADGET_LEFT_BROTHER_CIRCULAR-GADGET_FUNCBASE]=gadget_LeftBrotherCircularTL;
00288   call_vector[GADGET_RIGHT_BROTHER_CIRCULAR-GADGET_FUNCBASE]=gadget_RightBrotherCircularTL;
00289   call_vector[GADGET_FIRST_NODE-GADGET_FUNCBASE]=gadget_FirstNodeTL;
00290   call_vector[GADGET_NEXT_NODE-GADGET_FUNCBASE]=gadget_NextNodeTL;
00291   call_vector[GADGET_ATTACH_FIRST-GADGET_FUNCBASE]=gadget_AttachFirstTL;
00292   call_vector[GADGET_ATTACH-GADGET_FUNCBASE]=gadget_AttachTL;
00293   call_vector[GADGET_DETACH-GADGET_FUNCBASE]=gadget_DetachTL;
00294   call_vector[GADGET_SET_STATE-GADGET_FUNCBASE]=gadget_SetStateTL;
00295   call_vector[GADGET_POST_MESSAGE-GADGET_FUNCBASE]=gadget_PostMessageTL;
00296   call_vector[GADGET_GET_FONT-GADGET_FUNCBASE]=gadget_GetFontTL;
00297   call_vector[GADGET_GET_COLOR-GADGET_FUNCBASE]=gadget_GetColorTL;
00298   call_vector[GADGET_GET_STATE-GADGET_FUNCBASE]=gadget_GetStateTL;
00299   call_vector[GADGET_NEW-GADGET_FUNCBASE]=gadget_NewTL;
00300   call_vector[GADGET_DELETE_SUBTREE-GADGET_FUNCBASE]=gadget_DeleteSubtreeTL;
00301   call_vector[GADGET_SEARCH-GADGET_FUNCBASE]=gadget_SearchTL;
00302   call_vector[GADGET_SEARCH_IN_WINDOW-GADGET_FUNCBASE]=gadget_SearchInWindowTL;
00303   call_vector[GADGET_RENDER_CUSTOM-GADGET_FUNCBASE]=gadget_RenderCustomTL;
00304   call_vector[GADGET_REFRESH-GADGET_FUNCBASE]=gadget_RefreshTL;
00305   call_vector[GADGET_FIND_PARENT-GADGET_FUNCBASE]=gadget_FindParentTL;
00306   call_vector[GADGET_HIDE_ALL-GADGET_FUNCBASE]=gadget_HideAllTL;
00307   call_vector[GADGET_FIND_RIGHT_MOST-GADGET_FUNCBASE]=gadget_FindRightMostTL;
00308   call_vector[GADGET_GET_HINT-GADGET_FUNCBASE]=gadget_GetHintTL;
00309   call_vector[GADGET_GET_EXTENT-GADGET_FUNCBASE]=gadget_GetExtentTL;
00310   call_vector[GADGET_GET_RECT-GADGET_FUNCBASE]=gadget_GetRectTL;
00311   call_vector[GADGET_SUGGEST_EXTENT-GADGET_FUNCBASE]=gadget_SuggestExtentTL;
00312   call_vector[GADGET_DELETE_GADGET-GADGET_FUNCBASE]=gadget_DeleteGadgetTL;
00313   call_vector[GADGET_INIT_GADGET-GADGET_FUNCBASE]=gadget_InitGadgetTL;
00314   call_vector[GADGET_INPUT_EVENT_HANDLER-GADGET_FUNCBASE]=gadget_InputEventHandlerTL;
00315   call_vector[GADGET_LAYOUT-GADGET_FUNCBASE]=gadget_LayoutTL;
00316   call_vector[GADGET_DAMAGE-GADGET_FUNCBASE]=gadget_DamageTL;
00317   call_vector[GADGET_CALLBACK-GADGET_FUNCBASE]=gadget_CallBackTL;
00318   call_vector[GADGET_GET_UNIQUE_ID-GADGET_FUNCBASE]=gadget_GetUniqueIdTL;
00319   call_vector[GADGET_SAVE-GADGET_FUNCBASE]=gadget_SaveTL;
00320   call_vector[GADGET_RESTORE-GADGET_FUNCBASE]=gadget_RestoreTL;
00321   call_vector[GADGET_METHODCALL-GADGET_FUNCBASE]=gadget_MethodCallTL;
00322   call_vector[GADGET_BIND-GADGET_FUNCBASE]=gadget_BindTL;
00323   bases_modules.gadget_Call=gadget_Call;
00324   bases_modules.gadget_CallTL=gadget_CallTL;
00325 //Initialize call vector END
00326 
00327   if(class_list==NULL)
00328   {
00329     class_list=list_CreateList();
00330     ret=0;
00331   }
00332 
00333   debug_End();
00334 
00335   return(ret);
00336 }
00337 
00338 
00339 void gadget_CleanUp(void)
00340 {
00341   Node_t *node;
00342   gadget_ClassData_t *classdata;
00343 
00344   debug_Begin();
00345 
00346   if(class_list!=NULL)
00347   {
00348     for(node=list_GetNodeHead(class_list);node!=NULL;node=list_GetNodeHead(class_list))
00349     {
00350       list_RemoveNode(class_list,node);
00351       if(NULL!=(classdata=(gadget_ClassData_t *)list_GetNodeData(node)))
00352       {
00353         glw_CloseModule(classdata->module);
00354         if(NULL!=classdata->class_name) mem_free(classdata->class_name);
00355         mem_free(classdata);
00356       }
00357       list_DeleteNode(node);
00358     }
00359     list_DeleteList(class_list);
00360   }
00361   class_list=NULL;
00362 
00363   debug_End();
00364 }
00365 
00366 
00367 int gadget_LoadClass(gui_App_t *app, char *class, Skin_t *skin)
00368 {
00369   int ret=-1;
00370   char *path_gadgets,*fnam;
00371   int flen;
00372   u8 *mod;
00373   FILE *f;
00374 
00375   debug_Begin();
00376 
00377   if(class!=NULL)
00378   {
00379     path_gadgets=prefs_GetString(NULL,"path.gadgets","gadgets");
00380     if(NULL!=(fnam=mem_malloc(strlen(path_gadgets)+1+1+7+strlen(class))))
00381     {
00382       strcpy(fnam,path_gadgets);
00383       strcat(fnam,"/");
00384       strcat(fnam,class);
00385       strcat(fnam,".gadget");
00386       if(0L==glw_OpenModule(fnam))
00387       {
00388         // get the module from the client
00389         if(NULL!=(mod=(u8 *)net_LoadFile(TAG_NET_CONN,app->conn,TAG_NET_NAME,fnam,TAG_NET_LEN,&flen,TAG_DONE)))
00390         {
00391           if(NULL!=(f=fopen(fnam,"wb")))
00392           {
00393             fwrite(mod,1,flen,f);
00394             fclose(f);
00395           }
00396           mem_free(mod);
00397           if(0L!=glw_OpenModule(fnam)) ret=0;
00398         }
00399       }
00400       else ret=0;
00401       mem_free(fnam);
00402       if(ret==0&&skin!=NULL) skin_LoadSkin(skin,class);
00403     }
00404   }
00405 
00406   debug_End();
00407 
00408   return(ret);
00409 }
00410 
00411 
00426 u32 gadget_RegisterClass(u32 firsttag, ...)
00427 {
00428   return(gadget_RegisterClassTL((tag *)&firsttag));
00429 }
00430 u32 gadget_RegisterClassTL(tag *taglist)
00431 {
00432   u32 class_id;
00433   char *name;
00434   gadget_Binding_t *binding;
00435   char **color_names;
00436   char **custom_names;
00437   u32 state_mask;
00438   u32 module;
00439   int gadget_size;
00440   gadget_Method_t *methods;
00441   int (*ie_h)(Gadget_t *,struct glw_Event *);
00442   int (*e_h)(Gadget_t *,Gadget_t *,int,u32);
00443   int (*ge_h)(Gadget_t *,int,tag *);
00444 
00445   int ret=-1;
00446   Node_t *node;
00447   gadget_ClassData_t *classdata;
00448 
00449   debug_Begin();
00450 
00451   class_id=(u32 )tag_GetTagData(taglist,TAG_GADGET_CLASS_ID,0L);
00452   name=(char *)tag_GetTagData(taglist,TAG_GADGET_NAME,0L);
00453   binding=(gadget_Binding_t *)tag_GetTagData(taglist,TAG_GADGET_BINDING,0L);
00454   color_names=(char **)tag_GetTagData(taglist,TAG_GADGET_COLOR_NAMES,0L);
00455   custom_names=(char **)tag_GetTagData(taglist,TAG_GADGET_CUSTOM_NAMES,0L);
00456   state_mask=(u32 )tag_GetTagData(taglist,TAG_GADGET_STATE_MASK,0L);
00457   module=(u32 )tag_GetTagData(taglist,TAG_GADGET_MODULE,0L);
00458   gadget_size=(int )tag_GetTagData(taglist,TAG_GADGET_GADGET_SIZE,0L);
00459   methods=(gadget_Method_t *)tag_GetTagData(taglist,TAG_GADGET_METHODS,0L);
00460   ie_h=(void *)tag_GetTagData(taglist,TAG_GADGET_INPUT_EVENT_HANDLER,0L);
00461   e_h=(void *)tag_GetTagData(taglist,TAG_GADGET_EVENT_HANDLER,0L);
00462   ge_h=(void *)tag_GetTagData(taglist,TAG_GADGET_GADGET_EVENT_HANDLER,0L);
00463 
00464   if(class_list!=NULL&&ge_h!=NULL)
00465   {
00466     if(NULL==(gadget_ClassData_t *)gadget_FindClass(TAG_GADGET_CLASS_ID,class_id,TAG_DONE)&&NULL==(gadget_ClassData_t *)gadget_FindClassByName(TAG_GADGET_CLASS_NAME,name,TAG_DONE))
00467     {
00468       classdata=mem_calloc(1,sizeof(gadget_ClassData_t));
00469       if(classdata!=NULL)
00470       {
00471         if(NULL!=(node=list_CreateNode()))
00472         {
00473           classdata->class_id=class_id;
00474           classdata->module=module;
00475           classdata->class_name=common_strdup(name);
00476           classdata->color_names=color_names;
00477           classdata->color_count=0;
00478           classdata->custom_names=custom_names;
00479           classdata->custom_count=0;
00480           classdata->xmlbinding=binding;
00481           if(color_names!=NULL) while(NULL!=color_names[classdata->color_count]) classdata->color_count++;
00482           if(custom_names!=NULL) while(NULL!=custom_names[classdata->custom_count]) classdata->custom_count++;
00483           classdata->state_mask=state_mask;
00484           classdata->input_event_handler=ie_h;
00485           classdata->event_handler=e_h;
00486           classdata->gadget_event_handler=ge_h;
00487           classdata->gadget_counter=0;
00488           classdata->gadget_size=gadget_size;
00489           classdata->methods=(methods==NULL?no_methods:methods);
00490           for(classdata->method_count=0;classdata->methods[classdata->method_count].function!=NULL&&classdata->method_count<GADGET_METHOD_MAX_COUNT;classdata->method_count++);
00491           list_SetNodeData(node,classdata);
00492           list_InsertNodeTail(class_list,node);
00493           ret=0;
00494         }
00495       }
00496     }
00497   }
00498 
00499   debug_End();
00500 
00501   return((u32)ret);
00502 }
00503 
00504 
00508 u32 gadget_FindClass(u32 firsttag, ...)
00509 {
00510   return(gadget_FindClassTL((tag *)&firsttag));
00511 }
00512 u32 gadget_FindClassTL(tag *taglist)
00513 {
00514   u32 class_id;
00515 
00516   Node_t *node;
00517   gadget_ClassData_t *ret=NULL;
00518 
00519 
00520   debug_Begin();
00521 
00522   class_id=(u32 )tag_GetTagData(taglist,TAG_GADGET_CLASS_ID,0L);
00523 
00524   if(class_list!=NULL)
00525   {
00526     for(node=list_GetNodeHead(class_list);node!=NULL;node=list_GetNodeNext(class_list,node))
00527     {
00528       ret=(gadget_ClassData_t *)list_GetNodeData(node);
00529       if(ret!=NULL&&ret->class_id==class_id) break;
00530       ret=NULL;
00531     }
00532   }
00533 
00534   debug_End();
00535 
00536   return((u32)ret);
00537 }
00538 
00539 
00543 u32 gadget_FindClassByName(u32 firsttag, ...)
00544 {
00545   return(gadget_FindClassByNameTL((tag *)&firsttag));
00546 }
00547 u32 gadget_FindClassByNameTL(tag *taglist)
00548 {
00549   char *class_name;
00550 
00551   Node_t *node;
00552   gadget_ClassData_t *ret=NULL;
00553 
00554   debug_Begin();
00555 
00556   class_name=(char *)tag_GetTagData(taglist,TAG_GADGET_CLASS_NAME,0L);
00557 
00558   if(class_list!=NULL)
00559   {
00560     for(node=list_GetNodeHead(class_list);node!=NULL;node=list_GetNodeNext(class_list,node))
00561     {
00562       ret=(gadget_ClassData_t *)list_GetNodeData(node);
00563       if(strcmp(ret->class_name,class_name)==0) break;
00564       ret=NULL;
00565     }
00566   }
00567 
00568   debug_End();
00569 
00570   return((u32)ret);
00571 }
00572 
00573 
00579 u32 gadget_MethodCall(u32 firsttag, ...)
00580 {
00581   return(gadget_MethodCallTL((tag *)&firsttag));
00582 }
00583 u32 gadget_MethodCallTL(tag *taglist)
00584 {
00585   Window_t *window;
00586   u32 gadget_id;
00587   u32 method;
00588   Gadget_t *this;
00589 
00590   u32 ret=0L;
00591 
00592   debug_Begin();
00593 
00594   window=(Window_t *)tag_GetTagDataChg(taglist,TAG_GADGET_WINDOW,0L);
00595   gadget_id=(u32)tag_GetTagDataChg(taglist,TAG_GADGET_GADGET_ID,0L);
00596   method=(u32)tag_GetTagDataChg(taglist,TAG_GADGET_METHOD,0L);
00597   this=(Gadget_t *)tag_GetTagDataChg(taglist,TAG_GADGET_OBJECT,0L);
00598 
00599   if(this==NULL) this=(Gadget_t *)gadget_SearchInWindow(TAG_GADGET_WINDOW,window,TAG_GADGET_GADGET_ID,gadget_id,TAG_DONE);
00600   if(this!=NULL)
00601   {
00602     if(method<GADGET_METHOD_BASE&&method<GADGET_METHOD_COUNT)
00603     {
00604 //printf("  call: %ld gadget_%s\n",this->gadget_id,gadget_methods[method].name);
00605       ret=gadget_methods[method].function(this,taglist);
00606     }
00607     else
00608     {
00609       method-=GADGET_METHOD_BASE;
00610       if(this->class_data->method_count>method)
00611       {
00612 //printf("  call: %ld %s_%s\n",this->gadget_id,this->class_data->class_name,this->class_data->methods[method].name);
00613         ret=this->class_data->methods[method].function(this,taglist);
00614       }
00615     }
00616   }
00617 
00618   debug_End();
00619 
00620   return(ret);
00621 }
00622 
00623 
00627 u32 gadget_Father(u32 firsttag, ...)
00628 {
00629   return(gadget_FatherTL((tag *)&firsttag));
00630 }
00631 u32 gadget_FatherTL(tag *taglist)
00632 {
00633   Gadget_t *gad;
00634 
00635 
00636   debug_Begin();
00637 
00638   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00639 
00640   debug_End();
00641 
00642   return((u32)gad->parent);
00643 }
00644 
00648 u32 gadget_FirstChild(u32 firsttag, ...)
00649 {
00650   return(gadget_FirstChildTL((tag *)&firsttag));
00651 }
00652 u32 gadget_FirstChildTL(tag *taglist)
00653 {
00654   Gadget_t *gad;
00655 
00656 
00657   debug_Begin();
00658 
00659   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00660 
00661   debug_End();
00662   return((u32)gad->firstchild);
00663 }
00664 
00668 u32 gadget_LastChild(u32 firsttag, ...)
00669 {
00670   return(gadget_LastChildTL((tag *)&firsttag));
00671 }
00672 u32 gadget_LastChildTL(tag *taglist)
00673 {
00674   Gadget_t *gad;
00675 
00676 
00677   debug_Begin();
00678 
00679   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00680 
00681   debug_End();
00682   return((u32)gad->lastchild);
00683 }
00684 
00689 u32 gadget_NthChild(u32 firsttag, ...)
00690 {
00691   return(gadget_NthChildTL((tag *)&firsttag));
00692 }
00693 u32 gadget_NthChildTL(tag *taglist)
00694 {
00695   Gadget_t *gad;
00696   int index;
00697 
00698   Gadget_t *ret;
00699   int i;
00700 
00701   debug_Begin();
00702 
00703   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00704   index=(int )tag_GetTagData(taglist,TAG_GADGET_INDEX,0L);
00705 
00706   for(i=0,ret=gad->firstchild;i<=index&&gad!=NULL;gad=gad->next);
00707 
00708   debug_End();
00709 
00710   return((u32)ret);
00711 }
00712 
00716 u32 gadget_LeftBrother(u32 firsttag, ...)
00717 {
00718   return(gadget_LeftBrotherTL((tag *)&firsttag));
00719 }
00720 u32 gadget_LeftBrotherTL(tag *taglist)
00721 {
00722   Gadget_t *gad;
00723 
00724 
00725   debug_Begin();
00726 
00727   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00728 
00729   debug_End();
00730   return((u32)gad->prev);
00731 }
00732 
00736 u32 gadget_RightBrother(u32 firsttag, ...)
00737 {
00738   return(gadget_RightBrotherTL((tag *)&firsttag));
00739 }
00740 u32 gadget_RightBrotherTL(tag *taglist)
00741 {
00742   Gadget_t *gad;
00743 
00744 
00745   debug_Begin();
00746 
00747   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00748 
00749   debug_End();
00750   return((u32)gad->next);
00751 }
00752 
00756 u32 gadget_FirstBrother(u32 firsttag, ...)
00757 {
00758   return(gadget_FirstBrotherTL((tag *)&firsttag));
00759 }
00760 u32 gadget_FirstBrotherTL(tag *taglist)
00761 {
00762   Gadget_t *gad;
00763 
00764   Gadget_t *ret=NULL;
00765 
00766   debug_Begin();
00767 
00768   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00769 
00770   for(;gad!=NULL;gad=gad->prev) ret=gad;
00771 
00772   debug_End();
00773 
00774   return((u32)ret);
00775 }
00776 
00780 u32 gadget_LastBrother(u32 firsttag, ...)
00781 {
00782   return(gadget_LastBrotherTL((tag *)&firsttag));
00783 }
00784 u32 gadget_LastBrotherTL(tag *taglist)
00785 {
00786   Gadget_t *gad;
00787 
00788   Gadget_t *ret=NULL;
00789 
00790   debug_Begin();
00791 
00792   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00793 
00794   for(;gad!=NULL;gad=gad->next) ret=gad;
00795 
00796   debug_End();
00797 
00798   return((u32)ret);
00799 }
00800 
00804 u32 gadget_LeftBrotherCircular(u32 firsttag, ...)
00805 {
00806   return(gadget_LeftBrotherCircularTL((tag *)&firsttag));
00807 }
00808 u32 gadget_LeftBrotherCircularTL(tag *taglist)
00809 {
00810   Gadget_t *gad;
00811 
00812   Gadget_t *ret=NULL;
00813 
00814   debug_Begin();
00815 
00816   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00817 
00818   if(gad!=NULL&&NULL==(ret=gad->prev)) ret=(Gadget_t *)gadget_LastBrother(TAG_GADGET_OBJECT,gad,TAG_DONE);
00819 
00820   debug_End();
00821 
00822   return((u32)ret);
00823 }
00824 
00828 u32 gadget_RightBrotherCircular(u32 firsttag, ...)
00829 {
00830   return(gadget_RightBrotherCircularTL((tag *)&firsttag));
00831 }
00832 u32 gadget_RightBrotherCircularTL(tag *taglist)
00833 {
00834   Gadget_t *gad;
00835 
00836   Gadget_t *ret=NULL;
00837 
00838   debug_Begin();
00839 
00840   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00841 
00842   if(gad!=NULL&&NULL==(ret=gad->next)) ret=(Gadget_t *)gadget_FirstBrother(TAG_GADGET_OBJECT,gad,TAG_DONE);
00843 
00844   debug_End();
00845 
00846   return((u32)ret);
00847 }
00848 
00849 // szelessegi bejaro rutinok
00850 
00854 u32 gadget_FirstNode(u32 firsttag, ...)
00855 {
00856   return(gadget_FirstNodeTL((tag *)&firsttag));
00857 }
00858 u32 gadget_FirstNodeTL(tag *taglist)
00859 {
00860   Gadget_t *root;
00861 
00862 
00863   debug_Begin();
00864 
00865   root=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_ROOT,0L);
00866 
00867   debug_End();
00868   return((u32)root);
00869 }
00870 
00875 u32 gadget_NextNode(u32 firsttag, ...)
00876 {
00877   return(gadget_NextNodeTL((tag *)&firsttag));
00878 }
00879 u32 gadget_NextNodeTL(tag *taglist)
00880 {
00881   Gadget_t *gad;
00882   Gadget_t *root;
00883 
00884   Gadget_t *ret=NULL;
00885 
00886 
00887   debug_Begin();
00888 
00889   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00890   root=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_ROOT,0L);
00891 
00892   if(gad!=NULL)
00893   {
00894     if(NULL==(ret=gad->firstchild))
00895     {
00896       if(NULL==(ret=gad->next))
00897       {
00898         for(gad=gad->parent;gad!=root&&gad->next==NULL;gad=gad->parent);
00899         if(gad!=root) ret=gad->next;
00900       }
00901     }
00902   }
00903 
00904   debug_End();
00905 
00906   return((u32)ret);
00907 }
00908 
00909 
00914 u32 gadget_AttachFirst(u32 firsttag, ...)
00915 {
00916   return(gadget_AttachFirstTL((tag *)&firsttag));
00917 }
00918 u32 gadget_AttachFirstTL(tag *taglist)
00919 {
00920   Gadget_t *new_parent;
00921   Gadget_t *new_child;
00922 
00923 
00924   debug_Begin();
00925 
00926   new_parent=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_NEW_PARENT,0L);
00927   new_child=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_NEW_CHILD,0L);
00928 
00929   new_child->parent=new_parent;
00930   new_child->prev=NULL;
00931   new_child->next=new_parent->firstchild;
00932   if(new_parent->firstchild!=NULL) new_parent->firstchild->prev=new_child;
00933   else new_parent->lastchild=new_child;
00934   new_parent->firstchild=new_child;
00935 
00936   debug_End();
00937   return(0L);
00938 }
00939 
00944 u32 gadget_Attach(u32 firsttag, ...)
00945 {
00946   return(gadget_AttachTL((tag *)&firsttag));
00947 }
00948 u32 gadget_AttachTL(tag *taglist)
00949 {
00950   Gadget_t *new_parent;
00951   Gadget_t *new_child;
00952 
00953 
00954   debug_Begin();
00955 
00956   new_parent=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_NEW_PARENT,0L);
00957   new_child=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_NEW_CHILD,0L);
00958 //78
00959   new_child->parent=new_parent;
00960   new_child->next=NULL;
00961   new_child->prev=new_parent->lastchild;
00962   if(new_parent->lastchild!=NULL) new_parent->lastchild->next=new_child;
00963   else new_parent->firstchild=new_child;
00964   new_parent->lastchild=new_child;
00965 
00966   debug_End();
00967   return(0L);
00968 }
00969 
00973 u32 gadget_Detach(u32 firsttag, ...)
00974 {
00975   return(gadget_DetachTL((tag *)&firsttag));
00976 }
00977 u32 gadget_DetachTL(tag *taglist)
00978 {
00979   Gadget_t *gad;
00980 
00981 
00982   debug_Begin();
00983 
00984   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
00985 
00986   if(gad->parent!=NULL)
00987   {
00988     if(gad->prev!=NULL) gad->prev->next=gad->next;
00989     if(gad->next!=NULL) gad->next->prev=gad->prev;
00990     if(gad->parent->firstchild==gad) gad->parent->firstchild=gad->prev;
00991     if(gad->parent->lastchild==gad) gad->parent->lastchild=gad->next;
00992     gad->parent=NULL;
00993   }
00994 
00995   debug_End();
00996   return(0L);
00997 }
00998 
00999 
01005 u32 gadget_SetState(u32 firsttag, ...)
01006 {
01007   return(gadget_SetStateTL((tag *)&firsttag));
01008 }
01009 u32 gadget_SetStateTL(tag *taglist)
01010 {
01011   Gadget_t *gad;
01012   int state;
01013   int visual;
01014 
01015   int ret=-1;
01016 
01017 
01018   debug_Begin();
01019 
01020   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01021   state=(int )tag_GetTagData(taglist,TAG_GADGET_STATE,0L);
01022   visual=(int )tag_GetTagData(taglist,TAG_GADGET_VISUAL,0L);
01023 
01024   if(gad!=NULL&&(gad->class_data->state_mask&(1<<state))!=0)
01025   {
01026     ret=gad->state;
01027     gad->state=state;
01028     if(ret!=state&&visual!=0) gadget_Refresh(TAG_GADGET_OBJECT,gad,TAG_DONE);
01029   }
01030 
01031   debug_End();
01032 
01033   return((u32)ret);
01034 }
01035 
01036 
01042 u32 gadget_PostMessage(u32 firsttag, ...)
01043 {
01044   return(gadget_PostMessageTL((tag *)&firsttag));
01045 }
01046 u32 gadget_PostMessageTL(tag *taglist)
01047 {
01048   Gadget_t *gad;
01049   struct glw_Event *event;
01050   Window_t *window;
01051 
01052   int ret=-1;
01053   Gadget_t *node,*this;
01054 
01055   debug_Begin();
01056 
01057   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01058   event=(struct glw_Event *)tag_GetTagData(taglist,TAG_GADGET_EVENT,0L);
01059   window=(Window_t *)tag_GetTagData(taglist,TAG_GADGET_WINDOW,0L);
01060 
01061   if(gad!=NULL&&window!=NULL)
01062   {
01063     if(NULL==window->active_gadget&&((event->event&GLWEV_KEYUP)!=0||(event->event&GLWEV_KEYDOWN)!=0)&&window->focused_gadget!=NULL) this=window->focused_gadget;
01064     else if(NULL==(this=window->active_gadget)) this=gad;
01065     if(0>(ret=gadget_InputEventHandler(TAG_GADGET_OBJECT,this,TAG_GADGET_EVENT,event,TAG_DONE)))
01066     {
01067       for(node=(Gadget_t *)gadget_FirstNode(TAG_GADGET_ROOT,this,TAG_DONE);node!=NULL&&ret<0;node=(Gadget_t *)gadget_NextNode(TAG_GADGET_OBJECT,node,TAG_GADGET_ROOT,this,TAG_DONE))
01068       {
01069         if((node->class_data->flags&GAD_INVISIBLE)!=0||(node->flags&GAD_HIDDEN)!=0) continue;
01070         if(gui_IsInside(TAG_GUI_RECT,&node->rect,TAG_GUI_X,event->mousex,TAG_GUI_Y,event->mousey,TAG_DONE))
01071         {
01072           ret=gadget_InputEventHandler(TAG_GADGET_OBJECT,node,TAG_GADGET_EVENT,event,TAG_DONE);
01073         }
01074       }
01075     }
01076   }
01077 
01078   debug_End();
01079 
01080   return((u32)ret);
01081 }
01082 
01083 
01087 u32 gadget_GetFont(u32 firsttag, ...)
01088 {
01089   return(gadget_GetFontTL((tag *)&firsttag));
01090 }
01091 u32 gadget_GetFontTL(tag *taglist)
01092 {
01093   Gadget_t *this;
01094 
01095   u32 ret=0L;
01096 
01097 
01098   debug_Begin();
01099 
01100   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01101 
01102   if(NULL!=this)
01103   {
01104     ret=this->font;
01105     if(ret==0L) ret=skin_GetFont(window_GetSkin(this->window),this);
01106     for(;ret==0L&&this!=NULL;this=(Gadget_t *)gadget_Father(TAG_GADGET_OBJECT,this,TAG_DONE)) ret=this->font;
01107   }
01108 
01109   debug_End();
01110 
01111   return((u32)ret);
01112 }
01113 
01114 
01115 
01120 u32 gadget_GetColor(u32 firsttag, ...)
01121 {
01122   return(gadget_GetColorTL((tag *)&firsttag));
01123 }
01124 u32 gadget_GetColorTL(tag *taglist)
01125 {
01126   Gadget_t *this;
01127   int color;
01128 
01129   u32 ret=~0L;
01130 
01131 
01132   debug_Begin();
01133 
01134   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01135   color=(int )tag_GetTagData(taglist,TAG_GADGET_COLOR,0L);
01136 
01137   if(this!=NULL&&this->class_data->color_count>color&&this->color_table[this->state]!=NULL)
01138   {
01139     ret=this->color_table[this->state][color];
01140   }
01141 
01142   debug_End();
01143 
01144   return((u32)ret);
01145 }
01146 
01147 
01151 u32 gadget_GetState(u32 firsttag, ...)
01152 {
01153   return(gadget_GetStateTL((tag *)&firsttag));
01154 }
01155 u32 gadget_GetStateTL(tag *taglist)
01156 {
01157   Gadget_t *this;
01158 
01159   int ret=-1;
01160 
01161 
01162   debug_Begin();
01163 
01164   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01165 
01166   if(this!=NULL) ret=this->state;
01167 
01168   debug_End();
01169 
01170   return((u32)ret);
01171 }
01172 
01173 
01174 static int gadget_InitColorTable(Gadget_t *gad)
01175 {
01176   int ret=-1,i;
01177 
01178   debug_Begin();
01179 
01180   if(gad!=NULL)
01181   {
01182     ret=0;
01183     for(i=0;i<GADST_COUNT;i++)
01184     {
01185       if(((gad->class_data->state_mask)&(1<<i))!=0)
01186       {
01187         if(gad->class_data->color_count>0)
01188         {
01189           if(gad->color_table[i]!=NULL) mem_free(gad->color_table[i]);
01190           if(NULL==(gad->color_table[i]=mem_calloc(sizeof(u32),gad->class_data->color_count)))
01191           {
01192             ret=-1;
01193             break;
01194           }
01195           skin_FillColorTable(window_GetSkin(gad->window),gad,i);
01196         }
01197         else gad->color_table[i]=NULL;
01198       }
01199       else gad->color_table[i]=NULL;
01200     }
01201   }
01202 
01203   debug_End();
01204 
01205   return(ret);
01206 }
01207 
01208 
01214 u32 gadget_New(u32 firsttag, ...)
01215 {
01216   return(gadget_NewTL((tag *)&firsttag));
01217 }
01218 u32 gadget_NewTL(tag *taglist)
01219 {
01220   gadget_Descriptor_t *descriptor;
01221   Window_t *window;
01222   Gadget_t *parent;
01223   tag *closing_tag=NULL,*custom_taglist;
01224 
01225   Gadget_t *ret=NULL;
01226   gadget_ClassData_t *gadget_class;
01227   char *skinname;
01228   Skin_t *skin;
01229 
01230   debug_Begin();
01231 
01232   descriptor=(gadget_Descriptor_t *)tag_GetTagData(taglist,TAG_GADGET_DESCRIPTOR,0L);
01233   window=(Window_t *)tag_GetTagData(taglist,TAG_GADGET_WINDOW,0L);
01234   parent=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_PARENT,0L);
01235 
01236   if(descriptor!=NULL&&window!=NULL)
01237   {
01238     if(NULL!=(gadget_class=(gadget_ClassData_t *)gadget_FindClassByName(TAG_GADGET_CLASS_NAME,descriptor->class_name,TAG_DONE)))
01239     {
01240       if(NULL!=(ret=mem_calloc(1,gadget_class->gadget_size)))
01241       {
01242         gadget_class->gadget_counter++;
01243         ret->gadget_id=(descriptor->gadget_id==GADGET_ILLEGAL_ID?gadget_GetUniqueId():descriptor->gadget_id);
01244         ret->class_data=gadget_class;
01245         ret->weight=descriptor->weight;
01246         ret->window=window;
01247         ret->layout=(int)tag_GetTagData(descriptor->taglist,TAG_GAD_LAYOUT,GADGET_LAYOUT_FREE);
01248         ret->layout_width=(int)tag_GetTagData(descriptor->taglist,TAG_GAD_WIDTH,(u32)-1);
01249         ret->layout_height=(int)tag_GetTagData(descriptor->taglist,TAG_GAD_HEIGHT,(u32)-1);
01250         ret->hint=(char *)tag_GetTagData(descriptor->taglist,TAG_GAD_HINT,0L);
01251         ret->skincrc=0L;
01252         if(NULL!=(skinname=(char *)tag_GetTagData(descriptor->taglist,TAG_GAD_SKIN,0L)))
01253         {
01254           ret->skincrc=crc_CalcBuffer(skinname,strlen(skinname));
01255           if(ret->skincrc==0L) ret->skincrc=1L;
01256         }
01257         ret->font=0L;
01258         ret->callback_discard_mask=0L;
01259         if(parent!=NULL)
01260         {
01261           gadget_Attach(TAG_GADGET_NEW_PARENT,parent,TAG_GADGET_NEW_CHILD,ret,TAG_DONE);
01262         }
01263         gadget_InitColorTable(ret);
01264         gadget_SetFont(ret,descriptor->taglist);
01265         skin_FillGadgetInfo(skin=window_GetSkin(window),ret);
01266         if(NULL!=(custom_taglist=skin_GetCustomTaglist(skin,ret)))
01267         {
01268           closing_tag=tag_FindTag(descriptor->taglist,TAG_DONE);
01269           closing_tag->Name=TAG_MORE;
01270           closing_tag->Data=(u32)custom_taglist;
01271         }
01272         gadget_InitGadget(TAG_GADGET_OBJECT,ret,TAG_GADGET_TAGLIST,descriptor->taglist,TAG_DONE);
01273         if(NULL!=closing_tag)
01274         {
01275           closing_tag->Name=TAG_DONE;
01276           closing_tag->Data=0L;
01277         }
01278       }
01279     }
01280   }
01281 
01282   debug_End();
01283 
01284   return((u32)ret);
01285 }
01286 
01287 
01288 
01289 static Gadget_t *gadget_DeleteOne(Gadget_t *gad)
01290 {
01291   Gadget_t *ret=NULL;
01292   int i;
01293 
01294   debug_Begin();
01295 
01296   gad->flags&=~GAD_ONSCREEN;
01297   gadget_DeleteGadget(TAG_GADGET_OBJECT,gad,TAG_DONE);
01298   gad->class_data->gadget_counter--;
01299   if(gad->class_data->gadget_counter<=0)
01300   {
01301     Node_t *node;
01302     for(node=list_GetNodeHead(class_list);node!=NULL;node=list_GetNodeNext(class_list,node))
01303     {
01304       if(gad->class_data==(gadget_ClassData_t *)list_GetNodeData(node))
01305       {
01306         skin_UnloadSkin(window_GetSkin(gad->window),gad->class_data->class_id);
01307         list_RemoveNode(class_list,node);
01308         glw_CloseModule(gad->class_data->module);
01309         if(NULL!=gad->class_data->class_name) mem_free(gad->class_data->class_name);
01310         mem_free(gad->class_data);
01311         list_DeleteNode(node);
01312         break;
01313       }
01314     }
01315   }
01316   if(gad->next!=NULL) gad->next->prev=gad->prev;
01317   if(gad->prev!=NULL) gad->prev->next=gad->next;
01318   if(gad->font!=0L) glw_CloseFont(TAG_GLW_FONT,gad->font,TAG_DONE);
01319   for(i=0;i<GADST_COUNT;i++) if(gad->color_table[i]!=NULL) mem_free(gad->color_table[i]);
01320   ret=gad->firstchild;
01321   mem_free(gad);
01322 
01323   debug_End();
01324 
01325   return(ret);
01326 }
01327 
01328 
01332 u32 gadget_DeleteSubtree(u32 firsttag, ...)
01333 {
01334   return(gadget_DeleteSubtreeTL((tag *)&firsttag));
01335 }
01336 u32 gadget_DeleteSubtreeTL(tag *taglist)
01337 {
01338   Gadget_t *this;
01339 
01340   Gadget_t *next;
01341   tag intaglist1[]=
01342   {
01343     {TAG_GADGET_OBJECT, 0L},
01344     {TAG_DONE,0L}
01345   };
01346   tag intaglist2[]=
01347   {
01348     {TAG_GADGET_OBJECT, 0L},
01349     {TAG_DONE,0L}
01350   };
01351 
01352 
01353   debug_Begin();
01354 
01355   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01356 
01357   if(this!=NULL)
01358   {
01359     while(this!=NULL)
01360     {
01361       intaglist2[0].Data=(u32)this;
01362       next=(Gadget_t *)gadget_RightBrotherTL(intaglist2);
01363       intaglist1[0].Data=(u32)this->firstchild;
01364       gadget_DeleteSubtreeTL(intaglist1);
01365       gadget_DetachTL(intaglist2);
01366       gadget_DeleteOne(this);
01367       this=next;
01368     }
01369   }
01370 
01371   debug_End();
01372 
01373   return(0L);
01374 }
01375 
01376 
01381 u32 gadget_Search(u32 firsttag, ...)
01382 {
01383   return(gadget_SearchTL((tag *)&firsttag));
01384 }
01385 u32 gadget_SearchTL(tag *taglist)
01386 {
01387   Gadget_t *root;
01388   u32 gadget_id;
01389 
01390   Gadget_t *gad=NULL;
01391 
01392 
01393   debug_Begin();
01394 
01395   root=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_ROOT,0L);
01396   gadget_id=(u32 )tag_GetTagData(taglist,TAG_GADGET_GADGET_ID,0L);
01397 
01398   if (root != NULL)
01399   {
01400     for(gad=(Gadget_t *)gadget_FirstNode(TAG_GADGET_ROOT,root,TAG_DONE);gad!=NULL;gad=(Gadget_t *)gadget_NextNode(TAG_GADGET_OBJECT,gad,TAG_GADGET_ROOT,root,TAG_DONE))
01401     {
01402       if(gad->gadget_id==gadget_id) break;
01403     }
01404   }
01405 
01406   debug_End();
01407 
01408   return((u32)gad);
01409 }
01410 
01411 
01416 u32 gadget_SearchInWindow(u32 firsttag, ...)
01417 {
01418   return(gadget_SearchInWindowTL((tag *)&firsttag));
01419 }
01420 u32 gadget_SearchInWindowTL(tag *taglist)
01421 {
01422   Window_t *window;
01423   u32 gadget_id;
01424 
01425   u32 ret;
01426 
01427   debug_Begin();
01428 
01429   window=(Window_t *)tag_GetTagData(taglist,TAG_GADGET_WINDOW,0L);
01430   gadget_id=(u32 )tag_GetTagData(taglist,TAG_GADGET_GADGET_ID,0L);
01431 
01432   ret=gadget_Search(TAG_GADGET_ROOT,window_GetRootGadget(window),TAG_GADGET_GADGET_ID,gadget_id,TAG_DONE);
01433 
01434   debug_End();
01435 
01436   return((u32)ret);
01437 }
01438 
01439 
01446 u32 gadget_RenderCustom(u32 firsttag, ...)
01447 {
01448   return(gadget_RenderCustomTL((tag *)&firsttag));
01449 }
01450 u32 gadget_RenderCustomTL(tag *taglist)
01451 {
01452   Gadget_t *this;
01453   Rect_t *rect;
01454   int custom;
01455   int flags;
01456 
01457   int ret=-1;
01458   Rect_t inner;
01459   tag intaglist[]=
01460   {
01461     {TAG_GAD_RECT, 0L},
01462     {TAG_DONE,0L}
01463   };
01464 
01465 
01466   debug_Begin();
01467 
01468   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01469   rect=(Rect_t *)tag_GetTagData(taglist,TAG_GADGET_RECT,0L);
01470   custom=(int )tag_GetTagData(taglist,TAG_GADGET_CUSTOM,0L);
01471   flags=(int )tag_GetTagData(taglist,TAG_GADGET_FLAGS,0L);
01472 
01473   if(this!=NULL)
01474   {
01475     if((flags&GADGET_CUS_BACKGROUND)!=0) skin_RenderBackground(window_GetSkin(this->window),this,&this->rect,this->state);
01476     if((flags&GADGET_CUS_LAYOUT)!=0)
01477     {
01478       skin_GetInnerRect(window_GetSkin(this->window),this,rect,&inner);
01479       intaglist[0].Data=(u32)&inner;
01480       this->class_data->gadget_event_handler(this,GADEV_LAYOUT,intaglist);
01481     }
01482     skin_RenderCustom(window_GetSkin(this->window),this,rect,custom);
01483     if((flags&GADGET_CUS_REFRESH)!=0) glw_RefreshWindowPartial(TAG_GLW_WINDOW,this->window->handle,TAG_GLW_RECT,&this->rect,TAG_DONE);
01484     ret=0;
01485   }
01486 
01487   debug_End();
01488 
01489   return((u32)ret);
01490 }
01491 
01492 
01496 u32 gadget_Refresh(u32 firsttag, ...)
01497 {
01498   return(gadget_RefreshTL((tag *)&firsttag));
01499 }
01500 u32 gadget_RefreshTL(tag *taglist)
01501 {
01502   Gadget_t *gad;
01503 
01504 
01505   debug_Begin();
01506 
01507   gad=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01508 
01509   if(gad!=NULL)
01510   {
01511     if((gad->flags&GAD_ONSCREEN)!=0) gadget_Layout(TAG_GADGET_OBJECT,gad,TAG_GADGET_RECT,&gad->rect,TAG_DONE);
01512     glw_RefreshWindowPartial(TAG_GLW_WINDOW,gad->window->handle,TAG_GLW_RECT,&gad->rect,TAG_DONE);
01513   }
01514 
01515   debug_End();
01516   return(0L);
01517 }
01518 
01519 
01524 u32 gadget_FindParent(u32 firsttag, ...)
01525 {
01526   return(gadget_FindParentTL((tag *)&firsttag));
01527 }
01528 u32 gadget_FindParentTL(tag *taglist)
01529 {
01530   Gadget_t *this;
01531   int class_id;
01532 
01533   Gadget_t *gad=NULL;
01534 
01535   debug_Begin();
01536 
01537   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01538   class_id=(int )tag_GetTagData(taglist,TAG_GADGET_CLASS_ID,0L);
01539 
01540   if(this!=NULL)
01541   {
01542     gad=(Gadget_t *)gadget_Father(TAG_GADGET_OBJECT,this,TAG_DONE);
01543   }
01544 
01545   debug_End();
01546 
01547   return((u32)gad);
01548 }
01549 
01550 
01555 u32 gadget_HideAll(u32 firsttag, ...)
01556 {
01557   return(gadget_HideAllTL((tag *)&firsttag));
01558 }
01559 u32 gadget_HideAllTL(tag *taglist)
01560 {
01561   Gadget_t *this;
01562   int hidden;
01563 
01564   Gadget_t *gad;
01565 
01566 
01567   debug_Begin();
01568 
01569   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01570   hidden=(int )tag_GetTagData(taglist,TAG_GADGET_HIDDEN,0L);
01571 
01572   if (this != NULL)
01573   {
01574     for(gad=(Gadget_t *)gadget_FirstNode(TAG_GADGET_ROOT,this,TAG_DONE);gad!=NULL;gad=(Gadget_t *)gadget_NextNode(TAG_GADGET_OBJECT,gad,TAG_GADGET_ROOT,this,TAG_DONE))
01575     {
01576       if(hidden)
01577       {
01578         gad->flags|=GAD_HIDDEN;
01579       }
01580       else
01581       {
01582         gad->flags&=~GAD_HIDDEN;
01583       }
01584     }
01585   }
01586 
01587   debug_End();
01588 
01589   return(0L);
01590 }
01591 
01592 
01596 u32 gadget_FindRightMost(u32 firsttag, ...)
01597 {
01598   return(gadget_FindRightMostTL((tag *)&firsttag));
01599 }
01600 u32 gadget_FindRightMostTL(tag *taglist)
01601 {
01602   Gadget_t *this;
01603 
01604   Gadget_t *ret=NULL;
01605 
01606 
01607   debug_Begin();
01608 
01609   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01610 
01611   if(ret!=NULL)
01612   {
01613     while(((Gadget_t *)gadget_LastChild(TAG_GADGET_OBJECT,ret,TAG_DONE))!=NULL)
01614     {
01615       ret=(Gadget_t *)gadget_LastChild(TAG_GADGET_OBJECT,ret,TAG_DONE);
01616     }
01617   }
01618 
01619   debug_End();
01620 
01621   return((u32)ret);
01622 }
01623 
01624 
01628 u32 gadget_GetHint(u32 firsttag, ...)
01629 {
01630   return(gadget_GetHintTL((tag *)&firsttag));
01631 }
01632 u32 gadget_GetHintTL(tag *taglist)
01633 {
01634   Gadget_t *this;
01635 
01636 
01637   debug_Begin();
01638 
01639   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01640 
01641   if (this != NULL)
01642   {
01643     return((u32)this->hint);
01644   }
01645   else
01646   {
01647     return(0L);
01648   }
01649 
01650   debug_End();
01651 }
01652 
01653 
01659 u32 gadget_GetExtent(u32 firsttag, ...)
01660 {
01661   return(gadget_GetExtentTL((tag *)&firsttag));
01662 }
01663 u32 gadget_GetExtentTL(tag *taglist)
01664 {
01665   Gadget_t *this;
01666   Extent_t *min;
01667   Extent_t *max;
01668 
01669   Extent_t gadmin,gadmax;
01670   tag intaglist[]=
01671   {
01672     {TAG_GAD_EXTMIN, 0L},
01673     {TAG_GAD_EXTMAX, 0L},
01674     {TAG_DONE,0L}
01675   };
01676 
01677 
01678   debug_Begin();
01679 
01680   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01681   min=(Extent_t *)tag_GetTagData(taglist,TAG_GADGET_MIN,0L);
01682   max=(Extent_t *)tag_GetTagData(taglist,TAG_GADGET_MAX,0L);
01683 
01684   if(this!=NULL)
01685   {
01686     intaglist[0].Data=(u32)&gadmin;
01687     intaglist[1].Data=(u32)&gadmax;
01688     this->class_data->gadget_event_handler(this,GADEV_GET_EXTENT,intaglist);
01689     debug_Message("  from gad:  min:%dx%d  max:%dx%d",gadmin.width,gadmin.height,gadmax.width,gadmax.height);
01690     skin_GetExtent(window_GetSkin(this->window),this,&gadmin,min);
01691     debug_Message("  from skin: min:%dx%d",min->width,min->height);
01692     skin_GetExtent(window_GetSkin(this->window),this,&gadmax,max);
01693     debug_Message("  from skin: max:%dx%d",max->width,max->height);
01694     if(this->layout_width>=0&&this->layout_width>=min->width&&this->layout_width<=max->width) min->width=max->width=this->layout_width;
01695     if(this->layout_height>=0&&this->layout_height>=min->height&&this->layout_height<=max->height) min->height=max->height=this->layout_height;
01696     if(this->layout==GADGET_LAYOUT_FIXED)
01697     {
01698       max->width=min->width;
01699       max->height=min->height;
01700     }
01701     debug_Message("  final:     min:%dx%d  max:%dx%d",min->width,min->height,max->width,max->height);
01702   }
01703 
01704   debug_End();
01705 
01706   return(0L);
01707 }
01708 
01709 
01714 u32 gadget_GetRect(u32 firsttag, ...)
01715 {
01716   return(gadget_GetRectTL((tag *)&firsttag));
01717 }
01718 u32 gadget_GetRectTL(tag *taglist)
01719 {
01720   Gadget_t *this;
01721   Rect_t *rect;
01722 
01723   int ret=-1;
01724 
01725 
01726   debug_Begin();
01727 
01728   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01729   rect=(Rect_t *)tag_GetTagData(taglist,TAG_GADGET_RECT,0L);
01730 
01731   if(this!=NULL)
01732   {
01733     skin_GetInnerRect(window_GetSkin(this->window),this,&this->rect,rect);
01734   }
01735 
01736   debug_End();
01737 
01738   return((u32)ret);
01739 }
01740 
01741 
01747 u32 gadget_Save(u32 firsttag, ...)
01748 {
01749   return(gadget_SaveTL((tag *)&firsttag));
01750 }
01751 u32 gadget_SaveTL(tag *taglist)
01752 {
01753   Gadget_t *this;
01754   u8 **mem;
01755   int *size;
01756 
01757   int ret=-1;
01758 
01759   debug_Begin();
01760 
01761   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01762   mem=(u8 **)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
01763   size=(int *)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
01764 
01765 //  printf("save event posting...\n");
01766   if(this!=NULL&&mem!=NULL&&size!=NULL)
01767   {
01768     ret=this->class_data->gadget_event_handler(this,GADEV_SAVE,taglist);
01769 //    printf("save event posted\n");
01770   }
01771 
01772   debug_End();
01773 
01774   return((u32)ret);
01775 }
01776 
01777 
01783 u32 gadget_Restore(u32 firsttag, ...)
01784 {
01785   return(gadget_RestoreTL((tag *)&firsttag));
01786 }
01787 u32 gadget_RestoreTL(tag *taglist)
01788 {
01789   Gadget_t *this;
01790   u8 *mem;
01791   int size;
01792 
01793   int ret=-1;
01794 
01795   debug_Begin();
01796 
01797   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01798   mem=(u8 *)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
01799   size=(int)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
01800 
01801   if(this!=NULL&&mem!=NULL&&size!=0)
01802   {
01803     ret=this->class_data->gadget_event_handler(this,GADEV_RESTORE,taglist);
01804   }
01805 
01806   debug_End();
01807 
01808   return((u32)ret);
01809 }
01810 
01811 
01816 u32 gadget_SuggestExtent(u32 firsttag, ...)
01817 {
01818   return(gadget_SuggestExtentTL((tag *)&firsttag));
01819 }
01820 u32 gadget_SuggestExtentTL(tag *taglist)
01821 {
01822   Gadget_t *this;
01823   Rect_t *rect;
01824 
01825   Rect_t inner,store;
01826   Extent_t ext,inn,min,max;
01827   tag taglist2[]=
01828   {
01829     {TAG_GAD_EXTMIN, 0L},
01830     {TAG_GAD_EXTMAX, 0L},
01831     {TAG_DONE,0L}
01832   };
01833   tag taglist1[]=
01834   {
01835     {TAG_GAD_RECT, 0L},
01836     {TAG_DONE,0L}
01837   };
01838 
01839   debug_Begin();
01840 
01841   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01842   rect=(Rect_t *)tag_GetTagData(taglist,TAG_GADGET_RECT,0L);
01843 
01844   if(this!=NULL)
01845   {
01846     debug_Message("BEG %lx [class=%s] (width=%d height=%d)",this->gadget_id,this->class_data->class_name,rect->width,rect->height);
01847     skin_GetInnerRect(window_GetSkin(this->window),this,rect,&inner);
01848     memcpy(&store,&inner,sizeof(Rect_t));
01849     taglist1[0].Data=(u32)&inner;
01850     this->class_data->gadget_event_handler(this,GADEV_SUGGEST_EXTENT,taglist1);
01851     if(this->layout==GADGET_LAYOUT_SQUARE&&inner.width!=inner.height)
01852     {
01853       taglist2[0].Data=(u32)&min;
01854       taglist2[1].Data=(u32)&max;
01855       this->class_data->gadget_event_handler(this,GADEV_GET_EXTENT,taglist2);
01856       inner.width=min(inner.width,inner.height);
01857       inner.height=min(inner.width,inner.height);
01858       if(inner.width<min.width) inner.width=min.width;
01859       if(inner.height<min.height) inner.height=min.height;
01860     }
01861     ext.width=inner.width;
01862     ext.height=inner.height;
01863     skin_GetExtent(window_GetSkin(this->window),this,&ext,&inn);
01864     if(store.width!=inner.width||store.height!=inner.height||this->layout==GADGET_LAYOUT_SQUARE)
01865     {
01866       rect->width=inn.width;
01867       rect->height=inn.height;
01868     }
01869     debug_Message("END %lx (w=%d, h=%d)",this->gadget_id,rect->width,rect->height);
01870   }
01871 
01872   debug_End();
01873   return(0L);
01874 }
01875 
01876 
01880 u32 gadget_DeleteGadget(u32 firsttag, ...)
01881 {
01882   return(gadget_DeleteGadgetTL((tag *)&firsttag));
01883 }
01884 u32 gadget_DeleteGadgetTL(tag *taglist)
01885 {
01886   Gadget_t *this;
01887 
01888 
01889   debug_Begin();
01890 
01891   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01892 
01893   if(this!=NULL)
01894   {
01895     this->class_data->gadget_event_handler(this,GADEV_DELETE_GADGET,NULL);
01896   }
01897 
01898   debug_End();
01899 
01900   return(0L);
01901 }
01902 
01903 
01908 u32 gadget_InitGadget(u32 firsttag, ...)
01909 {
01910   return(gadget_InitGadgetTL((tag *)&firsttag));
01911 }
01912 u32 gadget_InitGadgetTL(tag *taglist)
01913 {
01914   Gadget_t *this;
01915   tag *intaglist;
01916 
01917   int ret=0;
01918 
01919 
01920   debug_Begin();
01921 
01922   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01923   intaglist=(tag *)tag_GetTagData(taglist,TAG_GADGET_TAGLIST,0L);
01924 
01925   if(this!=NULL)
01926   {
01927     ret=this->class_data->gadget_event_handler(this,GADEV_INIT_GADGET,intaglist);
01928   }
01929 
01930   debug_End();
01931 
01932   return((u32)ret);
01933 }
01934 
01935 
01940 u32 gadget_InputEventHandler(u32 firsttag, ...)
01941 {
01942   return(gadget_InputEventHandlerTL((tag *)&firsttag));
01943 }
01944 u32 gadget_InputEventHandlerTL(tag *taglist)
01945 {
01946   Gadget_t *this;
01947   struct glw_Event *event;
01948 
01949   int ret=-1;
01950 
01951   debug_Begin();
01952 
01953   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01954   event=(struct glw_Event *)tag_GetTagData(taglist,TAG_GADGET_EVENT,0L);
01955 
01956   if(this!=NULL&&this->class_data->input_event_handler!=NULL)
01957   {
01958     ret=this->class_data->input_event_handler(this,event);
01959   }
01960 
01961   debug_End();
01962 
01963   return((u32)ret);
01964 }
01965 
01966 
01971 u32 gadget_Layout(u32 firsttag, ...)
01972 {
01973   return(gadget_LayoutTL((tag *)&firsttag));
01974 }
01975 u32 gadget_LayoutTL(tag *taglist)
01976 {
01977   Gadget_t *this;
01978   Rect_t *rect;
01979 
01980   Rect_t inner;
01981   tag intaglist[]=
01982   {
01983     {TAG_GAD_RECT, 0L},
01984     {TAG_DONE,0L}
01985   };
01986 
01987 
01988   debug_Begin();
01989 
01990   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
01991   rect=(Rect_t *)tag_GetTagData(taglist,TAG_GADGET_RECT,0L);
01992 
01993   if(this!=NULL&&rect!=NULL)
01994   {
01995     debug_Message("gadget_id: 0x%08lx",this->gadget_id);
01996     memmove(&this->rect,rect,sizeof(Rect_t));
01997     skin_RenderBehind(window_GetSkin(this->window),this,rect,this->state);
01998     skin_GetInnerRect(window_GetSkin(this->window),this,rect,&inner);
01999     intaglist[0].Data=(u32)&inner;
02000     this->class_data->gadget_event_handler(this,GADEV_LAYOUT,intaglist);
02001     skin_RenderOver(window_GetSkin(this->window),this,rect,this->state);
02002     this->flags|=GAD_ONSCREEN;
02003   }
02004 
02005   debug_End();
02006 
02007   return(0L);
02008 }
02009 
02010 
02015 u32 gadget_Damage(u32 firsttag, ...)
02016 {
02017   return(gadget_DamageTL((tag *)&firsttag));
02018 }
02019 u32 gadget_DamageTL(tag *taglist)
02020 {
02021   Gadget_t *this;
02022   Rect_t *rect;
02023 
02024   tag intaglist[]=
02025   {
02026     {TAG_GAD_RECT, 0L},
02027     {TAG_DONE,0L}
02028   };
02029 
02030 
02031   debug_Begin();
02032 
02033   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
02034   rect=(Rect_t *)tag_GetTagData(taglist,TAG_GADGET_RECT,0L);
02035 
02036   intaglist[0].Data=(u32)rect;
02037   this->class_data->gadget_event_handler(this,GADEV_DAMAGE,intaglist);
02038 
02039   debug_End();
02040   return(0L);
02041 }
02042 
02043 
02049 u32 gadget_CallBack(u32 firsttag, ...)
02050 {
02051   return(gadget_CallBackTL((tag *)&firsttag));
02052 }
02053 u32 gadget_CallBackTL(tag *taglist)
02054 {
02055   Gadget_t *this;
02056   int event;
02057   u32 event_data;
02058 
02059   Gadget_t *receiver=NULL, *last;
02060   Window_t *win;
02061   int ret=0;
02062 
02063   debug_Begin();
02064 
02065   this=(Gadget_t *)tag_GetTagData(taglist,TAG_GADGET_OBJECT,0L);
02066   event=(int )tag_GetTagData(taglist,TAG_GADGET_EVENT,0L);
02067   event_data=(u32 )tag_GetTagData(taglist,TAG_GADGET_EVENT_DATA,0L);
02068 
02069   if((this->callback_discard_mask&event)==0)
02070   {
02071     last=this;
02072     if(this!=NULL&&this->gadget_id<GADGET_NOID)
02073     {
02074       for(receiver=(Gadget_t *)gadget_Father(TAG_GADGET_OBJECT,this,TAG_DONE); receiver!=NULL && receiver->class_data->event_handler==NULL; receiver=(Gadget_t *)gadget_Father(TAG_GADGET_OBJECT,receiver,TAG_DONE)) last=receiver;
02075         if(receiver!=NULL)
02076       {
02077         ret=receiver->class_data->event_handler(receiver, this, event, event_data);
02078       }
02079       else
02080       {
02081         win=last->window;
02082         if(win!=NULL) ret=window_WindowEvent(win,this->gadget_id,event,event_data);
02083       }
02084     }
02085   }
02086 
02087   debug_End();
02088 
02089   return((u32)ret);
02090 }
02091 
02092 
02093 /*
02094  *  Returns a unique ID which should be used by subgadgets.
02095  */
02096 u32 gadget_GetUniqueIdTL(tag *taglist)
02097 {
02098   return(gadget_GetUniqueId());
02099 }
02100 u32 gadget_GetUniqueId(void)
02101 {
02102   static int unique_id = 0x9000;
02103 
02104   debug_Begin();
02105 
02106   if (unique_id == 0x10000)
02107   {
02108     unique_id = 0x9000;
02109   }
02110 
02111   debug_End();
02112 
02113   return(unique_id++);
02114 }
02115 
02116 
02117 //END//
02118 
02119 
02120 void gadget_SetDiscardMask(Gadget_t *this, u32 add_event, u32 remove_event)
02121 {
02122   debug_Begin();
02123 
02124   if(this!=NULL)
02125   {
02126     this->callback_discard_mask|=add_event;
02127     this->callback_discard_mask&=~remove_event;
02128   }
02129 
02130   debug_End();
02131 }
02132 
02133 
02134 int gadget_ChangeSkin(Gadget_t *this, Skin_t *skin)
02135 {
02136   int ret=-1;
02137   Node_t *node;
02138   gadget_ClassData_t *classdata=NULL;
02139   Gadget_t *gad;
02140 
02141   debug_Begin();
02142 
02143   if(this!=NULL&&skin!=NULL&&class_list!=NULL)
02144   {
02145     for(node=list_GetNodeHead(class_list);node!=NULL;node=list_GetNodeNext(class_list,node))
02146     {
02147       classdata=(gadget_ClassData_t *)list_GetNodeData(node);
02148       skin_LoadSkin(skin,classdata->class_name);
02149     }
02150     for(gad=(Gadget_t *)gadget_FirstNode(TAG_GADGET_ROOT,this,TAG_DONE);gad!=NULL;gad=(Gadget_t *)gadget_NextNode(TAG_GADGET_OBJECT,gad,TAG_GADGET_ROOT,this,TAG_DONE))
02151     {
02152       if(gad->class_data->class_name[0]=='G'&&strcmp(gad->class_data->class_name,"Group")==0) gadget_MethodCall(TAG_GADGET_OBJECT,gad,TAG_GADGET_METHOD,MET_GROUP_INVALIDATE_SIZE,TAG_DONE);
02153       if((gad->class_data->flags&GAD_INVISIBLE)!=0) continue;
02154       debug_Message("  %04lx - %s\n",gad->gadget_id,gad->class_data->class_name);
02155 //      gadget_SetFont(gad,descriptor->taglist);
02156       gadget_InitColorTable(gad);
02157       skin_FillGadgetInfo(skin,gad);
02158     }
02159   }
02160 
02161   debug_End();
02162 
02163   return(ret);
02164 }
02165 
02166 
02167 u32 gadget_Call(int function, u32 firsttag, ...)
02168 {
02169   return(gadget_CallTL(function,(tag *)&firsttag));
02170 }
02171 u32 gadget_CallTL(int function, tag *taglist)
02172 {
02173   u32 ret=~0L;
02174 
02175   debug_Begin();
02176 
02177   if(function>=GADGET_FUNCBASE&&function<GADGET_FUNC_DONE)
02178   {
02179     ret=call_vector[function-GADGET_FUNCBASE](taglist);
02180   }
02181   else debug_Warning("%s(): Function code out of range! code=0x%04x",__FUNCTION__,function);
02182 
02183   debug_End();
02184 
02185   return(ret);
02186 }
02187 
02188 

Generated on Tue Jan 7 12:11:19 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002