home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 03 Mar 1997 : hb
-
- $AUT Holger Burkarth
- $DAT >>Exampe1Gad.c<< 03 Mar 1997 09:12:07 - (C) ProDAD
- *******************************************************************/
-
- //##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
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
-
-
- /*\
- *** Test the gadget:
- ***
- *** The 'win' command can load gadgets from libraries.
- ***
- *** Win Example1Gad.library/Example1Gad.class
- ***
- \*/
-
-
-
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Library.h"
- #include "p:pExec/Resident.h"
- #include "p:pExec/Class.h"
- #include "p:pExec/Task.h"
- #include "p:pExec/Diagnos.h"
- #include "p:pExec/TstTags.h"
- #include "p:Device/IEvent.h"
- #include "p:pDOS/Segment.h"
- #include "p:pDOS/DosTags.h"
- #include "p:pGadget/Gadget.h"
- #include "p:pScreen/DrawInfo.h"
- #include "p:pGfx/RastPort.h"
- #include "p:pGFX/Text.h"
- #include "p:pIntui/GClass.h"
- #include "p:pIntui/DragTags.h"
- #include "p:pIntui/IntuMsg.h"
- #include "p:pIntui/Tags.h"
- #include "p:pDtType/Ascii.h"
- #include "p:pDtType/DClass.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pIntui2.h"
- #include "p:proto/pList.h"
- #include "p:proto/pUtil2.h"
- #include "p:proto/pGfx2.h"
- #include "p:proto/pConsole2.h"
- #include "p:proto/pDtType2.h"
- #include "p:proto/pGadget2.h"
-
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_limits.h"
- #include "grund/inc_stdlib.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <limits.h>
- #include <stdlib.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- struct pOS_ExecBase *gb_ExecBase;
- struct pOS_ExecLibFunction *gb_ExecLib;
- struct pOS_DosBase *gb_DosBase;
- struct pOS_IntuiDevice *gb_IntuiBase;
- struct pOS_UtilityBase *gb_UtilityBase;
- struct pOS_GadgetBase *gb_GadgetBase;
- struct pOS_GfxBase *gb_GfxBase;
- struct pOS_ConsoleDevice *gb_ConsoleBase;
- struct pOS_DataTypeBase *gb_DtTypeBase;
-
-
- struct ExampleGadLib
- {
- struct pOS_Library amg_Lib;
- struct pOS_NClass *amg_CGadClass;
-
- struct pOS_Point amg_StartMouse;
- UWORD amg_StoreFac;
- };
-
- struct ExampleGadLib* gb_ExampleLibBase;
-
-
-
- extern ULONG *FuncTable[];
- const CHAR LibraryName[] ="Example1Gad.library";
- const CHAR LibraryIDName[]="Example1Gad.library 1.0 ("__DATE2__")";
-
- const pOS_TagItem LibraryDescribe[]=
- {
- EXTSTTAG_MainOSID, pOS_MAINOSID,
- TAG_END
- };
-
-
- BOOL pLibMain(_R_LB pOS_ExecBase*,_R_A0 ExampleGadLib*);
-
- pOS_ResidentLibInit InitTable=
- {
- sizeof(ExampleGadLib),
- FuncTable,
- NULL,
- (BOOL(*)(_R_LB pOS_ExecBase*,_R_A0 pOS_Library*))pLibMain
- };
-
-
- /*----------------------------------
- Wird in dieser Library nicht benötigt.
- -----------------------------------*/
- BOOL Open_func(_R_LB ExampleGadLib*) { return(1); }
- VOID Close_func(_R_LB ExampleGadLib*) {}
- ULONG Reserved_func(_R_LB ExampleGadLib*) { return(0); }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- pOS_SegmentLst* Expunge_func(_R_LB ExampleGadLib* lib)
- {
- if(lib->amg_Lib.lib_OpenCnt==0) {
- pOS_SegmentLst* Seg=lib->amg_Lib.lib_Segm;
-
- pOS_ListRemove(&lib->amg_Lib.lib_Node);
-
- if(lib->amg_CGadClass) pOS_DeleteClass(lib->amg_CGadClass);
-
- _pOS_FreeLibraryMem2(&lib->amg_Lib);
-
- pOS_CloseLibrary((struct pOS_Library*)gb_GadgetBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_UtilityBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_ConsoleBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_DosBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_DtTypeBase);
- return(Seg);
- }
- return(0);
- }
-
-
- ULONG *FuncTable[]=
- {
- (ULONG*)Open_func,
- (ULONG*)Close_func,
- (ULONG*)Expunge_func,
- // ------------
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- // ------------
-
- (ULONG*)ULONG_MAX
- };
-
-
-
- /*******************************************************************************/
-
- /*----------------------------------
- -----------------------------------*/
- struct ExampleDatas
- {
- UWORD ed_Fac;
-
- UWORD ed_DragFac; /* remember by drag */
- };
-
-
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID GetGadgetLightRect(const struct pOS_Rectangle* rect,const struct ExampleDatas* obj,
- const struct pOS_IClassInfo* ici,struct pOS_Rectangle* resRect)
- {
- resRect->MinX=rect->MaxX; /* full area */
- resRect->MinY=rect->MaxY;
- resRect->MaxX=rect->MaxX;
- resRect->MaxY=rect->MaxY;
- }
-
- /*----------------------------------
- -----------------------------------*/
- VOID CalcKnobRect(const struct pOS_Rectangle* rect,struct pOS_Rectangle* resRect)
- {
- resRect->MinX=rect->MinX+2; /* let 2 pixel space */
- resRect->MinY=rect->MinY+2;
- resRect->MaxX=rect->MaxX-2;
- resRect->MaxY=rect->MaxY-2;
- }
-
- /*----------------------------------
- -----------------------------------*/
- VOID GetGadgetKnobRect(const struct pOS_Rectangle* rect,const struct ExampleDatas* obj,
- const struct pOS_IClassInfo* ici,struct pOS_Rectangle* resRect)
- {
- SLONG Width,Height,MidX,MidY;
-
- CalcKnobRect(rect,resRect);
-
- Width =resRect->MaxX - resRect->MinX+1;
- Height=resRect->MaxY - resRect->MinY+1;
- MidX =resRect->MinX + Width/2;
- MidY =resRect->MinY + Height/2;
-
- Width =Width*obj->ed_Fac /(2*0xffff);
- Height=Height*obj->ed_Fac/(2*0xffff);
-
- resRect->MinX=MidX-Width;
- resRect->MinY=MidY-Height;
- resRect->MaxX=MidX+Width;
- resRect->MaxY=MidY+Height;
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID RenderGadgetGround(struct pOS_RastPort* rp,const struct pOS_Rectangle* rect,
- struct ExampleDatas* obj,const struct pOS_IClassInfo* ici)
- {
- const UWORD *const Pens=ici->ici_DrawInfo->dri_Pens;
-
- pOS_SetAPen(rp,Pens[SCRPEN_GadgetGround]);
- pOS_DrawRectFill(rp,rect->MinX,rect->MinY,rect->MaxX,rect->MaxY);
- }
-
- /*----------------------------------
- -----------------------------------*/
- VOID RenderGadgetKnob(struct pOS_RastPort* rp,const struct pOS_Rectangle* rect,
- struct ExampleDatas* obj,const struct pOS_IClassInfo* ici,
- BOOL selected)
- {
- struct pOS_Rectangle MRect;
- const UWORD *const Pens=ici->ici_DrawInfo->dri_Pens;
-
- pOS_SetAPen(rp,Pens[selected ? SCRPEN_Fill:SCRPEN_GadgetGround]);
- GetGadgetKnobRect(rect,obj,ici,&MRect);
-
- pOS_DrawRectFill(rp,MRect.MinX+1,MRect.MinY+1,MRect.MaxX-1,MRect.MaxY-1);
- pOS_DrawBorderBox(rp,ici->ici_DrawInfo,selected ? GADBORTYP_BevelDownBox:GADBORTYP_BevelUpBox,&MRect);
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID Render(const struct pOS_Class* cl,struct ExampleDatas* obj,
- const struct pOS_IClassInfo* ici,ULONG mode)
- {
- struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
- struct pOS_RastPort *RP;
- struct pOS_Rectangle Rect;
-
- if(RP=pOS_ObtainGRastPort(Gad,ici)) {
- pOS_CalcGadgetInnerBox(ici->ici_Window,Gad,&Rect);
-
- if( mode==GCLMTHRE_Update
- || mode==GCLMTHRE_Redraw)
- {
- RenderGadgetGround(RP,&Rect,obj,ici);
- }
-
- if( mode==GCLMTHRE_Update
- || mode==GCLMTHRE_Toggle
- || mode==GCLMTHRE_Redraw)
- {
- RenderGadgetKnob(RP,&Rect,obj,ici,pOS_GetAbsObjectData(cl,obj,ICLTAG_Selected) );
- }
- pOS_ReleaseGRastPort(ici,RP);
- }
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- ULONG SetTags(const struct pOS_Class* cl,struct ExampleDatas* obj,
- const struct pOS_TagItem* tags,const struct pOS_IClassInfo* ici)
- {
- const struct pOS_TagItem* Tag;
- ULONG Flg=1;
- UBYTE NewDraw=0;
-
- while(Tag=pOS_NextTagItem(&tags)) {
- switch(Tag->ti_Tag) {
-
- case PRGADTAG_VertPot: /* only an example tag */
- if(obj->ed_Fac != Tag->ti_Data) {
- obj->ed_Fac = Tag->ti_Data;
- NewDraw=1;
- }
- break;
-
- }
- }
-
- if(ici && NewDraw) Render(cl,obj,ici,GCLMTHRE_Update);
- return(Flg);
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- BOOL GetTags(struct ExampleDatas* obj,ULONG id,ULONG* Data)
- {
- BOOL Flg=1;
-
- switch(id) {
- case PRGADTAG_VertPot: /* only an example tag */
- *Data=(ULONG)obj->ed_Fac;
- break;
-
- default: Flg=0;
- }
- return(Flg);
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- ULONG pOSp_Example1GadDispatcher(_R_LB struct pOS_ExecBase* exec,
- _R_A0 const struct pOS_Class* cl,
- _R_A1 struct ExampleDatas* obj,
- _R_A2 struct pOS_GadgetMethod* mth)
- {
- ULONG ret=0;
-
- switch(mth->imth_Method) {
-
- case ICLMTH_New: /* first method by pOS_NewIObject() */
- /*\
- *** Default-Datas
- \*/
- pOS_SetAbsObjectData(cl,obj,
- ICLTAG_GadBorderType, GADBORTYP_StrBox | GADBORF_BgOverBorder,
- ICLTAG_TabCycle, TRUE,
- ICLTAG_HighlightFocus, TRUE,
- ICLTAG_HighlightDropBox,TRUE,
- /*\
- *** Define the drag-type. We can drag one line 'ascii' datas.
- *** And the same as drop.
- \*/
- ICLTAG_AddDragAttName, (ULONG)"Example1Gad.class:ascii/line/",
- ICLTAG_AddDropAttName, (ULONG)"#?ascii/line/#?",
-
- /*\
- *** Enable standard-drag/drop methods
- \*/
- ICLTAG_StandardDrag, TRUE,
- ICLTAG_StandardDrop, TRUE,
- TAG_END);
-
-
- obj->ed_Fac=0x4000; /* default */
-
- ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth); /* call Basisclass (SuperClass) */
-
- if(ret!=pOS_CLASSERR) {
- ret=SetTags(cl,obj,mth->imth_U.imth_New.imnw_Tags,NULL);
- }
- break;
-
-
- // -----
- case ICLMTH_Set: /* by pOS_SetGadgetAttrs() or pOS_SetObjectDatas() */
- case ICLMTH_Update: /* Gadget to gadget update */
- pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
- SetTags(cl,obj,mth->imth_U.imth_Set.imst_Tags,mth->imth_U.imth_Set.imst_Info);
- break;
-
-
- // -----
- case ICLMTH_Get: /* by pOS_GetGadgetAttr() or pOS_GetObjctData() */
- if( !(ret=pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth)))
- ret=GetTags(obj,mth->imth_U.imth_Get.imgt_ID,
- mth->imth_U.imth_Get.imgt_Variable);
- break;
-
-
- // -----
- case GCLMTH_Render: /* draw/refresh/update/... */
- Render(cl,obj,mth->imth_U.imth_Render.imre_Info,mth->imth_U.imth_Render.imre_Type);
- pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
- break;
-
- // -----
- case GCLMTH_GetIBox: /* for layouter */
- mth->imth_U.imth_GetIBox.imgb_MinIBox->Width =32;
- mth->imth_U.imth_GetIBox.imgb_MinIBox->Height=32;
- mth->imth_U.imth_GetIBox.imgb_MaxIBox->Width =32000;
- mth->imth_U.imth_GetIBox.imgb_MaxIBox->Height=32000;
- break;
-
-
- // -----
- case GCLMTH_GoActive: /* by mouseclick-left or pOS_ActivateGadget() */
- {
- struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
- struct pOS_Rectangle Rect,KnobRect;
- const struct pOS_IClassInfo *const ICI=mth->imth_U.imth_GoActive.imac_Info;
- const struct pOS_InputEvent *const IE =mth->imth_U.imth_GoActive.imac_IE;
-
- if(IE) { /** Activate comes from user directly (mouse-klick) **/
- const struct pOS_Point *const AP=mth->imth_U.imth_GoActive.imac_AMouse;
-
- /*\
- *** mth->imth_U.imth_GoActive.imac_RMouse => Mousepoint inner gadget
- *** mth->imth_U.imth_GoActive.imac_AMouse => Mousepoint inner window
- ***
- *** pOS_CalcGadgetBox(ICI->ici_Window,Gad,&Rect);
- *** => full gadget bounds (gad_LeftEdge => gad_LeftEdge+gad_Width-1)
- ***
- *** pOS_CalcGadgetInnerBox(ICI->ici_Window,Gad,&Rect);
- *** => gadget bound without gad_BorXX and without gad_Lable-bounds
- \*/
- pOS_CalcGadgetInnerBox(ICI->ici_Window,Gad,&Rect);
- GetGadgetKnobRect(&Rect,obj,ICI,&KnobRect);
-
- if( AP->X >= KnobRect.MinX && AP->X <= KnobRect.MaxX
- && AP->Y >= KnobRect.MinY && AP->Y <= KnobRect.MaxY)
- {
-
- /*\
- *** Mouseclick is in knob-bounds, we can handle the IE.
- *** Store the actual click-position.
- \*/
- gb_ExampleLibBase->amg_StartMouse=*AP;
- gb_ExampleLibBase->amg_StoreFac=obj->ed_Fac;
-
- pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, TRUE, TAG_END);
- Render(cl,obj,ICI,GCLMTHRE_Toggle);
-
- ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
- }
- else {
-
- /*\
- *** Click is not in inner-bounds, still activate.
- \*/
- ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
- }
- }
- else { /** Activate by pOS_ActivateGadget() **/
-
- /*\
- *** GCLMTHR_Activate => Gadget gets the focus
- *** GCLMTHR_AbortIE => InputEvent is done, no other should see it.
- ***
- *** IEGUCODE_Active => Shows the applicaten the new state
- \*/
-
- gb_ExampleLibBase->amg_StoreFac=obj->ed_Fac;
-
- mth->imth_U.imth_GoActive.imac_ResCode=IEGUCODE_Active; /* => IDCMP_GadgetDown im_Code */
- ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
- }
- }
-
- /*\
- *** Note:
- *** If 'imac_NextActGad' is set, the OS will be activate the imac_NextActGad gadget.
- *** The result must be 'GCLMTHR_None'.
- \*/
- break;
-
-
-
- // -----
- case GCLMTH_HandleInput: /* is gadget active => all IE passed to this method */
- {
- const struct pOS_IClassInfo *const ICI=mth->imth_U.imth_HandleInput.imhi_Info;
- const struct pOS_InputEvent *const IE =mth->imth_U.imth_HandleInput.imhi_IE;
- struct pOS_Rectangle Rect,KnobRect;
-
- mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Active; /* => IDCMP_GadgetDown im_Code */
-
- if(IE->ie_Class == IECLASS_RAWMOUSE) {
- if(IE->ie_Code == (IECODE_LBUTTON | IECODE_UP_PREFIX) ) {
-
- /*\
- *** Left mouse up => finish the edit.
- *** GCLMTHR_InputDone => cause IDCMP_GadgetUp and finish the event-loop
- *** GCLMTHR_UpdateGadget => cause IDCMP_UpdateGadget
- \*/
- pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, FALSE, TAG_END);
- Render(cl,obj,ICI,GCLMTHRE_Toggle);
-
- mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Ok; /* => IDCMP_GadgetUp im_Code */
- ret=GCLMTHR_Activate | GCLMTHR_AbortIE | GCLMTHR_InputDone;
- }
-
-
- /*\
- *** Only when the gadget is selected, do handle mouse-moves.
- \*/
- else if( IE->ie_Code == IECODE_NOBUTTON
- && pOS_GetAbsObjectData(cl,obj,ICLTAG_Selected))
- {
- struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
- const struct pOS_Point *const AP=mth->imth_U.imth_HandleInput.imhi_AMouse;
- SLONG DeltaX=AP->X - gb_ExampleLibBase->amg_StartMouse.X;
- SLONG DeltaY=AP->Y - gb_ExampleLibBase->amg_StartMouse.Y;
- SLONG Fac,FacX,FacY;
-
- pOS_CalcGadgetInnerBox(ICI->ici_Window,Gad,&Rect);
- CalcKnobRect(&Rect,&KnobRect);
-
- FacX = 2*0xffff*DeltaX/(KnobRect.MaxX - KnobRect.MinX + 1);
- FacY = 2*0xffff*DeltaY/(KnobRect.MaxY - KnobRect.MinY + 1);
-
- Fac=MAX(FacX,FacY);
- if (gb_ExampleLibBase->amg_StoreFac+Fac > 0xffff) Fac=0xffff;
- else if(gb_ExampleLibBase->amg_StoreFac+Fac < 0) Fac=0;
- else Fac+=gb_ExampleLibBase->amg_StoreFac;
-
- if(obj->ed_Fac != Fac) {
- obj->ed_Fac = Fac;
- Render(cl,obj,ICI,GCLMTHRE_Update);
-
- mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Scroll; /* => IDCMP_UpdateGadget im_Code */
- ret=GCLMTHR_Activate | GCLMTHR_AbortIE | GCLMTHR_UpdateGadget;
- }
- else {
- ret=GCLMTHR_Activate | GCLMTHR_AbortIE;
- }
- }
- }
-
- else if(IE->ie_Class==IECLASS_RAWKEY) {
- ret=pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
-
- /*\
- *** Has the basis-class a TAB-Cycle detected, no other handling needed.
- \*/
- if( !(ret & (GCLMTHR_NextActive | GCLMTHR_PrevActive)) ) {
- UWORD Fac=obj->ed_Fac;
- UBYTE Buffer[4],Len;
-
- Len=pOS_RawKeyConvert(IE,Buffer,sizeof(Buffer));
- if(Len==1) {
- if(Buffer[0]==13) { /* CR */
- mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Ok; /* => IDCMP_GadgetUp im_Code */
- ret |= GCLMTHR_InputDone;
- }
- else if(Buffer[0]==27) { /* ESC */
- Fac=gb_ExampleLibBase->amg_StoreFac;
- /*\
- *** Gadget left the focus by set GCLMTHR_InputDone and clear GCLMTHR_Activate.
- *** No IDCMP_GadgetUp would be sended.
- \*/
- ret &= ~GCLMTHR_Activate; ret |= GCLMTHR_InputDone;
- }
- }
- else if(Len==2 && Buffer[0]==0x9b) {
- if(Buffer[1]=='D') { /* Cursor left */
- if(Fac>0xc0) Fac-=0xc0;
- else Fac=0;
- }
- else if(Buffer[1]=='C') { /* Cursor right */
- if(Fac<0xffff-0xc0) Fac+=0xc0;
- else Fac=0xffff;
- }
- }
-
- if(Fac != obj->ed_Fac) {
- obj->ed_Fac=Fac;
- Render(cl,obj,ICI,GCLMTHRE_Update);
-
- mth->imth_U.imth_HandleInput.imhi_ResCode=IEGUCODE_Scroll; /* => IDCMP_UpdateGadget im_Code */
- ret |= GCLMTHR_UpdateGadget;
- }
- }
- }
-
-
- /*\
- *** All other events pass through the system. The gadget shall be activate stay.
- \*/
- else {
- ret=GCLMTHR_Activate;
- }
- }
- break;
-
-
- // -----
- case GCLMTH_GoInactive: /* by activate another gadget or none gadget or pOS_InactivateGadget() */
- pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, FALSE, TAG_END);
- Render(cl,obj,mth->imth_U.imth_GoInactive.imia_Info,GCLMTHRE_Toggle);
- mth->imth_U.imth_GoInactive.imia_ResCode=IEGUCODE_Unknown;
- ret=GCLMTHR_None;
- break;
-
-
- // -----
- case GCLMTH_Abort: /* by right-mousebotton or other exlicit abort */
- if(gb_ExampleLibBase->amg_StoreFac != obj->ed_Fac) {
- obj->ed_Fac=gb_ExampleLibBase->amg_StoreFac;
- Render(cl,obj,mth->imth_U.imth_Abort.imab_Info,GCLMTHRE_Update);
- mth->imth_U.imth_Abort.imab_ResCode=IEGUCODE_Scroll; /* => IDCMP_AbortGadget im_Code */
- ret=GCLMTHR_AbortIE | GCLMTHR_UpdateGadget;
- }
- else {
- ret=GCLMTHR_AbortIE;
- }
- pOS_SetAbsObjectData(cl,obj,ICLTAG_Selected, FALSE, TAG_END);
- Render(cl,obj,mth->imth_U.imth_Abort.imab_Info,GCLMTHRE_Toggle);
- break;
-
-
-
-
- // -----
- case GCLMTH_BeginDrag: /* by drag-key (mouse-left + ctrl || mouse-middle) */
- {
- struct pOS_Gadget *const Gad=(struct pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
- const struct pOS_IClassInfo *const ICI=mth->imth_U.imth_BDrag.imbd_Info;
- const UWORD *const Pens=ICI->ici_DrawInfo->dri_Pens;
- SWORD Dis=ICI->ici_DrawInfo->dri_Font->tf_YSize;
- UBYTE Buffer[12];
-
- /*\
- *** Set drag mouse-pointer offset.
- \*/
- if(mth->imth_U.imth_BDrag.imbd_Offset) {
- mth->imth_U.imth_BDrag.imbd_Offset->X=Dis;
- mth->imth_U.imth_BDrag.imbd_Offset->Y=Dis+6;
- }
-
- /*\
- *** In a multitasking system it is no safety, that the value is constant
- *** for a long time. We must remember the value.
- \*/
- obj->ed_DragFac=obj->ed_Fac;
- pOS_SPrintf(Buffer,"%ld%%",obj->ed_DragFac*100/0xffff);
-
-
-
- /*\
- *** Create drag-object.
- *** DRAGTAG_DeleteRender => the system will dispose DRAGTAG_Render-object
- *** DRAGTAG_GadDrag => List of Drag-Attributs (ICLTAG_AddDragAttName)
- *** DRAGTAG_Render => this object will be viewed
- \*/
- mth->imth_U.imth_BDrag.imbd_Result=pOS_CreateDrag(
- DRAGTAG_LeftEdge, (ULONG)mth->imth_U.imth_BDrag.imbd_AMouse->X-Dis,
- DRAGTAG_TopEdge, (ULONG)mth->imth_U.imth_BDrag.imbd_AMouse->Y-Dis-6,
- DRAGTAG_GadDrag, (ULONG)Gad->gad_Drag,
- DRAGTAG_DeleteRender,TRUE,
- DRAGTAG_Render, (ULONG)pOS_NewIObject(NULL,"itext.class",0,
- ICLTAG_DrawInfo, (ULONG)ICI->ici_DrawInfo,
- IOBJTAG_FGPen, Pens[SCRPEN_Text],
- IOBJTAG_FGSelPen, Pens[SCRPEN_FillText],
- IOBJTAG_String, (ULONG)Buffer,
- TAG_END),
- TAG_END);
- }
- ret=GCLMTHR_Activate; /* Ok */
- break;
-
-
-
-
- /*\
- *** The drag is done, the system needs a object to transmit the datas.
- ***
- *** Note:
- *** GCLMTH_GetQuickDropObject runs in the input.device task and must be very
- *** fast.
- ***
- *** GCLMTH_GetDropObject run on the drag-applicaten process.
- \*/
- // -----
- case GCLMTH_GetQuickDropObject:
- case GCLMTH_GetDropObject:
- {
- struct pOS_DtTypeAscii DT;
- struct pOS_DClassInfo DC={pOS_DTFORM_ASCII,NULL,DCLINFOF_None,&DT};
- UBYTE Buffer[12];
-
- pOS_SPrintf(Buffer,"%ld%%",obj->ed_DragFac*100/0xffff);
- DT.dtasc_Buffer =Buffer;
- DT.dtasc_BufSize=strlen(Buffer);
- mth->imth_U.imth_GetQObj.imgqo_Result=
- pOS_CreateDTObjectA(NULL,pOS_DTNAME_ASCII,0,&DC,DCLMTH_Save,NULL);
- ret=GCLMTHR_Activate; /* Ok */
- }
- break;
-
-
-
- /*\
- *** The has dropped a object over the gadget.
- \*/
- // -----
- case GCLMTH_SetDropObject:
- {
- struct pOS_DtTypeAscii DT;
- struct pOS_DClassInfo DC={pOS_DTFORM_ASCII,NULL,DCLINFOF_None,&DT};
- UBYTE Buffer[12];
-
- DT.dtasc_Buffer =Buffer;
- DT.dtasc_BufSize=sizeof(Buffer);
- pOS_LoadDTObjectA(mth->imth_U.imth_SetObj.imso_Object,&DC,NULL);
- if(DC.dci_Result>0) {
- Buffer[DC.dci_Result]='\0'; /* termination */
- obj->ed_Fac=atoi(Buffer)*0xffff/100;
- Render(cl,obj,mth->imth_U.imth_SetObj.imso_Info,GCLMTHRE_Update);
- }
- /*\
- *** Same do like mouse-input.
- *** Cause a IDCMP_GadgetUp
- \*/
- ret=GCLMTHR_InputDone | GCLMTHR_Activate;
- }
- break;
-
-
-
- // -----
- case GCLMTH_Msg: /* by pOS_SysIMessage() */
- {
- struct pOS_IntuiMessage *const Msg=mth->imth_U.imth_Msg.immg_Msg;
-
- /*\
- *** The applicaten must call pOS_SysIMessage().
- *** And all IDCMP-Messages would be passed througt the gadget.
- ***
- *** GCLMTHR_DoneMsg => the message is done and no other gadget should see it.
- \*/
- if(Msg->im_Class == IDCMP_VanillaKey) {
- if(Msg->im_Code == 'f') { /* set to full */
- obj->ed_Fac=0xffff;
- Render(cl,obj,mth->imth_U.imth_Msg.immg_Info,GCLMTHRE_Update);
- ret = GCLMTHR_DoneMsg;
- }
- else if(Msg->im_Code == 'e') { /* set to empty */
- obj->ed_Fac=0;
- Render(cl,obj,mth->imth_U.imth_Msg.immg_Info,GCLMTHRE_Update);
- ret = GCLMTHR_DoneMsg;
- }
- else if(Msg->im_Code == 'm') { /* set to middle */
- obj->ed_Fac=0x7fff;
- Render(cl,obj,mth->imth_U.imth_Msg.immg_Info,GCLMTHRE_Update);
- ret = GCLMTHR_DoneMsg;
- }
- }
-
- /*\
- *** Note:
- *** If this message not for us, alwasy call the basis-class method.
- \*/
- if(ret==0) ret=pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
- }
- break;
-
-
-
- /*\
- *** Optional:
- ***
- *** case GCLMTH_Add: the gadget would be added to the window and is visible
- *** case GCLMTH_Rem: the gadget would be removed from the window and is invisible
- *** case GCLMTH_HitTest: check the mouseclick, is it in my gadget => GCLMTHR_GadgetHit
- *** case GCLMTH_WinBorder: gadget must 'or' the filled region
- *** case GCLMTH_EndDrag: end of drag, basic-class can handle it ;-)
- *** case GCLMTH_DropTest: check the drop, is it in the gadget-bounds => GCLMTHR_DropHit
- *** case GCLMTH_DragTest: check, is a drag possible => GCLMTHR_DragHit
- ***
- \*/
-
- // -----
- case ICLMTH_Dispose: /* last method by pOS_DisposeIObject() */
- /** other own **/
- pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)mth);
- break;
-
- default: ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
- }
-
- return(ret);
- }
-
-
- /*******************************************************************************/
-
-
- /*----------------------------------
- -----------------------------------*/
- BOOL pLibMain(_R_LB struct pOS_ExecBase* exec,_R_A0 struct ExampleGadLib* lib)
- {
- #ifdef __pOS_EXECPRECODE
- extern struct pOS_ExecBase* gb_ExecBase;
- extern struct pOS_ExecLibFunction* gb_ExecLib;
-
- gb_ExecBase=(struct pOS_ExecBase*)exec;
- gb_ExecLib=*((struct pOS_ExecLibFunction**)lib->amg_Lib.lib_Segm->sel_Seg.seg_Reserved2);
- #endif
-
- gb_UtilityBase=(struct pOS_UtilityBase*)pOS_OpenLibrary("pUtility.library",0);
- gb_GadgetBase=(struct pOS_GadgetBase*)pOS_OpenLibrary("pGadget.library",0);
- gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pGraphics.library",0);
- gb_ConsoleBase=(struct pOS_ConsoleDevice*)pOS_OpenLibrary("pConsole.library",0);
- gb_DosBase =(struct pOS_DosBase*)pOS_OpenLibrary("pDos.library",0);
- gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pIntui.library",0);
- gb_DtTypeBase=(struct pOS_DataTypeBase*)pOS_OpenLibrary("pDtType.library",0);
-
-
- gb_ExampleLibBase=lib;
-
- lib->amg_CGadClass=
- pOS_CreateClass("Example1Gad.class","gadget.class",NULL,
- (APTR)pOSp_Example1GadDispatcher,
- sizeof(struct ExampleDatas),0);
- return(lib->amg_CGadClass!=NULL);
- }
-
-
-