;
; **  $VER: sghooks.h 38.1 (11.11.91)
; **  Includes Release 40.15
; **
; **  string gadget extensions and hooks
; **
; **  (C) Copyright 1988-1993 Commodore-Amiga, Inc.
; **     All Rights Reserved
;


IncludePath   "PureInclude:"        ; For compiling only...
XIncludeFile "graphics/text.pb"  ;
;XIncludeFile "intuition/cghooks.pb"  ;
XIncludeFile "utility/hooks.pb"  ;


Structure StringExtend
    ;  display specifications
    *Font.TextFont ;  must be an open Font (not TextAttr)
    Pens.b[2] ;  color of text/backgroun
    ActivePens.b[2] ;  colors when gadget is active

    ;  edit specifications
    InitialModes.l ;  initial mode flags, below
    *EditHook.Hook ;  if non-NULL, must supply WorkBuffer
    *WorkBuffer.b ;  must be as large as StringInfo.Buffer

    Reserved.l[4] ;  set to 0
EndStructure

Structure SGWork
    ;  set up when gadget is first activated
    *Gadget.Gadget ;  the contestant itself
    *StringInfo.StringInfo ;  easy access to sinfo
    *WorkBuffer.b ;  intuition's planned result
    *PrevBuffer.b ;  what was there before
    Modes.l  ;  current mode

    ;  modified for each input event
    *IEvent.InputEvent ;  actual event: do not change
    Code.w  ;  character code, if one byte
    BufferPos.w ;  cursor position
    NumChars.w
    Actions.l ;  what Intuition will do
    LongInt.l ;  temp storage for longint

    *GadgetInfo.GadgetInfo ;  see cghooks.h
    EditOp.w  ;  from constants below
EndStructure

;  SGWork.EditOp -
;  * These values indicate what basic type of operation the global
;  * editing hook has performed on the string before your gadget's custom
;  * editing hook gets called.  You do not have to be concerned with the
;  * value your custom hook leaves in the EditOp field, only if you
;  * write a global editing hook.
;  *
;  * For most of these general edit operations, you'll want to compare
;  * the BufferPos and NumChars of the StringInfo (before global editing)
;  * and SGWork (after global editing).
;

#EO_NOOP  = ($0001)
 ;  did nothing
#EO_DELBACKWARD = ($0002)
 ;  deleted some chars (maybe 0).
#EO_DELFORWARD = ($0003)
 ;  deleted some characters under and in front of the cursor
#EO_MOVECURSOR = ($0004)
 ;  moved the cursor
#EO_ENTER = ($0005)
 ;  "enter" or "return" key, terminate
#EO_RESET = ($0006)
 ;  current Intuition-style undo
#EO_REPLACECHAR = ($0007)
 ;  replaced one character and (maybe) advanced cursor
#EO_INSERTCHAR = ($0008)
 ;  inserted one char into string or added one at end
#EO_BADFORMAT = ($0009)
 ;  didn't like the text data, e.g., Bad LONGINT
#EO_BIGCHANGE = ($000A) ;  unused by Intuition
 ;  complete or major change to the text, e.g. new string
#EO_UNDO  = ($000B) ;  unused by Intuition
 ;  some other style of undo
#EO_CLEAR = ($000C)
 ;  clear the string
#EO_SPECIAL = ($000D) ;  unused by Intuition
 ;  some operation that doesn't fit into the categories here


;  Mode Flags definitions (ONLY first group allowed as InitialModes)
#SGM_REPLACE = (1  <<  0) ;  replace mode
;  please initialize StringInfo with in-range value of BufferPos
;  * if you are using SGM_REPLACE mode.
;

#SGM_FIXEDFIELD = (1  <<  1) ;  fixed length buffer
     ;  always set SGM_REPLACE, too
#SGM_NOFILTER = (1  <<  2) ;  don't filter control chars

;  SGM_EXITHELP is new for V37, and ignored by V36:
#SGM_EXITHELP = (1  <<  7) ;  exit with code = 0x5F if HELP hit


