LCOV - code coverage report
Current view: top level - embeddedobj/source/general - docholder.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 396 588 67.3 %
Date: 2015-06-13 12:38:46 Functions: 32 41 78.0 %
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           1 :     IntCounterGuard( sal_Int32& nFlag )
      87           1 :     : m_nFlag( nFlag )
      88             :     {
      89           1 :         m_nFlag++;
      90           1 :     }
      91             : 
      92           1 :     ~IntCounterGuard()
      93             :     {
      94           1 :         if ( m_nFlag )
      95           1 :             m_nFlag--;
      96           1 :     }
      97             : };
      98             : 
      99             : 
     100             : 
     101           8 : 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           8 :     sal_Int32 nInd = 0;
     109           8 :     OUString aModuleIdentPropName( "ModuleIdentifier" );
     110          16 :     OUString aDispProvPropName( "DispatchProvider" );
     111           8 :     bool bModuleNameSet = false;
     112           8 :     bool bDispProvSet = false;
     113             : 
     114          16 :     uno::Sequence< beans::PropertyValue > aSourceProps;
     115           8 :     xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps;
     116          16 :     uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() );
     117          56 :     for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ )
     118             :     {
     119          48 :         aTargetProps[nInd].Name = aSourceProps[nInd].Name;
     120          48 :         if ( !aContModuleName.isEmpty() && aTargetProps[nInd].Name.equals( aModuleIdentPropName ) )
     121             :         {
     122           0 :             aTargetProps[nInd].Value <<= aContModuleName;
     123           0 :             bModuleNameSet = true;
     124             :         }
     125          48 :         else if ( aTargetProps[nInd].Name.equals( aDispProvPropName ) )
     126             :         {
     127           0 :             aTargetProps[nInd].Value <<= xSourceDisp;
     128           0 :             bDispProvSet = true;
     129             :         }
     130             :         else
     131          48 :             aTargetProps[nInd].Value = aSourceProps[nInd].Value;
     132             :     }
     133             : 
     134           8 :     if ( !bModuleNameSet && !aContModuleName.isEmpty() )
     135             :     {
     136           2 :         aTargetProps.realloc( ++nInd );
     137           2 :         aTargetProps[nInd-1].Name = aModuleIdentPropName;
     138           2 :         aTargetProps[nInd-1].Value <<= aContModuleName;
     139             :     }
     140             : 
     141           8 :     if ( !bDispProvSet && xSourceDisp.is() )
     142             :     {
     143           8 :         aTargetProps.realloc( ++nInd );
     144           8 :         aTargetProps[nInd-1].Name = aDispProvPropName;
     145           8 :         aTargetProps[nInd-1].Value <<= xSourceDisp;
     146             :     }
     147             : 
     148          16 :     xTargetMenu->insertByIndex( nTargetIndex, uno::makeAny( aTargetProps ) );
     149           8 : }
     150             : 
     151             : 
     152         578 : 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         578 :   m_nNoResizeReact( 0 )
     163             : {
     164         578 :     m_aOutplaceFrameProps.realloc( 3 );
     165         578 :     beans::NamedValue aArg;
     166             : 
     167         578 :     aArg.Name = "TopWindow";
     168         578 :     aArg.Value <<= sal_True;
     169         578 :     m_aOutplaceFrameProps[0] <<= aArg;
     170             : 
     171         578 :     aArg.Name = "MakeVisible";
     172         578 :     aArg.Value <<= sal_False;
     173         578 :     m_aOutplaceFrameProps[1] <<= aArg;
     174             : 
     175        1156 :     uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
     176         578 :     m_refCount++;
     177             :     try
     178             :     {
     179         578 :         xDesktop->addTerminateListener( this );
     180             :     }
     181           0 :     catch ( const uno::Exception& )
     182             :     {
     183             :     }
     184         578 :     m_refCount--;
     185             : 
     186         578 :     aArg.Name = "ParentFrame";
     187         578 :     aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame
     188        1156 :     m_aOutplaceFrameProps[2] <<= aArg;
     189         578 : }
     190             : 
     191             : 
     192        1734 : DocumentHolder::~DocumentHolder()
     193             : {
     194         578 :     m_refCount++; // to allow deregistration as a listener
     195             : 
     196         578 :     if( m_xFrame.is() )
     197           0 :         CloseFrame();
     198             : 
     199         578 :     if ( m_xComponent.is() )
     200             :     {
     201             :         try {
     202           0 :             CloseDocument( true, false );
     203           0 :         } catch( const uno::Exception& ) {}
     204             :     }
     205             : 
     206         578 :     if ( m_pInterceptor )
     207             :     {
     208           0 :         m_pInterceptor->DisconnectDocHolder();
     209           0 :         m_pInterceptor->release();
     210             :     }
     211             : 
     212         578 :     if ( !m_bDesktopTerminated )
     213         578 :         FreeOffice();
     214        1156 : }
     215             : 
     216             : 
     217         579 : void DocumentHolder::CloseFrame()
     218             : {
     219         579 :     uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
     220         579 :     if ( xCloseBroadcaster.is() )
     221           1 :         xCloseBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) );
     222             : 
     223             :     uno::Reference<util::XCloseable> xCloseable(
     224        1158 :         m_xFrame,uno::UNO_QUERY );
     225         579 :     if( xCloseable.is() )
     226             :         try {
     227           1 :             xCloseable->close( sal_True );
     228             :         }
     229           0 :         catch( const uno::Exception& ) {
     230             :         }
     231             :     else {
     232         578 :         uno::Reference<lang::XComponent> xComp( m_xFrame,uno::UNO_QUERY );
     233         578 :         if( xComp.is() )
     234           0 :             xComp->dispose();
     235             :     }
     236             : 
     237        1158 :     uno::Reference< lang::XComponent > xComp( m_xHatchWindow, uno::UNO_QUERY );
     238         579 :     if ( xComp.is() )
     239           1 :         xComp->dispose();
     240             : 
     241         579 :     m_xHatchWindow = uno::Reference< awt::XWindow >();
     242         579 :     m_xOwnWindow = uno::Reference< awt::XWindow >();
     243        1158 :     m_xFrame = uno::Reference< frame::XFrame >();
     244         579 : }
     245             : 
     246             : 
     247        1174 : void DocumentHolder::FreeOffice()
     248             : {
     249        1174 :     uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
     250        1174 :     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        1174 : }
     271             : 
     272             : 
     273        1157 : void DocumentHolder::CloseDocument( bool bDeliverOwnership, bool bWaitForClose )
     274             : {
     275        1157 :     uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
     276        1157 :     if ( xBroadcaster.is() )
     277             :     {
     278         597 :         uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
     279         597 :         if ( xEventBroadcaster.is() )
     280         292 :             xEventBroadcaster->removeEventListener( static_cast<document::XEventListener*>(this) );
     281             :         else
     282             :         {
     283             :             // the object does not support document::XEventBroadcaster interface
     284             :             // use the workaround, register for modified events
     285         305 :             uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
     286         305 :             if ( xModifyBroadcaster.is() )
     287         304 :                 xModifyBroadcaster->removeModifyListener( static_cast<util::XModifyListener*>(this) );
     288             :         }
     289             : 
     290        1194 :         uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY );
     291         597 :         if ( xCloseable.is() )
     292             :         {
     293         597 :             m_bAllowClosing = true;
     294         597 :             m_bWaitForClose = bWaitForClose;
     295         597 :             xCloseable->close( bDeliverOwnership );
     296         597 :         }
     297             :     }
     298             : 
     299        1157 :     m_xComponent = 0;
     300        1157 : }
     301             : 
     302             : 
     303           1 : 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           1 :     if ( m_xFrame.is() && m_xOwnWindow.is() )
     310             :     {
     311             :         // the frame can be replaced only in inplace mode
     312           1 :         frame::BorderWidths aOldWidths;
     313           1 :         IntCounterGuard aGuard( m_nNoBorderResizeReact );
     314             : 
     315           1 :         do
     316             :         {
     317           1 :             aOldWidths = m_aBorderWidths;
     318             : 
     319           1 :             awt::Rectangle aHatchRect = AddBorderToArea( aNewRect );
     320             : 
     321           1 :             ResizeWindows_Impl( aHatchRect );
     322             : 
     323           1 :         } while ( aOldWidths.Left != m_aBorderWidths.Left
     324           1 :                || aOldWidths.Top != m_aBorderWidths.Top
     325           1 :                || aOldWidths.Right != m_aBorderWidths.Right
     326           1 :                || aOldWidths.Bottom != m_aBorderWidths.Bottom );
     327             : 
     328           1 :         m_aObjRect = aNewRect;
     329             :     }
     330           1 : }
     331             : 
     332             : 
     333           3 : 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           3 :     if ( m_xHatchWindow.is() )
     338             :     {
     339           6 :         m_xOwnWindow->setPosSize( HATCH_BORDER_WIDTH,
     340           3 :                                   HATCH_BORDER_WIDTH,
     341           3 :                                   aHatchRect.Width - 2*HATCH_BORDER_WIDTH,
     342           3 :                                   aHatchRect.Height - 2*HATCH_BORDER_WIDTH,
     343          15 :                                   awt::PosSize::POSSIZE );
     344             : 
     345             : 
     346           3 :         m_xHatchWindow->setPosSize( aHatchRect.X,
     347             :                                     aHatchRect.Y,
     348             :                                     aHatchRect.Width,
     349             :                                     aHatchRect.Height,
     350           3 :                                     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           3 : }
     359             : 
     360             : 
     361           1 : bool DocumentHolder::SetFrameLMVisibility( const uno::Reference< frame::XFrame >& xFrame, bool bVisible )
     362             : {
     363           1 :     bool bResult = false;
     364             : 
     365             :     try
     366             :     {
     367           1 :         uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
     368           2 :         uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY_THROW );
     369           1 :         xPropSet->getPropertyValue("LayoutManager") >>= xLayoutManager;
     370           1 :         if ( xLayoutManager.is() )
     371             :         {
     372           1 :             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           1 :             if ( bVisible )
     377           0 :                 xLayoutManager->unlock();
     378             :             else
     379           1 :                 xLayoutManager->lock();
     380             : 
     381           1 :             bResult = true;
     382           1 :         }
     383             :     }
     384           0 :     catch( const uno::Exception& )
     385             :     {}
     386             : 
     387           1 :     return bResult;
     388             : }
     389             : 
     390             : 
     391           1 : 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           1 :     if ( !m_xFrame.is() )
     398             :     {
     399           1 :         uno::Reference < frame::XModel > xModel( GetComponent(), uno::UNO_QUERY );
     400           1 :         awt::Rectangle aHatchRectangle = AddBorderToArea( aRectangleToShow );
     401             : 
     402           1 :         awt::Rectangle aOwnRectangle(  HATCH_BORDER_WIDTH,
     403           1 :                                     HATCH_BORDER_WIDTH,
     404           1 :                                     aHatchRectangle.Width - 2*HATCH_BORDER_WIDTH,
     405           4 :                                     aHatchRectangle.Height - 2*HATCH_BORDER_WIDTH );
     406           2 :         uno::Reference< awt::XWindow > xHWindow;
     407           2 :         uno::Reference< awt::XWindowPeer > xMyParent( xParent );
     408             : 
     409           1 :         if ( xModel.is() )
     410             :         {
     411             : 
     412             :             uno::Reference< embed::XHatchWindowFactory > xHatchFactory =
     413           1 :                     embed::HatchWindowFactory::create(m_xContext);
     414             : 
     415             :             uno::Reference< embed::XHatchWindow > xHatchWindow =
     416           1 :                             xHatchFactory->createHatchWindowInstance( xParent,
     417             :                                                                       aHatchRectangle,
     418           2 :                                                                       awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
     419             : 
     420           2 :             uno::Reference< awt::XWindowPeer > xHatchWinPeer( xHatchWindow, uno::UNO_QUERY );
     421           1 :             xHWindow = uno::Reference< awt::XWindow >( xHatchWinPeer, uno::UNO_QUERY );
     422           1 :             if ( !xHWindow.is() )
     423           0 :                 throw uno::RuntimeException(); // TODO: can not create own window
     424             : 
     425           1 :             xHatchWindow->setController( uno::Reference< embed::XHatchWindowController >(
     426           1 :                                                 static_cast< embed::XHatchWindowController* >( this ) ) );
     427             : 
     428           2 :             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           2 :                                                 awt::WindowAttribute::SHOW | awt::VclWindowPeerAttribute::CLIPCHILDREN );
     442             : 
     443           2 :         uno::Reference< awt::XToolkit2 > xToolkit = awt::Toolkit::create(m_xContext);
     444             : 
     445           2 :         uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor );
     446           2 :         uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY );
     447           1 :         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           2 :         uno::Reference< lang::XSingleServiceFactory > xFrameFact = frame::TaskCreator::create(m_xContext);
     452             : 
     453           2 :         uno::Sequence< uno::Any > aArgs( 2 );
     454           2 :         beans::NamedValue aArg;
     455             : 
     456           1 :         aArg.Name    = "ContainerWindow";
     457           1 :         aArg.Value <<= xOwnWindow;
     458           1 :         aArgs[0] <<= aArg;
     459             : 
     460           2 :         uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
     461           1 :         if ( xContFrame.is() )
     462             :         {
     463           1 :             aArg.Name    = "ParentFrame";
     464           1 :             aArg.Value <<= xContFrame;
     465           1 :             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           1 :         m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW );
     472             : 
     473           1 :         m_xHatchWindow = xHWindow;
     474           1 :         m_xOwnWindow = xOwnWindow;
     475             : 
     476           1 :         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           2 :         uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY );
     485           1 :         if ( xCloseBroadcaster.is() )
     486           2 :             xCloseBroadcaster->addCloseListener( static_cast<util::XCloseListener*>(this) );
     487             : 
     488             :         // TODO: some listeners to the frame and the window ( resize for example )
     489             :     }
     490             : 
     491           1 :     if ( m_xComponent.is() )
     492             :     {
     493           1 :         if ( !LoadDocToFrame( true ) )
     494             :         {
     495           0 :             CloseFrame();
     496           0 :             return false;
     497             :         }
     498             : 
     499           1 :         uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
     500           1 :         if ( xControllerBorder.is() )
     501             :         {
     502           0 :             m_aBorderWidths = xControllerBorder->getBorder();
     503           0 :             xControllerBorder->addBorderResizeListener( static_cast<frame::XBorderResizeListener*>(this) );
     504             :         }
     505             : 
     506           1 :         PlaceFrame( aRectangleToShow );
     507             : 
     508           1 :         if ( m_xHatchWindow.is() )
     509           1 :             m_xHatchWindow->setVisible( sal_True );
     510             : 
     511           1 :         return true;
     512             :     }
     513             : 
     514           0 :     return false;
     515             : }
     516             : 
     517             : 
     518           1 : uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl()
     519             : {
     520           1 :     uno::Reference< container::XIndexAccess > xResult;
     521             : 
     522             :     uno::Reference< ::com::sun::star::ui::XUIConfigurationManagerSupplier > xUIConfSupplier(
     523             :                 m_xComponent,
     524           2 :                 uno::UNO_QUERY );
     525           2 :     uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xUIConfigManager;
     526           1 :     if( xUIConfSupplier.is())
     527             :     {
     528             :         xUIConfigManager.set(
     529           0 :             xUIConfSupplier->getUIConfigurationManager(),
     530           0 :             uno::UNO_QUERY_THROW );
     531             :     }
     532             : 
     533             :     try
     534             :     {
     535           1 :         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           1 :     if ( !xResult.is() )
     546             :     {
     547             :         // no internal document configuration, use the one from the module
     548           1 :         uno::Reference< frame::XModuleManager2 > xModuleMan = frame::ModuleManager::create(m_xContext);
     549             :         OUString aModuleIdent =
     550           2 :             xModuleMan->identify( uno::Reference< uno::XInterface >( m_xComponent, uno::UNO_QUERY ) );
     551             : 
     552           1 :         if ( !aModuleIdent.isEmpty() )
     553             :         {
     554             :             uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xModConfSupplier =
     555           1 :                     ui::theModuleUIConfigurationManagerSupplier::get(m_xContext);
     556             :             uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xModUIConfMan(
     557           1 :                     xModConfSupplier->getUIConfigurationManager( aModuleIdent ),
     558           2 :                     uno::UNO_QUERY_THROW );
     559           3 :             xResult = xModUIConfMan->getSettings(
     560             :                     OUString( "private:resource/menubar/menubar" ),
     561           3 :                     sal_False );
     562           1 :         }
     563             :     }
     564             : 
     565           1 :     if ( !xResult.is() )
     566           0 :         throw uno::RuntimeException();
     567             : 
     568           2 :     return xResult;
     569             : }
     570             : 
     571             : 
     572           2 : void DocumentHolder::FindConnectPoints(
     573             :         const uno::Reference< container::XIndexAccess >& xMenu,
     574             :         sal_Int32 nConnectPoints[2] )
     575             :     throw ( uno::Exception )
     576             : {
     577           2 :     nConnectPoints[0] = -1;
     578           2 :     nConnectPoints[1] = -1;
     579          19 :     for ( sal_Int32 nInd = 0; nInd < xMenu->getCount(); nInd++ )
     580             :     {
     581          17 :         uno::Sequence< beans::PropertyValue > aProps;
     582          17 :         xMenu->getByIndex( nInd ) >>= aProps;
     583          34 :         OUString aCommand;
     584          17 :         for ( sal_Int32 nSeqInd = 0; nSeqInd < aProps.getLength(); nSeqInd++ )
     585          17 :             if ( aProps[nSeqInd].Name == "CommandURL" )
     586             :             {
     587          17 :                 aProps[nSeqInd].Value >>= aCommand;
     588          17 :                 break;
     589             :             }
     590             : 
     591          17 :         if ( aCommand.isEmpty() )
     592           0 :             throw uno::RuntimeException();
     593             : 
     594          17 :         if ( aCommand == ".uno:PickList" )
     595           2 :             nConnectPoints[0] = nInd;
     596          15 :         else if ( aCommand == ".uno:WindowList" )
     597           2 :             nConnectPoints[1] = nInd;
     598          17 :     }
     599           2 : }
     600             : 
     601             : 
     602           1 : 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           1 :     uno::Reference< lang::XSingleComponentFactory > xIndAccessFact( xContMenu, uno::UNO_QUERY_THROW );
     616             : 
     617             :     uno::Reference< container::XIndexContainer > xMergedMenu(
     618           1 :             xIndAccessFact->createInstanceWithContext(
     619           1 :                 comphelper::getProcessComponentContext() ),
     620           2 :             uno::UNO_QUERY_THROW );
     621             : 
     622           1 :     FindConnectPoints( xContMenu, nContPoints );
     623           1 :     FindConnectPoints( xOwnMenu, nOwnPoints );
     624             : 
     625           9 :     for ( sal_Int32 nInd = 0; nInd < xOwnMenu->getCount(); nInd++ )
     626             :     {
     627           8 :         if ( nOwnPoints[0] == nInd )
     628             :         {
     629           1 :             if ( nContPoints[0] >= 0 && nContPoints[0] < xContMenu->getCount() )
     630             :             {
     631           1 :                 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[0], aContModuleName, xContDisp );
     632             :             }
     633             :         }
     634           7 :         else if ( nOwnPoints[1] == nInd )
     635             :         {
     636           1 :             if ( nContPoints[1] >= 0 && nContPoints[1] < xContMenu->getCount() )
     637             :             {
     638           1 :                 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[1], aContModuleName, xContDisp );
     639             :             }
     640             :         }
     641             :         else
     642           6 :             InsertMenu_Impl( xMergedMenu, nInd, xOwnMenu, nInd, OUString(), xOwnDisp );
     643             :     }
     644             : 
     645           2 :     return uno::Reference< container::XIndexAccess >( xMergedMenu, uno::UNO_QUERY_THROW );
     646             : }
     647             : 
     648             : 
     649           1 : 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           1 :     bool bMenuMerged = false;
     655             :     try
     656             :     {
     657             :         uno::Reference< ::com::sun::star::ui::XUIElementSettings > xUISettings(
     658           1 :             xContLM->getElement(
     659           1 :                 OUString( "private:resource/menubar/menubar" ) ),
     660           1 :             uno::UNO_QUERY_THROW );
     661           2 :         uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings( sal_True );
     662           1 :         if ( !xContMenu.is() )
     663           0 :             throw uno::RuntimeException();
     664             : 
     665           2 :         uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl();
     666           2 :         uno::Reference< frame::XDispatchProvider > xOwnDisp( m_xFrame, uno::UNO_QUERY_THROW );
     667             : 
     668           2 :         uno::Reference< container::XIndexAccess > xMergedMenu = MergeMenusForInplace( xContMenu, xContDisp, aContModuleName, xOwnMenu, xOwnDisp );
     669             :         uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM,
     670           2 :                                                                                          uno::UNO_QUERY_THROW );
     671           2 :         bMenuMerged = xMerge->setMergedMenuBar( xMergedMenu );
     672             :     }
     673           0 :     catch( const uno::Exception& )
     674             :     {}
     675             : 
     676           1 :     return bMenuMerged;
     677             : }
     678             : 
     679           1 : 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           1 :     bool bResult = false;
     684           1 :     if ( xContainerLM.is() )
     685             :     {
     686             :         // the LM of the embedded frame and its current DockingAreaAcceptor
     687           1 :            uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
     688           2 :            uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc;
     689             : 
     690             :         try
     691             :         {
     692           1 :             uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
     693           1 :             xPropSet->getPropertyValue("LayoutManager") >>= xOwnLM;
     694           1 :             xDocAreaAcc = xContainerLM->getDockingAreaAcceptor();
     695             :         }
     696           0 :         catch( const uno::Exception& ){}
     697             : 
     698           1 :         if ( xOwnLM.is() && xDocAreaAcc.is() )
     699             :         {
     700             :             // make sure that lock state of LM is correct even if an exception is thrown in between
     701           1 :             bool bUnlock = false;
     702           1 :             bool bLock = false;
     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           1 :                 xOwnLM->setDockingAreaAcceptor( xDocAreaAcc );
     708             : 
     709             :                 // try to merge menus; don't do anything else if it fails
     710           1 :                 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           1 :                     xContainerLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
     715             : 
     716             :                     // prevent further changes at this LM
     717           1 :                     xContainerLM->setVisible( sal_False );
     718           1 :                        xContainerLM->lock();
     719           1 :                     bUnlock = true;
     720             : 
     721             :                     // by unlocking the LM each layout change will now resize the containers window; pending layouts will be processed now
     722           1 :                     xOwnLM->setVisible( sal_True );
     723             : 
     724           1 :                     uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
     725           1 :                     if ( xSupp.is() )
     726           1 :                         xSupp->setActiveFrame( m_xFrame );
     727             : 
     728           1 :                     xOwnLM->unlock();
     729           1 :                     bLock = true;
     730           1 :                        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           1 :                     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           1 :         }
     770             :     }
     771             : 
     772           1 :     return bResult;
     773             : }
     774             : 
     775             : 
     776           1 : bool DocumentHolder::HideUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM )
     777             : {
     778           1 :     bool bResult = false;
     779             : 
     780           1 :     if ( xContainerLM.is() )
     781             :     {
     782           1 :            uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM;
     783             : 
     784             :         try {
     785           1 :             uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW );
     786           1 :             xPropSet->getPropertyValue("LayoutManager") >>= xOwnLM;
     787           0 :         } catch( const uno::Exception& )
     788             :         {}
     789             : 
     790           1 :         if ( xOwnLM.is() )
     791             :         {
     792             :             try {
     793           1 :                 uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY );
     794           1 :                 if ( xSupp.is() )
     795           1 :                     xSupp->setActiveFrame( 0 );
     796             : 
     797           2 :                 uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc = xOwnLM->getDockingAreaAcceptor();
     798             : 
     799           1 :                 xOwnLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
     800           1 :                 xOwnLM->lock();
     801           1 :                 xOwnLM->setVisible( sal_False );
     802             : 
     803           2 :                 uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
     804           1 :                 xMerge->removeMergedMenuBar();
     805             : 
     806           1 :                 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
     807           1 :                 xContainerLM->setVisible( sal_True );
     808           1 :                 xContainerLM->unlock();
     809             : 
     810           1 :                 xContainerLM->doLayout();
     811           2 :                 bResult = true;
     812             :             }
     813           0 :             catch( const uno::Exception& )
     814             :             {
     815           0 :                 SetFrameLMVisibility( m_xFrame, true );
     816             :             }
     817           1 :         }
     818             :     }
     819             : 
     820           1 :     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( static_cast<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         608 : void DocumentHolder::SetComponent( const uno::Reference< util::XCloseable >& xDoc, bool bReadOnly )
     921             : {
     922         608 :     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         608 :     m_xComponent = xDoc;
     932             : 
     933         608 :     m_bReadOnly = bReadOnly;
     934         608 :     m_bAllowClosing = false;
     935             : 
     936         608 :     uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY );
     937         608 :     if ( xBroadcaster.is() )
     938         597 :         xBroadcaster->addCloseListener( static_cast<util::XCloseListener*>(this) );
     939             : 
     940        1216 :     uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
     941         608 :     if ( xEventBroadcaster.is() )
     942         292 :         xEventBroadcaster->addEventListener( static_cast<document::XEventListener*>(this) );
     943             :     else
     944             :     {
     945             :         // the object does not support document::XEventBroadcaster interface
     946             :         // use the workaround, register for modified events
     947         316 :         uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
     948         316 :         if ( xModifyBroadcaster.is() )
     949         304 :             xModifyBroadcaster->addModifyListener( static_cast<util::XModifyListener*>(this) );
     950             :     }
     951             : 
     952         608 :     if ( m_xFrame.is() )
     953         608 :         LoadDocToFrame(false);
     954         608 : }
     955             : 
     956             : 
     957           1 : bool DocumentHolder::LoadDocToFrame( bool bInPlace )
     958             : {
     959           1 :     if ( m_xFrame.is() && m_xComponent.is() )
     960             :     {
     961           1 :         uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
     962           1 :         if ( xDoc.is() )
     963             :         {
     964             :             // load new document in to the frame
     965           1 :             uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY_THROW );
     966             : 
     967           2 :             ::comphelper::NamedValueCollection aArgs;
     968           1 :             aArgs.put( "Model", m_xComponent );
     969           1 :             aArgs.put( "ReadOnly", m_bReadOnly );
     970           1 :             if ( bInPlace )
     971           1 :                 aArgs.put( "PluginMode", sal_Int16(1) );
     972           2 :             OUString sUrl;
     973           2 :             uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
     974           3 :             if (    xServiceInfo.is()
     975           4 :                 &&  xServiceInfo->supportsService("com.sun.star.report.ReportDefinition") )
     976             :             {
     977           0 :                 sUrl = ".component:DB/ReportDesign";
     978             :             }
     979           3 :             else if( xServiceInfo.is()
     980           4 :                 &&   xServiceInfo->supportsService("com.sun.star.chart2.ChartDocument"))
     981           1 :                 sUrl = "private:factory/schart";
     982             :             else
     983           0 :                 sUrl = "private:object";
     984             : 
     985           1 :             xComponentLoader->loadComponentFromURL( sUrl,
     986             :                                                         OUString( "_self" ),
     987             :                                                         0,
     988           1 :                                                         aArgs.getPropertyValues() );
     989             : 
     990           2 :             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           1 :         }
    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         298 : bool DocumentHolder::SetExtent( sal_Int64 nAspect, const awt::Size& aSize )
    1021             : {
    1022         298 :     uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
    1023         298 :     if ( xDocVis.is() )
    1024             :     {
    1025             :         try
    1026             :         {
    1027         145 :             xDocVis->setVisualAreaSize( nAspect, aSize );
    1028         145 :             return true;
    1029             :         }
    1030           0 :         catch( const uno::Exception& )
    1031             :         {
    1032             :             // TODO: Error handling
    1033             :         }
    1034             :     }
    1035             : 
    1036         153 :     return false;
    1037             : }
    1038             : 
    1039             : 
    1040        1448 : bool DocumentHolder::GetExtent( sal_Int64 nAspect, awt::Size *pSize )
    1041             : {
    1042        1448 :     uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
    1043        1448 :     if ( pSize && xDocVis.is() )
    1044             :     {
    1045             :         try
    1046             :         {
    1047        1447 :             *pSize = xDocVis->getVisualAreaSize( nAspect );
    1048        1447 :             return true;
    1049             :         }
    1050           0 :         catch( const uno::Exception& )
    1051             :         {
    1052             :             // TODO: Error handling
    1053             :         }
    1054             :     }
    1055             : 
    1056           1 :     return false;
    1057             : }
    1058             : 
    1059             : 
    1060        1587 : sal_Int32 DocumentHolder::GetMapUnit( sal_Int64 nAspect )
    1061             : {
    1062        1587 :     uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
    1063        1587 :     if ( xDocVis.is() )
    1064             :     {
    1065             :         try
    1066             :         {
    1067        1511 :             return xDocVis->getMapUnit( nAspect );
    1068             :         }
    1069           0 :         catch( const uno::Exception& )
    1070             :         {
    1071             :             // TODO: Error handling
    1072             :         }
    1073             :     }
    1074             : 
    1075          76 :     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           4 : awt::Rectangle DocumentHolder::AddBorderToArea( const awt::Rectangle& aRect )
    1089             : {
    1090           4 :     return awt::Rectangle( aRect.X - m_aBorderWidths.Left - HATCH_BORDER_WIDTH,
    1091           4 :                              aRect.Y - m_aBorderWidths.Top - HATCH_BORDER_WIDTH,
    1092           4 :                              aRect.Width + m_aBorderWidths.Left + m_aBorderWidths.Right + 2*HATCH_BORDER_WIDTH,
    1093          16 :                              aRect.Height + m_aBorderWidths.Top + m_aBorderWidths.Bottom + 2*HATCH_BORDER_WIDTH );
    1094             : }
    1095             : 
    1096             : 
    1097         596 : void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource )
    1098             :         throw (uno::RuntimeException, std::exception)
    1099             : {
    1100         596 :     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         596 :     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         596 : }
    1117             : 
    1118             : 
    1119             : 
    1120         597 : void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool /*bGetsOwnership*/ )
    1121             :         throw (util::CloseVetoException, uno::RuntimeException, std::exception)
    1122             : {
    1123         597 :     if ( m_xComponent.is() && m_xComponent == aSource.Source && !m_bAllowClosing )
    1124           1 :         throw util::CloseVetoException();
    1125         596 : }
    1126             : 
    1127             : 
    1128         596 : void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
    1129             :         throw (uno::RuntimeException, std::exception)
    1130             : {
    1131         596 :     if ( m_xComponent.is() && m_xComponent == aSource.Source )
    1132             :     {
    1133         596 :         m_xComponent = 0;
    1134         596 :         if ( m_bWaitForClose )
    1135             :         {
    1136          18 :             m_bWaitForClose = false;
    1137          18 :             FreeOffice();
    1138             :         }
    1139             :     }
    1140             : 
    1141         596 :     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         596 : }
    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( static_cast<frame::XTerminateListener*>(this) );
    1167           0 : }
    1168             : 
    1169             : 
    1170         834 : 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         834 :     if( aEvent.Source == m_xComponent && m_pEmbedObj && m_pEmbedObj->getCurrentState() == embed::EmbedStates::RUNNING )
    1176         823 :         m_pEmbedObj->PostEvent_Impl( OUString( "OnVisAreaChanged" ) );
    1177         834 : }
    1178             : 
    1179             : 
    1180        5101 : void SAL_CALL DocumentHolder::notifyEvent( const document::EventObject& Event )
    1181             :     throw ( uno::RuntimeException, std::exception )
    1182             : {
    1183        5101 :     if( m_pEmbedObj && Event.Source == m_xComponent )
    1184             :     {
    1185             :         // for now the ignored events are not forwarded, but sent by the object itself
    1186        9998 :         if ( !Event.EventName.startsWith( "OnSave" )
    1187        4999 :           && !Event.EventName.startsWith( "OnSaveDone" )
    1188        4999 :           && !Event.EventName.startsWith( "OnSaveAs" )
    1189        4999 :           && !Event.EventName.startsWith( "OnSaveAsDone" )
    1190        9998 :           && !( Event.EventName.startsWith( "OnVisAreaChanged" ) && m_nNoResizeReact ) )
    1191        4999 :             m_pEmbedObj->PostEvent_Impl( Event.EventName );
    1192             :     }
    1193        5101 : }
    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           1 : void SAL_CALL DocumentHolder::activated(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
    1258             : {
    1259           4 :     if ( (m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) ||
    1260           4 :         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           1 : }
    1286             : 
    1287           2 : void DocumentHolder::ResizeHatchWindow()
    1288             : {
    1289           2 :     awt::Rectangle aHatchRect = AddBorderToArea( m_aObjRect );
    1290           2 :     ResizeWindows_Impl( aHatchRect );
    1291           2 :     uno::Reference< embed::XHatchWindow > xHatchWindow( m_xHatchWindow, uno::UNO_QUERY );
    1292           2 :     xHatchWindow->setHatchBorderSize( awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) );
    1293           2 : }
    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           0 : }
    1300             : 
    1301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11