Update ooo320-m1
[ooovba.git] / embeddedobj / source / general / docholder.cxx
blobe6de69c3d79abf28cae74a7e9078b1bb3c883482
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docholder.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
33 #include <com/sun/star/embed/Aspects.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/frame/XComponentLoader.hpp>
36 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
40 #include <com/sun/star/util/XCloseBroadcaster.hpp>
41 #include <com/sun/star/util/XCloseable.hpp>
42 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACESS_HPP_
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #endif
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/NamedValue.hpp>
49 #include <com/sun/star/frame/XModel.hpp>
50 #include <com/sun/star/frame/XDesktop.hpp>
51 #include <com/sun/star/frame/XFramesSupplier.hpp>
52 #include <com/sun/star/frame/XDispatchHelper.hpp>
53 #include <com/sun/star/frame/FrameSearchFlag.hpp>
54 #include <com/sun/star/frame/XControllerBorder.hpp>
55 #include <com/sun/star/util/XModifyBroadcaster.hpp>
56 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
57 #include <com/sun/star/awt/XTopWindow.hpp>
58 #include <com/sun/star/awt/PosSize.hpp>
59 #include <com/sun/star/awt/XView.hpp>
60 #include <com/sun/star/awt/WindowAttribute.hpp>
61 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
62 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
63 #include <com/sun/star/bridge/ModelDependent.hpp>
64 #include <com/sun/star/embed/XHatchWindow.hpp>
65 #include <com/sun/star/embed/XHatchWindowFactory.hpp>
66 #include <com/sun/star/embed/XInplaceClient.hpp>
67 #include <com/sun/star/frame/XLayoutManager.hpp>
68 #include <com/sun/star/frame/XMenuBarMergingAcceptor.hpp>
69 #include <com/sun/star/frame/XModuleManager.hpp>
70 #include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
71 #include <com/sun/star/ui/XUIElementSettings.hpp>
72 #ifndef _COM_SUN_STAR_UI_XCONFIGURATIONMANAGER_HPP_
73 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
74 #endif
75 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
76 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
77 #include <com/sun/star/lang/XServiceInfo.hpp>
78 #include <com/sun/star/embed/StateChangeInProgressException.hpp>
80 #include <com/sun/star/embed/EmbedMisc.hpp>
81 #include <com/sun/star/embed/EmbedStates.hpp>
82 #include <osl/diagnose.h>
83 #include <rtl/process.h>
85 #include <comphelper/processfactory.hxx>
87 #include "docholder.hxx"
88 #include "commonembobj.hxx"
89 #include "intercept.hxx"
92 // #include <toolkit/helper/vclunohelper.hxx>
93 // #include <vcl/window.hxx>
95 #define HATCH_BORDER_WIDTH (((m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) && \
96 m_pEmbedObj->getCurrentState()!=embed::EmbedStates::UI_ACTIVE) ? 0 : 4 )
98 using namespace ::com::sun::star;
100 //===========================================================================
102 class IntCounterGuard {
103 sal_Int32& m_nFlag;
104 public:
105 IntCounterGuard( sal_Int32& nFlag )
106 : m_nFlag( nFlag )
108 m_nFlag++;
111 ~IntCounterGuard()
113 if ( m_nFlag )
114 m_nFlag--;
118 //===========================================================================
120 static void InsertMenu_Impl( const uno::Reference< container::XIndexContainer >& xTargetMenu,
121 sal_Int32 nTargetIndex,
122 const uno::Reference< container::XIndexAccess >& xSourceMenu,
123 sal_Int32 nSourceIndex,
124 const ::rtl::OUString aContModuleName,
125 const uno::Reference< frame::XDispatchProvider >& xSourceDisp )
127 sal_Int32 nInd = 0;
128 ::rtl::OUString aModuleIdentPropName( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ) );
129 ::rtl::OUString aDispProvPropName( RTL_CONSTASCII_USTRINGPARAM( "DispatchProvider" ) );
130 sal_Bool bModuleNameSet = sal_False;
131 sal_Bool bDispProvSet = sal_False;
133 uno::Sequence< beans::PropertyValue > aSourceProps;
134 xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps;
135 uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() );
136 for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ )
138 aTargetProps[nInd].Name = aSourceProps[nInd].Name;
139 if ( aContModuleName.getLength() && aTargetProps[nInd].Name.equals( aModuleIdentPropName ) )
141 aTargetProps[nInd].Value <<= aContModuleName;
142 bModuleNameSet = sal_True;
144 else if ( aTargetProps[nInd].Name.equals( aDispProvPropName ) )
146 aTargetProps[nInd].Value <<= xSourceDisp;
147 bDispProvSet = sal_True;
149 else
150 aTargetProps[nInd].Value = aSourceProps[nInd].Value;
153 if ( !bModuleNameSet && aContModuleName.getLength() )
155 aTargetProps.realloc( ++nInd );
156 aTargetProps[nInd-1].Name = aModuleIdentPropName;
157 aTargetProps[nInd-1].Value <<= aContModuleName;
160 if ( !bDispProvSet && xSourceDisp.is() )
162 aTargetProps.realloc( ++nInd );
163 aTargetProps[nInd-1].Name = aDispProvPropName;
164 aTargetProps[nInd-1].Value <<= xSourceDisp;
167 xTargetMenu->insertByIndex( nTargetIndex, uno::makeAny( aTargetProps ) );
170 //===========================================================================
171 DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
172 OCommonEmbeddedObject* pEmbObj )
173 : m_pEmbedObj( pEmbObj ),
174 m_pInterceptor( NULL ),
175 m_xFactory( xFactory ),
176 m_bReadOnly( sal_False ),
177 m_bWaitForClose( sal_False ),
178 m_bAllowClosing( sal_False ),
179 m_bDesktopTerminated( sal_False ),
180 m_nNoBorderResizeReact( 0 ),
181 m_nNoResizeReact( 0 )
183 m_aOutplaceFrameProps.realloc( 3 );
184 beans::NamedValue aArg;
186 aArg.Name = ::rtl::OUString::createFromAscii("TopWindow");
187 aArg.Value <<= sal_True;
188 m_aOutplaceFrameProps[0] <<= aArg;
190 aArg.Name = ::rtl::OUString::createFromAscii("MakeVisible");
191 aArg.Value <<= sal_False;
192 m_aOutplaceFrameProps[1] <<= aArg;
194 const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
195 uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
196 if ( xDesktop.is() )
198 m_refCount++;
201 xDesktop->addTerminateListener( this );
203 catch ( uno::Exception& )
206 m_refCount--;
208 aArg.Name = ::rtl::OUString::createFromAscii("ParentFrame");
209 aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame
210 m_aOutplaceFrameProps[2] <<= aArg;
212 else
213 m_aOutplaceFrameProps.realloc( 2 );
216 //---------------------------------------------------------------------------
217 DocumentHolder::~DocumentHolder()
219 m_refCount++; // to allow deregistration as a listener
221 if( m_xFrame.is() )
222 CloseFrame();
224 if ( m_xComponent.is() )
226 try {
227 CloseDocument( sal_True, sal_False );
228 } catch( uno::Exception& ) {}
231 if ( m_pInterceptor )
233 m_pInterceptor->DisconnectDocHolder();
234 m_pInterceptor->release();
237 if ( !m_bDesktopTerminated )
238 FreeOffice();
241 //---------------------------------------------------------------------------
242 void DocumentHolder::CloseFrame()
244 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
245 if ( xCloseBroadcaster.is() )
246 xCloseBroadcaster->removeCloseListener( ( util::XCloseListener* )this );
248 uno::Reference<util::XCloseable> xCloseable(
249 m_xFrame,uno::UNO_QUERY );
250 if( xCloseable.is() )
251 try {
252 xCloseable->close( sal_True );
254 catch( const uno::Exception& ) {
256 else {
257 uno::Reference<lang::XComponent> xComp( m_xFrame,uno::UNO_QUERY );
258 if( xComp.is() )
259 xComp->dispose();
262 uno::Reference< lang::XComponent > xComp( m_xHatchWindow, uno::UNO_QUERY );
263 if ( xComp.is() )
264 xComp->dispose();
266 m_xHatchWindow = uno::Reference< awt::XWindow >();
267 m_xOwnWindow = uno::Reference< awt::XWindow >();
268 m_xFrame = uno::Reference< frame::XFrame >();
271 //---------------------------------------------------------------------------
272 void DocumentHolder::FreeOffice()
274 const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
275 uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
276 if ( xDesktop.is() )
278 xDesktop->removeTerminateListener( this );
280 // the following code is commented out since for now there is still no completely correct way to detect
281 // whether the office can be terminated, so it is better to have unnecessary process running than
282 // to loose any data
284 // uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY );
285 // if ( xFramesSupplier.is() )
286 // {
287 // uno::Reference< frame::XFrames > xFrames = xFramesSupplier->getFrames();
288 // if ( xFrames.is() && !xFrames->hasElements() )
289 // {
290 // try
291 // {
292 // xDesktop->terminate();
293 // }
294 // catch( uno::Exception & )
295 // {}
296 // }
297 // }
301 //---------------------------------------------------------------------------
302 void DocumentHolder::CloseDocument( sal_Bool bDeliverOwnership, sal_Bool bWaitForClose )
304 uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
305 if ( xBroadcaster.is() )
307 uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
308 if ( xEventBroadcaster.is() )
309 xEventBroadcaster->removeEventListener( ( document::XEventListener* )this );
310 else
312 // the object does not support document::XEventBroadcaster interface
313 // use the workaround, register for modified events
314 uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
315 if ( xModifyBroadcaster.is() )
316 xModifyBroadcaster->removeModifyListener( ( util::XModifyListener* )this );
319 uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY );
320 if ( xCloseable.is() )
322 m_bAllowClosing = sal_True;
323 m_bWaitForClose = bWaitForClose;
324 xCloseable->close( bDeliverOwnership );
328 m_xComponent = 0;
331 //---------------------------------------------------------------------------
332 void DocumentHolder::PlaceFrame( const awt::Rectangle& aNewRect )
334 OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is(),
335 "The object does not have windows required for inplace mode!" );
337 //TODO: may need mutex locking???
338 if ( m_xFrame.is() && m_xOwnWindow.is() )
340 // the frame can be replaced only in inplace mode
341 frame::BorderWidths aOldWidths;
342 IntCounterGuard aGuard( m_nNoBorderResizeReact );
346 aOldWidths = m_aBorderWidths;
348 awt::Rectangle aHatchRect = AddBorderToArea( aNewRect );
350 ResizeWindows_Impl( aHatchRect );
352 } while ( aOldWidths.Left != m_aBorderWidths.Left
353 || aOldWidths.Top != m_aBorderWidths.Top
354 || aOldWidths.Right != m_aBorderWidths.Right
355 || aOldWidths.Bottom != m_aBorderWidths.Bottom );
357 m_aObjRect = aNewRect;
361 //---------------------------------------------------------------------------
362 void DocumentHolder::ResizeWindows_Impl( const awt::Rectangle& aHatchRect )
364 OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is() /*&& m_xHatchWindow.is()*/,
365 "The object does not have windows required for inplace mode!" );
366 if ( m_xHatchWindow.is() )
368 m_xOwnWindow->setPosSize( HATCH_BORDER_WIDTH,
369 HATCH_BORDER_WIDTH,
370 aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
371 aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
372 awt::PosSize::POSSIZE );
374 // Window* pWindow = VCLUnoHelper::GetWindow( m_xOwnWindow );
376 m_xHatchWindow->setPosSize( aHatchRect.X,
377 aHatchRect.Y,
378 aHatchRect.Width,
379 aHatchRect.Height,
380 awt::PosSize::POSSIZE );
382 else
383 m_xOwnWindow->setPosSize( aHatchRect.X + HATCH_BORDER_WIDTH,
384 aHatchRect.Y + HATCH_BORDER_WIDTH,
385 aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
386 aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
387 awt::PosSize::POSSIZE );
390 //---------------------------------------------------------------------------
391 sal_Bool DocumentHolder::SetFrameLMVisibility( const uno::Reference< frame::XFrame >& xFrame, sal_Bool bVisible )
393 sal_Bool bResult = sal_False;
397 uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
398 uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY_THROW );
399 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager;
400 if ( xLayoutManager.is() )
402 xLayoutManager->setVisible( bVisible );
404 // MBA: locking is done only on the container LM, because it is not about hiding windows, it's about
405 // giving up control over the component window (and stopping to listen for resize events of the container window)
406 if ( bVisible )
407 xLayoutManager->unlock();
408 else
409 xLayoutManager->lock();
411 bResult = sal_True;
414 catch( uno::Exception& )
417 return bResult;
420 //---------------------------------------------------------------------------
421 sal_Bool DocumentHolder::ShowInplace( const uno::Reference< awt::XWindowPeer >& xParent,
422 const awt::Rectangle& aRectangleToShow,
423 const uno::Reference< frame::XDispatchProvider >& xContDisp )
425 OSL_ENSURE( !m_xFrame.is(), "A frame exists already!" );
427 if ( !m_xFrame.is() )
429 uno::Reference < frame::XModel > xModel( GetComponent(), uno::UNO_QUERY );
430 awt::Rectangle aHatchRectangle = AddBorderToArea( aRectangleToShow );
432 awt::Rectangle aOwnRectangle( HATCH_BORDER_WIDTH,
433 HATCH_BORDER_WIDTH,
434 aHatchRectangle.Width - 2*HATCH_BORDER_WIDTH,
435 aHatchRectangle.Height - 2*HATCH_BORDER_WIDTH );
436 uno::Reference< awt::XWindow > xHWindow;
437 uno::Reference< awt::XWindowPeer > xMyParent( xParent );
439 if ( xModel.is() )
442 uno::Reference< embed::XHatchWindowFactory > xHatchFactory(
443 m_xFactory->createInstance(
444 ::rtl::OUString::createFromAscii( "com.sun.star.embed.HatchWindowFactory" ) ),
445 uno::UNO_QUERY );
447 if ( !xHatchFactory.is() )
448 throw uno::RuntimeException();
450 uno::Reference< embed::XHatchWindow > xHatchWindow =
451 xHatchFactory->createHatchWindowInstance( xParent,
452 aHatchRectangle,
453 awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
455 uno::Reference< awt::XWindowPeer > xHatchWinPeer( xHatchWindow, uno::UNO_QUERY );
456 xHWindow = uno::Reference< awt::XWindow >( xHatchWinPeer, uno::UNO_QUERY );
457 if ( !xHWindow.is() )
458 throw uno::RuntimeException(); // TODO: can not create own window
460 xHatchWindow->setController( uno::Reference< embed::XHatchWindowController >(
461 static_cast< embed::XHatchWindowController* >( this ) ) );
463 xMyParent = xHatchWinPeer;
465 else
467 aOwnRectangle.X += aHatchRectangle.X;
468 aOwnRectangle.Y += aHatchRectangle.Y;
471 awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_TOP,
472 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("dockingwindow") ),
473 xMyParent,
475 awt::Rectangle(),//aOwnRectangle,
476 awt::WindowAttribute::SHOW | awt::VclWindowPeerAttribute::CLIPCHILDREN );
478 uno::Reference< awt::XToolkit > xToolkit(
479 m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.awt.Toolkit" ) ),
480 uno::UNO_QUERY );
481 if ( !xToolkit.is() )
482 throw uno::RuntimeException();
484 uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor );
485 uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY );
486 if ( !xOwnWindow.is() )
487 throw uno::RuntimeException(); // TODO: can not create own window
489 // create a frame based on the specified window
490 uno::Reference< lang::XSingleServiceFactory > xFrameFact(
491 m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.TaskCreator" ) ),
492 uno::UNO_QUERY_THROW );
494 uno::Sequence< uno::Any > aArgs( 2 );
495 beans::NamedValue aArg;
497 aArg.Name = ::rtl::OUString::createFromAscii("ContainerWindow");
498 aArg.Value <<= xOwnWindow;
499 aArgs[0] <<= aArg;
501 uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
502 if ( xContFrame.is() )
504 aArg.Name = ::rtl::OUString::createFromAscii("ParentFrame");
505 aArg.Value <<= xContFrame;
506 aArgs[1] <<= aArg;
508 else
509 aArgs.realloc( 1 );
511 // the call will create, initialize the frame, and register it in the parent
512 m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW );
514 m_xHatchWindow = xHWindow;
515 m_xOwnWindow = xOwnWindow;
517 if ( !SetFrameLMVisibility( m_xFrame, sal_False ) )
519 OSL_ENSURE( sal_False, "Can't deactivate LayoutManager!\n" );
520 // TODO/LATER: error handling?
523 // m_bIsInplace = sal_True; TODO: ?
525 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
526 if ( xCloseBroadcaster.is() )
527 xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this );
529 // TODO: some listeners to the frame and the window ( resize for example )
532 if ( m_xComponent.is() )
534 if ( !LoadDocToFrame( sal_True ) )
536 CloseFrame();
537 return sal_False;
540 uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
541 if ( xControllerBorder.is() )
543 m_aBorderWidths = xControllerBorder->getBorder();
544 xControllerBorder->addBorderResizeListener( (frame::XBorderResizeListener*)this );
547 PlaceFrame( aRectangleToShow );
549 if ( m_xHatchWindow.is() )
550 m_xHatchWindow->setVisible( sal_True );
552 return sal_True;
555 return sal_False;
558 //---------------------------------------------------------------------------
559 uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl()
561 uno::Reference< container::XIndexAccess > xResult;
563 uno::Reference< ::com::sun::star::ui::XUIConfigurationManagerSupplier > xUIConfSupplier(
564 m_xComponent,
565 uno::UNO_QUERY );
566 uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xUIConfigManager;
567 if( xUIConfSupplier.is())
569 xUIConfigManager.set(
570 xUIConfSupplier->getUIConfigurationManager(),
571 uno::UNO_QUERY_THROW );
576 if( xUIConfigManager.is())
578 xResult = xUIConfigManager->getSettings(
579 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ),
580 sal_False );
583 catch( uno::Exception )
586 if ( !xResult.is() )
588 // no internal document configuration, use the one from the module
589 uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleMan(
590 m_xFactory->createInstance(
591 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
592 uno::UNO_QUERY_THROW );
593 ::rtl::OUString aModuleIdent =
594 xModuleMan->identify( uno::Reference< uno::XInterface >( m_xComponent, uno::UNO_QUERY ) );
596 if ( aModuleIdent.getLength() )
598 uno::Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModConfSupplier(
599 m_xFactory->createInstance( ::rtl::OUString(
600 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ),
601 uno::UNO_QUERY_THROW );
602 uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xModUIConfMan(
603 xModConfSupplier->getUIConfigurationManager( aModuleIdent ),
604 uno::UNO_QUERY_THROW );
605 xResult = xModUIConfMan->getSettings(
606 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ),
607 sal_False );
611 if ( !xResult.is() )
612 throw uno::RuntimeException();
614 return xResult;
617 //---------------------------------------------------------------------------
618 void DocumentHolder::FindConnectPoints(
619 const uno::Reference< container::XIndexAccess >& xMenu,
620 sal_Int32 nConnectPoints[2] )
621 throw ( uno::Exception )
623 nConnectPoints[0] = -1;
624 nConnectPoints[1] = -1;
625 for ( sal_Int32 nInd = 0; nInd < xMenu->getCount(); nInd++ )
627 uno::Sequence< beans::PropertyValue > aProps;
628 xMenu->getByIndex( nInd ) >>= aProps;
629 rtl::OUString aCommand;
630 for ( sal_Int32 nSeqInd = 0; nSeqInd < aProps.getLength(); nSeqInd++ )
631 if ( aProps[nSeqInd].Name.equalsAscii( "CommandURL" ) )
633 aProps[nSeqInd].Value >>= aCommand;
634 break;
637 if ( !aCommand.getLength() )
638 throw uno::RuntimeException();
640 if ( aCommand.equalsAscii( ".uno:PickList" ) )
641 nConnectPoints[0] = nInd;
642 else if ( aCommand.equalsAscii( ".uno:WindowList" ) )
643 nConnectPoints[1] = nInd;
647 //---------------------------------------------------------------------------
648 uno::Reference< container::XIndexAccess > DocumentHolder::MergeMenuesForInplace(
649 const uno::Reference< container::XIndexAccess >& xContMenu,
650 const uno::Reference< frame::XDispatchProvider >& xContDisp,
651 const ::rtl::OUString& aContModuleName,
652 const uno::Reference< container::XIndexAccess >& xOwnMenu,
653 const uno::Reference< frame::XDispatchProvider >& xOwnDisp )
654 throw ( uno::Exception )
656 // TODO/LATER: use dispatch providers on merge
658 sal_Int32 nContPoints[2];
659 sal_Int32 nOwnPoints[2];
661 uno::Reference< lang::XSingleComponentFactory > xIndAccessFact( xContMenu, uno::UNO_QUERY_THROW );
663 uno::Reference< uno::XComponentContext > xComponentContext;
665 uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
666 if ( xProps.is() )
667 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>=
668 xComponentContext;
670 uno::Reference< container::XIndexContainer > xMergedMenu(
671 xIndAccessFact->createInstanceWithContext( xComponentContext ),
672 uno::UNO_QUERY_THROW );
674 FindConnectPoints( xContMenu, nContPoints );
675 FindConnectPoints( xOwnMenu, nOwnPoints );
677 for ( sal_Int32 nInd = 0; nInd < xOwnMenu->getCount(); nInd++ )
679 if ( nOwnPoints[0] == nInd )
681 if ( nContPoints[0] >= 0 && nContPoints[0] < xContMenu->getCount() )
683 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[0], aContModuleName, xContDisp );
686 else if ( nOwnPoints[1] == nInd )
688 if ( nContPoints[1] >= 0 && nContPoints[1] < xContMenu->getCount() )
690 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[1], aContModuleName, xContDisp );
693 else
694 InsertMenu_Impl( xMergedMenu, nInd, xOwnMenu, nInd, ::rtl::OUString(), xOwnDisp );
697 return uno::Reference< container::XIndexAccess >( xMergedMenu, uno::UNO_QUERY_THROW );
700 //---------------------------------------------------------------------------
701 sal_Bool DocumentHolder::MergeMenues_Impl( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xOwnLM,
702 const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContLM,
703 const uno::Reference< frame::XDispatchProvider >& xContDisp,
704 const ::rtl::OUString& aContModuleName )
706 sal_Bool bMenuMerged = sal_False;
709 uno::Reference< ::com::sun::star::ui::XUIElementSettings > xUISettings(
710 xContLM->getElement(
711 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ) ),
712 uno::UNO_QUERY_THROW );
713 uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings( sal_True );
714 if ( !xContMenu.is() )
715 throw uno::RuntimeException();
717 uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl();
718 uno::Reference< frame::XDispatchProvider > xOwnDisp( m_xFrame, uno::UNO_QUERY_THROW );
720 uno::Reference< container::XIndexAccess > xMergedMenu = MergeMenuesForInplace( xContMenu, xContDisp, aContModuleName, xOwnMenu, xOwnDisp );
721 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM,
722 uno::UNO_QUERY_THROW );
723 bMenuMerged = xMerge->setMergedMenuBar( xMergedMenu );
725 catch( uno::Exception& )
728 return bMenuMerged;
731 sal_Bool DocumentHolder::ShowUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM,
732 const uno::Reference< frame::XDispatchProvider >& xContainerDP,
733 const ::rtl::OUString& aContModuleName )
735 sal_Bool bResult = sal_False;
736 if ( xContainerLM.is() )
738 // the LM of the embedded frame and its current DockingAreaAcceptor
739 uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
740 uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc;
744 uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
745 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
746 xDocAreaAcc = xContainerLM->getDockingAreaAcceptor();
748 catch( uno::Exception& ){}
750 // make sure that lock state of LM is correct even if an exception is thrown in between
751 sal_Bool bUnlock = sal_False;
752 sal_Bool bLock = sal_False;
753 if ( xOwnLM.is() && xDocAreaAcc.is() )
757 // take over the control over the containers window
758 // as long as the LM is invisible and locked an empty tool space will be used on resizing
759 xOwnLM->setDockingAreaAcceptor( xDocAreaAcc );
761 // try to merge menues; don't do anything else if it fails
762 if ( MergeMenues_Impl( xOwnLM, xContainerLM, xContainerDP, aContModuleName ) )
764 // make sure that the container LM does not control the size of the containers window anymore
765 // this must be done after merging menues as we won't get the container menu otherwise
766 xContainerLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
768 // prevent further changes at this LM
769 xContainerLM->setVisible( sal_False );
770 xContainerLM->lock();
771 bUnlock = sal_True;
773 // by unlocking the LM each layout change will now resize the containers window; pending layouts will be processed now
774 xOwnLM->setVisible( sal_True );
776 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
777 if ( xSupp.is() )
778 xSupp->setActiveFrame( m_xFrame );
780 xOwnLM->unlock();
781 bLock = sal_True;
782 bResult = sal_True;
784 // TODO/LATER: The following action should be done only if the window is not hidden
785 // otherwise the activation must fail, unfortunatelly currently it is not possible
786 // to detect whether the window is hidden using UNO API
787 m_xOwnWindow->setFocus();
790 catch( uno::Exception& )
792 // activation failed; reestablish old state
795 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
796 if ( xSupp.is() )
797 xSupp->setActiveFrame( 0 );
799 // remove control about containers window from own LM
800 if ( bLock )
801 xOwnLM->lock();
802 xOwnLM->setVisible( sal_False );
803 xOwnLM->setDockingAreaAcceptor( uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor >() );
805 // unmerge menu
806 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
807 xMerge->removeMergedMenuBar();
809 catch( uno::Exception& ) {}
813 // reestablish control of containers window
814 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
815 xContainerLM->setVisible( sal_True );
816 if ( bUnlock )
817 xContainerLM->unlock();
819 catch( uno::Exception& ) {}
824 return bResult;
827 //---------------------------------------------------------------------------
828 sal_Bool DocumentHolder::HideUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM )
830 sal_Bool bResult = sal_False;
832 if ( xContainerLM.is() )
834 uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
836 try {
837 uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
838 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
839 } catch( uno::Exception& )
842 if ( xOwnLM.is() )
844 try {
845 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
846 if ( xSupp.is() )
847 xSupp->setActiveFrame( 0 );
849 uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc = xOwnLM->getDockingAreaAcceptor();
851 xOwnLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
852 xOwnLM->lock();
853 xOwnLM->setVisible( sal_False );
855 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
856 xMerge->removeMergedMenuBar();
858 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
859 xContainerLM->setVisible( sal_True );
860 xContainerLM->unlock();
862 xContainerLM->doLayout();
863 bResult = sal_True;
865 catch( uno::Exception& )
867 SetFrameLMVisibility( m_xFrame, sal_True );
872 return bResult;
875 //---------------------------------------------------------------------------
876 uno::Reference< frame::XFrame > DocumentHolder::GetDocFrame()
878 // the frame for outplace activation
879 if ( !m_xFrame.is() )
881 uno::Reference< lang::XSingleServiceFactory > xFrameFact(
882 m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.TaskCreator" ) ),
883 uno::UNO_QUERY_THROW );
885 m_xFrame.set(xFrameFact->createInstanceWithArguments( m_aOutplaceFrameProps ), uno::UNO_QUERY_THROW);
887 uno::Reference< frame::XDispatchProviderInterception > xInterception( m_xFrame, uno::UNO_QUERY );
888 if ( xInterception.is() )
890 if ( m_pInterceptor )
892 m_pInterceptor->DisconnectDocHolder();
893 m_pInterceptor->release();
894 m_pInterceptor = NULL;
897 m_pInterceptor = new Interceptor( this );
898 m_pInterceptor->acquire();
900 // register interceptor from outside
901 if ( m_xOutplaceInterceptor.is() )
902 xInterception->registerDispatchProviderInterceptor( m_xOutplaceInterceptor );
904 xInterception->registerDispatchProviderInterceptor( m_pInterceptor );
907 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
908 if ( xCloseBroadcaster.is() )
909 xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this );
912 if ( m_xComponent.is() )
914 uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
915 try {
916 uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
917 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
918 } catch( uno::Exception& )
921 if ( xOwnLM.is() )
922 xOwnLM->lock();
924 // TODO/LATER: get it for the real aspect
925 awt::Size aSize;
926 GetExtent( embed::Aspects::MSOLE_CONTENT, &aSize );
927 LoadDocToFrame(sal_False);
929 if ( xOwnLM.is() )
931 xOwnLM->unlock();
932 xOwnLM->lock();
935 SetExtent( embed::Aspects::MSOLE_CONTENT, aSize );
937 if ( xOwnLM.is() )
938 xOwnLM->unlock();
943 uno::Reference< awt::XWindow > xHWindow = m_xFrame->getContainerWindow();
945 if( xHWindow.is() )
947 uno::Reference< beans::XPropertySet > xMonProps( m_xFactory->createInstance(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), uno::UNO_QUERY_THROW );
948 const rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) );
949 sal_Int32 nDisplay = 0;
950 xMonProps->getPropertyValue( sPropName ) >>= nDisplay;
952 uno::Reference< container::XIndexAccess > xMultiMon( xMonProps, uno::UNO_QUERY_THROW );
953 uno::Reference< beans::XPropertySet > xMonitor( xMultiMon->getByIndex( nDisplay ), uno::UNO_QUERY_THROW );
954 awt::Rectangle aWorkRect;
955 xMonitor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WorkArea" ) ) ) >>= aWorkRect;
956 awt::Rectangle aWindowRect = xHWindow->getPosSize();
958 if (( aWindowRect.Width < aWorkRect.Width) && ( aWindowRect.Height < aWorkRect.Height ))
960 int OffsetX = ( aWorkRect.Width - aWindowRect.Width ) / 2 + aWorkRect.X;
961 int OffsetY = ( aWorkRect.Height - aWindowRect.Height ) /2 + aWorkRect.Y;
962 xHWindow->setPosSize( OffsetX, OffsetY, aWindowRect.Width, aWindowRect.Height, awt::PosSize::POS );
964 else
966 xHWindow->setPosSize( aWorkRect.X, aWorkRect.Y, aWorkRect.Width, aWorkRect.Height, awt::PosSize::POSSIZE );
969 xHWindow->setVisible( sal_True );
972 catch ( uno::Exception& )
976 return m_xFrame;
979 //---------------------------------------------------------------------------
980 void DocumentHolder::SetComponent( const uno::Reference< util::XCloseable >& xDoc, sal_Bool bReadOnly )
982 if ( m_xComponent.is() )
984 // May be should be improved
985 try {
986 CloseDocument( sal_True, sal_False );
987 } catch( uno::Exception& )
991 m_xComponent = xDoc;
992 // done outside currently uno::Reference < container::XChild > xChild( m_xComponent, uno::UNO_QUERY );
993 // done outside currently if ( xChild.is() && m_pEmbedObj )
994 // done outside currently xChild->setParent( m_pEmbedObj->getParent() );
996 m_bReadOnly = bReadOnly;
997 m_bAllowClosing = sal_False;
999 uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
1000 if ( xBroadcaster.is() )
1001 xBroadcaster->addCloseListener( ( util::XCloseListener* )this );
1003 uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
1004 if ( xEventBroadcaster.is() )
1005 xEventBroadcaster->addEventListener( ( document::XEventListener* )this );
1006 else
1008 // the object does not support document::XEventBroadcaster interface
1009 // use the workaround, register for modified events
1010 uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
1011 if ( xModifyBroadcaster.is() )
1012 xModifyBroadcaster->addModifyListener( ( util::XModifyListener* )this );
1015 if ( m_xFrame.is() )
1016 LoadDocToFrame(sal_False);
1019 //---------------------------------------------------------------------------
1020 sal_Bool DocumentHolder::LoadDocToFrame( sal_Bool bInPlace )
1022 if ( m_xFrame.is() && m_xComponent.is() )
1024 uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
1025 if ( xDoc.is() )
1027 // load new document in to the frame
1028 uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY );
1029 if( !xComponentLoader.is() )
1030 throw uno::RuntimeException();
1032 uno::Sequence< beans::PropertyValue > aArgs(3);
1033 aArgs[0].Name = ::rtl::OUString::createFromAscii( "Model" );
1034 aArgs[0].Value <<= m_xComponent;
1035 aArgs[1].Name = ::rtl::OUString::createFromAscii( "ReadOnly" );
1036 aArgs[1].Value <<= m_bReadOnly;
1037 aArgs[2].Name = ::rtl::OUString::createFromAscii( "PluginMode" );
1038 aArgs[2].Value <<= sal_Int16(bInPlace ? 1 : 2);
1039 ::rtl::OUString sUrl;
1040 uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
1041 if ( xServiceInfo.is()
1042 && xServiceInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportDefinition"))) )
1044 sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".component:DB/ReportDesign"));
1046 else if( xServiceInfo.is()
1047 && xServiceInfo->supportsService( ::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartDocument")) )
1048 sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/schart"));
1049 else
1050 sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:object"));
1052 xComponentLoader->loadComponentFromURL( sUrl,
1053 rtl::OUString::createFromAscii( "_self" ),
1055 aArgs );
1057 return sal_True;
1059 else
1061 uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY );
1062 if ( xLoader.is() )
1063 return xLoader->load( uno::Sequence < beans::PropertyValue >(), m_xFrame );
1064 else
1065 return sal_False;
1069 return sal_True;
1072 //---------------------------------------------------------------------------
1073 void DocumentHolder::Show()
1075 if( m_xFrame.is() )
1077 m_xFrame->activate();
1078 uno::Reference<awt::XTopWindow> xTopWindow( m_xFrame->getContainerWindow(), uno::UNO_QUERY );
1079 if( xTopWindow.is() )
1080 xTopWindow->toFront();
1082 else
1083 GetDocFrame();
1086 //---------------------------------------------------------------------------
1087 sal_Bool DocumentHolder::SetExtent( sal_Int64 nAspect, const awt::Size& aSize )
1089 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1090 if ( xDocVis.is() )
1094 xDocVis->setVisualAreaSize( nAspect, aSize );
1095 return sal_True;
1097 catch( uno::Exception& )
1099 // TODO: Error handling
1103 return sal_False;
1106 //---------------------------------------------------------------------------
1107 sal_Bool DocumentHolder::GetExtent( sal_Int64 nAspect, awt::Size *pSize )
1109 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1110 if ( pSize && xDocVis.is() )
1114 *pSize = xDocVis->getVisualAreaSize( nAspect );
1115 return sal_True;
1117 catch( uno::Exception& )
1119 // TODO: Error handling
1123 return sal_False;
1126 //---------------------------------------------------------------------------
1127 sal_Int32 DocumentHolder::GetMapUnit( sal_Int64 nAspect )
1129 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1130 if ( xDocVis.is() )
1134 return xDocVis->getMapUnit( nAspect );
1136 catch( uno::Exception& )
1138 // TODO: Error handling
1142 return 0;
1145 //---------------------------------------------------------------------------
1146 awt::Rectangle DocumentHolder::CalculateBorderedArea( const awt::Rectangle& aRect )
1148 return awt::Rectangle( aRect.X + m_aBorderWidths.Left + HATCH_BORDER_WIDTH,
1149 aRect.Y + m_aBorderWidths.Top + HATCH_BORDER_WIDTH,
1150 aRect.Width - m_aBorderWidths.Left - m_aBorderWidths.Right - 2*HATCH_BORDER_WIDTH,
1151 aRect.Height - m_aBorderWidths.Top - m_aBorderWidths.Bottom - 2*HATCH_BORDER_WIDTH );
1154 //---------------------------------------------------------------------------
1155 awt::Rectangle DocumentHolder::AddBorderToArea( const awt::Rectangle& aRect )
1157 return awt::Rectangle( aRect.X - m_aBorderWidths.Left - HATCH_BORDER_WIDTH,
1158 aRect.Y - m_aBorderWidths.Top - HATCH_BORDER_WIDTH,
1159 aRect.Width + m_aBorderWidths.Left + m_aBorderWidths.Right + 2*HATCH_BORDER_WIDTH,
1160 aRect.Height + m_aBorderWidths.Top + m_aBorderWidths.Bottom + 2*HATCH_BORDER_WIDTH );
1163 //---------------------------------------------------------------------------
1164 void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource )
1165 throw (uno::RuntimeException)
1167 if ( m_xComponent.is() && m_xComponent == aSource.Source )
1169 m_xComponent = 0;
1170 if ( m_bWaitForClose )
1172 m_bWaitForClose = sal_False;
1173 FreeOffice();
1177 if( m_xFrame.is() && m_xFrame == aSource.Source )
1179 m_xHatchWindow = uno::Reference< awt::XWindow >();
1180 m_xOwnWindow = uno::Reference< awt::XWindow >();
1181 m_xFrame = uno::Reference< frame::XFrame >();
1186 //---------------------------------------------------------------------------
1187 void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool /*bGetsOwnership*/ )
1188 throw (util::CloseVetoException, uno::RuntimeException)
1190 if ( m_xComponent.is() && m_xComponent == aSource.Source && !m_bAllowClosing )
1191 throw util::CloseVetoException();
1194 //---------------------------------------------------------------------------
1195 void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
1196 throw (uno::RuntimeException)
1198 if ( m_xComponent.is() && m_xComponent == aSource.Source )
1200 m_xComponent = 0;
1201 if ( m_bWaitForClose )
1203 m_bWaitForClose = sal_False;
1204 FreeOffice();
1208 if( m_xFrame.is() && m_xFrame == aSource.Source )
1210 m_xHatchWindow = uno::Reference< awt::XWindow >();
1211 m_xOwnWindow = uno::Reference< awt::XWindow >();
1212 m_xFrame = uno::Reference< frame::XFrame >();
1216 //---------------------------------------------------------------------------
1217 void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& )
1218 throw (frame::TerminationVetoException, uno::RuntimeException)
1220 if ( m_bWaitForClose )
1221 throw frame::TerminationVetoException();
1224 //---------------------------------------------------------------------------
1225 void SAL_CALL DocumentHolder::notifyTermination( const lang::EventObject& aSource )
1226 throw (uno::RuntimeException)
1228 OSL_ENSURE( !m_xComponent.is(), "Just a disaster..." );
1230 uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY );
1231 m_bDesktopTerminated = sal_True;
1232 if ( xDesktop.is() )
1233 xDesktop->removeTerminateListener( ( frame::XTerminateListener* )this );
1236 //---------------------------------------------------------------------------
1237 void SAL_CALL DocumentHolder::modified( const lang::EventObject& aEvent )
1238 throw ( uno::RuntimeException )
1240 // if the component does not support document::XEventBroadcaster
1241 // the modify notifications are used as workaround, but only for running state
1242 if( aEvent.Source == m_xComponent && m_pEmbedObj && m_pEmbedObj->getCurrentState() == embed::EmbedStates::RUNNING )
1243 m_pEmbedObj->PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ), aEvent.Source );
1246 //---------------------------------------------------------------------------
1247 void SAL_CALL DocumentHolder::notifyEvent( const document::EventObject& Event )
1248 throw ( uno::RuntimeException )
1250 if( m_pEmbedObj && Event.Source == m_xComponent )
1252 // for now the ignored events are not forwarded, but sent by the object itself
1253 if ( !Event.EventName.equalsAscii( "OnSave" )
1254 && !Event.EventName.equalsAscii( "OnSaveDone" )
1255 && !Event.EventName.equalsAscii( "OnSaveAs" )
1256 && !Event.EventName.equalsAscii( "OnSaveAsDone" )
1257 && !( Event.EventName.equalsAscii( "OnVisAreaChanged" ) && m_nNoResizeReact ) )
1258 m_pEmbedObj->PostEvent_Impl( Event.EventName, Event.Source );
1262 //---------------------------------------------------------------------------
1263 void SAL_CALL DocumentHolder::borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject,
1264 const frame::BorderWidths& aNewSize )
1265 throw ( uno::RuntimeException )
1267 // TODO: may require mutex introduction ???
1268 if ( m_pEmbedObj && m_xFrame.is() && aObject == m_xFrame->getController() )
1270 if ( m_aBorderWidths.Left != aNewSize.Left
1271 || m_aBorderWidths.Right != aNewSize.Right
1272 || m_aBorderWidths.Top != aNewSize.Top
1273 || m_aBorderWidths.Bottom != aNewSize.Bottom )
1275 m_aBorderWidths = aNewSize;
1276 if ( !m_nNoBorderResizeReact )
1277 PlaceFrame( m_aObjRect );
1282 //---------------------------------------------------------------------------
1283 void SAL_CALL DocumentHolder::requestPositioning( const awt::Rectangle& aRect )
1284 throw (uno::RuntimeException)
1286 // TODO: may require mutex introduction ???
1287 if ( m_pEmbedObj )
1289 // borders should not be counted
1290 awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1291 IntCounterGuard aGuard( m_nNoResizeReact );
1292 m_pEmbedObj->requestPositioning( aObjRect );
1296 //---------------------------------------------------------------------------
1297 awt::Rectangle SAL_CALL DocumentHolder::calcAdjustedRectangle( const awt::Rectangle& aRect )
1298 throw (uno::RuntimeException)
1300 // Solar mutex should be locked already since this is a call from HatchWindow with focus
1301 awt::Rectangle aResult( aRect );
1303 if ( m_xFrame.is() )
1305 // borders should not be counted
1306 uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
1307 if ( xControllerBorder.is() )
1309 awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1310 aObjRect = xControllerBorder->queryBorderedArea( aObjRect );
1311 aResult = AddBorderToArea( aObjRect );
1315 awt::Rectangle aMinRectangle = AddBorderToArea( awt::Rectangle() );
1316 if ( aResult.Width < aMinRectangle.Width + 2 )
1317 aResult.Width = aMinRectangle.Width + 2;
1318 if ( aResult.Height < aMinRectangle.Height + 2 )
1319 aResult.Height = aMinRectangle.Height + 2;
1321 return aResult;
1324 void SAL_CALL DocumentHolder::activated( ) throw (::com::sun::star::uno::RuntimeException)
1326 if ( (m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) )
1328 if ( m_pEmbedObj->getCurrentState() != embed::EmbedStates::UI_ACTIVE &&
1329 !(m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
1333 m_pEmbedObj->changeState( embed::EmbedStates::UI_ACTIVE );
1335 catch ( com::sun::star::embed::StateChangeInProgressException& )
1337 // must catch this exception because focus is grabbed while UI activation in doVerb()
1339 catch ( com::sun::star::uno::Exception& )
1341 // no outgoing exceptions specified here
1344 else
1346 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
1347 if ( xSupp.is() )
1348 xSupp->setActiveFrame( m_xFrame );
1353 void DocumentHolder::ResizeHatchWindow()
1355 awt::Rectangle aHatchRect = AddBorderToArea( m_aObjRect );
1356 ResizeWindows_Impl( aHatchRect );
1357 uno::Reference< embed::XHatchWindow > xHatchWindow( m_xHatchWindow, uno::UNO_QUERY );
1358 xHatchWindow->setHatchBorderSize( awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
1361 void SAL_CALL DocumentHolder::deactivated( ) throw (::com::sun::star::uno::RuntimeException)
1363 // deactivation is too unspecific to be useful; usually we only trigger code from activation
1364 // so UIDeactivation is actively triggered by the container