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/XComponentLoader.hpp>
38 : #include <com/sun/star/frame/XFrame.hpp>
39 : #include <com/sun/star/frame/XFramesSupplier.hpp>
40 : #include <com/sun/star/frame/XLayoutManager.hpp>
41 :
42 : #include <comphelper/componentcontext.hxx>
43 : #include <comphelper/namedvaluecollection.hxx>
44 : #include <comphelper/processfactory.hxx>
45 : #include <svl/eitem.hxx>
46 : #include <svl/intitem.hxx>
47 : #include <svl/itemset.hxx>
48 : #include <svl/rectitem.hxx>
49 : #include <svl/stritem.hxx>
50 : #include <toolkit/helper/vclunohelper.hxx>
51 : #include <tools/diagnose_ex.h>
52 :
53 : using namespace ::com::sun::star;
54 : using namespace ::com::sun::star::uno;
55 : using namespace ::com::sun::star::frame;
56 : using namespace ::com::sun::star::util;
57 : using namespace ::com::sun::star::container;
58 : using namespace ::com::sun::star::beans;
59 : using ::com::sun::star::lang::XMultiServiceFactory;
60 : using ::com::sun::star::lang::XComponent;
61 : using ::com::sun::star::frame::XComponentLoader;
62 :
63 : //------------------------------------------------------------------------
64 :
65 : class SfxFrameWindow_Impl : public Window
66 : {
67 : public:
68 : SfxFrame* pFrame;
69 :
70 : SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow );
71 : ~SfxFrameWindow_Impl( );
72 :
73 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
74 : virtual void StateChanged( StateChangedType nStateChange );
75 : virtual long PreNotify( NotifyEvent& rNEvt );
76 : virtual long Notify( NotifyEvent& rEvt );
77 : virtual void Resize();
78 : virtual void GetFocus();
79 : void DoResize();
80 : };
81 :
82 516 : SfxFrameWindow_Impl::SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow )
83 : : Window( &i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
84 516 : , pFrame( pF )
85 : {
86 516 : }
87 :
88 196 : SfxFrameWindow_Impl::~SfxFrameWindow_Impl( )
89 : {
90 196 : }
91 :
92 184 : void SfxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
93 : {
94 184 : Window::DataChanged( rDCEvt );
95 184 : SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
96 184 : if ( pWorkWin )
97 184 : pWorkWin->DataChanged_Impl( rDCEvt );
98 184 : }
99 :
100 3626 : long SfxFrameWindow_Impl::Notify( NotifyEvent& rNEvt )
101 : {
102 3626 : if ( pFrame->IsClosing_Impl() || !pFrame->GetFrameInterface().is() )
103 2528 : return sal_False;
104 :
105 1098 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
106 1098 : if ( !pView || !pView->GetObjectShell() )
107 0 : return Window::Notify( rNEvt );
108 :
109 1098 : if ( rNEvt.GetType() == EVENT_GETFOCUS )
110 : {
111 318 : if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !pFrame->IsInPlace() )
112 : {
113 : OSL_TRACE("SfxFrame: GotFocus");
114 318 : pView->MakeActive_Impl( sal_False );
115 : }
116 :
117 : // TODO/LATER: do we still need this code?
118 318 : Window* pWindow = rNEvt.GetWindow();
119 318 : rtl::OString sHelpId;
120 954 : while ( sHelpId.isEmpty() && pWindow )
121 : {
122 318 : sHelpId = pWindow->GetHelpId();
123 318 : pWindow = pWindow->GetParent();
124 : }
125 :
126 318 : if ( !sHelpId.isEmpty() )
127 318 : SfxHelp::OpenHelpAgent( pFrame, sHelpId );
128 :
129 : // if focus was on an external window, the clipboard content might have been changed
130 318 : pView->GetBindings().Invalidate( SID_PASTE );
131 318 : pView->GetBindings().Invalidate( SID_PASTE_SPECIAL );
132 318 : return sal_True;
133 : }
134 780 : else if( rNEvt.GetType() == EVENT_KEYINPUT )
135 : {
136 0 : if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) )
137 0 : return sal_True;
138 : }
139 780 : else if ( rNEvt.GetType() == EVENT_EXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTDISABLE*/ )
140 : {
141 0 : pView->SetModalMode( sal_True );
142 0 : return sal_True;
143 : }
144 780 : else if ( rNEvt.GetType() == EVENT_ENDEXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTENABLE*/ )
145 : {
146 0 : pView->SetModalMode( sal_False );
147 0 : return sal_True;
148 : }
149 :
150 780 : return Window::Notify( rNEvt );
151 : }
152 :
153 1406 : long SfxFrameWindow_Impl::PreNotify( NotifyEvent& rNEvt )
154 : {
155 1406 : sal_uInt16 nType = rNEvt.GetType();
156 1406 : if ( nType == EVENT_KEYINPUT || nType == EVENT_KEYUP )
157 : {
158 0 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
159 0 : SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
160 0 : if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
161 0 : return sal_True;
162 : }
163 1406 : else if ( nType == EVENT_MOUSEBUTTONUP || nType == EVENT_MOUSEBUTTONDOWN )
164 : {
165 0 : Window* pWindow = rNEvt.GetWindow();
166 0 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
167 0 : SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
168 0 : if ( pShell )
169 0 : if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) )
170 0 : if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
171 0 : return sal_True;
172 : }
173 :
174 1406 : if ( nType == EVENT_MOUSEBUTTONDOWN )
175 : {
176 0 : Window* pWindow = rNEvt.GetWindow();
177 0 : const MouseEvent* pMEvent = rNEvt.GetMouseEvent();
178 0 : Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() );
179 0 : SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
180 0 : if ( pWorkWin )
181 0 : pWorkWin->EndAutoShow_Impl( aPos );
182 : }
183 :
184 1406 : return Window::PreNotify( rNEvt );
185 : }
186 :
187 364 : void SfxFrameWindow_Impl::GetFocus()
188 : {
189 364 : if ( pFrame && !pFrame->IsClosing_Impl() && pFrame->GetCurrentViewFrame() && pFrame->GetFrameInterface().is() )
190 318 : pFrame->GetCurrentViewFrame()->MakeActive_Impl( sal_True );
191 364 : }
192 :
193 1532 : void SfxFrameWindow_Impl::Resize()
194 : {
195 1532 : if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
196 1016 : DoResize();
197 1532 : }
198 :
199 1256 : void SfxFrameWindow_Impl::StateChanged( StateChangedType nStateChange )
200 : {
201 1256 : if ( nStateChange == STATE_CHANGE_INITSHOW )
202 : {
203 508 : pFrame->pImp->bHidden = sal_False;
204 508 : if ( pFrame->IsInPlace() )
205 : // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the
206 : // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that
207 : // the resize event never is sent to the component
208 0 : SetSizePixel( GetParent()->GetOutputSizePixel() );
209 :
210 508 : DoResize();
211 508 : SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
212 508 : if ( pView )
213 191 : pView->GetBindings().GetWorkWindow_Impl()->ShowChildren_Impl();
214 : }
215 :
216 1256 : Window::StateChanged( nStateChange );
217 1256 : }
218 :
219 1524 : void SfxFrameWindow_Impl::DoResize()
220 : {
221 1524 : if ( !pFrame->pImp->bLockResize )
222 1524 : pFrame->Resize();
223 1524 : }
224 :
225 0 : Reference < XFrame > SfxFrame::CreateBlankFrame()
226 : {
227 0 : Reference < XFrame > xFrame;
228 : try
229 : {
230 0 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
231 0 : Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
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 < XFramesSupplier > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
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 516 : SfxFrame* SfxFrame::Create( const Reference < XFrame >& i_rFrame )
300 : {
301 : // create a new TopFrame to an external XFrame object ( wrap controller )
302 516 : ENSURE_OR_THROW( i_rFrame.is(), "NULL frame not allowed" );
303 516 : Window* pWindow = VCLUnoHelper::GetWindow( i_rFrame->getContainerWindow() );
304 516 : ENSURE_OR_THROW( pWindow, "frame without container window not allowed" );
305 :
306 516 : SfxFrame* pFrame = new SfxFrame( *pWindow, false );
307 516 : pFrame->SetFrameInterface_Impl( i_rFrame );
308 516 : return pFrame;
309 : }
310 :
311 516 : SfxFrame::SfxFrame( Window& i_rContainerWindow, bool i_bHidden )
312 : :pParentFrame( NULL )
313 : ,pChildArr( NULL )
314 : ,pImp( NULL )
315 516 : ,pWindow( NULL )
316 : {
317 516 : Construct_Impl();
318 :
319 516 : pImp->bHidden = i_bHidden;
320 516 : InsertTopFrame_Impl( this );
321 516 : pImp->pExternalContainerWindow = &i_rContainerWindow;
322 :
323 516 : 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 516 : pWindow->Show();
330 516 : }
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 14086 : Window& SfxFrame::GetWindow() const
370 : {
371 14086 : return *pWindow;
372 : }
373 :
374 98 : sal_Bool SfxFrame::Close()
375 : {
376 98 : delete this;
377 98 : 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 1832 : sal_Bool SfxFrame::IsMenuBarOn_Impl() const
410 : {
411 1832 : return pImp->bMenuBarOn;
412 : }
413 :
414 516 : void SfxFrame::PrepareForDoc_Impl( SfxObjectShell& i_rDoc )
415 : {
416 516 : const ::comphelper::NamedValueCollection aDocumentArgs( i_rDoc.GetModel()->getArgs() );
417 :
418 : // hidden?
419 : OSL_ENSURE( !pImp->bHidden, "when does this happen?" );
420 516 : pImp->bHidden = aDocumentArgs.getOrDefault( "Hidden", pImp->bHidden );
421 :
422 : // update our descriptor
423 516 : UpdateDescriptor( &i_rDoc );
424 :
425 : // plugin mode
426 516 : sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
427 516 : if ( nPluginMode && ( nPluginMode != 2 ) )
428 0 : SetInPlace_Impl( sal_True );
429 516 : }
430 :
431 516 : bool SfxFrame::IsMarkedHidden_Impl() const
432 : {
433 516 : return pImp->bHidden;
434 : }
435 :
436 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|