LCOV - code coverage report
Current view: top level - libreoffice/embeddedobj/source/general - docholder.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 121 592 20.4 %
Date: 2012-12-17 Functions: 15 41 36.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10