💾 Archived View for mirrors.apple2.org.za › archive › apple.cabi.net › Graphics › PICT.and_QT.INFO ›… captured on 2024-05-10 at 15:25:42.
View Raw
More Information
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
/******************************************************************************\
- Apple Macintosh Developer Technical Support
- Picture Document routines
- Program: ColorReset
- File: PictDocument.c
- by: Forrest Tanaka
- Copyright . 1988-1992 Apple Computer, Inc.
- All rights reserved.
- This source file is the most important part of this program because it shows
- all the code needed to maintain Picture Documents. A Picture Document is a
- window which displays an off-screen image and lets you paint into it, and
- these two activities show how to use graphics environments to draw off screen
- and copy the off-screen image to the window on the screen.
\******************************************************************************/
/******************************************************************************\
\******************************************************************************/
/* System header files needed by MPW C */
#ifndef THINK_C
#include <Errors.h>
#include <Menus.h>
#include <Resources.h>
#include <Windows.h>
#endif
#include <GestaltEqu.h>
#include <Palettes.h>
#include <Picker.h>
#include <QDOffscreen.h>
/* Header files specific to this program */
#include "PictDocument.h"
#include "EmergMem.h"
#include "Exceptions.h"
#include "ColorReset.h"
#include "MenuHandler.h"
#include "WindowPositioner.h"
/******************************************************************************\
\******************************************************************************/
/* Picture Document window constants */
#define rPictDocWindID 128 /* Resource ID of Picture Document WIND resource */
#define rScrollBarID 128 /* Resource ID of scroll bar CNTL resource */
#define kDocWKind 128 /* windowKind field of Picture Document windows */
#define kMinWindowSize 64 /* Minimum size of the window in pixels */
/* PICT file constants */
#define kPictFileHeaderSize 512 /* Number of bytes in PICT file header */
#define kFileCreator 'CLIM' /* Creator code for this application */
#define kFileType 'PICT' /* File type for this app.s documents */
/* Off-screen Constants */
#define kMaxRowBytes 0x3FFE /* Maximum number of bytes in a row of pixels */
#define kDefaultRes 0x00480000 /* Default resolution is 72 DPI; Fixed type */
#define kITabRes 4 /* Inverse-table resolution */
/* Miscellaneous constants */
#define kPaintRadius 8 /* Radius of a drop of paint in pixels */
/******************************************************************************\
\******************************************************************************/
/* Picture Document information */
typedef struct
{
GWorldPtr image; /* Pointer to image in off-screen GWorld */
Rect windowRect; /* Rectangle of window except for scroll bars */
Rect destRect; /* Rectangle of image in window */
RGBColor foreground; /* Color of foreground */
RGBColor background; /* Color of background */
ControlHandle vScrollBar; /* Horizontal scroll bar */
ControlHandle hScrollBar; /* Vertical scroll bar */
FSSpec file; /* File spec of Picture Document.s PICT file */
short fileRef; /* File ref # of Picture Document.s PICT file */
Boolean dithering; /* True if image should be dithered */
} PictDocInfoRec, *PictDocInfoPtr, **PictDocInfoHnd;
/* Basic picture information */
typedef struct
{
CTabHandle colors; /* Handle to color table of deepest pixel map */
short depth; /* Max depth for all pixmaps (in the picture) */
Rect frame; /* Picture frame rect (contains entire picture) */
} PictureInfoRec;
/******************************************************************************\
- Prototypes of Private Functions
\******************************************************************************/
static OSErr CreatePictDoc(
Rect *pictureRect,
short pictureDepth,
CTabHandle pictureClut,
WindowPtr *retDoc);
pascal void ScrollActionProc(
ControlHandle control,
short part);
static void ScrollPictDoc(
WindowPtr docWindow,
short hScrollDelta,
short vScrollDelta);
void ResizePictDoc(
WindowPtr docWindow);
OSErr CreateOffScreen(
Rect *bounds,
short depth,
CTabHandle colors,
CGrafPtr *retPort,
GDHandle *retGDevice);
OSErr SetUpPixMap(
short depth,
Rect *bounds,
CTabHandle colors,
short bytesPerRow,
PixMapHandle aPixMap);
OSErr CreateGDevice(
PixMapHandle basePixMap,
GDHandle *retGDevice);
void DisposeOffScreen(
CGrafPtr doomedPort,
GDHandle doomedGDevice);
OSErr GetPictureInfo(
short pictFileRef,
PictureInfoRec *retPictInfo);
pascal void InfoBits(
BitMapPtr srcBits,
Rect *srcRect,
Rect *dstRect,
short mode,
RgnHandle maskRgn);
OSErr DrawFilePicture(
short pictFileRef,
Rect *destRect);
pascal void FileGetPic(
Ptr dataPtr,
short byteCount);
OSErr OpenFilePicture(
short pictFileRef,
Rect *sourceRect);
OSErr CloseFilePicture(void);
pascal void FilePutPic(
Ptr dataPtr,
short byteCount);
/******************************************************************************\
\******************************************************************************/
PictureInfoRec gPictureInfo; /* Information about a PICT file */
PicHandle gSpoolPicture; /* Temporary picture used to spool from PICT file */
QDProcsPtr gSavedProcs; /* Saves existing QDProcs; used when spooling out */
CQDProcs gCustomProcs; /* Customized bottlenecks to spool to PICT file */
short gPictFileRef; /* File reference number of a PICT file */
short gPictureSize; /* Size of picture in bytes */
/******************************************************************************\
- NAME & SYNOPSIS:
- FindPictDoc: Find the Picture Document window for a specific file
- PARAMETERS:
- See PictDocument.h
- DEFINITION:
- See PictDocument.h
- DESCRIPTION:
- Each Picture Document window in the window list is examined to see whether it
- has a corresponding disk file. The fileRef field of the Picture Document
- information record is non-zero if the Picture Document has a disk file
- associated with it. If there is a disk file, then EqualFSSpec is called to
- see if the FSSpec that I saved in the document.s info record is the same as
- the one passed in fileSpec. If they are, then a pointer to the window is
- returned. Otherwise, the loop goes to the next Picture Document window, if
- there is one.
- See ColorReset.h for a definition of EqualFSSpec.
- RETURN VALUES:
- See PictDocument.h
\******************************************************************************/
WindowPtr FindPictDoc(
FSSpecPtr fileSpec) /* Specification of file to search for */
{
WindowPtr pictDocWindow; /* Pointer to Picture Document being tested */
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document info rec */
Boolean foundDoc; /* True if found Pict Doc w/ same FSSpec */
/* Get a pointer to the first Picture Document window in the window list */
pictDocWindow = NextPictDocWindow( nil );
/* Keep searching until found or at end of list */
foundDoc = false;
while (pictDocWindow != nil && !foundDoc)
{
/* Only have to check FSSpecs if document has a corresponding file */
pictDocInfo = (PictDocInfoHnd)GetWRefCon( pictDocWindow );
if ((**pictDocInfo).fileRef != 0)
{
/* See if the Picture Document.s file is same as fileSpec */
HLock( (Handle)pictDocInfo );
foundDoc = EqualFSSpec( fileSpec, &(**pictDocInfo).file );
HUnlock( (Handle)pictDocInfo );
/* If FSSpecs aren.t the same, then go to next Picture Document */
if (!foundDoc)
pictDocWindow = NextPictDocWindow( pictDocWindow );
}
}
return pictDocWindow;
}
/******************************************************************************\
- NAME & SYNOPSIS:
- NextPictDocWindow: Return a pointer to the next Picture Document window
- PARAMETERS:
- See PictDocument.h
- DEFINITION:
- See PictDocument.h
- DESCRIPTION:
- NextPictDocWindow goes through every window in the window list that.s behind
- the window specified by aWindow until either a Picture Document window is
- found or until the end of the window list is reached. If aWindow is nil, then
- the search starts with the front window.
- RETURN VALUES:
- See PictDocument.h
\******************************************************************************/
WindowPtr NextPictDocWindow(
WindowPtr aWindow) /* Window to start search from, or nil if front */
{
/* Start search from next window, or front window if aWindow is nil */
if (aWindow == nil)
aWindow = FrontWindow();
else
aWindow = (WindowPtr)((WindowPeek)aWindow)->nextWindow;
/* Search until Picture Document wind found or end of wind list reached */
while (aWindow != nil && !IsPictDocWindow( aWindow ))
aWindow = (WindowPtr)((WindowPeek)aWindow)->nextWindow;
return aWindow;
}
/******************************************************************************\
- NAME & SYNOPSIS:
- IsPictDocWindow: Is a window a Picture Document window?
- PARAMETERS:
- See PictDocument.h
- DEFINITION:
- See PictDocument.h
- DESCRIPTION:
- When I create a window, I store a code for that kind of window in the
- windowKind field. IsPictDocWindow checks the windowKind field of the given
- window against the constant kDocWKind. If they.re equal, then aWindow
- must be a Picture Document window.
- RETURN VALUES:
- See PictDocument.h
\******************************************************************************/
Boolean IsPictDocWindow (
WindowPtr aWindow) /* Pointer to the window being tested */
{
return ((WindowPeek)aWindow)->windowKind == kDocWKind;
}
/******************************************************************************\
- NAME & SYNOPSIS:
- DrawPictDoc: Draw the contents of a Picture Document
- PARAMETERS:
- See PictDocument.h
- DEFINITION:
- See PictDocument.h
- DESCRIPTION:
- The image for Picture Documents is stored in an off-screen GrafPort, and its
- GrafPtr is stored in the information record. This GrafPtr is retrieved, and
- it.s used to CopyBits the GrafPort to the window. It.s possible that not all
- of the image can be copied to the window. For example, part of the window
- might be covered by another window. In this case, the visRgn of the window
- takes care of clipping out the undesireable parts of the original image. The
- other case in which part of the image shouldn.t be drawn is if part of the
- image is scrolled out of the window. The visRgn of the window takes care of
- part of this, but we still have to make sure that the image doesn.t draw
- itself over the scroll bar areas of the window in case the scroll bars are
- hidden, which they are if the window is inactive. To take care of this, the
- destination rectangle which is the rectangle that the off-screen image is
- copied to, is first intersected with the window rectangle, which is the
- rectangle of the window except for the scroll bars. This is used as the
- destination rectangle to CopyBits. Then this rectangle is offset by the top-
- left corner of the original destination rectangle, and this is used as the
- source rectangle to CopyBits. The off-screen image is then copied to the
- window.
- RETURN VALUES:
- See PictDocument.h
\******************************************************************************/
void DrawPictDoc(
WindowPtr docWindow) /* Ptr to Picture Document window being drawn */
{
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document information rec */
GWorldPtr image; /* Pointer to the off-screen image */
Rect destRect; /* Rectangle to copy image into */
Rect sourceRect; /* Rectangle to copy image from */
Rect windowRect; /* Rect of the window except for scroll bars */
short mode; /* Drawing mode to use */
/* Get a pointer to the off-screen image and the window rectangle */
pictDocInfo = (PictDocInfoHnd)GetWRefCon( docWindow );
image = (**pictDocInfo).image;
windowRect = (**pictDocInfo).windowRect;
/* Calculate the rectangle to copy the image to */
destRect = (**pictDocInfo).destRect;
(void)SectRect( &destRect, &windowRect, &destRect );
/* Calculate the rectangle to copy the image from */
sourceRect = destRect;
OffsetRect( &sourceRect, -(**pictDocInfo).destRect.left,
-(**pictDocInfo).destRect.top );
/* Specify the drawing mode to use */
mode = srcCopy;
if ((**pictDocInfo).dithering)
mode |= ditherCopy;
/* Draw the off-screen image to the screen */
EraseRect( &docWindow->portRect );
CopyBits( &((GrafPtr)image)->portBits, &docWindow->portBits,
&sourceRect, &destRect,
mode, nil );
/* Draw the grow box */
DrawGrowIcon( docWindow );
/* Draw the scroll bars */
DrawControls( docWindow );
}
/******************************************************************************\
- NAME & SYNOPSIS:
- ClickPictDoc: Handle a mouse click in a Picture Document window
- PARAMETERS:
- See PictDocument.h
- DEFINITION:
- See PictDocument.h
- DESCRIPTION:
- The first really important call in this routine is FindControl, which is the
- toolbox call which tells you which control and which part of the control the
- mouse was clicked in. If it returns zero, then the mouse was clicked outside
- of any control, and so we let the user paint into the document.
- Painting into the document is done within a loop which iterates as long as the
- mouse button is held down. While this is the case, the current mouse position
- is retrieved with a call to GetMouse. If the mouse position changed from the
- previous iteration.s mouse position, then the mouse position is offset to take
- into account the currently-scrolled position, and then the current port is set
- to the document.s off-screen GrafPort. Then, PaintOval is called which draws
- a drop of paint into the off-screen GrafPort.
- The off-screen image then has to be copied to the window so that the user can
- see the new drop of paint. This is done by first seeing if the drop of paint
- can actually be seen in the window in the currently-scrolled position. If it
- can, then the rectangle of the drop of paint is offset to take into account
- the currently-scrolled position. Then the current port is set to the document
- window, and CopyBits is called to copy the new drop of paint to the document
- window.
- Finally, the mouse position is remembered and the loop iterates again if the
- mouse button is still held down.
- If FindControl indicates that the mouse click was in the thumb of a scroll
- bar, TrackControl is called which lets the user move the thumb around until
- the user releases the mouse button. Then, the difference between the old and
- new scroll bar position is calculated which indicates the number of pixels
- that the document must be scrolled. ScrollPictDoc, defined below, is then
- called to scroll the document.s image, update the scrolled-in part of the
- image, and update the document information record to reflect the new scrolled
- position.
- If FindControl indicates that the mouse click was in the up arrow, down arrow,
- page up, or page down areas of either scroll bar, then TrackControl is called
- to scroll the document appropriately. The ScrollActionProc routine, defined
- below, handles the logistics of scrolling in this case.
- RETURN VALUES:
- See PictDocument.h
\******************************************************************************/
void ClickPictDoc(
WindowPtr docWindow, /* Picture Document window that was clicked */
EventRecord *clickEvent) /* Mouse click event */
{
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document info rec */
GWorldPtr image; /* Pointer to the off-screen image */
GDHandle savedDevice; /* Saves default GDevice */
Rect paintRect; /* Rectangle to draw paint into */
Rect windowPaintRect; /* Rectangle to draw paint into */
Rect windowRect; /* Window rect except for scroll bars */
Rect destRect; /* Rectangle of image in window */
Point newPosition; /* New pos of mouse click; local coords */
Point oldPosition; /* Old pos of mouse click; local coords */
ControlHandle scrollBar; /* Handle to the clicked scroll bar */
short partNumber; /* Part # of clicked part of control */
short scrollDelta; /* Number of pixels to scroll */
savedDevice = GetGDevice();
/* Get information about the Picture Document */
pictDocInfo = (PictDocInfoHnd)GetWRefCon( docWindow );
image = (**pictDocInfo).image;
windowRect = (**pictDocInfo).windowRect;
destRect = (**pictDocInfo).destRect;
/* Get the mouse click position */
SetPort( docWindow );
newPosition = clickEvent->where;
GlobalToLocal( /*.*/&newPosition );
/* Find whether the mouse was in a control */
partNumber = FindControl( newPosition, docWindow, /*<*/&scrollBar );
switch (partNumber)
{
case 0:
/* Clicked outside of any control; see if it was in the image */
if (PtInRect( newPosition, &windowRect ))
{
/* Click in image; paint while mouse button is held down */
oldPosition.v = oldPosition.h = -32767;
while (StillDown())
{
/* Only do something if the mouse moved */
if (!EqualPt( newPosition, oldPosition ))
{
/* Need to offset paint brush for scrolled position */
SubPt( topLeft( destRect ), /*.*/&newPosition );
SetRect( /*<*/&paintRect, newPosition.h - kPaintRadius,
newPosition.v - kPaintRadius,
newPosition.h + kPaintRadius,
newPosition.v + kPaintRadius );
/* Drop some paint into the off-screen image */
SetGWorld( image, nil );
PaintOval( &paintRect );
/* Offset brush back to window position */
AddPt( topLeft( destRect ), /*.*/&newPosition );
/* Calc rect in window for to brush rect in image */
windowPaintRect = paintRect;
OffsetRect( &windowPaintRect, destRect.left,
destRect.top );
/* Only copy if some part of brush within image */
if (SectRect( &windowPaintRect, &windowRect,
&windowPaintRect ))
{
/* Make clipped paint rect in off-screen image */
paintRect = windowPaintRect;
OffsetRect( &paintRect, -destRect.left,
-destRect.top );
/* Copy painted off-screen image to the screen */
SetGWorld( (CGrafPtr)docWindow, nil );
CopyBits( &((GrafPtr)image)->portBits, &docWindow->portBits,
&paintRect, &windowPaintRect,
srcCopy, nil );
}
/* Remember the new mouse position */
oldPosition = newPosition;
}
/* Get the new position of the mouse */
SetPort( docWindow );
GetMouse( /*<*/&newPosition );
}
}
break;
case inThumb:
/* Mouse in thumb of scroll bar; get existing control value */
scrollDelta = GetCtlValue( scrollBar );
/* Track mouse in thumb until mouse button is released */
partNumber = TrackControl( scrollBar, newPosition, nil );
if (partNumber != 0)
{
/* Find diff between old and new scroll bar values */
scrollDelta -= GetCtlValue( scrollBar );
if (scrollDelta != 0)
{
if (scrollBar == (**pictDocInfo).vScrollBar)
ScrollPictDoc( docWindow, 0, scrollDelta );
else
ScrollPictDoc( docWindow, scrollDelta, 0 );
}
}
break;
case inUpButton:
case inDownButton:
case inPageUp:
case inPageDown:
(void)TrackControl( scrollBar, newPosition, (ProcPtr)ScrollActionProc );
break;
default:
break;
}
}
/******************************************************************************\
- NAME & SYNOPSIS:
- ScrollActionProc: Handle a click in a scroll bar (except for thumb)
- PARAMETERS:
- ControlHandle control: Control that received the mouse click
- short part: Part number of the clicked control part
- DEFINITION:
- ScrollActionProc is called by the Control Manager when TrackControl is called
- in the ClickPictDoc function above. It handles scrolling when the user clicks
- in the scroll arrows or page areas of the scroll bar. The document is
- scrolled by the appropriate amount.
- DESCRIPTION:
- ScrollActionProc first checks to see which part of the scroll bar was clicked.
- If it was in either of the arrows, then the desired scroll amount is one
- pixel. If it was in either of the paging areas, then the desired scroll
- amount is 32 pixels. The current value of the clicked scroll bar is then
- adjusted by the desired scroll amount, and the result is compared against the
- limits of the scroll bar.s values. If the new value is beyond either limit,
- then it.s pinned back into the limits. Then the real amount to scroll is
- calculated simply by subtracting the new scroll value from the old scroll
- value, and ScrollPictDoc (defined below) is called to scroll the Picture
- Document window.
- RETURN VALUES:
- None
\******************************************************************************/
static pascal void ScrollActionProc(
ControlHandle control, /* Handle to clicked control */
short part) /* Part number of clicked control part */
{
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document info rec */
WindowPtr docWindow; /* Clicked Picture Document window */
Rect windowRect; /* Window rect except for scroll bars */
Rect destRect; /* Rectangle of image in window */
short scrollDelta; /* Number of pixels to scroll by */
short oldValue; /* Value of scroll bar before scrolling */
short newValue; /* Value of scroll bar after scrolling */
short maxValue; /* Maximum value of the scroll bar */
/* Get information about the Picture Document */
docWindow = (**control).contrlOwner;
pictDocInfo = (PictDocInfoHnd)GetWRefCon( docWindow );
windowRect = (**pictDocInfo).windowRect;
destRect = (**pictDocInfo).destRect;
/* Only process if the part # isn.t zero */
if (part != 0)
{
/* Decide scroll amount based on part of control that was clicked */
switch (part)
{
case inUpButton:
scrollDelta = 1;
break;
case inDownButton:
scrollDelta = -1;
break;
case inPageUp:
scrollDelta = 32;
break;
case inPageDown:
scrollDelta = -32;
break;
default:
scrollDelta = 0;
break;
}
/* Only do something if we.re actually scrolling */
if (scrollDelta != 0)
{
/* Get the current scroll bar state */
maxValue = GetCtlMax( control );
oldValue = GetCtlValue( control );
/* Calculate the new scroll bar value pinned to the limits */
newValue = oldValue - scrollDelta;
if (newValue < 0)
newValue = 0;
else if (newValue > maxValue)
newValue = maxValue;
/* Only scroll if the old and new values are different */
if (oldValue != newValue)
{
/* Set the new value of the scroll bar */
SetCtlValue( control, newValue );
/* Scroll by difference between old and new scroll bar values */
scrollDelta = oldValue - newValue;
if (control == (**pictDocInfo).vScrollBar)
ScrollPictDoc( docWindow, 0, scrollDelta );
else
ScrollPictDoc( docWindow, scrollDelta, 0 );
}
}
}
}
/******************************************************************************\
- NAME & SYNOPSIS:
- ScrollPictDoc: Scroll a Picture Document window.s image
- PARAMETERS:
- WindowPtr docWindow: Pointer to Picture Document window to scroll
- short vScrollDelta: Number of pixels to scroll vertically
- short hScrollDelta: Number of pixels to scroll horizontally
- DEFINITION:
- ScrollPictDoc scrolls the picture document window specified by the docWindow
- parameter by vScrollDelta pixels vertically and hScrollDelta pixels
- horizontally. The part of the window that.s scrolled in is updated, so no
- updating is needed outside of ScrollPictDoc.
- DESCRIPTION:
- ScrollRect is called to scroll the Picture Document.s image by the specified
- amount. The scrolled-in part is then redrawn with a call to CopyBits. The
- destRect field of the Picture Document information record keeps track of the
- scrolled position of the image, so it.s updated to reflect the new scrolled
- position.
- RETURN VALUES:
- None
\******************************************************************************/
static void ScrollPictDoc(
WindowPtr docWindow, /* Pointer to document window to scroll */
short hScrollDelta, /* Number of pixels to scroll horizontally */
short vScrollDelta) /* Number of pixels to scroll vertically */
{
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document info rec */
RgnHandle updateRegion; /* Region covering scrolled-in area */
Rect windowRect; /* Rect of window except for scroll bars */
Rect destRect; /* New destination rectangle */
GWorldPtr image; /* Off-screen document image */
/* Get the window rectangle and destination rectangle */
pictDocInfo = (PictDocInfoHnd)GetWRefCon( docWindow );
windowRect = (**pictDocInfo).windowRect;
destRect = (**pictDocInfo).destRect;
image = (**pictDocInfo).image;
/* Scroll the image by the specified amount */
updateRegion = NewRgn();
ScrollRect( &windowRect, hScrollDelta, vScrollDelta, updateRegion );
/* Update the destination rectangle to the new scrolled position */
OffsetRect( &destRect, hScrollDelta, vScrollDelta );
(**pictDocInfo).destRect = destRect;
/* Update the scrolled-in part of the window */
CopyBits( &((GrafPtr)image)->portBits, &docWindow->portBits,
&image->portRect, &destRect,
srcCopy, updateRegion );
/* Get rid of the update region */
DisposeRgn( updateRegion );
}
/******************************************************************************\
- NAME & SYNOPSIS:
- GrowPictDoc: Let the user change the size of a Picture Document window
- PARAMETERS:
- See PictDocument.h
- DEFINITION:
- See PictDocument.h
- DESCRIPTION:
- GrowWindow is called with a boundary rectangle that specifies that the window
- has a minimum size of kMinWindowSize (defined at the top of this source file)
- and a maximum size that.s the size of the image. After the user releases the
- mouse button, SizeWindow is called to change the size of the window, and
- ResizePictDoc (defined below) is called to update the Picture Document to the
- new size.
- RETURN VALUES:
- See PictDocument.h
\******************************************************************************/
void GrowPictDoc(
WindowPtr docWindow, /* Picture Document window that.s to be grown */
EventRecord *clickEvent) /* Mouse down event */
{
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document info rec */
Rect growBounds; /* Window can be dragged over this rectangle */
Point newSize; /* New size of the new window */
pictDocInfo = (PictDocInfoHnd)GetWRefCon( docWindow );
growBounds = (**pictDocInfo).image->portRect;
growBounds.left = growBounds.top = kMinWindowSize;
growBounds.right += kScrollBarWidth;
growBounds.bottom += kScrollBarWidth;
/* Let the user resize the window to any size */
*((long *)&newSize) = GrowWindow( docWindow, clickEvent->where,
&growBounds );
/* If the user actually changed the size of the window, resize the window */
if (*((long *)&newSize) != 0)
{
SizeWindow( docWindow, newSize.h, newSize.v, true );
ResizePictDoc( docWindow );
}
}
/******************************************************************************\
- NAME & SYNOPSIS:
- ResizePictDoc: Update a picture document window to a new size
- PARAMETERS:
- WindowPtr docWindow: Picture document window that was resized
- DEFINITION:
- ResizePictDoc updates the Picture Document window specified by the docWindow
- to a new size. This routine is called right after the size of docWindow has
- been changed. The act of updating the Picture Document window involves moving
- the scroll bars to the edge of the window and scrolling the document image.
- The image has to be scrolled when the window is grown in case the bottom or
- right edge of the window goes below or to the right of the image, in which
- case the bottom or right edges of the image has to .chase. the bottom or right
- edges of the window, and that means scrolling.
- DESCRIPTION:
- The first major thing that.s done is a new destination rectangle is calculated
- in case the document has to be scrolled as described in the definition. There
- are three conditions that have to be met before scrolling can happen:
- 1) The upper-left corner of destRect must not be (0,0), meaning that the
- document.s image is scrolled from its original position.
- 2) The window has become bigger.
- 3) The window.s rectangle has moved below or to the right of the image in
- the window.
- If all three of these conditions are met for either the horizontal or
- vertical cases, a new destRect is calculated. If this new destRect is
- different from the old destRect, ScrollPictDoc (defined above) is called to
- scroll the image to the new position.
- After this, the windowRect field of the Picture Document information record
- is updated to the new size of the window. Then, the maximum values of the
- scroll bars are set to the number of pixels in the horizontal or vertical
- direction that can.t be seen. And then, the old position of the scroll icon
- is invalidated so that it.ll be erased with the document.s image the next time
- the window is updated.
- Both of the scroll bars are then moved along the bottom and right edges of the
- window, and the new position of the grow icon is invalidated so that it.s
- redrawn in case the window was made smaller. Finally, the rectangles of the
- scroll bars are validated so that they won.t be redrawn in the next update
- event.
- RETURN VALUES:
- None
\******************************************************************************/
static void ResizePictDoc(
WindowPtr docWindow) /* Picture document window that was resized */
{
PictDocInfoHnd pictDocInfo; /* Handle to Picture Document information rec */
ControlHandle vScrollBar; /* Vertical scroll bar */
ControlHandle hScrollBar; /* Horizontal scroll bar */
Rect windowRect; /* Covers part of window that contains image */
Rect newWindowRect; /* Covers all of window except scroll bars */
Rect scrollRect; /* Rectangle of scroll bar */
Rect destRect; /* Rectangle of to draw image into */
Rect newDestRect; /* Rec