home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 7.9 KB | 310 lines | [TEXT/MPS ] |
- // UDeskScrapView.cp
- // Copyright © 1985-1991 Apple Computer, Inc. All rights reserved.
-
- #ifndef __UDESKSCRAPVIEW__
- #include <UDeskScrapView.h>
- #endif
-
- #ifndef __STDIO__
- #include <Stdio.h>
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include <UClipboardMgr.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UMEMORY__
- #include <UMemory.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
-
- Boolean gVarClipPicSize; // declared in interface
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInit
- pascal void TDeskScrapView::Initialize(void) // override
- {
- inherited::Initialize();
-
- fDataHandle = NULL;
- fHavePicture = FALSE;
- fHaveText = FALSE;
- fScrapCount = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- pascal void TDeskScrapView::IDeskScrapView(void)
- {
- VPoint itsSize(200, 200);
- PScrapStuff aPtr;
-
- // Can't know the extent required until we actually read the data in, which we won't bother
- // to do unless forced to by receiving an Update event
-
- this->IView(NULL, NULL, gZeroVPt, itsSize, sizeVariable, sizeVariable);
-
- aPtr = InfoScrap();
- fScrapCount = aPtr->scrapCount - 1;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- pascal void TDeskScrapView::IRes(TDocument* itsDocument,
- TView* itsSuperView,
- Ptr& itsParams)// override
- {
- PScrapStuff aPtr;
-
- inherited::IRes(itsDocument, itsSuperView, itsParams);
-
- aPtr = InfoScrap();
- fScrapCount = (aPtr->scrapCount) - 1;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TDeskScrapView::Free(void) // override
- {
- // Never want to free gClipboardMgr->fClipOrphanage. What if some creates another view of this type?
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TDeskScrapView::CalcMinSize(VPoint& minSize)// override
- {
- VRect aVRect;
- Rect aRect;
- TEHandle aTEHandle;
- Handle oldHText;
-
- minSize = fSize;
- if (fDataHandle)
- if (fHaveText)
- {
- // TEXT
- if (this->Focus())
- {
- SetPortTextStyle(gSystemStyle);
- fSuperView->GetExtent(aVRect);
- aTEHandle = TENew(aVRect, aVRect);
- FailNIL((Ptr)aTEHandle);
-
- oldHText = (*aTEHandle)->hText; // We'll need this for TEDispose
- (*aTEHandle)->hText = fDataHandle;
-
- TECalText(aTEHandle);
-
- minSize.h = (short) aVRect.Length(hSel);
- minSize.v = Min(IntMultiply((*aTEHandle)->nLines, (*aTEHandle)->lineHeight), kMaxCoord);
- (*aTEHandle)->hText = oldHText; // So TEDispose doesn't dispose our handle
-
- TEDispose(aTEHandle);
- }
- }
- else
- {
- #if qDebugMsg
- if (gIntenseDebugging)
- {
- fprintf(stderr, "Picture Frame:");
- fprintf(stderr, "%s\n", (char *) ((**(PicHandle)fDataHandle).picFrame));
- }
- #endif
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- if (!gVarClipPicSize)
- {
- aRect = (**((PicHandle)fDataHandle)).picFrame;// WITH PicHandle(fDataHandle)^^.picFrame DO
- minSize[vhs] = aRect[botRight][vhs] - aRect[topLeft][vhs];
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal Boolean LookForScrapType(ResType theResType, ResType& resTypeFound)
- {
- long err;
- long offset;
-
- err = GetScrap(NULL, theResType, offset);
- if (err > 0)
- resTypeFound = theResType;
- #if qDebugMsg
- if ((err != noTypeErr) && (err < 0))
- fprintf(stderr, "LookForScrapType: err = %d\n", err);
- #endif
-
- return (err > 0);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TDeskScrapView::CheckScrapContents(void)
- {
- long length;
- long offset;
- Handle aHandle;
- ResType resTypeFound;
- Boolean savedPerm;
- FailInfo fi;
-
- VOLATILE(aHandle);
-
- if (fScrapCount != gClipboardMgr->fNewScrapStuff.scrapCount)
- {
- // Make sure we get rid of the old scrap handle if necessary
- fDataHandle = DisposeIfHandle(fDataHandle);
-
- fHavePicture = LookForScrapType('PICT', resTypeFound);
- fHaveText = LookForScrapType('TEXT', resTypeFound);
-
- if (fHavePicture || fHaveText)
- {
- aHandle = NULL;
- aHandle = NewPermHandle(0);
-
- if (fi.Try())
- {
- savedPerm = PermAllocation(TRUE);
- length = GetScrap(aHandle, resTypeFound, offset);
- savedPerm = PermAllocation(savedPerm);
-
- if (length < 0) // Only results < 0 are really errors
- FailOSErr((OSErr)length);
- fDataHandle = aHandle;
- this->AdjustSize();
- this->Focus(); // Make sure we're still focused
- fi.Success();
- }
- else // Recover
- {
- aHandle = DisposeIfHandle(aHandle);
- fDataHandle = NULL;
- fi.ReSignal();
- }
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TDeskScrapView::Draw(const VRect& area)
- {
- Rect aRect;
- SignedByte savedState;
-
- #if qDebug
- this->AssumeFocused();
- #endif
-
- // Has scrap been updated since we last drew?
- this->CheckScrapContents();
-
- if (fHaveText)
- {
- SetPortTextStyle(gApplicationStyle);
- this->GetQDExtent(aRect);
-
- // Does TextEdit handle failure in TextBox???
- savedState = LockHandleHigh(fDataHandle);// Because MATextBox may move memory
- MATextBox(*fDataHandle, GetHandleSize(fDataHandle), aRect, teFlushDefault, kAutoWrap, NULL, kNoEraseFirst, kNoSpaceForCaret);
- HSetState(fDataHandle, savedState);
- }
- else if (fHavePicture)
- {
- if (gVarClipPicSize)
- this->GetQDExtent(aRect);
- else
- {
- aRect = (**((PicHandle)fDataHandle)).picFrame;
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- aRect[botRight][vhs] = aRect[botRight][vhs] - aRect[topLeft][vhs];
- aRect[topLeft][vhs] = 0;
- }
- }
- DrawPicture((PicHandle)fDataHandle, aRect);
- }
-
- if (fScrapCount != (gClipboardMgr->fNewScrapStuff.scrapCount))
- {
- this->ValidateRect(aRect); // avoid flicker upon clipboard installation
- // -- but could this cause failure to update
- // frame border/appendages sometimes, if that
- // code ever checked for visibility before drawing ???
- fScrapCount = (gClipboardMgr->fNewScrapStuff.scrapCount);
- gClipboardMgr->fClipWrittenToDeskScrap = TRUE;// Don't need to write it back out.
- }
-
- inherited::Draw(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFields
-
- pascal void TDeskScrapView::Fields(TObject* obj)
- {
- obj->DoToField("TDeskScrapView", NULL, bClass);
- obj->DoToField("fHavePicture", &fHavePicture, bBoolean);
- obj->DoToField("fHaveText", &fHaveText, bBoolean);
- obj->DoToField("fScrapCount", &fScrapCount, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInspector
-
- pascal void TDeskScrapView::GetInspectorName(Str255& inspectorName)// override
- {
- if (this == gClipboardMgr->fClipView)
- inspectorName = "gClipboardMgr->fClipView";
- else if (this == gClipboardMgr->fClipOrphanage)
- inspectorName = "gClipboardMgr->fClipOrphanage";
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TDeskScrapView::SuperViewChangedSize(const VPoint& ,
- Boolean)// override
- {
- this->AdjustSize();
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TDeskScrapView::WriteToDeskScrap(void)// override
- {
- // This view represents data that's already written to the desk scrap
- }
-
-
-