Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tips:revmedia:v4i5a8 [2023/11/27 14:08] bshumskytips:revmedia:v4i5a8 [2024/06/19 20:20] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Version 3 Technical Highlights - Add_Buttons=====
  
 +^Published By^Date^Version^Knowledge Level^Keywords^
 +|Sprezzatura Ltd|01 OCT 1992|3.0+|EXPERT|ADD_BUTTONS, @PROG.CHAR|
 +
 +The program on the following pages uses this extended functionality to put
 +buttons on the screen in an AREV window as in the illustration below. When
 +the buttons are pointed at and clicked with the mouse the buttons give the
 +illusion of being pressed into the screen and provide an audible click.
 +Setting up the buttons is simple a case of putting five parameters per
 +button into Register(5) of the window (see below), the parameters being
 +Label, X, Y, Code Command as shown below. Then add a call to ADD_BNS
 +passing PRE_INIT on the pre init hook. The program works by adding "pseudo"
 +prompts for each button into the window at pre init. It then checks on a
 +perpetual process to see if these prompts are in WC_Wi_Next%. If they are
 +they can be there by either arrowing to the prompt or clicking on the
 +prompt. Arrowing (or returning) to the prompt should ignore the prompts and
 +continue on in the direction of travel. Clicking on the prompt with a mouse
 +should action the code and command.
 +
 +<code>
 + ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍTESTÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
 + º                                      º
 + º Customer Id                        º
 + º Company Name  FIRST BANK OF NEW YORK º
 + º Contact Name  Rick Garber            º
 + º               Jim Lovell             º
 + º   ÚÄÄÄÄ·  ÚÄÄÄÄÄÄÄÄÄÄ·  ÚÄÄÄ·        º
 + º   ³Saveº  ³Table Modeº  ³TCLº        º
 + º   ÔÍÍÍͼ  ÔÍÍÍÍÍÍÍÍÍͼ  ÔÍÍͼ        º
 + ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
 +</code>
 +
 +<code>
 +     Example Parameters in Register(5) For Above Screen
 +     Save|2|5|K|{F9}
 +     Table Mode|10|5|K|{CTRL-F5}
 +     Print|24|5|K|{ALT-P}
 +</code>
 +
 +To determine whether the prompt was clicked on, @PROG.CHAR is checked. If it
 +is four characters long a mouse click was used. (See above). Note that
 +WC_Wi_Next% is not reliable when exiting an associated MVed prompt.
 +Essentially when an AMV group is exited by pressing return, WC_Wi_Next% is
 +not set. Rather WC_Mv_Next% is set to two more than the count of MVs in the
 +group! This behaviour is not new, but large thanks to Alan Humphrey/Bob
 +Madden of Revelation Technologies for helping to pinpoint it.
 +
 +The only remaining point of interest is that the window processor obviously
 +uses the length of the prompt label and entry to work out whether a prompt
 +has been clicked on using InRect. Originally the program following made the
 +prompt label equal to the complete button string but this led to false
 +alarms when clicking ANYWHERE on the prompt line. Hence the use of a
 +pre-key process to actually draw the button.
 +
 +<code>
 +  Subroutine Add_BNS(Branch)
 +  /*
 +    Author  AMcA
 +    Date    Sept 1992
 +    Notes   Note for BP@ read ButtonPrompts@, for Bn read Button
 +  */
 +    GoTo Main
 +    Declare Subroutine Catalyst, VSpace, Delay, Msg
 +    $Insert SysInclude, Window_Common%
 +    $Insert SysInclude, LcPositions
 +    $Insert SysInclude, Virtual.Params
 +    $Insert SysInclude, Logical
 +    $Insert SysInclude, Window.Constants
 +    Equ RegisterToUse$ To 49 ; * Window Register 5
 +    Equ BnLabel$ To 1
 +    Equ BnX$ To 2
 +    Equ BnY$ To 3
 +    Equ BnCode$ To 4
 +    Equ BnCommand$ To 5
 +    Equ Dm$ To Char(247)
 +
 +  Main:
 +    Common /WindowBns/ BP@, BnLabelPrePress@,
 +  BnLabelPress@
 +    Begin Case
 +     Case Branch = "PRE_KEY" ; GoSub SetUpBns
 +     Case Branch = "PRE_INIT" ;GoSub PreInit
 +     Case Branch = "PERP" ;    GoSub Perpetual
 +    End Case
 +  Return
 +
 +  Perpetual:
 +    CAG = WC_Curr_Amv_Group%
 +    If CAG Then
 +     If WC_Mv_Next%>(WC_Amv_Vars%<CAG,Amv.Depth$>+1) Then
 +      * Moving out of an AMV group downwards so the next prompt will be
 +      * equal to the start pos + count of prompts + 1
 +      WC_Wi_Next%=WC_Amv%<CAG,1>+ WC_Amv_Vars%<CAG, Amv.Width$>
 +     End
 +    End
 +    Locate WC_Wi_Next% In BP@ Using @Fm Setting Pos Then
 +     If Len(@Prog.Char) = 4 Then
 +      * Asked to mouse to Bn prompt so get options code and command and
 +      * execute it
 +      Old_Wi_Next% = WC_Wi_Next%
 +      GoSub BnPress
 +      Catalyst(WC_W%(BP@<Pos>)<Options.Code>, WC_W% (BP@<Pos>)
 +              <Options.Command>)
 +      If WC_Wi_Next% # Old_Wi_Next% Then
 +       * Do nothing, user must have changed it in catalyst
 +      End Else
 +       * Return whence one came
 +       WC_Wi_Next% = WC_Wi%
 +      End
 +      @Prog.Char = ""
 +     End Else
 +      * Normal attempt to move into the Bn prompt so just increment Wi_Next%
 +      Exit = False$
 +      Begin Case
 +       Case WC_Wi% = 1 And WC_Wi_Next% = WC_W_Cnt%
 +         Loop
 +          Locate WC_Wi_Next% In BP@ Using @Fm Setting Pos Else
 +           Exit = True$
 +          End
 +         Until Exit
 +          Wi_Next% -= 1
 +         Repeat
 +       Case WC_Wi_Next% > WC_Wi%
 +         Loop
 +          WC_Wi_Next% += 1
 +          Locate WC_Wi_Next% In BP@ Using @Fm Setting Pos Else
 +           Exit = True$
 +          End
 +          If WC_Wi_Next% > WC_W_Cnt% Then
 +           WC_Wi_Next% = 1
 +          End
 +         Until Exit Repeat
 +       Case WC_Wi_Next% < WC_Wi%
 +         Loop
 +          WC_Wi_Next% -= 1
 +          Locate WC_Wi_Next% In BP@ Using @Fm Setting Pos Else
 +           Exit = True$
 +          End
 +          If WC_Wi_Next% < 1 Then
 +           WC_Wi_Next% = WC_W_Cnt%
 +          End
 +         Until Exit Repeat
 +      End Case
 +     End
 +    End
 +  Return
 +
 +  PreInit:
 +  BnDetails = Field(@Record, Dm$, RegisterToUse$)
 +  If BnDetails Then
 +    * For each Bn defined, add into prompt array and into labelled common
 +    Convert "|" : @Vm To @Vm : @Fm In BnDetails
 +    BnCtr = Count(BnDetails, @Fm) + 1
 +    PromptArray = @Record[1,Char(247)]
 +    PromptCount = PromptArray<1>
 +    For X = 1 To BnCtr
 +     PromptCount += 1
 +     Bn = BnDetails<X>
 +     Prompt = ""
 +     Prompt<0,Type> = "F"
 +     GoSub ConstructBnLabel
 +     Prompt<0,D> = BnText
 +     Prompt<0,DA> = "^PL^"
 +     Prompt<0,DX> = BnX + 1
 +     Prompt<0,DY> = BnY
 +     Prompt<0,VX> = BnX + 1 ; Prompt<0,VY> = BnY
 +     Prompt<0,VLen> = 0 ; Prompt<0,VA> = "^PE^"
 +     Prompt<0,Options.Code> = Bn<0, BnCode$>
 +     Prompt<0,Options.Command> = Bn<0, BnCommand$>
 +     PromptArray = Insert(PromptArray,PromptCount+1,0,0,Prompt)
 +    Next
 +    PromptArray<1> = PromptCount
 +    @Record = FieldStore(@Record, Dm$, 1, -1, PromptArray)
 +    @Record = FieldStore(@Record, Dm$, 9, 1, "")
 +    BP@ = ""
 +    Top = PromptCount
 +    Bottom = Top - BnCtr + 1
 +    For X = Bottom To Top
 +     BP@<-1> = X
 +    Next
 +  End
 +  * Finally add Perpetual and Pre Key call in if not there
 +  PerpetualCall = Field(@Record, Dm$, 45)
 +  Begin Case
 +    Case PerpetualCall<1> = ""
 +     PerpetualCall = "S" : @Vm : "ADD_BNS,PERP"
 +    Case Index(PerpetualCall<1>, "ADD_BNS,PERP", 1)
 +     Null
 +    Case 1
 +     PerpetualCall<1,1> = PerpetualCall<1,1> : ";S"
 +     PerpetualCall<1,2> = PerpetualCall<1,2> : ";ADD_BNS,PERP"
 +  End Case
 +  @Record = FieldStore(@Record, Dm$, 45, 1, PerpetualCall)
 +  PreCode = @Record<2, Pre.Code>
 +  PostCode = @Record<2, Post.Command>
 +  Begin Case
 +    Case Index(@Record<2, Pre.Command>, "ADD_BNS,PRE_KEY", 1)
 +     Null
 +    Case 1
 +     @Record<2, Pre.Code> = "S;" : @Record<2, Pre.Code>
 +     @Record<2,Pre.Command>="ADD_BNS,PRE_KEY":";":@Record<2, Pre.Command>
 +    End Case
 +    Delay(0)
 +  Return
 +
 +  ConstructBnLabel:
 +    BnText = Bn<0, BnLabel$>
 +    BnX = Bn<0, BnX$>
 +    BnY = Bn<0, BnY$>
 +    BnLabelLength = Len(BnText)
 +    BnLabelTemp = @(BnX,BnY- 1):"Ú":Str("Ä",BnLabelLength):"·"
 +    BnLabelTemp := @(BnX,BnY):"³":BnText:"º"
 +    BnLabelTemp := @(BnX,BnY+1):"Ô":Str("Í",BnLabelLength):"¼"
 +    BnLabelPrePress@<X> = BnLabelTemp
 +    BnLabelTemp = @(BnX,BnY- 1):"Ú":Str("Ä",BnLabelLength):"¿"
 +    BnLabelTemp := @(BnX, BnY) : "³" : BnText : "³"
 +    BnLabelTemp := @(BnX,BnY+1):"À":Str("Ä",BnLabelLength):"Ù"
 +    BnLabelPress@<X> = BnLabelTemp
 +  Return
 +
 +  BnPress:
 +    X = WC_W%(WC_Wi_Next%)<DX>
 +    Y = WC_W%(WC_Wi_Next%)<DY>
 +    ReleaseColour = WC_W%(WC_Wi_Next%)<DA>
 +    ReleaseBn = ReleaseColour : BnLabelPrePress@<Pos>
 +    If Branch = "PERP" Then
 +     PressColour = WC_W%(WC_Wi_Next%)<VA>
 +     PressBn = PressColour : BnLabelPress@<Pos>
 +     Vspace(VPrnt, Flag, VWindow%, X, Y, PressBn)
 +     Out 67, 182 ; Out 66, 21 ; Out 66, 0
 +     OldValue = Inp(97) ; NewValue = BitOr(OldValue, 03)
 +     Out 97,NewValue
 +     Delay(.2)
 +     NewValue = BitAnd(OldValue,252)
 +     Out 97,NewValue
 +    End
 +    Vspace(VPrnt, Flag, WC_VWindow%, X, Y, ReleaseBn)
 +  Return
 +
 +  SetUpBns:
 +    BnCtr = Count(BP@, @Fm) + 1
 +    For Ctr = 1 To BnCtr
 +     X = WC_W%(BP@<Ctr>)<DX>
 +     Y = WC_W%(BP@<Ctr>)<DY>
 +     ReleaseColour = WC_W%(BP@<Ctr>)<DA>
 +     ReleaseBn = ReleaseColour : BnLabelPrePress@<Ctr>
 +     Vspace(VPrnt, Flag, WC_VWindow%, X, Y, ReleaseBn)
 +    Next
 +  Return
 +</code>
 +
 +(Volume 4, Issue 5, Pages 12-15)