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
);
210 const SfxViewFrameItem
* pItem
= dynamic_cast<const SfxViewFrameItem
*>( aReq
.GetReturnValue() );
212 rReq
.SetReturnValue( SfxFrameItem( 0, pItem
->GetFrame() ) );
218 // disable CloseWin, if frame is not a task
219 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
223 if ( GetViewShell()->PrepareClose() )
225 // More Views on the same Document?
226 SfxObjectShell
*pDocSh
= GetObjectShell();
228 for ( const SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pDocSh
);
230 pFrame
= SfxViewFrame::GetNext( *pFrame
, pDocSh
) )
231 bOther
= (pFrame
!= this);
233 // Document only needs to be queried, if no other View present.
234 bool bClosed
= false;
235 if ( bOther
|| pDocSh
->PrepareClose( true/*bUI*/ ) )
238 pDocSh
->SetModified( false );
239 rReq
.Done(); // Must call this before Close()!
246 catch (css::lang::DisposedException
&) {
247 // already closed; ignore
249 catch( CloseVetoException
& )
255 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bClosed
));
264 void SfxViewFrame::GetState_Impl( SfxItemSet
&rSet
)
266 SfxObjectShell
*pDocSh
= GetObjectShell();
271 const WhichRangesContainer
& pRanges
= rSet
.GetRanges();
272 DBG_ASSERT(!pRanges
.empty(), "Set without Range");
273 for ( auto const & pRange
: pRanges
)
275 for ( sal_uInt16 nWhich
= pRange
.first
; nWhich
<= pRange
.second
; ++nWhich
)
279 case SID_NEWDOCDIRECT
:
281 if ( !m_pImpl
->aFactoryName
.isEmpty() )
283 rSet
.Put( SfxStringItem( nWhich
, "private:factory/"+m_pImpl
->aFactoryName
) );
289 rSet
.DisableItem(nWhich
);
294 // disable CloseWin, if frame is not a task
295 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
297 rSet
.DisableItem(nWhich
);
301 case SID_SHOWPOPUPS
:
305 if ( GetViewShell() && GetViewShell()->GetVerbs().hasElements() && !GetObjectShell()->IsInPlaceActive() )
307 uno::Any
aAny(GetViewShell()->GetVerbs());
308 rSet
.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT
), aAny
) );
311 rSet
.DisableItem( SID_OBJECT
);
315 OSL_FAIL( "invalid message-id" );
321 void SfxViewFrame::INetExecute_Impl( SfxRequest
&rRequest
)
323 sal_uInt16 nSlotId
= rRequest
.GetSlot();
326 case SID_BROWSE_FORWARD
:
327 case SID_BROWSE_BACKWARD
:
328 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
332 /*! (pb) we need new implementation to create a link
336 case SID_FOCUSURLBOX
:
338 SfxStateCache
*pCache
= GetBindings().GetAnyStateCache_Impl( SID_OPENURL
);
341 SfxControllerItem
* pCtrl
= pCache
->GetItemLink();
344 pCtrl
->StateChangedAtToolBoxControl( SID_FOCUSURLBOX
, SfxItemState::UNKNOWN
, nullptr );
345 pCtrl
= pCtrl
->GetItemLink();
355 void SfxViewFrame::INetState_Impl( SfxItemSet
&rItemSet
)
357 rItemSet
.DisableItem( SID_BROWSE_FORWARD
);
358 rItemSet
.DisableItem( SID_BROWSE_BACKWARD
);
360 // Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
361 SfxObjectShell
*pDocSh
= GetObjectShell();
362 bool bEmbedded
= pDocSh
&& pDocSh
->GetCreateMode() == SfxObjectCreateMode::EMBEDDED
;
363 if ( !pDocSh
|| bEmbedded
|| !pDocSh
->HasName() )
364 rItemSet
.DisableItem( SID_CREATELINK
);
367 void SfxViewFrame::Activate( bool /*bMDI*/ )
369 DBG_ASSERT(GetViewShell(), "No Shell");
370 //(mba): here maybe as in Beanframe NotifyEvent ?!
373 void SfxViewFrame::Deactivate( bool /*bMDI*/ )
375 DBG_ASSERT(GetViewShell(), "No Shell");
376 //(mba): here maybe as in Beanframe NotifyEvent ?!
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */