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 <sfx2/viewfac.hxx>
24 #include "workwin.hxx"
26 #include <sfx2/app.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/ctrlitem.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/docfac.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/objitem.hxx>
33 #include <sfx2/objsh.hxx>
34 #include <sfx2/request.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/viewsh.hxx>
38 #include <com/sun/star/util/XCloseable.hpp>
40 #include <svtools/asynclink.hxx>
41 #include <svl/eitem.hxx>
42 #include <svl/intitem.hxx>
43 #include <svl/rectitem.hxx>
44 #include <svl/stritem.hxx>
45 #include <tools/diagnose_ex.h>
46 #include <tools/urlobj.hxx>
47 #include <vcl/window.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::frame
;
52 using namespace ::com::sun::star::util
;
53 using namespace ::com::sun::star::container
;
54 using namespace ::com::sun::star::beans
;
57 void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange
)
59 if ( nStateChange
== StateChangedType::InitShow
)
61 SfxObjectShell
* pDoc
= pFrame
->GetObjectShell();
62 if ( pDoc
&& !pFrame
->IsVisible() )
68 Window::StateChanged( nStateChange
);
71 void SfxFrameViewWindow_Impl::Resize()
73 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
78 void SfxViewFrame::UpdateTitle()
82 With this method, can the SfxViewFrame be forced to immediately provide
83 the new title from the <SfxObjectShell>.
87 This is for example necessary if one listens to the SfxObjectShell as
88 SfxListener and then react on the <SfxSimpleHint> SFX_HINT_TITLECHANGED,
89 then query the title of his views. However these views (SfxTopViewFrames)
90 are also SfxListener and because the order of notifications might not be
91 fixed, the title update will be enforced in advance.
95 void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
97 if ( dynamic_cast<const SfxSimpleHint *>(&rHint) != nullptr )
99 switch( ( (SfxSimpleHint&) rHint ).GetId() )
101 case SFX_HINT_TITLECHANGED:
102 for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
104 pTop = SfxViewFrame::GetNext( this );
107 ... pTop->GetName() ...
118 const SfxObjectFactory
&rFact
= GetObjectShell()->GetFactory();
119 m_pImpl
->aFactoryName
= OUString::createFromAscii(rFact
.GetShortName());
121 SfxObjectShell
*pObjSh
= GetObjectShell();
126 const SfxMedium
*pMedium
= pObjSh
->GetMedium();
128 GetFrame(); // -Wall required??
129 if ( pObjSh
->HasName() )
131 INetURLObject
aTmp( pMedium
->GetName() );
132 aURL
= aTmp
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
135 if ( aURL
!= m_pImpl
->aActualURL
)
137 m_pImpl
->aActualURL
= aURL
;
140 OUString aSbxName
= pObjSh
->SfxShell::GetName();
144 aSbxName
+= OUString::number(m_pImpl
->nDocViewNo
);
148 GetBindings().Invalidate( SID_CURRENT_URL
);
149 GetBindings().Invalidate( SID_NEWDOCDIRECT
);
152 void SfxViewFrame::Exec_Impl(SfxRequest
&rReq
)
154 // If presently the shells are replaced...
155 if ( !GetObjectShell() || !GetViewShell() )
158 switch ( rReq
.GetSlot() )
160 case SID_SHOWPOPUPS
:
162 const SfxBoolItem
* pShowItem
= rReq
.GetArg
<SfxBoolItem
>(SID_SHOWPOPUPS
);
163 bool bShow
= pShowItem
== nullptr || pShowItem
->GetValue();
165 SfxWorkWindow
*pWorkWin
= GetFrame().GetWorkWindow_Impl();
168 // First, make the floats viewable
169 pWorkWin
->MakeChildrenVisible_Impl( bShow
);
170 GetDispatcher()->Update_Impl( true );
173 GetBindings().HidePopups( !bShow
);
178 SfxBindings
*pBind
= &GetBindings();
181 pBind
->HidePopupCtrls_Impl( !bShow
);
182 pBind
= pBind
->GetSubBindings_Impl();
185 pWorkWin
->HidePopups_Impl( !bShow
, true );
186 pWorkWin
->MakeChildrenVisible_Impl( bShow
);
189 Invalidate( rReq
.GetSlot() );
196 MakeActive_Impl( true );
197 rReq
.SetReturnValue( SfxObjectItem( 0, this ) );
201 case SID_NEWDOCDIRECT
:
203 const SfxStringItem
* pFactoryItem
= rReq
.GetArg
<SfxStringItem
>(SID_NEWDOCDIRECT
);
206 aFactName
= pFactoryItem
->GetValue();
207 else if ( !m_pImpl
->aFactoryName
.isEmpty() )
208 aFactName
= m_pImpl
->aFactoryName
;
211 OSL_FAIL("Missing argument!");
215 SfxRequest
aReq( SID_OPENDOC
, SfxCallMode::SYNCHRON
, GetPool() );
216 OUString
aFact("private:factory/");
218 aReq
.AppendItem( SfxStringItem( SID_FILE_NAME
, aFact
) );
219 aReq
.AppendItem( SfxFrameItem( SID_DOCFRAME
, &GetFrame() ) );
220 aReq
.AppendItem( SfxStringItem( SID_TARGETNAME
, OUString( "_blank" ) ) );
221 SfxGetpApp()->ExecuteSlot( aReq
);
222 const SfxViewFrameItem
* pItem
= dynamic_cast<const SfxViewFrameItem
*>( aReq
.GetReturnValue() );
224 rReq
.SetReturnValue( SfxFrameItem( 0, pItem
->GetFrame() ) );
230 // disable CloseWin, if frame is not a task
231 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
235 if ( GetViewShell()->PrepareClose() )
237 // More Views on the same Document?
238 SfxObjectShell
*pDocSh
= GetObjectShell();
240 for ( const SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pDocSh
);
242 pFrame
= SfxViewFrame::GetNext( *pFrame
, pDocSh
) )
243 bOther
= (pFrame
!= this);
245 // Document only needs to be queried, if no other View present.
246 bool bClosed
= false;
248 if ( ( bOther
|| pDocSh
->PrepareClose( bUI
) ) )
251 pDocSh
->SetModified( false );
252 rReq
.Done(); // Must call this before Close()!
259 catch (css::lang::DisposedException
&) {
260 // already closed; ignore
262 catch( CloseVetoException
& )
268 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bClosed
));
277 void SfxViewFrame::GetState_Impl( SfxItemSet
&rSet
)
279 SfxObjectShell
*pDocSh
= GetObjectShell();
284 const sal_uInt16
*pRanges
= rSet
.GetRanges();
285 DBG_ASSERT(pRanges
, "Set without Range");
288 for ( sal_uInt16 nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++nWhich
)
292 case SID_NEWDOCDIRECT
:
294 if ( !m_pImpl
->aFactoryName
.isEmpty() )
296 OUString
aFact("private:factory/");
297 aFact
+= m_pImpl
->aFactoryName
;
298 rSet
.Put( SfxStringItem( nWhich
, aFact
) );
304 rSet
.DisableItem(nWhich
);
309 // disable CloseWin, if frame is not a task
310 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
312 rSet
.DisableItem(nWhich
);
316 case SID_SHOWPOPUPS
:
320 if ( GetViewShell() && GetViewShell()->GetVerbs().getLength() && !GetObjectShell()->IsInPlaceActive() )
322 uno::Any
aAny(GetViewShell()->GetVerbs());
323 rSet
.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT
), aAny
) );
326 rSet
.DisableItem( SID_OBJECT
);
330 OSL_FAIL( "invalid message-id" );
337 void SfxViewFrame::INetExecute_Impl( SfxRequest
&rRequest
)
339 sal_uInt16 nSlotId
= rRequest
.GetSlot();
342 case SID_BROWSE_FORWARD
:
343 case SID_BROWSE_BACKWARD
:
344 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
348 /*! (pb) we need new implementation to create a link
352 case SID_FOCUSURLBOX
:
354 SfxStateCache
*pCache
= GetBindings().GetAnyStateCache_Impl( SID_OPENURL
);
357 SfxControllerItem
* pCtrl
= pCache
->GetItemLink();
360 pCtrl
->StateChanged( SID_FOCUSURLBOX
, SfxItemState::UNKNOWN
, nullptr );
361 pCtrl
= pCtrl
->GetItemLink();
371 void SfxViewFrame::INetState_Impl( SfxItemSet
&rItemSet
)
373 rItemSet
.DisableItem( SID_BROWSE_FORWARD
);
374 rItemSet
.DisableItem( SID_BROWSE_BACKWARD
);
376 // Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
377 SfxObjectShell
*pDocSh
= GetObjectShell();
378 bool bPseudo
= pDocSh
&& !( pDocSh
->GetFactory().GetFlags() & SfxObjectShellFlags::HASOPENDOC
);
379 bool bEmbedded
= pDocSh
&& pDocSh
->GetCreateMode() == SfxObjectCreateMode::EMBEDDED
;
380 if ( !pDocSh
|| bPseudo
|| bEmbedded
|| !pDocSh
->HasName() )
381 rItemSet
.DisableItem( SID_CREATELINK
);
384 void SfxViewFrame::Activate( bool bMDI
)
386 DBG_ASSERT(GetViewShell(), "No Shell");
388 m_pImpl
->bActive
= true;
389 //(mba): here maybe as in Beanframe NotifyEvent ?!
392 void SfxViewFrame::Deactivate( bool bMDI
)
394 DBG_ASSERT(GetViewShell(), "No Shell");
396 m_pImpl
->bActive
= false;
397 //(mba): here maybe as in Beanframe NotifyEvent ?!
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */