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