xref: /aoo41x/main/sfx2/source/view/viewfrm.cxx (revision 0deba7fb)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 #include <stdio.h>
28 
29 #include <sfx2/viewfrm.hxx>
30 #include <com/sun/star/document/MacroExecMode.hpp>
31 #include <com/sun/star/frame/XLoadable.hpp>
32 #include <com/sun/star/frame/XLayoutManager.hpp>
33 #include <com/sun/star/frame/XComponentLoader.hpp>
34 
35 #include <toolkit/unohlp.hxx>
36 #include <vcl/splitwin.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/visitem.hxx>
40 #include <svl/stritem.hxx>
41 #include <svl/eitem.hxx>
42 #include <svl/slstitm.hxx>
43 #include <svl/whiter.hxx>
44 #include <svl/undo.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <svtools/sfxecode.hxx>
47 #include <svtools/ehdl.hxx>
48 #include <tools/diagnose_ex.h>
49 #include <com/sun/star/container/XIndexAccess.hpp>
50 #include <com/sun/star/frame/XFramesSupplier.hpp>
51 #include <com/sun/star/frame/FrameSearchFlag.hpp>
52 #include <com/sun/star/frame/XFrame.hpp>
53 #include <com/sun/star/frame/XFrames.hpp>
54 #include <com/sun/star/frame/XFramesSupplier.hpp>
55 #include <com/sun/star/awt/XWindow.hpp>
56 #include <com/sun/star/frame/XController.hpp>
57 #include <com/sun/star/frame/XModel2.hpp>
58 #include <com/sun/star/util/XURLTransformer.hpp>
59 #include <com/sun/star/util/XCloseable.hpp>
60 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
61 #include <com/sun/star/document/MacroExecMode.hpp>
62 #include <com/sun/star/document/UpdateDocMode.hpp>
63 #include <com/sun/star/beans/XPropertySet.hpp>
64 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
65 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
66 #include <com/sun/star/embed/XStorage.hpp>
67 #include <com/sun/star/embed/EmbedStates.hpp>
68 #include <com/sun/star/document/XViewDataSupplier.hpp>
69 #include <com/sun/star/container/XIndexContainer.hpp>
70 #include <rtl/ustrbuf.hxx>
71 
72 #include <unotools/localfilehelper.hxx>
73 #include <unotools/ucbhelper.hxx>
74 #include <comphelper/processfactory.hxx>
75 #include <comphelper/componentcontext.hxx>
76 #include <comphelper/namedvaluecollection.hxx>
77 #include <comphelper/configurationhelper.hxx>
78 #include <comphelper/docpasswordrequest.hxx>
79 #include <comphelper/docpasswordhelper.hxx>
80 
81 #include <com/sun/star/uno/Reference.h>
82 #include <com/sun/star/ucb/XContent.hpp>
83 
84 #include <basic/basmgr.hxx>
85 #include <basic/sbmod.hxx>
86 #include <basic/sbmeth.hxx>
87 #include <basic/sbx.hxx>
88 #include <comphelper/storagehelper.hxx>
89 #include <svtools/asynclink.hxx>
90 #include <svl/sharecontrolfile.hxx>
91 #include <svtools/svtools.hrc>
92 #include <svtools/svtdata.hxx>
93 #include <framework/framelistanalyzer.hxx>
94 
95 #include <boost/optional.hpp>
96 
97 using namespace ::com::sun::star;
98 using namespace ::com::sun::star::uno;
99 using namespace ::com::sun::star::ucb;
100 using namespace ::com::sun::star::frame;
101 using namespace ::com::sun::star::lang;
102 using ::com::sun::star::awt::XWindow;
103 using ::com::sun::star::beans::PropertyValue;
104 using ::com::sun::star::document::XViewDataSupplier;
105 using ::com::sun::star::container::XIndexContainer;
106 namespace css = ::com::sun::star;
107 
108 // wg. ViewFrame::Current
109 #include "appdata.hxx"
110 #include <sfx2/taskpane.hxx>
111 #include <sfx2/app.hxx>
112 #include <sfx2/objface.hxx>
113 #include "openflag.hxx"
114 #include "objshimp.hxx"
115 #include <sfx2/viewsh.hxx>
116 #include <sfx2/objsh.hxx>
117 #include <sfx2/bindings.hxx>
118 #include <sfx2/dispatch.hxx>
119 #include "arrdecl.hxx"
120 #include "sfxtypes.hxx"
121 #include <sfx2/request.hxx>
122 #include <sfx2/docfac.hxx>
123 #include <sfx2/ipclient.hxx>
124 #include "sfx2/sfxresid.hxx"
125 #include "appbas.hxx"
126 #include <sfx2/objitem.hxx>
127 #include "sfx2/viewfac.hxx"
128 #include <sfx2/event.hxx>
129 #include "fltfnc.hxx"
130 #include <sfx2/docfile.hxx>
131 #include <sfx2/module.hxx>
132 #include <sfx2/msgpool.hxx>
133 #include <sfx2/viewfrm.hxx>
134 #include "viewimp.hxx"
135 #include <sfx2/sfxbasecontroller.hxx>
136 #include <sfx2/sfx.hrc>
137 #include "view.hrc"
138 #include <sfx2/frmdescr.hxx>
139 #include <sfx2/sfxuno.hxx>
140 #include <sfx2/progress.hxx>
141 #include "workwin.hxx"
142 #include "helper.hxx"
143 #include "macro.hxx"
144 #include "sfx2/minfitem.hxx"
145 #include "../appl/app.hrc"
146 #include "impviewframe.hxx"
147 
148 //-------------------------------------------------------------------------
149 DBG_NAME(SfxViewFrame)
150 
151 #define SfxViewFrame
152 #include "sfxslots.hxx"
153 #undef SfxViewFrame
154 
155 //-------------------------------------------------------------------------
156 
157 SFX_IMPL_INTERFACE(SfxViewFrame,SfxShell,SfxResId(0))
158 {
159     SFX_CHILDWINDOW_REGISTRATION( SID_BROWSER );
160     SFX_CHILDWINDOW_REGISTRATION( SID_RECORDING_FLOATWINDOW );
161 
162     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, SfxResId(RID_FULLSCREENTOOLBOX) );
163     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, SfxResId(RID_ENVTOOLBOX) );
164 }
165 
166 TYPEINIT2(SfxViewFrame,SfxShell,SfxListener);
167 TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
168 
169 //=========================================================================
170 
171 //-------------------------------------------------------------------------
172 namespace
173 {
174     bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl )
175     {
176         if ( !i_rViewFrameImpl.aHasToolPanels )
177         {
178             i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels(
179                 i_rViewFrameImpl.rFrame.GetFrameInterface() ) );
180         }
181         return *i_rViewFrameImpl.aHasToolPanels;
182     }
183 }
184 
185 //-------------------------------------------------------------------------
186 static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue > aInfo )
187 {
188     // TODO/LATER: In future the info should replace the direct hash completely
189     sal_Bool bResult = ( !nPasswordHash && !aInfo.getLength() );
190 
191     OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" );
192 
193     if ( pFilter && xHandler.is() )
194     {
195         sal_Bool bCancel = sal_False;
196         sal_Bool bFirstTime = sal_True;
197 
198         while ( !bResult && !bCancel )
199         {
200             sal_Bool bMSType = !pFilter->IsOwnFormat();
201 
202             ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest(
203                  new ::comphelper::DocPasswordRequest(
204                  bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD,
205                  bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER,
206                  aPath,
207                  sal_True ) );
208 
209             uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
210             xHandler->handle( rRequest );
211 
212             if ( pPasswordRequest->isPassword() )
213             {
214                 if ( aInfo.getLength() )
215                 {
216                     bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo );
217                 }
218                 else
219                 {
220                     // the binary format
221                     bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
222                 }
223             }
224             else
225                 bCancel = sal_True;
226 
227             bFirstTime = sal_False;
228         }
229     }
230 
231     return bResult;
232 }
233 
234 //-------------------------------------------------------------------------
235 void SfxViewFrame::SetDowning_Impl()
236 {
237     pImp->bIsDowning = sal_True;
238 }
239 
240 //-------------------------------------------------------------------------
241 sal_Bool SfxViewFrame::IsDowning_Impl() const
242 {
243     return pImp->bIsDowning;
244 }
245 
246 
247 //--------------------------------------------------------------------
248 class SfxViewNotificatedFrameList_Impl :
249     public SfxListener, public SfxViewFrameArr_Impl
250 {
251 public:
252 
253     void InsertViewFrame( SfxViewFrame* pFrame )
254     {
255         StartListening( *pFrame );
256         C40_INSERT( SfxViewFrame, pFrame, Count() );
257     }
258     void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
259 };
260 
261 //-------------------------------------------------------------------------
262 void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
263 {
264     if ( rHint.IsA(TYPE(SfxSimpleHint)) )
265     {
266         switch( ( (SfxSimpleHint&) rHint ).GetId() )
267         {
268             case SFX_HINT_DYING:
269                 SfxViewFrame* pFrame = (SfxViewFrame*) &rBC;
270                 if( pFrame )
271                 {
272                     sal_uInt16 nPos = C40_GETPOS( SfxViewFrame, pFrame );
273                     if( nPos != USHRT_MAX )
274 						Remove( nPos );
275                 }
276                 break;
277         }
278     }
279 }
280 
281 //-------------------------------------------------------------------------
282 
283 long ReloadDecouple_Impl( void* pObj, void* pArg )
284 {
285     ((SfxViewFrame*) pObj)->ExecReload_Impl( *(SfxRequest*)pArg );
286     return 0;
287 }
288 
289 void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq, sal_Bool bAsync )
290 {
291 	if( bAsync )
292 	{
293 		if( !pImp->pReloader )
294             pImp->pReloader = new svtools::AsynchronLink(
295 				Link( this, ReloadDecouple_Impl ) );
296 		pImp->pReloader->Call( new SfxRequest( rReq ) );
297 	}
298 	else ExecReload_Impl( rReq );
299 }
300 
301 void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
302 {
303     SfxFrame *pParent = GetFrame().GetParentFrame();
304 	if ( rReq.GetSlot() == SID_RELOAD )
305 	{
306         // Bei CTRL-Reload den aktiven Frame reloaden
307         SfxViewFrame* pActFrame = this;
308         while ( pActFrame )
309             pActFrame = pActFrame->GetActiveChildFrame_Impl();
310 
311         if ( pActFrame )
312         {
313             sal_uInt16 nModifier = rReq.GetModifier();
314             if ( nModifier & KEY_MOD1 )
315             {
316                 pActFrame->ExecReload_Impl( rReq );
317                 return;
318             }
319         }
320 
321 		// Wenn nur ein Reload der Graphiken eines oder mehrerer ChildFrames
322 		// gemacht werden soll
323 		SfxFrame& rFrame = GetFrame();
324 		if ( pParent == &rFrame && rFrame.GetChildFrameCount() )
325 		{
326 			sal_Bool bReloadAvailable = sal_False;
327 			SfxFrameIterator aIter( rFrame, sal_False );
328 			SfxFrame *pChild = aIter.FirstFrame();
329 			while ( pChild )
330 			{
331 				SfxFrame *pNext = aIter.NextFrame( *pChild );
332 				SfxObjectShell *pShell = pChild->GetCurrentDocument();
333 				if( pShell && pShell->Get_Impl()->bReloadAvailable )
334 				{
335 					bReloadAvailable = sal_True;
336 					pChild->GetCurrentViewFrame()->ExecuteSlot( rReq );
337 				}
338 				pChild = pNext;
339 			}
340 
341 			// Der TopLevel-Frame selbst het keine Graphiken!
342 			if ( bReloadAvailable )
343 				return;
344 		}
345     }
346     else
347     {
348         // Bei CTRL-Edit den TopFrame bearbeiten
349         sal_uInt16 nModifier = rReq.GetModifier();
350 
351         if ( ( nModifier & KEY_MOD1 ) && pParent )
352         {
353             SfxViewFrame *pTop = GetTopViewFrame();
354             pTop->ExecReload_Impl( rReq );
355             return;
356         }
357     }
358 
359     SfxObjectShell* pSh = GetObjectShell();
360     switch ( rReq.GetSlot() )
361     {
362         case SID_EDITDOC:
363         {
364 			if ( GetFrame().HasComponent() )
365 				break;
366 
367             // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch
368             // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click
369             // trotzdem nicht geht!
370             if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ))
371                 break;
372 
373             SfxMedium* pMed = pSh->GetMedium();
374 
375             SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False );
376         	if ( pItem && pItem->GetValue() )
377 			{
378 				SfxApplication* pApp = SFX_APP();
379 				SfxAllItemSet aSet( pApp->GetPool() );
380 				aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) );
381 				aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
382 				aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) );
383                 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
384 				if ( pReferer )
385 					aSet.Put( *pReferer );
386 		        SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
387 				if ( pVersionItem )
388 					aSet.Put( *pVersionItem );
389 
390 				if( pMed->GetFilter() )
391 				{
392                     aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
393 			        SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
394 					if ( pOptions )
395 						aSet.Put( *pOptions );
396 				}
397 
398                 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
399                 return;
400 			}
401 
402             sal_uInt16 nOpenMode;
403             sal_Bool bNeedsReload = sal_False;
404             if ( !pSh->IsReadOnly() )
405             {
406                 // Speichern und Readonly Reloaden
407                 if( pSh->IsModified() )
408                 {
409                     if ( pSh->PrepareClose() )
410                     {
411                         // the storing could let the medium be changed
412                         pMed = pSh->GetMedium();
413                         bNeedsReload = sal_True;
414                     }
415                     else
416                     {
417                         rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
418                         return;
419                     }
420                 }
421                 nOpenMode = SFX_STREAM_READONLY;
422             }
423             else
424 			{
425                 if ( pSh->IsReadOnlyMedium()
426                   && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() )
427                   && !pSh->IsModifyPasswordEntered() )
428                 {
429                     ::rtl::OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
430                     if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) )
431                     {
432                         // this is a read-only document, if it has "Password to modify"
433                         // the user should enter password before he can edit the document
434                         rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
435                         return;
436                     }
437 
438                     pSh->SetModifyPasswordEntered();
439                 }
440 
441                 nOpenMode = SFX_STREAM_READWRITE;
442                 pSh->SetReadOnlyUI( sal_False );
443 
444                 // if only the view was in the readonly mode then there is no need to do the reload
445                 if ( !pSh->IsReadOnly() )
446                     return;
447 			}
448 
449 			// Parameter auswerten
450             // sal_Bool bReload = sal_True;
451 			if ( rReq.IsAPI() )
452 			{
453 				// per API steuern ob r/w oder r/o
454             	SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, sal_False);
455 				if ( pEditItem )
456 					nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
457 			}
458 
459 			// doing
460 
461             String aTemp;
462             utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp );
463             INetURLObject aPhysObj( aTemp );
464             SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(),
465                              pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
466 
467             INetURLObject aMedObj( pMed->GetName() );
468 
469             // the logic below is following, if the document seems not to need to be reloaded and the physical name is different
470             // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required
471             if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE &&
472                     aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) &&
473                     !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) ))
474                   || pMed->IsRemote() ) )
475                || pVersionItem )
476             {
477                 sal_Bool bOK = sal_False;
478                 if ( !pVersionItem )
479                 {
480                     sal_Bool bHasStorage = pMed->HasStorage_Impl();
481                     // switching edit mode could be possible without reload
482                     if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() )
483                     {
484                         // TODO/LATER: faster creation of copy
485                         if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) )
486                             return;
487                     }
488 
489                     pMed->CloseAndRelease();
490                     pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
491                     pMed->SetOpenMode( nOpenMode, pMed->IsDirect() );
492 
493                     pMed->CompleteReOpen();
494                     if ( nOpenMode & STREAM_WRITE )
495                         pMed->LockOrigFileOnDemand( sal_False, sal_True );
496 
497                     // LockOrigFileOnDemand might set the readonly flag itself, it should be set back
498                     pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
499 
500                     if ( !pMed->GetErrorCode() )
501                         bOK = sal_True;
502                 }
503 
504                 if( !bOK )
505                 {
506                     ErrCode nErr = pMed->GetErrorCode();
507                     if ( pVersionItem )
508                         nErr = ERRCODE_IO_ACCESSDENIED;
509                     else
510                     {
511                         pMed->ResetError();
512                         pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() );
513                         pMed->ReOpen();
514                         pSh->DoSaveCompleted( pMed );
515                     }
516 
517                     // r/o-Doc kann nicht in Editmode geschaltet werden?
518                     rReq.Done( sal_False );
519 
520                     if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() )
521                     {
522                         // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen
523                         QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
524                         if ( RET_YES == aBox.Execute() )
525                         {
526                             SfxApplication* pApp = SFX_APP();
527                             SfxAllItemSet aSet( pApp->GetPool() );
528                             aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
529                             SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
530                             if ( pReferer )
531                                 aSet.Put( *pReferer );
532                             aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
533                             if ( pVersionItem )
534                                 aSet.Put( *pVersionItem );
535 
536                             if( pMed->GetFilter() )
537                             {
538                                 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
539                                 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions,
540                                                  SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
541                                 if ( pOptions )
542                                     aSet.Put( *pOptions );
543                             }
544 
545                             GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
546                             return;
547                         }
548                         else
549                             nErr = 0;
550                     }
551 
552                     ErrorHandler::HandleError( nErr );
553                     rReq.SetReturnValue(
554                         SfxBoolItem( rReq.GetSlot(), sal_False ) );
555                     return;
556                 }
557                 else
558                 {
559                     pSh->DoSaveCompleted( pMed );
560                     pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
561                     rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) );
562                     rReq.Done( sal_True );
563                     // if( nOpenMode == SFX_STREAM_READONLY )
564                     //    pMed->Close();
565                     return;
566                 }
567             }
568 
569             rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) );
570             rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True ));
571         }
572 
573         case SID_RELOAD:
574         {
575             // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch
576             // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click
577             // trotzdem nicht geht!
578             if ( !pSh || !pSh->CanReload_Impl() )
579                 break;
580             SfxApplication* pApp = SFX_APP();
581             SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem,
582                             SID_FORCERELOAD, sal_False);
583             if(  pForceReloadItem && !pForceReloadItem->GetValue() &&
584                 !pSh->GetMedium()->IsExpired() )
585                 return;
586             if( pImp->bReloading || pSh->IsInModalMode() )
587                 return;
588 
589             // AutoLoad ist ggf. verboten
590             SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, sal_False);
591             if ( pAutoLoadItem && pAutoLoadItem->GetValue() &&
592                  GetFrame().IsAutoLoadLocked_Impl() )
593                 return;
594 
595             SfxObjectShellLock xOldObj( pSh );
596             pImp->bReloading = sal_True;
597             SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem,
598                             SID_FILE_NAME, sal_False);
599             // editierbar "offnen?
600             sal_Bool bForEdit = !pSh->IsReadOnly();
601             if ( rReq.GetSlot() == SID_EDITDOC )
602                 bForEdit = !bForEdit;
603 
604             // ggf. beim User nachfragen
605             sal_Bool bDo = ( GetViewShell()->PrepareClose() != sal_False );
606             SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
607             if ( bDo && GetFrame().DocIsModified_Impl() &&
608 				 !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) )
609             {
610                 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_LASTVERSION) );
611                 bDo = ( RET_YES == aBox.Execute() );
612             }
613 
614             if ( bDo )
615             {
616                 SfxMedium *pMedium = xOldObj->GetMedium();
617 
618 				// Frameset abziehen, bevor FramesetView evtl. verschwindet
619 				String aURL = pURLItem ? pURLItem->GetValue() :
620 								pMedium->GetName();
621 
622                 sal_Bool bHandsOff =
623                     ( pMedium->GetURLObject().GetProtocol() == INET_PROT_FILE && !xOldObj->IsDocShared() );
624 
625                 // bestehende SfxMDIFrames f"ur dieses Doc leeren
626                 // eigenes Format oder R/O jetzt editierbar "offnen?
627                 SfxObjectShellLock xNewObj;
628 
629                 // collect the views of the document
630                 // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should
631                 // be UNOized, too
632                 typedef ::std::pair< Reference< XFrame >, sal_uInt16 >  ViewDescriptor;
633                 ::std::list< ViewDescriptor > aViewFrames;
634                 SfxViewFrame *pView = GetFirst( xOldObj );
635 				while ( pView )
636 				{
637                     Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() );
638                     OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" );
639 					aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) );
640 
641                     pView = GetNext( *pView, xOldObj );
642 				}
643 
644                 DELETEZ( xOldObj->Get_Impl()->pReloadTimer );
645 
646                 SfxItemSet* pNewSet = 0;
647                 const SfxFilter *pFilter = pMedium->GetFilter();
648                 if( pURLItem )
649 				{
650 					pNewSet = new SfxAllItemSet( pApp->GetPool() );
651 					pNewSet->Put( *pURLItem );
652 
653 					// Filter Detection
654 					SfxMedium aMedium( pURLItem->GetValue(), SFX_STREAM_READWRITE );
655 					SfxFilterMatcher().GuessFilter( aMedium, &pFilter );
656 					if ( pFilter )
657 	                    pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
658 					pNewSet->Put( *aMedium.GetItemSet() );
659 				}
660 				else
661 				{
662 					pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() );
663 					pNewSet->ClearItem( SID_VIEW_ID );
664 					pNewSet->ClearItem( SID_STREAM );
665 					pNewSet->ClearItem( SID_INPUTSTREAM );
666                     pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) );
667 
668                     // let the current security settings be checked again
669                     pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) );
670 
671                     if ( rReq.GetSlot() == SID_EDITDOC || !bForEdit )
672                         // edit mode is switched or reload of readonly document
673                         pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, !bForEdit ) );
674                     else
675                         // Reload of file opened for writing
676                         pNewSet->ClearItem( SID_DOC_READONLY );
677 				}
678 
679 				// Falls eine salvagede Datei vorliegt, nicht nochmals die
680 				// OrigURL mitschicken, denn die Tempdate ist nach Reload
681 				// ungueltig
682                 SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
683 				if( pSalvageItem )
684 				{
685 					aURL = pSalvageItem->GetValue();
686 					// IAccessibility2 implementation 2009. ------
687                     if (pNewSet)
688                     {
689                         pNewSet->ClearItem( SID_ORIGURL );
690 					    pNewSet->ClearItem( SID_DOC_SALVAGE );
691                     }
692 					// ------ IAccessibility2 implementation 2009.
693 				}
694 
695                 // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName
696                 //             SfxMedium::Transfer_Impl() will be vorbidden then.
697                 if ( xOldObj->IsDocShared() )
698                     pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) );
699 
700                 //pNewMedium = new SfxMedium( aURL, nMode, pMedium->IsDirect(), bUseFilter ? pMedium->GetFilter() : 0, pNewSet );
701                 //pNewSet = pNewMedium->GetItemSet();
702                 if ( pURLItem )
703 					pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) );
704                 else
705                     pNewSet->Put( SfxStringItem( SID_REFERER, String() ) );
706 
707                 xOldObj->CancelTransfers();
708 
709                 // eigentliches Reload
710                 //pNewSet->Put( SfxFrameItem ( SID_DOCFRAME, GetFrame() ) );
711 
712                 if ( pSilentItem && pSilentItem->GetValue() )
713                     pNewSet->Put( SfxBoolItem( SID_SILENT, sal_True ) );
714 
715 		        SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
716 		        SFX_ITEMSET_ARG(pNewSet, pMacroExecItem  , SfxUInt16Item, SID_MACROEXECMODE     , sal_False);
717 		        SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE     , sal_False);
718 
719 		        if (!pInteractionItem)
720 		        {
721 		            Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
722 		            if (xHdl.is())
723 		                pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
724 		        }
725 
726 		        if (!pMacroExecItem)
727 		            pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
728 		        if (!pDocTemplateItem)
729 		            pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
730 
731 				xOldObj->SetModified( sal_False );
732                 // Altes Dok nicht cachen! Gilt nicht, wenn anderes
733 				// Doc geladen wird.
734 
735                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
736                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, sal_False);
737 
738                 sal_Bool bHasStorage = pMedium->HasStorage_Impl();
739                 if( bHandsOff )
740                 {
741                     if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() )
742                     {
743                         // TODO/LATER: faster creation of copy
744 						if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
745                             return;
746                     }
747 
748                     pMedium->CloseAndRelease();
749                 }
750 
751                 xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_STANDARD );
752 
753                 if ( xOldObj->IsModifyPasswordEntered() )
754                     xNewObj->SetModifyPasswordEntered();
755 
756                 uno::Sequence < beans::PropertyValue > aLoadArgs;
757                 TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs );
758                 try
759                 {
760                     uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY );
761                     xLoad->load( aLoadArgs );
762                 }
763                 catch ( uno::Exception& )
764                 {
765                     xNewObj->DoClose();
766                     xNewObj = 0;
767                 }
768 
769 				DELETEZ( pNewSet );
770 
771                 if( !xNewObj.Is() )
772                 {
773 					if( bHandsOff )
774                     {
775                         // back to old medium
776                         pMedium->ReOpen();
777                         pMedium->LockOrigFileOnDemand( sal_False, sal_True );
778 
779                         xOldObj->DoSaveCompleted( pMedium );
780                     }
781 
782                     // r/o-Doc couldn't be switched to writing mode
783                     if ( bForEdit && SID_EDITDOC == rReq.GetSlot() )
784                     {
785                         // ask user for opening as template
786                         QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
787                         if ( RET_YES == aBox.Execute() )
788                         {
789 							SfxAllItemSet aSet( pApp->GetPool() );
790                             aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
791                             aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) );
792                             if ( pSavedOptions )
793                                 aSet.Put( *pSavedOptions );
794                             if ( pSavedReferer )
795                                 aSet.Put( *pSavedReferer );
796 							aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
797                             if( pFilter )
798                                 aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) );
799                             GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
800                         }
801                     }
802 					else
803 					{
804                         // an error handling should be done here?!
805                         // if ( !pSilentItem || !pSilentItem->GetValue() )
806                         //    ErrorHandler::HandleError( nLoadError );
807 					}
808                 }
809                 else
810                 {
811                     if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() )
812                     {
813                         xNewObj->SetModifyPasswordEntered( sal_False );
814                         xNewObj->SetReadOnly();
815                     }
816                     else if ( rReq.GetSlot() == SID_EDITDOC && bForEdit && !xNewObj->IsReadOnlyMedium() )
817                     {
818                         // the filter might request setting of the document to readonly state
819                         // but in case of SID_EDITDOC it should not happen if the document
820                         // can be opened for editing
821                         xNewObj->SetReadOnlyUI( sal_False );
822                     }
823 
824                     if ( xNewObj->IsDocShared() )
825                     {
826                         // the file is shared but the closing can change the sharing control file
827                         xOldObj->DoNotCleanShareControlFile();
828                     }
829 
830                     // the Reload and Silent items were only temporary, remove them
831 					xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD );
832 					xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT );
833                     TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs );
834 
835 					UpdateDocument_Impl();
836 
837                     try
838                     {
839                         while ( !aViewFrames.empty() )
840                         {
841                             LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false );
842                             aViewFrames.pop_front();
843                         }
844                     }
845                     catch( const Exception& )
846                     {
847                         // close the remaining frames
848                         // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and
849                         // crashing is better than trying to proceed
850                         while ( !aViewFrames.empty() )
851                         {
852                             Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW );
853                             xClose->close( sal_True );
854                             aViewFrames.pop_front();
855                         }
856                     }
857 
858                     // Propagate document closure.
859                     SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), xOldObj ) );
860                 }
861 
862                 // als erledigt recorden
863                 rReq.Done( sal_True );
864                 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_True));
865                 return;
866             }
867             else
868             {
869                 // als nicht erledigt recorden
870                 rReq.Done();
871                 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_False));
872                 pImp->bReloading = sal_False;
873                 return;
874             }
875         }
876     }
877 }
878 
879 //-------------------------------------------------------------------------
880 void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
881 {
882     SfxObjectShell* pSh = GetObjectShell();
883 	if ( !pSh )
884 		// Ich bin gerade am Reloaden und Yielde so vor mich hin ...
885 		return;
886 
887     GetFrame().GetParentFrame();
888     SfxWhichIter aIter( rSet );
889     for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
890     {
891 		if ( GetFrame().HasComponent() )
892 		{
893 			// Wenn die Komponente es nicht selbst dispatched, dann
894 			// macht es auch keinen Sinn!
895 			rSet.DisableItem( nWhich );
896 			continue;
897 		}
898 
899         switch ( nWhich )
900         {
901             case SID_EDITDOC:
902             {
903 		        if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags &  SFX_LOADED_MAINDOCUMENT )
904 				  || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
905 		            rSet.DisableItem( SID_EDITDOC );
906 		        else
907 				{
908 					SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
909 					if ( pItem && !pItem->GetValue() )
910 						rSet.DisableItem( SID_EDITDOC );
911 					else
912 						rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) );
913 				}
914                 break;
915             }
916 
917             case SID_RELOAD:
918             {
919 				SfxFrame* pFrame = &GetTopFrame();
920 
921                 if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
922                     rSet.DisableItem(nWhich);
923                 else
924 				{
925 					// Wenn irgendein ChildFrame reloadable ist, wird der Slot
926 					// enabled, damit man CTRL-Reload machen kann
927 					sal_Bool bReloadAvailable = sal_False;
928 					SfxFrameIterator aFrameIter( *pFrame, sal_True );
929 					for( SfxFrame* pNextFrame = aFrameIter.FirstFrame();
930 							pFrame;
931 							pNextFrame = pNextFrame ?
932 								aFrameIter.NextFrame( *pNextFrame ) : 0 )
933 					{
934 						SfxObjectShell *pShell = pFrame->GetCurrentDocument();
935 						if( pShell && pShell->Get_Impl()->bReloadAvailable )
936 						{
937 							bReloadAvailable = sal_True;
938 							break;
939 						}
940 						pFrame = pNextFrame;
941 					}
942 
943                     rSet.Put( SfxBoolItem( nWhich, bReloadAvailable));
944 				}
945 
946                 break;
947             }
948         }
949     }
950 }
951 
952 
953 //--------------------------------------------------------------------
954 void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq )
955 {
956     // gibt es an der obersten Shell einen Undo-Manager?
957     SfxShell *pSh = GetDispatcher()->GetShell(0);
958     ::svl::IUndoManager* pShUndoMgr = pSh->GetUndoManager();
959     sal_Bool bOK = sal_False;
960     if ( pShUndoMgr )
961     {
962         switch ( rReq.GetSlot() )
963         {
964             case SID_CLEARHISTORY:
965                 pShUndoMgr->Clear();
966                 bOK = sal_True;
967                 break;
968 
969             case SID_UNDO:
970                 pShUndoMgr->Undo();
971                 GetBindings().InvalidateAll(sal_False);
972                 bOK = sal_True;
973                 break;
974 
975             case SID_REDO:
976                 pShUndoMgr->Redo();
977                 GetBindings().InvalidateAll(sal_False);
978                 bOK = sal_True;
979                 break;
980 
981             case SID_REPEAT:
982                 if ( pSh->GetRepeatTarget() )
983                     pShUndoMgr->Repeat( *pSh->GetRepeatTarget() );
984                 bOK = sal_True;
985                 break;
986         }
987     }
988     else if ( GetViewShell() )
989     {
990         // der SW hat eigenes Undo an der View
991         const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq );
992         if ( pRet )
993             bOK = ((SfxBoolItem*)pRet)->GetValue();
994     }
995 
996     rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) );
997     rReq.Done();
998 }
999 
1000 //--------------------------------------------------------------------
1001 void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
1002 {
1003     // Undo-Manager suchen
1004     SfxShell *pSh = GetDispatcher()->GetShell(0);
1005 	if ( !pSh )
1006 		// Ich bin gerade am Reloaden und Yielde so vor mich hin ...
1007 		return;
1008 
1009     ::svl::IUndoManager *pShUndoMgr = pSh->GetUndoManager();
1010     if ( !pShUndoMgr )
1011     {
1012         // der SW hat eigenes Undo an der View
1013         SfxWhichIter aIter( rSet );
1014         SfxViewShell *pViewSh = GetViewShell();
1015         if( !pViewSh ) return;
1016         for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
1017             pViewSh->GetSlotState( nSID, 0, &rSet );
1018         return;
1019     }
1020 
1021     if ( pShUndoMgr->GetUndoActionCount() == 0 &&
1022          pShUndoMgr->GetRedoActionCount() == 0 &&
1023          pShUndoMgr->GetRepeatActionCount() == 0 )
1024         rSet.DisableItem( SID_CLEARHISTORY );
1025 
1026     if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
1027 	{
1028         String aTmp( SvtResId( STR_UNDO ) );
1029 		aTmp+= pShUndoMgr->GetUndoActionComment(0);
1030 		rSet.Put( SfxStringItem( SID_UNDO, aTmp ) );
1031 	}
1032     else
1033         rSet.DisableItem( SID_UNDO );
1034 
1035     if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
1036 	{
1037         String aTmp( SvtResId(STR_REDO) );
1038 		aTmp += pShUndoMgr->GetRedoActionComment(0);
1039 	    rSet.Put( SfxStringItem( SID_REDO, aTmp ) );
1040 	}
1041     else
1042         rSet.DisableItem( SID_REDO );
1043     SfxRepeatTarget *pTarget = pSh->GetRepeatTarget();
1044     if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() &&
1045          pShUndoMgr->CanRepeat(*pTarget) )
1046 	{
1047         String aTmp( SvtResId(STR_REPEAT) );
1048 		aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget);
1049 		rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) );
1050 	}
1051     else
1052         rSet.DisableItem( SID_REPEAT );
1053 }
1054 
1055 //--------------------------------------------------------------------
1056 void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell )
1057 {
1058     i_rViewShell.PopSubShells_Impl();
1059     sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell );
1060     if ( nLevel != USHRT_MAX )
1061     {
1062         if ( nLevel )
1063         {
1064             // more sub shells on the stack, which were not affected by PopSubShells_Impl
1065             SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 );
1066             if ( pSubShell == i_rViewShell.GetSubShell() )
1067                 // "real" sub shells will be deleted elsewhere
1068                 pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL );
1069             else
1070                 pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE );
1071         }
1072         pDispatcher->Pop( i_rViewShell );
1073         pDispatcher->Flush();
1074     }
1075 
1076 }
1077 
1078 //--------------------------------------------------------------------
1079 void SfxViewFrame::ReleaseObjectShell_Impl()
1080 
1081 /*  [Beschreibung]
1082 
1083     Diese Methode entleert den SfxViewFrame, d.h. nimmt die <SfxObjectShell>
1084     vom Dispatcher und beendet seine <SfxListener>-Beziehung zu dieser
1085     SfxObjectShell (wodurch sie sich ggf. selbst zerst"ort).
1086 
1087     Somit kann durch Aufruf von ReleaseObjectShell() und SetObjectShell()
1088     die SfxObjectShell ausgetauscht werden.
1089 
1090     Zwischen RealeaseObjectShell() und SetObjectShell() darf die Kontrolle
1091     nicht an das System abgegeben werden.
1092 
1093 
1094     [Querverweise]
1095 
1096     <SfxViewFrame::SetObjectShell(SfxObjectShell&)>
1097 */
1098 {
1099     DBG_CHKTHIS(SfxViewFrame, 0);
1100     DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" );
1101 
1102 	GetFrame().ReleasingComponent_Impl( sal_True );
1103 	if ( GetWindow().HasChildPathFocus( sal_True ) )
1104 	{
1105 		DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" );
1106 		GetWindow().GrabFocus();
1107 	}
1108 
1109 	SfxViewShell *pDyingViewSh = GetViewShell();
1110     if ( pDyingViewSh )
1111     {
1112         PopShellAndSubShells_Impl( *pDyingViewSh );
1113         pDyingViewSh->DisconnectAllClients();
1114         SetViewShell_Impl(0);
1115         delete pDyingViewSh;
1116     }
1117 #ifdef DBG_UTIL
1118     else
1119         DBG_ERROR("Keine Shell");
1120 #endif
1121 
1122     if ( xObjSh.Is() )
1123     {
1124          pImp->aLastType = xObjSh->Type();
1125         pDispatcher->Pop( *xObjSh );
1126         SfxModule* pModule = xObjSh->GetModule();
1127         if( pModule )
1128             pDispatcher->RemoveShell_Impl( *pModule );
1129         pDispatcher->Flush();
1130         EndListening( *xObjSh );
1131 
1132         Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1133         Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
1134 
1135         if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1136             xObjSh->DoClose();
1137         SfxObjectShellRef xDyingObjSh = xObjSh;
1138         xObjSh.Clear();
1139         if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo )
1140             xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1);
1141         if ( pImp->bObjLocked )
1142         {
1143             xDyingObjSh->OwnerLock( sal_False );
1144             pImp->bObjLocked = sal_False;
1145         }
1146     }
1147 
1148 	GetDispatcher()->SetDisableFlags( 0 );
1149 }
1150 
1151 //--------------------------------------------------------------------
1152 sal_Bool SfxViewFrame::Close()
1153 {
1154     DBG_CHKTHIS(SfxViewFrame, 0);
1155 
1156     DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" );
1157 
1158 	// Wenn bis jetzt noch nicht gespeichert wurde, sollen eingebettete Objekte
1159 	// auch nicht mehr automatisch gespeichert werden!
1160 	if ( GetViewShell() )
1161 		GetViewShell()->DiscardClients_Impl();
1162 	Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
1163 
1164     if (SfxViewFrame::Current() == this)
1165         SfxViewFrame::SetViewFrame( NULL );
1166 
1167 	// Da der Dispatcher leer ger"aumt wird, kann man ihn auch nicht mehr
1168 	// vern"unftig verwenden - also besser still legen
1169 	GetDispatcher()->Lock(sal_True);
1170 	delete this;
1171 
1172 	return sal_True;
1173 }
1174 
1175 //--------------------------------------------------------------------
1176 
1177 void SfxViewFrame::DoActivate( sal_Bool bUI, SfxViewFrame* pOldFrame )
1178 {
1179     DBG_CHKTHIS(SfxViewFrame, 0);
1180     SFX_APP();
1181 
1182     pDispatcher->DoActivate_Impl( bUI, pOldFrame );
1183 
1184     // Wenn ich einen parent habe und dieser ist kein parent des alten
1185     // ViewFrames, erh"alt er ein ParentActivate
1186     if ( bUI )
1187     {
1188 /*
1189 		SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL;
1190 		if( pMed )
1191 		{
1192             SFX_ITEMSET_ARG(
1193                 pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem,
1194                 SID_INTERCEPTOR, sal_False );
1195 			if( pInterceptorItem )
1196 			{
1197 				SfxSlotInterceptor* pInter = pInterceptorItem->GetValue();
1198 				if( !pInter->GetBindings() )
1199 					pInter->SetBindings( &GetBindings() );
1200 				pInter->Activate( sal_True );
1201 			}
1202 		}
1203  */
1204         SfxViewFrame *pFrame = GetParentViewFrame();
1205         while ( pFrame )
1206         {
1207             if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
1208                 pFrame->pDispatcher->DoParentActivate_Impl();
1209             pFrame = pFrame->GetParentViewFrame();
1210         }
1211     }
1212 }
1213 
1214 //--------------------------------------------------------------------
1215 void SfxViewFrame::DoDeactivate(sal_Bool bUI, SfxViewFrame* pNewFrame )
1216 {
1217     DBG_CHKTHIS(SfxViewFrame, 0);
1218     SFX_APP();
1219     pDispatcher->DoDeactivate_Impl( bUI, pNewFrame );
1220 
1221     // Wenn ich einen parent habe und dieser ist kein parent des neuen
1222     // ViewFrames, erh"alt er ein ParentDeactivate
1223     if ( bUI )
1224     {
1225 //        if ( GetFrame().GetWorkWindow_Impl() )
1226 //            GetFrame().GetWorkWindow_Impl()->SaveStatus_Impl();
1227 /*
1228 		SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL;
1229 		if( pMed )
1230 		{
1231             SFX_ITEMSET_ARG(
1232                 pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem,
1233                 SID_INTERCEPTOR, sal_False );
1234 			if( pInterceptorItem )
1235 				pInterceptorItem->GetValue()->Activate( sal_False );
1236 		}
1237 */
1238         SfxViewFrame *pFrame = GetParentViewFrame();
1239         while ( pFrame )
1240         {
1241             if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
1242                 pFrame->pDispatcher->DoParentDeactivate_Impl();
1243             pFrame = pFrame->GetParentViewFrame();
1244         }
1245     }
1246 }
1247 
1248 //------------------------------------------------------------------------
1249 void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh )
1250 {
1251     if( pSh && !nAdjustPosPixelLock )
1252     {
1253         if ( GetViewShell() && GetWindow().IsVisible() )
1254         {
1255             if ( GetFrame().IsInPlace() )
1256             {
1257                 /*
1258                 Size aSize( GetViewShell()->GetWindow()->GetSizePixel() );
1259 
1260                 //Size aBorderSz( pEnv->GetBorderWin()->GetHatchBorderPixel() );
1261                 Point aOfs; //( aBorderSz.Width(), aBorderSz.Height() );
1262 
1263                 DoAdjustPosSizePixel( GetViewShell(), aOfs, aSize );*/
1264                 return;
1265             }
1266 
1267             DoAdjustPosSizePixel( (SfxViewShell *) GetViewShell(), Point(),
1268                                             GetWindow().GetOutputSizePixel() );
1269         }
1270     }
1271 }
1272 
1273 //------------------------------------------------------------------------
1274 sal_Bool SfxViewFrame::SetBorderPixelImpl
1275 (
1276     const SfxViewShell* pVSh,
1277     const SvBorder&     rBorder
1278 )
1279 
1280 {
1281     pImp->aBorder = rBorder;
1282 
1283     if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() )
1284 	{
1285 		Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
1286 		if ( aSize.Width() && aSize.Height() )
1287 		{
1288 			aSize.Width() += rBorder.Left() + rBorder.Right();
1289 			aSize.Height() += rBorder.Top() + rBorder.Bottom();
1290 
1291 			Size aOldSize = GetWindow().GetOutputSizePixel();
1292 			GetWindow().SetOutputSizePixel( aSize );
1293 			Window* pParent = &GetWindow();
1294 			while ( pParent->GetParent() )
1295 				pParent = pParent->GetParent();
1296 			Size aOuterSize = pParent->GetOutputSizePixel();
1297 			aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
1298 			aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
1299 			pParent->SetOutputSizePixel( aOuterSize );
1300 		}
1301 	}
1302 	else
1303 	{
1304 		Point aPoint;
1305 		Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
1306 		aEditArea.Left() += rBorder.Left();
1307 		aEditArea.Right() -= rBorder.Right();
1308 		aEditArea.Top() += rBorder.Top();
1309 		aEditArea.Bottom() -= rBorder.Bottom();
1310 		pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
1311 	}
1312 
1313 	return sal_True;
1314 }
1315 
1316 //------------------------------------------------------------------------
1317 const SvBorder& SfxViewFrame::GetBorderPixelImpl
1318 (
1319     const SfxViewShell* /*pSh*/
1320 )   const
1321 
1322 {
1323     return pImp->aBorder;
1324 }
1325 
1326 //--------------------------------------------------------------------
1327 void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1328 {
1329     {DBG_CHKTHIS(SfxViewFrame, 0);}
1330 
1331     if( IsDowning_Impl())
1332         return;
1333 
1334     // we know only SimpleHints
1335     if ( rHint.IsA(TYPE(SfxSimpleHint)) )
1336     {
1337         switch( ( (SfxSimpleHint&) rHint ).GetId() )
1338         {
1339             case SFX_HINT_MODECHANGED:
1340             {
1341                 UpdateTitle();
1342 
1343                 if ( !xObjSh.Is() )
1344                     break;
1345 
1346                 // r/o Umschaltung?
1347                 SfxBindings& rBind = GetBindings();
1348                 rBind.Invalidate( SID_RELOAD );
1349                 SfxDispatcher *pDispat = GetDispatcher();
1350                 sal_Bool bWasReadOnly = pDispat->GetReadOnly_Impl();
1351                 sal_Bool bIsReadOnly = xObjSh->IsReadOnly();
1352                 if ( !bWasReadOnly != !bIsReadOnly )
1353             	{
1354 					// Dann auch TITLE_CHANGED
1355 					UpdateTitle();
1356 	                rBind.Invalidate( SID_FILE_NAME );
1357 	                rBind.Invalidate( SID_DOCINFO_TITLE );
1358 					rBind.Invalidate( SID_EDITDOC );
1359 
1360                     pDispat->GetBindings()->InvalidateAll(sal_True);
1361                     pDispat->SetReadOnly_Impl( bIsReadOnly );
1362 
1363 					// Dispatcher-Update nur erzwingen, wenn es nicht sowieso
1364 					// demn"achst kommt, anderenfalls ist Zappelei oder gar
1365 					// GPF m"oglich, da Writer z.B. gerne mal im Resize irgendwelche
1366 					// Aktionen t"atigt, die ein SetReadOnlyUI am Dispatcher zur
1367 					// Folge haben!
1368 					if ( pDispat->IsUpdated_Impl() )
1369                     	pDispat->Update_Impl(sal_True);
1370                 }
1371 
1372                 Enable( !xObjSh->IsInModalMode() );
1373 				break;
1374             }
1375 
1376             case SFX_HINT_TITLECHANGED:
1377             {
1378 				UpdateTitle();
1379                 SfxBindings& rBind = GetBindings();
1380                 rBind.Invalidate( SID_FILE_NAME );
1381                 rBind.Invalidate( SID_DOCINFO_TITLE );
1382 				rBind.Invalidate( SID_EDITDOC );
1383 				rBind.Invalidate( SID_RELOAD );
1384                 break;
1385             }
1386 
1387             case SFX_HINT_DEINITIALIZING:
1388                 GetFrame().DoClose();
1389                 break;
1390             case SFX_HINT_DYING:
1391                 // when the Object is being deleted, destroy the view too
1392                 if ( xObjSh.Is() )
1393                     ReleaseObjectShell_Impl();
1394                 else
1395                     GetFrame().DoClose();
1396                 break;
1397 
1398         }
1399     }
1400     else if ( rHint.IsA(TYPE(SfxEventHint)) )
1401     {
1402         // Wenn das Document asynchron geladen wurde, wurde der Dispatcher
1403         // auf ReadOnly gesetzt, was zur"?ckgenommen werden mu\s, wenn
1404         // das Document selbst nicht ReadOnly ist und das Laden fertig ist.
1405         switch ( ((SfxEventHint&)rHint).GetEventId() )
1406         {
1407             case SFX_EVENT_MODIFYCHANGED:
1408             {
1409                 SfxBindings& rBind = GetBindings();
1410                 rBind.Invalidate( SID_DOC_MODIFIED );
1411                 rBind.Invalidate( SID_SAVEDOC );
1412                 rBind.Invalidate( SID_RELOAD );
1413                 rBind.Invalidate( SID_EDITDOC );
1414                 break;
1415             }
1416 
1417             case SFX_EVENT_OPENDOC:
1418             case SFX_EVENT_CREATEDOC:
1419             {
1420                 if ( !xObjSh.Is() )
1421                     break;
1422 
1423                 SfxBindings& rBind = GetBindings();
1424                 rBind.Invalidate( SID_RELOAD );
1425                 rBind.Invalidate( SID_EDITDOC );
1426                 if ( !xObjSh->IsReadOnly() )
1427                 {
1428                     // Im Gegensatz zu oben (TITLE_CHANGED) mu\s das UI nicht
1429                     // upgedated werden, da es nicht gehidet war!
1430 
1431                     // #i21560# InvalidateAll() causes the assertion
1432                     // 'SfxBindings::Invalidate while in update" when
1433                     // the sfx slot SID_BASICIDE_APPEAR is executed
1434                     // via API from another thread (Java).
1435                     // According to MBA this call is not necessary anymore,
1436                     // because each document has its own SfxBindings.
1437                     //
1438                     //GetDispatcher()->GetBindings()->InvalidateAll(sal_True);
1439                 }
1440 
1441                 break;
1442             }
1443 
1444             case SFX_EVENT_TOGGLEFULLSCREENMODE:
1445             {
1446                 if ( GetFrame().OwnsBindings_Impl() )
1447                     GetBindings().GetDispatcher_Impl()->Update_Impl( sal_True );
1448                 break;
1449             }
1450         }
1451     }
1452 }
1453 
1454 //------------------------------------------------------------------------
1455 void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
1456 {
1457     pImp->bResizeInToOut = sal_True;
1458     pImp->bDontOverwriteResizeInToOut = sal_False;
1459     pImp->bObjLocked = sal_False;
1460     pImp->pFocusWin = 0;
1461     pImp->pActiveChild = NULL;
1462     pImp->nCurViewId = 0;
1463     pImp->bReloading = sal_False;
1464     pImp->bIsDowning = sal_False;
1465     pImp->bModal = sal_False;
1466     pImp->bEnabled = sal_True;
1467     pImp->nDocViewNo = 0;
1468     pImp->aMargin = Size( -1, -1 );
1469 	pImp->pWindow = 0;
1470 
1471 	SetPool( &SFX_APP()->GetPool() );
1472     pDispatcher = new SfxDispatcher(this);
1473     if ( !GetBindings().GetDispatcher() )
1474         GetBindings().SetDispatcher( pDispatcher );
1475 
1476     xObjSh = pObjSh;
1477 	if ( xObjSh.Is() && xObjSh->IsPreview() )
1478 		SetQuietMode_Impl( sal_True );
1479 
1480     if ( pObjSh )
1481     {
1482         pDispatcher->Push( *SFX_APP() );
1483         SfxModule* pModule = xObjSh->GetModule();
1484         if( pModule )
1485             pDispatcher->Push( *pModule );
1486         pDispatcher->Push( *this );
1487         pDispatcher->Push( *pObjSh );
1488         pDispatcher->Flush();
1489         StartListening( *pObjSh );
1490         pObjSh->ViewAssigned();
1491         Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1492         Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
1493         pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() );
1494     }
1495     else
1496     {
1497         pDispatcher->Push( *SFX_APP() );
1498         pDispatcher->Push( *this );
1499         pDispatcher->Flush();
1500     }
1501 
1502     SfxViewFrame *pThis = this; // wegen der kranken Array-Syntax
1503     SfxViewFrameArr_Impl &rViewArr = SFX_APP()->GetViewFrames_Impl();
1504     rViewArr.C40_INSERT(SfxViewFrame, pThis, rViewArr.Count() );
1505 }
1506 
1507 SfxViewFrame::SfxViewFrame
1508 (
1509 	SfxFrame&           rFrame,
1510 	SfxObjectShell*     pObjShell
1511 )
1512 
1513 /*	[Beschreibung]
1514 
1515 	Ctor des SfxViewFrame f"ur eine <SfxObjectShell> aus der Ressource.
1516 	Die 'nViewId' der zu erzeugenden <SfxViewShell> kann angegeben werden
1517 	(default ist die zuerst registrierte SfxViewShell-Subklasse).
1518 */
1519 
1520     : pImp( new SfxViewFrame_Impl( rFrame ) )
1521     , pDispatcher(0)
1522     , pBindings( new SfxBindings )
1523     , nAdjustPosPixelLock( 0 )
1524 {
1525     DBG_CTOR( SfxViewFrame, NULL );
1526 
1527     rFrame.SetCurrentViewFrame_Impl( this );
1528     rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE );
1529     Construct_Impl( pObjShell );
1530 
1531     pImp->pWindow = new SfxFrameViewWindow_Impl( this, rFrame.GetWindow() );
1532     pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() );
1533 	rFrame.SetOwnsBindings_Impl( sal_True );
1534     rFrame.CreateWorkWindow_Impl();
1535 }
1536 
1537 //------------------------------------------------------------------------
1538 SfxViewFrame::~SfxViewFrame()
1539 {
1540     DBG_DTOR(SfxViewFrame, 0);
1541 
1542 	SetDowning_Impl();
1543 
1544     if ( SfxViewFrame::Current() == this )
1545         SfxViewFrame::SetViewFrame( NULL );
1546 
1547 	ReleaseObjectShell_Impl();
1548 
1549     if ( GetFrame().OwnsBindings_Impl() )
1550 		// Die Bindings l"oscht der Frame!
1551 		KillDispatcher_Impl();
1552 
1553     delete pImp->pWindow;
1554 
1555     if ( GetFrame().GetCurrentViewFrame() == this )
1556         GetFrame().SetCurrentViewFrame_Impl( NULL );
1557 
1558     // von Frame-Liste abmelden
1559     SfxApplication *pSfxApp = SFX_APP();
1560     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1561     const SfxViewFrame *pThis = this;
1562     rFrames.Remove( rFrames.GetPos(pThis) );
1563 
1564     // Member l"oschen
1565     KillDispatcher_Impl();
1566 
1567     delete pImp;
1568 }
1569 
1570 //------------------------------------------------------------------------
1571 void SfxViewFrame::KillDispatcher_Impl()
1572 
1573 // Dispatcher abr"aumen und l"oschen
1574 
1575 {
1576     DBG_CHKTHIS(SfxViewFrame, 0);
1577 
1578     SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0;
1579     if ( xObjSh.Is() )
1580         ReleaseObjectShell_Impl();
1581     if ( pDispatcher )
1582     {
1583         if( pModule )
1584 			pDispatcher->Pop( *pModule, SFX_SHELL_POP_UNTIL );
1585         else
1586 			pDispatcher->Pop( *this );
1587         DELETEZ(pDispatcher);
1588     }
1589 }
1590 
1591 //------------------------------------------------------------------------
1592 SfxViewFrame* SfxViewFrame::Current()
1593 {
1594     return SfxApplication::Get() ? SFX_APP()->Get_Impl()->pViewFrame : NULL;
1595 }
1596 
1597 //--------------------------------------------------------------------
1598 sal_uInt16 SfxViewFrame::Count()
1599 
1600 /*  [Beschreibung]
1601 
1602     Liefert die Anzahl der sichtbaren <SfxViewFrame>-Instanzen.
1603 */
1604 
1605 {
1606     SfxApplication *pSfxApp = SFX_APP();
1607     SfxViewFrameArr_Impl& rFrames = pSfxApp->GetViewFrames_Impl();
1608     const sal_uInt16 nCount = rFrames.Count();
1609     sal_uInt16 nFound = 0;
1610     for ( sal_uInt16 i = 0; i < nCount; ++i )
1611     {
1612         SfxViewFrame *pFrame = rFrames[i];
1613         if ( pFrame->IsVisible() )
1614             ++nFound;
1615     }
1616     return nFound;
1617 }
1618 
1619 //--------------------------------------------------------------------
1620 // returns the first window of spec. type viewing the specified doc.
1621 SfxViewFrame* SfxViewFrame::GetFirst
1622 (
1623     const SfxObjectShell*   pDoc,
1624     sal_Bool                    bOnlyIfVisible
1625 )
1626 {
1627     SfxApplication *pSfxApp = SFX_APP();
1628     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1629 
1630     // search for a SfxDocument of the specified type
1631     for ( sal_uInt16 nPos = 0; nPos < rFrames.Count(); ++nPos )
1632     {
1633         SfxViewFrame *pFrame = rFrames.GetObject(nPos);
1634         if  (   ( !pDoc || pDoc == pFrame->GetObjectShell() )
1635             &&  ( !bOnlyIfVisible || pFrame->IsVisible() )
1636             )
1637             return pFrame;
1638     }
1639 
1640     return 0;
1641 }
1642 //--------------------------------------------------------------------
1643 
1644 // returns thenext window of spec. type viewing the specified doc.
1645 SfxViewFrame* SfxViewFrame::GetNext
1646 (
1647     const SfxViewFrame&     rPrev,
1648     const SfxObjectShell*   pDoc,
1649     sal_Bool                    bOnlyIfVisible
1650 )
1651 {
1652     SfxApplication *pSfxApp = SFX_APP();
1653     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1654 
1655     // refind the specified predecessor
1656 	sal_uInt16 nPos;
1657     for ( nPos = 0; nPos < rFrames.Count(); ++nPos )
1658         if ( rFrames.GetObject(nPos) == &rPrev )
1659             break;
1660 
1661     // search for a Frame of the specified type
1662     for ( ++nPos; nPos < rFrames.Count(); ++nPos )
1663     {
1664         SfxViewFrame *pFrame = rFrames.GetObject(nPos);
1665         if  (   ( !pDoc || pDoc == pFrame->GetObjectShell() )
1666             &&  ( !bOnlyIfVisible || pFrame->IsVisible() )
1667             )
1668             return pFrame;
1669     }
1670     return 0;
1671 }
1672 
1673 void SfxViewFrame::CloseHiddenFrames_Impl()
1674 {
1675     SfxApplication *pSfxApp = SFX_APP();
1676     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1677     for ( sal_uInt16 nPos=0; nPos<rFrames.Count(); )
1678     {
1679         SfxViewFrame *pFrame = rFrames.GetObject(nPos);
1680         if ( !pFrame->IsVisible() )
1681 			pFrame->DoClose();
1682 		else
1683 			nPos++;
1684 	}
1685 }
1686 
1687 //--------------------------------------------------------------------
1688 SfxProgress* SfxViewFrame::GetProgress() const
1689 {
1690     SfxObjectShell *pObjSh = GetObjectShell();
1691     return pObjSh ? pObjSh->GetProgress() : 0;
1692 }
1693 
1694 //--------------------------------------------------------------------
1695 void SfxViewFrame::ShowStatusText( const String& /*rText*/)
1696 {
1697 /* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx &
1698              framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be
1699              extended to support a new interface to support ShowStatusText/HideStatusText
1700     SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl();
1701     SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl();
1702 	if ( pMgr )
1703 	{
1704 		pMgr->GetStatusBar()->HideItems();
1705 		pMgr->GetStatusBar()->SetText( rText );
1706 	}
1707 */
1708 }
1709 
1710 //--------------------------------------------------------------------
1711 void SfxViewFrame::HideStatusText()
1712 {
1713 /* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx &
1714              framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be
1715              extended to support a new interface to support ShowStatusText/HideStatusText
1716     SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl();
1717     SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl();
1718 	if ( pMgr )
1719 		pMgr->GetStatusBar()->ShowItems();
1720 */
1721 }
1722 
1723 
1724 //--------------------------------------------------------------------
1725 #ifdef ENABLE_INIMANAGER//MUSTINI
1726 SfxIniManager* SfxViewFrame::GetIniManager() const
1727 {
1728 /*  SfxIniManager *pIniMgr = GetObjectShell()
1729             ? GetObjectShell()->GetFactory().GetIniManager()
1730             : 0;
1731     if ( !pIniMgr )*/ //!
1732         return SFX_APP()->GetAppIniManager();
1733 //  return pIniMgr;
1734 }
1735 #endif
1736 
1737 //--------------------------------------------------------------------
1738 void SfxViewFrame::DoAdjustPosSizePixel //! teilen in Inner.../Outer...
1739 (
1740     SfxViewShell*   pSh,
1741     const Point&    rPos,
1742     const Size&     rSize
1743 )
1744 {
1745     DBG_CHKTHIS(SfxViewFrame, 0);
1746 
1747 	// Components benutzen diese Methode nicht!
1748     if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock )
1749     {
1750         nAdjustPosPixelLock++;
1751         if ( pImp->bResizeInToOut )
1752             pSh->InnerResizePixel( rPos, rSize );
1753         else
1754             pSh->OuterResizePixel( rPos, rSize );
1755         nAdjustPosPixelLock--;
1756     }
1757 }
1758 
1759 //========================================================================
1760 
1761 int SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const
1762 {
1763      return PTR_CAST(SfxViewFrameItem, &rItem)->pFrame== pFrame;
1764 }
1765 
1766 //--------------------------------------------------------------------
1767 String SfxViewFrameItem::GetValueText() const
1768 {
1769     return String();
1770 }
1771 
1772 //--------------------------------------------------------------------
1773 SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const
1774 {
1775     return new SfxViewFrameItem( pFrame);
1776 }
1777 
1778 //--------------------------------------------------------------------
1779 void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh )
1780 
1781 /*  [Beschreibung]
1782 
1783     Interne Methode zum setzen der jeweils aktuellen <SfxViewShell>-Instanz,
1784     die in diesem SfxViewFrame aktiv ist.
1785 */
1786 
1787 {
1788     SfxShell::SetViewShell_Impl( pVSh );
1789 
1790     // Hack: InPlaceMode
1791     if ( pVSh )
1792         pImp->bResizeInToOut = sal_False;
1793 }
1794 
1795 //--------------------------------------------------------------------
1796 /*
1797     Beschreibung:
1798     Der ParentViewFrame ist der ViewFrame des Containers bei internem InPlace
1799 */
1800 
1801 //TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl?
1802 SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const
1803 {
1804     return NULL;
1805 }
1806 
1807 //--------------------------------------------------------------------
1808 void SfxViewFrame::ForceOuterResize_Impl(sal_Bool bOn)
1809 {
1810 	if ( !pImp->bDontOverwriteResizeInToOut )
1811     	pImp->bResizeInToOut = !bOn;
1812 }
1813 
1814 void SfxViewFrame::ForceInnerResize_Impl(sal_Bool bOn)
1815 {
1816 	pImp->bDontOverwriteResizeInToOut = bOn;
1817 }
1818 
1819 //--------------------------------------------------------------------
1820 sal_Bool SfxViewFrame::IsResizeInToOut_Impl() const
1821 {
1822     return pImp->bResizeInToOut;
1823 }
1824 //--------------------------------------------------------------------
1825 void SfxViewFrame::DoAdjustPosSize( SfxViewShell *pSh,
1826                                 const Point rPos, const Size &rSize )
1827 {
1828     DBG_CHKTHIS(SfxViewFrame, 0);
1829     if( pSh && !nAdjustPosPixelLock )
1830     {
1831         Window *pWindow = pSh->GetWindow();
1832         Point aPos = pWindow->LogicToPixel(rPos);
1833         Size aSize = pWindow->LogicToPixel(rSize);
1834         DoAdjustPosSizePixel(pSh, aPos, aSize);
1835     }
1836 }
1837 
1838 //--------------------------------------------------------------------
1839 void SfxViewFrame::GetDocNumber_Impl()
1840 {
1841     DBG_ASSERT( GetObjectShell(), "Kein Dokument!" );
1842     GetObjectShell()->SetNamedVisibility_Impl();
1843     pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1;
1844 }
1845 
1846 //--------------------------------------------------------------------
1847 
1848 void SfxViewFrame::Enable( sal_Bool bEnable )
1849 {
1850     if ( bEnable != pImp->bEnabled )
1851     {
1852         pImp->bEnabled = bEnable;
1853 
1854         // e.g. InPlace-Frames have a parent...
1855         SfxViewFrame *pParent = GetParentViewFrame_Impl();
1856         if ( pParent )
1857         {
1858             pParent->Enable( bEnable );
1859         }
1860         else
1861         {
1862             Window *pWindow = &GetFrame().GetTopFrame().GetWindow();
1863             if ( !bEnable )
1864                 pImp->bWindowWasEnabled = pWindow->IsInputEnabled();
1865             if ( !bEnable || pImp->bWindowWasEnabled )
1866                 pWindow->EnableInput( bEnable, sal_True );
1867         }
1868 
1869         // cursor and focus
1870         SfxViewShell* pViewSh = GetViewShell();
1871         if ( bEnable )
1872         {
1873             // show cursor
1874             if ( pViewSh )
1875                 pViewSh->ShowCursor();
1876         }
1877         else
1878         {
1879             // hide cursor
1880             if ( pViewSh )
1881                 pViewSh->ShowCursor(sal_False);
1882         }
1883 /*
1884         if ( !bEnable )
1885             GetBindings().ENTERREGISTRATIONS();
1886         GetDispatcher()->Lock( !bEnable );
1887         if ( bEnable )
1888             GetBindings().LEAVEREGISTRATIONS();
1889 */
1890     }
1891 }
1892 
1893 //--------------------------------------------------------------------
1894 void SfxViewFrame::Show()
1895 
1896 /*  [Beschreibung]
1897 
1898     Diese Methode macht das Frame-Window sichtbar und ermittelt vorher
1899     den Fenstername. Au\serdem wird das Dokument festgehalten. Man darf
1900     i.d.R. nie das Window direkt showen!
1901 */
1902 
1903 {
1904     // zuerst locken damit in UpdateTitle() gilt: IsVisible() == sal_True (:#)
1905     if ( xObjSh.Is() )
1906     {
1907         xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN );
1908         if ( !pImp->bObjLocked )
1909             LockObjectShell_Impl( sal_True );
1910 
1911         // Doc-Shell Titel-Nummer anpassen, get unique view-no
1912         if ( 0 == pImp->nDocViewNo  )
1913         {
1914             GetDocNumber_Impl();
1915             UpdateTitle();
1916         }
1917     }
1918     else
1919         UpdateTitle();
1920 
1921     // Frame-Window anzeigen, aber nur wenn der ViewFrame kein eigenes Window
1922 	// hat oder wenn er keine Component enth"alt
1923 	if ( &GetWindow() == &GetFrame().GetWindow() || !GetFrame().HasComponent() )
1924     	GetWindow().Show();
1925     GetFrame().GetWindow().Show();
1926 
1927 /*    SfxViewFrame* pCurrent = SfxViewFrame::Current();
1928 	if ( GetFrame().GetFrameInterface()->isActive() &&
1929 			pCurrent != this &&
1930 			( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) &&
1931 			!GetActiveChildFrame_Impl() )
1932         MakeActive_Impl( sal_False );*/
1933     if ( xObjSh.Is() && xObjSh->Get_Impl()->bHiddenLockedByAPI )
1934     {
1935         xObjSh->Get_Impl()->bHiddenLockedByAPI = sal_False;
1936         xObjSh->OwnerLock(sal_False);
1937     }
1938 }
1939 
1940 //--------------------------------------------------------------------
1941 sal_Bool SfxViewFrame::IsVisible() const
1942 {
1943     return pImp->bObjLocked;
1944 }
1945 
1946 //--------------------------------------------------------------------
1947 void SfxViewFrame::Hide()
1948 {
1949     GetWindow().Hide();
1950     if ( pImp->bObjLocked )
1951         LockObjectShell_Impl( sal_False );
1952 }
1953 
1954 //--------------------------------------------------------------------
1955 void SfxViewFrame::LockObjectShell_Impl( sal_Bool bLock )
1956 {
1957     DBG_ASSERT( pImp->bObjLocked != bLock, "Falscher Locked-Status!" );
1958 
1959     DBG_ASSERT( GetObjectShell(), "Kein Dokument!" );
1960     GetObjectShell()->OwnerLock(bLock);
1961     pImp->bObjLocked = bLock;
1962 }
1963 
1964 //--------------------------------------------------------------------
1965 void SfxViewFrame::MakeActive_Impl( sal_Bool bGrabFocus )
1966 {
1967 	if ( GetViewShell() && !GetFrame().IsClosing_Impl() )
1968 	{
1969         if ( IsVisible() )
1970         {
1971             if ( GetViewShell() )
1972             {
1973                 sal_Bool bPreview = sal_False;
1974                 if ( GetObjectShell()->IsPreview() )
1975                 {
1976                     bPreview = sal_True;
1977                 }
1978                 else
1979                 {
1980                     SfxViewFrame* pParent = GetParentViewFrame();
1981                     if ( pParent )
1982                         pParent->SetActiveChildFrame_Impl( this );
1983                 }
1984 
1985                 SfxViewFrame* pCurrent = SfxViewFrame::Current();
1986                 css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface();
1987                 if ( !bPreview )
1988                 {
1989                     SetViewFrame( this );
1990                     GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() );
1991                     uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY );
1992                     if ( xSupp.is() )
1993                         xSupp->setActiveFrame( uno::Reference < frame::XFrame >() );
1994 
1995                     css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
1996                     Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
1997                     if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus)
1998                     {
1999                         SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient();
2000                         if ( ( !pCli || !pCli->IsObjectUIActive() ) &&
2001                             ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) )
2002                                 GetFrame().GrabFocusOnComponent_Impl();
2003                     }
2004                 }
2005                 else
2006                 {
2007                     GetBindings().SetDispatcher( GetDispatcher() );
2008                     GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
2009                     GetDispatcher()->Update_Impl( sal_False );
2010                 }
2011             }
2012         }
2013 	}
2014 }
2015 
2016 //-------------------------------------------------------------------------
2017 
2018 void SfxViewFrame::SetQuietMode_Impl( sal_Bool bOn )
2019 {
2020     GetDispatcher()->SetQuietMode_Impl( bOn );
2021 }
2022 
2023 //-------------------------------------------------------------------------
2024 
2025 SfxObjectShell* SfxViewFrame::GetObjectShell()
2026 {
2027     return xObjSh;
2028 }
2029 
2030 const Size& SfxViewFrame::GetMargin_Impl() const
2031 {
2032     return pImp->aMargin;
2033 }
2034 
2035 void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame )
2036 {
2037 	if ( pViewFrame != pImp->pActiveChild )
2038 	{
2039 	    if ( !pImp->pActiveChild )
2040 	        GetDispatcher()->LockUI_Impl( sal_False );
2041 
2042 	    pImp->pActiveChild = pViewFrame;
2043 
2044 		Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY );
2045 		Reference< XFrame >  xActive;
2046 		if ( pViewFrame )
2047 			xActive = pViewFrame->GetFrame().GetFrameInterface();
2048 
2049 		if ( xFrame.is() )	// PB: #74432# xFrame cann be NULL
2050 			xFrame->setActiveFrame( xActive );
2051 	}
2052 }
2053 
2054 SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const
2055 {
2056     SfxViewFrame *pViewFrame = pImp->pActiveChild;
2057 /*
2058     if ( !pViewFrame )
2059     {
2060         // Wenn es keinen aktiven ChildFrame gibt, irgendeinen nehmen
2061         for ( sal_uInt16 n=0; n<GetChildFrameCount(); n++ )
2062         {
2063             pViewFrame =
2064                 PTR_CAST( SfxViewFrame, GetChildFrame(n)->GetChildFrame(0) );
2065             if ( pViewFrame )
2066                 break;
2067         }
2068     }
2069 
2070     pImp->pActiveChild = pViewFrame;
2071 */
2072     return pViewFrame;
2073 }
2074 
2075 //--------------------------------------------------------------------
2076 SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
2077                                                    const sal_uInt16 i_nViewId, const bool i_bHidden )
2078 {
2079     Reference< XFrame > xFrame( i_rFrame );
2080     bool bOwnFrame = false;
2081     SfxViewShell* pSuccessView = NULL;
2082     try
2083     {
2084         if ( !xFrame.is() )
2085         {
2086             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2087             Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
2088 
2089             if ( !i_bHidden )
2090             {
2091                 try
2092                 {
2093                     // if there is a backing component, use it
2094                     Reference< XFramesSupplier > xTaskSupplier( xDesktop , css::uno::UNO_QUERY_THROW );
2095                     ::framework::FrameListAnalyzer aAnalyzer( xTaskSupplier, Reference< XFrame >(), ::framework::FrameListAnalyzer::E_BACKINGCOMPONENT );
2096 
2097                     if ( aAnalyzer.m_xBackingComponent.is() )
2098                         xFrame = aAnalyzer.m_xBackingComponent;
2099                 }
2100                 catch( uno::Exception& )
2101                 {}
2102             }
2103 
2104             if ( !xFrame.is() )
2105                 xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW );
2106 
2107             bOwnFrame = true;
2108         }
2109 
2110         pSuccessView = LoadViewIntoFrame_Impl(
2111             i_rDoc,
2112             xFrame,
2113             Sequence< PropertyValue >(),    // means "reuse existing model's args"
2114             i_nViewId,
2115             i_bHidden
2116         );
2117 
2118         if ( bOwnFrame && !i_bHidden )
2119         {
2120             // ensure the frame/window is visible
2121             Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
2122             xContainerWindow->setVisible( sal_True );
2123         }
2124     }
2125     catch( const Exception& )
2126     {
2127     	DBG_UNHANDLED_EXCEPTION();
2128     }
2129 
2130     if ( pSuccessView )
2131         return pSuccessView->GetViewFrame();
2132 
2133     if ( bOwnFrame )
2134     {
2135         try
2136         {
2137             xFrame->dispose();
2138         }
2139         catch( const Exception& )
2140         {
2141         	DBG_UNHANDLED_EXCEPTION();
2142         }
2143     }
2144 
2145     return NULL;
2146 }
2147 
2148 //--------------------------------------------------------------------
2149 SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
2150                                            const Sequence< PropertyValue >& i_rLoadArgs, const sal_uInt16 i_nViewId,
2151                                            const bool i_bHidden )
2152 {
2153     Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW );
2154 
2155     ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() );
2156     aTransformLoadArgs.put( "Model", xDocument );
2157     if ( i_nViewId )
2158         aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) );
2159     if ( i_bHidden )
2160         aTransformLoadArgs.put( "Hidden", i_bHidden );
2161     else
2162         aTransformLoadArgs.remove( "Hidden" );
2163 
2164     ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) );
2165     if ( !sURL.getLength() )
2166         sURL = i_rDoc.GetFactory().GetFactoryURL();
2167 
2168     Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
2169     xLoader->loadComponentFromURL( sURL, ::rtl::OUString::createFromAscii( "_self" ), 0,
2170         aTransformLoadArgs.getPropertyValues() );
2171 
2172     SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
2173     ENSURE_OR_THROW( pViewShell,
2174         "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" );
2175     return pViewShell;
2176 }
2177 
2178 //--------------------------------------------------------------------
2179 
2180 SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
2181 {
2182     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true );
2183 }
2184 
2185 //--------------------------------------------------------------------
2186 
2187 SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
2188 {
2189     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false );
2190 }
2191 
2192 //--------------------------------------------------------------------
2193 
2194 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const sal_uInt16 i_nViewId )
2195 {
2196     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false );
2197 }
2198 
2199 //--------------------------------------------------------------------
2200 
2201 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const sal_uInt16 i_nViewId )
2202 {
2203     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false );
2204 }
2205 
2206 //--------------------------------------------------------------------
2207 SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const sal_uInt16 i_nViewId )
2208 {
2209     SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
2210     SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
2211 
2212     return LoadViewIntoFrame_Impl_NoThrow(
2213         i_rDoc,
2214         pFrameItem ? pFrameItem->GetFrame() : NULL,
2215         i_nViewId,
2216         pHiddenItem ? pHiddenItem->GetValue() : false
2217     );
2218 }
2219 
2220 //--------------------------------------------------------------------
2221 
2222 SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc )
2223 {
2224     if ( !i_rController.is() )
2225         return NULL;
2226 
2227     const SfxObjectShell* pDoc = i_pDoc;
2228     if ( !pDoc )
2229     {
2230         Reference< XModel > xDocument( i_rController->getModel() );
2231         for (   pDoc = SfxObjectShell::GetFirst( 0, false );
2232                 pDoc;
2233                 pDoc = SfxObjectShell::GetNext( *pDoc, 0, false )
2234             )
2235         {
2236             if ( pDoc->GetModel() == xDocument )
2237                 break;
2238         }
2239     }
2240 
2241     SfxViewFrame* pViewFrame = NULL;
2242     for (   pViewFrame = SfxViewFrame::GetFirst( pDoc, sal_False );
2243             pViewFrame;
2244             pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, sal_False )
2245         )
2246     {
2247         if ( pViewFrame->GetViewShell()->GetController() == i_rController )
2248             break;
2249     }
2250 
2251     return pViewFrame;
2252 }
2253 
2254 //--------------------------------------------------------------------
2255 
2256 void SfxViewFrame::SaveCurrentViewData_Impl( const sal_uInt16 i_nNewViewId )
2257 {
2258     SfxViewShell* pCurrentShell = GetViewShell();
2259     ENSURE_OR_RETURN_VOID( pCurrentShell != NULL, "SfxViewFrame::SaveCurrentViewData_Impl: no current view shell -> no current view data!" );
2260 
2261     // determine the logical (API) view name
2262     const SfxObjectFactory& rDocFactory( pCurrentShell->GetObjectShell()->GetFactory() );
2263     const sal_uInt16 nCurViewNo = rDocFactory.GetViewNo_Impl( GetCurViewId(), 0 );
2264     const String sCurrentViewName = rDocFactory.GetViewFactory( nCurViewNo ).GetAPIViewName();
2265     const sal_uInt16 nNewViewNo = rDocFactory.GetViewNo_Impl( i_nNewViewId, 0 );
2266     const String sNewViewName = rDocFactory.GetViewFactory( nNewViewNo ).GetAPIViewName();
2267     if ( ( sCurrentViewName.Len() == 0 ) || ( sNewViewName.Len() == 0 ) )
2268     {
2269         // can't say anything about the view, the respective application did not yet migrate its code to
2270         // named view factories => bail out
2271         OSL_ENSURE( false, "SfxViewFrame::SaveCurrentViewData_Impl: views without API names? Shouldn't happen anymore?" );
2272         return;
2273     }
2274     OSL_ENSURE( !sNewViewName.Equals( sCurrentViewName ), "SfxViewFrame::SaveCurrentViewData_Impl: suspicious: new and old view name are identical!" );
2275 
2276     // save the view data only when we're moving from a non-print-preview to the print-preview view
2277     if ( !sNewViewName.EqualsAscii( "PrintPreview" ) )
2278         return;
2279 
2280     // retrieve the view data from the view
2281     Sequence< PropertyValue > aViewData;
2282     pCurrentShell->WriteUserDataSequence( aViewData );
2283 
2284     try
2285     {
2286         // retrieve view data (for *all* views) from the model
2287         const Reference< XController > xController( pCurrentShell->GetController(), UNO_SET_THROW );
2288         const Reference< XViewDataSupplier > xViewDataSupplier( xController->getModel(), UNO_QUERY_THROW );
2289         const Reference< XIndexContainer > xViewData( xViewDataSupplier->getViewData(), UNO_QUERY_THROW );
2290 
2291         // look up the one view data item which corresponds to our current view, and remove it
2292         const sal_Int32 nCount = xViewData->getCount();
2293         for ( sal_Int32 i=0; i<nCount; ++i )
2294         {
2295             const ::comphelper::NamedValueCollection aCurViewData( xViewData->getByIndex(i) );
2296             ::rtl::OUString sViewId( aCurViewData.getOrDefault( "ViewId", ::rtl::OUString() ) );
2297             if ( sViewId.getLength() == 0 )
2298                 continue;
2299 
2300             const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
2301             if ( pViewFactory == NULL )
2302                 continue;
2303 
2304             if ( pViewFactory->GetOrdinal() == GetCurViewId() )
2305             {
2306                 xViewData->removeByIndex(i);
2307                 break;
2308             }
2309         }
2310 
2311         // then replace it with the most recent view data we just obtained
2312         xViewData->insertByIndex( 0, makeAny( aViewData ) );
2313     }
2314     catch( const Exception& )
2315     {
2316     	DBG_UNHANDLED_EXCEPTION();
2317     }
2318 }
2319 
2320 //--------------------------------------------------------------------
2321 
2322 sal_Bool SfxViewFrame::SwitchToViewShell_Impl
2323 (
2324     sal_uInt16  nViewIdOrNo,    /*  > 0
2325                                 Registrierungs-Id der View, auf die umge-
2326                                 schaltet werden soll, bzw. die erstmalig
2327                                 erzeugt werden soll.
2328 
2329                                 == 0
2330                                 Es soll die Default-View verwendet werden. */
2331 
2332     sal_Bool    bIsIndex        /*  sal_True
2333                                 'nViewIdOrNo' ist keine Registrations-Id sondern
2334                                 ein Index in die f"ur die in diesem
2335                                 <SfxViewFrame> dargestellte <SfxObjectShell>.
2336                                 */
2337 )
2338 
2339 /*  [Beschreibung]
2340 
2341     Interne Methode zum Umschalten auf eine andere <SfxViewShell>-Subklasse,
2342     die in diesem SfxMDIFrame erzeugt werden soll. Existiert noch
2343     keine SfxViewShell in diesem SfxMDIFrame, so wird erstmalig eine
2344     erzeugt.
2345 
2346 
2347     [R"uckgabewert]
2348 
2349     sal_Bool                        sal_True
2350                                 die angeforderte SfxViewShell wurde erzeugt
2351                                 und eine ggf. bestehende gel"oscht
2352 
2353                                 sal_False
2354                                 die angeforderte SfxViewShell konnte nicht
2355                                 erzeugt werden, die bestehende SfxViewShell
2356                                 existiert daher weiterhin
2357 */
2358 
2359 {
2360     try
2361     {
2362         ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" );
2363 
2364         // if we already have a view shell, remove it
2365         SfxViewShell* pOldSh = GetViewShell();
2366         OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" );
2367         if ( pOldSh )
2368         {
2369             // ask wether it can be closed
2370             if ( !pOldSh->PrepareClose( sal_True ) )
2371                 return sal_False;
2372 
2373             // remove sub shells from Dispatcher before switching to new ViewShell
2374             PopShellAndSubShells_Impl( *pOldSh );
2375         }
2376 
2377         GetBindings().ENTERREGISTRATIONS();
2378         LockAdjustPosSizePixel();
2379 
2380         // ID of the new view
2381         SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory();
2382         const sal_uInt16 nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo;
2383 
2384         // save the view data of the old view, so it can be restored later on (when needed)
2385         SaveCurrentViewData_Impl( nViewId );
2386 
2387         // create and load new ViewShell
2388         SfxViewShell* pNewSh = LoadViewIntoFrame_Impl(
2389             *GetObjectShell(),
2390             GetFrame().GetFrameInterface(),
2391             Sequence< PropertyValue >(),    // means "reuse existing model's args"
2392             nViewId,
2393             false
2394         );
2395 
2396         // allow resize events to be processed
2397         UnlockAdjustPosSizePixel();
2398 
2399         if ( GetWindow().IsReallyVisible() )
2400             DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() );
2401 
2402 	    GetBindings().LEAVEREGISTRATIONS();
2403         delete pOldSh;
2404     }
2405     catch ( const com::sun::star::uno::Exception& )
2406     {
2407         // the SfxCode is not able to cope with exceptions thrown while creating views
2408         // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here
2409         DBG_UNHANDLED_EXCEPTION();
2410         return sal_False;
2411     }
2412 
2413     DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().Count() == SFX_APP()->GetViewShells_Impl().Count(), "Inconsistent view arrays!" );
2414     return sal_True;
2415 }
2416 
2417 //-------------------------------------------------------------------------
2418 void SfxViewFrame::SetCurViewId_Impl( const sal_uInt16 i_nID )
2419 {
2420     pImp->nCurViewId = i_nID;
2421 }
2422 
2423 //-------------------------------------------------------------------------
2424 sal_uInt16 SfxViewFrame::GetCurViewId() const
2425 {
2426     return pImp->nCurViewId;
2427 }
2428 
2429 //-------------------------------------------------------------------------
2430 void SfxViewFrame::ExecView_Impl
2431 (
2432     SfxRequest& rReq        // der auszuf"uhrende <SfxRequest>
2433 )
2434 
2435 /*  [Beschreibung]
2436 
2437     Interne Methode zum Ausf"uhren der f"ur die <SfxShell> Subklasse
2438     SfxViewFrame in der <SVIDL> beschriebenen Slots.
2439 */
2440 
2441 {
2442     DBG_CHKTHIS(SfxViewFrame, 0);
2443 
2444     // Wenn gerade die Shells ausgetauscht werden...
2445     if ( !GetObjectShell() || !GetViewShell() )
2446         return;
2447 
2448     switch ( rReq.GetSlot() )
2449     {
2450         case SID_TERMINATE_INPLACEACTIVATION :
2451         {
2452             SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient();
2453             if ( pClient )
2454                 pClient->DeactivateObject();
2455             break;
2456         }
2457 
2458         case SID_VIEWSHELL:
2459         {
2460             const SfxPoolItem *pItem = 0;
2461             if  (   rReq.GetArgs()
2462                 &&  SFX_ITEM_SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, sal_False, &pItem )
2463                 )
2464             {
2465                 const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
2466                 sal_Bool bSuccess = SwitchToViewShell_Impl( nViewId );
2467                 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
2468             }
2469             break;
2470         }
2471 
2472         case SID_VIEWSHELL0:
2473         case SID_VIEWSHELL1:
2474         case SID_VIEWSHELL2:
2475         case SID_VIEWSHELL3:
2476         case SID_VIEWSHELL4:
2477         {
2478             const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0;
2479             sal_Bool bSuccess = SwitchToViewShell_Impl( nViewNo, sal_True );
2480             rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
2481             break;
2482         }
2483 
2484         case SID_NEWWINDOW:
2485         {
2486             // Hack. demnaechst virtuelle Funktion
2487             if ( !GetViewShell()->NewWindowAllowed() )
2488             {
2489                 OSL_ENSURE( false, "You should have disabled the 'Window/New Window' slot!" );
2490                 return;
2491             }
2492 
2493 			// ViewData bei FrameSets rekursiv holen
2494 			GetFrame().GetViewData_Impl();
2495 			SfxMedium* pMed = GetObjectShell()->GetMedium();
2496 
2497             // do not open the new window hidden
2498 			pMed->GetItemSet()->ClearItem( SID_HIDDEN );
2499 
2500             // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...)
2501             SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False );
2502             const sal_uInt16 nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId();
2503 
2504         	Reference < XFrame > xFrame;
2505             // the frame (optional arg. TODO: this is currently not supported in the slot definition ...)
2506             SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
2507             if ( pFrameItem )
2508                 xFrame = pFrameItem->GetFrame();
2509 
2510             LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false );
2511 
2512 			rReq.Done();
2513             break;
2514         }
2515 
2516         case SID_OBJECT:
2517         {
2518             SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, SID_OBJECT, sal_False );
2519 
2520 	        SfxViewShell *pViewShell = GetViewShell();
2521 	        if ( pViewShell && pItem )
2522 	        {
2523 				pViewShell->DoVerb( pItem->GetValue() );
2524                 rReq.Done();
2525 				break;;
2526             }
2527         }
2528     }
2529 }
2530 
2531 //-------------------------------------------------------------------------
2532 /* TODO as96863:
2533         This method try to collect informations about the count of currently open documents.
2534         But the algorithm is implemented very simple ...
2535         E.g. hidden documents should be ignored here ... but they are counted.
2536         TODO: export special helper "framework::FrameListAnalyzer" within the framework module
2537         and use it here.
2538 */
2539 sal_Bool impl_maxOpenDocCountReached()
2540 {
2541     static ::rtl::OUString SERVICE_DESKTOP = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop");
2542 
2543     try
2544     {
2545         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
2546         css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
2547                                 xSMGR,
2548                                 ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"),
2549                                 ::rtl::OUString::createFromAscii("Misc"),
2550                                 ::rtl::OUString::createFromAscii("MaxOpenDocuments"),
2551                                 ::comphelper::ConfigurationHelper::E_READONLY);
2552 
2553         // NIL means: count of allowed documents = infinite !
2554         if ( ! aVal.hasValue())
2555             return sal_False;
2556 
2557         sal_Int32 nOpenDocs = 0;
2558         sal_Int32 nMaxDocs  = 0;
2559         aVal >>= nMaxDocs;
2560 
2561         css::uno::Reference< css::frame::XFramesSupplier >  xDesktop(xSMGR->createInstance(SERVICE_DESKTOP), css::uno::UNO_QUERY_THROW);
2562         css::uno::Reference< css::container::XIndexAccess > xCont   (xDesktop->getFrames()                 , css::uno::UNO_QUERY_THROW);
2563 
2564         sal_Int32 c = xCont->getCount();
2565         sal_Int32 i = 0;
2566 
2567         for (i=0; i<c; ++i)
2568         {
2569             try
2570             {
2571                 css::uno::Reference< css::frame::XFrame > xFrame;
2572                 xCont->getByIndex(i) >>= xFrame;
2573                 if ( ! xFrame.is())
2574                     continue;
2575 
2576                 // a) do not count the help window
2577                 if (xFrame->getName().equalsAscii("OFFICE_HELP_TASK"))
2578                     continue;
2579 
2580                 // b) count all other frames
2581                 ++nOpenDocs;
2582             }
2583             catch(const css::uno::Exception&)
2584                 // A IndexOutOfBoundException can happen in multithreaded environments,
2585                 // where any other thread can change this container !
2586                 { continue; }
2587         }
2588 
2589         return (nOpenDocs >= nMaxDocs);
2590     }
2591     catch(const css::uno::Exception&)
2592         {}
2593 
2594     // Any internal error is no reason to stop opening documents !
2595     // Limitation of opening documents is a special "nice to  have" feature.
2596     // Otherwhise it can happen, that NO document will be opened ...
2597     return sal_False;
2598 }
2599 
2600 //-------------------------------------------------------------------------
2601 void SfxViewFrame::StateView_Impl
2602 (
2603     SfxItemSet&     rSet            /*  leeres <SfxItemSet> mit <Which-Ranges>,
2604                                         welche die Ids der zu erfragenden
2605                                         Slots beschreiben. */
2606 )
2607 
2608 /*  [Beschreibung]
2609 
2610     Diese interne Methode liefert in 'rSet' die Status der f"ur die
2611     <SfxShell> Subklasse SfxViewFrame in der <SVIDL> beschriebenen <Slots>.
2612 
2613     In 'rSet' sind dabei genau die vom SFx als ung"ultig erkannten
2614     Slot-Ids als Which-ranges enthalten. Falls der an dieser Shell gesetzte
2615     <SfxItemPool> f"ur einzelne Slot-Ids ein Mapping hat, werden die
2616     entsprechenden Which-Ids verwendet, so da\s Items ggf. direkt mit
2617     einer mit Which-Ids arbeitenden Core-::com::sun::star::script::Engine ausgetauscht werden
2618     k"onnen.
2619 */
2620 
2621 {
2622     DBG_CHKTHIS(SfxViewFrame, 0);
2623 
2624     SfxObjectShell *pDocSh = GetObjectShell();
2625 
2626     if ( !pDocSh )
2627 		// Ich bin gerade am Reloaden und Yielde so vor mich hin ...
2628         return;
2629 
2630     const sal_uInt16 *pRanges = rSet.GetRanges();
2631     DBG_ASSERT(pRanges, "Set ohne Bereich");
2632     while ( *pRanges )
2633     {
2634         for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
2635         {
2636             switch(nWhich)
2637             {
2638                 case SID_VIEWSHELL:
2639                 {
2640                     rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) );
2641                     break;
2642                 }
2643 
2644                 case SID_VIEWSHELL0:
2645                 case SID_VIEWSHELL1:
2646                 case SID_VIEWSHELL2:
2647                 case SID_VIEWSHELL3:
2648                 case SID_VIEWSHELL4:
2649                 {
2650                     sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0;
2651                     if ( GetObjectShell()->GetFactory().GetViewFactoryCount() >
2652                          nViewNo && !GetObjectShell()->IsInPlaceActive() )
2653                     {
2654                         SfxViewFactory &rViewFactory =
2655                             GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
2656                         rSet.Put( SfxBoolItem(
2657                             nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) );
2658                     }
2659                     else
2660                         rSet.DisableItem( nWhich );
2661                     break;
2662                 }
2663                 case SID_FRAMETITLE:
2664                 {
2665                     if( GetFrameType() & SFXFRAME_HASTITLE )
2666                         rSet.Put( SfxStringItem(
2667                             SID_FRAMETITLE, pImp->aFrameTitle) );
2668                     else
2669                         rSet.DisableItem( nWhich );
2670                     break;
2671                 }
2672 
2673 		        case SID_NEWWINDOW:
2674 		        {
2675                     if  (   !GetViewShell()->NewWindowAllowed()
2676                         ||  impl_maxOpenDocCountReached()
2677                         )
2678                         rSet.DisableItem( nWhich );
2679 					break;
2680 				}
2681             }
2682         }
2683     }
2684 }
2685 
2686 //-------------------------------------------------------------------------
2687 void SfxViewFrame::ToTop()
2688 {
2689     GetFrame().Appear();
2690 }
2691 
2692 //-------------------------------------------------------------------------
2693 SfxViewFrame* SfxViewFrame::GetParentViewFrame() const
2694 /*
2695     Beschreibung:
2696     Der ParentViewFrame ist der ViewFrame des ParentFrames
2697 */
2698 {
2699     SfxFrame *pFrame = GetFrame().GetParentFrame();
2700     return pFrame ? pFrame->GetCurrentViewFrame() : NULL;
2701 }
2702 
2703 //-------------------------------------------------------------------------
2704 SfxFrame& SfxViewFrame::GetFrame() const
2705 /*
2706     Beschreibung:
2707     GetFrame liefert den Frame, in dem sich der ViewFrame befindet
2708 */
2709 {
2710     return pImp->rFrame;
2711 }
2712 
2713 //-------------------------------------------------------------------------
2714 SfxViewFrame* SfxViewFrame::GetTopViewFrame() const
2715 {
2716     return GetFrame().GetTopFrame().GetCurrentViewFrame();
2717 }
2718 
2719 Window& SfxViewFrame::GetWindow() const
2720 {
2721 	return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow();
2722 }
2723 
2724 sal_Bool SfxViewFrame::DoClose()
2725 {
2726 	return GetFrame().DoClose();
2727 }
2728 
2729 String SfxViewFrame::GetActualPresentationURL_Impl() const
2730 {
2731 	if ( xObjSh.Is() )
2732 		return xObjSh->GetMedium()->GetName();
2733 	return String();
2734 }
2735 
2736 void SfxViewFrame::SetModalMode( sal_Bool bModal )
2737 {
2738     pImp->bModal = bModal;
2739     if ( xObjSh.Is() )
2740     {
2741         for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh );
2742 			  !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) )
2743             bModal = pFrame->pImp->bModal;
2744         xObjSh->SetModalMode_Impl( bModal );
2745     }
2746 }
2747 
2748 sal_Bool SfxViewFrame::IsInModalMode() const
2749 {
2750     return pImp->bModal || GetFrame().GetWindow().IsInModalMode();
2751 }
2752 
2753 void SfxViewFrame::Resize( sal_Bool bForce )
2754 {
2755     Size aSize = GetWindow().GetOutputSizePixel();
2756     if ( bForce || aSize != pImp->aSize )
2757     {
2758         pImp->aSize = aSize;
2759         SfxViewShell *pShell = GetViewShell();
2760         if ( pShell )
2761         {
2762             if ( GetFrame().IsInPlace() )
2763             {
2764                 Point aPoint = GetWindow().GetPosPixel();
2765                 DoAdjustPosSizePixel( pShell, aPoint, aSize );
2766             }
2767             else
2768             {
2769                 DoAdjustPosSizePixel( pShell, Point(), aSize );
2770             }
2771         }
2772     }
2773 }
2774 
2775 #define LINE_SEP 0x0A
2776 
2777 void CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, sal_Bool bEraseTrailingEmptyLines )
2778 {
2779 	sal_Int32 nStartPos = 0;
2780 	sal_Int32 nEndPos = 0;
2781 	sal_Int32 nLine = 0;
2782 	while ( nLine < nStartLine )
2783 	{
2784         nStartPos = rStr.indexOf( LINE_SEP, nStartPos );
2785         if( nStartPos == -1 )
2786             break;
2787 		nStartPos++;	// nicht das \n.
2788 		nLine++;
2789 	}
2790 
2791 	DBG_ASSERTWARNING( nStartPos != STRING_NOTFOUND, "CutLines: Startzeile nicht gefunden!" );
2792 
2793 	if ( nStartPos != -1 )
2794 	{
2795 		nEndPos = nStartPos;
2796 		for ( sal_Int32 i = 0; i < nLines; i++ )
2797 			nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 );
2798 
2799 		if ( nEndPos == -1 ) // kann bei letzter Zeile passieren
2800 			nEndPos = rStr.getLength();
2801         else
2802 			nEndPos++;
2803 
2804         ::rtl::OUString aEndStr = rStr.copy( nEndPos );
2805         rStr = rStr.copy( 0, nStartPos );
2806         rStr += aEndStr;
2807 	}
2808 	if ( bEraseTrailingEmptyLines )
2809 	{
2810 		sal_Int32 n = nStartPos;
2811 		sal_Int32 nLen = rStr.getLength();
2812 		while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ) )
2813 			n++;
2814 
2815 		if ( n > nStartPos )
2816         {
2817             ::rtl::OUString aEndStr = rStr.copy( n );
2818             rStr = rStr.copy( 0, nStartPos );
2819             rStr += aEndStr;
2820         }
2821 	}
2822 }
2823 
2824 /*
2825     add new recorded dispatch macro script into the application global basic lib container
2826     It generates a new unique id for it and insert the macro by using this number as name for
2827     the modul
2828  */
2829 void SfxViewFrame::AddDispatchMacroToBasic_Impl( const ::rtl::OUString& sMacro )
2830 {
2831     /*
2832     // get lib and modul name from dialog
2833     SfxModule *pMod = GetObjectShell()->GetModule();
2834     SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pMod->GetPool() );
2835     const SfxPoolItem* pRet = pMod->ExecuteSlot( aReq );
2836     if ( pRet )
2837         ::rtl::OUString = ((SfxStringItem*)pRet)->GetValue();
2838     */
2839     if ( !sMacro.getLength() )
2840         return;
2841 
2842     SfxApplication* pSfxApp = SFX_APP();
2843     SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pSfxApp->GetPool() );
2844     aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,sal_True) );
2845     const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot( aReq );
2846     String aScriptURL;
2847     if ( pRet )
2848         aScriptURL = ((SfxStringItem*)pRet)->GetValue();
2849     if ( aScriptURL.Len() )
2850     {
2851         // parse scriptURL
2852         String aLibName;
2853         String aModuleName;
2854         String aMacroName;
2855         String aLocation;
2856         Reference< XMultiServiceFactory > xSMgr = ::comphelper::getProcessServiceFactory();
2857         Reference< com::sun::star::uri::XUriReferenceFactory > xFactory( xSMgr->createInstance(
2858             ::rtl::OUString::createFromAscii( "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY );
2859         if ( xFactory.is() )
2860         {
2861             Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY );
2862             if ( xUrl.is() )
2863             {
2864                 // get name
2865                 ::rtl::OUString aName = xUrl->getName();
2866                 sal_Unicode cTok = '.';
2867                 sal_Int32 nIndex = 0;
2868                 aLibName = aName.getToken( 0, cTok, nIndex );
2869                 if ( nIndex != -1 )
2870                     aModuleName = aName.getToken( 0, cTok, nIndex );
2871                 if ( nIndex != -1 )
2872                     aMacroName = aName.getToken( 0, cTok, nIndex );
2873 
2874                 // get location
2875                 ::rtl::OUString aLocKey = ::rtl::OUString::createFromAscii( "location" );
2876                 if ( xUrl->hasParameter( aLocKey ) )
2877                     aLocation = xUrl->getParameter( aLocKey );
2878             }
2879         }
2880 
2881 		BasicManager* pBasMgr = 0;
2882         if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
2883         {
2884 			// application basic
2885 			pBasMgr = pSfxApp->GetBasicManager();
2886 		}
2887         else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
2888         {
2889             pBasMgr = GetObjectShell()->GetBasicManager();
2890 		}
2891 
2892         ::rtl::OUString aOUSource;
2893         if ( pBasMgr)
2894 		{
2895 			StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
2896 			if ( pBasic )
2897 			{
2898 				SbModule* pModule = pBasic->FindModule( aModuleName );
2899 				if ( pModule )
2900 				{
2901                     SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD );
2902                     aOUSource = pModule->GetSource32();
2903                     sal_uInt16 nStart, nEnd;
2904                     pMethod->GetLineRange( nStart, nEnd );
2905                     sal_uIntPtr nlStart = nStart;
2906                     sal_uIntPtr nlEnd = nEnd;
2907                     CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, sal_True );
2908 				}
2909 			}
2910 		}
2911 
2912         // open lib container and break operation if it couldn't be opened
2913         com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont;
2914         if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
2915         {
2916             xLibCont = SFX_APP()->GetBasicContainer();
2917 		}
2918         else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
2919         {
2920             xLibCont = GetObjectShell()->GetBasicContainer();
2921 		}
2922 
2923         if(!xLibCont.is())
2924         {
2925             DBG_ERRORFILE("couldn't get access to the basic lib container. Adding of macro isn't possible.");
2926             return;
2927         }
2928 
2929         // get LibraryContainer
2930         com::sun::star::uno::Any aTemp;
2931         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot(
2932                 xLibCont,
2933                 com::sun::star::uno::UNO_QUERY);
2934 
2935         ::rtl::OUString sLib( aLibName );
2936         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib;
2937         if(xRoot->hasByName(sLib))
2938         {
2939             // library must be loaded
2940             aTemp = xRoot->getByName(sLib);
2941             xLibCont->loadLibrary(sLib);
2942             aTemp >>= xLib;
2943         }
2944         else
2945         {
2946             xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >(
2947                         xLibCont->createLibrary(sLib),
2948                         com::sun::star::uno::UNO_QUERY);
2949         }
2950 
2951         // pack the macro as direct usable "sub" routine
2952         ::rtl::OUString sCode;
2953         ::rtl::OUStringBuffer sRoutine(10000);
2954         ::rtl::OUString sMacroName( aMacroName );
2955         sal_Bool bReplace = sal_False;
2956 
2957         // get module
2958         ::rtl::OUString sModule( aModuleName );
2959         if(xLib->hasByName(sModule))
2960         {
2961             if ( aOUSource.getLength() )
2962             {
2963                 sRoutine.append( aOUSource );
2964             }
2965             else
2966             {
2967                 aTemp = xLib->getByName(sModule);
2968                 aTemp >>= sCode;
2969                 sRoutine.append( sCode );
2970             }
2971 
2972             bReplace = sal_True;
2973         }
2974 
2975         // append new method
2976         sRoutine.appendAscii("\nsub "     );
2977         sRoutine.append     (sMacroName   );
2978         sRoutine.appendAscii("\n"         );
2979         sRoutine.append     (sMacro       );
2980         sRoutine.appendAscii("\nend sub\n");
2981 
2982         // create the modul inside the library and insert the macro routine
2983         aTemp <<= sRoutine.makeStringAndClear();
2984         if ( bReplace )
2985         {
2986             com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
2987                 xLib,
2988                 com::sun::star::uno::UNO_QUERY);
2989             xModulCont->replaceByName(sModule,aTemp);
2990         }
2991         else
2992         {
2993             com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
2994                 xLib,
2995                 com::sun::star::uno::UNO_QUERY);
2996             xModulCont->insertByName(sModule,aTemp);
2997         }
2998 
2999         // #i17355# update the Basic IDE
3000         for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) )
3001         {
3002             if ( pViewShell->GetName().EqualsAscii( "BasicIDE" ) )
3003             {
3004                 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
3005                 SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
3006                 if ( pDispat )
3007                 {
3008                     SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, String(), String() );
3009                     pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L );
3010                 }
3011             }
3012         }
3013     }
3014     else
3015     {
3016         // add code for "session only" macro
3017     }
3018 }
3019 
3020 void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
3021 {
3022 	DBG_MEMTEST();
3023 	switch ( rReq.GetSlot() )
3024 	{
3025         case SID_STOP_RECORDING :
3026         case SID_RECORDMACRO :
3027         {
3028             // try to find any active recorder on this frame
3029             ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
3030             com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
3031                     GetFrame().GetFrameInterface(),
3032                     com::sun::star::uno::UNO_QUERY);
3033 
3034             com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY);
3035             com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
3036             com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
3037             aProp >>= xSupplier;
3038             com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
3039             if (xSupplier.is())
3040                 xRecorder = xSupplier->getDispatchRecorder();
3041 
3042             sal_Bool bIsRecording = xRecorder.is();
3043             SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, sal_False);
3044             if ( pItem && pItem->GetValue() == bIsRecording )
3045                 return;
3046 
3047             if ( xRecorder.is() )
3048             {
3049                 // disable active recording
3050                 aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >();
3051                 xSet->setPropertyValue(sProperty,aProp);
3052 
3053                 SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, sal_False);
3054                 if ( !pRecordItem || !pRecordItem->GetValue() )
3055                     // insert script into basic library container of application
3056                     AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro());
3057 
3058                 xRecorder->endRecording();
3059                 xRecorder = NULL;
3060 				GetBindings().SetRecorder_Impl( xRecorder );
3061 
3062                 SetChildWindow( SID_RECORDING_FLOATWINDOW, sal_False );
3063                 if ( rReq.GetSlot() != SID_RECORDMACRO )
3064                     GetBindings().Invalidate( SID_RECORDMACRO );
3065             }
3066             else if ( rReq.GetSlot() == SID_RECORDMACRO )
3067             {
3068                 // enable recording
3069                 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory(
3070                         ::comphelper::getProcessServiceFactory(),
3071                         com::sun::star::uno::UNO_QUERY);
3072 
3073                 xRecorder = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >(
3074                         xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorder")),
3075                         com::sun::star::uno::UNO_QUERY);
3076 
3077                 xSupplier = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >(
3078                         xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorderSupplier")),
3079                         com::sun::star::uno::UNO_QUERY);
3080 
3081                 xSupplier->setDispatchRecorder(xRecorder);
3082                 xRecorder->startRecording(xFrame);
3083                 aProp <<= xSupplier;
3084                 xSet->setPropertyValue(sProperty,aProp);
3085 				GetBindings().SetRecorder_Impl( xRecorder );
3086                 SetChildWindow( SID_RECORDING_FLOATWINDOW, sal_True );
3087             }
3088 
3089             rReq.Done();
3090             break;
3091         }
3092 
3093 		case SID_TOGGLESTATUSBAR:
3094 		{
3095             com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
3096                     GetFrame().GetFrameInterface(),
3097                     com::sun::star::uno::UNO_QUERY);
3098 
3099 	        Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
3100             Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
3101 	        if ( xPropSet.is() )
3102 	        {
3103 		        try
3104 		        {
3105 			        Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
3106 			        aValue >>= xLayoutManager;
3107                 }
3108                 catch ( Exception& )
3109                 {
3110                 }
3111             }
3112 
3113             if ( xLayoutManager.is() )
3114             {
3115                 rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ));
3116                 // Parameter auswerten
3117 			    SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), sal_False);
3118                 sal_Bool bShow( sal_True );
3119                 if ( !pShowItem )
3120                     bShow = xLayoutManager->isElementVisible( aStatusbarResString );
3121                 else
3122                     bShow = pShowItem->GetValue();
3123 
3124                 if ( bShow )
3125                 {
3126                     xLayoutManager->createElement( aStatusbarResString );
3127                     xLayoutManager->showElement( aStatusbarResString );
3128                 }
3129                 else
3130                     xLayoutManager->hideElement( aStatusbarResString );
3131 
3132                 if ( !pShowItem )
3133 				    rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) );
3134             }
3135 			rReq.Done();
3136 			break;
3137 		}
3138 
3139 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3140 		case SID_WIN_FULLSCREEN:
3141 		{
3142             SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), sal_False);
3143             SfxViewFrame *pTop = GetTopViewFrame();
3144             if ( pTop )
3145             {
3146                 WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
3147                 if ( pWork )
3148                 {
3149                     com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
3150                             GetFrame().GetFrameInterface(),
3151                             com::sun::star::uno::UNO_QUERY);
3152 
3153                     Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
3154                     Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
3155 	                if ( xPropSet.is() )
3156 	                {
3157 		                try
3158 		                {
3159 			                Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
3160 			                aValue >>= xLayoutManager;
3161                         }
3162                         catch ( Exception& )
3163                         {
3164                         }
3165                     }
3166 
3167                     sal_Bool bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode();
3168 					if ( bNewFullScreenMode != pWork->IsFullScreenMode() )
3169 					{
3170                         Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY );
3171                         if ( xLMPropSet.is() )
3172                         {
3173                             try
3174                             {
3175                                 xLMPropSet->setPropertyValue(
3176                                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HideCurrentUI" )),
3177                                     makeAny( bNewFullScreenMode ));
3178                             }
3179                             catch ( ::com::sun::star::beans::UnknownPropertyException& )
3180                             {
3181                             }
3182                         }
3183 	                    pWork->ShowFullScreenMode( bNewFullScreenMode );
3184 	                    pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL );
3185 	                    GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode );
3186 	                    if ( !pItem )
3187 	                        rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) );
3188 	                    rReq.Done();
3189 					}
3190 					else
3191 						rReq.Ignore();
3192                 }
3193             }
3194             else
3195                 rReq.Ignore();
3196 
3197             GetDispatcher()->Update_Impl( sal_True );
3198 			break;
3199 		}
3200 	}
3201 }
3202 
3203 void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet)
3204 {
3205 	DBG_MEMTEST();
3206 
3207 	const sal_uInt16 *pRanges = rSet.GetRanges();
3208 	DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
3209 	while ( *pRanges )
3210 	{
3211 		for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
3212 		{
3213 			switch(nWhich)
3214 			{
3215                 case SID_CURRENT_URL:
3216                 {
3217                     // Bei internem InPlace den ContainerFrame nehmen
3218                     SfxViewFrame *pFrame = this;
3219                     if ( pFrame->GetParentViewFrame_Impl() )
3220                         pFrame = pFrame->GetParentViewFrame_Impl();
3221                     rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) );
3222 	                break;
3223                 }
3224 
3225                 case SID_RECORDMACRO :
3226                 {
3227 					const char* pName = GetObjectShell()->GetFactory().GetShortName();
3228 					if (  strcmp(pName,"swriter") && strcmp(pName,"scalc") )
3229 					{
3230                         rSet.DisableItem( nWhich );
3231 						break;
3232 					}
3233 
3234                     ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
3235                     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3236                             GetFrame().GetFrameInterface(),
3237                             com::sun::star::uno::UNO_QUERY);
3238 
3239                     com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
3240                     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
3241                     if ( aProp >>= xSupplier )
3242                         rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) );
3243                     else
3244                         rSet.DisableItem( nWhich );
3245                     break;
3246                 }
3247 
3248                 case SID_STOP_RECORDING :
3249                 {
3250 					const char* pName = GetObjectShell()->GetFactory().GetShortName();
3251 					if (  strcmp(pName,"swriter") && strcmp(pName,"scalc") )
3252 					{
3253                         rSet.DisableItem( nWhich );
3254 						break;
3255 					}
3256 
3257                     ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
3258                     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3259                             GetFrame().GetFrameInterface(),
3260                             com::sun::star::uno::UNO_QUERY);
3261 
3262                     com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
3263                     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
3264                     if ( !(aProp >>= xSupplier) || !xSupplier.is() )
3265                         rSet.DisableItem( nWhich );
3266                     break;
3267                 }
3268 
3269 				case SID_TOGGLESTATUSBAR:
3270 				{
3271                     com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
3272                     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3273                             GetFrame().GetFrameInterface(),
3274                             com::sun::star::uno::UNO_QUERY);
3275                     com::sun::star::uno::Any aProp = xSet->getPropertyValue(
3276                         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )) );
3277 
3278 			        if ( !( aProp >>= xLayoutManager ))
3279                         rSet.Put( SfxBoolItem( nWhich, sal_False ));
3280                     else
3281                     {
3282                         rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ));
3283                         sal_Bool bShow = xLayoutManager->isElementVisible( aStatusbarResString );
3284                         rSet.Put( SfxBoolItem( nWhich, bShow ));
3285                     }
3286 					break;
3287 				}
3288 
3289 				case SID_WIN_FULLSCREEN:
3290                 {
3291                     SfxViewFrame* pTop = GetTopViewFrame();
3292                     if ( pTop )
3293                     {
3294                         WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
3295                         if ( pWork )
3296                         {
3297                             rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) );
3298                             break;
3299                         }
3300                     }
3301 
3302                     rSet.DisableItem( nWhich );
3303 					break;
3304                 }
3305 
3306                 case SID_FORMATMENUSTATE :
3307                 {
3308                     DBG_ERROR("Outdated slot!");
3309                     rSet.DisableItem( nWhich );
3310                     break;
3311                 }
3312 
3313 				default:
3314 					//! DBG_ASSERT(FALSE, "Falscher Server fuer GetState");
3315 					break;
3316 			}
3317 		}
3318 
3319 		++pRanges;
3320 	}
3321 }
3322 
3323 void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq )
3324 
3325 /* 	[Beschreibung]
3326 
3327 	Diese Methode kann in der Execute-Methode f"ur das ein- und ausschalten
3328 	von Child-Windows eingesetzt werden, um dieses inkl. API-Anbindung zu
3329 	implementieren.
3330 
3331 	Einfach in der IDL als 'ExecuteMethod' eintragen.
3332 */
3333 
3334 {
3335 	// Parameter auswerten
3336 	sal_uInt16 nSID = rReq.GetSlot();
3337 
3338 	SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, sal_False);
3339     if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
3340     {
3341         if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
3342             return;
3343         Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface();
3344         Reference < XFrame > xBeamer( xFrame->findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ) );
3345         sal_Bool bShow = sal_False;
3346         sal_Bool bHasChild = xBeamer.is();
3347         bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
3348         if ( pShowItem )
3349         {
3350             if( bShow == bHasChild )
3351                 return;
3352         }
3353         else
3354             rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
3355 
3356         if ( !bShow )
3357         {
3358             SetChildWindow( SID_BROWSER, sal_False );
3359         }
3360         else
3361         {
3362             ::com::sun::star::util::URL aTargetURL;
3363             aTargetURL.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser");
3364             Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
3365             xTrans->parseStrict( aTargetURL );
3366 
3367             Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
3368             Reference < ::com::sun::star::frame::XDispatch > xDisp;
3369             if ( xProv.is() )
3370                 xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_beamer"), 31 );
3371             if ( xDisp.is() )
3372             {
3373                 Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
3374                 ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray();
3375                 pArg[0].Name = rtl::OUString::createFromAscii("Referer");
3376                 pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user");
3377                 xDisp->dispatch( aTargetURL, aArgs );
3378             }
3379         }
3380 
3381         rReq.Done();
3382         return;
3383     }
3384 
3385 	sal_Bool bShow = sal_False;
3386 	sal_Bool bHasChild = HasChildWindow(nSID);
3387 	bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
3388 	// IAccessibility2 implementation 2009. ------
3389     GetDispatcher()->Update_Impl( sal_True );
3390 
3391 	// ausf"uhren
3392 	if ( !pShowItem || bShow != bHasChild )
3393 		ToggleChildWindow( nSID );
3394 
3395 	GetBindings().Invalidate( nSID );
3396 	// Move to the before show()
3397     //GetDispatcher()->Update_Impl( sal_True );
3398 	// ------ IAccessibility2 implementation 2009.
3399 
3400 	// ggf. recorden
3401     if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG )
3402     {
3403         rReq.Ignore();
3404     }
3405     else
3406     {
3407         rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
3408         rReq.Done();
3409     }
3410 }
3411 
3412 //--------------------------------------------------------------------
3413 
3414 void SfxViewFrame::ChildWindowState( SfxItemSet& rState )
3415 
3416 /* 	[Beschreibung]
3417 
3418 	Diese Methode kann in der Status-Methode f"ur das Ein- und Ausschalt-
3419 	Zustand von Child-Windows eingesetzt werden, um dieses zu implementieren.
3420 
3421 	Einfach in der IDL als 'StateMethod' eintragen.
3422 */
3423 
3424 {
3425 	SfxWhichIter aIter( rState );
3426 	for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
3427 	{
3428         if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
3429         {
3430             rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) );
3431         }
3432         else if ( nSID == SID_HYPERLINK_DIALOG )
3433 		{
3434 			const SfxPoolItem* pDummy = NULL;
3435             SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy );
3436 			if ( SFX_ITEM_DISABLED == eState )
3437 				rState.DisableItem(nSID);
3438 			else
3439 			{
3440 				if ( KnowsChildWindow(nSID) )
3441 					rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) );
3442 				else
3443 					rState.DisableItem(nSID);
3444 			}
3445 		}
3446         else if ( nSID == SID_BROWSER )
3447 		{
3448 			Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()->
3449 							findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN );
3450 			if ( !xFrame.is() )
3451 				rState.DisableItem( nSID );
3452 			else if ( KnowsChildWindow(nSID) )
3453 				rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
3454 		}
3455         else if ( nSID == SID_TASKPANE )
3456         {
3457             if  ( !KnowsChildWindow( nSID ) )
3458             {
3459                 OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
3460 			    rState.DisableItem( nSID );
3461             }
3462             else if ( !moduleHasToolPanels( *pImp ) )
3463             {
3464                 rState.Put( SfxVisibilityItem( nSID, sal_False ) );
3465             }
3466             else
3467             {
3468 			    rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
3469             }
3470         }
3471         else if ( nSID == SID_SIDEBAR )
3472         {
3473             if  ( !KnowsChildWindow( nSID ) )
3474             {
3475                 OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
3476 			    rState.DisableItem( nSID );
3477             }
3478             else
3479             {
3480 			    rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
3481             }
3482         }
3483 		else if ( KnowsChildWindow(nSID) )
3484 			rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
3485 		else
3486 			rState.DisableItem(nSID);
3487 	}
3488 }
3489 
3490 //--------------------------------------------------------------------
3491 SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( sal_uInt16 /*nId*/ )
3492 {
3493     SfxWorkWindow* pWork = 0;
3494     pWork = GetFrame().GetWorkWindow_Impl();
3495     return pWork;
3496 }
3497 
3498 /*
3499 void SfxViewFrame::SetChildWindow(sal_uInt16 nId, sal_Bool bOn)
3500 {
3501     SetChildWindow( nId, bOn, sal_True );
3502 }*/
3503 
3504 void SfxViewFrame::SetChildWindow(sal_uInt16 nId, sal_Bool bOn, sal_Bool bSetFocus )
3505 {
3506     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3507     if ( pWork )
3508         pWork->SetChildWindow_Impl( nId, bOn, bSetFocus );
3509 }
3510 
3511 //--------------------------------------------------------------------
3512 
3513 void SfxViewFrame::ToggleChildWindow(sal_uInt16 nId)
3514 {
3515     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3516     if ( pWork )
3517         pWork->ToggleChildWindow_Impl( nId, sal_True );
3518 }
3519 
3520 //--------------------------------------------------------------------
3521 
3522 sal_Bool SfxViewFrame::HasChildWindow( sal_uInt16 nId )
3523 {
3524 	SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3525 	return pWork ? pWork->HasChildWindow_Impl(nId) : sal_False;
3526 }
3527 
3528 //--------------------------------------------------------------------
3529 
3530 sal_Bool SfxViewFrame::KnowsChildWindow( sal_uInt16 nId )
3531 {
3532     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3533 	return pWork ? pWork->KnowsChildWindow_Impl(nId) : sal_False;
3534 }
3535 
3536 //--------------------------------------------------------------------
3537 
3538 void SfxViewFrame::ShowChildWindow( sal_uInt16 nId, sal_Bool bVisible )
3539 {
3540     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3541     if ( pWork )
3542     {
3543         GetDispatcher()->Update_Impl(sal_True);
3544         pWork->ShowChildWindow_Impl(nId, bVisible, sal_True );
3545     }
3546 }
3547 
3548 //--------------------------------------------------------------------
3549 
3550 SfxChildWindow* SfxViewFrame::GetChildWindow(sal_uInt16 nId)
3551 {
3552     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3553 	return pWork ? pWork->GetChildWindow_Impl(nId) : NULL;
3554 }
3555 
3556 void SfxViewFrame::UpdateDocument_Impl()
3557 {
3558     SfxObjectShell* pDoc = GetObjectShell();
3559 	if ( pDoc->IsLoadingFinished() )
3560         pDoc->CheckSecurityOnLoading_Impl();
3561 
3562 	// check if document depends on a template
3563     pDoc->UpdateFromTemplate_Impl();
3564 }
3565 
3566 void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
3567 {
3568     SFX_APP()->SetViewFrame_Impl( pFrame );
3569 }
3570 
3571 // ---------------------------------------------------------------------------------------------------------------------
3572 void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const ::rtl::OUString& i_rPanelURL )
3573 {
3574 	::vos::OGuard aGuard( Application::GetSolarMutex() );
3575 
3576     // look up the SfxFrame for the given XFrame
3577     SfxFrame* pFrame = NULL;
3578     for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
3579     {
3580         if ( pFrame->GetFrameInterface() == i_rFrame )
3581             break;
3582     }
3583     SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL;
3584     ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" );
3585 
3586     pViewFrame->ActivateToolPanel_Impl( i_rPanelURL );
3587 }
3588 
3589 // ---------------------------------------------------------------------------------------------------------------------
3590 void SfxViewFrame::ActivateToolPanel_Impl( const ::rtl::OUString& i_rPanelURL )
3591 {
3592     // ensure the task pane is visible
3593     ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" );
3594     if ( !HasChildWindow( SID_TASKPANE ) )
3595         ToggleChildWindow( SID_TASKPANE );
3596 
3597     SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE );
3598     ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" );
3599 
3600     ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow );
3601     ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" );
3602     pPanelAccess->ActivateToolPanel( i_rPanelURL );
3603 }
3604