home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1988
/
03
/
krute
/
krute.ls3
< prev
next >
Wrap
Text File
|
1987-12-03
|
35KB
|
1,097 lines
*----------------------------------- file information ----------------------------- *
* *
* rectCDEF.Asm *
* *
* *
* Assembly language source code for several styles of rectangular button controls *
* The assembled code is meant to be a CDEF resource *
* *
* The CDEF provides 16 styles of rectangular button controls *
* A button can: (1) contain text, an ICON, or a PICT *
* (2) can be outlined, or shadow-outlined *
* (3) if it contains an ICON or a PICT, can be bare *
* (4) indicate pressing via inversion or a content change *
* *
* Edited with QUED/M 2.04 *
* Compiled under MDS 2.01 *
* *
* Written and ⌐1987 by Stan Krute. All rights reserved. No part of this file, *
* or the object code it leads to, may be reproduced, in any form or by any means, *
* without the express written permission of the author and copyright holder. *
* *
* Timestamp: 6:51 pm PST November 16, 1987 *
* Spacestamp: 18617 Camp Creek Road Hornbrook, California 96044 *
* *
* This file looks good in 9 point Courier, QUED/M 2.04 tabs set to 3 *
* *
*--------------------------------------------------------------------------------- *
* --------------------------------- using the CDEF -------------------------------- *
; details on using the CDEF resource produced by this code
; a custom control is most easily specified via a CNTL resource,
; which uses a procID to indicate the CDEF resource ID and variation code
; for this CDEF, the resource ID is 40
; there are 16 variations, as follows:
; variation content border highlighting via proc ID
; --------- ------- -------- ---------------- -----
; 0 text outlined inversion 640
; 1 text outlined content change 641
; 2 text shadowed inversion 642
; 3 text shadowed content change 643
; 4 PICT bare inversion 644
; 5 PICT bare content change 645
; 6 PICT outlined inversion 646
; 7 PICT outlined content change 647
; 8 PICT shadowed inversion 648
; 9 PICT shadowed content change 649
; 10 ICON bare inversion 650
; 11 ICON bare content change 651
; 12 ICON outlined inversion 652
; 13 ICON outlined content change 653
; 14 ICON shadowed inversion 654
; 15 ICON shadowed content change 655
; for TEXT variations, select a font via the CNTL's contrlValue field:
; -1 for the window's font, 0 for the System font, 1 for the application font,
; anything else a standard Mac font number
; in the case of a font other than the System or window's font, store the font
; style in the high byte of the contrlMin field, and the font size in the
; low byte of the contrlMax field
; for PICT and ICON variations, store a resource ID indicating the PICT or ICON
; resource in the low word of the CNTL's refCon field
; for variations that indicate highlighting via a content change, store a resource
; ID indicating the highlighted-state STR (for text variations), PICT, or
; ICON resource in the high word of the CNTL's refCon field
; when figuring the size of a text button's boundsRect :
; be sure to size the button so the text will fit. Successive approximation works
; well. Rule of thumb for an initial height: 8 greater than the font size.
; when figuring the size of a PICTure button's CNTL's boundsRect :
; if the picture has no outline, try a boundsRect that matches the PICT's boundsRect
; if the picture is outlined, try a boundsRect that's at least 4 wider and 4
; higher -- that size lets the picture perfectly match the button's interior
; pictures in larger boundsRects get centered
; when figuring the size of a ICON button's CNTL's boundsRect :
; if the icon has no outline, try a boundsRect that matches the ICON's boundsRect
; if the icon is outlined, try a boundsRect that's at least 4 wider and 4
; higher -- that size lets the icon perfectly match the button's interior
; icons in larger boundsRects get centered
*----------------------------------- include files ---------------------------------*
; standard Mac definitions
Include MacTraps.D ; condensed trap file
Include SysEqu.D ; system equates
Include ToolEqu.D ; toolbox equates
Include QuickEqu.D ; toolbox equates
; our stuff
Include rectCDEFEqu.Txt ; private definitions for this file
*------------------------------- common entry point --------------------------------*
rectCDEFProc
; provide a stack frame
LINK A6,#-autoBytes ; set frame pointer, with enough
; bytes for automatic variables
; save some registers
MOVEM.L D3-D7/A2-A4,-(SP) ; save some work registers
; the key to 68000 code : fill those registers
LEA param(A6),A0 ; A0 points to param
MOVE.L (A0)+,D3 ; D3 holds param ( usage varies )
MOVE.W (A0)+,D7 ; D7 holds message (operation selector )
MOVEA.L (A0)+,A2 ; A2 holds theControl (control record handle )
CLR.L D4 ; clear out D4
MOVE.W (A0)+,D4 ; varCode into D4
MOVE.B varFlagTable(D4),D4 ; D4 holds a byte of variation flags
; set a default function result of 0, while A0's pointing in the right direction
CLR.L (A0)
; lock the control record down
MOVEA.L A2,A0
_HLock
; get a pointer to the control record
MOVE.L (A2),A2
; lock down and get a pointer to any control data block
MOVE.L contrlData(A2),D0 ; grab the handle
BEQ caseOut ; jump if NIL handle
; we've got a control data block, so lock it
MOVEA.L D0,A3 ; copy the handle
MOVEA.L A3,A0 ; lock the block
_HLock
MOVEA.L (A3),A3 ; get a pointer to the control data block
caseOut
; case out on the message
; just jump off a table of routine offsets
ADD.W D7, D7 ; double the message integer
MOVE.W messageTable(D7),D0 ; grab a table offset
JSR messageTable(D0) ; jump to messageTable + offset
; clean up and go home
; if there was a control data block, unlock it
MOVE.L contrlData(A2),D0 ; grab the handle
BEQ unlockRec ; jump if NIL handle
; we've got a control data block, so unlock it
MOVEA.L D0,A0 ; move the block's handle into place
_HUnlock ; and unlock it
unlockRec
; unlock the control record
MOVEA.L theControl(A6),A0
_HUnlock
; restore the saved registers
MOVEM.L (SP)+,D3-D7/A2-A4
; remove the stack frame
UNLK A6
; fetch the return address
MOVEA.L (SP)+, A0
; set stack pointer to the function result
ADD.L #theResult-param,SP
; we're outta here
JMP (A0)
*---------------------------- the message jump table ------------------------------ *
; there are nine possible messages
messageTable
DC.W doDrawCntl-messageTable ; draw the control
DC.W doTestCntl-messageTable ; test the control
DC.W doCalcCCntl-messageTable ; calculate the control's region
DC.W doInitCntl-messageTable ; do control initialization chores
DC.W doDispCntl-messageTable ; do control disposal chores
DC.W doPosCntl-messageTable ; reposition & update the control
DC.W doThumbCntl-messageTable ; calculate control dragging params
DC.W doDragCntl-messageTable ; drag the control
DC.W doAutoTrack-messageTable ; do the control's action proc
*---------------------------- the variations flag table --------------------------- *
; there are sixteen control variations
; eight bits are used to flag eight qualities of a control variation
; from bit 7 (hi) to bit 0 (lo), the bits are symbolically named :
; textBit - pictBit - iconBit - outBit - shadBit - bareBit - invBit - chngBit
varFlagTable
DC.B %10010010 ; text - outlined - invert
DC.B %10010001 ; text - outlined - content change
DC.B %10011010 ; text - shadowed - invert
DC.B %10011001 ; text - shadowed - content change
DC.B %01000110 ; pict - bare - invert
DC.B %01000101 ; pict - bare - content change
DC.B %01010010 ; pict - outlined - invert
DC.B %01010001 ; pict - outlined - content change
DC.B %01011010 ; pict - shadowed - invert
DC.B %01011001 ; pict - shadowed - content change
DC.B %00100110 ; icon - bare - invert
DC.B %00100101 ; icon - bare - content change
DC.B %00110010 ; icon - outlined - invert
DC.B %00110001 ; icon - outlined - content change
DC.B %00111010 ; icon - shadowed - invert
DC.B %00111001 ; icon - shadowed - content change
*---------------------------------- doDrawCntl -------------------------------------*
; the application wants the CDEF to draw the control
doDrawCntl
; if control is invisible, do nothing
TST.B contrlVis(A2) ; non-zero if the control is visible
BEQ drawn ; it's invisible, so no need to draw it
; save the entry pen state
PEA entryPenState(A6)
_GetPenState
; normalize the pen state
_PenNormal
; save a copy of the entry clip region
CLR.L -(SP) ; get a new region
_NewRgn
MOVE.L (SP),entryClipRgnCopy(A6) ; copy the entry clip region into it
_GetClip
shadOutTest
; see if a shadowed outline is to be drawn
BTST #shadBit,D4 ; check it out
BEQ simpOutTest ; no shadowed outline, on to the simple outline test
BSR doShadOutline ; draw a shadowed outline
BSR shadOutIntClip ; set a clip rect for the interior
BRA interiorDrawing ; on to the interior tests
simpOutTest
; see if a simple outline is to be drawn
BTST #outBit,D4 ; check it out
BEQ noOutNoTest ; if not, on to the no-outline duties
BSR doSimpOutline ; draw a simple outline
BSR simpOutIntClip ; set a clip rect for the interior
BRA interiorDrawing ; on to the interior tests
noOutNoTest
BSR noOutIntClip ; set a clip rect for the interior
interiorDrawing
textTest
; see if the button will contain text
BTST #textBit,D4 ; text ?
BEQ pictTest ; no, so next test
BSR doTextInterior ; yes, so draw text interior
BRA drawn ; and jump on
pictTest
BTST #pictBit,D4 ; pict ?
BEQ iconNoTest ; no, so it's an icon button
BSR doPictInterior ; yes, so draw pict interior
BRA drawn ; and jump on
iconNoTest
BSR doIconInterior ; draw icon interior
drawn
; all drawn
; restore the entry pen state
PEA entryPenState(A6)
_SetPenState
; restore the entry clipping region, and get rid of its holder
MOVE.L entryClipRgnCopy(A6),-(SP)
MOVE.L (SP),-(SP)
_SetClip
_DisposRgn
; so long
RTS
*--------------------------------- doShadOutline ---------------------------------- *
; draw a shadowed outline for a button
doShadOutline
; move to the starting point for the horizontal shadow line: (left+2,bottom)
MOVE.W contrlRect+left(A2),-(SP)
ADDQ.W #0002,(SP)
MOVE.W contrlRect+bottom(A2),-(SP)
_MoveTo
; draw a line to the right side of the horizontal shadow line: (right,bottom)
MOVE.W contrlRect+right(A2),-(SP)
MOVE.W contrlRect+bottom(A2),-(SP)
_LineTo
; draw a line to the top of the vertical shadow line: (right,top+2)
MOVE.W contrlRect+right(A2),-(SP)
MOVE.W contrlRect+top(A2),-(SP)
ADDQ.W #$0002,(SP)
_LineTo
; now draw an outline rect at (top,left,bottom,right)
PEA contrlRect(A2)
_FrameRect
; all done
RTS
*-------------------------------- doSimpOutline ----------------------------------- *
; draw a simple outline for a button
doSimpOutline
; draw an outline rect at (top,left,bottom,right)
PEA contrlRect(A2)
_FrameRect
; all done
RTS
*--------------------------------- shadOutIntClip --------------------------------- *
; set the clip region for the interior of a shadowed outlined button
shadOutIntClip
; use the rect at (top+2,left+2,bottom-2,right-2)
MOVE.L contrlRect+top(A2),interiorClipRect+top(A6)
MOVE.L contrlRect+bottom(A2),interiorClipRect+bottom(A6)
ADDI.L #$00020002,interiorClipRect+top(A6)
SUBI.L #$00020002,interiorClipRect+bottom(A6)
PEA interiorClipRect(A6)
_ClipRect
; all done
RTS
*------------------------------- simpOutIntClip ----------------------------------- *
; set the clip region for the interior of a simply outlined button
simpOutIntClip
; use the rect at (top+2,left+2,bottom-2,right-2)
MOVE.L contrlRect+top(A2),interiorClipRect+top(A6)
MOVE.L contrlRect+bottom(A2),interiorClipRect+bottom(A6)
ADDI.L #$00020002,interiorClipRect+top(A6)
SUBI.L #$00020002,interiorClipRect+bottom(A6)
PEA interiorClipRect(A6)
_ClipRect
; all done
RTS
*-------------------------------- noOutIntClip ------------------------------------ *
; set the clip region for the interior of a non-outlined button
noOutIntClip
; use the rect at (top,left,bottom,right)
MOVE.L contrlRect+top(A2),interiorClipRect+top(A6)
MOVE.L contrlRect+bottom(A2),interiorClipRect+bottom(A6)
PEA interiorClipRect(A6)
_ClipRect
; done
RTS
*-------------------------------- doTextInterior ---------------------------------- *
; draw a button's text content, in an indicated font
doTextInterior
; get a pointer to the current grafPort into A4
PEA currentGrafPort(A6)
_GetPort
MOVEA.L currentGrafPort(A6),A4
; we may be using a font other than the window's, so save current font settings
MOVE.L txFont(A4),curFontAndFace(A6) ; font and style
MOVE.W txSize(A4),curSize(A6) ; size
; the control's font is indicated by a value in the control record's contrlValue
; field: -1 for the window's font, 0 for the System font, 1 for the application
; font, anything else a standard Mac font number
; in the case of a font other than the System or window's font, the font style
; is in the ContrlMin field, and the font size is in the contrlMax field
; case out on the font
MOVE.W contrlValue(A2),D0
BMI useWindowsFont
; see if the new font is the System font or something else
TST.W D0
BEQ useSystemFont
useCustomFont
; set the font, style, and size for a font other than the System or window's font
MOVE.W D0,txFont(A4) ; set the font
MOVE.W contrlMin(A2),txFace(A4) ; set the style
MOVE.W contrlMax(A2),txSize(A4) ; set the size
BRA figgerFontInfo
useSystemFont
; set the font, style, and size for the system font (all zeroes will do it)
CLR.L txFont(A4) ; set the font and style
CLR.W txSize(A4) ; set the size
useWindowsFont
; we're using the window's current font, so font number, size, and style already set
figgerFontInfo
; so the font's set up -- let's get some more information
PEA fontInfo(A6)
_GetFontInfo
; from that info, we can figure the vertical positioning for the button's text
; the equation: vertPos = rectBottom - (fontDescent + ((rectHeight-fontHeight)/2))
MOVE.W interiorClipRect+bottom(A6),D0 ; bottom - top gives rectHeight
MOVE.L D0,D7 ; bottom will be used again
SUB.W interiorClipRect+top(A6),D0
SUB.W fontInfo+ascent(A6),D0 ; then subtract fontHeight
SUB.W fontInfo+descent(A6),D0
ASR.W #1,D0 ; divide what's left by 2
ADD.W fontInfo+descent(A6),D0 ; add it to the descent
SUB.W D0,D7 ; then subtract it from bottom
; determine whether we'll be drawing the control's title or a STR resource
; if the control hilites via a content change and is hilited and there's a handle to
; the STR resource, we draw the STR resource
; content change ?
BTST #chngBit,D4
BEQ useTitle ; no content change, so use control's title
; control hilites via a content change
; is it hilited ?
MOVE.B contrlHilite(A2),D0
BEQ useTitle ; 0=active, not hilited, so use control's title
ADDQ.B #1,D0
BEQ useTitle ; 255=inactive, not hilited, so use control's title
; control hiltes via a content change, and it's hilited
; do we have a handle to the content change string ?
MOVE.L firstRsrcHndl(A3),D5
BEQ useTitle ; no, so use control's title
useSTR
; okay, we'll be using a content change STR resource, and we have a non-NIL handle
; lock the resource, put a pointer to it into D5, and set a flag
MOVEA.L D5,A0 ; handle into A0
_HLock ; lock the STR resource
MOVEA.L D5,A0
MOVE.L (A0),D5 ; set a pointer to it
MOVE.W #1,usingCCRsrc(A6) ; set a flag
BRA setStrWidth
useTitle
; using the control's title
; put a pointer to the string into D5, and clear a flag
LEA contrlTitle(A2),A0
MOVE.L A0,D5 ; set a pointer
CLR.W usingCCRsrc(A6) ; clear a flag
setStrWidth
; now, the horizontal positioning: start by getting the button's string's width
SUBQ.L #2,SP ; room for function result
MOVE.L D5,-(SP) ; the string
_StringWidth
; now, use that width to get the horizontal positioning
; the equation: horzPos = rectLeft + ( (rectWidth-stringWidth) / 2)
MOVE.W interiorClipRect+right(A6),D0 ; get rect width ( right - left )
SUB.W interiorClipRect+left(A6),D0
SUB.W (SP)+,D0 ; subtract string width
ASR.W #1,D0 ; divide what's left by two
ADD.W interiorClipRect+left(A6),D0 ; and add in the left side of rect
; now we have the horizontal and vertical starting position for string drawing
; let's move there ...
MOVE.W D0,-(SP) ; the horizontal starting position
MOVE.W D7,-(SP) ; the vertical starting position
_MoveTo
; paint a button's interior's background, according to the button's hilite state
; and whether we're drawing a content change
; test for content change imminent
TST.W usingCCRsrc(A6) ; remember, we just set or cleared this flag above
BNE cCImminent1 ; flag set, content change imminent
; test the hilite state
bkgHSTest1
MOVE.B contrlHilite(A2),D7
BEQ hSActive1 ; 0 indicates an active button
bkgHSTest2
ADDQ.B #1,D7 ; 255 indicates an inactive button
BNE hSHilit1 ; 1-253 indicates a highlighted button
hSInactive1
; the button is inactive, so paint interior background white
cCImminent1
; a content change is imminent, so paint interior background white
hSActive1
; the button is active, so paint interior background white
MOVEA.L (A5),A0
PEA white(A0)
_PenPat
hSHilit1
; the button is highlighted, so paint interior background black
paintInteriorBkg
; paint the button's interior background
PEA interiorClipRect(A6)
_PaintRect
; draw the button's interior's text, according to the button's hilite state
; and whether we're drawing a content change
; clear a flag that, if set, signals an inactive button
CLR.B D6
; test for content change imminent
TST.W usingCCRsrc(A6)
BNE cCImminent2 ; flag set, content change imminent
; test the hilite state
txtIntHSTest1
MOVE.B contrlHilite(A2),D7
BEQ txtHSActive2 ; 0 indicates an active button
txtIntHSTest2
ADDQ.B #1,D7 ; 255 indicates an inactive button
BNE txtHSHilit2 ; 1-253 indicates a highlighted button
txtHSInactive2
; the button is inactive, so we'll draw the text in black, then gray it out
ADDQ.B #1,D6 ; set the inactive flag
BRA drawText ; and jump to draw
txtHSHilit2
; the button is highlighted, so we'll draw the text in white
MOVE.W #srcBic,txMode(A4) ; so the black bits show as white
cCImminent2
; a content change is imminent, so we'll draw the text in black
txtHSActive2
; the button is active, so we'll draw the text in black
drawText
; draw the button's string
MOVE.L D5,-(SP) ; pointer to the string to draw
_DrawString
; if we used a STR resource, unlock it
TST.W usingCCRsrc(A6) ; are we using ?
BNE grayTest ; no, so jump ahead
MOVE.L firstRsrcHndl(A3),A0 ; yes, so get the handle
_HUnlock ; and unlock it
grayTest
; see if we've got an inactive button, in which case we gray the text out
TST.B D6
BEQ txtGetNorm ; not inactive, so no graying out
; yup, we're inactive, so let's get grayed out
; set the pen pattern to gray
MOVEA.L (A5),A0
PEA gray(A0)
_PenPat
; and set pattern transfer mode to ANDing with the inverse of the pattern
MOVE #PatBic,-(SP)
_PenMode
; now paint the clip rectangle gray
PEA interiorClipRect(A6)
_PaintRect
txtGetNorm
; get things back to normal, in case they were changed
; normalize the text transfer mode
MOVE.W #srcOr,txMode(A4)
;restore the window's prior font settings
MOVE.L curFontAndFace(A6),txFont(A4)
MOVE.W curSize(A6),txSize(A4)
textDrawn
; text button interior's all drawn
RTS
*------------------------------------ doPictInterior -------------------------------*
; draw a PICTure interior for the button
doPictInterior
; we'll draw in the picture's bounding rectangle
; we'll try to center this rectangle horizontally and vertically
; in the control's clipping rectangle
; if the control's too small, the icon lines up against
; the top and or left sides of the control's clipping rectangle
; move clipping rectangle's top and left coords into place
MOVE.L interiorClipRect+top(A6),pictRect+top(A6)
; get the clipping rect's width into D6
MOVE.W interiorClipRect+right(A6),D6
SUB.W interiorClipRect+left(A6),D6
; get a pointer and handle to the picture
; if the control hilites via a content change and is hilited, we draw the secondary
; PICT resource
; does the control hilite via a content change ?
BTST #chngBit,D4
BEQ usePictOne ; doesn't hilite via a content change
; is the control hilited ?
MOVE.B contrlHilite(A2),D1
BEQ usePictOne ; 0=active, not hilited
ADDQ.B #1,D1
BEQ usePictOne ; 255=inactive, not hilited
usePictTwo
; we'll be using the secondary PICT resource
; get a handle and set a flag
MOVE.L secondRsrcHndl(A3),D5 ; the handle
BEQ usePictOne ; in case of a NIL handle
MOVE.W #1,usingCCRsrc(A6) ; the flag
BRA getPictPointer
usePictOne
; we'll be using the primary PICT resource
; get a handle and set a flag
MOVE.L firstRsrcHndl(A3),D5 ; the handle
BEQ pictDrawn ; in case of a NIL handle
CLR.W usingCCRsrc(A6) ; the flag
getPictPointer
; lock the PICT, and get a pointer to it
MOVEA.L D5,A0
_HLock ; lock the PICT
MOVEA.L D5,A4
MOVEA.L (A4),A4 ; get a pointer
figPicWidth
; figure the picture's width
MOVE.W picFrame+right(A4),D1
SUB.W picFrame+left(A4),D1
; now subtract the picture's width from the clip width
SUB.W D1,D6
; if 2 or more, divide by 2 and use as horizontal offset
; if it's < 2, no horizontal offset
CMPI.W #2,D6
BLT.S doPictRight
; divide and add the offset in
ASR.W #1,D6 ; divide by two
ADD.W D6,pictRect+left(A6)
; now do the right coord of rectangle
doPictRight
MOVE.W pictRect+left(A6),pictRect+right(A6)
ADD.W D1,pictRect+right(A6)
; get the clipping rect's height
MOVE.W interiorClipRect+bottom(A6),D0 ; get clip height into D0
SUB.W interiorClipRect+top(A6),D0
; figure the picture's height
MOVE.W picFrame+bottom(A4),D1
SUB.W picFrame+top(A4),D1
; now subtract the picture's height from the clip height
SUB.W D1,D0
; if 2 or more, divide by 2 and use as vertical offset
; if it's < 2, no vertical offset
CMPI.W #2,D0
BLT.S doPictBottom
; divide and add the offset in
ASR.W #1,D0 ; divide by two
ADD.W D0,pictRect+top(A6)
; now do the bottom coord of rectangle
doPictBottom
MOVE.W pictRect+top(A6),pictRect+bottom(A6)
ADD.W D1,pictRect+bottom(A6)
; clear the background
PEA interiorClipRect(A6)
_EraseRect
; okay, let's draw the picture (remember, it gets clipped to the button's interior )
MOVE.L D5,-(SP) ; the picture's handle
PEA pictRect(A6) ; the destination rectangle
_DrawPicture
; unlock the PICT
MOVEA.L D5,A0 ; handle's still here
_HUnlock
; now, adjust the picture for buttons that are hilited inverts or inactive
BSR interiorAdjust
pictDrawn
; pict button interior's all drawn
RTS
*---------------------------------- interiorAdjust----------------------------------*
; adjust a button's interior for buttons that are hilited inverts or inactive
interiorAdjust
; test the hilite state
hiliteTest1
MOVE.B contrlHilite(A2),D0
BEQ intAdjDone ; 0 indicates a non-hilited active button
hiliteTest2
ADDQ.B #1,D0 ; 255 indicates an inactive button
BNE itsHilited ; 1-253 indicates a highlighted button
itsInactive
; the button is inactive, so we'll gray it out
; set the pen pattern to gray
MOVEA.L (A5),A0
PEA gray(A0)
_PenPat
; and set pattern transfer mode to ANDing with the inverse of the pattern
MOVE #PatBic,-(SP)
_PenMode
; now paint the clip rectangle gray
PEA interiorClipRect(A6)
_PaintRect
; leave
BRA intAdjDone
itsHilited
; the button is highlighted
; test for being an invert
TST.W usingCCRsrc(A6)
BNE intAdjDone ; a content changer, so we done
; the button's a hilited invert, so invert it
PEA interiorClipRect(A6)
_InverRect
intAdjDone
; all done with the adjustment
RTS
*---------------------------------- doIconInterior ---------------------------------*
; draw an ICONic interior for the button
doIconInterior
; we'll draw in an icon-sized rectangle
; we'll try to center this rectangle horizontally and vertically
; in the control's clipping rectangle
; if the control's too small, the icon lines up against
; the top and or left sides of the control's clipping rectangle
; move clipping rectangle's top and left coords into place
MOVE.L interiorClipRect+top(A6),iconRect+top(A6)
; get the clipping rect's width into D0
MOVE.W interiorClipRect+right(A6),D0
SUB.W interiorClipRect+left(A6),D0
; now subtract the icon width
SUBI.W #iconSize,D0
; if 2 or more, divide by 2 and use as horizontal offset
; if it's < 2, no horizontal offset
CMPI.W #2,D0
BLT.S doIconRight
; divide and add the offset in
ASR.W #1,D0 ; divide by two
ADD.W D0,iconRect+left(A6)
; now do the right coord of rectangle
doIconRight
MOVE.W iconRect+left(A6),iconRect+right(A6)
ADD.W #iconSize,iconRect+right(A6)
; get the clipping rect's height
MOVE.W interiorClipRect+bottom(A6),D0 ; get clip height into D0
SUB.W interiorClipRect+top(A6),D0
; now subtract the icon height from the clip height
SUBI.W #iconSize,D0
; if 2 or more, divide by 2 and use as vertical offset
; if it's < 2, no vertical offset
CMPI.W #2,D0
BLT.S doIconBottom
; divide and add the offset in
ASR.W #1,D0 ; divide by two
ADD.W D0,iconRect+top(A6)
; now do the bottom coord of rectangle
doIconBottom
MOVE.W iconRect+top(A6),iconRect+bottom(A6)
ADD.W #iconSize,iconRect+bottom(A6)
; get a handle to the icon
; if the control hilites via a content change and is hilited, we draw the secondary
; ICON resource
; content change ?
BTST #chngBit,D4
BEQ useIconOne
; hilited ?
MOVE.B contrlHilite(A2),D1
BEQ useIconOne
ADDQ.B #1,D1
BEQ useIconOne
useIconTwo
; we'll be using the secondary ICON resource
; get a handle and set a flag
MOVE.L secondRsrcHndl(A3),D5 ; the handle
BEQ useIconOne ; in case of a NIL handle
MOVE.W #1,usingCCRsrc(A6) ; the flag
BRA clearBack ; and jump ahead
useIconOne
; we'll be using the primary ICON resource
; get a handle and set a flag
MOVE.L firstRsrcHndl(A3),D5 ; the handle
BEQ iconDrawn ; in case of a NIL handle
CLR.W usingCCRsrc(A6) ; the flag
clearBack
; clear the background
PEA interiorClipRect(A6)
_EraseRect
; okay, let's draw the icon (remember, it gets clipped to the button's interior )
PEA iconRect(A6) ; the destination rectangle
MOVE.L D5,-(SP) ; the icon's handle
_PlotIcon
; now, adjust the icon for buttons that are hilited inverts or inactive
BSR interiorAdjust
iconDrawn
; icon button interior's all drawn
RTS
*----------------------------------------- doTestCntl ----------------------------- *
; the application wants CDEF to test a point to see if it's in an active control
doTestCntl
; first, see if the control's even active, or if it's in one of the two inactive modes
MOVE.B contrlHilite(A2),D7 ;inactive control ?
CMPI.B #inact254,D7
BEQ setReturn2 ;yes, so return appropriate code
CMPI.B #inact255,D7
BEQ setReturn3 ;yes, so return appropriate code
; the control has been found to be active
; now find out if the supplied point is in the control's rectangle
SUBQ.L #2,SP ; room for the function result
MOVE.L D3,-(SP) ; param holds the mouse coords
PEA contrlRect(A2) ; pointer to the control's rectangle
_PtInRect
TST.B (SP)+ ; scan result while chucking
BEQ setReturn3 ; if point isn't in the control ...
; okay, the control's active, and the mouse point's in it
; the control has no separate parts, so we return the whole control's part number
setReturn1
MOVE.L #wholePartNumber,theResult(A6)
RTS
; and here are the return codes for the other possibilities
setReturn2
MOVE.L #254,theResult(A6) ;inactive type 254
RTS
setReturn3
MOVE.L #0,theResult(A6) ;inactive type 255
RTS ;or not in control
*------------------------------------- doCalcCCntl -------------------------------- *
; calculate the control's region
doCalcCCntl
MOVE.L D3,-(SP) ; param holds the waiting handle
PEA contrlRect(A2) ; use the control's rectangle
_RectRgn
RTS
*------------------------------------- doInitCntl --------------------------------- *
; do any special initialization of the control
; in this case, set up a control data block
; then load in any necessary resources, and store handles in the control data block
doInitCntl
; try to get a control data block
MOVE.L #cntlDataBlokSize,D0
_NewHandle,CLEAR
; store the result
MOVE.L A0,contrlData(A2)
BEQ initDone ; if we got no block, leave
lockDataBlock
MOVEA.L A0,A3 ; save a copy of the block's handle
_Hlock ; lock the block down
MOVEA.L (A3),A3 ; get a pointer to the locked block
initTextTest
; is this is a text control ?
BTST #textBit,D4 ; the test
BEQ initPictTest ; no, so jump on
;got a text control - does it indicate hiliting via a content change ?
BTST #chngBit,D4 ; the test
BEQ initPictTest ; no, so jump on
; got a text control with content change hiliting, so load in the string resource and lock it
SUBQ.L #4,SP ; room for a handle
MOVE.L #'STR ',-(SP) ; the resource type
MOVE.W contrlRFcon(A2),-(SP) ; the resource id
_GetResource ; try to grab that resource
MOVE.L (SP)+,firstRsrcHndl(A3) ; store its handle (possibly NIL)
BRA initDone
initPictTest
; see if this is a PICT control
BTST #pictBit,D4 ; the test
BEQ initIconTest ; no, so jump on
; got a pict control, so load in the main PICT
SUBQ.L #4,SP ; room for a handle
MOVE.L #'PICT',-(SP) ; the resource type
MOVE.W contrlRFcon+2(A2),-(SP) ; the resource id
_GetResource ; try to grab that resource
MOVE.L (SP)+,firstRsrcHndl(A3) ; store its handle (possibly NIL)
isPictCC
; does it indicate hiliting via a content change ?
BTST #chngBit,D4 ; the test
BEQ initDone ; no, so done
; got a pict control with content change, so load in the secondary PICT
SUBQ.L #4,SP ; room for a handle
MOVE.L #'PICT',-(SP) ; the resource type
MOVE.W contrlRFcon(A2),-(SP) ; the resource id
_GetResource ; try to grab that resource
MOVE.L (SP)+,secondRsrcHndl(A3) ; store its handle (possibly NIL)
BRA initDone ; done
initIconTest
; no test needed; we have an icon control, so load in the main ICON
SUBQ.L #4,SP ; room for a handle
MOVE.L #'ICON',-(SP) ; the resource type
MOVE.W contrlRFcon+2(A2),-(SP) ; the resource id
_GetResource ; try to grab that resource
MOVE.L (SP)+,firstRsrcHndl(A3) ; store its handle (possibly NIL)
isIconCC
; does it indicate hiliting via a content change ?
BTST #chngBit,D4 ; the test
BEQ initDone ; no, so done
; got an icon control with content change, so load in the secondary ICON
SUBQ.L #4,SP ; room for a handle
MOVE.L #'ICON',-(SP) ; the resource type
MOVE.W contrlRFcon(A2),-(SP) ; the resource id
_GetResource ; try to grab that resource
MOVE.L (SP)+,secondRsrcHndl(A3) ; store its handle (possibly NIL)
initDone
; that's it for initialization
RTS
*------------------------------------- doDispCntl --------------------------------- *
; do any special disposal operations for the control
; in this case, release resources whose handles are stored in the control's
; data block, then release that block
doDispCntl
; see if we ever got a control data block
TST.L contrlData(A2)
BEQ dispDone ; no block, so leave
checkFirst
; see if there's a handle in the first slot
TST.L firstRsrcHndl(A3) ; got a real handle ?
BEQ checkSecond ; no, it's NIL, so jump ahead
MOVE.L firstRsrcHndl(A3),-(SP) ; handle okay, so let go of that resource
_ReleaseResource
checkSecond
; see if there's a handle in the second slot
TST.L secondRsrcHndl(A3) ; got a real handle ?
BEQ dropDataBlock ; no, it's NIL, so jump ahead
MOVE.L secondRsrcHndl(A3),-(SP) ; handle okay, so let go of that resource
_ReleaseResource
dropDataBlock
; now get rid of the control's data block
MOVEA.L contrlData(A2),A0
_DisposHandle
dispDone RTS
*------------------------------------- doPosCntl ---------------------------------- *
; the position routine
; in this case, do nothing
doPosCntl RTS
*------------------------------------ doThumbCntl --------------------------------- *
; the thumb routine
; in this case, do nothing
doThumbCntl RTS
*------------------------------------ doDragCntl ---------------------------------- *
; the drag routine
; in this case, do nothing
doDragCntl RTS
*------------------------------------ doAutoTrack --------------------------------- *
; the track routine
; in this case, do nothing
doAutoTrack RTS