home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / prctclxf.sit / DemoStack / stack.txt < prev   
Text File  |  1990-08-28  |  14KB  |  486 lines

  1. -- stack: in
  2. -- format: 8 (HyperCard 1)
  3. -- flags: 0x1000 (none)
  4. -- protect password hash: 0
  5. -- maximum user level: 5 (scripting)
  6. -- window: Rect(x1=0, y1=0, x2=0, y2=0)
  7. -- screen: Rect(x1=0, y1=0, x2=0, y2=0)
  8. -- card dimensions: w=0 h=0
  9. -- scroll: x=0 y=0
  10. -- background count: 2
  11. -- first background id: 2685
  12. -- card count: 14
  13. -- first card id: 3017
  14. -- list block id: 8397
  15. -- print block id: 8547
  16. -- font table block id: 0
  17. -- style table block id: 0
  18. -- free block count: 0
  19. -- free size: 0 bytes
  20. -- total size: 99904 bytes
  21. -- stack block size: 14336 bytes
  22. -- created by hypercard version: 0x01208000
  23. -- compacted by hypercard version: 0x01208000
  24. -- modified by hypercard version: 0x01208000
  25. -- opened by hypercard version: 0x01208000
  26. -- patterns[0]: 0x0000000000000000
  27. -- patterns[1]: 0x8000000008000000
  28. -- patterns[2]: 0x8800220088002200
  29. -- patterns[3]: 0x8888222288882222
  30. -- patterns[4]: 0x88AA22AA88AA22AA
  31. -- patterns[5]: 0xCCAA33AACCAA33AA
  32. -- patterns[6]: 0xEEAABBAAEEAABBAA
  33. -- patterns[7]: 0xEEBBBBEEEEBBBBEE
  34. -- patterns[8]: 0xFFBBFFEEFFBBFFEE
  35. -- patterns[9]: 0xFFBBFFFFFFBBFFFF
  36. -- patterns[10]: 0x8010022001084004
  37. -- patterns[11]: 0xFFFFFFFFFFFFFFFF
  38. -- patterns[12]: 0x8822882288228822
  39. -- patterns[13]: 0x1122448811224488
  40. -- patterns[14]: 0xC4800C6843023026
  41. -- patterns[15]: 0xB130031BD8C00C8D
  42. -- patterns[16]: 0xAA00AA00AA00AA00
  43. -- patterns[17]: 0x8822552288225522
  44. -- patterns[18]: 0x8855225588552255
  45. -- patterns[19]: 0x77DD77DD77DD77DD
  46. -- patterns[20]: 0x8000000000000000
  47. -- patterns[21]: 0xAA55AA55AA55AA55
  48. -- patterns[22]: 0x038448300C020101
  49. -- patterns[23]: 0x8244394482010101
  50. -- patterns[24]: 0x8814224188412214
  51. -- patterns[25]: 0x8080413E080814E3
  52. -- patterns[26]: 0x22048C7422179810
  53. -- patterns[27]: 0xBE808808EB088880
  54. -- patterns[28]: 0x25C8328964244C92
  55. -- patterns[29]: 0xA29C41BE2AC914EB
  56. -- patterns[30]: 0x40A00000040A0000
  57. -- patterns[31]: 0x8040200002040800
  58. -- patterns[32]: 0xAA00800088008000
  59. -- patterns[33]: 0xFF80808080808080
  60. -- patterns[34]: 0x081C22C180010204
  61. -- patterns[35]: 0xFF808080FF080808
  62. -- patterns[36]: 0xF87422478F172271
  63. -- patterns[37]: 0xBF00BFBFB0B0B0B0
  64. -- patterns[38]: 0xFF7FBE5DA2418000
  65. -- patterns[39]: 0xFAF5FAF5A050A050
  66. -- checksum: 0x0
  67. ----- HyperTalk script -----
  68. on openStack
  69.   global userName
  70.   if (not validVersion()) then go stack "Home"
  71.   set userlevel to 5
  72.   put (userName contains "Ari Halberstadt") into me
  73.   set visible of bkgnd btn "Debugging" to me
  74.   get debugging((me) and (hilite of bkgnd btn "Debugging"))
  75.   set textArrows to true
  76.   get initRadio()
  77.   hide menubar
  78.   get lockMenuBar(false)
  79.   pass openStack
  80. end openStack
  81.  
  82. -- check version of HyperCard
  83. function validVersion
  84. if (the version < 1.2) then
  85.   answer "This stack requires HyperCard version 1.2." with "Go Home"
  86.   return false
  87. end if
  88. return true
  89. end validVersion
  90.  
  91. on closeStack
  92.   if (the version < 1.2) then pass closeStack
  93.   if (debugging() = true) then pass closeStack
  94.   get endRadio()
  95.   pass closeStack
  96. end closeStack
  97.  
  98. on openCard
  99.   if (debugging() = true) then
  100.     set the lockText of field "Description" to false
  101.     pass openCard
  102.   end if
  103.  
  104.   set the lockText of field "Description" to true
  105.   set the scroll of field "Description" to 0
  106.  
  107.   -- display the card's header
  108.   updateHeader
  109.  
  110.   pass openCard
  111. end openCard
  112.  
  113. -- Update the header displayed on most (or all) cards
  114. on updateHeader
  115.   put "DemoStack 0.9" into field "HeaderLeft"
  116.   put the short name of this card into field "HeaderRight"
  117.   put "Card #" & the number of this card into field "HeaderNumber"
  118. end updateHeader
  119.  
  120. ----------------------------------------------------------------------
  121. -- menu handlers
  122. ----------------------------------------------------------------------
  123.  
  124. on doMenu menuItem
  125.   if (menuItem = "Help") then GoHelp
  126.   else pass doMenu
  127. end doMenu
  128.  
  129. ----------------------------------------------------------------------
  130. -- misc. stuff
  131. ----------------------------------------------------------------------
  132.  
  133. -- return true if debugging, else false
  134. function debugging value
  135. global _gDebugging
  136. if (value Γëá empty) then put value into _gDebugging
  137. return _gDebugging
  138. end debugging
  139.  
  140. -- lock state of menu bar
  141. function lockMenuBar value
  142. global _gLockMenuBar
  143. if (value Γëá empty) then put value into _gLockMenuBar
  144. return _gLockMenuBar
  145. end lockMenuBar
  146.  
  147. ----------------------------------------------------------------------
  148. -- Handlers for moving around in the stack
  149. ----------------------------------------------------------------------
  150.  
  151. on GoPrevious
  152.   visual wipe right fast
  153.   go previous
  154. end GoPrevious
  155.  
  156. on GoNext
  157.   visual wipe left fast
  158.   go next
  159. end GoNext
  160.  
  161. on GoFirst
  162.   visual scroll right fast
  163.   go card 1
  164. end GoFirst
  165.  
  166. on GoLast
  167.   visual scroll left fast
  168.   go card the number of cards in this stack
  169. end GoLast
  170.  
  171. on GoBack
  172.   visual iris close
  173.   go back
  174. end GoBack
  175.  
  176. on GoHelp
  177.   visual zoom open
  178.   answer "Sorry, no help yet."
  179.   exit GoHelp
  180.   go card "Help"
  181. end GoHelp
  182.  
  183. on GoIndex
  184.   visual zoom open
  185.   go card "Index"
  186. end GoIndex
  187.  
  188. on GoHome
  189.   visual zoom close
  190.   go to this card
  191.   go home
  192. end GoHome
  193.  
  194. on GoThinkC
  195.   answer "Really launch THINK C?" with "No" or "Yes"
  196.   if (it = "Yes") then
  197.     visual zoom open
  198.     go to this card
  199.     open "THINK C 1:THINK C"
  200.   end if
  201. end GoThinkC
  202.  
  203. -------------------------------------------------------------------
  204. -- Return the line number of the field "What" based on the point
  205. -- "Where". A typical way to call this function from a field is:
  206. --     get clickLine(the target, the clickLoc)
  207. -- This function will work both for scrolling and non-scrolling
  208. -- fields.
  209. -------------------------------------------------------------------
  210. function clickLine what, where
  211. -- get the line number user clicked on
  212. put the textHeight of what into txtHt
  213. put item 2 of where into loc
  214. put item 2 of the rect of what into top
  215. put loc-top into offset
  216. if (the style of what = "scrolling") then
  217.   return( trunc( (offset + scroll of what) / txtHt ) + 1 )
  218. else
  219.   return( trunc( offset / txtHt ) + 1 )
  220. end if
  221. end clickLine
  222.  
  223. -------------------------------------------------------------------
  224. -- Put the named file into the named background field
  225. -------------------------------------------------------------------
  226. on putFileIntoField fileName, fieldName
  227.   open file fileName
  228.   if (the result <> empty) then
  229.     answer "Can't open file '" & fileName "'." with "OK"
  230.     exit putFileIntoField
  231.   end if
  232.   read from file fileName for 16384
  233.   put it into field fieldName
  234.   close file fileName
  235. end putFileIntoField
  236.  
  237. -------------------------------------------------------------------
  238. -- Put the named background field into the named file
  239. -------------------------------------------------------------------
  240. on putFieldIntoFile fieldName, fileName
  241.   open file fileName
  242.   if (the result <> empty) then
  243.     answer "Can't open file '" & fileName "'." with "OK"
  244.     exit putFieldIntoFile
  245.   end if
  246.   write field fieldName to file fileName
  247.   close file fileName
  248. end putFieldIntoFile
  249.  
  250. -----------------------------------------------------------------------
  251. -- Sort data using an array list. Returns the sorted data, or
  252. -- empty if error.
  253. -- Parameters:
  254. --   data      The data to sort
  255. --   compare   Rules for comparing items
  256. --   separator Character separating data items
  257. --   presorted If true, advises sort function that data are already
  258. --             nearly sorted.
  259. --   method    Either empty, "Sort", "QuickSort", or "ShellSort"
  260. -----------------------------------------------------------------------
  261. function listSort data, compare, separator, presorted, method
  262. set cursor to watch
  263.  
  264. -- use default method if none specified
  265. if (method = empty) then put "Sort" into method
  266.  
  267. -- get a unique name for temporary list
  268. put uniqList("listSort") into list
  269.  
  270. -- create list
  271. get alist(new, list)
  272. if (it = empty) then
  273.  
  274.   -- set sorting rules
  275.   get alist(setattribute, list, "compare", compare)
  276.   if (it = empty) then
  277.  
  278.     -- insert data
  279.     get alist(add, list, data, separator)
  280.  
  281.     if (presorted = true) then
  282.       get alist(setattribute, list, sorted, true)
  283.     end if
  284.  
  285.     if (it = empty) then
  286.       -- sort list and get results
  287.       get alist(method, list)
  288.       if (it = empty) then
  289.         put alist(get, list, separator) into data
  290.         get alist(error)
  291.       end if
  292.     end if
  293.   end if
  294. end if
  295.  
  296. -- dispose of temporary list
  297. put alist(dispose, list) into junk
  298.  
  299. -- report any errors and return
  300. if (it Γëá empty) then
  301.   answer "listSort: " & errorstring(it)
  302.   exit listSort
  303. end if
  304.  
  305. return data
  306. end listSort
  307.  
  308. -- return a name for a unique list
  309. function uniqList template
  310. global _uniqListCnt
  311.  
  312. if (_uniqListCnt = empty) then put 0 into _uniqListCnt
  313. else add 1 to _uniqListCnt
  314. return template & _uniqListCnt
  315. end uniqList
  316.  
  317. -----------------------------------------------------------------------
  318. -- Sort data using a binary tree. Returns the sorted data, or
  319. -- empty if error.
  320. -- Parameters:
  321. --   data      The data to sort
  322. --   compare   Rules for comparing items
  323. --   separator Character separating data items
  324. --   presorted If true, advises sort function that data are already
  325. --             nearly sorted.
  326. -----------------------------------------------------------------------
  327. function treeSort data, compare, separator, presorted
  328. set cursor to watch
  329. -- get a unique name for temporary tree
  330. put uniqTree("treeSort") into tree
  331.  
  332. -- create tree
  333. if (presorted = true) then
  334.   get btree(new, tree, compare, splay) -- splay trees are coming soon
  335. else
  336.   get btree(new, tree, compare)
  337. end if
  338.  
  339. if (it = empty) then
  340.  
  341.   -- insert data into tree
  342.   get btree(insert, tree, data, empty, separator)
  343.  
  344.   -- traverse tree
  345.   if (it = empty) then
  346.     put btree(inorder, tree, false, separator) into data
  347.     get alist(error)
  348.   end if
  349. end if
  350.  
  351. -- dispose of temporary tree
  352. put btree(dispose, tree) into junk
  353.  
  354. -- report any errors and return
  355. if (it <> empty) then
  356.   answer "treeSort: " & errorstring(it)
  357.   exit treeSort
  358. end if
  359.  
  360. return data
  361. end treeSort
  362.  
  363. -- return a name for a unique tree
  364. function uniqTree template
  365. global _uniqTreeCnt
  366.  
  367. if (_uniqTreeCnt = empty) then put 0 into _uniqTreeCnt
  368. else add 1 to _uniqTreeCnt
  369. return template & _uniqTreeCnt
  370. end uniqTree
  371.  
  372. -------------------------------------------------------------------
  373. -- Radio button handling using ArrayList.
  374. -- An auxillary list "_allRadioGroups" contains a list of all
  375. -- radio buttons groups. This list is used to dispose of all
  376. -- radio button groups when the endRadio handler is called.
  377. -- A radio button group is stored in an ArrayList with the
  378. -- name of the group; every item in this list corresponds to
  379. -- the name of a button.
  380. -- Handlers:
  381. -- initRadio     call before using any of the radio button routines
  382. -- endRadio      call when completely finished using the routines
  383. -- newRadio      create a new radio button group
  384. -- disposeRadio  dispose of a radio button group
  385. -- clickRadio    click a radio button
  386. -- selectedRadio return name of selected button
  387. -------------------------------------------------------------------
  388.  
  389. -- Initialize radio buttons handlers; returns error number if error
  390. function initRadio
  391. get alist(new, "_allRadioGroups")
  392. if (it Γëá empty) then return it
  393. get alist(setattribute, "_allRadioGroups", sorted, true)
  394. if (it Γëá empty) then return it
  395. get alist(setattribute, "_allRadioGroups", compare, ignorecase)
  396. if (it Γëá empty) then return it
  397. return(empty)
  398. end initRadio
  399.  
  400. -- End radio button handlers; returns error number if error
  401. function endRadio
  402. -- dispose of all groups of radio buttons
  403. put alist(get, "_allRadioGroups") into list
  404. if (alist(error) Γëá empty) then return alist(error)
  405. repeat with i=1 to the number of items in list
  406.   get alist(dispose, item i of list)
  407.   if (it Γëá empty) then return it
  408. end repeat
  409. -- dispose of master list of radio buttons
  410. get alist(dispose, "_allRadioGroups")
  411. return it
  412. end endRadio
  413.  
  414. -- Group is the name of a group; buttons is a string containing
  415. -- the names of buttons in the group; where is either "card" or
  416. -- "background". The first button in theButtons becomes hilited.
  417. -- Empty is returned if succesful, otherwise an error code is returned.
  418. function newRadio group, where, theButtons
  419.  
  420. -- create and add group to list of radio button groups
  421. get alist(new, group)
  422. if (it Γëá empty) then return it
  423. get alist(setattribute, group, compare, ignorecase)
  424. if (it Γëá empty) then return it
  425. get alist(add, "_allRadioGroups", group)
  426. if (it Γëá empty) then return it
  427.  
  428. -- build a list of buttons in the group
  429. repeat with i=1 to the number of items of theButtons
  430.   put where & " button " & quote before item i of theButtons
  431.   put quote after item i of theButtons
  432. end repeat
  433.  
  434. -- add all the buttons to the group
  435. get alist(add, group, theButtons, ",")
  436. if (it Γëá empty) then return it
  437.  
  438. -- hilite first button
  439. set hilite of item 1 of theButtons to true
  440.  
  441. -- unhilite all other buttons
  442. repeat with i=2 to the number of items of theButtons
  443.   set hilite of item i of theButtons to false
  444. end repeat
  445.  
  446. end newRadio
  447.  
  448. -- Dispose of the named radio button group.
  449. -- The list containing the group is disposed of and removed from the
  450. -- "_allRadioGroups" list.
  451. -- Empty is returned if succesful, otherwise an error code is returned.
  452. function disposeRadio group
  453. -- Remove entry from the list of all radio button groups
  454. get alist(search, "_allRadioGroups", group)
  455. get alist(delete, "_allRadioGroups" & "[" & it & "]")
  456. if (it Γëá empty) then return it
  457. -- Dispose of the group
  458. return alist(dispose, group)
  459. end disposeRadio
  460.  
  461. -- Click on the button in the group.
  462. -- The first button is always the button currently hilited, which
  463. -- means we only have to set the hilite property of two buttons:
  464. -- the button being hilited and the button being unhilited.
  465. on clickRadio group, theButton
  466.  
  467.   -- get index to button
  468.   put alist(search, group&"[2ΓǪ]", theButton) into index
  469.   if (index = empty) then exit clickRadio
  470.  
  471.   -- swap the locations of the buttons so hilited button is first
  472.   put alist(get, group&"[1]") into current
  473.   get alist(set, group&"[1]", theButton)
  474.   get alist(set, group&"["&index&"]", current)
  475.  
  476.   -- unhilite current button and hilite clicked button
  477.   set hilite of current to false
  478.   set hilite of theButton to true
  479. end clickRadio
  480.  
  481. -- Return the currently hilited button in the group
  482. function selectedRadio group
  483. return alist(get, group&"[1]")
  484. end selectedRadio
  485.  
  486.