home *** CD-ROM | disk | FTP | other *** search
- /*
- File: NoPart.cpp
-
- Contains: Implementation of class NoPart
-
- Owned by: Reginald Adkins
-
- Copyright: © 1992 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <7> 7/30/96 eeh 1372943: test for kTranslateItem
- <5> 7/17/96 jpa 1369044: Dispose pixpat in Draw method to
- avoid a memory leak.
- <4> 7/11/96 jpa 1364071: Glitch in message if editor name
- is non-NULL but empty.
- <3> 6/27/96 jpa 1361886: Kinder, gentler NoPart (display
- message to user.) 1361916: Don't force
- process to quit in Open method.
- <2> 6/22/96 EL 1344140: in NoPartOpen, do not rebind if it
- is root and do not call translation dialog.
-
- In Progress:
-
- */
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _ALTPOINT_
- #include <AltPoint.h> // Use C++ savvy XMPPoint and XMPRect
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef SOM_NoPart_xh
- #include <NoPart.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include "FrFaItr.xh"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef _BNDNGDEF_
- #include <BndngDef.h>
- #endif
-
- #ifndef _SHELLDEF_
- #include <ShellDef.h> /* I use RealShell's error messages (from ErrMsgs.r) */
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef SOM_ODPartWrapper_xh
- #include <PartWrap.xh>
- #endif
-
- #ifndef _BINDNGH_
- #include <BindngH.h>
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef _BNDNGDEF_
- #include <BndngDef.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef _TRANSUTL_
- #include <TransUtl.h>
- #endif
-
- #ifndef _BNDNSUTL_
- #include <BndNSUtl.h>
- #endif
-
-
- #pragma segment NoPart
-
- #define SOM_Module_nopart_Source
- #define VARIABLE_MACROS
- #include <NoPart.xih>
-
-
- //==============================================================================
- // Constants
- //==============================================================================
-
-
- const short kButtonWidth = 26; // Dimensions of button
- const short kButtonHeight = 22;
-
- const short kButtonPrefTop = 38; // Preferred position relative to frame top/left
- const short kButtonPrefLeft= 0;
-
- const short kButtonAltTop = 0; // Alternate position if frame too short
- const short kButtonAltLeft = 38;
-
- const short kMinTextWidth = 48; // Min dimensions of usable text box
- const short kMinTextHeight= 12;
-
- const ODError kFakeErrNoEditorNoName = -1;
- const ODError kFakeErrNoEditor = -2;
-
- const short kTranslateItem = 2; // "Translate..." button in alert
- const short kErrorNumberItem= 4;
-
-
- //==============================================================================
- // Variables
- //==============================================================================
-
-
- static ODIconFamily gButtonIcon = kODNULL;
-
-
- //==============================================================================
- // Local Functions
- //==============================================================================
-
-
- static void TransparentTextBox( void *text, short length, const Rect &box);
-
-
- static inline short Width ( const Rect &r ) {return r.right-r.left;}
- static inline short Height( const Rect &r ) {return r.bottom-r.top;}
-
-
-
- //==============================================================================
- // NoPart
- //==============================================================================
-
-
- //--------------------------------------------------------------------
- // somUninit
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartsomUninit(Apple_NoPart *somSelf)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","somUninit");
-
- DisposeIText(_fUserMessageEditorName);
- delete _fUserMessageParam;
- }
-
-
- //--------------------------------------------------------------------
- // Release
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartRelease(Apple_NoPart *somSelf, Environment *ev)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","Release");
-
- SOM_TRY
-
- parent_Release(somSelf, ev);
- if (somSelf->GetRefCount(ev) == 0)
- _fStorageUnit->GetDraft(ev)->ReleasePart(ev, (ODPart*)_fPartWrapper);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //--------------------------------------------------------------------
- // InitPart
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartInitPart(Apple_NoPart *somSelf, Environment *ev,
- ODStorageUnit* storageUnit, ODPart* partWrapper)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","InitPart");
-
- SOM_TRY
-
- parent_InitPart(somSelf, ev, storageUnit, partWrapper);
-
- _fStorageUnit = storageUnit;
- _fPartWrapper = (ODPartWrapper*)partWrapper;
- _fSession = storageUnit->GetSession(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //--------------------------------------------------------------------
- // InitPartFromStorage
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartInitPartFromStorage(Apple_NoPart *somSelf, Environment *ev,
- ODStorageUnit* storageUnit, ODPart* partWrapper)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","InitPartFromStorage");
-
- SOM_TRY
-
- parent_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
-
- _fStorageUnit = storageUnit;
- _fPartWrapper = (ODPartWrapper*)partWrapper;
- _fSession = storageUnit->GetSession(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //--------------------------------------------------------------------
- // SetUserMessage
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartSetUserMessage( Apple_NoPart *somSelf, Environment *ev,
- ODError err,
- ODIText *editorName,
- corbastring param )
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","SetUserMessage");
-
- SOM_TRY
-
- if( editorName && GetITextStringLength(editorName)==0 ) {
- DisposeIText(editorName);
- editorName = kODNULL;
- }
-
- if( err == 0 )
- err = editorName ?kFakeErrNoEditor :kFakeErrNoEditorNoName;
- _fUserMessageID = err;
- _fUserMessageEditorName = editorName;
- if( param )
- _fUserMessageParam = ODISOStrFromCStr(param);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //--------------------------------------------------------------------
- // ComputeButtonLocation
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartComputeButtonLocation( Apple_NoPart *somSelf, Environment *ev,
- ODFrame *frame,
- Rect *loc,
- Rect *textBox )
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ComputeButtonLocation");
-
- // Load icon now since caller will presumably need it:
- if( !gButtonIcon ) {
- CUsingLibraryResources r;
- OSErr err= GetIconSuite(&gButtonIcon,kNoPartButtonIconResID,kSelectorAllAvailableData);
- WASSERTM(err==noErr||err==memFullErr,"Can't get NoPart button");
- }
-
- TempODShape usedShape = frame->AcquireUsedShape(ev,kODNULL);
- Rect used = (**(usedShape->GetQDRegion(ev))).rgnBBox;
- InsetRect(&used,3,3); // allow for border
-
- // Preferentially put the button below the icon.
- // If the frame isn't tall enough, put it to the right.
- // If it's not even wide enough, put it at the bottom right.
-
- loc->left = used.left;
- loc->top = used.top;
- if( kButtonPrefTop + kButtonHeight <= Height(used) ) {
- loc->left += kButtonPrefLeft;
- loc->top += kButtonPrefTop;
- } else if( kButtonAltLeft + kButtonWidth <= Width(used) ) {
- loc->left += kButtonAltLeft;
- loc->top += kButtonAltTop;
- } else {
- loc->left = used.right-kButtonWidth;
- loc->top = used.bottom-kButtonHeight;
- }
-
- textBox->left = loc->left + kButtonWidth + 2; // Put text to right of button
- textBox->top = loc->top - 2;
- if( used.right-textBox->left < kMinTextWidth ) {
- textBox->left -= kButtonWidth+2; // ...but if no room move it below
- textBox->top += kButtonHeight+4;
- }
-
- textBox->right = used.right;
- textBox->bottom= used.bottom;
-
- loc->right = loc->left + 32; // Icon utils want exact 32x32 rect
- loc->bottom= loc->top + 32;
-
- if( Width(*textBox) < kMinTextWidth || Height(*textBox)< kMinTextHeight)
- textBox->bottom=textBox->top; // Force empty if it's too small
- }
-
-
- static void
- Substitute( Handle text, Str255 replacement, int which )
- {
- unsigned char whichStr[3] = "\p^0";
- whichStr[2] = '0'+which;
- Handle replaceH;
- THROW_IF_ERROR( PtrToHand(&replacement[1],&replaceH,replacement[0]) );
- ReplaceText(text,replaceH,whichStr);
- DisposeHandle(replaceH);
- }
-
-
- //--------------------------------------------------------------------
- // ComputeUserMessage
- //--------------------------------------------------------------------
-
- SOM_Scope ODIText SOMLINK NoPartComputeUserMessage( Apple_NoPart *somSelf, Environment *ev )
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ComputeUserMessage");
-
- Str255 messageStr;
- ODBoolean noSpecific = kODFalse;
- if( ! LookupString(_fUserMessageID,kNoPartMessageTableID,messageStr) ) {
- // No specific message. Get generic message & remember to lookup Shell msg later:
- CUsingLibraryResources r;
- GetIndString(messageStr,kNoPartMessageTableID,1);
- noSpecific = kODTrue;
- }
-
- Handle messageH = kODNULL;
- THROW_IF_ERROR( PtrToHand(&messageStr[1],&messageH,messageStr[0]) );
- TempODHandle tempMessageH = messageH; // ensure deletion
-
- Str255 editor;
- if( _fUserMessageEditorName )
- GetITextPString(_fUserMessageEditorName,editor);
- else
- editor[0] = '\0';
-
- Str255 param;
- if( noSpecific )
- LookupString(_fUserMessageID,kODErrUserID,param); // Get Shell's message as param
- else // (requires access to Shell rsrcs!)
- CopyISOStr2PStr(param,_fUserMessageParam);
-
-
- Str31 errStr;
- NumToString(_fUserMessageID,errStr);
-
- Substitute(messageH, editor, 1);
- Substitute(messageH, param, 2);
- Substitute(messageH, errStr, 3);
-
- ODIText itext;
- InitIText(&itext);
- HLock(messageH);
- SetITextText(&itext, (ODUByte*)*messageH, GetHandleSize(messageH));
- return itext;
- }
-
-
- //--------------------------------------------------------------------
- // Draw
- //--------------------------------------------------------------------
-
- SOM_Scope void SOMLINK NoPartDraw(Apple_NoPart *somSelf, Environment *ev,
- ODFacet* facet, ODShape* invalidShape)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","Draw");
-
- ODUnused(invalidShape);
-
- SOM_TRY
-
- ODFrame* frame = facet->GetFrame(ev);
- ODTypeToken view = frame->GetViewType(ev);
-
- IconTransformType transformType = ttNone;
- ODWindow* window = facet->GetWindow(ev);
-
- // Check to see if the frame is selected and in an active window
- // if ( facet->GetHighlight(ev) == kODFullHighlight &&
- // window->IsActive(ev) )
- // transformType = ttSelected;
-
- Rect iconRect;
- if (view == _fSession->Tokenize(ev, kODViewAsSmallIcon))
- SetRect(&iconRect, 0, 0, 16, 16);
- else
- SetRect(&iconRect, 0, 0, 32, 32);
-
- // Init the icon family if necessary
- if (_fIconFamily == kODNULL)
- _fIconFamily = ODGetIconFamily(ev, frame);
-
- TempODShape usedShape = frame->AcquireUsedShape(ev, kODNULL);
- RgnHandle usedRgn = usedShape->GetQDRegion(ev);
-
- // Now it's time to draw:
- CFocus foc(ev,facet);
- EraseRgn(usedRgn);
-
- if ( view == _fSession->Tokenize(ev, kODViewAsLargeIcon) ||
- view == _fSession->Tokenize(ev, kODViewAsSmallIcon) )
- {
- }
- else if ( view == _fSession->Tokenize(ev, kODViewAsThumbnail) )
- {
- CUsingLibraryResources res;
- Handle thumbnail = (Handle) GetPicture(kNoPartThumbnail);
-
- if ( thumbnail == kODNULL ) {
- THROW_IF_ERROR((ODError)ResError());
- THROW(resNotFound);
- }
-
- Rect bounds = (**(PicHandle) thumbnail).picFrame;
- OffsetRect(&bounds, -bounds.left, -bounds.top);
- DrawPicture((PicHandle) thumbnail, &bounds);
- ReleaseResource(thumbnail);
- }
- else // if ( view == _fSession->Tokenize(ev, kODViewAsFrame) )
- {
- RGBColor rgb = {32768,32768,32768};
- PixPatHandle ppat = NewPixPat();
- MakeRGBPat(ppat, &rgb);
- BackPixPat(ppat);
-
- EraseRgn(usedRgn);
- FrameRgn(usedRgn);
-
- // Draw button & message, if any
- {
- Rect rButton, rText;
- somSelf->ComputeButtonLocation(ev, frame, &rButton, &rText);
- if( gButtonIcon )
- PlotIconSuite(&rButton, atTopLeft, ttNone, gButtonIcon);
-
- if( !EmptyRect(&rText) ) {
- ODIText text = somSelf->ComputeUserMessage(ev);
- short savedFont = qd.thePort->txFont;
- short savedSize = qd.thePort->txSize;
- long fontsize = GetScriptVariable(GetITextScriptCode(&text),
- smScriptSmallFondSize);
- TextFont( fontsize >> 16 );
- TextSize( fontsize & 0xFFFF );
- TextFace(0);
-
- FontInfo i;
- GetFontInfo(&i);
- rText.bottom -= Height(rText) % (i.ascent+i.descent+i.leading); // no partial lines
-
- TETextBox( GetITextPtr(&text), GetITextStringLength(&text), &rText, teFlushDefault );
-
- TextFont(savedFont);
- TextSize(savedSize);
- DisposeITextStruct(text);
- }
- }
-
- BackPat(&qd.white);
- DisposePixPat(ppat); // According to IM, QD will dispose it, but IM is wrong...
-
- OffsetRect(&iconRect,2,2); // Position icon away from border
- }
-
- // Finally draw the part icon:
- PlotIconSuite(&iconRect, atTopLeft, transformType, _fIconFamily);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //--------------------------------------------------------------------
- // Open
- //--------------------------------------------------------------------
-
- SOM_Scope ODID SOMLINK NoPartOpen(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- /* Open just calls ShowUserMessage (q.v.) which will first attempt
- to rebind if this makes sense.
- In the special case where this is the root part, Open will put
- up an appropriate alert and always return false.
- If rebinding fails, I throw kODErrAlreadyNotified to inform the
- caller that the Open failed but that I've already alerted the
- user.
- In the case of the root part, the error will prevent the document
- from opening. If it was the first/only document, the process
- quits. Yay! */
-
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","Open");
-
- SOM_TRY
-
- if( ! somSelf->ShowUserMessage(ev,kODTrue) )
- THROW(kODErrAlreadyNotified);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return 0;
- }
-
-
- //--------------------------------------------------------------------
- // HandleEvent
- //--------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK NoPartHandleEvent(Apple_NoPart *somSelf, Environment *ev,
- ODEventData* event,
- ODFrame* frame,
- ODFacet* facet,
- ODEventInfo* eventInfo)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","HandleEvent");
-
- ODBoolean tWasHandled = kODFalse;
-
- SOM_TRY
-
- switch (event->what)
- {
- case nullEvent:
- break;
-
- case mouseDown:
- if ( somSelf->CheckDoubleClick(ev, event) )
- {
- _fIsDoubleClick = kODTrue;
- }
- else
- {
- Rect rButton, rText;
- somSelf->ComputeButtonLocation(ev, frame, &rButton, &rText);
- if( PtInIconSuite(eventInfo->where.AsQDPoint(),&rButton,atTopLeft,gButtonIcon) ) {
- // Track click in button:
- if( somSelf->TrackButton(ev,facet,&rButton) )
- (void) somSelf->ShowUserMessage(ev,kODTrue);
- } else {
- // Otherwise pass click to container to select this frame:
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- if (containingFrame)
- {
- event->what = kODEvtMouseDownEmbedded;
- eventInfo->embeddedFrame = frame;
- eventInfo->embeddedFacet = facet;
- TempODPart part = containingFrame->AcquirePart(ev);
- tWasHandled = part->
- HandleEvent(ev,event,containingFrame,facet->GetContainingFacet(ev),eventInfo);
- }
- }
- }
- break;
-
- case mouseUp:
-
- tWasHandled = kODTrue;
- somSelf->CaptureMouseUpEvent(ev, event, frame);
- if (_fIsDoubleClick)
- {
- somSelf->Open(ev, frame);
- tWasHandled = kODTrue;
- _fIsDoubleClick = kODFalse;
- }
- break;
-
- default:
- return kODFalse;
- }
-
- SOM_CATCH_ALL
- tWasHandled = kODFalse;
- SOM_ENDTRY
-
- return tWasHandled;
- }
-
-
- //--------------------------------------------------------------------
- // TrackButton
- //--------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK NoPartTrackButton(Apple_NoPart *somSelf, Environment *ev,
- ODFacet *facet,
- Rect *button)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","TrackButton");
-
- CFocus foc(ev,facet);
-
- ODBoolean inside = kODFalse;
- do {
- Point mouse;
- GetMouse(&mouse);
- ODBoolean nowinside = PtInIconSuite(mouse,button,atTopLeft,gButtonIcon);
- if( nowinside != inside ) {
- PlotIconSuite(button, atTopLeft, nowinside ?ttSelected:ttNone, gButtonIcon);
- inside = nowinside;
- }
- } while( StillDown() );
-
- if( inside )
- PlotIconSuite(button, atTopLeft, ttNone, gButtonIcon);
- return inside;
- }
-
-
- static ODBoolean
- IsRootPartSU( Environment *ev, ODStorageUnit *su )
- {
- TempODStorageUnit rootSU = ODAcquireRootPartSUOfDraft(ev,su->GetDraft(ev));
- return su==rootSU;
- }
-
-
- static void
- GetDocumentName( Environment *ev, ODStorageUnit *su, Str63 name )
- {
- TempODContainerIDStruct id( su->GetDraft(ev)->GetDocument(ev)->GetContainer(ev)->GetID(ev));
- ASSERT(id->_length>=8 && id->_length<=sizeof(FSSpec), kODErrAssertionFailed);
- CopyPascalString(name, ((FSSpec*)id->_buffer)->name);
- }
-
-
- //--------------------------------------------------------------------
- // Rebind
- //--------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK NoPartRebind(Apple_NoPart *somSelf, Environment *ev )
- {
- /* Rebinding is tricky when called from the part itself.
- The part _will_ be deleted whether or not the operation succeeded!
- Do not use 'somSelf' or 'somThis' after calling this method. */
-
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","Rebind");
-
- ODBoolean status = kODTrue;
-
- SOM_TRY
-
- if( ODGetDraft(ev, _fStorageUnit)->GetPermissions(ev) < kODDPSharedWrite )
- THROW(kODErrInvalidPermissions);
- // Unfortunately one can't swap editors in a read-only document because
- // UseEditor externalizes the WindowState...
-
- TempODEditor theEditor = _fSession->GetBinding(ev)->
- ChooseEditorForPart( ev, _fStorageUnit, kODNULL );
- ODBoolean editorIsNoPart = ODISOStrEqual(theEditor, kODBlackBoxHandlerOfLastResort);
-
- if( !editorIsNoPart )
- _fPartWrapper->UseEditor(ev,theEditor);
- else
- status = kODFalse;
-
- SOM_CATCH_ALL
- status = kODFalse;
- SetErrorCode(kODNoError); // don't propagate any exception
- SOM_ENDTRY
- return status;
- }
-
-
- static ODBoolean
- CanTranslate( Environment *ev, ODSession *session, ODPartWrapper *partWrapper )
- {
- // This function was blatantly stolen from TransDlg.cpp
- TRY{
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
- ODStorageUnit* storageUnit = partWrapper->GetStorageUnit(ev);
-
- // Create the list of kinds and translations
- TempODTypeList kindList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
-
- ContentValueTypes(storageUnit, kindList);
-
- { TempODEditor tempEditor = GetCurrentEditorForPart(partWrapper);
- GetAllKindsForEditor(nsm, kindList, tempEditor);
- }
-
- TempODTypeList translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
-
- OrderedCollection translateFromList;
- GetDestinationKindsList(kindList, translateToList, &translateFromList, session);
-
- return (translateToList->Count(ev) > 0);
- }CATCH_ALL{
- WARN("CanTranslate got err %ld",ErrorCode());
- }ENDTRY
- return kODFalse;
- }
-
-
- //--------------------------------------------------------------------
- // ShowUserMessage
- //--------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK NoPartShowUserMessage( Apple_NoPart *somSelf, Environment *ev,
- ODBoolean allowRebind )
- {
- /* There are a couple of things going on here.
- 1. First try reloading the original editor. If we succeed, just return.
- 2. Display the alert explaining why the part couldn't be opened.
- (If this is the root part, use a special alert that explains why the _document_
- couldn't be opened.)
- */
-
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ShowUserMessage");
-
- // Check whether this is the root part, and if not, attempt to rebind:
- short id;
- ODBoolean writeable = ODGetDraft(ev, _fStorageUnit)->GetPermissions(ev) >= kODDPSharedWrite;
- Str63 docName = "\p";
- if( IsRootPartSU(ev,_fStorageUnit) ) {
- id = kNoPartRootDlogID; // special alert for root part
- GetDocumentName(ev,_fStorageUnit,docName);
- } else {
- // First try to rebind if doc is writeable:
- id = kNoPartDlogID;
- if( allowRebind && writeable ) {
- ODPart *wrapper = _fPartWrapper;
- if( somSelf->Rebind(ev) )
- return kODTrue;
- else {
- /* We're in a precarious state now: Even though the rebind failed,
- the part has been deleted. To get around this, find the _new_
- part and tell it to show the message. */
- Apple_NoPart *part = CAST(wrapper->GetRealPart(ev),Apple_NoPart);
- wrapper->ReleaseRealPart(ev);
- part->ShowUserMessage(ev,kODFalse);
- return kODFalse;
- }
- }
- }
-
- // Determine the text to be put into the alert:
- ODIText msg = somSelf->ComputeUserMessage(ev);
- Str255 message;
- GetITextPString(&msg,message);
- DisposeITextStruct(msg);
-
- Str31 errStr;
- NumToString(_fUserMessageID,errStr);
-
- ODBoolean canTranslate;
- Str255 translateStr;
- if( _fUserMessageID==kFakeErrNoEditor || _fUserMessageID==kFakeErrNoEditorNoName ) {
- canTranslate = writeable && CanTranslate(ev,_fSession,_fPartWrapper);
- CUsingLibraryResources r;
- GetIndString(translateStr,kNoPartTranslationStrID, 1+canTranslate);
- } else {
- canTranslate = kODFalse;
- translateStr[0] = '\0';
- }
-
- ParamText(message,docName,translateStr,errStr);
-
- // Show the alert (which is really a dialog so we can play with the Translate button):
- short result = ok;
- if ( _fUserMessageID != kODErrAlreadyNotified ) // should test earlier?
- {
- CUsingLibraryResources r;
- DialogPtr dlog = ODGetNewDialog(ev,id,_fSession,kODFalse);
- if( !dlog ) return kODFalse;
- SetDialogDefaultItem(dlog,ok);
-
- if( _fUserMessageID==kFakeErrNoEditor || _fUserMessageID==kFakeErrNoEditorNoName ) {
- HideDialogItem(dlog,kErrorNumberItem);
- if( !canTranslate ) {
- short typ;
- ControlHandle but;
- Rect box;
- GetDialogItem(dlog,kTranslateItem,&typ,(Handle*)&but,&box);
- HiliteControl(but,kControlDisabledPart);
- }
- } else
- HideDialogItem(dlog,kTranslateItem);
-
- SetPort(dlog);
- ShowWindow(dlog);
- SelectWindow(dlog);
- TempODMenuBar menu = _fSession->GetWindowState(ev)->AcquireCurrentMenuBar(ev);
- ODDialogBegin(ev,_fSession,menu,dlog);
- ModalDialog(GetODDialogFilter(),&result);
- DisposeDialog(dlog);
- ODDialogEnd();
- }
-
- // Run the translation dialog if the user pushed the "Translate..." button:
- if( result==kTranslateItem ) {
- TRY{
- ODTranslation* translation = _fSession->GetTranslation(ev);
- result= translation->ShowPartTranslateDialog(ev, _fPartWrapper);
- }CATCH_ALL{
- WARN("Translation returned err %ld",ErrorCode());
- result = kODFalse;
- }ENDTRY
- return result;
- }
-
- return kODFalse;
- }
-
-
-
- //--------------------------------------------------------------------
- // CaptureMouseUpEvent
- //--------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK NoPartCaptureMouseUpEvent(Apple_NoPart *somSelf, Environment *ev,
- ODEventData* event,
- ODFrame* frame)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","NoPartCaptureMouseUpEvent");
-
- ODBoolean returnVal = kODTrue;
-
- // do this for double-click monitoring
- _fMouseWhen = event->when;
- _fMouseWhere = event->where;
-
- return (returnVal);
- }
-
-
- //--------------------------------------------------------------------
- // CheckDoubleClick
- //--------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK NoPartCheckDoubleClick(Apple_NoPart *somSelf, Environment *ev,
- ODEventData* event)
- {
- Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","NoPartCheckDoubleClick");
-
- ODBoolean isDoubleClick;
- Rect testRect;
-
- isDoubleClick = (event->when - _fMouseWhen) <= GetDblTime();
-
- SetRect(&testRect, _fMouseWhere.IntX( ), _fMouseWhere.IntY( ),
- _fMouseWhere.IntX( ), _fMouseWhere.IntY( ));
- InsetRect(&testRect, -2, -2);
-
- isDoubleClick &= PtInRect(event->where, &testRect);
-
- return isDoubleClick;
- }
-
-
- //--------------------------------------------------------------------
- // Stub methods
- //--------------------------------------------------------------------
-
-
- #pragma mark -------stubs-------
-
-
- SOM_Scope void SOMLINK NoPartContainingPartPropertiesUpdated(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame,
- ODStorageUnit* propertyUnit)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ContainingPartPropertiesUpdated");
-
- }
-
- SOM_Scope void SOMLINK NoPartDisplayFrameAdded(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameAdded");
- }
-
- SOM_Scope void SOMLINK NoPartDisplayFrameRemoved(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameRemoved");
-
- }
-
- SOM_Scope void SOMLINK NoPartDisplayFrameConnected(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameConnected");
- }
-
- SOM_Scope void SOMLINK NoPartDisplayFrameClosed(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameClosed");
- }
-
- SOM_Scope void SOMLINK NoPartAttachSourceFrame(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame,
- ODFrame* sourceFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","AttachSourceFrame");
- }
-
- SOM_Scope void SOMLINK NoPartFrameShapeChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","FrameShapeChanged");
- }
-
- SOM_Scope void SOMLINK NoPartViewTypeChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ViewTypeChanged");
- }
-
- SOM_Scope void SOMLINK NoPartPresentationChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","PresentationChanged");
- }
-
- SOM_Scope void SOMLINK NoPartSequenceChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","SequenceChanged");
- }
-
- SOM_Scope ODInfoType SOMLINK NoPartReadPartInfo(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame,
- ODStorageUnitView* storageUnitView)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ReadPartInfo");
-
- return kODNULL;
- }
-
- SOM_Scope void SOMLINK NoPartWritePartInfo(Apple_NoPart *somSelf, Environment *ev,
- ODInfoType partInfo,
- ODStorageUnitView* storageUnitView)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","WritePartInfo");
-
- }
-
- SOM_Scope void SOMLINK NoPartClonePartInfo(Apple_NoPart *somSelf, Environment *ev,
- ODDraftKey key,
- ODInfoType partInfo,
- ODStorageUnitView* storageUnitView,
- ODFrame* scopeFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ClonePartInfo");
-
- }
-
- SOM_Scope void SOMLINK NoPartFacetAdded(Apple_NoPart *somSelf, Environment *ev,
- ODFacet* facet)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- }
-
- SOM_Scope void SOMLINK NoPartFacetRemoved(Apple_NoPart *somSelf, Environment *ev,
- ODFacet* facet)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","FacetRemoved");
- }
-
- SOM_Scope void SOMLINK NoPartCanvasChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFacet* facet)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","CanvasChanged");
- }
-
- SOM_Scope void SOMLINK NoPartGeometryChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFacet* facet,
- ODBoolean clipShapeChanged,
- ODBoolean externalTransformChanged)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","GeometryChanged");
- }
-
- SOM_Scope void SOMLINK NoPartCanvasUpdated(Apple_NoPart *somSelf, Environment *ev,
- ODCanvas* canvas)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","CanvasUpdated");
- }
-
- SOM_Scope void SOMLINK NoPartHighlightChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFacet* facet)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","HighlightChanged");
- }
-
- SOM_Scope ODULong SOMLINK NoPartGetPrintResolution(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","GetPrintResolution");
-
- return 0;
- }
-
- SOM_Scope void SOMLINK NoPartLinkStatusChanged(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","LinkStatusChanged");
- }
-
- SOM_Scope ODBoolean SOMLINK NoPartBeginRelinquishFocus(Apple_NoPart *somSelf, Environment *ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","BeginRelinquishFocus");
-
- return kODFalse;
- }
-
- SOM_Scope void SOMLINK NoPartCommitRelinquishFocus(Apple_NoPart *somSelf, Environment *ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","CommitRelinquishFocus");
- }
-
- SOM_Scope void SOMLINK NoPartAbortRelinquishFocus(Apple_NoPart *somSelf, Environment *ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","AbortRelinquishFocus");
- }
-
- SOM_Scope void SOMLINK NoPartFocusAcquired(Apple_NoPart *somSelf, Environment *ev,
- ODTypeToken focus,
- ODFrame* ownerFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","FocusAcquired");
- }
-
- SOM_Scope void SOMLINK NoPartFocusLost(Apple_NoPart *somSelf, Environment *ev,
- ODTypeToken focus,
- ODFrame* ownerFrame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","FocusLost");
- }
-
-
- SOM_Scope void SOMLINK NoPartExternalizeKinds(Apple_NoPart *somSelf, Environment *ev,
- ODTypeList* kindset)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ExternalizeKinds");
- }
-
- SOM_Scope void SOMLINK NoPartChangeKind(Apple_NoPart *somSelf, Environment *ev,
- ODType kind)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","ChangeKind");
- }
-
- SOM_Scope void SOMLINK NoPartAdjustMenus(Apple_NoPart *somSelf, Environment *ev,
- ODFrame* frame)
- {
- // Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
- Apple_NoPartMethodDebug("Apple_NoPart","AdjustMenus");
- }
-