build fix
[LibreOffice.git] / sfx2 / source / view / viewfrm2.cxx
blob16ca900da627cd8c566fcfcc26c46555ac0b1dff
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 <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() )
63 pFrame->Show();
65 pFrame->Resize();
67 else
68 Window::StateChanged( nStateChange );
71 void SfxFrameViewWindow_Impl::Resize()
73 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
74 pFrame->Resize();
78 void SfxViewFrame::UpdateTitle()
80 /* [Description]
82 With this method, can the SfxViewFrame be forced to immediately provide
83 the new title from the <SfxObjectShell>.
85 [Note]
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.
93 [Example]
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 );
103 pTop;
104 pTop = SfxViewFrame::GetNext( this );
106 pTop->UpdateTitle();
107 ... pTop->GetName() ...
109 break;
118 const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
119 m_pImpl->aFactoryName = OUString::createFromAscii(rFact.GetShortName());
121 SfxObjectShell *pObjSh = GetObjectShell();
122 if ( !pObjSh )
123 return;
126 const SfxMedium *pMedium = pObjSh->GetMedium();
127 OUString aURL;
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 )
136 // URL has changed
137 m_pImpl->aActualURL = aURL;
139 // SbxObjects name
140 OUString aSbxName = pObjSh->SfxShell::GetName();
141 if ( IsVisible() )
143 aSbxName += ":";
144 aSbxName += OUString::number(m_pImpl->nDocViewNo);
147 SetName( aSbxName );
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() )
156 return;
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();
166 if ( bShow )
168 // First, make the floats viewable
169 pWorkWin->MakeChildrenVisible_Impl( bShow );
170 GetDispatcher()->Update_Impl( true );
172 // Then view it
173 GetBindings().HidePopups( !bShow );
175 else
177 // Hide all
178 SfxBindings *pBind = &GetBindings();
179 while ( pBind )
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() );
190 rReq.Done();
191 break;
194 case SID_ACTIVATE:
196 MakeActive_Impl( true );
197 rReq.SetReturnValue( SfxObjectItem( 0, this ) );
198 break;
201 case SID_NEWDOCDIRECT :
203 const SfxStringItem* pFactoryItem = rReq.GetArg<SfxStringItem>(SID_NEWDOCDIRECT);
204 OUString aFactName;
205 if ( pFactoryItem )
206 aFactName = pFactoryItem->GetValue();
207 else if ( !m_pImpl->aFactoryName.isEmpty() )
208 aFactName = m_pImpl->aFactoryName;
209 else
211 OSL_FAIL("Missing argument!");
212 break;
215 SfxRequest aReq( SID_OPENDOC, SfxCallMode::SYNCHRON, GetPool() );
216 OUString aFact("private:factory/");
217 aFact += aFactName;
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() );
223 if ( pItem )
224 rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
225 break;
228 case SID_CLOSEWIN:
230 // disable CloseWin, if frame is not a task
231 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
232 if ( !xTask.is() )
233 break;
235 if ( GetViewShell()->PrepareClose() )
237 // More Views on the same Document?
238 SfxObjectShell *pDocSh = GetObjectShell();
239 bool bOther = false;
240 for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
241 !bOther && pFrame;
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;
247 bool bUI = true;
248 if ( ( bOther || pDocSh->PrepareClose( bUI ) ) )
250 if ( !bOther )
251 pDocSh->SetModified( false );
252 rReq.Done(); // Must call this before Close()!
253 bClosed = false;
256 xTask->close(true);
257 bClosed = true;
259 catch (css::lang::DisposedException &) {
260 // already closed; ignore
262 catch( CloseVetoException& )
264 bClosed = false;
268 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
270 return;
274 rReq.Done();
277 void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
279 SfxObjectShell *pDocSh = GetObjectShell();
281 if ( !pDocSh )
282 return;
284 const sal_uInt16 *pRanges = rSet.GetRanges();
285 DBG_ASSERT(pRanges, "Set without Range");
286 while ( *pRanges )
288 for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
290 switch(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 ) );
300 break;
303 case SID_NEWWINDOW:
304 rSet.DisableItem(nWhich);
305 break;
307 case SID_CLOSEWIN:
309 // disable CloseWin, if frame is not a task
310 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
311 if ( !xTask.is() )
312 rSet.DisableItem(nWhich);
313 break;
316 case SID_SHOWPOPUPS :
317 break;
319 case SID_OBJECT:
320 if ( GetViewShell() && GetViewShell()->GetVerbs().getLength() && !GetObjectShell()->IsInPlaceActive() )
322 uno::Any aAny(GetViewShell()->GetVerbs());
323 rSet.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT ), aAny ) );
325 else
326 rSet.DisableItem( SID_OBJECT );
327 break;
329 default:
330 OSL_FAIL( "invalid message-id" );
333 ++pRanges;
337 void SfxViewFrame::INetExecute_Impl( SfxRequest &rRequest )
339 sal_uInt16 nSlotId = rRequest.GetSlot();
340 switch( nSlotId )
342 case SID_BROWSE_FORWARD:
343 case SID_BROWSE_BACKWARD:
344 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
345 break;
346 case SID_CREATELINK:
348 /*! (pb) we need new implementation to create a link
350 break;
352 case SID_FOCUSURLBOX:
354 SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
355 if( pCache )
357 SfxControllerItem* pCtrl = pCache->GetItemLink();
358 while( pCtrl )
360 pCtrl->StateChanged( SID_FOCUSURLBOX, SfxItemState::UNKNOWN, nullptr );
361 pCtrl = pCtrl->GetItemLink();
367 // Recording
368 rRequest.Done();
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");
387 if ( bMDI )
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");
395 if ( bMDI )
396 m_pImpl->bActive = false;
397 //(mba): here maybe as in Beanframe NotifyEvent ?!
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */