Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sfx2 / source / view / viewfrm2.cxx
blobe3cdb6b1a20767746df99d3d8dce9adebeceddb5
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;
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() )
61 pFrame->Show();
63 pFrame->Resize();
65 else
66 Window::StateChanged( nStateChange );
69 void SfxFrameViewWindow_Impl::Resize()
71 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
72 pFrame->Resize();
76 void SfxViewFrame::UpdateTitle()
78 /* [Description]
80 With this method, can the SfxViewFrame be forced to immediately provide
81 the new title from the <SfxObjectShell>.
83 [Note]
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.
91 [Example]
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 );
101 pTop;
102 pTop = SfxViewFrame::GetNext( this );
104 pTop->UpdateTitle();
105 ... pTop->GetName() ...
107 break;
116 const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
117 m_pImpl->aFactoryName = rFact.GetFactoryName();
119 SfxObjectShell *pObjSh = GetObjectShell();
120 if ( !pObjSh )
121 return;
124 const SfxMedium *pMedium = pObjSh->GetMedium();
125 OUString aURL;
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 )
134 // URL has changed
135 m_pImpl->aActualURL = aURL;
137 // SbxObjects name
138 OUString aSbxName = pObjSh->SfxShell::GetName();
139 if ( IsVisible() )
141 aSbxName += ":" + OUString::number(m_pImpl->nDocViewNo);
144 SetName( aSbxName );
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() )
153 return;
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();
163 if ( bShow )
165 // First, make the floats viewable
166 pWorkWin->MakeChildrenVisible_Impl(true);
167 GetDispatcher()->Update_Impl( true );
169 // Then view it
170 GetBindings().HidePopups(false);
172 else
174 pWorkWin->HidePopups_Impl(true);
175 pWorkWin->MakeChildrenVisible_Impl(false);
178 Invalidate( rReq.GetSlot() );
179 rReq.Done();
180 break;
183 case SID_ACTIVATE:
185 MakeActive_Impl( true );
186 rReq.SetReturnValue( SfxObjectItem( 0, this ) );
187 break;
190 case SID_NEWDOCDIRECT :
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
200 SAL_WARN("sfx.view", "Missing argument!");
201 break;
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;
216 case SID_CLOSEWIN:
218 // disable CloseWin, if frame is not a task
219 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
220 if ( !xTask.is() )
221 break;
223 if ( GetViewShell()->PrepareClose() )
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);
233 // Document only needs to be queried, if no other View present.
234 bool bClosed = false;
235 if ( bOther || pDocSh->PrepareClose( true/*bUI*/ ) )
237 if ( !bOther )
238 pDocSh->SetModified( false );
239 rReq.Done(); // Must call this before Close()!
240 bClosed = false;
243 xTask->close(true);
244 bClosed = true;
246 catch (css::lang::DisposedException &) {
247 // already closed; ignore
249 catch( CloseVetoException& )
251 bClosed = false;
255 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
257 return;
261 rReq.Done();
264 void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
266 SfxObjectShell *pDocSh = GetObjectShell();
268 if ( !pDocSh )
269 return;
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 )
277 switch(nWhich)
279 case SID_NEWDOCDIRECT :
281 if ( !m_pImpl->aFactoryName.isEmpty() )
283 rSet.Put( SfxStringItem( nWhich, "private:factory/"+m_pImpl->aFactoryName ) );
285 break;
288 case SID_NEWWINDOW:
289 rSet.DisableItem(nWhich);
290 break;
292 case SID_CLOSEWIN:
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;
301 case SID_SHOWPOPUPS :
302 break;
304 case SID_OBJECT:
305 if ( GetViewShell() && GetViewShell()->GetVerbs().hasElements() && !GetObjectShell()->IsInPlaceActive() )
307 uno::Any aAny(GetViewShell()->GetVerbs());
308 rSet.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT ), aAny ) );
310 else
311 rSet.DisableItem( SID_OBJECT );
312 break;
314 default:
315 OSL_FAIL( "invalid message-id" );
321 void SfxViewFrame::INetExecute_Impl( SfxRequest &rRequest )
323 sal_uInt16 nSlotId = rRequest.GetSlot();
324 switch( nSlotId )
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:
332 /*! (pb) we need new implementation to create a link
334 break;
336 case SID_FOCUSURLBOX:
338 SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
339 if( pCache )
341 SfxControllerItem* pCtrl = pCache->GetItemLink();
342 while( pCtrl )
344 pCtrl->StateChangedAtToolBoxControl( SID_FOCUSURLBOX, SfxItemState::UNKNOWN, nullptr );
345 pCtrl = pCtrl->GetItemLink();
351 // Recording
352 rRequest.Done();
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: */