home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CPPictPart.cpp
-
- Contains: CPPictPart OpenDoc part editor class implementation.
- Built using PartMaker , then modified.
-
- Owned by: Pierre-François BESSON / ORKIS
-
- Copyright: © 1995 by ORKIS S.A., all rights reserved.
- partly :© 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <5> 4/14/95 JS Updated for Developer Release 2
- <4> 3/8/95 JS Updated to b1c13/c14
- <3> 3/8/95 RA Add tokenized kODPresDefault param to RegisterWindow().
- <2> 2/21/95 RA Add kODFrameObject param to RegisterWindow().
- <1> 2/2/95 RA first checked in
- <0> PartMaker source by E, Soldan, T. Çelik, J. Alfke, R. Adkins, J. Schalk
- */
-
- #ifndef ODDebug
- #define ODDebug 0
- #endif
-
-
- #ifndef _ALTPOINT_
- #include <AltPoint.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
- #include "ODTypesB.xh"
- #endif
-
- #ifndef _CPPICTPART_
- #include "CPPictPart.h"
- #endif
-
- #ifndef _PARTUTILS_
- #include "PartUtils.h"
- #endif
-
- #ifndef _PICTPARTDEF_
- #include "PictPartDef.h"
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #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_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODLink_xh
- #include <Link.xh>
- #endif
-
- #ifndef SOM_ODBaseLink_xh
- #include <LinkB.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODBaseLinkSpec_xh
- #include <LinkSpcB.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- #ifndef SOM_ODBaseLinkSource_xh
- #include <LinkSrcB.xh>
- #endif
-
- #ifndef SOM_ODPstObj_
- #include <PstObj.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStdProps_xh
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStdTypes_xh
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef _STDDEFS_
- #include <StdDefs.xh>
- #endif
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef SOM_ODCmdDefs_xh
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODStorageU_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODTrnsform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWinStat_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #include <Memory.h>
- #include <StandardFile.h>
- #include <Files.h>
- #include <Events.h>
- #include <Drag.h>
- #include <ImageCompression.h>
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- // ISOString equivalents for Apple scrap types
- #define kODApplePICT "Apple:OSType:Scrap:PICT"
- #define kODApplehfs "Apple:OSType:Scrap:hfs "
-
- const ODPropertyName kPPPropPartInfo = "PictPart:Property:PartInfo";
- const ODPropertyName kPPPropSourceLink = "PictPart:Property:SourceLink";
- const ODPropertyName kPPPropDestLink = "PictPart:Property:DestLink";
- const ODValueType kPictPartValue = "PictPart:Value";
-
- const ODType kPictNormalFacette = "PictPart:Presentation:Normal";
- const ODType kPictToolsFacette = "PictPart:Presentation:Palette";
-
-
- //========================================================================================
- // Miscellaneous
- //========================================================================================
-
- #define qDebug 0
-
- #if qDebug
- #define WeBeHere(s) DebugStr((StringPtr)s)
- #else
- #define WeBeHere(s)
- #endif
-
-
- #ifdef applec
- #pragma segment PictPart
- #endif
-
-
- ODSession* gSession = kODNULL;
-
-
-
- //========================================================================================
- // Constants
- //========================================================================================
-
-
-
- const short kContentStringResID = 5000;
- const short kContentStringID = 1;
- const short kAboutTextID = 2;
-
- // PictParts special
- const short kShowPaletteID = 3;
- const short kHidePaletteID = 4;
- const short toolIconWidth = 32;
- const short toolIconHeight = 20;
-
-
-
- //========================================================================================
- // CPPictPart
- //========================================================================================
-
-
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::CPPictPart
- //----------------------------------------------------------------------------------------
-
- CPPictPart::CPPictPart()
- {
- WeBeHere("\pCPPictPart::CPPictPart");
-
- fDirty = kODFalse;
- fWindowID = 0;
- fSession = kODNULL;
- fMenuBar = kODNULL;
-
- fDraftKey = 0;
- fScopeFrame = kODNULL;
-
- // Note that fDisplayFrames is a static field, and therefore
- // its constructor is automatically called before
- // CPPictPart constructor.
-
- // PFB
-
- fClipboardChangeID = -1;
- fSrcLink = kODNULL;
- fSrcLinkChange = kODUnknownChange;
- fDestLink = kODNULL;
- fDraft = kODNULL;
-
- fPicture = nil;
-
- fCurrentCursorHandle = nil;
- fMouseInsideActiveFrame = kODFalse;
- fExternalizeOnlyPICTFormat = kODFalse;
-
- fPaletteIsOpen = kODFalse;
- fPaletteWindow = nil;
- fCurrentTool = arrowTool;
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::~CPPictPart
- //----------------------------------------------------------------------------------------
-
- CPPictPart::~CPPictPart()
- {
- WeBeHere("\pCPPictPart::~CPPictPart");
-
- // PFB
- if( fPicture != nil )
- DisposeHandle( fPicture );
- fPicture = nil;
- if( fCurrentCursorHandle != nil )
- DisposeHandle( (Handle)fCurrentCursorHandle );
- fCurrentCursorHandle = nil;
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::InitPart
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::InitPart(Environment* ev, ODStorageUnit* storageUnit, ODPart* partWrapper)
-
- // Called by the draft object.
-
- {
- WeBeHere("\pCPPictPart::InitPart");
-
- fSelf = partWrapper; // Will very much need this later.
- fStorageUnit = storageUnit;
-
- this->MyCommonInitPart(ev); // We say "this" everywhere just to be explicit.
-
- ODStorageUnit *pictPartContentSU;
-
- pictPartContentSU = storageUnit->AddProperty(ev, kODPropContents);
- pictPartContentSU->AddValue(ev, kPictPartKind);
- pictPartContentSU->AddValue(ev, kODApplePICT);
- // For your edification, AddProperty & AddValue
- // implicitly focus. Check the API for more info.
-
- {
- CUsingLibraryResources fil;
- fPicture = ::GetResource( bkgndPictureRsrcType, bkgndPictureRsrcId );
- if( fPicture == nil )
- DebugStr("\pcannot load picture resource !!!");
- else
- ::DetachResource( fPicture );
- } // Use CUsingLibraryResources to use your part's resource fork.
- // Make it go out of scope when you are done.
- // We are creating our part's initial content here.
-
-
- // Initialize your other fields here.
-
- fDirty = kODTrue;
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::InitPartFromStorage
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::InitPartFromStorage(Environment* ev, ODStorageUnit* storageUnit, ODPart* partWrapper)
-
- // Called by the draft object.
-
- {
- WeBeHere("\pCPPictPart::InitPartFromStorage");
-
- fSelf = partWrapper; // Will very much need this later.
- fStorageUnit = storageUnit;
-
- this->MyCommonInitPart(ev);
-
- ODStorageUnitRef weakRef;
- ODULong size;
-
- // Internalize the part's display frame list.
-
- if (ODSUExistsThenFocus(ev, storageUnit, kODPropDisplayFrames, kODWeakStorageUnitRefs ))
- {
- size = storageUnit->GetSize(ev);
- storageUnit->SetOffset(ev, 0);
-
- for ( ODULong offset = 0; offset < size; offset += 4 )
- {
- StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef), weakRef);
-
- if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
- {
- ODFrame *frame = storageUnit->GetDraft(ev)->
- GetFrame(ev, storageUnit->GetIDFromStorageUnitRef(ev, weakRef));
- fDisplayFrames.Add(frame);
- }
- }
- }
-
- // PFB
- InternalizeFromSU( ev, storageUnit, kODNULL );
-
- //
- // Read in the source and destination links
- //
- ODStorageUnitRef aSURef;
-
- if ( fStorageUnit->Exists(ev, kPPPropSourceLink, kPictPartKind, 0) )
- {
- ODBoolean validLink = kODTrue;
- fStorageUnit->Focus(ev, kPPPropSourceLink, kODPosUndefined, kPictPartKind, 0, kODPosUndefined);
- TRY
- StorageUnitGetValue(fStorageUnit, ev, sizeof(ODStorageUnitRef),&aSURef);
- if ( fStorageUnit->IsValidStorageUnitRef(ev, aSURef) )
- {
- fSrcLink = fDraft->GetLinkSource(ev, fStorageUnit->GetIDFromStorageUnitRef(ev, aSURef));
- StorageUnitGetValue(fStorageUnit, ev, sizeof(ODChangeID), (ODValue) &fSrcLinkChange );
-
- // Ensure the link source references this part
- fSrcLink->SetSourcePart(ev, fStorageUnit );
- }
- else
- {
- validLink = kODFalse;
- }
- CATCH_ALL
- validLink = kODFalse;
- ENDTRY
-
- if ( !validLink )
- {
- fStorageUnit->SetOffset(ev, 0);
- fStorageUnit->DeleteValue(ev, fStorageUnit->GetSize(ev));
- fSrcLink = kODNULL;
- }
- }
-
- if ( fStorageUnit->Exists(ev, kPPPropDestLink, kPictPartKind, 0) )
- {
- ODBoolean validLink = kODTrue;
- fStorageUnit->Focus(ev, kPPPropDestLink, kODPosUndefined, kPictPartKind, 0, kODPosUndefined);
- TRY
- StorageUnitGetValue(fStorageUnit, ev, sizeof(ODStorageUnitRef),&aSURef);
- if ( fStorageUnit->IsValidStorageUnitRef(ev, aSURef) )
- {
- fDestLink = fDraft->GetLink(ev, fStorageUnit->GetIDFromStorageUnitRef(ev, aSURef), (ODLinkSpec*) kODNULL);
- StorageUnitGetValue(fStorageUnit, ev, sizeof(ODLinkInfo), (ODValue) &fDestLinkInfo);
- ODType kind = (ODType) ODNewPtr((ODULong) fDestLinkInfo.kind , kDefaultHeapID);
- StorageUnitGetValue(fStorageUnit, ev, (ODULong) fDestLinkInfo.kind, (ODValue) kind);
- fDestLinkInfo.kind = kind;
-
- // Now register as a dependent of the link
- // Specify kODUnknownChange to force getting the text.
- // By default the destination is automatically updated.
- if( fDestLinkInfo.autoUpdate )
- fDestLink->RegisterDependent(ev, fSelf, kODUnknownChange);
- fDraft->SetChangedFromPrev(ev);
- }
- else
- {
- validLink = kODFalse;
- }
- CATCH_ALL
- validLink = kODFalse;
- ENDTRY
-
- if ( !validLink )
- {
- fStorageUnit->SetOffset(ev, 0);
- fStorageUnit->DeleteValue(ev, fStorageUnit->GetSize(ev));
- fDestLink = kODNULL;
- }
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::MyCommonInitPart
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::MyCommonInitPart(Environment* ev)
- {
- WeBeHere("\pCPPictPart::MyCommonInitPart");
-
- fSession = fStorageUnit->GetSession(ev);
- // As your part grows, add your initialization that is common
- // between InitPart and InitPartFromStorage here.
- // Note that GetStorageUnit can be used, since just prior to
- // calling this method, InitPart calledInitPersistentObject or
- // InitPartFromStorage called InitPersistentObjectFromStorage.
-
- fSelectionFocus = fSession->Tokenize(ev, kODSelectionFocus);
- fMenuFocus = fSession->Tokenize(ev, kODMenuFocus);
- fKeyFocus = fSession->Tokenize(ev, kODKeyFocus);
- fModalFocus = fSession->Tokenize(ev, kODModalFocus);
-
- fFocusSet = fSession->GetArbitrator(ev)->CreateFocusSet(ev);
- fFocusSet->Add(ev, fKeyFocus);
- fFocusSet->Add(ev, fMenuFocus);
- fFocusSet->Add(ev, fSelectionFocus);
-
- fMenuBar = fSession->GetWindowState(ev)->CopyBaseMenuBar(ev);
-
- {
- CUsingLibraryResources fil;
- fMenu = ::GetMenu(kMenuID);
- if (fMenu)
- ::DetachResource((Handle)fMenu); // Must detach it!
- }
-
- if (!fMenu)
- DebugStr("\pCPPictPart::MyCommonMyInitPart -- couldn't create menu.");
- // We are using debug messages
- // for these types of errors. When SOM is available, this issue
- // will be addressed correctly.
-
-
- fMenuBar->AddMenuLast(ev, kMenuID, fMenu, fSelf);
-
- // PFB
- fDraft = fStorageUnit->GetDraft(ev);
-
- fPictNormalPresentation = fSession->Tokenize( ev, kPictNormalFacette );
- fPictToolsPresentation = fSession->Tokenize(ev,kPictToolsFacette);
-
- fMenuBar->RegisterCommand( ev, kPictPart_PaletteStuff, kMenuID, 1 );
- fMenuBar->RegisterCommand( ev, kPictPart_ZoomInCmd, kMenuID, 3 );
- fMenuBar->RegisterCommand( ev, kPictPart_ZoomOutCmd, kMenuID, 4 );
- fMenuBar->RegisterCommand( ev, kPictPart_ExtOnlyPICT, kMenuID, 6 );
-
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::Externalize
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::Externalize(Environment* ev)
- {
- WeBeHere("\pCPPictPart::Externalize");
-
- if (fDirty != kODFalse)
- {
- ODSUForceFocus(ev, fStorageUnit, kODPropDisplayFrames, kODWeakStorageUnitRefs);
- // Externalize the part's display frame list.
-
- fStorageUnit->Remove(ev);
- fStorageUnit->AddValue(ev, kODWeakStorageUnitRefs);
- // Persistent object references are stored in a side table, rather than
- // in the property/value stream. Thus, deleting the contents of a value
- // will not "delete" the references previously written to that value. To
- // completely "delete" all references written to the value, we must
- // remove the value and add it back.
-
- for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
- {
- ODStorageUnitRef weakRef;
- ODID frameID;
-
- frameID = fl->Frame()->GetID(ev);
- if ( fDraftKey )
- frameID = fSelf->GetStorageUnit(ev)->GetDraft(ev)
- ->WeakClone(ev, fDraftKey, frameID, 0,
- fScopeFrame ? fScopeFrame->GetID(ev) : 0);
-
- fStorageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
- StorageUnitSetValue(fStorageUnit, ev, sizeof(ODStorageUnitRef), weakRef);
- }
-
-
- // PFB
- PrepareSU( ev, fStorageUnit );
- ExternalizeToSU( ev, fStorageUnit, kODNULL );
-
- //
- // Write out the source and destination links
- //
- ODStorageUnitRef aSURef;
-
-
- if ( fSrcLink == kODNULL)
- {
- if ( fStorageUnit->Exists(ev, kPPPropSourceLink, kPictPartKind, 0) )
- {
- fStorageUnit->Focus(ev, kPPPropSourceLink, kODPosUndefined, kPictPartKind, (ODValueIndex)0, kODPosUndefined);
- fStorageUnit->Remove(ev);
- }
- }
- else
- {
- fSrcLink->Externalize(ev);
- if ( fStorageUnit->Exists(ev, kPPPropSourceLink, kPictPartKind, 0) )
- fStorageUnit->Focus(ev, kPPPropSourceLink, kODPosUndefined, kPictPartKind, (ODValueIndex)0, kODPosUndefined);
- else
- fStorageUnit->AddProperty(ev,kPPPropSourceLink)->AddValue(ev,kPictPartKind);
- fStorageUnit->GetStrongStorageUnitRef(ev, fSrcLink->GetStorageUnit(ev)->GetID(ev), aSURef);
- StorageUnitSetValue( fStorageUnit, ev, sizeof(ODStorageUnitRef), aSURef);
- }
-
- if ( fDestLink == kODNULL)
- {
- if ( fStorageUnit->Exists(ev, kPPPropDestLink, kPictPartKind, 0) )
- {
- fStorageUnit->Focus(ev, kPPPropDestLink, kODPosUndefined, kPictPartKind, (ODValueIndex)0, kODPosUndefined);
- fStorageUnit->Remove(ev);
- }
- }
- else
- {
- fDestLink->Externalize(ev);
- if ( fStorageUnit->Exists(ev, kPPPropDestLink, kPictPartKind, 0) )
- fStorageUnit->Focus(ev, kPPPropDestLink, kODPosUndefined, kPictPartKind, (ODValueIndex)0, kODPosUndefined);
- else
- fStorageUnit->AddProperty(ev,kPPPropDestLink)->AddValue(ev,kPictPartKind);
- fStorageUnit->GetStrongStorageUnitRef(ev, fDestLink->GetStorageUnit(ev)->GetID(ev), aSURef);
- StorageUnitSetValue(fStorageUnit, ev, sizeof(ODStorageUnitRef), aSURef);
-
- // store dest link info kind as ISOStr
- ODType saveKind = fDestLinkInfo.kind;
- fDestLinkInfo.kind = (ODType) ODISOStrLength(saveKind) + 1;
- StorageUnitSetValue(fStorageUnit, ev, sizeof(ODLinkInfo), (ODValue) &fDestLinkInfo );
- StorageUnitSetValue(fStorageUnit, ev, (ODULong)fDestLinkInfo.kind, (ODValue) saveKind );
- fDestLinkInfo.kind = saveKind;
- }
-
- fDirty = kODFalse;
- // Flag our part as no longer being dirty.
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::MySetDirty
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::MySetDirty(Environment* ev)
- {
-
- WeBeHere("\pCPPictPart::MySetDirty");
-
- fDirty = kODTrue;
- fStorageUnit->GetDraft(ev)->SetChangedFromPrev(ev);
- fSrcLinkChange = fSession->UniqueChangeID(ev);
-
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::Purge
- //----------------------------------------------------------------------------------------
-
- ODSize CPPictPart::Purge(Environment* ev, ODSize size)
- {
- ODUnused(size);
- WeBeHere("\pCPPictPart::Purge");
-
- // CPPictPart doesn't do anything here.
-
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::Release
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::Release(Environment* ev)
- {
- WeBeHere("\pCPPictPart::Release");
-
- // If you are using RegisterIdle on the part, not on frames, then
- // the RefCount is bumped up by one by OpenDoc. OpenDoc keeps a
- // reference to all parts that register idle time. ALL OF THESE MUST
- // BE RESOLVED BEFORE THE DESTRUCTOR IS CALLED. This is
- // the place to do that.
-
- // The logic below, assuming that CPPictPart has registered for idle
- // time, is that if the RefCount is 1, then we are here to unregister
- // the idle. When the part is being removed, OpenDoc must decrement
- // the RefCount and call Release until the part gets messaged with
- // a RefCount of 0. Once you return from here with a RefCount of 0,
- // OpenDoc will call the destructor.
-
- // This means that if you have registered for idle time, Release will
- // be called TWICE when closing down your part. The first time the
- // RefCount is 1. This is when you should unregister the idle time.
- // When you are called with a RefCount of 0, that when it gets really
- // serious. This is when you detach from the draft.
-
- if (fSelf->GetRefCount(ev) == 1) {
- // Here is where you would unregister idle time for the part if
- // have registered time. Note that if you unregister without
- // registering, OpenDoc will crash. It's not just a simple
- // look-up-and-if-there-remove kind of operation.
-
- // Note that if you unregister idle here, OpenDoc will need to
- // call Release (here) due to it. This means that when we call
- // to unregister the idle, we are nesting calls to Release.
- // Due to this, I return out of each case, just to make the
- // flow of control of the call(s) to Release more straightforward.
-
- // Note that if you are going to use idle registration, you will
- // need to include "Disptch.h"
-
- return;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::Open
- //----------------------------------------------------------------------------------------
-
- ODID CPPictPart::Open(Environment* ev, ODFrame* frame)
-
- // Creates and opens a presentation of the part in a frame
- // in a new window.
- //
- // This method adds this part as the root part of the window.
- // It bases the presentation in the new frame on the presentation
- // in the old frame, or on a default presentation if there
- // is no old frame.
-
- {
- WeBeHere("\pCPPictPart::Open");
-
- ODWindow* window = kODNULL;
-
- if (frame)
- window = fSession->GetWindowState(ev)->GetWindow(ev, fWindowID);
-
- if (window == kODNULL)
- {
- window = this->MyMakeWindow(ev, frame);
- fWindowID = window->GetID(ev);
- window->Open(ev);
- window->Show(ev);
- }
-
- window->Select(ev);
-
- return window->GetID(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::ReleaseAll
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::ReleaseAll(Environment* ev)
- {
- WeBeHere("\pCPPictPart::ReleaseAll");
-
- if (fMenuBar != kODNULL)
- fMenuBar->Release(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::MyWantResizable
- //----------------------------------------------------------------------------------------
-
- ODBoolean CPPictPart::MyWantResizable()
- {
- return kODFalse;
- // used in MyMakeWindow() to toggle some parameters
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::MyMakeWindow
- //----------------------------------------------------------------------------------------
-
- ODWindow* CPPictPart::MyMakeWindow(Environment* ev, ODFrame* sourceFrame)
- {
- WeBeHere("\pCPPictPart::MyMakeWindow");
-
- Rect windRect;
- ODPlatformWindow platformWindow = kODNULL;
- ODWindow* window = kODNULL;
-
- if (sourceFrame)
- {
- SetRect(&windRect, 100, 100, 300, 300);
- }
- else
- {
- const ODSShort kOnePageWidth = 600;
-
- ::SetRect(&windRect, 4, GetMBarHeight() + 24,
- ODQDGlobals.screenBits.bounds.right - 64,
- ODQDGlobals.screenBits.bounds.bottom - 4);
-
- if (windRect.right - windRect.left > kOnePageWidth)
- windRect.right = windRect.left + kOnePageWidth;
- }
-
- Str255 windowTitleStr;
- ODName* partName = ODGetPOName( ev, fSelf, kODNULL);
- IntlToPStr(partName, (StringPtr)&windowTitleStr);
- DisposeIText(partName);
-
- platformWindow = ::NewCWindow
- (
- kODNULL,
- &windRect,
- windowTitleStr,
- kODFalse,
- this->MyWantResizable() ? zoomDocProc : zoomNoGrow,
- (WindowPtr)-1L,
- kODTrue,
- kODNULL
- );
-
- ODBoolean isRoot = (sourceFrame == kODNULL);
-
- window = fSession->GetWindowState(ev)->RegisterWindow
- (
- ev,
- platformWindow, // newWindow
- isRoot ? // Persistent
- kODFrameObject: // Non-Persistent
- kODNonPersistentFrameObject, // frameType
- isRoot, // isRootWindow
- this->MyWantResizable(), // isResizable
- kODFalse, // isFloating
- kODTrue, // shouldSave
- fSelf, // rootPart
- fSession->Tokenize(ev, kODViewAsFrame), // viewType
- fSession->Tokenize(ev, kODPresDefault), // presentation
- sourceFrame // sourceFrame
- );
-
- return window;
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::Draw
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
-
- // Draws the part in the facet, updating the portion of the
- // facet in the invalidShape.
- //
- // Called by the facet object.
- //
- // The part should draw itself on the facet's canvas. The part
- // must examine its canvas' isDynamic flag to determine if it
- // will be drawing on the screen or to a printer, and then draw
- // itself appropriately.
- //
- // Draw the part in the given facet. Only the portion in the
- // invalidShape needs to be drawn.
- //
- // There are several steps a part needs to take to perform the
- // imaging.
- // 1) The part should look at the given facet and its frame.
- // Both the frame and the facet may have some partInfo that
- // the part has placed there, which the part can use to
- // decide how it will display itself. The frame also has
- // viewType and presentation fields, which indicate what kind
- // of view of the part should display.
- // 2) The part should examine its canvas to see how it should
- // be imaged. The canvas can be obtained from the facet via
- // ODFacet::GetCanvas(). If the canvas’ isDynamic flag is
- // kODTrue, the part is imaging onto a dynamic device like
- // a CRT; otherwise, it is imaging to a static device like
- // a printer. The part will probably display its content
- // differently for static and dynamic views. For instance,
- // it should not display scroll bars on a static canvas.
- // 3) The part must make sure the platform graphics system is
- // prepared to draw into the correct context for the facet.
- // On the Macintosh using QuickDraw, it is necessary to call
- // SetPort() for the appropriate canvas, and set up other
- // attributes of the drawing environment. A FocusLib library
- // is supplied to help focus drawing commands to a facet.
- // Make sure to clip to the facet’s clipShape (FocusLib
- // does this for you).
- // 4) Draw the part’s contents.
- // 5) Restore the old graphics environment.
- //
- // Part editors may sometimes need to display their parts
- // asynchronously, that is, not in response to a ::Draw() call.
- // This process is very similar to the basic drawing recipe,
- // with minor modifications.
- // 1) Determine which of the part’s frames should be drawn. A part
- // may have multiple display frames, and more than one may need
- // updating. Parts store their display frames in whatever way
- // they want, so we can’t tell you how to find them here.
- // 2) For each frame being displayed, all facets must be drawn.
- // ODFrame::CreateFrameFacetIterator() returns an iterator
- // which will list all the facets of a frame. Draw the part’s
- // contents in each of these facets, using the recipe above.
- // 3) After drawing in a facet, call ODFacet::DrawnIn() on it to
- // tell it you’ve drawn in it asynchronously. If the facet is
- // on an offscreen canvas, this lets it get copied into the window.
-
- {
- WeBeHere("\pCPPictPart::Draw");
- ODUnused(invalidShape);
-
- CFocus foc(ev, facet);
-
- ODFrame* frame = facet->GetFrame(ev);
- ODShape* usedShape = frame->GetUsedShape(ev, kODNULL);
- RgnHandle rgn = usedShape->GetQDRegion(ev);
-
- usedShape->Release(ev);
-
- Rect rct = (*rgn)->rgnBBox;
- RgnHandle oldClip = NULL;
- RgnHandle newClip;
-
- ::PenSize(2, 2);
-
- if (frame->IsRoot(ev))
- {
- GrafPtr curPort;
-
- ::GetPort(&curPort);
- Rect r = curPort->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- ::GetClip(oldClip = NewRgn());
- ::ClipRect(&r);
- ::DrawGrowIcon(curPort);
- ::GetClip(newClip = ::NewRgn());
- ::DiffRgn(oldClip, newClip, newClip);
- ::SetClip(newClip);
- ::DisposeRgn(newClip);
- ::EraseRect(&(curPort->portRect));
- }
- else {
- ::EraseRoundRect(&rct, 40, 40);
- }
-
- if (frame->GetPresentation(ev) == fPictNormalPresentation )
- {
- PictPartInfoRec* thisFramePartInfo;
- Boolean temporaryPartInfo = kODFalse;
-
- thisFramePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- {
- temporaryPartInfo = kODTrue;
- thisFramePartInfo = new PictPartInfoRec;
- }
-
- if( fPicture != nil )
- {
- Rect drawRect;
- RgnHandle invalidShapeRgn;
- RgnHandle pictureRgn;
-
- drawRect = CalcPictureRect( ev, thisFramePartInfo );
- // effacement de la région hors picture
- invalidShapeRgn = invalidShape->CopyQDRegion(ev);
- pictureRgn = ::NewRgn();
- ::RectRgn( pictureRgn, &drawRect );
- ::DiffRgn( invalidShapeRgn, pictureRgn, invalidShapeRgn );
- ::DisposeRgn( pictureRgn );
- ::EraseRgn( invalidShapeRgn );
- // dessin
- ::DrawPicture( (PicHandle)fPicture, &drawRect );
- if( frame->GetLinkStatus( ev ) == kODInLinkSource )
- {
- Rect tempRect;
- tempRect = drawRect;
- InsetRect( &tempRect, 1, 1 );
- PenPat( &ODQDGlobals.ltGray );
- PenSize( 2, 2 );
- FrameRect( &tempRect );
- PenNormal();
- }
- if( frame->GetLinkStatus( ev ) == kODInLinkDestination )
- {
- Rect tempRect;
- tempRect = drawRect;
- InsetRect( &tempRect, 1, 1 );
- PenPat( &ODQDGlobals.dkGray );
- PenSize( 2, 2 );
- FrameRect( &tempRect );
- PenNormal();
- }
- }
- else
- {
- RgnHandle frameRgn;
-
- frameRgn = frame->GetFrameShape(ev, kODNULL )->CopyQDRegion(ev);
- ::EraseRgn( frameRgn );
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in Draw !!!");
- thisFramePartInfo->Initialize();
- thisFramePartInfo->activeRect = (*frameRgn)->rgnBBox;
- ::DisposeRgn( frameRgn );
- }
-
- if( temporaryPartInfo )
- delete thisFramePartInfo;
- }
- else if( frame->GetPresentation(ev) == fPictToolsPresentation )
- {
- CUsingLibraryResources fil;
- PicHandle palettePicture;
-
- palettePicture = (PicHandle)::GetResource( 'PICT', 10000 );
- if( palettePicture != nil )
- {
- Rect currentToolRect;
- Rect paletteDrawRect;
-
- paletteDrawRect = (*palettePicture)->picFrame;
- ::DrawPicture( palettePicture, &paletteDrawRect );
- ::ReleaseResource( (Handle)palettePicture );
-
- ::SetRect( ¤tToolRect, 0, fCurrentTool * toolIconHeight,
- toolIconWidth, (fCurrentTool + 1) * toolIconHeight );
- ::InvertRect( ¤tToolRect );
-
- if( fPicture == nil )
- {
- ::SetRect( ¤tToolRect, 0, toolIconHeight,
- toolIconWidth, toolCount * toolIconHeight );
- ::PenMode( patBic );
- ::PenPat( &ODQDGlobals.gray );
- ::PaintRect( ¤tToolRect );
- ::PenNormal();
- }
- }
- }
-
- if (oldClip) {
- ::SetClip(oldClip);
- ::DisposeRgn(oldClip);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // UI Events protocol
- //----------------------------------------------------------------------------------------
-
- ODBoolean CPPictPart::HandleEvent(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet,
- ODEventInfo* eventInfo)
- {
- WeBeHere("\pCPPictPart::HandleEvent");
- ODUnused(eventInfo);
-
- ODBoolean tWasHandled = kODFalse;
-
- switch ( event->what ) {
- case nullEvent:
- if (::IsDialogEvent((EventRecord *)event))
- {
- short itemHit;
- DialogPtr dialog;
- tWasHandled = ::DialogSelect((EventRecord *)event, &dialog, &itemHit);
- return tWasHandled;
- }
- tWasHandled = kODTrue;
- break;
-
- case mouseDown:
- tWasHandled = this->MyHandleMouseDown(ev, event, frame, facet);
- break;
-
- case kODEvtMouseDownEmbedded:
- case mouseUp:
- case keyDown:
- case autoKey:
- tWasHandled = kODTrue;
- break;
- case activateEvt:
- // PFB
- if (frame->GetPresentation(ev) == fPictNormalPresentation )
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)frame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in activateEvt !!!");
- if ((event->modifiers & activeFlag) != 0)
- {
- if( thisFramePartInfo->fNeedsActivating )
- {
- if ( fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame) )
- {
- this->FocusAcquired(ev, fSelectionFocus, frame);
- this->FocusAcquired(ev, fMenuFocus, frame);
- this->FocusAcquired(ev, fKeyFocus, frame);
- AdjustCursor( ev, thisFramePartInfo );
- }
- }
- }
- else
- {
- if( thisFramePartInfo->fIsActive )
- {
- fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, fFocusSet, frame);
- thisFramePartInfo->fNeedsActivating = true;
- }
- }
- }
- tWasHandled = kODTrue;
- break;
- case kODEvtMenu:
- tWasHandled = this->MyHandleMenuEvent(ev, frame, event );
- break;
- case kODEvtMouseEnter :
- // PFB
- if (facet->GetFrame(ev)->GetPresentation(ev) == fPictNormalPresentation )
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)facet->GetFrame(ev)->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in MouseEnter !!!");
- if( thisFramePartInfo->fIsActive )
- {
- AdjustCursor( ev, thisFramePartInfo );
- }
- fMouseInsideActiveFrame = kODTrue;
- }
- break;
- case kODEvtMouseWithin :
- // PFB
- if (facet->GetFrame(ev)->GetPresentation(ev) == fPictNormalPresentation )
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)facet->GetFrame(ev)->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in MouseWithin !!!");
- if( thisFramePartInfo->fIsActive )
- {
- AdjustCursor( ev, thisFramePartInfo );
- }
- }
- break;
- case kODEvtMouseLeave :
- // PFB
- ::SetCursor( &ODQDGlobals.arrow );
- fMouseInsideActiveFrame = kODFalse;
- break;
- default:
- break;
- }
-
- return tWasHandled;
-
- // Below is some documentation for this method. If you don't care for
- // being here, then just delete it.
- //
- // The frame and facet parameters of HandleEvent() may be
- // kODNULL, depending on the kind of event.
- //
- // Parts must handle the following events, which correspond to
- // standard Macintosh events:
- //
- // kODEvtNull
- // kODEvtMouseDown
- // kODEvtMouseUp
- // kODEvtKeyDown
- // kODEvtKeyUp
- // kODEvtAutoKey
- // kODEvtUpdate
- // kODEvtActivate
- // kODEvtOS
- //
- // Null Events --
- // In order to receive null events (i.e. idle time), parts must call
- // ODDispatcher::RegisterIdle(), specifying the part, a frame
- // (optional) and idle frequency. The part will receive a null event
- // for each frame registered. ODDispatcher::GetSleepTime() is called
- // by the shell, and the value passed to WaitNextEvent. An appropriate
- // sleep time is computed based on the idle frequencies of registered
- // idle frames.
- //
- // Mouse Events --
- // Unmodified mouse events are delivered to the facet under the mouse
- // location using Part::HandleEvent().
- //
- // Shift-Click and Command-Click go to the frame with the selection
- // focus. Mouse events in window title bars are converted to window
- // events. (See below) Mouse down events in the menu bar are converted
- // to menu events. (See below)
- //
- // Keyboard Events --
- // Keyboard events go to the frame with the keyboard focus, with the
- // exception of the Page Up, Page Down, Home and End keys, which will
- // go to the frame with the scrolling focus, if there is one.
- //
- // Update Events --
- // Update events are not passed to Part::HandleEvent(). Rather
- // Part::Draw() will be called for each facet in the window.
- //
- // Activate Events --
- // Activate events are also delivered to each facet, using
- // Part::HandleEvent().
- //
- // Disk Events --
- // Currently, disk events are not distributed to parts.
- // But where do they go???
- //
- // OS Events --
- // Suspend/Resume events are delivered to each facet in each
- // window using Part::HandleEvent().
- //
- // Mouse Moved events are not passed to Part::HandleEvent().
- // They are handled by the dispatcher, and translated into calls
- // to Part::MouseEnter(), MouseWithin() and MouseLeave().
- // See Cursor Tracking below.
- //
- // Menu Events --
- // OpenDoc converts a mouse down in the menu bar, or its
- // command-key equivalent, into a menu event of type kODEvtMenu.
- //
- // The message field of the event record contains the result
- // returned by MenuSelect() or MenuKey(). i.e. the menu is in
- // the high word, and the item in the low word. The part can
- // obtain a command number using ODMenuBar::GetCommand().
- //
- // Window Events --
- // Events in the title bar of a window (eg. clicking in the
- // close box) are usually handled by the shell, but are first
- // offered to the root part of the window. Parts which wish to
- // intercept these events (perhaps to hide rather than close a
- // window) must handle the following event: kODEvtWindow
- // The message field of the event contains the part code, as
- // returned by FindWindow().
- //
- // Events in Embedded Frames --
- // Parts which support embedding may also receive the following events:
- //
- // kODEvtMouseDownEmbedded
- // kODEvtMouseUpEmbedded
- // kODEvtMouseDownBorder
- // kODEvtMouseUpBorder
- //
- // If the user clicks in the active border, the containing
- // facet/frame/part will receive a kODEvtMouseDownBorder event.
- // The message field of the event record contains the embedded facet.
- //
- // Similarly, if the user clicks in an embedded frame with the
- // “frozen” or “selected” property set, a kODEvtMouseDownEmbedded
- // event is directed to the containing frame.
- //
- // If the user shift-clicks or command-clicks in a frame which is
- // embedded in the frame with the selection focus, then the latter
- // frame gets a kODEvtMouseDownEmbedded event.
- //
- // Cursor Tracking --
- // OpenDoc tracks cursor movement (with the mouse button up), and
- // calls MouseEnter() when the cursor first moves into a facet, and
- // MouseLeave() when the cursor leaves the facet. A part can change
- // the cursor on MouseEnter, and set it to the arrow on MouseLeave.
- //
- // This process is triggered by the shell calling
- // ODDispatcher::GetMouseRegion() and passing the result to
- // WaitNextEvent(). The region is only recomputed when necessary.
- // If the cursor is motionless within a facet, the shell application
- // goes to sleep because OpenDoc computes a mouse region containing
- // just the cursor location. The part can make this region larger
- // by calling ODDispatcher::SetMouseRegion(). In a future release,
- // OpenDoc will also compute a suitably large sleep region if the
- // cursor is not within any facet.
- //
- // Modal Focus --
- // Some events are constrained by the modal focus. For example a
- // mouse click outside the frame with the modal focus will be sent
- // to the modal focus frame, but a click in an embedded frame
- // within the modal focus frame will go to the embedded frame.
- //
- // Propagating Events --
- // If a containing part sets the “DoesPropagateEvents” property of
- // an embedded frame, the containing part will receive events not
- // handled by the embedded frame. A part which does this will have
- // to inspect the frame passed to HandleEvent() to determine if it
- // is one of its display frames.
-
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::AdjustMenus(Environment* ev, ODFrame* frame)
- {
- WeBeHere("\pCPPictPart::AdjustMenus");
- ODUnused(frame);
-
- Str63 aboutText;
- ODIText* odiText;
-
- fMenuBar->EnableCommand(ev, kODCommandViewAsWin, !frame->IsRoot(ev) );
- fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, kODTrue);
-
- {
- CUsingLibraryResources fil;
- ::GetIndString(aboutText, kContentStringResID, kAboutTextID);
- }
-
- odiText = CreateIText(smRoman, langEnglish, aboutText);
- fMenuBar->SetItemString(ev, kODCommandAbout, odiText);
- DisposeIText(odiText);
-
- // PFB
- Str63 showPalette, hidePalette;
-
- {
- CUsingLibraryResources fil;
- ::GetIndString(showPalette, kContentStringResID, kShowPaletteID);
- ::GetIndString(hidePalette, kContentStringResID, kHidePaletteID);
- }
- if (fPaletteIsOpen)
- {
- odiText = CreateIText(smRoman, langEnglish, hidePalette);
- fMenuBar->SetItemString(ev, kPictPart_PaletteStuff, odiText);
- DisposeIText(odiText);
- }
- else
- {
- odiText = CreateIText(smRoman, langEnglish, showPalette);
- fMenuBar->SetItemString(ev, kPictPart_PaletteStuff, odiText);
- DisposeIText(odiText);
- }
-
- PictPartInfoRec* framePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
- fMenuBar->EnableCommand( ev, kPictPart_PaletteStuff, kODTrue );
- fMenuBar->EnableCommand( ev, kPictPart_ZoomInCmd, (fPicture != nil) && framePartInfo->IsZoomingInAllowed() );
- fMenuBar->EnableCommand( ev, kPictPart_ZoomOutCmd, (fPicture != nil) && framePartInfo->IsZoomingOutAllowed() );
- fMenuBar->EnableCommand( ev, kPictPart_ExtOnlyPICT, kODTrue );
- fMenuBar->CheckCommand( ev, kPictPart_ExtOnlyPICT, fExternalizeOnlyPICTFormat );
-
- fMenuBar->EnableCommand( ev, kODCommandCut, (fPicture != nil) );
- fMenuBar->EnableCommand( ev, kODCommandCopy, (fPicture != nil) );
- fMenuBar->EnableCommand( ev, kODCommandClear, (fPicture != nil) );
-
- ODBoolean okToPaste = kODFalse;
- ODBoolean okToPasteAs = kODFalse;
-
- ODArbitrator* arbitrator = fSession->GetArbitrator(ev);
- ODTypeToken clipboardFocus = fSession->Tokenize(ev, kODClipboardFocus);
-
- if ( (frame == arbitrator->GetFocusOwner(ev, clipboardFocus)) ||
- (arbitrator->RequestFocus(ev, clipboardFocus, frame)) )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- // Get the root storage unit for the clipboard
- ODStorageUnit* clipRootSU = clipboard->GetContentStorageUnit(ev);
- okToPaste = ValidDataOnSU( ev, clipRootSU );
- // must be a link in clipboard and not be a link to myself
- okToPasteAs = ValidLinkOnSU( ev, clipRootSU ) &&
- (fClipboardChangeID != clipboard->GetChangeID(ev));
- arbitrator->RelinquishFocus(ev, clipboardFocus , frame);
- }
-
- fMenuBar->EnableCommand( ev, kODCommandPaste, okToPaste );
- fMenuBar->EnableCommand( ev, kODCommandPasteAs, okToPasteAs );
-
- #define shiftKeyItem 1
- #define shiftKeyMask 1
- #define optionKeyItem 1
- #define optionKeyMask 4
- #define commandKeyItem 1
- #define commandKeyMask 0x8000
- #define controlKeyItem 1
- #define controlKeyMask 8
- KeyMap theKeyMap;
- GetKeys( theKeyMap );
- if( ((fSrcLink != kODNULL) || (fDestLink != kODNULL)) &&
- (theKeyMap[optionKeyItem] & optionKeyMask))
- {
- fShowLinkInfo = kODTrue;
- fMenuBar->SetItemString(ev, kODCommandGetPartInfo, PStrToIntl("\pLink Info", kODNULL));
- }
- else
- {
- fShowLinkInfo = kODFalse;
- fMenuBar->SetItemString(ev, kODCommandGetPartInfo, PStrToIntl("\pPart Info", kODNULL));
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::MyHandleMenuEvent
- //----------------------------------------------------------------------------------------
-
- ODBoolean CPPictPart::MyHandleMenuEvent(Environment* ev, ODFrame* frame, ODEventData* event)
- {
- WeBeHere("\pCPPictPart::MyHandleMenuEvent");
- ODUnused(frame);
-
- long menuResult = event->message;
- short menu = HiWord(menuResult);
- short item = LoWord(menuResult);
-
- if (menu) {
-
- ODCommandID theMenuCommand = fMenuBar->GetCommand(ev, menu, item);
- switch( theMenuCommand ) {
-
- case kODCommandAbout:
- {
- CUsingLibraryResources fil;
-
- if (fSession->GetArbitrator(ev)->RequestFocus(ev, fModalFocus, frame))
- {
- ::SetCursor(&ODQDGlobals.arrow);
- gSession = fSession; // DialogFilter uses this!
- ModalFilterUPP modalFilter = NewModalFilterProc(MyDialogFilter);
- ::Alert(kPictPartAboutBoxID, modalFilter);
- DisposeRoutineDescriptor(modalFilter);
- fSession->GetArbitrator(ev)->RelinquishFocus(ev, fModalFocus,frame);
- }
- else
- ::SysBeep(1);
- }
- break;
- /*
- case kODCommandClear:
- break;
- */
- case kODCommandViewAsWin:
- // PFB
- if (frame->GetPresentation(ev) == fPictNormalPresentation )
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)frame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in activateEvt !!!");
- if( thisFramePartInfo->fIsActive )
- {
- fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, fFocusSet, frame);
- thisFramePartInfo->fNeedsActivating = true;
- }
- }
- this->Open(ev, frame);
- break;
-
- case kODCommandGetPartInfo:
- if( fShowLinkInfo )
- {
- ODLinkInfoResult infoResult;
- ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
- if( fSrcLink != kODNULL )
- {
- if ( fSrcLink->ShowLinkSourceInfo( ev,
- facets->First(ev),
- fSrcLinkChange,
- true,
- &infoResult) )
- {
- switch( infoResult.action )
- {
- case kODLinkInfoBreakLink:
- RemoveSourceLink(ev);
- break;
- case kODLinkInfoUpdateNow:
- UpdateSourceLink( ev, true );
- break;
- case kODLinkInfoOk :
- if ( infoResult.autoUpdate != fSrcLink->IsAutoUpdate(ev) )
- {
- fSrcLink->SetAutoUpdate(ev, infoResult.autoUpdate);
- if ( infoResult.autoUpdate )
- if ( fSrcLinkChange != fSrcLink->GetChangeID(ev) )
- {
- // Changed from manual to automatic updates, and the link
- // is out of date; update it now
- UpdateSourceLink( ev, true );
- }
- }
- break;
- }
- }
- }
- else if( fDestLink != kODNULL )
- {
- if ( fDestLink->ShowLinkDestinationInfo(ev,
- facets->First(ev),
- &fDestLinkInfo,
- true,
- &infoResult) )
- {
- switch (infoResult.action)
- {
- case kODLinkInfoFindSource:
- TRY
- fDestLink->ShowSourceContent(ev);
- CATCH_ALL
- SysBeep( 30 );
- SysBeep( 30 );
- SysBeep( 30 );
- // DebugStr("\pPictPart : Error returned by ODLink::ShowSourceContent" );
- ENDTRY;
- break;
- case kODLinkInfoBreakLink:
- RemoveDestLink(ev);
- break;
- case kODLinkInfoUpdateNow:
- LinkUpdated(ev, fDestLink, fDestLink->GetChangeID(ev));
- break;
- case kODLinkInfoOk:
- if ( infoResult.autoUpdate != fDestLinkInfo.autoUpdate )
- {
- fDestLinkInfo.autoUpdate = infoResult.autoUpdate;
- if( infoResult.autoUpdate )
- fDestLink->RegisterDependent( ev, fSelf, fDestLinkInfo.change );
- else
- fDestLink->UnregisterDependent( ev, fSelf );
- }
- break;
- default:
- break;
- }
- }
- }
- delete facets;
- }
- else
- {
- ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
- fSession->GetInfo(ev)->ShowPartFrameInfo(ev, facets->First(ev), true ); //Adkins
- delete facets;
- }
- break;
-
- // PFB
- case kODCommandCut :
- case kODCommandCopy :
- {
- ODArbitrator* arbitrator = fSession->GetArbitrator(ev);
- ODTypeToken clipboardFocus = fSession->Tokenize(ev, kODClipboardFocus);
-
- if ( (frame == arbitrator->GetFocusOwner(ev, clipboardFocus)) ||
- (arbitrator->RequestFocus(ev, clipboardFocus, frame)) )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- // Remove any existing data on the clipboard
- clipboard->Clear(ev);
- // Get the root storage unit for the clipboard
- ODStorageUnit* clipRootSU = clipboard->GetContentStorageUnit(ev);
- // Part specific code to write to the clipboard draft via 'clipRootSU'.
- PrepareSU( ev, clipRootSU );
- ExternalizeToSU( ev, clipRootSU, frame );
- if( theMenuCommand == kODCommandCopy )
- ExternalizeLinkToSU( ev, clipRootSU );
- arbitrator->RelinquishFocus(ev, clipboardFocus , frame);
- // memorize the change ID to detect cut/püaste in myself
- fClipboardChangeID = clipboard->GetChangeID(ev);
- }
- if( theMenuCommand == kODCommandCut )
- {
- DisposeHandle( fPicture );
- fPicture = nil;
- fCurrentTool = arrowTool;
- MyInvalAllDisplayFrames(ev);
- MySetDirty(ev);
- }
-
- break;
- }
-
- case kODCommandPasteAs :
- {
- ODArbitrator* arbitrator = fSession->GetArbitrator(ev);
- ODTypeToken clipboardFocus = fSession->Tokenize(ev, kODClipboardFocus);
-
- if( (frame == arbitrator->GetFocusOwner(ev, clipboardFocus)) || (arbitrator->RequestFocus(ev, clipboardFocus, frame)) )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- ODFrameFacetIterator* facets = (ODFrameFacetIterator*) kODNULL;
- ODPasteAsResult pasteAsRslt;
-
- pasteAsRslt.pasteLinkSetting = kODTrue;
- TRY
- {
- ODStorageUnit* clipContentSU = clipboard->GetContentStorageUnit(ev);
- facets = frame->CreateFacetIterator(ev);
- if ( clipboard->ShowPasteAsDialog(ev,
- kODTrue,
- kODFalse,
- facets->First(ev),
- fSession->Tokenize(ev, kODViewAsFrame),
- &pasteAsRslt) )
- {
- // Cannot paste a link if translation is required
- if ( pasteAsRslt.translateKind != kODNULL )
- DebugStr("\pcannot translate !!!");
- if( fPicture != nil )
- {
- ::DisposeHandle( fPicture );
- fPicture = nil;
- fCurrentTool = arrowTool;
- }
- // Get the root storage unit for the clipboard
- ODStorageUnit* clipRootSU = clipboard->GetContentStorageUnit(ev);
- InternalizeFromSU(ev, clipRootSU );
- InternalizeLinkFromSU(ev, clipRootSU, &pasteAsRslt );
- arbitrator->RelinquishFocus(ev, clipboardFocus , frame);
- }
- }
- CATCH_ALL
- somPrintf("DoPasteAs caught error %d\n", ErrorCode());
- ENDTRY
- delete facets;
- if( pasteAsRslt.pasteLinkSetting == kODTrue )
- break;
- }
- // NO break; continue if simple paste !!!
- }
-
- case kODCommandPaste :
- {
- ODArbitrator* arbitrator = fSession->GetArbitrator(ev);
- ODTypeToken clipboardFocus = fSession->Tokenize(ev, kODClipboardFocus);
-
- if ( (frame == arbitrator->GetFocusOwner(ev, clipboardFocus)) ||
- (arbitrator->RequestFocus(ev, clipboardFocus, frame)) )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- // Get the root storage unit for the clipboard
- ODStorageUnit* clipRootSU = clipboard->GetContentStorageUnit(ev);
- Boolean gotSomething = InternalizeFromSU( ev, clipRootSU, frame );
- if( gotSomething )
- RemoveDestLink( ev );
- arbitrator->RelinquishFocus(ev, clipboardFocus , frame);
- }
- break;
- }
-
- case kODCommandClear :
- {
- if( fPicture != nil )
- {
- ::DisposeHandle( fPicture );
- fPicture = nil;
- fCurrentTool = arrowTool;
- }
- MyInvalAllDisplayFrames(ev);
- MySetDirty(ev);
- break;
- }
-
- case kPictPart_ZoomInCmd :
- {
- PictPartInfoRec* framePartInfo;
- framePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
- framePartInfo->ZoomIn();
- frame->Invalidate(ev, kODNULL, kODNULL);
- MySetDirty(ev);
- break;
- }
- case kPictPart_ZoomOutCmd :
- {
- PictPartInfoRec* framePartInfo;
- framePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
- framePartInfo->ZoomOut();
- frame->Invalidate(ev, kODNULL, kODNULL);
- MySetDirty(ev);
- break;
- }
- case kPictPart_ExtOnlyPICT :
- {
- fExternalizeOnlyPICTFormat = !fExternalizeOnlyPICTFormat;
- break;
- }
-
- case kPictPart_PaletteStuff :
- {
- if( fPaletteIsOpen == kODFalse )
- {
- if( fPaletteWindow == nil )
- {
- ODPlatformWindow platformWindow;
- Rect windRect;
-
- ::SetRect(&windRect, 0, 0, toolIconWidth, toolIconHeight * toolCount );
- platformWindow = ::NewCWindow( kODNULL, &windRect,"\p",
- kODFalse, noGrowDocProc, (WindowPtr)-1L, kODTrue, kODNULL );
- ::MoveWindow( platformWindow, 100, 100, kODFalse);
- fPaletteWindow = fSession->GetWindowState(ev)->RegisterWindow(
- ev,
- platformWindow, // newWindow
- kODNonPersistentFrameObject,
- kODFalse, // isRootWindow
- kODFalse, // Is resizable
- kODTrue, // Is floating
- kODFalse, // don't save
- fSelf,
- fSession->Tokenize(ev,kODViewAsFrame),
- fPictToolsPresentation,
- kODNULL);
- fPaletteWindow->Open(ev);
- }
- fPaletteWindow->Show(ev);
- fPaletteIsOpen = kODTrue;
- }
- else
- {
- fPaletteWindow->Hide(ev);
- fCurrentTool = arrowTool;
- fPaletteIsOpen = kODFalse;
- }
- break;
- }
- /*
-
- case kODPictPart_LoadFile :
- {
- OSErr err;
- SFTypeList typeList;
- StandardFileReply reply;
-
- typeList[0] = 'PICT';
- StandardGetFilePreview( (FileFilterProcPtr)nil, 1, typeList, &reply);
- if (reply.sfGood == kODTrue)
- {
- short fileRefNum;
- long fileSize;
-
- err = FSpOpenDF( &reply.sfFile, fsRdPerm, &fileRefNum );
- if( err != noErr )
- DebugStr("\pcannot FSpOpenDF !!!");
- err = GetEOF( fileRefNum, &fileSize );
- if( err != noErr )
- DebugStr("\pcannot GetEOF !!!");
- err = SetFPos( fileRefNum, fsFromStart, 512 );
- if( err != noErr )
- DebugStr("\pcannot SetFPos !!!");
- fileSize -= 512;
- if( fPicture != nil )
- {
- DisposeHandle( fPicture );
- fPicture = nil;
- }
- fPicture = NewHandle( fileSize );
- if( fPicture == nil )
- {
- FSClose( fileRefNum );
- SysBeep( 30 );
- }
- HLock( fPicture );
- err = FSRead( fileRefNum, &fileSize, *fPicture );
- if( err != noErr )
- DebugStr("\pcannot FSRead !!!");
- HUnlock( fPicture );
- FSClose( fileRefNum );
- }
- frame->Invalidate(ev, kODNULL, kODNULL);
- MySetDirty();
- break;
- }
- */
- default:
- return kODFalse;
- }
- }
-
- return kODTrue;
- }
-
-
-
- //------------------------------------------------------------------------------
- // CPPictPart::MyHandleMouseDown
- //------------------------------------------------------------------------------
-
- ODBoolean CPPictPart::MyHandleMouseDown(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet)
- {
- WeBeHere("\pCPPictPart::MyHandleMouseDown");
-
- ODBoolean handled = kODFalse;
-
- if (facet == kODNULL) // Did we get a click outside a modal dialog? …
- {
- ::SysBeep(1);
- return kODTrue; // Return that click was handled.
- }
-
- // Activate the window if it is not active…
- if (! facet->GetWindow(ev)->IsActive(ev))
- {
- facet->GetWindow(ev)->Select(ev);
-
- #ifdef FIRST_CLICK_WINDOW_BEHAVIOR
- handled = kODTrue;
- #else
- return kODTrue;
- #endif
- // We argued way too much about which this should be. The answer is that
- // some types of content need first click, and some absolutely don't. Even
- // for 'TEXT', sometimes you want one, and sometimes you want the other.
- // It depends on your content, usage model, etc.
- //
- // If you are unsure about which you want, the default for PictPart
- // should be FIRST_CLICK_WINDOW_BEHAVIOR. This probably means fewer clicks
- // for the user. If this doesn't work for your part, of course change it.
- }
-
- if (::IsDialogEvent((EventRecord *)event))
- {
- short itemHit;
- DialogPtr dialog;
-
- handled = ::DialogSelect((EventRecord *)event, &dialog, &itemHit);
- ODWindow* window = fSession->GetWindowState(ev)->GetODWindow(ev, dialog);
- return handled; // In preparation for more "if" cases to be added below.
- }
-
- // get the mouse in local coordinates
- ODWindow* odwnd = frame->GetWindow(ev);
- ODPoint odPoint;
- GetWindowPoint(odwnd, ev, event->where, &odPoint);
-
- // test for click in grow box, if appropriate
- if (frame->IsRoot(ev))
- {
- WindowPtr wnd = (WindowPtr)odwnd->GetPlatformWindow(ev);
-
- Rect r = wnd->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- if (::PtInRect(odPoint.AsQDPoint(), &r)) {
- ::SetRect(&r, 200, 200, 20000, 20000);
- long newWindowSize = GrowWindow(wnd, event->where, &r);
- ::SizeWindow(wnd, LoWord(newWindowSize), HiWord(newWindowSize), kODTrue);
- odwnd->AdjustWindowShape(ev);
- return kODTrue;
- }
- }
-
- // PFB
- if( frame->GetPresentation(ev) == fPictToolsPresentation )
- {
- if( fPicture != nil )
- {
- CFocus foc(ev, facet);
- PictPartInfoRec* thisFramePartInfo;
- Point where = event->where;
-
- thisFramePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
- ::GlobalToLocal(&where);
- fCurrentTool = (PictPartTool)(where.v / toolIconHeight);
- facet->Invalidate( ev, kODNULL, kODNULL );
- return kODTrue;
- }
- }
- else if( frame->GetPresentation(ev) == fPictNormalPresentation )
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)frame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in MyHandleMouseDown !!!");
- if( thisFramePartInfo->fIsActive == kODFalse )
- {
- // Try to grab all of our foci…
- if ( fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame) )
- {
- this->FocusAcquired(ev, fSelectionFocus, frame);
- this->FocusAcquired(ev, fMenuFocus, frame);
- this->FocusAcquired(ev, fKeyFocus, frame);
- AdjustCursor( ev, thisFramePartInfo );
- return kODTrue;
-
- }
- else
- return kODFalse; // We couldn't get focus.
-
- // Of course, you shouldn't fail if you really don't need the *all*
- // of the foci. For example, a vector drawing part that also has
- // a text tool should probably go ahead and allow drawing while
- // disabling the text tool.
- }
-
-
- // Handle clicks in used shape…
- odPoint = facet->GetWindowContentTransform(ev, kODNULL)->InvertPoint(ev, &odPoint);
-
- ODShape* usedShape = this->MyGetUsedShape(ev, frame);
- ODBoolean hit = usedShape->ContainsPoint(ev, &odPoint);
- usedShape->Release(ev);
-
- if (hit)
- return this->MyUsedShapeHandleMouseDown(ev, event, frame, facet);
- }
-
- return handled;
- }
-
-
-
- //------------------------------------------------------------------------------
- // CPPictPart::MyUsedShapeHandleMouseDown
- //------------------------------------------------------------------------------
-
- ODBoolean CPPictPart::MyUsedShapeHandleMouseDown(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet)
- {
- WeBeHere("\pCPPictPart::MyUsedShapeHandleMouseDown");
-
- // Get the window and platform window (i.e. WindowPtr)…
- ODWindow* odwnd = frame->GetWindow(ev);
- ODPlatformWindow facetPort = odwnd->GetPlatformWindow(ev);
-
- // Get the mouse in window-local and facet-local coordinates…
- ODPoint windowPoint;
- GetWindowPoint(odwnd, ev, event->where, &windowPoint);
- ODPoint facetPoint = facet->GetWindowContentTransform(ev, kODNULL)->
- InvertPoint(ev, &windowPoint);
-
- // Handle the click in whatever way is appropriate…
- {
-
- Point macPoint;
- {
- CFocus foc(ev, facet);
- macPoint = facetPoint.AsQDPoint();
- }
-
- // PFB
- PictPartInfoRec* thisFramePartInfo;
- thisFramePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in MyUsedShapeHandleMouseDown !!!");
-
- switch( fCurrentTool )
- {
- case arrowTool :
- if( WaitMouseMoved(event->where) &&
- ::PtInRect( macPoint, &thisFramePartInfo->activeRect ) &&
- (fPicture != nil) )
- {
- // Get the ODDragAndDrop object from the session.
- ODDragAndDrop* dragAndDrop;
-
- dragAndDrop = fSession->GetDragAndDrop(ev);
- dragAndDrop->Clear(ev);
- ODStorageUnit* storageUnit = dragAndDrop->GetContentStorageUnit(ev);
- PrepareSU( ev, storageUnit );
- ExternalizeToSU( ev, storageUnit, frame );
- ExternalizeLinkToSU( ev, storageUnit );
-
- ODDropResult dropResult;
- ODByteArray eventBA;
- ODByteArray dragRgnBA;
- ODPart *destPart;
- // Initiate the Dragging
- RgnHandle dragRgn;
- Rect tempRect;
- Point xForm;
-
- {
- CFocus foc(ev, facet);
- dragRgn = ::NewRgn();
- ::OpenRgn();
- tempRect = thisFramePartInfo->activeRect;
- ::FrameRect( &tempRect );
- ::InsetRect( &tempRect, 2, 2 );
- ::FrameRect( &tempRect );
- ::CloseRgn( dragRgn );
-
- SetPt(&xForm, 0, 0);
- LocalToGlobal(&xForm);
- OffsetRgn(dragRgn, xForm.h, xForm.v);
- }
-
- eventBA = CreateByteArrayStruct(&event, sizeof(ODEventData*));
- dragRgnBA = CreateByteArrayStruct(&dragRgn, sizeof(RgnHandle));
- dropResult = dragAndDrop->StartDrag( ev, facet->GetFrame(ev),
- kODDragImageRegionHandle, &dragRgnBA, &destPart, &eventBA );
-
- DisposeByteArrayStruct(dragRgnBA);
- DisposeByteArrayStruct(eventBA);
-
- if( dropResult == kODDropMove )
- {
- ::DisposeHandle( fPicture );
- fPicture = nil;
- fCurrentTool = arrowTool;
- }
- ::DisposeRgn( dragRgn );
- }
- break;
-
- case moveTool :
- {
- Point theLoc = {0,0};
- Point lastLoc = {0,0};
- ODBoolean mustRedraw = kODFalse;
- Point *pictureOffsetPtr;
-
- pictureOffsetPtr = &thisFramePartInfo->pictureOffset;
-
- ::GetMouse(&lastLoc);
- while( ::StillDown() )
- {
- ::GetMouse(&theLoc);
- if ((theLoc.h != lastLoc.h) || (theLoc.v != lastLoc.v))
- {
- Point offsetDelta;
-
- offsetDelta = theLoc;
- ::SubPt( lastLoc, &offsetDelta );
- ::AddPt( offsetDelta, pictureOffsetPtr );
- lastLoc = theLoc;
- mustRedraw = kODTrue;
- }
- else if( mustRedraw )
- {
- Draw( ev, facet, frame->GetUsedShape(ev, kODNULL) );
- mustRedraw = kODFalse;
- }
- }
- break;
- }
- case zoomInTool :
- if( thisFramePartInfo->IsZoomingInAllowed() )
- {
- thisFramePartInfo->ZoomIn();
- frame->Invalidate(ev, kODNULL, kODNULL);
- MySetDirty(ev);
- if( fMouseInsideActiveFrame )
- AdjustCursor( ev, thisFramePartInfo );
- }
- break;
- case zoomOutTool :
- if( thisFramePartInfo->IsZoomingOutAllowed() )
- {
- thisFramePartInfo->ZoomOut();
- frame->Invalidate(ev, kODNULL, kODNULL);
- MySetDirty(ev);
- if( fMouseInsideActiveFrame )
- AdjustCursor( ev, thisFramePartInfo );
- }
- break;
- }
- }
-
- return kODTrue; // We handled the click.
- }
-
- //----------------------------------------------------------------------------------------
- // Facet protocol
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::FacetAdded(Environment* ev, ODFacet* facet)
- {
- WeBeHere("\pCPPictPart::FacetAdded");
-
- ODFrame* frame = facet->GetFrame(ev);
- frame->RequestFrameShape(ev, this->MyGetFrameShape(ev, frame), kODNULL);
- // •• First, MyGetFrameShape is called to calculate the frame
- // shape we want. However, we might not get it, due to the
- // needs/constraints of the containing part. Therefore, after
- // calculating what we want, we see if we can get it by calling
- // RequestFrameShape.
- // RequestFrameShape either returns us what we passed it, or
- // returns something else because it thinks it knows best.
- // Either way, we then proceed with the returned result.
- // Note that this means that we have to be prepared to deal
- // with a frame shape other than we desire.
-
- this->MyAdjustFacets(ev, frame);
- // Given a new negotiated frame shape, adjust our facets based
- // on it. That's all there is to it.
-
- // PFB
- if (frame->IsRoot(ev) && (frame->GetPresentation(ev) == fPictNormalPresentation))
- {
- ODBoolean succeeded = kODFalse;
- succeeded = fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame);
- if (succeeded)
- {
- this->FocusAcquired(ev, fSelectionFocus, frame);
- this->FocusAcquired(ev, fMenuFocus, frame);
- this->FocusAcquired(ev, fKeyFocus, frame);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPPictPart::MyInvalAllDisplayFrames
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::MyInvalAllDisplayFrames(Environment* ev)
- {
- WeBeHere("\pCPPictPart::MyInvalAllDisplayFrames");
-
- // This is just a CPPictPart utility method.
-
- for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
- fl->Frame()->Invalidate(ev, kODNULL, kODNULL);
- }
-
- //----------------------------------------------------------------------------------------
- // Part Activation protocol
- //----------------------------------------------------------------------------------------
-
- ODBoolean CPPictPart::BeginRelinquishFocus(Environment* ev, ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- WeBeHere("\pCPPictPart::BeginRelinquishFocus");
- ODUnused(ownerFrame);
-
- if ((focus == fModalFocus) && (proposedFrame->GetPart(ev) != fSelf)) {
- return kODFalse;
- // •• 6/23/94
- // What IS ModalFocus, anyway? The whole purpose of this
- // ModalFocus thing is to restrict frame changes. This is
- // the part's chance to do this. But how much to restrict…
- //
- // This is an interesting case. ModalFocus is kind of a weird
- // concept in OpenDoc, as it goes against the principal of
- // being able to click anywhere at any time. This implementation
- // keeps the focus on the part. Note that the implementation
- // of ModalFocus might be more restrictive than this. You may
- // wish to restrict it to a single frame, instead of allowing
- // the focus to move from frame to frame within a single part.
- // If you wish to restrict it to a single frame, then the if
- // should only check if it is a modal focus.
- }
- else {
- return kODTrue;
- // This is the super-script way of handling ModalFocus. You
- // can NOT switch off the frame to another, no matter what.
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::CommitRelinquishFocus(Environment* ev,
- ODTypeToken focus, ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- WeBeHere("\pCPPictPart::CommitRelinquishFocus");
- ODUnused(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.
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::AbortRelinquishFocus(Environment* ev,
- ODTypeToken focus, ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- WeBeHere("\pCPPictPart::AbortRelinquishFocus");
- 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 kODFalse 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.
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::FocusAcquired(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame)
- {
- WeBeHere("\pCPPictPart::FocusAcquired");
- // PFB
- if (focus == fSelectionFocus)
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)ownerFrame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in FocusAcquired !!!");
- thisFramePartInfo->fIsActive = kODTrue;
-
- if( fPaletteIsOpen )
- fPaletteWindow->Show(ev);
- }
-
- if (focus == fMenuFocus)
- if (ownerFrame && fMenuBar)
- {
- fMenuBar->Display(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::FocusLost(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame)
- {
- WeBeHere("\pCPPictPart::FocusLost");
- ODUnused(ownerFrame);
- if (focus == fMenuFocus)
- {
- }
-
- if (focus == fSelectionFocus)
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)ownerFrame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in FocusLost !!!");
- thisFramePartInfo->fIsActive = kODFalse;
- thisFramePartInfo->fNeedsActivating = kODFalse;
-
- if( fPaletteIsOpen )
- fPaletteWindow->Hide(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // Storage protocol
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::CloneInto(Environment* ev, ODDraftKey key, ODStorageUnit* toSU, ODFrame* scope)
- {
- WeBeHere("\pCPPictPart::CloneInto");
-
- ODStorageUnit* su = fStorageUnit;
- ODDraft* draft = su->GetDraft(ev);
-
- ODVolatile(draft);
-
- this->Externalize(ev);
- su->CloneInto(ev, key, toSU, scope->GetStorageUnit(ev)->GetID(ev));
-
- if (ev->_major != NO_EXCEPTION)
- draft->AbortClone(ev, key);
- }
-
- //----------------------------------------------------------------------------------------
- // Frame protocol
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::DisplayFrameAdded(Environment* ev, ODFrame* frame)
-
- // Tells a part to add “frame” as one of its display frames.
- //
- // This method is only called by frame objects during their
- // initialization. Same for RemoveDisplayFrame() and
- // CloseDisplayFrame().
- //
- // The part must record “frame” in whatever internal structures it
- // uses to remember its display frames. The new frame will carry a
- // suggested viewType and presentation information. The part should
- // look at those settings, and decide if it can support them; if not,
- // it should update those settings in the frame to reflect a default
- // presentation that it can support. Note that the part must support
- // the required set of standard viewTypes (frame, icon, small icon,
- // thumbnail, etc.). The part will then create the appropriate
- // partInfo data and store it in the frame. This data allows the part
- // to distinguish the frame from its other display frames, and is
- // also a handy place to store other view-related information.
- //
- // Add the new display frame to the part’s list of its display frames.
- // This list, like the part’s other internal structures, is completely
- // hidden from OpenDoc. The developer may represent this list any way
- // he chooses. The simplest of parts may be able to do without such a
- // list, but most parts will require it.
- //
- // Validate the viewType and presentation of the new frame. The part
- // must support the required set of view types. Other kinds of view
- // types or presentations are optional. The part should inspect these
- // values and correct them if necessary. See the recipe for View Types
- // and Presentations for more detail.
- //
- // Add partInfo to the frame. The partInfo field of a frame is a
- // convenient place for a part to store information about that view of
- // itself. It can be anything from a simple ID to a pointer to a
- // complicated structure or a helper object. The partInfo for a frame
- // is stored in the storage unit for the frame, not the part. If the
- // part has many frames of which only a few are internalized, only the
- // partInfo of those frames will be internalized and take up memory.
- //
- // The display frames need not be internalized until needed and will be
- // done by the containing part. ???
-
- {
- WeBeHere("\pCPPictPart::AddDisplayFrame");
-
- fDisplayFrames.Add(frame);
- // Add new frame to list of current display frames.
-
- // PFB
- if ( frame->GetPart(ev) == fSelf)
- {
- ODTypeToken presentation = frame->GetPresentation(ev);
- if ((presentation != fPictNormalPresentation) &&
- (presentation != fPictToolsPresentation))
- frame->SetPresentation( ev, fPictNormalPresentation );
-
-
- // on crée un part info pour cette frame
- PictPartInfoRec* thisFramePartInfo = new PictPartInfoRec;
- // on l'initialise
- if (frame->IsRoot(ev))
- thisFramePartInfo->fNeedsActivating = kODTrue;
- frame->SetPartInfo( ev, (ODInfoType)thisFramePartInfo );
- frame->SetDroppable( ev, kODTrue );
-
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::DisplayFrameConnected(Environment* ev, ODFrame* /*frame*/)
- {
- WeBeHere("\pCPPictPart::DisplayFrameConnected");
-
- // // fDisplayFrames.Add(frame);
- // Don't need to add frame to list of current display frames because we already did
- // in InitPartFromStorage.
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::DisplayFrameRemoved(Environment* ev, ODFrame* frame)
-
- // Removes the frame from the list of display frames.
- //
- // Called by Frame::Remove().
- //
- // This method makes whatever other adjustments are necessary
- // to deal with removing one of the presentations. This includes
- // removing any frames embedded within this display frame.
- // Before calling this method, you must ensure that the frame
- // has no facets.
-
- {
- WeBeHere("\pCPPictPart::DisplayFrameRemoved");
-
- // PFB
- if ( frame->GetPart(ev) == fSelf)
- {
- ODTypeToken presentation = frame->GetPresentation(ev);
- if( presentation == fPictNormalPresentation )
- {
- fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, fFocusSet, frame);
- }
- else if( presentation == fPictToolsPresentation )
- {
- fPaletteIsOpen = kODFalse;
- fPaletteWindow = nil;
- fCurrentTool = arrowTool;
- }
- }
-
- fDisplayFrames.Remove(frame);
- // This just removes the reference from our frame list.
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::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.
-
- {
- WeBeHere("\pCPPictPart::DisplayFrameClosed");
-
- if ( frame->GetPart(ev) == fSelf)
- {
- ODTypeToken presentation = frame->GetPresentation(ev);
- if( presentation == fPictNormalPresentation )
- {
- fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, fFocusSet, frame);
- }
- else if( presentation == fPictToolsPresentation )
- {
- fPaletteIsOpen = kODFalse;
- fPaletteWindow = nil;
- fCurrentTool = arrowTool;
- }
- }
-
- fDisplayFrames.Remove(frame);
- // This just removes the reference from our frame list.
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::FrameShapeChanged(Environment* ev, ODFrame* frame)
-
- // •• Notifies the part that the frame shape of one of its
- // display frames has been changed by its containing part.
- //
- // Called by Frame::ChangeFrameShape.
- //
- // The part should take whatever actions are necessary to respond
- // to the new shape. It may need to re-layout its content, change
- // its used shape, resize its embedded frames, or something else.
- // It also has the option of turning around and asking the frame
- // for a different frame shape via RequestFrameShape, though it
- // must be able to handle the shape it is given. If the size of
- // the frame is not sufficient, the part may ask the containing
- // part for a continuation frame via CreateEmbeddedFrame.
-
- {
- WeBeHere("\pCPPictPart::FrameShapeChanged");
-
- frame->RequestFrameShape(ev, this->MyGetFrameShape(ev, frame), kODNULL);
- this->MyAdjustFacets(ev, frame);
- frame->Invalidate(ev, kODNULL, kODNULL);
- frame->InvalidateActiveBorder(ev);
- }
-
- //----------------------------------------------------------------------------------------
-
- ODShape* CPPictPart::MyGetFrameShape(Environment* ev, ODFrame* frame)
-
- // This is just to centralize the frame shape code. Do it any way
- // is best for your part.
-
- {
- ODShape* newFrameShape;
-
- if (frame->IsRoot(ev))
- newFrameShape = frame->GetFrameShape(ev, kODNULL);
- else
- newFrameShape = this->MyGetUsedShape(ev, frame);
-
- return newFrameShape;
- }
-
- //----------------------------------------------------------------------------------------
-
- ODShape* CPPictPart::MyGetUsedShape(Environment* ev, ODFrame* frame)
-
- // This is just to centralize the frame shape code. Do it any way
- // is best for your part.
-
- {
- ODShape* frameShape = frame->GetFrameShape(ev, kODNULL);
-
- RgnHandle shapeRgn = frameShape->CopyQDRegion(ev);
- ODShape* usedShape = frame->CreateShape(ev);
- usedShape->SetQDRegion(ev, shapeRgn);
-
- return usedShape;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::MyAdjustFacets(Environment* ev, ODFrame* frame)
-
- // Given a frame, iterate through all of the facets and adjust them
- // according to the new frame.
-
- {
- ODShape* usedShape = this->MyGetUsedShape(ev, frame);
- frame->ChangeUsedShape(ev, usedShape, kODNULL);
- usedShape->Release(ev);
-
- ODShape* frameShape = frame->GetFrameShape(ev, kODNULL);
- ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
- for (ODFacet* facet = facets->First(ev);
- facets->IsNotComplete(ev);
- facet = facets->Next(ev) )
- {
- facet->ChangeActiveShape(ev, frameShape, kODNULL);
- }
- frameShape->Release(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- /*Adkins*/
- void CPPictPart::ClonePartInfo (Environment *ev, /*Adkins*/
- ODDraftKey key,
- ODInfoType partInfo,
- ODStorageUnitView* storageUnitView,
- ODFrame* scope)
- {
- WeBeHere("\pCPPictPart::ClonePartInfo");
-
- // same thing for us…
- WritePartInfo( ev, partInfo, storageUnitView );
- return ;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::WritePartInfo(Environment* ev, ODInfoType partInfo,
- ODStorageUnitView* storageUnitView)
-
- // Externalizes the frame's partInfo data onto the frame's
- // storage unit.
- //
- // Called by the frame object.
- //
- // Duh???
-
- {
- WeBeHere("\pCPPictPart::WritePartInfo");
-
- if (partInfo)
- {
- ODStorageUnit *storageUnit = storageUnitView->GetStorageUnit(ev);
- ODPropertyName partInfoProperty = storageUnitView->GetProperty(ev);
- ODStorageUnit *partInfoStorageUnit;
-
- if (storageUnit->Exists(ev, partInfoProperty, kODNULL, 0) == kODFalse)
- partInfoStorageUnit = storageUnit->AddProperty(ev, partInfoProperty);
- else
- partInfoStorageUnit = storageUnit->Focus(ev, partInfoProperty, kODPosUndefined, (ODValueType)kODNULL, 0, kODPosUndefined );
- if (storageUnit->Exists(ev, partInfoProperty, kPPPropPartInfo, 0) == kODFalse)
- partInfoStorageUnit->AddValue(ev, kPPPropPartInfo);
-
- storageUnit->Focus(ev, partInfoProperty, kODPosUndefined, kPPPropPartInfo, 0, kODPosUndefined);
- StorageUnitSetValue( storageUnit, ev, sizeof(Point), (ODValue)&(((PictPartInfoRec*)partInfo)->pictureOffset));
- StorageUnitSetValue( storageUnit, ev, sizeof(int), (ODValue)&(((PictPartInfoRec*)partInfo)->zoomFactor));
- StorageUnitSetValue( storageUnit, ev, sizeof(Rect), (ODValue)&(((PictPartInfoRec*)partInfo)->activeRect));
- ODBoolean needsActivating = ((PictPartInfoRec*)partInfo)->fNeedsActivating
- || ((PictPartInfoRec*)partInfo)->fIsActive;
- StorageUnitSetValue( storageUnit, ev, sizeof(ODBoolean), (ODValue)&needsActivating);
- }
-
- }
-
-
- //----------------------------------------------------------------------------------------
-
-
- ODInfoType CPPictPart::ReadPartInfo(Environment* ev, ODFrame* frame,
- ODStorageUnitView* storageUnitView)
-
- // Internalizes the partInfo for a display frame of this part.
- //
- //
- // Called by the frame object.
- //
- // The data for the partInfo is stored in a value in the frame's
- // storage unit, specified by the suView parameter. It gets the
- // data from out of the value, and places it in a block of memory.
- // It then returns the memory block to the frame for it to hold.
-
- {
- WeBeHere("\pCPPictPart::ReadPartInfo");
-
- ODStorageUnit *storageUnit = storageUnitView->GetStorageUnit(ev);
- ODPropertyName partInfoProperty = storageUnitView->GetProperty(ev);
- PictPartInfoRec* partInfo = new PictPartInfoRec;
-
- if (storageUnit->Exists(ev, partInfoProperty, kPPPropPartInfo, 0) )
- {
- storageUnit->Focus(ev, partInfoProperty, kODPosUndefined, kPPPropPartInfo, 0, kODPosUndefined);
- StorageUnitGetValue( storageUnit, ev, sizeof(Point), (ODValue)&(partInfo->pictureOffset));
- StorageUnitGetValue( storageUnit, ev, sizeof(int), (ODValue)&(partInfo->zoomFactor));
- StorageUnitGetValue( storageUnit, ev, sizeof(Rect), (ODValue)&(partInfo->activeRect));
- StorageUnitGetValue( storageUnit, ev, sizeof(ODBoolean), (ODValue)&(partInfo->fNeedsActivating));
- }
- else
- WeBeHere("\p nothing read in ReadPartInfo !!!");
- frame->SetDroppable(ev, kODTrue);
-
- return (ODInfoType)partInfo;
- }
-
-
- //-------------------------------------------------------------------------
- // DragAndDrop protocol
- //-------------------------------------------------------------------------
-
- ODDragResult CPPictPart::DragEnter(Environment* ev, ODDragItemIterator* dragInfo,
- ODFacet* facet, ODPoint* where)
-
- // Activates the part used to track the drag.
- //
- // Called by the facet object.
- //
- // The part should display a drag target border within the facet.
- // During drag tracking (DragEnter, DragWithin) the part should
- // never attempt to read data from any of the storage units supplied
- // by the iterator. The part should only inspect the type of the
- // dragged data. Before calling this method, you must ensure that
- // the part is ready to receive DrawWithin messages.
- //
- // DragEnter() is called when the mouse enters a facet. The part
- // should examine the available data types of the dragged items
- // using the ODDragItemIterator passed in. If the part can handle
- // a drop of the dragged object, it should provide the appropriate
- // feedback (e.g., adorning the droppable frame, changing the cursor).
- // If the destination part cannot handle the data types, nothing
- // should be done.
-
- {
- WeBeHere("\pCPPictPart::DragEnter");
- ODUnused(dragInfo);
- ODUnused(facet);
- ODUnused(where);
-
- ODStorageUnit *dragSU;
-
- fAcceptThisDrag = kODFalse;
- fActiveFrameHilitedForDrop = kODFalse;
- for (dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- {
- fAcceptThisDrag = fAcceptThisDrag || ValidDataOnSU( ev,dragSU );
- }
-
- return( fAcceptThisDrag );
- }
-
-
- //----------------------------------------------------------------------------------------
-
- ODDragResult CPPictPart::DragWithin(Environment* ev, ODDragItemIterator* dragInfo,
- ODFacet* facet, ODPoint* where)
-
- // Tracks the drag operation, and provides graphical feedback
- // regarding possible drop targets.
- //
- // This method highlights the appropriate content to provide
- // feedback about potential drop targets, based on type of dragged
- // data. It gets the type information out of the dragInfo. During
- // drag tracking (DragEnter, DragWithin) the part should never
- // attempt to read data from any of the storage units supplied by
- // the iterator. The part should only inspect the type of the
- // dragged data. Before calling tis method, you must ensure that
- // the part was previously activated via DragEnter().
- //
- // DragWithin() is called continuously when the mouse is still in
- // the facet. This allows the part to do any processing desired.
- // One good example is when the frame has several hot spots where
- // objects can be dropped. If the mouse is not over these hot spots,
- // the cursor may need to be changed to reflect that the no
- // dropping can be done there even though it is still in a
- // droppable frame. Again, a ODDragItemIterator is passed in so
- // that the part can examine the availabe data types of the dragged
- // objects.
- //
- // DragWithin() also provides a chance for the part to examine the
- // state of the machine. For example, some part may want to find
- // out whether the modifier keys are down or not.
-
- {
- WeBeHere("\pCPPictPart::DragWithin");
- ODUnused(dragInfo);
- ODUnused(facet);
-
- ODULong attributes;
- ODFrame* displayFrame;
- PictPartInfoRec* thisFramePartInfo;
- DragReference theDrag;
-
- attributes = fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
- theDrag = fSession->GetDragAndDrop(ev)->GetDragReference(ev);
- displayFrame = facet->GetFrame(ev);
- thisFramePartInfo = (PictPartInfoRec*)displayFrame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in DragWithin !!!" );
-
- if( fAcceptThisDrag )
- {
- CFocus myFocus(ev, facet);
-
- if( ::PtInRect( where->AsQDPoint(), &thisFramePartInfo->activeRect ) )
- {
- if( (fActiveFrameHilitedForDrop == kODFalse) && ((attributes & kODDragIsInSourcePart) == kODFalse) )
- {
- RgnHandle dragHiliteRgn;
-
- dragHiliteRgn = ::NewRgn();
- ::RectRgn( dragHiliteRgn, &thisFramePartInfo->activeRect );
- ShowDragHilite(theDrag, dragHiliteRgn, kODTrue);
- fActiveFrameHilitedForDrop = kODTrue;
- }
- }
- else if( fActiveFrameHilitedForDrop )
- {
- HideDragHilite(theDrag);
- fActiveFrameHilitedForDrop = kODFalse;
- }
- }
-
- return( fAcceptThisDrag );
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::DragLeave(Environment* ev, ODFacet* facet, ODPoint* where)
-
- // Signals that the drag operation is complete, and so
- // deactivates the part from drag tracking.
- //
- // This method un-highlights any content previously highlighted
- // during drag tracking. It also removes the drag target border.
- // Before calling this method you must ensure that the part was
- // previously activated via DragEnter(). After executing this
- // method successfully, the part is no longer active, and cannot
- // receive further DragWithin() or Drop() messages.
- //
- // DragLeave() is called when the mouse leaves a droppable frame.
- // This allows the part to clean up after a drag within it
- // (e.g., removing adornment on the frame, changing the cursor
- // back to its original form).
-
- {
- WeBeHere("\pCPPictPart::DragLeave");
- ODUnused(facet);
-
- ODULong attributes;
- ODPoint windowWhere;
- ODFrame* displayFrame;
- PictPartInfoRec* thisFramePartInfo;
- DragReference theDrag;
-
- attributes = fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
- theDrag = fSession->GetDragAndDrop(ev)->GetDragReference(ev);
- windowWhere = facet->GetWindowFrameTransform(ev, kODNULL)->TransformPoint(ev,where);
- displayFrame = facet->GetFrame(ev);
- thisFramePartInfo = (PictPartInfoRec*)displayFrame->GetPartInfo(ev);
-
- // && (attributes & kODDragHasLeftSourceFrame)
- if( fAcceptThisDrag )
- {
- CFocus myFocus(ev, facet);
- if (fActiveFrameHilitedForDrop )
- {
- HideDragHilite(theDrag);
- fActiveFrameHilitedForDrop = kODFalse;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- ODDropResult CPPictPart::Drop(Environment* ev, ODDragItemIterator* dropInfo,
- ODFacet* facet, ODPoint* where)
-
- // Transfers the dragged data into this part.
- //
- // Called by the facet object.
- //
- // Respond to the Drop operation. This might involve moving or
- // copying data in to the part, or some other response entirely.
- // However, the response should use the data returned from the
- // dropInfo iterator to perform the operation. Before calling
- // this method, you must ensure that the part was previously
- // activated via DragEnter().
- //
- // Don't forget whether the drop is a move or a copy.
- //
- // Drop() is called when the mouse is released within a part which
- // owns the facet. The part can then figure out whether it can
- // receive the dragged object using the ODDragItemIterator passed
- // in. The following is a sample code fragment for incorporating
- // text into a part.
- //
- // The destination part should return an appropriate ODDropResult
- // from Drop(). This result tells the source part (via the system)
- // whether the drop is accepted.
-
- {
- WeBeHere("\pCPPictPart::Drop");
- ODUnused(dropInfo);
- ODUnused(facet);
- ODUnused(where);
-
- ODDropResult theResult = kODDropFail;
- if( fActiveFrameHilitedForDrop )
- {
- ODULong attributes;
- DragReference theDrag;
- short mouseDownModifiers;
- short mouseUpModifiers;
- ODStorageUnit *dropSU;
- Boolean moveData = kODFalse;
- Boolean useLinkInfo = kODFalse;
- Handle dropPicHandle;
- Boolean gotSomething = kODFalse;
-
- attributes = fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
- theDrag = fSession->GetDragAndDrop(ev)->GetDragReference(ev);
- GetDragModifiers(theDrag, 0L, &mouseDownModifiers, &mouseUpModifiers);
- // If option key is held down at mousedown, it is a force-copy.
- if (mouseDownModifiers & optionKey)
- moveData = kODFalse;
- // If cmd key is held down at mousedown, it is a force-move.
- else if (mouseDownModifiers & cmdKey)
- useLinkInfo = kODTrue;
- // If option key is held down at mouseUp, it is a force-copy.
- else if (mouseUpModifiers & optionKey)
- moveData = kODFalse;
- // If cmd key is held down at mouseUp, it is a force-move.
- else if (mouseUpModifiers & cmdKey)
- useLinkInfo = kODTrue;
-
- dropPicHandle = nil;
- for (dropSU = dropInfo->First(ev); (dropSU && gotSomething == kODFalse); dropSU = dropInfo->Next(ev))
- {
- if( useLinkInfo )
- {
- if( ValidLinkOnSU( ev, dropSU ) )
- {
- ODFrameFacetIterator* facets = (ODFrameFacetIterator*) kODNULL;
- ODPasteAsResult pasteAsRslt;
-
- pasteAsRslt.pasteLinkSetting = kODTrue;
- if ( fSession->GetDragAndDrop(ev)->ShowPasteAsDialog(ev,
- kODTrue,
- kODFalse,
- facet,
- fSession->Tokenize(ev, kODViewAsFrame),
- dropSU,
- &pasteAsRslt) )
- {
- // Cannot paste a link if translation is required
- if ( pasteAsRslt.translateKind != kODNULL )
- DebugStr("\pcannot translate !!!");
- InternalizeLinkFromSU(ev, dropSU, &pasteAsRslt );
- }
- if( pasteAsRslt.pasteLinkSetting == kODTrue )
- theResult = kODDropMove;
- }
- }
- gotSomething = InternalizeFromSU( ev, dropSU, facet->GetFrame(ev) );
- if( gotSomething && (useLinkInfo == kODFalse) )
- RemoveDestLink( ev );
- if( moveData )
- theResult = kODDropMove;
- else
- theResult = kODDropCopy;
- }
- fAcceptThisDrag = kODFalse;
- }
- return theResult;
- }
-
-
- //----------------------------------------------------------------------------------------
- // From Linking protocol
- //----------------------------------------------------------------------------------------
-
- ODLinkSource* CPPictPart::CreateLink(Environment* ev, ODByteArray* data)
-
- // Creates a new link object.
- //
- // If a link already exists to the content identified by the data
- // and size arguments, this method returns the link object;
- // otherwise, it creates a new link object, puts in the initial
- // data and returns it to the caller.
- //
- // This method identifies the content to be linked (by resolving
- // the object specifier saved in the data parameter, or by some
- // other means). It then creates a link object to represent the
- // content data. The part must maintain information about what
- // portion of its contents have been linked to it, so that it may
- // notify link clients when that data has been changed. The link
- // created is returned to the caller. Before calling this method,
- // you must ensure that the data identifies some portion of this
- // part's contents. After calling this method successfully, this
- // part maintains a link to the identified content.
-
- {
- WeBeHere("\pCPPictPart::CreateLink");
-
- // Call a part-specific method to get the link if it already exists
- ODLinkSource* linkSource = fSrcLink;
-
- if (linkSource == kODNULL)
- {
- // Call this part's draft to create both the link source object
- // used by this part, and the link object returned from this
- // method and used by destinations of the link.
-
- linkSource = fSelf->GetStorageUnit(ev)->GetDraft(ev)->
- CreateLinkSource(ev, fSelf);
- // Add the link to the content model of this part.
- fSrcLink = linkSource;
-
- ODLinkKey key;
- ODVolatile(linkSource);
- ODVolatile(key);
- TRY
- if (linkSource->Lock(ev, 0, &key))
- {
- TRY
- ODStorageUnit* linkContentSU =
- linkSource->GetContentStorageUnit(ev, key);
-
- PrepareSU( ev, linkContentSU );
- ExternalizeToSU( ev, linkContentSU );
- // A new change ID is used to update the link the first time.
- ODChangeID change = fSession->UniqueChangeID(ev);
- linkSource->ContentChanged(ev, change, key);
- fSrcLinkChange = change;
- linkSource->Unlock(ev, key);
-
- CATCH_ALL
-
- DebugStr("\pexception at CreateLink !!!");
- linkSource->Unlock(ev, key);
- RERAISE;
- ENDTRY
- }
- CATCH( kODErrBrokenLinkSource )
- DebugStr("\pPictPart: ODLinkSource::Lock() returned broken link error\n");
- RemoveSourceLink(ev);
- ENDTRY
- }
-
-
- // change link status of my frames
- for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
- {
- if (fl->Frame()->GetPresentation(ev) == fPictNormalPresentation )
- fl->Frame()->ChangeLinkStatus( ev, kODInLinkSource );
- }
-
- // update all my facets
- MySetDirty(ev);
- MyInvalAllDisplayFrames( ev );
-
-
- return linkSource;
-
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::LinkUpdated(Environment* ev, ODLink* updatedLink, ODChangeID id)
-
- // Retrieves the data from the link and incorporates it into
- // this part at the link's destination, thereby replacing any
- // previous content of the link.
-
- {
- WeBeHere("\pCPPictPart::LinkUpdated");
- ODUnused(id);
-
- ODStorageUnit* su;
- ODLinkKey key;
- ODBoolean gotSomething = kODFalse;
-
- if (updatedLink->Lock(ev, 0, &key))
- {
- su = updatedLink->GetContentStorageUnit(ev, key);
- if( ValidDataOnSU( ev, su ) )
- {
- gotSomething = InternalizeFromSU( ev, su );
- fDestLinkInfo.change = fDestLink->GetChangeID(ev);
- fDestLinkInfo.changeTime = fDestLink->GetChangeTime(ev);
- }
- updatedLink->Unlock(ev, key);
- if( gotSomething )
- MyInvalAllDisplayFrames( ev );
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPPictPart::RevealLink(Environment* ev, ODLinkSource* linkSource)
-
- // Reveals data that was previously linked in a window, making it
- // available for viewing in a display frame.
- //
- // Called by ODLinkSource objects. Should not be called by parts.
- // In some display frame for this part, this method selects the
- // content linked by the linkSource argument, and scrolls it into
- // view. That display frame is made the active frame. If no display
- // frames for the part currently exist, or if this part's containing
- // frame can't reveal the display frame, it opens a frame in a new
- // window.
-
- {
- WeBeHere("\pCPPictPart::RevealLink");
-
- if( linkSource != fSrcLink )
- return;
-
- ODFrame* frame = fDisplayFrames.First()->Frame();
-
- if ( frame != (ODFrame*) kODNULL )
- {
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcess(&psn);
-
- ODFrame* containingFrame = frame->GetContainingFrame(ev);
-
- if ( containingFrame != (ODFrame*) kODNULL )
- {
- // Sample parts currently THROW so catch and ignore
- TRY
- containingFrame->GetPart(ev)->RevealFrame(ev, frame, (ODShape*) kODNULL);
- CATCH_ALL
- ENDTRY
- }
-
- // Try to grab all of our foci…
- if ( fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame) )
- {
- this->FocusAcquired(ev, fSelectionFocus, frame);
- this->FocusAcquired(ev, fMenuFocus, frame);
- this->FocusAcquired(ev, fKeyFocus, frame);
-
- ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
- for (ODFacet* facet = facets->First(ev);
- facets->IsNotComplete(ev);
- facet = facets->Next(ev) )
- {
- CFocus myFocus( ev, facet );
- long finalTicks;
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec*)frame->GetPartInfo(ev);
-
- InvertRect( &thisFramePartInfo->activeRect );
- Delay( 10, &finalTicks );
- InvertRect( &thisFramePartInfo->activeRect );
- }
-
- }
- }
- }
-
-
- //----------------------------------------------------------------------------------------
-
-
- // PFB
-
- void CPPictPart::UpdateSourceLink( Environment* ev, Boolean forceUpdate )
- {
-
- if( fSrcLink != kODNULL )
- {
- ODLinkKey linkKey;
- ODLinkSource* linkSource = fSrcLink;
- ODChangeID changeID = fSrcLinkChange;
-
- ODVolatile(linkSource);
- ODVolatile(linkKey);
-
- WeBeHere("\pin UpdateSourceLink…" );
-
- if( forceUpdate || fSrcLink->IsAutoUpdate(ev) )
- {
-
- TRY
- if ( linkSource->Lock(ev, 0, &linkKey) )
- {
- TRY
-
- ODStorageUnit* linkContentSU = linkSource->GetContentStorageUnit(ev, linkKey);
- // Begin a transaction if objects are cloned into the link
- ODDraftKey draftKey = 0;
- ODVolatile(fDraft);
- ODVolatile(draftKey);
- TRY
- draftKey = fDraft->BeginClone(ev,
- linkContentSU->GetDraft(ev),
- kODCloneToLink);
- // For each value in the link, focus and rewrite
- // This is part specific
- PrepareSU( ev, linkContentSU );
- ExternalizeToSU( ev, linkContentSU );
-
- fDraft->EndClone(ev, draftKey);
-
- CATCH_ALL
-
- if (draftKey != 0 )
- fDraft->AbortClone(ev, draftKey);
- RERAISE;
-
- ENDTRY
-
- // Inform the link that it has changed, so destinations can
- // update. The changeID parameter should be the change
- // causing the link to update.
-
- linkSource->ContentChanged(ev, changeID, linkKey);
- linkSource->Unlock(ev, linkKey);
-
- CATCH_ALL
-
- // Clear a partially-updated link
- DebugStr("\pexception at UpdateSourceLink !!!");
- linkSource->Clear(ev, fSession->UniqueChangeID(ev), linkKey);
- linkSource->Unlock(ev, linkKey);
-
- ENDTRY
- }
- else
- {
- DebugStr("\pcannot lock !!!");
- }
- CATCH(kODErrBrokenLinkSource)
- DebugStr("\pPictPart: ODLinkSource::Lock() returned broken link error\n");
- RemoveSourceLink(ev);
- ENDTRY
- }
- }
- }
-
- void CPPictPart::RemoveSourceLink( Environment* ev )
- {
- if( fSrcLink != kODNULL )
- {
-
- WeBeHere("\pin RemoveSourceLink…" );
-
- ODLinkSource* linkSource = fSrcLink;
- fSrcLink = kODNULL;
- fSrcLinkChange = kODUnknownChange;
-
- ODLinkKey linkKey;
- if ( linkSource->Lock(ev, 0, &linkKey) )
- {
- linkSource->ContentChanged(ev, kODUnknownChange, linkKey);
- linkSource->Unlock(ev, linkKey);
- }
-
- linkSource->SetSourcePart(ev, kODNULL);
- linkSource->Release(ev);
-
- for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
- fl->Frame()->ChangeLinkStatus( ev, kODNotInLink );
-
- MySetDirty( ev );
- MyInvalAllDisplayFrames(ev);
- }
- }
-
- void CPPictPart::RemoveDestLink( Environment* ev )
- {
- if( fDestLink != kODNULL )
- {
-
- WeBeHere("\pin RemoveDestLink…" );
-
- if ( fDestLinkInfo.autoUpdate )
- fDestLink->UnregisterDependent(ev, fSelf );
- fDestLink->Release(ev);
- fDestLink = kODNULL;
-
- for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
- fl->Frame()->ChangeLinkStatus( ev, kODNotInLink );
-
- MySetDirty( ev );
- MyInvalAllDisplayFrames(ev);
- }
- }
-
- void CPPictPart::AdjustCursor( Environment* ev, PictPartInfoRec* framePartInfo )
- {
- CUsingLibraryResources fil;
-
- WeBeHere("\pPictPart::AdjustCursor");
-
- if( fCurrentCursorHandle != nil )
- {
- ::HUnlock( (Handle)fCurrentCursorHandle );
- ::DisposeHandle( (Handle)fCurrentCursorHandle );
- fCurrentCursorHandle = nil;
- }
- switch( fCurrentTool )
- {
- case arrowTool:
- ::SetCursor(&ODQDGlobals.arrow);
- break;
- case zoomInTool:
- if( framePartInfo->IsZoomingInAllowed() )
- fCurrentCursorHandle = ::GetCursor( zoomInCursorRsrcId );
- else
- fCurrentCursorHandle = ::GetCursor( noZoomCursorRsrcId );
- break;
- case zoomOutTool:
- if( framePartInfo->IsZoomingOutAllowed() )
- fCurrentCursorHandle = ::GetCursor( zoomOutCursorRsrcId );
- else
- fCurrentCursorHandle = ::GetCursor( noZoomCursorRsrcId );
- break;
- case moveTool:
- fCurrentCursorHandle = ::GetCursor( handCursorRsrcId );
- break;
- }
- if( fCurrentCursorHandle != nil )
- {
- ::DetachResource( (Handle)fCurrentCursorHandle );
- ::HLock( (Handle)fCurrentCursorHandle );
- ::SetCursor( *fCurrentCursorHandle );
- }
- }
-
-
-
- void CPPictPart::PrepareSU( Environment* ev, ODStorageUnit *storageUnit )
- {
- ODStorageUnit *pictPartContentSU;
-
- if (storageUnit->Exists(ev, kODPropContents, kODNULL, 0) == kODFalse)
- pictPartContentSU = storageUnit->AddProperty(ev, kODPropContents);
- else
- pictPartContentSU = storageUnit->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType)kODNULL, 0, kODPosUndefined );
- if( fExternalizeOnlyPICTFormat == kODFalse )
- {
- if (storageUnit->Exists(ev, kODPropContents, kPictPartKind, 0) == kODFalse)
- pictPartContentSU->AddValue(ev, kPictPartKind);
- }
- if (storageUnit->Exists(ev, kODPropContents, kODApplePICT, 0) == kODFalse)
- pictPartContentSU->AddValue(ev, kODApplePICT);
-
- }
-
- void CPPictPart::ExternalizeToSU( Environment* ev, ODStorageUnit *storageUnit,
- ODFrame *frame )
- {
-
- WeBeHere("\pPictPart::ExternalizeToSU");
-
- PictPartInfoRec* thisFramePartInfo;
-
- if( fPicture == nil )
- return;
-
- if( frame != nil )
- thisFramePartInfo = (PictPartInfoRec *)frame->GetPartInfo(ev);
- else
- thisFramePartInfo = new PictPartInfoRec; // for default values
-
- // private format
- if( fExternalizeOnlyPICTFormat == kODFalse )
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kPictPartKind, 0, kODPosUndefined);
- ::HLock( fPicture );
- StorageUnitSetValue( storageUnit, ev, ::GetHandleSize( fPicture ), (ODValue)*fPicture);
- StorageUnitSetValue( storageUnit, ev, sizeof(Point), (ODValue)&(thisFramePartInfo->pictureOffset));
- StorageUnitSetValue( storageUnit, ev, sizeof(int), (ODValue)&(thisFramePartInfo->zoomFactor));
- ::HUnlock( fPicture );
- }
- // universal PICT ???
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kODApplePICT, 0, kODPosUndefined );
- ::HLock( fPicture );
- StorageUnitSetValue( storageUnit, ev, ::GetHandleSize( fPicture ), (ODValue)*fPicture);
- ::HUnlock( fPicture );
-
- if( frame == nil )
- delete thisFramePartInfo;
-
- }
-
- ODBoolean CPPictPart::InternalizeFromSU( Environment* ev, ODStorageUnit *storageUnit, ODFrame *frame)
- {
-
- WeBeHere("\pPictPart::InternalizeFromSU");
-
- Handle suPicHandle;
- long valueSize;
- ODBoolean gotSomething = kODFalse;
-
- if (storageUnit->Exists(ev, kODPropContents, kPictPartKind, 0))
- {
- storageUnit->Focus( ev, kODPropContents, kODPosUndefined, kPictPartKind, 0, kODPosUndefined);
- valueSize = storageUnit->GetSize(ev) - sizeof(Point) - sizeof(int);
- suPicHandle = ::NewHandle( valueSize );
- THROW_IF_NULL( suPicHandle );
- ::HLock( suPicHandle );
- StorageUnitGetValue( storageUnit, ev, valueSize, (ODValue)*suPicHandle);
- ::HUnlock( suPicHandle );
- if( frame != nil )
- {
- PictPartInfoRec* thisFramePartInfo = (PictPartInfoRec *)frame->GetPartInfo(ev);
- if( thisFramePartInfo == nil )
- DebugStr("\pthisFramePartInfo == nil in InternalizeFromSU !!!");
- StorageUnitGetValue( storageUnit, ev, sizeof(Point), (ODValue)&(thisFramePartInfo->pictureOffset));
- StorageUnitGetValue( storageUnit, ev, sizeof(int), (ODValue)&(thisFramePartInfo->zoomFactor));
- }
- if( fPicture != nil )
- ::DisposeHandle( fPicture );
- fPicture = suPicHandle;
- gotSomething = kODTrue;
- }
- else if (storageUnit->Exists(ev, kODPropContents, kODApplePICT, 0))
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kODApplePICT, 0, kODPosUndefined);
- valueSize = storageUnit->GetSize(ev);
- suPicHandle = ::NewHandle( valueSize );
- THROW_IF_NULL( suPicHandle );
- ::HLock( suPicHandle );
- StorageUnitGetValue( storageUnit, ev, valueSize, (ODValue)*suPicHandle);
- ::HUnlock( suPicHandle );
- // store picture and reinit part info (zoom offset,etc… );
- if( fPicture != nil )
- ::DisposeHandle( fPicture );
- fPicture = suPicHandle;
- gotSomething = kODTrue;
- }
- else if( storageUnit->Exists( ev, kODPropContents, kODApplehfs, 0) )
- {
- long fileSize;
- Ptr fileData;
- short fileRefNum;
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kODApplehfs, 0, kODPosUndefined);
- fileSize = storageUnit->GetSize(ev); // really hfsflavor size
- fileData = ::NewPtr( fileSize ); // really hfsflavor data
- THROW_IF_NULL( fileData );
- StorageUnitGetValue( storageUnit, ev, fileSize, (ODValue)fileData);
-
- THROW_IF_ERROR(::FSpOpenDF((FSSpec*)&(((HFSFlavor*)fileData)->fileSpec), fsRdPerm, &fileRefNum));
- THROW_IF_ERROR(::GetEOF(fileRefNum,&valueSize));
- if (valueSize == 0)
- THROW(kODErrUndefined);
- valueSize -= 512;
- suPicHandle = ::NewHandle( valueSize );
- THROW_IF_NULL( suPicHandle );
- ::HLock( suPicHandle );
- THROW_IF_ERROR(::SetFPos(fileRefNum,fsFromStart, 512));
- THROW_IF_ERROR(::FSRead(fileRefNum,&valueSize,*suPicHandle));
- THROW_IF_ERROR(::FSClose(fileRefNum));
- ::DisposePtr( fileData );
- ::HUnlock( suPicHandle );
- // store picture and reinit part info (zoom offset,etc… );
- if( fPicture != nil )
- ::DisposeHandle( fPicture );
- fPicture = suPicHandle;
- gotSomething = kODTrue;
- }
- if( gotSomething )
- {
- MySetDirty(ev);
- UpdateSourceLink( ev, false );
- MyInvalAllDisplayFrames(ev);
- }
- else
- {
- WeBeHere("\pgot nothing …");
- }
-
- return( gotSomething );
- }
-
- const ODISOStr kDummyLinkSpecData = "LinkSpec dummy data";
-
- void CPPictPart::ExternalizeLinkToSU( Environment* ev, ODStorageUnit *storageUnit )
- {
- // Add a link spec to the storage unit if we don't already have a source link
- // (or the source link is selected exactly),
- // and as long as the selection does not include a link destination.
- // Also, don't add a link spec if draft permissions don't allow writing.
-
- WeBeHere("\pPictPart::ExternalizeLinkToSU");
-
- ODBoolean makeLinkSpec = kODFalse;
-
- if( fExternalizeOnlyPICTFormat == kODFalse )
- {
- if ( fDraft->GetPermissions(ev) >= kDPSharedWrite )
- {
- if (fSrcLink == (ODLinkSource*) kODNULL)
- {
- if (fDestLink == (ODLink*) kODNULL)
- {
- makeLinkSpec = kODTrue;
- }
- }
- else
- makeLinkSpec = kODTrue;
- }
-
- if (makeLinkSpec)
- {
- storageUnit->AddProperty(ev, kODPropLinkSpec);
- ODByteArray data = CreateByteArrayStruct(kDummyLinkSpecData, ODISOStrLength(kDummyLinkSpecData));
- ODLinkSpec* linkSpec = fDraft->CreateLinkSpec(ev, fSelf, &data);
- linkSpec->WriteLinkSpec(ev, storageUnit);
- DisposeByteArrayStruct(data);
- delete linkSpec;
- }
- }
- }
-
- ODBoolean CPPictPart::InternalizeLinkFromSU( Environment* ev, ODStorageUnit *storageUnit,
- ODPasteAsResult *pasteAsResult )
- {
-
- WeBeHere("\pPictPart::InternalizeLinkFromSU");
-
- if( storageUnit->Exists(ev, kODPropLinkSpec, (ODValueType) kODNULL, 0) )
- {
- ODLinkSpec* linkSpec = fDraft->CreateLinkSpec(ev, fSelf, 0);
- storageUnit->Focus(ev, kODPropLinkSpec, kODPosUndefined, (ODValueType)kODNULL, 0, kODPosUndefined);
- linkSpec->ReadLinkSpec(ev, storageUnit);
- TRY
- {
- fDestLink = fDraft->GetLink(ev, (ODStorageUnitID) kODNULL, linkSpec);
- if (fDestLink != (ODLink*) kODNULL)
- {
- fDestLinkInfo.change = fDestLink->GetChangeID(ev);
- GetDateTime((ODTime*) &fDestLinkInfo.creationTime);
- fDestLinkInfo.changeTime = fDestLinkInfo.creationTime;
- fDestLinkInfo.kind = pasteAsResult->selectedKind;
- fDestLinkInfo.autoUpdate = pasteAsResult->autoUpdateSetting;
-
- for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
- {
- if (fl->Frame()->GetPresentation(ev) == fPictNormalPresentation )
- fl->Frame()->ChangeLinkStatus( ev, kODInLinkDestination );
- }
-
- // Now register as a dependent of the link
- // Specify kODUnknownChange to force getting the text.
- // By default the destination is automatically updated.
- if( fDestLinkInfo.autoUpdate )
- fDestLink->RegisterDependent(ev, fSelf, kODUnknownChange);
- fDraft->SetChangedFromPrev(ev);
- }
- else
- SysBeep( 30 );
- }
- CATCH_ALL
- DebugStr("\pexception at InternalizeLinkFromSU!!!");
- ENDTRY
- delete linkSpec;
- }
- return kODFalse;
- }
-
- ODBoolean CPPictPart::ValidDataOnSU( Environment* ev, ODStorageUnit *storageUnit)
- {
-
- WeBeHere("\pPictPart::ValidDataOnSU");
-
- HFSFlavor *valueData;
- long valueSize;
- ODBoolean validDataWasFound = kODFalse;
-
- if ( storageUnit->Exists( ev, kODPropContents, kODApplePICT, 0) ||
- storageUnit->Exists( ev, kODPropContents, kPictPartKind, 0) )
- {
- validDataWasFound = kODTrue;
- }
- else
- {
- if ( storageUnit->Exists(ev, kODPropContents, kODApplehfs, 0) )
- {
- storageUnit->Focus( ev, kODPropContents, kODPosUndefined, kODApplehfs, 0, kODPosUndefined );
- valueSize = storageUnit->GetSize(ev);
- valueData = (HFSFlavor *)::NewPtr(valueSize);
- if (valueData)
- {
- StorageUnitGetValue( storageUnit, ev, valueSize, (ODValue)valueData);
- if ((valueData->fileType == 'PICT') ) // sEXT = TeachText stationery
- validDataWasFound = kODTrue;
- }
- ::DisposePtr((Ptr)valueData);
- }
- }
- return( validDataWasFound );
- }
-
- ODBoolean CPPictPart::ValidLinkOnSU( Environment* ev, ODStorageUnit *storageUnit)
- {
-
- WeBeHere("\pPictPart::ValidLinkOnSU");
-
- ODBoolean validDataWasFound = kODFalse;
-
- if ( storageUnit->Exists(ev, kODPropLinkSpec, (ODValueType) kODNULL, 0) )
- {
- validDataWasFound = kODTrue;
- }
- return( validDataWasFound );
- }
-
- Rect CPPictPart::CalcPictureRect( Environment* ev, PictPartInfoRec* framePartInfo )
- {
-
- if( fPicture != nil )
- {
- int zoomFactor;
- Point pictureOffset;
- Rect pictureRect;
- PicHandle thePicture;
-
- thePicture = (PicHandle)fPicture;
- pictureRect = (*thePicture)->picFrame;
- zoomFactor = framePartInfo->zoomFactor;
- pictureOffset = framePartInfo->pictureOffset;
- // normalisation
- ::OffsetRect( &pictureRect, -pictureRect.left, -pictureRect.top );
- // zoom
- if( zoomFactor > 0 )
- {
- pictureRect.right <<= zoomFactor;
- pictureRect.bottom <<= zoomFactor;
- }
- else
- {
- pictureRect.right >>= -zoomFactor;
- pictureRect.bottom >>= -zoomFactor;
- }
- // offset
- ::OffsetRect( &pictureRect, pictureOffset.h, pictureOffset.v );
- // stockage comme partie active
- framePartInfo->activeRect = pictureRect;
- }
- return( framePartInfo->activeRect );
- }
-
- //====================================================================
- // PictPartInfo
- //====================================================================
-
-
- PictPartInfoRec::PictPartInfoRec()
- {
- fIsActive = kODFalse;
- fNeedsActivating = kODFalse;
- Initialize();
- }
-
- PictPartInfoRec::~PictPartInfoRec()
- {
- }
-
- void PictPartInfoRec::Initialize()
- {
- pictureOffset.h = pictureOffset.v = 0;
- zoomFactor = 0;
- activeRect.left = 0;
- activeRect.right = 0;
- activeRect.top = 0;
- activeRect.bottom = 0;
- }
-
-
- void PictPartInfoRec::ZoomIn()
- {
- if( IsZoomingInAllowed() )
- zoomFactor++;
- }
-
- void PictPartInfoRec::ZoomOut()
- {
- if( IsZoomingOutAllowed() )
- zoomFactor--;
- }
-
- ODBoolean PictPartInfoRec::IsZoomingInAllowed()
- {
- return( zoomFactor < 2 );
- }
-
- ODBoolean PictPartInfoRec::IsZoomingOutAllowed()
- {
- return( zoomFactor > -2 );
- }
-
-
-