home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / microema.sit / src / wdef128.a < prev    next >
Encoding:
Text File  |  1989-06-09  |  24.3 KB  |  992 lines  |  [TEXT/Earl]

  1. ; WDEF.a.
  2. ; A window definition procedure by Earle R. Horton.
  3. ; This file looks most attractive with tabstops set to 8.
  4. ; Portions of this file are based on a disassembly of the standard
  5. ; 'WDEF' #0 from Apple.  Therefore, portions of this file are
  6. ; Copyright Apple Computer Inc.
  7. ;
  8. ; Significant modifications to the Apple Code include:
  9. ;
  10. ;    Lowmem globals not used for scratch variables.
  11. ;    Source-level support for non-standard width scroll bars:
  12. ;        GrowWidth equate used to determine width of
  13. ;        GrowIcon and gray scroll bar image.
  14. ;    Title bar has a different appearance:
  15. ;        Narrower:
  16. ;            More elegant.
  17. ;            Relieves the boredom.
  18. ;        Close and Zoom icons moved to look better with 
  19. ;        new title bar height.
  20. ;        Title drawn in bold Geneva 9.
  21. ;    Squares in GrowIcon are shadowed.
  22. ;
  23.     STRING ASIS
  24.     include    'Traps.a'
  25.     include 'ToolEqu.a'
  26.     include 'QuickEqu.a'
  27.  
  28. ROM85            EQU    $028E
  29. WMgrCPort       EQU     $0D2C
  30.  
  31. tfinfo            EQU    -8
  32. PatMargin        EQU    tfinfo+leading    ; reusable storage
  33. scratchRgn        EQU    tfinfo-4
  34. ctabH            EQU    scratchRgn-4
  35. ctabP            EQU    ctabH-4
  36. DefaultForeColor    EQU    ctabP-6
  37. DefaultBackColor    EQU    DefaultForeColor-6
  38. ColorMac        EQU    DefaultBackColor-2
  39. savetxFont        EQU    ColorMac-2
  40. savetxFace        EQU    savetxFont-2
  41. savetxSize        EQU    savetxFace-2
  42. gport            EQU    savetxSize-4
  43. scratchRect        EQU    gport-8
  44. myBitMap        EQU    scratchRect-bitmapRec
  45. savePort        EQU    myBitMap-4
  46. ourHandle        EQU    savePort-4
  47. frameVars        EQU    ourHandle
  48.  
  49. wptr            EQU    A3
  50. grect            EQU    A3
  51.  
  52. varCode            EQU    D5
  53. TBarHeight        EQU    D7
  54.  
  55. param            EQU    8
  56. message            EQU    12
  57. window            EQU    14
  58. retVal            EQU    20
  59.  
  60. MinTBarHeight        EQU    12
  61. ; Note that scroll bars look funny in other than the standard width
  62. ; of 16.  13 doesn't look too bad, however.  If you want wide scroll
  63. ; bars (and GrowIcon), then you have to create a BitMap image for the
  64. ; GrowIcon.
  65. GrowWidth        EQU    13
  66. UseSystemFont        EQU    0    ; System Font if 1, programmer choice otherwise
  67. TrueShadowColorMac    EQU    1
  68. CZBoxTop        EQU    1    ; Offset to close and zoom boxes
  69.  
  70. ZoomLeft        EQU    -16
  71. CloseLeft        EQU    6
  72. PadInsideTitleBarIcons    EQU    6
  73. ;
  74. ; Must be first code in 'WDEF', since Init routine uses it to get
  75. ; Handle to 'WDEF'.
  76. ;
  77. WDEFProc    PROC    EXPORT
  78.     BRA.S    EntryPoint
  79.     dc.w    0
  80.     dc.l    'WDEF'
  81.     dc.l    $0000000A
  82. EntryPoint
  83.     LINK    A6,#frameVars
  84.     MOVEM.L    D3-D7/A1-A4,-(A7)
  85.     lea    WDEFProc,a0
  86.     _RecoverHandle
  87.     move.l    a0,ourHandle(a6)
  88.     _HLock
  89.     CMPI.W    #6,Message(A6)    ; Range-check message
  90.     BGT    LeaveWDEF    ; Ignore if > 6
  91.     CMPI.W    #0,Message(A6)    ; Range-check message
  92.     BMI    LeaveWDEF    ; ignore if < 0
  93.     pea    savePort(a6)    ; Restored on exit
  94.     _GetPort        ; Get the current port
  95.     CMPI.W    #$3FFF,ROM85    ; Test for Color QD
  96.     SLS    ColorMac(A6)    ; Save in a variable
  97.     BHI.S    DoMono        ; Set up port for QuickDraw
  98.     BSR    SetUpForColor    ; Set up port for QD II
  99.     BRA.S    SetUpSaveFont    ; And skip QuickDraw part
  100. DoMono
  101.     pea    gport(a6)    ; QuickDraw: Most routines draw in WMgrPort
  102.     _GetWMgrPort        ; Get it
  103.     move.l    gport(a6),-(sp)    ; Save in a variable
  104.     _SetPort        ; Make it the current port
  105. SetUpSaveFont            ; Save current port text settings
  106.     movea.l    gport(a6),a0            ; Save text variables
  107.     move.w    txFont(a0),savetxFont(a6)    ;  from our current drawing
  108.     move.w    txSize(a0),savetxSize(a6)    ;   port.
  109.     move.w    txFace(a0),savetxFace(a6)
  110.  
  111.     LEA    tfinfo(a6),a3            
  112.     MOVE.L    a3,-(A7)
  113. ; Before doing any operation which uses text, apply the text settings we
  114. ; use for the title bar.  Afterwards, restore default WMgrPort settings.
  115. ; This is perhaps overly conservative, but if we draw into the WMgrPort
  116. ; with a font which is not the system font, we have to be carefulâ•”
  117.     bsr    MyFont            ; Set up for my text settings.
  118.     _GetFontInfo            ; Do the font call.
  119.     bsr     RestoreFont        ; Restore to normal.
  120.     MOVE.W    (a3)+,TBarHeight    ; TBarHeight = ascent
  121.     ADD.W    (a3)+,TBarHeight    ;     + descent
  122.     ADDQ.W    #2,TBarHeight        ;    + 2
  123.     bset    #0,TBarHeight        ; + 1 if even
  124.     moveq    #MinTBarHeight,D1
  125.     CMP.W    D1,TBarHeight        ; > MinTBarHeight?
  126.     BGE.S    BigEnough        ; OK, great.
  127.     SUB.W    TBarHeight,D1        ; No, get difference.
  128.     LSR.W    #1,D1            ; Divide by 2.
  129.     ADD.W    D1,tfinfo+ascent(a6)    ; Add to tfinfo.ascent
  130.     moveq    #MinTBarHeight,TBarHeight    ; Use MinTBarHeight.
  131. BigEnough
  132.     MOVE.W    TBarHeight,(a3)+    ; tfinfo.widMax = TBarHeight
  133.     move.w    #3,(a3)            ; PatMargin = 1
  134.     CLR.L    -(A7)            ; Get a region to work with.
  135.     _NewRgn                ; From _NewRgn
  136.     MOVE.L    (A7)+,scratchRgn(A6)    ; Save it in a variable.
  137.     TST.B    ColorMac(A6)        ; Doing Color?
  138.     BEQ.S    ColorSkip1
  139. ; Get color info for this window.
  140.     PEA    DefaultForeColor(A6)    ; Get Fore and Back Colors
  141.     _GetForeColor
  142.     PEA    DefaultBackColor(A6)
  143.     _GetBackColor
  144.     CLR.L    -(A7)            ; Space for Auxiliary Window Record Handle.
  145.     CLR.W    -(A7)            ; Space for result = Boolean
  146.     MOVE.L    window(A6),-(A7)    ; Push window pointer
  147.     PEA    6(A7)            ; Push address of Handle on stack
  148.     _GetAuxWin            ; Get Auxiliary Window Record
  149.     ADDQ.W    #2,A7            ; Toss result
  150.     MOVEA.L    (A7)+,A0        ; Get Handle into register
  151.     MOVEA.L    (A0),A0            ; Dereference
  152.     MOVEA.L    awCTable(A0),A0        ; Get CTabHandle
  153.     MOVE.L    A0,ctabH(a6)        ; save Handle
  154.     _HLock                ; Lock it
  155.     MOVE.L    (A0),ctabP(a6)        ; Get Pointer
  156. ColorSkip1
  157.     LEA    param(A6),A0        ; Fetch function parameters.
  158.     MOVE.L    (A0)+,D3        ; param
  159.     MOVE.W    (A0)+,D0        ; message
  160.     MOVEA.L    (A0)+,wptr        ; WindowPtr
  161.     MOVE.W    (A0)+,varCode        ; varCode
  162.     MOVE.W    varCode,D6        ; varCode in d6
  163.     ANDI.W    #3,varCode        ; low 2 bits in d5
  164.     CLR.L    (A0)            ; Clears return value.
  165.     ADD.W    D0,D0            ; message to jump table offset
  166.     LEA    WDispatch,A0        ; Get jump table
  167.     ADDA.W    WDispatch(D0.W),A0    ; Add offset of routine.
  168.     JSR    (A0)            ; Dispatch to service routine.
  169.     MOVE.L    scratchRgn(A6),-(A7)    ; Done, now we clean up and leave.
  170.     _DisposRgn            ; Toss scratchRgn
  171.     TST.B    ColorMac(A6)        ; Color?
  172.     BEQ.S    RestoreAndLeave        ; No.
  173.     MOVEA.L    ctabH(a6),A0        ; Get CTabHandle.
  174.     _HUnlock            ; Unlock it.
  175.     PEA    DefaultBackColor(A6)    ; Restore colors to those used
  176.     _RGBBackColor            ; before we were called.
  177.     PEA    DefaultForeColor(A6)
  178.     _RGBForeColor
  179. RestoreAndLeave
  180.     move.l    savePort(a6),-(sp)    ; Restore previous port.
  181.     _SetPort
  182. LeaveWDEF
  183.     move.l    ourHandle(a6),a0
  184.     _HLock
  185.     MOVEM.L    (A7)+,D3-D7/A1-A4    ; Restore registers.
  186.     UNLK    A6            ; Pascal return.
  187.     MOVEA.L    (A7)+,A0
  188.     ADDA.W    #12,A7
  189.     JMP    (A0)
  190.     dc.b    'WDEF    '        ; For MacsBug
  191. WDispatch                ; Service routine jump table
  192.     dc.w    Draw     - WDispatch
  193.     dc.w    Hit     - WDispatch
  194.     dc.w    CalcRgn - WDispatch
  195.     dc.w    Init     - WDispatch
  196.     dc.w    Dispos     - WDispatch
  197.     dc.w    Grow     - WDispatch
  198.     dc.w    GIcon     - WDispatch
  199.  
  200. SetUpForColor
  201.     pea    gport(a6)        ; Standard Color QD WDEF port setup.
  202.     _GetWMgrPort            ; Get WMgrPort
  203.     move.l    gport(a6),-(sp)        ; save on stack
  204.     pea    gport(a6)        ; Get CWMgrPort
  205.     _GetCWMgrPort
  206.     move.l    gport(a6),-(sp)        ; Make it the current port
  207.     _SetPort            ;    to allow for RGB colors in 'wctb'.
  208.     move.l    (sp)+,a0        ; a0 -> WMgrPort = source
  209.     move.l    gport(a6),a1        ; a1 -> CWMgrPort = destination
  210.     PEA    bkPat(A0)        ; copy bkPat,
  211.     PEA    pnPat(A0)        ;    pnPat,
  212.     LEA    pnLoc(A0),A0        ;    pnLoc,
  213.     LEA    pnLoc(A1),A1
  214.     MOVE.L    (A0)+,(A1)+        
  215.     MOVE.L    (A0)+,(A1)+        ;    pnSize,
  216.     MOVE.W    (A0)+,(A1)+        ;    pnMode,
  217.     ADDQ.W    #8,A0            ;    all fields from
  218.     ADDQ.W    #8,A1            ;        pnVis
  219.     MOVE.W    #20,D0            ;            to
  220. portCopy
  221.     MOVE.W    (A0)+,(A1)+        ;                bkColor
  222.     DBRA    D0,portCopy
  223.     _PenPat                ; Do the patterns using the traps.
  224.     _BackPat
  225.     RTS
  226. ;
  227. ; Init the window.  This routine will allocate a Handle, and thus
  228. ; potentially move memory, if the window has a zoom box.  Not to
  229. ; worry about locking the 'WDEF' resource over this, since the 
  230. ; Window Manager locks us if we are called with the Init message.
  231. ;
  232. Init
  233.                     ; Set up for Zooming if ZoomDocProc
  234.     BTST    #3,D6            ; Bit 3 set means ZoomDocProc
  235.     BEQ.S    NoZoom            ; OK, forget it.
  236.     CLR.B    wZoom(wptr)        ; Clear zoom flag.
  237.     TST.W    ROM85            ; Test for ROM support.
  238.     BMI.S    NoZoom            ; Don't have it.
  239.     moveq    #16,D0            ; Get a new Handle to store
  240.     _NewHandle    ,Clear        ; 2 Rects.
  241.     BNE.S    NoMem            ; No good, SIMM prices must still be high.
  242.     ADDQ.B    #1,wZoom(wptr)        ; OK, we can zoom.
  243.     MOVE.L    A0,wDataHandle(wptr)    ; Save Handle in window's wDataHandle.
  244.     MOVEA.L    (A0),A4            ; point A4 at contents
  245.     ADDQ.W    #8,A4            ; point to stdState
  246.     MOVEA.L    GrafGlobals(A5),A1    ; Get screenBits.bounds
  247.     MOVE.L    screenBits+bounds+topLeft(A1),(A4)+
  248.     MOVE.L    screenBits+bounds+botRight(A1),(A4)+
  249.     moveq    #3,D0
  250.     SUB.W    D0,-(A4)        ; Standard State is inset by 3 from 
  251.     SUB.W    D0,-(A4)        ; screenBits.bounds
  252.     ADD.W    D0,-(A4)
  253.     ADD.W    D0,-(A4)
  254.     move.w    MBarHeight,d0        ; Get Height of MenuBar
  255.     ADD.W    d0,(A4)            ; Top is dropped for Menu Bar height plus
  256.     ADD.W    TBarHeight,(A4)        ; Title Bar height.
  257.     MOVEA.L    (A0),A4            ; point at userState
  258. ;
  259. ; Make 8 bytes pointed to by A4 a copy of wDataHandle^^.userState.
  260. ;
  261. Get_userState
  262.     MOVE.L    A4,-(A7)        ; Push Rect address
  263.     MOVE.L    portRect(wptr),(A4)    ; Get port topLeft
  264.     MOVE.L    portRect+4(wptr),4(A4)    ;     and botRight.
  265.     MOVEA.L    wptr,A0            ; Get WindowPtr
  266.     BSR    GetBitsPtr        ; Get Ptr to {Bit,Pix}Map in a0
  267.     MOVE.L    6(A0),-(A7)        ; Get topLeft of portBits
  268.     NEG.W    top(A7)            ; Get Global portRect for userState
  269.     NEG.W    left(A7)        ; Offset by -topLeft.
  270.     _OffsetRect
  271. NoMem
  272. NoZoom
  273.     RTS
  274. ;
  275. ; This routine tries to determine whether the user has tried to create
  276. ; a larger-than-normal standard state.
  277. ; If [s]he has, then wDataHandle^^.userState.topLeft will be slightly
  278. ; to the left and higher than wDataHandle^^stdState.topLeft, and
  279. ; wDataHandle^^.userState.botRight will be slightly to the right
  280. ; and below wDataHandle^^.stdState.botRight.
  281. ;
  282. CheckStdState
  283.     SUBQ.W    #8,A7            ; Make room for Rect
  284.     MOVEA.L    A7,A4            ; Make a4 point to it
  285.     BSR.S    Get_userState        ; Get copy of wDataHandle^^.userState
  286.     MOVEA.L    wDataHandle(wptr),A0    ; Get wDataHandle
  287.     MOVEA.L    (A0),A2            ; Dereference
  288.     ADDQ.W    #8,A2            ; a2 -> WStateData.stdState
  289.     BSR.S    L01C2            ; topLeft in range?
  290.      BNE.S    L01B4
  291.      BSR.S    L01C2            ; botRight in range, too?
  292.     BEQ.S    L01BE
  293. L01B4                    ; Yes, must create
  294.     MOVEA.L    wDataHandle(wptr),A0    ; Get wDataHandle
  295.     MOVEA.L    (A0),A4            ; a4 points to wDataHandle^^.stdState
  296.     BSR.S    Get_userState        ; Put current userState into it,
  297.     moveq    #1,D0            ; and return 1.
  298. L01BE
  299.     ADDQ.W    #8,A7            ; Pop off temp Rect, and return.
  300.     RTS
  301. L01C2
  302.     MOVE.L    (A2),-(A7)        ; stdState.topLeft
  303.     MOVE.L    (A2)+,-(A7)        ; stdState.botRight
  304.     MOVE.L    A7,-(A7)        ; push address of Rect on stack
  305.     MOVE.L    #$FFF9FFF9,-(A7)    ; swell by 7
  306.     _InsetRect            
  307.     CLR.W    -(A7)            ; room for function result
  308.     MOVE.L    (A4)+,-(A7)        ; push userState.topLeft first time
  309.                     ; push userState.botRight second time
  310.     PEA    6(A7)            ; push pointer to swelled stdState
  311.     _PtInRect            ; contained?
  312.     SUBQ.B    #1,(A7)            ; subtract 1
  313.     MOVE.B    (A7)+,D0        ; move Boolean result - 1 to d0
  314.     ADDQ.W    #8,A7            ; fix stack
  315.     RTS
  316.  
  317. IsZoomWindow
  318.     BTST    #3,D6        ; Right varcode?
  319.     BEQ.S    NopeItIsnt    ; Nope
  320.     TST.B    wZoom(wptr)    ; Window set up for Zooming?
  321. NopeItIsnt
  322.     RTS
  323.  
  324. Dispos                    ; Toss wDataHandle.
  325.     BSR.S    IsZoomWindow        ; Anything to toss?
  326.     BEQ.S    NothingToDispose    ; Nope
  327.     MOVEA.L    wDataHandle(wptr),A0    ; Yes, get wDataHandle
  328.     _DisposHandle            ; and toss it.
  329. NothingToDispose
  330.     RTS
  331.  
  332. getCtabEntry
  333.     MOVE.L    D1,-(A7)        ; save d1
  334.     MOVEA.L    ctabP(a6),A0        ; Point at window color table
  335.     MOVE.W    ctSize(A0),D1        ; use ctSize for loop
  336.     MULU    #ctEntrySize,D1        ; *size of entry
  337. getNextColorSpec
  338.     CMP.W    ctEntrySize(A0,D1.W),D0    ; ColorSpec.value == d0 ?
  339.     BEQ.S    gottheColor        ; Yes, return the color
  340.     SUBQ.W    #ctEntrySize,D1        ; Decrement loop counter
  341.     BGE.S    getNextColorSpec    ; loop if > 0
  342.     moveq    #0,D1            ; Default to first entry
  343. gottheColor
  344.     LEA    10(A0,D1.W),A0        ; Point to actual ColorSpec
  345.     MOVE.L    A0,D0            ; stick it in d0
  346.     MOVE.L    (A7)+,D1        ; restore d1
  347.     MOVEA.L    (A7)+,A0        ; pop return address
  348.     MOVE.L    D0,-(A7)        ; push return value on stack
  349.     JMP    (A0)            ; return
  350.  
  351. GetBitsPtr
  352.     ADDQ.W    #2,A0        ; a0 -> portBits
  353.     TST.W    4(A0)        ; This is portBits.rowBytes in QD I
  354.     BPL.S    L022E        ; and portVersion in QD II.
  355.     MOVEA.L    (A0),A0        ; QD II means we have to dereference
  356.     MOVEA.L    (A0),A0        ; the PixMapHandle.
  357. L022E    RTS
  358.  
  359. Draw
  360.     TST.B    wVisible(wptr)            ; Window visible?
  361.     BEQ    DontThinkWeHaveTo        ; No, skip this.
  362.     CMPI.W    #wInGoAway,D3            ; >= 4, draw a hit action mask
  363.     BGE    ToggleHitMask
  364.     _PenNormal                ;
  365.     TST.W    varCode                ;
  366.     BNE    BigShadowTest
  367.     BSR    GetTitleBarRect
  368.     TST.B    ColorMac(A6)
  369.     BEQ.S    ColorSkip2
  370.     MOVE.W    #wFrameColor,D0            ; Use correct Frame color.
  371.     BSR.S    getCtabEntry
  372.     _RGBForeColor
  373.     MOVE.W    #wTitleBarColor,D0        ; Use correct Title bar color.
  374.     BSR.S    getCtabEntry
  375.     _RGBBackColor
  376. ColorSkip2
  377.     PEA    scratchRect(a6)            ; Push three copies of pointer
  378.     MOVE.L    (A7),-(A7)            ; to Title Bar Rect.
  379.     MOVE.L    (A7),-(A7)
  380.     _FrameRect                ; Frame it.
  381.     MOVE.L    #$00010001,-(A7)        ; inset by one pixel
  382.     _InsetRect    
  383.     _EraseRect                ; Erase it
  384.     pea    scratchRect(a6)            ; Push another copy of the pointer
  385.     move.l    #-1,-(sp)            ; Restore size.
  386.     _InsetRect
  387.     BSR    DrawTitleInTitleBar        ; Title the window.
  388.     TST.B    wHilited(wptr)            ; Is it Hilited?
  389.     BEQ    L031A
  390.     TST.B    ColorMac(A6)            ; Does it need color?
  391.     BEQ.S    ColorSkip3
  392.     MOVE.W    #wHiliteColor,D0        ; Use the Hilite color.
  393.     BSR    getCtabEntry            ; for ForeGround.  (Title Bar color 
  394.     _RGBForeColor                ; is already set.)
  395. ColorSkip3
  396.     move.l    scratchRect+topLeft(a6),d0    ; Align pattern to start
  397.     andi.l    #$00070007,d0            ; at TitleBarRect.topLeft
  398.     move.l    (a5),a4                ; by setting a "private" QD
  399.     move.l    d0,patAlign(a4)            ; global.
  400.     PEA    scratchRect(a6)            ; Inset on sides by 1,
  401.     MOVE.W    #1,-(A7)            ; and on top and bottom
  402.     MOVE.W    PatMargin(a6),-(A7)        ; by saved margin for Pattern.
  403.     _InsetRect
  404.     MOVE.W    scratchRect+right(a6),-(A7)    ; 
  405.     MOVE.W    D3,scratchRect+right(a6)    ; d3 = left of Title Rect
  406.     PEA    scratchRect(a6)            ; Fill to left of Title Box
  407.     PEA    TBarPat                ; Using hard-wired pattern.
  408.     _FillRect
  409.     BSR    IsZoomWindow            ; Zoom?
  410.     BEQ.S    L02DC
  411.     MOVE.W    (A7),D0                ; Pop right of scratch Rect.
  412.     add.W    #2*ZoomLeft+8,D0
  413.                         ; Leave room for Zoom Box
  414.     CMP.W    D4,D0                ; (d4 = left of Zoom)
  415.     BGE.S    L02DC
  416.     MOVE.W    D0,D4
  417. L02DC    MOVE.W    (A7)+,scratchRect+right(a6)    ; Pop right of scratch Rect.
  418.     MOVE.W    D4,scratchRect+left(a6)        ; Fill area to left
  419.     PEA    scratchRect(a6)            ;  of zoom box
  420.     PEA    TBarPat                ;   with Title Bar fill pattern.
  421.     _FillRect                ; Yeah!
  422.     clr.l    patAlign(a4)            ; Restore pattern alignment.
  423.     TST.B    wGoAway(wptr)            ; GoAway box?
  424.     BEQ.S    L0306                ; Nope.
  425.     BSR    GetTitleBarRect            ; Get the Title Bar
  426.     LEA    CloseBoxBits,A1            ; Load close box
  427.     moveq    #srcCopy,D0            ; Copy it.
  428.     lea    scratchRect(a6),a0        ; Load dest Rect
  429.     BSR    L0406                ; Draw it.
  430. L0306    BSR    IsZoomWindow            ; Window Zoomable?
  431.     BEQ.S    L031A                ; Nope.
  432.     BSR    GetTitleBarRect            ; Get the Title Bar.
  433.     LEA    ZoomBoxBits,A1            ; Load zoom box,
  434.     lea    scratchRect(a6),a0        ;  and dest Rect.
  435.     moveq    #srcCopy,D0            ; Copy it.
  436.     BSR    L03F0                ; Draw it.
  437. L031A    MOVE.L    #$00010001,D4            ; Inset by 1.
  438. L031E    TST.B    ColorMac(A6)            ; Color active?
  439.     BEQ.S    ColorSkip4
  440.     moveq    #wFrameColor,D0            ; Fore = Frame.
  441.     BSR    getCtabEntry
  442.     _RGBForeColor
  443.     moveq    #wContentColor,D0        ; Back = content.
  444.     BSR    getCtabEntry
  445.     _RGBBackColor
  446. ColorSkip4
  447.     MOVEA.L    structRgn(wptr),A0        ; Get frame box.
  448.     MOVEA.L    (A0),A0
  449.     LEA    rgnBBox(A0),A4            ; load the region box.
  450.     SUB.W    D4,bottom(A4)            ; Inset
  451.     SUB.W    D4,right(A4)
  452.     MOVE.L    A4,-(A7)
  453.     _FrameRect                ; Frame it.
  454.     CMPI.W    #altDBoxProc,varCode        ; Shadowed dBox?
  455.     BEQ.S    L0354                ; Nope.
  456.     TST.W    varCode
  457.     BNE.S    L0358
  458. L0354    BSR    FrameAltdBox
  459. L0358    CMPI.W    #dBoxProc,varCode
  460.     BNE.S    L03A4
  461.     MOVE.L    (A4),scratchRect(a6)
  462.     MOVE.L    4(A4),scratchRect+botRight(a6)
  463.     PEA    scratchRect(a6)
  464.     MOVE.L    (A7),-(A7)
  465.     MOVE.L    (A7),-(A7)
  466.     MOVE.L    #$00010001,-(A7)
  467.     _InsetRect
  468.     MOVE.L    #$00070007,-(A7)
  469.     _PenSize
  470.     MOVEA.L    (A5),A0
  471.     PEA    -8(A0)
  472.     _PenPat
  473.     _FrameRect
  474.     MOVEA.L    (A5),A0
  475.     PEA    -16(A0)
  476.     _PenPat
  477.     MOVE.L    #$00020002,-(A7)
  478.     MOVE.L    (A7),-(A7)
  479.     _PenSize
  480.     _InsetRect
  481.     PEA    scratchRect(a6)
  482.     _FrameRect
  483.     _PenNormal
  484. L03A4    MOVEA.L    structRgn(wptr),A4
  485.     MOVEA.L    (A4),A4
  486.     LEA    rgnBBox(A4),A4
  487.     ADD.W    D4,bottom(A4)
  488.     ADD.W    D4,right(A4)
  489.  
  490. DontThinkWeHaveTo
  491.     RTS
  492.  
  493. GetTitleBarRect
  494.     LEA    scratchRect(a6),A0    ; Get our scratchRect
  495.     MOVEA.L    structRgn(wptr),A1    ; a1 -> structRgn pointer
  496.     MOVEA.L    (A1),A1            ; dereference
  497.     ADDQ.W    #2,A1            ; a1 -> rgnBBox
  498.     MOVE.L    (A1)+,topLeft(A0)    ; Copy structRgn^^.rgnBBox to scratchRect
  499.     MOVE.L    (A1),botRight(A0)
  500.     MOVE.W    top(A0),D0        ; scratchRect.top
  501.     ADD.W    TBarHeight,D0        ;    + TBarHeight
  502.     MOVE.W    D0,bottom(A0)        ;        to scratchRect.bottom
  503.     SUBQ.W    #1,right(A0)        ; sub 1 pixel on right for shadow
  504.     RTS
  505.  
  506. ToggleHitMask
  507.     BEQ.S    L03FE            ; Equal means goaway.
  508.     BSR    IsZoomWindow        ; Is it, in fact a zoomable window?
  509.     BEQ.S    L042A            ; It's not, so forget it.
  510.     BSR.S    GetTitleBarRect        ; Toggling zoom box.
  511.     LEA    ZoomHitMask,A1        ; Load the hit mask.
  512.     moveq    #srcXor,D0        ; Draw it in Xor mode to toggle it.
  513. L03F0
  514.     LEA    scratchRect(a6),A0
  515.     MOVE.W    right(A0),left(A0)
  516.     moveq    #ZoomLeft,D1
  517.     BRA.S    L040C
  518. L03FE
  519.     BSR.S    GetTitleBarRect
  520.     LEA    CloseHitMask,A1
  521.     moveq    #srcXor,D0        ; Draw it in Xor mode to toggle it.
  522. L0406
  523.     moveq    #CloseLeft,D1
  524. L040C
  525.     LEA    scratchRect(a6),A0
  526.     add.w    #2,top(a0)
  527.     ADD.W    D1,left(A0)
  528.     MOVE.W    #CZBoxTop,D1
  529.     ADD.W    D1,top(A0)
  530.     SUBQ.W    #1,top(A0)
  531.     MOVE.L    (A0)+,(A0)
  532.     moveq    #11,D1
  533.     ADD.W    D1,(A0)+
  534.     ADD.W    D1,(A0)
  535.     MOVE.L    #$000b000b,D1
  536.     BSR    DrawBits
  537. L042A    RTS
  538.  
  539. BigShadowTest
  540.     MOVE.L    #$00020002,D4
  541.     CMPI.W    #altDBoxProc,varCode
  542.     BEQ    L031E
  543.     moveq    #0,D4
  544.     BRA    L031E
  545.  
  546. DrawTitleInTitleBar
  547.     MOVE.W    scratchRect+right(a6),D4    ; d4 = right of title bar
  548.     MOVE.W    D4,D3
  549.     SUB.W    scratchRect+left(a6),D3        ; d3 = width of title bar
  550.  
  551.     movea.l    wTitleHandle(wptr),a0
  552.     _Hlock
  553.     movea.l    (a0),a0
  554.     clr.w    -(sp)
  555.     move.l    a0,-(sp)
  556.     bsr     MyFont
  557.     _StringWidth
  558.     bsr     RestoreFont
  559.     move.w    (sp)+,d0
  560.     sub.w    d0,d3                ; sub TitleWidth from d3
  561.     movea.l    wTitleHandle(wptr),a0
  562.     _HUnlock
  563.     ASR.W    #1,D3                ; d3 = (TitleBar - Title)/2
  564.     moveq    #2,D0
  565.     TST.B    wGoAway(wptr)
  566.     BEQ.S    L045A
  567.     moveq    #CloseLeft+PadInsideTitleBarIcons+20,D0
  568.                         ; Leave space around close box.
  569. L045A    CMP.W    D0,D3
  570.     BGE.S    L0460
  571.     MOVE.W    D0,D3
  572. L0460    ADD.W    scratchRect+left(a6),D3        ; d3 = CloseLeft*2 + 10 + (TitleBar + Title)/2
  573.     MOVE.W    D4,-(A7)
  574.     BSR    IsZoomWindow
  575.     BEQ.S    L0470
  576.     add.w    #ZoomLeft+PadInsideTitleBarIcons+10,D4
  577.                         ; Leave min space around Zoom box.
  578.                         ; d4 = Titlebar + 2*ZoomLeft + 10
  579. L0470    MOVE.L    scratchRgn(a6),-(A7)
  580.     MOVE.L    (A7),-(A7)
  581.     _GetClip
  582.     MOVE.W    D4,scratchRect+right(a6)
  583.     PEA    scratchRect(a6)
  584.     _ClipRect
  585.     MOVEA.L    (A5),A0
  586.     MOVEA.L    (A0),A0
  587.     MOVE.L    28(A0),-(A7)
  588.     MOVE.L    (A7),-(A7)
  589.     _SectRgn
  590.     MOVE.W    (A7)+,scratchRect+right(a6)
  591.     MOVE.W    D3,-(A7)
  592.     MOVE.W    scratchRect+top(a6),D0
  593.     ADD.W    tfinfo+ascent(a6),D0
  594.     ADDQ.W    #1,D0
  595.     MOVE.W    D0,-(A7)
  596.     _MoveTo
  597.     TST.B    ColorMac(A6)
  598.     BEQ.S    ColorSkip5
  599.     MOVE.W    #wTitleBarColor,D0
  600.     BSR    getCtabEntry
  601.     _RGBBackColor
  602.     MOVE.W    #wTextColor,D0
  603.     BSR    getCtabEntry
  604.     _RGBForeColor
  605.     MOVE.W    #srcOr,-(A7)
  606.     _TextMode
  607. ColorSkip5
  608.     MOVEA.L    wTitleHandle(wptr),A0
  609.     _HLock
  610.     MOVE.L    (A0),-(A7)
  611.     bsr     MyFont
  612.     _DrawString
  613.     bsr     RestoreFont
  614.     MOVEA.L    wTitleHandle(wptr),A0
  615.     _HUnlock
  616.     MOVE.L    scratchRgn(A6),-(A7)
  617.     _SetClip
  618.  
  619.     movea.l    wTitleHandle(wptr),a0
  620.     _Hlock
  621.     movea.l    (a0),a0
  622.     clr.w    -(sp)
  623.     move.l    a0,-(sp)
  624.     bsr     MyFont
  625.     _StringWidth
  626.     bsr     RestoreFont
  627.     movea.l    wTitleHandle(wptr),a0
  628.     _HUnlock
  629.     move.w    (sp)+,d0
  630.     add.w    d3,d0                ; d0 = right of title Rect
  631.     SUBQ.W    #6,D3                ; d3 = left of title Rect
  632.     CMP.W    D4,D0                ; d4 = left of zoom box
  633.     BGE.S    L04E6
  634.     MOVE.W    D0,D4
  635. L04E6    ADDQ.W    #6,D4
  636.     RTS
  637.  
  638. Hit
  639.     CLR.W    -(A7)
  640.     MOVE.L    D3,-(A7)
  641.     MOVE.L    contRgn(wptr),-(A7)
  642.     _PtInRgn
  643.     TST.B    (A7)+
  644.     BEQ.S    L05B0
  645.     TST.W    varCode
  646.     BNE.S    IsContent
  647.     BTST    #2,D6
  648.     BGT.S    IsContent
  649.     TST.B    wHilited(wptr)
  650.     BEQ.S    IsContent
  651.     MOVEA.L    contRgn(wptr),A0
  652.     MOVEA.L    (A0),A0
  653.     MOVE.L    rgnBBox+bottom(A0),D0
  654.     moveq    #GrowWidth-2,D4
  655.     SUB.W    D4,D0
  656.     CMP.W    D0,D3
  657.     BLT.S    IsContent
  658.     SWAP    D0
  659.     SUB.W    D4,D0
  660.     SWAP    D3
  661.     CMP.W    D0,D3
  662.     BLT.S    IsContent
  663.     moveq    #wInGrow,D0
  664.     BRA    L063A
  665. IsContent
  666.     moveq    #wInContent,D0
  667.     BRA    L063A
  668. L05B0    TST.W    varCode
  669.     BNE    L063E
  670.     BSR    GetTitleBarRect
  671.     CLR.W    -(A7)
  672.     MOVE.L    D3,-(A7)
  673.     MOVE.L    A0,-(A7)
  674.     _PtInRect
  675.     TST.B    (A7)+
  676.     BEQ.S    L063E
  677.     TST.B    wHilited(wptr)
  678.     BEQ.S    IsDrag
  679.     MOVE.L    D3,D0
  680.     SWAP    D0
  681.     MOVEA.L    wptr,A0
  682.     BSR    GetBitsPtr
  683.     ADD.W    6(A0),D0
  684.     SUB.W    portRect+top(wptr),D0
  685.     ADD.W    #CZBoxTop,D0
  686.     BPL.S    IsDrag
  687.     ADDI.W    #11,D0
  688.     BMI.S    IsDrag
  689.     TST.B    wGoAway(wptr)
  690.     BEQ.S    L0608
  691.     MOVE.L    D3,D0
  692.     ADD.W    portBounds+top(A0),D0
  693.     SUB.W    portRect+left(wptr),D0
  694.     CMPI.W    #CloseLeft+8,D0
  695.     BGT.S    L0608
  696.     SUB.W    #CloseLeft,D0
  697.     BMI.S    IsDrag
  698.     moveq    #wInGoAway,D0
  699.     BRA.S    L063A
  700. L0608    BSR    IsZoomWindow
  701.     BEQ.S    IsDrag
  702.     MOVE.W    D3,D0
  703.     MOVEA.L    wptr,A0
  704.     BSR    GetBitsPtr
  705.     ADD.W    8(A0),D0
  706.     SUB.W    portRect+right(wptr),D0
  707.     CMPI.W    #ZoomLeft+2,D0
  708.     BLT.S    IsDrag
  709.     CMPI.W    #ZoomLeft+10,D0
  710.     BGT.S    IsDrag
  711.     BSR    CheckStdState
  712.     BEQ.S    L0634
  713.     moveq    #wInZoomOut,D0
  714.     BRA.S    L063A
  715. L0634    moveq    #wInZoomIn,D0
  716.     BRA.S    L063A
  717. IsDrag
  718.     moveq    #wInDrag,D0
  719. L063A    MOVE.L    D0,retVal(A6)
  720. L063E    RTS
  721.  
  722. CalcRgn
  723.     BSR    IsZoomWindow
  724.     BEQ.S    L064A
  725.     BSR    CheckStdState
  726. L064A    LEA    scratchRect(a6),A0
  727.     MOVE.L    A0,-(A7)
  728.     MOVE.L    portRect+topLeft(wptr),(A0)+
  729.     MOVE.L    portRect+botRight(wptr),(A0)
  730.     MOVEA.L    wptr,A0
  731.     BSR    GetBitsPtr
  732.     MOVE.L    bounds+topLeft(A0),-(A7)
  733.     NEG.W    (A7)
  734.     NEG.W    2(A7)
  735.     _OffsetRect
  736.     MOVE.L    contRgn(wptr),-(A7)
  737.     PEA    scratchRect(a6)
  738.     _RectRgn
  739.     MOVE.L    #$00020002,D4
  740.     MOVE.L    structRgn(wptr),-(A7)
  741.     PEA    scratchRect(a6)
  742.     MOVE.L    (A7),-(A7)
  743.     MOVE.L    #-1,-(A7)
  744.     _InsetRect
  745.     TST.W    varCode
  746.     BNE.S    proc14
  747.     MOVE.W    TBarHeight,D0
  748.     SUBQ.W    #1,D0
  749.     SUB.W    D0,scratchRect+top(a6)
  750.     LSR.L    #1,D4
  751. L0698
  752.     _RectRgn
  753.     TST.W    varCode
  754.     BEQ.S    DoShadow
  755.     CMPI.W    #altDBoxProc,varCode
  756.     BNE.S    L06DC
  757. DoShadow
  758.     if    TrueShadowColorMac = 0 then
  759.     TST.B    ColorMac(A6)
  760.     BEQ.S    ColorSkip6
  761.     TST.W    varCode
  762.     BNE.S    L06BE
  763.     ADD.L    D4,scratchRect+botRight(a6)
  764.     MOVE.L    structRgn(wptr),-(A7)
  765.     PEA    scratchRect(a6)
  766.     _RectRgn
  767.     BRA.S    L06DC
  768.     endif
  769. ColorSkip6
  770.     MOVE.L    scratchRgn(A6),-(A7)
  771.     PEA    scratchRect(a6)
  772.     MOVE.L    (A7),-(A7)
  773.     MOVE.L    D4,-(A7)
  774.     _OffsetRect
  775.     _RectRgn
  776.     MOVE.L    structRgn(wptr),-(A7)
  777.     MOVE.L    scratchRgn(A6),-(A7)
  778.     MOVE.L    structRgn(wptr),-(A7)
  779.     _UnionRgn
  780. L06DC    RTS
  781.  
  782. proc14
  783.     CMPI.W    #dBoxProc,varCode
  784.     BNE.S    L0698
  785.     PEA    scratchRect(a6)
  786.     MOVE.L    #$FFF9FFF9,-(A7)
  787.     _InsetRect
  788.     BRA.S    L0698
  789.  
  790. Grow    MOVE.L    D3,-(A7)
  791.     MOVE.L    #-1,-(A7)
  792.     _InsetRect
  793.     MOVEA.L    D3,grect
  794.     MOVE.L    (grect),-(A7)
  795.     MOVE.W    TBarHeight,D0
  796.     SUBQ.W    #1,D0
  797.     SUB.W    D0,top(grect)
  798.     MOVE.L    D3,-(A7)
  799.     _FrameRect
  800.     MOVE.W    left(grect),-(A7)
  801.     MOVE.W    bottom(grect),-(A7)
  802.     SUBI.W    #GrowWidth,(A7)
  803.     MOVE.L    (A7),-(A7)
  804.     _MoveTo
  805.     MOVE.W    right(grect),2(A7)
  806.     _LineTo
  807.     MOVE.L    (A7),(grect)
  808.     MOVE.L    (A7),-(A7)
  809.     _MoveTo
  810.     MOVE.W    right(grect),2(A7)
  811.     _LineTo
  812.     MOVE.W    right(grect),-(A7)
  813.     SUBI.W    #GrowWidth,(A7)
  814.     MOVE.W    top(grect),-(A7)
  815.     MOVE.L    (A7),-(A7)
  816.     _MoveTo
  817.     MOVE.W    bottom(grect),(A7)
  818.     _LineTo
  819.     MOVE.L    D3,-(A7)
  820.     MOVE.L    #$00010001,-(A7)
  821.     _InsetRect
  822.     RTS
  823.  
  824. FrameAltdBox
  825.     MOVE.L    D4,-(A7)
  826.     _PenSize
  827.     MOVE.W    right(A4),D0
  828.     MOVE.W    D0,-(A7)
  829.     MOVE.W    top(A4),-(A7)
  830.     MOVE.W    D0,-(A7)
  831.     MOVE.W    bottom(A4),D0
  832.     MOVE.W    D0,-(A7)
  833.     MOVE.W    left(A4),-(A7)
  834.     MOVE.W    D0,-(A7)
  835.     if    TrueShadowColorMac = 0 then
  836.     TST.B    ColorMac(A6)
  837.     BNE.S    ColorSkip7
  838.     endif
  839.     TST.W    varCode
  840.     BEQ.S    ColorSkip7
  841.     ADD.W    D4,2(A7)
  842.     ADD.W    D4,8(A7)
  843. ColorSkip7
  844.     _MoveTo
  845.     _LineTo
  846.     _LineTo
  847.     _PenNormal
  848.     RTS
  849. DrawBits
  850.     LEA    myBitMap(a6),A0
  851.     MOVE.L    A1,(A0)+
  852.     MOVE.W    #2,(A0)+
  853.     CLR.L    (A0)+
  854.     MOVE.L    D1,(A0)
  855.     PEA    myBitMap(a6)
  856.     MOVEA.L    (A7),A0
  857.     MOVEA.L    (A5),A1
  858.     MOVEA.L    (A1),A1
  859.     PEA    2(A1)
  860.     PEA    6(A0)
  861.     PEA    scratchRect(a6)
  862.     MOVE.W    D0,-(A7)
  863.     CLR.L    -(A7)
  864.     _CopyBits
  865.     RTS
  866. ; This routine is unique in that it draws in the window's port and
  867. ; not in the WMgrPort.
  868. GIcon
  869.     pea    gport(a6)
  870.     _GetPort
  871.     MOVE.L    wptr,-(A7)
  872.     _SetPort
  873.     TST.B    ColorMac(A6)
  874.     BEQ.S    ColorSkip8
  875.     SUBQ.W    #6,A7
  876.     MOVE.L    A7,-(A7)
  877.     _GetForeColor
  878.     SUBQ.W    #6,A7
  879.     MOVE.L    A7,-(A7)
  880.     _GetBackColor
  881.     CLR.W    D0
  882.     BSR    getCtabEntry
  883.     _RGBBackColor
  884.     MOVE.W    #1,D0
  885.     BSR    getCtabEntry
  886.     _RGBForeColor
  887. ColorSkip8
  888.     LEA    scratchRect(a6),A4
  889.     MOVE.L    portRect+botRight(wptr),botRight(A4)
  890.     MOVE.L    botRight(A4),topLeft(A4)
  891.     SUBI.W    #GrowWidth-1,top(A4)
  892.     SUBI.W    #GrowWidth-1,left(A4)
  893.     TST.B    wHilited(wptr)
  894.     BEQ.S    EraseGIcon
  895.     LEA    GrowBits,A1
  896.     moveq    #0,D0
  897.     move.w    #GrowWidth,d1
  898.     swap    d1
  899.     move.w    #GrowWidth,d1
  900.     BSR    DrawBits
  901. DrawGrowLines
  902.     MOVE.W    left(A4),-(A7)
  903.     MOVE.W    (A7),-(A7)
  904.     MOVE.W    portRect+top(wptr),-(A7)
  905.     _MoveTo
  906.     MOVE.W    portRect+bottom(wptr),-(A7)
  907.     _LineTo
  908.     MOVE.W    portRect+left(wptr),-(A7)
  909.     MOVE.W    (A4),-(A7)
  910.     _MoveTo
  911.     MOVE.W    portRect+right(wptr),-(A7)
  912.     MOVE.W    (A4),-(A7)
  913.     _lineTo
  914.     TST.B    ColorMac(a6)
  915.     BEQ.S    GIconRet
  916.     MOVE.L    A7,-(A7)
  917.     _RGBBackColor
  918.     ADDQ.W    #6,A7
  919.     MOVE.L    A7,-(A7)
  920.     _RGBForeColor
  921.     ADDQ.W    #6,A7
  922. GIconRet
  923.     move.l    gport(a6),-(sp)
  924.     _SetPort
  925.     RTS
  926.  
  927. EraseGIcon
  928.     PEA    scratchRect(a6)
  929.     _EraseRect
  930.     BRA.S    DrawGrowLines
  931. RestoreFont
  932.     if UseSystemFont = 0 then
  933.     move.w    savetxFont(a6),-(sp)
  934.     _TextFont
  935.     move.w    savetxSize(a6),-(sp)
  936.     _TextSize
  937.     move.w    savetxFace(a6),-(sp)
  938.     _TextFace
  939.     endif
  940.     RTS
  941. MyFont
  942.     if UseSystemFont = 0 then
  943.     move.w    #geneva,-(a7)
  944.     _TextFont
  945.     move.w    #9,-(a7)
  946.     _TextSize
  947.     move.w    #(1 << boldBit),-(a7)
  948.     _TextFace
  949.     endif
  950.     RTS
  951. ArtWork
  952. ZoomBoxBits
  953.     dc.l    $7FC08420,$84208420,$8420FC20,$80208020
  954.     dc.l    $80208020,$7FC00000,$00000000,$00000000
  955. CloseBoxBits
  956.     dc.l    $7FC08020,$80208020,$80208020,$80208020
  957.     dc.l    $80208020,$7FC00000,$00000000,$00000000
  958. CloseHitMask
  959. ZoomHitMask
  960.     dc.l    -1,-1,-1,-1,-1,-1,-1,-1
  961.     if    GrowWidth < 16 then
  962. GrowBits
  963.     dc.l    $00000000
  964.     dc.l    $3F0021E0
  965.     dc.l    $21B021B0
  966.     dc.l    $21B03FB0
  967.     dc.l    $1FB01030
  968.     dc.l    $1FF00FF0
  969.     dc.l    $00000000
  970.     dc.l    $00000000
  971.  
  972.     elseif    GrowWidth = 16 then
  973. GrowBits
  974.     dc.l    $00000000
  975.     dc.l    $3FC02060
  976.     dc.l    $207C2066
  977.     dc.l    $20662066
  978.     dc.l    $20663FE6
  979.     dc.l    $1FE60806
  980.     dc.l    $08060FFE
  981.     dc.l    $07FE0000
  982.  
  983.     endif
  984. TBarPat
  985. ; This is a gray that looks like a checkerboard in Fat Bits.
  986. ;    dc.l    $55aa55aa,$55aa55aa
  987. ; And this is the familiar horizontal lines pattern used by Apple for 
  988. ; document window Title Bars.
  989.     dc.l    $00ff00ff,$00ff00ff
  990.     ENDP
  991.     END
  992.