(* ------------------------------------------------------------------------
  :Program.       intuisup
  :Contents.      Interface to Torsten Jürgeleits intuisup.library
  :Author.        Johann Semsrott
  :Address.       Märkerweg 50 d
  :Address.       D-2000 Hamburg 61 (Germany)
  :History.       v4.5 14-aug-92 (translated from C)
  :Copyright.     1991 by Torsten Jürgeleit
  :Language.      Modula-2
  :Translator.    M2Amiga V4.0d
  :Remark.        Thanks to Torsten for his great library
  :Bugs.          ?
------------------------------------------------------------------------ *)

DEFINITION MODULE intuisupD {"intuisup.library",4};
(*$ Implementation:=FALSE *)

FROM Arts           IMPORT  BreakPoint,Assert;
FROM SYSTEM         IMPORT  ADDRESS,CAST;
FROM IntuitionD     IMPORT  WindowPtr,NewWindowPtr,ScreenPtr,Image,ImagePtr,
                            IDCMPFlagSet,IDCMPFlags,GadgetPtr,Gadget,
                            MenuPtr,MenuItemPtr,IntuiMessagePtr;
FROM GraphicsD      IMPORT  TextFontPtr,TextAttr,TextAttrPtr;
FROM ExecD          IMPORT  MinList,MinNode,MsgPortPtr;
FROM DiskFontD      IMPORT  AvailFontHeader,AvailFontHeaderPtr;
FROM DosD           IMPORT  FileHandlePtr;

CONST
  isupname = "intuisup.library";
  iversion = 4;        (* Current library version *)

  dtText  =1; dtInt =2; dtCard   =3; dtHex =4; dtBin=5;
  
  Box1Out =1; Box1In=2; Box2Out  =3; Box2In=4;
  
  mdTitle =1; mdItem=2; mdSubitem=3;

  tfstNormal=0;     tfstEOF=1;

  errNoFileData  =-1;   errLineTooLong=-2;  
  errNoCommentEnd=-3; errReadFailed =-4;
  
  Button  =1;   (* button gadget *)
  Check =2;     (* checkbox gadget *)
  MX    =3;     (* mutual exclude gadget *)
  String  =4;   (* string input gadget *)
  Integer =5;   (* integer input gadget *)
  Slider  =6;   (* slider gadget *)
  Scroller=7;   (* scroller gadget *)
  Cycle =8;     (* cycle gadget *)
  Count =9;     (* count gadget *)
  Listview=10;  (* list view gadget *)
  Palette =11;  (* palette gadget *)

  button  =IDCMPFlagSet{gadgetUp,vanillaKey};
  check   =IDCMPFlagSet{gadgetDown,vanillaKey};
  mx      =IDCMPFlagSet{gadgetDown,vanillaKey};
  string  =IDCMPFlagSet{gadgetUp,vanillaKey};
  integer =IDCMPFlagSet{gadgetUp,vanillaKey};
  slider  =IDCMPFlagSet{gadgetUp,mouseMove,vanillaKey};
  scroller=IDCMPFlagSet{gadgetDown,gadgetUp,mouseMove,intuiTicks,vanillaKey};
  cycle   =IDCMPFlagSet{gadgetUp,vanillaKey};
  count   =IDCMPFlagSet{gadgetDown,gadgetUp,mouseMove,vanillaKey};
  listview=IDCMPFlagSet{gadgetDown,gadgetUp,mouseMove,intuiTicks,vanillaKey};
  palette =IDCMPFlagSet{gadgetUp,vanillaKey};
  all     =IDCMPFlagSet{gadgetDown,gadgetUp,mouseMove,intuiTicks,vanillaKey};
  
  ISUP    =CAST(IDCMPFlagSet,49535550H);
  
  curValue=80000000H;
  
(************** S T R U C T U R E S *************************************)

