home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAProxyPart.cpp
-
- Contains: CAProxyPart CALib proxy part editor class implementation.
- Built using PartMaker , then modified.
-
- Written by: Rick Badertscher, Tantek Çelik, Eric Soldan, Jens Alfke,
- AND PartMaker AND Steve Foley
-
- Change History (most recent first):
-
- <3> 11/18/95 RB Major strip down, Removed many obsolete methods
- <2> 11/10/95 RB Modified to keep storage unit refs to frames in
- kCAPropEmbeddedFrames instead of in kODPropContents
- <1> 6/15-6/30 RB Major rewrite.
-
- ------------------------------------------------------------------------------
- <36> 5/16/95 SJF Fix handle mouse down in border (HandleEvent)
- to change an activated frame to selected on a drag
- <32> 5/16/95 SJF Condense Frame negotiation callbacks into
- common subroutines in UTIL...
- <30> 5/15/95 RB Removing default "Container" behavior.
- Fixing up some exception handling code.
-
- <29> 5/12/95 RB Integrating new selection implementation.
- <28> 5/09/95 SJF Fixes to drag outline calculation
- <22> 5/06/95 SJF Drag & Drop support changes
- <21> 5/05/95 DAS fixed 1 declaration for MWC v6.0 scope rule change
- some minor cleanup
- <20> 4/23/95 RB Adding support for CA Focus transfer handlers
- <19> 4/23/95 SJF Splitting UTIL methods into CAProxyPartUTIL.cpp
- <18> 4/23/95 RB Fixing menu stuff
- <17> 4/22/95 RB Uncommented ProxyExtension allocation.
- <16> 4/19/95 RB A couple b1c18 mods. Commented out all
- enables in AdjustPartMenus except insert.
- <15+> 4/19/95 SJF Fix bug in AdjustPartMenus
- <15> 4/08/95 RB Major makeover. Fixed mouse event handling,
- Updated with new TFrameProxy class.
- <14> 4/7/95 SJF Change _CAProxyPart_ROOT_ to
- _ALLOCATE_STORAGE_
- <13> 4/05/95 RB More Fixes for b1c14. Temp commenting out exception
- handling code.
- <13> 4/04/95 RB Fixes for b1c14. Store all part values in
- the root SU (used to create an additional SU)
- <12> 4/02/95 RB Integrating changes for b1c14 build
- <11> 4/01/95 RB Adding support for CAWindowActivateHandler()
- <10> 3/31/95 RB Adding support for multiple root frames
- <9> 3/30/95 RB Mods to correctly handle first click behavior.
- Added method UTIL_HandleActivateEvent()
- <8> 3/15/95 SJF Merge in RickB's changes
- <7> 3/15/95 SJF Split Drag & Drop support methods out into
- another file (CAProxyPartDnD.cpp)
- <6> 2/28/95 SJF Inhibit drawing of the ProxyPart rectangle
- in ::Draw
- <4+> 2/28/95 SJF Turn off rectangle drawing in ::Draw method, add
- constant for ScrollBarOffset for rectangle calculations
- <4> 2/21/95 SJF fix include paths, incorporate RickB's changes
- <3> 2/13/95 SJF Interim checkin to update project database
- <0> 11/16/94 SJF first written
-
- To Do:
- */
-
- #ifndef _ALTPOINT_
- #include <AltPoint.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFacetIterator_xh
- #include <FacetItr.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined //•
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined //•
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitCursor_xh
- #include <SUCursor.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef SOM_ODStorageUnitRefIterator_xh
- #include <SURefItr.xh>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef SOM_CAProxyEmbeddedFramesIterator_xh
- #include "CAProxyEmFrI.xh"
- #endif
-
- #ifndef _CAPROXYPARTDEF_
- #include "CAProxyPartDef.h"
- #endif
-
- #ifndef _CAPROXYPART_
- #include "CAProxyPart.h"
- #endif
-
- #ifndef SOM_CAProxyExtension_xh
- #include "CAProxyExtension.xh"
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _ORDCOLL_
- #include <OrdColl.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _TEMPOBJL_
- #include <TempObj.h>
- #endif
-
- #ifndef _CAPROXYDEBUG_
- #include "CAProxyDebug.h"
- #endif
-
- //====================================================================
- // Miscellaneous
- //====================================================================
-
- //==============================================================================
- // Part Library Globals (shared across instances of the part)
- //==============================================================================
-
- #pragma segment CAProxyPart
-
-
- static ODUShort gGlobalsUsageCount = 0;
-
- static ODMenuBar* gMenuBar = kODNULL;
- static ODFocusSet* gUIFocusSet = kODNULL;
-
- static ODTypeToken gSelectionFocus = 0;
- static ODTypeToken gMenuFocus = 0;
- static ODTypeToken gModalFocus = 0;
- static ODTypeToken gKeyFocus = 0;
- static ODTypeToken gClipboardFocus = 0;
-
- //====================================================================
- // Constants
- //====================================================================
-
-
- //====================================================================
- // CAProxyPart
- //====================================================================
-
-
-
- CFrameInfo::CFrameInfo (Environment* ev, ODID frameID, ODDraft* draft)
- {
- fFrameID = frameID;
- fDraft = draft;
- fFrame = kODNULL;
- fEv = ev;
- }
-
- CFrameInfo::~CFrameInfo ()
- {
- ODReleaseObject (fEv, fFrame);
- }
-
- void CFrameInfo::Internalize(void)
- {
- if (fFrame == kODNULL)
- fFrame = fDraft->AcquireFrame (fEv, fFrameID);
-
- }
-
- void CFrameInfo::Externalize(ODStorageUnit* su)
- {
- ODStorageUnitRef value;
- ODSize streamSize;
-
- ODSUExistsThenFocus (fEv, su, kCAPropEmbeddedFrames, kODStrongStorageUnitRefs);
-
- streamSize = su->GetSize(fEv);
- su->SetOffset (fEv, streamSize);
-
- su->GetStrongStorageUnitRef(fEv, fFrameID, value);
- StorageUnitSetValue(su, fEv, kODStorageUnitRefLen, value);
- }
-
- ODFrame* CFrameInfo::GetFrame(void)
- {
- if (fFrame == kODNULL)
- {
- fFrame = fDraft->AcquireFrame (fEv, fFrameID);
- }
-
- return (fFrame);
- }
-
- void CFrameInfo::Close(void)
- {
- fFrame->Close(fEv);
- fFrame = kODNULL;
- }
-
- void CFrameInfo::Remove(void)
- {
- fFrame->Remove(fEv);
- fFrame = kODNULL;
- }
-
- ODID CFrameInfo::GetID(void)
- {
- return fFrameID;
- }
-
- CDisplayFrameInfo::CDisplayFrameInfo (Environment* ev, ODFrame* frame)
- {
- fFrameID = frame->GetID(ev);
- fFrame = frame;
- fEv = ev;
- frame->Acquire(ev);
- }
-
- CDisplayFrameInfo::~CDisplayFrameInfo ()
- {
- ODReleaseObject (fEv, fFrame);
- }
-
- //--------------------------------------------------------------------
- // CAProxyPart::CAProxyPart
- //--------------------------------------------------------------------
-
- CAProxyPart::CAProxyPart( void )
- {
- #if TRACING
- InitTracing(NULL, false);
- #endif
-
- fDirty = kODFalse;
- fCADocumentRef = kODNULL;
- fActiveFrame = kODNULL;
- fSelf = kODNULL;
- fDisplayFrame = kODNULL;
- fEmbeddedFrames = kODNULL;
- fActiveBorderShape = kODNULL;
-
- fProxyExt = kODNULL;
-
- fCADnDTrackHnd = kODNULL;
- fTrackRefCon = kODNULL;
- fCADnDReceiveHnd = kODNULL;
- fReceiveRefCon = kODNULL;
-
- fCAWindowActivateHandler = kODNULL;
- fCAFocusAquiredHandler = kODNULL;
- fCAFocusLostHandler = kODNULL;
- fCAAdjustBorderHandler = kODNULL;
- fCAAdjustBorderHook = kODNULL;
- fCAFrameShapeRequestHandler = kODNULL;
- fCAFrameShapeRequestHook = kODNULL;
-
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::~CAProxyPart
- //--------------------------------------------------------------------
-
- CAProxyPart::~CAProxyPart( void )
- {
- ODDeleteObject (fProxyExt);
-
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::AbortRelinquishFocus
- //-------------------------------------------------------------------------
-
- void CAProxyPart::AbortRelinquishFocus(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- ODUnused(ev);
- ODUnused(focus);
- ODUnused(ownerFrame);
- ODUnused(proposedFrame);
- // •• 6/23/94
- // Being here means that BeginRelinquishFocus said no to one of the foci.
- // You are being informed of this because you may have already taken action
- // based on a previous focus. Note that if foci are managed as a set, if
- // BeginRelinquishFocus says false to any of the foci, then no action is
- // taken. If however the foci are tested one at a time, it is possible that
- // the part has already taken action based on the first foci, and therefore
- // needs to undo something once a foci says no thanks.
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::AdjustBorderShape
- //--------------------------------------------------------------------
-
- ODShape* CAProxyPart::AdjustBorderShape(Environment* ev, ODFacet* embeddedFacet, ODShape* shape)
-
- // Adjusts the shape of the active frame border of an embedded
- // frame.
- //
- // Called by the arbitrator object.
- //
- // The “shape” parameter specifies the requested shape. The
- // return value specifies that shape as it is obscured by the
- // other contents of this part.
-
- {
- ODTransform* xform = kODNULL;
- ODFacet* rootFacet;
-
- if ( embeddedFacet == kODNULL )
- THROW(kODErrIllegalNullInput); // $$$$$ kODErrIllegalNullFacetInput
-
- ODReleaseObject (ev, fActiveBorderShape);
-
- if (shape != kODNULL)
- {
-
- if (fCAAdjustBorderHook && fCAAdjustBorderHandler)
- {
-
- fCAAdjustBorderHook ( fCAAdjustBorderHandler,
- fSelf->GetStorageUnit(ev)->GetDraft(ev),
- embeddedFacet->GetFrame(ev),
- shape);
-
-
- }
-
- ODAcquireObject(ev, shape);
-
- xform = embeddedFacet->AcquireWindowFrameTransform(ev, kNoBias);
-
- fActiveBorderShape = shape->Copy(ev);
- fActiveBorderShape->Transform (ev, xform);
-
- ODRelease (ev, xform);
-
- }
-
-
- rootFacet = embeddedFacet;
- if (rootFacet->GetContainingFacet(ev) != kODNULL)
- {
- rootFacet = rootFacet->GetContainingFacet(ev);
- }
-
-
- return shape;
-
- }
-
- //--------------------------------------------------------------------
- // CAProxyPart::AdjustMenus
- //--------------------------------------------------------------------
-
- void CAProxyPart::AdjustMenus(Environment* ev, ODFrame* frame)
- {
- ODUnused (ev);
- ODUnused (frame);
-
- }
-
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::BeginRelinquishFocus
- //-------------------------------------------------------------------------
-
- ODBoolean CAProxyPart::BeginRelinquishFocus(Environment* ev, ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- ODUnused(ev);
- ODUnused(ownerFrame);
- ODUnused(focus);
- ODUnused(proposedFrame);
-
- return kODTrue;
- }
-
- //-------------------------------------------------------------------------
- // Imaging protocol
- //-------------------------------------------------------------------------
-
- void CAProxyPart::CanvasUpdated(Environment* ev, ODCanvas* canvas)
-
- {
- if (this->fCACanvasUpdatedHandler)
- {
- CallUniversalProc(fCACanvasUpdatedHandler, uppCACanvasUpdatedProcInfo,
- canvas->GetQDPort(ev));
- }
- }
-
-
- //-------------------------------------------------------------------------
- // Storage protocol
- //-------------------------------------------------------------------------
-
- void CAProxyPart::CloneInto(Environment* ev, ODDraftKey key,
- ODStorageUnit* toSU, ODFrame* scope)
-
-
- {
- ODID scopeID = 0;
-
- if (scope)
- scopeID = scope->GetID(ev);
-
- // Clone our SU
- fSelf->GetStorageUnit(ev)->CloneInto (ev, key, toSU, scopeID);
-
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::CommitRelinquishFocus
- //-------------------------------------------------------------------------
-
- void CAProxyPart::CommitRelinquishFocus(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
-
- ODUnused(proposedFrame);
-
-
- if ( (focus == gSelectionFocus)) // && fEmbeddedFrames->Contains (proposedFrame))
- {
-
-
- //ODAcquireObject (ev, proposedFrame);
- //fActiveFrame = proposedFrame;
-
- }
-
- this->FocusLost(ev, focus, ownerFrame);
- // •• 6/23/94
- // No choices to be made here. It's too late to say no. We are
- // losing the focus if we are here. Getting called here means
- // that BeginRelinquishFocus has already agreed that losing focus
- // is okay. If you don't want this to be happening, then you need
- // to do something in BeginRelinquishFocus.
- //
- // The way that some other samples are currently written I believe
- // to be in error. The recipes say that when this is called, it
- // has already been decided that, focus-wise, you lose. Therefore
- // there should be no conditions on calling FocusLost.
- }
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::CreateEmbeddedFramesIterator
- //-------------------------------------------------------------------------
-
- ODEmbeddedFramesIterator* CAProxyPart::CreateEmbeddedFramesIterator(Environment *ev,
- ODFrame* frame)
- {
-
- CAProxyEmbeddedFramesIterator* iter = new CAProxyEmbeddedFramesIterator;
- iter->InitEmbeddedFramesIterator(ev, (ODPart*) this);
-
- return iter;
- }
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::DisplayFrameAdded
- //-------------------------------------------------------------------------
-
- void CAProxyPart::DisplayFrameAdded(Environment *ev,
- ODFrame* frame)
- {
-
- OrderedCollectionIterator* iter;
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
- CFrameInfo* frameInfo;
-
- iter = fEmbeddedFrames->CreateIterator();
-
- for (frameInfo = (CFrameInfo*)iter->First();
- iter->IsNotComplete();
- frameInfo = (CFrameInfo*)iter->Next())
- {
- frameInfo->GetFrame()->SetContainingFrame(ev, frame);
- }
-
- ODDeleteObject (iter);
-
- CDisplayFrameInfo* displayFrameInfo = new CDisplayFrameInfo (ev, frame);
-
- //frameInfo->Internalize();
- //frameInfo->Externalize(fSelf->GetStorageUnit(ev)); // Keep a su ref for the root frame with the other frame refs
- fDisplayFrame = displayFrameInfo;
-
- if (frame->GetViewType(ev) == kODNullTypeToken) // if frame view is set don't change it
- frame->SetViewType(ev, session->Tokenize(ev, kODViewAsFrame)); // if not, make it viewasframe
- if (frame->GetPresentation(ev) == kODNullTypeToken)
- frame->SetPresentation(ev, session->Tokenize(ev, kCAProxyPartPresNormal));
-
- PartInfo* partInfo = new PartInfo;
- fDisplayFrame->GetFrame()->SetPartInfo (ev, (ODInfoType) partInfo);
-
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::DisplayFrameClosed
- //-------------------------------------------------------------------------
-
- void CAProxyPart::DisplayFrameClosed(Environment* ev, ODFrame* frame)
-
- // Informs a part that one of its display frames is closing.
- //
- // Called by the frame object.
- // The part should remove “frame” from its list of display frames,
- // call Frame::Close() on any frames that are embedded within that
- // frame, and then release the frame.
-
- {
-
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
- OrderedCollectionIterator* iter;
- CFrameInfo* frameInfo;
-
- session->GetArbitrator(ev)->RelinquishFocusSet(ev, gUIFocusSet, frame);
-
- frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
-
- iter = fEmbeddedFrames->CreateIterator();
-
- for (frameInfo = (CFrameInfo*)iter->First();
- iter->IsNotComplete();
- frameInfo = (CFrameInfo*)iter->Next())
- {
- frameInfo->Close();
- }
-
- ODDeleteObject (iter);
-
- PartInfo* partInfo = (PartInfo*) fDisplayFrame->GetFrame()->GetPartInfo(ev);
- fDisplayFrame->GetFrame()->SetPartInfo (ev, (ODInfoType) kODNULL);
- ODDeleteObject (partInfo);
-
- if (frame != fDisplayFrame->GetFrame())
- DebugStr ("\p CAProxyPart::DisplayFrameClosed - close what?");
-
- ODDeleteObject (fDisplayFrame);
- fDisplayFrame = NULL;
-
- }
-
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::DisplayFrameConnected
- //-------------------------------------------------------------------------
-
- void CAProxyPart::DisplayFrameConnected( Environment* ev,
- ODFrame* frame )
- {
-
- CFrameInfo* frameInfo;
- OrderedCollectionIterator* iter;
-
- if ((fDisplayFrame) && (fDisplayFrame->GetFrame() != frame))
- {
- DebugStr ("\pUnknown displayframe connected");
- }
-
- if (!fDisplayFrame)
- {
- fDisplayFrame = new CDisplayFrameInfo (ev, frame);
- }
-
- iter = fEmbeddedFrames->CreateIterator();
-
- for (frameInfo = (CFrameInfo*)iter->First();
- iter->IsNotComplete();
- frameInfo = (CFrameInfo*)iter->Next())
- {
- frameInfo->GetFrame()->SetContainingFrame(ev, frame);
- }
-
- ODDeleteObject (iter);
-
-
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::DisplayFrameRemoved
- //-------------------------------------------------------------------------
-
- void CAProxyPart::DisplayFrameRemoved(Environment *ev,
- ODFrame* frame)
- {
- CFrameInfo* frameInfo;
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
-
- session->GetArbitrator(ev)->RelinquishFocusSet(ev, gUIFocusSet, frame);
-
- frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
-
- while (frameInfo != kODNULL)
- {
-
- fEmbeddedFrames->Remove(frameInfo);
- frameInfo->Remove();
- delete frameInfo;
- frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
-
- }
-
- if (frame != fDisplayFrame->GetFrame())
- DebugStr ("\p CAProxyPart::DisplayFrameClosed error");
-
- PartInfo* partInfo = (PartInfo*) fDisplayFrame->GetFrame()->GetPartInfo(ev);
- fDisplayFrame->GetFrame()->SetPartInfo (ev, (ODInfoType) kODNULL);
- ODDeleteObject (partInfo);
-
- ODDeleteObject (fDisplayFrame);
- fDisplayFrame = NULL;
-
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::Draw
- //--------------------------------------------------------------------
-
- void CAProxyPart::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- ODUnused(ev);
- ODUnused(facet);
- ODUnused(invalidShape);
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::ExternalizeKinds
- //--------------------------------------------------------------------
-
- void CAProxyPart::ExternalizeKinds(Environment* ev, ODTypeList* kindList)
- {
- ODUnused(ev);
- ODUnused(kindList);
- }
-
-
-
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::Externalize
- //--------------------------------------------------------------------
-
- void CAProxyPart::Externalize(Environment* ev)
- {
-
- // Flag our part as no longer being dirty.
-
- if ( fDirty && !fReadOnlyStorage)
- fDirty = kODFalse;
-
- }
-
- //-------------------------------------------------------------------------
- // Facet protocol
- //-------------------------------------------------------------------------
-
- void CAProxyPart::FacetAdded(Environment* ev, ODFacet* facet)
- {
-
- // Add new facet to list of current facets.
- fFacets.Add(facet);
-
- }
-
-
- void CAProxyPart::FacetRemoved(Environment* ev, ODFacet* facet)
- {
-
- fFacets.Remove(facet);
- // This just removes the reference from our facet list.
-
- OrderedCollection* children = new OrderedCollection;
- ODFacetIterator* facets = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
- ODFacet* childFacet;
- for (childFacet = facets->First(ev);
- facets->IsNotComplete(ev);
- childFacet = facets->Next(ev))
- {
- children->AddLast(childFacet);
- }
- delete facets;
-
- OrderedCollectionIterator iter(children);
- for (childFacet = (ODFacet*)iter.First();
- iter.IsNotComplete();
- childFacet = (ODFacet*)iter.Next())
- {
- facet->RemoveFacet(ev, childFacet);
- delete childFacet;
- }
- delete children;
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::FocusAcquired
- //-------------------------------------------------------------------------
-
- void CAProxyPart::FocusAcquired(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame)
- {
- ODUnused(ev);
- ODUnused(ownerFrame);
-
- PartInfo* partInfo;
-
- if (focus == gSelectionFocus)
- {
- partInfo = (PartInfo*) ownerFrame->GetPartInfo(ev);
- partInfo->SetFrameActive (kODTrue);
- }
-
- if (fCAFocusAquiredHandler)
- {
- if (focus == gSelectionFocus)
- {
- CallUniversalProc(fCAFocusAquiredHandler, uppCAFocusAcquiredProcInfo,
- fCADocumentRef, kCAPrimaryFocus);
- }
- }
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::FocusLost
- //-------------------------------------------------------------------------
-
- void CAProxyPart::FocusLost(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame)
- {
- ODUnused(ev);
- ODUnused(ownerFrame);
-
- PartInfo* partInfo;
- ODFrame* focusFrame = kODNULL;
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
-
- if (focus == gSelectionFocus)
- {
- partInfo = (PartInfo*) ownerFrame->GetPartInfo(ev);
- partInfo->SetFrameActive (kODFalse);
-
- if (fCAFocusLostHandler)
- {
-
- CallUniversalProc(fCAFocusLostHandler, uppCAFocusLostProcInfo,
- fCADocumentRef, kCAPrimaryFocus);
-
- }
-
- }
-
-
- }
-
- //-------------------------------------------------------------------------
- // CAProxyPart::FrameShapeChanged
- //-------------------------------------------------------------------------
-
- void CAProxyPart::FrameShapeChanged(Environment* ev, ODFrame* frame)
- {
-
- ODFacet* rootFacet;
- ODWindow* window;
- ODShape* clipShape;
-
- window = frame->AcquireWindow(ev);
- rootFacet = window->GetRootFacet(ev);
- ODReleaseObject (ev, window);
-
- if (rootFacet)
- {
- clipShape = ODCopyAndRelease (ev, frame->AcquireFrameShape(ev, kODNULL));
-
- rootFacet->ChangeGeometry (ev, clipShape, kODNULL, kODNULL);
- ODReleaseObject (ev, clipShape);
- }
- }
-
-
- //-------------------------------------------------------------------------
- // UI Events protocol
- //-------------------------------------------------------------------------
-
- ODBoolean CAProxyPart::HandleEvent(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet, ODEventInfo* eventInfo)
- {
-
- ODBoolean tWasHandled = kODFalse;
-
- fLastEventInfo = *eventInfo;
-
- switch ( event->what )
- {
- case nullEvent:
- break;
-
- case mouseDown:
- break;
-
- case mouseUp:
- case keyDown:
- case autoKey:
- tWasHandled = kODFalse;
- break;
-
- case kODEvtActivate:
- tWasHandled = this->UTIL_HandleActivateEvent (ev, frame, event);
- break;
-
- case kODEvtMenu:
- break;
-
- case kODEvtMouseDownEmbedded:
- break;
-
- case kODEvtMouseDownBorder:
- break;
-
- case kODEvtMouseUpEmbedded:
- break;
-
- case kODEvtBGMouseDownEmbedded:
- break;
-
- default:
- break;
- }
-
- return tWasHandled;
-
- }
-
- void CAProxyPart::HighlightChanged(Environment* ev, ODFacet* facet)
- {
- ODUnused(ev);
- ODUnused(facet);
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::InitPart
- //--------------------------------------------------------------------
-
- void CAProxyPart::InitPart(Environment* ev, ODStorageUnit* storageUnit, ODPart* partWrapper)
- {
- fSelf = partWrapper;
- fReadOnlyStorage = kODFalse;
-
- this->UTIL_CleanseContentProperty (ev, storageUnit);
- this->UTIL_CheckAndAddProperties (ev, storageUnit);
- this->UTIL_CommonInitPart (ev);
- this->UTIL_SetDirty (ev);
-
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::InitPartFromStorage
- //--------------------------------------------------------------------
-
- void CAProxyPart::InitPartFromStorage(Environment* ev, ODStorageUnit* storageUnit, ODPart* partWrapper)
- {
-
- fSelf = partWrapper;
- fReadOnlyStorage = ( storageUnit->GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly );
-
- this->UTIL_CommonInitPart(ev);
- this->UTIL_InternalizeContent (ev, storageUnit);
- this->UTIL_SetDirty (ev);
-
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::Open
- //--------------------------------------------------------------------
-
- ODID CAProxyPart::Open(Environment* ev, ODFrame* frame)
- {
- ODUnused (ev);
- ODUnused (frame);
-
- return (0);
- }
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::Purge
- //-------------------------------------------------------------------------
-
- ODSize CAProxyPart::Purge(Environment* ev, ODSize size)
- {
- ODUnused(ev);
- ODUnused(size);
-
- return 0L;
- }
-
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::Release
- //-------------------------------------------------------------------------
-
- void CAProxyPart::Release(Environment* ev)
- {
-
- if (fSelf->GetRefCount(ev) == 1)
- return;
- if (fSelf->GetRefCount(ev) == 0)
- fSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleasePart(ev, fSelf);
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::ReleaseAll
- //--------------------------------------------------------------------
-
- void CAProxyPart::ReleaseAll(Environment* ev)
- {
-
- CFrameInfo* frameInfo;
-
- TRY
-
- if (fEmbeddedFrames)
- {
-
- frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
-
- while (frameInfo != kODNULL)
- {
-
- fEmbeddedFrames->Remove(frameInfo);
- //frameInfo->GetFrame()->Release(ev);
- delete frameInfo;
- frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
-
- }
-
- }
-
- ODDeleteObject (fEmbeddedFrames);
- ODDeleteObject (fDisplayFrame);
-
- ODFinalReleaseObject (ev, fProxyExt);
- ODFinalReleaseObject (ev, fActiveBorderShape);
-
- // If the last part instance using the globals is released,
- // we need to NULL out the globals.
-
- if ( --gGlobalsUsageCount == 0 )
- {
- // We can't delete the MenuBar because it is shared by multiple
- // clients, and we're not going to assume they are done with it.
- gMenuBar = kODNULL;
-
- // On the other hand, the FocusSet is not shared and deleting it
- // is the right thing to do.
- if ( gUIFocusSet )
- {
- delete gUIFocusSet;
- gUIFocusSet = kODNULL;
- }
- }
-
- SOM_ENDTRY
-
-
- }
-
-
- //------------------------------------------------------------------------------
- // CAProxyPart::RemoveEmbeddedFrame
- //------------------------------------------------------------------------------
-
- void CAProxyPart::RemoveEmbeddedFrame(Environment *ev,
- ODFrame* embeddedFrame)
- {
- ODFrame* containingFrame;
- ODFrameFacetIterator* facets;
- ODFacet* embFacet;
- CFrameInfo* targetFrameInfo = kODNULL;
-
- containingFrame = embeddedFrame->AcquireContainingFrame(ev);
-
- facets = embeddedFrame->CreateFacetIterator(ev);
-
- for (embFacet = facets->First(ev);
- facets->IsNotComplete(ev);
- embFacet = facets->Next(ev))
- {
- ODDeleteObject (embFacet);
- }
-
- ODDeleteObject (facets);
-
- targetFrameInfo = this->UTIL_FindFrameInfoForFrame (ev, embeddedFrame);
-
- if (targetFrameInfo)
- {
- fEmbeddedFrames->Remove(targetFrameInfo);
- embeddedFrame->Remove(ev);
- delete targetFrameInfo;
- }
-
- containingFrame->Release(ev);
-
- }
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::RequestFrameShape
- //-------------------------------------------------------------------------
-
- ODShape* CAProxyPart::RequestFrameShape(Environment *ev,
- ODFrame* embeddedFrame,
- ODShape* frameShape)
- {
- ODShape* shapeCopy;
-
- shapeCopy = frameShape->Copy(ev);
-
- if (fCAFrameShapeRequestHandler && fCAFrameShapeRequestHook)
- {
-
- fCAFrameShapeRequestHook ( fCAFrameShapeRequestHandler,
- fSelf->GetStorageUnit(ev)->GetDraft(ev),
- embeddedFrame, shapeCopy);
- }
-
- return shapeCopy;
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::UsedShapeChanged
- //--------------------------------------------------------------------
-
- void CAProxyPart::UsedShapeChanged(Environment *ev,
- ODFrame* embeddedFrame)
- {
- TempODFrame containingFrame = embeddedFrame->AcquireContainingFrame(ev);
- embeddedFrame->Invalidate (ev, kODNULL, kODNULL);
- }
-
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_CleanseContentProperty
- //--------------------------------------------------------------------
-
- void CAProxyPart::UTIL_CleanseContentProperty( Environment* ev,
- ODStorageUnit* storageUnit)
- {
- ODULong numValues;
- ODULong index;
-
- if (storageUnit->Exists (ev, kODPropContents, kODNULL, kODPosFirstSib))
- {
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, 0, kODPosAll);
-
- numValues = storageUnit->CountValues(ev);
-
- for (index = numValues; index >= 1; index--)
- {
- // Index from 1 to n through the values.
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, index, kODPosUndefined);
- storageUnit->Remove(ev);
-
- }
-
- }
-
- }
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_CheckAndAddProperties
- //--------------------------------------------------------------------
-
- void CAProxyPart::UTIL_CheckAndAddProperties( Environment* ev,
- ODStorageUnit* storageUnit )
- {
-
- // Create our content property and preferred content property kind.
-
- if ( !storageUnit->Exists(ev, kCAPropEmbeddedFrames, kODNULL, 0) )
- storageUnit->AddProperty(ev, kCAPropEmbeddedFrames);
- if (!storageUnit->Exists (ev, kCAPropEmbeddedFrames, kODNULL, 1))
- storageUnit->AddValue(ev, kODStrongStorageUnitRefs);
-
- // Only add a kCAProxyPartKind value if the kODPropContents property
- // is empty
-
- // Add our display frame list.
-
- if ( !storageUnit->Exists(ev, kODPropDisplayFrames, kODNULL, 0) )
- storageUnit->AddProperty(ev, kODPropDisplayFrames);
- if ( !storageUnit->Exists(ev, kODPropDisplayFrames, kODWeakStorageUnitRefs, 0) )
- storageUnit->AddValue(ev, kODWeakStorageUnitRefs);
-
- if ( !storageUnit->Exists(ev, kODPropPreferredKind, kODNULL, 0) )
- storageUnit->AddProperty(ev, kODPropPreferredKind);
- if ( !storageUnit->Exists(ev, kODPropPreferredKind, kODISOStr, 0) )
- {
- storageUnit->AddValue(ev, kODISOStr);
-
- // Since we are setting up the preferred kind property, we just write
- // out our default "kind" for the editor. We can write out the user
- // chosen kind in the ExternalizeStateInfo method.
-
- TRY
- StorageUnitSetValue(storageUnit, ev, ODISOStrLength(kCAProxyPartKind) + 1,
- kCAProxyPartKind);
- SOM_ENDTRY
- }
-
- // Parts by default have no name, though one is visible from
- // the part info dialog and is required during Drag&Drop to the
- // Finder. We check for existence of the name property. If there
- // is none, we add it; if there is, we focus to it.
-
- if ( !storageUnit->Exists(ev, kODPropName, kODMacIText, 0) )
- {
- storageUnit->AddProperty(ev, kODPropName)->AddValue(ev, kODMacIText);
-
- // Generate a default name for the part using the category
- // user string.
- ODIText* defaultName;
-
- defaultName = CreateITextCString (smRoman, langEnglish, kCAProxyPartKindUserString);
-
- ODSetITextProp(ev, storageUnit, kODPropName, kODMacIText, defaultName);
-
- }
-
-
- }
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_InternalizeContent
- //--------------------------------------------------------------------
-
- void CAProxyPart::UTIL_InternalizeContent( Environment* ev,
- ODStorageUnit* storageUnit)
- {
-
- ODStorageUnitRef aSURef;
- ODID frameID;
- ODStorageUnitRefIterator* frameIter;
- CFrameInfo* frameInfo;
- ODSize size;
- ODStorageUnitRef ref;
-
- if (!storageUnit->Exists (ev, kCAPropEmbeddedFrames, kODStrongStorageUnitRefs, 0))
- DebugStr ("\pCAProxyPart::UTIL_InternalizeContent - no embedded frames");
-
- ODSUExistsThenFocus (ev, storageUnit, kCAPropEmbeddedFrames, kODStrongStorageUnitRefs);
-
- ODSize streamSize = storageUnit->GetSize(ev);
-
- frameIter = storageUnit->CreateStorageUnitRefIterator (ev);
-
- for (frameIter->First(ev, aSURef);
- frameIter->IsNotComplete(ev);
- frameIter->Next(ev, aSURef))
- {
-
- frameID = storageUnit->GetIDFromStorageUnitRef (ev, aSURef);
- frameInfo = new CFrameInfo (ev, frameID, storageUnit->GetDraft(ev));
- frameInfo->Internalize();
-
- TRACE (3, "InteralizeContent - frame %x, frameID %d, ref %x",
- frameInfo->GetFrame(), frameID, *aSURef);
-
- fEmbeddedFrames->AddLast (frameInfo);
-
- }
-
- ODDeleteObject (frameIter);
-
-
- }
-
-
-
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_FindFrameInfoForFrame
- //--------------------------------------------------------------------
-
- CFrameInfo* CAProxyPart::UTIL_FindFrameInfoForFrame( Environment *ev, ODFrame* frame)
- {
-
- CFrameInfo* frameInfo = kODNULL;
- CFrameInfo* targetFrameInfo = kODNULL;
- OrderedCollectionIterator* iter;
-
- iter = fEmbeddedFrames->CreateIterator();
-
- for (frameInfo = (CFrameInfo*)iter->First();
- iter->IsNotComplete();
- frameInfo = (CFrameInfo*)iter->Next())
- {
- if (frameInfo->GetFrame() == frame)
- {
- targetFrameInfo = frameInfo;
- break;
- }
-
- }
-
- ODDeleteObject (iter);
-
- return (targetFrameInfo);
-
-
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_ActivateDisplayFrame
- //--------------------------------------------------------------------
-
- void CAProxyPart::UTIL_ActivateDisplayFrame(Environment *ev,
- ODFrame* frame)
- {
- ODMenuBar* menuBar = kODNULL;
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
-
-
- PartInfo* partInfo = (PartInfo*) frame->GetPartInfo(ev);
-
- if (!partInfo->IsFrameActive())
- {
- // Request the set of foci necessary to become active.
- if ( session->GetArbitrator(ev)->RequestFocusSet(ev, gUIFocusSet, frame) )
- {
-
- // Notify ourself that we acquired the selection and menu foci.
- this->FocusAcquired(ev, gSelectionFocus, frame);
- this->FocusAcquired(ev, gMenuFocus, frame);
- this->FocusAcquired(ev, gKeyFocus, frame);
-
- }
- }
-
- // We sucessfully acquired the foci we need to be active.
-
- }
-
-
-
-
-
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_CommonInitPart
- //--------------------------------------------------------------------
-
- void CAProxyPart::UTIL_CommonInitPart(Environment* ev)
- {
-
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
-
- if ( gGlobalsUsageCount == 0 )
- {
- // It is required that parts instantiate their menu bars from
- // the base OpenDoc menu bar. This maintains consistency in the
- // default menu items and their placement.
- // Since the object is a copy, we can add and subtract menus and
- // items without affecting other running parts.
- //gMenuBar = session->GetWindowState(ev)->CopyBaseMenuBar(ev);
-
- // We will be using the following foci (shared resources) in this
- // part. For convenience, we tokenize the values here and store
- // them for equivalence tests in the activation methods.
- gSelectionFocus = session->Tokenize(ev, kODSelectionFocus);
- gMenuFocus = session->Tokenize(ev, kODMenuFocus);
- gModalFocus = session->Tokenize(ev, kODModalFocus);
- gKeyFocus = session->Tokenize(ev, kODKeyFocus);
- gClipboardFocus = session->Tokenize(ev, kODClipboardFocus);
-
- // Lastly, we will package the menu and selection focus
- // so that we can request the "set" at activation time.
- gUIFocusSet = session->GetArbitrator(ev)->CreateFocusSet(ev);
- gUIFocusSet->Add(ev, gMenuFocus);
- gUIFocusSet->Add(ev, gSelectionFocus);
- gUIFocusSet->Add(ev, gKeyFocus);
-
- // Determine what Script/Language the part is localized for.
- // This is important/necessary for creating OpenDoc's text objects.
- //GetEditorScriptLanguage(ev, &gPartsScript, &gPartsLanguage);
-
- // The first client of the global variables is running.
- gGlobalsUsageCount = 1;
- }
- else
- // If the globals have been initialized, we just bump the refcount of the
- // menu bar. This prevents will prevent it from going away before we are
- // done using it. We also keep a "usage" count so that we can null out the
- // global variables when we are finished using them.
- {
- //ODAcquireObject (ev, gMenuBar);;
- gGlobalsUsageCount++;
- }
-
- fEmbeddedFrames = new OrderedCollection;
-
- // Get the interface extension object for CALib callback support
- // and initialize it
-
- fProxyExt = new CAProxyExtension;
- fProxyExt->InitProxyExtension( ev, fSelf, this );
-
-
- }
-
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_GetEmbeddedFrames
- //--------------------------------------------------------------------
-
- OrderedCollection* CAProxyPart::UTIL_GetEmbeddedFrames(Environment* ev)
- {
- ODUnused (ev);
-
- return (fEmbeddedFrames);
-
- }
-
- //--------------------------------------------------------------------
- // CAProxyPart::UTIL_HandleActivateEvent
- //--------------------------------------------------------------------
-
- ODBoolean CAProxyPart::UTIL_HandleActivateEvent(Environment* ev, ODFrame* frame, ODEventData* event)
- {
- short activating = event->modifiers & activeFlag;
- ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
- ODPlatformWindow platformWindow;
- ODWindow* window;
-
-
- PartInfo* partInfo = (PartInfo*) frame->GetPartInfo(ev);
- TempODFrame activeFrame = session->GetArbitrator(ev)->AcquireFocusOwner(ev, gSelectionFocus);
-
- if (activating)
- {
-
- if (partInfo->GetNeedsActivating ())
- {
- this->UTIL_ActivateDisplayFrame (ev, frame);
- partInfo->SetNeedsActivating (kODFalse);
- }
- else
- {
- //DebugStr ("\pWindow Activating, active frame is not root");
- }
-
- }
- else
- {
-
-
- if (partInfo->IsFrameActive())
- {
- partInfo->SetNeedsActivating (kODTrue);
- }
- else
- {
- partInfo->SetNeedsActivating (kODFalse);
- }
-
- InvalMenuBar();
- }
-
- window = frame->AcquireWindow(ev);
- platformWindow = window->GetPlatformWindow(ev);
- window->Release(ev);
-
- // Call the CA's CAWindowActivateHandler if it exists.
- if (this->fCAWindowActivateHandler)
- {
- CallUniversalProc(fCAWindowActivateHandler, uppCAWindowActivateHandlerInfo,
- platformWindow, activating);
- }
-
- return (kODFalse);
-
- }
-
-
-
-
-
- //-------------------------------------------------------------------------
- // CAProxyPart::UTIL_SetDirty
- //-------------------------------------------------------------------------
-
- void CAProxyPart::UTIL_SetDirty(Environment* ev)
- {
-
- // There is no need to repeatedly tell the draft we have changed;
- // once is sufficient.
- if (!fReadOnlyStorage )
- {
- fDirty = kODTrue;
- fSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
- }
-
- }
-
-