home *** CD-ROM | disk | FTP | other *** search
- /* ----------------------------------------------------------------------
-
- PICTButton CDEF
- version 1.3
-
- Written by: Paul Celestin
-
- Copyright © 1993-1995 Celestin Company, Inc.
-
- This CDEF displays a picture whose resource ID is derived from
- the min, max, and value fields of the CNTL. For a multiple-state
- button, set min to ID of the the first PICT and max to the ID of
- the last PICT. Also set value to the ID of the first PICT.
-
- 930822 - 1.0.0 initial release
- 930829 - 1.0.1 added variations 1 and 2
- 930915 - 1.0.2 fixed the new variations
- 930922 - 1.0.3 fixed a problem with black and white PICTs showing
- up, or so I thought
- 931012 - 1.0.4 changed color of text in variation 2 to blue
- 931012 - 1.0.5 really fixed problem with black and white PICTs
- showing up properly
- 940319 - 1.0.6 removed unnecessary erasing code
- 940703 - 1.0.7 now works over multiple monitors of different bit
- depths
- 950804 - 1.1.0 finally converted this thing over to CodeWarrior!
- 950809 - 1.2.0 fixed bug in hasColor that caused computer to crash
- if button was partially or completely offscreen
- 951215 - 1.3.0 updated to CW7
-
- ---------------------------------------------------------------------- */
-
- #define kPlain 0
- #define kInverted 1
- #define kInvertedPICT 100
- #define kOffset 200
- #define kIsColorPort 0xC000 // If these bits are set, its a CGrafPort.
-
-
- /* ----------------------------------------------------------------------
- prototypes
- ---------------------------------------------------------------------- */
- pascal long main(short variation, ControlHandle theControl, short message, long param);
- int hasColor(Rect);
- void drawIt(ControlHandle control,short variation);
- long testIt(ControlHandle control, Point myPoint);
-
-
- /* ----------------------------------------------------------------------
- main
- ---------------------------------------------------------------------- */
- pascal long main(short variation, ControlHandle theControl, short message, long param)
- {
- long returnValue = 0L;
- char state = HGetState((Handle)theControl);
-
- switch(message)
- {
- case drawCntl:
- drawIt(theControl,variation);
- case testCntl:
- returnValue = testIt(theControl, *(Point *) ¶m);
- case calcCRgns:
- break;
- case initCntl:
- break;
- case dispCntl:
- break;
- case posCntl:
- break;
- case thumbCntl:
- break;
- case dragCntl:
- break;
- case autoTrack:
- break;
- case calcCntlRgn:
- break;
- case calcThumbRgn:
- break;
- default:
- break;
- }
-
- HSetState((Handle)theControl,state);
-
- return(returnValue); /* tell them what happened */
- }
-
-
- /* ----------------------------------------------------------------------
- hasColor
- ---------------------------------------------------------------------- */
- int hasColor(Rect r)
-
- {
- SysEnvRec myComputer;
- GDHandle curDev;
- PixMapHandle myPixMap;
-
- SysEnvirons(2,&myComputer);
- if (myComputer.hasColorQD)
- {
- LocalToGlobal((Point*) &r);
- LocalToGlobal(1 + (Point*) &r);
- curDev = GetMaxDevice(&r);
- if (curDev != nil)
- {
- myPixMap = (**curDev).gdPMap;
- if ((**myPixMap).pixelSize > 1)
- return(1);
- else
- return(0);
- }
- }
- return(0);
- }
-
-
- /* ----------------------------------------------------------------------
- drawIt - here is where we actually draw the control
- ---------------------------------------------------------------------- */
- void drawIt(ControlHandle control, short variation)
-
- {
- short invert = 0, useBW = 0;
- int savedFont, savedSize, savedMode;
- Rect myRect;
- GrafPtr thePort;
- PicHandle myPicture;
- PenState oldPenState;
- Str255 myTitle;
- Pattern myGray;
-
- GetPort(&thePort); /* save off the current port */
-
- if (!(*control)->contrlVis) /* if not visible, do nothing */
- return;
-
- myRect = (*control)->contrlRect;
-
- if (!hasColor(myRect)) /* use the B&W PICTs */
- useBW = kOffset;
-
- if ((*control)->contrlHilite == inButton)
- {
- invert = kInvertedPICT; /* invert while tracking */
- SetControlReference(control, kInverted);
- }
- else
- {
- if ( (GetControlReference(control) == kInverted) && (!Button()) )
- {
-