Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / embeddedobj / source / general / docholder.cxx
blobb8930efede2da2eabe85500bd2a17ea27bbfaf0b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/embed/Aspects.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/frame/XComponentLoader.hpp>
32 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
35 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
36 #include <com/sun/star/util/XCloseBroadcaster.hpp>
37 #include <com/sun/star/util/XCloseable.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/beans/NamedValue.hpp>
43 #include <com/sun/star/frame/XModel.hpp>
44 #include <com/sun/star/frame/XDesktop.hpp>
45 #include <com/sun/star/frame/XFramesSupplier.hpp>
46 #include <com/sun/star/frame/XDispatchHelper.hpp>
47 #include <com/sun/star/frame/FrameSearchFlag.hpp>
48 #include <com/sun/star/frame/XControllerBorder.hpp>
49 #include <com/sun/star/util/XModifyBroadcaster.hpp>
50 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
51 #include <com/sun/star/awt/XTopWindow.hpp>
52 #include <com/sun/star/awt/PosSize.hpp>
53 #include <com/sun/star/awt/XView.hpp>
54 #include <com/sun/star/awt/WindowAttribute.hpp>
55 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
56 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
57 #include <com/sun/star/bridge/ModelDependent.hpp>
58 #include <com/sun/star/embed/XHatchWindow.hpp>
59 #include <com/sun/star/embed/XHatchWindowFactory.hpp>
60 #include <com/sun/star/embed/XInplaceClient.hpp>
61 #include <com/sun/star/frame/XLayoutManager.hpp>
62 #include <com/sun/star/frame/XMenuBarMergingAcceptor.hpp>
63 #include <com/sun/star/frame/XModuleManager.hpp>
64 #include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
65 #include <com/sun/star/ui/XUIElementSettings.hpp>
66 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
67 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
68 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
69 #include <com/sun/star/lang/XServiceInfo.hpp>
70 #include <com/sun/star/embed/StateChangeInProgressException.hpp>
72 #include <com/sun/star/embed/EmbedMisc.hpp>
73 #include <com/sun/star/embed/EmbedStates.hpp>
74 #include <osl/diagnose.h>
75 #include <rtl/process.h>
77 #include <comphelper/processfactory.hxx>
78 #include <comphelper/namedvaluecollection.hxx>
80 #include "docholder.hxx"
81 #include "commonembobj.hxx"
82 #include "intercept.hxx"
85 #define HATCH_BORDER_WIDTH (((m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) && \
86 m_pEmbedObj->getCurrentState()!=embed::EmbedStates::UI_ACTIVE) ? 0 : 4 )
88 using namespace ::com::sun::star;
90 //===========================================================================
92 class IntCounterGuard {
93 sal_Int32& m_nFlag;
94 public:
95 IntCounterGuard( sal_Int32& nFlag )
96 : m_nFlag( nFlag )
98 m_nFlag++;
101 ~IntCounterGuard()
103 if ( m_nFlag )
104 m_nFlag--;
108 //===========================================================================
110 static void InsertMenu_Impl( const uno::Reference< container::XIndexContainer >& xTargetMenu,
111 sal_Int32 nTargetIndex,
112 const uno::Reference< container::XIndexAccess >& xSourceMenu,
113 sal_Int32 nSourceIndex,
114 const ::rtl::OUString aContModuleName,
115 const uno::Reference< frame::XDispatchProvider >& xSourceDisp )
117 sal_Int32 nInd = 0;
118 ::rtl::OUString aModuleIdentPropName( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ) );
119 ::rtl::OUString aDispProvPropName( RTL_CONSTASCII_USTRINGPARAM( "DispatchProvider" ) );
120 sal_Bool bModuleNameSet = sal_False;
121 sal_Bool bDispProvSet = sal_False;
123 uno::Sequence< beans::PropertyValue > aSourceProps;
124 xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps;
125 uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() );
126 for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ )
128 aTargetProps[nInd].Name = aSourceProps[nInd].Name;
129 if ( !aContModuleName.isEmpty() && aTargetProps[nInd].Name.equals( aModuleIdentPropName ) )
131 aTargetProps[nInd].Value <<= aContModuleName;
132 bModuleNameSet = sal_True;
134 else if ( aTargetProps[nInd].Name.equals( aDispProvPropName ) )
136 aTargetProps[nInd].Value <<= xSourceDisp;
137 bDispProvSet = sal_True;
139 else
140 aTargetProps[nInd].Value = aSourceProps[nInd].Value;
143 if ( !bModuleNameSet && !aContModuleName.isEmpty() )
145 aTargetProps.realloc( ++nInd );
146 aTargetProps[nInd-1].Name = aModuleIdentPropName;
147 aTargetProps[nInd-1].Value <<= aContModuleName;
150 if ( !bDispProvSet && xSourceDisp.is() )
152 aTargetProps.realloc( ++nInd );
153 aTargetProps[nInd-1].Name = aDispProvPropName;
154 aTargetProps[nInd-1].Value <<= xSourceDisp;
157 xTargetMenu->insertByIndex( nTargetIndex, uno::makeAny( aTargetProps ) );
160 //===========================================================================
161 DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
162 OCommonEmbeddedObject* pEmbObj )
163 : m_pEmbedObj( pEmbObj ),
164 m_pInterceptor( NULL ),
165 m_xFactory( xFactory ),
166 m_bReadOnly( sal_False ),
167 m_bWaitForClose( sal_False ),
168 m_bAllowClosing( sal_False ),
169 m_bDesktopTerminated( sal_False ),
170 m_nNoBorderResizeReact( 0 ),
171 m_nNoResizeReact( 0 )
173 m_aOutplaceFrameProps.realloc( 3 );
174 beans::NamedValue aArg;
176 aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TopWindow"));
177 aArg.Value <<= sal_True;
178 m_aOutplaceFrameProps[0] <<= aArg;
180 aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MakeVisible"));
181 aArg.Value <<= sal_False;
182 m_aOutplaceFrameProps[1] <<= aArg;
184 const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
185 uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
186 if ( xDesktop.is() )
188 m_refCount++;
191 xDesktop->addTerminateListener( this );
193 catch ( const uno::Exception& )
196 m_refCount--;
198 aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentFrame"));
199 aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame
200 m_aOutplaceFrameProps[2] <<= aArg;
202 else
203 m_aOutplaceFrameProps.realloc( 2 );
206 //---------------------------------------------------------------------------
207 DocumentHolder::~DocumentHolder()
209 m_refCount++; // to allow deregistration as a listener
211 if( m_xFrame.is() )
212 CloseFrame();
214 if ( m_xComponent.is() )
216 try {
217 CloseDocument( sal_True, sal_False );
218 } catch( const uno::Exception& ) {}
221 if ( m_pInterceptor )
223 m_pInterceptor->DisconnectDocHolder();
224 m_pInterceptor->release();
227 if ( !m_bDesktopTerminated )
228 FreeOffice();
231 //---------------------------------------------------------------------------
232 void DocumentHolder::CloseFrame()
234 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
235 if ( xCloseBroadcaster.is() )
236 xCloseBroadcaster->removeCloseListener( ( util::XCloseListener* )this );
238 uno::Reference<util::XCloseable> xCloseable(
239 m_xFrame,uno::UNO_QUERY );
240 if( xCloseable.is() )
241 try {
242 xCloseable->close( sal_True );
244 catch( const uno::Exception& ) {
246 else {
247 uno::Reference<lang::XComponent> xComp( m_xFrame,uno::UNO_QUERY );
248 if( xComp.is() )
249 xComp->dispose();
252 uno::Reference< lang::XComponent > xComp( m_xHatchWindow, uno::UNO_QUERY );
253 if ( xComp.is() )
254 xComp->dispose();
256 m_xHatchWindow = uno::Reference< awt::XWindow >();
257 m_xOwnWindow = uno::Reference< awt::XWindow >();
258 m_xFrame = uno::Reference< frame::XFrame >();
261 //---------------------------------------------------------------------------
262 void DocumentHolder::FreeOffice()
264 const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
265 uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
266 if ( xDesktop.is() )
268 xDesktop->removeTerminateListener( this );
270 // the following code is commented out since for now there is still no completely correct way to detect
271 // whether the office can be terminated, so it is better to have unnecessary process running than
272 // to loose any data
274 // uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY );
275 // if ( xFramesSupplier.is() )
276 // {
277 // uno::Reference< frame::XFrames > xFrames = xFramesSupplier->getFrames();
278 // if ( xFrames.is() && !xFrames->hasElements() )
279 // {
280 // try
281 // {
282 // xDesktop->terminate();
283 // }
284 // catch( uno::Exception & )
285 // {}
286 // }
287 // }
291 //---------------------------------------------------------------------------
292 void DocumentHolder::CloseDocument( sal_Bool bDeliverOwnership, sal_Bool bWaitForClose )
294 uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
295 if ( xBroadcaster.is() )
297 uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
298 if ( xEventBroadcaster.is() )
299 xEventBroadcaster->removeEventListener( ( document::XEventListener* )this );
300 else
302 // the object does not support document::XEventBroadcaster interface
303 // use the workaround, register for modified events
304 uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
305 if ( xModifyBroadcaster.is() )
306 xModifyBroadcaster->removeModifyListener( ( util::XModifyListener* )this );
309 uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY );
310 if ( xCloseable.is() )
312 m_bAllowClosing = sal_True;
313 m_bWaitForClose = bWaitForClose;
314 xCloseable->close( bDeliverOwnership );
318 m_xComponent = 0;
321 //---------------------------------------------------------------------------
322 void DocumentHolder::PlaceFrame( const awt::Rectangle& aNewRect )
324 OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is(),
325 "The object does not have windows required for inplace mode!" );
327 //TODO: may need mutex locking???
328 if ( m_xFrame.is() && m_xOwnWindow.is() )
330 // the frame can be replaced only in inplace mode
331 frame::BorderWidths aOldWidths;
332 IntCounterGuard aGuard( m_nNoBorderResizeReact );
336 aOldWidths = m_aBorderWidths;
338 awt::Rectangle aHatchRect = AddBorderToArea( aNewRect );
340 ResizeWindows_Impl( aHatchRect );
342 } while ( aOldWidths.Left != m_aBorderWidths.Left
343 || aOldWidths.Top != m_aBorderWidths.Top
344 || aOldWidths.Right != m_aBorderWidths.Right
345 || aOldWidths.Bottom != m_aBorderWidths.Bottom );
347 m_aObjRect = aNewRect;
351 //---------------------------------------------------------------------------
352 void DocumentHolder::ResizeWindows_Impl( const awt::Rectangle& aHatchRect )
354 OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is() /*&& m_xHatchWindow.is()*/,
355 "The object does not have windows required for inplace mode!" );
356 if ( m_xHatchWindow.is() )
358 m_xOwnWindow->setPosSize( HATCH_BORDER_WIDTH,
359 HATCH_BORDER_WIDTH,
360 aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
361 aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
362 awt::PosSize::POSSIZE );
365 m_xHatchWindow->setPosSize( aHatchRect.X,
366 aHatchRect.Y,
367 aHatchRect.Width,
368 aHatchRect.Height,
369 awt::PosSize::POSSIZE );
371 else
372 m_xOwnWindow->setPosSize( aHatchRect.X + HATCH_BORDER_WIDTH,
373 aHatchRect.Y + HATCH_BORDER_WIDTH,
374 aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
375 aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
376 awt::PosSize::POSSIZE );
379 //---------------------------------------------------------------------------
380 sal_Bool DocumentHolder::SetFrameLMVisibility( const uno::Reference< frame::XFrame >& xFrame, sal_Bool bVisible )
382 sal_Bool bResult = sal_False;
386 uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
387 uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY_THROW );
388 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager;
389 if ( xLayoutManager.is() )
391 xLayoutManager->setVisible( bVisible );
393 // MBA: locking is done only on the container LM, because it is not about hiding windows, it's about
394 // giving up control over the component window (and stopping to listen for resize events of the container window)
395 if ( bVisible )
396 xLayoutManager->unlock();
397 else
398 xLayoutManager->lock();
400 bResult = sal_True;
403 catch( const uno::Exception& )
406 return bResult;
409 //---------------------------------------------------------------------------
410 sal_Bool DocumentHolder::ShowInplace( const uno::Reference< awt::XWindowPeer >& xParent,
411 const awt::Rectangle& aRectangleToShow,
412 const uno::Reference< frame::XDispatchProvider >& xContDisp )
414 OSL_ENSURE( !m_xFrame.is(), "A frame exists already!" );
416 if ( !m_xFrame.is() )
418 uno::Reference < frame::XModel > xModel( GetComponent(), uno::UNO_QUERY );
419 awt::Rectangle aHatchRectangle = AddBorderToArea( aRectangleToShow );
421 awt::Rectangle aOwnRectangle( HATCH_BORDER_WIDTH,
422 HATCH_BORDER_WIDTH,
423 aHatchRectangle.Width - 2*HATCH_BORDER_WIDTH,
424 aHatchRectangle.Height - 2*HATCH_BORDER_WIDTH );
425 uno::Reference< awt::XWindow > xHWindow;
426 uno::Reference< awt::XWindowPeer > xMyParent( xParent );
428 if ( xModel.is() )
431 uno::Reference< embed::XHatchWindowFactory > xHatchFactory(
432 m_xFactory->createInstance(
433 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.HatchWindowFactory" )) ),
434 uno::UNO_QUERY );
436 if ( !xHatchFactory.is() )
437 throw uno::RuntimeException();
439 uno::Reference< embed::XHatchWindow > xHatchWindow =
440 xHatchFactory->createHatchWindowInstance( xParent,
441 aHatchRectangle,
442 awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
444 uno::Reference< awt::XWindowPeer > xHatchWinPeer( xHatchWindow, uno::UNO_QUERY );
445 xHWindow = uno::Reference< awt::XWindow >( xHatchWinPeer, uno::UNO_QUERY );
446 if ( !xHWindow.is() )
447 throw uno::RuntimeException(); // TODO: can not create own window
449 xHatchWindow->setController( uno::Reference< embed::XHatchWindowController >(
450 static_cast< embed::XHatchWindowController* >( this ) ) );
452 xMyParent = xHatchWinPeer;
454 else
456 aOwnRectangle.X += aHatchRectangle.X;
457 aOwnRectangle.Y += aHatchRectangle.Y;
460 awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_TOP,
461 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("dockingwindow") ),
462 xMyParent,
464 awt::Rectangle(),//aOwnRectangle,
465 awt::WindowAttribute::SHOW | awt::VclWindowPeerAttribute::CLIPCHILDREN );
467 uno::Reference< awt::XToolkit > xToolkit(
468 m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" )) ),
469 uno::UNO_QUERY );
470 if ( !xToolkit.is() )
471 throw uno::RuntimeException();
473 uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor );
474 uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY );
475 if ( !xOwnWindow.is() )
476 throw uno::RuntimeException(); // TODO: can not create own window
478 // create a frame based on the specified window
479 uno::Reference< lang::XSingleServiceFactory > xFrameFact(
480 m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.TaskCreator" )) ),
481 uno::UNO_QUERY_THROW );
483 uno::Sequence< uno::Any > aArgs( 2 );
484 beans::NamedValue aArg;
486 aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContainerWindow"));
487 aArg.Value <<= xOwnWindow;
488 aArgs[0] <<= aArg;
490 uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
491 if ( xContFrame.is() )
493 aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentFrame"));
494 aArg.Value <<= xContFrame;
495 aArgs[1] <<= aArg;
497 else
498 aArgs.realloc( 1 );
500 // the call will create, initialize the frame, and register it in the parent
501 m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW );
503 m_xHatchWindow = xHWindow;
504 m_xOwnWindow = xOwnWindow;
506 if ( !SetFrameLMVisibility( m_xFrame, sal_False ) )
508 OSL_FAIL( "Can't deactivate LayoutManager!\n" );
509 // TODO/LATER: error handling?
512 // m_bIsInplace = sal_True; TODO: ?
514 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
515 if ( xCloseBroadcaster.is() )
516 xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this );
518 // TODO: some listeners to the frame and the window ( resize for example )
521 if ( m_xComponent.is() )
523 if ( !LoadDocToFrame( sal_True ) )
525 CloseFrame();
526 return sal_False;
529 uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
530 if ( xControllerBorder.is() )
532 m_aBorderWidths = xControllerBorder->getBorder();
533 xControllerBorder->addBorderResizeListener( (frame::XBorderResizeListener*)this );
536 PlaceFrame( aRectangleToShow );
538 if ( m_xHatchWindow.is() )
539 m_xHatchWindow->setVisible( sal_True );
541 return sal_True;
544 return sal_False;
547 //---------------------------------------------------------------------------
548 uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl()
550 uno::Reference< container::XIndexAccess > xResult;
552 uno::Reference< ::com::sun::star::ui::XUIConfigurationManagerSupplier > xUIConfSupplier(
553 m_xComponent,
554 uno::UNO_QUERY );
555 uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xUIConfigManager;
556 if( xUIConfSupplier.is())
558 xUIConfigManager.set(
559 xUIConfSupplier->getUIConfigurationManager(),
560 uno::UNO_QUERY_THROW );
565 if( xUIConfigManager.is())
567 xResult = xUIConfigManager->getSettings(
568 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ),
569 sal_False );
572 catch( const uno::Exception& )
575 if ( !xResult.is() )
577 // no internal document configuration, use the one from the module
578 uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleMan(
579 m_xFactory->createInstance(
580 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
581 uno::UNO_QUERY_THROW );
582 ::rtl::OUString aModuleIdent =
583 xModuleMan->identify( uno::Reference< uno::XInterface >( m_xComponent, uno::UNO_QUERY ) );
585 if ( !aModuleIdent.isEmpty() )
587 uno::Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModConfSupplier(
588 m_xFactory->createInstance( ::rtl::OUString(
589 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ),
590 uno::UNO_QUERY_THROW );
591 uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xModUIConfMan(
592 xModConfSupplier->getUIConfigurationManager( aModuleIdent ),
593 uno::UNO_QUERY_THROW );
594 xResult = xModUIConfMan->getSettings(
595 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ),
596 sal_False );
600 if ( !xResult.is() )
601 throw uno::RuntimeException();
603 return xResult;
606 //---------------------------------------------------------------------------
607 void DocumentHolder::FindConnectPoints(
608 const uno::Reference< container::XIndexAccess >& xMenu,
609 sal_Int32 nConnectPoints[2] )
610 throw ( uno::Exception )
612 nConnectPoints[0] = -1;
613 nConnectPoints[1] = -1;
614 for ( sal_Int32 nInd = 0; nInd < xMenu->getCount(); nInd++ )
616 uno::Sequence< beans::PropertyValue > aProps;
617 xMenu->getByIndex( nInd ) >>= aProps;
618 rtl::OUString aCommand;
619 for ( sal_Int32 nSeqInd = 0; nSeqInd < aProps.getLength(); nSeqInd++ )
620 if ( aProps[nSeqInd].Name == "CommandURL" )
622 aProps[nSeqInd].Value >>= aCommand;
623 break;
626 if ( aCommand.isEmpty() )
627 throw uno::RuntimeException();
629 if ( aCommand == ".uno:PickList" )
630 nConnectPoints[0] = nInd;
631 else if ( aCommand == ".uno:WindowList" )
632 nConnectPoints[1] = nInd;
636 //---------------------------------------------------------------------------
637 uno::Reference< container::XIndexAccess > DocumentHolder::MergeMenuesForInplace(
638 const uno::Reference< container::XIndexAccess >& xContMenu,
639 const uno::Reference< frame::XDispatchProvider >& xContDisp,
640 const ::rtl::OUString& aContModuleName,
641 const uno::Reference< container::XIndexAccess >& xOwnMenu,
642 const uno::Reference< frame::XDispatchProvider >& xOwnDisp )
643 throw ( uno::Exception )
645 // TODO/LATER: use dispatch providers on merge
647 sal_Int32 nContPoints[2];
648 sal_Int32 nOwnPoints[2];
650 uno::Reference< lang::XSingleComponentFactory > xIndAccessFact( xContMenu, uno::UNO_QUERY_THROW );
652 uno::Reference< uno::XComponentContext > xComponentContext;
654 uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
655 if ( xProps.is() )
656 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>=
657 xComponentContext;
659 uno::Reference< container::XIndexContainer > xMergedMenu(
660 xIndAccessFact->createInstanceWithContext( xComponentContext ),
661 uno::UNO_QUERY_THROW );
663 FindConnectPoints( xContMenu, nContPoints );
664 FindConnectPoints( xOwnMenu, nOwnPoints );
666 for ( sal_Int32 nInd = 0; nInd < xOwnMenu->getCount(); nInd++ )
668 if ( nOwnPoints[0] == nInd )
670 if ( nContPoints[0] >= 0 && nContPoints[0] < xContMenu->getCount() )
672 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[0], aContModuleName, xContDisp );
675 else if ( nOwnPoints[1] == nInd )
677 if ( nContPoints[1] >= 0 && nContPoints[1] < xContMenu->getCount() )
679 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[1], aContModuleName, xContDisp );
682 else
683 InsertMenu_Impl( xMergedMenu, nInd, xOwnMenu, nInd, ::rtl::OUString(), xOwnDisp );
686 return uno::Reference< container::XIndexAccess >( xMergedMenu, uno::UNO_QUERY_THROW );
689 //---------------------------------------------------------------------------
690 sal_Bool DocumentHolder::MergeMenues_Impl( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xOwnLM,
691 const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContLM,
692 const uno::Reference< frame::XDispatchProvider >& xContDisp,
693 const ::rtl::OUString& aContModuleName )
695 sal_Bool bMenuMerged = sal_False;
698 uno::Reference< ::com::sun::star::ui::XUIElementSettings > xUISettings(
699 xContLM->getElement(
700 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ) ),
701 uno::UNO_QUERY_THROW );
702 uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings( sal_True );
703 if ( !xContMenu.is() )
704 throw uno::RuntimeException();
706 uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl();
707 uno::Reference< frame::XDispatchProvider > xOwnDisp( m_xFrame, uno::UNO_QUERY_THROW );
709 uno::Reference< container::XIndexAccess > xMergedMenu = MergeMenuesForInplace( xContMenu, xContDisp, aContModuleName, xOwnMenu, xOwnDisp );
710 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM,
711 uno::UNO_QUERY_THROW );
712 bMenuMerged = xMerge->setMergedMenuBar( xMergedMenu );
714 catch( const uno::Exception& )
717 return bMenuMerged;
720 sal_Bool DocumentHolder::ShowUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM,
721 const uno::Reference< frame::XDispatchProvider >& xContainerDP,
722 const ::rtl::OUString& aContModuleName )
724 sal_Bool bResult = sal_False;
725 if ( xContainerLM.is() )
727 // the LM of the embedded frame and its current DockingAreaAcceptor
728 uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
729 uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc;
733 uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
734 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
735 xDocAreaAcc = xContainerLM->getDockingAreaAcceptor();
737 catch( const uno::Exception& ){}
739 // make sure that lock state of LM is correct even if an exception is thrown in between
740 sal_Bool bUnlock = sal_False;
741 sal_Bool bLock = sal_False;
742 if ( xOwnLM.is() && xDocAreaAcc.is() )
746 // take over the control over the containers window
747 // as long as the LM is invisible and locked an empty tool space will be used on resizing
748 xOwnLM->setDockingAreaAcceptor( xDocAreaAcc );
750 // try to merge menus; don't do anything else if it fails
751 if ( MergeMenues_Impl( xOwnLM, xContainerLM, xContainerDP, aContModuleName ) )
753 // make sure that the container LM does not control the size of the containers window anymore
754 // this must be done after merging menus as we won't get the container menu otherwise
755 xContainerLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
757 // prevent further changes at this LM
758 xContainerLM->setVisible( sal_False );
759 xContainerLM->lock();
760 bUnlock = sal_True;
762 // by unlocking the LM each layout change will now resize the containers window; pending layouts will be processed now
763 xOwnLM->setVisible( sal_True );
765 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
766 if ( xSupp.is() )
767 xSupp->setActiveFrame( m_xFrame );
769 xOwnLM->unlock();
770 bLock = sal_True;
771 bResult = sal_True;
773 // TODO/LATER: The following action should be done only if the window is not hidden
774 // otherwise the activation must fail, unfortunatelly currently it is not possible
775 // to detect whether the window is hidden using UNO API
776 m_xOwnWindow->setFocus();
779 catch( const uno::Exception& )
781 // activation failed; reestablish old state
784 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
785 if ( xSupp.is() )
786 xSupp->setActiveFrame( 0 );
788 // remove control about containers window from own LM
789 if ( bLock )
790 xOwnLM->lock();
791 xOwnLM->setVisible( sal_False );
792 xOwnLM->setDockingAreaAcceptor( uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor >() );
794 // unmerge menu
795 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
796 xMerge->removeMergedMenuBar();
798 catch( const uno::Exception& ) {}
802 // reestablish control of containers window
803 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
804 xContainerLM->setVisible( sal_True );
805 if ( bUnlock )
806 xContainerLM->unlock();
808 catch( const uno::Exception& ) {}
813 return bResult;
816 //---------------------------------------------------------------------------
817 sal_Bool DocumentHolder::HideUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM )
819 sal_Bool bResult = sal_False;
821 if ( xContainerLM.is() )
823 uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
825 try {
826 uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
827 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
828 } catch( const uno::Exception& )
831 if ( xOwnLM.is() )
833 try {
834 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
835 if ( xSupp.is() )
836 xSupp->setActiveFrame( 0 );
838 uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc = xOwnLM->getDockingAreaAcceptor();
840 xOwnLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
841 xOwnLM->lock();
842 xOwnLM->setVisible( sal_False );
844 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
845 xMerge->removeMergedMenuBar();
847 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
848 xContainerLM->setVisible( sal_True );
849 xContainerLM->unlock();
851 xContainerLM->doLayout();
852 bResult = sal_True;
854 catch( const uno::Exception& )
856 SetFrameLMVisibility( m_xFrame, sal_True );
861 return bResult;
864 //---------------------------------------------------------------------------
865 uno::Reference< frame::XFrame > DocumentHolder::GetDocFrame()
867 // the frame for outplace activation
868 if ( !m_xFrame.is() )
870 uno::Reference< lang::XSingleServiceFactory > xFrameFact(
871 m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.TaskCreator" ) )),
872 uno::UNO_QUERY_THROW );
874 m_xFrame.set(xFrameFact->createInstanceWithArguments( m_aOutplaceFrameProps ), uno::UNO_QUERY_THROW);
876 uno::Reference< frame::XDispatchProviderInterception > xInterception( m_xFrame, uno::UNO_QUERY );
877 if ( xInterception.is() )
879 if ( m_pInterceptor )
881 m_pInterceptor->DisconnectDocHolder();
882 m_pInterceptor->release();
883 m_pInterceptor = NULL;
886 m_pInterceptor = new Interceptor( this );
887 m_pInterceptor->acquire();
889 // register interceptor from outside
890 if ( m_xOutplaceInterceptor.is() )
891 xInterception->registerDispatchProviderInterceptor( m_xOutplaceInterceptor );
893 xInterception->registerDispatchProviderInterceptor( m_pInterceptor );
896 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
897 if ( xCloseBroadcaster.is() )
898 xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this );
901 if ( m_xComponent.is() )
903 uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
904 try {
905 uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
906 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
907 } catch( const uno::Exception& )
910 if ( xOwnLM.is() )
911 xOwnLM->lock();
913 // TODO/LATER: get it for the real aspect
914 awt::Size aSize;
915 GetExtent( embed::Aspects::MSOLE_CONTENT, &aSize );
916 LoadDocToFrame(sal_False);
918 if ( xOwnLM.is() )
920 xOwnLM->unlock();
921 xOwnLM->lock();
924 SetExtent( embed::Aspects::MSOLE_CONTENT, aSize );
926 if ( xOwnLM.is() )
927 xOwnLM->unlock();
932 uno::Reference< awt::XWindow > xHWindow = m_xFrame->getContainerWindow();
934 if( xHWindow.is() )
936 uno::Reference< beans::XPropertySet > xMonProps( m_xFactory->createInstance(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), uno::UNO_QUERY_THROW );
937 const rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) );
938 sal_Int32 nDisplay = 0;
939 xMonProps->getPropertyValue( sPropName ) >>= nDisplay;
941 uno::Reference< container::XIndexAccess > xMultiMon( xMonProps, uno::UNO_QUERY_THROW );
942 uno::Reference< beans::XPropertySet > xMonitor( xMultiMon->getByIndex( nDisplay ), uno::UNO_QUERY_THROW );
943 awt::Rectangle aWorkRect;
944 xMonitor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WorkArea" ) ) ) >>= aWorkRect;
945 awt::Rectangle aWindowRect = xHWindow->getPosSize();
947 if (( aWindowRect.Width < aWorkRect.Width) && ( aWindowRect.Height < aWorkRect.Height ))
949 int OffsetX = ( aWorkRect.Width - aWindowRect.Width ) / 2 + aWorkRect.X;
950 int OffsetY = ( aWorkRect.Height - aWindowRect.Height ) /2 + aWorkRect.Y;
951 xHWindow->setPosSize( OffsetX, OffsetY, aWindowRect.Width, aWindowRect.Height, awt::PosSize::POS );
953 else
955 xHWindow->setPosSize( aWorkRect.X, aWorkRect.Y, aWorkRect.Width, aWorkRect.Height, awt::PosSize::POSSIZE );
958 xHWindow->setVisible( sal_True );
961 catch ( const uno::Exception& )
965 return m_xFrame;
968 //---------------------------------------------------------------------------
969 void DocumentHolder::SetComponent( const uno::Reference< util::XCloseable >& xDoc, sal_Bool bReadOnly )
971 if ( m_xComponent.is() )
973 // May be should be improved
974 try {
975 CloseDocument( sal_True, sal_False );
976 } catch( const uno::Exception& )
980 m_xComponent = xDoc;
982 m_bReadOnly = bReadOnly;
983 m_bAllowClosing = sal_False;
985 uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
986 if ( xBroadcaster.is() )
987 xBroadcaster->addCloseListener( ( util::XCloseListener* )this );
989 uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
990 if ( xEventBroadcaster.is() )
991 xEventBroadcaster->addEventListener( ( document::XEventListener* )this );
992 else
994 // the object does not support document::XEventBroadcaster interface
995 // use the workaround, register for modified events
996 uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
997 if ( xModifyBroadcaster.is() )
998 xModifyBroadcaster->addModifyListener( ( util::XModifyListener* )this );
1001 if ( m_xFrame.is() )
1002 LoadDocToFrame(sal_False);
1005 //---------------------------------------------------------------------------
1006 sal_Bool DocumentHolder::LoadDocToFrame( sal_Bool bInPlace )
1008 if ( m_xFrame.is() && m_xComponent.is() )
1010 uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
1011 if ( xDoc.is() )
1013 // load new document in to the frame
1014 uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY_THROW );
1016 ::comphelper::NamedValueCollection aArgs;
1017 aArgs.put( "Model", m_xComponent );
1018 aArgs.put( "ReadOnly", m_bReadOnly );
1019 if ( bInPlace )
1020 aArgs.put( "PluginMode", sal_Int16(1) );
1021 ::rtl::OUString sUrl;
1022 uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
1023 if ( xServiceInfo.is()
1024 && xServiceInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportDefinition"))) )
1026 sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".component:DB/ReportDesign"));
1028 else if( xServiceInfo.is()
1029 && xServiceInfo->supportsService( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.ChartDocument")) ))
1030 sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/schart"));
1031 else
1032 sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:object"));
1034 xComponentLoader->loadComponentFromURL( sUrl,
1035 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "_self" )),
1037 aArgs.getPropertyValues() );
1039 return sal_True;
1041 else
1043 uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY );
1044 if ( xLoader.is() )
1045 return xLoader->load( uno::Sequence < beans::PropertyValue >(), m_xFrame );
1046 else
1047 return sal_False;
1051 return sal_True;
1054 //---------------------------------------------------------------------------
1055 void DocumentHolder::Show()
1057 if( m_xFrame.is() )
1059 m_xFrame->activate();
1060 uno::Reference<awt::XTopWindow> xTopWindow( m_xFrame->getContainerWindow(), uno::UNO_QUERY );
1061 if( xTopWindow.is() )
1062 xTopWindow->toFront();
1064 else
1065 GetDocFrame();
1068 //---------------------------------------------------------------------------
1069 sal_Bool DocumentHolder::SetExtent( sal_Int64 nAspect, const awt::Size& aSize )
1071 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1072 if ( xDocVis.is() )
1076 xDocVis->setVisualAreaSize( nAspect, aSize );
1077 return sal_True;
1079 catch( const uno::Exception& )
1081 // TODO: Error handling
1085 return sal_False;
1088 //---------------------------------------------------------------------------
1089 sal_Bool DocumentHolder::GetExtent( sal_Int64 nAspect, awt::Size *pSize )
1091 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1092 if ( pSize && xDocVis.is() )
1096 *pSize = xDocVis->getVisualAreaSize( nAspect );
1097 return sal_True;
1099 catch( const uno::Exception& )
1101 // TODO: Error handling
1105 return sal_False;
1108 //---------------------------------------------------------------------------
1109 sal_Int32 DocumentHolder::GetMapUnit( sal_Int64 nAspect )
1111 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1112 if ( xDocVis.is() )
1116 return xDocVis->getMapUnit( nAspect );
1118 catch( const uno::Exception& )
1120 // TODO: Error handling
1124 return 0;
1127 //---------------------------------------------------------------------------
1128 awt::Rectangle DocumentHolder::CalculateBorderedArea( const awt::Rectangle& aRect )
1130 return awt::Rectangle( aRect.X + m_aBorderWidths.Left + HATCH_BORDER_WIDTH,
1131 aRect.Y + m_aBorderWidths.Top + HATCH_BORDER_WIDTH,
1132 aRect.Width - m_aBorderWidths.Left - m_aBorderWidths.Right - 2*HATCH_BORDER_WIDTH,
1133 aRect.Height - m_aBorderWidths.Top - m_aBorderWidths.Bottom - 2*HATCH_BORDER_WIDTH );
1136 //---------------------------------------------------------------------------
1137 awt::Rectangle DocumentHolder::AddBorderToArea( const awt::Rectangle& aRect )
1139 return awt::Rectangle( aRect.X - m_aBorderWidths.Left - HATCH_BORDER_WIDTH,
1140 aRect.Y - m_aBorderWidths.Top - HATCH_BORDER_WIDTH,
1141 aRect.Width + m_aBorderWidths.Left + m_aBorderWidths.Right + 2*HATCH_BORDER_WIDTH,
1142 aRect.Height + m_aBorderWidths.Top + m_aBorderWidths.Bottom + 2*HATCH_BORDER_WIDTH );
1145 //---------------------------------------------------------------------------
1146 void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource )
1147 throw (uno::RuntimeException)
1149 if ( m_xComponent.is() && m_xComponent == aSource.Source )
1151 m_xComponent = 0;
1152 if ( m_bWaitForClose )
1154 m_bWaitForClose = sal_False;
1155 FreeOffice();
1159 if( m_xFrame.is() && m_xFrame == aSource.Source )
1161 m_xHatchWindow = uno::Reference< awt::XWindow >();
1162 m_xOwnWindow = uno::Reference< awt::XWindow >();
1163 m_xFrame = uno::Reference< frame::XFrame >();
1168 //---------------------------------------------------------------------------
1169 void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool /*bGetsOwnership*/ )
1170 throw (util::CloseVetoException, uno::RuntimeException)
1172 if ( m_xComponent.is() && m_xComponent == aSource.Source && !m_bAllowClosing )
1173 throw util::CloseVetoException();
1176 //---------------------------------------------------------------------------
1177 void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
1178 throw (uno::RuntimeException)
1180 if ( m_xComponent.is() && m_xComponent == aSource.Source )
1182 m_xComponent = 0;
1183 if ( m_bWaitForClose )
1185 m_bWaitForClose = sal_False;
1186 FreeOffice();
1190 if( m_xFrame.is() && m_xFrame == aSource.Source )
1192 m_xHatchWindow = uno::Reference< awt::XWindow >();
1193 m_xOwnWindow = uno::Reference< awt::XWindow >();
1194 m_xFrame = uno::Reference< frame::XFrame >();
1198 //---------------------------------------------------------------------------
1199 void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& )
1200 throw (frame::TerminationVetoException, uno::RuntimeException)
1202 if ( m_bWaitForClose )
1203 throw frame::TerminationVetoException();
1206 //---------------------------------------------------------------------------
1207 void SAL_CALL DocumentHolder::notifyTermination( const lang::EventObject& aSource )
1208 throw (uno::RuntimeException)
1210 OSL_ENSURE( !m_xComponent.is(), "Just a disaster..." );
1212 uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY );
1213 m_bDesktopTerminated = sal_True;
1214 if ( xDesktop.is() )
1215 xDesktop->removeTerminateListener( ( frame::XTerminateListener* )this );
1218 //---------------------------------------------------------------------------
1219 void SAL_CALL DocumentHolder::modified( const lang::EventObject& aEvent )
1220 throw ( uno::RuntimeException )
1222 // if the component does not support document::XEventBroadcaster
1223 // the modify notifications are used as workaround, but only for running state
1224 if( aEvent.Source == m_xComponent && m_pEmbedObj && m_pEmbedObj->getCurrentState() == embed::EmbedStates::RUNNING )
1225 m_pEmbedObj->PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ) );
1228 //---------------------------------------------------------------------------
1229 void SAL_CALL DocumentHolder::notifyEvent( const document::EventObject& Event )
1230 throw ( uno::RuntimeException )
1232 if( m_pEmbedObj && Event.Source == m_xComponent )
1234 // for now the ignored events are not forwarded, but sent by the object itself
1235 if ( !Event.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnSave" ) )
1236 && !Event.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnSaveDone" ) )
1237 && !Event.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnSaveAs" ) )
1238 && !Event.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnSaveAsDone" ) )
1239 && !( Event.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnVisAreaChanged" ) ) && m_nNoResizeReact ) )
1240 m_pEmbedObj->PostEvent_Impl( Event.EventName );
1244 //---------------------------------------------------------------------------
1245 void SAL_CALL DocumentHolder::borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject,
1246 const frame::BorderWidths& aNewSize )
1247 throw ( uno::RuntimeException )
1249 // TODO: may require mutex introduction ???
1250 if ( m_pEmbedObj && m_xFrame.is() && aObject == m_xFrame->getController() )
1252 if ( m_aBorderWidths.Left != aNewSize.Left
1253 || m_aBorderWidths.Right != aNewSize.Right
1254 || m_aBorderWidths.Top != aNewSize.Top
1255 || m_aBorderWidths.Bottom != aNewSize.Bottom )
1257 m_aBorderWidths = aNewSize;
1258 if ( !m_nNoBorderResizeReact )
1259 PlaceFrame( m_aObjRect );
1264 //---------------------------------------------------------------------------
1265 void SAL_CALL DocumentHolder::requestPositioning( const awt::Rectangle& aRect )
1266 throw (uno::RuntimeException)
1268 // TODO: may require mutex introduction ???
1269 if ( m_pEmbedObj )
1271 // borders should not be counted
1272 awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1273 IntCounterGuard aGuard( m_nNoResizeReact );
1274 m_pEmbedObj->requestPositioning( aObjRect );
1278 //---------------------------------------------------------------------------
1279 awt::Rectangle SAL_CALL DocumentHolder::calcAdjustedRectangle( const awt::Rectangle& aRect )
1280 throw (uno::RuntimeException)
1282 // Solar mutex should be locked already since this is a call from HatchWindow with focus
1283 awt::Rectangle aResult( aRect );
1285 if ( m_xFrame.is() )
1287 // borders should not be counted
1288 uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
1289 if ( xControllerBorder.is() )
1291 awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1292 aObjRect = xControllerBorder->queryBorderedArea( aObjRect );
1293 aResult = AddBorderToArea( aObjRect );
1297 awt::Rectangle aMinRectangle = AddBorderToArea( awt::Rectangle() );
1298 if ( aResult.Width < aMinRectangle.Width + 2 )
1299 aResult.Width = aMinRectangle.Width + 2;
1300 if ( aResult.Height < aMinRectangle.Height + 2 )
1301 aResult.Height = aMinRectangle.Height + 2;
1303 return aResult;
1306 void SAL_CALL DocumentHolder::activated( ) throw (::com::sun::star::uno::RuntimeException)
1308 if ( (m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) )
1310 if ( m_pEmbedObj->getCurrentState() != embed::EmbedStates::UI_ACTIVE &&
1311 !(m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
1315 m_pEmbedObj->changeState( embed::EmbedStates::UI_ACTIVE );
1317 catch ( const com::sun::star::embed::StateChangeInProgressException& )
1319 // must catch this exception because focus is grabbed while UI activation in doVerb()
1321 catch ( const com::sun::star::uno::Exception& )
1323 // no outgoing exceptions specified here
1326 else
1328 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
1329 if ( xSupp.is() )
1330 xSupp->setActiveFrame( m_xFrame );
1335 void DocumentHolder::ResizeHatchWindow()
1337 awt::Rectangle aHatchRect = AddBorderToArea( m_aObjRect );
1338 ResizeWindows_Impl( aHatchRect );
1339 uno::Reference< embed::XHatchWindow > xHatchWindow( m_xHatchWindow, uno::UNO_QUERY );
1340 xHatchWindow->setHatchBorderSize( awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
1343 void SAL_CALL DocumentHolder::deactivated( ) throw (::com::sun::star::uno::RuntimeException)
1345 // deactivation is too unspecific to be useful; usually we only trigger code from activation
1346 // so UIDeactivation is actively triggered by the container
1349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */