Important: The information in this document is obsolete and should not be used for new development.
MyWindow
The window definition function is responsible for drawing the window frame, reporting the region where mouse-down events occur, calculating the window's structure region and content region, drawing the size box, resizing the window frame when the user drags the size box, and performing any customized initialization or disposal tasks.You can give your window definition function any name you wish. It takes four parameters and returns a result code:
FUNCTION MyWindow (varCode: Integer; theWindow: WindowPtr; message: Integer; param: LongInt): LongInt;
varCode
- The window's variation code.
theWindow
- A pointer to the window's window record.
message
- A code for the task to be performed. The
message
parameter has one of these values:CONST wDraw = 0; {draw window frame} wHit = 1; {report where mouse-down event } { occurred} wCalcRgns = 2; {calculate strucRgn and contRgn} wNew = 3; {perform additional } { initialization} wDispose = 4; {perform additional disposal } { tasks} wGrow = 5; {draw grow image during resizing} wDrawGIcon = 6; {draw size box and scroll bar } { outline}Your window definition function performs whatever task is specified by the
- The subsections that follow explain each of these tasks in detail.
param
- Data associated with the task specified by the
message
parameter. If the task requires no data, this parameter is ignored.message
parameter and returns a function result if appropriate. If the task performed requires no result code, return 0.The function's entry point must be at the beginning of the function.
You can set up the various tasks as subroutines inside the window definition function, but you're not required to do so.
Drawing the Window Frame
When you receive awDraw
message, draw the window frame in the current graphics port, which is the Window Manager port.You must make certain checks to determine exactly how to draw the frame. If the value of the
visible
field in the window record isFALSE
, you should do nothing; otherwise, you should examine theparam
parameter and the status flags in the window record:
- If the value of
param
is 0, draw the entire window frame.- If the value of
param
is 0 and thehilited
field in the window record isTRUE
, highlight the frame to show that the window is active.
- If the value of the
goAwayFlag
field in the window record is alsoTRUE
, draw a close box in the window frame.- If the value of the
spareFlag
field in the window record is alsoTRUE
, draw a zoom box in the window frame.
- If the value of the
param
parameter iswInGoAway
, add highlighting to, or remove
it from, the window's close box. Figure 4-19 on page 4-46 illustrates the close box
with and without highlighting as drawn by the Window Manager's window definition function.- If the value of the
param
parameter iswInZoom
, add highlighting to, or remove it from, the window's zoom box. Figure 4-20 on page 4-47 illustrates the zoom box
with and without highlighting as drawn by the Window Manager's window definition function.
The window frame typically but not necessarily includes the window's title, which should be displayed in the system font and system font size. The Window Manager
- Note
- When the Window Manager calls a window definition function
with a message ofwDraw
, it stores a value of typeInteger
in theparam
parameter without clearing the high-order word. When processing thewDraw
message, use only the low-order word of theparam
parameter.
port is already set to use the system font and system font size.When designing a title bar that includes the window title, allow at least 16 pixels vertically to support localization for script systems in which the system font can be no smaller than 12 points.
- Note
- Nothing drawn outside the window's structure region is visible.
Returning the Region of a Mouse-Down Event
When you receive awHit
message, you must determine where the cursor was when the mouse button was pressed. ThewHit
message is accompanied by the mouse location, in global coordinates, in theparam
parameter. The vertical coordinate is in the high-order word of the parameter, and the horizontal coordinate is in the low-order word. You return one of these constants:
CONST wNoHit = 0; {none of the following} wInContent = 1; {in content region (except grow, if active)} wInDrag = 2; {in drag region} wInGrow = 3; {in grow region (active window only)} wInGoAway = 4; {in go-away region (active window only)} wInZoomIn = 5; {in zoom box for zooming in (active window } { only)} wInZoomOut = 6; {in zoom box for zooming out (active window } { only)}The return valuewNoHit
might mean (but not necessarily) that the point isn't in the window. The standard window definition functions, for example, returnwNoHit
if the point is in the window frame but not in the title bar.Return the constants
wInGrow
,wInGoAway
,wInZoomIn
, andwInZoomOut
only if the window is active--by convention, the size box, close box, and zoom box aren't drawn if the window is inactive. In an inactive document window, for example, a mouse-down event in the part of the title bar that would contain the close box if the window were active is reported aswInDrag
.Calculating Regions
When you receive thewCalcRgns
message, you calculate the window's structure and content regions based on the current graphics port's port rectangle. These regions, whose handles are in thestrucRgn
andcontRgn
fields of the window record, are in global coordinates. The Window Manager requests this operation only if the window is visible.
- WARNING
- When you calculate regions for your own type of window, do not alter the clip region or the visible region of the window's graphics port. The Window Manager and QuickDraw take care of this for you. Altering the clip region or visible region may damage other windows.
Initializing a New Window
When you receive thewNew
message, you can perform any type-specific initialization that may be required. If the content region has an unusual shape, for example, you might allocate memory for the region and store the region handle in thedataHandle
field of the window record. The initialization routine for a standard document window creates thewStateData
record for storing zooming data.Disposing of a Window
When you receive thewDispose
message, you can perform any additional tasks necessary for disposing of a window. You might, for example, release memory that was allocated by the initialization routine. The dispose routine for a standard document window disposes of thewStateData
record.Resizing a Window
When you receive thewGrow
message, draw a grow image of the window. With thewGrow
message you receive a pointer to a rectangle, in global coordinates, whose upper-left corner is aligned with the port rectangle of the window's graphics port. Your grow image should fit inside the rectangle. As the user drags the mouse, the Window Manager sends repeatedwGrow
messages, so that you can change your grow image to match the changing mouse location.Draw the grow image in the current graphics port, which is the Window Manager port, in the current pen pattern and pen mode. These are set up (as
gray
andnotPatXor
) to conform to the Macintosh user interface guidelines.The grow routine for a standard document window draws a dotted (gray) outline of the window and also the lines delimiting the title bar, size box, and scroll bar areas.
Drawing the Size Box
When you receive thewDrawGIcon
message, you draw the size box in the content region if the window is active--if the window is inactive, draw whatever is appropriate to show that the window cannot currently be sized.
The routine that draws a size box for an active document window draws the size box in the lower-right corner of the port rectangle of the window's graphics port. It also draws lines delimiting the size box and scroll bar areas. For an inactive document window, it erases the size box and draws the delimiting lines.
- Note
- If the size box is located in the window frame instead of the content region, do nothing in response to the
wDrawGIcon
message, instead drawing the size box in response to thewDraw
message.