(****************************************************************************

$RCSfile: GUIEnvD.def $

$Revision: 1.1 $
    $Date: 1994/07/26 18:28:33 $

    All type and const definition for GUIEnvironment V37.0

    M2Amiga Modula-2 Compiler V4.3

  Copyright © 1994, Carsten Ziegeler
                    Augustin-Wibbelt-Str.7, 33106 Paderborn, Germany

****************************************************************************)
DEFINITION MODULE GUIEnvD; (*$ Implementation:=FALSE *)

  FROM SYSTEM     IMPORT ADDRESS, BITSET, WORD;
  FROM GadToolsD  IMPORT NewMenu, NewGadget;
  FROM ExecD      IMPORT MsgPortPtr;
  FROM GraphicsD  IMPORT TextAttr, TextAttrPtr;
  FROM IntuitionD IMPORT IDCMPFlagSet, ScreenPtr, WindowPtr, GadgetPtr,
                         MenuPtr, DrawInfoPtr, IntuiMessagePtr,
                         MenuItemPtr, Gadget, IntuiText;
  FROM LocaleD    IMPORT CatalogPtr, LocalePtr;
  FROM UtilityD   IMPORT TagItemPtr, tagUser;
IMPORT R;

(* ----------------------------- PRIVATE --------------------------------- *)
(* ------------------------- DO NOT USE THEM ----------------------------- *)

TYPE
  DistanceFlags = (abs, rel, gadget, unused1, unused2, obLeftTop,
                   unused3, unused4);
  DistanceFlagSet = SET OF DistanceFlags;

  STRPTR = POINTER TO ARRAY[0..255] OF CHAR;
  LINTPTR= POINTER TO LONGINT;
  INTPTR = POINTER TO INTEGER;
  CARDPTR= POINTER TO CARDINAL;
  BOOLPTR= POINTER TO BOOLEAN;
  DISTFIELD = ARRAY[0..3] OF DistanceFlagSet;
  GADOFIELD = ARRAY[0..3] OF SHORTCARD;


CONST lvNotSel = 65535;
      noKeyEqu = -1;

      (* GUIInfo status flags - 16 Bit *)

      gadgetsSet = 0;
      menuSet    = 1;
      spezialGadsNoText = 2;
      chainGadgets = 3;


      GUIENVGADSIZE = SIZE(Gadget) + SIZE(IntuiText);

      MAXGADS = 256;
      MAXMENUS= 256;

(* --------------------------- END PRIVATE ------------------------------- *)




(* ======================================================================= *)
(*                               Error codes                               *)
(* ======================================================================= *)

