home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 4 / CD_Magazyn_EXEC_nr_4.iso / Recent / dev / c / apputil.lha / apputil / buttonclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-06  |  3.0 KB  |  128 lines

  1. /*
  2.  * buttonclass.c
  3.  * =============
  4.  * Extends the intuition frbuttonclass to render disabled state properly.
  5.  *
  6.  * Copyright (C) 1999-2000 HÃ¥kan L. Younes (lorens@hem.passagen.se)
  7.  */
  8.  
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/imageclass.h>
  11.  
  12. #include <clib/alib_protos.h>
  13. #include <proto/intuition.h>
  14. #include <proto/utility.h>
  15.  
  16. #include "apputil.h"
  17.  
  18.  
  19. typedef struct {
  20.   struct Image *ghostingPattern;
  21. } ButtonClassData;
  22.  
  23.  
  24. static UWORD ghostingData[] = { 0x4444, 0x1111 };
  25.  
  26.  
  27. static BOOL ButtonNew(Class *cl, struct Gadget *obj, struct opSet *msg) {
  28.   ButtonClassData *data = INST_DATA(cl, obj);
  29.  
  30.   data->ghostingPattern =
  31.     (struct Image *)NewObject(NULL, "fillrectclass",
  32.                   IA_Width, obj->Width,
  33.                   IA_Height, obj->Height,
  34.                   IA_APattern, ghostingData,
  35.                   IA_APatSize, 1,
  36.                   TAG_DONE);
  37.  
  38.   return (BOOL)(data->ghostingPattern != NULL);
  39. }
  40.  
  41.  
  42. static VOID ButtonDispose(Class *cl, struct Gadget *obj) {
  43.   ButtonClassData *data = INST_DATA(cl, obj);
  44.  
  45.   DisposeObject(data->ghostingPattern);
  46. }
  47.  
  48.  
  49. static VOID ButtonSet(Class *cl, struct Gadget *obj, struct opSet *msg) {
  50.   struct TagItem *ti, *tstate = msg->ops_AttrList;
  51.   struct RastPort *rp;
  52.  
  53.   while ((ti = NextTagItem(&tstate)) != NULL) {
  54.     switch (ti->ti_Tag) {
  55.     case GA_Disabled:
  56.       rp = ObtainGIRPort(msg->ops_GInfo);
  57.       if (rp != NULL) {
  58.     DoMethod((Object *)obj, GM_RENDER, msg->ops_GInfo, rp, GREDRAW_REDRAW);
  59.     ReleaseGIRPort(rp);
  60.       }
  61.       break;
  62.     }
  63.   }
  64. }
  65.  
  66.  
  67. static VOID ButtonRender(Class *cl, struct Gadget *obj, struct gpRender *msg) {
  68.   ButtonClassData *data = INST_DATA(cl, obj);
  69.  
  70.   if (obj->Flags & GFLG_DISABLED) {
  71.     data->ghostingPattern->PlanePick =
  72.       msg->gpr_GInfo->gi_DrInfo->dri_Pens[TEXTPEN];
  73.     DrawImageState(msg->gpr_RPort, data->ghostingPattern,
  74.            (LONG)obj->LeftEdge, (LONG)obj->TopEdge,
  75.            IDS_NORMAL, msg->gpr_GInfo->gi_DrInfo);
  76.   }
  77. }
  78.  
  79.  
  80. static ULONG __saveds __asm ButtonClassDispatch(register __a0 Class *cl,
  81.                         register __a2 Object *obj,
  82.                         register __a1 Msg msg) {
  83.   ULONG result = 0;
  84.  
  85.   switch (msg->MethodID) {
  86.   case OM_NEW:
  87.     result = DoSuperMethodA(cl, obj, msg);
  88.     if (result != NULL) {
  89.       if (!ButtonNew(cl, (struct Gadget *)result, (struct opSet *)msg)) {
  90.     DoMethod((Object *)result, OM_DISPOSE);
  91.     result = NULL;
  92.       }
  93.     }
  94.     break;
  95.   case OM_DISPOSE:
  96.     ButtonDispose(cl, (struct Gadget *)obj);
  97.     DoSuperMethodA(cl, obj, msg);
  98.     break;
  99.   case OM_SET:
  100.     DoSuperMethodA(cl, obj, msg);
  101.     ButtonSet(cl, (struct Gadget *)obj, (struct opSet *)msg);
  102.     break;
  103.   case GM_RENDER:
  104.     DoSuperMethodA(cl, obj, msg);
  105.     ButtonRender(cl, (struct Gadget *)obj, (struct gpRender *)msg);
  106.     break;
  107.   default:
  108.     result = DoSuperMethodA(cl, obj, msg);
  109.     break;
  110.   }
  111.  
  112.   return result;
  113. }
  114.  
  115.  
  116. Class *CreateButtonClass(VOID) {
  117.   Class *cl;
  118.  
  119.   cl = MakeClass(NULL, "frbuttonclass", NULL, sizeof (ButtonClassData), 0);
  120.   if (cl != NULL) {
  121.     cl->cl_Dispatcher.h_SubEntry = NULL;
  122.     cl->cl_Dispatcher.h_Entry = (HOOKFUNC)ButtonClassDispatch;
  123.     cl->cl_Dispatcher.h_Data = NULL;
  124.   }
  125.  
  126.   return cl;
  127. }
  128.