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