home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pGadgets / Example1Gad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  25.8 KB  |  873 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 03 Mar 1997 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>Exampe1Gad.c<<   03 Mar 1997    09:12:07 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/libs/Example1Gad.library p:pLib/LibCode.o p:/pOS_RKRM/pGadgets/Example1Gad.c -l pOSStub -l CPPList -l pOS
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42.  
  43.  
  44. /*\
  45. *** Test the gadget:
  46. ***
  47. *** The 'win' command can load gadgets from libraries.
  48. ***
  49. *** Win Example1Gad.library/Example1Gad.class
  50. ***
  51. \*/
  52.  
  53.  
  54.  
  55.  
  56.  
  57. #define __COMPUTER_AMIGA 1
  58. #define NOMYDEBUG
  59.  
  60. #include "p:pExec/Library.h"
  61. #include "p:pExec/Resident.h"
  62. #include "p:pExec/Class.h"
  63. #include "p:pExec/Task.h"
  64. #include "p:pExec/Diagnos.h"
  65. #include "p:pExec/TstTags.h"
  66. #include "p:Device/IEvent.h"
  67. #include "p:pDOS/Segment.h"
  68. #include "p:pDOS/DosTags.h"
  69. #include "p:pGadget/Gadget.h"
  70. #include "p:pScreen/DrawInfo.h"
  71. #include "p:pGfx/RastPort.h"
  72. #include "p:pGFX/Text.h"
  73. #include "p:pIntui/GClass.h"
  74. #include "p:pIntui/DragTags.h"
  75. #include "p:pIntui/IntuMsg.h"
  76. #include "p:pIntui/Tags.h"
  77. #include "p:pDtType/Ascii.h"
  78. #include "p:pDtType/DClass.h"
  79. #include "p:proto/pLibExt.h"
  80. #include "p:proto/pExec2.h"
  81. #include "p:proto/pIntui2.h"
  82. #include "p:proto/pList.h"
  83. #include "p:proto/pUtil2.h"
  84. #include "p:proto/pGfx2.h"
  85. #include "p:proto/pConsole2.h"
  86. #include "p:proto/pDtType2.h"
  87. #include "p:proto/pGadget2.h"
  88.  
  89.  
  90. #ifdef _____ME_____
  91.   #include "grund/inc_string.h"
  92.   #include "grund/inc_limits.h"
  93.   #include "grund/inc_stdlib.h"
  94. #else
  95.  #ifdef __cplusplus
  96.  extern "C" {
  97.  #endif
  98.   #include <string.h>
  99.   #include <limits.h>
  100.   #include <stdlib.h>
  101.  #ifdef __cplusplus
  102.  }
  103.  #endif
  104. #endif
  105.  
  106.  
  107. struct pOS_ExecBase        *gb_ExecBase;
  108. struct pOS_ExecLibFunction *gb_ExecLib;
  109. struct pOS_DosBase         *gb_DosBase;
  110. struct pOS_IntuiDevice     *gb_IntuiBase;
  111. struct pOS_UtilityBase     *gb_UtilityBase;
  112. struct pOS_GadgetBase      *gb_GadgetBase;
  113. struct pOS_GfxBase         *gb_GfxBase;
  114. struct pOS_ConsoleDevice   *gb_ConsoleBase;
  115. struct pOS_DataTypeBase    *gb_DtTypeBase;
  116.  
  117.  
  118. struct ExampleGadLib
  119. {
  120.   struct pOS_Library  amg_Lib;
  121.   struct pOS_NClass  *amg_CGadClass;
  122.  
  123.   struct pOS_Point    amg_StartMouse;
  124.   UWORD               amg_StoreFac;
  125. };
  126.  
  127. struct ExampleGadLib* gb_ExampleLibBase;
  128.  
  129.  
  130.  
  131. extern ULONG *FuncTable[];
  132. const CHAR LibraryName[]  ="Example1Gad.library";
  133. const CHAR LibraryIDName[]="Example1Gad.library 1.0 ("__DATE2__")";
  134.  
  135. const pOS_TagItem LibraryDescribe[]=
  136. {
  137.   EXTSTTAG_MainOSID, pOS_MAINOSID,
  138.   TAG_END
  139. };
  140.  
  141.  
  142. BOOL pLibMain(_R_LB pOS_ExecBase*,_R_A0 ExampleGadLib*);
  143.  
  144. pOS_ResidentLibInit InitTable=
  145. {
  146.   sizeof(ExampleGadLib),
  147.   FuncTable,
  148.   NULL,
  149.   (BOOL(*)(_R_LB pOS_ExecBase*,_R_A0 pOS_Library*))pLibMain
  150. };
  151.  
  152.  
  153. /*----------------------------------
  154.  Wird in dieser Library nicht benötigt.
  155. -----------------------------------*/
  156. BOOL Open_func(_R_LB ExampleGadLib*)      { return(1); }
  157. VOID Close_func(_R_LB ExampleGadLib*)     {}
  158. ULONG Reserved_func(_R_LB ExampleGadLib*) { return(0); }
  159.  
  160.  
  161.  
  162. /*----------------------------------
  163. -----------------------------------*/
  164. pOS_SegmentLst* Expunge_func(_R_LB ExampleGadLib* lib)
  165. {
  166.   if(lib->amg_Lib.lib_OpenCnt==0) {
  167.     pOS_SegmentLst* Seg=lib->amg_Lib.lib_Segm;
  168.  
  169.     pOS_ListRemove(&lib->amg_Lib.lib_Node);
  170.  
  171.     if(lib->amg_CGadClass) pOS_DeleteClass(lib->amg_CGadClass);
  172.  
  173.     _pOS_FreeLibraryMem2(&lib->amg_Lib);
  174.  
  175.     pOS_CloseLibrary((struct pOS_Library*)gb_GadgetBase);
  176.     pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
  177.     pOS_CloseLibrary((struct pOS_Library*)gb_UtilityBase);
  178.     pOS_CloseLibrary((struct pOS_Library*)gb_ConsoleBase);
  179.     pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
  180.     pOS_CloseLibrary((struct pOS_Library*)gb_DosBase);
  181.     pOS_CloseLibrary((struct pOS_Library*)gb_DtTypeBase);
  182.     return(Seg);
  183.   }
  184.   return(0);
  185. }
  186.  
  187.  
  188. ULONG *FuncTable[]=
  189. {
  190.  (ULONG*)Open_func,
  191.  (ULONG*)Close_func,
  192.  (ULONG*)Expunge_func,
  193. // ------------
  194.  (ULONG*)Reserved_func,
  195.  (ULONG*)Reserved_func,
  196.  (ULONG*)Reserved_func,
  197.  (ULONG*)Reserved_func,
  198.  (ULONG*)Reserved_func,
  199.  (ULONG*)Reserved_func,
  200.  (ULONG*)Reserved_func,
  201.  (ULONG*)Reserved_func,
  202. // ------------
  203.  
  204.  (ULONG*)ULONG_MAX
  205. };
  206.  
  207.  
  208.  
  209. /*******************************************************************************/
  210.  
  211. /*----------------------------------
  212. -----------------------------------*/
  213. struct ExampleDatas
  214. {
  215.   UWORD ed_Fac;
  216.  
  217.   UWORD ed_DragFac; /* remember by drag */
  218. };
  219.  
  220.  
  221.  
  222.  
  223.  
  224. /*----------------------------------
  225. -----------------------------------*/
  226. VOID GetGadgetLightRect(const struct pOS_Rectangle* rect,const struct ExampleDatas* obj,
  227.                         const struct pOS_IClassInfo* ici,struct pOS_Rectangle* resRect)
  228. {
  229.   resRect->MinX=rect->MaxX; /* full area */
  230.   resRect->MinY=rect->MaxY;
  231.   resRect->MaxX=rect->MaxX;
  232.   resRect->MaxY=rect->MaxY;
  233. }
  234.  
  235. /*----------------------------------
  236. -----------------------------------*/
  237. VOID CalcKnobRect(const struct pOS_Rectangle* rect,struct pOS_Rectangle* resRect)
  238. {
  239.   resRect->MinX=rect->MinX+2; /* let 2 pixel space */
  240.   resRect->MinY=rect->MinY+2;
  241.   resRect->MaxX=rect->MaxX-2;
  242.   resRect->MaxY=rect->MaxY-2;
  243. }
  244.  
  245. /*----------------------------------
  246. -----------------------------------*/
  247. VOID GetGadgetKnobRect(const struct pOS_Rectangle* rect,const struct ExampleDatas* obj,
  248.                        const struct pOS_IClassInfo* ici,struct pOS_Rectangle* resRect)
  249. {
  250.   SLONG Width,Height,MidX,MidY;
  251.  
  252.   CalcKnobRect(rect,resRect);
  253.  
  254.   Width =resRect->MaxX - resRect->MinX+1;
  255.   Height=resRect->MaxY - resRect->MinY+1;
  256.   MidX  =resRect->MinX + Width/2;
  257.   MidY  =resRect->MinY + Height/2;
  258.  
  259.   Width =Width*obj->ed_Fac /(2*0xffff);
  260.   Height=Height*obj->ed_Fac/(2*0xffff);
  261.  
  262.   resRect->MinX=MidX-Width;
  263.   resRect->MinY=MidY-Height;
  264.   resRect->MaxX=MidX+Width;
  265.   resRect->MaxY=MidY+Height;
  266. }
  267.  
  268.  
  269.  
  270. /*----------------------------------
  271. -----------------------------------*/
  272. VOID RenderGadgetGround(struct pOS_RastPort* rp,const struct pOS_Rectangle* rect,
  273.                   struct ExampleDatas* obj,const struct pOS_IClassInfo* ici)
  274. {
  275.   const UWORD *const Pens=ici->ici_DrawInfo->dri_Pens;
  276.  
  277.   pOS_SetAPen(rp,Pens[SCRPEN_GadgetGround]);
  278.   pOS_DrawRectFill(rp,rect->MinX,rect->MinY,rect->MaxX,rect->MaxY);
  279. }
  280.  
  281. /*----------------------------------
  282. -----------------------------------*/
  283. VOID RenderGadgetKnob(struct pOS_RastPort* rp,const struct pOS_Rectangle* rect,
  284.                       struct ExampleDatas* obj,const struct pOS_IClassInfo* ici,
  285.                       BOOL selected)
  286. {
  287.   struct pOS_Rectangle MRect;
  288.   const UWORD *const Pens=ici->ici_DrawInfo->dri_Pens;
  289.  
  290.   pOS_SetAPen(rp,Pens[selected ? SCRPEN_Fill:SCRPEN_GadgetGround]);
  291.   GetGadgetKnobRect(rect,obj,ici,&MRect);
  292.  
  293.   pOS_DrawRectFill(rp,MRect.MinX+1,MRect.MinY+1,MRect.MaxX-1,MRect.MaxY-1);
  294.   pOS_DrawBorderBox(rp,ici->ici_DrawInfo,selected ? GADBORTYP_BevelDownBox:GADBORTYP_BevelUpBox,&MRect);
  295. }
  296.  
  297.  
  298. /*----------------------------------
  299. -----------------------------------*/
  300. VOID Render(const struct pOS_Class* cl,struct ExampleDatas* obj,
  301.             const struct pOS_IClassInfo* ici,ULONG mode)
  302. {
  303.   struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
  304.   struct pOS_RastPort *RP;
  305.   struct pOS_Rectangle Rect;
  306.  
  307.   if(RP=pOS_ObtainGRastPort(Gad,ici)) {
  308.     pOS_CalcGadgetInnerBox(ici->ici_Window,Gad,&Rect);
  309.  
  310.     if(   mode==GCLMTHRE_Update
  311.        || mode==GCLMTHRE_Redraw)
  312.     {
  313.       RenderGadgetGround(RP,&Rect,obj,ici);
  314.     }
  315.  
  316.     if(   mode==GCLMTHRE_Update
  317.        || mode==GCLMTHRE_Toggle
  318.        || mode==GCLMTHRE_Redraw)
  319.     {
  320.       RenderGadgetKnob(RP,&Rect,obj,ici,pOS_GetAbsObjectData(cl,obj,ICLTAG_Selected) );
  321.     }
  322.     pOS_ReleaseGRastPort(ici,RP);
  323.   }
  324. }
  325.  
  326.  
  327. /*----------------------------------
  328. -----------------------------------*/
  329. ULONG SetTags(const struct pOS_Class* cl,struct ExampleDatas* obj,
  330.               const struct pOS_TagItem* tags,const struct pOS_IClassInfo* ici)
  331. {
  332.   const struct pOS_TagItem* Tag;
  333.   ULONG Flg=1;
  334.   UBYTE NewDraw=0;
  335.  
  336.   while(Tag=pOS_NextTagItem(&tags)) {
  337.     switch(Tag->ti_Tag) {
  338.  
  339.       case PRGADTAG_VertPot:  /* only an example tag */
  340.         if(obj->ed_Fac != Tag->ti_Data) {
  341.           obj->ed_Fac = Tag->ti_Data;
  342.           NewDraw=1;
  343.         }
  344.         break;
  345.  
  346.     }
  347.   }
  348.  
  349.   if(ici && NewDraw) Render(cl,obj,ici,GCLMTHRE_Update);
  350.   return(Flg);
  351. }
  352.  
  353.  
  354.  
  355. /*----------------------------------
  356. -----------------------------------*/
  357. BOOL GetTags(struct ExampleDatas* obj,ULONG id,ULONG* Data)
  358. {
  359.   BOOL Flg=1;
  360.  
  361.   switch(id) {
  362.     case PRGADTAG_VertPot:  /* only an example tag */
  363.       *Data=(ULONG)obj->ed_Fac;
  364.       break;
  365.  
  366.     default: Flg=0;
  367.   }
  368.   return(Flg);
  369. }
  370.  
  371.  
  372.  
  373. /*----------------------------------
  374. -----------------------------------*/
  375. ULONG pOSp_Example1GadDispatcher(_R_LB struct pOS_ExecBase* exec,
  376.                                  _R_A0 const struct pOS_Class* cl,
  377.                                  _R_A1 struct ExampleDatas* obj,
  378.                                  _R_A2 struct pOS_GadgetMethod* mth)
  379. {
  380.   ULONG ret=0;
  381.  
  382.   switch(mth->imth_Method) {
  383.  
  384.     case ICLMTH_New: /* first method by pOS_NewIObject() */
  385. /*\
  386. *** Default-Datas
  387. \*/
  388.       pOS_SetAbsObjectData(cl,obj,
  389.         ICLTAG_GadBorderType,   GADBORTYP_StrBox | GADBORF_BgOverBorder,
  390.         ICLTAG_TabCycle,        TRUE,
  391.         ICLTAG_HighlightFocus,  TRUE,
  392.         ICLTAG_HighlightDropBox,TRUE,
  393. /*\
  394. *** Define the drag-type. We can drag one line 'ascii' datas.
  395. *** And the same as drop.
  396. \*/
  397.         ICLTAG_AddDragAttName,  (ULONG)"Example1Gad.class:ascii/line/",
  398.         ICLTAG_AddDropAttName,  (ULONG)"#?ascii/line/#?",
  399.  
  400. /*\
  401. *** Enable standard-drag/drop methods
  402. \*/
  403.         ICLTAG_StandardDrag,    TRUE,
  404.         ICLTAG_StandardDrop,    TRUE,
  405.         TAG_END);
  406.  
  407.  
  408.       obj->ed_Fac=0x4000; /* default */
  409.  
  410.       ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);  /* call Basisclass (SuperClass) */
  411.  
  412.       if(ret!=pOS_CLASSERR) {
  413.         ret=SetTags(cl,obj,mth->imth_U.imth_New.imnw_Tags,NULL);
  414.       }
  415.       break;
  416.  
  417.  
  418. // -----
  419.     case ICLMTH_Set:    /* by pOS_SetGadgetAttrs() or pOS_SetObjectDatas() */
  420.     case ICLMTH_Update: /* Gadget to gadget update */
  421.       pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
  422.       SetTags(cl,obj,mth->imth_U.imth_Set.imst_Tags,mth->imth_U.imth_Set.imst_Info);
  423.       break;
  424.  
  425.  
  426. // -----
  427.     case ICLMTH_Get:   /* by pOS_GetGadgetAttr() or pOS_GetObjctData() */
  428.       if( !(ret=pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth)))
  429.         ret=GetTags(obj,mth->imth_U.imth_Get.imgt_ID,
  430.                         mth->imth_U.imth_Get.imgt_Variable);
  431.       break;
  432.  
  433.  
  434. // -----
  435.     case GCLMTH_Render:  /* draw/refresh/update/... */
  436.       Render(cl,obj,mth->imth_U.imth_Render.imre_Info,mth->imth_U.imth_Render.imre_Type);
  437.       pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
  438.       break;
  439.  
  440. // -----
  441.     case GCLMTH_GetIBox:  /* for layouter */
  442.       mth->imth_U.imth_GetIBox.imgb_MinIBox->Width =32;
  443.       mth->imth_U.imth_GetIBox.imgb_MinIBox->Height=32;
  444.       mth->imth_U.imth_GetIBox.imgb_MaxIBox->Width =32000;
  445.       mth->imth_U.imth_GetIBox.imgb_MaxIBox->Height=32000;
  446.       break;
  447.  
  448.  
  449. // -----
  450.     case GCLMTH_GoActive:  /* by mouseclick-left or pOS_ActivateGadget() */
  451.       {
  452.         struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
  453.         struct pOS_Rectangle Rect,KnobRect;
  454.         const struct pOS_IClassInfo *const ICI=mth->imth_U.imth_GoActive.imac_Info;
  455.         const struct pOS_InputEvent *const IE =mth->imth_U.imth_GoActive.imac_IE;
  456.  
  457.         if(IE) { /** Activate comes from user directly (mouse-klick) **/
  458.           const struct pOS_Point *const AP=mth->imth_U.imth_GoActive.imac_AMouse;
  459.  
  460. /*\
  461. *** mth->imth_U.imth_GoActive.imac_RMouse => Mousepoint inner gadget
  462. *** mth->imth_U.imth_GoActive.imac_AMouse => Mousepoint inner window
  463. ***
  464. *** pOS_CalcGadgetBox(ICI->ici_Window,Gad,&Rect);
  465. ***   => full gadget bounds (gad_LeftEdge => gad_LeftEdge+gad_Width-1)
  466. ***
  467. *** pOS_CalcGadgetInnerBox(ICI->ici_Window,Gad,&Rect);
  468. ***   => gadget bound without gad_BorXX and without gad_Lable-bounds
  469. \*/
  470.           pOS_CalcGadgetInnerBox(ICI->ici_Window,Gad,&Rect);
  471.           GetGadgetKnobRect(&Rect,obj,ICI,&KnobRect);
  472.  
  473.           if(   AP->X >= KnobRect.MinX && AP->X <= KnobRect.MaxX
  474.              && AP->Y >= KnobRect.MinY && AP->Y <= KnobRect.MaxY)
  475.           {
  476.  
  477. /*\
  478. *** Mouseclick is in knob-bounds, we can handle the IE.
  479. *** Store the actual click-position.
  480. \*/
  481.             gb_ExampleLibBase->amg_StartMouse=*AP;
  482.             gb_ExampleLibBase->amg_StoreFac=obj->ed_Fac;
  483.  
  484.             pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, TRUE, TAG_END);
  485.             Render(cl,obj,ICI,GCLMTHRE_Toggle);
  486.  
  487.             ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
  488.           }
  489.           else {
  490.  
  491. /*\
  492. *** Click is not in inner-bounds, still activate.
  493. \*/
  494.             ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
  495.           }
  496.         }
  497.         else { /** Activate by pOS_ActivateGadget() **/
  498.  
  499. /*\
  500. *** GCLMTHR_Activate => Gadget gets the focus
  501. *** GCLMTHR_AbortIE  => InputEvent is done, no other should see it.
  502. ***
  503. *** IEGUCODE_Active  => Shows the applicaten the new state
  504. \*/
  505.  
  506.           gb_ExampleLibBase->amg_StoreFac=obj->ed_Fac;
  507.  
  508.           mth->imth_U.imth_GoActive.imac_ResCode=IEGUCODE_Active; /* => IDCMP_GadgetDown im_Code */
  509.           ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
  510.         }
  511.       }
  512.  
  513. /*\
  514. *** Note:
  515. *** If 'imac_NextActGad' is set, the OS will be activate the imac_NextActGad gadget.
  516. ***   The result must be 'GCLMTHR_None'.
  517. \*/
  518.       break;
  519.  
  520.  
  521.  
  522. // -----
  523.     case GCLMTH_HandleInput: /* is gadget active => all IE passed to this method */
  524.       {
  525.         const struct pOS_IClassInfo *const ICI=mth->imth_U.imth_HandleInput.imhi_Info;
  526.         const struct pOS_InputEvent *const IE =mth->imth_U.imth_HandleInput.imhi_IE;
  527.         struct pOS_Rectangle Rect,KnobRect;
  528.  
  529.         mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Active; /* => IDCMP_GadgetDown im_Code */
  530.  
  531.         if(IE->ie_Class == IECLASS_RAWMOUSE) {
  532.           if(IE->ie_Code == (IECODE_LBUTTON | IECODE_UP_PREFIX) ) {
  533.  
  534. /*\
  535. *** Left mouse up => finish the edit.
  536. *** GCLMTHR_InputDone    => cause IDCMP_GadgetUp and finish the event-loop
  537. *** GCLMTHR_UpdateGadget => cause IDCMP_UpdateGadget
  538. \*/
  539.             pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, FALSE, TAG_END);
  540.             Render(cl,obj,ICI,GCLMTHRE_Toggle);
  541.  
  542.             mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Ok; /* => IDCMP_GadgetUp im_Code */
  543.             ret=GCLMTHR_Activate | GCLMTHR_AbortIE | GCLMTHR_InputDone;
  544.           }
  545.  
  546.  
  547. /*\
  548. *** Only when the gadget is selected, do handle mouse-moves.
  549. \*/
  550.           else if(   IE->ie_Code == IECODE_NOBUTTON
  551.                   && pOS_GetAbsObjectData(cl,obj,ICLTAG_Selected))
  552.           {
  553.             struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
  554.             const struct pOS_Point *const AP=mth->imth_U.imth_HandleInput.imhi_AMouse;
  555.             SLONG DeltaX=AP->X - gb_ExampleLibBase->amg_StartMouse.X;
  556.             SLONG DeltaY=AP->Y - gb_ExampleLibBase->amg_StartMouse.Y;
  557.             SLONG Fac,FacX,FacY;
  558.  
  559.             pOS_CalcGadgetInnerBox(ICI->ici_Window,Gad,&Rect);
  560.             CalcKnobRect(&Rect,&KnobRect);
  561.  
  562.             FacX = 2*0xffff*DeltaX/(KnobRect.MaxX - KnobRect.MinX + 1);
  563.             FacY = 2*0xffff*DeltaY/(KnobRect.MaxY - KnobRect.MinY + 1);
  564.  
  565.             Fac=MAX(FacX,FacY);
  566.             if     (gb_ExampleLibBase->amg_StoreFac+Fac > 0xffff) Fac=0xffff;
  567.             else if(gb_ExampleLibBase->amg_StoreFac+Fac < 0)      Fac=0;
  568.             else Fac+=gb_ExampleLibBase->amg_StoreFac;
  569.  
  570.             if(obj->ed_Fac != Fac) {
  571.               obj->ed_Fac = Fac;
  572.               Render(cl,obj,ICI,GCLMTHRE_Update);
  573.  
  574.               mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Scroll; /* => IDCMP_UpdateGadget im_Code */
  575.               ret=GCLMTHR_Activate | GCLMTHR_AbortIE | GCLMTHR_UpdateGadget;
  576.             }
  577.             else {
  578.               ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
  579.             }
  580.           }
  581.         }
  582.  
  583.         else if(IE->ie_Class==IECLASS_RAWKEY) {
  584.           ret=pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
  585.  
  586. /*\
  587. *** Has the basis-class a TAB-Cycle detected, no other handling needed.
  588. \*/
  589.           if( !(ret & (GCLMTHR_NextActive | GCLMTHR_PrevActive)) ) {
  590.             UWORD Fac=obj->ed_Fac;
  591.             UBYTE Buffer[4],Len;
  592.  
  593.             Len=pOS_RawKeyConvert(IE,Buffer,sizeof(Buffer));
  594.             if(Len==1) {
  595.               if(Buffer[0]==13) { /* CR */
  596.                 mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Ok; /* => IDCMP_GadgetUp im_Code */
  597.                 ret |= GCLMTHR_InputDone;
  598.               }
  599.               else if(Buffer[0]==27) { /* ESC */
  600.                 Fac=gb_ExampleLibBase->amg_StoreFac;
  601. /*\
  602. *** Gadget left the focus by set GCLMTHR_InputDone and clear GCLMTHR_Activate.
  603. *** No IDCMP_GadgetUp would be sended.
  604. \*/
  605.                 ret &= ~GCLMTHR_Activate; ret |= GCLMTHR_InputDone;
  606.               }
  607.             }
  608.             else if(Len==2 && Buffer[0]==0x9b) {
  609.               if(Buffer[1]=='D') { /* Cursor left */
  610.                 if(Fac>0xc0) Fac-=0xc0;
  611.                 else         Fac=0;
  612.               }
  613.               else if(Buffer[1]=='C') { /* Cursor right */
  614.                 if(Fac<0xffff-0xc0) Fac+=0xc0;
  615.                 else                Fac=0xffff;
  616.               }
  617.             }
  618.  
  619.             if(Fac != obj->ed_Fac) {
  620.               obj->ed_Fac=Fac;
  621.               Render(cl,obj,ICI,GCLMTHRE_Update);
  622.  
  623.               mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Scroll; /* => IDCMP_UpdateGadget im_Code */
  624.               ret |= GCLMTHR_UpdateGadget;
  625.             }
  626.           }
  627.         }
  628.  
  629.  
  630. /*\
  631. *** All other events pass through the system. The gadget shall be activate stay.
  632. \*/
  633.         else {
  634.           ret=GCLMTHR_Activate;
  635.         }
  636.       }
  637.       break;
  638.  
  639.  
  640. // -----
  641.     case GCLMTH_GoInactive: /* by activate another gadget or none gadget or pOS_InactivateGadget() */
  642.       pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, FALSE, TAG_END);
  643.       Render(cl,obj,mth->imth_U.imth_GoInactive.imia_Info,GCLMTHRE_Toggle);
  644.       mth->imth_U.imth_GoInactive.imia_ResCode=IEGUCODE_Unknown;
  645.       ret=GCLMTHR_None;
  646.       break;
  647.  
  648.  
  649. // -----
  650.     case GCLMTH_Abort: /* by right-mousebotton or other exlicit abort */
  651.       if(gb_ExampleLibBase->amg_StoreFac != obj->ed_Fac) {
  652.         obj->ed_Fac=gb_ExampleLibBase->amg_StoreFac;
  653.         Render(cl,obj,mth->imth_U.imth_Abort.imab_Info,GCLMTHRE_Update);
  654.         mth->imth_U.imth_Abort.imab_ResCode=IEGUCODE_Scroll; /* => IDCMP_AbortGadget im_Code */
  655.         ret=GCLMTHR_AbortIE | GCLMTHR_UpdateGadget;
  656.       }
  657.       else {
  658.         ret=GCLMTHR_AbortIE;
  659.       }
  660.       pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, FALSE, TAG_END);
  661.       Render(cl,obj,mth->imth_U.imth_Abort.imab_Info,GCLMTHRE_Toggle);
  662.       break;
  663.  
  664.  
  665.  
  666.  
  667. // -----
  668.     case GCLMTH_BeginDrag: /* by drag-key (mouse-left + ctrl || mouse-middle) */
  669.       {
  670.         struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
  671.         const struct pOS_IClassInfo *const ICI=mth->imth_U.imth_BDrag.imbd_Info;
  672.         const UWORD *const Pens=ICI->ici_DrawInfo->dri_Pens;
  673.         SWORD Dis=ICI->ici_DrawInfo->dri_Font->tf_YSize;
  674.         UBYTE Buffer[12];
  675.  
  676. /*\
  677. *** Set drag mouse-pointer offset.
  678. \*/
  679.         if(mth->imth_U.imth_BDrag.imbd_Offset) {
  680.           mth->imth_U.imth_BDrag.imbd_Offset->X=Dis;
  681.           mth->imth_U.imth_BDrag.imbd_Offset->Y=Dis+6;
  682.         }
  683.  
  684. /*\
  685. *** In a multitasking system it is no safety, that the value is constant
  686. *** for a long time. We must remember the value.
  687. \*/
  688.         obj->ed_DragFac=obj->ed_Fac;
  689.         pOS_SPrintf(Buffer,"%ld%%",obj->ed_DragFac*100/0xffff);
  690.  
  691.  
  692.  
  693. /*\
  694. *** Create drag-object.
  695. *** DRAGTAG_DeleteRender => the system will dispose DRAGTAG_Render-object
  696. *** DRAGTAG_GadDrag      => List of Drag-Attributs (ICLTAG_AddDragAttName)
  697. *** DRAGTAG_Render       => this object will be viewed
  698. \*/
  699.         mth->imth_U.imth_BDrag.imbd_Result=pOS_CreateDrag(
  700.            DRAGTAG_LeftEdge,  (ULONG)mth->imth_U.imth_BDrag.imbd_AMouse->X-Dis,
  701.            DRAGTAG_TopEdge,   (ULONG)mth->imth_U.imth_BDrag.imbd_AMouse->Y-Dis-6,
  702.            DRAGTAG_GadDrag,   (ULONG)Gad->gad_Drag,
  703.            DRAGTAG_DeleteRender,TRUE,
  704.            DRAGTAG_Render,    (ULONG)pOS_NewIObject(NULL,"itext.class",0,
  705.               ICLTAG_DrawInfo,      (ULONG)ICI->ici_DrawInfo,
  706.               IOBJTAG_FGPen,        Pens[SCRPEN_Text],
  707.               IOBJTAG_FGSelPen,     Pens[SCRPEN_FillText],
  708.               IOBJTAG_String,       (ULONG)Buffer,
  709.               TAG_END),
  710.            TAG_END);
  711.       }
  712.       ret=GCLMTHR_Activate; /* Ok */
  713.       break;
  714.  
  715.  
  716.  
  717.  
  718. /*\
  719. *** The drag is done, the system needs a object to transmit the datas.
  720. ***
  721. *** Note:
  722. *** GCLMTH_GetQuickDropObject runs in the input.device task and must be very
  723. *** fast.
  724. ***
  725. *** GCLMTH_GetDropObject run on the drag-applicaten process.
  726. \*/
  727. // -----
  728.     case GCLMTH_GetQuickDropObject:
  729.     case GCLMTH_GetDropObject:
  730.       {
  731.         struct pOS_DtTypeAscii DT;
  732.         struct pOS_DClassInfo  DC={pOS_DTFORM_ASCII,NULL,DCLINFOF_None,&DT};
  733.         UBYTE Buffer[12];
  734.  
  735.         pOS_SPrintf(Buffer,"%ld%%",obj->ed_DragFac*100/0xffff);
  736.         DT.dtasc_Buffer =Buffer;
  737.         DT.dtasc_BufSize=strlen(Buffer);
  738.         mth->imth_U.imth_GetQObj.imgqo_Result=
  739.             pOS_CreateDTObjectA(NULL,pOS_DTNAME_ASCII,0,&DC,DCLMTH_Save,NULL);
  740.         ret=GCLMTHR_Activate; /* Ok */
  741.       }
  742.       break;
  743.  
  744.  
  745.  
  746. /*\
  747. *** The has dropped  a object over the gadget.
  748. \*/
  749. // -----
  750.     case GCLMTH_SetDropObject:
  751.       {
  752.         struct pOS_DtTypeAscii DT;
  753.         struct pOS_DClassInfo  DC={pOS_DTFORM_ASCII,NULL,DCLINFOF_None,&DT};
  754.         UBYTE Buffer[12];
  755.  
  756.         DT.dtasc_Buffer =Buffer;
  757.         DT.dtasc_BufSize=sizeof(Buffer);
  758.         pOS_LoadDTObjectA(mth->imth_U.imth_SetObj.imso_Object,&DC,NULL);
  759.         if(DC.dci_Result>0) {
  760.           Buffer[DC.dci_Result]='\0'; /* termination */
  761.           obj->ed_Fac=atoi(Buffer)*0xffff/100;
  762.           Render(cl,obj,mth->imth_U.imth_SetObj.imso_Info,GCLMTHRE_Update);
  763.         }
  764. /*\
  765. *** Same do like mouse-input.
  766. *** Cause a IDCMP_GadgetUp
  767. \*/
  768.         ret=GCLMTHR_InputDone | GCLMTHR_Activate;
  769.       }
  770.       break;
  771.  
  772.  
  773.  
  774. // -----
  775.     case GCLMTH_Msg: /* by pOS_SysIMessage() */
  776.       {
  777.         struct pOS_IntuiMessage *const Msg=mth->imth_U.imth_Msg.immg_Msg;
  778.  
  779. /*\
  780. *** The applicaten must call pOS_SysIMessage().
  781. *** And all IDCMP-Messages would be passed througt the gadget.
  782. ***
  783. *** GCLMTHR_DoneMsg => the message is done and no other gadget should see it.
  784. \*/
  785.         if(Msg->im_Class == IDCMP_VanillaKey) {
  786.           if(Msg->im_Code == 'f') { /* set to full */
  787.             obj->ed_Fac=0xffff;
  788.             Render(cl,obj,mth->imth_U.imth_Msg.immg_Info,GCLMTHRE_Update);
  789.             ret = GCLMTHR_DoneMsg;
  790.           }
  791.           else if(Msg->im_Code == 'e') { /* set to empty */
  792.             obj->ed_Fac=0;
  793.             Render(cl,obj,mth->imth_U.imth_Msg.immg_Info,GCLMTHRE_Update);
  794.             ret = GCLMTHR_DoneMsg;
  795.           }
  796.           else if(Msg->im_Code == 'm') { /* set to middle */
  797.             obj->ed_Fac=0x7fff;
  798.             Render(cl,obj,mth->imth_U.imth_Msg.immg_Info,GCLMTHRE_Update);
  799.             ret = GCLMTHR_DoneMsg;
  800.           }
  801.         }
  802.  
  803. /*\
  804. *** Note:
  805. *** If this message not for us, alwasy call the basis-class method.
  806. \*/
  807.         if(ret==0) ret=pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
  808.       }
  809.       break;
  810.  
  811.  
  812.  
  813. /*\
  814. *** Optional:
  815. ***
  816. *** case GCLMTH_Add:   the gadget would be added to the window and is visible
  817. *** case GCLMTH_Rem:   the gadget would be removed from the window and is invisible
  818. *** case GCLMTH_HitTest: check the mouseclick, is it in my gadget => GCLMTHR_GadgetHit
  819. *** case GCLMTH_WinBorder: gadget must 'or' the filled region
  820. *** case GCLMTH_EndDrag:   end of drag, basic-class can handle it ;-)
  821. *** case GCLMTH_DropTest:  check the drop, is it in the gadget-bounds => GCLMTHR_DropHit
  822. *** case GCLMTH_DragTest:  check, is a drag possible => GCLMTHR_DragHit
  823. ***
  824. \*/
  825.  
  826. // -----
  827.     case ICLMTH_Dispose: /* last method by pOS_DisposeIObject() */
  828.       /** other own **/
  829.       pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
  830.       break;
  831.  
  832.     default: ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
  833.   }
  834.  
  835.   return(ret);
  836. }
  837.  
  838.  
  839. /*******************************************************************************/
  840.  
  841.  
  842. /*----------------------------------
  843. -----------------------------------*/
  844. BOOL pLibMain(_R_LB struct pOS_ExecBase* exec,_R_A0 struct ExampleGadLib* lib)
  845. {
  846. #ifdef __pOS_EXECPRECODE
  847.   extern struct pOS_ExecBase* gb_ExecBase;
  848.   extern struct pOS_ExecLibFunction* gb_ExecLib;
  849.  
  850.   gb_ExecBase=(struct pOS_ExecBase*)exec;
  851.   gb_ExecLib=*((struct pOS_ExecLibFunction**)lib->amg_Lib.lib_Segm->sel_Seg.seg_Reserved2);
  852. #endif
  853.  
  854.   gb_UtilityBase=(struct pOS_UtilityBase*)pOS_OpenLibrary("pUtility.library",0);
  855.   gb_GadgetBase=(struct pOS_GadgetBase*)pOS_OpenLibrary("pGadget.library",0);
  856.   gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pGraphics.library",0);
  857.   gb_ConsoleBase=(struct pOS_ConsoleDevice*)pOS_OpenLibrary("pConsole.library",0);
  858.   gb_DosBase  =(struct pOS_DosBase*)pOS_OpenLibrary("pDos.library",0);
  859.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pIntui.library",0);
  860.   gb_DtTypeBase=(struct pOS_DataTypeBase*)pOS_OpenLibrary("pDtType.library",0);
  861.  
  862.  
  863.   gb_ExampleLibBase=lib;
  864.  
  865.   lib->amg_CGadClass=
  866.      pOS_CreateClass("Example1Gad.class","gadget.class",NULL,
  867.                      (APTR)pOSp_Example1GadDispatcher,
  868.                      sizeof(struct ExampleDatas),0);
  869.   return(lib->amg_CGadClass!=NULL);
  870. }
  871.  
  872.  
  873.