home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ShPrpAcc.cpp
-
- Contains: Implemementation of Shell property accessor classes.
-
- Owned by: Eric House
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <15> 9/13/95 TÇ 1249149 FB2: Memory leak/crash fixes
- <14> 8/22/95 eeh 1230007: refbal-inspired cleanup
- <13> 8/15/95 TÇ 1262179 FB: Shell calls BlockMove() in many
- places
- <12> 7/25/95 DM #1270320: Memory leak fixes.
- <11> 6/30/95 TJ Included TempObj.h
- <10> 6/29/95 DM 1242642 BB: refcounting: release shapes in
- SetPropertyData(), comment out ifdef'd
- sections.
- <9> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <8> 5/26/95 TJ Changed Get to Aquire.
- <7> 5/7/95 TÇ 1155852 BB: String constants need to be
- moved to resource for Localization (mostly
- done)
- <6> 2/20/95 TÇ #1210979 BB: 5-$ Bugs need to be evaluated
- and removed from Shell
- <5> 9/23/94 VL 1155579, 1184272: Use StorUtil to
- create/get container and get its file.
- <4> 9/6/94 VL 1184177: Commented out draft::GetName and
- draft::SetName as they no longer exist.
- <3> 8/19/94 NP 1181622: Ownership fix.
- <2> 8/10/94 JBS 1179919: coordinate system bias changes
- <1> 6/30/94 TÇ first checked in
- <0> 6/29/94 SV SOMverted
- <4> 5/27/94 jpa New exception support [1165267]
- <3> 3/24/94 eeh bug# 1151750: scripting support for
- operations on draft
- <2> 2/16/94 JA Include new AltPoint.h.
- <10> 2/8/94 TÇ Throw -> THROW & some code clean up
- <9> 2/7/94 TÇ fixes to compile with PPC Headers
- <8> 1/11/94 eeh removed "frame" from objspec vocab
- <7> 12/17/93 eeh work on frame bounds property
- <6> 12/9/93 eeh added ShellSelfPropAccessor and
- ShellFramePropAccessor
- <5> 11/30/93 JA Rearranged #includes for new "frame"
- constant fix.
- <4> 11/22/93 SS Added typecasts for latest headers
- <3> 11/19/93 PH Fix declarations for braindead CFront
- <2> 11/15/93 eeh added GetPropertyData and SetPropertyData
- <1> 10/11/93 NP first checked in
-
- To Do:
-
- */
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" // Use C++ savvy ODPoint and ODRect
- #endif
-
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef _RLSHELL_
- #include <RlShell.h>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _SHPRPACC_
- #include "ShPrpAcc.h"
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef __RESOURCES__
- #include "Resources.h"
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef __STRING__
- #include <string.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #pragma segment ShPrpAcc
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- //==============================================================================
- // Local Classes
- //==============================================================================
-
- //==============================================================================
- // Global Variables
- //==============================================================================
-
- //==============================================================================
- // Function Prototype
- //==============================================================================
-
- //extern pascal void GetAppParms(Str255 apName, short *apRefNum, Handle *apParam)
- // ONEWORDINLINE(0xA9F5);
- /*
- CountAppFiles, GetAppFiles, ClrAppFiles, GetAppParms, and
- getappparms are obsolete. They are still supported for 68K
- apps (if OBSOLETE is defined), but they are not supported
- for PowerPC apps. Use AppleEvents to determine which files
- are to be opened or printed from the Finder.
- -- from "SegLoad.h"
- */
-
- //==============================================================================
- // ShellPropAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellPropAccessor::ShellPropAccessor
- //------------------------------------------------------------------------------
-
- ShellPropAccessor::ShellPropAccessor(DescType property, RealShell* shell)
- {
- #ifdef TO_BE_DELETED
- fProperty = property;
- fShell = shell;
- #endif /* TO_BE_DELETED */
- }
-
- //------------------------------------------------------------------------------
- // ShellPropAccessor::GetProperty
- //------------------------------------------------------------------------------
-
- DescType ShellPropAccessor::GetProperty()
- {
- #ifdef TO_BE_DELETED
- return fProperty;
- #endif /* TO_BE_DELETED */
- }
-
- //------------------------------------------------------------------------------
- // ShellPropAccessor::GetShell
- //------------------------------------------------------------------------------
-
- RealShell* ShellPropAccessor::GetShell()
- {
- #ifdef TO_BE_DELETED
- return fShell;
- #endif /* TO_BE_DELETED */
- }
-
-
- //==============================================================================
- // ShellSelfPropAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellSelfPropAccessor::ShellSelfPropAccessor
- //------------------------------------------------------------------------------
-
- ShellSelfPropAccessor::ShellSelfPropAccessor(DescType property, RealShell* shell):
- ShellPropAccessor(property, shell)
- {
- }
-
- //------------------------------------------------------------------------------
- // ShellSelfPropAccessor::GetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellSelfPropAccessor::GetPropertyData( AEDesc* result )
- {
- Environment* ev = somGetGlobalEnvironment();
- switch(fProperty)
- {
- case pBestType: // Return the null descriptor representing
- case pDefaultType: // the application.
- result->descriptorType = typeNull;
- result->dataHandle = NULL;
- break;
-
- case pClass:
- DescType theType = cApplication;
- THROW_IF_ERROR(AECreateDesc(typeType, (Ptr)&theType,
- sizeof(DescType), result));
- break;
-
- case pName:
- {
- TempPlatformFile file(GetPlatformFileFromContainer(ev,this->GetShell()->GetDocument()->GetContainer(ev)));
- TempODName name = file->GetName();
- TempODString tempname = GetCStringFromIText(name);
- THROW_IF_ERROR( AECreateDesc( typeChar, (char*)tempname,
- GetITextStringLength(name), result ) ) ;
-
- // delete tempname;
- // ODDisposePtr(tempname);
- // delete file;
- } break;
-
- case pIsFrontProcess:
- {
- ProcessSerialNumber curPSN = {0, kCurrentProcess}, myPSN;
- ODBoolean isFront;
- GetFrontProcess(&myPSN);
- SameProcess(&myPSN, &curPSN, &isFront);
- THROW_IF_ERROR(AECreateDesc(typeBoolean, (Ptr)&isFront,
- sizeof(Boolean), result));
- } break;
-
- case pVersion:
- {
- // ODSShort refNum = CurResFile();
- // UseResFile(this->GetShellResFile());
- Handle myHandle = (Handle)Get1Resource((ResType)'vers', 1);
- HLock(myHandle);
- OSErr err = AECreateDesc(typeVersion, *myHandle, GetHandleSize(myHandle),
- result);
- HUnlock(myHandle);
- // UseResFile(refNum); // reset back to resource previously set
- THROW_IF_ERROR(err);
- } break;
-
- default: // We don't handle the requested property.
- THROW(errAEEventNotHandled);
- }
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellSelfPropAccessor::SetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellSelfPropAccessor::SetPropertyData(AEDesc* data)
- {
- ODUnused(data);
- switch(fProperty)
- {
- case pBestType: // Return the null descriptor representing
- case pDefaultType: // the application.
- case pClass:
- case pName:
- case pIsFrontProcess:
- case pVersion:
- THROW(errAENotModifiable);
- default: // We don't handle the requested property.
- THROW(errAEEventNotHandled);
- }
- }
- #endif /* TO_BE_DELETED */
-
- //==============================================================================
- // ShellPartPropAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellPartPropAccessor::ShellPartPropAccessor
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- ShellPartPropAccessor::ShellPartPropAccessor(DescType property, RealShell* shell,
- ODFrame* frame):
- ShellPropAccessor(property, shell)
- {
- fFrame = frame;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellPartPropAccessor::GetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellPartPropAccessor::GetPropertyData(AEDesc* result)
- {
- Environment* ev = somGetGlobalEnvironment();
- switch(fProperty)
- {
- case pBounds:
- {
- TempODShape theShape = fFrame->AcquireFrameShape(ev, kODNULL);
- ODRect bounds;
- theShape->GetBoundingBox(ev, &bounds);
- Rect qdBounds;
- bounds.AsQDRect(qdBounds);
- THROW_IF_ERROR(AECreateDesc(typeQDRectangle, (Ptr)&qdBounds,
- sizeof(qdBounds), result));
- } break;
- default:
- THROW(errAEEventNotHandled);
- }
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellPartPropAccessor::SetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellPartPropAccessor::SetPropertyData(AEDesc* data)
- {
- Environment* ev = somGetGlobalEnvironment();
- switch(fProperty)
- {
- case pBounds:
- {
- ThrowIfCantCoerce(data, typeQDPoint);
- Rect r;
- ODBlockMove(*data->dataHandle, &r, sizeof(r));
-
- ODBoolean success;
- { TempODShape newShape = new ODShape; // DMc refcount
- ODRect xmpR = r;
- newShape->SetRectangle(ev, &xmpR);
- TempODShape resultShape = fFrame->RequestFrameShape(ev, newShape, kODNULL);
- success = newShape->IsSameAs(ev, resultShape);
- }
-
- if (!success)
- THROW(errAEEventNotHandled);
-
- } break;
- default:
- THROW(errAEEventNotHandled);
- }
- }
- #endif /* TO_BE_DELETED */
-
- //==============================================================================
- // ShellDraftPropAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellDraftPropAccessor::ShellDraftPropAccessor
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- ShellDraftPropAccessor::ShellDraftPropAccessor( DescType property, RealShell* shell,
- ODDraft* draft ):
- ShellPropAccessor(property, shell)
- {
- fDraft = draft;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellDraftPropAccessor::GetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellDraftPropAccessor::GetPropertyData(AEDesc* result)
- {
- Environment* ev = somGetGlobalEnvironment();
- switch(fProperty)
- {
- case pName:
- // {
- // ODDraftName name = fDraft->GetName(ev);
- // THROW_IF_ERROR( AECreateDesc( typeChar, (Ptr)name, strlen(name),
- // result ) ) ;
- // } break;
- default:
- THROW(errAEEventNotHandled);
- }
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellDraftPropAccessor::SetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellDraftPropAccessor::SetPropertyData(AEDesc* data)
- {
- Environment* ev = somGetGlobalEnvironment();
- switch(fProperty)
- {
- case pName:
- // {
- // ThrowIfCantCoerce(data, typeChar);
- // char theName[100] ;
-
- // <eeh> THIS IS NOT AN ISOSTRING!!! Perhaps we need to look
- // one up, or is this just something not to export?
-
- // long len = GetHandleSize( data->dataHandle ) ;
- // ODBlockMove( *data->dataHandle, theName, len ) ;
- // theName[len] = '\0' ;
- // fDraft->SetName(ev, (ODDraftName)theName ) ;
- // } break;
- default:
- THROW(errAEEventNotHandled);
- }
- }
- #endif /* TO_BE_DELETED */
-
- //==============================================================================
- // ShellFramePropAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellFramePropAccessor::ShellFramePropAccessor
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- // ShellFramePropAccessor::ShellFramePropAccessor(DescType property, RealShell* shell,
- // ODFrame* frame):
- // ShellPropAccessor(property, shell)
- // {
- // fFrame = frame;
- // }
- #endif // TO_BE_DELETED
-
- //------------------------------------------------------------------------------
- // ShellFramePropAccessor::GetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- // void ShellFramePropAccessor::GetPropertyData(AEDesc* result)
- // {
- // Environment* ev = somGetGlobalEnvironment();
- // switch(fProperty)
- // {
- // case pBounds:
- // {
- // ODShape* theShape = fFrame->GetFrameShape(ev);
- // ODRect bounds;
- // theShape->GetBoundingBox(ev, &bounds);
- // Rect qdBounds;
- // bounds.AsQDRect(qdBounds);
- // THROW_IF_ERROR(AECreateDesc(typeQDRectangle, (Ptr)&qdBounds,
- // sizeof(qdBounds), result));
- // } break;
- // default:
- // THROW(errAEEventNotHandled);
- // }
- // }
- #endif // TO_BE_DELETED
-
- //------------------------------------------------------------------------------
- // ShellFramePropAccessor::SetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- // void ShellFramePropAccessor::SetPropertyData(AEDesc* data)
- // {
- // Environment* ev = somGetGlobalEnvironment();
- // switch(fProperty)
- // {
- // case pBounds:
- // {
- // ThrowIfCantCoerce(data, typeQDPoint);
- // Rect r;
- // ODBlockMove(*data->dataHandle, &r, sizeof(r));
- //
- // ODShape* newShape = new ODShape;
- // ODRect xmpR = r;
- // newShape->SetRectangle(ev, &xmpR);
- // ODShape* resultShape = fFrame->RequestFrameShape(ev, newShape);
- // ODBoolean success = newShape->IsSameAs(ev, resultShape);
- // delete newShape;
- // delete resultShape;
- // if (!success)
- // THROW(errAEEventNotHandled);
- //
- // } break;
- // case kODPIsFrozen :
- // case kXMPPIsStationery :
- // case kODPView :
- //
- // default:
- // THROW(errAEEventNotHandled);
- // }
- // }
- #endif // TO_BE_DELETED
-
- //==============================================================================
- // ShellWinPropAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellWinPropAccessor::ShellWinPropAccessor
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- ShellWinPropAccessor::ShellWinPropAccessor(DescType property, RealShell* shell,
- ODWindow* window):
- ShellPropAccessor(property, shell)
- {
- fWindow = window;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellWinPropAccessor::GetName
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellWinPropAccessor::GetName(StringPtr name)
- {
- Environment* ev = somGetGlobalEnvironment();
- // WindowPeek window = (WindowPeek)fWindow->GetPlatformWindow(ev);
-
- GetWTitle(fWindow->GetPlatformWindow(ev), name);
- // CopyPascalString(name, *(window->titleHandle));
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellWinPropAccessor::GetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellWinPropAccessor::GetPropertyData(AEDesc* result)
- {
- Str255 name;
-
- Environment* ev = somGetGlobalEnvironment();
- switch(fProperty)
- {
- #ifdef TO_BE_DELETED
- case pPosition:
- Rect bounds;
- bounds=(**(((WindowRecord*)fWindow->GetPlatformWindow(ev))->contRgn))
- .rgnBBox;
- THROW_IF_ERROR(AECreateDesc(typeQDPoint, (Ptr)&bounds,
- sizeof(Point), result));
- break;
- #endif // TO_BE_DELETED
- case pBounds :
- Rect bounds=(**(((WindowRecord*)fWindow->GetPlatformWindow(ev))->contRgn))
- .rgnBBox;
- THROW_IF_ERROR(AECreateDesc(typeQDRectangle, (Ptr)&bounds,
- sizeof(bounds), result));
- break;
- case pName :
- this->GetName(name);
- THROW_IF_ERROR(AECreateDesc(typeChar, (Ptr)&name[1], name[0], result));
- break;
- default :
- THROW(errAENotAnElement); // really want "not a property"
- }
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellWinPropAccessor::SetPropertyData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellWinPropAccessor::SetPropertyData(AEDesc* data)
- {
- Environment* ev = somGetGlobalEnvironment();
- WindowPtr window = fWindow->GetPlatformWindow(ev);
- Str255 name;
- unsigned long len;
-
- switch(fProperty)
- {
- #ifdef TO_BE_DELETED
- case pPosition:
- Point upperLeft;
- ThrowIfCantCoerce(data, typeQDPoint);
- ODBlockMove(*(data->dataHandle), &upperLeft, sizeof(upperLeft));
- MoveWindow(window, upperLeft.h, upperLeft.v, false);
- InvalRect(&window->portRect);
- break;
- #endif // TO_BE_DELETED
-
- case pBounds :
- Rect bounds;
- ThrowIfCantCoerce(data, typeQDRectangle);
- ODBlockMove(*(data->dataHandle), &bounds, sizeof(bounds));
- MoveWindow(window, bounds.left, bounds.top, fWindow->IsActive(ev));
- SizeWindow(window, bounds.right - bounds.left,
- bounds.bottom - bounds.top, true);
- break;
-
- case pName :
- ThrowIfCantCoerce(data, typeChar);
- len = GetHandleSize(data->dataHandle);
- if (len >= 0xFF) THROW(errAECorruptData);
- ODBlockMove(*(data->dataHandle), &name[1], len);
- name[0] = (unsigned char)len;
- SetWTitle(window, name);
- break;
-
- default :
- THROW(errAENotAnElement); // really want "not a property"
- }
- }
- #endif /* TO_BE_DELETED */
-