home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: TLineObj.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* See the files "=How to write your app" and "=Using TreeObj.c" for information
- ** on this function. */
-
- /* This file implements the messages for the round-rect object. Many of the messages
- ** can be handled by the rect object, as they deal with a rect structure. Only
- ** a few of them are round-rect-specific. */
-
- /* It would seem that you would want a custom hit-test message handler here, but
- ** the rect object first checks to see if the hit is within the bounding box of
- ** the object, and if so, it then calls the object to return the region. This
- ** allows the rect object to generically handle hit-testing. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- static OSErr LineLayerProc(LayerObj theLayer, short message);
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment DrawObjects
- long TLineObj(TreeObjHndl hndl, short message, long data)
- {
- Rect rct, drct, grabber;
- RgnHandle rgn, accumRgn;
- short orn, h, w, i;
- LayerObj lineLayer;
- Rect *rptr;
- Boolean change;
- ClickInfo *click;
- RGBColor rgb, oldRgb;
- #if VH_VERSION
- char *cptr;
- #endif
-
- switch (message) {
- case INITMESSAGE:
- case FREEMESSAGE:
- case COPYMESSAGE:
- case UNDOMESSAGE:
- case CONVERTMESSAGE:
- case FREADMESSAGE:
- case FWRITEMESSAGE:
- case HREADMESSAGE:
- case HWRITEMESSAGE:
- case HITTESTMESSAGE:
- case SETOBJRECTMESSAGE:
- case SECTOBJRECTMESSAGE:
- case CLICKMESSAGE:
- case KEYMESSAGE:
- case SETSELECTMESSAGE:
- case GETSELECTMESSAGE:
- case COMPAREMESSAGE:
- return(TRectObj(hndl, message, data));
- break;
-
- case GETBBOXMESSAGE:
- TRectObj(hndl, message, data);
- h = (mDerefCommon(hndl)->penHeight / 2) + 1;
- w = (mDerefCommon(hndl)->penWidth / 2) + 1;
- rptr = (Rect *)data;
- rptr->left -= w;
- rptr->right += w;
- rptr->top -= h;
- rptr->bottom += h;
- break;
-
- case GETOBJRECTMESSAGE:
- TRectObj(hndl, message, data);
- rptr = (Rect *)data;
- if (rptr->left == rptr->right ) rptr->right++;
- if (rptr->top == rptr->bottom) rptr->bottom++;
- break;
-
- case GETRGNMESSAGE:
- rgn = NewRgn();
- accumRgn = (RgnHandle)data;
- if (accumRgn)
- if (GetHandleSize((Handle)accumRgn) > 10000)
- return((long)rgn);
- NewLayer(&lineLayer, nil, LineLayerProc, nil, 0, (long)hndl);
- if (lineLayer) {
- SetLayerWorld(lineLayer);
- TLineObj(hndl, DRAWMESSAGE, DRAWMASK);
- if (gQDVersion)
- BitMapToRegion(rgn, (BitMapPtr)(*((CGrafPtr)(*lineLayer)->layerPort)->portPixMap));
- else
- BitMapToRegion(rgn, &(*lineLayer)->layerPort->portBits);
- ResetLayerWorld(lineLayer);
- DisposeLayer(lineLayer);
- if (!data)
- InsetRgn(rgn, -1, -1);
- }
- if (accumRgn)
- UnionRgn(rgn, accumRgn, accumRgn);
- return((long)rgn);
- break;
-
- case DRAWMESSAGE:
- rct = mDerefLine(hndl)->rect;
- orn = mDerefLine(hndl)->flip;
- drct = rct;
- switch (orn) {
- case 1:
- drct.top = rct.bottom;
- drct.bottom = rct.top;
- break;
- case 2:
- drct.left = rct.right;
- drct.right = rct.left;
- break;
- case 3:
- drct.top = rct.bottom;
- drct.bottom = rct.top;
- drct.left = rct.right;
- drct.right = rct.left;
- break;
- }
- h = mDerefCommon(hndl)->penHeight;
- w = mDerefCommon(hndl)->penWidth;
- PenSize(w, h);
- switch (data) {
- case DRAWOBJ:
- if (gQDVersion) {
- GetForeColor(&oldRgb);
- rgb = mDerefLine(hndl)->borderColor;
- RGBForeColor(&rgb);
- }
- MoveTo(drct.left - (w / 2), drct.top - (h / 2));
- LineTo(drct.right - (w / 2), drct.bottom - (h / 2));
- if (gQDVersion)
- RGBForeColor(&oldRgb);
- break;
- case ERASEOBJ:
- break;
- case DRAWSELECT:
- if (mDerefCommon(hndl)->selected) {
- for (i = 0; i < 2; ++i) {
- grabber.top = i ? drct.top : drct.bottom;
- grabber.left = i ? drct.left : drct.right;
- grabber.bottom = (grabber.top -= 3) + 6;
- grabber.right = (grabber.left -= 3) + 6;
- InvertRect(&grabber);
- }
- }
- break;
- case DRAWGHOST:
- PenMode(patXor);
- TLineObj(hndl, DRAWMESSAGE, DRAWOBJ);
- break;
- case DRAWMASK:
- ForeColor(blackColor);
- MoveTo(drct.left - (w / 2), drct.top - (h / 2));
- LineTo(drct.right - (w / 2), drct.bottom - (h / 2));
- break;
- }
- PenNormal();
- break;
-
- case PRINTMESSAGE:
- TLineObj(hndl, DRAWMESSAGE, DRAWOBJ);
- break;
-
- #if VH_VERSION
- case VHMESSAGE:
- cptr = ((VHFormatDataPtr)data)->data;
- ccatchr(cptr, 13, 2);
- ccat (cptr, "$10: TRectObj:");
- ccatchr(cptr, 13, 1);
- ccat (cptr, " $00: selected = ");
- ccatdec(cptr, mDerefLine(hndl)->selected);
- ccatchr(cptr, 13, 1);
- rct = mDerefLine(hndl)->rect;
- ccat (cptr, " $02: rect = ($");
- ccatpadhex(cptr, 0, 4, 4, rct.top);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, rct.left);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, rct.bottom);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, rct.right);
- ccat (cptr, ")");
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $0A: penHeight = ");
- ccatdec (cptr, mDerefLine(hndl)->penHeight);
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $0A: penWidth = ");
- ccatdec (cptr, mDerefLine(hndl)->penWidth);
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $0E: borderColor = ($");
- ccatpadhex(cptr, 0, 4, 4, mDerefLine(hndl)->borderColor.red);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, mDerefLine(hndl)->borderColor.green);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, mDerefLine(hndl)->borderColor.blue);
- ccat (cptr, ")");
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $14: content = ($");
- ccatdec (cptr, mDerefLine(hndl)->content);
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $16: contentColor = ($");
- ccatpadhex(cptr, 0, 4, 4, mDerefLine(hndl)->contentColor.red);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, mDerefLine(hndl)->contentColor.green);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, mDerefLine(hndl)->contentColor.blue);
- ccat (cptr, ")");
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $1A: flip = ($");
- ccatdec (cptr, mDerefLine(hndl)->flip);
- return(true);
- break;
- #endif
-
- case SIZEMESSAGE:
- change = TRectObj(hndl, message, data);
- if (change) {
- click = (ClickInfo *)data;
- mDerefLine(hndl)->flip = click->newFlip;
- }
- return(change);
- break;
-
- default:
- break;
- }
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static OSErr LineLayerProc(LayerObj theLayer, short message)
- {
- OSErr err;
- TreeObjHndl line;
- Rect rct;
- CGrafPtr keepPort;
- GDHandle keepGDevice;
- GWorldPtr layerWorld;
-
- switch (message) {
- case kLayerInit:
- err = noErr;
- if (theLayer) {
- if (!(*theLayer)->layerPort) {
- line = (TreeObjHndl)(*theLayer)->layerData;
- TLineObj(line, GETBBOXMESSAGE, (long)&rct);
- GetGWorld(&keepPort, &keepGDevice); /* Keep the GWorld. */
- err = NewGWorld(&layerWorld, 1, &rct, nil, nil, 0);
- if (err == noErr) {
- (*theLayer)->layerOwnsPort = true;
- SetPort((*theLayer)->layerPort = (GrafPtr)layerWorld);
- SetOrigin(rct.left, rct.top);
- EraseRect(&rct);
- }
- SetGWorld(keepPort, keepGDevice); /* Restore the kept GWorld. */
- }
- }
- else err = paramErr;
- break;
-
- default:
- err = DefaultLayerProc(theLayer, message);
- /* Default behavior for everything else. */
- break;
- }
-
- return(err);
- }
-
-
-
-