home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-26 | 12.8 KB | 441 lines | [TEXT/CWIE] |
- // Copyright © 1995 Apple Computer, Inc. All rights reserved.
- // Release Version: $ 1.0 d11 $
-
- //=======================================================================
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- // ----- Framework Layer -----
- #ifndef FWUTIL_H
- #include "FWUtil.h" // FW_CFacetContext, FW_Beep()
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h" // FW_CViewContext
- #endif
-
- #ifndef FWPRHDLR_H
- #include "FWPrHdlr.h" // FW_CPrintHandler
- #endif
-
- // ----- OS Layer -----
- #ifndef FWMENU_H
- #include "FWMenu.h" // FW_CMenuBar, etc.
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h" // FW_CMenuEvent, FW_CMouseEvent
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h" // FW_CAlert
- #endif
-
- #ifndef FWEVEDEF_H
- #include "FWEveDef.h" // FW_BACKSPACE, etc.
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h" // FW_CSharedLibraryResourceFile
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h" // FW_NewODShape
- #endif
-
- #ifndef SLMIXCOS_H
- #include "SLMixOS.h" // FW_Beep
- #endif
-
- // ----- Graphic Includes -----
- #ifndef FWRECT_H
- #include <FWRect.h> // FW_CRect
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h" // FW_CRectShape
- #endif
-
- #ifndef FWPOLY_H
- #include "FWPoly.h" // FW_PPolygon
- #endif
-
- #ifndef FWPOLYSH_H
- #include "FWPolySh.h" // FW_CPolygonShape
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h" // FW_COvalShape
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h" // FW_PPicture, FW_CPictureShape
- #endif
-
- #ifndef FWTXTSHP_H
- #include "FWTxtShp.h" // FW_CTextShape
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h" // FW_CLineShape
- #endif
-
- #ifndef FWRGNSHP_H
- #include "FWRgnShp.h" // FW_CRegionShape
- #endif
-
- //========================================================================================
- #ifdef FW_BUILD_MAC
- #pragma segment GraphicsBfr
- #endif
-
- //========================================================================================
- FW_DEFINE_AUTO(CGraphicsBfrFrame)
-
- //========================================================================================
- CGraphicsBfrFrame::CGraphicsBfrFrame(Environment* ev, ODFrame* odFrame,
- FW_CPresentation* presentation, CGraphicsBfrPart* part)
- : FW_CFrame(ev, odFrame, presentation, part),
- fLargePictureShape(NULL),
- fLineShape(NULL),
- fRegionShape(NULL),
- fPolygonShape(NULL),
- fBitmap(1, 1, 0),
- fBitmapShape(NULL),
- fDisplayChanged(TRUE)
- {
- fLargePictureShape = MyCreatePictureShape(ev);
- fLineShape = MyCreateLineShape(ev);
- fRegionShape = MyCreateRegionShape(ev);
- fPolygonShape = MyCreatePolygonShape(ev);
- this->MyUpdateBitmap(ev);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- CGraphicsBfrFrame::~CGraphicsBfrFrame()
- {
- FW_START_DESTRUCTOR
- delete fLargePictureShape;
- delete fLineShape;
- delete fRegionShape;
- delete fPolygonShape;
- delete fBitmapShape;
- }
-
- //------------------------------------------------------------------------------
- FW_CPictureShape*
- CGraphicsBfrFrame::MyCreatePictureShape(Environment* ev)
- {
- FW_CSharedLibraryResourceFile resFile(ev); // resource from our shared library
-
- // draw large picture - use natural picture size
- const short kMacPictID = 2001;
- const short kCatPictID = 2002;
- const short kOPFIconPictID = 2003;
- FW_CPicture picture(resFile, kMacPictID);
- picture.GetPictBounds(fLargePictRect);
- return FW_NEW(FW_CPictureShape, (picture, fLargePictRect) );
- }
-
- //------------------------------------------------------------------------------
- FW_CLineShape*
- CGraphicsBfrFrame::MyCreateLineShape(Environment* ev)
- {
- // derived from FW_CAutoDestructObject
- FW_CLineShape* shp = FW_NEW(FW_CLineShape,
- (FW_CPoint(FW_IntToFixed(200), FW_IntToFixed(70)),
- FW_CPoint(FW_IntToFixed(300), FW_IntToFixed(70)) ) );
- shp->GetStyle().SetPenSize(FW_IntToFixed(5));
- shp->GetInk().SetForeColor(FW_kRGBRed);
- return shp;
- }
-
- //------------------------------------------------------------------------------
- FW_CRegionShape*
- CGraphicsBfrFrame::MyCreateRegionShape(Environment* ev)
- {
- FW_CRegionShape* shp = NULL;
- #ifdef FW_BUILD_MAC
- // make an arrow QuickDraw region
- RgnHandle rgnHdl = NewRgn();
- OpenRgn();
- MoveTo(00,10); // start
- LineTo(40,10); // right
- LineTo(40,00); // up
- LineTo(60,20); // to point
- LineTo(40,40); // from point
- LineTo(40,30); // up
- LineTo(00,30); // left
- LineTo(00,10); // up
- CloseRgn(rgnHdl);
- // make OpenDoc shape
- ODShape* odArrowShape = FW_NewODShape(ev, rgnHdl);
- // make ODF shape
- shp = FW_NEW(FW_CRegionShape, (odArrowShape, FW_kFill) );
- shp->MoveShape(FW_IntToFixed(40), FW_IntToFixed(150));
- shp->GetInk().SetForeColor(FW_kRGBRed);
- #endif
- return shp;
- }
-
- //------------------------------------------------------------------------------
- FW_CPolygonShape*
- CGraphicsBfrFrame::MyCreatePolygonShape(Environment* ev)
- {
- FW_CPoint* points = new FW_CPoint[8];
- points[0] = FW_CPoint(FW_IntToFixed(230), FW_IntToFixed(330));
- points[1] = FW_CPoint(FW_IntToFixed(270), FW_IntToFixed(330));
- points[2] = FW_CPoint(FW_IntToFixed(270), FW_IntToFixed(320));
- points[3] = FW_CPoint(FW_IntToFixed(290), FW_IntToFixed(340));
- points[4] = FW_CPoint(FW_IntToFixed(270), FW_IntToFixed(360));
- points[5] = FW_CPoint(FW_IntToFixed(270), FW_IntToFixed(350));
- points[6] = FW_CPoint(FW_IntToFixed(230), FW_IntToFixed(350));
- points[7] = FW_CPoint(FW_IntToFixed(230), FW_IntToFixed(330));
- FW_CPolygon poly(8, points);
- delete [] points;
- FW_Boolean kAutoCloseFrame = true;
- FW_CPolygonShape* shape = FW_NEW(FW_CPolygonShape, (poly, FW_kFill, kAutoCloseFrame));
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- ODCanvas* canvas = odFacet->GetCanvas(ev);
- FW_Boolean dynamicCanvas = canvas->IsDynamic(ev);
- FW_CViewContext vContext(ev, this, odFacet, invalidShape);
- if (dynamicCanvas) { // not printing
- this->MyDrawToBitmap(ev, invalidShape);
- fBitmapShape->Render(vContext);
- }
- else
- this->MyDrawAllStuff(ev, vContext); // for printing
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawBackground(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CRect box = this->GetBounds(ev);
- FW_CRectShape::RenderRect(gc, box, FW_kFill, FW_kRGBLightGray);
- }
-
- //----------------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawAllStuff(Environment* ev, FW_CGraphicContext& gc)
- {
- this->MyDrawBackground(ev, gc);
- this->MyDrawPictures(ev, gc);
- this->MyDrawShapes(ev, gc);
- this->MyDrawLine(ev, gc);
- this->MyDrawText(ev, gc);
- this->MyDrawPolygon(ev, gc);
- }
-
- //----------------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawToBitmap(Environment *ev, ODShape* invalidShape)
- {
- if (fDisplayChanged) {
- FW_CBitmapContext context(ev, fBitmap);
- context.SetClip(invalidShape);
- this->MyDrawAllStuff(ev, context);
- fDisplayChanged = FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::FrameShapeChanged(Environment* ev) // override
- {
- FW_CFrame::FrameShapeChanged(ev);
- fDisplayChanged = TRUE;
- this->MyUpdateBitmap(ev);
- }
-
- //----------------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyUpdateBitmap(Environment* ev)
- {
- fFrameRect = this->GetBounds(ev); // Get new frame rect
- const short kPixelSize = 0;
- const FW_Boolean kScaleBitmap = true;
- fBitmap.ChangeBitmap( FW_FixedToInt(fFrameRect.Width()),
- FW_FixedToInt(fFrameRect.Height()),
- kPixelSize,
- kScaleBitmap);
- if (fBitmapShape)
- delete fBitmapShape;
- fBitmapShape = FW_NEW(FW_CBitmapShape, (fBitmap, fFrameRect));
- FW_CAcquiredODShape invalidShape = ::FW_NewODShape(ev, fFrameRect);
- this->MyDrawToBitmap(ev, invalidShape);
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawShapes(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CRect boxRect(FW_IntToFixed(25), FW_IntToFixed (25), FW_IntToFixed(100), FW_IntToFixed(100));
-
- // draw filled black box
- FW_CRectShape boxShape(boxRect, FW_kFill);
- boxShape.Render(gc);
-
- // draw filled green box
- boxShape.MoveShape(FW_IntToFixed(25), FW_IntToFixed(25));
- boxShape.GetInk().SetForeColor(FW_kRGBGreen);
- boxShape.Render(gc);
-
- // draw framed black box
- boxRect.Offset(FW_IntToFixed(50), FW_IntToFixed(50));
- FW_CRectShape::RenderRect(gc, boxRect, FW_kFrame);
-
- // draw oval inscribed in box; special pattern, transfer mode
- boxRect.Offset(FW_IntToFixed(25), FW_IntToFixed(25));
- const FW_CColor kForeColor(FW_kRGBRed);
- const FW_CColor kBackColor(FW_kRGBBlue);
- FW_CInk ink(kForeColor, kBackColor, FW_kXOr);
- const FW_Fixed kPenSize = FW_IntToFixed(4);
- const FW_CPattern kPattern = FW_kDiagCrossPat;
- FW_CStyle style(kPenSize, kPattern);
- FW_COvalShape::RenderOval(gc, boxRect, FW_kFill, ink, style);
-
- // draw oval frame
- FW_COvalShape::RenderOval(gc, boxRect, FW_kFrame);
-
- // draw arrow
- fRegionShape->Render(gc);
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawText(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CString32 string("ODF");
- FW_CPoint position( FW_IntToFixed(200), FW_IntToFixed(50) );
-
- // draw 12 point ODF
- FW_CTextShape stringShape(string, position.x, position.y);
- stringShape.Render(gc);
-
- // draw fancy ODF
- const FW_Fixed kFontSize = FW_IntToFixed(48);
- FW_CTextShape::RenderText(gc,
- string,
- position,
- FW_CFont(FW_kPalatino, FW_kItalic, kFontSize),
- FW_kTextAlignLeft | FW_kTextAlignBottom,
- FW_CInk(FW_kRGBBlue, FW_kRGBWhite, FW_kOr));
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawPictures(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CSharedLibraryResourceFile resFile(ev); // resource from our shared library
-
- fLargePictureShape->Render(gc);
-
- // draw DevU logo - I choose size
- const short kDevUPictID = 2000;
- const short kCatPictID = 2002;
- const short kOPFIconPictID = 2003;
- FW_CPictureShape::RenderPicture(gc,
- FW_CPicture(resFile, kDevUPictID),
- FW_CRect(FW_IntToFixed(25), FW_IntToFixed(175), FW_IntToFixed(125), FW_IntToFixed(275))
- );
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawLine(Environment* ev, FW_CGraphicContext& gc)
- {
- fLineShape->Render(gc);
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyDrawPolygon(Environment* ev, FW_CGraphicContext& gc)
- {
- fPolygonShape->Render(gc);
- }
-
- //----------------------------------------------------------------------------------------
- FW_Boolean
- CGraphicsBfrFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean eventHandled = FALSE;
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- this->GetContentView(ev)->FrameToViewContent(ev, where);
- ODFacet* theFacet = theMouseEvent.GetFacet(ev);
- FW_CViewContext context(ev, this, theFacet, NULL); // invalidShape = NULL
- const FW_Fixed kTolerance = FW_IntToFixed(2);
- if ( fLineShape->HitTest(context, where, kTolerance) ) { // new argument for d9
- FW_Beep();
- eventHandled = TRUE;
- this->MyInvalidateLine(ev);
- fLineShape->MoveShape(FW_IntToFixed(0), FW_IntToFixed(20)); // move down
- this->MyInvalidateLine(ev);
- fDisplayChanged = true;
- } // if
-
- if ( fRegionShape->HitTest(context, where, kTolerance) ) {
- FW_Beep();
- eventHandled = true;
- this->Invalidate(ev, fRegionShape->GetODShape() ); // won't blink when buffered
- } // if
-
- if ( fPolygonShape->HitTest(context, where, kTolerance) ) {
- FW_Beep();
- eventHandled = true;
- } // if
-
- return eventHandled;
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::MyInvalidateLine(Environment* ev)
- {
- FW_CPoint start;
- FW_CPoint end;
- fLineShape->GetGeometry(start, end);
- FW_CRect lineRect(start.x, start.y, end.x, end.y);
- lineRect.Sort();
- FW_Fixed halfPen = fLineShape->GetPenSize() / FW_IntToFixed(2);
- lineRect.Inset(-halfPen, -halfPen); // expand for pen size
- this->Invalidate(ev, lineRect); // force update
- }
-
- //------------------------------------------------------------------------------
- FW_CPrintHandler*
- CGraphicsBfrFrame::NewPrintHandler(Environment* ev)
- {
- FW_CPart* part = GetPart(ev);
- return new FW_CPrintHandler(part, this);
- }
-
- //------------------------------------------------------------------------------
- FW_Boolean
- CGraphicsBfrFrame::IsCurrentlyPrintable(Environment* ev) const
- {
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsBfrFrame::GetPrintContentExtent(Environment *ev, FW_CPoint& extent) const
- {
- extent = fLargePictRect.Size();
- FW_ASSERT(extent.x != FW_kFixed0);
- FW_ASSERT(extent.y != FW_kFixed0);
- }
-
-