LibreOffice Module sfx2 (master) 1
viewfrm2.cxx
Go to the documentation of this file.
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
21#include "impviewframe.hxx"
22#include <statcach.hxx>
23#include <workwin.hxx>
24
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>
41
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>
47
48using namespace ::com::sun::star;
49using namespace ::com::sun::star::uno;
50using namespace ::com::sun::star::util;
51using namespace ::com::sun::star::container;
52using namespace ::com::sun::star::beans;
53
54
56{
57 if ( nStateChange == StateChangedType::InitShow )
58 {
60 if ( pDoc && !pFrame->IsVisible() )
61 pFrame->Show();
62
63 pFrame->Resize();
64 }
65 else
66 Window::StateChanged( nStateChange );
67}
68
70{
72 pFrame->Resize();
73}
74
75
77
78/* [Description]
79
80 With this method, can the SfxViewFrame be forced to immediately provide
81 the new title from the <SfxObjectShell>.
82
83 [Note]
84
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.
90
91 [Example]
92
93 void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
94 {
95 if ( dynamic_cast<const SfxSimpleHint *>(&rHint) != nullptr )
96 {
97 switch( ( (SfxSimpleHint&) rHint ).GetId() )
98 {
99 case SfxHintId::TitleChanged:
100 for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
101 pTop;
102 pTop = SfxViewFrame::GetNext( this );
103 {
104 pTop->UpdateTitle();
105 ... pTop->GetName() ...
106 }
107 break;
108 ...
109 }
110 }
111 }
112*/
113
114{
115
116 const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
117 m_pImpl->aFactoryName = rFact.GetFactoryName();
118
119 SfxObjectShell *pObjSh = GetObjectShell();
120 if ( !pObjSh )
121 return;
122
123
124 const SfxMedium *pMedium = pObjSh->GetMedium();
125 OUString aURL;
126 GetFrame(); // -Wall required??
127 if ( pObjSh->HasName() )
128 {
129 INetURLObject aTmp( pMedium->GetName() );
131 }
132
133 if ( aURL != m_pImpl->aActualURL )
134 // URL has changed
135 m_pImpl->aActualURL = aURL;
136
137 // SbxObjects name
138 OUString aSbxName = pObjSh->SfxShell::GetName();
139 if ( IsVisible() )
140 {
141 aSbxName += ":" + OUString::number(m_pImpl->nDocViewNo);
142 }
143
144 SetName( aSbxName );
145 GetBindings().Invalidate( SID_CURRENT_URL );
146 GetBindings().Invalidate( SID_NEWDOCDIRECT );
147}
148
150{
151 // If presently the shells are replaced...
152 if ( !GetObjectShell() || !GetViewShell() )
153 return;
154
155 switch ( rReq.GetSlot() )
156 {
157 case SID_SHOWPOPUPS :
158 {
159 const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(SID_SHOWPOPUPS);
160 bool bShow = pShowItem == nullptr || pShowItem->GetValue();
161
163 if ( bShow )
164 {
165 // First, make the floats viewable
166 pWorkWin->MakeChildrenVisible_Impl(true);
167 GetDispatcher()->Update_Impl( true );
168
169 // Then view it
170 GetBindings().HidePopups(false);
171 }
172 else
173 {
174 pWorkWin->HidePopups_Impl(true);
175 pWorkWin->MakeChildrenVisible_Impl(false);
176 }
177
178 Invalidate( rReq.GetSlot() );
179 rReq.Done();
180 break;
181 }
182
183 case SID_ACTIVATE:
184 {
185 MakeActive_Impl( true );
186 rReq.SetReturnValue( SfxObjectItem( 0, this ) );
187 break;
188 }
189
190 case SID_NEWDOCDIRECT :
191 {
192 const SfxStringItem* pFactoryItem = rReq.GetArg<SfxStringItem>(SID_NEWDOCDIRECT);
193 OUString aFactName;
194 if ( pFactoryItem )
195 aFactName = pFactoryItem->GetValue();
196 else if ( !m_pImpl->aFactoryName.isEmpty() )
197 aFactName = m_pImpl->aFactoryName;
198 else
199 {
200 SAL_WARN("sfx.view", "Missing argument!");
201 break;
202 }
203
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() );
211 if ( pItem )
212 rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
213 break;
214 }
215
216 case SID_CLOSEWIN:
217 {
218 // disable CloseWin, if frame is not a task
219 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
220 if ( !xTask.is() )
221 break;
222
223 if ( GetViewShell()->PrepareClose() )
224 {
225 // More Views on the same Document?
226 SfxObjectShell *pDocSh = GetObjectShell();
227 bool bOther = false;
228 for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
229 !bOther && pFrame;
230 pFrame = SfxViewFrame::GetNext( *pFrame, pDocSh ) )
231 bOther = (pFrame != this);
232
233 // Document only needs to be queried, if no other View present.
234 bool bClosed = false;
235 if ( bOther || pDocSh->PrepareClose( true/*bUI*/ ) )
236 {
237 if ( !bOther )
238 pDocSh->SetModified( false );
239 rReq.Done(); // Must call this before Close()!
240 bClosed = false;
241 try
242 {
243 xTask->close(true);
244 bClosed = true;
245 }
246 catch (css::lang::DisposedException &) {
247 // already closed; ignore
248 }
249 catch( CloseVetoException& )
250 {
251 bClosed = false;
252 }
253 }
254
255 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
256 }
257 return;
258 }
259 }
260
261 rReq.Done();
262}
263
265{
266 SfxObjectShell *pDocSh = GetObjectShell();
267
268 if ( !pDocSh )
269 return;
270
271 const WhichRangesContainer & pRanges = rSet.GetRanges();
272 DBG_ASSERT(!pRanges.empty(), "Set without Range");
273 for ( auto const & pRange : pRanges )
274 {
275 for ( sal_uInt16 nWhich = pRange.first; nWhich <= pRange.second; ++nWhich )
276 {
277 switch(nWhich)
278 {
279 case SID_NEWDOCDIRECT :
280 {
281 if ( !m_pImpl->aFactoryName.isEmpty() )
282 {
283 rSet.Put( SfxStringItem( nWhich, "private:factory/"+m_pImpl->aFactoryName ) );
284 }
285 break;
286 }
287
288 case SID_NEWWINDOW:
289 rSet.DisableItem(nWhich);
290 break;
291
292 case SID_CLOSEWIN:
293 {
294 // disable CloseWin, if frame is not a task
295 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
296 if ( !xTask.is() )
297 rSet.DisableItem(nWhich);
298 break;
299 }
300
301 case SID_SHOWPOPUPS :
302 break;
303
304 case SID_OBJECT:
305 if ( GetViewShell() && GetViewShell()->GetVerbs().hasElements() && !GetObjectShell()->IsInPlaceActive() )
306 {
307 uno::Any aAny(GetViewShell()->GetVerbs());
308 rSet.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT ), aAny ) );
309 }
310 else
311 rSet.DisableItem( SID_OBJECT );
312 break;
313
314 default:
315 OSL_FAIL( "invalid message-id" );
316 }
317 }
318 }
319}
320
322{
323 sal_uInt16 nSlotId = rRequest.GetSlot();
324 switch( nSlotId )
325 {
326 case SID_BROWSE_FORWARD:
327 case SID_BROWSE_BACKWARD:
328 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
329 break;
330 case SID_CREATELINK:
331 {
334 break;
335 }
336 case SID_FOCUSURLBOX:
337 {
338 SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
339 if( pCache )
340 {
341 SfxControllerItem* pCtrl = pCache->GetItemLink();
342 while( pCtrl )
343 {
344 pCtrl->StateChangedAtToolBoxControl( SID_FOCUSURLBOX, SfxItemState::UNKNOWN, nullptr );
345 pCtrl = pCtrl->GetItemLink();
346 }
347 }
348 }
349 }
350
351 // Recording
352 rRequest.Done();
353}
354
356{
357 rItemSet.DisableItem( SID_BROWSE_FORWARD );
358 rItemSet.DisableItem( SID_BROWSE_BACKWARD );
359
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 );
365}
366
367void SfxViewFrame::Activate( bool /*bMDI*/ )
368{
369 DBG_ASSERT(GetViewShell(), "No Shell");
370//(mba): here maybe as in Beanframe NotifyEvent ?!
371}
372
373void SfxViewFrame::Deactivate( bool /*bMDI*/ )
374{
375 DBG_ASSERT(GetViewShell(), "No Shell");
376//(mba): here maybe as in Beanframe NotifyEvent ?!
377}
378
379/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
const OUString & GetValue() const
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
SAL_DLLPRIVATE SfxStateCache * GetAnyStateCache_Impl(sal_uInt16 nId)
Definition: bindings.cxx:457
void Invalidate(sal_uInt16 nId)
Definition: bindings.cxx:639
void HidePopups(bool bHide=true)
Definition: bindings.cxx:230
bool GetValue() const
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState)
Definition: ctrlitem.cxx:203
SfxControllerItem * GetItemLink()
Definition: ctrlitem.cxx:31
SAL_DLLPRIVATE void Update_Impl(bool bForce=false)
Definition: dispatch.cxx:1034
virtual void StateChanged(StateChangedType nStateChange) override
Definition: viewfrm2.cxx:55
virtual void Resize() override
Definition: viewfrm2.cxx:69
SAL_DLLPRIVATE SfxWorkWindow * GetWorkWindow_Impl() const
Definition: frame.cxx:588
const WhichRangesContainer & GetRanges() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void DisableItem(sal_uInt16 nWhich)
const OUString & GetName() const
Definition: docfile.cxx:3592
const OUString & GetFactoryName() const
Definition: docfac.hxx:52
virtual bool PrepareClose(bool bUI=true)
Definition: objxtor.cxx:506
bool HasName() const
Definition: objsh.hxx:266
virtual SfxObjectFactory & GetFactory() const =0
SfxMedium * GetMedium() const
Definition: objsh.hxx:261
SfxObjectCreateMode GetCreateMode() const
Definition: objsh.hxx:487
virtual void SetModified(bool bModified=true)
Definition: objmisc.cxx:301
sal_uInt16 GetSlot() const
Definition: request.hxx:68
const SfxPoolItem * GetReturnValue() const
Definition: request.cxx:429
const T * GetArg(sal_uInt16 nSlotId) const
Templatized access to the individual parameters of the SfxRequest.
Definition: request.hxx:84
void AppendItem(const SfxPoolItem &)
Definition: request.cxx:404
void SetReturnValue(const SfxPoolItem &)
Definition: request.cxx:422
void Done(bool bRemove=false)
Definition: request.cxx:484
SfxItemPool & GetPool() const
Each Subclass of SfxShell must reference a pool.
Definition: shell.hxx:511
const css::uno::Sequence< css::embed::VerbDescriptor > & GetVerbs() const
Definition: shell.cxx:597
virtual void Invalidate(sal_uInt16 nId=0)
With this method can the slots of the subclasses be invalidated through the slot Id or alternatively ...
Definition: shell.cxx:235
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
This method allows you to forward a <SfxRequest> to the specified base <SfxShell>.
Definition: shell.cxx:438
SfxViewShell * GetViewShell() const
Returns the SfxViewShell in which they are located in the subshells.
Definition: shell.cxx:129
friend class SfxObjectItem
Definition: shell.hxx:129
void SetName(const OUString &rName)
Sets the name of the Shell object.
Definition: shell.cxx:114
SfxControllerItem * GetItemLink() const
Definition: statcach.hxx:141
SfxViewFrame * GetFrame() const
Definition: viewfrm.hxx:275
virtual void Deactivate(bool bUI) override
Virtual method that is called when disabling the SfxShell instance, to give the Subclasses the opport...
Definition: viewfrm2.cxx:373
SAL_DLLPRIVATE void Exec_Impl(SfxRequest &)
Definition: viewfrm2.cxx:149
SAL_DLLPRIVATE void INetState_Impl(SfxItemSet &)
Definition: viewfrm2.cxx:355
SAL_DLLPRIVATE void GetState_Impl(SfxItemSet &rSet)
Definition: viewfrm2.cxx:264
SAL_DLLPRIVATE void INetExecute_Impl(SfxRequest &)
Definition: viewfrm2.cxx:321
SfxBindings & GetBindings()
Definition: viewfrm.hxx:110
void Resize(bool bForce=false)
Definition: viewfrm.cxx:2835
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:2006
SfxDispatcher * GetDispatcher()
Definition: viewfrm.hxx:109
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:1983
SfxFrame & GetFrame() const
Definition: viewfrm.cxx:2782
virtual SfxObjectShell * GetObjectShell() override
Definition: viewfrm.cxx:2218
virtual void Activate(bool bUI) override
Virtual method that is called when enabling the SfxShell instance, in order to give the Subclasses th...
Definition: viewfrm2.cxx:367
void UpdateTitle()
Definition: viewfrm2.cxx:76
void Show()
Definition: viewfrm.cxx:2135
bool IsVisible() const
Definition: viewfrm.cxx:2162
SAL_DLLPRIVATE void MakeActive_Impl(bool bActivate)
Definition: viewfrm.cxx:2178
std::unique_ptr< struct SfxViewFrame_Impl > m_pImpl
Definition: viewfrm.hxx:51
void HidePopups_Impl(bool bHide, sal_uInt16 nId=0)
Definition: workwin.cxx:1499
void MakeChildrenVisible_Impl(bool bVis)
Definition: workwin.cxx:2214
bool IsReallyVisible() const
bool IsReallyShown() const
Size GetOutputSizePixel() const
#define DBG_ASSERT(sCon, aError)
URL aURL
#define SAL_WARN(area, stream)
static SfxItemSet & rSet
Definition: shell.cxx:534
bool empty() const noexcept
StateChangedType