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