LCOV - code coverage report
Current view: top level - sd/source/ui/toolpanel - ToolPanelFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 61 65.6 %
Date: 2012-08-25 Functions: 7 11 63.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 51 136 37.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4                 :            :  *
       5                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       6                 :            :  *
       7                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       8                 :            :  *
       9                 :            :  * This file is part of OpenOffice.org.
      10                 :            :  *
      11                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      12                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      13                 :            :  * only, as published by the Free Software Foundation.
      14                 :            :  *
      15                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU Lesser General Public License version 3 for more details
      19                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public License
      22                 :            :  * version 3 along with OpenOffice.org.  If not, see
      23                 :            :  * <http://www.openoffice.org/license.html>
      24                 :            :  * for a copy of the LGPLv3 License.
      25                 :            :  *
      26                 :            :  ************************************************************************/
      27                 :            : 
      28                 :            : 
      29                 :            : #include "taskpane/ToolPanelViewShell.hxx"
      30                 :            : #include "framework/FrameworkHelper.hxx"
      31                 :            : #include "PaneChildWindows.hxx"
      32                 :            : #include "ViewShellBase.hxx"
      33                 :            : #include "app.hrc"
      34                 :            : 
      35                 :            : #include <com/sun/star/ui/XUIElementFactory.hpp>
      36                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      37                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      38                 :            : #include <com/sun/star/uno/XComponentContext.hpp>
      39                 :            : #include <com/sun/star/frame/XFrame.hpp>
      40                 :            : #include <com/sun/star/awt/XWindow.hpp>
      41                 :            : 
      42                 :            : #include <sfx2/frame.hxx>
      43                 :            : #include <vcl/svapp.hxx>
      44                 :            : #include <osl/mutex.hxx>
      45                 :            : #include <sfx2/viewfrm.hxx>
      46                 :            : #include <cppuhelper/implbase3.hxx>
      47                 :            : #include <comphelper/namedvaluecollection.hxx>
      48                 :            : #include <toolkit/helper/vclunohelper.hxx>
      49                 :            : 
      50                 :            : //......................................................................................................................
      51                 :            : namespace sd { namespace toolpanel
      52                 :            : {
      53                 :            : //......................................................................................................................
      54                 :            : 
      55                 :            :     /** === begin UNO using === **/
      56                 :            :     using ::com::sun::star::uno::Reference;
      57                 :            :     using ::com::sun::star::uno::XInterface;
      58                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      59                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      60                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      61                 :            :     using ::com::sun::star::uno::Exception;
      62                 :            :     using ::com::sun::star::uno::RuntimeException;
      63                 :            :     using ::com::sun::star::uno::Any;
      64                 :            :     using ::com::sun::star::uno::makeAny;
      65                 :            :     using ::com::sun::star::uno::Sequence;
      66                 :            :     using ::com::sun::star::uno::Type;
      67                 :            :     using ::com::sun::star::uno::XComponentContext;
      68                 :            :     using ::com::sun::star::ui::XUIElementFactory;
      69                 :            :     using ::com::sun::star::ui::XUIElement;
      70                 :            :     using ::com::sun::star::beans::PropertyValue;
      71                 :            :     using ::com::sun::star::container::NoSuchElementException;
      72                 :            :     using ::com::sun::star::lang::IllegalArgumentException;
      73                 :            :     using ::com::sun::star::lang::XServiceInfo;
      74                 :            :     using ::com::sun::star::lang::XInitialization;
      75                 :            :     using ::com::sun::star::frame::XFrame;
      76                 :            :     using ::com::sun::star::awt::XWindow;
      77                 :            :     /** === end UNO using === **/
      78                 :            : 
      79                 :            :     //==================================================================================================================
      80                 :            :     //= ToolPanelFactory
      81                 :            :     //==================================================================================================================
      82                 :            :     typedef ::cppu::WeakImplHelper3 <   XUIElementFactory
      83                 :            :                                     ,   XServiceInfo
      84                 :            :                                     ,   XInitialization
      85                 :            :                                     >   ToolPanelFactory_Base;
      86                 :            :     class ToolPanelFactory : public ToolPanelFactory_Base
      87                 :            :     {
      88                 :            :     public:
      89                 :            :         ToolPanelFactory( const Reference< XComponentContext >& i_rContext );
      90                 :            : 
      91                 :            :         // XUIElementFactory
      92                 :            :         virtual Reference< XUIElement > SAL_CALL createUIElement( const ::rtl::OUString& ResourceURL, const Sequence< PropertyValue >& Args ) throw (NoSuchElementException, IllegalArgumentException, RuntimeException);
      93                 :            : 
      94                 :            :         // XServiceInfo
      95                 :            :         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
      96                 :            :         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException);
      97                 :            :         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
      98                 :            : 
      99                 :            :         // XInitialization
     100                 :            :         virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
     101                 :            : 
     102                 :            :     protected:
     103                 :            :         virtual ~ToolPanelFactory();
     104                 :            : 
     105                 :            :     private:
     106                 :            :         const Reference< XComponentContext >    m_xContext;
     107                 :            :     };
     108                 :            : 
     109                 :            :     //------------------------------------------------------------------------------------------------------------------
     110                 :         32 :     Reference< XInterface > SAL_CALL ToolPanelFactory_createInstance( const Reference< XComponentContext >& i_rContext )
     111                 :            :     {
     112         [ +  - ]:         32 :         return Reference< XInterface >( *new ToolPanelFactory( i_rContext ) );
     113                 :            :     }
     114                 :            : 
     115                 :            :     //------------------------------------------------------------------------------------------------------------------
     116                 :         30 :     ::rtl::OUString ToolPanelFactory_getImplementationName() throw(RuntimeException)
     117                 :            :     {
     118                 :         30 :         return ::rtl::OUString( "com.sun.star.comp.drawing.ToolPanelFactory" ) ;
     119                 :            :     }
     120                 :            : 
     121                 :            :     //------------------------------------------------------------------------------------------------------------------
     122                 :          8 :     Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory_getSupportedServiceNames (void)
     123                 :            :         throw (RuntimeException)
     124                 :            :     {
     125                 :          8 :         const ::rtl::OUString sServiceName( "com.sun.star.drawing.DefaultToolPanelFactory" );
     126         [ +  - ]:          8 :         return Sequence< ::rtl::OUString >( &sServiceName, 1 );
     127                 :            :     }
     128                 :            : 
     129                 :            :     //------------------------------------------------------------------------------------------------------------------
     130                 :         32 :     ToolPanelFactory::ToolPanelFactory( const Reference< XComponentContext >& i_rContext )
     131                 :         32 :         :m_xContext( i_rContext )
     132                 :            :     {
     133                 :         32 :     }
     134                 :            : 
     135                 :            :     //------------------------------------------------------------------------------------------------------------------
     136                 :         32 :     ToolPanelFactory::~ToolPanelFactory()
     137                 :            :     {
     138         [ -  + ]:         64 :     }
     139                 :            : 
     140                 :            :     //------------------------------------------------------------------------------------------------------------------
     141                 :         32 :     Reference< XUIElement > SAL_CALL ToolPanelFactory::createUIElement( const ::rtl::OUString& i_rResourceURL, const Sequence< PropertyValue >& i_rArgs ) throw (NoSuchElementException, IllegalArgumentException, RuntimeException)
     142                 :            :     {
     143         [ +  - ]:         32 :         SolarMutexGuard aSolarGuard;
     144                 :            : 
     145         [ +  - ]:         32 :         const PanelId ePanelId( toolpanel::GetStandardPanelId( i_rResourceURL ) );
     146         [ -  + ]:         32 :         if ( ePanelId == PID_UNKNOWN )
     147 [ #  # ][ #  # ]:          0 :             throw NoSuchElementException( i_rResourceURL, *this );
     148                 :            : 
     149         [ +  - ]:         32 :         const ::comphelper::NamedValueCollection aArgs( i_rArgs );
     150         [ +  - ]:         32 :         const Reference< XFrame > xDocFrame( aArgs.getOrDefault( "Frame", Reference< XFrame >() ) );
     151         [ +  - ]:         32 :         const Reference< XWindow > xParentWindow( aArgs.getOrDefault( "ParentWindow", Reference< XWindow >() ) );
     152 [ -  + ][ -  + ]:         32 :         if ( !xDocFrame.is() || !xParentWindow.is() )
                 [ +  - ]
     153                 :            :             throw IllegalArgumentException(
     154                 :            :                 "For creating a standard tool panel, a Frame and a Parent window are needed." ,
     155                 :            :                 *this,
     156                 :            :                 2
     157 [ #  # ][ #  # ]:          0 :             );
     158                 :            : 
     159                 :            :         // look up the Sfx(View)Frame for the given XFrame
     160                 :         32 :         SfxViewFrame* pViewFrame = NULL;
     161 [ +  - ][ +  - ]:         38 :         for (   SfxFrame* pFrame = SfxFrame::GetFirst();
                 [ +  - ]
     162                 :            :                 pFrame != NULL;
     163                 :            :                 pFrame = SfxFrame::GetNext( *pFrame )
     164                 :            :             )
     165                 :            :         {
     166 [ +  - ][ +  - ]:         38 :             if ( pFrame->GetFrameInterface() == xDocFrame )
                 [ +  + ]
     167                 :            :             {
     168         [ +  - ]:         32 :                 pViewFrame = pFrame->GetCurrentViewFrame();
     169                 :         32 :                 break;
     170                 :            :             }
     171                 :            :         }
     172                 :            : 
     173 [ +  - ][ +  - ]:         32 :         if ( !pViewFrame || !pViewFrame->HasChildWindow( SID_TASKPANE ) )
         [ -  + ][ -  + ]
     174                 :            :             throw IllegalArgumentException(
     175                 :            :                 "Illegal frame." ,
     176                 :            :                 *this,
     177                 :            :                 2
     178 [ #  # ][ #  # ]:          0 :             );
     179                 :            : 
     180                 :            :         // retrieve the task pane
     181 [ +  - ][ -  + ]:         32 :         ToolPanelChildWindow* pToolPanelWindow( dynamic_cast< ToolPanelChildWindow* >( pViewFrame->GetChildWindow( SID_TASKPANE ) ) );
     182         [ -  + ]:         32 :         if ( !pToolPanelWindow )
     183                 :            :             throw IllegalArgumentException(
     184                 :            :                 "No Impress document, or no Impress Task Pane." ,
     185                 :            :                 *this,
     186                 :            :                 2
     187 [ #  # ][ #  # ]:          0 :             );
     188                 :            : 
     189                 :            :         // retrieve the ViewShellBase, and the view shell of the task pane
     190 [ +  - ][ -  + ]:         32 :         ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pViewFrame->GetViewShell() );
     191         [ +  - ]:         32 :         ::boost::shared_ptr< framework::FrameworkHelper > pFrameworkHelper;
     192         [ +  - ]:         32 :         if ( pViewShellBase )
     193 [ +  - ][ +  - ]:         32 :             pFrameworkHelper = framework::FrameworkHelper::Instance( *pViewShellBase );
                 [ +  - ]
     194         [ +  - ]:         32 :         ::boost::shared_ptr< ViewShell > pViewShell;
     195         [ +  - ]:         32 :         if ( pFrameworkHelper.get() )
     196 [ +  - ][ +  - ]:         32 :             pViewShell = pFrameworkHelper->GetViewShell( framework::FrameworkHelper::msRightPaneURL );
                 [ +  - ]
     197         [ -  + ]:         32 :         ToolPanelViewShell* pToolPanelShell = dynamic_cast< ToolPanelViewShell* >( pViewShell.get() );
     198                 :            : 
     199         [ -  + ]:         32 :         if ( !pToolPanelShell )
     200                 :            :             throw IllegalArgumentException(
     201                 :            :                 "Wrong document type." ,
     202                 :            :                 *this,
     203                 :            :                 2
     204 [ #  # ][ #  # ]:          0 :             );
     205                 :            : 
     206         [ +  - ]:         32 :         ::Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow );
     207 [ +  - ][ +  - ]:         32 :         if ( !pParentWindow || !pToolPanelShell->IsPanelAnchorWindow( *pParentWindow ) )
         [ -  + ][ -  + ]
     208                 :            :             throw IllegalArgumentException(
     209                 :            :                 "Unsupported parent window." ,
     210                 :            :                 *this,
     211                 :            :                 2
     212 [ #  # ][ #  # ]:          0 :             );
     213                 :            : 
     214 [ +  - ][ +  - ]:         32 :         return pToolPanelShell->CreatePanelUIElement( xDocFrame, i_rResourceURL );
         [ +  - ][ +  - ]
                 [ +  - ]
     215                 :            :     }
     216                 :            : 
     217                 :            :     //------------------------------------------------------------------------------------------------------------------
     218                 :          0 :     ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName(  ) throw (RuntimeException)
     219                 :            :     {
     220                 :          0 :         return ToolPanelFactory_getImplementationName();
     221                 :            :     }
     222                 :            : 
     223                 :            :     //------------------------------------------------------------------------------------------------------------------
     224                 :          0 :     ::sal_Bool SAL_CALL ToolPanelFactory::supportsService( const ::rtl::OUString& i_rServiceName ) throw (RuntimeException)
     225                 :            :     {
     226         [ #  # ]:          0 :         const Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
     227         [ #  # ]:          0 :         for (   const ::rtl::OUString* pSupported = aSupported.getConstArray();
     228                 :          0 :                 pSupported != aSupported.getConstArray() + aSupported.getLength();
     229                 :            :                 ++pSupported
     230                 :            :             )
     231         [ #  # ]:          0 :             if ( *pSupported == i_rServiceName )
     232                 :          0 :                 return sal_True;
     233                 :            : 
     234         [ #  # ]:          0 :         return sal_False;
     235                 :            :     }
     236                 :            : 
     237                 :            :     //------------------------------------------------------------------------------------------------------------------
     238                 :          0 :     Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames(  ) throw (RuntimeException)
     239                 :            :     {
     240                 :          0 :         return ToolPanelFactory_getSupportedServiceNames();
     241                 :            :     }
     242                 :            : 
     243                 :            :     //------------------------------------------------------------------------------------------------------------------
     244                 :          0 :     void SAL_CALL ToolPanelFactory::initialize( const Sequence< Any >& i_rArguments ) throw (Exception, RuntimeException)
     245                 :            :     {
     246         [ #  # ]:          0 :         ::comphelper::NamedValueCollection aArgs( i_rArguments );
     247         [ #  # ]:          0 :         (void)aArgs;
     248                 :            :         // TODO
     249                 :          0 :     }
     250                 :            : 
     251                 :            : //......................................................................................................................
     252                 :            : } } // namespace sd::toolpanel
     253                 :            : //......................................................................................................................
     254                 :            : 
     255                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10