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

Generated by: LCOV version 1.10