TYPE
  StrPtr=POINTER TO ARRAY [0..255] OF CHAR;
    
  RenderInfoFlags=(
    innerWindow,(* use upper left corner of inner window as location (0,0) *)
    backFill,   (* fill window back ground with different color *)
    availFonts, (* scan available fonts and use this list for  
                   ask_font/ open_font *)
    f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15); 
  
  RenderInfoFlagSet=SET OF RenderInfoFlags;
    
  RWindowFlags=(
    centerWindow,   (* center window on screen *)
    renderPens,     (* use render pens for detail and backfill pen *)
    centerMouse,    (* center window over current position of mouse pointer*)
    w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14,w15);
    
  RWindowFlagSet=SET OF RWindowFlags;

  ClrWindowFlags=(
    customDrawMode, (* don't change draw mode *)
    customColor,    (* don't change background color *)
    normalColor,    (* use normal background color *)
    useRaster,      (* use standard raster for window background *)
    absolutePos,    (* don't add window border offset to given upper left
                       position *)
    text1Color,     (* use text color 1 *)
    text2Color,     (* use text color 2 *)
    cw7,cw8,cw9,cw10,cw11,cw12,cw13,cw14,cw15);

  ClrWindowFlagSet=SET OF ClrWindowFlags;
    
  RenderInfoPtr=POINTER TO RenderInfo;
    
  RenderInfo=RECORD
    ID                                      :LONGINT;
    ScreenWidth,ScreenHeight                :INTEGER;
    ScreenDepth,WindowBorderTop,
    WindowBorderLeft,WindowBorderRight,
    WindowBorderBottom,HighlightPen,ShadowPen,
    TextPen1,TextPen2,BackPen               :SHORTCARD;
    flags                                   :RenderInfoFlagSet;
    imageDataSize                           :LONGCARD;
    imageData                               :ADDRESS;
    AvailFontsHeader                        :AvailFontHeaderPtr;
    textFont                                :TextFontPtr;
    textAttr                                :TextAttr;
    image                                   :ARRAY [0..10] OF Image;
  END;                           
    
  TextDataFlags=(
    Bold,Italic,Underlined,
    AbsolutePos,    (* absolute text pos given - don't add border offsets *)
    Center,         (* center text with in window width *)
    PlaceLeft,      (* place text left of given left edge *)
    Color2,         (* use 2nd text render pen *)
    Complement,     (* use complement of front and back pen *)
    Backfill,       (* use draw mode JAM2 to fill text background with 
                       ri_BackPen *)
    NoPrint,        (* don't print text - only calc width *)
    NumIdentifier,  (* convert number with normal (assembler style) leading
                       identifier `$' or `%' *)
    NumC,           (* use C style identifier `0x' for hex numbers *)
    NumLeading,     (* convert number including leading zeroes *)
    NumUpper,       (* use upper case characters for hex number *)
    td14,td15);
    
  TextDataFlagSet=SET OF TextDataFlags;
    
  TextDataPtr=POINTER TO TextData;
    
  TextData=RECORD
    type                :INTEGER;
    flags               :TextDataFlagSet;
    leftEdge,topEdge    :INTEGER;
    text                :ADDRESS;
    textAttr            :TextAttrPtr;
  END;

  ConvertFlags=(
    identifier,     (* convert number with normal (assmebler style)
                       leading identifier `$' or `%' *)
    cStyle,         (* use C style identifier `0x' for hex numbers *)
    leadingZeros,   (* convert number includeing leading zeroes *)
    upperCase,      (* use upper case characters for hex number *)
    cf4,cf5,cf6,cf7,cf8,cf9,cf10,cf11,cf12,cf13,cf14,cf15);

  ConvertFlagSet=SET OF ConvertFlags;

  BorderDataPtr=POINTER TO BorderData;
    
  BorderData=RECORD
    bdType,bdLeftEdge,bdTopEdge,bdWidth,bdHeight:INTEGER;
  END;
    
  GadgetDataFlags=(
    disabled,       (* gadget disabled (ghosted) - default enabled *)
    noBorder,       (* no gadget border - default with border *)
    highComp,       (* highliting by complement - default by select border *)
    vertOrient,     (* vertical orientation - default horizontal *)
    hotKey,         (* hot key given - default none *)
    noText,         (* no text output, but scan gadget text for hotkey *)
    textLeft,       (* place text left of gadget *)
    textRight,      (* place text right of gadget *)
    textAbove,      (* place text above of gadget *)
    textBelow,      (* place text below of gadget *)
    gdcolor2,       (* use 2nd text render pen for gadget text *)
    buttonToggle,   (* button gadgets: toggle button - default no toggle *)
    buttonImage,    (* button gadgets: render image - default no image *)
    autoActivate,   (* input gadgets: acivate after GADGETUP next or previous
                       input gadget *)
    unsignDec,      (* string gadgets: input default no pointer to string 
                       but an unsigned decimal number *)
    signDec,        (* string gadgets: input default no pointer to string 
                       but an signed decimal number *)
    hex,            (* string gadgets: input default no pointer to string 
                       but an hex number *)
    bin,            (* string gadgets: input default no pointer to string 
                       but an binary number *)
    noArrows,       (* scroller gadget: no arrows - default with arrows *)
    countSignDec,   (* count gadget: signed dec - default unsigned dec *)
    readOnly,       (* list view gadget: read only - default selection 
                       enabled *)
    showSelected,   (* list view gadget: show last selected entry - 
                       default no *)
    noIndicator,    (* palette gadget: no current color indicator - 
                       default with indicator *)
    indicatorTop,   (* palette gadget: place indicator at top - 
                       default at left *)
    movePointer,    (* move mouse pointer to center of this gadget *)
    noClear,        (* don't clear area occupied by this gadget before 
                       drawing *)
    sliderImage,    (* kludge to define image for knob of proportional 
                       gadget in gd_TextAttr (if text then default 
                       TextAttr used) *)
    listViewColor,  (* list view gadget: if first char of an entry text 
                       equals  <Ctrl A> ($01) then this char will be skipped
                       and the rest of this entry text will be printed in a
                       different color *)
    inputCenter,    (* input gadgets: center input string within gadget *)
    inputRight,     (* input gadgets: right justify input string within 
                       gadget *)
    gd30,gd31);
    
  GadgetDataFlagSet=SET OF GadgetDataFlags;
                 
  GadgetDataPtr=POINTER TO GadgetData;
    
  GadgetData=RECORD
    gdType                                  :LONGINT;
    gdFlags                                 :GadgetDataFlagSet;
    gdLeftEdge,gdTopEdge,gdWidth,gdHeight   :INTEGER;
    gdText                                  :ADDRESS;
    gdTextAttr                              :TextAttrPtr;
    CASE :INTEGER OF
      (* standard data struct *)
      |1:gdData1,gdData2,gdData3:LONGINT;
      (* for button gadgets *)
      |2:gdButtonSelected       :LONGINT;   (* selection state for toggle
                        buttons - ZERO = unselected, non ZERO = selected *)
         gdButtonNormalRender   :ImagePtr;  (* normal render image *)
         gdButtonSelectRender   :ImagePtr;  (* select render image *)
      (* for check gadgets *)
      |3:gdCheckSelected        :LONGINT;   (* selection state - 
                                    ZERO = unselected, non ZERO = selected *)
         gdCheckPad1,gdCheckPad2:LONGINT;
      (* for mutual exclude gadgets *)
      |4:gdMXSpacing    :LONGINT;   (* pixel spacing between MX gadgets *)
         gdMXActiveEntry:LONGINT;   (* num of active entry from text array *)
         gdMXTextArray  :ADDRESS;   (* ptr to MX text ptr array *)
      (* for string and integer gadgets *)
      |5:gdInputLen             :LONGINT;   (* len of input buffer *)
         gdInputActivateNext    :INTEGER;   (* num of next string/num 
                                               gadget to activate *)
         gdInputActivatePrev    :INTEGER;   (* num of previous string/num 
                                               gadget to activate *)
         gdInputDefault         :ADDRESS;   
                            (* string: default text [syntax: "text"] *)
                            (* integer: default number [syntax: (VOID #)num] *)
      (* for slider gadgets *)
      |6:gdSliderMin            :LONGINT;   (* min level *)
         gdSliderMax            :LONGINT;   (* max level *)
         gdSliderLevel          :LONGINT;   (* current slider level *)
      (* for scroller gadgets *)
      |7:gdScrollerVisible      :LONGINT;   (* visible entries *)
         gdScrollerTotal        :LONGINT;   (* total entries *)
         gdScrollerTop          :LONGINT;   (* current top entry *)
      (* for cycle gadget *)
      |8:gdCyclePad             :LONGINT;
         gdCycleActive          :LONGINT;   (* num of current cycle text ptr
                                               array entry *)
         gdCycleTextArray       :ADDRESS;   (* ptr to cycle text ptr array *)
      (* for count gadget *)
      |9:gdCountMin             :LONGINT;   (* min value *)
         gdCountMax             :LONGINT;   (* max value *)
         gdCountValue           :LONGINT;   (* current count value *)
      (* for list view gadget *)
      |10:gdListViewSpacing     :LONGINT;   (* pixel spacing between 
                                               list view entries *)
          gdListViewTop         :LONGINT;   (* current top entry *)
          gdListViewList        :ADDRESS;   (* current list ptr *)
      (* for palette gadget *)
      |11:gdPaletteDepth        :LONGINT;   (* num of bitplanes for palette *)
          gdPaletteColorOffset  :LONGINT;   (* first color of palette *)
          gdPaletteActiveColor  :LONGINT;   (* selected color *)
    END;
  END;
    
  ExtendedGadgetFlags=
    (eghotkey,egrenderBorder,egRenderImage,egnormalImageCopy,
     egselectImageCopy,egcloseFont,egmovePointer,
     eg7,eg8,eg9,eg10,eg11,eg12,eg13,eg14,eg15);

  ExtendedGadgetFlagSet=SET OF ExtendedGadgetFlags;

  GadgetListPtr=POINTER TO GadgetList;

  ExtendedGadgetPtr=POINTER TO ExtendedGadget;

  ExtendedGadget=RECORD
    egGadget        :Gadget;
    egBorderWidth   :INTEGER;   (* needed by editor *)
    egBorderHeight  :INTEGER;   (* needed by editor *)
    egType          :SHORTINT;  (* internal gadget type *)
    egFlags         :SHORTINT;  (* special flags, e.g render object type *)
    egDataEntry     :INTEGER;   (* ordinal number of entry in gl_Data array *)
    egGadgetList    :GadgetListPtr;
    egTextLeftEdge  :INTEGER;
    egTextTopEdge   :INTEGER;
    egText          :StrPtr;
    egTextAttr      :TextAttrPtr;
    egTextFont      :TextFontPtr;
    egHotkey        :INTEGER;   (* ASCII value of gadget hot key *)
    egHotkeyPos     :INTEGER;   (* pos of as hot key marked 
                                   (underscore) char in gadget text *)
    egRender        :ADDRESS;   (* ptr to image or border -  
                                   determined by eg_Flags *)
    egNextGadget    :ExtendedGadgetPtr;
  END;
    
  GadgetListFlags=(
    displayed,                  (* gadget list currently displayed *)
    gl1,gl2,gl3,gl4,gl5,gl6,gl7);
    
  GadgetListFlagSet=SET OF GadgetListFlags;

  RequesterListPtr=POINTER TO RequesterList; 

  GadgetList=RECORD
    glMinNode           :MinNode;   (* node to insert GadgetList into 
                                       VisibleGadgetLists list *)
    glRenderInfo        :RenderInfoPtr;
    glWindow            :WindowPtr;
    glData              :GadgetDataPtr;
    glID                :LONGINT;
    glDataEntries       :INTEGER;
    glFlags             :GadgetListFlagSet;
    glAutoRepeatDelay   :SHORTCARD;   (* delay counter for start of 
                                    auto repeat for active arrow gadget *)
    glGadgetBuffer      :ADDRESS;
    glGadgetBufferSize  :LONGINT;
    glImageBuffer       :ADDRESS;
    glImageBufferSize   :LONGINT;
    glLanguageTextArray :ADDRESS;
    glRequesterList     :RequesterListPtr;
    glActiveGadget      :ExtendedGadgetPtr;
    glGadgets           :ExtendedGadgetPtr;   
                (* array with gl_DataEntries ptr to extended gadgets *)
  END;

  AutoRequesterFlags=(
    rbackFill,rrenderPens,rtextCenter,rtextColor2,
    rhotkey,rbeep,rmovePointerPos,rmovePointerNeg,
    rdrawRaster,        (* draw raster around text area *)
    rcenterMouse,       (* center last gadget of auto requester over
                           current position of mouse pointer *)
    r10,r11,r12,r13,r14,r15);
    
  AutoRequesterFlagSet=SET OF AutoRequesterFlags;


  RequesterDataFlags=(
    rdbackFill,rdrenderPens,rdinnerWindow,rdavailFonts,
    rdcenter,           (* center requester on window's screen *)
    rddragGadget,rddepthGadget,
    rddrawRaster,       (* draw raster between FIRST BORDER and window
                           border - FIRST BORDER will not be used further *)
    rdcenterWindow,     (* center requester on window *)
    rdcenterMouse,      (* center requester over current position of
                           mouse pointer *)
    rd10,rd11,rd12,rd13,rd14,rd15,
    rd16,rd17,rd18,rd19,rd20,rd21,rd22,rd23,rd24,rd25,
    rd26,rd27,rd28,rd29,rd30,rd31);

  RequesterDataFlagSet=SET OF RequesterDataFlags;

  RequesterList = RECORD
    rlRenderInfo        :RenderInfoPtr;
    rlWindow            :WindowPtr;     (* window requester displayed on *)
    rlReqWindow         :WindowPtr;     (* window of requester *)
    rlGadgetList        :GadgetListPtr; (* requester gadgets *)
    rlMenu              :MenuPtr;       (* menu of window requester
                                           displayed on *)
    rlVisibleGadgetLists:MinList;       (* list for removed visible 
                                           gadget lists *)
    rlID                :LONGINT;       (* id = 'ISUP' *)
  END;

  RequesterDataPtr=POINTER TO RequesterData;

  RequesterData = RECORD
    rdLeftEdge,rdTopEdge,
    rdWidth,rdHeight    :INTEGER;
    rdFlags             :RequesterDataFlagSet;
    rdTitle             :ADDRESS;
    rdTexts             :TextDataPtr;
    rdBorders           :BorderDataPtr;
    rdGadgets           :GadgetDataPtr;
  END;

  MenuDataFlags=(
    Disabled,   (* disable menu or menu item *)
    attribute,  (* attribute menu item *)
    selected,   (* selected attribute menu item *)
    emptyLine,  (* insert empty line before this item *)
    highNone,   (* no highliting *)
    highBox,    (* highliting with box, otherwise with complement *)
    mdColor2,   (* alternate color for item text *)
    md7,md8,md9,md10,md11,md12,md13,md14,md15);
    
  MenuDataFlagSet=SET OF MenuDataFlags;

  MenuListFlags=(
    attached,   (* menu list is currently attached to a window *)
    ml1,ml2,ml3,ml4,ml5,ml6,ml7,ml8,ml9,ml10,ml11,ml12,ml13,ml14,ml15);
    
  MenuListFlagSet=SET OF MenuListFlags;
                    
  MenuData=RECORD
    mdType          :INTEGER;
    mdFlags         :MenuDataFlagSet;
    mdText          :StrPtr;
    mdCommandKey    :ADDRESS;
    mdMutualExclude :LONGCARD;
  END;
    
  MenuDataPtr=POINTER TO MenuData;

  MenuList=RECORD 
    mlRenderInfo            :RenderInfoPtr;
    mlWindow                :WindowPtr;
    mlTextAttr              :TextAttrPtr;
    mlTextFont              :TextFontPtr;
    mlData                  :MenuDataPtr;
    mlID                    :LONGINT;
    mlFlags                 :MenuListFlagSet;
    mlTextPen1,mlTextPen2   :SHORTCARD;
    mlLanguageTextArray     :ADDRESS;
    mlBuffer                :ADDRESS;
    mlBufferSize            :LONGCARD;
  END;
    
  MenuListPtr=POINTER TO MenuList;
    
  TextFileFlags =(
    trimLine,           (* strip leading and trailing white space *)
    skipComments,       (* skip C style comments *)
    skipEmptyLines,     (* skip empty lines *)
    lineContinuation,   (* continue line with last character
                           '\' in next line *)
    tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11,tf12,tf13,tf14,tf15);
    
  TextFileFlagSet=SET OF TextFileFlags;

  FileDataPtr=POINTER TO FileData;
    
  FileData = RECORD 
    fdLine              :ADDRESS;
    fdLineLen,fdLineNum :CARDINAL;
  END;

  PointerDataPtr=POINTER TO PointerData; 
    
  PointerData = RECORD
    pdWidth,pdHeight    :SHORTCARD;
    pdXOffset,pdYOffset :SHORTINT;
    pdData              :ADDRESS;
  END;

  PointerListPtr=POINTER TO PointerList;
    
  PointerList = RECORD
    plID                :LONGINT;       (* id = 'ISUP' *)
    plWidth,plHeight    :SHORTCARD;
    plXOffset,plYOffset :SHORTINT;
    plData              :ADDRESS;
    plBuffer            :ADDRESS;   (* if non NULL then chipmem buffer
                                       was allocated *)
    plBufferSize        :LONGINT;
    plNext              :PointerListPtr;
END;

END intuisupD.
