home *** CD-ROM | disk | FTP | other *** search
- /********************************************************\
- CWASTEText.cpp
-
- version 1.1
-
- \********************************************************/
-
- #ifdef TCL_PCH
- #include <TCLHeaders>
- #endif
-
- #include "CWASTEText.h"
- #include "CWASTEEditTask.h"
- #include "CWASTEStyleTask.h"
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #include <Script.h>
- #include "CClipboard.h"
- #include "CBartender.h"
- #include "Commands.h"
- #include "TCLUtilities.h"
- #include "Constants.h"
- #include "CScrollPane.h"
- #include "Global.h"
- #include <TextServices.h>
- #include "CPrinter.h"
-
- // Global Variables
- extern CClipboard *gClipboard; // Copies and Pastes data
- extern EventRecord gLastMouseUp;
- extern CBureaucrat *gGopher;
- extern CBartender *gBartender;
-
- extern long gSleepTime;
- extern short gUsingTSM;
-
- static pascal Boolean WEClickLoop(WEHandle hWE);
- static pascal void WEPreUpdate(WEHandle hWE);
-
- CWASTEText *gWASTEText=NULL; /* Current WASTEText object */
-
- // undocumented WASTE routine
- #define CWASTE
- #ifdef CWASTE
- extern "C"
- {
- long _WEOffsetToLine(long offset, WEHandle hWE);
- }
- #else
- pascal long _WEOffsetToLine(long offset, WEHandle hWE);
- #endif
- // undocumented WASTE feature flag
- const short weFActive = 20;
-
- TCL_DEFINE_CLASS_D1(CWASTEText, CAbstractText);
-
- /********************************************************\
- CWASTEText() - default constructor
- You must call IWASTEText if you use this
- \********************************************************/
-
- CWASTEText::CWASTEText()
- {
- macWE = NULL;
- spacingCmd = cmdSingleSpace;
- alignCmd = cmdAlignLeft;
-
- wholeLines = false;
-
- fixedLineHeights = false;
-
- TCL_END_CONSTRUCTOR
- }
-
- /********************************************************\
- CWASTEText - constructor
- You cannot call IWASTEText if you use this
- \********************************************************/
-
- CWASTEText::CWASTEText(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- short aLineWidth,
- Boolean aScrollHoriz,
- TextStyle *tStyle)
-
- : CAbstractText(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing,
- aLineWidth, aScrollHoriz)
- {
- macWE = NULL;
- spacingCmd = cmdSingleSpace;
- alignCmd = cmdAlignLeft;
-
- wholeLines = false;
- fixedLineHeights = false;
-
- if (tStyle)
- {
- TextFont(tStyle->tsFont);
- TextSize(tStyle->tsSize);
- TextFace(tStyle->tsFace);
- if (gSystem.hasColorQD)
- RGBForeColor(&tStyle->tsColor);
- }
-
-
- IWASTETextX();
- TCL_END_CONSTRUCTOR
- }
-
- /********************************************************\
- ~CWASTEText - destructor
- \********************************************************/
-
- CWASTEText::~CWASTEText()
- {
- TCL_START_DESTRUCTOR
- if (macWE)
- {
- WEDispose(macWE);
- macWE = NULL;
- }
- }
-
- /********************************************************\
- IWASTEText - initialize CWASTEText
- Use this only if you use the default constructor
- \********************************************************/
-
- void CWASTEText::IWASTEText(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- short aLineWidth,
- TextStyle *tStyle)
- {
-
- CAbstractText::IAbstractText(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing,
- aLineWidth);
- if (tStyle)
- {
- TextFont(tStyle->tsFont);
- TextSize(tStyle->tsSize);
- TextFace(tStyle->tsFace);
- if (gSystem.hasColorQD)
- RGBForeColor(&tStyle->tsColor);
- }
-
- IWASTETextX();
- }
-
- /********************************************************\
- IViewTemp - initialize from View resource
- \********************************************************/
-
- void CWASTEText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
- Ptr viewData)
- {
- CAbstractText::IViewTemp(anEnclosure, aSupervisor, viewData);
-
- macWE = NULL;
- spacingCmd = cmdSingleSpace;
- alignCmd = cmdAlignLeft;
- fixedLineHeights = FALSE;
-
- IWASTETextX();
- }
-
- /********************************************************\
- IWASTETextX - initialization common to above routines
- \********************************************************/
-
- void CWASTEText::IWASTETextX()
- {
- LongRect tLongFrame;
- WEClickLoopProcPtr clickLoop;
- Boolean saveAllocState;
- OSErr err;
- WETSMPreUpdateProcPtr preProc;
- WEHandle newMacWE;
-
- ForceNextPrepare();
-
- UseLongCoordinates(TRUE);
-
- // Figure out size of of rectangle
- GetAperture(&tLongFrame);
-
- // create WEHandle
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WENew(&tLongFrame, &tLongFrame, weDoOutlineHilite + weDoDrawOffscreen,
- &newMacWE);
- SetAllocation(saveAllocState);
- FailOSErr(err);
- macWE = newMacWE;
-
- SetWholeLines(wholeLines);
-
- AdjustBounds();
-
- autoRefresh = lineWidth <= 0;
-
- preProc = &WEPreUpdate;
- WESetInfo(weTSMPreUpdate, (Ptr)&preProc, macWE);
-
- clickLoop = &WEClickLoop;
- WESetInfo(weClickLoop, (Ptr)&clickLoop, macWE);
- CalcWERects();
- if (lineWidth < 0)
- {
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECalText( macWE);
- SetAllocation(saveAllocState);
- }
- }
-
- /********************************************************\
- CheckInsertion -- sees if it is possible to insert
- text
- \********************************************************/
-
- void CWASTEText::CheckInsertion(long numChars, long styleSize, Boolean useSelection)
- {
- long selStart, selEnd;
- long growSize = numChars;
- Handle h;
- OSErr err;
-
- if (useSelection)
- {
- GetSelection(&selStart, &selEnd);
- growSize -= Abs(selEnd - selStart);
- }
-
- /* The problem with WASTE is that it can succeed in adding the text to its content
- * structure, and then fail to expand its style tables or line start tables. The way
- * I address this is to add a fudge factor to the amount of data being added, and
- * hope that its enough to cover the WASTE overhead.
- */
-
- if (growSize > 0)
- {
- /* Add fudge factor for new line starts (1/5th of numChars) */
-
- growSize += growSize / 5;
-
- /* Add fudge factor for style information (1/2 of styleSize) */
-
- growSize += styleSize + styleSize / 2;
-
- if (WEFeatureFlag(weFUseTempMem, weBitTest, macWE))
- {
- h = TempNewHandle(growSize, &err);
- if (!h && err == noErr)
- err = memFullErr;
- DisposeHandle(h);
- FailOSErr(err);
- }
- else
- {
- h = NewHandleCanFail(growSize);
- FailNIL(h);
- DisposeHandle(h);
- }
- }
- }
-
-
- /********************************************************\
- WEPreUpdate -- prepare the port
- \********************************************************/
-
- static pascal void WEPreUpdate(WEHandle hWE)
- {
- if (gWASTEText != NULL)
- {
- gWASTEText->Prepare();
- }
- }
-
-
- /********************************************************\
- DoClick - handle mouse clicks
- \********************************************************/
-
- void CWASTEText::DoClick(Point hitPt, short modifierKeys, long when)
- {
-
- // Handle the mouse click
-
- WEClick(hitPt, modifierKeys, when, macWE);
-
- // CSwitchboard will never see the mouse up that ended
- // the drag, so we stuff gLastMouseUp here to allow
- // multi-click counting to work.
-
- gLastMouseUp.what = mouseUp;
- gLastMouseUp.when = TickCount();
- gLastMouseUp.where = hitPt;
- LocalToGlobal( &gLastMouseUp.where);
- gLastMouseUp.modifiers = modifierKeys;
-
- SelectionChanged();
-
- if (!editable && (gGopher == this))
- {
- long selStart, selEnd;
-
- GetSelection( &selStart, &selEnd);
- if (selStart == selEnd)
- itsSupervisor->BecomeGopher( TRUE);
- }
- }
-
-
- /********************************************************\
- UpdateMenus - handle WASTE specific menu enabling
- \********************************************************/
-
- void CWASTEText::UpdateMenus()
- {
- long selStart, selEnd;
-
- inherited::UpdateMenus();
-
- // Copy and Cut are only possible if the selection is small (< 32K).
- // The danger here is that a piece of styled text > 32K will pass
- // through the clipboard to another applciation which cannot handle
- // it (like the Finder).
- //
- // Should probably override DoCommand as well to make sure a command
- // does not get past the Menu Manager -- can be done later.
-
- GetSelection(&selStart, &selEnd);
- if (Abs(selEnd - selStart) >= 32767)
- {
- gBartender->DisableCmd(cmdCopy);
- gBartender->DisableCmd(cmdCut);
- }
- }
-
- /********************************************************\
- MakeEditTask -- use WASTE specific one
- \********************************************************/
-
- CTextEditTask *CWASTEText::MakeEditTask( long editCmd)
- {
- CWASTEEditTask *volatile editTask = NULL;
-
- try_
- {
- editTask = new CWASTEEditTask(this, editCmd, cFirstTaskIndex);
- }
-
- catch_all_()
- {
- TCLForgetObject(editTask);
-
- throw_same_();
- }
- end_try_
-
- return editTask;
- }
-
- /********************************************************\
- MakeStyleTask -- use WASTE specific one
- \********************************************************/
-
-
- CTextStyleTask *CWASTEText::MakeStyleTask( long styleCmd)
- {
-
- CWASTEStyleTask *volatile newTask = NULL;
- short taskIndex;
-
- try_
- {
- taskIndex = cFirstTaskIndex > 0 ? cFirstTaskIndex + undoFormatting : 0;
- newTask = new CWASTEStyleTask(this, styleCmd, taskIndex);
- }
-
- catch_all_()
- {
- TCLForgetObject( newTask);
-
- throw_same_();
- }
- end_try_
-
- return newTask;
- }
-
-
- /********************************************************\
- PerformEditCommand - handle cut, copy, paste, and clear
- \********************************************************/
-
- void CWASTEText::PerformEditCommand(long theCommand)
- {
- Boolean saveAllocState;
- OSErr err = noErr;
-
- Prepare();
- if (!ReallyVisible())
- SetOrigin(-10000, -10000);
-
- switch( theCommand)
- {
- case cmdCut:
- gClipboard->EmptyGlobalScrap();
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECut(macWE);
- SetAllocation(saveAllocState);
- if (err == noErr)
- gClipboard->UpdateDisplay();
- break;
-
- case cmdCopy:
- gClipboard->EmptyGlobalScrap();
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECopy(macWE);
- SetAllocation(saveAllocState);
- if (err == noErr)
- gClipboard->UpdateDisplay();
- break;
-
- case cmdPaste:
- CheckInsertion(gClipboard->DataSize('TEXT'),
- gClipboard->DataSize('styl'), TRUE);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WEPaste(macWE);
- SetAllocation(saveAllocState);
- break;
-
- case cmdClear:
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WEDelete(macWE);
- SetAllocation(saveAllocState);
- break;
-
- }
- AdjustBounds();
- ScrollToSelection();
- FailOSErr(err);
- }
-
-
- /********************************************************\
- Draw - draw the text
- \********************************************************/
-
- void CWASTEText::Draw(Rect *area)
- {
- RgnHandle updateRgn;
- LongRect fr, dr;
- Rect r;
-
- if (!ReallyVisible())
- return;
-
- updateRgn = NewRgn();
- RectRgn(updateRgn, area);
- SectRgn(updateRgn, macPort->visRgn, updateRgn);
-
- if (!printing)
- CalcWERects();
- else
- {
- // Prepare the destination and view rectangles
-
- WEGetDestRect(&dr, macWE);
- GetAperture(&fr);
- OffsetLongRect(&dr, -(dr.left + fr.left), -(dr.top + fr.top));
- FrameToQDR(&fr, &r);
- OffsetLongRect(&dr, r.left, r.top);
- dr.right = (lineWidth > 0) ? dr.left + lineWidth : printPageWidth;
- WESetDestRect(&dr, macWE);
- QDToLongRect(area, &fr);
- if (wholeLines)
- fr.bottom = fr.top + vScale * ((area->bottom - area->top) / vScale);
- WESetViewRect(&fr, macWE);
- }
-
- WEUpdate(updateRgn, macWE);
- // not necessary -- err = WESetInfo(wePort, &macPort, macWE);
- DisposeRgn(updateRgn);
-
- }
-
-
- /********************************************************\
- Activate - activate the pane
- \********************************************************/
-
- void CWASTEText::Activate()
- {
- TSMDocumentID aTSMDocument;
-
- if (gWASTEText==this) // already active
- {
- return;
- }
-
- CAbstractText::Activate();
-
- // deactivate old WASTEText
- if (gWASTEText!=NULL) gWASTEText->Deactivate();
- Prepare();
- CalcWERects();
- WEActivate(macWE);
- gWASTEText = this;
- if (!editable)
- {
- // if not editable, deactivate TSM so inline input won't work
- if (gUsingTSM)
- {
- if (WEGetInfo(weTSMDocumentID, (Ptr)&aTSMDocument, macWE) == noErr)
- {
- if (aTSMDocument != NULL)
- DeactivateTSMDocument(aTSMDocument);
- }
- }
- }
- }
-
- /********************************************************\
- Deactivate - deactivate the pane
- \********************************************************/
-
- void CWASTEText::Deactivate()
- {
- CAbstractText::Deactivate();
-
- Prepare();
- WEStopInlineSession(macWE);
- if (macWE)
- {
- CalcWERects();
- WEDeactivate(macWE);
- }
- gWASTEText = NULL;
- }
-
- /********************************************************\
- SetSelection - set what text is selected
- \********************************************************/
-
- void CWASTEText::SetSelection(long selStart, long selEnd, Boolean fRedraw)
- {
- short wasActive, wasOutline;
-
- Prepare();
- if (!fRedraw)
- {
- wasActive = WEFeatureFlag(weFActive, weBitClear, macWE);
- wasOutline = WEFeatureFlag(weFOutlineHilite, weBitClear, macWE);
- }
- WESetSelection(selStart, selEnd, macWE);
- if (!fRedraw)
- {
- WEFeatureFlag(weFActive, wasActive, macWE);
- WEFeatureFlag(weFOutlineHilite, wasOutline, macWE);
- }
- }
-
- /********************************************************\
- Clear - clear the text
- Deactivates text before clearing to prevent
- highlighting from showing up
- \********************************************************/
-
- void CWASTEText::Clear(void)
- {
- Boolean saveAllocState;
- OSErr err;
-
- // select all temporarily
- //TempSelectAll();
- SetSelection(0, 0x7FFFFFFF, false);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WEDelete(macWE);
- SetAllocation(saveAllocState);
-
- //RestoreSelection();
- AdjustBounds();
- ScrollToSelection();
- FailOSErr(err);
- }
-
- /********************************************************\
- SetTextPtr - set the text to a block of memory
- \********************************************************/
-
- void CWASTEText::SetTextPtr(Ptr textPtr, long numChars)
- {
- Boolean saveAllocState;
- OSErr err;
- Handle newHand;
-
- Prepare();
- if (!ReallyVisible())
- SetOrigin(-10000, -10000);
-
- SetSelection(0, 0x7FFFFFFF, false);
- FailOSErr(WEDelete(macWE));
- CheckInsertion(numChars, 0, FALSE);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WEInsert(textPtr, numChars, NULL, macWE);
- SetAllocation(saveAllocState);
-
- AdjustBounds();
- Refresh();
-
- FailOSErr(err);
- }
-
- /********************************************************\
- StopInlineSession - stop inline session, confirm text
- \********************************************************/
-
- void CWASTEText::StopInlineSession(void)
- {
- WEStopInlineSession(macWE);
- }
-
- /********************************************************\
- SetOutlineHighliting - turns on or off outline
- highliting and returns old setting
- \********************************************************/
-
- Boolean CWASTEText::SetOutlineHighliting(Boolean hilite)
- {
- Boolean oldValue;
-
- oldValue = (WEFeatureFlag(weFOutlineHilite,
- hilite ? weBitSet : weBitClear, macWE) == weBitSet);
-
- return oldValue;
- }
-
- /********************************************************\
- GetTextHandle - get a handle to the text
- This is not a copy of the handle, but the real thing
- \********************************************************/
-
- Handle CWASTEText::GetTextHandle()
- {
- return( (Handle) WEGetText(macWE));
- }
-
- /********************************************************\
- CopyTextRange - return a handle to a copy of the
- indicated range of text
- \********************************************************/
-
- Handle CWASTEText::CopyTextRange(long start, long end)
- {
- Handle h;
- long len;
-
- end = Min(end, WEGetTextLength(macWE));
-
- len = Max(end - start, 0);
- h = NewHandleCanFail(len);
- FailNIL(h);
- if (len > 0)
- BlockMove( (char*)*(WEGetText(macWE)) + start, *h, len);
-
- return h;
- }
-
- /********************************************************\
- CopyRangeWithStyle - return a handle to the text and
- styles in a range. Handles must be previously
- created with NewHandle();
- \********************************************************/
-
- void CWASTEText::CopyRangeWithStyle(long start, long end, Handle hText,
- StScrpHandle hStyles)
- {
- Boolean saveAllocState;
- OSErr err;
-
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECopyRange(start, end, hText, hStyles, macWE);
- SetAllocation(saveAllocState);
- FailOSErr(err);
- }
-
- /********************************************************\
- InsertTextPtr - insert a block of text
- \********************************************************/
-
- void CWASTEText::InsertTextPtr(Ptr text, long length, Boolean fRedraw)
- {
- Boolean saveAllocState;
- OSErr err;
-
- Prepare();
- if (!ReallyVisible())
- SetOrigin(-10000, -10000);
- CheckInsertion(length, 0, TRUE);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WEInsert(text, length, NULL, macWE);
- SetAllocation(saveAllocState);
-
- AdjustBounds();
- if (fRedraw) Refresh();
- FailOSErr(err);
- }
-
- /********************************************************\
- InsertWithStyle -- insert text along with style
- \********************************************************/
-
- void CWASTEText::InsertWithStyle(Ptr text, long length, StScrpHandle hStyles,
- Boolean fRedraw)
- {
- Boolean saveAllocState;
- OSErr err;
- long i, numStyles;
- short fontSize;
- StScrpPtr styles;
-
- Prepare();
- if (!ReallyVisible())
- SetOrigin(-10000, -10000);
- CheckInsertion(length, hStyles ? GetHandleSize((Handle) hStyles) : 0, TRUE);
-
- /* Fix style entries which have a font size of 0 */
-
- if (hStyles)
- {
- //fontSize = LMGetSysFontSize(); // for some reason this is returning 0 also
- fontSize = 12;
- styles = *hStyles;
-
- numStyles = styles->scrpNStyles;
- for (i = 0; i < numStyles; i++)
- if (styles->scrpStyleTab[i].scrpSize == 0)
- styles->scrpStyleTab[i].scrpSize = fontSize;
- }
-
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WEInsert(text, length, hStyles, macWE);
- SetAllocation(saveAllocState);
-
- AdjustBounds();
- if (fRedraw) Refresh();
- FailOSErr(err);
- }
-
- /********************************************************\
- TypeChar - type a character
- \********************************************************/
-
- void CWASTEText::TypeChar(char theChar, short theModifers)
- {
- Boolean saveAllocState;
-
- Prepare();
- CheckInsertion(1, 0, TRUE);
- saveAllocState = SetAllocation(kAllocCanFail);
- WEKey(theChar, theModifers, macWE);
- SetAllocation(saveAllocState);
- AdjustBounds();
- ScrollToSelection();
- }
-
- /********************************************************\
- CalcWERects - Sets the DestRect and ViewRect fields
- used by WASTE
- \********************************************************/
-
- void CWASTEText::CalcWERects()
- {
- LongRect fr, dr;
- Rect r;
-
- // Prepare the destination and view rectangles
-
- WEGetDestRect(&dr, macWE);
- GetAperture(&fr);
- OffsetLongRect(&dr, -(dr.left + fr.left), -(dr.top + fr.top));
- FrameToQDR(&fr, &r);
- OffsetLongRect(&dr, r.left, r.top);
- dr.right = (lineWidth > 0) ? dr.left + lineWidth : fr.right;
- WESetDestRect(&dr, macWE);
- QDToLongRect(&r, &fr);
- WESetViewRect(&fr, macWE);
- }
-
- /********************************************************\
- ResizeFrame - resize the frame when the size of the
- pane changes
- \********************************************************/
-
- void CWASTEText::ResizeFrame(Rect *delta)
- {
- Boolean saveAllocState;
- OSErr err;
-
- CAbstractText::ResizeFrame(delta);
-
- CalcWERects();
- if (lineWidth < 0)
- {
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECalText( macWE);
- SetAllocation(saveAllocState);
- CalcWERects();
- }
- AdjustBounds();
- }
-
- /********************************************************\
- AdjustBounds - change the size of the CWASTEText to
- match that in the WASTE record
- \********************************************************/
-
- void CWASTEText::AdjustBounds()
- {
- LongRect oldBounds;
- long newHeight;
- long hFix = 0, vFix = 0;
-
- oldBounds = bounds;
- newHeight = GetHeight(0, MAXINT);
-
- bounds.left = bounds.top = 0;
- bounds.bottom = newHeight;
-
- if (lineWidth > 0)
- {
- bounds.right = lineWidth;
- } else {
- bounds.right = frame.right - frame.left;
- }
-
- bounds.right = (bounds.right - 1) / hScale + 1;
-
- /* Deal with the possibility that the new bounds is smaller than the older one,
- * that the old position is now outside the bounds.
- */
- /*
- if (position.h > bounds.right)
- hFix = bounds.right - oldBounds.right;
- if (position.v > bounds.bottom)
- vFix = bounds.bottom - oldBounds.bottom;
- if (hFix || vFix)
- Scroll(hFix, vFix, TRUE);
- */
- if (itsScrollPane != NULL)
- {
- itsScrollPane->AdjustScrollMax();
- itsScrollPane->Calibrate();
- }
- }
-
- /********************************************************\
- FindLine - return the line on which the character
- at charPos is on.
- \********************************************************/
-
- long CWASTEText::FindLine(long charPos)
- {
- long lineNo;
-
- lineNo = _WEOffsetToLine(charPos, macWE);
- if (charPos == WEGetTextLength(macWE) &&
- ((char*)(*GetTextHandle()))[GetLength()-1] == 13)
- lineNo++;
-
- return (lineNo);
-
- }
-
- /********************************************************\
- GetLength - return the length of the text
- \********************************************************/
-
- long CWASTEText::GetLength()
- {
- return WEGetTextLength(macWE);
- }
-
- /********************************************************\
- SetFontNumber - set the font of the selection
- \********************************************************/
-
- void CWASTEText::SetFontNumber(short aFontNumber)
- {
- TextStyle style;
-
- style.tsFont = aFontNumber;
- SetStyle( doFont, &style, TRUE);
-
- }
-
- /********************************************************\
- SetFontNumberAll - set the font of all of the text
- \********************************************************/
-
- void CWASTEText::SetFontNumberAll(short aFontNumber)
- {
- TempSelectAll();
- SetFontNumber(aFontNumber);
- RestoreSelection();
- }
-
- /********************************************************\
- SetFontNameAll - set the font of the selection
- \********************************************************/
-
- void CWASTEText::SetFontNameAll(Str255 aFontName)
- {
- TempSelectAll();
- SetFontName(aFontName);
- RestoreSelection();
- }
-
- /********************************************************\
- SetFontStyle - set the font style of the selection
- \********************************************************/
-
- void CWASTEText::SetFontStyle(short aStyle)
- {
- TextStyle style;
- short mode = doFace;
-
- style.tsFace = aStyle;
- if (aStyle != NOTHING)
- mode += doToggle;
- SetStyle( mode, &style, TRUE);
- }
-
- /********************************************************\
- SetFontStyleAll - set the font style of all of the text
- \********************************************************/
-
- void CWASTEText::SetFontStyleAll(short aStyle)
- {
- TempSelectAll();
- SetFontStyle(aStyle);
- RestoreSelection();
- }
-
- /********************************************************\
- SetFontSize - set the font size of the selection
- \********************************************************/
-
- void CWASTEText::SetFontSize(short aSize)
- {
- TextStyle style;
-
- style.tsSize = aSize;
- SetStyle( doSize, &style, TRUE);
- }
-
- /********************************************************\
- SetFontSizeAll - set the font size of all of the text
- \********************************************************/
-
- void CWASTEText::SetFontSizeAll(short aSize)
- {
- TempSelectAll();
- SetFontSize(aSize);
- RestoreSelection();
- }
-
- /********************************************************\
- SetTextMode - currently not implemented
- \********************************************************/
-
- void CWASTEText::SetTextMode(short aMode)
- {
- return;
- }
-
- /********************************************************\
- SetAlignment - set the alignment
- \********************************************************/
-
- void CWASTEText::SetAlignment(short anAlignment)
- {
- WESetAlignment(anAlignment, macWE);
- Refresh();
- }
-
- /********************************************************\
- SetAlignCmd - set the alignment
- \********************************************************/
-
- void CWASTEText::SetAlignCmd(long anAlignCmd)
- {
- short teAlign;
-
- alignCmd = anAlignCmd;
- switch( alignCmd)
- {
- case cmdAlignLeft:
- teAlign = weFlushLeft;
- break;
- case cmdAlignCenter:
- teAlign = weCenter;
- break;
- case cmdAlignRight:
- teAlign = weFlushRight;
- break;
- default:
- teAlign = weFlushDefault;
- }
- SetAlignment(teAlign);
- }
-
- /********************************************************\
- SetSpacingCmd - not really supported
- \********************************************************/
-
- void CWASTEText::SetSpacingCmd(long aSpacingCmd)
- {
- spacingCmd = cmdSingleSpace;
-
- // only single-spaced text is supported.
-
- SetWholeLines(wholeLines);
- CalcAperture();
- AdjustBounds();
-
- }
-
- /********************************************************\
- SetTheStyleScrap - set the style of a given range
- caller disposes handle
- \********************************************************/
-
- void CWASTEText::SetTheStyleScrap(long rangeStart, long rangeEnd,
- StScrpHandle styleScrap, Boolean redraw)
- {
- Boolean saveAllocState;
- OSErr err;
- long selStart, selEnd;
-
- Prepare();
- if (!ReallyVisible())
- SetOrigin(-10000, -10000);
- saveAllocState = SetAllocation(kAllocCanFail);
- WEGetSelection(&selStart, &selEnd, macWE);
- SetSelection(rangeStart, rangeEnd, FALSE);
- err = WEUseStyleScrap(styleScrap, macWE);
- if (err == noErr)
- {
- SetSelection(selStart, selEnd, false);
- err = WECalText( macWE);
- }
-
- SetAllocation(saveAllocState);
- AdjustBounds();
- FailOSErr(err);
- }
-
- /********************************************************\
- SetStyle - set the style of the current selection
- \********************************************************/
-
- void CWASTEText::SetStyle(short mode, TextStyle *newStyle, Boolean redraw)
- {
- Boolean saveAllocState;
- OSErr err;
-
- Prepare();
- if (!ReallyVisible())
- SetOrigin(-10000, -10000);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WESetStyle( mode, newStyle, macWE);
- SetAllocation(saveAllocState);
-
- if (err == noErr)
- {
- SetSpacingCmd( spacingCmd);
- SetWholeLines( wholeLines);
- }
- AdjustBounds();
- FailOSErr(err);
- }
-
- /********************************************************\
- GetHeight - get the height of the indicated lines
- \********************************************************/
-
- long CWASTEText::GetHeight(long startLine, long endLine)
- {
- long height;
- long nLines;
-
- nLines = GetNumLines();
- height = WEGetHeight( startLine - 1, endLine, macWE);
- if (endLine >= nLines && ((char*)(*GetTextHandle()))[GetLength()-1] == 13)
- height += WEGetHeight(nLines - 2, nLines - 1, macWE);
-
- return height;
- }
-
- /********************************************************\
- GetCharOffset - return offset of character at point in
- frame coords
- \********************************************************/
-
- long CWASTEText::GetCharOffset(LongPt *aPt)
- {
- Point qdPt;
- LongPt lPt;
- char edge;
-
- Prepare();
- FrameToQD( aPt, &qdPt);
- lPt.v = qdPt.v;
- lPt.h = qdPt.h;
-
- return WEGetOffset( &lPt, &edge, macWE);
-
- }
-
- /********************************************************\
- GetCharPoint - return the position of the character in
- Frame coordinates
- \********************************************************/
-
- void CWASTEText::GetCharPoint( long offset, LongPt *aPt)
- {
- Point qdPt;
- LongPt lPt;
- short lineHeight;
-
- ASSERT( offset <= MAXLONG);
-
- Prepare();
- WEGetPoint(offset, &lPt, &lineHeight, macWE);
- qdPt.h = lPt.h;
- qdPt.v = lPt.v;
- QDToFrame( qdPt, aPt);
- }
-
- /********************************************************\
- GetTextStyle - return style of selection
- \********************************************************/
-
- void CWASTEText::GetTextStyle(short *whichAttributes, TextStyle *aStyle)
- {
- WEContinuousStyle(whichAttributes, aStyle, macWE);
- }
-
- StScrpHandle CWASTEText::GetTextStyles(void)
- {
- OSErr err;
- StScrpHandle styles;
- Boolean saveAllocState;
-
- styles = (StScrpHandle) NewHandleCanFail(0);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECopyRange(0, WEGetTextLength(macWE), NULL, styles, macWE);
- SetAllocation(saveAllocState);
- if (err != noErr)
- {
- DisposeHandle((Handle) styles);
- FailOSErr(err);
- }
-
- return (styles);
- }
-
- /********************************************************\
- GetCharStyle - return style of one character
- \********************************************************/
-
- void CWASTEText::GetCharStyle(long charOffset, TextStyle *theStyle)
- {
- WERunInfo runInfo;
-
- WEGetRunInfo(charOffset, &runInfo, macWE);
- *theStyle = runInfo.runStyle;
- }
-
- /********************************************************\
- GetSpacingCmd - not really supported
- \********************************************************/
-
- long CWASTEText::GetSpacingCmd(void)
- {
- return spacingCmd;
- }
-
- /********************************************************\
- GetAlignCmd - not really supported
- \********************************************************/
-
- long CWASTEText::GetAlignCmd(void)
- {
- return alignCmd;
- }
-
- /********************************************************\
- GetTheStyleScrap -- get a scrap handle of the styles
- of the selection
- \********************************************************/
-
- StScrpHandle CWASTEText::GetTheStyleScrap(void)
- {
- Boolean saveAllocState;
- OSErr err;
- long selStart, selEnd;
- StScrpHandle h;
-
- WEGetSelection(&selStart, &selEnd, macWE);
-
- h=(StScrpHandle)NewHandleCanFail(1);
- FailNIL(h);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECopyRange(selStart, selEnd, (Handle)NULL, h, macWE);
- SetAllocation(saveAllocState);
- FailOSErr(err);
-
- return h;
- }
-
- /********************************************************\
- GetNumLines - return the number of lines
- \********************************************************/
-
- long CWASTEText::GetNumLines(void)
- {
- long nLines = WECountLines(macWE);
-
- if (!GetLength()) return 0;
- if (((char*)(*GetTextHandle()))[GetLength()-1] == 13)
- nLines++;
- return nLines;
- }
-
- /********************************************************\
- GetSelection - get the position of the start and end
- of the selection
- \********************************************************/
-
- void CWASTEText::GetSelection(long *selStart, long *selEnd)
- {
- WEGetSelection(selStart, selEnd, macWE);
- }
-
- /********************************************************\
- HideSelection - not implemented
- \********************************************************/
-
- void CWASTEText::HideSelection(Boolean hide, Boolean redraw)
- {
- return;
- }
-
- /********************************************************\
- GetSteps - get the size of the scrolling steps
- Step sizes hard coded in
- \********************************************************/
-
- void CWASTEText::GetSteps(short *hStep, short *vStep)
- {
- long nLines,
- height;
-
- nLines = GetNumLines();
- height = GetHeight(0, MAXINT);
- *hStep = 20;
- if (nLines)
- *vStep = Min(height / nLines, 30);
- else
- *vStep = height;
- }
-
- /********************************************************\
- AboutToPrint -- called right before printing
- \********************************************************/
-
- void CWASTEText::AboutToPrint(short *firstPage, short *lastPage)
- {
- if (active)
- {
- Prepare();
- HidePen();
- WEDeactivate(macWE);
- ShowPen();
- }
-
- CAbstractText::AboutToPrint(firstPage, lastPage);
- }
-
-
- void CWASTEText::Paginate(CPrinter *aPrinter, short pageWidth, short pageHeight)
- {
- Boolean saveAllocState;
- OSErr err;
- LongRect dr;
-
- WEGetDestRect(&dr, macWE);
- dr.right = dr.left + pageWidth;
- WESetDestRect(&dr, macWE);
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECalText(macWE);
- SetAllocation(saveAllocState);
- FailOSErr(err);
- printPageWidth = pageWidth;
-
- CAbstractText::Paginate(aPrinter, pageWidth, pageHeight);
- }
-
-
- /********************************************************\
- PrintPage -- called to print page
- \********************************************************/
-
- void CWASTEText::PrintPage(short pageNum, short pageWidth, short pageHeight,
- CPrinter *aPrinter)
- {
- OSErr err;
- short oldOffscreen,
- oldOutline;
-
- err = WESetInfo(wePort, (Ptr)&qd.thePort, macWE);
- // temporarily turn off off screen drawing and outline hiliting
- oldOffscreen = WEFeatureFlag(weFDrawOffscreen, weBitClear, macWE);
- oldOutline = WEFeatureFlag(weFOutlineHilite, weBitClear, macWE);
-
- // if (printClip == clipPAGE) { /* Expand viewRect to the size of a */
- // /* page. It will be restored by */
- // /* the DonePrinting() method. */
- // WEGetViewRect(&viewRect, macWE);
- // viewRect.right = viewRect.left + pageWidth;
- //
- // if (wholeLines) {
- // viewRect.bottom = viewRect.top +
- // vScale * (pageHeight / vScale);
- // } else {
- // viewRect.bottom = viewRect.top + pageHeight;
- // }
- // WESetViewRect(&viewRect, macWE);
- // }
-
- itsPrinter = aPrinter;
- CAbstractText::PrintPage(pageNum, pageWidth, pageHeight, aPrinter);
-
- err = WESetInfo(wePort, (Ptr)&macPort, macWE);
- WEFeatureFlag(weFDrawOffscreen, oldOffscreen, macWE);
- WEFeatureFlag(weFOutlineHilite, oldOutline, macWE);
- }
-
- /********************************************************\
- DonePrinting - called when printing is finished
- \********************************************************/
-
- void CWASTEText::DonePrinting()
- {
- Boolean saveAllocState;
- OSErr err;
-
- CAbstractText::DonePrinting();
-
- if (active)
- {
- Prepare();
- HidePen();
- WEActivate(macWE);
- ShowPen();
- }
-
- TCL_ASSERT(itsPrinter);
- itsPrinter->ResetPagination();
- itsPrinter = NULL;
-
- CalcWERects();
- if (lineWidth < 0)
- {
- saveAllocState = SetAllocation(kAllocCanFail);
- err = WECalText( macWE);
- SetAllocation(saveAllocState);
- }
- }
-
- /********************************************************\
- Dawdle - do idle stuff
- \********************************************************/
-
- void CWASTEText::Dawdle(long *maxSleep)
- {
- if (editable && visible)
- {
- Prepare();
- WEIdle(NULL, macWE);
- *maxSleep = GetCaretTime();
- }
- }
-
- /********************************************************\
- PutTo - not implemented
- \********************************************************/
-
- void CWASTEText::PutTo(CStream& stream)
- {
- return;
- }
-
- /********************************************************\
- GetFrom - not implemented
- \********************************************************/
-
- void CWASTEText::GetFrom(CStream& stream)
- {
- return;
- }
-
- /********************************************************\
- WEClickLoop - click loop routine
- \********************************************************/
-
- static pascal Boolean WEClickLoop(WEHandle hWE)
- {
- Point mouseLoc;
- LongPt longMouse;
-
- if (gWASTEText != NULL) {
- GetMouse(&mouseLoc);
- gWASTEText->QDToFrame(mouseLoc, &longMouse);
- gWASTEText->AutoScroll( &longMouse);
- }
- return(TRUE);
- }
-
- // static variables for the following routines
- static Boolean wasActive, outlineHilite;
- static long selStart, selEnd;
-
- /********************************************************\
- TempSelectAll -- temporarily selects all of the text
- while deactivating the text and turning off
- outline hilighting so that the selection won't show
- up. It can be restored by Restore selection. This
- is useful when you want to apply something to all
- of the text without seeing all of the text flash.
-
- Note: Calls to TempSelectAll/RestoreSelection cannot
- be nested
- \********************************************************/
-
- void CWASTEText::TempSelectAll(void)
- {
- // turn off outline highlighting temporarily
- outlineHilite = SetOutlineHighliting(false);
-
- // deactivate text
- wasActive = active;
- if (wasActive) Deactivate();
-
- // select all
- GetSelection(&selStart, &selEnd);
- SetSelection(0, 0x7FFFFFF, false);
- }
-
- /********************************************************\
- RestoreSelection - restores things to the way they
- were before a call to TempSelectAll()
- \********************************************************/
-
- void CWASTEText::RestoreSelection(void)
- {
- if (wasActive) Activate();
- SetOutlineHighliting(outlineHilite);
- SetSelection(selStart, selEnd, false);
- }
-
- /******************************************************************************
- Specify
-
- If editable is changed and it's active, enable/disable TSMInput
- ******************************************************************************/
-
- void CWASTEText::Specify(Boolean fEditable, Boolean fSelectable, Boolean fStylable)
- {
- Boolean wasEditable = editable;
- TSMDocumentID aTSMDocument;
-
- inherited::Specify(fEditable, fSelectable, fStylable);
-
- if (active && wasEditable && !editable)
- {
- // if not editable, deactivate TSM so inline input won't work
- if (gUsingTSM)
- {
- if (WEGetInfo(weTSMDocumentID, (Ptr)&aTSMDocument, macWE) == noErr)
- {
- if (aTSMDocument != NULL)
- DeactivateTSMDocument(aTSMDocument);
- }
- }
- }
-
- if (active && !wasEditable && editable)
- {
- // if not editable, deactivate TSM so inline input won't work
- if (gUsingTSM)
- {
- if (WEGetInfo(weTSMDocumentID, (Ptr)&aTSMDocument, macWE) == noErr)
- {
- if (aTSMDocument != NULL)
- ActivateTSMDocument(aTSMDocument);
- }
- }
- }
-
-
-
- }
-
-
-
-