Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gadget_Compound.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  *  compound.c
00026  *
00027  *  Author            : Gergely Gáti
00028  *  Date              :
00029  *  Description       :
00030  *
00031  */
00032 #include <stdlib.h>
00033 
00034 #include "Tag.h"
00035 #include "macros.h"
00036 #include "debug.h"
00037 #include "classes.h"
00038 #include "Memory.h"
00039 #include "xml_Gui.h"
00040 #include "Bases.h"
00041 #include "Module.h"
00042 #include "Common.h"
00043 
00044 #include "gadgets/gadget_Compound.h"
00045 #include "gadgets/gadget_Space.h"
00046 #include "gadgets/gadget_Test.h"
00047 #include "gadgets/gadget_Group.h"
00048 
00049 
00050 struct _compound
00051 {
00052   Gadget_t gadget;
00053   u32 color;
00054   Gadget_t *subtree;
00055 };
00056 
00057 static bases_Modules_t *api;
00058 VERSION("Compound.gadget",1,0,"Gergely Gati","g.gati@freemail.hu");
00059 
00060 
00061 static gadget_Binding_t binding[]=
00062 {
00063   {"color",TAG_CPD_COLOR,GADGET_INT,NULL},
00064   GADGET_BINDING_DONE
00065 };
00066 
00067 static gadget_Check_t checklist[]=
00068 {
00069  { GADGET_SUBGADGET_BASE+1, "Group", GADGET_REQUIRED },
00070  { GADGET_SUBGADGET_BASE+2, "Test", 0L },
00071  GADGET_CHECK_DONE
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 compound_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 compound_get_extent(Gadget_t *this, Extent_t *min, Extent_t *max)
00082 {
00083   debug_Begin();
00084 
00085   api->gadget_Call(GADGET_GET_EXTENT,TAG_GADGET_OBJECT,api->gadget_Call(GADGET_SEARCH,TAG_GADGET_ROOT,((compound *)this)->subtree,TAG_GADGET_GADGET_ID,GADGET_SUBGADGET_BASE+1,TAG_DONE),TAG_GADGET_MIN,min,TAG_GADGET_MAX,max,TAG_DONE);
00086 
00087   debug_End();
00088 }
00089 
00090 
00091 /*
00092  *  This function is called always after compound_get_extent() has been called at
00093  *  least once. It receives a position and an extent which determine the
00094  *  position and the size of the Gadget_t on the screen. This extent is always
00095  *  between the minimum and maximum sizes which were returned by
00096  *  compound_get_extent() of the same gadget. After this call the Gadget_t is made
00097  *  visible.
00098  */
00099 static void compound_layout(Gadget_t *this, Rect_t *rect)
00100 {
00101   debug_Begin();
00102 
00103   debug_Message("exact size: id=%04lx  %dx%d",this->gadget_id,rect->width,rect->height);
00104   api->gadget_Call(GADGET_LAYOUT,TAG_GADGET_OBJECT,((compound *)this)->subtree,TAG_GADGET_RECT,rect,TAG_DONE);
00105 
00106   debug_End();
00107 }
00108 
00109 
00110 int compound_event_handler(Gadget_t *this, Gadget_t *sender, int event, u32 event_data)
00111 {
00112   int ret=0;
00113 
00114   debug_Begin();
00115 
00116   switch(event)
00117   {
00118     case CBK_GADGET_UP:
00119     {
00120       if(sender->gadget_id==(GADGET_SUBGADGET_BASE+2)) ret=api->gadget_Call(GADGET_CALLBACK,TAG_GADGET_OBJECT,this,TAG_GADGET_EVENT,event,TAG_GADGET_EVENT_DATA,event_data,TAG_DONE);
00121       break;
00122     }
00123   }
00124 
00125   debug_End();
00126 
00127   return(ret);
00128 }
00129 
00130 #if 0
00131   static int compound_input_event_handler(Gadget_t *gad, struct glw_Event *event)
00132   {
00133     int ret=0;
00134 
00135     debug_Begin();
00136 
00137     ret=api->gadget_Call(GADGET_POST_MESSAGE,TAG_GADGET_OBJECT,((compound *)gad)->subtree,TAG_GADGET_EVENT,event,TAG_DONE);
00138 
00139     debug_End();
00140 
00141     return(ret);
00142   }
00143 #endif
00144 
00145 
00146 static int compound_init_gadget(Gadget_t *this, tag *taglist)
00147 {
00148   int ret=-1;
00149   char *gui_file;
00150 
00151   debug_Begin();
00152 
00153   ((compound *)this)->color=tag_GetTagData(taglist,TAG_CPD_COLOR,0xff00ff);
00154   if(NULL!=(gui_file=(char *)api->gui_Call(GUI_LOADSUBGADGETDESCRIPTOR,TAG_GUI_WIN,this->window,TAG_GUI_CLASS_NAME,this->class_data->class_name,TAG_DONE)))
00155   {
00156     if(NULL!=(((compound *)this)->subtree=(Gadget_t *)api->gxml_Call(GXML_CREATEGADGETTREE,
00157                    TAG_GXML_XML_FILE,gui_file,
00158                    TAG_GXML_LOCALE,NULL,
00159                    TAG_GXML_TYPE,"gadget",
00160                    TAG_GXML_LAYOUTNAME,this->class_data->class_name,
00161                    TAG_GXML_APPNAME,NULL,
00162                    TAG_GXML_WINDOW,this->window,
00163                    TAG_GXML_CHECK,checklist,
00164                    TAG_DONE)))
00165     {
00166       api->gadget_Call(GADGET_ATTACH,TAG_GADGET_NEW_PARENT,this,TAG_GADGET_NEW_CHILD,((compound *)this)->subtree,TAG_DONE);
00167       ret=0;
00168     }
00169     api->gui_Call(GUI_UNLOADSUBGADGETDESCRIPTOR,TAG_GUI_FILE,gui_file,TAG_DONE);
00170   }
00171 
00172   debug_End();
00173 
00174   return(ret);
00175 }
00176 
00177 
00178 static void compound_suggest_extent(Gadget_t *this, Rect_t *rect)
00179 {
00180   debug_Begin();
00181 
00182   api->gadget_Call(GADGET_SUGGEST_EXTENT,TAG_GADGET_OBJECT,((compound *)this)->subtree,TAG_GADGET_RECT,rect,TAG_DONE);
00183 
00184   debug_End();
00185 }
00186 
00187 
00188 static int compound_gadget_event_handler(Gadget_t *this, int event, tag *taglist)
00189 {
00190   int ret=-1;
00191 
00192   debug_Begin();
00193 
00194   if(this!=NULL&&event>=0)
00195   {
00196     switch(event)
00197     {
00198       case GADEV_INIT_GADGET:
00199       {
00200         ret=compound_init_gadget(this,taglist);
00201         break;
00202       }
00203       case GADEV_DELETE_GADGET:
00204       {
00205         ret=0;
00206         break;
00207       }
00208       case GADEV_GET_EXTENT:
00209       {
00210         Extent_t *min,*max,n,x;
00211         min=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMIN,(u32)&n);
00212         max=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMAX,(u32)&x);
00213         compound_get_extent(this,min,max);
00214         ret=0;
00215         break;
00216       }
00217       case GADEV_SUGGEST_EXTENT:
00218       {
00219         Rect_t *rect,r;
00220         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00221         compound_suggest_extent(this,rect);
00222         ret=0;
00223         break;
00224       }
00225       case GADEV_LAYOUT:
00226       case GADEV_DAMAGE:
00227       {
00228         Rect_t *rect,r;
00229         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00230         compound_layout(this,rect);
00231         ret=0;
00232         break;
00233       }
00234       case GADEV_SAVE:
00235       {
00236         u8 **mem;
00237         int *size;
00238         mem=(u8 **)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00239         size=(int *)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00240         break;
00241       }
00242       case GADEV_RESTORE:
00243       {
00244         u8 *mem;
00245         int size;
00246         mem=(u8 *)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00247         size=(int)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00248         break;
00249       }
00250     }
00251   }
00252 
00253   debug_End();
00254 
00255   return(ret);
00256 }
00257 
00258 
00259 /*
00260  *  This function is called once before the creation of any Gadget_t of this
00261  *  class. Gadgets can be created only after this function has been called.
00262  */
00263 static void init_compound_class(u32 module)
00264 {
00265   api->gadget_Call(GADGET_REGISTER_CLASS,
00266                             TAG_GADGET_CLASS_ID,CLASS_COMPOUND_ID,
00267                             TAG_GADGET_NAME,CLASS_COMPOUND_NAME,
00268                 TAG_GADGET_BINDING,binding,
00269                 TAG_GADGET_COLOR_NAMES,NULL,
00270                 TAG_GADGET_CUSTOM_NAMES,NULL,
00271                 TAG_GADGET_STATE_MASK,GADSTF_NORMAL,
00272                 TAG_GADGET_MODULE,module,
00273                 TAG_GADGET_GADGET_SIZE,sizeof(compound),
00274                 TAG_GADGET_METHODS,NULL,
00275                 TAG_GADGET_INPUT_EVENT_HANDLER,NULL,
00276                 TAG_GADGET_EVENT_HANDLER,compound_event_handler,
00277                 TAG_GADGET_GADGET_EVENT_HANDLER,compound_gadget_event_handler,
00278                 TAG_DONE);
00279 }
00280 
00281 
00282 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00283 {
00284     api=bases;
00285     init_compound_class(module);  return(0);
00286 }

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