1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "impviewframe.hxx"
22 #include <statcach.hxx>
23 #include <workwin.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/ctrlitem.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/docfac.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <sfx2/objitem.hxx>
32 #include <sfx2/objsh.hxx>
33 #include <sfx2/request.hxx>
34 #include <sfx2/sfxsids.hrc>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/viewsh.hxx>
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include <com/sun/star/util/CloseVetoException.hpp>
39 #include <com/sun/star/util/XCloseable.hpp>
40 #include <com/sun/star/embed/VerbDescriptor.hpp>
42 #include <osl/diagnose.h>
43 #include <svl/eitem.hxx>
44 #include <svl/stritem.hxx>
45 #include <tools/urlobj.hxx>
46 #include <sal/log.hxx>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::util
;
51 using namespace ::com::sun::star::container
;
52 using namespace ::com::sun::star::beans
;
55 void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange
)
57 if ( nStateChange
== StateChangedType::InitShow
)
59 SfxObjectShell
* pDoc
= pFrame
->GetObjectShell();
60 if ( pDoc
&& !pFrame
->IsVisible() )
66 Window::StateChanged( nStateChange
);
69 void SfxFrameViewWindow_Impl::Resize()
71 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
76 void SfxViewFrame::UpdateTitle()
80 With this method, can the SfxViewFrame be forced to immediately provide
81 the new title from the <SfxObjectShell>.
85 This is for example necessary if one listens to the SfxObjectShell as
86 SfxListener and then react on the <SfxSimpleHint> SfxHintId::TitleChanged,
87 then query the title of his views. However these views (SfxTopViewFrames)
88 are also SfxListener and because the order of notifications might not be
89 fixed, the title update will be enforced in advance.
93 void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
95 if ( dynamic_cast<const SfxSimpleHint *>(&rHint) != nullptr )
97 switch( ( (SfxSimpleHint&) rHint ).GetId() )
99 case SfxHintId::TitleChanged:
100 for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
102 pTop = SfxViewFrame::GetNext( this );
105 ... pTop->GetName() ...
116 const SfxObjectFactory
&rFact
= GetObjectShell()->GetFactory();
117 m_pImpl
->aFactoryName
= rFact
.GetFactoryName();
119 SfxObjectShell
*pObjSh
= GetObjectShell();
124 const SfxMedium
*pMedium
= pObjSh
->GetMedium();
126 GetFrame(); // -Wall required??
127 if ( pObjSh
->HasName() )
129 INetURLObject
aTmp( pMedium
->GetName() );
130 aURL
= aTmp
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DecodeMechanism::WithCharset
);
133 if ( aURL
!= m_pImpl
->aActualURL
)
135 m_pImpl
->aActualURL
= aURL
;
138 OUString aSbxName
= pObjSh
->SfxShell::GetName();
141 aSbxName
+= ":" + OUString::number(m_pImpl
->nDocViewNo
);
145 GetBindings().Invalidate( SID_CURRENT_URL
);
146 GetBindings().Invalidate( SID_NEWDOCDIRECT
);
149 void SfxViewFrame::Exec_Impl(SfxRequest
&rReq
)
151 // If presently the shells are replaced...
152 if ( !GetObjectShell() || !GetViewShell() )
155 switch ( rReq
.GetSlot() )
157 case SID_SHOWPOPUPS
:
159 const SfxBoolItem
* pShowItem
= rReq
.GetArg
<SfxBoolItem
>(SID_SHOWPOPUPS
);
160 bool bShow
= pShowItem
== nullptr || pShowItem
->GetValue();
162 SfxWorkWindow
*pWorkWin
= GetFrame().GetWorkWindow_Impl();
165 // First, make the floats viewable
166 pWorkWin
->MakeChildrenVisible_Impl(true);
167 GetDispatcher()->Update_Impl( true );
170 GetBindings().HidePopups(false);
174 pWorkWin
->HidePopups_Impl(true);
175 pWorkWin
->MakeChildrenVisible_Impl(false);
178 Invalidate( rReq
.GetSlot() );
185 MakeActive_Impl( true );
186 rReq
.SetReturnValue(SfxObjectItem(0, this));
190 case SID_NEWDOCDIRECT
:
192 const SfxStringItem
* pFactoryItem
= rReq
.GetArg
<SfxStringItem
>(SID_NEWDOCDIRECT
);
195 aFactName
= pFactoryItem
->GetValue();
196 else if ( !m_pImpl
->aFactoryName
.isEmpty() )
197 aFactName
= m_pImpl
->aFactoryName
;
200 SAL_WARN("sfx.view", "Missing argument!");
204 SfxRequest
aReq( SID_OPENDOC
, SfxCallMode::SYNCHRON
, GetPool() );
205 const OUString
aFact("private:factory/" + aFactName
);
206 aReq
.AppendItem( SfxStringItem( SID_FILE_NAME
, aFact
) );
207 aReq
.AppendItem( SfxFrameItem( SID_DOCFRAME
, &GetFrame() ) );
208 aReq
.AppendItem( SfxStringItem( SID_TARGETNAME
, "_blank" ) );
209 SfxGetpApp()->ExecuteSlot( aReq
);
211 const SfxViewFrameItem
* pItem(dynamic_cast<const SfxViewFrameItem
*>(aReq
.GetReturnValue().getItem()));
212 if (nullptr != pItem
)
213 rReq
.SetReturnValue(SfxFrameItem(0, pItem
->GetFrame()));
219 // disable CloseWin, if frame is not a task
220 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
224 if ( GetViewShell()->PrepareClose() )
226 // More Views on the same Document?
227 SfxObjectShell
*pDocSh
= GetObjectShell();
229 for ( const SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pDocSh
);
231 pFrame
= SfxViewFrame::GetNext( *pFrame
, pDocSh
) )
232 bOther
= (pFrame
!= this);
234 // Document only needs to be queried, if no other View present.
235 bool bClosed
= false;
236 if ( bOther
|| pDocSh
->PrepareClose( true/*bUI*/ ) )
239 pDocSh
->SetModified( false );
240 rReq
.Done(); // Must call this before Close()!
247 catch (css::lang::DisposedException
&) {
248 // already closed; ignore
250 catch( CloseVetoException
& )
256 rReq
.SetReturnValue(SfxBoolItem(rReq
.GetSlot(), bClosed
));
265 void SfxViewFrame::GetState_Impl( SfxItemSet
&rSet
)
267 SfxObjectShell
*pDocSh
= GetObjectShell();
272 const WhichRangesContainer
& pRanges
= rSet
.GetRanges();
273 DBG_ASSERT(!pRanges
.empty(), "Set without Range");
274 for ( auto const & pRange
: pRanges
)
276 for ( sal_uInt16 nWhich
= pRange
.first
; nWhich
<= pRange
.second
; ++nWhich
)
280 case SID_NEWDOCDIRECT
:
282 if ( !m_pImpl
->aFactoryName
.isEmpty() )
284 rSet
.Put( SfxStringItem( nWhich
, "private:factory/"+m_pImpl
->aFactoryName
) );
290 rSet
.DisableItem(nWhich
);
295 // disable CloseWin, if frame is not a task
296 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
298 rSet
.DisableItem(nWhich
);
302 case SID_SHOWPOPUPS
:
306 if ( GetViewShell() && GetViewShell()->GetVerbs().hasElements() && !GetObjectShell()->IsInPlaceActive() )
308 uno::Any
aAny(GetViewShell()->GetVerbs());
309 rSet
.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT
), aAny
) );
312 rSet
.DisableItem( SID_OBJECT
);
316 OSL_FAIL( "invalid message-id" );
322 void SfxViewFrame::INetExecute_Impl( SfxRequest
&rRequest
)
324 sal_uInt16 nSlotId
= rRequest
.GetSlot();
327 case SID_BROWSE_FORWARD
:
328 case SID_BROWSE_BACKWARD
:
329 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
333 /*! (pb) we need new implementation to create a link
337 case SID_FOCUSURLBOX
:
339 SfxStateCache
*pCache
= GetBindings().GetAnyStateCache_Impl( SID_OPENURL
);
342 SfxControllerItem
* pCtrl
= pCache
->GetItemLink();
345 pCtrl
->StateChangedAtToolBoxControl( SID_FOCUSURLBOX
, SfxItemState::UNKNOWN
, nullptr );
346 pCtrl
= pCtrl
->GetItemLink();
356 void SfxViewFrame::INetState_Impl( SfxItemSet
&rItemSet
)
358 rItemSet
.DisableItem( SID_BROWSE_FORWARD
);
359 rItemSet
.DisableItem( SID_BROWSE_BACKWARD
);
361 // Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
362 SfxObjectShell
*pDocSh
= GetObjectShell();
363 bool bEmbedded
= pDocSh
&& pDocSh
->GetCreateMode() == SfxObjectCreateMode::EMBEDDED
;
364 if ( !pDocSh
|| bEmbedded
|| !pDocSh
->HasName() )
365 rItemSet
.DisableItem( SID_CREATELINK
);
368 void SfxViewFrame::Activate( bool /*bMDI*/ )
370 DBG_ASSERT(GetViewShell(), "No Shell");
371 //(mba): here maybe as in Beanframe NotifyEvent ?!
374 void SfxViewFrame::Deactivate( bool /*bMDI*/ )
376 DBG_ASSERT(GetViewShell(), "No Shell");
377 //(mba): here maybe as in Beanframe NotifyEvent ?!
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */