tdf#150789 - FILEOPEN PPTX: fix text in SmartArt vertically off
[LibreOffice.git] / sfx2 / source / view / viewfrm2.cxx
blob295aa4d38db9a89e48e77c30c85e7c95e357f71f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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() )
59 pFrame->Show();
61 pFrame->Resize();
63 else
64 Window::StateChanged( nStateChange );
67 void SfxFrameViewWindow_Impl::Resize()
69 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
70 pFrame->Resize();
74 void SfxViewFrame::UpdateTitle()
76 /* [Description]
78 With this method, can the SfxViewFrame be forced to immediately provide
79 the new title from the <SfxObjectShell>.
81 [Note]
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.
89 [Example]
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 );
99 pTop;
100 pTop = SfxViewFrame::GetNext( this );
102 pTop->UpdateTitle();
103 ... pTop->GetName() ...
105 break;
114 const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
115 m_pImpl->aFactoryName = rFact.GetFactoryName();
117 SfxObjectShell *pObjSh = GetObjectShell();
118 if ( !pObjSh )
119 return;
122 const SfxMedium *pMedium = pObjSh->GetMedium();
123 OUString aURL;
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 )
132 // URL has changed
133 m_pImpl->aActualURL = aURL;
135 // SbxObjects name
136 OUString aSbxName = pObjSh->SfxShell::GetName();
137 if ( IsVisible() )
139 aSbxName += ":" + OUString::number(m_pImpl->nDocViewNo);
142 SetName( aSbxName );
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() )
151 return;
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();
161 if ( bShow )
163 // First, make the floats viewable
164 pWorkWin->MakeChildrenVisible_Impl(true);
165 GetDispatcher()->Update_Impl( true );
167 // Then view it
168 GetBindings().HidePopups(false);
170 else
172 pWorkWin->HidePopups_Impl(true);
173 pWorkWin->MakeChildrenVisible_Impl(false);
176 Invalidate( rReq.GetSlot() );
177 rReq.Done();
178 break;
181 case SID_ACTIVATE:
183 MakeActive_Impl( true );
184 rReq.SetReturnValue(SfxObjectItem(0, this));
185 break;
188 case SID_NEWDOCDIRECT :
190 const SfxStringItem* pFactoryItem = rReq.GetArg<SfxStringItem>(SID_NEWDOCDIRECT);
191 OUString aFactName;
192 if ( pFactoryItem )
193 aFactName = pFactoryItem->GetValue();
194 else if ( !m_pImpl->aFactoryName.isEmpty() )
195 aFactName = m_pImpl->aFactoryName;
196 else
198 SAL_WARN("sfx.view", "Missing argument!");
199 break;
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()));
212 break;
215 case SID_CLOSEWIN:
217 // disable CloseWin, if frame is not a task
218 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
219 if ( !xTask.is() )
220 break;
222 if ( GetViewShell()->PrepareClose() )
224 // More Views on the same Document?
225 SfxObjectShell *pDocSh = GetObjectShell();
226 bool bOther = false;
227 for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
228 !bOther && pFrame;
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*/ ) )
236 if ( !bOther )
237 pDocSh->SetModified( false );
238 rReq.Done(); // Must call this before Close()!
239 bClosed = false;
242 xTask->close(true);
243 bClosed = true;
245 catch (css::lang::DisposedException &) {
246 // already closed; ignore
248 catch( CloseVetoException& )
250 bClosed = false;
254 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), bClosed));
256 return;
260 rReq.Done();
263 void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
265 SfxObjectShell *pDocSh = GetObjectShell();
267 if ( !pDocSh )
268 return;
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 )
276 switch(nWhich)
278 case SID_NEWDOCDIRECT :
280 if ( !m_pImpl->aFactoryName.isEmpty() )
282 rSet.Put( SfxStringItem( nWhich, "private:factory/"+m_pImpl->aFactoryName ) );
284 break;
287 case SID_NEWWINDOW:
288 rSet.DisableItem(nWhich);
289 break;
291 case SID_CLOSEWIN:
293 // disable CloseWin, if frame is not a task
294 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
295 if ( !xTask.is() )
296 rSet.DisableItem(nWhich);
297 break;
300 case SID_SHOWPOPUPS :
301 break;
303 case SID_OBJECT:
304 if ( GetViewShell() && GetViewShell()->GetVerbs().hasElements() && !GetObjectShell()->IsInPlaceActive() )
306 uno::Any aAny(GetViewShell()->GetVerbs());
307 rSet.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT ), aAny ) );
309 else
310 rSet.DisableItem( SID_OBJECT );
311 break;
313 default:
314 OSL_FAIL( "invalid message-id" );
320 void SfxViewFrame::INetExecute_Impl( SfxRequest &rRequest )
322 sal_uInt16 nSlotId = rRequest.GetSlot();
323 switch( nSlotId )
325 case SID_BROWSE_FORWARD:
326 case SID_BROWSE_BACKWARD:
327 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
328 break;
329 case SID_CREATELINK:
331 /*! (pb) we need new implementation to create a link
333 break;
335 case SID_FOCUSURLBOX:
337 SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
338 if( pCache )
340 SfxControllerItem* pCtrl = pCache->GetItemLink();
341 while( pCtrl )
343 pCtrl->StateChangedAtToolBoxControl( SID_FOCUSURLBOX, SfxItemState::UNKNOWN, nullptr );
344 pCtrl = pCtrl->GetItemLink();
350 // Recording
351 rRequest.Done();
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: */