home *** CD-ROM | disk | FTP | other *** search
- /*
- * iconwindow.c - a custom Window Definition procedure.
- *
- * The window implemented here behaves just like a standard window,
- * but with one twist:
- * if the window is less than a certain size, it is drawn differently.
- *
- * A small window (called "collapsed" here) has its title box below the window
- * contents (rather than above). The title is drawn in a smaller font and
- * on a separate line from the close and zoom boxes.
- *
- * A collapsed window's grow region occupies the entire window contents.
- * It has no grow icon.
- *
- * To use this WDEF, create a window with a ProcID of 4120
- * (16 x iconwind's ID of 257, +8 for zooming) or 4112
- * (if you don't want zooming).
- *
- * Brad Needham
- * 2239 SE 74th Ave.
- * Hillsboro, OR 97123 USA
- */
-
- #include <MemoryMgr.h>
- #include <Quickdraw.h>
- #include <WindowMgr.h>
- #include <FontMgr.h>
-
- /*
- * SMALLWIDTH,
- * SMALLHEIGHT - largest dimensions of a collapsed-state window's portRect.
- * Any window larger than this (in both dimensions) is drawn in its
- * uncollapsed state.
- *
- * NOTE: don't change these numbers -- the applications need to use them
- * to tell whether a window is collapsed or not.
- */
-
- #define SMALLWIDTH 63
- #define SMALLHEIGHT 15
-
- /*
- * TITLEFONT
- * TITLESTYLE
- * TITLEFSIZE - The look of the title in a collapsed window.
- * These values are the same ones the finder uses.
- *
- * NOTE: If you change these constants, you will need to recalculate piles
- * of hard-coded numbers in this file.
- */
-
- #define TITLEFONT geneva
- #define TITLESTYLE ((Style) 0)
- #define TITLEFSIZE 9
-
- /*
- * SMALLCHANGE - largest difference from the "Standard State"
- * window size and position that is still considered the "Standard State".
- *
- * A window that has moved or resized more than this number of pixels
- * goes into the "User State".
- *
- * This number comes from Inside Macintosh IV, page 10.
- */
-
- #define SMALLCHANGE 7
-
- #define BOXWIDSMALL 9 /* pixels width (and height) of a close/zoom-box */
- #define BOXWIDBIG 11 /* ditto in a normal-size window */
- #define BOXHMARGIN 2 /* horizontal margin around a small box */
-
- /*
- * struct wdims - interesting areas of a window.
- * wcalcdims() calculates these values.
- */
-
- struct wdims {
- Rect contrect; /* bounds of the content region */
- Rect titlerect; /* the title bar (and it's frame) */
- Rect textclip; /* a clip rectangle for the title string */
- Point titleref; /* starting point for drawing the title text */
- Rect closerect; /* the close box and frame */
- Rect zoomrect; /* the zoom box and frame */
- Rect growrect; /* the grow rectangle */
- };
-
- /*
- * main() - the entry-point to our custom window definition.
- *
- * Because the WDEF must be a pure-code resource,
- * we can't use any global or static data,
- * which forces us to recalculate a lot of information each time we're called.
- */
-
- pascal long
- main(varcode, windp, op, parm)
- int varcode; /* window variation code */
- WindowPeek windp; /* the window to operate on */
- int op; /* the operation to perform */
- long parm; /* the parameter of the operation (if any) */
- {
- long retval; /* the value to return */
- long wfindhit();
-
- retval = 0L;
-
- switch(op) {
- case wNew: /* do our custom initialization */
- winit(windp, varcode);
- break;
- case wDispose: /* do our custom disposal */
- wcleanup(windp);
- break;
- case wCalcRgns: /* calculate the important window regions */
- wregions(windp);
- break;
- case wDraw: /* draw an interesting piece (if visible) */
- if (windp->visible) {
- if ((int) parm == 0) {
- wdrawframe(windp);
- } else {
- wtoggle_box(windp, (int) parm);
- }
- }
- break;
- case wHit: /* see which region the mouse is in */
- retval = wfindhit(windp, LoWord(parm), HiWord(parm));
- break;
- case wGrow: /* draw the window's growing image */
- woutline(windp, (Rect *) parm);
- break;
- case wDrawGIcon: /* draw the size box */
- wgicon(windp);
- break;
- }
- return(retval);
- }
-
- /*
- * winit() - initialize the given window.
- */
-
- winit(windp, varcode)
- WindowPeek windp;
- int varcode; /* the window's variation code */
- {
- GrafPtr myport; /* the window manager port */
- WStateData *wsp;
-
- GetPort(&myport);
-
- /*
- * If the user has requested a zoomable window,
- * we need to allocate the zoom information.
- */
-
- if (varcode & 0x8) {
- windp->dataHandle = NewHandle((Size) sizeof(WStateData));
- } else {
- windp->dataHandle = (Handle) 0;
- }
-
- /*
- * If the allocation failed or the user didn't ask for zooming,
- * Leave spareFlag alone (zero), indicating we don't zoom.
- * Otherwise, set the spareFlag to indicate we're a zoomable window.
- */
-
- if (!windp->dataHandle) {
- return;
- }
- windp->spareFlag = 1;
-
- /*
- * The default Standard State is a little less than the bounds
- * of the screen. (This code should be modded to support multiple screens.)
- *
- * The userState is the user's port, mapped into global coordinates.
- */
-
- HLock(windp->dataHandle);
- wsp = (WStateData *) *(windp->dataHandle);
-
- wsp->stdState = myport->portRect;
- wsp->stdState.top += 38; /* space for the menubar and title bar */
- InsetRect(&wsp->stdState, 3, 3);
-
- wsp->userState = windp->port.portRect;
- OffsetRect(&wsp->userState,
- -windp->port.portBits.bounds.left,
- -windp->port.portBits.bounds.top);
-
- HUnlock(windp->dataHandle);
- }
-
- /*
- * wcleanup() - dispose of the special parts of the window.
- */
-
- wcleanup(windp)
- WindowPeek windp;
- {
- if (windp->spareFlag != 0) {
- DisposHandle(windp->dataHandle);
- }
- }
-
- /*
- * wregions() - calculate the window's structure and content regions
- * based on the current GrafPort's portRect.
- * These regions are in global coordinates.
- *
- * Calling this routine can change the userState (unzoomed state) of the window.
- */
-
- wregions(windp)
- WindowPeek windp;
- {
- struct wdims dim; /* dimensions of the window */
- WStateData *wsp; /* the window's zoomed and unzoomed state */
- int v; /* a temporary vertical position */
-
- /*
- * If we can zoom and we are in the un-zoomed ("User") state,
- * record the new un-zoomed size and position of the window.
- */
-
- if (windp->spareFlag && zoompart(windp) == wInZoomOut) {
- HLock(windp->dataHandle);
- wsp = (WStateData *) *(windp->dataHandle);
-
- wsp->userState = windp->port.portRect;
- OffsetRect(&wsp->userState,
- -windp->port.portBits.bounds.left,
- -windp->port.portBits.bounds.top);
-
- HUnlock(windp->dataHandle);
- }
-
- wcalcdims(windp, (Rect *) 0, &dim);
-
- /*
- * The content region calculation is straightforward.
- * The Structure region calculation depends on whether the window
- * is collapsed or not.
- */
-
- RectRgn(windp->contRgn, &dim.contrect);
-
- OpenRgn();
- if (is_smallrect(&dim.contrect)) {
-
- /*
- * A collapsed window has a 1-pixel frame around the content box
- * with a title box below the content box.
- *
- * Since the content box can be either larger or smaller than
- * the title box, the enclosing region for one case is
- * a little different than that for the other.
- */
-
- if (dim.titlerect.right >= dim.contrect.right + 1) {
- v = dim.titlerect.top;
- } else {
- v = dim.titlerect.top + 1;
- }
-
- MoveTo(dim.contrect.left - 1, dim.contrect.top - 1);
- LineTo(dim.contrect.right + 1, dim.contrect.top - 1);
- LineTo(dim.contrect.right + 1, v);
- LineTo(dim.titlerect.right, v);
- LineTo(dim.titlerect.right, dim.titlerect.bottom);
- LineTo(dim.titlerect.left, dim.titlerect.bottom);
- LineTo(dim.titlerect.left, v);
- LineTo(dim.contrect.left - 1, v);
- LineTo(dim.contrect.left - 1, dim.contrect.top - 1);
-
- } else {
-
- /*
- * A standard window is rectangular, but it has a 1-pixel shadow
- * to its right and bottom.
- */
-
- MoveTo(dim.titlerect.left, dim.titlerect.top);
- LineTo(dim.titlerect.right, dim.titlerect.top);
- LineTo(dim.titlerect.right, dim.titlerect.top + 1);
- LineTo(dim.titlerect.right + 1, dim.titlerect.top + 1);
- LineTo(dim.titlerect.right + 1, dim.contrect.bottom + 2);
- LineTo(dim.titlerect.left + 1, dim.contrect.bottom + 2);
- LineTo(dim.titlerect.left + 1, dim.contrect.bottom + 1);
- LineTo(dim.titlerect.left, dim.contrect.bottom + 1);
- LineTo(dim.titlerect.left, dim.titlerect.top);
- }
- CloseRgn(windp->strucRgn);
- }
-
- /*
- * wdrawframe() - draw the window frame in the current (window manager's) port.
- * Assumes the window is visible.
- */
-
- wdrawframe(windp)
- WindowPeek windp;
- {
- GrafPtr myport; /* the current port */
- struct wdims dim; /* dimensions of the window */
- int oldfont; /* the original font to restore */
- Style oldface; /* its Style */
- int oldsize; /* its font size */
- RgnHandle oldclip; /* the original clipRgn to restore */
- int v; /* a temporary vertical coordinate */
- Rect tmprect; /* a temporary rectangle */
-
- wcalcdims(windp, (Rect *) 0, &dim);
-
- GetPort(&myport);
-
- if (is_smallrect(&dim.contrect)) {
-
- /*
- * For a collapsed window,
- * Always draw the border and the window title.
- */
-
- tmprect = dim.contrect;
- InsetRect(&tmprect, -1, -1);
- FrameRect(&tmprect);
- FrameRect(&dim.titlerect);
-
- tmprect = dim.titlerect;
- InsetRect(&tmprect, 1, 1);
- EraseRect(&tmprect);
-
- oldfont = myport->txFont;
- oldface = myport->txFace;
- oldsize = myport->txSize;
- TextFont(TITLEFONT);
- TextFace(TITLESTYLE);
- TextSize(TITLEFSIZE);
-
- HLock((Handle) windp->titleHandle);
-
- MoveTo(dim.titleref.h, dim.titleref.v);
- DrawString(*(windp->titleHandle));
-
- HUnlock((Handle) windp->titleHandle);
-
- TextFont(oldfont);
- TextFace(oldface);
- TextSize(oldsize);
-
- /*
- * If the window is active,
- * draw the close/zoom boxes (if they exist) and the selection lines.
- */
-
- if (windp->hilited) {
-
- if (windp->goAwayFlag) {
- FrameRect(&dim.closerect);
- }
-
- if (windp->spareFlag != 0) {
- FrameRect(&dim.zoomrect);
- MoveTo(dim.zoomrect.left,
- (dim.zoomrect.top + dim.zoomrect.bottom + 1) / 2);
- LineTo((dim.zoomrect.left + dim.zoomrect.right + 1) / 2,
- (dim.zoomrect.top + dim.zoomrect.bottom + 1) / 2);
- LineTo((dim.zoomrect.left + dim.zoomrect.right + 1) / 2,
- dim.zoomrect.top);
- }
-
- for (v = dim.closerect.bottom - 1; v >= dim.closerect.top; v -= 2) {
- if (windp->goAwayFlag) {
- MoveTo(dim.closerect.right + BOXHMARGIN, v);
- } else {
- MoveTo(dim.closerect.left, v);
- }
- if (windp->spareFlag != 0) {
- LineTo(dim.zoomrect.left - BOXHMARGIN - 1, v);
- } else {
- LineTo(dim.zoomrect.right - 1, v);
- }
- }
- }
- } else {
-
- /*
- * For a standard (non-collapsed) window,
- * Draw the border, the shadow, and the (clipped) window title.
- */
-
- tmprect = dim.contrect;
- InsetRect(&tmprect, -1, -1);
- UnionRect(&tmprect, &dim.titlerect, &tmprect);
- FrameRect(&tmprect);
-
- tmprect = dim.titlerect;
- InsetRect(&tmprect, 1, 1);
- EraseRect(&tmprect);
-
- MoveTo(dim.titlerect.left, dim.titlerect.bottom - 1);
- LineTo(dim.titlerect.right - 1, dim.titlerect.bottom - 1);
-
- MoveTo(dim.titlerect.left + 1, dim.contrect.bottom + 1);
- LineTo(dim.titlerect.right, dim.contrect.bottom + 1);
- LineTo(dim.titlerect.right, dim.titlerect.top + 1);
-
- /*
- * The window's title has to be clipped, in case it's too long for the
- * window width.
- */
-
- oldclip = NewRgn();
- if (oldclip) {
- GetClip(oldclip);
- RectRgn(myport->clipRgn, &dim.textclip);
- SectRgn(oldclip, myport->clipRgn, myport->clipRgn);
- }
-
- HLock((Handle) windp->titleHandle);
- MoveTo(dim.titleref.h, dim.titleref.v);
- DrawString(*(windp->titleHandle));
- HUnlock((Handle) windp->titleHandle);
-
- if (oldclip) {
- SetClip(oldclip);
- DisposeRgn(oldclip);
- }
-
- /*
- * If the window is active,
- * draw the close/zoom boxes (if they exist) and the selection lines.
- */
-
- if (windp->hilited) {
-
- if (windp->goAwayFlag) {
- FrameRect(&dim.closerect);
- }
-
- if (windp->spareFlag != 0) {
- FrameRect(&dim.zoomrect);
- MoveTo(dim.zoomrect.left,
- (dim.zoomrect.top + dim.zoomrect.bottom + 1) / 2);
- LineTo((dim.zoomrect.left + dim.zoomrect.right + 1) / 2,
- (dim.zoomrect.top + dim.zoomrect.bottom) / 2 + 1);
- LineTo((dim.zoomrect.left + dim.zoomrect.right + 1) / 2,
- dim.zoomrect.top);
- }
-
- for (v = dim.closerect.bottom - 1; v >= dim.closerect.top; v -= 2) {
- MoveTo(dim.titlerect.left + 2, v);
- if (windp->goAwayFlag) {
- LineTo(dim.closerect.left - 1 - 1, v);
- MoveTo(dim.closerect.right + 1, v);
- }
- LineTo(dim.textclip.left - 6 - 1, v);
-
- MoveTo(dim.textclip.right + 5, v);
- if (windp->spareFlag != 0) {
- LineTo(dim.zoomrect.left - 1 - 1, v);
- MoveTo(dim.zoomrect.right + 1, v);
- }
- LineTo(dim.titlerect.right - 2 - 1, v);
- }
- }
- }
- }
-
- /*
- * wgicon() - draw the grow icon (and scrollbar outlines, if necessary)
- * for the given window.
- *
- * Remember we want to draw in the window's port rather than the managers port.
- */
-
- wgicon(windp)
- WindowPeek windp;
- {
- GrafPtr oldport; /* the original port to restore */
- Rect windrect; /* the content Rect of the window (in local coords) */
- Rect iconrect; /* the bounds of the grow icon */
- BitMap bm; /* a temporary bitmap containing the pattern to draw */
- unsigned int block[16]; /* the 16 X 16 bit bitmap bm points to */
- Rect tmprect; /* a temporary rectangle */
-
- GetPort(&oldport);
- SetPort(&windp->port);
-
- bm.baseAddr = (QDPtr) &block[0];
- bm.rowBytes = 2;
- bm.bounds.top = 0;
- bm.bounds.left = 0;
- bm.bounds.right = 16;
- bm.bounds.bottom = 16;
-
- windrect = windp->port.portRect;
-
- if (is_smallrect(&windrect)) {
-
- /*
- * Collapsed windows have no grow icon or scrollbars,
- * so we draw nothing.
- */
-
- } else {
-
- /*
- * A Standard window.
- *
- * Draw (or erase) the Grow icon, depending on whether the window
- * is active or not.
- */
-
- iconrect.right = windrect.right + 1;
- iconrect.bottom = windrect.bottom + 1;
- iconrect.left = iconrect.right - 16;
- iconrect.top = iconrect.bottom - 16;
-
- if (windp->hilited) {
- block[0] = 0xFFFF;
- block[1] = 0x8001;
- block[2] = 0x8001;
- block[3] = 0x9FC1;
- block[4] = 0x9041;
- block[5] = 0x907D;
- block[6] = 0x9045;
- block[7] = 0x9045;
- block[8] = 0x9045;
- block[9] = 0x9FC5;
- block[10] = 0x8405;
- block[11] = 0x8405;
- block[12] = 0x8405;
- block[13] = 0x87FD;
- block[14] = 0x8001;
- block[15] = 0xFFFF;
- CopyBits(&bm, &windp->port.portBits, &bm.bounds, &iconrect,
- srcCopy, (RgnHandle) 0);
- } else {
- tmprect = iconrect;
- InsetRect(&tmprect, 1, 1);
- EraseRect(&iconrect);
- }
-
- /*
- * Finally, draw the lines enclosing the scrollbars.
- *
- * (Personally, I'd prefer the application to draw these lines
- * instead, depending on whether the window contains horizontal and
- * vertical scrollbars. This routine draws them to duplicate
- * the flawed, but standard, behavior.)
- */
-
- MoveTo(iconrect.left, windrect.top);
- LineTo(iconrect.left, windrect.bottom - 1);
- MoveTo(windrect.left, iconrect.top);
- LineTo(windrect.right - 1, iconrect.top);
- }
-
- SetPort(oldport);
- }
-
- /*
- * wfindhit() - see what part of the window the mouse hit.
- */
-
- long
- wfindhit(windp, h, v)
- WindowPeek windp;
- int h, v; /* (global) coords of the mouse-down */
- {
- long retval; /* the region ID to return */
- struct wdims dim; /* dimensions of the window */
- Point pt; /* the mouse-down point */
-
- wcalcdims(windp, (Rect *) 0, &dim);
- pt.h = h;
- pt.v = v;
-
- retval = (long) wNoHit;
-
- if (!windp->visible) {
- /* if we're invisible, nothing can be hit */
-
- } else if (PtInRect(pt, &dim.contrect)) {
- if (windp->hilited && PtInRect(pt, &dim.growrect)) {
- retval = (long) wInGrow;
- } else {
- retval = (long) wInContent;
- }
- } else if (PtInRect(pt, &dim.titlerect)) {
- retval = (long) wInDrag;
- if (windp->hilited) {
- if (windp->goAwayFlag && PtInRect(pt, &dim.closerect)) {
- retval = (long) wInGoAway;
- } else if (windp->spareFlag != 0 && PtInRect(pt, &dim.zoomrect)) {
- retval = (long) zoompart(windp);
- }
- }
- }
- return(retval);
- }
-
- /*
- * wtoggle_box() - toggle the drawn state of the given region (close or zoom).
- */
-
- wtoggle_box(windp, part)
- WindowPeek windp;
- int part; /* the region to toggle (e.g., wInGoAway) */
- {
- GrafPtr myport; /* the window manager port */
- struct wdims dim; /* dimensions of the window */
- BitMap bm; /* a temporary bitmap containing the pattern to Xor */
- unsigned int block[16]; /* the 16 X 16 bit bitmap bm points to */
- Rect xrect; /* the (inset) box to Xor into */
-
- GetPort(&myport);
-
- wcalcdims(windp, (Rect *) 0, &dim);
-
- if (part == wInZoomOut || part == wInZoomIn) {
- xrect = dim.zoomrect;
- } else {
- xrect = dim.closerect;
- }
- InsetRect(&xrect, 1, 1);
-
- bm.baseAddr = (QDPtr) &block[0];
- bm.rowBytes = 2;
- bm.bounds.top = 0;
- bm.bounds.left = 0;
- bm.bounds.right = xrect.right - xrect.left;
- bm.bounds.bottom = xrect.bottom - xrect.top;
-
- if (is_smallrect(&dim.contrect)) {
- if (part == wInZoomOut || part == wInZoomIn) {
- block[0] = 0x1800;
- block[1] = 0x5C00;
- block[2] = 0x2000;
- block[3] = 0xCE00;
- block[4] = 0xD000;
- block[5] = 0x5400;
- block[6] = 0x1000;
- } else {
- block[0] = 0x1000;
- block[1] = 0x5400;
- block[2] = 0x2800;
- block[3] = 0xC600;
- block[4] = 0x2800;
- block[5] = 0x5400;
- block[6] = 0x1000;
- }
- } else {
- if (part == wInZoomOut || part == wInZoomIn) {
- block[0] = 0x0C00;
- block[1] = 0x4D00;
- block[2] = 0x2E00;
- block[3] = 0x0400;
- block[4] = 0xE780;
- block[5] = 0xFC00;
- block[6] = 0x2A00;
- block[7] = 0x4900;
- block[8] = 0x0800;
- } else {
- block[0] = 0x0800;
- block[1] = 0x4900;
- block[2] = 0x2A00;
- block[3] = 0x0000;
- block[4] = 0xE380;
- block[5] = 0x0000;
- block[6] = 0x2A00;
- block[7] = 0x4900;
- block[8] = 0x0800;
- }
- }
- CopyBits(&bm, &myport->portBits, &bm.bounds, &xrect, srcXor, (RgnHandle) 0);
- }
-
- /*
- * woutline() - given a hypothetical content region rectangle for a window,
- * draw the outline of that window, using the passed content region.
- *
- * This routine is called when growing a window.
- */
-
- woutline(windp, contp)
- WindowPeek windp;
- Rect *contp; /* points to a hypothetical, global-coord, content Rect */
- {
- struct wdims dim; /* dimensions of the window */
- Rect tmprect;
-
- wcalcdims(windp, contp, &dim);
-
- if (is_smallrect(&dim.contrect)) {
-
- /*
- * For a collapsed window,
- * draw a frame inside the title box and another around the contents.
- * Because we're XORing, we have to avoid drawing any pixel twice.
- */
-
- FrameRect(&dim.titlerect);
- MoveTo(dim.contrect.left - 1, dim.contrect.bottom - 1);
- LineTo(dim.contrect.left - 1, dim.contrect.top - 1);
- LineTo(dim.contrect.right, dim.contrect.top - 1);
- LineTo(dim.contrect.right, dim.contrect.bottom - 1);
-
- if (dim.contrect.left < dim.titlerect.left) {
- MoveTo(dim.contrect.left - 1, dim.contrect.bottom);
- LineTo(dim.titlerect.left - 1, dim.contrect.bottom);
- MoveTo(dim.titlerect.right, dim.contrect.bottom);
- LineTo(dim.contrect.right, dim.contrect.bottom);
- }
- } else {
-
- /*
- * For a Standard window,
- * frame the whole window and title box,
- * then draw the inner edges of the scrollbars.
- */
-
- tmprect = dim.titlerect;
- tmprect.bottom = dim.contrect.bottom + 1;
- FrameRect(&tmprect);
- MoveTo(dim.titlerect.left + 1, dim.titlerect.bottom - 1);
- LineTo(dim.titlerect.right - 2, dim.titlerect.bottom - 1);
-
- MoveTo(dim.contrect.right - 15, dim.contrect.top);
- LineTo(dim.contrect.right - 15, dim.contrect.bottom - 1);
- MoveTo(dim.contrect.left, dim.contrect.bottom - 15);
- LineTo(dim.contrect.right - 1, dim.contrect.bottom - 15);
- }
- }
-
- /*
- * is_smallrect() - "the given rectangle is small"
- * I.e., if the given Rect were a window's portRect,
- * that window would be in its collapsed state.
- */
-
- int /* "it's small" */
- is_smallrect(rp)
- Rect *rp; /* pointer to the Rect of interest */
- {
- if (rp->right - rp->left <= SMALLWIDTH ||
- rp->bottom - rp->top <= SMALLHEIGHT) {
- return(TRUE);
- }
- return(FALSE);
- }
-
- /*
- * zoompart() - return the "zoom in" or "zoom out" window part hit,
- * based on the size and position of the window vs the window's Standard State.
- */
-
- int /* wInZoomIn vs wInZoomOut */
- zoompart(windp)
- WindowPeek windp;
- {
- Rect *zrp; /* the window's zoomed (Standard State) Rect */
- Rect globwport; /* the window's portRect in global coordinates */
- int delta; /* temporary difference of two measurements */
- int retval; /* the part to return */
-
- /*
- * If this isn't a zoomable window,
- * we shouldn't even get here -- return "nowhere".
- *
- * If any dimension or side of the window has moved more than SMALLCHANGE,
- * the window is in the user state -- return "zoom out".
- * Otherwise the window's zoomed out -- return "zoom in".
- */
-
- if (windp->spareFlag == 0) {
- return(wNoHit);
- }
-
- HLock(windp->dataHandle);
-
- zrp = &((WStateData *) *(windp->dataHandle))->stdState;
-
- globwport = windp->port.portRect;
- OffsetRect(&globwport,
- -windp->port.portBits.bounds.left,
- -windp->port.portBits.bounds.top);
-
- delta = globwport.left - zrp->left;
- if (delta < 0) delta = -delta;
- if (delta > SMALLCHANGE) {
- retval = wInZoomOut;
- goto known;
- }
-
- delta = globwport.top - zrp->top;
- if (delta < 0) delta = -delta;
- if (delta > SMALLCHANGE) {
- retval = wInZoomOut;
- goto known;
- }
-
- delta = globwport.right - globwport.left;
- if (delta < 0) return(wInZoomOut);
- delta -= zrp->right - zrp->left;
- if (delta < 0) delta = -delta;
- if (delta > SMALLCHANGE) {
- retval = wInZoomOut;
- goto known;
- }
-
- delta = globwport.bottom - globwport.top;
- if (delta < 0) return(wInZoomOut);
- delta -= zrp->bottom - zrp->top;
- if (delta < 0) delta = -delta;
- if (delta > SMALLCHANGE) {
- retval = wInZoomOut;
- goto known;
- }
-
- /*
- * The window hasn't changed much from the zoomed state,
- * so we're zooming in.
- */
-
- retval = wInZoomIn;
-
- known:
- HUnlock(windp->dataHandle);
-
- return(retval);
- }
-
- /*
- * wcalcdims() - calculate the interesting dimensions of the given window.
- *
- * If growrectp isn't NIL, use that (rather than the window's port) as the
- * location and size of the window.
- */
-
- wcalcdims(windp, growrectp, dimp)
- WindowPeek windp; /* the window to calculate for */
- Rect *growrectp; /* (global-coord) hypothetical Rect for the window */
- struct wdims *dimp; /* where to put the results */
- {
- GrafPtr myport; /* the current port (the window manager's) */
- int boxwidth; /* width/height of a close/zoom box */
- FontInfo finfo; /* info about the title font */
- int lheight; /* height of one text line of the title */
- int titlewidth; /* width (pixels) of the title */
- int trectwidth; /* width of the title box */
- int oldfont;
- Style oldface;
- int oldsize;
-
- GetPort(&myport);
-
- /*
- * the content rectangle is just the window's Rect, in global coordinates.
- */
-
- if (growrectp) {
- dimp->contrect = *growrectp;
- } else {
- dimp->contrect = windp->port.portRect;
- OffsetRect(&dimp->contrect,
- -windp->port.portBits.bounds.left,
- -windp->port.portBits.bounds.top);
- }
-
- if (is_smallrect(&dimp->contrect)) {
-
- /*
- * Calculate everything for the collapsed type of window:
- *
- * The growrect occupies the whole contents.
- *
- * The Title box, beneath the frame, contains
- * - The title, centered on the first line
- * - the closebox, zoombox, and active marking lines on the second line.
- */
-
- boxwidth = BOXWIDSMALL;
-
- dimp->growrect = dimp->contrect;
-
- oldfont = myport->txFont;
- oldface = myport->txFace;
- oldsize = myport->txSize;
- TextFont(TITLEFONT);
- TextFace(TITLESTYLE);
- TextSize(TITLEFSIZE);
-
- GetFontInfo(&finfo);
- HLock((Handle) windp->titleHandle);
- titlewidth = StringWidth(*(windp->titleHandle));
- HUnlock((Handle) windp->titleHandle);
-
- TextFont(oldfont);
- TextFace(oldface);
- TextSize(oldsize);
-
- lheight = finfo.ascent + finfo.descent + finfo.leading;
-
- trectwidth = 1 + BOXHMARGIN + titlewidth + BOXHMARGIN + 1;
- if (trectwidth < 50) trectwidth = 50;
-
- dimp->titlerect.top = dimp->contrect.bottom;
- dimp->titlerect.bottom = dimp->titlerect.top + lheight * 2 + 1;
-
- dimp->titlerect.left =
- (dimp->contrect.right + dimp->contrect.left) / 2 -
- trectwidth / 2;
- dimp->titlerect.right = dimp->titlerect.left + trectwidth;
-
- dimp->titleref.h = (dimp->titlerect.right + dimp->titlerect.left) / 2
- - titlewidth / 2;
- dimp->titleref.v = dimp->titlerect.top + 1 + finfo.leading + finfo.ascent;
-
- dimp->textclip = dimp->titlerect;
-
- dimp->closerect.bottom = dimp->titlerect.bottom - 2;
- dimp->closerect.left = dimp->titlerect.left + 1 + BOXHMARGIN;
- dimp->closerect.top = dimp->closerect.bottom - boxwidth;
- dimp->closerect.right = dimp->closerect.left + boxwidth;
-
- dimp->zoomrect.top = dimp->closerect.top;
- dimp->zoomrect.bottom = dimp->closerect.bottom;
- dimp->zoomrect.right = dimp->titlerect.right - 1 - BOXHMARGIN;
- dimp->zoomrect.left = dimp->zoomrect.right - boxwidth;
-
- } else {
-
- /*
- * Calculate everything for the normal type of window:
- *
- * The grow region is in the lower righthand corner of the window.
- *
- * The Title box, above the frame, contains
- * - The title, centered and possibly clipped.
- * - the closebox, zoombox, and active marking lines.
- */
-
- boxwidth = BOXWIDBIG;
-
- dimp->growrect.right = dimp->contrect.right;
- dimp->growrect.bottom = dimp->contrect.bottom;
- dimp->growrect.left = dimp->growrect.right - 15;
- dimp->growrect.top = dimp->growrect.bottom - 15;
-
- dimp->titlerect.bottom = dimp->contrect.top;
- dimp->titlerect.top = dimp->titlerect.bottom - 19;
-
- dimp->titlerect.left = dimp->contrect.left - 1;
- dimp->titlerect.right = dimp->contrect.right + 1;
-
- dimp->closerect.bottom = dimp->titlerect.bottom - 4;
- dimp->closerect.left = dimp->titlerect.left + 9;
- dimp->closerect.top = dimp->closerect.bottom - boxwidth;
- dimp->closerect.right = dimp->closerect.left + boxwidth;
-
- dimp->zoomrect.top = dimp->closerect.top;
- dimp->zoomrect.bottom = dimp->closerect.bottom;
- dimp->zoomrect.right = dimp->titlerect.right - 9;
- dimp->zoomrect.left = dimp->zoomrect.right - boxwidth;
-
- dimp->titleref.h = (dimp->titlerect.right + dimp->titlerect.left) / 2
- - windp->titleWidth / 2;
- if (dimp->titleref.h < dimp->titlerect.left + 33) {
- dimp->titleref.h = dimp->titlerect.left + 33;
- }
- dimp->titleref.v = dimp->closerect.bottom - 1;
-
- dimp->textclip = dimp->titlerect;
- dimp->textclip.left = dimp->titleref.h;
- dimp->textclip.right = dimp->textclip.left + windp->titleWidth;
- if (dimp->textclip.right > dimp->titlerect.right - 33) {
- dimp->textclip.right = dimp->titlerect.right - 33;
- }
- }
- }
-