home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC08ListLineEd / Lists.asm < prev    next >
Encoding:
Assembly Source File  |  1990-05-25  |  62.2 KB  |  1,713 lines  |  [04] ASCII Text (0x0000)

  1. *******************************************************************************
  2. *
  3. * List Manager/LineEdit Demo -- Version 3.0
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Keith Rollin and Jim Mensch
  11. *
  12. * This program demonstrates the use of lists and LineEdit items in a window. It
  13. * uses controls to create, rename, remove and sort items in a list, and uses a
  14. * LineEdit item to enter new and rename old items. Cut, Copy, Paste, and Clear
  15. * are supported.
  16. *
  17. *******************************************************************************
  18.                     eject
  19.                     
  20. **********************************************************************
  21. *                                                                    *
  22. *             Apple IIGS Source Code Sampler, Volume I               *
  23. *                                                                    *
  24. *             Copyright (c) Apple Computer, Inc. 1988-1990           *
  25. *                       All Rights Reserved                          *
  26. *                                                                    *
  27. *            Written by Apple II Developer Tech Support              *
  28. *                                                                    *
  29. *                                                                    *
  30. *                                                                    *
  31. *  ----------------------------------------------------------------  *
  32. *                                                                    *
  33. *     This program and its derivatives are licensed only for         *
  34. *     use on Apple computers.                                        *
  35. *                                                                    *
  36. *     Works based on this program must contain and                   *
  37. *     conspicuously display this notice.                             *
  38. *                                                                    *
  39. *     This software is provided for your evaluation and to           *
  40. *     assist you in developing software for the Apple IIGS           *
  41. *     computer.                                                      *
  42. *                                                                    *
  43. *     DISCLAIMER OF WARRANTY                                         *
  44. *                                                                    *
  45. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  46. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  47. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  48. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  49. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  50. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  51. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  52. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  53. *     REPAIR OR CORRECTION.                                          *
  54. *                                                                    *
  55. *     Apple does not warrant that the functions                      *
  56. *     contained in the Software will meet your requirements          *
  57. *     or that the operation of the Software will be                  *
  58. *     uninterrupted or error free or that defects in the             *
  59. *     Software will be corrected.                                    *
  60. *                                                                    *
  61. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  62. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  63. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  64. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  65. *     WHICH VARY FROM STATE TO STATE.                                *
  66. *                                                                    *
  67. *                                                                    *
  68. **********************************************************************
  69.                     eject
  70.                     
  71.                     case   on
  72.  
  73.                     copy 2/ainclude/E16.Quickdraw
  74.                     copy 2/ainclude/E16.Memory
  75.                     copy 2/ainclude/E16.EVENT
  76.                     copy 2/ainclude/E16.Control
  77.                     copy 2/ainclude/E16.Window
  78.                     copy 2/ainclude/E16.Dialog
  79.                     copy 2/ainclude/E16.List
  80.                     mcopy macros/lists.macros
  81.  
  82. *******************************************************************************
  83. *
  84. *    Equates used in this program.
  85. *
  86. *******************************************************************************
  87. DPHandle            gequ 0              ; Handle to Tool Direct Page area
  88. DPPointer           gequ DPHandle+4     ; Pointer to Tool Direct Page area
  89. deref               gequ DPPointer+4    ; Temporary Handle dereference area
  90. TempLong            gequ deref+4
  91. TempWord            gequ TempLong+4
  92.  
  93. ScreenMode          gequ mode640
  94. ScreenWidth         gequ 640
  95.  
  96.  
  97.                     EJECT
  98. *******************************************************************************
  99. *
  100. Main                start
  101. *
  102. * Description:      This is the main routine. It calls routines to Initialize
  103. *                   the tools, initialize application specific data, run the
  104. *                   main EventLoop, close the application, and close the tools.
  105. *                   Then it calls the ProDOS Quit command.
  106. *
  107. *
  108. * Inputs:           NONE
  109. *
  110. * Outputs:          NONE
  111. *
  112. * External Refs:
  113. *                   Import InitTools
  114. *                   Import InitApp
  115. *                   Import EventLoop
  116. *                   Import CloseApp
  117. *                   Import CloseTools
  118. *                   Import QuitParms
  119. *
  120. * Entry Points:     NONE
  121. *
  122. *******************************************************************************
  123.  
  124.                     jsr InitTools
  125.                     jsr InitApp
  126.  
  127.                     _ShowCursor
  128.  
  129.                     jsr EventLoop
  130.  
  131.                     jsr CloseApp
  132.                     jsr CloseTools
  133.  
  134.                     _Quit QuitParms
  135.  
  136.                     end
  137.  
  138.                     EJECT
  139. *******************************************************************************
  140. *
  141. Globals             data
  142. *
  143. * Description:      Holder of all of our data.
  144. *
  145. *
  146. * Inputs:           N/A
  147. *
  148. * Outputs:          N/A
  149. *
  150. * External Refs:
  151. *                   Import PrUpdate
  152. *                   Import PrOldUpdate
  153. *
  154. * Entry Points:
  155. *                   Export QuitParms    ; used by Main
  156. *
  157. *******************************************************************************
  158. *
  159. * Standard global data
  160. *
  161. *******************************************************************************
  162.  
  163. TitleString         str 'Apple IIgs List Mgr/LineEdit Example Application'
  164. AutString           str 'By Rollin and Mensch Apple DTS -- Version: 3.0'
  165. VersString          str 'Copyright (c) 1988-1990 Apple Computer'
  166.  
  167. MenuHeight          ds 2                ; Stored height of menu bar
  168. MyID                ds 2                ; Application ID
  169. MyDP                ds 2                ; My direct page storage
  170.  
  171. QuitFlag            ds 2
  172. QuitParms           dc i4'0'            ; Pathname of next app
  173.                     dc i2'$00'          ; flags
  174.  
  175. EventRecord         ANOP
  176. EventWhat           ds 2
  177. EventMessage        ds 4
  178. EventWhen           ds 4
  179. EventWhere          ds 4
  180. EventModifiers      ds 2
  181. TaskData            ds 4
  182. TaskMask            dc i4'$0000FFFF'
  183.  
  184.                     EJECT
  185. *******************************************************************************
  186. *
  187. * Application specific global data
  188. *
  189. *******************************************************************************
  190.  
  191. ; This is a list of pointers to the text that is used to create our menus. It
  192. ; is used by InitApp to find all of the menu templates and use them to create
  193. ; our menubar. This loop loads MenuPtrLen-4 into an index, gets the
  194. ; corresponding menu template pointer in this table, and uses that in a
  195. ; NewMenu call. It then decrements the index by 4, and repeats the procees
  196. ; until the index is negative.
  197.  
  198. MenuPtr             dc i4'AppMenu'
  199.                     dc i4'FileMenu'
  200.                     dc i4'EditMenu'
  201. MenuPtrLen          equ *-MenuPtr
  202.  
  203.  
  204. ; Menu list: menu items should be numbered consecutivly starting from 250.
  205. ; As a convention, use 256 as about and 257 as Quit.
  206.  
  207. AppMenu             dc c'$$@\XN1',i1'$0D'
  208.                     dc c'--About List Manager/LineEdit Demo...\N256V',i1'$00'
  209.                     dc c'.'
  210. FileMenu            dc c'$$  File  \N2',i1'$00'
  211.                     dc c'--Close Document\N255DV',i1'$00'
  212.                     dc c'--Quit\N257*Qq',i1'$00'
  213.                     dc c'.'
  214. EditMenu            dc c'$$  Edit  \N3',i1'$00'
  215.                     dc c'--Undo\N250*ZzVD',i1'$00'
  216.                     dc c'--Cut\N251*Xx',i1'$00'
  217.                     dc c'--Copy\N252*Cc',i1'$00'
  218.                     dc c'--Paste\N253*Vv',i1'$00'
  219.                     dc c'--Clear\N254',i1'$00'
  220.                     dc c'.'
  221.  
  222. ErrOut              ds 4
  223. TempSave            ds 4
  224. TempHndl            ds 4
  225.  
  226. ;
  227. ;   Control definitions for use with new control
  228. ;
  229. NumCtrls            dc i2'5'
  230. MyCtrlList          dc i4'NewBRec,DelBRec,RepBRec,RstBRec,SortBRec'
  231.  
  232. MyCtlHdls           ANOP
  233. NewBHdl             ds 4                ; storage for returned handles
  234. DelBHdl             ds 4
  235. RepBHdl             ds 4
  236. RstBHdl             ds 4
  237. SortBHdl            ds 4
  238. LEHandle            ds 4
  239.  
  240. NewBTitle           str 'New Entry'
  241. DelBTitle           str 'Remove'
  242. RepBTitle           str 'Replace'
  243. RstBTitle           str 'UnHilite'
  244. SortBTitle          str 'Sort'
  245.  
  246. NewBRect            dc i2'10,250,25,350'
  247. DelBRect            dc i2'30,250,45,350'
  248. RepBRect            dc i2'50,250,65,350'
  249. RstBRect            dc i2'70,250,85,350'
  250. SortBRect           dc i2'90,250,105,350'
  251. destRect            dc i2'100,20,110,224'
  252. viewRect            dc i2'97,10,113,234'
  253.  
  254. NewBRec             ANOP
  255.                     dc i4'0'
  256.                     dc i4'1'
  257.                     dc i4'simpleProc'   ; defproc = simple button
  258.                     dc i2'0,0'          ; no params
  259.                     dc i2'1'            ; starting value
  260.                     dc i2'boldButton'   ; control flags
  261.                     dc i4'NewBTitle'    ; pointer to title string
  262.                     dc i4'NewBRect'     ; pointer to bounds rect
  263. cRecSize            equ *-NewBRec       ; size of my control record
  264.  
  265. DelBRec             ANOP
  266.                     dc i4'0'            ; color table pointer
  267.                     dc i4'2'            ; refcon ( control dispatch number )
  268.                     dc i4'simpleProc'   ; defproc = simple button
  269.                     dc i2'0,0'          ; no params
  270.                     dc i2'1'            ; starting value
  271.                     dc i2'simpRound'    ; control flags
  272.                     dc i4'DelBTitle'    ; pointer to title string
  273.                     dc i4'DelBRect'     ; pointer to bounds rect
  274.  
  275.  
  276. RepBRec             ANOP
  277.                     dc i4'0'            ; color table pointer
  278.                     dc i4'3'            ; refcon ( control dispatch number )
  279.                     dc i4'simpleProc'   ; defproc = simple button
  280.                     dc i2'0,0'          ; no params
  281.                     dc i2'1'            ; starting value
  282.                     dc i2'simpRound'    ; control flags
  283.                     dc i4'RepBTitle'    ; pointer to title string
  284.                     dc i4'RepBRect'     ; pointer to bounds rect
  285.  
  286. RstBRec             ANOP
  287.                     dc i4'0'            ; color table pointer
  288.                     dc i4'4'            ; refcon ( control dispatch number )
  289.                     dc i4'simpleProc'   ; defproc = simple button
  290.                     dc i2'0,0'          ; no params
  291.                     dc i2'1'            ; starting value
  292.                     dc i2'simpRound'    ; control flags
  293.                     dc i4'RstBTitle'    ; pointer to title string
  294.                     dc i4'RstBRect'     ; pointer to bounds rect
  295.  
  296. SortBRec            ANOP
  297.                     dc i4'0'            ; color table pointer
  298.                     dc i4'6'            ; refcon ( control dispatch number )
  299.                     dc i4'simpleProc'   ; defproc = simple button
  300.                     dc i2'0,0'          ; no params
  301.                     dc i2'1'            ; starting value
  302.                     dc i2'simpRound'    ; control flags
  303.                     dc i4'SortBTitle'   ; pointer to title string
  304.                     dc i4'SortBRect'    ; pointer to bounds rect
  305.  
  306.  
  307. FullRect            dc i2'0,0,120,400'
  308. ListCtlHndl         ds 4
  309.  
  310. MemberSize          equ 10
  311.  
  312. MyList              ANOP                ; List record
  313. ListRect            dc i2'10,10,92,210' ; list is 200x80
  314. MLNum               dc i2'5'            ; number of members in the list
  315.                     dc i2'8'            ; max seen at once
  316.                     dc i2'selectOnlyOne'                    ; single selection/pascal strings
  317.                     dc i2'1'            ; list start
  318.                     dc i4'0'            ; list control handle
  319.                     dc i4'0'            ; no list draw
  320.                     dc i2'10'           ; list member height
  321.                     dc i2'MemberSize'   ; list record size
  322.                     dc i4'MyData'       ; pointer to member list
  323.                     dc i4'5'            ; list ref con (control dispatch number)
  324.                     dc i4'0'            ; color table pointer (default colors)
  325.  
  326. ;
  327. ; These are the data records for each member of the list. Each one consists of:
  328. ;      - a pointer to the string to be printed
  329. ;      - a word of bit flags (only the lower byte is used; the upper byte is
  330. ;        used as padding to make data access easier.
  331. ;      - a 4 byte space to hold a handle for those items whose names have been
  332. ;        stored in the heap with the Memory Manager
  333. ; We define only 5 members initially. However, we reserve space in the member
  334. ; record array for 30 members total.
  335.  
  336. MyData              dc i4'member1'
  337.                     dc i2'0'
  338.                     dc i4'0'
  339.                     dc i4'member2'
  340.                     dc i2'0'
  341.                     dc i4'0'
  342.                     dc i4'member3'
  343.                     dc i2'0'
  344.                     dc i4'0'
  345.                     dc i4'member4'
  346.                     dc i2'0'
  347.                     dc i4'0'
  348.                     dc i4'member5'
  349.                     dc i2'0'
  350.                     dc i4'0'
  351.                     ds 25*MemberSize    ; and at the end, room for 25 more
  352. MyDataTSize         equ *-MyData
  353.  
  354. member1             str 'Member 1'
  355. member2             str 'Member 2'
  356. member3             str 'Member 3'
  357. member4             str 'Member 4'
  358. member5             str 'Member 5'
  359.  
  360. MyWindow            dc i2'WindEnd-*'    ; size of paramBlock
  361.                     dc i2'%0010000000100000' ; frame bits : alert, vis
  362.                     dc i4'0'            ; no title bar, no title...
  363.                     dc i4'0'            ; ref con 0
  364.                     dc i2'0,0,0,0'      ; zoomed rect
  365.                     dc i4'0'            ; color table = default
  366.                     dc i2'0,0'          ; scroll bar XY origin
  367.                     dc i2'0,0'          ; no scroll no max...
  368.                     dc i2'0,0'          ; No zooming...
  369.                     dc i2'0,0'          ; no scrolling
  370.                     dc i2'0,0'          ; no paging....
  371.                     dc i4'0'            ; no info bar, no ref con
  372.                     dc i2'0'            ; info bar height (none...)
  373.                     dc i4'0'            ; Frame defproc, NIL=standard
  374.                     dc i4'0'            ; no info bar def proc
  375.                     dc i4'0'            ; no auto updates..(yet)
  376.                     dc i2'20,20,140,420'                    ; bounds rect...
  377.                     dc i4'$FFFFFFFF'    ; plane= on top...
  378.                     dc i4'0'            ; NIL storage pointer
  379. WindEnd             equ *
  380. WindPointer         ds 4
  381.  
  382.                     end
  383.  
  384.  
  385.                     EJECT
  386. *******************************************************************************
  387. *
  388. InitApp             start
  389. *
  390. * Description:      Perform any application specific initialization.
  391. *
  392. * Inputs:           NONE
  393. *
  394. * Outputs:          NONE
  395. *
  396. * External Refs:    
  397. *                   Import CreateList
  398. *                   Import CreateCtrls
  399. *                   Import NoSelection
  400. *
  401. * Entry Points:     NONE
  402. *
  403. *******************************************************************************
  404.                     using Globals
  405.  
  406.                     stz QuitFlag
  407.  
  408.                     pha
  409.                     pha
  410.                     PushLong #MyWindow
  411.                     _NewWindow
  412.                     PullLong WindPointer
  413.  
  414.                     PushLong WindPointer
  415.                     _SetPort
  416.  
  417.                     jsr CreateList      ; make a list in the window
  418.                     jsr CreateCtrls
  419.                     jsr NoSelection     ; reset the buttons to unselected
  420.  
  421.                     PushWord #255       ; deactivate the delete button
  422.                     PushLong NewBHdl    ; handle to the delete button
  423.                     _HiLiteControl
  424.  
  425.                     PushWord #25        ; set the size of LineEdit's
  426.                     _LESetScrapLen      ; scrap to 25 characters
  427.  
  428.                     rts
  429.                     end
  430.  
  431.                     EJECT
  432. *******************************************************************************
  433. *
  434. CloseApp            start
  435. *
  436. * Description:      Close down things. This disposes of all items and memory
  437. *                   that we allocated.
  438. *
  439. *
  440. * Inputs:           NONE
  441. *
  442. * Outputs:          NONE
  443. *
  444. * External Refs:    NONE
  445. *
  446. * Entry Points:     NONE
  447. *
  448. *******************************************************************************
  449.                     using Globals
  450.  
  451.                     rts
  452.                     end
  453.  
  454.                     EJECT
  455. *******************************************************************************
  456. *
  457. EventLoop           start
  458. *
  459. * Description:      Main Event Loop. Handle things until user selects Quit.
  460. *
  461. *
  462. * Inputs:           NONE
  463. *
  464. * Outputs:          NONE
  465. *
  466. * External Refs:
  467. *                   Import MenuSelect
  468. *                   Import Ignore
  469. *                   Import doUpdate
  470. *                   Import InContent
  471. *                   Import doActivate
  472. *                   Import doKey
  473. *
  474. * Entry Points:     NONE
  475. *
  476. *******************************************************************************
  477.                     using Globals
  478.  
  479.                     PushLong LEHandle   ; flash the LineEdit cursor
  480.                     _LEIdle
  481.  
  482.                     pha                 ; Push on space for TaskMaster result
  483.                     PushWord #everyEvent ; GetNextEvent mask
  484.                     PushLong #EventRecord ; Pointer to Event Record
  485.                     _TaskMaster
  486.  
  487.                     pla                 ; Get TaskMaster result
  488.                     beq EventLoop       ; Remove if you want to use null events
  489.                     asl A               ; Turn it into an index
  490.                     tax
  491.                     jsr (TaskTable,x)   ; Call appropriate event handler
  492.  
  493.                     lda QuitFlag        ; Quit selected?
  494.                     beq EventLoop       ; no - keep looping
  495.  
  496.                     rts                 ; yes- leave the program
  497.  
  498. TaskTable           dc i2'Ignore'       ; 0 Null
  499.                     dc i2'Ignore'       ; 1 MouseDown
  500.                     dc i2'Ignore'       ; 2 MouseUp
  501.                     dc i2'doKey'        ; 3 KeyDown
  502.                     dc i2'Ignore'       ; 4 undefined
  503.                     dc i2'doKey'        ; 5 AutoKey
  504.                     dc i2'doUpdate'     ; 6 Update
  505.                     dc i2'Ignore'       ; 7 undefined
  506.                     dc i2'doActivate'   ; 8 Activate
  507.                     dc i2'Ignore'       ; 9 Switch
  508.                     dc i2'Ignore'       ; 10 Desk accessory
  509.                     dc i2'Ignore'       ; 11 Device driver
  510.                     dc i2'Ignore'       ; 12 ap
  511.                     dc i2'Ignore'       ; 13 ap
  512.                     dc i2'Ignore'       ; 14 ap
  513.                     dc i2'Ignore'       ; 15 ap
  514.                     dc i2'Ignore'       ; TASK 0 indesk
  515.                     dc i2'MenuSelect'   ; TASK 1 in menuBar
  516.                     dc i2'Ignore'       ; TASK 2 in system window
  517.                     dc i2'InContent'    ; TASK 3 in content
  518.                     dc i2'Ignore'       ; TASK 4 in Drag
  519.                     dc i2'Ignore'       ; TASK 5 in grow
  520.                     dc i2'Ignore'       ; TASK 6 in goaway
  521.                     dc i2'Ignore'       ; TASK 7 in zoom
  522.                     dc i2'Ignore'       ; TASK 8 in info bar
  523.                     dc i2'MenuSelect'   ; TASK 9 in special menu
  524.                     dc i2'Ignore'       ; TASK 10 in NDA
  525.                     dc i2'Ignore'       ; TASK 11 in frame
  526.                     dc i2'Ignore'       ; TASK 12 in drop
  527.  
  528.                     end
  529.  
  530.                     EJECT
  531. *******************************************************************************
  532. *
  533. MenuSelect          start
  534. *
  535. * Description:      This routine is called when TaskMaster returns a menu
  536. *                   event. It takes the menu item that was hit and calculates
  537. *                   an offset into the menu dispatch table. It then calls that
  538. *                   routine and unhilites the menu when it is done.
  539. *
  540. * Inputs:           TaskData holds menu item selected.
  541. *
  542. * Outputs:          NONE
  543. *
  544. * External Refs:
  545. *                   Import Ignore
  546. *                   Import doAbout
  547. *                   Import doQuit
  548. *                   Import doCut
  549. *                   Import doCopy
  550. *                   Import doPaste
  551. *                   Import doClear
  552. *
  553. * Entry Points:     NONE
  554. *
  555. *******************************************************************************
  556.                     using Globals
  557.  
  558.                     lda TaskData        ; Get the ID of the menu item selected.
  559.                     sec                 ; Turn it into an index by subtracting
  560.                     sbc #250            ; the starting ID number (25) and mul-
  561.                     asl a               ; tiplying by 2 (each table entry con-
  562.                     tax                 ; sists of 2 bytes).
  563.                     jsr (MenuTable,x)   ; Call the routine behind it.
  564.  
  565.                     PushWord #0         ; Routine done - unhilite the menubar.
  566.                     PushWord TaskData+2
  567.                     _HiLiteMenu
  568.  
  569.                     rts
  570.  
  571. MenuTable           dc i2'Ignore'       ; undo
  572.                     dc i2'doCut'        ; cut
  573.                     dc i2'doCopy'       ; copy
  574.                     dc i2'doPaste'      ; paste
  575.                     dc i2'doClear'      ; clear
  576.                     dc i2'Ignore'       ; close
  577.                     dc i2'doAbout'
  578.                     dc i2'doQuit'
  579.                     end
  580.  
  581.                     EJECT
  582. *******************************************************************************
  583. *
  584. Ignore              start
  585. *
  586. * Description:      Called when I want to ignore an event.
  587. *
  588. *
  589. * Inputs:           NONE
  590. *
  591. * Outputs:          NONE
  592. *
  593. * External Refs:    NONE
  594. *
  595. * Entry Points:     NONE
  596. *
  597. *******************************************************************************
  598.  
  599.                     rts
  600.                     end
  601.  
  602.                     EJECT
  603. *******************************************************************************
  604. *
  605. doUpdate            start
  606. *
  607. * Description:      Called by the Main Event Loop to update a window's
  608. *                   contents.
  609. *
  610. *
  611. * Inputs:           NONE
  612. *
  613. * Outputs:          NONE
  614. *
  615. * External Refs:    NONE
  616. *
  617. * Entry Points:     NONE
  618. *
  619. *******************************************************************************
  620.                     using Globals
  621.  
  622.                     lda WindPointer     ; first test to see that its our window
  623.                     ora WindPointer+2
  624.                     beq NotUp           ; bad bad update event!
  625.  
  626.                     PushLong WindPointer ; Prepare to update our window
  627.                     _BeginUpdate
  628.  
  629.                     PushLong WindPointer ; draw all of the controls
  630.                     _DrawControls
  631.  
  632.                     PushLong #viewRect  ; frame our lineEdit item
  633.                     _FrameRect
  634.  
  635.                     PushLong LEHandle   ; update the LineEdit item
  636.                     _LEUpdate
  637.  
  638.                     PushLong WindPointer ; end updating of our window
  639.                     _EndUpdate
  640.  
  641. NotUp               ANOP
  642.                     rts
  643.                     end
  644.  
  645.                     EJECT
  646. *******************************************************************************
  647. *
  648. doActivate          start
  649. *
  650. * Description:      This routine is called when our window is either coming
  651. *                   to front, or no longer being in front. Its main function
  652. *                   is to make the LineEdit item (in)active.
  653. *
  654. *
  655. * Inputs:           Event record from TaskMaster
  656. *
  657. * Outputs:          NONE
  658. *
  659. * External Refs:    NONE
  660. *
  661. * Entry Points:     NONE
  662. *
  663. *******************************************************************************
  664.                     using Globals
  665.  
  666.                     PushLong LEHandle
  667.                     lda EventModifiers
  668.                     and #activeFlag
  669.                     bne Activate
  670.                     _LEDeactivate
  671.                     bra done
  672. Activate            _LEActivate
  673. done                ANOP
  674.                     rts
  675.                     end
  676.  
  677.                     EJECT
  678. *******************************************************************************
  679. *
  680. doKey               start
  681. *
  682. * Description:      Called by the Main Event loop when a Keydown or AutoKey
  683. *                   Event occurs. If the RETURN key was hit, a hit on the
  684. *                   "New Item" button is simulated. Otherwise, the key press
  685. *                   is passed on to LEKey.
  686. *
  687. *
  688. * Inputs:           Event record from TaskMaster
  689. *
  690. * Outputs:          LineEdit or List is modified
  691. *
  692. * External Refs:    
  693. *                   Import NewListItem
  694. *                   Import ckNewAndRep
  695. *
  696. * Entry Points:     NONE
  697. *
  698. *******************************************************************************
  699.                     using Globals
  700.  
  701.                     lda EventMessage    ; get the character pressed
  702.                     and #$007f          ; clear the high if it's set
  703.                     cmp #$0D            ; see if it's a <RETURN> 
  704.                     beq doCR            ; if is one, simulate New Item hit
  705.                     PushWord EventMessage ; else, pass this on to LEKey
  706.                     PushWord EventModifiers
  707.                     PushLong LEHandle
  708.                     _LEKey
  709.  
  710.                     jsr ckNewAndRep     ; update the New and Replace buttons
  711.                     bra done
  712.  
  713. doCR                ANOP
  714.                     PushWord #1         ; Hilite the New button
  715.                     PushLong NewBHdl
  716.                     _HiLiteControl
  717.  
  718.                     PushWord #0         ; UnHilite the New button
  719.                     PushLong NewBHdl
  720.                     _HiLiteControl
  721.  
  722.                     jsr NewListItem     ; add the LineEdit text to the list.
  723.  
  724. done                ANOP
  725.                     rts
  726.                     end
  727.  
  728.                     EJECT
  729. *******************************************************************************
  730. *
  731. doEdit              start
  732. *
  733. * Description:      This block is really 4 routines to handle the Edit Menu.
  734. *                   Any Edit selections are passed on to the appropriate
  735. *                   LineEdit routine. Undo is currently not supported.
  736. *
  737. *
  738. * Inputs:           NONE
  739. *
  740. * Outputs:          NONE
  741. *
  742. * External Refs:
  743. *                   Import ckNewAndRep
  744. *
  745. * Entry Points:
  746. *                   Entry doCut
  747. *                   Entry doCopy
  748. *                   Entry doPaste
  749. *                   Entry doClear
  750. *
  751. *******************************************************************************
  752.                     using Globals
  753.  
  754. doCut               Entry
  755.                     PushLong LEHandle   ; Handle a "Cut" command
  756.                     _LECut
  757.                     bra done
  758.  
  759. doCopy              Entry
  760.                     PushLong LEHandle   ; Handle a "Copy" command
  761.                     _LECopy
  762.                     rts                 ; Don't update New and Replace buttons
  763.  
  764. doPaste             Entry
  765.                     PushLong LEHandle   ; Handle a "Paste" command
  766.                     _LEPaste
  767.                     bra done
  768.  
  769. doClear             Entry
  770.                     PushLong LEHandle   ; Handle a "Clear" command
  771.                     _LEDelete
  772.  
  773. done                ANOP
  774.                     jsr ckNewAndRep     ; update the New and Replace buttons
  775.  
  776.                     rts
  777.                     end
  778.  
  779.                     EJECT
  780. *******************************************************************************
  781. *
  782. InContent           start
  783. *
  784. * Description:      Called to handle clicks in a window's contents. FindControl
  785. *                   is called to determine on what, if any, control was hit.
  786. *                   If a control is hit, it is tracked, and the appropriate
  787. *                   routine is called to perform some action. If a control
  788. *                   is not hit, then a check is made to see if the LineEdit
  789. *                   item was hit. If so, then the click is passed on to LEClick
  790. *                   for handling.
  791. *
  792. *
  793. * Inputs:           NONE
  794. *
  795. * Outputs:          NONE
  796. *
  797. * External Refs:
  798. *                   Import NewListItem
  799. *                   Import DelListItem
  800. *                   Import RepListItem
  801. *                   Import RstListItem
  802. *                   Import ListHit
  803. *                   Import SortHit
  804. *
  805. * Entry Points:     NONE
  806. *
  807. *******************************************************************************
  808.                     using Globals
  809.  
  810. ; First, find out where we clicked, and see if it was on a control
  811.  
  812.                     pha                 ; result space
  813.                     PushLong #TempHndl
  814.                     PushLong EventWhere ; push the point
  815.                     PushLong WindPointer
  816.                     _FindControl
  817.                     pla
  818.                     bne IC0010          ; hit a control! Track it!
  819.                     brl ckLine          ; didn't hit control. See if we hit LE
  820. IC0010              ANOP
  821.                     pha                 ; result space
  822.                     PushLong EventWhere ; push mouse location
  823.                     PushLong #-1        ; use default action procedure
  824.                     PushLong TempHndl   ; push on handle to control hit
  825.                     _TrackControl       ; track it
  826.                     pla                 ; where did we end up?
  827.                     bne IC0020          ; still in control. Do something
  828.                     brl done            ; out of control - exit this routine
  829. IC0020              ANOP
  830.                     cmp #simpleButton   ; was it a button?
  831.                     beq CallCtlAction   ; if so then handle it
  832.                     cmp #$88            ; was it the list itself?
  833.                     bne done            ; if not, then not a hit!
  834.  
  835. ; We use a neat trick to determine what routine to call inresponse to a
  836. ; click on a control. We keep a 'routine index' in the refcon field of
  837. ; the control. When a click occurs on that control, we retrieve the
  838. ; refcon, turn it into an index into a table of routine pointers, get
  839. ; the pointer to a routine, and call it!
  840.  
  841. CallCtlAction       ANOP
  842.                     pha                 ; space for result
  843.                     pha
  844.                     PushLong TempHndl   ; get the item number from the refcon
  845.                     _GetCtlRefCon
  846.                     pla                 ; low byte of ref con
  847.                     plx                 ; (we don't use high byte)
  848.                     dec a               ; subtract 1 from the refcon then
  849.                     asl a               ; multiply by two to get table offset
  850.                     tax
  851.                     jsr (InCTable,x)    ; jump to routine to handle this ctl
  852.                     bra done
  853.  
  854. ; the mouse click did not occur in any of the regular controls. check to
  855. ; see if we clicked in the LineEdit item. If so, then call LEClick.
  856.  
  857. ckLine              ANOP
  858.                     lda EventWhere      ; Check to see if we clicked in the
  859.                     sta LocalPt         ; LineEdit item. We do this by doing a
  860.                     lda EventWhere+2    ; PtInRect. But we need the mouse in
  861.                     sta LocalPt+2       ; local coordinates for this.
  862.  
  863.                     PushLong #LocalPt
  864.                     _GlobalToLocal
  865.  
  866.                     pha                 ; space for result
  867.                     PushLong #LocalPt
  868.                     PushLong #destRect
  869.                     _PtInRect           ; see if we clicked in the edit item
  870.                     pla
  871.                     beq done            ; no, we didn't, so leave
  872.  
  873.                     PushLong #EventRecord ; yes we did, so call LEClick
  874.                     PushLong LEHandle
  875.                     _LEClick
  876.  
  877. done                rts
  878.  
  879. theRefCon           ds 4
  880. InCTable            dc i2'NewListItem,DelListItem,RepListItem'
  881.                     dc i2'RstListItem,ListHit,SortHit'
  882. LocalPt             ds 4
  883.  
  884.                     end
  885.  
  886.                     EJECT
  887. *******************************************************************************
  888. *
  889. NewListItem         start
  890. *
  891. * Description:      This routine is called by InContent if a click occured
  892. *                   on the "New" button. This routine determines is there
  893. *                   is enough room in the List record for another item. If
  894. *                   so, then a pointer to the next record is is created, and
  895. *                   AddMember is called to create a new List member using
  896. *                   the text from the LineEdit item. When that is done, we
  897. *                   tell the List Manager about it, and hilite the LineEdit
  898. *                   text so that it is easily changed into something else.
  899. *
  900. *
  901. * Inputs:           NONE
  902. *
  903. * Outputs:          List updated. LineEdit text hilited.
  904. *
  905. * External Refs:
  906. *                   Import AddMember
  907. *
  908. * Entry Points:     NONE
  909. *
  910. *******************************************************************************
  911.                     using Globals
  912.  
  913.                     lda MLNum           ; # of elements in the list
  914.                     cmp #30             ; do we have 30 already?
  915.                     bge NLIDone
  916.                     inc MLNum           ; bump number of list entries
  917.  
  918. ; Create a pointer to the next available space in the array of list record.
  919. ; This is done by multiplying the entry number the entry size. Multiplying
  920. ; is done by using the formula x = index*2 + index*8 (assuming that the size
  921. ; of a member record = 10)
  922.  
  923.                     asl a               ; multiply by 2
  924.                     sta TempWord        ; save it for adding to *8 later
  925.                     asl a               ; by four
  926.                     asl a               ; and eight
  927.                     clc
  928.                     adc TempWord        ; add in the times 2 part
  929.  
  930. ; AddMember is the routine that we use to assign the text of the LineEdit
  931. ; item to a certain list record. All we have to do is enter with the
  932. ; accumulator holding a pointer to the right record, and it does the rest.
  933.  
  934.                     jsr AddMember       ; enter with record offset in Acc.
  935.  
  936. ; Now tell the List Manager that we changed the list. Also, make sure that
  937. ; the item that is hilited in the list is STILL hilited. Do this by getting
  938. ; a pointer to the selected record, and passing it to _NewList
  939.  
  940.                     pha                 ; long space for result
  941.                     pha
  942.                     PushLong #0         ; start searching from the beginning
  943.                     PushLong #MyList
  944.                     _NextMember         ; Get pointer Keep it on the stack
  945.                     PushLong #MyList    ; pointer to my list record
  946.                     _NewList            ; and make the new list!
  947.  
  948. ; finally, hilite the line edit text so that we can easily change it later
  949.  
  950.                     PushWord #0         ; starting hilite range
  951.                     PushWord #255       ; ending range
  952.                     PushLong LEHandle   ; hande to the LE control
  953.                     _LESetSelect        ; hilite it.
  954.  
  955. NLIDone             ANOP
  956.                     rts
  957.  
  958.                     end
  959.  
  960.                     EJECT
  961. *******************************************************************************
  962. *
  963. DelListItem         start
  964. *
  965. * Description:      Called by InContent to remove a member from the list. It
  966. *                   is called only when there is a hilited list item to be
  967. *                   removed. This routine determines which item is hilited,
  968. *                   removes it from the list of member records, decrements
  969. *                   the number of members in the list, and redraws the list.
  970. *
  971. *
  972. * Inputs:           NONE
  973. *
  974. * Outputs:          NONE
  975. *
  976. * External Refs:
  977. *                   Import DisposeMember
  978. *                   Import NoSelection
  979. *                   Import ckNewAndRep
  980. *
  981. * Entry Points:     NONE
  982. *
  983. *******************************************************************************
  984.                     using Globals
  985.  
  986.                     lda MLNum           ; contains # of elements
  987.                     cmp #1              ; do we have only 1 left?
  988.                     beq DLIDone         ; if so then remove no more!
  989.                     dec MLNum           ; adjust number of list entries
  990.  
  991. ; DisposeMember finds the hilited list item, and puts an index to it in the
  992. ; X register. Also, if the string for the name of the member was stored in
  993. ; a handle, that handle is disposed of.
  994.  
  995.                     jsr DisposeMember   ; X set up for us on exit
  996.  
  997. loop                ANOP
  998.                     lda MyData+MemberSize,x
  999.                     sta MyData,x        ; move all data down 10 bytes
  1000.                     inx                 ; ...in memory...
  1001.                     inx                 ; ...two bytes at a time
  1002.                     cpx #MyDataTSize    ; is X bumped past the end of records?
  1003.                     blt loop            ; nope, keep looping
  1004.  
  1005.                     PushLong #0         ; Draw All members to redraw the list!
  1006.                     PushLong #MyList
  1007.                     _NewList            ; and create the new list!
  1008.  
  1009.                     jsr NoSelection     ; now reset the apropriate buttons
  1010.  
  1011. DLIDone             ANOP
  1012.                     jsr ckNewAndRep
  1013.                     rts
  1014.  
  1015.                     end
  1016.  
  1017.                     EJECT
  1018. *******************************************************************************
  1019. *
  1020. RepListItem         start
  1021. *
  1022. * Description:      This routine is called from InContent to replace the text
  1023. *                   of the hilited member with the text in the LineEdit Item.
  1024. *                   It calls NextMember to find the hilited item, Disposes of
  1025. *                   it, and then inserts a new item in the same place with the
  1026. *                   new name.
  1027. *
  1028. *
  1029. * Inputs:           NONE
  1030. *
  1031. * Outputs:          NONE
  1032. *
  1033. * External Refs:
  1034. *                   Import DisposeMember
  1035. *                   Import AddMember
  1036. *                   Import NoSelection
  1037. *
  1038. * Entry Points:     NONE
  1039. *
  1040. *******************************************************************************
  1041.                     using Globals
  1042.  
  1043.                     pha                 ; space for result
  1044.                     pha
  1045.                     PushLong #0         ; member to start looking at
  1046.                     PushLong #MyList    ; NOTE: This is the list template ptr
  1047.                     _NextMember
  1048.                     PullLong TempLong   ; Pointer to item Selected
  1049.  
  1050. ;
  1051. ; Now that we know which member is being replaced, call DisposeMember to free
  1052. ; up the memory that is allocated to it, and then call AddMember to fill in that
  1053. ; member's record with new information.
  1054. ;
  1055.                     jsr DisposeMember
  1056.                     txa
  1057.                     jsr AddMember
  1058.                     
  1059. ; The information for the currently selected member has been changed. Now
  1060. ; redraw the member.
  1061.  
  1062.                     PushLong TempLong   ; pass ptr of member to redraw
  1063.                     PushLong #MyList
  1064.                     _DrawMember
  1065.  
  1066.                     jsr NoSelection     ; now reset the apropriate buttons
  1067.  
  1068. ; finally, hilite the line edit text so that we can easily change it later
  1069.  
  1070.                     PushWord #0         ; starting hilite range
  1071.                     PushWord #255       ; ending range
  1072.                     PushLong LEHandle   ; hande to the LE control
  1073.                     _LESetSelect        ; hilite it.
  1074.  
  1075.                     rts
  1076.                     end
  1077.  
  1078.                     EJECT
  1079. *******************************************************************************
  1080. *
  1081. RstListItem         start
  1082. *
  1083. * Description:      This routine is called by InContent to unhilite, or reset,
  1084. *                   the currently selected item. It simply calls ResetMember
  1085. *                   and then redraws that member.
  1086. *
  1087. *
  1088. * Inputs:           NONE
  1089. *
  1090. * Outputs:          NONE
  1091. *
  1092. * External Refs:    
  1093. *                   Import NoSelection
  1094. *
  1095. * Entry Points:     NONE
  1096. *
  1097. *******************************************************************************
  1098.                     using Globals
  1099.  
  1100.                     pha                 ; space for result
  1101.                     pha
  1102.                     PushLong #MyList    ; NOTE: This Is the list template ptr
  1103.                     _ResetMember        ; get item selected & unselect it
  1104.                     PullLong TempLong   ; Item Selected
  1105.  
  1106. ; Obviously, at this point we could have omitted the PullLong/PushLong
  1107. ; sequence to save some bytes, but we wanted to make sure that people were
  1108. ; clear on what ResetMember returned, and what was passed to DrawMember.
  1109.  
  1110.                     PushLong TempLong   ; pass ptr of member to redraw
  1111.                     PushLong #MyList    ; now redraw the list
  1112.                     _DrawMember
  1113.  
  1114.                     jsr NoSelection     ; turn off those buttons
  1115.                     rts
  1116.                     end
  1117.  
  1118.                     EJECT
  1119. *******************************************************************************
  1120. *
  1121. ListHit             start
  1122. *
  1123. * Description:      This routine is called by InContent when a hit on the List
  1124. *                   item has occured. It activates the buttons we need when a
  1125. *                   list item is selected, and gets the text of the item and
  1126. *                   puts it into the LineEdit box. Finally, it hilites the
  1127. *                   LineEdit text so that we can easily change it if we want.
  1128. *
  1129. *
  1130. * Inputs:           NONE
  1131. *
  1132. * Outputs:          NONE
  1133. *
  1134. * External Refs:    NONE
  1135. *
  1136. * Entry Points:     NONE
  1137. *
  1138. *******************************************************************************
  1139.                     using Globals
  1140.  
  1141.                     PushWord #0         ; activate the delete button
  1142.                     PushLong DelBHdl    ; handle to the delete button
  1143.                     _HiLiteControl
  1144.  
  1145.                     PushWord #255       ; now deactivate the replace button
  1146.                     PushLong RepBHdl    ; until we change edit item
  1147.                     _HiLiteControl
  1148.  
  1149.                     PushWord #0         ; now activate the replace button
  1150.                     PushLong RstBHdl
  1151.                     _HiLiteControl
  1152.  
  1153. ;
  1154. ; Find out which member we hit, and insert its text into Line Edit
  1155. ;
  1156.                     pha                 ; space for result
  1157.                     pha
  1158.                     PushLong #0         ; NIL to start at first entry
  1159.                     PushLong #MyList    ; pointer to my list record...
  1160.                     _NextMember
  1161.                     PullLong deref      ; pointer to the next record
  1162.  
  1163.                     ldy #2              ; get the pointer to the string. We do
  1164.                     lda [deref],y       ; this by getting the pointer that the
  1165.                     tax                 ; handle points to, and storing it back
  1166.                     lda [deref]         ; out in 'deref'.
  1167.                     sta deref
  1168.                     stx deref+2
  1169.  
  1170.                     PushWord deref+2    ; push on a pointer to the first character
  1171.                     lda deref
  1172.                     ina
  1173.                     pha
  1174.                     lda [deref]         ; get the length of the string
  1175.                     and #$00FF
  1176.                     pha                 ; push on the length
  1177.                     PushLong LEHandle
  1178.                     _LESetText
  1179.                     
  1180. ; Now invalidate the area of the screen that contained the text so that
  1181. ; LineEdit will redraw it.
  1182.  
  1183.                     PushLong #destRect
  1184.                     _InvalRect
  1185.  
  1186. ; finally, hilite the line edit text so that we can easily change it later
  1187.  
  1188.                     PushWord #0         ; starting hilite range
  1189.                     PushWord #255       ; ending range
  1190.                     PushLong LEHandle   ; hande to the LE control
  1191.                     _LESetSelect        ; hilite it.
  1192.  
  1193.                     rts
  1194.                     end
  1195.  
  1196.                     EJECT
  1197. *******************************************************************************
  1198. *
  1199. SortHit             start
  1200. *
  1201. * Description:      This routine is called by InCotent when a click on the
  1202. *                   Sort button occurs. It calls _SortList with a pointer to
  1203. *                   a custom sorting routine, and then redraws the entire list.
  1204. *                   The custom sorting procedure sorts the list in reverse
  1205. *                   alphabetical order.
  1206. *
  1207. *
  1208. * Inputs:           NONE
  1209. *
  1210. * Outputs:          NONE
  1211. *
  1212. * External Refs:    NONE
  1213. *
  1214. * Entry Points:     NONE
  1215. *
  1216. *******************************************************************************
  1217.                     using Globals
  1218.  
  1219.                     PushLong #MySort    ; Case insensitive sort routine
  1220.                     PushLong #MyList
  1221.                     _SortList
  1222.  
  1223.                     PushLong #0         ; redraw all members
  1224.                     PushLong #MyList
  1225.                     _DrawMember
  1226.  
  1227.                     rts
  1228.  
  1229. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1230. ;
  1231. MySort              ANOP
  1232. ;
  1233. ; This is the custom sorting routine. It is passed the pointers to
  1234. ; 2 member records to compare. If the first member is 'less than' the
  1235. ; second, then return with the carry set. Otherwise, the carry should
  1236. ; be returned clear. When I am done, remove the parameters off of the
  1237. ; stack and RTL back to the List Manager.
  1238. ;
  1239. ; The following are equates that I use for a 'local direct page'. I
  1240. ; save off the register that points to the normal direct page, and
  1241. ; put the value of the stack pointer into the Direct Page register.
  1242. ; This way, the stack doubles as my direct page, and I can easily
  1243. ; access the variables that were pushed on it. These equates repre-
  1244. ; sent the information on the stack when my routine is called.
  1245. ; Specifically, there is a 3 byte return address that will get me
  1246. ; back to the list manager, and then there are 2 4-byte parameters
  1247. ; that are pointers to the 2 members I have to compare.
  1248. ;
  1249. RTLAddr             equ 1
  1250. MemberA             equ RTLAddr+3
  1251. MemberB             equ MemberA+4
  1252.  
  1253.                     tsc                 ; save the old Direct Page and
  1254.                     phd                 ; make the stack our DP so that
  1255.                     tcd                 ; we can use the params as pointers
  1256.  
  1257.                     ldy #2              ; replace the pointer to the first
  1258.                     lda [MemberA],y     ; member with the pointer to the
  1259.                     tax                 ; string of that member.
  1260.                     lda [MemberA]
  1261.                     sta MemberA
  1262.                     stx MemberA+2
  1263.  
  1264.                     lda [MemberB],y     ; do the same thing with the second
  1265.                     tax                 ; member.
  1266.                     lda [MemberB]
  1267.                     sta MemberB
  1268.                     stx MemberB+2
  1269.  
  1270.                     SHORTMX             ; Use 8-bit registers
  1271.  
  1272.                     ldy #1              ; Start comparing with char #1
  1273. cmpLoop             ANOP
  1274.                     lda [MemberB],y     ; Now compare the string characters.
  1275.                     jsr upperIt
  1276.                     sta firstChar
  1277.                     lda [MemberA],y     
  1278.                     jsr upperIt
  1279.                     cmp firstChar       ; If they are not equal, exit with the
  1280.                     bne done            ; carry is set appropriately.
  1281.  
  1282.                     tya                 ; Check to see if we ended a string
  1283.                     dec a
  1284.                     cmp [MemberB]       ; end of Member B?
  1285.                     beq AGreater        ; if so, exit with carry set.
  1286.  
  1287.                     cmp [MemberA]       ; end of Member A?
  1288.                     beq BGreater        ; if so, exit with carry clear.
  1289.  
  1290.                     iny                 ; bump index to examine next char.
  1291.                     bra cmpLoop
  1292.  
  1293. AGreater            clc
  1294.                     bra done
  1295. BGreater            sec
  1296. done                LONGMX
  1297.  
  1298.                     pld                 ; restore the Direct Page reg from stack.
  1299.  
  1300.                     lda 0,s             ; move the RTL address up so that it is
  1301.                     sta 8,s             ; in the right place after we remove the
  1302.                     lda 2,s             ; parameters.
  1303.                     sta 10,s
  1304.                     pla                 ; remove the pointers to the members from
  1305.                     pla                 ; the stack.
  1306.                     pla
  1307.                     pla
  1308.                     rtl
  1309.  
  1310.                     longa off
  1311. upperIt             cmp #'z'+1
  1312.                     bcs aa
  1313.                     cmp #'a'
  1314.                     bcc aa
  1315.                     sbc #32
  1316. aa                  rts
  1317.                     longa on
  1318.  
  1319. firstChar           dc i1'0'
  1320.  
  1321.                     end
  1322.  
  1323.                     EJECT
  1324. *******************************************************************************
  1325. *
  1326. ckNewAndRep         start
  1327. *
  1328. * Description:      Called from all over the place to correctly set the
  1329. *                   activation states of the New and Replace buttons.
  1330. *
  1331. *
  1332. * Inputs:           NONE
  1333. *
  1334. * Outputs:          NONE
  1335. *
  1336. * External Refs:    NONE
  1337. *
  1338. * Entry Points:     NONE
  1339. *
  1340. *******************************************************************************
  1341.                     using Globals
  1342.  
  1343. ; Disable the replace button if no items are selected
  1344.  
  1345.                     pha                 ; long space for result
  1346.                     pha
  1347.                     PushLong #0         ; start searching from the beginning
  1348.                     PushLong #MyList
  1349.                     _NextMember
  1350.                     pla                 ; was a pointer returned (if a long
  1351.                     sta TempWord        ; zero is return, there are not items
  1352.                     pla                 ; selected).
  1353.                     ora TempWord
  1354.                     beq DisableRepItem
  1355.  
  1356.                     PushWord #0         ; activate the replace button
  1357.                     bra FixRepButton
  1358.  
  1359. DisableRepItem      ANOP
  1360.                     PushWord #255       ; deactivate the replace button
  1361.  
  1362. FixRepButton        ANOP
  1363.                     PushLong RepBHdl
  1364.                     _HiLiteControl
  1365.  
  1366. ; Enable or disable the New entry button depending on whether or not there
  1367. ; is any text in the LineEdit buffer.
  1368.  
  1369.                     pha
  1370.                     PushLong LEHandle
  1371.                     _LEGetTextLen
  1372.                     pla
  1373.                     beq disableIt       ; if no length, then no text.
  1374.  
  1375.                     PushWord #0         ; activate the New button
  1376.                     bra CallHilite
  1377.  
  1378. disableIt           ANOP
  1379.                     PushWord #255       ; deactivate the New button
  1380.  
  1381. CallHilite          ANOP
  1382.                     PushLong NewBHdl
  1383.                     _HiLiteControl
  1384.  
  1385.                     RTS
  1386.                     end
  1387.  
  1388.                     EJECT
  1389. *******************************************************************************
  1390. *
  1391. AddMember           start
  1392. *
  1393. * Description:      Utility routine called from NewListItem and RepListItem to
  1394. *                   insert a new member. This routine will read the entry in
  1395. *                   the LineEdit record, store it in a handle, and create a
  1396. *                   new member record at the spot that is specified by the
  1397. *                   accumulator. It does not redraw the list.
  1398. *
  1399. *
  1400. * Inputs:           A = the offset to the record that you want to change.
  1401. *
  1402. * Outputs:          X = the offset to the record that was changed.
  1403. *
  1404. * External Refs:    NONE
  1405. *
  1406. * Entry Points:     NONE
  1407. *
  1408. *******************************************************************************
  1409.                     using Globals
  1410.  
  1411.                     sta RecordIndex
  1412.  
  1413.                     pha                 ; space for handle
  1414.                     pha
  1415.                     PushLong LEHandle
  1416.                     _LEGetTextHand      ; get the text from Line Edit
  1417.                     PullLong TempHandle
  1418.  
  1419.                     pha
  1420.                     PushLong LEHandle
  1421.                     _LEGetTextLen       ; find out how large it is.
  1422.                     PullWord StringSize
  1423.  
  1424.                     pha                 ; make room for NewHandle result
  1425.                     pha
  1426.                     PushWord #0         ; push handle size that we want
  1427.                     lda StringSize      ; but add 1 to it to take into
  1428.                     inc a               ; account the string length byte
  1429.                     pha
  1430.                     PushWord MyID
  1431.                     PushWord #attrFixed+attrNoCross
  1432.                     PushLong #0
  1433.                     _NewHandle          ; create a handle for the string
  1434.  
  1435. ; save the handle we got in 'StringHandle' so that we can later store it in the
  1436. ; member's record. Also store it in 'deref' so that we can dereference it. The
  1437. ; macro PullLong addr1,addr2 will do that for us in one step!
  1438.  
  1439.                     PullLong StringHandle,deref
  1440.  
  1441.                     ldy #2              ; dereference the String Handle to get
  1442.                     lda [deref],y       ; just a pointer.
  1443.                     tax
  1444.                     lda [deref]
  1445.                     sta deref
  1446.                     stx deref+2
  1447.  
  1448.                     lda StringSize      ; create a Pascal string from the lineEdit
  1449.                     sta [deref]         ; item for the List Manager
  1450.  
  1451. ; Copy the LineEdit string into the string's handle. However, set the
  1452. ; destination to be the second byte of the handle, as we need to put the
  1453. ; length of the string in the first byte.
  1454.  
  1455.                     PushLong TempHandle ; handle of the source string
  1456.                     lda deref+2         ; deref holds a pointer to the start
  1457.                     pha                 ; of the destination, but we have to bump
  1458.                     lda deref           ; by one to account for the length byte
  1459.                     inc a               ; that we have to stick there.
  1460.                     pha
  1461.                     PushWord #0         ; bytes to transfer must be LONG, so
  1462.                     PushWord StringSize ; create a high byte of zero.
  1463.                     _HandToPtr
  1464.  
  1465. ; initialize the data in the member record we are creating.
  1466.  
  1467.                     ldx RecordIndex
  1468.                     lda deref           ; get low word of address of new string
  1469.                     sta MyData,x        ; and save it
  1470.                     lda deref+2         ; and now the high word
  1471.                     sta MyData+2,x
  1472.                     lda #0              ; store a memflag byte
  1473.                     sta MyData+4,x
  1474.                     lda StringHandle    ; store the handle to the string so that
  1475.                     sta MyData+6,x      ; we can easily dispose of it later.
  1476.                     lda StringHandle+2
  1477.                     sta MyData+8,x
  1478.  
  1479.                     rts
  1480.  
  1481. StringHandle        ds 4
  1482. TempHandle          ds 4
  1483. StringSize          ds 4
  1484. RecordIndex         ds 2
  1485.  
  1486.                     end
  1487.  
  1488.                     EJECT
  1489. *******************************************************************************
  1490. *
  1491. DisposeMember       start
  1492. *
  1493. * Description:      Find the currently hilited list member and and return
  1494. *                   with an offset to it. Will also dispose of any memory
  1495. *                   associated with it to hold the displayed text.
  1496. *
  1497. *
  1498. * Inputs:           NONE
  1499. *
  1500. * Outputs:          X = offset from start of Member record array where the
  1501. *                       currently hilited member is stored.
  1502. *
  1503. * External Refs:    NONE
  1504. *
  1505. * Entry Points:     NONE
  1506. *
  1507. *******************************************************************************
  1508.                     using Globals
  1509.  
  1510. ; Call _NextMember to find the hilited item. Calculate the offset
  1511. ; within MyData of that record, and dispose of any string handles
  1512. ; that may be there.
  1513.  
  1514.                     pha                 ; space for result
  1515.                     pha
  1516.                     PushLong #0         ; NIL to start at first entry
  1517.                     PushLong #MyList    ; pointer to my list record.
  1518.                     _NextMember
  1519.                     pla                 ; pointer to the next record
  1520.                     plx                 ; discard the high byte
  1521.                     sec                 ; subtract the front of the list to
  1522.                     sbc #MyData         ; get the offset into the table
  1523.                     tax                 ; put into X so we can adjust the list
  1524.                     stx RecordIndex     ; save it here for when we exit
  1525.  
  1526.                     lda MyData+6+2,x    ; See if there's a string handle by
  1527.                     ora MyData+6,x      ; checking for a NULL handle.
  1528.                     beq done            ; no string - so nothing to dispose of
  1529.  
  1530.                     PushLong MyData+6,x ; get the string handle and dispose of it
  1531.                     _DisposeHandle
  1532. done                ANOP
  1533.                     ldx RecordIndex     ; return with offset in X register.
  1534.                     rts
  1535.  
  1536. RecordIndex         ds 2
  1537.  
  1538.                     end
  1539.  
  1540.  
  1541.                     EJECT
  1542. *******************************************************************************
  1543. *
  1544. NoSelection         start
  1545. *
  1546. * Description:      Set the activation state of the buttons to reflect the
  1547. *                   fact that no list items are selected.
  1548. *
  1549. *
  1550. * Inputs:           NONE
  1551. *
  1552. * Outputs:          NONE
  1553. *
  1554. * External Refs:    NONE
  1555. *
  1556. * Entry Points:     NONE
  1557. *
  1558. *******************************************************************************
  1559.                     using Globals
  1560.  
  1561.                     PushWord #255       ; deactivate the delete button
  1562.                     PushLong DelBHdl    ; handle to the delete button
  1563.                     _HiLiteControl
  1564.  
  1565.                     PushWord #255       ; deactivate the reset button
  1566.                     PushLong RstBHdl
  1567.                     _HiLiteControl
  1568.  
  1569.                     PushWord #255       ; deactivate the replace button
  1570.                     PushLong RepBHdl
  1571.                     _HiLiteControl
  1572.  
  1573.                     rts
  1574.                     end
  1575.  
  1576.                     EJECT
  1577. *******************************************************************************
  1578. *
  1579. CreateCtrls         start
  1580. *
  1581. * Description:      Called at initialization time to create all of the
  1582. *                   simple buttons we use.
  1583. *
  1584. *
  1585. * Inputs:           NONE
  1586. *
  1587. * Outputs:          NONE
  1588. *
  1589. * External Refs:    NONE
  1590. *
  1591. * Entry Points:     NONE
  1592. *
  1593. *******************************************************************************
  1594.                     using Globals
  1595.  
  1596.                     stz CCCount         ; zero our counter
  1597. CCLoop              ANOP
  1598.                     lda CCCount         ; get the next ctrl num to add
  1599.                     asl a               ; multiply it by four to make it an
  1600.                     asl a               ; offset into our control table
  1601.                     tax                 ; now use it as an index
  1602.                     lda MyCtrlList,x    ; to get the pointer to the control data
  1603.                     sta deref           ; and save it in the DPage
  1604.                     lda MyCtrlList+2,x  ; so we can read it nicely
  1605.                     sta deref+2
  1606.                     stx TempWord        ; save x for a moment
  1607.  
  1608.                     pha                 ; space for result
  1609.                     pha
  1610.                     PushLong WindPointer ; pointer to my window
  1611.  
  1612. ; Push on NewControl parameters. These parameters are obtained from tables
  1613. ; in our Globals section. Each one is 'cRecSize' long, so we load the Y reg
  1614. ; with that value (less 2), and use it to access all of the parameters in 
  1615. ; the table, pushing each one on the stack as we go.
  1616.  
  1617.                     ldy #cRecSize-2
  1618. CCL010              lda [deref],y       ; Get these parameters from a list of
  1619.                     pha                 ; data blocks in the Globals data
  1620.                     dey                 ; section.
  1621.                     dey
  1622.                     bpl CCL010          ; if not done, get the next one!
  1623.  
  1624.                     _NewControl         ; if so, then just call new control!
  1625.  
  1626.                     ldx TempWord        ; retrieve x
  1627.                     pla                 ; and save the control handle
  1628.                     sta MyCtlHdls,x
  1629.                     pla
  1630.                     sta MyCtlHdls+2,x
  1631.  
  1632.                     inc CCCount         ; bump counter to get next record
  1633.                     lda CCCount
  1634.                     cmp NumCtrls        ; test to see if we did the last one
  1635.                     blt CCLoop          ; if so, then just end
  1636.  
  1637. ;
  1638. ; Create the LineEdit item.
  1639. ;
  1640.                     pha                 ; space for result
  1641.                     pha
  1642.                     PushLong #destRect
  1643.                     PushLong #destRect
  1644.                     PushWord #20        ; Allow only 20 chars in list item
  1645.                     _LENew
  1646.                     PullLong LEHandle
  1647.  
  1648.                     rts
  1649.  
  1650. tempHandle          ds 4
  1651. CCCount             ds 2
  1652.  
  1653.                     end
  1654.  
  1655.                     EJECT
  1656. *******************************************************************************
  1657. *
  1658. CreateList          start
  1659. *
  1660. * Description:      Called at initialization time to create the list item. It
  1661. *                   simply calls _CreateList with a parameter block defined
  1662. *                   in the Globals data section.
  1663. *
  1664. *
  1665. * Inputs:           NONE
  1666. *
  1667. * Outputs:          NONE
  1668. *
  1669. * External Refs:    NONE
  1670. *
  1671. * Entry Points:     NONE
  1672. *
  1673. *******************************************************************************
  1674.                     using Globals
  1675.  
  1676.                     pha                 ; room for result
  1677.                     pha
  1678.                     PushLong WindPointer
  1679.                     PushLong #MyList    ; pointer to list rec
  1680.                     _CreateList
  1681.                     PullLong ListCtlHndl ; and get our list control handle
  1682.  
  1683.                     rts
  1684.                     end
  1685.  
  1686.                     EJECT
  1687. *******************************************************************************
  1688. *
  1689. doQuit              start
  1690. *
  1691. * Description:      Quit routine. Set the QuitFlag to TRUE for the EventLoop.
  1692. *
  1693. *
  1694. * Inputs:           NONE
  1695. *
  1696. * Outputs:          QuitFlag set to $FFFF
  1697. *
  1698. * External Refs:    NONE
  1699. *
  1700. * Entry Points:     NONE
  1701. *
  1702. *******************************************************************************
  1703.                     using Globals
  1704.  
  1705.                     lda #$FFFF
  1706.                     sta QuitFlag
  1707.                     rts
  1708.                     end
  1709.  
  1710.                     copy lists.inits.asm
  1711.  
  1712.                     END
  1713.