00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025 #include <string.h>
00026
00027 #define __SKIN_MODULE
00028
00029 #include "debug.h"
00030 #include "Memory.h"
00031 #include "Net.h"
00032 #include "Common.h"
00033 #include "Crc.h"
00034 #include "Skin.h"
00035 #include "Image.h"
00036 #include "Gadget.h"
00037
00038
00039
00040 struct skin_Class_s
00041 {
00042 char *name;
00043 int counter;
00044 u32 module;
00045 Node_t *node;
00046 Skin_t *(*CreateSkin)(gui_App_t *app, char *path);
00047 void (*DeleteSkin)(Skin_t *skin);
00048 int (*RenderBehind)(Skin_t *skin, Gadget_t *gad, Rect_t *rect, u32 state);
00049 int (*RenderOver)(Skin_t *skin, Gadget_t *gad, Rect_t *rect, u32 state);
00050 int (*RenderBackground)(Skin_t *skin, Gadget_t *gad, Rect_t *rect, u32 state);
00051 int (*RenderCustom)(Skin_t *skin, Gadget_t *gad, Rect_t *rect, int custom);
00052 int (*GetExtent)(Skin_t *skin, Gadget_t *gad, Extent_t *ext, Extent_t *outer);
00053 int (*GetInnerRect)(Skin_t *skin, Gadget_t *gad, Rect_t *rect, Rect_t *inner);
00054 int (*FillColorTable)(Skin_t *skin, Gadget_t *gad, int state);
00055 int (*FillGadgetInfo)(Skin_t *skin, Gadget_t *gad);
00056 u32 (*GetFont)(Skin_t *skin, Gadget_t *gad);
00057 int (*LoadSkin)(Skin_t *skin, char *gadget_class);
00058 int (*UnloadSkin)(Skin_t *skin, u32 class_id);
00059 u32 (*GetCustomTaglist)(Skin_t *skin, Gadget_t *gad);
00060 };
00061
00062
00063 static u32 (*call_vector[SKIN_FUNC_DONE-SKIN_FUNCBASE+1])(tag *);
00064
00065 static List_t *skinclasslist=NULL;
00066
00067
00086 u32 skin_RegisterSkin(u32 firsttag, ...)
00087 {
00088 return(skin_RegisterSkinTL((tag *)&firsttag));
00089 }
00090 u32 skin_RegisterSkinTL(tag *taglist)
00091 {
00092 char *name;
00093 u32 module;
00094 Skin_t *(*CreateSkin)(gui_App_t *,char *);
00095 void (*DeleteSkin)(Skin_t *);
00096 int (*RenderBehind)(Skin_t *,Gadget_t *,Rect_t *,u32);
00097 int (*RenderOver)(Skin_t *,Gadget_t *,Rect_t *,u32);
00098 int (*RenderBackground)(Skin_t *,Gadget_t *,Rect_t *,u32);
00099 int (*RenderCustom)(Skin_t *,Gadget_t *,Rect_t *,int);
00100 int (*GetExtent)(Skin_t *,Gadget_t *,Extent_t *,Extent_t *);
00101 int (*GetInnerRect)(Skin_t *,Gadget_t *,Rect_t *,Rect_t *);
00102 int (*FillColorTable)(Skin_t *,Gadget_t *,int);
00103 int (*FillGadgetInfo)(Skin_t *,Gadget_t *);
00104 u32 (*GetFont)(Skin_t *,Gadget_t *);
00105 int (*LoadSkin)(Skin_t *,char *);
00106 int (*UnloadSkin)(Skin_t *,u32);
00107 u32 (*GetCustomTaglist)(Skin_t *skin, Gadget_t *gad);
00108
00109 int ret=-1;
00110 Node_t *node;
00111 skin_Class_t *skinclass;
00112
00113 debug_Begin();
00114
00115 name=(char *)tag_GetTagData(taglist,TAG_SKIN_NAME,0L);
00116 module=(u32)tag_GetTagData(taglist,TAG_SKIN_MODULE,0L);
00117 CreateSkin=(Skin_t *(*)(gui_App_t *,char *))tag_GetTagData(taglist,TAG_SKIN_CREATESKIN,0L);
00118 DeleteSkin=(void (*)(Skin_t *))tag_GetTagData(taglist,TAG_SKIN_DELETESKIN,0L);
00119 RenderBehind=(int (*)(Skin_t *,Gadget_t *,Rect_t *,u32))tag_GetTagData(taglist,TAG_SKIN_RENDERBEHIND,0L);
00120 RenderOver=(int (*)(Skin_t *,Gadget_t *,Rect_t *,u32))tag_GetTagData(taglist,TAG_SKIN_RENDEROVER,0L);
00121 RenderBackground=(int (*)(Skin_t *,Gadget_t *,Rect_t *,u32))tag_GetTagData(taglist,TAG_SKIN_RENDERBACKGROUND,0L);
00122 RenderCustom=(int (*)(Skin_t *,Gadget_t *,Rect_t *,int))tag_GetTagData(taglist,TAG_SKIN_RENDERCUSTOM,0L);
00123 GetExtent=(int (*)(Skin_t *,Gadget_t *,Extent_t *,Extent_t *))tag_GetTagData(taglist,TAG_SKIN_GETEXTENT,0L);
00124 GetInnerRect=(int (*)(Skin_t *,Gadget_t *,Rect_t *,Rect_t *))tag_GetTagData(taglist,TAG_SKIN_GETINNERRECT,0L);
00125 FillColorTable=(int (*)(Skin_t *,Gadget_t *,int))tag_GetTagData(taglist,TAG_SKIN_FILLCOLORTABLE,0L);
00126 FillGadgetInfo=(int (*)(Skin_t *,Gadget_t *))tag_GetTagData(taglist,TAG_SKIN_FILLGADGETINFO,0L);
00127 GetFont=(u32 (*)(Skin_t *,Gadget_t *))tag_GetTagData(taglist,TAG_SKIN_GETFONT,0L);
00128 LoadSkin=(int (*)(Skin_t *,char *))tag_GetTagData(taglist,TAG_SKIN_LOADSKIN,0L);
00129 UnloadSkin=(int (*)(Skin_t *,u32))tag_GetTagData(taglist,TAG_SKIN_UNLOADSKIN,0L);
00130 GetCustomTaglist=(u32 (*)(Skin_t *, Gadget_t *))tag_GetTagData(taglist,TAG_SKIN_GETCUSTOMTAGLIST,0L);
00131
00132 if(CreateSkin!=NULL&&name!=NULL&&NULL!=(skinclass=mem_calloc(1,sizeof(skin_Class_t))))
00133 {
00134 if(NULL!=(node=list_CreateNode()))
00135 {
00136 skinclass->name=common_strdup(name);
00137 skinclass->counter=0;
00138 skinclass->node=node;
00139 skinclass->module=module;
00140 skinclass->CreateSkin=CreateSkin;
00141 skinclass->DeleteSkin=DeleteSkin;
00142 skinclass->RenderBehind=RenderBehind;
00143 skinclass->RenderOver=RenderOver;
00144 skinclass->RenderBackground=RenderBackground;
00145 skinclass->RenderCustom=RenderCustom;
00146 skinclass->GetExtent=GetExtent;
00147 skinclass->GetInnerRect=GetInnerRect;
00148 skinclass->FillColorTable=FillColorTable;
00149 skinclass->FillGadgetInfo=FillGadgetInfo;
00150 skinclass->GetFont=GetFont;
00151 skinclass->LoadSkin=LoadSkin;
00152 skinclass->UnloadSkin=UnloadSkin;
00153 skinclass->GetCustomTaglist=GetCustomTaglist;
00154 list_SetNodeData(node,skinclass);
00155 list_InsertNodeTail(skinclasslist,node);
00156 ret=0;
00157 }
00158 }
00159
00160 debug_End();
00161
00162 return((u32)ret);
00163 }
00164
00165
00166 int skin_Init(void)
00167 {
00168 int ret=-1;
00169
00170 debug_Begin();
00171
00172 call_vector[SKIN_REGISTERSKIN-SKIN_FUNCBASE]=skin_RegisterSkinTL;
00173 bases_modules.skin_Call=skin_Call;
00174 bases_modules.skin_CallTL=skin_CallTL;
00175
00176 if(NULL!=(skinclasslist=list_CreateList()))
00177 {
00178 ret=0;
00179 }
00180
00181 debug_End();
00182
00183 return(ret);
00184 }
00185
00186
00187 void skin_CleanUp(void)
00188 {
00189 Node_t *node;
00190
00191 debug_Begin();
00192
00193 if(skinclasslist!=NULL)
00194 {
00195 while(NULL!=(node=list_RemoveNodeHead(skinclasslist)))
00196 {
00197 skin_Class_t *skinclass;
00198 if(NULL!=(skinclass=(skin_Class_t *)list_GetNodeData(node)))
00199 {
00200 glw_CloseModule(skinclass->module);
00201 if(skinclass->name!=NULL) mem_free(skinclass->name);
00202 mem_free(skinclass);
00203 }
00204 list_DeleteNode(node);
00205 }
00206 list_DeleteList(skinclasslist);
00207 }
00208
00209 debug_End();
00210 }
00211
00212
00213 Skin_t *skin_CreateSkin(gui_App_t *app, char *skinname)
00214 {
00215 Skin_t *ret=NULL;
00216
00217 debug_Begin();
00218
00219 if(skinname!=NULL)
00220 {
00221 char *skinpath;
00222 if(NULL!=(skinpath=mem_malloc(strlen(skinname)+2)))
00223 {
00224 char *fnam;
00225 strcpy(skinpath,skinname);
00226 strcat(skinpath,"/");
00227 if(NULL!=(fnam=mem_malloc(strlen(skinpath)+4)))
00228 {
00229 int fsiz;
00230 char *id;
00231 strcpy(fnam,skinpath);
00232 strcat(fnam,"_ID");
00233 if(NULL!=(id=(char *)net_LoadFile(TAG_NET_CONN,app->conn,TAG_NET_NAME,fnam,TAG_NET_LEN,&fsiz,TAG_DONE)))
00234 {
00235 int i;
00236 char *classname;
00237 for(i=0;i<fsiz;i++) if(((unsigned char)id[i])<32||((unsigned char)id[i])>127) id[i]='\0';
00238 if(NULL!=(classname=mem_calloc(1,fsiz+1)))
00239 {
00240 Node_t *node;
00241 skin_Class_t *skinclass=NULL;
00242 memcpy(classname,id,fsiz);
00243 for(node=list_GetNodeHead(skinclasslist);node!=NULL;node=list_GetNodeNext(skinclasslist,node))
00244 {
00245 if(NULL!=(skinclass=(skin_Class_t *)list_GetNodeData(node)))
00246 {
00247 if(strcmp(skinclass->name,classname)==0) break;
00248 skinclass=NULL;
00249 }
00250 }
00251 if(skinclass==NULL)
00252 {
00253 char *name;
00254
00255 if(NULL!=(name=mem_malloc(strlen(classname)+1+5+6)))
00256 {
00257 strcpy(name,"skins/");
00258 strcat(name,classname);
00259 strcat(name,".skin");
00260
00261 if(0L==(glw_OpenModule(name)))
00262 {
00263 u8 *skinfile;
00264 int slen;
00265 FILE *f;
00266 if(NULL!=(skinfile=(u8 *)net_LoadFile(TAG_NET_CONN,app->conn,TAG_NET_NAME,name,TAG_NET_LEN,&slen,TAG_DONE)))
00267 {
00268 if(NULL!=(f=fopen(name,"wb")))
00269 {
00270 fwrite(skinfile,1,slen,f);
00271 fclose(f);
00272 }
00273 mem_free(skinfile);
00274 if(0L!=glw_OpenModule(name)) debug_Warning("Cannot open downloaded module '%s'!",name);
00275 }
00276 else debug_Warning("Cannot find module '%s'!",name);
00277 }
00278 mem_free(name);
00279 for(node=list_GetNodeHead(skinclasslist);node!=NULL;node=list_GetNodeNext(skinclasslist,node))
00280 {
00281 if(NULL!=(skinclass=(skin_Class_t *)list_GetNodeData(node)))
00282 {
00283 if(strcmp(skinclass->name,classname)==0) break;
00284 skinclass=NULL;
00285 }
00286 }
00287 }
00288
00289 }
00290 mem_free(classname);
00291 if(skinclass!=NULL&&NULL!=(ret=skinclass->CreateSkin(app,skinpath)))
00292 {
00293 skin_Common_t *common;
00294 common=(skin_Common_t *)ret;
00295 common->skinclass=skinclass;
00296 common->path=skinpath;
00297 skinclass->counter++;
00298 }
00299 }
00300 mem_free(id);
00301 }
00302 mem_free(fnam);
00303 }
00304 }
00305 }
00306 if(ret==NULL) debug_Error("cannot create skin");
00307
00308 debug_End();
00309
00310 return(ret);
00311 }
00312
00313
00314 void skin_DeleteSkin(Skin_t *skin)
00315 {
00316 skin_Common_t *common;
00317 skin_Class_t *skinclass;
00318
00319 debug_Begin();
00320
00321 common=(skin_Common_t *)skin;
00322 if(skin!=NULL)
00323 {
00324 skinclass=common->skinclass;
00325 if(common->path!=NULL) mem_free(common->path);
00326 common->path=NULL;
00327 skinclass->DeleteSkin(skin);
00328
00329 skinclass->counter--;
00330 if(skinclass->counter==0&&skinclass->module!=0L)
00331 {
00332 list_RemoveNode(skinclasslist,skinclass->node);
00333 glw_CloseModule(skinclass->module);
00334 if(skinclass->name!=NULL) mem_free(skinclass->name);
00335 list_DeleteNode(skinclass->node);
00336 mem_free(skinclass);
00337 }
00338 }
00339
00340
00341 debug_End();
00342 }
00343
00344
00345
00346
00347 int skin_RenderBackground(Skin_t *skin, Gadget_t *gad, Rect_t *rect, u32 state)
00348 {
00349 int ret=-1;
00350 skin_Common_t *common=(skin_Common_t *)skin;
00351
00352 debug_Begin();
00353
00354 if(skin!=NULL&&gad!=NULL&&rect!=NULL)
00355 {
00356 ret=common->skinclass->RenderBackground(skin,gad,rect,state);
00357 }
00358
00359 debug_End();
00360
00361 return(ret);
00362 }
00363
00364
00365 int skin_RenderBehind(Skin_t *skin, Gadget_t *gad, Rect_t *rect, u32 state)
00366 {
00367 int ret=-1;
00368 skin_Common_t *common=(skin_Common_t *)skin;
00369
00370 debug_Begin();
00371
00372 if(skin!=NULL&&gad!=NULL&&rect!=NULL)
00373 {
00374 ret=common->skinclass->RenderBehind(skin,gad,rect,state);
00375 }
00376
00377 debug_End();
00378
00379 return(ret);
00380 }
00381
00382
00383 int skin_RenderOver(Skin_t *skin, Gadget_t *gad, Rect_t *rect, u32 state)
00384 {
00385 int ret=-1;
00386 skin_Common_t *common=(skin_Common_t *)skin;
00387
00388 debug_Begin();
00389
00390 if(skin!=NULL&&gad!=NULL&&rect!=NULL)
00391 {
00392 ret=common->skinclass->RenderOver(skin,gad,rect,state);
00393 }
00394
00395 debug_End();
00396
00397 return(ret);
00398 }
00399
00400
00401 int skin_RenderCustom(Skin_t *skin, Gadget_t *gad, Rect_t *rect, int custom)
00402 {
00403 int ret=-1;
00404 skin_Common_t *common=(skin_Common_t *)skin;
00405
00406 debug_Begin();
00407
00408 if(skin!=NULL&&gad!=NULL&&rect!=NULL)
00409 {
00410 ret=common->skinclass->RenderCustom(skin,gad,rect,custom);
00411 }
00412
00413 debug_End();
00414
00415 return(ret);
00416 }
00417
00418
00419 int skin_GetExtent(Skin_t *skin, Gadget_t *gad, Extent_t *ext, Extent_t *outer)
00420 {
00421 int ret=-1;
00422 skin_Common_t *common=(skin_Common_t *)skin;
00423
00424 debug_Begin();
00425
00426 if(skin!=NULL&&gad!=NULL&&ext!=NULL&&outer!=NULL)
00427 {
00428 ret=common->skinclass->GetExtent(skin,gad,ext,outer);
00429 }
00430
00431 debug_End();
00432
00433 return(ret);
00434 }
00435
00436
00437 int skin_GetInnerRect(Skin_t *skin, Gadget_t *gad, Rect_t *rect, Rect_t *inner)
00438 {
00439 int ret=-1;
00440 skin_Common_t *common=(skin_Common_t *)skin;
00441
00442 debug_Begin();
00443
00444 if(skin!=NULL&&gad!=NULL&&rect!=NULL&&inner!=NULL)
00445 {
00446 ret=common->skinclass->GetInnerRect(skin,gad,rect,inner);
00447 }
00448
00449 debug_End();
00450
00451 return(ret);
00452 }
00453
00454
00455 int skin_FillGadgetInfo(Skin_t *skin, Gadget_t *gad)
00456 {
00457 int ret=-1;
00458 skin_Common_t *common=(skin_Common_t *)skin;
00459
00460 debug_Begin();
00461
00462 if(skin!=NULL&&gad!=NULL)
00463 {
00464 ret=common->skinclass->FillGadgetInfo(skin,gad);
00465 }
00466
00467 debug_End();
00468
00469 return(ret);
00470 }
00471
00472
00473 int skin_FillColorTable(Skin_t *skin, Gadget_t *gad, int state)
00474 {
00475 int ret=-1;
00476 skin_Common_t *common=(skin_Common_t *)skin;
00477
00478 debug_Begin();
00479
00480 if(skin!=NULL&&gad!=NULL)
00481 {
00482 ret=common->skinclass->FillColorTable(skin,gad,state);
00483 }
00484
00485 debug_End();
00486
00487 return(ret);
00488 }
00489
00490
00491 int skin_GetFont(Skin_t *skin, Gadget_t *gad)
00492 {
00493 int ret=-1;
00494 skin_Common_t *common=(skin_Common_t *)skin;
00495
00496 debug_Begin();
00497
00498 if(skin!=NULL&&gad!=NULL)
00499 {
00500 ret=common->skinclass->GetFont(skin,gad);
00501 }
00502
00503 debug_End();
00504
00505 return(ret);
00506 }
00507
00508
00509 int skin_LoadSkin(Skin_t *skin, char *class)
00510 {
00511 int ret=-1;
00512 skin_Common_t *common=(skin_Common_t *)skin;
00513
00514 debug_Begin();
00515
00516 if(skin!=NULL&&class!=NULL)
00517 {
00518 ret=common->skinclass->LoadSkin(skin,class);
00519 }
00520
00521 debug_End();
00522
00523 return(ret);
00524 }
00525
00526
00527 int skin_UnloadSkin(Skin_t *skin, u32 class_id)
00528 {
00529 int ret=-1;
00530 skin_Common_t *common=(skin_Common_t *)skin;
00531
00532 debug_Begin();
00533
00534 if(skin!=NULL)
00535 {
00536 ret=common->skinclass->UnloadSkin(skin,class_id);
00537 }
00538
00539 debug_End();
00540
00541 return(ret);
00542 }
00543
00544
00545 tag *skin_GetCustomTaglist(Skin_t *skin, Gadget_t *gad)
00546 {
00547 tag *ret=NULL;
00548 skin_Common_t *common=(skin_Common_t *)skin;
00549
00550 debug_Begin();
00551
00552 if(skin!=NULL&&gad!=NULL)
00553 {
00554 ret=(tag *)common->skinclass->GetCustomTaglist(skin,gad);
00555 }
00556
00557 debug_End();
00558
00559 return(ret);
00560 }
00561
00562
00563 char *skin_GetWindowDecorationName(Skin_t *skin)
00564 {
00565 char *ret=NULL;
00566 char name[]="WindowDecoration.xml";
00567 skin_Common_t *common=(skin_Common_t *)skin;
00568
00569 debug_Begin();
00570
00571 if(skin!=NULL)
00572 {
00573 if(NULL!=(ret=mem_malloc(strlen(common->path)+sizeof(name)+1)))
00574 {
00575 strcpy(ret,common->path);
00576 strcat(ret,name);
00577 }
00578 }
00579
00580 debug_End();
00581
00582 return(ret);
00583 }
00584
00585
00586 u32 skin_Call(int function, u32 firsttag, ...)
00587 {
00588 return(skin_CallTL(function,(tag *)&firsttag));
00589 }
00590 u32 skin_CallTL(int function, tag *taglist)
00591 {
00592 u32 ret=~0L;
00593
00594 debug_Begin();
00595
00596 debug_Message("%s() function ID : %d",__FUNCTION__,function-SKIN_FUNCBASE);
00597
00598 if(function>=SKIN_FUNCBASE&&function<SKIN_FUNC_DONE)
00599 {
00600 ret=call_vector[function-SKIN_FUNCBASE](taglist);
00601 }
00602 else debug_Warning("%s(): Function code out of range! code=0x%04x",__FUNCTION__,function);
00603
00604 debug_End();
00605
00606 return(ret);
00607 }