Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

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

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