home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-22 | 11.2 KB | 383 lines | [TEXT/CWIE] |
- // Release Version: $ ODF 2 $
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- //=======================================================================
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- // ----- Framework Layer -----
- #ifndef FWCONTXT_H
- #include "FWContxt.h" // FW_CViewContext
- #endif
-
- #ifndef FWPRHDLR_H
- #include "FWPrHdlr.h" // FW_CPrintHandler
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h" // FW_CMenuEvent, FW_CMouseEvent
- #endif
-
- // ----- OS Layer -----
- #ifndef FWMENU_H
- #include "FWMenu.h" // FW_CMenuBar, etc.
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h" // FW_PSharedLibraryResourceFile
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h" // FW_NewODShape
- #endif
-
- #ifndef SLMIXOS_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_CPicture, 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 Graphics
- #endif
-
- //========================================================================================
- FW_DEFINE_AUTO(CGraphicsFrame)
-
- //========================================================================================
- CGraphicsFrame::CGraphicsFrame(Environment* ev, ODFrame* odFrame,
- FW_CPresentation* presentation, CGraphicsPart* part)
- : FW_CFrame(ev, odFrame, presentation, part),
- fLargePictureShape(NULL),
- fLineShape(NULL),
- fRegionShape(NULL),
- fPolygonShape(NULL)
- {
- fLargePictureShape = MyCreatePictureShape(ev);
- fLineShape = MyCreateLineShape(ev);
- fRegionShape = MyCreateRegionShape(ev);
- fPolygonShape = MyCreatePolygonShape(ev);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- CGraphicsFrame::~CGraphicsFrame()
- {
- FW_START_DESTRUCTOR
- delete fLargePictureShape;
- delete fLineShape;
- delete fRegionShape;
- delete fPolygonShape;
- }
-
- //------------------------------------------------------------------------------
- FW_CPictureShape*
- CGraphicsFrame::MyCreatePictureShape(Environment* ev)
- {
- FW_UNUSED(ev);
- FW_PSharedLibraryResourceFile resFile(ev); // resource from our shared library
-
- // draw large picture - use natural picture size
- const short kMacPictID = 2001;
- const short kCatPictID = 2002;
- const short kODFIconPictID = 2003;
- FW_CPicture picture(resFile, kMacPictID);
- picture.GetPictBounds(fLargePictRect);
- return FW_NEW(FW_CPictureShape, (picture, fLargePictRect) );
- }
-
- //------------------------------------------------------------------------------
- FW_CLineShape*
- CGraphicsFrame::MyCreateLineShape(Environment* ev)
- {
- FW_UNUSED(ev);
- 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*
- CGraphicsFrame::MyCreateRegionShape(Environment* ev)
- {
- const FW_CPoint kSize( FW_IntToFixed(25), FW_IntToFixed(25) );
- const FW_CPoint kOffset( FW_IntToFixed(32), FW_IntToFixed(0) );
- const FW_Fixed kInset = FW_IntToFixed(4);
-
- FW_CRect fwR1(FW_kZeroPoint, kSize);
- FW_CAcquiredODShape odR1 = FW_NewODShape (ev, fwR1);
-
- FW_CRect fwR2(fwR1);
- fwR2.Offset(kOffset);
- fwR2.Inset(kInset);
- ODShape* odR2 = FW_NewODShape (ev, fwR2);
-
- odR2->Union(ev, odR1);
- FW_CRegionShape* shp = FW_NEW(FW_CRegionShape, (odR2, FW_kFill) );
- shp->GetInk().SetForeColor(FW_kRGBPurple);
- shp->MoveShape(FW_IntToFixed(40), FW_IntToFixed(300)); // x, y
- return shp;
- }
-
- //------------------------------------------------------------------------------
- FW_CPolygonShape*
- CGraphicsFrame::MyCreatePolygonShape(Environment* ev)
- {
- FW_UNUSED(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
- CGraphicsFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
- {
- FW_CFrame::FacetAdded(ev, facet, facetCount);
- if ( this->IsRoot(ev) ) {
- FW_CPoint interiorSize = fLargePictRect.BotRight();
- this->GetWindow(ev)->SetWindowSize(ev, interiorSize);
- }
- }
-
- //----------------------------------------------------------------------------------------
- void
- CGraphicsFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CViewContext context(ev, this, odFacet, invalidShape);
- this->MyDrawBackground(ev, context);
- this->MyDrawPictures(ev, context);
- this->MyDrawShapes(ev, context);
- this->MyDrawLine(ev, context);
- this->MyDrawText(ev, context);
- this->MyDrawPolygon(ev, context);
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::MyDrawBackground(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CRect box = this->GetBounds(ev);
- FW_CRectShape::RenderRect(gc, box, FW_kFill, FW_kRGBLightGray);
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::MyDrawShapes(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_UNUSED(ev);
- 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
- CGraphicsFrame::MyDrawText(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_UNUSED(ev);
- 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_GetPalatinoFontName(), FW_kItalic, kFontSize),
- FW_kTextAlignLeft | FW_kTextAlignBottom,
- FW_CInk(FW_kRGBBlue, FW_kRGBWhite, FW_kOr));
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::MyDrawPictures(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_PSharedLibraryResourceFile resFile(ev); // resource from our shared library
-
- fLargePictureShape->Render(gc);
-
- // draw DevU logo - I choose size
- const short kODFPictID = 2000;
- const short kCatPictID = 2002;
- const short kODFIconPictID = 2003;
- FW_CPictureShape::RenderPicture(gc,
- FW_CPicture(resFile, kODFPictID),
- FW_CRect(FW_IntToFixed(25), FW_IntToFixed(175), FW_IntToFixed(125), FW_IntToFixed(275))
- );
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::MyDrawLine(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_UNUSED(ev);
- fLineShape->Render(gc);
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::MyDrawPolygon(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_UNUSED(ev);
- fPolygonShape->Render(gc);
- }
-
- //----------------------------------------------------------------------------------------
- FW_Handled
- CGraphicsFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Handled eventHandled = false;
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- this->GetContentView(ev)->FrameToViewContent(ev, where);
- ODFacet* theFacet = theMouseEvent.GetFacet(ev);
- FW_CViewContext fc(ev, this, theFacet, NULL); // invalidShape = NULL
- const FW_Fixed kTolerance = FW_IntToFixed(2);
- if ( fLineShape->HitTest(fc, where, kTolerance) ) {
- FW_Beep();
- eventHandled = true;
- this->MyInvalidateLine(ev);
- fLineShape->MoveShape(FW_IntToFixed(0), FW_IntToFixed(20)); // move down
- this->MyInvalidateLine(ev);
- } // if
-
- if ( fRegionShape->HitTest(fc, where, kTolerance) ) {
- FW_Beep();
- eventHandled = true;
- this->Invalidate(ev, fRegionShape->GetODShape() );
- } // if
-
- if ( fPolygonShape->HitTest(fc, where, kTolerance) ) {
- FW_Beep();
- eventHandled = true;
- } // if
-
- return eventHandled;
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::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*
- CGraphicsFrame::NewPrintHandler(Environment* ev)
- {
- FW_CPart* part = GetPart(ev);
- return new FW_CPrintHandler(part, this);
- }
-
- //------------------------------------------------------------------------------
- FW_Boolean
- CGraphicsFrame::IsCurrentlyPrintable(Environment* ev) const
- {
- FW_UNUSED(ev);
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- void
- CGraphicsFrame::GetPrintContentExtent(Environment *ev, FW_CPoint& extent) const
- {
- FW_UNUSED(ev);
- extent = fLargePictRect.Size();
- FW_ASSERT(extent.x != FW_kFixed0);
- FW_ASSERT(extent.y != FW_kFixed0);
- }