Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "impframe.hxx"
22 : #include "objshimp.hxx"
23 : #include "sfx2/sfxhelp.hxx"
24 : #include "workwin.hxx"
25 :
26 : #include "sfx2/app.hxx"
27 : #include "sfx2/bindings.hxx"
28 : #include "sfx2/dispatch.hxx"
29 : #include "sfx2/docfac.hxx"
30 : #include "sfx2/docfile.hxx"
31 : #include "sfx2/event.hxx"
32 : #include "sfx2/objface.hxx"
33 : #include "sfx2/request.hxx"
34 :
35 : #include <com/sun/star/awt/XWindow2.hpp>
36 : #include <com/sun/star/beans/XPropertySet.hpp>
37 : #include <com/sun/star/frame/Desktop.hpp>
38 : #include <com/sun/star/frame/XComponentLoader.hpp>
39 : #include <com/sun/star/frame/XFrame.hpp>
40 : #include <com/sun/star/frame/XFramesSupplier.hpp>
41 : #include <com/sun/star/frame/XLayoutManager.hpp>
42 :
43 : #include <comphelper/componentcontext.hxx>
44 : #include <comphelper/namedvaluecollection.hxx>
45 : #include <comphelper/processfactory.hxx>
46 : #include <svl/eitem.hxx>
47 : #include <svl/intitem.hxx>
48 : #include <svl/itemset.hxx>
49 : #include <svl/rectitem.hxx>
50 : #include <svl/stritem.hxx>
51 : #include <toolkit/helper/vclunohelper.hxx>
52 : #include <tools/diagnose_ex.h>
53 :
54 : using namespace ::com::sun::star;
55 : using namespace ::com::sun::star::uno;
56 : using namespace ::com::sun::star::frame;
57 : using namespace ::com::sun::star::util;
58 : using namespace ::com::sun::star::container;
59 : using namespace ::com::sun::star::beans;
60 : using ::com::sun::star::lang::XMultiServiceFactory;
61 : using ::com::sun::star::lang::XComponent;
62 : using ::com::sun::star::frame::XComponentLoader;
63 :
64 : //------------------------------------------------------------------------
65 :
66 : class SfxFrameWindow_Impl : public Window
67 : {
68 : public:
69 : SfxFrame* pFrame;
70 :
71 : SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow );
72 : ~SfxFrameWindow_Impl( );
73 :
74 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
75 : virtual void StateChanged( StateChangedType nStateChange );
76 : virtual long PreNotify( NotifyEvent& rNEvt );
77 : virtual long Notify( NotifyEvent& rEvt );
78 : virtual void Resize();
79 : virtual void GetFocus();
80 : void DoResize();
81 : };
82 :
83 240 : SfxFrameWindow_Impl::SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow )
84 : : Window( &i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
85 240 : , pFrame( pF )
86 : {
87 240 : }
88 :
89 126 : SfxFrameWindow_Impl::~SfxFrameWindow_Impl( )
90 : {
91 126 : }
92 :
93 92 : void SfxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
94 : {
95 92 : Window::DataChanged( rDCEvt );
96 92 : SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
97 92 : if ( pWorkWin )
98 92 : pWorkWin->DataChanged_Impl( rDCEvt );
99 92 : }
100 :
101 1729 : long SfxFrameWindow_Impl::Notify( NotifyEvent& rNEvt )
102 : {
103 1729 : if ( pFrame->IsClosing_Impl() || !pFrame->GetFrameInterface().is() )
104 1337 : return sal_False;
105 :
106 392 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
107 392 : if ( !pView || !pView->GetObjectShell() )
108 0 : return Window::Notify( rNEvt );
109 :
110 392 : if ( rNEvt.GetType() == EVENT_GETFOCUS )
111 : {
112 142 : if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !pFrame->IsInPlace() )
113 : {
114 : OSL_TRACE("SfxFrame: GotFocus");
115 142 : pView->MakeActive_Impl( sal_False );
116 : }
117 :
118 : // TODO/LATER: do we still need this code?
119 142 : Window* pWindow = rNEvt.GetWindow();
120 142 : rtl::OString sHelpId;
121 426 : while ( sHelpId.isEmpty() && pWindow )
122 : {
123 142 : sHelpId = pWindow->GetHelpId();
124 142 : pWindow = pWindow->GetParent();
125 : }
126 :
127 142 : if ( !sHelpId.isEmpty() )
128 142 : SfxHelp::OpenHelpAgent( pFrame, sHelpId );
129 :
130 : // if focus was on an external window, the clipboard content might have been changed
131 142 : pView->GetBindings().Invalidate( SID_PASTE );
132 142 : pView->GetBindings().Invalidate( SID_PASTE_SPECIAL );
133 142 : return sal_True;
134 : }
135 250 : else if( rNEvt.GetType() == EVENT_KEYINPUT )
136 : {
137 0 : if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) )
138 0 : return sal_True;
139 : }
140 250 : else if ( rNEvt.GetType() == EVENT_EXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTDISABLE*/ )
141 : {
142 0 : pView->SetModalMode( sal_True );
143 0 : return sal_True;
144 : }
145 250 : else if ( rNEvt.GetType() == EVENT_ENDEXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTENABLE*/ )
146 : {
147 0 : pView->SetModalMode( sal_False );
148 0 : return sal_True;
149 : }
150 :
151 250 : return Window::Notify( rNEvt );
152 : }
153 :
154 688 : long SfxFrameWindow_Impl::PreNotify( NotifyEvent& rNEvt )
155 : {
156 688 : sal_uInt16 nType = rNEvt.GetType();
157 688 : if ( nType == EVENT_KEYINPUT || nType == EVENT_KEYUP )
158 : {
159 0 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
160 0 : SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
161 0 : if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
162 0 : return sal_True;
163 : }
164 688 : else if ( nType == EVENT_MOUSEBUTTONUP || nType == EVENT_MOUSEBUTTONDOWN )
165 : {
166 0 : Window* pWindow = rNEvt.GetWindow();
167 0 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
168 0 : SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
169 0 : if ( pShell )
170 0 : if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) )
171 0 : if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
172 0 : return sal_True;
173 : }
174 :
175 688 : if ( nType == EVENT_MOUSEBUTTONDOWN )
176 : {
177 0 : Window* pWindow = rNEvt.GetWindow();
178 0 : const MouseEvent* pMEvent = rNEvt.GetMouseEvent();
179 0 : Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() );
180 0 : SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
181 0 : if ( pWorkWin )
182 0 : pWorkWin->EndAutoShow_Impl( aPos );
183 : }
184 :
185 688 : return Window::PreNotify( rNEvt );
186 : }
187 :
188 182 : void SfxFrameWindow_Impl::GetFocus()
189 : {
190 182 : if ( pFrame && !pFrame->IsClosing_Impl() && pFrame->GetCurrentViewFrame() && pFrame->GetFrameInterface().is() )
191 142 : pFrame->GetCurrentViewFrame()->MakeActive_Impl( sal_True );
192 182 : }
193 :
194 709 : void SfxFrameWindow_Impl::Resize()
195 : {
196 709 : if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
197 469 : DoResize();
198 709 : }
199 :
200 586 : void SfxFrameWindow_Impl::StateChanged( StateChangedType nStateChange )
201 : {
202 586 : if ( nStateChange == STATE_CHANGE_INITSHOW )
203 : {
204 236 : pFrame->pImp->bHidden = sal_False;
205 236 : if ( pFrame->IsInPlace() )
206 : // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the
207 : // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that
208 : // the resize event never is sent to the component
209 0 : SetSizePixel( GetParent()->GetOutputSizePixel() );
210 :
211 236 : DoResize();
212 236 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
213 236 : if ( pView )
214 94 : pView->GetBindings().GetWorkWindow_Impl()->ShowChildren_Impl();
215 : }
216 :
217 586 : Window::StateChanged( nStateChange );
218 586 : }
219 :
220 705 : void SfxFrameWindow_Impl::DoResize()
221 : {
222 705 : if ( !pFrame->pImp->bLockResize )
223 705 : pFrame->Resize();
224 705 : }
225 :
226 0 : Reference < XFrame > SfxFrame::CreateBlankFrame()
227 : {
228 0 : Reference < XFrame > xFrame;
229 : try
230 : {
231 0 : Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
232 0 : xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW );
233 : }
234 0 : catch( const Exception& )
235 : {
236 : DBG_UNHANDLED_EXCEPTION();
237 : }
238 0 : return xFrame;
239 : }
240 :
241 0 : SfxFrame* SfxFrame::Create( SfxObjectShell& rDoc, Window& rWindow, sal_uInt16 nViewId, bool bHidden )
242 : {
243 0 : SfxFrame* pFrame = NULL;
244 : try
245 : {
246 : // create and initialize new top level frame for this window
247 0 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
248 0 : Reference < XDesktop2 > xDesktop = Desktop::create( aContext.getUNOContext() );
249 0 : Reference < XFrame > xFrame( aContext.createComponent( "com.sun.star.frame.Frame"), UNO_QUERY_THROW );
250 :
251 0 : Reference< awt::XWindow2 > xWin( VCLUnoHelper::GetInterface ( &rWindow ), uno::UNO_QUERY_THROW );
252 0 : xFrame->initialize( xWin.get() );
253 0 : xDesktop->getFrames()->append( xFrame );
254 :
255 0 : if ( xWin->isActive() )
256 0 : xFrame->activate();
257 :
258 : // create load arguments
259 0 : Sequence< PropertyValue > aLoadArgs;
260 0 : TransformItems( SID_OPENDOC, *rDoc.GetMedium()->GetItemSet(), aLoadArgs );
261 :
262 0 : ::comphelper::NamedValueCollection aArgs( aLoadArgs );
263 0 : aArgs.put( "Model", rDoc.GetModel() );
264 0 : aArgs.put( "Hidden", bHidden );
265 0 : if ( nViewId )
266 0 : aArgs.put( "ViewId", nViewId );
267 :
268 0 : aLoadArgs = aArgs.getPropertyValues();
269 :
270 : // load the doc into that frame
271 0 : ::rtl::OUString sLoaderURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) );
272 0 : Reference< XComponentLoader > xLoader( xFrame, UNO_QUERY_THROW );
273 0 : xLoader->loadComponentFromURL(
274 : sLoaderURL,
275 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ),
276 : 0,
277 : aLoadArgs
278 0 : );
279 :
280 0 : for ( pFrame = SfxFrame::GetFirst();
281 : pFrame;
282 : pFrame = SfxFrame::GetNext( *pFrame )
283 : )
284 : {
285 0 : if ( pFrame->GetFrameInterface() == xFrame )
286 0 : break;
287 : }
288 :
289 0 : OSL_ENSURE( pFrame, "SfxFrame::Create: load succeeded, but no SfxFrame was created during this!" );
290 : }
291 0 : catch( const Exception& )
292 : {
293 : DBG_UNHANDLED_EXCEPTION();
294 : }
295 :
296 0 : return pFrame;
297 : }
298 :
299 240 : SfxFrame* SfxFrame::Create( const Reference < XFrame >& i_rFrame )
300 : {
301 : // create a new TopFrame to an external XFrame object ( wrap controller )
302 240 : ENSURE_OR_THROW( i_rFrame.is(), "NULL frame not allowed" );
303 240 : Window* pWindow = VCLUnoHelper::GetWindow( i_rFrame->getContainerWindow() );
304 240 : ENSURE_OR_THROW( pWindow, "frame without container window not allowed" );
305 :
306 240 : SfxFrame* pFrame = new SfxFrame( *pWindow, false );
307 240 : pFrame->SetFrameInterface_Impl( i_rFrame );
308 240 : return pFrame;
309 : }
310 :
311 240 : SfxFrame::SfxFrame( Window& i_rContainerWindow, bool i_bHidden )
312 : :pParentFrame( NULL )
313 : ,pChildArr( NULL )
314 : ,pImp( NULL )
315 240 : ,pWindow( NULL )
316 : {
317 240 : Construct_Impl();
318 :
319 240 : pImp->bHidden = i_bHidden;
320 240 : InsertTopFrame_Impl( this );
321 240 : pImp->pExternalContainerWindow = &i_rContainerWindow;
322 :
323 240 : pWindow = new SfxFrameWindow_Impl( this, i_rContainerWindow );
324 :
325 : // always show pWindow, which is the ComponentWindow of the XFrame we live in
326 : // nowadays, since SfxFrames can be created with an XFrame only, hiding or showing the complete XFrame
327 : // is not done at level of the container window, not at SFX level. Thus, the component window can
328 : // always be visible.
329 240 : pWindow->Show();
330 240 : }
331 :
332 0 : void SfxFrame::SetPresentationMode( sal_Bool bSet )
333 : {
334 0 : if ( GetCurrentViewFrame() )
335 0 : GetCurrentViewFrame()->GetWindow().SetBorderStyle( bSet ? WINDOW_BORDER_NOBORDER : WINDOW_BORDER_NORMAL );
336 :
337 0 : Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
338 0 : Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
339 :
340 0 : if ( xPropSet.is() )
341 : {
342 0 : Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
343 0 : aValue >>= xLayoutManager;
344 : }
345 :
346 0 : if ( xLayoutManager.is() )
347 0 : xLayoutManager->setVisible( !bSet ); // we don't want to have ui in presentation mode
348 :
349 0 : SetMenuBarOn_Impl( !bSet );
350 0 : if ( GetWorkWindow_Impl() )
351 0 : GetWorkWindow_Impl()->SetDockingAllowed( !bSet );
352 0 : if ( GetCurrentViewFrame() )
353 0 : GetCurrentViewFrame()->GetDispatcher()->Update_Impl( sal_True );
354 0 : }
355 :
356 0 : SystemWindow* SfxFrame::GetSystemWindow() const
357 : {
358 0 : return GetTopWindow_Impl();
359 : }
360 :
361 0 : SystemWindow* SfxFrame::GetTopWindow_Impl() const
362 : {
363 0 : if ( pImp->pExternalContainerWindow->IsSystemWindow() )
364 0 : return (SystemWindow*) pImp->pExternalContainerWindow;
365 : else
366 0 : return NULL;
367 : }
368 :
369 6512 : Window& SfxFrame::GetWindow() const
370 : {
371 6512 : return *pWindow;
372 : }
373 :
374 63 : sal_Bool SfxFrame::Close()
375 : {
376 63 : delete this;
377 63 : return sal_True;
378 : }
379 :
380 0 : void SfxFrame::LockResize_Impl( sal_Bool bLock )
381 : {
382 0 : pImp->bLockResize = bLock;
383 0 : }
384 :
385 0 : void SfxFrame::SetMenuBarOn_Impl( sal_Bool bOn )
386 : {
387 0 : pImp->bMenuBarOn = bOn;
388 :
389 0 : Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
390 0 : Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
391 :
392 0 : if ( xPropSet.is() )
393 : {
394 0 : Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
395 0 : aValue >>= xLayoutManager;
396 : }
397 :
398 0 : if ( xLayoutManager.is() )
399 : {
400 0 : rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
401 :
402 0 : if ( bOn )
403 0 : xLayoutManager->showElement( aMenuBarURL );
404 : else
405 0 : xLayoutManager->hideElement( aMenuBarURL );
406 0 : }
407 0 : }
408 :
409 830 : sal_Bool SfxFrame::IsMenuBarOn_Impl() const
410 : {
411 830 : return pImp->bMenuBarOn;
412 : }
413 :
414 240 : void SfxFrame::PrepareForDoc_Impl( SfxObjectShell& i_rDoc )
415 : {
416 240 : const ::comphelper::NamedValueCollection aDocumentArgs( i_rDoc.GetModel()->getArgs() );
417 :
418 : // hidden?
419 : OSL_ENSURE( !pImp->bHidden, "when does this happen?" );
420 240 : pImp->bHidden = aDocumentArgs.getOrDefault( "Hidden", pImp->bHidden );
421 :
422 : // update our descriptor
423 240 : UpdateDescriptor( &i_rDoc );
424 :
425 : // plugin mode
426 240 : sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
427 240 : if ( nPluginMode && ( nPluginMode != 2 ) )
428 0 : SetInPlace_Impl( sal_True );
429 240 : }
430 :
431 240 : bool SfxFrame::IsMarkedHidden_Impl() const
432 : {
433 240 : return pImp->bHidden;
434 : }
435 :
436 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|