Cross-Platform default btn Geometry

FlexibleLearning at aol.com FlexibleLearning at aol.com
Wed Aug 3 08:43:36 EDT 2005


Something Richard said the other day, that Mac and Win display the OK and  
Cancel buttons differently. So it occured to me that there should be a handler  
that deals with this automatically so the buttons display correctly on either  
OS, preferably in a flexible way.

This is what I have come up with. Not  very elegant and a bit brute-force, so 
improvements welcome. Consider the  gauntlet thrown!

In a stack with three buttons called 'OK', 'Default' and  'Cancel' 
horizontally from left to right, add this to a 'TestMe'  button...

on mouseUp
setOSbtnGeometry  "Cancel/D","OK","off","MacOS"
end mouseUp

--| Cross platform button  geometry
--| This assumes that the default or main option should be on the  right in 
win32 and on the
--| left in macOS.
--| This handler takes the names of two buttons, then  sets their position 
and default state
--| accordingly. It also provides for over-riding the OS for testing  
purposes.
--|
--| Syntax:
--|    setOSbtnGeometry  "Btn1Name[/D]","Btn2Name[/D]","on|off" 
[,"macOS|Win32"]
--|
--|       Param 1 and 2:
--|       The names of the two buttons  involved. Use /D to define which is 
the default  position
--|       Param 3:
--|       Define whether the default state  should be "on" or "off"
--|       Param  4:
--|       Optional, to force platform  over-ride for testing. Omit to use the 
current platform.
--|
--|  Examples:
--|   setOSbtnGeometry  "Cancel/D","OK","on"
--|   setOSbtnGeometry  "Cancel","OK/D","off"
--|   setOSbtnGeometry  "Yes","No/D","on","macOS"

on setOSbtnGeometry pFirstBtnName,  pSecondBtnName, pState, pOS
if char -2 to -1 of pFirstBtnName is "/D"  then
delete char -2 to -1 of  pFirstBtnName
put pFirstBtnName into  tDefault
put pSecondBtnName into tOther
else
if char -2 to -1 of pSecondBtnName is "/D"  then
delete char -2 to -1 of  pSecondBtnName
end if
put  pSecondBtnName into tDefault
put pFirstBtnName into  tOther
end if

put the rect of btn pFirstBtnName  into rect1
put the rect of btn pSecondBtnName into rect2

if pState is "on" then set the default of btn tDefault to  TRUE
else set the default of btn tDefault to FALSE
set the  default of btn tOther to FALSE

if item 1 of rect1 < item  1 of rect2 then
put rect2 into leftSide; put rect1 into  rightSide
else
put rect2 into rightSide; put  rect1 into leftSide
end if

if pOS <>"" then  put pOS into tPlatform
else put the platform into tPlatform

if tPlatform="MacOS" then
set the rect of btn  tDefault to rightSide
set the rect of btn tOther to  leftSide
else
set the rect of btn tDefault to  leftSide
set the rect of btn tOther to rightSide
end if
end setOSbtnGeometry



/H
 



More information about the use-livecode mailing list