xref: /AOO41X/main/embeddedobj/source/general/docholder.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
39*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACESS_HPP_
40*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchHelper.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/frame/XControllerBorder.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/awt/XView.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/bridge/ModelDependent.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/embed/XHatchWindow.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/embed/XHatchWindowFactory.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/frame/XMenuBarMergingAcceptor.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/ui/XUIElementSettings.hpp>
69*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_XCONFIGURATIONMANAGER_HPP_
70*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManager.hpp>
71*cdf0e10cSrcweir #endif
72*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
73*cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
74*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
75*cdf0e10cSrcweir #include <com/sun/star/embed/StateChangeInProgressException.hpp>
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
78*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
79*cdf0e10cSrcweir #include <osl/diagnose.h>
80*cdf0e10cSrcweir #include <rtl/process.h>
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
83*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir #include "docholder.hxx"
86*cdf0e10cSrcweir #include "commonembobj.hxx"
87*cdf0e10cSrcweir #include "intercept.hxx"
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir // #include <toolkit/helper/vclunohelper.hxx>
91*cdf0e10cSrcweir // #include <vcl/window.hxx>
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir #define HATCH_BORDER_WIDTH (((m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) && \
94*cdf0e10cSrcweir                              m_pEmbedObj->getCurrentState()!=embed::EmbedStates::UI_ACTIVE) ? 0 : 4 )
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir using namespace ::com::sun::star;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir //===========================================================================
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir class IntCounterGuard {
101*cdf0e10cSrcweir 	sal_Int32& m_nFlag;
102*cdf0e10cSrcweir public:
103*cdf0e10cSrcweir 	IntCounterGuard( sal_Int32& nFlag )
104*cdf0e10cSrcweir 	: m_nFlag( nFlag )
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 		m_nFlag++;
107*cdf0e10cSrcweir 	}
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	~IntCounterGuard()
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		if ( m_nFlag )
112*cdf0e10cSrcweir 			m_nFlag--;
113*cdf0e10cSrcweir 	}
114*cdf0e10cSrcweir };
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir //===========================================================================
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir static void InsertMenu_Impl( const uno::Reference< container::XIndexContainer >& xTargetMenu,
119*cdf0e10cSrcweir 							sal_Int32 nTargetIndex,
120*cdf0e10cSrcweir 							const uno::Reference< container::XIndexAccess >& xSourceMenu,
121*cdf0e10cSrcweir 							sal_Int32 nSourceIndex,
122*cdf0e10cSrcweir 							const ::rtl::OUString aContModuleName,
123*cdf0e10cSrcweir 							const uno::Reference< frame::XDispatchProvider >& xSourceDisp )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	sal_Int32 nInd = 0;
126*cdf0e10cSrcweir 	::rtl::OUString aModuleIdentPropName( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ) );
127*cdf0e10cSrcweir 	::rtl::OUString aDispProvPropName( RTL_CONSTASCII_USTRINGPARAM( "DispatchProvider" ) );
128*cdf0e10cSrcweir 	sal_Bool bModuleNameSet = sal_False;
129*cdf0e10cSrcweir 	sal_Bool bDispProvSet = sal_False;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aSourceProps;
132*cdf0e10cSrcweir 	xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps;
133*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() );
134*cdf0e10cSrcweir 	for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ )
135*cdf0e10cSrcweir 	{
136*cdf0e10cSrcweir 		aTargetProps[nInd].Name = aSourceProps[nInd].Name;
137*cdf0e10cSrcweir 		if ( aContModuleName.getLength() && aTargetProps[nInd].Name.equals( aModuleIdentPropName ) )
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			aTargetProps[nInd].Value <<= aContModuleName;
140*cdf0e10cSrcweir 			bModuleNameSet = sal_True;
141*cdf0e10cSrcweir 		}
142*cdf0e10cSrcweir 		else if ( aTargetProps[nInd].Name.equals( aDispProvPropName ) )
143*cdf0e10cSrcweir 		{
144*cdf0e10cSrcweir 			aTargetProps[nInd].Value <<= xSourceDisp;
145*cdf0e10cSrcweir 			bDispProvSet = sal_True;
146*cdf0e10cSrcweir 		}
147*cdf0e10cSrcweir 		else
148*cdf0e10cSrcweir 			aTargetProps[nInd].Value = aSourceProps[nInd].Value;
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	if ( !bModuleNameSet && aContModuleName.getLength() )
152*cdf0e10cSrcweir 	{
153*cdf0e10cSrcweir 		aTargetProps.realloc( ++nInd );
154*cdf0e10cSrcweir 		aTargetProps[nInd-1].Name = aModuleIdentPropName;
155*cdf0e10cSrcweir 		aTargetProps[nInd-1].Value <<= aContModuleName;
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	if ( !bDispProvSet && xSourceDisp.is() )
159*cdf0e10cSrcweir 	{
160*cdf0e10cSrcweir 		aTargetProps.realloc( ++nInd );
161*cdf0e10cSrcweir 		aTargetProps[nInd-1].Name = aDispProvPropName;
162*cdf0e10cSrcweir 		aTargetProps[nInd-1].Value <<= xSourceDisp;
163*cdf0e10cSrcweir 	}
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	xTargetMenu->insertByIndex( nTargetIndex, uno::makeAny( aTargetProps ) );
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //===========================================================================
169*cdf0e10cSrcweir DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
170*cdf0e10cSrcweir 								OCommonEmbeddedObject* pEmbObj )
171*cdf0e10cSrcweir : m_pEmbedObj( pEmbObj ),
172*cdf0e10cSrcweir   m_pInterceptor( NULL ),
173*cdf0e10cSrcweir   m_xFactory( xFactory ),
174*cdf0e10cSrcweir   m_bReadOnly( sal_False ),
175*cdf0e10cSrcweir   m_bWaitForClose( sal_False ),
176*cdf0e10cSrcweir   m_bAllowClosing( sal_False ),
177*cdf0e10cSrcweir   m_bDesktopTerminated( sal_False ),
178*cdf0e10cSrcweir   m_nNoBorderResizeReact( 0 ),
179*cdf0e10cSrcweir   m_nNoResizeReact( 0 )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	m_aOutplaceFrameProps.realloc( 3 );
182*cdf0e10cSrcweir 	beans::NamedValue aArg;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	aArg.Name = ::rtl::OUString::createFromAscii("TopWindow");
185*cdf0e10cSrcweir 	aArg.Value <<= sal_True;
186*cdf0e10cSrcweir 	m_aOutplaceFrameProps[0] <<= aArg;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     aArg.Name = ::rtl::OUString::createFromAscii("MakeVisible");
189*cdf0e10cSrcweir     aArg.Value <<= sal_False;
190*cdf0e10cSrcweir     m_aOutplaceFrameProps[1] <<= aArg;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
193*cdf0e10cSrcweir 	uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
194*cdf0e10cSrcweir 	if ( xDesktop.is() )
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         m_refCount++;
197*cdf0e10cSrcweir         try
198*cdf0e10cSrcweir         {
199*cdf0e10cSrcweir             xDesktop->addTerminateListener( this );
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir         catch ( uno::Exception& )
202*cdf0e10cSrcweir         {
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir         m_refCount--;
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 		aArg.Name = ::rtl::OUString::createFromAscii("ParentFrame");
207*cdf0e10cSrcweir 		aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame
208*cdf0e10cSrcweir 		m_aOutplaceFrameProps[2] <<= aArg;
209*cdf0e10cSrcweir     }
210*cdf0e10cSrcweir 	else
211*cdf0e10cSrcweir 		m_aOutplaceFrameProps.realloc( 2 );
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir //---------------------------------------------------------------------------
215*cdf0e10cSrcweir DocumentHolder::~DocumentHolder()
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	m_refCount++; // to allow deregistration as a listener
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	if( m_xFrame.is() )
220*cdf0e10cSrcweir 		CloseFrame();
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     if ( m_xComponent.is() )
223*cdf0e10cSrcweir 	{
224*cdf0e10cSrcweir 		try {
225*cdf0e10cSrcweir 			CloseDocument( sal_True, sal_False );
226*cdf0e10cSrcweir 		} catch( uno::Exception& ) {}
227*cdf0e10cSrcweir 	}
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	if ( m_pInterceptor )
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		m_pInterceptor->DisconnectDocHolder();
232*cdf0e10cSrcweir 		m_pInterceptor->release();
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     if ( !m_bDesktopTerminated )
236*cdf0e10cSrcweir         FreeOffice();
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir //---------------------------------------------------------------------------
240*cdf0e10cSrcweir void DocumentHolder::CloseFrame()
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir 	uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
243*cdf0e10cSrcweir 	if ( xCloseBroadcaster.is() )
244*cdf0e10cSrcweir 		xCloseBroadcaster->removeCloseListener( ( util::XCloseListener* )this );
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	uno::Reference<util::XCloseable> xCloseable(
247*cdf0e10cSrcweir 		m_xFrame,uno::UNO_QUERY );
248*cdf0e10cSrcweir 	if( xCloseable.is() )
249*cdf0e10cSrcweir 		try {
250*cdf0e10cSrcweir 			xCloseable->close( sal_True );
251*cdf0e10cSrcweir 		}
252*cdf0e10cSrcweir 		catch( const uno::Exception& ) {
253*cdf0e10cSrcweir 		}
254*cdf0e10cSrcweir 	else {
255*cdf0e10cSrcweir 		uno::Reference<lang::XComponent> xComp( m_xFrame,uno::UNO_QUERY );
256*cdf0e10cSrcweir 		if( xComp.is() )
257*cdf0e10cSrcweir 			xComp->dispose();
258*cdf0e10cSrcweir 	}
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 	uno::Reference< lang::XComponent > xComp( m_xHatchWindow, uno::UNO_QUERY );
261*cdf0e10cSrcweir 	if ( xComp.is() )
262*cdf0e10cSrcweir 		xComp->dispose();
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	m_xHatchWindow = uno::Reference< awt::XWindow >();
265*cdf0e10cSrcweir 	m_xOwnWindow = uno::Reference< awt::XWindow >();
266*cdf0e10cSrcweir 	m_xFrame = uno::Reference< frame::XFrame >();
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir //---------------------------------------------------------------------------
270*cdf0e10cSrcweir void DocumentHolder::FreeOffice()
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir 	const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
273*cdf0e10cSrcweir 	uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
274*cdf0e10cSrcweir 	if ( xDesktop.is() )
275*cdf0e10cSrcweir 	{
276*cdf0e10cSrcweir         xDesktop->removeTerminateListener( this );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 		// the following code is commented out since for now there is still no completely correct way to detect
279*cdf0e10cSrcweir 		// whether the office can be terminated, so it is better to have unnecessary process running than
280*cdf0e10cSrcweir 		// to loose any data
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir //		uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY );
283*cdf0e10cSrcweir //		if ( xFramesSupplier.is() )
284*cdf0e10cSrcweir //		{
285*cdf0e10cSrcweir //			uno::Reference< frame::XFrames > xFrames = xFramesSupplier->getFrames();
286*cdf0e10cSrcweir //			if ( xFrames.is() && !xFrames->hasElements() )
287*cdf0e10cSrcweir //			{
288*cdf0e10cSrcweir //				try
289*cdf0e10cSrcweir //				{
290*cdf0e10cSrcweir //					xDesktop->terminate();
291*cdf0e10cSrcweir //				}
292*cdf0e10cSrcweir //				catch( uno::Exception & )
293*cdf0e10cSrcweir //				{}
294*cdf0e10cSrcweir //			}
295*cdf0e10cSrcweir //		}
296*cdf0e10cSrcweir 	}
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir //---------------------------------------------------------------------------
300*cdf0e10cSrcweir void DocumentHolder::CloseDocument( sal_Bool bDeliverOwnership, sal_Bool bWaitForClose )
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir     uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
303*cdf0e10cSrcweir 	if ( xBroadcaster.is() )
304*cdf0e10cSrcweir 	{
305*cdf0e10cSrcweir         uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
306*cdf0e10cSrcweir 		if ( xEventBroadcaster.is() )
307*cdf0e10cSrcweir 			xEventBroadcaster->removeEventListener( ( document::XEventListener* )this );
308*cdf0e10cSrcweir 		else
309*cdf0e10cSrcweir 		{
310*cdf0e10cSrcweir 			// the object does not support document::XEventBroadcaster interface
311*cdf0e10cSrcweir 			// use the workaround, register for modified events
312*cdf0e10cSrcweir 			uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
313*cdf0e10cSrcweir 			if ( xModifyBroadcaster.is() )
314*cdf0e10cSrcweir 				xModifyBroadcaster->removeModifyListener( ( util::XModifyListener* )this );
315*cdf0e10cSrcweir 		}
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 		uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY );
318*cdf0e10cSrcweir 		if ( xCloseable.is() )
319*cdf0e10cSrcweir 		{
320*cdf0e10cSrcweir 			m_bAllowClosing = sal_True;
321*cdf0e10cSrcweir 			m_bWaitForClose = bWaitForClose;
322*cdf0e10cSrcweir 			xCloseable->close( bDeliverOwnership );
323*cdf0e10cSrcweir 		}
324*cdf0e10cSrcweir 	}
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     m_xComponent = 0;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir //---------------------------------------------------------------------------
330*cdf0e10cSrcweir void DocumentHolder::PlaceFrame( const awt::Rectangle& aNewRect )
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is(),
333*cdf0e10cSrcweir                 "The object does not have windows required for inplace mode!" );
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	//TODO: may need mutex locking???
336*cdf0e10cSrcweir     if ( m_xFrame.is() && m_xOwnWindow.is() )
337*cdf0e10cSrcweir 	{
338*cdf0e10cSrcweir 		// the frame can be replaced only in inplace mode
339*cdf0e10cSrcweir 		frame::BorderWidths aOldWidths;
340*cdf0e10cSrcweir 		IntCounterGuard aGuard( m_nNoBorderResizeReact );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		do
343*cdf0e10cSrcweir 		{
344*cdf0e10cSrcweir 			aOldWidths = m_aBorderWidths;
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 			awt::Rectangle aHatchRect = AddBorderToArea( aNewRect );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 			ResizeWindows_Impl( aHatchRect );
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 		} while ( aOldWidths.Left != m_aBorderWidths.Left
351*cdf0e10cSrcweir 			   || aOldWidths.Top != m_aBorderWidths.Top
352*cdf0e10cSrcweir 			   || aOldWidths.Right != m_aBorderWidths.Right
353*cdf0e10cSrcweir 			   || aOldWidths.Bottom != m_aBorderWidths.Bottom );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 		m_aObjRect = aNewRect;
356*cdf0e10cSrcweir 	}
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir //---------------------------------------------------------------------------
360*cdf0e10cSrcweir void DocumentHolder::ResizeWindows_Impl( const awt::Rectangle& aHatchRect )
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir 	OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is() /*&& m_xHatchWindow.is()*/,
363*cdf0e10cSrcweir 				"The object does not have windows required for inplace mode!" );
364*cdf0e10cSrcweir 	if ( m_xHatchWindow.is() )
365*cdf0e10cSrcweir 	{
366*cdf0e10cSrcweir 		m_xOwnWindow->setPosSize( HATCH_BORDER_WIDTH,
367*cdf0e10cSrcweir 								  HATCH_BORDER_WIDTH,
368*cdf0e10cSrcweir 								  aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
369*cdf0e10cSrcweir 								  aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
370*cdf0e10cSrcweir 								  awt::PosSize::POSSIZE );
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 		// Window* pWindow = VCLUnoHelper::GetWindow( m_xOwnWindow );
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 		m_xHatchWindow->setPosSize( aHatchRect.X,
375*cdf0e10cSrcweir 									aHatchRect.Y,
376*cdf0e10cSrcweir 									aHatchRect.Width,
377*cdf0e10cSrcweir 									aHatchRect.Height,
378*cdf0e10cSrcweir 									awt::PosSize::POSSIZE );
379*cdf0e10cSrcweir 	}
380*cdf0e10cSrcweir 	else
381*cdf0e10cSrcweir 		m_xOwnWindow->setPosSize( aHatchRect.X + HATCH_BORDER_WIDTH,
382*cdf0e10cSrcweir 								  aHatchRect.Y + HATCH_BORDER_WIDTH,
383*cdf0e10cSrcweir 								  aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
384*cdf0e10cSrcweir 								  aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
385*cdf0e10cSrcweir 								  awt::PosSize::POSSIZE );
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir //---------------------------------------------------------------------------
389*cdf0e10cSrcweir sal_Bool DocumentHolder::SetFrameLMVisibility( const uno::Reference< frame::XFrame >& xFrame, sal_Bool bVisible )
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 	try
394*cdf0e10cSrcweir 	{
395*cdf0e10cSrcweir     	uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
396*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY_THROW );
397*cdf0e10cSrcweir 		xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager;
398*cdf0e10cSrcweir 		if ( xLayoutManager.is() )
399*cdf0e10cSrcweir 		{
400*cdf0e10cSrcweir 			xLayoutManager->setVisible( bVisible );
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir             // MBA: locking is done only on the container LM, because it is not about hiding windows, it's about
403*cdf0e10cSrcweir             // giving up control over the component window (and stopping to listen for resize events of the container window)
404*cdf0e10cSrcweir             if ( bVisible )
405*cdf0e10cSrcweir                 xLayoutManager->unlock();
406*cdf0e10cSrcweir             else
407*cdf0e10cSrcweir                 xLayoutManager->lock();
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 			bResult = sal_True;
410*cdf0e10cSrcweir 		}
411*cdf0e10cSrcweir 	}
412*cdf0e10cSrcweir 	catch( uno::Exception& )
413*cdf0e10cSrcweir 	{}
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	return bResult;
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir //---------------------------------------------------------------------------
419*cdf0e10cSrcweir sal_Bool DocumentHolder::ShowInplace( const uno::Reference< awt::XWindowPeer >& xParent,
420*cdf0e10cSrcweir 									  const awt::Rectangle& aRectangleToShow,
421*cdf0e10cSrcweir 									  const uno::Reference< frame::XDispatchProvider >& xContDisp )
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir 	OSL_ENSURE( !m_xFrame.is(), "A frame exists already!" );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	if ( !m_xFrame.is() )
426*cdf0e10cSrcweir 	{
427*cdf0e10cSrcweir         uno::Reference < frame::XModel > xModel( GetComponent(), uno::UNO_QUERY );
428*cdf0e10cSrcweir 		awt::Rectangle aHatchRectangle = AddBorderToArea( aRectangleToShow );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir         awt::Rectangle aOwnRectangle(  HATCH_BORDER_WIDTH,
431*cdf0e10cSrcweir                                     HATCH_BORDER_WIDTH,
432*cdf0e10cSrcweir                                     aHatchRectangle.Width - 2*HATCH_BORDER_WIDTH,
433*cdf0e10cSrcweir                                     aHatchRectangle.Height - 2*HATCH_BORDER_WIDTH );
434*cdf0e10cSrcweir         uno::Reference< awt::XWindow > xHWindow;
435*cdf0e10cSrcweir         uno::Reference< awt::XWindowPeer > xMyParent( xParent );
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         if ( xModel.is() )
438*cdf0e10cSrcweir         {
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 			uno::Reference< embed::XHatchWindowFactory > xHatchFactory(
441*cdf0e10cSrcweir 					m_xFactory->createInstance(
442*cdf0e10cSrcweir 						::rtl::OUString::createFromAscii( "com.sun.star.embed.HatchWindowFactory" ) ),
443*cdf0e10cSrcweir 					uno::UNO_QUERY );
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 			if ( !xHatchFactory.is() )
446*cdf0e10cSrcweir 				throw uno::RuntimeException();
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 			uno::Reference< embed::XHatchWindow > xHatchWindow =
449*cdf0e10cSrcweir 							xHatchFactory->createHatchWindowInstance( xParent,
450*cdf0e10cSrcweir 																	  aHatchRectangle,
451*cdf0e10cSrcweir 																	  awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 			uno::Reference< awt::XWindowPeer > xHatchWinPeer( xHatchWindow, uno::UNO_QUERY );
454*cdf0e10cSrcweir             xHWindow = uno::Reference< awt::XWindow >( xHatchWinPeer, uno::UNO_QUERY );
455*cdf0e10cSrcweir 			if ( !xHWindow.is() )
456*cdf0e10cSrcweir 				throw uno::RuntimeException(); // TODO: can not create own window
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir             xHatchWindow->setController( uno::Reference< embed::XHatchWindowController >(
459*cdf0e10cSrcweir 												static_cast< embed::XHatchWindowController* >( this ) ) );
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir             xMyParent = xHatchWinPeer;
462*cdf0e10cSrcweir 		}
463*cdf0e10cSrcweir         else
464*cdf0e10cSrcweir         {
465*cdf0e10cSrcweir             aOwnRectangle.X += aHatchRectangle.X;
466*cdf0e10cSrcweir             aOwnRectangle.Y += aHatchRectangle.Y;
467*cdf0e10cSrcweir         }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir         awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_TOP,
470*cdf0e10cSrcweir                                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("dockingwindow") ),
471*cdf0e10cSrcweir                                                 xMyParent,
472*cdf0e10cSrcweir 												0,
473*cdf0e10cSrcweir                                                 awt::Rectangle(),//aOwnRectangle,
474*cdf0e10cSrcweir                                                 awt::WindowAttribute::SHOW | awt::VclWindowPeerAttribute::CLIPCHILDREN );
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 		uno::Reference< awt::XToolkit > xToolkit(
477*cdf0e10cSrcweir 							m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.awt.Toolkit" ) ),
478*cdf0e10cSrcweir 							uno::UNO_QUERY );
479*cdf0e10cSrcweir 		if ( !xToolkit.is() )
480*cdf0e10cSrcweir 			throw uno::RuntimeException();
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir 		uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor );
483*cdf0e10cSrcweir 		uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY );
484*cdf0e10cSrcweir 		if ( !xOwnWindow.is() )
485*cdf0e10cSrcweir 			throw uno::RuntimeException(); // TODO: can not create own window
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 		// create a frame based on the specified window
488*cdf0e10cSrcweir         uno::Reference< lang::XSingleServiceFactory > xFrameFact(
489*cdf0e10cSrcweir 			m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.TaskCreator" ) ),
490*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 		uno::Sequence< uno::Any > aArgs( 2 );
493*cdf0e10cSrcweir 		beans::NamedValue aArg;
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 		aArg.Name    = ::rtl::OUString::createFromAscii("ContainerWindow");
496*cdf0e10cSrcweir 		aArg.Value <<= xOwnWindow;
497*cdf0e10cSrcweir 		aArgs[0] <<= aArg;
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 		uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
500*cdf0e10cSrcweir 		if ( xContFrame.is() )
501*cdf0e10cSrcweir 		{
502*cdf0e10cSrcweir 			aArg.Name    = ::rtl::OUString::createFromAscii("ParentFrame");
503*cdf0e10cSrcweir 			aArg.Value <<= xContFrame;
504*cdf0e10cSrcweir 			aArgs[1] <<= aArg;
505*cdf0e10cSrcweir 		}
506*cdf0e10cSrcweir 		else
507*cdf0e10cSrcweir 			aArgs.realloc( 1 );
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 		// the call will create, initialize the frame, and register it in the parent
510*cdf0e10cSrcweir 		m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW );
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 		m_xHatchWindow = xHWindow;
513*cdf0e10cSrcweir 		m_xOwnWindow = xOwnWindow;
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 		if ( !SetFrameLMVisibility( m_xFrame, sal_False ) )
516*cdf0e10cSrcweir 		{
517*cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Can't deactivate LayoutManager!\n" );
518*cdf0e10cSrcweir 			// TODO/LATER: error handling?
519*cdf0e10cSrcweir 		}
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 		// m_bIsInplace = sal_True; TODO: ?
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
524*cdf0e10cSrcweir 		if ( xCloseBroadcaster.is() )
525*cdf0e10cSrcweir 			xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		// TODO: some listeners to the frame and the window ( resize for example )
528*cdf0e10cSrcweir 	}
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     if ( m_xComponent.is() )
531*cdf0e10cSrcweir 	{
532*cdf0e10cSrcweir         if ( !LoadDocToFrame( sal_True ) )
533*cdf0e10cSrcweir         {
534*cdf0e10cSrcweir             CloseFrame();
535*cdf0e10cSrcweir             return sal_False;
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 		uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
539*cdf0e10cSrcweir 		if ( xControllerBorder.is() )
540*cdf0e10cSrcweir 		{
541*cdf0e10cSrcweir 			m_aBorderWidths = xControllerBorder->getBorder();
542*cdf0e10cSrcweir 			xControllerBorder->addBorderResizeListener( (frame::XBorderResizeListener*)this );
543*cdf0e10cSrcweir 		}
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 		PlaceFrame( aRectangleToShow );
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir         if ( m_xHatchWindow.is() )
548*cdf0e10cSrcweir             m_xHatchWindow->setVisible( sal_True );
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir         return sal_True;
551*cdf0e10cSrcweir 	}
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 	return sal_False;
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir //---------------------------------------------------------------------------
557*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl()
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess > xResult;
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 	uno::Reference< ::com::sun::star::ui::XUIConfigurationManagerSupplier > xUIConfSupplier(
562*cdf0e10cSrcweir 				m_xComponent,
563*cdf0e10cSrcweir 				uno::UNO_QUERY );
564*cdf0e10cSrcweir 	uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xUIConfigManager;
565*cdf0e10cSrcweir     if( xUIConfSupplier.is())
566*cdf0e10cSrcweir     {
567*cdf0e10cSrcweir         xUIConfigManager.set(
568*cdf0e10cSrcweir             xUIConfSupplier->getUIConfigurationManager(),
569*cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
570*cdf0e10cSrcweir     }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir     try
573*cdf0e10cSrcweir 	{
574*cdf0e10cSrcweir         if( xUIConfigManager.is())
575*cdf0e10cSrcweir         {
576*cdf0e10cSrcweir             xResult = xUIConfigManager->getSettings(
577*cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ),
578*cdf0e10cSrcweir 				sal_False );
579*cdf0e10cSrcweir         }
580*cdf0e10cSrcweir 	}
581*cdf0e10cSrcweir 	catch( uno::Exception )
582*cdf0e10cSrcweir 	{}
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 	if ( !xResult.is() )
585*cdf0e10cSrcweir 	{
586*cdf0e10cSrcweir 		// no internal document configuration, use the one from the module
587*cdf0e10cSrcweir 		uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleMan(
588*cdf0e10cSrcweir                 m_xFactory->createInstance(
589*cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
590*cdf0e10cSrcweir 					uno::UNO_QUERY_THROW );
591*cdf0e10cSrcweir 		::rtl::OUString aModuleIdent =
592*cdf0e10cSrcweir 			xModuleMan->identify( uno::Reference< uno::XInterface >( m_xComponent, uno::UNO_QUERY ) );
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 		if ( aModuleIdent.getLength() )
595*cdf0e10cSrcweir 		{
596*cdf0e10cSrcweir 			uno::Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModConfSupplier(
597*cdf0e10cSrcweir 					m_xFactory->createInstance( ::rtl::OUString(
598*cdf0e10cSrcweir 						RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ),
599*cdf0e10cSrcweir 					uno::UNO_QUERY_THROW );
600*cdf0e10cSrcweir 			uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xModUIConfMan(
601*cdf0e10cSrcweir 					xModConfSupplier->getUIConfigurationManager( aModuleIdent ),
602*cdf0e10cSrcweir 					uno::UNO_QUERY_THROW );
603*cdf0e10cSrcweir 			xResult = xModUIConfMan->getSettings(
604*cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ),
605*cdf0e10cSrcweir 					sal_False );
606*cdf0e10cSrcweir 		}
607*cdf0e10cSrcweir 	}
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 	if ( !xResult.is() )
610*cdf0e10cSrcweir 		throw uno::RuntimeException();
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 	return xResult;
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir //---------------------------------------------------------------------------
616*cdf0e10cSrcweir void DocumentHolder::FindConnectPoints(
617*cdf0e10cSrcweir 		const uno::Reference< container::XIndexAccess >& xMenu,
618*cdf0e10cSrcweir 		sal_Int32 nConnectPoints[2] )
619*cdf0e10cSrcweir 	throw ( uno::Exception )
620*cdf0e10cSrcweir {
621*cdf0e10cSrcweir 	nConnectPoints[0] = -1;
622*cdf0e10cSrcweir 	nConnectPoints[1] = -1;
623*cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < xMenu->getCount(); nInd++ )
624*cdf0e10cSrcweir 	{
625*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aProps;
626*cdf0e10cSrcweir 		xMenu->getByIndex( nInd ) >>= aProps;
627*cdf0e10cSrcweir 		rtl::OUString aCommand;
628*cdf0e10cSrcweir 		for ( sal_Int32 nSeqInd = 0; nSeqInd < aProps.getLength(); nSeqInd++ )
629*cdf0e10cSrcweir 			if ( aProps[nSeqInd].Name.equalsAscii( "CommandURL" ) )
630*cdf0e10cSrcweir 			{
631*cdf0e10cSrcweir 				aProps[nSeqInd].Value >>= aCommand;
632*cdf0e10cSrcweir 				break;
633*cdf0e10cSrcweir 			}
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir 		if ( !aCommand.getLength() )
636*cdf0e10cSrcweir 			throw uno::RuntimeException();
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 		if ( aCommand.equalsAscii( ".uno:PickList" ) )
639*cdf0e10cSrcweir 			nConnectPoints[0] = nInd;
640*cdf0e10cSrcweir 		else if ( aCommand.equalsAscii( ".uno:WindowList" ) )
641*cdf0e10cSrcweir 			nConnectPoints[1] = nInd;
642*cdf0e10cSrcweir 	}
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir //---------------------------------------------------------------------------
646*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > DocumentHolder::MergeMenuesForInplace(
647*cdf0e10cSrcweir 		const uno::Reference< container::XIndexAccess >& xContMenu,
648*cdf0e10cSrcweir 		const uno::Reference< frame::XDispatchProvider >& xContDisp,
649*cdf0e10cSrcweir 		const ::rtl::OUString& aContModuleName,
650*cdf0e10cSrcweir 		const uno::Reference< container::XIndexAccess >& xOwnMenu,
651*cdf0e10cSrcweir 		const uno::Reference< frame::XDispatchProvider >& xOwnDisp )
652*cdf0e10cSrcweir 	throw ( uno::Exception )
653*cdf0e10cSrcweir {
654*cdf0e10cSrcweir 	// TODO/LATER: use dispatch providers on merge
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 	sal_Int32 nContPoints[2];
657*cdf0e10cSrcweir 	sal_Int32 nOwnPoints[2];
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir 	uno::Reference< lang::XSingleComponentFactory > xIndAccessFact( xContMenu, uno::UNO_QUERY_THROW );
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 	uno::Reference< uno::XComponentContext > xComponentContext;
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
664*cdf0e10cSrcweir 	if ( xProps.is() )
665*cdf0e10cSrcweir         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>=
666*cdf0e10cSrcweir             xComponentContext;
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 	uno::Reference< container::XIndexContainer > xMergedMenu(
669*cdf0e10cSrcweir 			xIndAccessFact->createInstanceWithContext( xComponentContext ),
670*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 	FindConnectPoints( xContMenu, nContPoints );
673*cdf0e10cSrcweir 	FindConnectPoints( xOwnMenu, nOwnPoints );
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < xOwnMenu->getCount(); nInd++ )
676*cdf0e10cSrcweir 	{
677*cdf0e10cSrcweir 		if ( nOwnPoints[0] == nInd )
678*cdf0e10cSrcweir 		{
679*cdf0e10cSrcweir 			if ( nContPoints[0] >= 0 && nContPoints[0] < xContMenu->getCount() )
680*cdf0e10cSrcweir 			{
681*cdf0e10cSrcweir 				InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[0], aContModuleName, xContDisp );
682*cdf0e10cSrcweir 			}
683*cdf0e10cSrcweir 		}
684*cdf0e10cSrcweir 		else if ( nOwnPoints[1] == nInd )
685*cdf0e10cSrcweir 		{
686*cdf0e10cSrcweir 			if ( nContPoints[1] >= 0 && nContPoints[1] < xContMenu->getCount() )
687*cdf0e10cSrcweir 			{
688*cdf0e10cSrcweir 				InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[1], aContModuleName, xContDisp );
689*cdf0e10cSrcweir 			}
690*cdf0e10cSrcweir 		}
691*cdf0e10cSrcweir 		else
692*cdf0e10cSrcweir 			InsertMenu_Impl( xMergedMenu, nInd, xOwnMenu, nInd, ::rtl::OUString(), xOwnDisp );
693*cdf0e10cSrcweir 	}
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 	return uno::Reference< container::XIndexAccess >( xMergedMenu, uno::UNO_QUERY_THROW );
696*cdf0e10cSrcweir }
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir //---------------------------------------------------------------------------
699*cdf0e10cSrcweir sal_Bool DocumentHolder::MergeMenues_Impl( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xOwnLM,
700*cdf0e10cSrcweir 	   										const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContLM,
701*cdf0e10cSrcweir 											const uno::Reference< frame::XDispatchProvider >& xContDisp,
702*cdf0e10cSrcweir 											const ::rtl::OUString& aContModuleName )
703*cdf0e10cSrcweir {
704*cdf0e10cSrcweir 	sal_Bool bMenuMerged = sal_False;
705*cdf0e10cSrcweir 	try
706*cdf0e10cSrcweir 	{
707*cdf0e10cSrcweir         uno::Reference< ::com::sun::star::ui::XUIElementSettings > xUISettings(
708*cdf0e10cSrcweir 			xContLM->getElement(
709*cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ) ),
710*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
711*cdf0e10cSrcweir 		uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings( sal_True );
712*cdf0e10cSrcweir 		if ( !xContMenu.is() )
713*cdf0e10cSrcweir 			throw uno::RuntimeException();
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir 		uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl();
716*cdf0e10cSrcweir 		uno::Reference< frame::XDispatchProvider > xOwnDisp( m_xFrame, uno::UNO_QUERY_THROW );
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 		uno::Reference< container::XIndexAccess > xMergedMenu = MergeMenuesForInplace( xContMenu, xContDisp, aContModuleName, xOwnMenu, xOwnDisp );
719*cdf0e10cSrcweir 		uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM,
720*cdf0e10cSrcweir 																						 uno::UNO_QUERY_THROW );
721*cdf0e10cSrcweir 		bMenuMerged = xMerge->setMergedMenuBar( xMergedMenu );
722*cdf0e10cSrcweir 	}
723*cdf0e10cSrcweir 	catch( uno::Exception& )
724*cdf0e10cSrcweir 	{}
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir 	return bMenuMerged;
727*cdf0e10cSrcweir }
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir sal_Bool DocumentHolder::ShowUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM,
730*cdf0e10cSrcweir 								 const uno::Reference< frame::XDispatchProvider >& xContainerDP,
731*cdf0e10cSrcweir 								 const ::rtl::OUString& aContModuleName )
732*cdf0e10cSrcweir {
733*cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
734*cdf0e10cSrcweir 	if ( xContainerLM.is() )
735*cdf0e10cSrcweir 	{
736*cdf0e10cSrcweir         // the LM of the embedded frame and its current DockingAreaAcceptor
737*cdf0e10cSrcweir 	   	uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
738*cdf0e10cSrcweir    		uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir         try
741*cdf0e10cSrcweir         {
742*cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
743*cdf0e10cSrcweir 			xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
744*cdf0e10cSrcweir             xDocAreaAcc = xContainerLM->getDockingAreaAcceptor();
745*cdf0e10cSrcweir         }
746*cdf0e10cSrcweir         catch( uno::Exception& ){}
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir         // make sure that lock state of LM is correct even if an exception is thrown in between
749*cdf0e10cSrcweir         sal_Bool bUnlock = sal_False;
750*cdf0e10cSrcweir         sal_Bool bLock = sal_False;
751*cdf0e10cSrcweir         if ( xOwnLM.is() && xDocAreaAcc.is() )
752*cdf0e10cSrcweir 		{
753*cdf0e10cSrcweir 			try
754*cdf0e10cSrcweir 			{
755*cdf0e10cSrcweir                 // take over the control over the containers window
756*cdf0e10cSrcweir                 // as long as the LM is invisible and locked an empty tool space will be used on resizing
757*cdf0e10cSrcweir                 xOwnLM->setDockingAreaAcceptor( xDocAreaAcc );
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir                 // try to merge menues; don't do anything else if it fails
760*cdf0e10cSrcweir 				if ( MergeMenues_Impl( xOwnLM, xContainerLM, xContainerDP, aContModuleName ) )
761*cdf0e10cSrcweir 				{
762*cdf0e10cSrcweir                     // make sure that the container LM does not control the size of the containers window anymore
763*cdf0e10cSrcweir                     // this must be done after merging menues as we won't get the container menu otherwise
764*cdf0e10cSrcweir                     xContainerLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir                     // prevent further changes at this LM
767*cdf0e10cSrcweir                     xContainerLM->setVisible( sal_False );
768*cdf0e10cSrcweir                		xContainerLM->lock();
769*cdf0e10cSrcweir                     bUnlock = sal_True;
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir                     // by unlocking the LM each layout change will now resize the containers window; pending layouts will be processed now
772*cdf0e10cSrcweir                     xOwnLM->setVisible( sal_True );
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir                     uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
775*cdf0e10cSrcweir                     if ( xSupp.is() )
776*cdf0e10cSrcweir                         xSupp->setActiveFrame( m_xFrame );
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir                     xOwnLM->unlock();
779*cdf0e10cSrcweir                     bLock = sal_True;
780*cdf0e10cSrcweir                		bResult = sal_True;
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir                     // TODO/LATER: The following action should be done only if the window is not hidden
783*cdf0e10cSrcweir                     // otherwise the activation must fail, unfortunatelly currently it is not possible
784*cdf0e10cSrcweir                     // to detect whether the window is hidden using UNO API
785*cdf0e10cSrcweir                     m_xOwnWindow->setFocus();
786*cdf0e10cSrcweir                 }
787*cdf0e10cSrcweir 			}
788*cdf0e10cSrcweir 			catch( uno::Exception& )
789*cdf0e10cSrcweir 			{
790*cdf0e10cSrcweir                 // activation failed; reestablish old state
791*cdf0e10cSrcweir                 try
792*cdf0e10cSrcweir                 {
793*cdf0e10cSrcweir                     uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
794*cdf0e10cSrcweir                     if ( xSupp.is() )
795*cdf0e10cSrcweir                         xSupp->setActiveFrame( 0 );
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir                     // remove control about containers window from own LM
798*cdf0e10cSrcweir                     if ( bLock )
799*cdf0e10cSrcweir                         xOwnLM->lock();
800*cdf0e10cSrcweir                     xOwnLM->setVisible( sal_False );
801*cdf0e10cSrcweir                     xOwnLM->setDockingAreaAcceptor( uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor >() );
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir                     // unmerge menu
804*cdf0e10cSrcweir                     uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
805*cdf0e10cSrcweir                     xMerge->removeMergedMenuBar();
806*cdf0e10cSrcweir                 }
807*cdf0e10cSrcweir                 catch( uno::Exception& ) {}
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir                 try
810*cdf0e10cSrcweir                 {
811*cdf0e10cSrcweir                     // reestablish control of containers window
812*cdf0e10cSrcweir                     xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
813*cdf0e10cSrcweir 					xContainerLM->setVisible( sal_True );
814*cdf0e10cSrcweir                     if ( bUnlock )
815*cdf0e10cSrcweir                         xContainerLM->unlock();
816*cdf0e10cSrcweir                 }
817*cdf0e10cSrcweir                 catch( uno::Exception& ) {}
818*cdf0e10cSrcweir 			}
819*cdf0e10cSrcweir 		}
820*cdf0e10cSrcweir 	}
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 	return bResult;
823*cdf0e10cSrcweir }
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir //---------------------------------------------------------------------------
826*cdf0e10cSrcweir sal_Bool DocumentHolder::HideUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM )
827*cdf0e10cSrcweir {
828*cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir 	if ( xContainerLM.is() )
831*cdf0e10cSrcweir 	{
832*cdf0e10cSrcweir 	   	uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir 		try {
835*cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
836*cdf0e10cSrcweir 			xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
837*cdf0e10cSrcweir 		} catch( uno::Exception& )
838*cdf0e10cSrcweir 		{}
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir 		if ( xOwnLM.is() )
841*cdf0e10cSrcweir 		{
842*cdf0e10cSrcweir 			try {
843*cdf0e10cSrcweir                 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
844*cdf0e10cSrcweir                 if ( xSupp.is() )
845*cdf0e10cSrcweir                     xSupp->setActiveFrame( 0 );
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir                 uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc = xOwnLM->getDockingAreaAcceptor();
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir                 xOwnLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
850*cdf0e10cSrcweir                 xOwnLM->lock();
851*cdf0e10cSrcweir 				xOwnLM->setVisible( sal_False );
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir                 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
854*cdf0e10cSrcweir 				xMerge->removeMergedMenuBar();
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir                 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
857*cdf0e10cSrcweir 				xContainerLM->setVisible( sal_True );
858*cdf0e10cSrcweir 				xContainerLM->unlock();
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir             	xContainerLM->doLayout();
861*cdf0e10cSrcweir 				bResult = sal_True;
862*cdf0e10cSrcweir 			}
863*cdf0e10cSrcweir 			catch( uno::Exception& )
864*cdf0e10cSrcweir 			{
865*cdf0e10cSrcweir 				SetFrameLMVisibility( m_xFrame, sal_True );
866*cdf0e10cSrcweir 			}
867*cdf0e10cSrcweir 		}
868*cdf0e10cSrcweir 	}
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir 	return bResult;
871*cdf0e10cSrcweir }
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir //---------------------------------------------------------------------------
874*cdf0e10cSrcweir uno::Reference< frame::XFrame > DocumentHolder::GetDocFrame()
875*cdf0e10cSrcweir {
876*cdf0e10cSrcweir 	// the frame for outplace activation
877*cdf0e10cSrcweir 	if ( !m_xFrame.is() )
878*cdf0e10cSrcweir 	{
879*cdf0e10cSrcweir         uno::Reference< lang::XSingleServiceFactory > xFrameFact(
880*cdf0e10cSrcweir 			m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.TaskCreator" ) ),
881*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 		m_xFrame.set(xFrameFact->createInstanceWithArguments( m_aOutplaceFrameProps ), uno::UNO_QUERY_THROW);
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir 		uno::Reference< frame::XDispatchProviderInterception > xInterception( m_xFrame, uno::UNO_QUERY );
886*cdf0e10cSrcweir 		if ( xInterception.is() )
887*cdf0e10cSrcweir 		{
888*cdf0e10cSrcweir 			if ( m_pInterceptor )
889*cdf0e10cSrcweir 			{
890*cdf0e10cSrcweir 				m_pInterceptor->DisconnectDocHolder();
891*cdf0e10cSrcweir 				m_pInterceptor->release();
892*cdf0e10cSrcweir 				m_pInterceptor = NULL;
893*cdf0e10cSrcweir 			}
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir 			m_pInterceptor = new Interceptor( this );
896*cdf0e10cSrcweir 			m_pInterceptor->acquire();
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir 			// register interceptor from outside
899*cdf0e10cSrcweir 			if ( m_xOutplaceInterceptor.is() )
900*cdf0e10cSrcweir 				xInterception->registerDispatchProviderInterceptor( m_xOutplaceInterceptor );
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 			xInterception->registerDispatchProviderInterceptor( m_pInterceptor );
903*cdf0e10cSrcweir 		}
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
906*cdf0e10cSrcweir 		if ( xCloseBroadcaster.is() )
907*cdf0e10cSrcweir 			xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this );
908*cdf0e10cSrcweir 	}
909*cdf0e10cSrcweir 
910*cdf0e10cSrcweir     if ( m_xComponent.is() )
911*cdf0e10cSrcweir     {
912*cdf0e10cSrcweir 		uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
913*cdf0e10cSrcweir 		try {
914*cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
915*cdf0e10cSrcweir 			xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM;
916*cdf0e10cSrcweir 		} catch( uno::Exception& )
917*cdf0e10cSrcweir 		{}
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir 		if ( xOwnLM.is() )
920*cdf0e10cSrcweir 			xOwnLM->lock();
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir         // TODO/LATER: get it for the real aspect
923*cdf0e10cSrcweir         awt::Size aSize;
924*cdf0e10cSrcweir         GetExtent( embed::Aspects::MSOLE_CONTENT, &aSize );
925*cdf0e10cSrcweir         LoadDocToFrame(sal_False);
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir 		if ( xOwnLM.is() )
928*cdf0e10cSrcweir 		{
929*cdf0e10cSrcweir 			xOwnLM->unlock();
930*cdf0e10cSrcweir 			xOwnLM->lock();
931*cdf0e10cSrcweir 		}
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir         SetExtent( embed::Aspects::MSOLE_CONTENT, aSize );
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 		if ( xOwnLM.is() )
936*cdf0e10cSrcweir 			xOwnLM->unlock();
937*cdf0e10cSrcweir     }
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir     try
940*cdf0e10cSrcweir     {
941*cdf0e10cSrcweir         uno::Reference< awt::XWindow > xHWindow = m_xFrame->getContainerWindow();
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir         if( xHWindow.is() )
944*cdf0e10cSrcweir         {
945*cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xMonProps( m_xFactory->createInstance(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), uno::UNO_QUERY_THROW );
946*cdf0e10cSrcweir             const rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) );
947*cdf0e10cSrcweir             sal_Int32 nDisplay = 0;
948*cdf0e10cSrcweir             xMonProps->getPropertyValue( sPropName ) >>= nDisplay;
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir             uno::Reference< container::XIndexAccess > xMultiMon( xMonProps, uno::UNO_QUERY_THROW );
951*cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xMonitor( xMultiMon->getByIndex( nDisplay ), uno::UNO_QUERY_THROW );
952*cdf0e10cSrcweir             awt::Rectangle aWorkRect;
953*cdf0e10cSrcweir             xMonitor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WorkArea" ) ) ) >>= aWorkRect;
954*cdf0e10cSrcweir             awt::Rectangle aWindowRect = xHWindow->getPosSize();
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir             if (( aWindowRect.Width < aWorkRect.Width) && ( aWindowRect.Height < aWorkRect.Height ))
957*cdf0e10cSrcweir             {
958*cdf0e10cSrcweir                 int OffsetX = ( aWorkRect.Width - aWindowRect.Width ) / 2 + aWorkRect.X;
959*cdf0e10cSrcweir                 int OffsetY = ( aWorkRect.Height - aWindowRect.Height ) /2 + aWorkRect.Y;
960*cdf0e10cSrcweir                 xHWindow->setPosSize( OffsetX, OffsetY, aWindowRect.Width, aWindowRect.Height, awt::PosSize::POS );
961*cdf0e10cSrcweir             }
962*cdf0e10cSrcweir             else
963*cdf0e10cSrcweir             {
964*cdf0e10cSrcweir                 xHWindow->setPosSize( aWorkRect.X, aWorkRect.Y, aWorkRect.Width, aWorkRect.Height, awt::PosSize::POSSIZE );
965*cdf0e10cSrcweir             }
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir             xHWindow->setVisible( sal_True );
968*cdf0e10cSrcweir         }
969*cdf0e10cSrcweir     }
970*cdf0e10cSrcweir     catch ( uno::Exception& )
971*cdf0e10cSrcweir     {
972*cdf0e10cSrcweir     }
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir 	return m_xFrame;
975*cdf0e10cSrcweir }
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir //---------------------------------------------------------------------------
978*cdf0e10cSrcweir void DocumentHolder::SetComponent( const uno::Reference< util::XCloseable >& xDoc, sal_Bool bReadOnly )
979*cdf0e10cSrcweir {
980*cdf0e10cSrcweir     if ( m_xComponent.is() )
981*cdf0e10cSrcweir 	{
982*cdf0e10cSrcweir 		// May be should be improved
983*cdf0e10cSrcweir 		try {
984*cdf0e10cSrcweir 			CloseDocument( sal_True, sal_False );
985*cdf0e10cSrcweir 		} catch( uno::Exception& )
986*cdf0e10cSrcweir 		{}
987*cdf0e10cSrcweir 	}
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir     m_xComponent = xDoc;
990*cdf0e10cSrcweir     // done outside currently uno::Reference < container::XChild > xChild( m_xComponent, uno::UNO_QUERY );
991*cdf0e10cSrcweir     // done outside currently if ( xChild.is() && m_pEmbedObj )
992*cdf0e10cSrcweir     // done outside currently 	xChild->setParent( m_pEmbedObj->getParent() );
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir 	m_bReadOnly = bReadOnly;
995*cdf0e10cSrcweir     m_bAllowClosing = sal_False;
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir     uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
998*cdf0e10cSrcweir 	if ( xBroadcaster.is() )
999*cdf0e10cSrcweir 		xBroadcaster->addCloseListener( ( util::XCloseListener* )this );
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
1002*cdf0e10cSrcweir 	if ( xEventBroadcaster.is() )
1003*cdf0e10cSrcweir 		xEventBroadcaster->addEventListener( ( document::XEventListener* )this );
1004*cdf0e10cSrcweir 	else
1005*cdf0e10cSrcweir 	{
1006*cdf0e10cSrcweir 		// the object does not support document::XEventBroadcaster interface
1007*cdf0e10cSrcweir 		// use the workaround, register for modified events
1008*cdf0e10cSrcweir 		uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
1009*cdf0e10cSrcweir 		if ( xModifyBroadcaster.is() )
1010*cdf0e10cSrcweir 			xModifyBroadcaster->addModifyListener( ( util::XModifyListener* )this );
1011*cdf0e10cSrcweir 	}
1012*cdf0e10cSrcweir 
1013*cdf0e10cSrcweir 	if ( m_xFrame.is() )
1014*cdf0e10cSrcweir         LoadDocToFrame(sal_False);
1015*cdf0e10cSrcweir }
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir //---------------------------------------------------------------------------
1018*cdf0e10cSrcweir sal_Bool DocumentHolder::LoadDocToFrame( sal_Bool bInPlace )
1019*cdf0e10cSrcweir {
1020*cdf0e10cSrcweir     if ( m_xFrame.is() && m_xComponent.is() )
1021*cdf0e10cSrcweir 	{
1022*cdf0e10cSrcweir         uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
1023*cdf0e10cSrcweir         if ( xDoc.is() )
1024*cdf0e10cSrcweir         {
1025*cdf0e10cSrcweir             // load new document in to the frame
1026*cdf0e10cSrcweir             uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY_THROW );
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArgs;
1029*cdf0e10cSrcweir             aArgs.put( "Model", m_xComponent );
1030*cdf0e10cSrcweir             aArgs.put( "ReadOnly", m_bReadOnly );
1031*cdf0e10cSrcweir             //aArgs.put( "Hidden", sal_True );
1032*cdf0e10cSrcweir             if ( bInPlace )
1033*cdf0e10cSrcweir                 aArgs.put( "PluginMode", sal_Int16(1) );
1034*cdf0e10cSrcweir 			::rtl::OUString sUrl;
1035*cdf0e10cSrcweir 			uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
1036*cdf0e10cSrcweir 			if (	xServiceInfo.is()
1037*cdf0e10cSrcweir 				&&	xServiceInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportDefinition"))) )
1038*cdf0e10cSrcweir 			{
1039*cdf0e10cSrcweir 				sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".component:DB/ReportDesign"));
1040*cdf0e10cSrcweir 			}
1041*cdf0e10cSrcweir             else if( xServiceInfo.is()
1042*cdf0e10cSrcweir 				&&   xServiceInfo->supportsService( ::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartDocument")) )
1043*cdf0e10cSrcweir 				sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/schart"));
1044*cdf0e10cSrcweir 			else
1045*cdf0e10cSrcweir 				sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:object"));
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir             xComponentLoader->loadComponentFromURL( sUrl,
1048*cdf0e10cSrcweir                                                         rtl::OUString::createFromAscii( "_self" ),
1049*cdf0e10cSrcweir                                                         0,
1050*cdf0e10cSrcweir                                                         aArgs.getPropertyValues() );
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir             return sal_True;
1053*cdf0e10cSrcweir         }
1054*cdf0e10cSrcweir         else
1055*cdf0e10cSrcweir         {
1056*cdf0e10cSrcweir             uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY );
1057*cdf0e10cSrcweir             if ( xLoader.is() )
1058*cdf0e10cSrcweir                 return xLoader->load( uno::Sequence < beans::PropertyValue >(), m_xFrame );
1059*cdf0e10cSrcweir             else
1060*cdf0e10cSrcweir                 return sal_False;
1061*cdf0e10cSrcweir         }
1062*cdf0e10cSrcweir 	}
1063*cdf0e10cSrcweir 
1064*cdf0e10cSrcweir     return sal_True;
1065*cdf0e10cSrcweir }
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir //---------------------------------------------------------------------------
1068*cdf0e10cSrcweir void DocumentHolder::Show()
1069*cdf0e10cSrcweir {
1070*cdf0e10cSrcweir 	if( m_xFrame.is() )
1071*cdf0e10cSrcweir 	{
1072*cdf0e10cSrcweir 		m_xFrame->activate();
1073*cdf0e10cSrcweir 		uno::Reference<awt::XTopWindow> xTopWindow( m_xFrame->getContainerWindow(), uno::UNO_QUERY );
1074*cdf0e10cSrcweir 		if( xTopWindow.is() )
1075*cdf0e10cSrcweir 			xTopWindow->toFront();
1076*cdf0e10cSrcweir 	}
1077*cdf0e10cSrcweir 	else
1078*cdf0e10cSrcweir 		GetDocFrame();
1079*cdf0e10cSrcweir }
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir //---------------------------------------------------------------------------
1082*cdf0e10cSrcweir sal_Bool DocumentHolder::SetExtent( sal_Int64 nAspect, const awt::Size& aSize )
1083*cdf0e10cSrcweir {
1084*cdf0e10cSrcweir     uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1085*cdf0e10cSrcweir 	if ( xDocVis.is() )
1086*cdf0e10cSrcweir 	{
1087*cdf0e10cSrcweir 		try
1088*cdf0e10cSrcweir 		{
1089*cdf0e10cSrcweir 			xDocVis->setVisualAreaSize( nAspect, aSize );
1090*cdf0e10cSrcweir 			return sal_True;
1091*cdf0e10cSrcweir 		}
1092*cdf0e10cSrcweir 		catch( uno::Exception& )
1093*cdf0e10cSrcweir 		{
1094*cdf0e10cSrcweir 			// TODO: Error handling
1095*cdf0e10cSrcweir 		}
1096*cdf0e10cSrcweir 	}
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir 	return sal_False;
1099*cdf0e10cSrcweir }
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir //---------------------------------------------------------------------------
1102*cdf0e10cSrcweir sal_Bool DocumentHolder::GetExtent( sal_Int64 nAspect, awt::Size *pSize )
1103*cdf0e10cSrcweir {
1104*cdf0e10cSrcweir     uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1105*cdf0e10cSrcweir 	if ( pSize && xDocVis.is() )
1106*cdf0e10cSrcweir 	{
1107*cdf0e10cSrcweir 		try
1108*cdf0e10cSrcweir 		{
1109*cdf0e10cSrcweir 			*pSize = xDocVis->getVisualAreaSize( nAspect );
1110*cdf0e10cSrcweir 			return sal_True;
1111*cdf0e10cSrcweir 		}
1112*cdf0e10cSrcweir 		catch( uno::Exception& )
1113*cdf0e10cSrcweir 		{
1114*cdf0e10cSrcweir 			// TODO: Error handling
1115*cdf0e10cSrcweir 		}
1116*cdf0e10cSrcweir 	}
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir 	return sal_False;
1119*cdf0e10cSrcweir }
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir //---------------------------------------------------------------------------
1122*cdf0e10cSrcweir sal_Int32 DocumentHolder::GetMapUnit( sal_Int64 nAspect )
1123*cdf0e10cSrcweir {
1124*cdf0e10cSrcweir     uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1125*cdf0e10cSrcweir 	if ( xDocVis.is() )
1126*cdf0e10cSrcweir 	{
1127*cdf0e10cSrcweir 		try
1128*cdf0e10cSrcweir 		{
1129*cdf0e10cSrcweir             return xDocVis->getMapUnit( nAspect );
1130*cdf0e10cSrcweir 		}
1131*cdf0e10cSrcweir 		catch( uno::Exception& )
1132*cdf0e10cSrcweir 		{
1133*cdf0e10cSrcweir 			// TODO: Error handling
1134*cdf0e10cSrcweir 		}
1135*cdf0e10cSrcweir 	}
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir 	return 0;
1138*cdf0e10cSrcweir }
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir //---------------------------------------------------------------------------
1141*cdf0e10cSrcweir awt::Rectangle DocumentHolder::CalculateBorderedArea( const awt::Rectangle& aRect )
1142*cdf0e10cSrcweir {
1143*cdf0e10cSrcweir 	return awt::Rectangle( aRect.X + m_aBorderWidths.Left + HATCH_BORDER_WIDTH,
1144*cdf0e10cSrcweir 							 aRect.Y + m_aBorderWidths.Top + HATCH_BORDER_WIDTH,
1145*cdf0e10cSrcweir 							 aRect.Width - m_aBorderWidths.Left - m_aBorderWidths.Right - 2*HATCH_BORDER_WIDTH,
1146*cdf0e10cSrcweir 							 aRect.Height - m_aBorderWidths.Top - m_aBorderWidths.Bottom - 2*HATCH_BORDER_WIDTH );
1147*cdf0e10cSrcweir }
1148*cdf0e10cSrcweir 
1149*cdf0e10cSrcweir //---------------------------------------------------------------------------
1150*cdf0e10cSrcweir awt::Rectangle DocumentHolder::AddBorderToArea( const awt::Rectangle& aRect )
1151*cdf0e10cSrcweir {
1152*cdf0e10cSrcweir 	return awt::Rectangle( aRect.X - m_aBorderWidths.Left - HATCH_BORDER_WIDTH,
1153*cdf0e10cSrcweir 							 aRect.Y - m_aBorderWidths.Top - HATCH_BORDER_WIDTH,
1154*cdf0e10cSrcweir 							 aRect.Width + m_aBorderWidths.Left + m_aBorderWidths.Right + 2*HATCH_BORDER_WIDTH,
1155*cdf0e10cSrcweir 							 aRect.Height + m_aBorderWidths.Top + m_aBorderWidths.Bottom + 2*HATCH_BORDER_WIDTH );
1156*cdf0e10cSrcweir }
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir //---------------------------------------------------------------------------
1159*cdf0e10cSrcweir void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource )
1160*cdf0e10cSrcweir 		throw (uno::RuntimeException)
1161*cdf0e10cSrcweir {
1162*cdf0e10cSrcweir     if ( m_xComponent.is() && m_xComponent == aSource.Source )
1163*cdf0e10cSrcweir 	{
1164*cdf0e10cSrcweir         m_xComponent = 0;
1165*cdf0e10cSrcweir 		if ( m_bWaitForClose )
1166*cdf0e10cSrcweir 		{
1167*cdf0e10cSrcweir 			m_bWaitForClose = sal_False;
1168*cdf0e10cSrcweir 			FreeOffice();
1169*cdf0e10cSrcweir 		}
1170*cdf0e10cSrcweir 	}
1171*cdf0e10cSrcweir 
1172*cdf0e10cSrcweir 	if( m_xFrame.is() && m_xFrame == aSource.Source )
1173*cdf0e10cSrcweir 	{
1174*cdf0e10cSrcweir 		m_xHatchWindow = uno::Reference< awt::XWindow >();
1175*cdf0e10cSrcweir 		m_xOwnWindow = uno::Reference< awt::XWindow >();
1176*cdf0e10cSrcweir 		m_xFrame = uno::Reference< frame::XFrame >();
1177*cdf0e10cSrcweir 	}
1178*cdf0e10cSrcweir }
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir //---------------------------------------------------------------------------
1182*cdf0e10cSrcweir void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool /*bGetsOwnership*/ )
1183*cdf0e10cSrcweir 		throw (util::CloseVetoException, uno::RuntimeException)
1184*cdf0e10cSrcweir {
1185*cdf0e10cSrcweir     if ( m_xComponent.is() && m_xComponent == aSource.Source && !m_bAllowClosing )
1186*cdf0e10cSrcweir 		throw util::CloseVetoException();
1187*cdf0e10cSrcweir }
1188*cdf0e10cSrcweir 
1189*cdf0e10cSrcweir //---------------------------------------------------------------------------
1190*cdf0e10cSrcweir void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
1191*cdf0e10cSrcweir 		throw (uno::RuntimeException)
1192*cdf0e10cSrcweir {
1193*cdf0e10cSrcweir     if ( m_xComponent.is() && m_xComponent == aSource.Source )
1194*cdf0e10cSrcweir 	{
1195*cdf0e10cSrcweir         m_xComponent = 0;
1196*cdf0e10cSrcweir 		if ( m_bWaitForClose )
1197*cdf0e10cSrcweir 		{
1198*cdf0e10cSrcweir 			m_bWaitForClose = sal_False;
1199*cdf0e10cSrcweir 			FreeOffice();
1200*cdf0e10cSrcweir 		}
1201*cdf0e10cSrcweir 	}
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir 	if( m_xFrame.is() && m_xFrame == aSource.Source )
1204*cdf0e10cSrcweir 	{
1205*cdf0e10cSrcweir 		m_xHatchWindow = uno::Reference< awt::XWindow >();
1206*cdf0e10cSrcweir 		m_xOwnWindow = uno::Reference< awt::XWindow >();
1207*cdf0e10cSrcweir 		m_xFrame = uno::Reference< frame::XFrame >();
1208*cdf0e10cSrcweir 	}
1209*cdf0e10cSrcweir }
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir //---------------------------------------------------------------------------
1212*cdf0e10cSrcweir void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& )
1213*cdf0e10cSrcweir 		throw (frame::TerminationVetoException, uno::RuntimeException)
1214*cdf0e10cSrcweir {
1215*cdf0e10cSrcweir 	if ( m_bWaitForClose )
1216*cdf0e10cSrcweir 		throw frame::TerminationVetoException();
1217*cdf0e10cSrcweir }
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir //---------------------------------------------------------------------------
1220*cdf0e10cSrcweir void SAL_CALL DocumentHolder::notifyTermination( const lang::EventObject& aSource )
1221*cdf0e10cSrcweir 		throw (uno::RuntimeException)
1222*cdf0e10cSrcweir {
1223*cdf0e10cSrcweir     OSL_ENSURE( !m_xComponent.is(), "Just a disaster..." );
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 	uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY );
1226*cdf0e10cSrcweir     m_bDesktopTerminated = sal_True;
1227*cdf0e10cSrcweir 	if ( xDesktop.is() )
1228*cdf0e10cSrcweir 		xDesktop->removeTerminateListener( ( frame::XTerminateListener* )this );
1229*cdf0e10cSrcweir }
1230*cdf0e10cSrcweir 
1231*cdf0e10cSrcweir //---------------------------------------------------------------------------
1232*cdf0e10cSrcweir void SAL_CALL DocumentHolder::modified( const lang::EventObject& aEvent )
1233*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
1234*cdf0e10cSrcweir {
1235*cdf0e10cSrcweir 	// if the component does not support document::XEventBroadcaster
1236*cdf0e10cSrcweir 	// the modify notifications are used as workaround, but only for running state
1237*cdf0e10cSrcweir 	if( aEvent.Source == m_xComponent && m_pEmbedObj && m_pEmbedObj->getCurrentState() == embed::EmbedStates::RUNNING )
1238*cdf0e10cSrcweir 		m_pEmbedObj->PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ), aEvent.Source );
1239*cdf0e10cSrcweir }
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir //---------------------------------------------------------------------------
1242*cdf0e10cSrcweir void SAL_CALL DocumentHolder::notifyEvent( const document::EventObject& Event )
1243*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
1244*cdf0e10cSrcweir {
1245*cdf0e10cSrcweir     if( m_pEmbedObj && Event.Source == m_xComponent )
1246*cdf0e10cSrcweir 	{
1247*cdf0e10cSrcweir 		// for now the ignored events are not forwarded, but sent by the object itself
1248*cdf0e10cSrcweir 		if ( !Event.EventName.equalsAscii( "OnSave" )
1249*cdf0e10cSrcweir 		  && !Event.EventName.equalsAscii( "OnSaveDone" )
1250*cdf0e10cSrcweir 		  && !Event.EventName.equalsAscii( "OnSaveAs" )
1251*cdf0e10cSrcweir 		  && !Event.EventName.equalsAscii( "OnSaveAsDone" )
1252*cdf0e10cSrcweir 		  && !( Event.EventName.equalsAscii( "OnVisAreaChanged" ) && m_nNoResizeReact ) )
1253*cdf0e10cSrcweir 			m_pEmbedObj->PostEvent_Impl( Event.EventName, Event.Source );
1254*cdf0e10cSrcweir 	}
1255*cdf0e10cSrcweir }
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir //---------------------------------------------------------------------------
1258*cdf0e10cSrcweir void SAL_CALL DocumentHolder::borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject,
1259*cdf0e10cSrcweir 													const frame::BorderWidths& aNewSize )
1260*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
1261*cdf0e10cSrcweir {
1262*cdf0e10cSrcweir 	// TODO: may require mutex introduction ???
1263*cdf0e10cSrcweir 	if ( m_pEmbedObj && m_xFrame.is() && aObject == m_xFrame->getController() )
1264*cdf0e10cSrcweir 	{
1265*cdf0e10cSrcweir 		if ( m_aBorderWidths.Left != aNewSize.Left
1266*cdf0e10cSrcweir 		  || m_aBorderWidths.Right != aNewSize.Right
1267*cdf0e10cSrcweir 		  || m_aBorderWidths.Top != aNewSize.Top
1268*cdf0e10cSrcweir 		  || m_aBorderWidths.Bottom != aNewSize.Bottom )
1269*cdf0e10cSrcweir 		{
1270*cdf0e10cSrcweir 			m_aBorderWidths = aNewSize;
1271*cdf0e10cSrcweir 			if ( !m_nNoBorderResizeReact )
1272*cdf0e10cSrcweir 				PlaceFrame( m_aObjRect );
1273*cdf0e10cSrcweir 		}
1274*cdf0e10cSrcweir 	}
1275*cdf0e10cSrcweir }
1276*cdf0e10cSrcweir 
1277*cdf0e10cSrcweir //---------------------------------------------------------------------------
1278*cdf0e10cSrcweir void SAL_CALL DocumentHolder::requestPositioning( const awt::Rectangle& aRect )
1279*cdf0e10cSrcweir 	throw (uno::RuntimeException)
1280*cdf0e10cSrcweir {
1281*cdf0e10cSrcweir 	// TODO: may require mutex introduction ???
1282*cdf0e10cSrcweir 	if ( m_pEmbedObj )
1283*cdf0e10cSrcweir 	{
1284*cdf0e10cSrcweir 		// borders should not be counted
1285*cdf0e10cSrcweir 		awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1286*cdf0e10cSrcweir 		IntCounterGuard aGuard( m_nNoResizeReact );
1287*cdf0e10cSrcweir 		m_pEmbedObj->requestPositioning( aObjRect );
1288*cdf0e10cSrcweir 	}
1289*cdf0e10cSrcweir }
1290*cdf0e10cSrcweir 
1291*cdf0e10cSrcweir //---------------------------------------------------------------------------
1292*cdf0e10cSrcweir awt::Rectangle SAL_CALL DocumentHolder::calcAdjustedRectangle( const awt::Rectangle& aRect )
1293*cdf0e10cSrcweir 	throw (uno::RuntimeException)
1294*cdf0e10cSrcweir {
1295*cdf0e10cSrcweir 	// Solar mutex should be locked already since this is a call from HatchWindow with focus
1296*cdf0e10cSrcweir 	awt::Rectangle aResult( aRect );
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir 	if ( m_xFrame.is() )
1299*cdf0e10cSrcweir 	{
1300*cdf0e10cSrcweir 		// borders should not be counted
1301*cdf0e10cSrcweir 		uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
1302*cdf0e10cSrcweir 		if ( xControllerBorder.is() )
1303*cdf0e10cSrcweir 		{
1304*cdf0e10cSrcweir 			awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1305*cdf0e10cSrcweir 			aObjRect = xControllerBorder->queryBorderedArea( aObjRect );
1306*cdf0e10cSrcweir 			aResult = AddBorderToArea( aObjRect );
1307*cdf0e10cSrcweir 		}
1308*cdf0e10cSrcweir 	}
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir 	awt::Rectangle aMinRectangle = AddBorderToArea( awt::Rectangle() );
1311*cdf0e10cSrcweir 	if ( aResult.Width < aMinRectangle.Width + 2 )
1312*cdf0e10cSrcweir 		aResult.Width = aMinRectangle.Width + 2;
1313*cdf0e10cSrcweir 	if ( aResult.Height < aMinRectangle.Height + 2 )
1314*cdf0e10cSrcweir 		aResult.Height = aMinRectangle.Height + 2;
1315*cdf0e10cSrcweir 
1316*cdf0e10cSrcweir 	return aResult;
1317*cdf0e10cSrcweir }
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir void SAL_CALL DocumentHolder::activated(  ) throw (::com::sun::star::uno::RuntimeException)
1320*cdf0e10cSrcweir {
1321*cdf0e10cSrcweir     if ( (m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) )
1322*cdf0e10cSrcweir     {
1323*cdf0e10cSrcweir         if ( m_pEmbedObj->getCurrentState() != embed::EmbedStates::UI_ACTIVE &&
1324*cdf0e10cSrcweir         !(m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
1325*cdf0e10cSrcweir         {
1326*cdf0e10cSrcweir             try
1327*cdf0e10cSrcweir             {
1328*cdf0e10cSrcweir                 m_pEmbedObj->changeState( embed::EmbedStates::UI_ACTIVE );
1329*cdf0e10cSrcweir             }
1330*cdf0e10cSrcweir             catch ( com::sun::star::embed::StateChangeInProgressException& )
1331*cdf0e10cSrcweir             {
1332*cdf0e10cSrcweir                 // must catch this exception because focus is grabbed while UI activation in doVerb()
1333*cdf0e10cSrcweir             }
1334*cdf0e10cSrcweir             catch ( com::sun::star::uno::Exception& )
1335*cdf0e10cSrcweir             {
1336*cdf0e10cSrcweir                 // no outgoing exceptions specified here
1337*cdf0e10cSrcweir             }
1338*cdf0e10cSrcweir         }
1339*cdf0e10cSrcweir         else
1340*cdf0e10cSrcweir         {
1341*cdf0e10cSrcweir             uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
1342*cdf0e10cSrcweir             if ( xSupp.is() )
1343*cdf0e10cSrcweir                 xSupp->setActiveFrame( m_xFrame );
1344*cdf0e10cSrcweir         }
1345*cdf0e10cSrcweir     }
1346*cdf0e10cSrcweir }
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir void DocumentHolder::ResizeHatchWindow()
1349*cdf0e10cSrcweir {
1350*cdf0e10cSrcweir     awt::Rectangle aHatchRect = AddBorderToArea( m_aObjRect );
1351*cdf0e10cSrcweir     ResizeWindows_Impl( aHatchRect );
1352*cdf0e10cSrcweir     uno::Reference< embed::XHatchWindow > xHatchWindow( m_xHatchWindow, uno::UNO_QUERY );
1353*cdf0e10cSrcweir     xHatchWindow->setHatchBorderSize( awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
1354*cdf0e10cSrcweir }
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir void SAL_CALL DocumentHolder::deactivated(  ) throw (::com::sun::star::uno::RuntimeException)
1357*cdf0e10cSrcweir {
1358*cdf0e10cSrcweir     // deactivation is too unspecific to be useful; usually we only trigger code from activation
1359*cdf0e10cSrcweir     // so UIDeactivation is actively triggered by the container
1360*cdf0e10cSrcweir }
1361