Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gadget_Icon.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  *  icon.c
00026  *
00027  *  Author            : Gergely Gáti
00028  *  Date              :
00029  *  Description       :
00030  *
00031  */
00032 #include <stdlib.h>
00033 
00034 #include "Window.h"
00035 #include "Bases.h"
00036 #include "Module.h"
00037 #include "Image.h"
00038 #include "debug.h"
00039 #include "classes.h"
00040 #include "Memory.h"
00041 #include "Common.h"
00042 #include "gadgets/gadget_Icon.h"
00043 
00044 
00045 struct _icon
00046 {
00047   Gadget_t gadget;
00048   Image_t *img;
00049 //  u8 *buff;
00050 //  int buffsize;
00051 };
00052 
00053 
00054 static u32 icon_set_image(Gadget_t *this_gadget, tag *taglist);
00055 
00056 
00057 static bases_Modules_t *api;
00058 VERSION("Icon.gadget",1,0,"Gergely Gati","g.gati@freemail.hu");
00059 
00060 static gadget_Method_t methods[]=
00061 {
00062   {"set_image",icon_set_image,0L},
00063   GADGET_METHOD_DONE
00064 };
00065 
00066 
00067 static gadget_Binding_t binding[]=
00068 {
00069   {"image",TAG_ICO_IMAGENAME,GADGET_STRING,""},
00070   GADGET_BINDING_DONE
00071 };
00072 
00073 
00074 
00075 /*
00076  *  This function is always called after the Gadget_t has been created and
00077  *  attached to the Gadget_t tree, but before the call to icon_layout(). It may be
00078  *  called more than once. It must fill in the Gadget_t's minimum and maximum
00079  *  sizes into the supplied extent structures.
00080  */
00081 static void icon_get_extent(Gadget_t *this, Extent_t *min, Extent_t *max)
00082 {
00083   ImageInfo_t imginfo;
00084 
00085   debug_Begin();
00086 
00087   if(0==api->img_Call(IMG_GETINFO,TAG_IMG_OBJECT,((icon *)this)->img,TAG_IMG_IMGINFO,&imginfo,TAG_DONE))
00088   {
00089     min->width=imginfo.minwidth;
00090     min->height=imginfo.minheight;
00091     max->width=imginfo.maxwidth;
00092     max->height=imginfo.maxheight;
00093   }
00094   else
00095   {
00096     min->width=0;
00097     min->height=0;
00098     max->width=0;
00099     max->height=0;
00100   }
00101   debug_Message("gadget_id: 0x%08lx extent: %dx%d..%dx%d",this->gadget_id,min->width,min->height,max->width,max->height);
00102 
00103   debug_End();
00104 }
00105 
00106 
00107 /*
00108  *  This function is called always after icon_get_extent() has been called at
00109  *  least once. It receives a position and an extent which determine the
00110  *  position and the size of the Gadget_t on the screen. This extent is always
00111  *  between the minimum and maximum sizes which were returned by
00112  *  icon_get_extent() of the same gadget. After this call the Gadget_t is made
00113  *  visible.
00114  */
00115 static void icon_layout(Gadget_t *this, Rect_t *rect)
00116 {
00117 //  u8 *buff;
00118 //  int buffsize;
00119 
00120   debug_Begin();
00121 
00122   debug_Message("gadget_id: 0x%04x");
00123   api->img_Call(IMG_PUTIMAGE,TAG_IMG_OBJECT,((icon *)this)->img,TAG_IMG_WINDOW,this->window,TAG_IMG_RECT,rect,TAG_DONE);
00124 
00125 /*
00126   buffsize=(rect->width*rect->height*4)+1;
00127   if((buffsize>((icon *)this)->buffsize||buffsize<(((icon *)this)->buffsize>>1))&&NULL!=(buff=mem_malloc(buffsize)))
00128   {
00129     if(NULL!=((icon *)this)->buff) mem_free(((icon *)this)->buff);
00130     ((icon *)this)->buff=buff;
00131     ((icon *)this)->buffsize=buffsize;
00132   }
00133   if(((icon *)this)->buff!=NULL)
00134   {
00135     if(0==(img_RenderImage(((icon *)this)->img,((icon *)this)->buff,buffsize,rect->width,rect->height)))
00136     {
00137       glw_PutImage(this->window->handle,((icon *)this)->buff,rect,rect->left,rect->top,rect->width,rect->height);
00138     }
00139   }
00140 */
00141   debug_End();
00142 }
00143 
00144 
00145 #if 0
00146   static int icon_input_event_handler(Gadget_t *gad, struct glw_Event *event)
00147   {
00148     int ret=0;
00149 
00150     debug_Begin();
00151 
00152     debug_End();
00153 
00154     return(ret);
00155   }
00156 #endif
00157 
00158 
00159 static int icon_init_gadget(Gadget_t *this, tag *taglist)
00160 {
00161   int ret=-1;
00162   ImageIn_t *image;
00163   char *imagename;
00164 
00165   debug_Begin();
00166 
00167   if(this!=NULL)
00168   {
00169     ((icon *)this)->img=NULL;
00170 //    ((icon *)this)->buff=NULL;
00171 //    ((icon *)this)->buffsize=0;
00172     imagename=(char *)tag_GetTagData(taglist,TAG_ICO_IMAGENAME,(u32)0L);
00173     image=(ImageIn_t *)tag_GetTagData(taglist,TAG_ICO_IMAGEIN,0L);
00174     ((icon *)this)->img=(Image_t *)api->img_Call(IMG_INITIMAGE,TAG_IMG_APP,(u32)this->window->app,
00175                                       TAG_IMG_IMAGEIN,(u32)image,
00176                                       TAG_IMG_IMAGENAME,(u32)imagename,
00177                                       TAG_DONE);
00178     if(((icon *)this)->img!=NULL) ret=0;
00179   }
00180 
00181   debug_End();
00182 
00183   return(ret);
00184 }
00185 
00186 
00187 static void icon_delete_gadget(Gadget_t *this)
00188 {
00189   debug_Begin();
00190 
00191   if(((icon *)this)->img!=NULL) api->img_Call(IMG_CLEANUPIMAGE,TAG_IMG_OBJECT,((icon *)this)->img,TAG_DONE);
00192   ((icon *)this)->img=NULL;
00193 //  if(NULL!=((icon *)this)->buff) mem_free(((icon *)this)->buff);
00194 //  ((icon *)this)->buff=NULL;
00195 //  ((icon *)this)->buffsize=0;
00196 
00197   debug_End();
00198 }
00199 
00200 
00201 static int icon_gadget_event_handler(Gadget_t *this, int event, tag *taglist)
00202 {
00203   int ret=-1;
00204 
00205   debug_Begin();
00206 
00207   if(this!=NULL&&event>=0)
00208   {
00209     switch(event)
00210     {
00211       case GADEV_INIT_GADGET:
00212       {
00213         ret=icon_init_gadget(this,taglist);
00214         break;
00215       }
00216       case GADEV_DELETE_GADGET:
00217       {
00218         icon_delete_gadget(this);
00219         ret=0;
00220         break;
00221       }
00222       case GADEV_GET_EXTENT:
00223       {
00224         Extent_t *min,*max,n,x;
00225         min=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMIN,(u32)&n);
00226         max=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMAX,(u32)&x);
00227         icon_get_extent(this,min,max);
00228         ret=0;
00229         break;
00230       }
00231       case GADEV_LAYOUT:
00232       case GADEV_DAMAGE:
00233       {
00234         Rect_t *rect,r;
00235         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00236         icon_layout(this,rect);
00237         ret=0;
00238         break;
00239       }
00240       case GADEV_SAVE:
00241       {
00242         u8 **mem;
00243         int *size;
00244         ImageInfo_t imginfo;
00245         mem=(u8 **)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00246         size=(int *)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00247         // az image iim.data -jat kell lementeni
00248         if(0==(api->img_Call(IMG_GETINFO,TAG_IMG_OBJECT,((icon *)this)->img,TAG_IMG_IMGINFO,&imginfo,TAG_DONE)))
00249         {
00250           *size=imginfo.iim.data_size;
00251           if(NULL!=(*mem=mem_malloc(*size)))
00252           {
00253             memcpy(*mem,imginfo.iim.data,*size);
00254           }
00255           else *size=0;
00256         }
00257         else
00258         {
00259           *size=0;
00260           *mem=NULL;
00261         }
00262         break;
00263       }
00264       case GADEV_RESTORE:
00265       {
00266         u8 *mem;
00267         int size;
00268         ImageIn_t image;
00269         mem=(u8 *)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00270         size=(int)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00271         // az image iim.data -jat kapom meg, felmasolom egy sajat helyre es
00272         // initimage-el elkeszitem
00273         image.data_size=size;
00274         if(NULL!=(image.data=mem_malloc(size)))
00275         {
00276           memcpy(image.data,mem,size);
00277           if(((icon *)this)->img!=NULL) api->img_Call(IMG_CLEANUPIMAGE,TAG_IMG_OBJECT,((icon *)this)->img,TAG_DONE);
00278           ((icon *)this)->img=(Image_t *)api->img_Call(IMG_INITIMAGE,TAG_IMG_APP,this->window->app,TAG_IMG_IMAGEIN,(u32)&image,TAG_IMG_FREEAFTERUSE,1L,TAG_DONE);
00279         }
00280         break;
00281       }
00282     }
00283   }
00284 
00285   debug_End();
00286 
00287   return(ret);
00288 }
00289 
00290 
00291 // !!FIXME!!
00292 static u32 icon_set_image(Gadget_t *this_gadget, tag *taglist)
00293 {
00294   icon *this=(icon *)this_gadget;
00295   u32 ret=~0;
00296   ImageInfo_t imginfo;
00297   char *imagename;
00298   Image_t *img;
00299   Rect_t rect;
00300 
00301   debug_Begin();
00302 
00303   if(this!=NULL)
00304   {
00305     if(NULL!=(imagename=(char *)tag_GetTagData(taglist,TAG_ICO_IMAGENAME,0L)))
00306     {
00307       if(NULL!=(img=(Image_t *)api->img_Call(IMG_INITIMAGE,TAG_IMG_APP,(u32)this->gadget.window->app,TAG_IMG_IMAGENAME,(u32)imagename,TAG_DONE)))
00308       {
00309         if(0==(api->img_Call(IMG_GETINFO,TAG_IMG_OBJECT,img,TAG_IMG_IMGINFO,&imginfo,TAG_DONE)))
00310         {
00311           api->gadget_Call(GADGET_GET_RECT,TAG_GADGET_OBJECT,this_gadget,TAG_GADGET_RECT,&rect,TAG_DONE);
00312           if(imginfo.minwidth<=rect.width   &&
00313              imginfo.minheight<=rect.height &&
00314              imginfo.maxwidth>=rect.width   &&
00315              imginfo.maxheight>=rect.height)
00316           {
00317             if(this->img!=NULL) api->img_Call(IMG_CLEANUPIMAGE,TAG_IMG_OBJECT,this->img,TAG_DONE);
00318             this->img=img;
00319             api->gadget_Call(GADGET_REFRESH,TAG_GADGET_OBJECT,this_gadget,TAG_DONE);
00320             ret=0L;
00321           }
00322           else api->img_Call(IMG_CLEANUPIMAGE,TAG_IMG_OBJECT,img,TAG_DONE);
00323         }
00324       }
00325     }
00326   }
00327 
00328   debug_End();
00329 
00330   return(ret);
00331 }
00332 
00333 
00334 
00335 /*
00336  *  This function is called once before the creation of any Gadget_t of this
00337  *  class. Gadgets can be created only after this function has been called.
00338  */
00339 static void init_icon_class(u32 module)
00340 {
00341   api->gadget_Call(GADGET_REGISTER_CLASS,
00342                             TAG_GADGET_CLASS_ID,CLASS_ICON_ID,
00343                             TAG_GADGET_NAME,CLASS_ICON_NAME,
00344                 TAG_GADGET_BINDING,binding,
00345                 TAG_GADGET_COLOR_NAMES,NULL,
00346                 TAG_GADGET_CUSTOM_NAMES,NULL,
00347                 TAG_GADGET_STATE_MASK,GADSTF_NORMAL,
00348                 TAG_GADGET_MODULE,module,
00349                 TAG_GADGET_GADGET_SIZE,sizeof(icon),
00350                 TAG_GADGET_METHODS,methods,
00351                 TAG_GADGET_INPUT_EVENT_HANDLER,NULL,
00352                 TAG_GADGET_EVENT_HANDLER,NULL,
00353                 TAG_GADGET_GADGET_EVENT_HANDLER,icon_gadget_event_handler,
00354                 TAG_DONE);
00355 }
00356 
00357 
00358 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00359 {
00360     api=bases;
00361     init_icon_class(module);  return(0);
00362 }

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