home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 6.9 KB | 268 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: TextShp.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawshapes
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- FW_DEFINE_AUTO(CTextShape)
- FW_DEFINE_CLASS_M1(CTextShape, CBoundedShape)
-
- const FW_ClassTypeConstant LTextShape = FW_TYPE_CONSTANT('s','h','t','x');
- FW_REGISTER_ARCHIVABLE_CLASS(LTextShape, CTextShape, CTextShape::Read, 0, 0, CBaseShape::Write)
-
- //========================================================================================
- // class CTextShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTextShape::CTextShape
- //----------------------------------------------------------------------------------------
-
- CTextShape::CTextShape() :
- CBoundedShape(kTextShape, kFrameOnly),
- fText
- (
- "\"Young man\", said the Russian playwright Anton Chekhov, "
- "\"I see a brilliant future written on your face.\" "
- "These words were spoken to Serge Rachmaninoff."
- )
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::CTextShape
- //----------------------------------------------------------------------------------------
-
- CTextShape::CTextShape(FW_CReadableStream& archive) :
- CBoundedShape(archive)
- {
- archive >> fText;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::~CTextShape
- //----------------------------------------------------------------------------------------
-
- CTextShape::~CTextShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::RenderShape
- //----------------------------------------------------------------------------------------
-
- void CTextShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
- {
- // Draw a frame
- FW_CRect rect = GetRectGeometry();
- AdjustRectForPenSize(rect, GetPenSize());
-
- if (HasFrameStyle())
- FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
-
- // Draw the text
- FW_CFont font(FW_kTimes, FW_kPlain, FW_IntToFixed(12));
-
- rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
- FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxWordWrap | FW_kTextBoxWordBreak | FW_kTextBoxClipToBox;
- FW_CTextBoxShape::RenderTextBox(gc, fText, rect, font, options, fFrameInk);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTextShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
- {
- FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
-
- FW_CTextBoxShape textShape(fText, GetRectGeometry());
- return textShape.HitTest(gc, mouse, FW_IntToFixed(2));
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::OutlineShape
- //----------------------------------------------------------------------------------------
-
- void CTextShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
- {
- FW_CRectShape::RenderRect(gc,
- rect,
- FW_kFrame,
- ink, style);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::GetClipRegion
- //----------------------------------------------------------------------------------------
-
- void CTextShape::GetClipRegion(Environment *ev, ODShape* clipRegion)
- {
- FW_CRect odRect = GetRectGeometry();
- clipRegion->SetRectangle(ev, (ODRect*)&odRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::CreateShapeOutline
- //----------------------------------------------------------------------------------------
-
- ODShape* CTextShape::CreateShapeOutline(Environment *ev)
- {
- // We don't acquire it because we return it
- ODShape* dragRgn = ::FW_NewODShape(ev, GetRectGeometry());
-
- ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
-
- return dragRgn;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void CTextShape::Flatten(FW_CWritableStream& archive)
- {
- CBoundedShape::Flatten(archive);
- archive << fText;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextShape::Read
- //----------------------------------------------------------------------------------------
-
- void* CTextShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- return FW_NEW(CTextShape, (stream));
- }
-
-