home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 10.7 KB | 351 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTxtBox.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef SLRENDER_H
- #include "SLRender.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRANSFORM_
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_TextBoxShape
- #endif
-
- //========================================================================================
- // class FW_CTextBoxShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CTextBoxShape)
- FW_DEFINE_CLASS_M1(FW_CTextBoxShape, FW_CBaseTextShape)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(const FW_CTextBoxShape& other) :
- FW_CBaseTextShape(other),
- fTextBox(other.fTextBox),
- fOptions(other.fOptions)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape() :
- FW_CBaseTextShape(),
- fOptions(kDefaultJustification)
- // fTextBox is set to 0's to its default constructor
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(const FW_CString& string,
- const FW_CRect& box,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& ink) :
- FW_CBaseTextShape(string, ink, font),
- fOptions(options),
- fTextBox(box)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(FW_CTextReader& textReader,
- const FW_CRect& box,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& ink) :
- FW_CBaseTextShape(textReader, ink, font),
- fOptions(options),
- fTextBox(box)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(FW_CReadableStream& stream) :
- FW_CBaseTextShape(stream)
- {
- stream >> fTextBox;
- stream >> fOptions;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::~FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::~FW_CTextBoxShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape& FW_CTextBoxShape::operator=(const FW_CTextBoxShape& other)
- {
- if (this != &other)
- {
- FW_CBaseTextShape::operator=(other);
-
- fTextBox = other.fTextBox;
- fOptions = other.fOptions;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Render(FW_CGraphicContext& gc) const
- {
- FW_PrivRenderTextBoxString(gc.GetEnvironment(),
- gc,
- fString,
- fTextBox,
- fOptions,
- GetRenderVerb(),
- fInk,
- fFont);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::RenderTextBox
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc,
- FW_CTextReader& textReader,
- const FW_CRect& box,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& ink)
- {
- FW_Fixed result = FW_PrivRenderTextBoxReader(gc.GetEnvironment(), gc,
- textReader,
- box,
- options,
- FW_kFill,
- ink,
- font);
- FW_FailOnEvError(gc.GetEnvironment());
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::RenderTextBox
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc,
- const FW_CString& string,
- const FW_CRect& box,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& ink)
- {
- FW_Fixed result = FW_PrivRenderTextBoxString(gc.GetEnvironment(), gc,
- string,
- box,
- options,
- FW_kFill,
- ink,
- font);
- FW_FailOnEvError(gc.GetEnvironment());
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::UpdateTextBox
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::UpdateTextBox(FW_CGraphicContext& gc)
- {
- FW_PrivTextBoxSizeString(gc.GetEnvironment(), gc,
- fString,
- fFont,
- fOptions,
- fTextBox);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::CalcTextBox
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc,
- FW_CTextReader& textReader,
- FW_TextBoxOptions options,
- const FW_CFont& font,
- FW_CRect& box)
- {
- FW_ByteCount savedPosition = textReader.GetPosition();
- FW_PrivTextBoxSizeReader(gc.GetEnvironment(), gc,
- textReader,
- font,
- options,
- box);
- FW_FailOnEvError(gc.GetEnvironment());
- textReader.SetPosition(savedPosition); // restore original textReader position
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::CalcTextBox
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc,
- const FW_CString& string,
- FW_TextBoxOptions options,
- const FW_CFont& font,
- FW_CRect& box)
- {
- FW_PrivTextBoxSizeString(gc.GetEnvironment(), gc,
- string,
- font,
- options,
- box);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Transform(Environment* ev, ODTransform* odTransform)
- {
- fTextBox.Transform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::InverseTransform(Environment* ev, ODTransform* odTransform)
- {
- fTextBox.InverseTransform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Inset(FW_Fixed x, FW_Fixed y)
- {
- fTextBox.Inset(x, y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CTextBoxShape::Copy() const
- {
- return FW_NEW(FW_CTextBoxShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- fTextBox.left += deltaX;
- fTextBox.top += deltaY;
- fTextBox.right += deltaX;
- fTextBox.bottom += deltaY;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
- {
- fTextBox.right += x - fTextBox.left;
- fTextBox.bottom += y - fTextBox.top;
- fTextBox.left = x;
- fTextBox.top = y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_UNUSED(gc);
-
- rect = fTextBox;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::GetAnchorPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CTextBoxShape::GetAnchorPoint() const
- {
- return fTextBox.TopLeft();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CBaseTextShape::Flatten(stream);
-
- stream << fTextBox;
- stream << fOptions;
- }
-
-