;  These Mode Flags are for internal use only
#SGM_NOCHANGE = (1  <<  3) ;  no edit changes yet
#SGM_NOWORKB = (1  <<  4) ;  Buffer == PrevBuffer
#SGM_CONTROL = (1  <<  5) ;  control char escape mode
#SGM_LONGINT = (1  <<  6) ;  an intuition longint gadget

;  String Gadget Action Flags (put in SGWork.Actions by EditHook)
#SGA_USE  = ($1) ;  use contents of SGWork
#SGA_END  = ($2) ;  terminate gadget, code in Code field
#SGA_BEEP = ($4) ;  flash the screen for the user
#SGA_REUSE = ($8) ;  reuse input event
#SGA_REDISPLAY = ($10) ;  gadget visuals changed

;  New for V37:
#SGA_NEXTACTIVE = ($20) ;  Make next possible gadget active.
#SGA_PREVACTIVE = ($40) ;  Make previous possible gadget active.

;  function id for only existing custom string gadget edit hook

#SGH_KEY  = (1) ;  process editing keystroke
#SGH_CLICK = (2) ;  process mouse click cursor position

;  Here's a brief summary of how the custom string gadget edit hook works:
;  * You provide a hook in StringInfo.Extension.EditHook.
;  * The hook is called in the standard way with the 'object'
;  * a pointer to SGWork, and the 'message' a pointer to a command
;  * block, starting either with (longword) SGH_KEY, SGH_CLICK,
;  * or something new.
;  *
;  * You return 0 if you don't understand the command (SGH_KEY is
;  * required and assumed). Return non-zero if you implement the
;  * command.
;  *
;  *   SGH_KEY:
;  * There are no parameters following the command longword.
;  *
;  * Intuition will put its idea of proper values in the SGWork
;  * before calling you, and if you leave SGA_USE set in the
;  * SGWork.Actions field, Intuition will use the values
;  * found in SGWork fields WorkBuffer, NumChars, BufferPos,
;  * and LongInt, copying the WorkBuffer back to the StringInfo
;  * Buffer.
;  *
;  * NOTE WELL: You may NOT change other SGWork fields.
;  *
;  * If you clear SGA_USE, the string gadget will be unchanged.
;  *
;  * If you set SGA_END, Intuition will terminate the activation
;  * of the string gadget.  If you also set SGA_REUSE, Intuition
;  * will reuse the input event after it deactivates your gadget.
;  *
;  * In this case, Intuition will put the value found in SGWork.Code
;  * into the IntuiMessage.Code field of the IDCMP_GADGETUP message it
;  * sends to the application.
;  *
;  * If you set SGA_BEEP, Intuition will call DisplayBeep(); use
;  * this if the user has typed in error, or buffer is full.
;  *
;  * Set SGA_REDISPLAY if the changes to the gadget warrant a
;  * gadget redisplay.  Note: cursor movement requires a redisplay.
;  *
;  * Starting in V37, you may set SGA_PREVACTIVE or SGA_NEXTACTIVE
;  * when you set SGA_END.  This tells Intuition that you want
;  * the next or previous gadget with GFLG_TABCYCLE to be activated.
;  *
;  *   SGH_CLICK:
;  * This hook command is called when Intuition wants to position
;  * the cursor in response to a mouse click in the string gadget.
;  *
;  * Again, here are no parameters following the command longword.
;  *
;  * This time, Intuition has already calculated the mouse position
;  * character cell and put it in SGWork.BufferPos. The previous
;  * BufferPos value remains in the SGWork.StringInfo.BufferPos.
;  *
;  * Intuition will again use the SGWork fields listed above for
;  * SGH_KEY.  One restriction is that you are NOT allowed to set
;  * SGA_END or SGA_REUSE for this command. Intuition will not
;  * stand for a gadget which goes inactive when you click in it.
;  *
;  * You should always leave the SGA_REDISPLAY flag set, since Intuition
;  * uses this processing when activating a string gadget.
;

