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 #if defined(_MSC_VER) && (_MSC_VER > 1310)
28*cdf0e10cSrcweir #pragma warning(disable : 4917 4555)
29*cdf0e10cSrcweir #endif
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "xwin.hxx"
33*cdf0e10cSrcweir #include "docholder.hxx"
34*cdf0e10cSrcweir #include "embeddoc.hxx"
35*cdf0e10cSrcweir #include "intercept.hxx"
36*cdf0e10cSrcweir #include "syswinwrapper.hxx"
37*cdf0e10cSrcweir #include "iipaobj.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "common.h"
40*cdf0e10cSrcweir #include <Windows.h>
41*cdf0e10cSrcweir #include <com/sun/star/lang/SystemDependent.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/awt/XSystemChildFactory.hpp>
43*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_AWT_XSYSTEMDEPENDENTWINDOWPERR_HPP_
44*cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/ui/XUIElement.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/util/XCloseAble.hpp>
54*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACESS_HPP_
55*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/awt/XView.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
69*cdf0e10cSrcweir #include <com/sun/star/bridge/ModelDependent.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp>
71*cdf0e10cSrcweir #include <com/sun/star/embed/XVisualObject.hpp>
72*cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp>
73*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
74*cdf0e10cSrcweir #include <osl/diagnose.h>
75*cdf0e10cSrcweir #include <rtl/process.h>
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir using namespace ::com::sun::star;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir extern ::rtl::OUString	getFilterNameFromGUID_Impl( GUID* );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir // add mutex locking ???
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir DocumentHolder::DocumentHolder(
84*cdf0e10cSrcweir 	const uno::Reference<lang::XMultiServiceFactory >& xFactory,
85*cdf0e10cSrcweir 	const ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl >& xOleAccess )
86*cdf0e10cSrcweir 	:
87*cdf0e10cSrcweir 	m_bAllowInPlace(true),
88*cdf0e10cSrcweir 	m_pIOleIPSite(0),
89*cdf0e10cSrcweir 	m_pIOleIPFrame(0),
90*cdf0e10cSrcweir 	m_pIOleIPUIWindow(0),
91*cdf0e10cSrcweir 	m_pCHatchWin(0),
92*cdf0e10cSrcweir 	m_xOleAccess( xOleAccess ),
93*cdf0e10cSrcweir 	m_pInterceptor(0),
94*cdf0e10cSrcweir 	m_xFactory( xFactory ),
95*cdf0e10cSrcweir     m_bOnDeactivate(false),
96*cdf0e10cSrcweir     m_hWndxWinParent(NULL),
97*cdf0e10cSrcweir     m_hWndxWinCont(NULL),
98*cdf0e10cSrcweir     m_nMenuHandle(NULL),
99*cdf0e10cSrcweir     m_nMenuShared(NULL),
100*cdf0e10cSrcweir     m_nOLEMenu(NULL),
101*cdf0e10cSrcweir     m_nMacroExecMode( document::MacroExecMode::USE_CONFIG ),
102*cdf0e10cSrcweir 	m_bLink( sal_False )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	static const ::rtl::OUString aServiceName (
105*cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
106*cdf0e10cSrcweir 	uno::Reference< frame::XDesktop > xDesktop(
107*cdf0e10cSrcweir 		m_xFactory->createInstance( aServiceName ),
108*cdf0e10cSrcweir 		uno::UNO_QUERY );
109*cdf0e10cSrcweir 	if ( xDesktop.is() )
110*cdf0e10cSrcweir 		xDesktop->addTerminateListener( (frame::XTerminateListener*)this );
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir DocumentHolder::~DocumentHolder()
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	delete m_pCHatchWin;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	ClearInterceptorInternally();
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void DocumentHolder::LoadDocInFrame( sal_Bool bPluginMode )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     uno::Reference<frame::XComponentLoader> xComponentLoader(
125*cdf0e10cSrcweir         m_xFrame,uno::UNO_QUERY);
126*cdf0e10cSrcweir     if( xComponentLoader.is() && m_xDocument.is() )
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         uno::Reference< task::XInteractionHandler > xHandler(
129*cdf0e10cSrcweir             m_xFactory->createInstance(
130*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ),
131*cdf0e10cSrcweir             uno::UNO_QUERY );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         uno::Any aAny;
134*cdf0e10cSrcweir         sal_Int32 nLen = 3;
135*cdf0e10cSrcweir         uno::Sequence<beans::PropertyValue> aSeq( nLen );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         aAny <<= uno::Reference<uno::XInterface>(
138*cdf0e10cSrcweir             m_xDocument, uno::UNO_QUERY);
139*cdf0e10cSrcweir         aSeq[0] = beans::PropertyValue(
140*cdf0e10cSrcweir             rtl::OUString(
141*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("Model")),
142*cdf0e10cSrcweir             -1,
143*cdf0e10cSrcweir             aAny,
144*cdf0e10cSrcweir             beans::PropertyState_DIRECT_VALUE);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         aAny <<= sal_False;
147*cdf0e10cSrcweir         aSeq[1] = beans::PropertyValue(
148*cdf0e10cSrcweir             rtl::OUString(
149*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("ReadOnly")),
150*cdf0e10cSrcweir             -1,
151*cdf0e10cSrcweir             aAny,
152*cdf0e10cSrcweir             beans::PropertyState_DIRECT_VALUE);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         aAny <<= (sal_Bool) sal_True;
155*cdf0e10cSrcweir         aSeq[2] = beans::PropertyValue(
156*cdf0e10cSrcweir             rtl::OUString(
157*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("NoAutoSave")),
158*cdf0e10cSrcweir             -1,
159*cdf0e10cSrcweir             aAny,
160*cdf0e10cSrcweir             beans::PropertyState_DIRECT_VALUE);
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         if ( bPluginMode )
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             aSeq.realloc( ++nLen );
165*cdf0e10cSrcweir             aAny <<= (sal_Int16) 3;
166*cdf0e10cSrcweir             aSeq[nLen-1] = beans::PropertyValue(
167*cdf0e10cSrcweir                 rtl::OUString(
168*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM("PluginMode")),
169*cdf0e10cSrcweir                 -1,
170*cdf0e10cSrcweir                 aAny,
171*cdf0e10cSrcweir                 beans::PropertyState_DIRECT_VALUE);
172*cdf0e10cSrcweir         }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         if ( xHandler.is() )
175*cdf0e10cSrcweir         {
176*cdf0e10cSrcweir             aSeq.realloc( nLen+=2 );
177*cdf0e10cSrcweir             aAny <<= xHandler;
178*cdf0e10cSrcweir             aSeq[nLen-2] = beans::PropertyValue(
179*cdf0e10cSrcweir                 rtl::OUString(
180*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")),
181*cdf0e10cSrcweir                 -1,
182*cdf0e10cSrcweir                 aAny,
183*cdf0e10cSrcweir                 beans::PropertyState_DIRECT_VALUE);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir             aAny <<= m_nMacroExecMode;
186*cdf0e10cSrcweir             aSeq[nLen-1] = beans::PropertyValue(
187*cdf0e10cSrcweir                 rtl::OUString(
188*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode")),
189*cdf0e10cSrcweir                 -1,
190*cdf0e10cSrcweir                 aAny,
191*cdf0e10cSrcweir                 beans::PropertyState_DIRECT_VALUE);
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         xComponentLoader->loadComponentFromURL(
195*cdf0e10cSrcweir             rtl::OUString(
196*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("private:object")),
197*cdf0e10cSrcweir             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")),
198*cdf0e10cSrcweir             0,
199*cdf0e10cSrcweir             aSeq);
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aResArgs = m_xDocument->getArgs();
202*cdf0e10cSrcweir         for ( int nInd = 0; nInd < aResArgs.getLength(); nInd++ )
203*cdf0e10cSrcweir             if ( aResArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MacroExecutionMode" ) ) ) )
204*cdf0e10cSrcweir             {
205*cdf0e10cSrcweir                 aResArgs[nInd].Value >>= m_nMacroExecMode;
206*cdf0e10cSrcweir                 break;
207*cdf0e10cSrcweir             }
208*cdf0e10cSrcweir     }
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void DocumentHolder::OnPosRectChanged(LPRECT lpRect) const
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     lpRect->left += m_aBorder.left;
214*cdf0e10cSrcweir     lpRect->right -= m_aBorder.right;
215*cdf0e10cSrcweir     lpRect->top += m_aBorder.top;
216*cdf0e10cSrcweir     lpRect->bottom -= m_aBorder.bottom;
217*cdf0e10cSrcweir     if(m_pIOleIPSite)
218*cdf0e10cSrcweir         m_pIOleIPSite->OnPosRectChange(lpRect);
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void DocumentHolder::DisableInplaceActivation(BOOL b)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir 	m_bAllowInPlace = ! b;
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir BOOL DocumentHolder::isActive() const
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	return m_pIOleIPSite != 0;
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir HRESULT DocumentHolder::InPlaceActivate(
234*cdf0e10cSrcweir 	LPOLECLIENTSITE pActiveSite,
235*cdf0e10cSrcweir 	BOOL fIncludeUI)
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir 	m_bOnDeactivate = false;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	if(!m_bAllowInPlace)
240*cdf0e10cSrcweir 		return ERROR;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     HRESULT                 hr;
243*cdf0e10cSrcweir     HWND                    hWndSite;
244*cdf0e10cSrcweir     RECT                    rcPos;
245*cdf0e10cSrcweir     RECT                    rcClip;
246*cdf0e10cSrcweir     OLEINPLACEFRAMEINFO     frameInfo;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     if (NULL==pActiveSite)
249*cdf0e10cSrcweir         return ResultFromScode(E_INVALIDARG);
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     if (NULL!=m_pIOleIPSite)
252*cdf0e10cSrcweir 	{
253*cdf0e10cSrcweir         if (fIncludeUI)
254*cdf0e10cSrcweir             UIActivate();
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         return NOERROR;
257*cdf0e10cSrcweir 	}
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir     if ( !m_xDocument.is() )
260*cdf0e10cSrcweir         return ERROR;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     //1.  Initialization, obtaining interfaces, OnInPlaceActivate.
263*cdf0e10cSrcweir     hr=pActiveSite->QueryInterface(
264*cdf0e10cSrcweir 		IID_IOleInPlaceSite,
265*cdf0e10cSrcweir 		(void**) &m_pIOleIPSite);
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     if (FAILED(hr))
268*cdf0e10cSrcweir         return hr;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     hr=m_pIOleIPSite->CanInPlaceActivate();
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     if (NOERROR!=hr)
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir         m_pIOleIPSite->Release(), m_pIOleIPSite=NULL;
275*cdf0e10cSrcweir         return ResultFromScode(E_FAIL);
276*cdf0e10cSrcweir 	}
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     m_pIOleIPSite->OnInPlaceActivate();
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     //2. Get the site window
281*cdf0e10cSrcweir     //3. and determine container frame and
282*cdf0e10cSrcweir     //   document window for tools and menus, as well
283*cdf0e10cSrcweir     //   as frameInfo for accelerators
284*cdf0e10cSrcweir     m_pIOleIPSite->GetWindow(&hWndSite);
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     frameInfo.cb=sizeof(OLEINPLACEFRAMEINFO);
287*cdf0e10cSrcweir     m_pIOleIPSite->GetWindowContext(
288*cdf0e10cSrcweir 		&m_pIOleIPFrame,&m_pIOleIPUIWindow,&rcPos,&rcClip,&frameInfo);
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 	// initialize the office as, with hwnd as parentwindow
291*cdf0e10cSrcweir     uno::Any                      aAny;
292*cdf0e10cSrcweir     uno::Sequence<sal_Int8> aProcessIdent(16);
293*cdf0e10cSrcweir     rtl_getGlobalProcessId((sal_uInt8*)aProcessIdent.getArray());
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     try
296*cdf0e10cSrcweir     {
297*cdf0e10cSrcweir         if(!m_xEditWindow.is())
298*cdf0e10cSrcweir         {   // determine XWindow and window handle of parent
299*cdf0e10cSrcweir             HWND                          hWndxWinParent(0);
300*cdf0e10cSrcweir             uno::Reference<awt::XWindow>  xWin;
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir             static const ::rtl::OUString aToolkitServiceName(
303*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.awt.Toolkit" ) );
304*cdf0e10cSrcweir             uno::Reference<awt::XSystemChildFactory> xToolkit(
305*cdf0e10cSrcweir                 m_xFactory->createInstance(aToolkitServiceName ),uno::UNO_QUERY);
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir             if(xToolkit.is()) {
308*cdf0e10cSrcweir                 // create system window wrapper for hwnd
309*cdf0e10cSrcweir                 if( !m_pCHatchWin )
310*cdf0e10cSrcweir                     m_pCHatchWin = new winwrap::CHatchWin(
311*cdf0e10cSrcweir                         m_hInstance,this);
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir                 if(m_pCHatchWin->Init(hWndSite,/*ID_HATCHWINDOW*/2000, NULL)) {
314*cdf0e10cSrcweir                     m_pCHatchWin->RectsSet(&rcPos,&rcClip); //set visible area
315*cdf0e10cSrcweir                     hWndxWinParent = m_pCHatchWin->Window();
316*cdf0e10cSrcweir                     ShowWindow(hWndxWinParent,SW_SHOW);  //Make visible.
317*cdf0e10cSrcweir                 }
318*cdf0e10cSrcweir                 else {
319*cdf0e10cSrcweir                     // no success initializing hatch window
320*cdf0e10cSrcweir                     delete m_pCHatchWin, m_pCHatchWin = 0;
321*cdf0e10cSrcweir                     hWndxWinParent = hWndSite;
322*cdf0e10cSrcweir                 }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir                 aAny <<= sal_Int32(hWndxWinParent);
325*cdf0e10cSrcweir                 xWin = uno::Reference<awt::XWindow>(
326*cdf0e10cSrcweir                     xToolkit->createSystemChild(
327*cdf0e10cSrcweir                         aAny,
328*cdf0e10cSrcweir                         aProcessIdent,
329*cdf0e10cSrcweir                         lang::SystemDependent::SYSTEM_WIN32),
330*cdf0e10cSrcweir                     uno::UNO_QUERY);
331*cdf0e10cSrcweir             }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir             if(xWin.is()) {
334*cdf0e10cSrcweir                 xWin->setPosSize(
335*cdf0e10cSrcweir                     m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
336*cdf0e10cSrcweir                     m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
337*cdf0e10cSrcweir                     rcPos.right-rcPos.left,
338*cdf0e10cSrcweir                     rcPos.bottom - rcPos.top,
339*cdf0e10cSrcweir                     awt::PosSize::POSSIZE);
340*cdf0e10cSrcweir                 xWin->setVisible(sal_True);
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir                 m_xEditWindow = xWin;
343*cdf0e10cSrcweir                 m_hWndxWinParent = hWndxWinParent;
344*cdf0e10cSrcweir             }
345*cdf0e10cSrcweir             else
346*cdf0e10cSrcweir                 return ERROR;
347*cdf0e10cSrcweir         }
348*cdf0e10cSrcweir         else {
349*cdf0e10cSrcweir             if(m_hWndxWinParent) {
350*cdf0e10cSrcweir                 SetParent(m_hWndxWinParent,hWndSite);
351*cdf0e10cSrcweir                 ShowWindow(m_hWndxWinParent,SW_SHOW);  //Make visible.
352*cdf0e10cSrcweir             }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir             if ( !m_xFrame.is() )
355*cdf0e10cSrcweir                 // initially set size to "empty", this guarantees that the final resize
356*cdf0e10cSrcweir                 // is always executed (will be done by "SetObjectRects" after getting internal border)
357*cdf0e10cSrcweir                 m_xEditWindow->setPosSize(
358*cdf0e10cSrcweir                     0,
359*cdf0e10cSrcweir                     0,
360*cdf0e10cSrcweir                     0,
361*cdf0e10cSrcweir                     0,
362*cdf0e10cSrcweir                     awt::PosSize::POSSIZE);
363*cdf0e10cSrcweir             m_xEditWindow->setVisible(sal_True);
364*cdf0e10cSrcweir         }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir         if(m_xContainerWindow.is()) {
367*cdf0e10cSrcweir             if(m_hWndxWinCont) {
368*cdf0e10cSrcweir                 if(m_pIOleIPFrame) {
369*cdf0e10cSrcweir                     HWND  hWndCont;
370*cdf0e10cSrcweir                     m_pIOleIPFrame->GetWindow(&hWndCont);
371*cdf0e10cSrcweir                     SetParent(m_hWndxWinCont,hWndCont);
372*cdf0e10cSrcweir                     ShowWindow(m_hWndxWinCont,SW_SHOW);
373*cdf0e10cSrcweir                 }
374*cdf0e10cSrcweir             }
375*cdf0e10cSrcweir             m_xContainerWindow->setVisible(true);
376*cdf0e10cSrcweir         }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         if(m_xFrame.is())
379*cdf0e10cSrcweir             m_xFrame->activate();
380*cdf0e10cSrcweir         else {
381*cdf0e10cSrcweir             // create frame and initialize it with with the created window
382*cdf0e10cSrcweir             static const ::rtl::OUString aFrameServiceName(
383*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Frame" ) );
384*cdf0e10cSrcweir             m_xFrame = uno::Reference<frame::XFrame>(
385*cdf0e10cSrcweir                 m_xFactory->createInstance(aFrameServiceName),
386*cdf0e10cSrcweir                 uno::UNO_QUERY);
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir             if(!m_xFrame.is())
389*cdf0e10cSrcweir                 return ERROR;
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir             m_xFrame->initialize(m_xEditWindow);
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir             uno::Reference<frame::XDispatchProviderInterception>
394*cdf0e10cSrcweir                 xDPI(m_xFrame,uno::UNO_QUERY);
395*cdf0e10cSrcweir             if(xDPI.is())
396*cdf0e10cSrcweir                 xDPI->registerDispatchProviderInterceptor( CreateNewInterceptor() );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir             uno::Reference<beans::XPropertySet> xPS(m_xFrame,uno::UNO_QUERY);
399*cdf0e10cSrcweir             if( xPS.is() )
400*cdf0e10cSrcweir             {
401*cdf0e10cSrcweir                 aAny = xPS->getPropertyValue(
402*cdf0e10cSrcweir                     rtl::OUString::createFromAscii("LayoutManager"));
403*cdf0e10cSrcweir                 aAny >>= m_xLayoutManager;
404*cdf0e10cSrcweir             }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir             if(m_xLayoutManager.is())
407*cdf0e10cSrcweir                 m_xLayoutManager->setDockingAreaAcceptor(this);
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir             // load the model into the frame
410*cdf0e10cSrcweir             LoadDocInFrame( sal_True );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir             static const ::rtl::OUString aDesktopServiceName (
413*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
414*cdf0e10cSrcweir             uno::Reference< frame::XFramesSupplier > xDesktop(
415*cdf0e10cSrcweir                 m_xFactory->createInstance( aDesktopServiceName ),
416*cdf0e10cSrcweir                 uno::UNO_QUERY );
417*cdf0e10cSrcweir             if(xDesktop.is())
418*cdf0e10cSrcweir                 xDesktop->getFrames()->append(m_xFrame);
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir             // determine the menuhandle to get menutitems.
421*cdf0e10cSrcweir             if(m_xLayoutManager.is()) {
422*cdf0e10cSrcweir                 uno::Reference< ::com::sun::star::ui::XUIElement > xUIEl(
423*cdf0e10cSrcweir                     m_xLayoutManager->getElement(
424*cdf0e10cSrcweir                         rtl::OUString::createFromAscii(
425*cdf0e10cSrcweir                             "private:resource/menubar/menubar")));
426*cdf0e10cSrcweir                 OSL_ENSURE(xUIEl.is(),"no menubar");
427*cdf0e10cSrcweir                 uno::Reference<awt::XSystemDependentMenuPeer> xSDMP(
428*cdf0e10cSrcweir                     xUIEl->getRealInterface(),
429*cdf0e10cSrcweir                     uno::UNO_QUERY);
430*cdf0e10cSrcweir                 aAny = xSDMP->getMenuHandle(
431*cdf0e10cSrcweir                     aProcessIdent,lang::SystemDependent::SYSTEM_WIN32);
432*cdf0e10cSrcweir                 sal_Int32 tmp;
433*cdf0e10cSrcweir                 if( aAny >>= tmp )
434*cdf0e10cSrcweir                     m_nMenuHandle = HMENU(tmp);
435*cdf0e10cSrcweir                 m_xLayoutManager->hideElement(
436*cdf0e10cSrcweir                     rtl::OUString(
437*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
438*cdf0e10cSrcweir                             "private:resource/menubar/menubar" )));
439*cdf0e10cSrcweir             }
440*cdf0e10cSrcweir         }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         // TODO/cd: Workaround for status indicator bug. It always makes the
443*cdf0e10cSrcweir         // document window visible, when someone tries to use the status
444*cdf0e10cSrcweir         // indicator. As we save our document when we get the deactivation
445*cdf0e10cSrcweir         // from OLE this conflict to hide floating windows.
446*cdf0e10cSrcweir         if(m_xLayoutManager.is())
447*cdf0e10cSrcweir             m_xLayoutManager->setVisible(true);
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir         // get document border and resize rects according to border
450*cdf0e10cSrcweir         GetDocumentBorder( &m_aBorder );
451*cdf0e10cSrcweir         SetObjectRects( &rcPos, &rcClip );
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir         if ( m_xOleAccess.is() )
454*cdf0e10cSrcweir         {
455*cdf0e10cSrcweir             LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
456*cdf0e10cSrcweir             if ( aDocLock.GetEmbedDocument() )
457*cdf0e10cSrcweir                 aDocLock.GetEmbedDocument()->ShowObject();
458*cdf0e10cSrcweir         }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir         // setTitle(m_aDocumentNamePart);
461*cdf0e10cSrcweir         if (fIncludeUI)
462*cdf0e10cSrcweir             hr=UIActivate();
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir         m_pIOleIPSite->DiscardUndoState();
465*cdf0e10cSrcweir     }
466*cdf0e10cSrcweir     catch( uno::Exception& )
467*cdf0e10cSrcweir     {
468*cdf0e10cSrcweir         hr = ERROR;
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir     return hr;
472*cdf0e10cSrcweir }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir void DocumentHolder::InPlaceDeactivate(void)
476*cdf0e10cSrcweir {
477*cdf0e10cSrcweir     m_bOnDeactivate = true;
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 	UIDeactivate();
480*cdf0e10cSrcweir 	if(m_xFrame.is()) m_xFrame->deactivate();
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir     if(m_xEditWindow.is()) {
483*cdf0e10cSrcweir         m_xEditWindow->setVisible(false);
484*cdf0e10cSrcweir         ShowWindow(m_hWndxWinParent,SW_HIDE);
485*cdf0e10cSrcweir         SetParent(m_hWndxWinParent,0);
486*cdf0e10cSrcweir     }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir     if(m_xContainerWindow.is()) {
489*cdf0e10cSrcweir         m_xContainerWindow->setVisible(false);
490*cdf0e10cSrcweir         ShowWindow(m_hWndxWinCont,SW_HIDE);
491*cdf0e10cSrcweir         SetParent(m_hWndxWinCont,0);
492*cdf0e10cSrcweir     }
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir     // TODO/cd: Workaround for status indicator bug. It always makes the
495*cdf0e10cSrcweir     // document window visible, when someone tries to use the status
496*cdf0e10cSrcweir     // indicator. As we save our document when we get the deactivation
497*cdf0e10cSrcweir     // from OLE this conflict to hide floating windows.
498*cdf0e10cSrcweir     if (m_xLayoutManager.is())
499*cdf0e10cSrcweir         m_xLayoutManager->setVisible(false);
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     if (NULL!=m_pIOleIPSite)
502*cdf0e10cSrcweir     {
503*cdf0e10cSrcweir         // The following workaround should let the object be stored in case of inplace editing
504*cdf0e10cSrcweir //        CComPtr< IOleClientSite > pClientSite;
505*cdf0e10cSrcweir //
506*cdf0e10cSrcweir //        m_pIOleIPSite->QueryInterface(
507*cdf0e10cSrcweir //		        IID_IOleClientSite, (void**)&pClientSite );
508*cdf0e10cSrcweir //        if ( pClientSite )
509*cdf0e10cSrcweir //            pClientSite->SaveObject();
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir         m_pIOleIPSite->OnInPlaceDeactivate();
512*cdf0e10cSrcweir     }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir     if(m_pIOleIPFrame) m_pIOleIPFrame->Release(); m_pIOleIPFrame = 0;
515*cdf0e10cSrcweir     if(m_pIOleIPUIWindow) m_pIOleIPUIWindow->Release(); m_pIOleIPUIWindow = 0;
516*cdf0e10cSrcweir 	if(m_pIOleIPSite) m_pIOleIPSite->Release(); m_pIOleIPSite = 0;
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 	if ( m_xOleAccess.is() )
519*cdf0e10cSrcweir 	{
520*cdf0e10cSrcweir 		LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
521*cdf0e10cSrcweir 		if ( aDocLock.GetEmbedDocument() )
522*cdf0e10cSrcweir         {
523*cdf0e10cSrcweir             aDocLock.GetEmbedDocument()->SaveObject();
524*cdf0e10cSrcweir         }
525*cdf0e10cSrcweir 	}
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir     return;
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir HRESULT DocumentHolder::UIActivate()
532*cdf0e10cSrcweir {
533*cdf0e10cSrcweir     // 1.  Call IOleInPlaceSite::UIActivate
534*cdf0e10cSrcweir     if (NULL!=m_pIOleIPSite)
535*cdf0e10cSrcweir         m_pIOleIPSite->OnUIActivate();
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir     //2.  Critical for accelerators to work initially.
538*cdf0e10cSrcweir     SetFocus(m_pCHatchWin->Window());
539*cdf0e10cSrcweir 	// if(m_xEditWindow.is()) m_xEditWindow->setFocus();
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir     //3.  Set the active object
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     OLECHAR starOffice[] = {'S','t','a','r','O','f','f','i','c','e',0};
544*cdf0e10cSrcweir 	CComPtr< IOleInPlaceActiveObject > pObj = new CIIAObj( this );
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     if (NULL!=m_pIOleIPFrame)
547*cdf0e10cSrcweir         m_pIOleIPFrame->SetActiveObject(
548*cdf0e10cSrcweir 			pObj, starOffice );
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir     if (NULL!=m_pIOleIPUIWindow)
551*cdf0e10cSrcweir 		m_pIOleIPUIWindow->SetActiveObject(
552*cdf0e10cSrcweir 			pObj, starOffice );
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir     //4.  Create the shared menu.
555*cdf0e10cSrcweir     InPlaceMenuCreate();
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir 	return NOERROR;
558*cdf0e10cSrcweir }
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir void DocumentHolder::UIDeactivate()
561*cdf0e10cSrcweir {
562*cdf0e10cSrcweir     //1.  Remove the shared menu.
563*cdf0e10cSrcweir     InPlaceMenuDestroy();
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir     if (NULL!=m_pIOleIPFrame)
566*cdf0e10cSrcweir         m_pIOleIPFrame->SetActiveObject(NULL, NULL);
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir     if (NULL!=m_pIOleIPUIWindow)
569*cdf0e10cSrcweir         m_pIOleIPUIWindow->SetActiveObject(NULL, NULL);
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir     //3.  Call IOleInPlaceSite::OnUIDeactivate
572*cdf0e10cSrcweir     if (NULL!=m_pIOleIPSite)
573*cdf0e10cSrcweir         m_pIOleIPSite->OnUIDeactivate(FALSE);
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir     return;
576*cdf0e10cSrcweir }
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir void CopyToOLEMenu(HMENU hOrig,WORD origPos,HMENU hDest,WORD destPos)
579*cdf0e10cSrcweir {
580*cdf0e10cSrcweir     HMENU subMenu(NULL);
581*cdf0e10cSrcweir     UINT uTemp = MF_BYPOSITION | MF_POPUP;
582*cdf0e10cSrcweir     char buffer[256];
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir     subMenu = GetSubMenu(hOrig,origPos);
585*cdf0e10cSrcweir     GetMenuString(hOrig,origPos,buffer,256,MF_BYPOSITION);
586*cdf0e10cSrcweir     InsertMenu(hDest,destPos,uTemp,
587*cdf0e10cSrcweir                (UINT)subMenu,LPCTSTR(buffer));
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir     MENUITEMINFOW mi;
590*cdf0e10cSrcweir     memset(&mi,0,sizeof(mi));
591*cdf0e10cSrcweir     mi.cbSize = sizeof(mi);
592*cdf0e10cSrcweir     mi.fMask = MIIM_DATA;
593*cdf0e10cSrcweir     if(GetMenuItemInfoW(hOrig,origPos,TRUE,&mi))
594*cdf0e10cSrcweir         SetMenuItemInfoW(hDest,(WORD)destPos,TRUE,&mi);
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir BOOL DocumentHolder::InPlaceMenuCreate(void)
598*cdf0e10cSrcweir {
599*cdf0e10cSrcweir     HMENU               hMenu;
600*cdf0e10cSrcweir     UINT                i;
601*cdf0e10cSrcweir     OLEMENUGROUPWIDTHS  mgw;
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     for (i=0; i<6; i++)
604*cdf0e10cSrcweir         mgw.width[i]=0;
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir     //We already have popup menu handles in m_pFR->m_phMenu[]
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir     //Create the new shared menu and let container do its thing
609*cdf0e10cSrcweir     hMenu=CreateMenu();
610*cdf0e10cSrcweir     m_pIOleIPFrame->InsertMenus(hMenu,&mgw);
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir     int count = GetMenuItemCount(m_nMenuHandle);
613*cdf0e10cSrcweir     int help = count-1;
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir     // start with 1, because we don't include "File"
616*cdf0e10cSrcweir     WORD pos = (WORD)mgw.width[0];
617*cdf0e10cSrcweir     CopyToOLEMenu(m_nMenuHandle,1,hMenu,pos);
618*cdf0e10cSrcweir     mgw.width[1] = 1;
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     // insert object menu here
621*cdf0e10cSrcweir     pos = ((WORD)(mgw.width[0] + mgw.width[1] + mgw.width[2]));
622*cdf0e10cSrcweir     for(WORD i = 2; i < help-1; ++i,++pos)
623*cdf0e10cSrcweir         CopyToOLEMenu(m_nMenuHandle,i,hMenu,pos);
624*cdf0e10cSrcweir     mgw.width[3] = help - 3;
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     // insert help menu
627*cdf0e10cSrcweir     pos = (WORD)(mgw.width[0] + mgw.width[1] + mgw.width[2] +
628*cdf0e10cSrcweir                  mgw.width[3] + mgw.width[4]);
629*cdf0e10cSrcweir     CopyToOLEMenu(m_nMenuHandle,WORD(help),hMenu,pos);
630*cdf0e10cSrcweir     mgw.width[5] = 1;
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir     m_nMenuShared = hMenu;
633*cdf0e10cSrcweir     m_nOLEMenu = OleCreateMenuDescriptor(m_nMenuShared,&mgw);
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir     uno::Reference<awt::XSystemDependentWindowPeer> xSysDepWin(m_xContainerWindow,uno::UNO_QUERY);
636*cdf0e10cSrcweir     if(xSysDepWin.is()) {
637*cdf0e10cSrcweir         uno::Sequence<sal_Int8> aProcessIdent(16);
638*cdf0e10cSrcweir         rtl_getGlobalProcessId((sal_uInt8*)aProcessIdent.getArray());
639*cdf0e10cSrcweir         uno::Any aAny = xSysDepWin->getWindowHandle(aProcessIdent,lang::SystemDependent::SYSTEM_WIN32);
640*cdf0e10cSrcweir         sal_Int32 tmp;
641*cdf0e10cSrcweir         aAny >>= tmp;
642*cdf0e10cSrcweir         HWND aHwnd = (HWND) tmp;
643*cdf0e10cSrcweir         m_pIOleIPFrame->SetMenu(
644*cdf0e10cSrcweir             m_nMenuShared,m_nOLEMenu,aHwnd);
645*cdf0e10cSrcweir     }
646*cdf0e10cSrcweir     else
647*cdf0e10cSrcweir         m_pIOleIPFrame->SetMenu(
648*cdf0e10cSrcweir             m_nMenuShared,m_nOLEMenu,::GetWindow(m_hWndxWinParent,GW_CHILD));
649*cdf0e10cSrcweir     return TRUE;
650*cdf0e10cSrcweir }
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir BOOL DocumentHolder::InPlaceMenuDestroy(void)
653*cdf0e10cSrcweir {
654*cdf0e10cSrcweir     if( NULL == m_nMenuShared )
655*cdf0e10cSrcweir         return TRUE;
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir     m_pIOleIPFrame->SetMenu(NULL,NULL,NULL);
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir     OleDestroyMenuDescriptor(m_nOLEMenu),m_nOLEMenu = NULL;
660*cdf0e10cSrcweir 	return TRUE;
661*cdf0e10cSrcweir }
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir void DocumentHolder::OpenIntoWindow(void)
664*cdf0e10cSrcweir {
665*cdf0e10cSrcweir 	// not implemented
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir BOOL DocumentHolder::Undo(void)
669*cdf0e10cSrcweir {
670*cdf0e10cSrcweir 	// not implemented
671*cdf0e10cSrcweir 	return false;
672*cdf0e10cSrcweir }
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir void DocumentHolder::FreeOffice()
676*cdf0e10cSrcweir {
677*cdf0e10cSrcweir 	const ::rtl::OUString aServiceName(
678*cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
679*cdf0e10cSrcweir 	uno::Reference< frame::XDesktop > xDesktop(
680*cdf0e10cSrcweir 		m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
681*cdf0e10cSrcweir 	if ( xDesktop.is() )
682*cdf0e10cSrcweir 	{
683*cdf0e10cSrcweir 		xDesktop->removeTerminateListener(
684*cdf0e10cSrcweir 			(frame::XTerminateListener*)this );
685*cdf0e10cSrcweir 	}
686*cdf0e10cSrcweir }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir void DocumentHolder::DisconnectFrameDocument( sal_Bool bComplete )
689*cdf0e10cSrcweir {
690*cdf0e10cSrcweir 	try
691*cdf0e10cSrcweir 	{
692*cdf0e10cSrcweir 		uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, uno::UNO_QUERY_THROW );
693*cdf0e10cSrcweir 		xModifiable->removeModifyListener( (util::XModifyListener*)this );
694*cdf0e10cSrcweir 	}
695*cdf0e10cSrcweir 	catch( uno::Exception& )
696*cdf0e10cSrcweir 	{}
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 	try
699*cdf0e10cSrcweir 	{
700*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xBroadcaster(
701*cdf0e10cSrcweir 			m_xDocument, uno::UNO_QUERY_THROW );
702*cdf0e10cSrcweir 		xBroadcaster->removeCloseListener( (util::XCloseListener*)this );
703*cdf0e10cSrcweir 	}
704*cdf0e10cSrcweir 	catch( uno::Exception& )
705*cdf0e10cSrcweir 	{}
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	try
708*cdf0e10cSrcweir 	{
709*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xBroadcaster(
710*cdf0e10cSrcweir 			m_xFrame, uno::UNO_QUERY_THROW );
711*cdf0e10cSrcweir 		xBroadcaster->removeCloseListener( (util::XCloseListener*)this );
712*cdf0e10cSrcweir 	}
713*cdf0e10cSrcweir 	catch( uno::Exception& )
714*cdf0e10cSrcweir 	{}
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     if ( bComplete )
717*cdf0e10cSrcweir     {
718*cdf0e10cSrcweir         m_xFrame = uno::Reference< frame::XFrame>();
719*cdf0e10cSrcweir 	    m_pIDispatch = NULL;
720*cdf0e10cSrcweir 	    m_xDocument = uno::Reference< frame::XModel >();
721*cdf0e10cSrcweir     }
722*cdf0e10cSrcweir }
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir void DocumentHolder::CloseDocument()
725*cdf0e10cSrcweir {
726*cdf0e10cSrcweir 	DisconnectFrameDocument();
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir 	uno::Reference< util::XCloseable > xCloseable(
729*cdf0e10cSrcweir 			m_xDocument, uno::UNO_QUERY );
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir 	if ( xCloseable.is() )
732*cdf0e10cSrcweir 	{
733*cdf0e10cSrcweir 		try
734*cdf0e10cSrcweir 		{
735*cdf0e10cSrcweir 			xCloseable->close( sal_True );
736*cdf0e10cSrcweir 		}
737*cdf0e10cSrcweir 		catch( uno::Exception& )
738*cdf0e10cSrcweir 		{}
739*cdf0e10cSrcweir 	}
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir 	m_pIDispatch = NULL;
742*cdf0e10cSrcweir 	m_xDocument = uno::Reference< frame::XModel >();
743*cdf0e10cSrcweir }
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir void DocumentHolder::CloseFrame()
747*cdf0e10cSrcweir {
748*cdf0e10cSrcweir 	try
749*cdf0e10cSrcweir 	{
750*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xBroadcaster(
751*cdf0e10cSrcweir 			m_xFrame, uno::UNO_QUERY_THROW );
752*cdf0e10cSrcweir 		xBroadcaster->removeCloseListener( (util::XCloseListener*)this );
753*cdf0e10cSrcweir 	}
754*cdf0e10cSrcweir 	catch( uno::Exception& )
755*cdf0e10cSrcweir 	{}
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir 	uno::Reference<util::XCloseable> xCloseable(
758*cdf0e10cSrcweir 		m_xFrame,uno::UNO_QUERY);
759*cdf0e10cSrcweir 	if(xCloseable.is())
760*cdf0e10cSrcweir 		try {
761*cdf0e10cSrcweir 			xCloseable->close(sal_True);
762*cdf0e10cSrcweir 		}
763*cdf0e10cSrcweir 		catch( const uno::Exception& ) {
764*cdf0e10cSrcweir 		}
765*cdf0e10cSrcweir 	else {
766*cdf0e10cSrcweir 		uno::Reference<lang::XComponent> xComp(m_xFrame,uno::UNO_QUERY);
767*cdf0e10cSrcweir 		if(xComp.is())
768*cdf0e10cSrcweir 			xComp->dispose();
769*cdf0e10cSrcweir 	}
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir 	m_xFrame = uno::Reference< frame::XFrame >();
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir void DocumentHolder::SetDocument( const uno::Reference< frame::XModel >& xDoc, sal_Bool bLink )
775*cdf0e10cSrcweir {
776*cdf0e10cSrcweir 	if ( m_xDocument.is() )
777*cdf0e10cSrcweir 		CloseDocument();
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir 	m_xDocument = xDoc;
780*cdf0e10cSrcweir 	m_bLink = bLink;
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 	uno::Reference< util::XCloseBroadcaster > xBroadcaster(
783*cdf0e10cSrcweir 		m_xDocument, uno::UNO_QUERY );
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir 	if ( xBroadcaster.is() )
786*cdf0e10cSrcweir 		xBroadcaster->addCloseListener( (util::XCloseListener*)this );
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir 	if ( m_xDocument.is() && !m_bLink )
789*cdf0e10cSrcweir 	{
790*cdf0e10cSrcweir 		// set the document mode to embedded
791*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aSeq(1);
792*cdf0e10cSrcweir 		aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" );
793*cdf0e10cSrcweir 		aSeq[0].Value <<= sal_True;
794*cdf0e10cSrcweir 		m_xDocument->attachResource(::rtl::OUString(),aSeq);
795*cdf0e10cSrcweir 	}
796*cdf0e10cSrcweir }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir sal_Bool DocumentHolder::ExecuteSuspendCloseFrame()
799*cdf0e10cSrcweir {
800*cdf0e10cSrcweir 	if ( m_xFrame.is() && m_xFactory.is() )
801*cdf0e10cSrcweir 	{
802*cdf0e10cSrcweir 		try
803*cdf0e10cSrcweir 		{
804*cdf0e10cSrcweir 			uno::Reference< frame::XController > xController = m_xFrame->getController();
805*cdf0e10cSrcweir 			if ( xController.is() )
806*cdf0e10cSrcweir 			{
807*cdf0e10cSrcweir 				if ( !xController->suspend( sal_True ) )
808*cdf0e10cSrcweir 					return sal_False;
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir 				FreeOffice();
811*cdf0e10cSrcweir 				try
812*cdf0e10cSrcweir 				{
813*cdf0e10cSrcweir 					uno::Reference<util::XCloseable> xCloseable( m_xFrame, uno::UNO_QUERY );
814*cdf0e10cSrcweir 					if ( xCloseable.is() )
815*cdf0e10cSrcweir 						xCloseable->close(sal_True);
816*cdf0e10cSrcweir 					else
817*cdf0e10cSrcweir 					{
818*cdf0e10cSrcweir 						uno::Reference<lang::XComponent> xComp( m_xFrame, uno::UNO_QUERY_THROW );
819*cdf0e10cSrcweir 						if( xComp.is() )
820*cdf0e10cSrcweir 							xComp->dispose();
821*cdf0e10cSrcweir 					}
822*cdf0e10cSrcweir 				}
823*cdf0e10cSrcweir 				catch( const util::CloseVetoException& )
824*cdf0e10cSrcweir 				{
825*cdf0e10cSrcweir 					// should be called if the frame could not be closed
826*cdf0e10cSrcweir 					xController->suspend( sal_False );
827*cdf0e10cSrcweir 				}
828*cdf0e10cSrcweir 			}
829*cdf0e10cSrcweir 		}
830*cdf0e10cSrcweir 		catch( uno::Exception& )
831*cdf0e10cSrcweir 		{
832*cdf0e10cSrcweir 		}
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir 		m_xFrame = uno::Reference< frame::XFrame >();
835*cdf0e10cSrcweir 	}
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir 	return sal_True;
838*cdf0e10cSrcweir }
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir uno::Reference< frame::XFrame > DocumentHolder::DocumentFrame()
841*cdf0e10cSrcweir {
842*cdf0e10cSrcweir 	if(! m_xFrame.is() )
843*cdf0e10cSrcweir 	{
844*cdf0e10cSrcweir 		rtl::OUString aDesktopSrvNm(
845*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"));
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir 		uno::Reference<frame::XDesktop> xDesktop(
848*cdf0e10cSrcweir 			m_xFactory->createInstance(aDesktopSrvNm),
849*cdf0e10cSrcweir 			uno::UNO_QUERY);
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir 		uno::Reference<frame::XFrame> xFrame(
852*cdf0e10cSrcweir 			xDesktop,uno::UNO_QUERY);
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 		// the frame will be registered on desktop here, later when the document
855*cdf0e10cSrcweir 		// is loaded into the frame in ::show() method the terminate listener will be removed
856*cdf0e10cSrcweir 		// this is so only for outplace activation
857*cdf0e10cSrcweir 		if( xFrame.is() )
858*cdf0e10cSrcweir 			m_xFrame = xFrame->findFrame(
859*cdf0e10cSrcweir 				rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")),0);
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xBroadcaster(
862*cdf0e10cSrcweir 			m_xFrame, uno::UNO_QUERY );
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir 		if ( xBroadcaster.is() )
865*cdf0e10cSrcweir 		{
866*cdf0e10cSrcweir 			xBroadcaster->addCloseListener( (util::XCloseListener*)this );
867*cdf0e10cSrcweir 			FreeOffice(); // the frame is part of the desktop
868*cdf0e10cSrcweir 		}
869*cdf0e10cSrcweir 	}
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir 	if( m_xFrame.is() )
872*cdf0e10cSrcweir 	{
873*cdf0e10cSrcweir 		// intercept
874*cdf0e10cSrcweir 		uno::Reference<frame::XDispatchProviderInterception>
875*cdf0e10cSrcweir 			xDPI(m_xFrame,uno::UNO_QUERY);
876*cdf0e10cSrcweir 		if(xDPI.is())
877*cdf0e10cSrcweir 			xDPI->registerDispatchProviderInterceptor( CreateNewInterceptor() );
878*cdf0e10cSrcweir 	}
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 	return m_xFrame;
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir uno::Reference< frame::XDispatchProviderInterceptor > DocumentHolder::CreateNewInterceptor()
885*cdf0e10cSrcweir {
886*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir 	ClearInterceptorInternally();
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir 	uno::Reference< frame::XDispatchProviderInterceptor > xInterceptor( m_pInterceptor = new Interceptor( m_xOleAccess, this, m_bLink ) );
891*cdf0e10cSrcweir 	m_xInterceptorLocker = xInterceptor;
892*cdf0e10cSrcweir 	return xInterceptor;
893*cdf0e10cSrcweir }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir void DocumentHolder::ClearInterceptorInternally()
896*cdf0e10cSrcweir {
897*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
898*cdf0e10cSrcweir 	uno::Reference< frame::XDispatchProviderInterceptor > xInterceptor( m_xInterceptorLocker );
899*cdf0e10cSrcweir 	if ( xInterceptor.is() && m_pInterceptor )
900*cdf0e10cSrcweir 		m_pInterceptor->DisconnectDocHolder();
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 	m_xInterceptorLocker = uno::Reference< frame::XDispatchProviderInterceptor >();
903*cdf0e10cSrcweir 	m_pInterceptor = 0;
904*cdf0e10cSrcweir }
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir void DocumentHolder::ClearInterceptor()
907*cdf0e10cSrcweir {
908*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
909*cdf0e10cSrcweir 	m_xInterceptorLocker = uno::Reference< frame::XDispatchProviderInterceptor >();
910*cdf0e10cSrcweir 	m_pInterceptor = 0;
911*cdf0e10cSrcweir }
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir void DocumentHolder::show()
915*cdf0e10cSrcweir {
916*cdf0e10cSrcweir     try
917*cdf0e10cSrcweir     {
918*cdf0e10cSrcweir         if(m_xFrame.is())
919*cdf0e10cSrcweir         {
920*cdf0e10cSrcweir             m_xFrame->activate();
921*cdf0e10cSrcweir             uno::Reference<awt::XTopWindow> xTopWindow(
922*cdf0e10cSrcweir                 m_xFrame->getContainerWindow(),uno::UNO_QUERY);
923*cdf0e10cSrcweir             if(xTopWindow.is())
924*cdf0e10cSrcweir                 xTopWindow->toFront();
925*cdf0e10cSrcweir         }
926*cdf0e10cSrcweir         else if( DocumentFrame().is() )
927*cdf0e10cSrcweir         {
928*cdf0e10cSrcweir             LoadDocInFrame( sal_False );
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir             // get rid of second closer if it is there
931*cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xProps( m_xFrame, uno::UNO_QUERY );
932*cdf0e10cSrcweir             if ( xProps.is() )
933*cdf0e10cSrcweir             {
934*cdf0e10cSrcweir                 uno::Reference< frame::XLayoutManager > xLayoutManager;
935*cdf0e10cSrcweir                 xProps->getPropertyValue( rtl::OUString::createFromAscii( "LayoutManager" ) ) >>= xLayoutManager;
936*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xLMProps( xLayoutManager, uno::UNO_QUERY );
937*cdf0e10cSrcweir                 if ( xLMProps.is() )
938*cdf0e10cSrcweir                 {
939*cdf0e10cSrcweir                     xLMProps->setPropertyValue( ::rtl::OUString::createFromAscii( "MenuBarCloser" ),
940*cdf0e10cSrcweir                                                 uno::makeAny( uno::Reference< frame::XStatusListener >() ) );
941*cdf0e10cSrcweir                 }
942*cdf0e10cSrcweir             }
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir             if ( !m_bLink )
945*cdf0e10cSrcweir             {
946*cdf0e10cSrcweir                 try
947*cdf0e10cSrcweir                 {
948*cdf0e10cSrcweir                     uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, uno::UNO_QUERY_THROW );
949*cdf0e10cSrcweir                     xModifiable->addModifyListener( (util::XModifyListener*)this );
950*cdf0e10cSrcweir                 }
951*cdf0e10cSrcweir                 catch( uno::Exception& )
952*cdf0e10cSrcweir                 {}
953*cdf0e10cSrcweir             }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir             if ( !m_bLink )
956*cdf0e10cSrcweir                 setTitle(m_aDocumentNamePart);
957*cdf0e10cSrcweir         }
958*cdf0e10cSrcweir 	}
959*cdf0e10cSrcweir     catch( uno::Exception& )
960*cdf0e10cSrcweir     {
961*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "Can not show the frame!\n" );
962*cdf0e10cSrcweir     }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir }
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir void DocumentHolder::resizeWin( const SIZEL& rNewSize )
967*cdf0e10cSrcweir {
968*cdf0e10cSrcweir 	LockedEmbedDocument_Impl aDocLock;
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir 	if ( m_xOleAccess.is() )
971*cdf0e10cSrcweir 		aDocLock = m_xOleAccess->GetEmbedDocument();
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 	if ( m_xFrame.is() && aDocLock.GetEmbedDocument() )
974*cdf0e10cSrcweir 	{
975*cdf0e10cSrcweir 		uno::Reference< awt::XWindow > xWindow(
976*cdf0e10cSrcweir 			m_xFrame->getContainerWindow(), uno::UNO_QUERY );
977*cdf0e10cSrcweir 		uno::Reference< awt::XView > xView( xWindow, uno::UNO_QUERY );
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir 		if ( xWindow.is() && xView.is() )
980*cdf0e10cSrcweir 		{
981*cdf0e10cSrcweir 			float fScale = 1;
982*cdf0e10cSrcweir 			xView->setZoom( fScale, fScale );
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir 			SIZEL aOldSize;
985*cdf0e10cSrcweir 			GetExtent( &aOldSize );
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir 			if ( aOldSize.cx != rNewSize.cx || aOldSize.cy != rNewSize.cy )
988*cdf0e10cSrcweir 			{
989*cdf0e10cSrcweir 				HDC hdc = GetDC( NULL );
990*cdf0e10cSrcweir 				SetMapMode( hdc, MM_HIMETRIC );
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir 				POINT aOldOffset;
993*cdf0e10cSrcweir 				aOldOffset.x = aOldSize.cx;
994*cdf0e10cSrcweir 				aOldOffset.y = aOldSize.cy;
995*cdf0e10cSrcweir 				BOOL bIsOk = LPtoDP( hdc, &aOldOffset, 1 );
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir 				POINT aNewOffset;
998*cdf0e10cSrcweir 				aNewOffset.x = rNewSize.cx;
999*cdf0e10cSrcweir 				aNewOffset.y = rNewSize.cy;
1000*cdf0e10cSrcweir 				bIsOk = LPtoDP( hdc, &aNewOffset, 1 );
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir 				ReleaseDC( NULL, hdc );
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir 				awt::Rectangle aWinRect = xWindow->getPosSize();
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir 				sal_Int32 aWidthDelta = aWinRect.Width - aOldOffset.x;
1007*cdf0e10cSrcweir 				sal_Int32 aHeightDelta = aWinRect.Height - aOldOffset.y;
1008*cdf0e10cSrcweir 
1009*cdf0e10cSrcweir 				if ( aWidthDelta > 0 && aHeightDelta > 0 )
1010*cdf0e10cSrcweir 					xWindow->setPosSize(0,
1011*cdf0e10cSrcweir 										0,
1012*cdf0e10cSrcweir 										aNewOffset.x + aWidthDelta,
1013*cdf0e10cSrcweir 										aNewOffset.y + aHeightDelta,
1014*cdf0e10cSrcweir 										awt::PosSize::SIZE );
1015*cdf0e10cSrcweir 			}
1016*cdf0e10cSrcweir 		}
1017*cdf0e10cSrcweir 	}
1018*cdf0e10cSrcweir }
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir void DocumentHolder::setTitle(const rtl::OUString& aDocumentName)
1021*cdf0e10cSrcweir {
1022*cdf0e10cSrcweir 	if(m_xFrame.is())
1023*cdf0e10cSrcweir 	{
1024*cdf0e10cSrcweir 		if(m_aFilterName.getLength() == 0)
1025*cdf0e10cSrcweir 		{
1026*cdf0e10cSrcweir 			rtl::OUString aFilterName;
1027*cdf0e10cSrcweir 			uno::Sequence<beans::PropertyValue> aSeq;
1028*cdf0e10cSrcweir 			if(m_xDocument.is())
1029*cdf0e10cSrcweir 			{
1030*cdf0e10cSrcweir 				aSeq =
1031*cdf0e10cSrcweir 					m_xDocument->getArgs();
1032*cdf0e10cSrcweir 				for(sal_Int32 j = 0; j < aSeq.getLength(); ++j)
1033*cdf0e10cSrcweir 				{
1034*cdf0e10cSrcweir 					if(aSeq[j].Name ==
1035*cdf0e10cSrcweir 					   rtl::OUString(
1036*cdf0e10cSrcweir 						   RTL_CONSTASCII_USTRINGPARAM("FilterName")))
1037*cdf0e10cSrcweir 					{
1038*cdf0e10cSrcweir 						aSeq[j].Value >>= aFilterName;
1039*cdf0e10cSrcweir 						break;
1040*cdf0e10cSrcweir 					}
1041*cdf0e10cSrcweir 				}
1042*cdf0e10cSrcweir 			}
1043*cdf0e10cSrcweir 
1044*cdf0e10cSrcweir 			if(aFilterName.getLength())
1045*cdf0e10cSrcweir 			{
1046*cdf0e10cSrcweir 				uno::Reference<container::XNameAccess> xNameAccess(
1047*cdf0e10cSrcweir 					m_xFactory->createInstance(
1048*cdf0e10cSrcweir 						rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1049*cdf0e10cSrcweir 							"com.sun.star.document.FilterFactory"))),
1050*cdf0e10cSrcweir 					uno::UNO_QUERY);
1051*cdf0e10cSrcweir 				try {
1052*cdf0e10cSrcweir 					if(xNameAccess.is() &&
1053*cdf0e10cSrcweir 					   (xNameAccess->getByName(aFilterName) >>= aSeq))
1054*cdf0e10cSrcweir 					{
1055*cdf0e10cSrcweir 						for(sal_Int32 j = 0; j < aSeq.getLength(); ++j)
1056*cdf0e10cSrcweir 							if(aSeq[j].Name ==
1057*cdf0e10cSrcweir 							   rtl::OUString(
1058*cdf0e10cSrcweir 								   RTL_CONSTASCII_USTRINGPARAM("UIName")))
1059*cdf0e10cSrcweir 							{
1060*cdf0e10cSrcweir 								aSeq[j].Value >>= m_aFilterName;
1061*cdf0e10cSrcweir 								break;
1062*cdf0e10cSrcweir 							}
1063*cdf0e10cSrcweir 					}
1064*cdf0e10cSrcweir 				}
1065*cdf0e10cSrcweir 				catch(const uno::Exception& ) {
1066*cdf0e10cSrcweir 					// nothing better to do here
1067*cdf0e10cSrcweir 					m_aFilterName = aFilterName;
1068*cdf0e10cSrcweir 				}
1069*cdf0e10cSrcweir 			}
1070*cdf0e10cSrcweir 		}
1071*cdf0e10cSrcweir 		// set the title
1072*cdf0e10cSrcweir 		uno::Reference<beans::XPropertySet> xPropSet(
1073*cdf0e10cSrcweir 			m_xFrame,uno::UNO_QUERY);
1074*cdf0e10cSrcweir 		if(xPropSet.is()) {
1075*cdf0e10cSrcweir 			uno::Any aAny;
1076*cdf0e10cSrcweir 			static const sal_Unicode u[] = { ' ','(',0 };
1077*cdf0e10cSrcweir 			static const sal_Unicode c[] = { ')',0 };
1078*cdf0e10cSrcweir 			rtl::OUString aTotalName(m_aFilterName);
1079*cdf0e10cSrcweir 			aTotalName += rtl::OUString(u);
1080*cdf0e10cSrcweir 			aTotalName += aDocumentName;
1081*cdf0e10cSrcweir 			aTotalName += rtl::OUString(c);
1082*cdf0e10cSrcweir 			aAny <<= aTotalName;
1083*cdf0e10cSrcweir 			try {
1084*cdf0e10cSrcweir 				xPropSet->setPropertyValue(
1085*cdf0e10cSrcweir 					rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")),
1086*cdf0e10cSrcweir 					aAny);
1087*cdf0e10cSrcweir 			}
1088*cdf0e10cSrcweir 			catch( const uno::Exception& ) {
1089*cdf0e10cSrcweir 			}
1090*cdf0e10cSrcweir 		}
1091*cdf0e10cSrcweir 	}
1092*cdf0e10cSrcweir 
1093*cdf0e10cSrcweir 	m_aDocumentNamePart = aDocumentName;
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir 	if(m_pInterceptor)
1096*cdf0e10cSrcweir 	{
1097*cdf0e10cSrcweir 		::osl::ClearableMutexGuard aGuard( m_aMutex );
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir 		Interceptor* pTmpInter = NULL;
1100*cdf0e10cSrcweir 		uno::Reference< frame::XDispatchProviderInterceptor > xLock( m_xInterceptorLocker );
1101*cdf0e10cSrcweir 		if ( xLock.is() && m_pInterceptor )
1102*cdf0e10cSrcweir 			pTmpInter = m_pInterceptor;
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir 		aGuard.clear();
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir 		if ( pTmpInter )
1107*cdf0e10cSrcweir 			pTmpInter->generateFeatureStateEvent();
1108*cdf0e10cSrcweir 	}
1109*cdf0e10cSrcweir }
1110*cdf0e10cSrcweir 
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir void DocumentHolder::setContainerName(const rtl::OUString& aContainerName)
1113*cdf0e10cSrcweir {
1114*cdf0e10cSrcweir 	m_aContainerName = aContainerName;
1115*cdf0e10cSrcweir }
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir void DocumentHolder::hide()
1119*cdf0e10cSrcweir {
1120*cdf0e10cSrcweir 	if(m_xFrame.is()) m_xFrame->deactivate();
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir 	//todo: sendadvise
1123*cdf0e10cSrcweir 	// after hiding the window it is always allowed to InPlaceActivate it
1124*cdf0e10cSrcweir 	m_bAllowInPlace = true;
1125*cdf0e10cSrcweir }
1126*cdf0e10cSrcweir 
1127*cdf0e10cSrcweir IDispatch* DocumentHolder::GetIDispatch()
1128*cdf0e10cSrcweir {
1129*cdf0e10cSrcweir 	if ( !m_pIDispatch && m_xDocument.is() )
1130*cdf0e10cSrcweir 	{
1131*cdf0e10cSrcweir 		const ::rtl::OUString aServiceName (
1132*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM (
1133*cdf0e10cSrcweir 				"com.sun.star.bridge.OleBridgeSupplier2" ) );
1134*cdf0e10cSrcweir 		uno::Reference< bridge::XBridgeSupplier2 > xSupplier(
1135*cdf0e10cSrcweir 			m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir 		if ( xSupplier.is() )
1138*cdf0e10cSrcweir 		{
1139*cdf0e10cSrcweir 			uno::Sequence< sal_Int8 > aProcId( 16 );
1140*cdf0e10cSrcweir 			rtl_getGlobalProcessId( (sal_uInt8*)aProcId.getArray() );
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir 			try {
1143*cdf0e10cSrcweir 				uno::Any anyResult = xSupplier->createBridge(
1144*cdf0e10cSrcweir 					uno::makeAny( m_xDocument ),
1145*cdf0e10cSrcweir 					aProcId,
1146*cdf0e10cSrcweir 					bridge::ModelDependent::UNO,
1147*cdf0e10cSrcweir 					bridge::ModelDependent::OLE );
1148*cdf0e10cSrcweir 
1149*cdf0e10cSrcweir 				if ( anyResult.getValueTypeClass() ==
1150*cdf0e10cSrcweir 					 getCppuType((sal_uInt32*) 0).getTypeClass() )
1151*cdf0e10cSrcweir 				{
1152*cdf0e10cSrcweir 					VARIANT* pVariant = *(VARIANT**)anyResult.getValue();
1153*cdf0e10cSrcweir 					if ( pVariant->vt == VT_DISPATCH )
1154*cdf0e10cSrcweir 						m_pIDispatch = pVariant->pdispVal;
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir 					VariantClear( pVariant );
1157*cdf0e10cSrcweir 					CoTaskMemFree( pVariant );
1158*cdf0e10cSrcweir 				}
1159*cdf0e10cSrcweir 			}
1160*cdf0e10cSrcweir 			catch ( uno::Exception& )
1161*cdf0e10cSrcweir 			{}
1162*cdf0e10cSrcweir 		}
1163*cdf0e10cSrcweir 	}
1164*cdf0e10cSrcweir 
1165*cdf0e10cSrcweir 	return m_pIDispatch;
1166*cdf0e10cSrcweir }
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir #if 0
1169*cdf0e10cSrcweir HRESULT DocumentHolder::SetVisArea( const RECTL *pRect )
1170*cdf0e10cSrcweir {
1171*cdf0e10cSrcweir 	if ( pRect && m_xDocument.is() )
1172*cdf0e10cSrcweir 	{
1173*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs();
1174*cdf0e10cSrcweir 		for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ )
1175*cdf0e10cSrcweir 			if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) )
1176*cdf0e10cSrcweir 			{
1177*cdf0e10cSrcweir 				// should allways be there
1178*cdf0e10cSrcweir 				uno::Sequence< sal_Int32 > aRect(4);
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir 				aRect[0] = pRect->left;
1181*cdf0e10cSrcweir 				aRect[1] = pRect->top;
1182*cdf0e10cSrcweir 				aRect[2] = pRect->right;
1183*cdf0e10cSrcweir 				aRect[3] = pRect->bottom;
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir 				aArgs[nInd].Value <<= aRect;
1186*cdf0e10cSrcweir 
1187*cdf0e10cSrcweir 				m_xDocument->attachResource( m_xDocument->getURL(), aArgs );
1188*cdf0e10cSrcweir 				return S_OK;
1189*cdf0e10cSrcweir 			}
1190*cdf0e10cSrcweir 
1191*cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "WinExtent seems not to be implemented!\n" );
1192*cdf0e10cSrcweir 	}
1193*cdf0e10cSrcweir 
1194*cdf0e10cSrcweir 	return E_FAIL;
1195*cdf0e10cSrcweir }
1196*cdf0e10cSrcweir 
1197*cdf0e10cSrcweir HRESULT DocumentHolder::GetVisArea( RECTL *pRect )
1198*cdf0e10cSrcweir {
1199*cdf0e10cSrcweir 	if ( pRect && m_xDocument.is() )
1200*cdf0e10cSrcweir 	{
1201*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs();
1202*cdf0e10cSrcweir 		for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ )
1203*cdf0e10cSrcweir 			if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) )
1204*cdf0e10cSrcweir 			{
1205*cdf0e10cSrcweir 				uno::Sequence< sal_Int32 > aRect;
1206*cdf0e10cSrcweir 				if ( ( aArgs[nInd].Value >>= aRect ) && aRect.getLength() == 4 )
1207*cdf0e10cSrcweir 				{
1208*cdf0e10cSrcweir 					pRect->left   = aRect[0];
1209*cdf0e10cSrcweir 					pRect->top    = aRect[1];
1210*cdf0e10cSrcweir 					pRect->right  = aRect[2];
1211*cdf0e10cSrcweir 					pRect->bottom = aRect[3];
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir 					return S_OK;
1214*cdf0e10cSrcweir 				}
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 				break;
1217*cdf0e10cSrcweir 			}
1218*cdf0e10cSrcweir 	}
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir 	return E_FAIL;
1221*cdf0e10cSrcweir }
1222*cdf0e10cSrcweir #endif
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir HRESULT DocumentHolder::GetDocumentBorder( RECT *pRect )
1225*cdf0e10cSrcweir {
1226*cdf0e10cSrcweir 	if ( pRect && m_xDocument.is() )
1227*cdf0e10cSrcweir 	{
1228*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs();
1229*cdf0e10cSrcweir 		for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ )
1230*cdf0e10cSrcweir             if ( aArgs[nInd].Name.equalsAscii( "DocumentBorder" ) )
1231*cdf0e10cSrcweir 			{
1232*cdf0e10cSrcweir 				uno::Sequence< sal_Int32 > aRect;
1233*cdf0e10cSrcweir 				if ( ( aArgs[nInd].Value >>= aRect ) && aRect.getLength() == 4 )
1234*cdf0e10cSrcweir 				{
1235*cdf0e10cSrcweir 					pRect->left   = aRect[0];
1236*cdf0e10cSrcweir 					pRect->top    = aRect[1];
1237*cdf0e10cSrcweir 					pRect->right  = aRect[2];
1238*cdf0e10cSrcweir 					pRect->bottom = aRect[3];
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir 					return S_OK;
1241*cdf0e10cSrcweir 				}
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir 				break;
1244*cdf0e10cSrcweir 			}
1245*cdf0e10cSrcweir 	}
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir 	return E_FAIL;
1248*cdf0e10cSrcweir }
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir HRESULT DocumentHolder::SetExtent( const SIZEL *pSize )
1251*cdf0e10cSrcweir {
1252*cdf0e10cSrcweir 	if ( pSize )
1253*cdf0e10cSrcweir 	{
1254*cdf0e10cSrcweir 		uno::Reference< embed::XVisualObject > xVisObj( m_xDocument, uno::UNO_QUERY );
1255*cdf0e10cSrcweir 		if ( xVisObj.is() )
1256*cdf0e10cSrcweir 		{
1257*cdf0e10cSrcweir 			try
1258*cdf0e10cSrcweir 			{
1259*cdf0e10cSrcweir 				awt::Size aNewSize( pSize->cx, pSize->cy );
1260*cdf0e10cSrcweir 
1261*cdf0e10cSrcweir 				sal_Int32 aMapMode = xVisObj->getMapUnit( DVASPECT_CONTENT );
1262*cdf0e10cSrcweir 
1263*cdf0e10cSrcweir 				// TODO/LATER: in future UNO API should be used for the conversion, currently there is no
1264*cdf0e10cSrcweir 				if ( aMapMode == embed::EmbedMapUnits::TWIP )
1265*cdf0e10cSrcweir 				{
1266*cdf0e10cSrcweir 					// convertion from ONE_100TH_MM
1267*cdf0e10cSrcweir 					aNewSize.Width = aNewSize.Width * 144 / 254;
1268*cdf0e10cSrcweir 					aNewSize.Height = aNewSize.Height * 144 / 254;
1269*cdf0e10cSrcweir 				}
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir 
1272*cdf0e10cSrcweir 				xVisObj->setVisualAreaSize( DVASPECT_CONTENT, aNewSize );
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir 				return S_OK;
1275*cdf0e10cSrcweir 			}
1276*cdf0e10cSrcweir 			catch( uno::Exception& )
1277*cdf0e10cSrcweir 			{}
1278*cdf0e10cSrcweir 		}
1279*cdf0e10cSrcweir 	}
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir 	return E_FAIL;
1282*cdf0e10cSrcweir }
1283*cdf0e10cSrcweir 
1284*cdf0e10cSrcweir HRESULT DocumentHolder::GetExtent( SIZEL *pSize )
1285*cdf0e10cSrcweir {
1286*cdf0e10cSrcweir 	if ( pSize )
1287*cdf0e10cSrcweir 	{
1288*cdf0e10cSrcweir 		uno::Reference< embed::XVisualObject > xVisObj( m_xDocument, uno::UNO_QUERY );
1289*cdf0e10cSrcweir 		if ( xVisObj.is() )
1290*cdf0e10cSrcweir 		{
1291*cdf0e10cSrcweir 			try
1292*cdf0e10cSrcweir 			{
1293*cdf0e10cSrcweir 				awt::Size aDocSize = xVisObj->getVisualAreaSize( DVASPECT_CONTENT );
1294*cdf0e10cSrcweir 
1295*cdf0e10cSrcweir 				sal_Int32 aMapMode = xVisObj->getMapUnit( DVASPECT_CONTENT );
1296*cdf0e10cSrcweir 
1297*cdf0e10cSrcweir 				// TODO/LATER: in future UNO API should be used for the conversion, currently there is no
1298*cdf0e10cSrcweir 				if ( aMapMode == embed::EmbedMapUnits::TWIP )
1299*cdf0e10cSrcweir 				{
1300*cdf0e10cSrcweir 					// convertion to ONE_100TH_MM
1301*cdf0e10cSrcweir 					aDocSize.Width = aDocSize.Width * 254 / 144;
1302*cdf0e10cSrcweir 					aDocSize.Height = aDocSize.Height * 254 / 144;
1303*cdf0e10cSrcweir 				}
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir 				pSize->cx = aDocSize.Width;
1306*cdf0e10cSrcweir 				pSize->cy = aDocSize.Height;
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir 				return S_OK;
1309*cdf0e10cSrcweir 			}
1310*cdf0e10cSrcweir 			catch( uno::Exception& )
1311*cdf0e10cSrcweir 			{}
1312*cdf0e10cSrcweir 		}
1313*cdf0e10cSrcweir 	}
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir 	return E_FAIL;
1316*cdf0e10cSrcweir }
1317*cdf0e10cSrcweir 
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir HRESULT DocumentHolder::SetContRects(LPCRECT aRect)
1320*cdf0e10cSrcweir {
1321*cdf0e10cSrcweir 	if(m_xContainerWindow.is()) {
1322*cdf0e10cSrcweir 		RECT wi;
1323*cdf0e10cSrcweir         memset(&wi,0,sizeof(wi));
1324*cdf0e10cSrcweir 		if(m_pIOleIPFrame) {
1325*cdf0e10cSrcweir 			m_pIOleIPFrame->GetBorder((LPRECT)&wi);
1326*cdf0e10cSrcweir 			m_xContainerWindow->setPosSize(
1327*cdf0e10cSrcweir 				0,0,
1328*cdf0e10cSrcweir 				wi.right - wi.left,
1329*cdf0e10cSrcweir 				wi.bottom - wi.top,
1330*cdf0e10cSrcweir 				awt::PosSize::POSSIZE);
1331*cdf0e10cSrcweir 		}
1332*cdf0e10cSrcweir 		else
1333*cdf0e10cSrcweir 	       m_xContainerWindow->setPosSize(
1334*cdf0e10cSrcweir 			0,0,
1335*cdf0e10cSrcweir             aRect->right - aRect->left,
1336*cdf0e10cSrcweir             aRect->bottom - aRect->top,
1337*cdf0e10cSrcweir             awt::PosSize::POSSIZE);
1338*cdf0e10cSrcweir         return NOERROR;
1339*cdf0e10cSrcweir     }
1340*cdf0e10cSrcweir     else {
1341*cdf0e10cSrcweir         return ERROR;
1342*cdf0e10cSrcweir     }
1343*cdf0e10cSrcweir }
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir 
1346*cdf0e10cSrcweir HRESULT DocumentHolder::SetObjectRects(LPCRECT aRect, LPCRECT aClip)
1347*cdf0e10cSrcweir {
1348*cdf0e10cSrcweir     ((LPRECT)aRect)->left -= m_aBorder.left;
1349*cdf0e10cSrcweir     ((LPRECT)aRect)->right += m_aBorder.right;
1350*cdf0e10cSrcweir     ((LPRECT)aRect)->top -= m_aBorder.top;
1351*cdf0e10cSrcweir     ((LPRECT)aRect)->bottom += m_aBorder.bottom;
1352*cdf0e10cSrcweir     ((LPRECT)aClip)->left -= m_aBorder.left;
1353*cdf0e10cSrcweir     ((LPRECT)aClip)->right += m_aBorder.right;
1354*cdf0e10cSrcweir     ((LPRECT)aClip)->top -= m_aBorder.top;
1355*cdf0e10cSrcweir     ((LPRECT)aClip)->bottom += m_aBorder.bottom;
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir 	if(m_pCHatchWin)
1358*cdf0e10cSrcweir 		m_pCHatchWin->RectsSet((LPRECT)aRect, (LPRECT)aClip);
1359*cdf0e10cSrcweir 	if(m_xEditWindow.is()) {
1360*cdf0e10cSrcweir         m_xEditWindow->setVisible(false);
1361*cdf0e10cSrcweir         m_xEditWindow->setPosSize(
1362*cdf0e10cSrcweir             m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
1363*cdf0e10cSrcweir             m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
1364*cdf0e10cSrcweir             aRect->right - aRect->left,
1365*cdf0e10cSrcweir             aRect->bottom - aRect->top,
1366*cdf0e10cSrcweir             awt::PosSize::POSSIZE);
1367*cdf0e10cSrcweir         m_xEditWindow->setVisible(true);
1368*cdf0e10cSrcweir     }
1369*cdf0e10cSrcweir 	return NOERROR;
1370*cdf0e10cSrcweir }
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir ::com::sun::star::uno::Reference<
1374*cdf0e10cSrcweir     ::com::sun::star::awt::XWindow> SAL_CALL
1375*cdf0e10cSrcweir DocumentHolder::getContainerWindow(
1376*cdf0e10cSrcweir )
1377*cdf0e10cSrcweir     throw (
1378*cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException
1379*cdf0e10cSrcweir     )
1380*cdf0e10cSrcweir {
1381*cdf0e10cSrcweir     if(m_xContainerWindow.is())
1382*cdf0e10cSrcweir         return m_xContainerWindow;
1383*cdf0e10cSrcweir 
1384*cdf0e10cSrcweir     uno::Reference<awt::XWindow> xWin(0);
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir     static const ::rtl::OUString aToolkitServiceName(
1387*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.awt.Toolkit" ) );
1388*cdf0e10cSrcweir     uno::Reference<awt::XSystemChildFactory> xToolkit(
1389*cdf0e10cSrcweir         m_xFactory->createInstance(aToolkitServiceName ),uno::UNO_QUERY);
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir     if(xToolkit.is() && m_pIOleIPFrame) {
1392*cdf0e10cSrcweir         HWND hWnd;
1393*cdf0e10cSrcweir         m_pIOleIPFrame->GetWindow(&hWnd);
1394*cdf0e10cSrcweir 
1395*cdf0e10cSrcweir         uno::Sequence<sal_Int8> aProcessIdent(16);
1396*cdf0e10cSrcweir         rtl_getGlobalProcessId((sal_uInt8*)aProcessIdent.getArray());
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir         uno::Any aAny;
1399*cdf0e10cSrcweir         aAny <<= sal_Int32(hWnd);
1400*cdf0e10cSrcweir         xWin = uno::Reference<awt::XWindow>(
1401*cdf0e10cSrcweir             xToolkit->createSystemChild(
1402*cdf0e10cSrcweir                 aAny,
1403*cdf0e10cSrcweir                 aProcessIdent,
1404*cdf0e10cSrcweir                 lang::SystemDependent::SYSTEM_WIN32),
1405*cdf0e10cSrcweir             uno::UNO_QUERY);
1406*cdf0e10cSrcweir 
1407*cdf0e10cSrcweir         RECT wi;
1408*cdf0e10cSrcweir         memset(&wi,0,sizeof(wi));
1409*cdf0e10cSrcweir 		if(xWin.is() && m_pIOleIPFrame->GetBorder((LPRECT)&wi) == NOERROR) {
1410*cdf0e10cSrcweir             xWin->setVisible(true);
1411*cdf0e10cSrcweir             xWin->setPosSize(
1412*cdf0e10cSrcweir                 0,0,
1413*cdf0e10cSrcweir                 wi.right-wi.left,
1414*cdf0e10cSrcweir                 wi.bottom - wi.top,
1415*cdf0e10cSrcweir                 awt::PosSize::POSSIZE);
1416*cdf0e10cSrcweir 
1417*cdf0e10cSrcweir             uno::Reference<awt::XSystemDependentWindowPeer> xSysWin(
1418*cdf0e10cSrcweir                 xWin,uno::UNO_QUERY);
1419*cdf0e10cSrcweir             if(xSysWin.is()) {
1420*cdf0e10cSrcweir                 aAny = xSysWin->getWindowHandle(
1421*cdf0e10cSrcweir                     aProcessIdent,lang::SystemDependent::SYSTEM_WIN32);
1422*cdf0e10cSrcweir                 sal_Int32 tmp;
1423*cdf0e10cSrcweir                 if( aAny >>= tmp )
1424*cdf0e10cSrcweir                     SetContainerWindowHandle((HWND) tmp);
1425*cdf0e10cSrcweir             }
1426*cdf0e10cSrcweir         }
1427*cdf0e10cSrcweir     }
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir     m_xContainerWindow= xWin;
1430*cdf0e10cSrcweir     return xWin;
1431*cdf0e10cSrcweir }
1432*cdf0e10cSrcweir 
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir 
1435*cdf0e10cSrcweir sal_Bool SAL_CALL
1436*cdf0e10cSrcweir DocumentHolder::requestDockingAreaSpace(
1437*cdf0e10cSrcweir     const ::com::sun::star::awt::Rectangle& RequestedSpace
1438*cdf0e10cSrcweir )
1439*cdf0e10cSrcweir     throw(
1440*cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException
1441*cdf0e10cSrcweir     )
1442*cdf0e10cSrcweir {
1443*cdf0e10cSrcweir     if(m_bOnDeactivate)
1444*cdf0e10cSrcweir         return sal_True;
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir     BORDERWIDTHS bw;
1447*cdf0e10cSrcweir     SetRect((LPRECT)&bw,
1448*cdf0e10cSrcweir             RequestedSpace.X,RequestedSpace.Y,
1449*cdf0e10cSrcweir             RequestedSpace.Width,RequestedSpace.Height);
1450*cdf0e10cSrcweir     if( m_pIOleIPFrame )
1451*cdf0e10cSrcweir         return m_pIOleIPFrame->RequestBorderSpace(&bw) == NOERROR ;
1452*cdf0e10cSrcweir     else
1453*cdf0e10cSrcweir         return sal_Bool(false);
1454*cdf0e10cSrcweir }
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir 
1457*cdf0e10cSrcweir void SAL_CALL
1458*cdf0e10cSrcweir DocumentHolder::setDockingAreaSpace(
1459*cdf0e10cSrcweir     const ::com::sun::star::awt::Rectangle& BorderSpace
1460*cdf0e10cSrcweir )
1461*cdf0e10cSrcweir     throw (
1462*cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException
1463*cdf0e10cSrcweir     )
1464*cdf0e10cSrcweir {
1465*cdf0e10cSrcweir     if(m_bOnDeactivate)
1466*cdf0e10cSrcweir         return;
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir     BORDERWIDTHS bw;
1469*cdf0e10cSrcweir     SetRect((LPRECT)&bw,
1470*cdf0e10cSrcweir             BorderSpace.X,BorderSpace.Y,
1471*cdf0e10cSrcweir             BorderSpace.Width,BorderSpace.Height);
1472*cdf0e10cSrcweir     if( m_pIOleIPFrame ) {
1473*cdf0e10cSrcweir         RECT aRect;
1474*cdf0e10cSrcweir         GetClientRect(m_hWndxWinCont,&aRect);
1475*cdf0e10cSrcweir         HRGN hrgn1 = CreateRectRgn(
1476*cdf0e10cSrcweir             0,0,
1477*cdf0e10cSrcweir             aRect.right,BorderSpace.Y);
1478*cdf0e10cSrcweir         HRGN hrgn2 = CreateRectRgn(aRect.right-BorderSpace.Width,0,aRect.right,aRect.bottom);
1479*cdf0e10cSrcweir         CombineRgn(hrgn1,hrgn1,hrgn2,RGN_OR);
1480*cdf0e10cSrcweir         DeleteObject(hrgn2);
1481*cdf0e10cSrcweir         hrgn2 = CreateRectRgn(0,aRect.bottom-BorderSpace.Height,aRect.right,aRect.bottom);
1482*cdf0e10cSrcweir         CombineRgn(hrgn1,hrgn1,hrgn2,RGN_OR);
1483*cdf0e10cSrcweir         DeleteObject(hrgn2);
1484*cdf0e10cSrcweir         hrgn2 = CreateRectRgn(0,0,BorderSpace.X,aRect.bottom);
1485*cdf0e10cSrcweir         CombineRgn(hrgn1,hrgn1,hrgn2,RGN_OR);
1486*cdf0e10cSrcweir         DeleteObject(hrgn2);
1487*cdf0e10cSrcweir 
1488*cdf0e10cSrcweir         SetWindowRgn(m_hWndxWinCont,hrgn1,true);
1489*cdf0e10cSrcweir         // not:: DeleteObject(hrgn1);
1490*cdf0e10cSrcweir         m_pIOleIPFrame->SetBorderSpace(&bw);
1491*cdf0e10cSrcweir     }
1492*cdf0e10cSrcweir }
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir 
1495*cdf0e10cSrcweir void SAL_CALL
1496*cdf0e10cSrcweir DocumentHolder::disposing(
1497*cdf0e10cSrcweir 	const com::sun::star::lang::EventObject& aSource
1498*cdf0e10cSrcweir )
1499*cdf0e10cSrcweir 		throw( uno::RuntimeException )
1500*cdf0e10cSrcweir {
1501*cdf0e10cSrcweir 	if ( m_xDocument.is() && m_xDocument == aSource.Source )
1502*cdf0e10cSrcweir 	{
1503*cdf0e10cSrcweir 		m_pIDispatch = NULL;
1504*cdf0e10cSrcweir 		m_xDocument = uno::Reference< frame::XModel >();
1505*cdf0e10cSrcweir 	}
1506*cdf0e10cSrcweir 
1507*cdf0e10cSrcweir 	if( m_xFrame.is() && m_xFrame == aSource.Source )
1508*cdf0e10cSrcweir 		m_xFrame = uno::Reference< frame::XFrame >();
1509*cdf0e10cSrcweir }
1510*cdf0e10cSrcweir 
1511*cdf0e10cSrcweir 
1512*cdf0e10cSrcweir void SAL_CALL
1513*cdf0e10cSrcweir DocumentHolder::queryClosing(
1514*cdf0e10cSrcweir 	const lang::EventObject& aSource,
1515*cdf0e10cSrcweir 	sal_Bool /*bGetsOwnership*/
1516*cdf0e10cSrcweir )
1517*cdf0e10cSrcweir 	throw(
1518*cdf0e10cSrcweir 		util::CloseVetoException
1519*cdf0e10cSrcweir 	)
1520*cdf0e10cSrcweir {
1521*cdf0e10cSrcweir 	if ( !m_bLink
1522*cdf0e10cSrcweir 	  && ( m_xDocument.is() && m_xDocument == aSource.Source || m_xFrame.is() && m_xFrame == aSource.Source ) )
1523*cdf0e10cSrcweir 		throw util::CloseVetoException();
1524*cdf0e10cSrcweir }
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir 
1527*cdf0e10cSrcweir void SAL_CALL
1528*cdf0e10cSrcweir DocumentHolder::notifyClosing(
1529*cdf0e10cSrcweir 	const lang::EventObject& aSource )
1530*cdf0e10cSrcweir 		throw( uno::RuntimeException )
1531*cdf0e10cSrcweir {
1532*cdf0e10cSrcweir 	try
1533*cdf0e10cSrcweir 	{
1534*cdf0e10cSrcweir 		uno::Reference< util::XCloseBroadcaster > xEventBroadcaster(
1535*cdf0e10cSrcweir 			aSource.Source, uno::UNO_QUERY_THROW );
1536*cdf0e10cSrcweir 		xEventBroadcaster->removeCloseListener( (util::XCloseListener*)this );
1537*cdf0e10cSrcweir 	}
1538*cdf0e10cSrcweir 	catch( uno::Exception& )
1539*cdf0e10cSrcweir 	{}
1540*cdf0e10cSrcweir 
1541*cdf0e10cSrcweir 	if ( m_xDocument.is() && m_xDocument == aSource.Source )
1542*cdf0e10cSrcweir 	{
1543*cdf0e10cSrcweir 		// can happen only in case of links
1544*cdf0e10cSrcweir 		m_pIDispatch = NULL;
1545*cdf0e10cSrcweir 		m_xDocument = uno::Reference< frame::XModel >();
1546*cdf0e10cSrcweir 		m_xFrame = uno::Reference< frame::XFrame >();
1547*cdf0e10cSrcweir 
1548*cdf0e10cSrcweir 		LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
1549*cdf0e10cSrcweir 		if ( aDocLock.GetEmbedDocument() )
1550*cdf0e10cSrcweir             aDocLock.GetEmbedDocument()->OLENotifyClosing();
1551*cdf0e10cSrcweir 	}
1552*cdf0e10cSrcweir 	else if( m_xFrame.is() && m_xFrame == aSource.Source )
1553*cdf0e10cSrcweir 		m_xFrame = uno::Reference< frame::XFrame >();
1554*cdf0e10cSrcweir }
1555*cdf0e10cSrcweir 
1556*cdf0e10cSrcweir void SAL_CALL
1557*cdf0e10cSrcweir DocumentHolder::queryTermination(
1558*cdf0e10cSrcweir     const lang::EventObject& /*aSource*/
1559*cdf0e10cSrcweir )
1560*cdf0e10cSrcweir 	throw(
1561*cdf0e10cSrcweir 		frame::TerminationVetoException
1562*cdf0e10cSrcweir 	)
1563*cdf0e10cSrcweir {
1564*cdf0e10cSrcweir 	if ( m_xDocument.is() )
1565*cdf0e10cSrcweir 		throw frame::TerminationVetoException();
1566*cdf0e10cSrcweir }
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir void SAL_CALL
1569*cdf0e10cSrcweir DocumentHolder::notifyTermination(
1570*cdf0e10cSrcweir 	const lang::EventObject& aSource
1571*cdf0e10cSrcweir )
1572*cdf0e10cSrcweir 		throw( uno::RuntimeException )
1573*cdf0e10cSrcweir {
1574*cdf0e10cSrcweir 	OSL_ENSURE( !m_xDocument.is(), "Just a disaster..." );
1575*cdf0e10cSrcweir 	uno::Reference< frame::XDesktop > xDesktop(
1576*cdf0e10cSrcweir         aSource.Source, uno::UNO_QUERY );
1577*cdf0e10cSrcweir 
1578*cdf0e10cSrcweir 	if ( xDesktop.is() )
1579*cdf0e10cSrcweir 		xDesktop->removeTerminateListener( (frame::XTerminateListener*)this );
1580*cdf0e10cSrcweir }
1581*cdf0e10cSrcweir 
1582*cdf0e10cSrcweir 
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir void SAL_CALL DocumentHolder::modified( const lang::EventObject& /*aEvent*/ )
1585*cdf0e10cSrcweir 	throw (uno::RuntimeException)
1586*cdf0e10cSrcweir {
1587*cdf0e10cSrcweir 	if ( m_xOleAccess.is() )
1588*cdf0e10cSrcweir 	{
1589*cdf0e10cSrcweir 		LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
1590*cdf0e10cSrcweir 		if ( aDocLock.GetEmbedDocument() )
1591*cdf0e10cSrcweir             aDocLock.GetEmbedDocument()->notify();
1592*cdf0e10cSrcweir 	}
1593*cdf0e10cSrcweir }
1594*cdf0e10cSrcweir 
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir 
1597*cdf0e10cSrcweir //     if(m_pOLEInterface->GetGUID() == OID_WriterTextServer) {
1598*cdf0e10cSrcweir //         // edit group
1599*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,1,hMenu,(WORD)mgw.width[0]);
1600*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,2,hMenu,1+(WORD)mgw.width[0]);
1601*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,3,hMenu,2+(WORD)mgw.width[0]);
1602*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,4,hMenu,3+(WORD)mgw.width[0]);
1603*cdf0e10cSrcweir //         mgw.width[1]=4;
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir //         // object group
1606*cdf0e10cSrcweir //         CopyToOLEMenu(
1607*cdf0e10cSrcweir //             m_nMenuHandle,5,
1608*cdf0e10cSrcweir //             hMenu,4+(WORD)mgw.width[0]+(WORD)mgw.width[2]);
1609*cdf0e10cSrcweir //         mgw.width[3]=1;
1610*cdf0e10cSrcweir 
1611*cdf0e10cSrcweir //         // help group
1612*cdf0e10cSrcweir //         CopyToOLEMenu(
1613*cdf0e10cSrcweir //             m_nMenuHandle,7,
1614*cdf0e10cSrcweir //             hMenu,5+(WORD)mgw.width[0]+(WORD)mgw.width[2]+(WORD)mgw.width[4]);
1615*cdf0e10cSrcweir //         mgw.width[5]=1;
1616*cdf0e10cSrcweir //     }
1617*cdf0e10cSrcweir //     else if(m_pOLEInterface->GetGUID() == OID_CalcServer) {
1618*cdf0e10cSrcweir //         // edit group
1619*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,1,hMenu,(WORD)mgw.width[0]);
1620*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,2,hMenu,1+(WORD)mgw.width[0]);
1621*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,3,hMenu,2+(WORD)mgw.width[0]);
1622*cdf0e10cSrcweir //         CopyToOLEMenu(m_nMenuHandle,4,hMenu,3+(WORD)mgw.width[0]);
1623*cdf0e10cSrcweir //         mgw.width[1]=4;
1624*cdf0e10cSrcweir 
1625*cdf0e10cSrcweir //         // object group
1626*cdf0e10cSrcweir //         CopyToOLEMenu(
1627*cdf0e10cSrcweir //             m_nMenuHandle,5,
1628*cdf0e10cSrcweir //             hMenu,4+(WORD)mgw.width[0]+(WORD)mgw.width[2]);
1629*cdf0e10cSrcweir //         CopyToOLEMenu(
1630*cdf0e10cSrcweir //             m_nMenuHandle,6,
1631*cdf0e10cSrcweir //             hMenu,5+(WORD)mgw.width[0]+(WORD)mgw.width[2]);
1632*cdf0e10cSrcweir //         mgw.width[3]=2;
1633*cdf0e10cSrcweir 
1634*cdf0e10cSrcweir //         // help group
1635*cdf0e10cSrcweir //         CopyToOLEMenu(
1636*cdf0e10cSrcweir //             m_nMenuHandle,8,
1637*cdf0e10cSrcweir //             hMenu,6+(WORD)mgw.width[0]+(WORD)mgw.width[2]+(WORD)mgw.width[4]);
1638*cdf0e10cSrcweir //         mgw.width[5]=1;
1639*cdf0e10cSrcweir //     }
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir // Fix strange warnings about some
1642*cdf0e10cSrcweir // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
1643*cdf0e10cSrcweir // warning C4505: 'xxx' : unreferenced local function has been removed
1644*cdf0e10cSrcweir #if defined(_MSC_VER)
1645*cdf0e10cSrcweir #pragma warning(disable: 4505)
1646*cdf0e10cSrcweir #endif
1647