Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / view / viewfrm2.cxx
blobf84b209a678479d53afd2c9eaec0c1c8d13d3661
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 <comphelper/componentcontext.hxx>
41 #include <svtools/asynclink.hxx>
42 #include <svl/eitem.hxx>
43 #include <svl/intitem.hxx>
44 #include <svl/rectitem.hxx>
45 #include <svl/stritem.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <tools/urlobj.hxx>
48 #include <vcl/window.hxx>
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::frame;
53 using namespace ::com::sun::star::util;
54 using namespace ::com::sun::star::container;
55 using namespace ::com::sun::star::beans;
56 using ::com::sun::star::lang::XMultiServiceFactory;
57 using ::com::sun::star::lang::XComponent;
59 //--------------------------------------------------------------------
60 void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange )
62 if ( nStateChange == STATE_CHANGE_INITSHOW )
64 SfxObjectShell* pDoc = pFrame->GetObjectShell();
65 if ( pDoc && !pFrame->IsVisible() )
66 pFrame->Show();
68 pFrame->Resize();
70 else
71 Window::StateChanged( nStateChange );
74 void SfxFrameViewWindow_Impl::Resize()
76 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
77 pFrame->Resize();
80 //========================================================================
82 //--------------------------------------------------------------------
83 void SfxViewFrame::UpdateTitle()
85 /* [Description]
87 With this method, can the SfxViewFrame be forced to immediately provide
88 the new title from the <SfxObjectShell>.
90 [Note]
92 This is for example necessary if one listens to the SfxObjectShell as
93 SfxListener and then react on the <SfxSimpleHint> SFX_HINT_TITLECHANGED,
94 then query the title of his views. However these views (SfxTopViewFrames)
95 are also SfxListener and because the order of notifications might not be
96 fixed, the title update will be enforced in advance.
98 [Example]
100 void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
102 if ( rHint.IsA(TYPE(SfxSimpleHint)) )
104 switch( ( (SfxSimpleHint&) rHint ).GetId() )
106 case SFX_HINT_TITLECHANGED:
107 for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
108 pTop;
109 pTop = SfxViewFrame::GetNext( this );
111 pTop->UpdateTitle();
112 ... pTop->GetName() ...
114 break;
122 DBG_CHKTHIS(SfxViewFrame, 0);
124 const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
125 pImp->aFactoryName = OUString::createFromAscii(rFact.GetShortName());
127 SfxObjectShell *pObjSh = GetObjectShell();
128 if ( !pObjSh )
129 return;
132 const SfxMedium *pMedium = pObjSh->GetMedium();
133 String aURL;
134 GetFrame(); // -Wall required??
135 if ( pObjSh->HasName() )
137 INetURLObject aTmp( pMedium->GetName() );
138 aURL = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
141 if ( aURL != pImp->aActualURL )
142 // URL has changed
143 pImp->aActualURL = aURL;
145 // SbxObjects name
146 String aSbxName = pObjSh->SfxShell::GetName();
147 if ( IsVisible() )
149 aSbxName += ':';
150 aSbxName += OUString::number(pImp->nDocViewNo);
153 SetName( aSbxName );
154 GetBindings().Invalidate( SID_CURRENT_URL );
155 GetBindings().Invalidate( SID_NEWDOCDIRECT );
158 void SfxViewFrame::Exec_Impl(SfxRequest &rReq )
160 // If presently the shells are replaced...
161 if ( !GetObjectShell() || !GetViewShell() )
162 return;
164 switch ( rReq.GetSlot() )
166 case SID_SHOWPOPUPS :
168 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, SID_SHOWPOPUPS, sal_False);
169 sal_Bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
170 SFX_REQUEST_ARG(rReq, pIdItem, SfxUInt16Item, SID_CONFIGITEMID, sal_False);
171 sal_uInt16 nId = pIdItem ? pIdItem->GetValue() : 0;
173 SfxWorkWindow *pWorkWin = GetFrame().GetWorkWindow_Impl();
174 if ( bShow )
176 // First, make the floats viewable
177 pWorkWin->MakeChildrenVisible_Impl( bShow );
178 GetDispatcher()->Update_Impl( sal_True );
180 // Then view it
181 GetBindings().HidePopups( !bShow );
183 else
185 // Hide all
186 SfxBindings *pBind = &GetBindings();
187 while ( pBind )
189 pBind->HidePopupCtrls_Impl( !bShow );
190 pBind = pBind->GetSubBindings_Impl();
193 pWorkWin->HidePopups_Impl( !bShow, sal_True, nId );
194 pWorkWin->MakeChildrenVisible_Impl( bShow );
197 Invalidate( rReq.GetSlot() );
198 rReq.Done();
199 break;
202 case SID_ACTIVATE:
204 MakeActive_Impl( sal_True );
205 rReq.SetReturnValue( SfxObjectItem( 0, this ) );
206 break;
209 case SID_NEWDOCDIRECT :
211 SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, sal_False);
212 String aFactName;
213 if ( pFactoryItem )
214 aFactName = pFactoryItem->GetValue();
215 else if ( pImp->aFactoryName.Len() )
216 aFactName = pImp->aFactoryName;
217 else
219 OSL_FAIL("Missing argument!");
220 break;
223 SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, GetPool() );
224 String aFact = OUString("private:factory/");
225 aFact += aFactName;
226 aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) );
227 aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, &GetFrame() ) );
228 aReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString( "_blank" ) ) );
229 SFX_APP()->ExecuteSlot( aReq );
230 const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() );
231 if ( pItem )
232 rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
233 break;
236 case SID_CLOSEWIN:
238 // disable CloseWin, if frame is not a task
239 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
240 if ( !xTask.is() )
241 break;
243 if ( GetViewShell()->PrepareClose() )
245 // More Views on the same Document?
246 SfxObjectShell *pDocSh = GetObjectShell();
247 int bOther = sal_False;
248 for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
249 !bOther && pFrame;
250 pFrame = SfxViewFrame::GetNext( *pFrame, pDocSh ) )
251 bOther = (pFrame != this);
253 // Document only needs to be queried, if no other View present.
254 sal_Bool bClosed = sal_False;
255 sal_Bool bUI = sal_True;
256 if ( ( bOther || pDocSh->PrepareClose( bUI ) ) )
258 if ( !bOther )
259 pDocSh->SetModified( sal_False );
260 rReq.Done(); // Must call this before Close()!
261 bClosed = sal_False;
264 xTask->close(sal_True);
265 bClosed = sal_True;
267 catch( CloseVetoException& )
269 bClosed = sal_False;
273 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
275 return;
279 rReq.Done();
282 void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
284 SfxObjectShell *pDocSh = GetObjectShell();
286 if ( !pDocSh )
287 return;
289 const sal_uInt16 *pRanges = rSet.GetRanges();
290 DBG_ASSERT(pRanges, "Set without Range");
291 while ( *pRanges )
293 for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
295 switch(nWhich)
297 case SID_NEWDOCDIRECT :
299 if ( pImp->aFactoryName.Len() )
301 String aFact = OUString("private:factory/");
302 aFact += pImp->aFactoryName;
303 rSet.Put( SfxStringItem( nWhich, aFact ) );
305 break;
308 case SID_NEWWINDOW:
309 rSet.DisableItem(nWhich);
310 break;
312 case SID_CLOSEWIN:
314 // disable CloseWin, if frame is not a task
315 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
316 if ( !xTask.is() )
317 rSet.DisableItem(nWhich);
318 break;
321 case SID_SHOWPOPUPS :
322 break;
324 case SID_OBJECT:
325 if ( GetViewShell() && GetViewShell()->GetVerbs().getLength() && !GetObjectShell()->IsInPlaceActive() )
327 uno::Any aAny;
328 aAny <<= GetViewShell()->GetVerbs();
329 rSet.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT ), aAny ) );
331 else
332 rSet.DisableItem( SID_OBJECT );
333 break;
335 default:
336 OSL_FAIL( "invalid message-id" );
339 ++pRanges;
343 void SfxViewFrame::INetExecute_Impl( SfxRequest &rRequest )
345 sal_uInt16 nSlotId = rRequest.GetSlot();
346 switch( nSlotId )
348 case SID_BROWSE_FORWARD:
349 case SID_BROWSE_BACKWARD:
350 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
351 break;
352 case SID_CREATELINK:
354 /*! (pb) we need new implementation to create a link
356 break;
358 case SID_FOCUSURLBOX:
360 SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
361 if( pCache )
363 SfxControllerItem* pCtrl = pCache->GetItemLink();
364 while( pCtrl )
366 pCtrl->StateChanged( SID_FOCUSURLBOX, SFX_ITEM_UNKNOWN, 0 );
367 pCtrl = pCtrl->GetItemLink();
373 // Recording
374 rRequest.Done();
377 void SfxViewFrame::INetState_Impl( SfxItemSet &rItemSet )
379 rItemSet.DisableItem( SID_BROWSE_FORWARD );
380 rItemSet.DisableItem( SID_BROWSE_BACKWARD );
382 // Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
383 SfxObjectShell *pDocSh = GetObjectShell();
384 sal_Bool bPseudo = pDocSh && !( pDocSh->GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC );
385 sal_Bool bEmbedded = pDocSh && pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
386 if ( !pDocSh || bPseudo || bEmbedded || !pDocSh->HasName() )
387 rItemSet.DisableItem( SID_CREATELINK );
390 void SfxViewFrame::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
392 GetViewShell()->SetZoomFactor( rZoomX, rZoomY );
395 void SfxViewFrame::Activate( sal_Bool bMDI )
397 DBG_ASSERT(GetViewShell(), "No Shell");
398 if ( bMDI )
399 pImp->bActive = sal_True;
400 //(mba): here maybe as in Beanframe NotifyEvent ?!
403 void SfxViewFrame::Deactivate( sal_Bool bMDI )
405 DBG_ASSERT(GetViewShell(), "No Shell");
406 if ( bMDI )
407 pImp->bActive = sal_False;
408 //(mba): here maybe as in Beanframe NotifyEvent ?!
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */