home *** CD-ROM | disk | FTP | other *** search
/ Asymetrix Demo / Asymetrix.iso / prg / mtb30 / advanced.ats next >
Encoding:
Text File  |  1994-07-11  |  60.8 KB  |  2,024 lines

  1. ACTION    "Open a file using Common Open Dialog"
  2. BEHAVIOR    "Opens a file that the user has chosen."
  3. CATEGORY    Files
  4. HANDLERS    buttonClick, buttonUp, buttonDown, buttonDoubleClick, rightButtonDown, rightButtonUp, rightButtonDoubleClick
  5. ARG    caption    is    "Open"
  6. ARG    prompt    is    "Choose the file to open"
  7. ARG    extension    is    "*.txt"
  8. ARG    Directory    is    "."
  9. {
  10.     linkDll sysToolBookDirectory & "tb30dlg.dll"
  11.         string openDlg(string,string,string,string)
  12.     end    linkDLL
  13.     
  14.     get openDlg("$$Directory","$$extension","$$prompt","$$caption")
  15.     if it <> null    
  16.         clear sysError
  17.         openfile it
  18.         if sysError <> null
  19.             request "The file"&&it&&"could not be opened"
  20.         end if
  21.     end if
  22.     unlinkDLL sysToolBookDirectory & "tb30dlg.dll"
  23. }
  24.  
  25. SCRIPT "Insert a textline"
  26. BEHAVIOR "Use if you need to insert a single line and maintain the fields sorted order."
  27. CATEGORY Text
  28. {
  29. to get insertLine txt,newLine
  30.     if txt is null
  31.         return newLine
  32.     end
  33.     set start to 1  -- first textline
  34.     set tlc to textlinecount(txt)
  35.     set ending to tlc -- last textline
  36.     local insertSpot
  37.     while start <= ending 
  38.         set midPoint to (start+ending) div 2 
  39.         set middleLine to textline midPoint of txt
  40.         conditions
  41.             when newLine < middleLine as text
  42.                 -- start looking at values less than current midPoint
  43.                 set ending to midPoint-1
  44.                 set insertSpot to midPoint
  45.             when newLine > middleLine as text
  46.                 -- start looking at values greater than current midPoint
  47.                 set start to midPoint+1
  48.                 set insertSpot to midPoint+1
  49.             else
  50.                 -- the item already exists
  51.                 set insertSpot to midPoint
  52.                 break while
  53.         end
  54.     end
  55.     if insertSpot > tlc
  56.         put newLine before textline insertSpot of txt
  57.     else
  58.         put newLine&crlf before textline insertSpot of txt
  59.     end
  60.     return txt
  61. end
  62. }
  63.  
  64. SCRIPT "Get the name of MRU file"
  65. BEHAVIOR "A method for getting the name of any of the MRU (most recently used) files listed at the bottom of the author level file menu."
  66. CATEGORIES Files
  67. {
  68. to handle loadFile mAlias      -- possible custom message
  69. -- Pass mAlias in from menuItemSelected. 
  70. -- See page 13-30 of the ToolBook User Manual for an example
  71.         linkDLL sysToolBookDirectory & "tb30WIN.DLL"
  72.             STRING     getIniVar(STRING,STRING,STRING)
  73.                            -- section, item, file
  74.         end linkDLL
  75.         
  76.         get getIniVar("files", mAlias, "toolbook.ini") 
  77.         request it
  78. --        go to page 1 of book it    -- same as default behavior
  79.         unlinkDLL sysToolBookDirectory & "tb30WIN.DLL"
  80. end loadFile
  81. }
  82.  
  83. ACTION    "Show or hide object(s) with transition"
  84. BEHAVIOR    "Allows user to $$show an object with a transition effect"
  85. CATEGORIES    Effects
  86. ARG speed  oneOf  "slow,normal,fast" is "normal"
  87. ARG effect oneOf     "blinds,dissolve,drip,fade,iris,push,puzzle,rain,slide,spiral,split,tear,turnPage,wipe,zoom"  is "fade"
  88. ARG myObjects is     "objects of this page"     help "Set to a reference ($$myObjects) to an object or objects."
  89. ARG show oneOf "show,hide" is "show"    help "Show hidden objects or hide shown objects."
  90.  
  91. {
  92. -- This script works fine as is, but there are so many  
  93. -- variations, consider doing a little experimentation.
  94.       set sysSuspendMessages to TRUE
  95.     linkDLL "USER"
  96.         int LockWindowUpdate(WORD)
  97.     end    linkDLL
  98.     set pObjList to $$myObjects
  99.     if pObjList is Null and object of self is not in "page,background,book"
  100.         set pObjList to self
  101.     end if
  102.     set sysLockScreen to true
  103.     while (pObjList is not NULL)
  104.         pop pObjList
  105.         $$show it
  106.     end
  107.  
  108.  -- Reset sysLockScreen, get rid of Windows' Paint message:
  109.      get LockWindowUpdate(sysClientHandle)
  110.     sysLockScreen = false
  111.     get lockWindowUpdate(0)
  112.  
  113.     transition "$$effect $$speed" to this page
  114.     unlinkDLL "USER"
  115. }
  116.  
  117. SCRIPT    "Convert textlines to a list"
  118. BEHAVIOR    "This handler converts a string delimited by CRLF's to a list delimited by commas."
  119. CATEGORIES    Text
  120. {
  121. to get textLinesToList txt
  122.     local STACK lst
  123.     step i from textlinecount(txt) to 1 by - 1
  124.         push textline i of txt onto lst
  125.     end
  126.     return lst
  127. end textLinesToList
  128. }
  129.  
  130. SCRIPT "Display 1-D array values"
  131. BEHAVIOR "Displays the contents of a one-dimensional array."
  132. CATEGORY Data
  133. {
  134. to handle request1DArray x[]
  135.     local retval
  136.     set d to dimensions(x)
  137.     step i from 1 to d
  138.         put x[i] after retval
  139.         if i < d
  140.             put crlf after retval
  141.         end    if
  142.     end    step
  143.     request retval
  144. end    request1DArray
  145. }
  146.  
  147. SCRIPT "Display 2-D array values"
  148. BEHAVIOR "Displays the contents of a two-dimensional array."
  149. CATEGORY Data
  150. {
  151.   to handle request2DArray x[][]
  152.     local retval
  153.     set d to dimensions(x)
  154.     step i from 1 to item 1 of d
  155.         step j from 1 to item 2 of d
  156.             put x[i][j] after retval
  157.             if j < item 2 of d
  158.                 put tab after retval
  159.             end    if
  160.         end    step
  161.         if i < item 1 of d
  162.             put crlf after retval
  163.         end    if
  164.     end    step
  165.     request retval
  166.  end request2DArray
  167. }
  168.  
  169. SCRIPT "Sorting a 1-D array"
  170. BEHAVIOR "This is an OpenScript implementation of the standard recursive quick sort."
  171. CATEGORIES Data
  172. {
  173. -- The next three handlers make up a  
  174. -- standard recursive QuickSort.
  175. to handle quicksort fArray[] by reference
  176.     system s_noSwap
  177.     set s_noSwap to 0
  178.     send quicksrt fArray, 1, dimensions ( fArray )
  179. end    quicksort
  180.  
  181. to handle quicksrt fArray[] by reference, lo, hi
  182.     system  s_noSwap
  183.     if hi > lo 
  184.         send swap  fArray, lo, ((lo+hi) div 2)
  185.         set lst to lo
  186.         step i from (lo+1) to hi
  187.             if fArray[i] < fArray[lo] as text
  188.                 increment lst
  189.                 send swap fArray, lst, i
  190.             else
  191.                 increment s_noswap
  192.             end
  193.         end 
  194.         send swap fArray,lo,lst 
  195.            send quicksrt fArray, lo, lst-1
  196.         send quicksrt fArray, lst+1,hi
  197.        end
  198. end    quicksrt
  199.  
  200. to handle swap fArray[] by reference, x, y
  201.     local temp
  202.     set temp to fArray[x]
  203.     set fArray[x] to fArray[y]
  204.     set fArray[y] to temp
  205. end    swap
  206. }
  207.  
  208. SCRIPT "Sorting a 2-D array"
  209. BEHAVIOR "This is an OpenScript implementation of the standard recursive quick sort adjusted for two dimensions."
  210. CATEGORIES Data
  211. {
  212. -- keep in mind that arrays are passed by reference, not by value
  213. --
  214. to handle twoDquicksort fArray[][] by reference,sortColumn,dtype
  215.     system stbk_noSwap
  216.  
  217.     set stbk_noSwap to 0
  218.     send twoDquicksrt fArray, 1, item 1 of dimensions(fArray),sortColumn,dtype
  219. end
  220.  
  221. to handle twoDquicksrt fArray[][] by reference, lo, hi,sortColumn,dtype
  222.     system  stbk_noSwap
  223.     if hi > lo 
  224.         send swap  fArray, lo, ((lo+hi) div 2)
  225.         set lst to lo
  226.         step i from (lo+1) to hi
  227.             conditions
  228.                 when dtype is "text"
  229.                     set test to fArray[i][sortColumn] < fArray[lo][sortColumn] as text
  230.                 when dtype is "date"
  231.                     set test to fArray[i][sortColumn] < fArray[lo][sortColumn] as date
  232.                 else
  233.                     set test to fArray[i][sortColumn] < fArray[lo][sortColumn] as number
  234.             end
  235.             if test
  236.                 increment lst
  237.                 send swap fArray, lst, i
  238.             else
  239.                 increment stbk_noswap
  240.             end if
  241.         end step
  242.         send swap fArray,lo,lst 
  243.            
  244.            send twoDquicksrt fArray, lo, lst-1,sortColumn,dtype
  245.         send twoDquicksrt fArray, lst+1,hi,sortColumn,dtype
  246.        end
  247. end
  248.  
  249. to handle swap fArray[][] by reference, a, b
  250.     local temp
  251.     step i from 1 to item 2 of dimensions (fArray)
  252.         set temp to farray[a][i]
  253.         set farray[a][i] to farray[b][i]
  254.         set farray[b][i] to temp
  255.     end
  256. end
  257. }
  258.  
  259. SCRIPT "Using a RECT structure"
  260. BEHAVIOR  "The following functions are useful for dealing with windows functions that require or return a RECT structure."
  261. CATEGORIES Data
  262. {
  263. -- lst is a list of 4 integers
  264. -- pRect is a locked pointer to 8 bytes
  265. to handle setRect lst,pRect
  266.     step i from 0 to 6 by 2
  267.         pop lst
  268.         get pointerInt(i,pRect,it)
  269.     end
  270. end
  271.  
  272. -- pRect is a locked pointer to 8 bytes
  273. to get getRect pRect
  274.     local retval
  275.     step i from 6 to 0 by -2
  276.         push pointerInt(i,pRect) onto retval
  277.     end
  278.     return retval
  279. end
  280. }
  281.  
  282. SCRIPT "Using Windows pointers"
  283. BEHAVIOR "The following functions are helpful if you need to allocate a pointer for calling a Windows function."
  284. CATEGORIES Windows
  285. {
  286. -- the link statements for needed functions below
  287. to handle linkMemFunctions
  288.     linkDLL "KERNEL"
  289.         WORD     GlobalAlloc(WORD,DWORD)
  290.         WORD     GlobalFree(WORD)
  291.         WORD     GlobalHandle(WORD)
  292.         POINTER GlobalLock(WORD)    
  293.         WORD     GlobalUnlock(WORD)
  294.     end linkDLL
  295. end    linkMemFunctions
  296.  
  297. to get getWinPointer nSize
  298.     local word hMem
  299.     local retValue
  300.     hMem = GlobalAlloc(66,nSize)
  301.     return GlobalLock(hMem)
  302. end getWinPointer
  303.  
  304. to get freeWinPointer pMem
  305.     local word hMem, retValue
  306.     hMem = GlobalHandle(item 1 of pMem)
  307.     retValue = GlobalUnlock(hMem)
  308.     return GlobalFree(hMem)
  309. end    freeWinPointer
  310. }
  311.  
  312. ACTION    "Create shuffled array"
  313. BEHAVIOR    "Creates an array with the elements 1 to $$num (num) in a random order."
  314. CATEGORIES     Data
  315. ARG    num is    "52"    help    "Enter the number of elements to be shuffled."
  316. {
  317.     local INT result[$$num]
  318.     local LOGICAL table[$$num]
  319.  
  320.     set i to 1
  321.     while i <= $$num
  322.         set x to random($$num)
  323.         if table[x] is not true
  324.             set table[x] to true
  325.             set result[i] to x
  326.             increment i
  327.         end    if
  328.     end while
  329. }
  330.  
  331. ACTION    "Find text in a list box"
  332. BEHAVIOR    "Searches a list box (single or multi-select) for some text and selects the line that the text is on."
  333. CATEGORIES    Text
  334. ARG    searchText    is "What are you looking for?" help "Place your text here or modify the script accordingly."
  335. ARG fieldName is "searchField" help "Set this to the name of the list box you want to search."
  336. {
  337.     set searchtext to "$$searchText"
  338. --     or try
  339. --     ask "What text would you like to search for?" with \
  340. --    "$$searchText"
  341. --     if it is null or it is "Cancel"
  342. --        break
  343. --    else
  344. --         set searchText to it
  345. --    end if        
  346.     set sysLockScreen to TRUE
  347.     set oldFT to fieldType of field "$$fieldName"
  348.     set fieldType of field "$$fieldName" to wordWrap
  349.     search for searchText
  350.     get item 3 of selectedTextState
  351.     set fieldType of field "$$fieldName" to oldFT
  352.      if it <> NULL
  353.         set selectedTextLines of field "$$fieldName" to it 
  354.         set scroll of field "$$fieldName" to it - 1 
  355.     else
  356.         request QUOTE & searchText & QUOTE && "was not found."
  357.     end if
  358. }
  359.  
  360. SCRIPT "Limit the length of an entry"
  361. BEHAVIOR "When a key is pressed, this handler checks that the charCount of the text of the field is within the limits specified in the script."
  362. CATEGORY Data
  363. {
  364. -- does not allow entry of more than specified
  365. -- amount of characters. Place this hander in a field.
  366. to handle keyChar keyPressed
  367.     local INT maxCharAllowed
  368.     local INT currentCount
  369.     maxCharAllowed = 10
  370.     currentCount = charCount(my text)
  371.     if (currentCount >= maxCharAllowed) \
  372.      or (keyPressed = keyEnter and currentCount >= \
  373.      maxCharAllowed - 1)
  374.         beep 1
  375.     else
  376.         forward
  377.     end    if
  378. end    keyChar
  379. }
  380.  
  381.  
  382. SCRIPT "Enable overwrite in a field"
  383. BEHAVIOR "Allows a field to toggle between Insert and Overwrite mode common to many word processors."
  384. CATEGORY Text
  385. {
  386. to handle keyDown key
  387.     system LOGICAL overWriteFlag
  388.     if key is keyInsert
  389.         set overWriteFlag to not overWriteFlag 
  390.     end if
  391.     forward
  392. end    keyDown
  393.  
  394. to handle keyChar key
  395.     system LOGICAL overWriteFlag
  396.     set sysLockScreen to true
  397.  
  398.     if overWriteFlag and (key <> keyBack)
  399.         send clear
  400.     end if
  401.     forward
  402. end    keyChar
  403. }
  404.  
  405. ACTION    "Sum the lines in a text field"
  406. BEHAVIOR    "This script adds the numbers on each line in the text field $$numbers and puts the result in the text field $$total."
  407. CATEGORIES    Math
  408. ARG    numbers    is    "numbers"    help "The name of the field that has the numbers in it."
  409. ARG    total    is    "total"    help "The name of the field that will have the total in it."
  410. {
  411.     set total to 0
  412.     step i from 1 to textLineCount(text of field "$$numbers")
  413.         set temp to (textline i of text of field "$$numbers")
  414.         set total to total + temp
  415.     end
  416.     put total into text of field "$$total"  
  417. }
  418.  
  419. SCRIPT "Get the sine from points"
  420. BEHAVIOR "Get the sine of an angle as described by two points and the default coordinate system."
  421. CATEGORY Math
  422. {
  423. to get sinFromPoints x1,x2,y1,y2
  424.     x = abs(x2 - x1)
  425.     y = abs(y2 - y1)
  426.     conditions
  427.     when x = 0
  428.         r = 1 
  429.     when y = 0
  430.         r = 0
  431.     else
  432.     -- this is where your high school algebra comes back to you
  433.         r = y/sqrt(x^2 + y^2)
  434.     end conditions
  435.     if y2 < y1
  436.         r = -r
  437.     end if
  438.     return r
  439. end sinFromPoints
  440. }
  441.  
  442. SCRIPT "Get the cosine from points"
  443. BEHAVIOR "Get the cosine of an angle as described by two points and the default coordinate system."
  444. CATEGORY Math
  445. {
  446. to get cosFromPoints x1,x2,y1,y2
  447.     x = abs(x2 - x1)
  448.     y = abs(y2 - y1)
  449.     conditions
  450.     when x = 0
  451.         r = 0 
  452.     when y = 0
  453.         r = 1
  454.     else
  455.     -- this is where your high school algebra comes back to you
  456.         r = x/sqrt(x^2 + y^2)
  457.     end conditions
  458.     if x2 < x1
  459.         r = -r
  460.     end if
  461.     return r
  462. end cosFromPoints
  463. }
  464.  
  465. SCRIPT "Get the angle between points" 
  466. BEHAVIOR "Returns the angle between a point on a vector (like an animation) and another point (like a mouse click)." 
  467. CATEGORY  Math 
  468. to get myAngle loc, obj, vector 
  469.     -- loc is (possibly) where the mouse was clicked
  470.     -- obj is an object reference to something (moving?) on a
  471.     -- vector, which is really a direction defined by a point, so it's a point
  472.     -- like this:
  473.     
  474.     -- . vector
  475.     --  \      . loc
  476.      --   \    /    
  477.     --    \  /
  478.     --       . obj
  479.     
  480.     -- what's the angle?
  481.     -- returns angle in radians
  482.  
  483.     system s_2PI,s_PIdiv2 
  484.     -- only calculate these once
  485.     if s_2PI is null 
  486.         set s_2PI to 2 * PI
  487.     end if 
  488.  
  489.     if s_PIdiv2 is null 
  490.         set s_PIdiv2 to PI/2 
  491.     end if
  492.      
  493.     -- see "Get the center of an object"
  494.     set yCenter to objectCenter (obj) 
  495.     pop yCenter into xCenter     
  496.     set yOffset to loc 
  497.     pop yOffset into xOffset
  498.     -- You may want these next two as system variables, because
  499.     -- they're no likely to change. 
  500.     set yVec to vector
  501.     pop yVec into xVec 
  502.     --     see "Get the cosine from points" and "Get the sine from points"
  503.     set mouseSin to (sinFromPoints(xCenter,yCenter,xOffset,yOffset)) 
  504.     set mouseCos to (cosFromPoints(xCenter,yCenter,xOffset,yOffset))
  505.     set vecSin to (sinFromPoints(xCenter,yCenter,xVec,yVec)) 
  506.     set vecCos to (cosFromPoints(xCenter,yCenter,xVec,yVec))
  507.     
  508. --    angle between them is: arctan(x2/y2) - arctan(x1/y1)
  509.     set myAngle to ((aTan2(vecCos,vecSin)) - (aTan2(mouseCos,mouseSin)) + s_PIdiv2) -- adjust quadrant
  510.  
  511.  -- determine the quadrant        
  512.     if myAngle > PI
  513.         if myAngle > s_2PI
  514.             set myAngle to myAngle mod s_2PI
  515.         else
  516.             set myAngle to (myAngle mod PI) - PI
  517.         end if
  518.     end if
  519.     return myAngle
  520. end myAngle
  521. }
  522.  
  523. SCRIPT "Search and replace text"
  524. BEHAVIOR "This function searches 'txt' for all occurrences of 'searchString' and replaces it with 'replaceString'."
  525. CATEGORIES Utilities
  526. {
  527. -- this function searches txt for all occurrences of searchString 
  528. -- and replaces it with replaceString.
  529. -- If asWord is true, replaceString replaces searchString only where 
  530. -- searchString appears as a word.
  531. -- (A word is defined as a string that is preceded and followed by
  532. -- either the beginning or end of txt, or by any character in the 
  533. -- wordDelimit string.  The wordDelimit string contains 
  534. -- space, tab, crlf, and common punctuation and mathematical operators.)
  535.  
  536. to get searchReplace txt,searchFor,replaceWith,asWord
  537.     if asWord is null
  538.         set asWord to "false"
  539.     end if
  540.     runningTotal = 1
  541.     totalChars=charcount(txt)
  542.     searchLen=charcount(searchFor)
  543.     replaceLen=charcount(replaceWith)
  544.     -- this string contains all characters that are legally adjacent
  545.     -- to a word.
  546.     wordDelimit = " " & tab & crlf & "-+*/<>,()[];^=&.?':" & quote 
  547.     while runningTotal <= totalChars
  548.         set curTxt to chars runningTotal to totalChars of txt
  549.         curOffset = offset(searchFor,curTxt)
  550.         if curOffset = 0
  551.             break while
  552.         else
  553.             startPos = (runningTotal+curOffset-1)
  554.             endPos = (runningTotal+curOffset+searchLen-2)
  555.             if asWord is true
  556.                 -- test if this occurance is an isolated word:
  557.                 if not ((startPos = 1 or char (startPos - 1) \
  558.                  of txt is in wordDelimit) and\
  559.                  (endPos = totalChars or char endPos + 1 \
  560.                  of txt is in wordDelimit))
  561.                      increment runningTotal by curOffset+searchLen-1
  562.                     continue while
  563.                 end if
  564.             end    if
  565.             set chars startPos to endPos of txt to replaceWith
  566.             increment runningTotal by curOffset+replaceLen-1
  567.             increment totalChars by replaceLen - searchLen
  568.         end    if    
  569.     end    while
  570.     return txt
  571. end    searchReplace
  572. }
  573.  
  574. SCRIPT "Change the behavior of the Back command"
  575. BEHAVIOR "Provides an alternative to the standard behavior of ToolBook's 'Back' command"
  576. CATEGORY Navigation
  577. {
  578. to handle enterApplication
  579.     system s_backMessageSent
  580.     -- initialize system variable
  581.     s_backMessageSent = false
  582.     -- turn off syshistory
  583.     syshistoryrecord = false
  584.     clear syshistory
  585.     forward
  586. end enterApplication
  587.  
  588. to handle leavePage
  589.     system s_backMessageSent
  590.     -- only puts page on syshistory if navigation is *not* initiated by BACK
  591.     if targetWindow is mainWindow
  592.         if s_backMessageSent is false
  593.             push this page onto syshistory
  594.         else
  595.             s_backMessageSent = false
  596.         end
  597.     end if
  598.     forward
  599. end leavePage
  600.  
  601. to handle back
  602.     system s_backMessageSent
  603.     if itemcount(syshistory) > 0
  604.         s_backMessageSent = true
  605.         pop syshistory
  606.         in mainwindow
  607.             go to it
  608.         end in
  609.     else
  610.         request "You are already all the way back."
  611.     end if
  612. end back
  613. }
  614.  
  615. SCRIPT "Multi-select field becomes extend-select"
  616. BEHAVIOR "This script will make a multi-select field much more versatile, acting like a single-select, multi-select or extend-select"
  617. CATEGORIES Utilities
  618. {
  619. to handle buttonDown loc,isShift,isControl
  620.     -- Script in field to be ExtendSelect
  621.     -- Click without shift, then click with shift for extended selection
  622.     -- Hold ctrl for normal multi-select
  623.     -- Without shift or control for normal single-select
  624.     system WORD s_shiftStart
  625.      -- fieldType must be multiSelect for this to work
  626.     if fieldType of self <> "multiSelect"
  627.         fieldType of self = multiSelect
  628.     end if
  629.      sysLockScreen = TRUE
  630.     conditions
  631.     when isShift
  632.         if s_shiftStart is not null
  633.             shiftEnd = item 1 of textFromPoint(loc)
  634.             if shiftEnd < s_shiftStart
  635.                 counter = -1
  636.             else
  637.                 counter = 1
  638.             end if
  639.             clear my selectedTextlines
  640.             step i from s_shiftStart to shiftEnd by counter
  641.                 push i onto my selectedTextlines
  642.             end step
  643.         end if
  644.         break buttonDown
  645.     when not isControl
  646.         clear my selectedTextlines
  647.         my selectedTextlines = item 1 of textFromPoint(loc)
  648.         sysLockScreen = FALSE
  649.     end conditions
  650.     s_shiftStart = item 1 of textFromPoint(loc)
  651.     forward
  652. end buttonDown
  653. }
  654.  
  655. SCRIPT "Drag objects"
  656. BEHAVIOR "Easy way to drag objects around at reader level."
  657. CATEGORY Utilities
  658. {
  659. to handle buttonDown loc
  660.     local STACK bnds,mouseOffset
  661.     linkDLL "user"
  662.         int getsystemmetrics(int)
  663.     end    linkDLL
  664.  
  665.     -- check if the user has swapped mouse buttons.
  666.     if getsystemmetrics(23) >0
  667.         set leftMouseButton to keyRightButton
  668.     else
  669.         set leftMouseButton to keyLeftButton
  670.     end    if
  671.  
  672.     unlinkDLL "user"
  673.     set bnds to bounds of target
  674.     set mouseOffset to item 1 of loc - item 1 of bnds,\
  675.       item 2 of loc - item 2 of bnds
  676.     
  677.     while keystate(leftMouseButton)is down
  678.         newloc = sysMousePosition
  679.         if newLoc <> loc
  680.             set position of target to \
  681.               item 1 of newLoc-item 1 of mouseOffset,\
  682.               item 2 of newLoc-item 2 of mouseOffset
  683.             set loc to newLoc
  684.         end    if
  685.     end while
  686. end    buttonDown
  687. }
  688.  
  689. SCRIPT    "Draw a selection rectangle"
  690. BEHAVIOR    "Draws a selection rectangle (rubber band) for selecting and clearing objects at reader level."
  691. CATEGORIES    Draw
  692. {
  693. to handle buttonDown loc
  694.     system xy
  695.     set myObj to objectFromPoint (loc)
  696.     if myObj = NULL or object of parent of myObj = background
  697.         draw rectangle from loc to loc
  698.         set name of selection to "selectionRectangle"
  699.         set transparent of selection to TRUE
  700.         set lineStyle of selection to dotted
  701.         set xy to position of selection
  702.     end if
  703.     
  704. end buttonDown
  705.  
  706.  
  707. to handle buttonStillDown    
  708.     send drawSelectionRectangle        
  709. end buttonStillDown
  710.  
  711. to handle buttonUp
  712.     if selectionRectangleDrawn of this page <> TRUE
  713.         break
  714.     end if
  715.     set x to item 1 of bounds of selection
  716.     set y to item 2 of bounds of selection
  717.     set cx to item 3 of bounds of selection
  718.     set cy to item 4 of bounds of selection
  719.     step i from 1 to itemCount (objects of this page)
  720.         if x < item 1 of bounds of item i of objects of this page and \
  721.             y < item 2 of bounds of item i of objects of this page and \
  722.             cx > item 3 of bounds of item i of objects of this page and \
  723.             cy > item 4 of bounds of item i of objects of this page
  724.             
  725.             extend select item i of objects of this page
  726.         end if            
  727.     end step
  728.     if itemCount (selection) >= 2 -- 1 = selectionRectangle
  729.         -- modify this clause for different behavior
  730.         request "Delete all enclosed objects?" with "Yes" or "No"
  731.         if it = "Yes"
  732.             send clear
  733.         else
  734.             set selection to rectangle "selectionRectangle"
  735.             send clear
  736.         end if
  737.     else
  738.         set selection to rectangle "selectionRectangle"
  739.         send clear
  740.     end if
  741. end buttonUp
  742.     
  743. to handle drawSelectionRectangle
  744.     system xy
  745.     set selectionRectangleDrawn of this page to TRUE    
  746.     if item 1 of sysMousePosition < item 1 of xy and \
  747.         item 2 of sysMousePosition > item 2 of xy            
  748.         set thirdQuadrant to TRUE
  749.     else
  750.         set thirdQuadrant to FALSE
  751.     end if
  752.         
  753.     if item 1 of sysMousePosition > item 1 of xy and \
  754.         item 2 of sysMousePosition < item 2 of xy            
  755.         set firstQuadrant to TRUE
  756.     else
  757.         set firstQuadrant to FALSE
  758.     end if
  759.                 
  760.     conditions        
  761.       when not thirdQuadrant and not firstQuadrant    
  762.           set temp to xy
  763.          set item 3 of temp to item 1 of sysMousePosition
  764.          set item 4 of temp to item 2 of sysMousePosition
  765.             
  766.       when thirdQuadrant and not firstQuadrant
  767.           set temp to sysMousePosition
  768.           set item 2 of temp to item 2 of xy
  769.           set item 3 of temp to item 1 of xy
  770.           set item 4 of temp to item 2 of sysMousePosition
  771.                 
  772.      when not thirdQuadrant and firstQuadrant
  773.          set temp to sysMousePosition
  774.          set item 1 of temp to item 1 of xy
  775.          set item 3 of temp to item 1 of sysMousePosition
  776.          set item 4 of temp to item 2 of xy
  777.                 
  778.     end conditions        
  779.     set bounds of selection to temp                
  780. end drawSelectionRectangle  
  781. }
  782.  
  783. SCRIPT    "Resize a polypoint object"
  784. BEHAVIOR    "This handler will proportionally size any polygon, irregularPolygon, line, angledLine, or curve."
  785. CATEGORIES    Draw
  786. {
  787. -- Proportionally resizes current object by percentage:
  788. -- Example: to make a polygon 90% of its original size, 
  789. -- you'd call this function like this:
  790. -- send resize polygon "foo",.9
  791.  
  792. to handle resize curObj,amount
  793.     set b to bounds of curobj
  794.     -- get center of object
  795.     set cx to item 1 of b + (item 3 of b - item 1 of b) /2
  796.     set cy to item 2 of b + (item 4 of b - item 2 of b) /2
  797.     -- make sure object has settable vertices
  798.     set curObjType to object of curObj
  799.     if curObjType is not in \
  800.      "polygon,irregularPolygon,line,angledLine,curve"
  801.         break
  802.     end    if
  803.     set v to vertices of curObj
  804.     -- walk through vertices, convert to polar, resize each vector,
  805.     -- convert back
  806.     step i from 1 to itemCount(v) by 2
  807.         set x to item i of v
  808.         set y to item i+1 of v
  809.         -- x,y distance of each point from center
  810.         set dx to x-cx
  811.         set dy to y-cy
  812.         -- find length and angle of vector:
  813.         -- atan2 is undefined at x=0,y=0:
  814.         if dx=0 and dy=0
  815.             set radians to 0
  816.             set h to 0
  817.         else
  818.             -- resize occurs here
  819.             set h to hypotenuse(dx,dy)*amount
  820.             set radians to atan2(dy,dx)
  821.         end    if
  822.         set item i of v to cx+cos(radians)*h
  823.         set item i+1 of v to cy+sin(radians)*h
  824.     end    step
  825.     set vertices of curObj to v
  826. end resize
  827. }
  828.  
  829. SCRIPT    "Search and replace in all a book's scripts"
  830. BEHAVIOR    "Searches through all the scripts of a book for a string and replaces it."
  831. CATEGORIES    Debug
  832. {
  833. to handle SearchNReplace
  834.     set sysTimeFormat to "seconds"
  835.     local szBackgroundName
  836.     clear sysError
  837.     ask "Enter text to be replaced:"
  838.     if sysError <> "cancel" and it is not null
  839.         set textToReplace to it
  840.     else
  841.         break buttonUp
  842.     end    if
  843.     ask "Enter text to replace" && textToReplace && "with:"
  844.     if sysError <> "cancel" and it is not null
  845.         set replaceText to it
  846.     else
  847.         break buttonUp
  848.     end    if
  849.     set startTime to sysTime
  850.     set sysCursor to 4
  851.     if script of this book contains textToReplace
  852.         step i from 1 to wordCount(script of this book)
  853.             if word i of script of this book = textToReplace as text
  854.                 put replaceText into word i of script of this book
  855.             end    if
  856.         end    step
  857.     end    if
  858.     step n from 1 to pageCount of this book
  859.         go to page n
  860.         step i from 1 to itemCount(objects of this page)
  861.             if script of item i of objects of this page contains textToReplace
  862.                 step j from 1 to wordCount(script of item i of objects of this page)
  863.                     if word j of script of item i of objects of this page = textToReplace as text
  864.                         put replaceText into word j of script of item i of objects of this page
  865.                     end    if
  866.                 end    step
  867.             end if
  868.             if object of item i of objects of this page is group
  869.                 get groupReplace(item i of objects of this page, \
  870.                         textToReplace,replaceText)
  871.             end    if
  872.         end    step
  873.         if uniqueName of this background <> szBackgroundName as text
  874.             set szBackgroundName to uniqueName of this background
  875.             step i from 1 to itemCount(objects of this background)
  876.                 if script of item i of objects of this background contains textToReplace
  877.                     step j from 1 to wordCount(script of item i of objects of this background)
  878.                         if word j of script of item i of objects of this background = textToReplace as text
  879.                             put replaceText into word j of script of item i of objects of this background
  880.                         end    if
  881.                     end    step
  882.                 end if 
  883.                 if object of item i of objects of this background is group
  884.                     get groupReplace(item i of objects of this background, \
  885.                             textToReplace,replaceText)
  886.                 end    if
  887.             end
  888.             if script of this background contains textToReplace
  889.                 step i from 1 to wordCount(script of this background)
  890.                     if word i of script of this background = textToReplace as text
  891.                         put replaceText into word i of script of this background
  892.                     end    if
  893.                 end    step
  894.             end    if
  895.         end    if
  896.         if script of this page contains textToReplace
  897.             step i from 1 to wordCount(script of this page)
  898.                 if word i of script of this page = textToReplace as text
  899.                     put replaceText into word i of script of this page
  900.                 end    if
  901.             end    step
  902.         end    if
  903.     end    step
  904.     request "Elapsed: " && sysTime - startTime && "seconds."
  905.     set sysCursor to default
  906. end    SearchNReplace
  907.  
  908. to get groupReplace groupID,textToReplace,replaceText
  909.     step i from 1 to itemCount(objects of groupID)
  910.         if script of item i of objects of groupID contains textToReplace
  911.             step n from 1 to wordCount(script of item i of objects of groupID)
  912.                 if word n of script of item i of objects of groupID = textToReplace as text
  913.                     put replaceText into word n of script of item i of objects \
  914.                             of groupID
  915.                 end    if
  916.             end    step
  917.         end    if
  918.         if object of item i of objects of groupID is group
  919.             get groupReplace(item i of objects of groupID,textToReplace, \
  920.                     replaceText)
  921.         end    if
  922.     end    step
  923.     return true
  924. end    groupReplace
  925. }
  926.  
  927. SCRIPT "Compact a ToolBook file"
  928. BEHAVIOR "Automates the process of doing garbage collection on a book. Guaranteed to work."
  929. CATEGORY Debug
  930. {
  931. -- from the scrap book
  932. to handle compactBook
  933.     LOCAL lpMem, tempFile
  934.     LOCAL INT status
  935.  
  936.     send linkDlls
  937.     lpMem = getWinPointer(192)
  938.     if lpMem = NULL
  939.         break to system
  940.     end
  941.  
  942.     sysCursor = 4
  943.     status = GetTempFileName(0,"tbk",0,lpMem)
  944.     tempFile = pointerString(0,lpMem)
  945.     fileName = name of this book
  946.     save as tempFile,TRUE
  947.     save as fileName,TRUE
  948.     get freeWinPointer(lpMem)
  949.     get removeFile(tempFile)
  950.     syscursor = default
  951. end    compactBook
  952.  
  953.  
  954. to handle linkDlls
  955.     linkDLL "kernel"
  956.         WORD    globalAlloc         (WORD,DWORD)
  957.         WORD    globalFree           (WORD)
  958.         POINTER globalLock           (WORD)
  959.         WORD    globalUnlock         (WORD)
  960.         WORD    globalReAlloc       (WORD,DWORD,WORD)
  961.         WORD     globalHandle        (INT)
  962.         INT     getTempFileName        (INT,STRING,WORD,POINTER)
  963.     end    linkDLL
  964.  
  965.     linkDLL sysToolBookDirectory & "tb30dos.dll"
  966.         INT     removeFile             (STRING)
  967.     end linkDLL
  968. end    linkDLLs
  969.  
  970.  
  971. to get getWinPointer memChunk
  972.     LOCAL memHandle, lPointer
  973.     
  974.     memHandle = globalAlloc(66, memChunk)    -- FIXED,ZEROINIT
  975.     if memHandle = NULL
  976.         return NULL
  977.     end    if
  978.     
  979.     lPointer = globalLock(memHandle)
  980.     if lPointer = NULL
  981.         return NULL
  982.     end    if
  983.     
  984.     return lPointer
  985. end    getWinPointer
  986.  
  987.  
  988. to get freeWinPointer lpointer
  989.     LOCAL WORD memHandle
  990.     LOCAL INT status
  991.     LOCAL LOGICAL passFlag
  992.     
  993.     passFlag = TRUE
  994.  
  995.     if lpointer = NULL or item 1 of lpointer < 0
  996.         return FALSE
  997.     end    if
  998.     
  999.     memHandle = globalHandle(item 1 of lpointer)
  1000.     
  1001.     status = globalUnlock(memHandle)
  1002.     if status <> 0
  1003.         passFlag = FALSE
  1004.     else
  1005.         status = globalFree(memHandle)
  1006.         if status <> 0
  1007.             passFlag = FALSE
  1008.         end    if
  1009.     end    if
  1010.     return passFlag
  1011. end    freeWinPointer
  1012. }
  1013.  
  1014. SCRIPT "Unpack a DWord to three bytes"
  1015. BEHAVIOR    "Takes a DWord and unpacks it into three bytes. Useful for getting colors and MIDI messages from Windows."
  1016. CATEGORIES    Utilities
  1017. {
  1018. to get explicitByte packedDWord    
  1019.     r = (packeddword mod 256)
  1020.     g = (packeddword mod 65536) bitShiftRight 8
  1021.     b = packeddword bitShiftRight 16
  1022.     push b onto it
  1023.     push g onto it
  1024.     push r onto it
  1025.     return it
  1026. end    explicitByte
  1027. }
  1028.  
  1029. SCRIPT "Pack three bytes into a DWord"
  1030. BEHAVIOR    "Takes three bytes and packs them into a DWord. Useful for sending colors and MIDI messages to Windows."
  1031. CATEGORIES    Utilities
  1032. {
  1033. to get packDWord rgb
  1034.     set r to item 1 of rgb
  1035.     set g to item 2 of rgb
  1036.     set b to item 3 of rgb
  1037.     set it to r + (g bitShiftLeft 8) + (b bitshiftLeft 16)
  1038.     return it
  1039. end    packDWord
  1040. }
  1041. ACTION    "Create a link to timeGetTime()"
  1042. BEHAVIOR    "Create a link to timeGetTime() for timing events. This is a better timer than getTickCount."
  1043. CATEGORY    Windows
  1044. {
  1045.     linkdll "mmSystem"
  1046.         DWORD timeGetTime()
  1047.     end
  1048. }
  1049.  
  1050. ACTION    "Flash screen"
  1051. BEHAVIOR    "Causes the ToolBook window to flash $$times times at a rate of approx. $$speed flashes per second."
  1052. CATEGORIES    Effects
  1053. ARG times is "5"  help "Can be any number of times."
  1054. ARG    speed is "100"    help "The larger the number, the faster it flashes."
  1055. {
  1056. --to handle flash  -- suggested custom message
  1057.     linkDLL "kernel"
  1058.           word     globalAlloc(word,dword)
  1059.         pointer globalLock(word)
  1060.         word     globalUnlock(word)
  1061.         word     globalFree(word)
  1062.     end    linkDLL
  1063.    
  1064.    linkDLL "user"
  1065.         word     invertRect(word,pointer)
  1066.         word     getClientRect(word,pointer)
  1067.         word     getDC(word)
  1068.         int     releaseDC(word,word)
  1069.     end    linkDLL
  1070.     
  1071.     set vHmem to globalAlloc(66, 8)
  1072.     set vPtrMem to globalLock(vHmem)
  1073.     get getClientRect(sysClientHandle,vPtrMem)
  1074.     set vHDC to getDC(sysClientHandle)
  1075.     set newSpeed to 1000/$$speed
  1076.  
  1077.     step i from 1 to $$times
  1078.         get invertRect(vHDC,vPtrMem)
  1079.         pause newSpeed ticks         
  1080.         get invertRect(vHDC,vPtrMem)
  1081.         pause newSpeed ticks
  1082.     end step
  1083.     
  1084.     get releaseDC (sysClientHandle,vHDC)
  1085.     get GlobalUnlock(vHmem)
  1086.     get GlobalFree(vHmem)
  1087.     unlinkDLL "kernel"
  1088.     unlinkDLL "user"
  1089. --end
  1090. }
  1091.  
  1092. SCRIPT    "Find the execution time"
  1093. BEHAVIOR    "Use these two handlers to make timing tests. They will automatically compare two tests run in a row."
  1094. CATEGORIES    Debug
  1095. {
  1096. to handle startTime
  1097.     system s_testTime
  1098.     linkDLL "mmSystem"
  1099.         DWORD timeGetTime()
  1100.     end    linkDLL
  1101.     set s_testTime to timeGetTime()
  1102. end    startTime
  1103.  
  1104. to handle showElapsedTime
  1105.     system s_testTime, s_lastTestTime
  1106.     
  1107.     set thisTestTime to (timeGetTime() - s_testTime) / 1000
  1108.     format number thisTestTime as "#.0"
  1109.     
  1110.     set prompt to "This test took" && thisTestTime && "seconds."
  1111.     if s_lastTestTime <> 0 and s_lastTestTime is not null
  1112.         get (thisTestTime - s_lastTestTime)
  1113.         set deltaTime to (it / min(s_lastTestTime,thisTestTime)) * 100
  1114.         format number deltaTime as "#.0"
  1115.         if deltaTime <> 0
  1116.             
  1117.             conditions
  1118.             when deltaTime < 0
  1119.                 set relation to "faster"
  1120.             when deltaTime > 0
  1121.                 set relation to "slower"
  1122.             end    conditions
  1123.  
  1124.             get abs(deltaTime)
  1125.             format number it as "#.0"
  1126.             put " It was" && it & "%" && relation &&\
  1127.               "than the previous test." after prompt
  1128.         end    if
  1129.     end    if
  1130.     request prompt
  1131.     set s_lastTestTime to thisTestTime
  1132.     unlinkDLL "mmSystem" -- decrement refCount
  1133. end    showElapsedTime
  1134. }
  1135.  
  1136. SCRIPT "Initialize a conversation with Excel"
  1137. BEHAVIOR "This function will run Excel if it is not running already.  If a filename is passed to this function it will tell Excel to load that file if it is not loaded already."
  1138. CATEGORY Windows
  1139. {
  1140. to get InitializeExcel fileNameToRun
  1141.     
  1142.     -- Get the current status of Excel
  1143.     getRemote "Status" application "Excel" topic "System"
  1144.     
  1145.     -- If it failed because there is no server
  1146.     -- run excel
  1147.     if item 1 of sysError = "Failed: No Server"
  1148.         linkDLL sysToolBookDirectory & "tb30win.dll"
  1149.             INT yieldApp()
  1150.         end linkDLL 
  1151.         run "excel.exe" && fileNameToRun
  1152.         -- give excel a break
  1153.         get yieldApp()
  1154.         getRemote "Status" application "Excel" topic "System"
  1155.         unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1156.       end    if
  1157.       
  1158.       -- getRemote status should return Ready
  1159.     if it <> "Ready" 
  1160.         return FALSE
  1161.     end if
  1162.    
  1163.        -- Make sure that it is not minimized
  1164.     executeRemote "[App.Restore()]" application "excel"
  1165.     
  1166.     -- If no file has been specified then return successfully
  1167.     if fileNameToRun = NULL 
  1168.         return TRUE
  1169.     end if
  1170.     
  1171.     -- Check to see if fFileName is open and, if so, 
  1172.     -- make it active
  1173.     executeRemote "[Activate(""" & fileNameToRun & """)]" \
  1174.      application "excel" topic fileNameToRun
  1175.     
  1176.     -- If it failed because there is no server then try 
  1177.     -- opening the file
  1178.     if item 1 of sysError = "Failed: No Server" 
  1179.         executeRemote "[Open(""" & fileNameToRun & """)]" \
  1180.          application "excel"
  1181.     end if
  1182.     
  1183.     -- If sysError is OK then success
  1184.     if item 1 of sysError = "OK" 
  1185.         return TRUE
  1186.     end if
  1187.     return FALSE
  1188. end    InitializeExcel
  1189. }
  1190.  
  1191. SCRIPT "Bring a ToolBook window to the front"
  1192. BEHAVIOR "Dynamically brings a ToolBook window to the front. Useful when running different ToolBook applications from a central book."
  1193. CATEGORY Windows
  1194. {
  1195. to handle bringWindowToFront appNameToRun
  1196.     
  1197.     linkDLL "user"  
  1198.         --bringWindowToTop is a Windows function that
  1199.         --puts the Window whose window handle is passed to it
  1200.         --in front of all the other windows.
  1201.         INT bringWindowToTop(WORD)
  1202.     end linkDLL
  1203.     
  1204.     --getRemote returns 9 separate items in sysError  
  1205.     --item 1 is the status of the remote request
  1206.        getRemote "sysWindowHandle" application  toolBook topic appNameToRun
  1207.     if (item 1 of sysError) is "OK"
  1208.         get bringWindowToTop(it)
  1209.         --bringWindowToTop doesn't size to page or even 
  1210.         --restore it
  1211.         executeRemote "send SizeToPage" application toolbook \
  1212.          topic appNameToRun
  1213.     else
  1214.         --the app isn't running, so we'll start it
  1215.         run appNameToRun
  1216.     end if
  1217.     
  1218.     unlinkDLL "user"
  1219. end bringWindowToFront
  1220. }
  1221.  
  1222. SCRIPT    "Get the screen resolution"
  1223. BEHAVIOR    "Sets the variable screenResolution to the screen resolution."
  1224. CATEGORY    Windows
  1225. {
  1226. to get screenRes
  1227.     local hRes, vRes, screenResolution
  1228.  
  1229.     linkDLL sysToolBookDirectory & "tb30win.dll"
  1230.         INT horizontalDisplayRes()
  1231.         INT verticalDisplayRes()
  1232.     end    linkDLL
  1233.     set hRes to horizontalDisplayRes()
  1234.     set vRes to verticalDisplayRes()
  1235.  
  1236.     push vRes onto screenResolution  -- item 2 is verticle resolution
  1237.     push hRes onto screenResolution  -- item 1 is horizontal resolution
  1238.  
  1239.     unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1240.     return screenResolution
  1241. end screenRes
  1242. }
  1243.  
  1244. SCRIPT "Get the resolution of the printer"
  1245. BEHAVIOR "Returns the dot per inch that the printer prints"
  1246. CATEGORY Windows
  1247. {
  1248. to get printerRes
  1249.     linkDll "GDI"
  1250.         WORD     createIC    (STRING,STRING,STRING,STRING)
  1251.         INT    getDeviceCaps    (WORD,INT)
  1252.         INT     deleteDC     (WORD)
  1253.     end linkDLL
  1254.     
  1255.     linkDLL sysToolBookDirectory & "tb30win.dll"
  1256.         STRING GetWinIniVar     (STRING, STRING)
  1257.     end linkDLL
  1258.     
  1259.     LOGPIXELSX = 88 -- Windows constants
  1260.     LOGPIXELSY = 90 
  1261.     
  1262.     driverInfo = getWinIniVar("windows", "device")
  1263.     deviceName = item 1 of driverInfo
  1264.     
  1265.     if deviceName is NULL
  1266.         set sysError to "There is no printer attached."
  1267.         unlinkDLL "GDI"
  1268.         unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1269.         return NULL
  1270.     end if
  1271.     
  1272.     deviceFile = item 2 of driverInfo
  1273.     devicePort = item 3 of driverInfo
  1274.     
  1275.     hDC = createIC(deviceFile,deviceName,devicePort,NULL)
  1276.     prnXRes = getDeviceCaps(hDC,LOGPIXELSX)
  1277.     prnYRes = getDeviceCaps(hDC,LOGPIXELSY)
  1278.     get deleteDC(hDC)
  1279.     
  1280.     unlinkDLL "GDI"
  1281.     unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1282.     return prnXRes & "," & prnYRes
  1283. end printerRes
  1284. }
  1285.  
  1286. SCRIPT "Get the display resolution"
  1287. BEHAVIOR "Gets the pixels per inch for the display monitor"
  1288. CATEGORY Windows
  1289. {
  1290. to get displayRes
  1291.     
  1292.     linkDLL sysToolBookDirectory & "tb30win.dll"
  1293.         INT    displayLogPixelsX()
  1294.         INT displayLogPixelsY()
  1295.     end linkDLL
  1296.     
  1297.     displayPixX = displayLogPixelsX()
  1298.     displayPixY = displayLogPixelsY()    
  1299.  
  1300.     unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1301.     return displayPixX & "," & displayPixY
  1302. end displayRes
  1303. }
  1304.  
  1305. SCRIPT    "Get the colors in the display"
  1306. BEHAVIOR    "Returns the number of colors displayed"
  1307. CATEGORIES    Windows
  1308. {
  1309. to get numColors
  1310.     linkDLL "gdi"
  1311.         INT getDeviceCaps(WORD,INT)
  1312.     end linkDLL
  1313.  
  1314.     linkDLL "user"
  1315.         WORD getDC(WORD)
  1316.         INT  releaseDC(WORD,WORD)
  1317.     end linkDLL
  1318.     
  1319.     hDC = getDC(windowHandle of mainWindow)
  1320.     retVal = getDeviceCaps(hDC,24) -- 24 is the magic number for colors
  1321.     get ReleaseDC(windowHandle of mainWindow, hDC)
  1322.     unlinkDLL "gdi"
  1323.     unlinkDLL "user"
  1324.     return retVal
  1325. end    numColors
  1326. }
  1327.  
  1328. SCRIPT    "Get the color of a pixel"
  1329. BEHAVIOR    "Get the color of any pixel on the screen."
  1330. CATEGORIES    Windows
  1331. {
  1332. to handle buttonClick loc
  1333.     linkDLL "user"
  1334.         WORD getDC(WORD)
  1335.         INT releaseDC(WORD,WORD)
  1336.     end    linkDLL
  1337.     
  1338.     linkDLL "gdi"
  1339.         DWORD getPixel(WORD,INT,INT)
  1340.     end    linkDLL
  1341.     
  1342.     linkDLL sysToolBookDirectory & "tb30WIN.DLL"
  1343.         STRING RGBtoHLS(DOUBLE,DOUBLE,DOUBLE)
  1344.      end    linkDLL
  1345.     
  1346.     get pageUnitsToClient(loc)
  1347.     set xCoord to item 1 of it
  1348.     set yCoord to item 2 of it
  1349.     set hDC to getDC(sysClientHandle)
  1350.     get getPixel(hDC, xCoord, yCoord)
  1351.     if it <> -1     -- unlikely
  1352.         redValue = it mod 256 -- get the lobyte of the loword
  1353.         it = it bitShiftRight 8
  1354.         greenValue = it mod 256 -- get the lobyte of the loword
  1355.         blueValue = it bitShiftRight 8
  1356.         
  1357.         set HLSValue to RGBtoHLS(redValue, greenValue, blueValue)
  1358.         if HLSValue = -20     -- very unlikely
  1359.             request "RGB to HLS conversion failed "
  1360.             unlinkDLL "gdi"
  1361.             unlinkDLL "user"
  1362.             unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1363.             break buttonUp
  1364.         end    if
  1365.         
  1366. --        set text of field "RGB" to redValue&","&greenValue&","&blueValue
  1367. --        set text of field "HLS" to HLSValue
  1368. --        set fillColor of rectangle "color" to HLSValue
  1369.         request "RGB is" && redValue&","&greenValue&","&blueValue
  1370.         request "HLS is" && HLSValue
  1371.     else 
  1372.         request "Error getting pixel."
  1373.     end    if
  1374.     get ReleaseDC(sysWindowHandle, hDC)
  1375.     unlinkDLL "gdi"
  1376.     unlinkDLL "user"
  1377.     unlinkDLL sysToolBookDirectory & "tb30win.dll"
  1378. end buttonClick
  1379. }
  1380.  
  1381. SCRIPT    "Get the running version of Windows"
  1382. BEHAVIOR    "Returns the running version of Windows."
  1383. CATEGORIES    Windows
  1384. {
  1385. to get winVersion
  1386.     linkDLL "kernel"
  1387.         DWORD GetVersion()
  1388.     end
  1389.     set verNum to GetVersion()
  1390.     set WverNum to verNum mod 65536
  1391.     set majorNumber to WverNum mod 256
  1392.     set minorNumber to WverNum div 256
  1393.     unlinkDLL "kernel"
  1394.     return majorNumber &"." & minorNumber
  1395.  end winVersion    
  1396. }
  1397.  
  1398. SCRIPT    "Get the current version of DOS"
  1399. BEHAVIOR    "Returns the running versions of DOS"
  1400. CATEGORIES    DOS
  1401. {
  1402. to get DOSVersion
  1403.     linkDLL "kernel"
  1404.         DWORD GetVersion()
  1405.     end
  1406.     set verNum to GetVersion()
  1407.     set DverNum to verNum div 65536
  1408.      set dmajorNumber to DverNum div 256
  1409.     set dminorNumber to DverNum mod 256
  1410.     unlinkDLL "kernel"
  1411.     return dmajorNumber & "." & dminorNumber
  1412. end DOSVersion
  1413. }
  1414.  
  1415. SCRIPT "Exit and restart Windows"
  1416. BEHAVIOR "This handler demonstrates a way to leave and restart Windows."
  1417. CATEGORY Windows
  1418. {
  1419. --When restart is true, Windows will exit and restart.  
  1420. --If if restart is null or false, Windows will just exit.
  1421. to handle exitWindows restart
  1422.     linkDLL "user"
  1423.         INT ExitWindows (DWORD, INT)
  1424.     end linkDLL
  1425.     if restart is true
  1426.         get ExitWindows (66, 0)
  1427.     else
  1428.         get ExitWindows (0, 0)
  1429.     end if
  1430.     -- no need to unlink this one.
  1431. end    exitWindows
  1432. }
  1433.  
  1434. ACTION "Get custom sys info"
  1435. BEHAVIOR "Returns information on the system multimedia drivers"
  1436. CATEGORIES    Multimedia
  1437. ARG mediaType oneOf "all,animation,bitmap,cdAudio,digitalVideo,overlay,sequencer,vcr,videodisc,waveAudio" is "all" help "Choose a device type."
  1438. ARG info oneOf "installname, quantity, quantity open, name 1, name 1 open" is "installname" help "Get this information about the device."
  1439. {
  1440.       sMS = sysMediaSuspend
  1441.     sysMediaSuspend = FALSE
  1442.     clear sysError
  1443.     devType = "$$mediaType"
  1444.     info = "$$info"
  1445.  
  1446.     get callMCI("sysInfo" && devType && info)
  1447.     if sysError is NULL
  1448.         request it 
  1449.     else
  1450.         if sMS = TRUE -- we'll trap the error if the user is expecting it
  1451.             request "Device" && QUOTE & devType & QUOTE && "does not understand" \
  1452.                 && QUOTE & info & QUOTE & ":" & CRLF & CRLF & sysError
  1453.         end if
  1454.     end if
  1455.     sysMediaSuspend = sMS
  1456. }
  1457.  
  1458. ACTION "Get device capabilities"
  1459. BEHAVIOR "Returns information on the capabilities of the multimedia drivers"
  1460. CATEGORIES    Multimedia
  1461. ARG mediaType oneOf "all,animation,bitmap,cdAudio,digitalVideo,overlay,sequencer,vcr,videodisc,waveAudio" is "all" help "Choose a device type."
  1462. ARG info oneOf "can eject,can freeze,can play,can record,can reverse,can save,can stretch,compound device,device type,fast play rate,has audio,has video,inputs,normal play rate,outputs,slow play rate,uses files,uses palettes,windows" is "device type" help "Get this information about the device."
  1463. {
  1464.     -- If the behavior is not supported by the driver, but is supported
  1465.     -- in the spec, this function will return FALSE. If the behavior is
  1466.     -- not supported in the spec, this will return NULL and set up
  1467.     -- a report that is shown if sysMediaSuspend is TRUE
  1468.     sMS = sysMediaSuspend
  1469.     sysMediaSuspend = FALSE
  1470.     clear sysError
  1471.     devType = "$$mediaType"
  1472.     cap = "$$info"
  1473.     get callMCI("capability" && devType && cap)
  1474.     if sysError is NULL
  1475.         request it 
  1476.     else
  1477.         if sMS = TRUE -- we'll trap the error if the user is expecting it
  1478.             request "Device" && QUOTE & devType & QUOTE && "does not understand" \
  1479.                 && QUOTE & cap & QUOTE & ":" & CRLF & CRLF & sysError
  1480.         end if
  1481.     end if
  1482.     sysMediaSuspend = sMS    
  1483. }
  1484.  
  1485.  
  1486. ACTION "Set mixer values"
  1487. BEHAVIOR "Sets the volume for the virtual audio mixer"
  1488. CATEGORIES Multimedia
  1489. ARG lineType oneOf "device_in,device_out" is "device_in" help "Choose input or output"
  1490. ARG lineSpec oneOf "AMP,AUX,CDA,MIC,MUS,WAV" is "WAV" help "Choose the MCI device to query"
  1491. ARG channel oneOf "LEFT,RIGHT,BOTH" is "BOTH" help "Choose which channel"
  1492. ARG value oneOf "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100" is "99" help "Choose the percent of full volume"
  1493. {
  1494.     -- The virtual mixer does the best it can with whatever 
  1495.     -- soundcard is on the target machine. As there is no real 
  1496.     -- standard, results will vary from card to card.
  1497.     clear sysError
  1498.     get mixerCommand("set tbkmixer $$lineType $$lineSpec control volume $$channel value")
  1499.     if it = 0
  1500.         if $$channel <> "both"
  1501.             request "Volume for the $$channel channel of the $$lineSpec device has been set to $$value"
  1502.         else
  1503.             request "Volume for both channels of the $$lineSpec device have been set to $$value"
  1504.         end if
  1505.     else
  1506.         request sysError
  1507.     end if
  1508. }
  1509.  
  1510. ACTION "Let user set mixer values for a device"
  1511. BEHAVIOR "Lets the user set the volume for the virtual audio mixer"
  1512. CATEGORIES Multimedia
  1513. ARG lineType oneOf "device_in,device_out" is "device_in" help "Choose input or output"
  1514. ARG lineSpec oneOf "AMP,AUX,CDA,MIC,MUS,WAV" is "WAV" help "Choose the MCI device to query"
  1515. {
  1516.     -- The virtual mixer does the best it can with whatever 
  1517.     -- soundcard is on the target machine. As there is no real 
  1518.     -- standard, results will vary from card to card.
  1519.     -- This script lets the author decide which device, 
  1520.     -- but lets the user decide what value
  1521.     local l_cancel,l_channel,l_value
  1522.     request "What channel would you like to set the volume of: the left, right, or both channels?" \
  1523.         with "Left" or "Right" or "Both"
  1524.     if it <> null -- null when canceled with the system button or alt-F4
  1525.         set l_channel to it
  1526.     else
  1527.         set l_cancel to TRUE,"the user canceled."
  1528.     end if
  1529.     
  1530.     if item 1 of l_cancel <> TRUE
  1531.         ask "What percent of full volume should the setting be?" with "50"
  1532.         if isType(INT,it) and it >= 0  and it <=100
  1533.             set l_value to it
  1534.         else
  1535.             set l_cancel to TRUE,"there was a bad value for volume."
  1536.         end if
  1537.     end if
  1538.     clear sysError
  1539.     if item 1 of l_cancel <> TRUE
  1540.         get mixerCommand("set tbkmixer $$lineType $$lineSpec control volume" && l_channel && l_value)
  1541.         if it = 0
  1542.             if l_channel <> "both"
  1543.                 request "Volume for the" && l_channel && "channel of the $$lineSpec device has been set to" && l_value
  1544.             else
  1545.                 request "Volume for both channels of the $$lineSpec device have been set to" && l_value
  1546.             end if
  1547.         else
  1548.             request sysError
  1549.         end if
  1550.     else
  1551.         request "The command was not executed because" && item 2 of l_cancel
  1552.     end if
  1553. }
  1554.  
  1555. ACTION "Get mixer values"
  1556. BEHAVIOR "Gets the volume for the virtual audio mixer"
  1557. CATEGORIES Multimedia
  1558. ARG lineType oneOf "device_in,device_out" is "device_in" help "Choose input or output"
  1559. ARG lineSpec oneOf "AMP,AUX,CDA,MIC,MUS,WAV" is "WAV" help "Choose the MCI device to query"
  1560. ARG channel oneOf "LEFT,RIGHT,BOTH" is "BOTH" help "Choose which channel"
  1561. {
  1562.     -- The virtual mixer does the best it can with whatever 
  1563.     -- soundcard is on the target machine. As there is no real 
  1564.     -- standard, results will vary from card to card.
  1565.     clear sysError
  1566.     get mixerCommand("get tbkmixer $$lineType $$lineSpec control volume $$channel")
  1567.     if sysError is NULL
  1568.         if $$channel <> "both"
  1569.             request "Volume for the $$channel channel of the $$lineSpec device is set to" && it
  1570.         else
  1571.             request "Volume for both channels of the $$lineSpec device are set to" && it
  1572.         end if
  1573.     else
  1574.         request sysError
  1575.     end if
  1576. }
  1577.  
  1578. ACTION "Image Command - Capability"
  1579. BEHAVIOR "Requests information about the capability of the bitmap player"
  1580. CATEGORIES Images
  1581. ARG args oneOf "compound device,device type,has files,has video,static,uses palettes" is "device type" help "Choose what capability."
  1582. {
  1583.     get imageCommand("capability placeHolder $$args")
  1584.     request it
  1585. }
  1586.  
  1587. ACTION "Image Command - Close"
  1588. BEHAVIOR "Closes the window and file associated with the alias"
  1589. CATEGORIES Images
  1590. ARG alias is "myAlias" help "The filename or the alias you want to close, or 'all' to close all open bitmaps. Keep your aliases consistent!"
  1591. {
  1592.     get imageCommand("close $$alias")
  1593. }
  1594.  
  1595. ACTION "Image Command - Info"
  1596. BEHAVIOR "Get info on the window or file associated with the alias"
  1597. CATEGORIES Images
  1598. ARG alias is "myAlias" help "The filename or the alias you want information on. Keep your aliases consistent!"
  1599. ARG args oneOf "product,text,file" is "file" help "The type of information you want."
  1600. {
  1601.     get imageCommand("info $$alias $$args")
  1602.     request it
  1603. }
  1604.  
  1605. ACTION "Image Command - Open"
  1606. BEHAVIOR "Initializes the displayer and associates the file with the alias"
  1607. CATEGORIES Images
  1608. ARG myBitmap FILE "Bitmap Files(*.BMP),*.bmp,(*.DIB),*.dib" is "Cars.bmp" help "Find the bitmap file to display."
  1609. ARG alias is "myAlias" help "The alias you want associated with this file. Keep your aliases consistent!"
  1610. ARG style oneOf "overlapped,popup,child" is "overlapped" help "Choose the style of the window."
  1611. {
  1612.     get imageCommand("open $$myBitmap alias $$alias style $$style")
  1613. }
  1614.  
  1615. ACTION "Image Command - Play"
  1616. BEHAVIOR "Play the file in the window associated with the alias"
  1617. CATEGORIES Images
  1618. ARG alias is "myAlias" help "The filename or the alias you want to play. Keep your aliases consistent!"
  1619. {
  1620.     get imageCommand("play $$alias")
  1621. }
  1622.  
  1623.  
  1624. ACTION "Image Command - Put"
  1625. BEHAVIOR "Play the file in the window associated with the alias"
  1626. CATEGORIES Images
  1627. ARG alias is "myAlias" help "The filename or the alias you want to play. Keep your aliases consistent!"
  1628. ARG whereTo oneOf "source,destination" is "destination" help "Get the offset and extent of the source or destination."
  1629. ARG x1 is "0" help "Left to right offset."
  1630. ARG y1 is "0" help "Up to down offset."
  1631. ARG x2 is "100" help "Left to right extent."
  1632. ARG y2 is "100" help "Up to down extent."
  1633. {
  1634.     get imageCommand("put $$alias $$whereTo at $$x1 $$y1 $$x2 $$y2")
  1635. }
  1636.  
  1637.  
  1638. ACTION "Image Command - Status"
  1639. BEHAVIOR "Get the status of the window and file associated with the alias"
  1640. CATEGORIES Images
  1641. ARG alias is "myAlias" help "The filename or the alias you want the status of. Keep your aliases consistent!"
  1642. ARG args oneOf "window,position,extent,size,visible,style,palette" is "position" help "The element you need the status of."
  1643. {
  1644.     get imageCommand("status $$alias $$args")
  1645.     request it
  1646. }
  1647.  
  1648. ACTION "Image Command - Where"
  1649. BEHAVIOR "Obtains the rectangle specifying the source or destination area of the image."
  1650. CATEGORIES Images
  1651. ARG whereTo oneOf "source,destination" is "destination" help "Get the offset and extent of the source or destination."
  1652. ARG alias is "myAlias" help "The filename or the alias you want. Keep your aliases consistent!"
  1653. {
  1654.     get imageCommand("where $$alias $$whereto")
  1655.     request it
  1656. }
  1657.  
  1658. ACTION "Image Command - Window"
  1659. BEHAVIOR "Change parameters of the window associated with the alias"
  1660. CATEGORIES Images
  1661. ARG alias is "myAlias" help "The filename or the alias you want to close, or 'all' to close all open bitmaps. Keep your aliases consistent!"
  1662. ARG args oneOf "text,position,size" is "position" help "Choose what aspect of the window to change."
  1663. ARG value help "For 'text', the caption of the window, or use 'default' for the name of the bitmap. For 'position'and 'size', use two pixels, e.g. '100,100'."
  1664. {
  1665.     get imageCommand("window $$alias $$args $$value")
  1666. }
  1667.  
  1668. ACTION "Image Command - Window State"
  1669. BEHAVIOR "Change the state of the window associated with the alias"
  1670. CATEGORIES Images
  1671. ARG alias is "myAlias" help "The filename or the alias you want to close, or 'all' to close all open bitmaps. Keep your aliases consistent!"
  1672. ARG value oneOf "hide,minimize,minimized,show,maximize,iconic,asIs,asWas,normal" is "show" help "Use one of these constants to more precisely control the way the window is displayed."
  1673. {
  1674.     get imageCommand("window $$alias state $$value")
  1675. }
  1676.  
  1677. ACTION    "Play a Wave file as a new clip"
  1678. BEHAVIOR "Creates a clip from a wave file using 'WaveFile' ($$WaveFile,) then plays it."
  1679. CATEGORY    Clips,Audio
  1680. ARG     waveFile FILE "Wave Files(*.WAV),*.wav" is "Chord.Wav" help "Get the wave file."
  1681. ARG clipName is "myClip" help "Give the new clip a name."
  1682. ARG startTime is "0:00:00" help "Set to a time in 'Minutes:Seconds:Milliseconds' format; defaults to beginning of the file."
  1683. ARG endTime is "0:10:00" help "Set to a time in 'Minutes:Seconds:Milliseconds' format; defaults to 10 seconds into the file."
  1684.  
  1685. {
  1686.      -- The new clip is made when this script is activated, 
  1687.      -- not when it is written, so make sure the media is 
  1688.      -- still in the right place before activating this script
  1689.       new clip from "$$WaveFile"
  1690.       name of it = "$$clipName"
  1691.       mediaRef = clip "$$clipName"
  1692.       mmTimeFormat of mediaRef = "MSms"
  1693.       mmBeginPoint of mediaRef = "$$startTime"
  1694.       mmEndPoint of mediaRef = "$$endTime"
  1695.       mmPlay mediaRef autoclose
  1696. }
  1697.  
  1698.  
  1699.  
  1700. ACTION    "Play an AVI file as a clip"
  1701. BEHAVIOR "Creates a clip from an AVI file using 'AVIFile' ($$AVIFile,) then plays it."
  1702. CATEGORY    Clips,Video
  1703. ARG     AVIFile FILE "AVI Files(*.avi),*.avi" is "windmill.avi" help "Get the wave file."
  1704. ARG clipName is "myClip" help "Give the new clip a name."
  1705. ARG startTime is "0" help "Set to frame number; defaults to beginning of the file."
  1706. ARG endTime is "300" help "Set to a frame number; defaults to frame 300."
  1707. ARG StageObj OBJTYP "Stage" is "stage myStage" help "Choose the stage object for playback"
  1708. {
  1709.      -- The new clip is made when this script is activated, 
  1710.      -- not when it is written, so make sure the media is 
  1711.      -- still in the right place before activating this script
  1712.       new clip from "$$AVIFile"
  1713.       name of it = "$$clipName"
  1714.       mediaRef = clip "$$clipName"
  1715.       mmTimeFormat of mediaRef = "frames"
  1716.       mmBeginPoint of mediaRef = "$$startTime"
  1717.       mmEndPoint of mediaRef = "$$endTime"
  1718.       mmPlay mediaRef in $$StageObj autoclose
  1719. }
  1720.  
  1721.  
  1722. ACTION    "Build and play an AVI clip w/out the clip manager"
  1723. BEHAVIOR "Allows the user to create a clip from an AVI file, then plays it."
  1724. CATEGORY    Clips,Video
  1725. ARG ClipName is "Enter a name for the new clip" help "This is the default text the user will see, or modify for your needs."
  1726. ARG StageObj OBJTYP "Stage" is "stage myStage" help "Choose the stage object for playback"
  1727. ARG BeginPoint is "Enter a beginning point for the clip in frames" help "This is the default text the user will see, or modify for your needs."
  1728. ARG EndPoint is "Enter an ending point for the clip in frames" help "This is the default text the user will see, or modify for your needs."
  1729. ARG    caption    is    "Open an AVI File"    help "This is the default text the user will see, or modify for your needs."
  1730. ARG    prompt    is    "Choose the AVI file to open" help "This is the default text the user will see, or modify for your needs."
  1731. {
  1732.      -- The new clip is made by the user, so this is more
  1733.      -- flexible than the 'Play a Wave file as a clip' script.
  1734.      -- This is a good sample script, as defauults and errorrs 
  1735.      -- are handled fairly gracefully.
  1736.     while not (sysSupportedMedia contains "digitalVideo")
  1737.         request  "Error: breaking execution of this script." & CRLF \
  1738.           & "Multimedia ToolBook is not being allowed to play digitalVideo." & CRLF \
  1739.           & "The appropriate drivers may not be available."
  1740.         break to system
  1741.     end while
  1742.     linkDll sysToolBookDirectory & "tb30dlg.dll"
  1743.         string openDlg(string,string,string,string)
  1744.     end    linkDLL
  1745.     
  1746.     get openDlg(".","*.avi","$$prompt","$$caption")
  1747.     if it <> null    
  1748.         newAVI = it
  1749.         
  1750.         do
  1751.             ask "$$ClipName" with "newClip"
  1752.             if it is null
  1753.                 request "Are you sure you want to cancel creating this clip?" \
  1754.                   with "Yes, cancel" or "No, try again"
  1755.                 if it contains "Yes"
  1756.                     break to system
  1757.                 else
  1758.                     clear it
  1759.                   end if
  1760.             end if
  1761.         until it <> null
  1762.         clipName = it
  1763.         
  1764.         new clip from newAVI
  1765.         name of it = clipName
  1766.         mediaRef = clip clipName
  1767.         while not (mmPlayable of mediaRef)
  1768.             request "This clip is not playable"
  1769.             break to system
  1770.         end while
  1771.         mmTimeFormat of mediaRef = "frames"
  1772.         
  1773.          sS = sysSuspend
  1774.         sMS = sysMediaSuspend
  1775.         sysSuspend = FALSE
  1776.         sysMediaSuspend = FALSE
  1777.                 
  1778.         ask  "$$BeginPoint" with "0"
  1779.         clear sysError
  1780.         mmBeginPoint of mediaRef = it
  1781.         if sysError <> null
  1782.             request "Error, the beginning point of the clip set to default: ""0"""
  1783.             mmBeginPoint of mediaRef = "0"
  1784.         end if
  1785.         
  1786.         ask "$$EndPoint" with "300"
  1787.         clear sysError
  1788.          mmEndPoint of mediaRef = it
  1789.         if sysError <> null
  1790.             request "Error, the ending point of the clip set to default: ""300"""
  1791.             mmEndPoint of mediaRef = "300"
  1792.         end if
  1793.         
  1794.         sysSuspend = sS
  1795.         sysMediaSuspend = sMS
  1796.         if mmPlayable of mediaRef
  1797.             mmPlay mediaRef in $$StageObj autoclose 
  1798.         end if
  1799.     end if
  1800.     
  1801.     unlinkDLL sysToolBookDirectory & "tb30dlg.dll"
  1802. }
  1803.  
  1804. ACTION    "Build and play a Wave clip"
  1805. BEHAVIOR "Allows the user to create a clip from a wave file, then plays it."
  1806. CATEGORY    Clips,Audio
  1807. ARG ClipName is "Enter a name for the new clip" help "Default is good, or modify for your needs."
  1808. ARG BeginPoint is "Enter a beginning point for the clip in 'Minutes:Seconds:Milliseconds'" help "Default is good, or modify for your needs."
  1809. ARG EndPoint is "Enter an ending point for the clip in 'Minutes:Seconds:Milliseconds'" help "Default is good, or modify for your needs."
  1810. ARG    caption    is    "Open a Wave File"    help "Default is good, or modify for your needs."
  1811. ARG    prompt    is    "Choose the wave file to open" help "Default is good, or modify for your needs."
  1812. {
  1813.      -- The new clip is made by the user, so this is more
  1814.      -- flexible than the 'Play a Wave file as a clip' script.
  1815.      -- This is a good sample script, as defauults and errorrs 
  1816.      -- are handled fairly gracefully.
  1817.  
  1818.     -- this funny structure gets around auto-script choking when it sees the break
  1819.     -- statement in an "if" structure
  1820.     while not (sysSupportedMedia contains "waveAudio")
  1821.         request  "Error: breaking execution of this script." & CRLF \
  1822.           & "The multimedia driver can not find the waveAudio device." & CRLF \
  1823.           & "The appropriate drivers may not be available."
  1824.         break to system
  1825.     end while
  1826.     linkDll sysToolBookDirectory & "tb30dlg.dll"
  1827.         string openDlg(string,string,string,string)
  1828.     end    linkDLL
  1829.     
  1830.     get openDlg(".","*.wav","$$prompt","$$caption")
  1831.     if it <> null    
  1832.         newWave = it
  1833.         
  1834.         do
  1835.             ask "$$ClipName" with "newClip"
  1836.             if it is null
  1837.                 request "Are you sure you want to cancel creating this clip?" \
  1838.                   with "Yes, cancel" or "No, try again"
  1839.                 if it contains "Yes"
  1840.                     break to system
  1841.                 else
  1842.                     clear it
  1843.                   end if
  1844.             end if
  1845.         until it <> null
  1846.         clipName = it
  1847.         
  1848.         new clip from newWave
  1849.         name of it = clipName
  1850.         mediaRef = clip clipName
  1851.         mmTimeFormat of mediaRef = "MSms"
  1852.         
  1853.          sS = sysSuspend
  1854.         sMS = sysMediaSuspend
  1855.         sysSuspend = FALSE
  1856.         sysMediaSuspend = FALSE    
  1857.         
  1858.         ask  "$$BeginPoint" with "0:00:00"
  1859.         clear sysError
  1860.         mmBeginPoint of mediaRef = it
  1861.         if sysError <> null
  1862.             request "Error, the beginning point of the clip set to default: ""0:00:00"""
  1863.             mmBeginPoint of mediaRef = "0:00:00"
  1864.         end if
  1865.         
  1866.         ask "$$EndPoint" with "0:05:00"
  1867.         clear sysError
  1868.          mmEndPoint of mediaRef = it
  1869.         if sysError <> null
  1870.             request "Error, the ending point of the clip set to default: ""0:05:00"""
  1871.             mmEndPoint of mediaRef = "0:05:00"
  1872.         end if
  1873.         
  1874.         sysSuspend = sS
  1875.         sysMediaSuspend = sMS
  1876.         if mmPlayable of mediaRef
  1877.             mmPlay mediaRef autoclose
  1878.         end if
  1879.     end if
  1880.     
  1881.     unlinkDLL sysToolBookDirectory & "tb30dlg.dll"
  1882. }
  1883.  
  1884. ACTION    "Set book to read automatically"
  1885. BEHAVIOR    "Example program for a continuously running book."
  1886. HANDLERS    enterApplication, enterBook, enterBackground, buttonClick, buttonUp, buttonDown
  1887. CATEGORIES Navigation
  1888. ARG    Effect    oneOf    "blinds,dissolve,drip,fade,iris,puzzle,tear"  is "fade"
  1889. ARG    Speed    oneOf    "Normal,Fast,Slow"    is    "Normal"    
  1890. ARG pauseTime    oneof    "1,2,3,4,5,6,7,8,9,10" is "5" help "Time in seconds to pause on a page."
  1891. {
  1892.      send reader
  1893.     send sizeToPage
  1894.     set caption of mainWindow to name of this page
  1895.     forward
  1896.      
  1897.     -- defeat imaging behavior
  1898.     set sysLockScreen to TRUE
  1899.     set sysLockScreen to FALSE
  1900.     
  1901.     show statusBar
  1902.     set caption of statusBar to "Press and hold [space] to stop demo"    
  1903.     
  1904.     while keyState(keySpace) <> down
  1905.         transition    "$$effect $$speed" to next page
  1906.         set caption of mainWindow to name of this page
  1907.         pause $$pauseTime
  1908.     end while
  1909.     set caption of statusBar to " "
  1910. }
  1911.  
  1912. ACTION "Step through a clip"
  1913. BEHAVIOR "Step through a video or animation"
  1914. CATEGORIES Clips,Stages,Videon
  1915. ARG ClipRef  Clip is "clip id 100" help "Select the clip to be played."
  1916. ARG StepSize is "1" help "Any integer value from 1 up to the frame count of the clip."
  1917. ARG StageObj OBJTYP "Stage" is "stage myStage" help "Choose the stage object for showing"
  1918. ARG StepDelay is "100" help "Delay in ticks, or one hundredths of a second, so '100' = 1 second, '50' = 1/2 of a second."
  1919. {
  1920.     if mmIsOpen of $$ClipRef
  1921.         mmClose $$ClipRef wait
  1922.     end if
  1923.     mmOpen $$ClipRef  wait
  1924.  
  1925.     oldMTF = mmTimeFormat of $$ClipRef 
  1926.     mmTimeFormat of $$ClipRef  = "frames"
  1927.     frameVar= $$StepSize
  1928.     
  1929.     maxFrame = mmLength of $$ClipRef 
  1930.     conditions
  1931.     when frameVar < 1
  1932.         frameVar = 1
  1933.     when frameVar > maxFrame
  1934.         frameVar = maxFrame
  1935.     end conditions
  1936.  
  1937.     mmCue $$ClipRef
  1938.  
  1939.     conditions
  1940.     when $$StepDelay < 1
  1941.         myDelay = 1
  1942.     when $$StepDelay > 231
  1943.         myDelay = 231
  1944.     else
  1945.         myDelay = $$StepDelay
  1946.     end conditions
  1947.     step i from 1 to (floor(maxframe/frameVar))-1
  1948.         mmShow $$ClipRef  in $$StageObj  wait
  1949.         pause myDelay
  1950.         mmStep $$ClipRef by frameVar
  1951.     end step
  1952.     mmShow clip "windmill"  in $$StageObj  wait
  1953.     mmSeek clip "windMill" to maxFrame
  1954.     mmShow clip "windmill"  in $$StageObj  wait
  1955.     mmTimeFormat of $$ClipRef  = oldMTF
  1956. }
  1957.  
  1958. SCRIPT "Continuously play a visual clip"
  1959. BEHAVIOR "Use the mmNotify message to play an animation or video clip continuously. This script would go in the page object."
  1960. CATEGORIES Clips,Video
  1961. ARG ClipRef CLIP is "clip id 100" help "Select the clip to be played."
  1962. ARG StageObj OBJTYP "Stage" is "stage myStage" help "Choose the stage object for playback"
  1963. {
  1964. to handle enterPage
  1965.     forward
  1966.     --cue and play the clip at enterPage
  1967.     mmOpen $$ClipRef
  1968.     send playScore
  1969. end enterPage
  1970.  
  1971. to handle playScore
  1972.     mmPlay $$ClipRef in $$StageObj notify self
  1973. end playScore
  1974.  
  1975. to handle mmNotify mediaRef, commandName, cResult
  1976.     if (mediaRef = $$ClipRef) and (cResult = "successful")
  1977.         send playScore
  1978.     end if
  1979. end mmNotify
  1980. }
  1981.  
  1982. SCRIPT "Continuously play any clip"
  1983. BEHAVIOR "Use the mmNotify message to play any clip continuously. This script would go in the page object."
  1984. CATEGORIES Clips
  1985. ARG ClipRef CLIP is "clip id 100" help "Select the clip to be played."
  1986. {
  1987. to handle enterPage
  1988.     forward
  1989.     --cue and play the clip at enterPage
  1990.     mmOpen $$ClipRef
  1991.     send playScore
  1992. end enterPage
  1993.  
  1994. to handle playScore
  1995.     mmPlay $$ClipRef notify self
  1996. end playScore
  1997.  
  1998. to handle mmNotify mediaRef, commandName, cResult
  1999.     if (mediaRef = $$ClipRef) and (cResult = "successful")
  2000.         send playScore
  2001.     end if
  2002. end mmNotify
  2003. }
  2004.  
  2005. SCRIPT "Set text of field to position of clip"
  2006. BEHAVIOR "Use a field to show the current position of a clip as it is being played"
  2007. CATEGORIES Utilities
  2008. ARG ClipRef CLIP is "clip id 100" help "Select the clip to be monitored."
  2009. {
  2010. -- this script goes in the field displaying the position
  2011. notifyBefore idle
  2012.     cName = $$ClipRef
  2013.     if (mmIsOpen of cName)
  2014.         oldPos = my text
  2015.         newPos = mmPosition of cName
  2016.         if oldPos <> newPos
  2017.             my text = newPos
  2018.         end if
  2019.     end if
  2020. end idle
  2021. }
  2022.  
  2023.