1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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() )
71 Window::StateChanged( nStateChange
);
74 void SfxFrameViewWindow_Impl::Resize()
76 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
80 //========================================================================
82 //--------------------------------------------------------------------
83 void SfxViewFrame::UpdateTitle()
87 With this method, can the SfxViewFrame be forced to immediately provide
88 the new title from the <SfxObjectShell>.
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.
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 );
109 pTop = SfxViewFrame::GetNext( this );
112 ... pTop->GetName() ...
122 DBG_CHKTHIS(SfxViewFrame
, 0);
124 const SfxObjectFactory
&rFact
= GetObjectShell()->GetFactory();
125 pImp
->aFactoryName
= OUString::createFromAscii(rFact
.GetShortName());
127 SfxObjectShell
*pObjSh
= GetObjectShell();
132 const SfxMedium
*pMedium
= pObjSh
->GetMedium();
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
)
143 pImp
->aActualURL
= aURL
;
146 String aSbxName
= pObjSh
->SfxShell::GetName();
150 aSbxName
+= OUString::number(pImp
->nDocViewNo
);
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() )
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();
176 // First, make the floats viewable
177 pWorkWin
->MakeChildrenVisible_Impl( bShow
);
178 GetDispatcher()->Update_Impl( sal_True
);
181 GetBindings().HidePopups( !bShow
);
186 SfxBindings
*pBind
= &GetBindings();
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() );
204 MakeActive_Impl( sal_True
);
205 rReq
.SetReturnValue( SfxObjectItem( 0, this ) );
209 case SID_NEWDOCDIRECT
:
211 SFX_REQUEST_ARG( rReq
, pFactoryItem
, SfxStringItem
, SID_NEWDOCDIRECT
, sal_False
);
214 aFactName
= pFactoryItem
->GetValue();
215 else if ( pImp
->aFactoryName
.Len() )
216 aFactName
= pImp
->aFactoryName
;
219 OSL_FAIL("Missing argument!");
223 SfxRequest
aReq( SID_OPENDOC
, SFX_CALLMODE_SYNCHRON
, GetPool() );
224 String aFact
= OUString("private:factory/");
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() );
232 rReq
.SetReturnValue( SfxFrameItem( 0, pItem
->GetFrame() ) );
238 // disable CloseWin, if frame is not a task
239 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
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
);
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
) ) )
259 pDocSh
->SetModified( sal_False
);
260 rReq
.Done(); // Must call this before Close()!
264 xTask
->close(sal_True
);
267 catch( CloseVetoException
& )
273 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bClosed
));
282 void SfxViewFrame::GetState_Impl( SfxItemSet
&rSet
)
284 SfxObjectShell
*pDocSh
= GetObjectShell();
289 const sal_uInt16
*pRanges
= rSet
.GetRanges();
290 DBG_ASSERT(pRanges
, "Set without Range");
293 for ( sal_uInt16 nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++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
) );
309 rSet
.DisableItem(nWhich
);
314 // disable CloseWin, if frame is not a task
315 Reference
< XCloseable
> xTask( GetFrame().GetFrameInterface(), UNO_QUERY
);
317 rSet
.DisableItem(nWhich
);
321 case SID_SHOWPOPUPS
:
325 if ( GetViewShell() && GetViewShell()->GetVerbs().getLength() && !GetObjectShell()->IsInPlaceActive() )
328 aAny
<<= GetViewShell()->GetVerbs();
329 rSet
.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT
), aAny
) );
332 rSet
.DisableItem( SID_OBJECT
);
336 OSL_FAIL( "invalid message-id" );
343 void SfxViewFrame::INetExecute_Impl( SfxRequest
&rRequest
)
345 sal_uInt16 nSlotId
= rRequest
.GetSlot();
348 case SID_BROWSE_FORWARD
:
349 case SID_BROWSE_BACKWARD
:
350 OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
354 /*! (pb) we need new implementation to create a link
358 case SID_FOCUSURLBOX
:
360 SfxStateCache
*pCache
= GetBindings().GetAnyStateCache_Impl( SID_OPENURL
);
363 SfxControllerItem
* pCtrl
= pCache
->GetItemLink();
366 pCtrl
->StateChanged( SID_FOCUSURLBOX
, SFX_ITEM_UNKNOWN
, 0 );
367 pCtrl
= pCtrl
->GetItemLink();
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");
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");
407 pImp
->bActive
= sal_False
;
408 //(mba): here maybe as in Beanframe NotifyEvent ?!
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */