Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gadget_Test.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  *  test.c
00026  *
00027  *  Author            : Gergely Gáti
00028  *  Date              :
00029  *  Description       :
00030  *
00031  */
00032 #include <stdlib.h>
00033 
00034 #include "gadgets/gadget_Test.h"
00035 #include "debug.h"
00036 #include "classes.h"
00037 #include "Bases.h"
00038 #include "Module.h"
00039 #include "Common.h"
00040 #include "Window.h"
00041 
00042 
00043 struct _test
00044 {
00045   Gadget_t gadget;
00046   u32 color;
00047 };
00048 
00049 typedef struct _test_class_data
00050 {
00051   gadget_ClassData_t class_data;
00052 } test_class_data;
00053 
00054 static bases_Modules_t *api;
00055 VERSION("Test.gadget",1,0,"Gergely Gati","g.gati@freemail.hu");
00056 
00057 //static test_class_data test_data;
00058 
00059 
00060 static gadget_Binding_t binding[]=
00061 {
00062   {"color",TAG_TST_COLOR,GADGET_INT,NULL},
00063   GADGET_BINDING_DONE
00064 };
00065 
00066 static char *color_names[]=
00067 {
00068   "inactive",
00069   "active",
00070   NULL
00071 };
00072 
00073 
00074 /*
00075  *  This function is always called after the Gadget_t has been created and
00076  *  attached to the Gadget_t tree, but before the call to test_layout(). It may be
00077  *  called more than once. It must fill in the Gadget_t's minimum and maximum
00078  *  sizes into the supplied extent structures.
00079  */
00080 static void test_get_extent(Gadget_t *this, Extent_t *min, Extent_t *max)
00081 {
00082   debug_Begin();
00083 
00084   min->width=1;
00085   min->height=1;
00086   max->width=GADGET_MAXIMUM_SIZE;
00087   max->height=GADGET_MAXIMUM_SIZE;
00088 
00089   debug_End();
00090 }
00091 
00092 
00093 /*
00094  *  This function is called always after test_get_extent() has been called at
00095  *  least once. It receives a position and an extent which determine the
00096  *  position and the size of the Gadget_t on the screen. This extent is always
00097  *  between the minimum and maximum sizes which were returned by
00098  *  test_get_extent() of the same gadget. After this call the Gadget_t is made
00099  *  visible.
00100  */
00101 static void test_layout(Gadget_t *this, Rect_t *rect)
00102 {
00103   debug_Begin();
00104 
00105   api->glw_Call(GLW_SETCOLOR,TAG_GLW_WINDOW,this->window->handle, TAG_GLW_RGB,((test *)this)->color,TAG_DONE);
00106   api->glw_Call(GLW_DRAWFILLEDRECT,TAG_GLW_WINDOW,this->window->handle,TAG_GLW_LEFT,rect->left,TAG_GLW_TOP,rect->top,TAG_GLW_WIDTH,rect->width,TAG_GLW_HEIGHT,rect->height,TAG_DONE);
00107 
00108   debug_End();
00109 }
00110 
00111 
00112 static int test_input_event_handler(Gadget_t *gad, struct glw_Event *event)
00113 {
00114   int ret=0;
00115 
00116   debug_Begin();
00117 
00118   switch(event->event)
00119   {
00120     case GLWEV_MOUSEBUTTONS:
00121     {
00122       switch(event->data)
00123       {
00124         case GLWEVD_LEFTDOWN:
00125         {
00126           ((test *)gad)->color^=~0;
00127           api->gadget_Call(GADGET_REFRESH,TAG_GADGET_OBJECT,gad,TAG_DONE);
00128           ((test *)gad)->color^=~0;
00129           ret=api->gadget_Call(GADGET_CALLBACK,TAG_GADGET_OBJECT,gad,TAG_GADGET_EVENT,CBK_GADGET_DOWN,TAG_GADGET_EVENT_DATA,0L,TAG_DONE);
00130           break;
00131         }
00132         case GLWEVD_LEFTUP:
00133         {
00134           api->gadget_Call(GADGET_REFRESH,TAG_GADGET_OBJECT,gad,TAG_DONE);
00135           ret=api->gadget_Call(GADGET_CALLBACK,TAG_GADGET_OBJECT,gad,TAG_GADGET_EVENT,CBK_GADGET_UP,TAG_GADGET_EVENT_DATA,0L,TAG_DONE);
00136           break;
00137         }
00138         case GLWEVD_RIGHTDOWN:
00139         {
00140           ret=api->gadget_Call(GADGET_CALLBACK,TAG_GADGET_OBJECT,gad,TAG_GADGET_EVENT,CBK_GADGET_MOVE,TAG_GADGET_EVENT_DATA,0L,TAG_DONE);
00141           break;
00142         }
00143         case GLWEVD_RIGHTUP:
00144         {
00145           ret=api->gadget_Call(GADGET_CALLBACK,TAG_GADGET_OBJECT,gad,TAG_GADGET_EVENT,CBK_GADGET_MOVE,TAG_GADGET_EVENT_DATA,0L,TAG_DONE);
00146           break;
00147         }
00148       }
00149       break;
00150     }
00151   }
00152 
00153   debug_End();
00154 
00155   return(ret);
00156 }
00157 
00158 
00159 int test_init_gadget(Gadget_t *this, tag *taglist)
00160 {
00161   debug_Begin();
00162 
00163   ((test *)this)->color=tag_GetTagData(taglist,TAG_TST_COLOR,0xff00ff);
00164 
00165   debug_End();
00166 
00167   return(0);
00168 }
00169 
00170 
00171 static int test_gadget_event_handler(Gadget_t *this, int event, tag *taglist)
00172 {
00173   int ret=-1;
00174 
00175   debug_Begin();
00176 
00177   if(this!=NULL&&event>=0)
00178   {
00179     switch(event)
00180     {
00181       case GADEV_INIT_GADGET:
00182       {
00183         ret=test_init_gadget(this,taglist);
00184         break;
00185       }
00186       case GADEV_DELETE_GADGET:
00187       {
00188         ret=0;
00189         break;
00190       }
00191       case GADEV_GET_EXTENT:
00192       {
00193         Extent_t *min,*max,n,x;
00194         min=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMIN,(u32)&n);
00195         max=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMAX,(u32)&x);
00196         test_get_extent(this,min,max);
00197         ret=0;
00198         break;
00199       }
00200       case GADEV_LAYOUT:
00201       case GADEV_DAMAGE:
00202       {
00203         Rect_t *rect,r;
00204         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00205         test_layout(this,rect);
00206         ret=0;
00207         break;
00208       }
00209       case GADEV_SAVE:
00210       {
00211         u8 **mem;
00212         int *size;
00213         mem=(u8 **)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00214         size=(int *)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00215         break;
00216       }
00217       case GADEV_RESTORE:
00218       {
00219         u8 *mem;
00220         int size;
00221         mem=(u8 *)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00222         size=(int)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00223         break;
00224       }
00225     }
00226   }
00227 
00228   debug_End();
00229 
00230   return(ret);
00231 }
00232 
00233 
00234 /*
00235  *  This function is called once before the creation of any Gadget_t of this
00236  *  class. Gadgets can be created only after this function has been called.
00237  */
00238 static void init_test_class(u32 module)
00239 {
00240   api->gadget_Call(GADGET_REGISTER_CLASS,
00241                             TAG_GADGET_CLASS_ID,CLASS_TEST_ID,
00242                             TAG_GADGET_NAME,CLASS_TEST_NAME,
00243                 TAG_GADGET_BINDING,binding,
00244                 TAG_GADGET_COLOR_NAMES,color_names,
00245                 TAG_GADGET_CUSTOM_NAMES,NULL,
00246                 TAG_GADGET_STATE_MASK,GADSTF_NORMAL|GADSTF_PRESSED,
00247                 TAG_GADGET_MODULE,module,
00248                 TAG_GADGET_GADGET_SIZE,sizeof(test),
00249                 TAG_GADGET_METHODS,NULL,
00250                 TAG_GADGET_INPUT_EVENT_HANDLER,test_input_event_handler,
00251                 TAG_GADGET_EVENT_HANDLER,NULL,
00252                 TAG_GADGET_GADGET_EVENT_HANDLER,test_gadget_event_handler,
00253                 TAG_DONE);
00254 }
00255 
00256 
00257 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00258 {
00259     api=bases;
00260     init_test_class(module);  return(0);
00261 }

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