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
;
53 void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange
)
55 if ( nStateChange
== StateChangedType::InitShow
)
57 SfxObjectShell
* pDoc
= pFrame
->GetObjectShell();
58 if ( pDoc
&& !pFrame
->IsVisible() )
64 Window::StateChanged( nStateChange
);
67 void SfxFrameViewWindow_Impl::Resize()
69 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
74 void SfxViewFrame::UpdateTitle()
78 With this method, can the SfxViewFrame be forced to immediately provide
79 the new title from the <SfxObjectShell>.
83 This is for example necessary if one listens to the SfxObjectShell as
84 SfxListener and then react on the <SfxSimpleHint> SfxHintId::TitleChanged,
85 then query the title of his views. However these views (SfxTopViewFrames)
86 are also SfxListener and because the order of notifications might not be
87 fixed, the title update will be enforced in advance.
91 void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
93 if ( dynamic_cast<const SfxSimpleHint *>(&rHint) != nullptr )
95 switch( ( (SfxSimpleHint&) rHint ).GetId() )
97 case SfxHintId::TitleChanged:
98 for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
100 pTop = SfxViewFrame::GetNext( this );
103 ... pTop->GetName() ...
114 const SfxObjectFactory
&rFact
= GetObjectShell()->GetFactory();
115 m_pImpl
->aFactoryName
= rFact
.GetFactoryName();
117 SfxObjectShell
*pObjSh
= GetObjectShell();
122 const SfxMedium
*pMedium
= pObjSh
->GetMedium();
124 GetFrame(); // -Wall required??
125 if ( pObjSh
->HasName() )
127 INetURLObject
aTmp( pMedium
->GetName() );
128 aURL
= aTmp
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DecodeMechanism::WithCharset
);
131 if ( aURL
!= m_pImpl
->aActualURL
)
133 m_pImpl
->aActualURL
= aURL
;
136 OUString aSbxName
= pObjSh
->SfxShell::GetName();
139 aSbxName
+= ":" + OUString::number(m_pImpl
->nDocViewNo
);
143 GetBindings().Invalidate( SID_CURRENT_URL
);
144 GetBindings().Invalidate( SID_NEWDOCDIRECT
);
147 void SfxViewFrame::Exec_Impl(SfxRequest
&rReq
)
149 // If presently the shells are replaced...
150 if ( !GetObjectShell() || !GetViewShell() )
153 switch ( rReq
.GetSlot() )
155 case SID_SHOWPOPUPS
:
157 const SfxBoolItem
* pShowItem
= rReq
.GetArg
<SfxBoolItem
>(SID_SHOWPOPUPS
);
158 bool bShow
= pShowItem
== nullptr || pShowItem
->GetValue();
160 SfxWorkWindow
*pWorkWin
= GetFrame().GetWorkWindow_Impl();
163 // First, make the floats viewable
164 pWorkWin
->MakeChildrenVisible_Impl(true);
165 GetDispatcher()->Update_Impl( true );
168 GetBindings().HidePopups(false);
172 pWorkWin
->HidePopups_Impl(true);
173 pWorkWin
->MakeChildrenVisible_Impl(false);
176 Invalidate( rReq
.GetSlot() );
183 MakeActive_Impl( true );
184 rReq
.SetReturnValue(SfxObjectItem(0, this));
188 case SID_NEWDOCDIRECT
:
190 const SfxStringItem
* pFactoryItem
= rReq
.GetArg
<SfxStringItem
>(SID_NEWDOCDIRECT
);
193 aFactName
= pFactoryItem
->GetValue();
194 else if ( !m_pImpl
->aFactoryName
.isEmpty() )
195 aFactName
= m_pImpl
->aFactoryName
;
198 SAL_WARN("sfx.view", "Missing argument!");
202 SfxRequest
aReq( SID_OPENDOC
, SfxCallMode::SYNCHRON
, GetPool() );
203 const OUString
aFact("private:factory/" + aFactName
);
204 aReq
.AppendItem( SfxStringItem( SID_FILE_NAME
, aFact
) );
205 aReq
.AppendItem( SfxFrameItem( SID_DOCFRAME
, &GetFrame() ) );
206 aReq
.AppendItem( SfxStringItem( SID_TARGETNAME
, u
"_blank"_ustr
) );
207 SfxGetpApp()->ExecuteSlot( aReq
);
209 const SfxViewFrameItem
* pItem(dynamic_cast<const SfxViewFrameItem
*>(aReq
.GetReturnValue().getItem()));
210 if (nullptr != pItem
)
211 rReq
.SetReturnValue(SfxFrameItem(0, pItem
->GetFrame()));
217 // disable CloseWin, if frame is not a task
218 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
222 if ( GetViewShell()->PrepareClose() )
224 // More Views on the same Document?
225 SfxObjectShell
*pDocSh
= GetObjectShell();
227 for ( const SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pDocSh
);
229 pFrame
= SfxViewFrame::GetNext( *pFrame
, pDocSh
) )
230 bOther
= (pFrame
!= this);
232 // Document only needs to be queried, if no other View present.
233 bool bClosed
= false;
234 if ( bOther
|| pDocSh
->PrepareClose( true/*bUI*/ ) )
237 pDocSh
->SetModified( false );
238 rReq
.Done(); // Must call this before Close()!
245 catch (css::lang::DisposedException
&) {
246 // already closed; ignore
248 catch( CloseVetoException
& )
254 rReq
.SetReturnValue(SfxBoolItem(rReq
.GetSlot(), bClosed
));
263 void SfxViewFrame::GetState_Impl( SfxItemSet
&rSet
)
265 SfxObjectShell
*pDocSh
= GetObjectShell();
270 const WhichRangesContainer
& pRanges
= rSet
.GetRanges();
271 DBG_ASSERT(!pRanges
.empty(), "Set without Range");
272 for ( auto const & pRange
: pRanges
)
274 for ( sal_uInt16 nWhich
= pRange
.first
; nWhich
<= pRange
.second
; ++nWhich
)
278 case SID_NEWDOCDIRECT
:
280 if ( !m_pImpl
->aFactoryName
.isEmpty() )
282 rSet
.Put( SfxStringItem( nWhich
, "private:factory/"+m_pImpl
->aFactoryName
) );
288 rSet
.DisableItem(nWhich
);
293 // disable CloseWin, if frame is not a task
294 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
296 rSet
.DisableItem(nWhich
);
300 case SID_SHOWPOPUPS
:
304 if ( GetViewShell() && GetViewShell()->GetVerbs().hasElements() && !GetObjectShell()->IsInPlaceActive() )
306 uno::Any
aAny(GetViewShell()->GetVerbs());
307 rSet
.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT
), aAny
) );
310 rSet
.DisableItem( SID_OBJECT
);
314 OSL_FAIL( "invalid message-id" );
320 void SfxViewFrame::INetExecute_Impl( SfxRequest
&rRequest
)
322 sal_uInt16 nSlotId
= rRequest
.GetSlot();
325 case SID_BROWSE_FORWARD
:
326 case SID_BROWSE_BACKWARD
:
327 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
331 /*! (pb) we need new implementation to create a link
335 case SID_FOCUSURLBOX
:
337 SfxStateCache
*pCache
= GetBindings().GetAnyStateCache_Impl( SID_OPENURL
);
340 SfxControllerItem
* pCtrl
= pCache
->GetItemLink();
343 pCtrl
->StateChangedAtToolBoxControl( SID_FOCUSURLBOX
, SfxItemState::UNKNOWN
, nullptr );
344 pCtrl
= pCtrl
->GetItemLink();
354 void SfxViewFrame::INetState_Impl( SfxItemSet
&rItemSet
)
356 rItemSet
.DisableItem( SID_BROWSE_FORWARD
);
357 rItemSet
.DisableItem( SID_BROWSE_BACKWARD
);
359 // Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
360 SfxObjectShell
*pDocSh
= GetObjectShell();
361 bool bEmbedded
= pDocSh
&& pDocSh
->GetCreateMode() == SfxObjectCreateMode::EMBEDDED
;
362 if ( !pDocSh
|| bEmbedded
|| !pDocSh
->HasName() )
363 rItemSet
.DisableItem( SID_CREATELINK
);
366 void SfxViewFrame::Activate( bool /*bMDI*/ )
368 DBG_ASSERT(GetViewShell(), "No Shell");
369 //(mba): here maybe as in Beanframe NotifyEvent ?!
372 void SfxViewFrame::Deactivate( bool /*bMDI*/ )
374 DBG_ASSERT(GetViewShell(), "No Shell");
375 //(mba): here maybe as in Beanframe NotifyEvent ?!
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */