home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-02-21 | 3.5 KB | 163 lines | [TEXT/CWIE] |
- class TText : public CAbstractText //Abstract text supplies all the other // methods
- {
-
- private:
- TPrivateText *fInternalText;
- public:
- void ActivateText (Boolean OnOff);
- void Compact();
- void UnCompact();
- virtual void Update(RgnHandle updateRgn);
- }
-
- void TText::ActivateText (Boolean OnOff)
- {
- if (OnOff)
- {
- UnCompact(); // transmutes from a string, if needed
- FocusToDraw();
- fInternalText->Activate(true);
- }
- else
- {
- FocusToDraw();
- fInternalText->Activate(false);
- Compact(); // attempts to transmute into a string
- }
- }
-
- void TText::Compact()
- {Handle itsText;
- TInternalText *newText;
- Point itsPenStart
-
- if (fInternalText->CanCompact()) {
- itsText= fInternalText->GetText();
- itsPenStart= fInternalText->GetPenStart();
- newText= new TString(itsText,itsPenStart);
- delete fInternalText;
- fInternalText=newText;
- }
- }
-
- void TText::UnCompact()
- {Handle itsText;
- TInternalText *newText;
-
- if (fInternalText->CanExpand()) {
- itsText= fInternalText->GetText();
- newText= new TStyledText(itsText);
- delete fInternalText;
- fInternalText=newText;
- }
- }
-
- void TText::Update(RgnHandle updateRgn)
- {
-
- if (RectInRgn(&fBoundingBox, updateRgn))
- {
- FocusToDraw();
- Frame();
- fInternalText->Update(updateRgn);
- }
- }
-
-
-
- class TInternalText //important fields and methods only
- {
- virtual void ActivateText (Boolean OnOff) {;};
- virtual Boolean CanCompact() {return false};
- virtual Boolean CanExpand() {return false};
- virtual Handle GetText();
- virtual Point GetPenStart(){return PointOf(0,0)};
- virtual void SetPenStart(Point aStart){;};
- virtual void Update(RgnHandle updateRgn);
- }
-
- class TString : public TInternalText //important fields and methods //only
- {
- Handle fText;
- Point fPenStart;
-
- Boolean CanExpand() {return true};
- Handle GetText() {return fText};
- void SetPenStart(Point aStart){fPenStart=aStart};
- void Update(RgnHandle updateRgn);
- }
-
- class TStyledText : public TInternalText //important fields and //methods only
- {
- void ActivateText (Boolean OnOff);
- Boolean CanCompact();
- virtual Point GetPenStart(){return PointOf(0,0)};
- Handle GetText();
- void Update(RgnHandle updateRgn);
- }
-
-
- void TString::Update(RgnHandle updateRgn)
- {
- MoveTo(fPenStart.h,fPenStart.v);
- HLock(fText);
- DrawText( *fText, 0, GetHandleSize (fText) ); //Toolbox Routine HUnlock( fText );
- }
-
-
- Boolean TStyledText::CanCompact()
- {
- long oldStart,oldEnd,length;
- long kMaxString=999;
- SignedByte alignment;
- Boolean canDo=false;
-
- length= WEGetTextLength(fMacWE);
-
- WEGetSelection(&oldStart,&oldEnd,fMacWE);
-
- if ((oldEnd-oldStart)<kMaxString) // not too long
- {
- WESetSelection(0,kMaxString,fMacWE);
-
- mode = doFont + doFace + doSize + doColor;
-
- alignment=WEGetAlignment(fMacWE);
-
- if ((WEContinuousStyle(&mode, &aStyle, fMacWE)) &&
- // one style
- (WEOffsetToLine(kMaxString, fMacWE)==0) &&
- // one line
- ((alignment== weFlushLeft) ||(alignment== weFlushDefault))
- // no fancy alignment
- )
- canDo=true;
-
- WESetSelection(oldStart,oldEnd,fMacWE);
- }
- else
- return canDo
- }
-
- Point TStyledText::GetPenStart()
- {Point penStart;
- short lineAscent,lineDescent;
- LongRect destRect;
-
- WEGetDestRect(&destRect,fMacWE);
-
- penStart.h=destRect.left;
-
- _WECalcHeights(0, 1, &lineAscent, &lineDescent, fMacWE);
-
- penStart.v= destRect.top+lineAscent;
-
- return
- penStart
- }
-
- void TStyledText::Update(RgnHandle updateRgn)
- {
- WEUpdate(updateRgn, fMacWE); // passed to the styled text engine
- }
-