update dev300-m57
[ooovba.git] / embedserv / source / embed / docholder.cxx
blob25ba6c37857b16cd12aaf5ecd34e7389c2888195
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docholder.cxx,v $
10 * $Revision: 1.31.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #if defined(_MSC_VER) && (_MSC_VER > 1310)
31 #pragma warning(disable : 4917 4555)
32 #endif
35 #include "xwin.hxx"
36 #include "docholder.hxx"
37 #include "embeddoc.hxx"
38 #include "intercept.hxx"
39 #include "syswinwrapper.hxx"
40 #include "iipaobj.hxx"
42 #include "common.h"
43 #include <Windows.h>
44 #include <com/sun/star/lang/SystemDependent.hpp>
45 #include <com/sun/star/awt/XSystemChildFactory.hpp>
46 #ifndef _COM_SUN_STAR_AWT_XSYSTEMDEPENDENTWINDOWPERR_HPP_
47 #include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
48 #endif
49 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
50 #include <com/sun/star/ui/XUIElement.hpp>
51 #include <com/sun/star/awt/WindowAttribute.hpp>
52 #include <com/sun/star/awt/XWindow.hpp>
53 #include <com/sun/star/frame/XComponentLoader.hpp>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/util/XCloseBroadcaster.hpp>
56 #include <com/sun/star/util/XCloseAble.hpp>
57 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACESS_HPP_
58 #include <com/sun/star/container/XNameAccess.hpp>
59 #endif
60 #include <com/sun/star/beans/XPropertySet.hpp>
61 #include <com/sun/star/frame/XModel.hpp>
62 #include <com/sun/star/frame/XDesktop.hpp>
63 #include <com/sun/star/frame/XFramesSupplier.hpp>
64 #include <com/sun/star/frame/FrameSearchFlag.hpp>
65 #include <com/sun/star/frame/XStatusListener.hpp>
66 #include <com/sun/star/util/XModifyBroadcaster.hpp>
67 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
68 #include <com/sun/star/awt/XTopWindow.hpp>
69 #include <com/sun/star/awt/PosSize.hpp>
70 #include <com/sun/star/awt/XView.hpp>
71 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
72 #include <com/sun/star/bridge/ModelDependent.hpp>
73 #include <com/sun/star/embed/EmbedMapUnits.hpp>
74 #include <com/sun/star/embed/XVisualObject.hpp>
75 #include <com/sun/star/document/MacroExecMode.hpp>
76 #include <com/sun/star/task/XInteractionHandler.hpp>
77 #include <osl/diagnose.h>
78 #include <rtl/process.h>
80 using namespace ::com::sun::star;
82 extern ::rtl::OUString getFilterNameFromGUID_Impl( GUID* );
84 // add mutex locking ???
86 DocumentHolder::DocumentHolder(
87 const uno::Reference<lang::XMultiServiceFactory >& xFactory,
88 const ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl >& xOleAccess )
90 m_bAllowInPlace(true),
91 m_pIOleIPSite(0),
92 m_pIOleIPFrame(0),
93 m_pIOleIPUIWindow(0),
94 m_pCHatchWin(0),
95 m_xOleAccess( xOleAccess ),
96 m_pInterceptor(0),
97 m_xFactory( xFactory ),
98 m_bOnDeactivate(false),
99 m_hWndxWinParent(NULL),
100 m_hWndxWinCont(NULL),
101 m_nMenuHandle(NULL),
102 m_nMenuShared(NULL),
103 m_nOLEMenu(NULL),
104 m_nMacroExecMode( document::MacroExecMode::USE_CONFIG ),
105 m_bLink( sal_False )
107 static const ::rtl::OUString aServiceName (
108 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
109 uno::Reference< frame::XDesktop > xDesktop(
110 m_xFactory->createInstance( aServiceName ),
111 uno::UNO_QUERY );
112 if ( xDesktop.is() )
113 xDesktop->addTerminateListener( (frame::XTerminateListener*)this );
117 DocumentHolder::~DocumentHolder()
119 delete m_pCHatchWin;
121 ClearInterceptorInternally();
125 void DocumentHolder::LoadDocInFrame( sal_Bool bPluginMode )
127 uno::Reference<frame::XComponentLoader> xComponentLoader(
128 m_xFrame,uno::UNO_QUERY);
129 if( xComponentLoader.is() && m_xDocument.is() )
131 uno::Reference< task::XInteractionHandler > xHandler(
132 m_xFactory->createInstance(
133 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ),
134 uno::UNO_QUERY );
136 uno::Any aAny;
137 sal_Int32 nLen = 3;
138 uno::Sequence<beans::PropertyValue> aSeq( nLen );
140 aAny <<= uno::Reference<uno::XInterface>(
141 m_xDocument, uno::UNO_QUERY);
142 aSeq[0] = beans::PropertyValue(
143 rtl::OUString(
144 RTL_CONSTASCII_USTRINGPARAM("Model")),
146 aAny,
147 beans::PropertyState_DIRECT_VALUE);
149 aAny <<= sal_False;
150 aSeq[1] = beans::PropertyValue(
151 rtl::OUString(
152 RTL_CONSTASCII_USTRINGPARAM("ReadOnly")),
154 aAny,
155 beans::PropertyState_DIRECT_VALUE);
157 aAny <<= (sal_Bool) sal_True;
158 aSeq[2] = beans::PropertyValue(
159 rtl::OUString(
160 RTL_CONSTASCII_USTRINGPARAM("NoAutoSave")),
162 aAny,
163 beans::PropertyState_DIRECT_VALUE);
165 if ( bPluginMode )
167 aSeq.realloc( ++nLen );
168 aAny <<= (sal_Int16) 3;
169 aSeq[nLen-1] = beans::PropertyValue(
170 rtl::OUString(
171 RTL_CONSTASCII_USTRINGPARAM("PluginMode")),
173 aAny,
174 beans::PropertyState_DIRECT_VALUE);
177 if ( xHandler.is() )
179 aSeq.realloc( nLen+=2 );
180 aAny <<= xHandler;
181 aSeq[nLen-2] = beans::PropertyValue(
182 rtl::OUString(
183 RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")),
185 aAny,
186 beans::PropertyState_DIRECT_VALUE);
188 aAny <<= m_nMacroExecMode;
189 aSeq[nLen-1] = beans::PropertyValue(
190 rtl::OUString(
191 RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode")),
193 aAny,
194 beans::PropertyState_DIRECT_VALUE);
197 xComponentLoader->loadComponentFromURL(
198 rtl::OUString(
199 RTL_CONSTASCII_USTRINGPARAM("private:object")),
200 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")),
202 aSeq);
204 uno::Sequence< beans::PropertyValue > aResArgs = m_xDocument->getArgs();
205 for ( int nInd = 0; nInd < aResArgs.getLength(); nInd++ )
206 if ( aResArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MacroExecutionMode" ) ) ) )
208 aResArgs[nInd].Value >>= m_nMacroExecMode;
209 break;
214 void DocumentHolder::OnPosRectChanged(LPRECT lpRect) const
216 lpRect->left += m_aBorder.left;
217 lpRect->right -= m_aBorder.right;
218 lpRect->top += m_aBorder.top;
219 lpRect->bottom -= m_aBorder.bottom;
220 if(m_pIOleIPSite)
221 m_pIOleIPSite->OnPosRectChange(lpRect);
226 void DocumentHolder::DisableInplaceActivation(BOOL b)
228 m_bAllowInPlace = ! b;
231 BOOL DocumentHolder::isActive() const
233 return m_pIOleIPSite != 0;
236 HRESULT DocumentHolder::InPlaceActivate(
237 LPOLECLIENTSITE pActiveSite,
238 BOOL fIncludeUI)
240 m_bOnDeactivate = false;
242 if(!m_bAllowInPlace)
243 return ERROR;
245 HRESULT hr;
246 HWND hWndSite;
247 RECT rcPos;
248 RECT rcClip;
249 OLEINPLACEFRAMEINFO frameInfo;
251 if (NULL==pActiveSite)
252 return ResultFromScode(E_INVALIDARG);
254 if (NULL!=m_pIOleIPSite)
256 if (fIncludeUI)
257 UIActivate();
259 return NOERROR;
262 if ( !m_xDocument.is() )
263 return ERROR;
265 //1. Initialization, obtaining interfaces, OnInPlaceActivate.
266 hr=pActiveSite->QueryInterface(
267 IID_IOleInPlaceSite,
268 (void**) &m_pIOleIPSite);
270 if (FAILED(hr))
271 return hr;
273 hr=m_pIOleIPSite->CanInPlaceActivate();
275 if (NOERROR!=hr)
277 m_pIOleIPSite->Release(), m_pIOleIPSite=NULL;
278 return ResultFromScode(E_FAIL);
281 m_pIOleIPSite->OnInPlaceActivate();
283 //2. Get the site window
284 //3. and determine container frame and
285 // document window for tools and menus, as well
286 // as frameInfo for accelerators
287 m_pIOleIPSite->GetWindow(&hWndSite);
289 frameInfo.cb=sizeof(OLEINPLACEFRAMEINFO);
290 m_pIOleIPSite->GetWindowContext(
291 &m_pIOleIPFrame,&m_pIOleIPUIWindow,&rcPos,&rcClip,&frameInfo);
293 // initialize the office as, with hwnd as parentwindow
294 uno::Any aAny;
295 uno::Sequence<sal_Int8> aProcessIdent(16);
296 rtl_getGlobalProcessId((sal_uInt8*)aProcessIdent.getArray());
300 if(!m_xEditWindow.is())
301 { // determine XWindow and window handle of parent
302 HWND hWndxWinParent(0);
303 uno::Reference<awt::XWindow> xWin;
305 static const ::rtl::OUString aToolkitServiceName(
306 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.awt.Toolkit" ) );
307 uno::Reference<awt::XSystemChildFactory> xToolkit(
308 m_xFactory->createInstance(aToolkitServiceName ),uno::UNO_QUERY);
310 if(xToolkit.is()) {
311 // create system window wrapper for hwnd
312 if( !m_pCHatchWin )
313 m_pCHatchWin = new winwrap::CHatchWin(
314 m_hInstance,this);
316 if(m_pCHatchWin->Init(hWndSite,/*ID_HATCHWINDOW*/2000, NULL)) {
317 m_pCHatchWin->RectsSet(&rcPos,&rcClip); //set visible area
318 hWndxWinParent = m_pCHatchWin->Window();
319 ShowWindow(hWndxWinParent,SW_SHOW); //Make visible.
321 else {
322 // no success initializing hatch window
323 delete m_pCHatchWin, m_pCHatchWin = 0;
324 hWndxWinParent = hWndSite;
327 aAny <<= sal_Int32(hWndxWinParent);
328 xWin = uno::Reference<awt::XWindow>(
329 xToolkit->createSystemChild(
330 aAny,
331 aProcessIdent,
332 lang::SystemDependent::SYSTEM_WIN32),
333 uno::UNO_QUERY);
336 if(xWin.is()) {
337 xWin->setPosSize(
338 m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
339 m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
340 rcPos.right-rcPos.left,
341 rcPos.bottom - rcPos.top,
342 awt::PosSize::POSSIZE);
343 xWin->setVisible(sal_True);
345 m_xEditWindow = xWin;
346 m_hWndxWinParent = hWndxWinParent;
348 else
349 return ERROR;
351 else {
352 if(m_hWndxWinParent) {
353 SetParent(m_hWndxWinParent,hWndSite);
354 ShowWindow(m_hWndxWinParent,SW_SHOW); //Make visible.
357 if ( !m_xFrame.is() )
358 // initially set size to "empty", this guarantees that the final resize
359 // is always executed (will be done by "SetObjectRects" after getting internal border)
360 m_xEditWindow->setPosSize(
365 awt::PosSize::POSSIZE);
366 m_xEditWindow->setVisible(sal_True);
369 if(m_xContainerWindow.is()) {
370 if(m_hWndxWinCont) {
371 if(m_pIOleIPFrame) {
372 HWND hWndCont;
373 m_pIOleIPFrame->GetWindow(&hWndCont);
374 SetParent(m_hWndxWinCont,hWndCont);
375 ShowWindow(m_hWndxWinCont,SW_SHOW);
378 m_xContainerWindow->setVisible(true);
381 if(m_xFrame.is())
382 m_xFrame->activate();
383 else {
384 // create frame and initialize it with with the created window
385 static const ::rtl::OUString aFrameServiceName(
386 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Frame" ) );
387 m_xFrame = uno::Reference<frame::XFrame>(
388 m_xFactory->createInstance(aFrameServiceName),
389 uno::UNO_QUERY);
391 if(!m_xFrame.is())
392 return ERROR;
394 m_xFrame->initialize(m_xEditWindow);
396 uno::Reference<frame::XDispatchProviderInterception>
397 xDPI(m_xFrame,uno::UNO_QUERY);
398 if(xDPI.is())
399 xDPI->registerDispatchProviderInterceptor( CreateNewInterceptor() );
401 uno::Reference<beans::XPropertySet> xPS(m_xFrame,uno::UNO_QUERY);
402 if( xPS.is() )
404 aAny = xPS->getPropertyValue(
405 rtl::OUString::createFromAscii("LayoutManager"));
406 aAny >>= m_xLayoutManager;
409 if(m_xLayoutManager.is())
410 m_xLayoutManager->setDockingAreaAcceptor(this);
412 // load the model into the frame
413 LoadDocInFrame( sal_True );
415 static const ::rtl::OUString aDesktopServiceName (
416 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
417 uno::Reference< frame::XFramesSupplier > xDesktop(
418 m_xFactory->createInstance( aDesktopServiceName ),
419 uno::UNO_QUERY );
420 if(xDesktop.is())
421 xDesktop->getFrames()->append(m_xFrame);
423 // determine the menuhandle to get menutitems.
424 if(m_xLayoutManager.is()) {
425 uno::Reference< ::com::sun::star::ui::XUIElement > xUIEl(
426 m_xLayoutManager->getElement(
427 rtl::OUString::createFromAscii(
428 "private:resource/menubar/menubar")));
429 OSL_ENSURE(xUIEl.is(),"no menubar");
430 uno::Reference<awt::XSystemDependentMenuPeer> xSDMP(
431 xUIEl->getRealInterface(),
432 uno::UNO_QUERY);
433 aAny = xSDMP->getMenuHandle(
434 aProcessIdent,lang::SystemDependent::SYSTEM_WIN32);
435 sal_Int32 tmp;
436 if( aAny >>= tmp )
437 m_nMenuHandle = HMENU(tmp);
438 m_xLayoutManager->hideElement(
439 rtl::OUString(
440 RTL_CONSTASCII_USTRINGPARAM(
441 "private:resource/menubar/menubar" )));
445 // TODO/cd: Workaround for status indicator bug. It always makes the
446 // document window visible, when someone tries to use the status
447 // indicator. As we save our document when we get the deactivation
448 // from OLE this conflict to hide floating windows.
449 if(m_xLayoutManager.is())
450 m_xLayoutManager->setVisible(true);
452 // get document border and resize rects according to border
453 GetDocumentBorder( &m_aBorder );
454 SetObjectRects( &rcPos, &rcClip );
456 if ( m_xOleAccess.is() )
458 LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
459 if ( aDocLock.GetEmbedDocument() )
460 aDocLock.GetEmbedDocument()->ShowObject();
463 // setTitle(m_aDocumentNamePart);
464 if (fIncludeUI)
465 hr=UIActivate();
467 m_pIOleIPSite->DiscardUndoState();
469 catch( uno::Exception& )
471 hr = ERROR;
474 return hr;
478 void DocumentHolder::InPlaceDeactivate(void)
480 m_bOnDeactivate = true;
482 UIDeactivate();
483 if(m_xFrame.is()) m_xFrame->deactivate();
485 if(m_xEditWindow.is()) {
486 m_xEditWindow->setVisible(false);
487 ShowWindow(m_hWndxWinParent,SW_HIDE);
488 SetParent(m_hWndxWinParent,0);
491 if(m_xContainerWindow.is()) {
492 m_xContainerWindow->setVisible(false);
493 ShowWindow(m_hWndxWinCont,SW_HIDE);
494 SetParent(m_hWndxWinCont,0);
497 // TODO/cd: Workaround for status indicator bug. It always makes the
498 // document window visible, when someone tries to use the status
499 // indicator. As we save our document when we get the deactivation
500 // from OLE this conflict to hide floating windows.
501 if (m_xLayoutManager.is())
502 m_xLayoutManager->setVisible(false);
504 if (NULL!=m_pIOleIPSite)
506 // The following workaround should let the object be stored in case of inplace editing
507 // CComPtr< IOleClientSite > pClientSite;
509 // m_pIOleIPSite->QueryInterface(
510 // IID_IOleClientSite, (void**)&pClientSite );
511 // if ( pClientSite )
512 // pClientSite->SaveObject();
514 m_pIOleIPSite->OnInPlaceDeactivate();
517 if(m_pIOleIPFrame) m_pIOleIPFrame->Release(); m_pIOleIPFrame = 0;
518 if(m_pIOleIPUIWindow) m_pIOleIPUIWindow->Release(); m_pIOleIPUIWindow = 0;
519 if(m_pIOleIPSite) m_pIOleIPSite->Release(); m_pIOleIPSite = 0;
521 if ( m_xOleAccess.is() )
523 LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
524 if ( aDocLock.GetEmbedDocument() )
526 aDocLock.GetEmbedDocument()->SaveObject();
530 return;
534 HRESULT DocumentHolder::UIActivate()
536 // 1. Call IOleInPlaceSite::UIActivate
537 if (NULL!=m_pIOleIPSite)
538 m_pIOleIPSite->OnUIActivate();
540 //2. Critical for accelerators to work initially.
541 SetFocus(m_pCHatchWin->Window());
542 // if(m_xEditWindow.is()) m_xEditWindow->setFocus();
544 //3. Set the active object
546 OLECHAR starOffice[] = {'S','t','a','r','O','f','f','i','c','e',0};
547 CComPtr< IOleInPlaceActiveObject > pObj = new CIIAObj( this );
549 if (NULL!=m_pIOleIPFrame)
550 m_pIOleIPFrame->SetActiveObject(
551 pObj, starOffice );
553 if (NULL!=m_pIOleIPUIWindow)
554 m_pIOleIPUIWindow->SetActiveObject(
555 pObj, starOffice );
557 //4. Create the shared menu.
558 InPlaceMenuCreate();
560 return NOERROR;
563 void DocumentHolder::UIDeactivate()
565 //1. Remove the shared menu.
566 InPlaceMenuDestroy();
568 if (NULL!=m_pIOleIPFrame)
569 m_pIOleIPFrame->SetActiveObject(NULL, NULL);
571 if (NULL!=m_pIOleIPUIWindow)
572 m_pIOleIPUIWindow->SetActiveObject(NULL, NULL);
574 //3. Call IOleInPlaceSite::OnUIDeactivate
575 if (NULL!=m_pIOleIPSite)
576 m_pIOleIPSite->OnUIDeactivate(FALSE);
578 return;
581 void CopyToOLEMenu(HMENU hOrig,WORD origPos,HMENU hDest,WORD destPos)
583 HMENU subMenu(NULL);
584 UINT uTemp = MF_BYPOSITION | MF_POPUP;
585 char buffer[256];
587 subMenu = GetSubMenu(hOrig,origPos);
588 GetMenuString(hOrig,origPos,buffer,256,MF_BYPOSITION);
589 InsertMenu(hDest,destPos,uTemp,
590 (UINT)subMenu,LPCTSTR(buffer));
592 MENUITEMINFOW mi;
593 memset(&mi,0,sizeof(mi));
594 mi.cbSize = sizeof(mi);
595 mi.fMask = MIIM_DATA;
596 if(GetMenuItemInfoW(hOrig,origPos,TRUE,&mi))
597 SetMenuItemInfoW(hDest,(WORD)destPos,TRUE,&mi);
600 BOOL DocumentHolder::InPlaceMenuCreate(void)
602 HMENU hMenu;
603 UINT i;
604 OLEMENUGROUPWIDTHS mgw;
606 for (i=0; i<6; i++)
607 mgw.width[i]=0;
609 //We already have popup menu handles in m_pFR->m_phMenu[]
611 //Create the new shared menu and let container do its thing
612 hMenu=CreateMenu();
613 m_pIOleIPFrame->InsertMenus(hMenu,&mgw);
615 int count = GetMenuItemCount(m_nMenuHandle);
616 int help = count-1;
618 // start with 1, because we don't include "File"
619 WORD pos = (WORD)mgw.width[0];
620 CopyToOLEMenu(m_nMenuHandle,1,hMenu,pos);
621 mgw.width[1] = 1;
623 // insert object menu here
624 pos = ((WORD)(mgw.width[0] + mgw.width[1] + mgw.width[2]));
625 for(WORD i = 2; i < help-1; ++i,++pos)
626 CopyToOLEMenu(m_nMenuHandle,i,hMenu,pos);
627 mgw.width[3] = help - 3;
629 // insert help menu
630 pos = (WORD)(mgw.width[0] + mgw.width[1] + mgw.width[2] +
631 mgw.width[3] + mgw.width[4]);
632 CopyToOLEMenu(m_nMenuHandle,WORD(help),hMenu,pos);
633 mgw.width[5] = 1;
635 m_nMenuShared = hMenu;
636 m_nOLEMenu = OleCreateMenuDescriptor(m_nMenuShared,&mgw);
638 uno::Reference<awt::XSystemDependentWindowPeer> xSysDepWin(m_xContainerWindow,uno::UNO_QUERY);
639 if(xSysDepWin.is()) {
640 uno::Sequence<sal_Int8> aProcessIdent(16);
641 rtl_getGlobalProcessId((sal_uInt8*)aProcessIdent.getArray());
642 uno::Any aAny = xSysDepWin->getWindowHandle(aProcessIdent,lang::SystemDependent::SYSTEM_WIN32);
643 sal_Int32 tmp;
644 aAny >>= tmp;
645 HWND aHwnd = (HWND) tmp;
646 m_pIOleIPFrame->SetMenu(
647 m_nMenuShared,m_nOLEMenu,aHwnd);
649 else
650 m_pIOleIPFrame->SetMenu(
651 m_nMenuShared,m_nOLEMenu,::GetWindow(m_hWndxWinParent,GW_CHILD));
652 return TRUE;
655 BOOL DocumentHolder::InPlaceMenuDestroy(void)
657 if( NULL == m_nMenuShared )
658 return TRUE;
660 m_pIOleIPFrame->SetMenu(NULL,NULL,NULL);
662 OleDestroyMenuDescriptor(m_nOLEMenu),m_nOLEMenu = NULL;
663 return TRUE;
666 void DocumentHolder::OpenIntoWindow(void)
668 // not implemented
671 BOOL DocumentHolder::Undo(void)
673 // not implemented
674 return false;
678 void DocumentHolder::FreeOffice()
680 const ::rtl::OUString aServiceName(
681 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
682 uno::Reference< frame::XDesktop > xDesktop(
683 m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
684 if ( xDesktop.is() )
686 xDesktop->removeTerminateListener(
687 (frame::XTerminateListener*)this );
691 void DocumentHolder::DisconnectFrameDocument( sal_Bool bComplete )
695 uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, uno::UNO_QUERY_THROW );
696 xModifiable->removeModifyListener( (util::XModifyListener*)this );
698 catch( uno::Exception& )
703 uno::Reference< util::XCloseBroadcaster > xBroadcaster(
704 m_xDocument, uno::UNO_QUERY_THROW );
705 xBroadcaster->removeCloseListener( (util::XCloseListener*)this );
707 catch( uno::Exception& )
712 uno::Reference< util::XCloseBroadcaster > xBroadcaster(
713 m_xFrame, uno::UNO_QUERY_THROW );
714 xBroadcaster->removeCloseListener( (util::XCloseListener*)this );
716 catch( uno::Exception& )
719 if ( bComplete )
721 m_xFrame = uno::Reference< frame::XFrame>();
722 m_pIDispatch = NULL;
723 m_xDocument = uno::Reference< frame::XModel >();
727 void DocumentHolder::CloseDocument()
729 DisconnectFrameDocument();
731 uno::Reference< util::XCloseable > xCloseable(
732 m_xDocument, uno::UNO_QUERY );
734 if ( xCloseable.is() )
738 xCloseable->close( sal_True );
740 catch( uno::Exception& )
744 m_pIDispatch = NULL;
745 m_xDocument = uno::Reference< frame::XModel >();
749 void DocumentHolder::CloseFrame()
753 uno::Reference< util::XCloseBroadcaster > xBroadcaster(
754 m_xFrame, uno::UNO_QUERY_THROW );
755 xBroadcaster->removeCloseListener( (util::XCloseListener*)this );
757 catch( uno::Exception& )
760 uno::Reference<util::XCloseable> xCloseable(
761 m_xFrame,uno::UNO_QUERY);
762 if(xCloseable.is())
763 try {
764 xCloseable->close(sal_True);
766 catch( const uno::Exception& ) {
768 else {
769 uno::Reference<lang::XComponent> xComp(m_xFrame,uno::UNO_QUERY);
770 if(xComp.is())
771 xComp->dispose();
774 m_xFrame = uno::Reference< frame::XFrame >();
777 void DocumentHolder::SetDocument( const uno::Reference< frame::XModel >& xDoc, sal_Bool bLink )
779 if ( m_xDocument.is() )
780 CloseDocument();
782 m_xDocument = xDoc;
783 m_bLink = bLink;
785 uno::Reference< util::XCloseBroadcaster > xBroadcaster(
786 m_xDocument, uno::UNO_QUERY );
788 if ( xBroadcaster.is() )
789 xBroadcaster->addCloseListener( (util::XCloseListener*)this );
791 if ( m_xDocument.is() && !m_bLink )
793 // set the document mode to embedded
794 uno::Sequence< beans::PropertyValue > aSeq(1);
795 aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" );
796 aSeq[0].Value <<= sal_True;
797 m_xDocument->attachResource(::rtl::OUString(),aSeq);
801 sal_Bool DocumentHolder::ExecuteSuspendCloseFrame()
803 if ( m_xFrame.is() && m_xFactory.is() )
807 uno::Reference< frame::XController > xController = m_xFrame->getController();
808 if ( xController.is() )
810 if ( !xController->suspend( sal_True ) )
811 return sal_False;
813 FreeOffice();
816 uno::Reference<util::XCloseable> xCloseable( m_xFrame, uno::UNO_QUERY );
817 if ( xCloseable.is() )
818 xCloseable->close(sal_True);
819 else
821 uno::Reference<lang::XComponent> xComp( m_xFrame, uno::UNO_QUERY_THROW );
822 if( xComp.is() )
823 xComp->dispose();
826 catch( const util::CloseVetoException& )
828 // should be called if the frame could not be closed
829 xController->suspend( sal_False );
833 catch( uno::Exception& )
837 m_xFrame = uno::Reference< frame::XFrame >();
840 return sal_True;
843 uno::Reference< frame::XFrame > DocumentHolder::DocumentFrame()
845 if(! m_xFrame.is() )
847 rtl::OUString aDesktopSrvNm(
848 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"));
850 uno::Reference<frame::XDesktop> xDesktop(
851 m_xFactory->createInstance(aDesktopSrvNm),
852 uno::UNO_QUERY);
854 uno::Reference<frame::XFrame> xFrame(
855 xDesktop,uno::UNO_QUERY);
857 // the frame will be registered on desktop here, later when the document
858 // is loaded into the frame in ::show() method the terminate listener will be removed
859 // this is so only for outplace activation
860 if( xFrame.is() )
861 m_xFrame = xFrame->findFrame(
862 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")),0);
864 uno::Reference< util::XCloseBroadcaster > xBroadcaster(
865 m_xFrame, uno::UNO_QUERY );
867 if ( xBroadcaster.is() )
869 xBroadcaster->addCloseListener( (util::XCloseListener*)this );
870 FreeOffice(); // the frame is part of the desktop
874 if( m_xFrame.is() )
876 // intercept
877 uno::Reference<frame::XDispatchProviderInterception>
878 xDPI(m_xFrame,uno::UNO_QUERY);
879 if(xDPI.is())
880 xDPI->registerDispatchProviderInterceptor( CreateNewInterceptor() );
883 return m_xFrame;
887 uno::Reference< frame::XDispatchProviderInterceptor > DocumentHolder::CreateNewInterceptor()
889 ::osl::MutexGuard aGuard( m_aMutex );
891 ClearInterceptorInternally();
893 uno::Reference< frame::XDispatchProviderInterceptor > xInterceptor( m_pInterceptor = new Interceptor( m_xOleAccess, this, m_bLink ) );
894 m_xInterceptorLocker = xInterceptor;
895 return xInterceptor;
898 void DocumentHolder::ClearInterceptorInternally()
900 ::osl::MutexGuard aGuard( m_aMutex );
901 uno::Reference< frame::XDispatchProviderInterceptor > xInterceptor( m_xInterceptorLocker );
902 if ( xInterceptor.is() && m_pInterceptor )
903 m_pInterceptor->DisconnectDocHolder();
905 m_xInterceptorLocker = uno::Reference< frame::XDispatchProviderInterceptor >();
906 m_pInterceptor = 0;
909 void DocumentHolder::ClearInterceptor()
911 ::osl::MutexGuard aGuard( m_aMutex );
912 m_xInterceptorLocker = uno::Reference< frame::XDispatchProviderInterceptor >();
913 m_pInterceptor = 0;
917 void DocumentHolder::show()
921 if(m_xFrame.is())
923 m_xFrame->activate();
924 uno::Reference<awt::XTopWindow> xTopWindow(
925 m_xFrame->getContainerWindow(),uno::UNO_QUERY);
926 if(xTopWindow.is())
927 xTopWindow->toFront();
929 else if( DocumentFrame().is() )
931 LoadDocInFrame( sal_False );
933 // get rid of second closer if it is there
934 uno::Reference< beans::XPropertySet > xProps( m_xFrame, uno::UNO_QUERY );
935 if ( xProps.is() )
937 uno::Reference< frame::XLayoutManager > xLayoutManager;
938 xProps->getPropertyValue( rtl::OUString::createFromAscii( "LayoutManager" ) ) >>= xLayoutManager;
939 uno::Reference< beans::XPropertySet > xLMProps( xLayoutManager, uno::UNO_QUERY );
940 if ( xLMProps.is() )
942 xLMProps->setPropertyValue( ::rtl::OUString::createFromAscii( "MenuBarCloser" ),
943 uno::makeAny( uno::Reference< frame::XStatusListener >() ) );
947 if ( !m_bLink )
951 uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, uno::UNO_QUERY_THROW );
952 xModifiable->addModifyListener( (util::XModifyListener*)this );
954 catch( uno::Exception& )
958 if ( !m_bLink )
959 setTitle(m_aDocumentNamePart);
962 catch( uno::Exception& )
964 OSL_ENSURE( sal_False, "Can not show the frame!\n" );
969 void DocumentHolder::resizeWin( const SIZEL& rNewSize )
971 LockedEmbedDocument_Impl aDocLock;
973 if ( m_xOleAccess.is() )
974 aDocLock = m_xOleAccess->GetEmbedDocument();
976 if ( m_xFrame.is() && aDocLock.GetEmbedDocument() )
978 uno::Reference< awt::XWindow > xWindow(
979 m_xFrame->getContainerWindow(), uno::UNO_QUERY );
980 uno::Reference< awt::XView > xView( xWindow, uno::UNO_QUERY );
982 if ( xWindow.is() && xView.is() )
984 float fScale = 1;
985 xView->setZoom( fScale, fScale );
987 SIZEL aOldSize;
988 GetExtent( &aOldSize );
990 if ( aOldSize.cx != rNewSize.cx || aOldSize.cy != rNewSize.cy )
992 HDC hdc = GetDC( NULL );
993 SetMapMode( hdc, MM_HIMETRIC );
995 POINT aOldOffset;
996 aOldOffset.x = aOldSize.cx;
997 aOldOffset.y = aOldSize.cy;
998 BOOL bIsOk = LPtoDP( hdc, &aOldOffset, 1 );
1000 POINT aNewOffset;
1001 aNewOffset.x = rNewSize.cx;
1002 aNewOffset.y = rNewSize.cy;
1003 bIsOk = LPtoDP( hdc, &aNewOffset, 1 );
1005 ReleaseDC( NULL, hdc );
1007 awt::Rectangle aWinRect = xWindow->getPosSize();
1009 sal_Int32 aWidthDelta = aWinRect.Width - aOldOffset.x;
1010 sal_Int32 aHeightDelta = aWinRect.Height - aOldOffset.y;
1012 if ( aWidthDelta > 0 && aHeightDelta > 0 )
1013 xWindow->setPosSize(0,
1015 aNewOffset.x + aWidthDelta,
1016 aNewOffset.y + aHeightDelta,
1017 awt::PosSize::SIZE );
1023 void DocumentHolder::setTitle(const rtl::OUString& aDocumentName)
1025 if(m_xFrame.is())
1027 if(m_aFilterName.getLength() == 0)
1029 rtl::OUString aFilterName;
1030 uno::Sequence<beans::PropertyValue> aSeq;
1031 if(m_xDocument.is())
1033 aSeq =
1034 m_xDocument->getArgs();
1035 for(sal_Int32 j = 0; j < aSeq.getLength(); ++j)
1037 if(aSeq[j].Name ==
1038 rtl::OUString(
1039 RTL_CONSTASCII_USTRINGPARAM("FilterName")))
1041 aSeq[j].Value >>= aFilterName;
1042 break;
1047 if(aFilterName.getLength())
1049 uno::Reference<container::XNameAccess> xNameAccess(
1050 m_xFactory->createInstance(
1051 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1052 "com.sun.star.document.FilterFactory"))),
1053 uno::UNO_QUERY);
1054 try {
1055 if(xNameAccess.is() &&
1056 (xNameAccess->getByName(aFilterName) >>= aSeq))
1058 for(sal_Int32 j = 0; j < aSeq.getLength(); ++j)
1059 if(aSeq[j].Name ==
1060 rtl::OUString(
1061 RTL_CONSTASCII_USTRINGPARAM("UIName")))
1063 aSeq[j].Value >>= m_aFilterName;
1064 break;
1068 catch(const uno::Exception& ) {
1069 // nothing better to do here
1070 m_aFilterName = aFilterName;
1074 // set the title
1075 uno::Reference<beans::XPropertySet> xPropSet(
1076 m_xFrame,uno::UNO_QUERY);
1077 if(xPropSet.is()) {
1078 uno::Any aAny;
1079 static const sal_Unicode u[] = { ' ','(',0 };
1080 static const sal_Unicode c[] = { ')',0 };
1081 rtl::OUString aTotalName(m_aFilterName);
1082 aTotalName += rtl::OUString(u);
1083 aTotalName += aDocumentName;
1084 aTotalName += rtl::OUString(c);
1085 aAny <<= aTotalName;
1086 try {
1087 xPropSet->setPropertyValue(
1088 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")),
1089 aAny);
1091 catch( const uno::Exception& ) {
1096 m_aDocumentNamePart = aDocumentName;
1098 if(m_pInterceptor)
1100 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1102 Interceptor* pTmpInter = NULL;
1103 uno::Reference< frame::XDispatchProviderInterceptor > xLock( m_xInterceptorLocker );
1104 if ( xLock.is() && m_pInterceptor )
1105 pTmpInter = m_pInterceptor;
1107 aGuard.clear();
1109 if ( pTmpInter )
1110 pTmpInter->generateFeatureStateEvent();
1115 void DocumentHolder::setContainerName(const rtl::OUString& aContainerName)
1117 m_aContainerName = aContainerName;
1121 void DocumentHolder::hide()
1123 if(m_xFrame.is()) m_xFrame->deactivate();
1125 //todo: sendadvise
1126 // after hiding the window it is always allowed to InPlaceActivate it
1127 m_bAllowInPlace = true;
1130 IDispatch* DocumentHolder::GetIDispatch()
1132 if ( !m_pIDispatch && m_xDocument.is() )
1134 const ::rtl::OUString aServiceName (
1135 RTL_CONSTASCII_USTRINGPARAM (
1136 "com.sun.star.bridge.OleBridgeSupplier2" ) );
1137 uno::Reference< bridge::XBridgeSupplier2 > xSupplier(
1138 m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
1140 if ( xSupplier.is() )
1142 uno::Sequence< sal_Int8 > aProcId( 16 );
1143 rtl_getGlobalProcessId( (sal_uInt8*)aProcId.getArray() );
1145 try {
1146 uno::Any anyResult = xSupplier->createBridge(
1147 uno::makeAny( m_xDocument ),
1148 aProcId,
1149 bridge::ModelDependent::UNO,
1150 bridge::ModelDependent::OLE );
1152 if ( anyResult.getValueTypeClass() ==
1153 getCppuType((sal_uInt32*) 0).getTypeClass() )
1155 VARIANT* pVariant = *(VARIANT**)anyResult.getValue();
1156 if ( pVariant->vt == VT_DISPATCH )
1157 m_pIDispatch = pVariant->pdispVal;
1159 VariantClear( pVariant );
1160 CoTaskMemFree( pVariant );
1163 catch ( uno::Exception& )
1168 return m_pIDispatch;
1171 #if 0
1172 HRESULT DocumentHolder::SetVisArea( const RECTL *pRect )
1174 if ( pRect && m_xDocument.is() )
1176 uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs();
1177 for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ )
1178 if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) )
1180 // should allways be there
1181 uno::Sequence< sal_Int32 > aRect(4);
1183 aRect[0] = pRect->left;
1184 aRect[1] = pRect->top;
1185 aRect[2] = pRect->right;
1186 aRect[3] = pRect->bottom;
1188 aArgs[nInd].Value <<= aRect;
1190 m_xDocument->attachResource( m_xDocument->getURL(), aArgs );
1191 return S_OK;
1194 OSL_ENSURE( sal_False, "WinExtent seems not to be implemented!\n" );
1197 return E_FAIL;
1200 HRESULT DocumentHolder::GetVisArea( RECTL *pRect )
1202 if ( pRect && m_xDocument.is() )
1204 uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs();
1205 for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ )
1206 if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) )
1208 uno::Sequence< sal_Int32 > aRect;
1209 if ( ( aArgs[nInd].Value >>= aRect ) && aRect.getLength() == 4 )
1211 pRect->left = aRect[0];
1212 pRect->top = aRect[1];
1213 pRect->right = aRect[2];
1214 pRect->bottom = aRect[3];
1216 return S_OK;
1219 break;
1223 return E_FAIL;
1225 #endif
1227 HRESULT DocumentHolder::GetDocumentBorder( RECT *pRect )
1229 if ( pRect && m_xDocument.is() )
1231 uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs();
1232 for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ )
1233 if ( aArgs[nInd].Name.equalsAscii( "DocumentBorder" ) )
1235 uno::Sequence< sal_Int32 > aRect;
1236 if ( ( aArgs[nInd].Value >>= aRect ) && aRect.getLength() == 4 )
1238 pRect->left = aRect[0];
1239 pRect->top = aRect[1];
1240 pRect->right = aRect[2];
1241 pRect->bottom = aRect[3];
1243 return S_OK;
1246 break;
1250 return E_FAIL;
1253 HRESULT DocumentHolder::SetExtent( const SIZEL *pSize )
1255 if ( pSize )
1257 uno::Reference< embed::XVisualObject > xVisObj( m_xDocument, uno::UNO_QUERY );
1258 if ( xVisObj.is() )
1262 awt::Size aNewSize( pSize->cx, pSize->cy );
1264 sal_Int32 aMapMode = xVisObj->getMapUnit( DVASPECT_CONTENT );
1266 // TODO/LATER: in future UNO API should be used for the conversion, currently there is no
1267 if ( aMapMode == embed::EmbedMapUnits::TWIP )
1269 // convertion from ONE_100TH_MM
1270 aNewSize.Width = aNewSize.Width * 144 / 254;
1271 aNewSize.Height = aNewSize.Height * 144 / 254;
1275 xVisObj->setVisualAreaSize( DVASPECT_CONTENT, aNewSize );
1277 return S_OK;
1279 catch( uno::Exception& )
1284 return E_FAIL;
1287 HRESULT DocumentHolder::GetExtent( SIZEL *pSize )
1289 if ( pSize )
1291 uno::Reference< embed::XVisualObject > xVisObj( m_xDocument, uno::UNO_QUERY );
1292 if ( xVisObj.is() )
1296 awt::Size aDocSize = xVisObj->getVisualAreaSize( DVASPECT_CONTENT );
1298 sal_Int32 aMapMode = xVisObj->getMapUnit( DVASPECT_CONTENT );
1300 // TODO/LATER: in future UNO API should be used for the conversion, currently there is no
1301 if ( aMapMode == embed::EmbedMapUnits::TWIP )
1303 // convertion to ONE_100TH_MM
1304 aDocSize.Width = aDocSize.Width * 254 / 144;
1305 aDocSize.Height = aDocSize.Height * 254 / 144;
1308 pSize->cx = aDocSize.Width;
1309 pSize->cy = aDocSize.Height;
1311 return S_OK;
1313 catch( uno::Exception& )
1318 return E_FAIL;
1322 HRESULT DocumentHolder::SetContRects(LPCRECT aRect)
1324 if(m_xContainerWindow.is()) {
1325 RECT wi;
1326 memset(&wi,0,sizeof(wi));
1327 if(m_pIOleIPFrame) {
1328 m_pIOleIPFrame->GetBorder((LPRECT)&wi);
1329 m_xContainerWindow->setPosSize(
1330 0,0,
1331 wi.right - wi.left,
1332 wi.bottom - wi.top,
1333 awt::PosSize::POSSIZE);
1335 else
1336 m_xContainerWindow->setPosSize(
1337 0,0,
1338 aRect->right - aRect->left,
1339 aRect->bottom - aRect->top,
1340 awt::PosSize::POSSIZE);
1341 return NOERROR;
1343 else {
1344 return ERROR;
1349 HRESULT DocumentHolder::SetObjectRects(LPCRECT aRect, LPCRECT aClip)
1351 ((LPRECT)aRect)->left -= m_aBorder.left;
1352 ((LPRECT)aRect)->right += m_aBorder.right;
1353 ((LPRECT)aRect)->top -= m_aBorder.top;
1354 ((LPRECT)aRect)->bottom += m_aBorder.bottom;
1355 ((LPRECT)aClip)->left -= m_aBorder.left;
1356 ((LPRECT)aClip)->right += m_aBorder.right;
1357 ((LPRECT)aClip)->top -= m_aBorder.top;
1358 ((LPRECT)aClip)->bottom += m_aBorder.bottom;
1360 if(m_pCHatchWin)
1361 m_pCHatchWin->RectsSet((LPRECT)aRect, (LPRECT)aClip);
1362 if(m_xEditWindow.is()) {
1363 m_xEditWindow->setVisible(false);
1364 m_xEditWindow->setPosSize(
1365 m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
1366 m_pCHatchWin ? HATCHWIN_BORDERWIDTHDEFAULT : 0,
1367 aRect->right - aRect->left,
1368 aRect->bottom - aRect->top,
1369 awt::PosSize::POSSIZE);
1370 m_xEditWindow->setVisible(true);
1372 return NOERROR;
1376 ::com::sun::star::uno::Reference<
1377 ::com::sun::star::awt::XWindow> SAL_CALL
1378 DocumentHolder::getContainerWindow(
1380 throw (
1381 ::com::sun::star::uno::RuntimeException
1384 if(m_xContainerWindow.is())
1385 return m_xContainerWindow;
1387 uno::Reference<awt::XWindow> xWin(0);
1389 static const ::rtl::OUString aToolkitServiceName(
1390 RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.awt.Toolkit" ) );
1391 uno::Reference<awt::XSystemChildFactory> xToolkit(
1392 m_xFactory->createInstance(aToolkitServiceName ),uno::UNO_QUERY);
1394 if(xToolkit.is() && m_pIOleIPFrame) {
1395 HWND hWnd;
1396 m_pIOleIPFrame->GetWindow(&hWnd);
1398 uno::Sequence<sal_Int8> aProcessIdent(16);
1399 rtl_getGlobalProcessId((sal_uInt8*)aProcessIdent.getArray());
1401 uno::Any aAny;
1402 aAny <<= sal_Int32(hWnd);
1403 xWin = uno::Reference<awt::XWindow>(
1404 xToolkit->createSystemChild(
1405 aAny,
1406 aProcessIdent,
1407 lang::SystemDependent::SYSTEM_WIN32),
1408 uno::UNO_QUERY);
1410 RECT wi;
1411 memset(&wi,0,sizeof(wi));
1412 if(xWin.is() && m_pIOleIPFrame->GetBorder((LPRECT)&wi) == NOERROR) {
1413 xWin->setVisible(true);
1414 xWin->setPosSize(
1415 0,0,
1416 wi.right-wi.left,
1417 wi.bottom - wi.top,
1418 awt::PosSize::POSSIZE);
1420 uno::Reference<awt::XSystemDependentWindowPeer> xSysWin(
1421 xWin,uno::UNO_QUERY);
1422 if(xSysWin.is()) {
1423 aAny = xSysWin->getWindowHandle(
1424 aProcessIdent,lang::SystemDependent::SYSTEM_WIN32);
1425 sal_Int32 tmp;
1426 if( aAny >>= tmp )
1427 SetContainerWindowHandle((HWND) tmp);
1432 m_xContainerWindow= xWin;
1433 return xWin;
1438 sal_Bool SAL_CALL
1439 DocumentHolder::requestDockingAreaSpace(
1440 const ::com::sun::star::awt::Rectangle& RequestedSpace
1442 throw(
1443 ::com::sun::star::uno::RuntimeException
1446 if(m_bOnDeactivate)
1447 return sal_True;
1449 BORDERWIDTHS bw;
1450 SetRect((LPRECT)&bw,
1451 RequestedSpace.X,RequestedSpace.Y,
1452 RequestedSpace.Width,RequestedSpace.Height);
1453 if( m_pIOleIPFrame )
1454 return m_pIOleIPFrame->RequestBorderSpace(&bw) == NOERROR ;
1455 else
1456 return sal_Bool(false);
1460 void SAL_CALL
1461 DocumentHolder::setDockingAreaSpace(
1462 const ::com::sun::star::awt::Rectangle& BorderSpace
1464 throw (
1465 ::com::sun::star::uno::RuntimeException
1468 if(m_bOnDeactivate)
1469 return;
1471 BORDERWIDTHS bw;
1472 SetRect((LPRECT)&bw,
1473 BorderSpace.X,BorderSpace.Y,
1474 BorderSpace.Width,BorderSpace.Height);
1475 if( m_pIOleIPFrame ) {
1476 RECT aRect;
1477 GetClientRect(m_hWndxWinCont,&aRect);
1478 HRGN hrgn1 = CreateRectRgn(
1479 0,0,
1480 aRect.right,BorderSpace.Y);
1481 HRGN hrgn2 = CreateRectRgn(aRect.right-BorderSpace.Width,0,aRect.right,aRect.bottom);
1482 CombineRgn(hrgn1,hrgn1,hrgn2,RGN_OR);
1483 DeleteObject(hrgn2);
1484 hrgn2 = CreateRectRgn(0,aRect.bottom-BorderSpace.Height,aRect.right,aRect.bottom);
1485 CombineRgn(hrgn1,hrgn1,hrgn2,RGN_OR);
1486 DeleteObject(hrgn2);
1487 hrgn2 = CreateRectRgn(0,0,BorderSpace.X,aRect.bottom);
1488 CombineRgn(hrgn1,hrgn1,hrgn2,RGN_OR);
1489 DeleteObject(hrgn2);
1491 SetWindowRgn(m_hWndxWinCont,hrgn1,true);
1492 // not:: DeleteObject(hrgn1);
1493 m_pIOleIPFrame->SetBorderSpace(&bw);
1498 void SAL_CALL
1499 DocumentHolder::disposing(
1500 const com::sun::star::lang::EventObject& aSource
1502 throw( uno::RuntimeException )
1504 if ( m_xDocument.is() && m_xDocument == aSource.Source )
1506 m_pIDispatch = NULL;
1507 m_xDocument = uno::Reference< frame::XModel >();
1510 if( m_xFrame.is() && m_xFrame == aSource.Source )
1511 m_xFrame = uno::Reference< frame::XFrame >();
1515 void SAL_CALL
1516 DocumentHolder::queryClosing(
1517 const lang::EventObject& aSource,
1518 sal_Bool /*bGetsOwnership*/
1520 throw(
1521 util::CloseVetoException
1524 if ( !m_bLink
1525 && ( m_xDocument.is() && m_xDocument == aSource.Source || m_xFrame.is() && m_xFrame == aSource.Source ) )
1526 throw util::CloseVetoException();
1530 void SAL_CALL
1531 DocumentHolder::notifyClosing(
1532 const lang::EventObject& aSource )
1533 throw( uno::RuntimeException )
1537 uno::Reference< util::XCloseBroadcaster > xEventBroadcaster(
1538 aSource.Source, uno::UNO_QUERY_THROW );
1539 xEventBroadcaster->removeCloseListener( (util::XCloseListener*)this );
1541 catch( uno::Exception& )
1544 if ( m_xDocument.is() && m_xDocument == aSource.Source )
1546 // can happen only in case of links
1547 m_pIDispatch = NULL;
1548 m_xDocument = uno::Reference< frame::XModel >();
1549 m_xFrame = uno::Reference< frame::XFrame >();
1551 LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
1552 if ( aDocLock.GetEmbedDocument() )
1553 aDocLock.GetEmbedDocument()->OLENotifyClosing();
1555 else if( m_xFrame.is() && m_xFrame == aSource.Source )
1556 m_xFrame = uno::Reference< frame::XFrame >();
1559 void SAL_CALL
1560 DocumentHolder::queryTermination(
1561 const lang::EventObject& /*aSource*/
1563 throw(
1564 frame::TerminationVetoException
1567 if ( m_xDocument.is() )
1568 throw frame::TerminationVetoException();
1571 void SAL_CALL
1572 DocumentHolder::notifyTermination(
1573 const lang::EventObject& aSource
1575 throw( uno::RuntimeException )
1577 OSL_ENSURE( !m_xDocument.is(), "Just a disaster..." );
1578 uno::Reference< frame::XDesktop > xDesktop(
1579 aSource.Source, uno::UNO_QUERY );
1581 if ( xDesktop.is() )
1582 xDesktop->removeTerminateListener( (frame::XTerminateListener*)this );
1587 void SAL_CALL DocumentHolder::modified( const lang::EventObject& /*aEvent*/ )
1588 throw (uno::RuntimeException)
1590 if ( m_xOleAccess.is() )
1592 LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
1593 if ( aDocLock.GetEmbedDocument() )
1594 aDocLock.GetEmbedDocument()->notify();
1600 // if(m_pOLEInterface->GetGUID() == OID_WriterTextServer) {
1601 // // edit group
1602 // CopyToOLEMenu(m_nMenuHandle,1,hMenu,(WORD)mgw.width[0]);
1603 // CopyToOLEMenu(m_nMenuHandle,2,hMenu,1+(WORD)mgw.width[0]);
1604 // CopyToOLEMenu(m_nMenuHandle,3,hMenu,2+(WORD)mgw.width[0]);
1605 // CopyToOLEMenu(m_nMenuHandle,4,hMenu,3+(WORD)mgw.width[0]);
1606 // mgw.width[1]=4;
1608 // // object group
1609 // CopyToOLEMenu(
1610 // m_nMenuHandle,5,
1611 // hMenu,4+(WORD)mgw.width[0]+(WORD)mgw.width[2]);
1612 // mgw.width[3]=1;
1614 // // help group
1615 // CopyToOLEMenu(
1616 // m_nMenuHandle,7,
1617 // hMenu,5+(WORD)mgw.width[0]+(WORD)mgw.width[2]+(WORD)mgw.width[4]);
1618 // mgw.width[5]=1;
1619 // }
1620 // else if(m_pOLEInterface->GetGUID() == OID_CalcServer) {
1621 // // edit group
1622 // CopyToOLEMenu(m_nMenuHandle,1,hMenu,(WORD)mgw.width[0]);
1623 // CopyToOLEMenu(m_nMenuHandle,2,hMenu,1+(WORD)mgw.width[0]);
1624 // CopyToOLEMenu(m_nMenuHandle,3,hMenu,2+(WORD)mgw.width[0]);
1625 // CopyToOLEMenu(m_nMenuHandle,4,hMenu,3+(WORD)mgw.width[0]);
1626 // mgw.width[1]=4;
1628 // // object group
1629 // CopyToOLEMenu(
1630 // m_nMenuHandle,5,
1631 // hMenu,4+(WORD)mgw.width[0]+(WORD)mgw.width[2]);
1632 // CopyToOLEMenu(
1633 // m_nMenuHandle,6,
1634 // hMenu,5+(WORD)mgw.width[0]+(WORD)mgw.width[2]);
1635 // mgw.width[3]=2;
1637 // // help group
1638 // CopyToOLEMenu(
1639 // m_nMenuHandle,8,
1640 // hMenu,6+(WORD)mgw.width[0]+(WORD)mgw.width[2]+(WORD)mgw.width[4]);
1641 // mgw.width[5]=1;
1642 // }
1644 // Fix strange warnings about some
1645 // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
1646 // warning C4505: 'xxx' : unreferenced local function has been removed
1647 #if defined(_MSC_VER)
1648 #pragma warning(disable: 4505)
1649 #endif