Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gadget_SysClose.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  *  sys_close.c
00026  *
00027  *  Author            : Gergely Gáti
00028  *  Date              :
00029  *  Description       :
00030  *
00031  */
00032 #include <stdlib.h>
00033 
00034 #include "gadgets/gadget_SysClose.h"
00035 
00036 #include "debug.h"
00037 #include "classes.h"
00038 #include "Bases.h"
00039 #include "Module.h"
00040 #include "Window.h"
00041 #include "Common.h"
00042 
00043 
00044 struct _sys_close
00045 {
00046   Gadget_t gadget;
00047 /*  u32 col_title;
00048   u32 col_white;
00049   u32 col_black;*/
00050   int state;
00051 };
00052 
00053 static bases_Modules_t *api;
00054 VERSION("SysClose.gadget",1,0,"Gergely Gati","g.gati@freemail.hu");
00055 
00056 
00057 
00058 /*
00059  *  This function is always called after the Gadget_t has been created and
00060  *  attached to the Gadget_t tree, but before the call to sys_close_layout(). It may be
00061  *  called more than once. It must fill in the Gadget_t's minimum and maximum
00062  *  sizes into the supplied extent structures.
00063  */
00064 static void sys_close_get_extent(Gadget_t *this, Extent_t *min, Extent_t *max)
00065 {
00066   debug_Begin();
00067 
00068   min->width=1;
00069   min->height=1;
00070   max->width=GADGET_MAXIMUM_SIZE;
00071   max->height=GADGET_MAXIMUM_SIZE;
00072 
00073   debug_End();
00074 }
00075 
00076 
00077 /*
00078  *  This function is called always after sys_close_get_extent() has been called at
00079  *  least once. It receives a position and an extent which determine the
00080  *  position and the size of the Gadget_t on the screen. This extent is always
00081  *  between the minimum and maximum sizes which were returned by
00082  *  sys_close_get_extent() of the same gadget. After this call the Gadget_t is made
00083  *  visible.
00084  */
00085 static void sys_close_layout(Gadget_t *this, Rect_t *rect)
00086 {
00087 //  int iw,ih,il,it;
00088 
00089   debug_Begin();
00090 
00091 /*
00092   iw=rect->width/3;
00093   ih=rect->height/3;
00094   il=rect->left+((rect->width-iw)>>1);
00095   it=rect->top+((rect->height-ih)>>1);
00096   glw_SetColor(this->window->handle, ((sys_close *)this)->col_title);
00097   glw_DrawFilledRect(this->window->handle,rect->left,rect->top,rect->width,rect->height);
00098   glw_SetColor(this->window->handle, ((sys_close *)this)->col_black);
00099   glw_DrawLine(this->window->handle,rect->left,rect->top+rect->height-1,rect->left+rect->width-1,rect->top+rect->height-1);
00100   glw_DrawLine(this->window->handle,rect->left+rect->width-1,rect->top+rect->height-1,rect->left+rect->width-1,rect->top);
00101   glw_SetColor(this->window->handle, ((sys_close *)this)->col_white);
00102   glw_DrawLine(this->window->handle,rect->left,rect->top,rect->left,rect->top+rect->height-1);
00103   glw_DrawLine(this->window->handle,rect->left,rect->top,rect->left+rect->width-1,rect->top);
00104   glw_DrawFilledRect(this->window->handle,il,it,iw,ih);
00105   glw_SetColor(this->window->handle, ((sys_close *)this)->col_black);
00106   glw_DrawRect(this->window->handle,il,it,iw,ih);
00107 */
00108 
00109   debug_End();
00110 }
00111 
00112 
00113 static void sys_close_suggest_extent(Gadget_t *this, Rect_t *rect)
00114 {
00115   debug_Begin();
00116 
00117   debug_End();
00118 }
00119 
00120 
00121 static int sys_close_input_event_handler(Gadget_t *gad, struct glw_Event *event)
00122 {
00123   int ret=0;
00124 //  u32 col_store;
00125 
00126   debug_Begin();
00127 
00128   switch(event->event)
00129   {
00130     case GLWEV_MOUSEMOVE:
00131     {
00132       if(((sys_close *)gad)->state!=0)
00133       {
00134         if(!api->gui_Call(GUI_ISINSIDE,TAG_GUI_RECT,&gad->rect,TAG_GUI_X,event->mousex,TAG_GUI_Y,event->mousey,TAG_DONE))
00135         {
00136           api->gadget_Call(GADGET_SET_STATE,TAG_GADGET_OBJECT,gad,TAG_GADGET_STATE,GADST_NORMAL,TAG_GADGET_VISUAL,1,TAG_DONE);
00137         }
00138         else
00139         {
00140           api->gadget_Call(GADGET_SET_STATE,TAG_GADGET_OBJECT,gad,TAG_GADGET_STATE,GADST_PRESSED,TAG_GADGET_VISUAL,1,TAG_DONE);
00141         }
00142       }
00143       break;
00144     }
00145     case GLWEV_MOUSEBUTTONS:
00146     {
00147       switch(event->data)
00148       {
00149         case GLWEVD_LEFTDOWN:
00150         {
00151           api->gadget_Call(GADGET_SET_STATE,TAG_GADGET_OBJECT,gad,TAG_GADGET_STATE,GADST_PRESSED,TAG_GADGET_VISUAL,1,TAG_DONE);
00152           api->window_Call(WINDOW_SETACTIVE,TAG_WIN_OBJECT,gad->window,TAG_WIN_GADGET,gad,TAG_DONE);
00153           ((sys_close *)gad)->state=1;
00154           break;
00155         }
00156         case GLWEVD_LEFTUP:
00157         {
00158           api->gadget_Call(GADGET_SET_STATE,TAG_GADGET_OBJECT,gad,TAG_GADGET_STATE,GADST_NORMAL,TAG_GADGET_VISUAL,1,TAG_DONE);
00159           api->window_Call(WINDOW_SETACTIVE,TAG_WIN_OBJECT,gad->window,TAG_WIN_GADGET,NULL,TAG_DONE);
00160           ((sys_close *)gad)->state=0;
00161           if(api->gui_Call(GUI_ISINSIDE,TAG_GUI_RECT,&gad->rect,TAG_GUI_X,event->mousex,TAG_GUI_Y,event->mousey,TAG_DONE))
00162           {
00163             ret=api->gadget_Call(GADGET_CALLBACK,TAG_GADGET_OBJECT,gad,TAG_GADGET_EVENT,CBK_WINDOW_CLOSE,TAG_GADGET_EVENT_DATA,0L,TAG_DONE);
00164           }
00165           break;
00166         }
00167       }
00168       break;
00169     }
00170   }
00171 
00172   debug_End();
00173 
00174   return(ret);
00175 }
00176 
00177 
00178 int sys_close_init_gadget(Gadget_t *this, tag *taglist)
00179 {
00180   debug_Begin();
00181 
00182 /*
00183   ((sys_close *)this)->col_title=0x6182ae;
00184   ((sys_close *)this)->col_white=0xefefef;
00185   ((sys_close *)this)->col_black=0x000000;
00186 */
00187   ((sys_close *)this)->state=0;
00188 
00189   debug_End();
00190 
00191   return(0);
00192 }
00193 
00194 
00195 static int sys_close_gadget_event_handler(Gadget_t *this, int event, tag *taglist)
00196 {
00197   int ret=-1;
00198 
00199   debug_Begin();
00200 
00201   if(this!=NULL&&event>=0)
00202   {
00203     switch(event)
00204     {
00205       case GADEV_INIT_GADGET:
00206       {
00207         ret=sys_close_init_gadget(this,taglist);
00208         break;
00209       }
00210       case GADEV_DELETE_GADGET:
00211       {
00212         ret=0;
00213         break;
00214       }
00215       case GADEV_GET_EXTENT:
00216       {
00217         Extent_t *min,*max,n,x;
00218         min=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMIN,(u32)&n);
00219         max=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMAX,(u32)&x);
00220         sys_close_get_extent(this,min,max);
00221         ret=0;
00222         break;
00223       }
00224       case GADEV_SUGGEST_EXTENT:
00225       {
00226         Rect_t *rect,r;
00227         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00228         sys_close_suggest_extent(this,rect);
00229         ret=0;
00230         break;
00231       }
00232       case GADEV_LAYOUT:
00233       case GADEV_DAMAGE:
00234       {
00235         Rect_t *rect,r;
00236         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00237         sys_close_layout(this,rect);
00238         ret=0;
00239         break;
00240       }
00241     }
00242   }
00243 
00244   debug_End();
00245 
00246   return(ret);
00247 }
00248 
00249 
00250 /*
00251  *  This function is called once before the creation of any Gadget_t of this
00252  *  class. Gadgets can be created only after this function has been called.
00253  */
00254 static void init_sys_close_class(u32 module)
00255 {
00256   api->gadget_Call(GADGET_REGISTER_CLASS,
00257                             TAG_GADGET_CLASS_ID,CLASS_SYS_CLOSE_ID,
00258                             TAG_GADGET_NAME,CLASS_SYS_CLOSE_NAME,
00259                 TAG_GADGET_BINDING,NULL,
00260                 TAG_GADGET_COLOR_NAMES,NULL,
00261                 TAG_GADGET_CUSTOM_NAMES,NULL,
00262                 TAG_GADGET_STATE_MASK,GADSTF_NORMAL|GADSTF_PRESSED,
00263                 TAG_GADGET_MODULE,module,
00264                 TAG_GADGET_GADGET_SIZE,sizeof(sys_close),
00265                 TAG_GADGET_METHODS,NULL,
00266                 TAG_GADGET_INPUT_EVENT_HANDLER,sys_close_input_event_handler,
00267                 TAG_GADGET_EVENT_HANDLER,NULL,
00268                 TAG_GADGET_GADGET_EVENT_HANDLER,sys_close_gadget_event_handler,
00269                 TAG_DONE);
00270 }
00271 
00272 
00273 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00274 {
00275     api=bases;
00276     init_sys_close_class(module);  return(0);
00277 }

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