home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-22 | 6.6 KB | 217 lines | [TEXT/CWIE] |
- // =================================================================================
- // CDynamicText.cp ©1997 BB's Team inc. All rights reserved
- // =================================================================================
- #include "CDynamicText.h"
-
- #include <LString.h>
- #include <LScroller.h>
- #include <UDrawingState.h>
- #include <UDrawingUtils.h>
-
-
- // ---------------------------------------------------------------------------------
- // • CreateDynamicTextStream [static]
- // ---------------------------------------------------------------------------------
- CDynamicText*
- CDynamicText::CreateDynamicTextStream (LStream *inStream)
- {
- return new CDynamicText ( inStream );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CDynamicText
- // ---------------------------------------------------------------------------------
- CDynamicText::CDynamicText()
- { }
-
-
- // ---------------------------------------------------------------------------------
- // • CDynamicText (SPaneInfo&, SViewInfo&, UInt16, ResIDT)
- // ---------------------------------------------------------------------------------
- CDynamicText::CDynamicText (
- const SPaneInfo &inPaneInfo,
- const SViewInfo &inViewInfo,
- Uint16 inTextAttributes,
- ResIDT inTextTraitsID)
- : LTextEdit ( inPaneInfo, inViewInfo, inTextAttributes, inTextTraitsID )
- { }
-
-
- // ---------------------------------------------------------------------------------
- // • CDynamicText (const CDynamicText&)
- // ---------------------------------------------------------------------------------
- CDynamicText::CDynamicText(const CDynamicText &inOriginal)
- : LTextEdit ( inOriginal )
- {
- // Copy the text traits.
- ::BlockMoveData( &inOriginal.mTextTraits,
- &mTextTraits, sizeof(TextTraitsRecord) );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CDynamicText (LStream*)
- // ---------------------------------------------------------------------------------
- CDynamicText::CDynamicText (LStream *inStream)
- : LTextEdit ( inStream )
- { }
-
-
- // ---------------------------------------------------------------------------------
- // • FinishCreateSelf
- // ---------------------------------------------------------------------------------
- void CDynamicText::FinishCreateSelf ()
- {
- // Load the text traits for the text.
- TextTraitsH theTraitsH = UTextTraits::LoadTextTraits (mTextTraitsID);
- Assert_( theTraitsH != nil );
-
- // Copy the text traits.
- ::BlockMoveData( *theTraitsH, &mTextTraits, sizeof(TextTraitsRecord) );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetTextTraitsID (ResIDT)
- // ---------------------------------------------------------------------------------
- void CDynamicText::SetTextTraitsID (ResIDT inTextTraitsID)
- {
- // Load the text traits.
- TextTraitsH theTraitsH = UTextTraits::LoadTextTraits( inTextTraitsID );
- Assert_( theTraitsH != nil );
-
- // Copy the text traits.
- ::BlockMoveData( *theTraitsH, &mTextTraits, sizeof(TextTraitsRecord) );
-
- // Refresh the text.
- SetTextTraits();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetTextTraits (TextTraitsRecord&)
- // ---------------------------------------------------------------------------------
- void CDynamicText::SetTextTraits (const TextTraitsRecord &inTextTraits)
- {
- // Copy the text traits.
- ::BlockMoveData( &inTextTraits, &mTextTraits, sizeof(TextTraitsRecord) );
-
- // Refresh the text.
- SetTextTraits();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • GetTextTraits
- // ---------------------------------------------------------------------------------
- void CDynamicText::GetTextTraits (TextTraitsRecord &outTextTraits) const
- {
- // Copy the text traits.
- ::BlockMoveData( &mTextTraits, &outTextTraits, sizeof(TextTraitsRecord) );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetFont
- // ---------------------------------------------------------------------------------
- void CDynamicText::SetFont (const Str255 inFontName)
- {
- // Copy the font name.
- LString::CopyPStr( inFontName, mTextTraits.fontName );
-
- // Get the font number.
- ::GetFNum( mTextTraits.fontName, &mTextTraits.fontNumber );
-
- // Refresh the text.
- SetTextTraits();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • GetFont
- // ---------------------------------------------------------------------------------
- void CDynamicText::GetFont (Str255 outFontName) const
- {
- // Copy the font name.
- LString::CopyPStr( mTextTraits.fontName, outFontName );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetSize
- // ---------------------------------------------------------------------------------
- void
- CDynamicText::SetSize(
- Int16 inSize )
- {
- // Set the size.
- mTextTraits.size = inSize;
-
- // Refresh the text.
- SetTextTraits();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • GetSize
- // ---------------------------------------------------------------------------------
- Int16
- CDynamicText::GetSize() const
- {
- return mTextTraits.size;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetTextTraits
- // ---------------------------------------------------------------------------------
- void
- CDynamicText::SetTextTraits (void)
- {
- UTextTraits::SetTETextTraits(&mTextTraits, mTextEditH);
-
- SPoint32 scrollUnit;
- scrollUnit.h = 4;
- scrollUnit.v = (**mTextEditH).lineHeight;
- SetScrollUnit (scrollUnit);
- Refresh();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetWidth
- // ---------------------------------------------------------------------------------
- void
- CDynamicText::SetWidth (Int16 inWidth)
- {
- ResizeImageTo (inWidth, ::TEGetHeight((**mTextEditH).nLines, 1, mTextEditH), false);
-
- // Warning : do not remove
- // This avoids some of the unwanted line breaks appearing in certain circumstances
- AlignTextEditRects();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • PrepareToPrint
- // ---------------------------------------------------------------------------------
- void
- CDynamicText::PrepareToPrint (void)
- {
- SDimension32 theImageSize;
- GetImageSize(theImageSize);
- GetFrameSize (mFrameSize);
- ResizeFrameTo (theImageSize.width, theImageSize.height, false);
- }
-
-
- // ---------------------------------------------------------------------------------
- // • RevertFromPrint
- // ---------------------------------------------------------------------------------
- void
- CDynamicText::RevertFromPrint (void)
- {
- ResizeFrameTo (mFrameSize.width, mFrameSize.height, false);
- }
-