LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/toolpanel - ToolPanelFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 61 3.3 %
Date: 2012-12-27 Functions: 1 11 9.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10