home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-30 | 6.3 KB | 258 lines | [TEXT/CWIE] |
- // ===========================================================================
- // LAGADiscloTriangle.cp
- // ===========================================================================
- // “Apple Grayscale Appearance” compliant right-hand disclosure triangle.
- // Uses the same PPob as LStdCheckBox. A left-hand version is left as an
- // exercise for the reader :-).
- //
- // Copyright 1996 by Michael™ Hamel of ADInstruments NZ Ltd, mhamel@adi.co.nz
- //
- // You may use this source code in any application (commercial, shareware, freeware,
- // postcardware, etc), without acknowledgment, but may not remove this notice.
- //
- // You may not sell this source code in any form. This source code may be placed on
- // publicly accessible archive sites and source code disks. It may not be placed on
- // for-profit archive sites and source code disks without the permission of the author.
- //
- // This source code is distributed "as is", without any warranty. Use it at your own
- // risk.
- //
- // This class requires AGAColors.cp to be present in your project
- //
- // Version : 1.2
- //
- // Change History (most recent first, date in US form : mm/dd/yy):
- //
- // 06/30/96 ca Public release of version 1.2
- // 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
- // in order that triState_Latent state is drawn as disabled
- // 06/04/96 ca Added RegisterClass method to ease registry
- // Increased version to 1.2
- // 05/21/96 M™H Initial version set to 1.1 to be put with other AGA classes
- //
- // To Do:
- //
-
- #include "LAGADiscloTriangle.h"
- #include "AGAColors.h"
- #include <UTextTraits.h>
- #include <UDrawingState.h>
- #include <UDrawingUtils.h>
- #include <LStream.h>
-
- enum {
- kTextStart = 14
- };
-
- // begin <06/04/96 ca>
- void LAGADiscloTriangle::RegisterClass ()
-
- {
- URegistrar::RegisterClass(LAGADiscloTriangle::class_ID, (ClassCreatorFunc)LAGADiscloTriangle::CreateAGADiscloTriangleStream);
- }
- // end <06/04/96 ca>
-
- LAGADiscloTriangle*
- LAGADiscloTriangle::CreateAGADiscloTriangleStream( LStream *inStream)
- {
- return (new LAGADiscloTriangle(inStream));
- }
-
- LAGADiscloTriangle::LAGADiscloTriangle()
- :LControl()
- {
- }
-
- LAGADiscloTriangle::LAGADiscloTriangle(const SPaneInfo &inPaneInfo,
- MessageT inValueMessage,
- Int32 inValue,
- ResIDT traitsID,
- Str255 title)
- :LControl(inPaneInfo,inValueMessage,inValue,0,1)
- {
- mTitle = title;
- mTextTraitsID = traitsID;
- }
-
- LAGADiscloTriangle::LAGADiscloTriangle( LStream *inStream)
- : LControl(inStream)
- {
- Int16 controlKind;
- Int32 macRefCon;
-
- inStream->ReadData(&controlKind, sizeof(Int16)); // ignored
- inStream->ReadData(&mTextTraitsID, sizeof(ResIDT));
- inStream->ReadPString(mTitle);
- inStream->ReadData(&macRefCon, sizeof(Int32)); // ignored
- }
-
- LAGADiscloTriangle::~LAGADiscloTriangle()
- {
- }
-
- void
- LAGADiscloTriangle::SetValue(Int32 inValue)
- {
- Int32 oldValue;
-
- oldValue = mValue;
- LControl::SetValue(inValue);
- if (oldValue != mValue) Draw(nil);
- }
-
- void
- LAGADiscloTriangle::DrawText ( )
- {
- Rect frame;
- FontInfo info;
- short space,
- alignment;
- RGBColor textColor;
-
- if (CalcLocalFrameRect(frame)) {
- frame.left += kTextStart;
- alignment = UTextTraits::SetPortTextTraits(mTextTraitsID);
-
- // Get the font centered top/bottom
- ::GetFontInfo(&info);
- space = (frame.bottom - frame.top - (info.ascent + info.descent))/2;
- frame.top += space;
- frame.bottom -= space;
-
- if (mInColor) {
- ::GetForeColor(&textColor);
-
- ApplyForeAndBackColors();
- if (mEnabled == triState_On) // <06/27/96 ca>
- ::RGBForeColor(&textColor);
- else
- ::RGBForeColor(&gAGAColorArray[7]);
- }
- UTextDrawing::DrawWithJustification((Ptr)&mTitle[1], mTitle[0], frame, alignment);
- }
- }
-
- void
- LAGADiscloTriangle::DrawTriangle(TriangleState stage, Boolean hilite)
- {
- enum {
- kArrowSpace = 13,
- kArrowHeight = 10
- };
-
- Rect cSpace;
- PolyHandle aPoly;
- short extra;
-
- CalcLocalFrameRect(cSpace);
- cSpace.right = cSpace.left + kArrowSpace;
- extra = (cSpace.bottom - cSpace.top - kArrowHeight)/2;
- aPoly = ::OpenPoly();
- switch (stage) {
- case kDown : // Down-arrow
- ::MoveTo(cSpace.left,cSpace.top+extra+3);
- ::Line(5,5);
- ::Line(5,-5);
- ::Line(-10,0);
- break;
-
- case kIntermediate : // Intermediate-arrow
- ::MoveTo(cSpace.left,cSpace.top+extra+7);
- ::Line(7,0);
- ::Line(0,-7);
- ::Line(-7,7);
- break;
-
- case kRight : // Right-arrow
- ::MoveTo(cSpace.left+3,cSpace.top+extra);
- ::Line(0,10);
- ::Line(5,-5);
- ::Line(-5,-5);
- break;
- }
- ::ClosePoly();
-
- if (mInColor) ApplyForeAndBackColors();
- EraseRect(&cSpace);
- if (mEnabled != triState_On) { // <06/27/96 ca>
- if (!mInColor)
- ::FillPoly(aPoly,&qd.gray);
- else {
- ::RGBForeColor(&gAGAColorArray[5]);
- ::PaintPoly(aPoly);
- }
- }
- else {
- if (hilite) {
- if (mInColor) ::RGBForeColor(&gAGAColorArray[A4]);
- else ::ForeColor(blackColor);
- ::PaintPoly(aPoly);
- }
- else if (mInColor) {
- // Interior colors
- ::RGBForeColor(&gAGAColorArray[A2]);
- ::PaintPoly(aPoly);
- ::RGBForeColor(&gAGAColorArray[A1]);
- if (stage==kDown) {
- ::MoveTo(cSpace.left+2,cSpace.top+extra+4);
- ::Line(5,0);
- ::Move(0,1);
- ::RGBForeColor(&gAGAColorArray[A3]);
- ::Line(-2,2);
- ::Move(4,-4);
- }
- else {
- ::MoveTo(cSpace.left+4,cSpace.top+extra+2);
- ::Line(0,5);
- ::Move(1,0);
- ::RGBForeColor(&gAGAColorArray[A3]);
- ::Line(2,-2);
- }
- // Shadow
- ::RGBForeColor(&gAGAColorArray[7]);
- ::Move(1,1);
- ::Line(-4,4);
- ::RGBForeColor(&gAGAColorArray[4]);
- ::Move(0,1);
- ::Line(5,-5);
- }
- ::ForeColor(blackColor);
- ::FramePoly(aPoly);
- }
- ::KillPoly(aPoly);
- }
-
- void
- LAGADiscloTriangle::DrawSelf()
- {
- StColorPenState savedState;
-
- mInColor = PaneInColor(this);
- DrawText();
- if (mValue!=0) DrawTriangle(kDown,FALSE);
- else DrawTriangle(kRight,FALSE);
- }
-
- void
- LAGADiscloTriangle::HotSpotAction(short inHotSpot,
- Boolean inCurrInside,
- Boolean inPrevInside)
- {
- if (inCurrInside != inPrevInside) {
- StColorPenState savedState;
- FocusDraw();
- if (GetValue()!=0) DrawTriangle(kDown,inCurrInside);
- else DrawTriangle(kRight,inCurrInside);
- }
- }
-
- void
- LAGADiscloTriangle::HotSpotResult(short inHotSpot)
- // Animate through intermediate step
- {
- long t = ::TickCount()+3;
- DrawTriangle(kIntermediate,TRUE);
- while (::TickCount()<t) {} ;
- SetValue(1-GetValue());
- }
-