Skip to content

Instantly share code, notes, and snippets.

@CarlTBarnes
Last active September 2, 2020 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlTBarnes/297557ade046558cdeb183fdd27bb1df to your computer and use it in GitHub Desktop.
Save CarlTBarnes/297557ade046558cdeb183fdd27bb1df to your computer and use it in GitHub Desktop.
Popup() Menu Under or Beside a Control so Menu appears to drop under a Button
!Use the POPUP('xxx', X, Y, 1=Relative) to position a POPUP() right under a Button so it appears to drop down
!The fourth parameter is not documented well. Pass 1 to indicate the X/Y are Relative so can use Clarion GetPosition()
!
!Replace existing Popup() placing the ?Control as the first parameter
!Example: OF ?MenuBtn ; CASE PopupUnder(?,'Copy|Delete')
!---------------------------------------
MAP
PopupBeside(LONG BesideCtrlFEQ, STRING PopMenu),LONG
PopupUnder(LONG UnderCtrlFEQ, STRING PopMenu),LONG
PopupBeside PROCEDURE(LONG BesideCtrlFEQ, STRING PopMenu),LONG
PopupUnder PROCEDURE(LONG UnderCtrlFEQ, STRING PopMenu),LONG
END
!---------------------------------------
PopupBeside PROCEDURE(LONG CtrlFEQ, STRING PopMenu)!,LONG
X LONG,AUTO
Y LONG,AUTO
W LONG,AUTO
CODE
GETPOSITION(CtrlFEQ,X,Y,W)
IF CtrlFEQ{PROP:InToolBar} THEN Y -= (0{PROP:ToolBar}){PROP:Height}.
RETURN POPUP(PopMenu,X+W,Y,1)
!---------------------------------------
PopupUnder PROCEDURE(LONG CtrlFEQ, STRING PopMenu)!,LONG
X LONG,AUTO
Y LONG,AUTO
H LONG,AUTO
CODE
GETPOSITION(CtrlFEQ,X,Y,,H)
IF CtrlFEQ{PROP:InToolBar} THEN Y -= (0{PROP:ToolBar}){PROP:Height}.
RETURN POPUP(PopMenu,X,Y+H+1,1)
!=============================================================
PopClean PROCEDURE(STRING T)!,STRING !Remove Popup Control Characters {}|~+-
X USHORT,AUTO
N USHORT
CODE
LOOP X=1 TO LenFastClip(T)
CASE T[X]
OF '{{' OROF '}' OROF '|' ; CYCLE
OF ' ' OROF '+' OROF '-' OROF '~' ; IF N=0 THEN CYCLE.
END
N+=1 ; T[N]=T[X]
END
RETURN SUB(T,1,N)
!--------------------------------------------------
PopItem PROCEDURE(STRING ItemTxt, <BOOL Checked>, <BOOL Disabled>,BYTE Pipe012=1)!,STRING
Pfx PSTRING(3)
CODE
IF ~OMITTED(Checked) AND Checked THEN Pfx=CHOOSE(~Checked,'-','+').
IF ~OMITTED(Disabled) AND Disabled THEN Pfx='~'&Pfx.
RETURN CHOOSE(Pipe012,'|','|-|','') & Pfx & PopClean(ItemTxt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment