home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / defproc / rdocproc.hqx / rdocproc.a
Encoding:
Text File  |  1990-03-05  |  27.6 KB  |  843 lines

  1. ;EASE$$$ READ ONLY COPY of file ╥rdocproc.a╙
  2. ; 1.0    CCH 11/16/1988 Added to EASE.
  3. ; END EASE MODIFICATION HISTORY 
  4. ;
  5. ;File RDocProc.A
  6. ;-------------------------------------------------------
  7. ;
  8. ;  Rounded Corner Window Definition Routine "RDocProc"
  9. ;
  10. ;  written by Andy Hertzfeld  Aug 4, 1982
  11. ;
  12. ;  (c) 1982-1986 by Apple Computer, Inc.  All rights reserved.
  13. ;
  14. ;     This file contains the window definition procedure
  15. ;  "RDocProc", a standard Mac window type similar to the
  16. ;  "DocumentProc" included in the ROM.    It is indentical if
  17. ;  the refCon is zero, otherwise the roundness of the corners
  18. ;  is specified using the high 2 bytes of the window
  19. ;  refCon.    It is intended to be linked with applications or
  20. ;  desk ornaments.
  21. ;
  22. ;  Modification History:
  23. ;
  24. ;    16-OCt-82  AJH    Converted to QuickDraw Trap Interface
  25. ;    15-Nov-82  AJH    Added GoAway button, made content rectangular
  26. ;    02-Jan-83  AJH    Made it a "WDEF" resource
  27. ;    07-Mar-83  AJH    Made it dispose the title region (bug fix)
  28. ;    17-Mar-83  AJH    Fixed D4 trash bug
  29. ;    27-Apr-83  AJH    only plot, hit-test goAway if window is active
  30. ;    20-Aug-83  AJH    made it get roundness from selector instead of refCon
  31. ;    18-Oct-83  AJH    made it ignore unwanted messages; new hiliting
  32. ;    11-Jan-85  JTC    convert to MDS
  33. ;    31-Jan-85  EHB    made hit-testing of GoAway box accurate
  34. ;    14-Feb-85  JTC    named rsrc.
  35. ;    29-Jul-85  EHB    converted back to porkshop
  36. ;v4  7-Aug-85  EHB    did variable system font height version
  37. ;   23 Jul 86  DLD  Converted source to MPW.
  38. ;   22 Aug 86  DLD  Recoded draw goaway before DoHilite to fix Mac Plus system.
  39. ;
  40. ;----Reno World!----------------------------------------
  41. ;
  42. ;    <C59/30Jun86> DAF added color support for nuMac
  43. ;   <C60/22Aug86> DLD Recoded draw goaway before DoHilite to fix Mac Plus system.
  44. ;    <Cxxx/06Oct86> DAF updated color support to use RGB calls on Beck's.  Fixed
  45. ;                        goaway mask to center mask for everyone.
  46. ;    <C407/13Oct86> DAF changed textmode from srcBIC to srcCopy
  47. ;     <C424/18Nov86> DAF    Added portToMap to correct problems in cWindows.
  48. ;    <C491/08Dec86> DAF    Locked title string before drawing it (OLD BUG!)
  49. ;    <C700/26Jan87> DAF    Universal defproc (version 10)
  50. ;
  51.  
  52.             BLANKS        ON
  53.             STRING        ASIS
  54.  
  55.             PRINT        OFF
  56.             LOAD        'inc.sum.d'
  57.             LOAD        'nEqu.d'
  58.             INCLUDE        'colorequ.a'
  59.             PRINT        ON
  60.  
  61. WDEF1        FUNC        EXPORT
  62.  
  63.  
  64. ; Stack Frame Definitions
  65.  
  66. WindowID    EQU        14            ;                                
  67. message        EQU        12            ;                                
  68.  
  69. WFrameSize    EQU        -30            ;    
  70. IsColor        EQU        -30            ; do we have colorQD and toolbox?  [boolean]
  71. Align        EQU        -29            ; a dead byte for IsColor            
  72. SavFgCol    EQU        -28
  73. SavBkCol    EQU        -22
  74. WCTabHndl    EQU        -16            ;                                
  75. WCTabPtr    EQU        -12            ;                                
  76. WInfoRec    EQU     -8            ;                                <7Aug85>
  77. WAscent     EQU     -8            ;                                <7Aug85>
  78. WDescent    EQU     -6            ;                                <7Aug85>
  79. WHeight     EQU     -4            ;                                <7Aug85>
  80. WBoxDelta    EQU     -2            ;                                <7Aug85>
  81.  
  82. ;
  83. ;  FUNCTION   RDocProc(    selector: INTEGER
  84. ;               window: WindowPtr,
  85. ;               message: INTEGER;
  86. ;               parameter: LongInt): LongInt
  87. ;
  88.             BRA.S    @0
  89.  
  90. ; standard header
  91.  
  92.             DC.W    0                    ; flags word
  93.             DC.B    'WDEF'                ; type
  94.             DC.W    1                    ; ID
  95.             DC.W    10                    ; version
  96.  
  97. @0
  98.             LINK    A6,#WFrameSize        ; set up a stack frame to address parameters    
  99.             MOVEM.L D3-D5/A3-A4,-(SP)    ; save work registers
  100.  
  101. ; test if the message is in range
  102.  
  103.             CMP.W    #wCalcRgnMsg,message(A6) ; compare to highest value    (this is highest for rdocs)<C700/26Jan87> DAF
  104.             BGT     OORange                    ; skip it, it's too high            <C700/26Jan87> DAF
  105.             CMP.W    #wDrawMsg,message(A6)    ;  compare to lowest value, too        <C700/26Jan87> DAF
  106.             BMI     OORange                    ;                                    <C700/26Jan87> DAF
  107.             
  108.             MOVE.L    grafGlobals(A5),A0     ; get pointer to quickDraw globals            <7Aug85>
  109.             MOVE.L    thePort(A0),-(SP)    ; save current port on stack                <7Aug85>
  110.  
  111. ; Determine type of system.  We need to know if we have color QuickDraw and a color
  112. ;    window manager port.
  113.     
  114.             CMP.W    #$3FFF,ROM85        ; do we have color QD? 
  115.             SLS        IsColor(A6)            ; set boolean depending on color or B&W system
  116.             BHI.S    @BWSys                ; no, this system has B&W QD
  117.  
  118. ; when using the wmgrCPort, it is the defproc's responsibility to reconcile
  119. ;     the wmgrPort and the wmgrCPort.  
  120.  
  121.             BSR     UpdateCPort            ; compare and update wmgrPorts, also set WMgrCPort
  122.  
  123. ; save off the current port fore- & backcolors on color systems. 
  124.             
  125.             PEA        SavFgCol(A6)        ; push a pointer to save area
  126.             _GetForeColor                ; get the current color
  127.             PEA        SavBkCol(A6)        ; 
  128.             _GetBackColor                ;
  129.  
  130. ; also, find the auxWinRec and lock it down
  131.             
  132.             CLR.L    -(SP)                ; here's a space for the var handle
  133.             CLR.W    -(SP)                ; function return here
  134.             MOVE.L    14(A6),-(SP)        ; push window ptr 
  135.             PEA        6(SP)                ; a pointer to the space above
  136.             _GetAuxWin                    ; find the auxrec
  137.             ADDQ    #2,SP                ; pitch the boolean (it doesn't matter)
  138.             MOVE.L    (SP)+,A0            ; get the auxRecHandle
  139.             MOVE.L    (A0),A0                ; handle -> ptr
  140.             MOVE.L    winCTable(A0),A0    ; get the colortable handle
  141.             MOVE.L    A0,WCTabHndl(A6)    ; save this handle
  142.             _HLock                        ; lock the table down in memory
  143.             MOVE.L    (A0),WCTabPtr(A6)    ; and get a pointer too!
  144.             BRA.S    @CommonSys            ; 
  145.  
  146. @BWSys                                    ; END OF A COLOR-ONLY SECTION
  147.             MOVE.L    WMgrPort,-(SP)        ; and set port to window manager port
  148.             _SetPort                    ; 
  149. @CommonSys                                
  150.  
  151. ; rdocprocs have asymmetric titles that are 19 high.  Figure it so that fonts smaller
  152. ; or equal to chicago get mapped to 19, and all others are made odd for good centering.
  153.  
  154.             LEA     WInfoRec(A6),A3     ; point to our info rec                     <7Aug85>
  155. @1            MOVE.L    A3,-(SP)            ; push a pointer                            <7Aug85>
  156.             _GetFontInfo                ; and get the font's info                   <7Aug85>
  157.             MOVE.W    (A3)+,D0            ; get ascent+2                                <5Aug85>
  158.             ADD.W    (A3)+,D0            ; add descent                                <5Aug85>
  159.             ADDQ.W    #4,D0                ; get the height                            <5Aug85>
  160.             BSET    #0,D0                ; make height odd for symmetry                <7Aug85>
  161.             MOVEQ    #19,D1                ; get 19                                    <26Aug85>
  162.             CMP.W    D1,D0                ; force height to 19 min                    <26Aug85>
  163.             BGE.S    @3                    ; => not a tiny font                        <5Aug85>
  164.             SUB.W    D0,D1                ; how much less than 19 is it?                <26Aug85>
  165.             LSR.W    #1,D1                ; used for centering tiny fonts             <26Aug85>
  166.             ADD.W    D1,WAscent(A6)        ; make the ascent "bigger"                    <26Aug85>
  167.             MOVEQ    #19,D0                ;                                            <7Aug85>
  168. @3            MOVE.W    D0,(A3)+            ; WHeight = ascent+descent+4                <7Aug85>
  169.             SUB.W    #13,D0                ; subtract height of box                    <7Aug85>
  170.             LSR.W    #1,D0                ; divide by 2                                <7Aug85>
  171.             MOVE.W    D0,(A3)             ; save delta to goAway box                <7Aug85>
  172.  
  173. ; fetch the parameters into registers
  174.  
  175.             LEA     8(A6),A0            ; get ptr to first parameter
  176.             MOVE.L    (A0)+,D3            ; get param in D3
  177.             MOVE.W    (A0)+,D0            ; get message
  178.             MOVE.L    (A0)+,A3            ; get the window pointer
  179.             MOVE.W    (A0)+,D5            ; get the selector
  180.             LSR     #1,D5                ; only use 8 alternatives
  181.             ASL     #2,D5                ; quadruple for long index
  182.             CLR.L    (A0)                ; clear out function result
  183. ;
  184. ; case out on the message number
  185. ;
  186.             CMP     #3,D0                ; is it one we deal with?
  187.             BGE.S    @4                    ; if not, skip
  188.  
  189.             ASL     #2,D0                ; quadruple for long index
  190.             JSR     GODOCPROC(D0)        ; dispatch to appropriate routine
  191. ;
  192. ; we're done -- restore port and registers and return to caller
  193. ;
  194.  
  195. @4            
  196.             TST.B    IsColor(A6)            ; are we on a color system?            
  197.             BEQ.S    @NoColor2            ; if on B&W, then skip            
  198.  
  199.             PEA        SavFgCol(A6)        ;
  200.             _RGBForeColor                ;
  201.             PEA        SavBkCol(A6)        ;
  202.             _RGBBackColor                ;
  203.             MOVE.L    WCTabHndl(A6),A0    ; unlock the colortable
  204.             _HUnlock                    ;
  205. @NoColor2                                ; END OF A COLOR-ONLY SECTION
  206.  
  207.             _SetPort                    ; restore the port                        <7Aug85>
  208. OORange                                    ; 'Out Of Range, of course'            <C700/26Jan87> DAF
  209.             MOVEM.L (SP)+,D3-D5/A3-A4    ; restore work registers
  210.             UNLK    A6                    ; unlink stack frame
  211.             MOVE.L    (SP)+,A0
  212.             ADD     #12,SP                ; strip parameters
  213.             JMP     (A0)                ; return to caller
  214. ;
  215. ; DocumentProc dispatch table -- entries must be long branches!
  216. ;
  217. GODOCPROC
  218.             BRA     DRAWDOC             ; draw is message 0
  219.             BRA     HITDOC                ; hit test is message 1
  220.             BRA     CALCDOC             ; calc test is message 2
  221.  
  222. DoneDoc     RTS                         ; nor does it need dispose call
  223.  
  224.  
  225. ; utility UpdateCPort 
  226. ;    This utility compares the pertinent fields of the wmgrPort and the wmgrCPort,
  227. ;    updating the wmgrCPort as necessary to match the wmgrPort.
  228.  
  229. UpdateCPort                                ; <C700/26Jan87> DAF    
  230.             MOVE.L    WmgrCPort,-(SP)        ; make the wmgrCPort the current port
  231.             _SetPort                    ; set it
  232.  
  233.             MOVE.L    WmgrPort,A0            ; get the wmgrPort addr
  234.             MOVE.L    WmgrCPort,A1        ; and the wmgrCPort too
  235.             
  236.             PEA        bkPat(A0)            ; push pointers to pattern for later
  237.             PEA        pnPat(A0)            ;
  238.  
  239. ; copy all fields from pnLoc to end of grafPort, excluding pnPixPat and fillPixPat
  240.  
  241.             LEA        pnLoc(A0),A0                    ; point at source
  242.             LEA        pnLoc(A1),A1                    ; point at dest
  243.             MOVE.L    (A0)+,(A1)+                        ; copy pnLoc
  244.             MOVE.L    (A0)+,(A1)+                        ; copy pnSize
  245.             MOVE.W    (A0)+,(A1)+                        ; copy pnMode
  246.             ADDQ    #8,A0                            ; skip pnPat (aka, pnPixPat,fillPixPat)
  247.             ADDQ    #8,A1                            ; 
  248.             MOVE.W    #((portRec-pnVis)/2)-1,D0        ; set up a counter (long sized)
  249. @1
  250.             MOVE.W    (A0)+,(A1)+                        ; copy it
  251.             DBRA    D0,@1                            ; loop
  252.             
  253. ; now set up the patterns in the wmgrCPort (which is thePort)
  254. ;    the parameters were pushed before the copying loop above
  255.  
  256.             _PenPat
  257.             _BackPat
  258.  
  259.             RTS                            ; <C700/26Jan87> DAF
  260.  
  261.  
  262. ; SetUpColor takes a window part identifier in D0, finds the corresponding
  263. ;    part in the AuxWinTable (the part code is in the .value field) and returns
  264. ;    a pointer to its RGB on the stack.  If the requested part is not found,
  265. ;    the first color table element is used (I'd use frameColor, but that might
  266. ;    not be there!).  Trashes A0/D0.
  267.  
  268. SetUpColor
  269.             MOVE.L    D1,-(SP)            ; save a register
  270.             MOVE.L    WCTabPtr(A6),A0        ; get the color table pointer
  271.             MOVE.W    CTSize(A0),D1        ; get the color table size
  272.             MULU    #8,D1                ; convert to color table index
  273. LegalIndex    
  274.             CMP.W    CTTable+value(A0,D1),D0    ; is this the one?
  275.             BEQ.S    FoundIt                ; if equal, then done
  276.             SUB.W    #8,D1                ; try the previous one
  277.             BGE.S    LegalIndex            ; loop while index positive
  278.             MOVEQ    #0,D1                ; OK, use the first one
  279. FoundIt        
  280.             LEA        CTTable+rgb(A0,D1),A0 ; get the address of the color to use
  281.             MOVE.L    A0,D0                ; we'll need A0 in a second
  282.             MOVE.L    (SP)+,D1            ; restore the register
  283.             MOVE.L    (SP)+,A0            ; get the return address
  284.             MOVE.L    D0,-(SP)            ; push the rgb addr on the stack
  285.             JMP        (A0)                ; return to caller
  286.             
  287.  
  288. PORTTOMAP                                        ; <C424/18Nov86> DAF
  289. ;----------------------------------------------------------
  290. ;
  291. ; Given a window pointer in A0, return the bitmap/pixmap pointer in A0
  292.  
  293.             ADDQ    #PORTBITS,A0                ;POINT TO BITMAP/PIXMAP HANDLE
  294.             TST        ROWBYTES(A0)                ;BITMAP OR PIXMAP HANDLE?
  295.             BPL.S    GOTBITMAP                    ;=>JUST A BITMAP
  296.             MOVE.L    BASEADDR(A0),A0                ;ELSE GET PORT'S PIXMAP HANDLE
  297.             MOVE.L    (A0),A0                        ;GET PIXMAP POINTER
  298. GOTBITMAP    RTS            
  299.                                     
  300. ;
  301. ;  DrawDoc -- draw the document window.   The windowPtr is in A3
  302. ;
  303. DrawDoc
  304.             TST.B    WVISIBLE(A3)        ; is it visible?
  305.             BEQ.S    DoneDoc             ; if not, don't do anything
  306. ;
  307. ; see if its a EORGoAway call and special case it
  308. ;
  309.             CMP     #wInGoAway,D3        ; is it a goAway call?
  310.             BEQ     EorGoAway            ; if so, go handle it
  311.  
  312. ;
  313. ; derive the titleBar rectangle from the structRgn and keep it in TempRect
  314. ;
  315.             LEA     TEMPRECT,A0         ; get pointer to tempRect
  316.             MOVE.L    STRUCTRGN(A3),A1    ; get structure region handle
  317.             MOVE.L    (A1),A1             ; get strucRgn pointer
  318.             ADDQ    #RGNBBOX,A1         ; point A1 at the bounding box
  319.             MOVE.L    (A1)+,(A0)+         ; copy bounding box into tempRect
  320.             MOVE.L    (A1),(A0)
  321. ;
  322. ;  make bottom := top + height
  323. ;
  324.             MOVE    -4(A0),D0            ; get top
  325.             ADD.W    WHeight(A6),D0        ; compute top + height                    <EHB 7Aug85>
  326.             MOVE    D0,(A0)             ; update bottom
  327. ;
  328. ; handle the case of non-rectangular titleBar -- we must allocate a region
  329. ;
  330.             CLR.L    -(SP)                ; make space for function result
  331.             _NewRgn                     ; allocate a region
  332.  
  333.             MOVE.L    (SP),A4             ; keep it in A4 -- and don't pop it off
  334.             PEA     TEMPRECT            ; tempRect defines the bounding rect
  335.             BSR     GetRadPoint         ; get the radius point in D0
  336.             MOVE.L    D0,-(SP)            ; push the radius factor
  337.             ST        -(SP)                ; topRound is true
  338.             CLR     -(SP)                ; botRound is false
  339.             BSR     MakeRoundRegion     ; make the region
  340.  
  341. ; set the frame color first                    
  342.  
  343.             TST.B    IsColor(A6)            ; is it color?
  344.             BEQ.S    @NoColor3            ; no, so skip this
  345.             
  346.             MOVE.W    #wframeColor,D0        ; get element index
  347.             BSR.S    SetUpColor            ; get it on the stack
  348.             _RGBForeColor                ; and set it
  349.  
  350. ; and do a PenNormal so that pattern and mode are OK (mostly for PaintRgn coming up) <C254/22Oct86> DAF
  351.             
  352.             _PenNormal                    ;                 <C254/22Oct86> DAF
  353.  
  354. @NoColor3                                ; END OF A COLOR-ONLY SECTION
  355.             
  356. ; draw the titlebar outline
  357.  
  358.             MOVE.L    A4,-(SP)            ; push the region
  359.             _FrameRgn                    ; frame it
  360.             
  361. ; determine the highlight state and set colors accordingly                <26Apr86>
  362.             
  363.             TST.B    IsColor(A6)            ; is it color?
  364.             BEQ.S    @NoColor4            ; no, so skip this
  365.             
  366.             TST.B    WHILITED(A3)        ; is it hilited?
  367.             BNE.S    @8                    ; ¡ is highlighted, = is not highlighted
  368.             MOVEQ    #wTitleBarColor,D0    ; not hilited, so paint the titlebar in this color
  369.             BSR.S    SetUpColor            ;
  370.             _RGBForeColor
  371.             MOVEQ    #wFrameColor,D0        ; in this state, text is in frame color
  372.             BSR.S    SetUpColor            ;
  373.             BRA.S    @9
  374. @8            MOVEQ    #wTitleBarColor,D0    ; hilited, so paint the text in this color
  375.             BSR.S    SetUpColor            ;    (foreColor is already frameColor!)
  376. @9            _RGBBackColor
  377.     
  378. @NoColor4                                ; END OF A COLOR-ONLY SECTION
  379.             
  380. ; now, go on and draw the rest of the titlebar
  381.  
  382.             MOVE.L    A4,-(SP)            ; push it again
  383.             MOVE.L    OneOne,-(SP)        ; inset by 1
  384.             _InsetRgn                    ; inset it
  385.             MOVE.L    A4,-(SP)            ; push for erase (now paint)
  386.  
  387.             TST.B    IsColor(A6)            ; is it color?
  388.             BEQ.S    @NoColor5            ; no, so erase            
  389.             _PaintRgn                    ; paint it
  390.             BRA.S    @Common5            ; and continue
  391. @NoColor5    _EraseRgn                    ; erase it
  392. @Common5
  393.  
  394. ;
  395. ; hilite the title bar by filling it with specified pattern
  396. ;
  397. DrawTheTitle
  398.             BSR     DoTitleString        ; draw the centered Title
  399. ;
  400. ; plot the goAway button, if necessary
  401. ;
  402.             TST.B    WHilited(A3)        ; if hilited window            <08/22/86 DLD>
  403.             BEQ.S    DisposIt            ; if not, don't plot goAway    <08/22/86 DLD>
  404.  
  405.             TST.B    WGoAway(A3)         ; is there a goaway button?    <08/22/86 DLD>
  406.             BEQ.S    DoHilite            ; if not, skip                <08/22/86 DLD>
  407.  
  408.             TST.B    IsColor(A6)            ; is it color?
  409.             BEQ.S    @NoColor6            ;
  410.             MOVEQ    #notSrcCopy,D1        ; plot in notsrcCopy mode    <08/22/86 DLD>
  411.             BRA.S    @Common6            ; continue
  412. @NoColor6    MOVEQ    #srcCopy,D1            ; default to srcCopy mode    <08/22/86 DLD>
  413. @Common6                                ;    since we will invert    <08/22/86 DLD>
  414.             LEA     GoAwaySymbol,A1     ; get the goAway symbol        <08/22/86 DLD>
  415.             BSR.S     PlotGoAway            ; draw goAway                <08/22/86 DLD>
  416.  
  417. DoHilite
  418.             TST.B    IsColor(A6)            ; is it B&W?
  419.             BNE.S    @BW1                ;
  420.             
  421.             SUBQ    #1,TempRect+Bottom    ; adjust bottom
  422.             PEA     TEMPRECT            ; push the title rect
  423.             _InverRect
  424. @BW1                                    ; END OF A B&W-ONLY SECTION    
  425.  
  426. DisposIt
  427.             MOVE.L    A4,-(SP)            ; push the region handle
  428.             _DisposRgn                    ; deallocate it
  429. ;
  430. ; frame the body of the window
  431. ;
  432. DrawFrame
  433.             TST.B    IsColor(A6)            ; is it color?
  434.             BEQ.S    @NoColor8            ;
  435.  
  436.             MOVEQ    #wFrameColor,D0        ; get the framecolor in Fore
  437.             BSR        SetUpColor            ;
  438.             _RGBForeColor
  439. @NoColor8                                ; END OF A COLOR-ONLY SECTION    
  440.             MOVE.L    STRUCTRGN(A3),-(SP) ; push the structure
  441.             _FrameRgn                    ; frame the body
  442.             RTS
  443.  
  444. ;
  445. ; BuildTBarRect builds a rectangle enclosing the titleBar in TempRect
  446. ;
  447. BuildTBarRect
  448.             LEA     TEMPRECT,A0         ; get pointer to tempRect
  449.             MOVE.L    STRUCTRGN(A3),A1    ; get structure region handle
  450.             MOVE.L    (A1),A1             ; get strucRgn pointer
  451.             ADDQ    #RGNBBOX,A1         ; point A1 at the bounding box
  452.             MOVE.L    (A1)+,(A0)            ; copy bounding box into tempRect
  453.             MOVE.L    (A1),4(A0)
  454. ;
  455. ;  make bottom := top + height
  456. ;
  457.             MOVE    Top(A0),D0            ; get top
  458.             ADD.W    WHeight(A6),D0        ; add in height                         <EHB 7Aug85>
  459.             MOVE    D0,Bottom(A0)        ; update bottom
  460.             SUBQ    #1,Right(A0)        ; inset right
  461.             RTS                         ; return to caller
  462. ;
  463. ; EORGoAway hilites/unhilites the goAway button.  It falls through into PlotGoAway
  464. ;
  465. EorGoAway
  466.             BSR.S    BuildTBarRect        ; build the bounding rect
  467.             LEA     GoAwaySymbol,A1     ; get the bitMap
  468.             ADD.W    #32,A1                ; bump to the EOR Mask
  469.             MOVEQ    #SrcXOR,D1            ; set EOR as the plot mode
  470. ;
  471. ; PlotGoAway plots the goAway button.  A1 holds the symbol, D1 the plotting mode
  472. ;
  473. PlotGoAway
  474.             LEA     TempRect,A0         ; point to temprect                     <7Aug85>
  475.             MOVE.W    WBoxDelta(A6),D0    ; get offset from top to GABox            <7Aug85>
  476.             ADD.W    D0,(A0)             ; add offset to top                     <7Aug85>
  477.             SUBQ.W    #1,(A0)             ; align bitmap                            <7Aug85>
  478.             ADDQ.W    #8,2(A0)            ; add margin to left                    <7Aug85>
  479.             MOVE.L    (A0)+,(A0)            ; bottom/right = top/left                <7Aug85>
  480.             MOVEQ    #16,D0                ; get a constant                        <7Aug85>
  481.             ADD.W    D0,(A0)+            ; Bottom = top + 16                     <7Aug85>
  482.             ADD.W    D0,(A0)             ; Right = Left + 16                     <7Aug85>
  483.  
  484.             MOVE    D1,D0                ; set plotting mode
  485.             MOVE.L    #$00100010,D1
  486.             BSR.S     PlotSymbol            ; plot it in tempRect
  487.             BSR.S    BuildTBarRect        ; rebuild tempRect
  488.             RTS
  489.  
  490. ;
  491. ;  PlotSymbol -- plot the little 16 by 16 symbol bitmap pointed to by A1 into the rectangle
  492. ;  pointed held in TempRect. D0 holds the mode.
  493. ;
  494. PlotSymbol
  495.             LEA     IconBitMap,A0        ; get pointer to source bitmap
  496.             MOVE.L    A1,(A0)             ; update base address of bitMap
  497.             MOVE    #2,4(A0)            ; update rowBytes
  498.             MOVE.L    #$00100010,10(A0)    ; adjust boundsRect
  499. ;
  500. ; push parameters for CopyBits call to transfer arrow bitMap
  501. ;
  502.             MOVE.L    A0,-(SP)            ; push pointer source bitmap
  503.             MOVE.L    GrafGlobals(A5),A1        ; get lisaGraf global baseaddress
  504.             MOVE.L    THEPORT(A1),A1        ; get thePort
  505.             PEA     PORTBITS(A1)        ; that's the destination bitmap
  506. ;
  507.             PEA     BOUNDS(A0)            ; boundsRect of bitmap is source
  508.             PEA     TempRect            ; tempRect is the destination
  509.             MOVE.W    D0,-(SP)            ; theMode is in D0
  510.             CLR.L    -(SP)                ; no mask region
  511. ;
  512. ; transfer the bitMap (stretching as necessary...)
  513. ;
  514.             _CopyBits                    ; let Bill stretch those bits
  515.             RTS                         ; return to caller
  516. ;
  517. ; DoTitleString is the common code that draws the title centered in tempRect
  518. ;
  519. DoTitleString    ; on entry, temprect is title rect inset by one
  520.  
  521.             BSR     BuildTBarRect        ; calculate title bar rect
  522.  
  523. ; compute indent factor based on GoAwayButton state
  524.  
  525. @1            MOVE.W    TempRect+Right,D3    ; get right
  526.             SUB.W    TempRect+Left,D3    ; compute width
  527.  
  528.             SUB.W    WTITLEWIDTH(A3),D3    ; compute extra x
  529.             ASR.W    #1,D3                ; divide by 2
  530. ;
  531. ; if there's a goAway button, make sure the margin is at least 28 pixels
  532. ;
  533.             TST.B    WGoAway(A3)         ; is there a go away button
  534.             BEQ.S    @2                    ; skip if there's not
  535.  
  536.             TST     D3                    ; is it negative?
  537.             BMI.S    @3                    ; if so, pin at 28
  538.             CMP.W    #28,D3                ; if goAway button, must have some margin
  539.             BGT.S    @2
  540. @3            MOVEQ    #28,D3
  541.  
  542. @2            ADD     TempRect+Left,D3    ; compute x position
  543.             MOVE.W    D3,-(SP)            ; and push for MoveTo
  544.  
  545.             MOVE.W    TempRect+Top,D0     ; get top                        <7Aug85>
  546.             ADD.W    WAscent(A6),D0        ; move down to baseline         <7Aug85>
  547.             ADDQ.W    #2,D0                ; add a little white space        <7Aug85>
  548.             MOVE.W    D0,-(SP)            ; push baseline                 <7Aug85>
  549.             _MoveTo
  550.  
  551.             TST.B    IsColor(A6)            ; is it color?
  552.             BEQ.S    @NoColor9            ; no, so skip
  553.  
  554.             MOVE.W    txMode(A3),-(SP)    ; save the xfer mode
  555.             MOVE.W    #notsrcCopy,-(SP)    ; set the text mode                <C407/13Nov86> DAF
  556.             _TextMode
  557. @NoColor9                                ; END OF A COLOR-ONLY SECTION
  558.  
  559. ; draw the string
  560.  
  561.             MOVE.L    WTITLEHANDLE(A3),A0 ; get titleHandle
  562.             _HLock                        ; lock that puppy            <C491/08Dec86> DAF
  563.             MOVE.L    (A0),-(SP)            ; push title pointer
  564.             _DrawString                 ; draw it
  565.             MOVE.L    WTITLEHANDLE(A3),A0 ; get titleHandle again        <C491/08Dec86> DAF
  566.             _HUnlock                    ; unlock it                    <C491/08Dec86> DAF
  567.  
  568.             TST.B    IsColor(A6)            ; is it color?
  569.             BEQ.S    @NoColor10            ; no, so skip
  570.             _TextMode                    ; and restore textMode        <26Apr86>
  571. @NoColor10                                ; END OF A COLOR-ONLY SECTION
  572.  
  573. DoneDString
  574.             RTS                         ; all done drawing title...
  575.  
  576. ;
  577. ;  GetRadPoint returns the radius in D0 of the round rect parameter defined
  578. ; by the selector parameter
  579. ;
  580. GetRadPoint
  581.             MOVE.L    RadiusTable(D5),D0
  582.             RTS
  583.  
  584. RadiusTable
  585.             DC.L    $00100010            ; (16,16)
  586.             DC.L    $00040004            ; (4,4)
  587.             DC.L    $00060006            ; (6,6)
  588.             DC.L    $00080008            ; (8,8)
  589.             DC.L    $000A000A            ; (10,10)
  590.             DC.L    $000C000C            ; (12,12)
  591.             DC.L    $00140014            ; (20,20)
  592.             DC.L    $00180018            ; (24,24)
  593. ;
  594. ;  MakeRoundRegion -- makes a round region given a bounding rectangle and a radius
  595. ;  value.  Also, half round regions (top round, bottom square) are supported
  596. ;  by the topRound,botRound booleans
  597. ;
  598. ;      MakeRoundRegion( theRgn:RegionHandle
  599. ;             theRect:         Rect
  600. ;             xRad,yRad:  INTEGER
  601. ;             topRound,botRound: BOOLEAN)
  602. ;
  603. MakeRoundRegion                         ; ???? was ...Rgn
  604.             LINK    A6,#0                ; set up stack frame
  605.             MOVE.L    A3,-(SP)            ; save work registers
  606.             TST.L    8(A6)                ; are flags both    false?
  607.             BEQ.S    PlainRect            ; if so, its just a rectangle
  608.             TST.L    12(A6)                ; is radius factor 0?
  609.             BNE.S    ComplexRect         ; if not, its a round one
  610. ;
  611. ; optimize for the rectangular case
  612. ;
  613. PlainRect
  614.             MOVE.L    20(A6),-(SP)        ; push region handle
  615.             MOVE.L    16(A6),-(SP)        ; push    rectangle pointer
  616.             _RectRgn                    ; make a    rectangular region
  617.             BRA.S    MMRDone             ; all done!
  618. ;
  619. ; make a region with top and bottom corners rounded
  620. ;
  621. ComplexRect
  622.             _HidePen                    ; hide the pen
  623.             _OpenRgn                    ; start recording the region
  624. ;
  625.             MOVE.L    16(A6),-(SP)        ; push the rectangle pointer
  626.             MOVE.L    12(A6),-(SP)        ; push the radius point
  627.             _FrameRoundRect             ; define the region
  628.             MOVE.L    20(A6),-(SP)        ; push region handle
  629.             _CloseRgn                    ; assign roundRect region
  630. ;
  631.             _ShowPen                    ; enable drawing again
  632. ;
  633. ; now square up either the top or bottom of the region (or neither)
  634. ;
  635.             MOVE.L    16(A6),A0            ; get rectangle pointer
  636.             TST.W    8(A6)                ; examine 'botRound' flag
  637.             BNE.S    CheckTRound         ; if true, see if top needs squaring
  638.             MOVE    BOTTOM(A0),D1        ; get bottom y coordinate
  639.             MOVE    D1,D0
  640.             SUBQ    #8,D0                ; compute top
  641.             BRA.S    SquareIt
  642. ;
  643. CheckTRound
  644.             TST.W    10(A6)                ; examine 'topRound' flag
  645.             BNE.S    MMRDone             ; if that true, we're done
  646.             MOVE    Top(A0),D0            ; get top y coordinate
  647.             MOVE    D0,D1
  648.             ADDQ    #8,D1                ; get bottom
  649. ;
  650. ; here we build a rect in ToolScratch that has the same X as tempRect, but centered
  651. ; around the top or bottom
  652. ;
  653. SquareIt
  654.             LEA     ToolScratch,A1        ; get pointer to dest Rect
  655.             MOVE    D0,(A1)+            ; update top
  656.             MOVE    Left(A0),(A1)+        ; copy left
  657.             MOVE    D1,(A1)+            ; update bottom
  658.             MOVE    Right(A0),(A1)        ; copy    right
  659. ;
  660. ; now make a region out of that rectangle
  661. ;
  662.             CLR.L    -(SP)                ; make space for result
  663.             _NewRgn                     ; allocate a new region
  664.             MOVE.L    (SP),A3             ; keep a copy in    A3
  665.             PEA     ToolScratch         ; push the rectangle pointer
  666.             _RectRgn                    ; make the rectangular region
  667. ;
  668. ; now union with the parameter region to square up the edges
  669. ;
  670.             MOVE.L    20(A6),-(SP)        ; push destination region
  671.             MOVE.L    A3,-(SP)            ; push square region
  672.             MOVE.L    20(A6),-(SP)        ; dest gets the result
  673.             _UnionRgn
  674. ;
  675. ; all done -- deallocate the temporary region
  676. ;
  677.             MOVE.L    A3,-(SP)
  678.             _DisposRgn
  679. ;
  680. MMRDone
  681.             MOVE.L    (SP)+,A3            ; restore work reg
  682.             UNLK    A6                    ; unlink stack frame
  683.             MOVE.L    (SP)+,A0            ; get return address
  684.             ADD     #16,SP                ; strip parameters
  685.             JMP     (A0)                ; all done!
  686.  
  687. ; HitDoc -- perform a hit test on the document.  On entry, D3 contains the mousePoint
  688. ; in global coordinates while A3 holds the window pointer
  689. ;
  690. HitDoc
  691.             MOVEQ    #16,D4                ; keep 16 in a register to save code
  692.             CLR.W    -(SP)                ; make room for function    result
  693.             MOVE.L    D3,-(SP)            ; push the mouse    point
  694.             MOVE.L    CONTRGN(A3),-(SP)    ; push content region handle
  695.             _PtInRgn                    ; is the point in the content region?
  696.             TST.B    (SP)+                ; well, is it?
  697.             BEQ.S    NotInContent        ; if not, go check out drag region
  698.  
  699. ; the point is in the content region so return a '1'
  700.  
  701. justContent
  702.             MOVEQ    #wInContent,D0        ; return in content
  703.             BRA.S    DoneHitDoc            ; go store function result and return
  704.  
  705. ; its not in the content -- see if its in the dragRgn (content extended by titleBar)
  706.  
  707. NotInContent
  708.  
  709.             CLR.W    -(SP)
  710.             MOVE.L    D3,-(SP)
  711.             MOVE.L    StructRgn(A3),-(SP)
  712.             _PtInRgn
  713.             TST.B    (SP)+
  714.             BEQ.S    DoneHit1
  715.  
  716.             CLR.W    -(SP)                ; make room for function result
  717.             MOVE.L    D3,-(SP)            ; push the mouse point
  718.             MOVE.L    ContRgn(A3),A4        ; get content region handle
  719.             MOVE.L    (A4),A4             ; get region ptr
  720.             ADDQ    #RgnBBox,A4         ; get bounding box ptr
  721.             MOVE.W    WHeight(A6),D0        ; get height of title bar                <7Aug85>
  722.             SUB.W    D0,Top(A4)            ; decrease by height of title bar        <7Aug85>
  723.             MOVE.L    A4,-(SP)            ; push the rect
  724.             _PtInRect                    ; is the point in the title bar?
  725.             MOVE.W    WHeight(A6),D0        ; get height of title bar                <7Aug85>
  726.             ADD.W    D0,Top(A4)            ; and fix the bounding box up            <7Aug85>
  727.  
  728.             TST.B    (SP)+                ; examine result
  729.             BEQ.S    DoneHit1            ; if not, return 0 (do nothing)
  730.  
  731. ; see if its in leftmost 16 of drag, which is the goAway button
  732.  
  733.             TST.B    WGoAway(A3)         ; is there a goAway button?
  734.             BEQ.S    ItsInDrag            ; if not, skip
  735.             TST.B    WHilited(A3)        ; only draw it for the active one
  736.             BEQ.S    ItsInDrag
  737.  
  738.             MOVE    D3,D0                ; get mousePt
  739.             MOVE.L    A3,A0                ; copy the windowPtr for PortToMap    <C424/18Nov86> DAF
  740.             BSR        PortToMap            ; convert it                        <C424/18Nov86> DAF    
  741.             ADD     Bounds+Left(A0),D0    ; convert to local                    <C424/18Nov86> DAF
  742.             SUB     PortRect+Left(A3),D0    ; compensate for origin
  743.             CMP     #18,D0                ; is it too far right?
  744.             BGT.S    ItsInDrag            ; if so, its in drag
  745.             SUBQ    #8,D0                ; it must be at least 8
  746.             BMI.S    ItsInDrag
  747.  
  748.             MOVE.L    D3,D0                ;; now check vertical
  749.             SWAP    D0                    ;; which is high word of D3
  750.             ADD.W    Bounds+Top(A0),D0    ;; convert to local    (A0 is still valid)    <C424/18Nov86> DAF
  751.             SUB.W    PortRect+Top(A3),D0     ;; compensate for origin
  752.  
  753. ; D0 is aligned with 0 as the bottom of the title bar.
  754.  
  755.             ADD.W    WBoxDelta(A6),D0        ; below box?                <7Aug85>
  756.             BPL.S    ItsInDrag                ; => yes                    <7Aug85>
  757.             ADD.W    #11,D0                    ; in box?                    <7Aug85>
  758.             BMI.S    ItsInDrag                ; => no                     <7Aug85>
  759.  
  760. ; its in the goAway button so signal it
  761.  
  762.             MOVEQ    #wInGoAway,D0
  763.             BRA.S    DoneHitDoc
  764.  
  765. ItsInDrag
  766.             MOVEQ    #wInDrag,D0         ; flag in drag region
  767. DoneHitDoc
  768.             MOVE.L    D0,20(A6)            ; update function result
  769. DoneHit1    RTS
  770.  
  771.  
  772. ; CalcDoc  -- calculate the structure and content regions for the window pointed
  773. ; to by A3.
  774.  
  775. CalcDoc
  776.             LEA     TEMPRECT,A0         ; get a pointer to the work rectangle
  777.             MOVE.L    A0,-(SP)            ; push for later offset
  778.             MOVE.L    PORTRECT(A3),(A0)+    ; copy topLeft of portRect
  779.             MOVE.L    PORTRECT+4(A3),(A0) ; copy botLeft of portRect
  780.  
  781. ; offset it to global coordinates
  782.  
  783.             MOVE.L    A3,A0                ; copy window pointer                <C424/18Nov86> DAF
  784.             BSR        PortToMap            ; convert pointer, if necessary        <C424/18Nov86> DAF
  785.             MOVE.L    BOUNDS(A0),-(SP)    ; push topLeft of port.portBits.bounds <C424/18Nov86> DAF
  786.             NEG     2(SP)                ; negate    offset
  787.             NEG     (SP)
  788.             _OffsetRect                 ; offset    tempRect to global coordinates
  789.  
  790. ; make the content region square for fast updating
  791.  
  792.             MOVE.L    CONTRGN(A3),A0        ; A0 holds the content region
  793.             CLR     D1                    ; topround is false
  794.             BSR.S    GOMAKERGN            ; go make the region into content region
  795.  
  796. ; now do the structure region.    First correct the bounding rectangle (tempRect) for
  797. ; structure instead of content
  798.  
  799.             PEA     TEMPRECT            ; push a    pointer to the rect
  800.             MOVE.L    MinusOne,-(SP)        ; make 1    pixel bigger, all around
  801.             _InsetRect                    ; make it bigger
  802.  
  803.             MOVE.W    WHeight(A6),D0        ; move up to top of window                <7Aug85>
  804.             SUBQ.W    #1,D0                ; tweak it                                <7Aug85>
  805.             SUB.W    D0,TempRect+Top     ; and set top of struct region            <7Aug85>
  806.  
  807.             MOVEQ    #1,D1                ; topRound is true
  808.             MOVE.L    STRUCTRGN(A3),A0    ; A0 holds the structRgn    pointer
  809.  
  810. GoMakeRgn
  811.             MOVE.L    A0,-(SP)            ; push the region handle
  812.             PEA     TEMPRECT            ; push bounding rectangle pointer
  813.             BSR     GETRADPOINT         ; get the radius    factor
  814.             MOVE.L    D0,-(SP)            ; push it
  815.             MOVE.W    D1,-(SP)            ; topRound is in    D1
  816.             ST        -(SP)                ; so is botRound
  817.             BSR     MakeRoundRegion     ; go make the region
  818.  
  819. ; all done with CalcDocRgns
  820.  
  821.             RTS
  822.  
  823. ;
  824. ; BitMap for default GoAway button
  825.  
  826. GoAwaySymbol
  827.             DC.W    $0000,$0000,$7FF0,$4010
  828.             DC.W    $4010,$4010,$4010,$4010
  829.             DC.W    $4010,$4010,$4010,$4010
  830.             DC.W    $7FF0,$0000,$0000,$0000
  831.  
  832. ; brand-new, centered mask                        <Cxxx/06Oct86> DAF
  833.  
  834.             DC.W    $0000,$0000,$7FF0,$4210
  835.             DC.W    $5250,$4A90,$4010,$5DD0
  836.             DC.W    $4010,$4A90,$5250,$4210
  837.             DC.W    $7FF0,$0000,$0000,$0000
  838.  
  839.             END 
  840. ;
  841.  
  842.