CONST

  geDone             =   0;   (* no error, everything done *)
  geMemoryErr        =   1;   (* not enough memory *)
  geWindowErr        =   2;   (* no window specified *)
  geVisualInfoErr    =   3;   (* couldn't get VisualInfo *)
  geDrawInfoErr      =   4;   (* couldn't get DrawInfo *)

  geGadContextErr    = 100;   (* GadTools CreateContext failed *)
  geGadCreateErr     = 101;   (* error calling CreateGadget/NewObject *)
  geGadTooManyErr    = 102;   (* more than 256 gadgets *)
  geGadKeyTwiceErr   = 102;   (* same key equivalent for two gadgets *)
  geGadUnknownKind   = 104;   (* unknown gadget kind *)
  geGadChainErr      = 105;   (* ChainStart/ChainEnd missing *)
  geGadHookErr       = 106;   (* Hook function failed *)

  geMenuCreateErr    = 200;   (* error calling CreateMenu *)
  geMenuStripErr     = 201;   (* error calling SetMenuStrip *)
  geMenuLayoutErr    = 202;   (* error calling LayoutMenus *)
  geMenuTooManyErr   = 203;   (* more than 256 menu items *)


(* ======================================================================= *)
(*                         GE Hook functions                               *)
(* ======================================================================= *)

(* The GUIEnvironment hook functions:
   - Before a hook functions is called, the A4 register is set
   - Every hook functions gets in A0 a pointer to the GUIInfo structure
   - There are different hook functions with differen parameters and
     also different return values.
*)

(* ------------------------ return values -------------------------------- *)

  gehKeyShifted  = 512;
  gehKeyUnknown  = -1;

(* ------------------------ The hook functions --------------------------- *)

TYPE

         GED0LHOOK = PROCEDURE(ADDRESS{8}, CHAR{0}) : LONGINT;

                     (* Hook function for key equivalents:
                        D0     : character
                        RESULT : gehKeyUnknown if the key is not a key
                                 equivalent or the number of the gadget,
                                 or the number of the gadget plus
                                 gehKeyShifted !
                      *)

         GEHOOK    = PROCEDURE(ADDRESS{8}) : BOOLEAN;

                     (* Handle message hook & refreshing hook *)

         GEA1HOOK  = PROCEDURE(ADDRESS{8}, ADDRESS{9}) : BOOLEAN;

                     (* Event message hooks:

                         - gadget event message
                           A1 : pointer to gadget

                         - menu event message
                           A1 : pointer to menu item (if possible)

                         If you want to wait for further messages return
                         TRUE, otherwise FALSE to exit the message-loop.


                        Gadget creation hook
                          A1 : pointer to the gadget
                      *)


(* ======================================================================= *)
(*                               Gadgets                                   *)
(* ======================================================================= *)

CONST
(* ----------------------- gadget kinds ---------------------------------- *)

  gegKinds                 =  65535; (* GUIEnv gadgets *)
  gegProgressIndicatorKind =  65536;
  gegBevelboxKind          =  65537;
  gegBorderKind            =  65538;

  gegBOOPSIKinds           = 131071; (* BOOPSI gadgets *)
  gegBOOPSIPublicKind      = 131072;
  gegBOOPSIPrivateKind     = 131073;

(* ----------------------- gadget chain flags ---------------------------- *)

TYPE
  GEGChainFlags = (gegChainUpNext, gegChainUpPrev, gegChainDownNext,
                   gegChainDownPrev, gengcf4, gengcf5, gengcf6,
                   gengcf7, gengcf8);

  GEGChainFlagSet = SET OF GEGChainFlags;  (* 16 bits *)

(* ----------------------- gadget description flags ---------------------- *)

CONST
  gegDistNorm    =  0;  (* Normal distance *)
  gegDistAbs     =  1;  (* absolute distance from an object *)
  gegDistRel     =  2;  (* relative distance from an object *)
  gegDistPercent =  3;  (* percentual distance *)

  gegObjBorder   =  0;  (* window border *)
  gegObjGadget   =  4;  (* gadget (standard is previous gadget) *)

  gegObjRight    =  0;  (* distance from which part of the object *)
  gegObjBottom   =  0;
  gegObjLeft     = 32;
  gegObjTop      = 32;

(* ----------------------- gadget tag values ----------------------------- *)

  gegACTIVATIONUP  =  0;
  gegACTIVATIONDOWN=  1;


  gegALLGADGETS    = -1;

(* ----------------------- gadget tags ----------------------------------- *)

  gegBase = tagUser + 016000H;
  gegText            = gegBase +  1;
  gegFlags           = gegBase +  2;
  gegFont            = gegBase +  3;
  gegUserData        = gegBase +  4;
  gegDescription     = gegBase +  5;
  gegObjects         = gegBase +  6;
  gegGuideNode       = gegBase +  7;
  gegFunctionUp      = gegBase +  8;
  gegFunctionDown    = gegBase +  9;
  gegCatalogString   = gegBase + 10;
  gegClass           = gegBase + 11;
  gegVarAddress      = gegBase + 12;
  gegHandleInternal  = gegBase + 13;
  gegStartChain      = gegBase + 14;
  gegEndChain        = gegBase + 15;
  gegActivate        = gegBase + 16;
  gegChainActivation = gegBase + 17;
  gegCreationHook    = gegBase + 18;

  gegPIMaxValue      = gegBase + 50;
  gegPICurrentValue  = gegBase + 51;
  gegBBRecessed      = gegBase + 52;

  gegDisable         = gegBase + 100;
  gegEnable          = gegBase + 101;
  gegSetVar          = gegBase + 102;
  gegGetVar          = gegBase + 103;
  gegActivateUp      = gegBase + 104;
  gegActivateDown    = gegBase + 105;

  gegAddress         = gegBase + 200;
  gegLeftEdge        = gegBase + 201;
  gegTopEdge         = gegBase + 202;
  gegWidth           = gegBase + 203;
  gegHeight          = gegBase + 204;
  gegRedraw          = gegBase + 205;


(* ----------------------- GUIGadgetInfo structure ------------------------ *)

TYPE

  GUIGadgetInfoPtr = POINTER TO GUIGadgetInfo; (* gadget^.userData *)

  GUIGadgetInfo = RECORD  (* a pointer to this structure is stored in
                             gadget^.userData *)
    userData : ADDRESS;   (* use this for own user data *)
    kind     : LONGINT;   (* gadget kind *)

    gadgetClass : ADDRESS;(* The BOOPSI Gadget Class *)

    functionUp   : GEA1HOOK;
    functionDown : GEA1HOOK;

    guideNode: ADDRESS;   (* The AmigaGuide node for this gadget *)

 (* And now PRIVATE / DO NOT USE THEM *)

    guideBuffer : ARRAY[0..11] OF CHAR;
    this        : GadgetPtr;   (* Points to the belonging gadget *)
    CASE :SHORTINT OF
      0 : buffer : ADDRESS;
    | 1 : string : STRPTR;
    | 2 : lint   : LINTPTR;
    | 3 : bool   : BOOLPTR;
    | 4 : card   : CARDPTR;
    | 5 : int    : INTPTR;
    END;
    CASE :SHORTINT OF     (* parameters, depands on gadgetkind *)
      1 : v0 : CARDINAL;
          v1 : CARDINAL;
          v2 : CARDINAL;
          v3 : CARDINAL;  (* contains GadgetNbr *)
    | 2 : v0S: INTEGER;
          v1S: INTEGER;
          v2S: INTEGER;
          v3S: INTEGER;   (* see v3 *)
    | 3 : v0B: BOOLEAN;
          V1B: BOOLEAN;
          v0C: CHAR;
          v1C: CHAR;
          pad0:LONGCARD;  (* see v3 *)
    | 4 : v0L: LONGCARD;
          pad1:LONGCARD;  (* see v3 *)
    | 5 : v0I: LONGINT;
          pad2:LONGCARD;  (* see v3 *)
    END;
    description : DISTFIELD;
    gadfield    : GADOFIELD;
    leftC, topC : INTEGER;
    widthC, heightC : INTEGER;
    nextInfo   : GUIGadgetInfoPtr; (* Chain all infos *)
    tagsC      : TagItemPtr; (* tag-list for this gadget *)
    impTags    : TagItemPtr; (* internal tag-list *)
    nbrTags    : CARDINAL;   (* number of tags *)
    chainFlags : GEGChainFlagSet;
    nextChainGadNbr: INTEGER; (* number of the gadget to be activated next *)
    prevChainGadNbr: INTEGER;
    nextChainGad : GadgetPtr; (* next gadget to activate *)
    prevChainGad : GadgetPtr;
    gadDesc    : NewGadget;  (* copy of the NewGadget-Structur *)
    hook       : GEA1HOOK;
    onlyIntern : BOOLEAN; (* for internMsgHandling *)
    gadActive  : BOOLEAN; (* gadget active ? *)
    activate   : BOOLEAN; (* activate on creation *)
    pad        : BOOLEAN;
    activation : LONGCARD;
  END;


(* ======================================================================= *)
(*                             Menu Items                                  *)
(* ======================================================================= *)

CONST
(* ---------------------- menu item tags --------------------------------- *)

  gemBase = tagUser + 018000H;
  gemUserData        = gemBase + 1;
  gemFunction        = gemBase + 2;
  gemGuideNode       = gemBase + 3;
  gemCatalogString   = gemBase + 4;
  gemShortCut        = gemBase + 5;
  gemFlags           = gemBase + 6;
  gemMutualExclude   = gemBase + 7;

(* ---------------------- GUIMenuInfo structure -------------------------- *)

TYPE

  GUIMenuInfoPtr = POINTER TO GUIMenuInfo; (* menu^.userData *)

  GUIMenuInfo = RECORD    (* a pointer to this structure is stored in
                              menuitem^.userData *)
    userData : ADDRESS;   (* use this for own user data *)

    function : GEA1HOOK;

    guideNode: ADDRESS;   (* The AmigaGuide node for this menuitem *)

 (* And now PRIVATE / DO NOT USE THEM *)

    guideBuffer : ARRAY[0..11] OF CHAR;

    nextInfo    : GUIMenuInfoPtr;          (* Chain all infos in
                                              reverse order !*)
  END;



(* ======================================================================= *)
(*                            GUIInfo                                      *)
(* ======================================================================= *)

(* -------------------------- GUIInfo structure -------------------------- *)

  GUIInfoPtr = POINTER TO GUIInfo;
  GUIInfo = RECORD
    window     : WindowPtr;         (* pointer to the used Window *)
    screen     : ScreenPtr;         (* pointer to window's screen *)
    visualInfo : ADDRESS;           (* pointer to screen's VisualInfo *)
    drawInfo   : DrawInfoPtr;       (* pointer to a copy of DrawInfo *)
    localeInfo : LocalePtr;         (* pointer to locale environment *)

    menuFont : TextAttrPtr;         (* pointer to menu-font. Is set to
                                       screens font. *)

    creationWidth  : INTEGER;       (* window inner width *)
    creationHeight : INTEGER;       (* window inner height *)

    msgPort  : MsgPortPtr;          (* Pointer to IDCMP-Port *)

    intuiMsg : IntuiMessagePtr;     (* Points to a copy of the
                                       FULL IntuiMessage even if it
                                       is extended (OS3.0+) *)

 (* Additional information about the message: *)
    msgClass : IDCMPFlagSet;

    msgCode     : INTEGER;
    msgBoolCode : BOOLEAN;
    msgCharCode : CHAR;

    msgGadget  : GadgetPtr;

    msgItemAdr : MenuItemPtr;

    msgGadNbr  : INTEGER;

    msgMenuNum : INTEGER;
    msgItemNum : INTEGER;
    msgSubNum  : INTEGER;

 (* Some user stuff: *)
    userData      : ADDRESS;        (* for own data *)
    compilerReg   : ADDRESS;        (* for compiler data reg *)

    gadgetGuide   : ADDRESS;        (* name & path for the guide *)
    menuGuide     : ADDRESS;        (* name & path for the guide *)

    catalogInfo   : CatalogPtr;     (* points to the catalog given
                                       with the GUI_CatalogFile tag *)
    gadgetCatalogString : LONGINT;  (* The number of the next string *)
    menuCatalogString   : LONGINT;  (* in the catalog *)

    vanKeyHook    : GED0LHOOK;      (* Hook functions *)
    handleMsgHook : GEHOOK;
    refreshHook   : GEHOOK;

 (* And now PRIVATE / DO NOT USE THEM !!! *)
    actGad   : INTEGER;           (* actual CreateGadget *)
    actMenu  : INTEGER;           (* same as with gadgets *)
    menu     : MenuPtr;           (* pointer to new menu *)
    newGadget : NewGadget;        (* used to store infos for CreateGadget*)
    font     : TextAttr;          (* Font for gadgets , can be changed *)
    gadList  : GadgetPtr;         (* pointer to gadtools gadget list
                                     Please don't use it anymore ! *)
    gad      : GadgetPtr;          (* current gadget during definition*)
    gadChainStart : GadgetPtr;          (* first activation entry-gadget *)
    gadChainPrev  : GadgetPtr;          (* internal use ! *)
    firstGadInfo: GUIGadgetInfoPtr;   (* pointer to the first gadgets
                                        info-structure / chained list *)
    firstMenuInfo:GUIMenuInfoPtr;     (* pointer to the first menus
                                         info-structure / chained list *)
    guitoolsGad : GadgetPtr;        (* first GUITools gadget *)
    boopsiGad   : GadgetPtr;        (* first BOOPSI gadget *)
    prevBOOPSIGad: GadgetPtr;       (* previous BOOPSI gadget *)
    keys   : ARRAY[0..25] OF INTEGER; (* for key equivalents *)

    firstError:INTEGER; (* error number *)
    status   : BITSET;  (* internal use ! what's up ! (see flags above)*)

    allGadgets : ARRAY[0..MAXGADS-1] OF GadgetPtr;
    allMenus   : ARRAY[0..MAXMENUS-1] OF NewMenu;

    NEXT : GUIInfoPtr;  (* Chain all GUIInfo's *)
    PREV : GUIInfoPtr;
  END;

CONST

(* --------------------------- GUI Tags ------------------------------------ *)

  guiBase = tagUser + 015000H;
  guiGadgetFont          = guiBase +  1;
  guiMenuFont            = guiBase +  2;
  guiVanKeyHook          = guiBase +  3;
  guiCreateError         = guiBase +  4;
  guiUserData            = guiBase +  5;
  guiCompilerReg         = guiBase +  6;
  guiHandleMsgHook       = guiBase +  7;
  guiGadgetGuide         = guiBase +  8;
  guiMenuGuide           = guiBase +  9;
  guiCatalogFile         = guiBase + 10;
  guiGadgetCatalogOffset = guiBase + 11;
  guiMenuCatalogOffset   = guiBase + 12;
  guiCreationWidth       = guiBase + 13;
  guiCreationHeight      = guiBase + 14;
  guiRefreshHook         = guiBase + 15;

  guiRemoveMenu          = guiBase + 100;
  guiRemoveGadgets       = guiBase + 101;
  guiClearWindow         = guiBase + 102;
  guiEmptyMsgPort        = guiBase + 103;


(* ======================================================================= *)
(*                             Requester                                   *)
(* ======================================================================= *)

(* -------------------- Requester kinds ---------------------------------- *)

  gerGeneralKind = 0;
  gerOKKind      = 1;
  gerDoItKind    = 2;
  gerYNCKind     = 3;
  gerFileKind    = 4;
  gerDirKind     = 5;

(* --------------------- Return values ----------------------------------- *)

  gerCancel = 0;  (* gerYNCKind / gerDoItKind / gerOKKind /
                     gerFileKind / gerDirKind*)
  gerYes    = 1;  (* gerYNCKind / gerDoItKind / gerFileKind / gerDirKind *)
  gerNo     = 2;  (* gerYNCKind *)

(* --------------------- Requester tags ---------------------------------- *)

  gerBase = tagUser + 017000H;
  gerGadgets        = gerBase +  1;
  gerArgs           = gerBase +  2;
  gerFlags          = gerBase +  3;
  gerTitle          = gerBase +  4;
  gerIDCMP          = gerBase +  5;
  gerPattern        = gerBase +  6;
  gerNameBuffer     = gerBase +  7;
  gerFileBuffer     = gerBase +  8;
  gerDirBuffer      = gerBase +  9;
  gerSave           = gerBase + 10;


(* ======================================================================= *)
(*                              Windows                                    *)
(* ======================================================================= *)

(* ---------------------- window tags ------------------------------------ *)

  gewBase = tagUser + 019000H;
  gewOuterSize = gewBase + 1;

END GUIEnvD.
