[Rezilla-commits] RezillaSource/Rezilla_Src/Editors/Plugin_editor CPluginEditorDoc.cp, 1.34, 1.35
Brought to you by:
bdesgraupes
From: Bernard D. <bde...@us...> - 2006-11-25 12:00:06
|
Update of /cvsroot/rezilla/RezillaSource/Rezilla_Src/Editors/Plugin_editor In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv29379 Modified Files: CPluginEditorDoc.cp Log Message: Improved error control Index: CPluginEditorDoc.cp =================================================================== RCS file: /cvsroot/rezilla/RezillaSource/Rezilla_Src/Editors/Plugin_editor/CPluginEditorDoc.cp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- CPluginEditorDoc.cp 27 Oct 2006 09:38:39 -0000 1.34 +++ CPluginEditorDoc.cp 25 Nov 2006 11:59:59 -0000 1.35 @@ -78,6 +78,7 @@ { OSErr error = noErr; Handle rezData; + Boolean acceptIt = true; ThrowIfNil_(mPlugin); @@ -96,85 +97,90 @@ } } - SPluginEditorInterface** interface = mPlugin->GetInterface(); - ThrowIfNil_(interface); - - // Install the contents - if (mRezObj != nil) { - rezData = mRezObj->GetData(); - if (rezData != nil) { - // Work with a copy of the handle - ::HandToHand(&rezData); + if (error == noErr) { + SPluginEditorInterface** interface = mPlugin->GetInterface(); + ThrowIfNil_(interface); + + // Install the contents + if (mRezObj != nil) { + rezData = mRezObj->GetData(); + if (rezData != nil) { + // Work with a copy of the handle + ::HandToHand(&rezData); + } } - } - - // Ask the plugin its initial requirements - RezPlugInfo plugInfo; - RezHostInfo hostInfo; - - UCursor::SetWatch(); // May take a little while - - plugInfo.error = noErr; - - // Pass mSubstType, not mRezObj->GetType() - if ( (*interface)->AcceptResource(interface, mSubstType, mRezObj->GetID(), rezData, &plugInfo) ) { - mAttributes = plugInfo.attributes; - // Create a window for our document and set this doc as its SuperCommander - mPluginWindow = CreatePluginWindow(plugInfo.attributes, plugInfo.winbounds); - Assert_( mPluginWindow != nil ); + // Ask the plugin its initial requirements + RezPlugInfo plugInfo; + RezHostInfo hostInfo; - // See LWindow::CreateWindow() - SetDefaultCommander(this); - SetDefaultAttachable(nil); - - mPluginWindow->SetPlugRef(plugInfo.plugref); + UCursor::SetWatch(); // May take a little while - SetMainWindow( dynamic_cast<CEditorWindow *>(mPluginWindow) ); - NameNewEditorDoc(); - mPluginWindow->FinalizeEditor(this, NULL); + plugInfo.error = noErr; - // Create the plugin menus - hostInfo.menucount = mPlugin->CreateMenus(plugInfo.menucount, plugInfo.menuIDs); + // Pass mSubstType, not mRezObj->GetType() + acceptIt = (*interface)->AcceptResource(interface, mSubstType, mRezObj->GetID(), rezData, &plugInfo); - // Fill the reply structure - hostInfo.bundleref = ::CFPlugInGetBundle( mPlugin->GetPluginRef() ); - hostInfo.winref = mPluginWindow->GetMacWindow(); - hostInfo.readonly = IsReadOnly(); - if (mRezObj != nil) { - hostInfo.refnum = mRezObj->GetOwnerRefnum(); + if (acceptIt) { + mAttributes = plugInfo.attributes; + + // Create a window for our document and set this doc as its SuperCommander + mPluginWindow = CreatePluginWindow(plugInfo.attributes, plugInfo.winbounds); + Assert_( mPluginWindow != nil ); + + // See LWindow::CreateWindow() + SetDefaultCommander(this); + SetDefaultAttachable(nil); + + mPluginWindow->SetPlugRef(plugInfo.plugref); + + SetMainWindow( dynamic_cast<CEditorWindow *>(mPluginWindow) ); + NameNewEditorDoc(); + mPluginWindow->FinalizeEditor(this, NULL); + + // Create the plugin menus + hostInfo.menucount = mPlugin->CreateMenus(plugInfo.menucount, plugInfo.menuIDs); + + // Fill the reply structure + hostInfo.bundleref = ::CFPlugInGetBundle( mPlugin->GetPluginRef() ); + hostInfo.winref = mPluginWindow->GetMacWindow(); + hostInfo.readonly = IsReadOnly(); + if (mRezObj != nil) { + hostInfo.refnum = mRezObj->GetOwnerRefnum(); + } else { + hostInfo.refnum = kResFileNotOpened; + } + + if (hostInfo.menucount > 0) { + mMenuRefs = (MenuRef *) malloc( sizeof(MenuRef) * hostInfo.menucount); + if (mMenuRefs != NULL) { + TArray<LMenu*>* menusListPtr = mPlugin->GetMenusList(); + + TArrayIterator<LMenu*> iterator(*menusListPtr); + LMenu * theMenu; + int i = 0; + while (iterator.Next(theMenu)) { + mMenuRefs[i] = theMenu->GetMacMenuH(); + i++; + } + } + } + hostInfo.menurefs = mMenuRefs; + + mPluginWindow->GetContentsRect(hostInfo.editrect); } else { - hostInfo.refnum = kResFileNotOpened; + ReportPluginError(CFSTR("PluginEditorRefusedResource"), plugInfo.error); + error = err_PluginRefusedResource; } - if (hostInfo.menucount > 0) { - mMenuRefs = (MenuRef *) malloc( sizeof(MenuRef) * hostInfo.menucount); - if (mMenuRefs != NULL) { - TArray<LMenu*>* menusListPtr = mPlugin->GetMenusList(); - - TArrayIterator<LMenu*> iterator(*menusListPtr); - LMenu * theMenu; - int i = 0; - while (iterator.Next(theMenu)) { - mMenuRefs[i] = theMenu->GetMacMenuH(); - i++; - } - } - } - hostInfo.menurefs = mMenuRefs; + if (error == noErr) { + // Now pass the info struct to the plugin for editing + error = (*interface)->EditResource(plugInfo.plugref, hostInfo); + } + } - mPluginWindow->GetContentsRect(hostInfo.editrect); - } else { - error = plugInfo.error; - } - - if (error == noErr) { - // Now pass the info struct to the plugin for editing - error = (*interface)->EditResource(plugInfo.plugref, hostInfo); - } - if (error != noErr) { - if (error != userCanceledErr) { + if (error != userCanceledErr && error != err_PluginRefusedResource) { ReportPluginError(CFSTR("ErrorUsingPluginEditor"), error); } delete this; @@ -413,7 +419,6 @@ // --------------------------------------------------------------------------- // ReportPluginError [public] // --------------------------------------------------------------------------- -// Create the plugin window in compositing mode void CPluginEditorDoc::ReportPluginError(CFStringRef inCFStringRef, SInt32 inError) |