home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Broderbund Demo / DemoData / _menu.Dxr / 00007_DialogMgr.ls < prev    next >
Encoding:
Text File  |  1997-09-03  |  2.5 KB  |  87 lines

  1. property myDialog, myParams, myName
  2.  
  3. on new me
  4.   set myParams to [:]
  5.   set myName to EMPTY
  6.   return me
  7. end
  8.  
  9. on show me, theName
  10.   set myName to theName
  11.   set theFile to getaProp(getaProp(myParams, myName), #file)
  12.   set myDialog to window "dialog"
  13.   set the windowType of myDialog to 3
  14.   set the fileName of myDialog to the pathName & "dialog" & fileDelimiter() & theFile
  15.   set the rect of myDialog to rect(0, 0, 288, 112)
  16.   set the rect of myDialog to the rect of myDialog - 10000
  17.   open(myDialog)
  18.   centreDialogOnStage(me)
  19.   updateStage()
  20. end
  21.  
  22. on dispose me
  23.   tell myDialog
  24.     cleanup()
  25.   end tell
  26.   close(myDialog)
  27.   forget(myDialog)
  28.   set myName to EMPTY
  29.   set myDialog to EMPTY
  30.   dontPassEvent()
  31. end
  32.  
  33. on hide me
  34.   moveToBack(myDialog)
  35.   updateStage()
  36. end
  37.  
  38. on handle me, theButton
  39.   set theParams to getaProp(myParams, myName)
  40.   if not voidp(theParams) then
  41.     set theActions to getaProp(theParams, #actions)
  42.     do(getAt(theActions, theButton))
  43.   end if
  44. end
  45.  
  46. on setProperties me, theName, theFile, theAction
  47.   set theProps to [:]
  48.   setaProp(theProps, #file, theFile)
  49.   setaProp(theProps, #actions, theAction)
  50.   setaProp(myParams, theName, theProps)
  51. end
  52.  
  53. on moveDialogWindow me
  54.   global myDialog
  55.   set vOrigRect to the rect of myDialog
  56.   set vOrigHorizontal to the mouseH
  57.   set vOrigVertical to the mouseV
  58.   set vNewRect to rect(0, 0, 0, 0)
  59.   repeat while the stillDown
  60.     set vHorizontalDelta to the mouseH - vOrigHorizontal
  61.     set vVerticalDelta to the mouseV - vOrigVertical
  62.     set the left of vNewRect to the left of vOrigRect + vHorizontalDelta
  63.     set the right of vNewRect to the right of vOrigRect + vHorizontalDelta
  64.     set the top of vNewRect to the top of vOrigRect + vVerticalDelta
  65.     set the bottom of vNewRect to the bottom of vOrigRect + vVerticalDelta
  66.     set the rect of myDialog to vNewRect
  67.     updateStage()
  68.     tell myDialog
  69.       updateStage()
  70.     end tell
  71.   end repeat
  72. end
  73.  
  74. on centreDialogOnStage me
  75.   set theRect to the rect of myDialog
  76.   set theWidth to the right of theRect - the left of theRect
  77.   set theHeight to the bottom of theRect - the top of theRect
  78.   set newRect to rect(0, 0, 0, 0)
  79.   set centreV to the stageTop + ((the stageBottom - the stageTop) / 2)
  80.   set centreH to the stageLeft + ((the stageRight - the stageLeft) / 2)
  81.   set the left of newRect to centreH - (theWidth / 2)
  82.   set the right of newRect to the left of newRect + theWidth
  83.   set the top of newRect to centreV - (theHeight / 2)
  84.   set the bottom of newRect to the top of newRect + theHeight
  85.   set the rect of myDialog to newRect
  86. end
  87.