Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gadget_SysDrag.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_drag.c
00026  *
00027  *  Author            : Gergely Gáti
00028  *  Date              :
00029  *  Description       :
00030  *
00031  */
00032 #include <stdlib.h>
00033 #include <string.h>
00034 
00035 #include "gadgets/gadget_SysDrag.h"
00036 
00037 #include "debug.h"
00038 #include "classes.h"
00039 #include "Memory.h"
00040 #include "Common.h"
00041 #include "Bases.h"
00042 #include "Module.h"
00043 #include "Window.h"
00044 
00045 
00046 struct _sys_drag
00047 {
00048   Gadget_t gadget;
00049   char *title;
00050   int optimal;
00051 };
00052 
00053 
00054 static bases_Modules_t *api;
00055 VERSION("SysDrag.gadget",1,0,"Gergely Gati","g.gati@freemail.hu");
00056 
00057 
00058 static u32 sys_drag_set_title(Gadget_t *this_gadget, tag *taglist);
00059 
00060 static gadget_Method_t methods[]=
00061 {
00062   {"set_title",sys_drag_set_title,0L},
00063   GADGET_METHOD_DONE
00064 };
00065 
00066 
00067 static gadget_Binding_t binding[]=
00068 {
00069   {"title",TAG_SSZ_TITLE,GADGET_STRING,""},
00070   {"optimal",TAG_SSZ_OPTIMAL,GADGET_INT,NULL},
00071   GADGET_BINDING_DONE
00072 };
00073 
00074 static char *color_names[]=
00075 {
00076   "text",
00077   NULL
00078 };
00079 
00080 
00081 /*
00082  *  This function is always called after the Gadget_t has been created and
00083  *  attached to the Gadget_t tree, but before the call to sys_drag_layout(). It may be
00084  *  called more than once. It must fill in the Gadget_t's minimum and maximum
00085  *  sizes into the supplied extent structures.
00086  */
00087 static void sys_drag_get_extent(Gadget_t *this, Extent_t *min, Extent_t *max)
00088 {
00089   debug_Begin();
00090 
00091   if(((sys_drag *)this)->title!=NULL)
00092   {
00093     min->width=2;
00094     min->height=api->glw_Call(GLW_GETFONTSIZE,TAG_GLW_FONT,api->gadget_Call(GADGET_GET_FONT,TAG_GADGET_OBJECT,this,TAG_DONE),TAG_DONE);
00095     max->width=(((sys_drag *)this)->optimal<=1?GADGET_MAXIMUM_SIZE:((sys_drag *)this)->optimal);
00096     max->height=min->height;
00097   }
00098   else
00099   {
00100     min->width=1;
00101     min->height=1;
00102     max->width=GADGET_MAXIMUM_SIZE;
00103     max->height=GADGET_MAXIMUM_SIZE;
00104   }
00105 
00106   debug_End();
00107 }
00108 
00109 
00110 /*
00111  *  This function is called always after sys_drag_get_extent() has been called at
00112  *  least once. It receives a position and an extent which determine the
00113  *  position and the size of the Gadget_t on the screen. This extent is always
00114  *  between the minimum and maximum sizes which were returned by
00115  *  sys_drag_get_extent() of the same gadget. After this call the Gadget_t is made
00116  *  visible.
00117  */
00118 static void sys_drag_layout(Gadget_t *this, Rect_t *rect)
00119 {
00120   debug_Begin();
00121 
00122 //  glw_SetColor(this->window->handle, 0x6182ae);
00123 //  glw_DrawFilledRect(this->window->handle,rect->left,rect->top,rect->width,rect->height);
00124   if(((sys_drag *)this)->title!=NULL)
00125   {
00126     Rect_t rct;
00127     rct.left=rect->left;
00128     rct.top=rect->top;
00129     rct.width=rect->width;
00130     rct.height=rect->height;
00131     api->glw_Call(GLW_SETCOLOR,TAG_GLW_WINDOW,this->window->handle,TAG_GLW_RGB, api->gadget_Call(GADGET_GET_COLOR,TAG_GADGET_OBJECT,this,TAG_GADGET_COLOR,SSZ_COL_TEXT,TAG_DONE));
00132     api->glw_Call(GLW_DRAWTEXT,TAG_GLW_WINDOW,this->window->handle,TAG_GLW_CLIPRECT,&rct,TAG_GLW_FONT,api->gadget_Call(GADGET_GET_FONT,TAG_GADGET_OBJECT,this,TAG_DONE),TAG_GLW_TEXT,((sys_drag *)this)->title,TAG_GLW_FLAGS,0L,TAG_DONE);
00133   }
00134 /*
00135   glw_SetColor(this->window->handle, 0xefefef);
00136   glw_DrawLine(this->window->handle,rect->left,rect->top,rect->left+rect->width-1,rect->top);
00137   glw_DrawLine(this->window->handle,rect->left,rect->top,rect->left,rect->top+rect->height-1);
00138   glw_SetColor(this->window->handle, 0x000000);
00139   glw_DrawLine(this->window->handle,rect->left,rect->top+rect->height-1,rect->left+rect->width-1,rect->top+rect->height-1);
00140   glw_DrawLine(this->window->handle,rect->left+rect->width-1,rect->top,rect->left+rect->width-1,rect->top+rect->height-1);
00141 */
00142 
00143   debug_End();
00144 }
00145 
00146 
00147 static int sys_drag_input_event_handler(Gadget_t *gad, struct glw_Event *event)
00148 {
00149   debug_Begin();
00150 
00151   switch(event->event)
00152   {
00153     case GLWEV_MOUSEBUTTONS:
00154     {
00155       switch(event->data)
00156       {
00157         case GLWEVD_LEFTDOWN:
00158         {
00159           api->glw_Call(GLW_DRAGWINDOW,TAG_GLW_WINDOW,gad->window->handle,TAG_DONE);
00160           break;
00161         }
00162         case GLWEVD_LEFTUP:
00163         {
00164           break;
00165         }
00166       }
00167       break;
00168     }
00169   }
00170 
00171   debug_End();
00172 
00173   return(0);
00174 }
00175 
00176 
00177 static int sys_drag_init_gadget(Gadget_t *this, tag *taglist)
00178 {
00179   int ret=-1;
00180   char *title;
00181 
00182   debug_Begin();
00183 
00184   title=(char *)tag_GetTagData(taglist,TAG_SSZ_TITLE,0L);
00185   if(title!=NULL) ((sys_drag *)this)->title=common_strdup(title);
00186   else ((sys_drag *)this)->title=NULL;
00187   ((sys_drag *)this)->optimal=(int)tag_GetTagData(taglist,TAG_SSZ_OPTIMAL,0L);
00188   ret=0;
00189 
00190   debug_End();
00191 
00192   return(ret);
00193 }
00194 
00195 
00196 static void sys_drag_delete_gadget(Gadget_t *this)
00197 {
00198   debug_Begin();
00199 
00200   if(((sys_drag *)this)->title!=NULL) mem_free(((sys_drag *)this)->title);
00201 
00202   debug_End();
00203 }
00204 
00205 
00206 static u32 sys_drag_set_title(Gadget_t *this_gadget, tag *taglist)
00207 {
00208   u32 ret=~0;
00209   char *new_title;
00210   u32 font;
00211 
00212   debug_Begin();
00213 
00214   new_title=common_strdup((char *)tag_GetTagData(taglist,TAG_SSZ_TITLE,(u32)""));
00215   if(new_title!=NULL)
00216   {
00217     if(((sys_drag *)this_gadget)->title!=NULL) mem_free(((sys_drag *)this_gadget)->title);
00218     ((sys_drag *)this_gadget)->title=new_title;
00219     if(((sys_drag *)this_gadget)->optimal>0)
00220     {
00221       font=api->gadget_Call(GADGET_GET_FONT,TAG_GADGET_OBJECT,this_gadget,TAG_DONE);
00222       ((sys_drag *)this_gadget)->optimal=4+api->glw_Call(GLW_GETTEXTLENGTH,TAG_GLW_FONT,font,TAG_GLW_TEXT,new_title,TAG_DONE);
00223     }
00224     api->gadget_Call(GADGET_REFRESH,TAG_GADGET_OBJECT,api->gadget_Call(GADGET_FATHER,TAG_GADGET_OBJECT,this_gadget,TAG_DONE),TAG_DONE);
00225   }
00226 
00227   debug_End();
00228 
00229   return(ret);
00230 }
00231 
00232 
00233 static int sys_drag_gadget_event_handler(Gadget_t *this, int event, tag *taglist)
00234 {
00235   int ret=-1;
00236 
00237   debug_Begin();
00238 
00239   if(this!=NULL&&event>=0)
00240   {
00241     switch(event)
00242     {
00243       case GADEV_INIT_GADGET:
00244       {
00245         ret=sys_drag_init_gadget(this,taglist);
00246         break;
00247       }
00248       case GADEV_DELETE_GADGET:
00249       {
00250         sys_drag_delete_gadget(this);
00251         ret=0;
00252         break;
00253       }
00254       case GADEV_GET_EXTENT:
00255       {
00256         Extent_t *min,*max,n,x;
00257         min=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMIN,(u32)&n);
00258         max=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMAX,(u32)&x);
00259         sys_drag_get_extent(this,min,max);
00260         ret=0;
00261         break;
00262       }
00263       case GADEV_LAYOUT:
00264       case GADEV_DAMAGE:
00265       {
00266         Rect_t *rect,r;
00267         rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00268         sys_drag_layout(this,rect);
00269         ret=0;
00270         break;
00271       }
00272       case GADEV_SAVE:
00273       {
00274         u8 **mem;
00275         int *size;
00276         mem=(u8 **)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00277         size=(int *)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00278         break;
00279       }
00280       case GADEV_RESTORE:
00281       {
00282         u8 *mem;
00283         int size;
00284         mem=(u8 *)tag_GetTagData(taglist,TAG_GADGET_MEM,0L);
00285         size=(int)tag_GetTagData(taglist,TAG_GADGET_SIZE,0L);
00286         break;
00287       }
00288     }
00289   }
00290 
00291   debug_End();
00292 
00293   return(ret);
00294 }
00295 
00296 
00297 /*
00298  *  This function is called once before the creation of any Gadget_t of this
00299  *  class. Gadgets can be created only after this function has been called.
00300  */
00301 static void init_sys_drag_class(u32 module)
00302 {
00303   api->gadget_Call(GADGET_REGISTER_CLASS,
00304                             TAG_GADGET_CLASS_ID,CLASS_SYS_DRAG_ID,
00305                             TAG_GADGET_NAME,CLASS_SYS_DRAG_NAME,
00306                 TAG_GADGET_BINDING,binding,
00307                 TAG_GADGET_COLOR_NAMES,color_names,
00308                 TAG_GADGET_CUSTOM_NAMES,NULL,
00309                 TAG_GADGET_STATE_MASK,GADSTF_NORMAL,
00310                 TAG_GADGET_MODULE,module,
00311                 TAG_GADGET_GADGET_SIZE,sizeof(sys_drag),
00312                 TAG_GADGET_METHODS,methods,
00313                 TAG_GADGET_INPUT_EVENT_HANDLER,sys_drag_input_event_handler,
00314                 TAG_GADGET_EVENT_HANDLER,NULL,
00315                 TAG_GADGET_GADGET_EVENT_HANDLER,sys_drag_gadget_event_handler,
00316                 TAG_DONE);
00317 }
00318 
00319 
00320 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00321 {
00322     api=bases;
00323     init_sys_drag_class(module);  return(0);
00324 }

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