LCOV - code coverage report
Current view: top level - filter/source/xsltdialog - xmlfilterdialogcomponent.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 55 126 43.7 %
Date: 2014-11-03 Functions: 17 31 54.8 %
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 <osl/mutex.hxx>
      21             : #include <toolkit/helper/vclunohelper.hxx>
      22             : 
      23             : #include <osl/thread.h>
      24             : #include <cppuhelper/factory.hxx>
      25             : #include <cppuhelper/typeprovider.hxx>
      26             : #include <cppuhelper/component.hxx>
      27             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      28             : #include <com/sun/star/frame/Desktop.hpp>
      29             : #include <com/sun/star/frame/XTerminateListener.hpp>
      30             : #include <cppuhelper/implbase4.hxx>
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : #include <com/sun/star/lang/XServiceInfo.hpp>
      33             : #include <com/sun/star/lang/XInitialization.hpp>
      34             : #include <com/sun/star/awt/XWindow.hpp>
      35             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      36             : #include <com/sun/star/beans/PropertyValue.hpp>
      37             : #include <tools/resmgr.hxx>
      38             : #include <vcl/svapp.hxx>
      39             : #include <vcl/settings.hxx>
      40             : #include <rtl/instance.hxx>
      41             : #include <comphelper/processfactory.hxx>
      42             : 
      43             : #include <svl/solar.hrc>
      44             : 
      45             : #include "xmlfiltersettingsdialog.hxx"
      46             : 
      47             : using namespace ::cppu;
      48             : using namespace ::osl;
      49             : using namespace ::com::sun::star::uno;
      50             : using namespace ::com::sun::star::lang;
      51             : using namespace ::com::sun::star::beans;
      52             : using namespace ::com::sun::star::registry;
      53             : using namespace ::com::sun::star::frame;
      54             : 
      55             : 
      56           4 : class XMLFilterDialogComponentBase
      57             : {
      58             : protected:
      59             :     ::osl::Mutex maMutex;
      60             : };
      61             : 
      62             : 
      63             : class XMLFilterDialogComponent :    public XMLFilterDialogComponentBase,
      64             :                                     public OComponentHelper,
      65             :                                     public ::com::sun::star::ui::dialogs::XExecutableDialog,
      66             :                                     public XServiceInfo,
      67             :                                     public XInitialization,
      68             :                                     public XTerminateListener
      69             : {
      70             : public:
      71             :     XMLFilterDialogComponent( const Reference< XComponentContext >& rxContext );
      72             :     virtual ~XMLFilterDialogComponent();
      73             : 
      74             : protected:
      75             :     // XInterface
      76             :     virtual Any SAL_CALL queryInterface( const Type& aType ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      77             :     virtual Any SAL_CALL queryAggregation( Type const & rType ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      78             :     virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
      79             :     virtual void SAL_CALL release() throw () SAL_OVERRIDE;
      80             : 
      81             :     // XTypeProvider
      82             :     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException, std::exception) SAL_OVERRIDE;
      83             :     virtual Sequence< Type > SAL_CALL getTypes() throw (RuntimeException, std::exception) SAL_OVERRIDE;
      84             : 
      85             :     // XServiceInfo
      86             :     virtual OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      87             :     virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      88             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      89             : 
      90             :     // XExecutableDialog
      91             :     virtual void SAL_CALL setTitle( const OUString& aTitle ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      92             :     virtual sal_Int16 SAL_CALL execute(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      93             : 
      94             :     // XInitialization
      95             :     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
      96             : 
      97             :     // XTerminateListener
      98             :     virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException, std::exception) SAL_OVERRIDE;
      99             :     virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     100             :     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     101             : 
     102             :     /** Called in dispose method after the listeners were notified.
     103             :     */
     104             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     105             : 
     106             : private:
     107             :     com::sun::star::uno::Reference<com::sun::star::awt::XWindow> mxParent;  /// parent window
     108             :     com::sun::star::uno::Reference< XComponentContext > mxContext;
     109             : 
     110             :     XMLFilterSettingsDialog* mpDialog;
     111             : };
     112             : 
     113             : 
     114             : 
     115             : namespace
     116             : {
     117             :     static ResMgr* pXSLTResMgr = NULL;
     118             : }
     119             : 
     120           0 : ResMgr* getXSLTDialogResMgr()
     121             : {
     122           0 :     return pXSLTResMgr;
     123             : }
     124             : 
     125           2 : XMLFilterDialogComponent::XMLFilterDialogComponent( const com::sun::star::uno::Reference< XComponentContext >& rxContext ) :
     126             :     OComponentHelper( maMutex ),
     127             :     mxContext( rxContext ),
     128           2 :     mpDialog( NULL )
     129             : {
     130           2 :     Reference< XDesktop2 > xDesktop = Desktop::create( rxContext );
     131           4 :     Reference< XTerminateListener > xListener( this );
     132           4 :     xDesktop->addTerminateListener( xListener );
     133           2 : }
     134             : 
     135             : 
     136             : 
     137           4 : XMLFilterDialogComponent::~XMLFilterDialogComponent()
     138             : {
     139           4 : }
     140             : 
     141             : 
     142             : 
     143             : // XInterface
     144          10 : Any SAL_CALL XMLFilterDialogComponent::queryInterface( const Type& aType ) throw (RuntimeException, std::exception)
     145             : {
     146          10 :     return OComponentHelper::queryInterface( aType );
     147             : }
     148             : 
     149             : 
     150             : 
     151          10 : Any SAL_CALL XMLFilterDialogComponent::queryAggregation( Type const & rType ) throw (RuntimeException, std::exception)
     152             : {
     153          10 :     if (rType == cppu::UnoType<com::sun::star::ui::dialogs::XExecutableDialog>::get())
     154             :     {
     155           0 :         void * p = static_cast< ::com::sun::star::ui::dialogs::XExecutableDialog * >( this );
     156           0 :         return Any( &p, rType );
     157             :     }
     158          10 :     else if (rType == cppu::UnoType<XServiceInfo>::get())
     159             :     {
     160           2 :         void * p = static_cast< XServiceInfo * >( this );
     161           2 :         return Any( &p, rType );
     162             :     }
     163           8 :     else if (rType == cppu::UnoType<XInitialization>::get())
     164             :     {
     165           0 :         void * p = static_cast< XInitialization * >( this );
     166           0 :         return Any( &p, rType );
     167             :     }
     168           8 :     else if (rType == cppu::UnoType<XTerminateListener>::get())
     169             :     {
     170           0 :         void * p = static_cast< XTerminateListener * >( this );
     171           0 :         return Any( &p, rType );
     172             :     }
     173           8 :     return OComponentHelper::queryAggregation( rType );
     174             : }
     175             : 
     176             : 
     177             : 
     178          32 : void SAL_CALL XMLFilterDialogComponent::acquire() throw ()
     179             : {
     180          32 :     OComponentHelper::acquire();
     181          32 : }
     182             : 
     183             : 
     184             : 
     185          32 : void SAL_CALL XMLFilterDialogComponent::release() throw ()
     186             : {
     187          32 :     OComponentHelper::release();
     188          32 : }
     189             : 
     190             : 
     191             : 
     192           4 : OUString XMLFilterDialogComponent_getImplementationName() throw ( RuntimeException )
     193             : {
     194           4 :     return OUString( "com.sun.star.comp.ui.XSLTFilterDialog" );
     195             : }
     196             : 
     197           2 : Sequence< OUString > SAL_CALL XMLFilterDialogComponent_getSupportedServiceNames()  throw ( RuntimeException )
     198             : {
     199           2 :     Sequence< OUString > aSupported(1);
     200           2 :     aSupported[0] = "com.sun.star.ui.dialogs.XSLTFilterDialog";
     201           2 :     return aSupported;
     202             : }
     203             : 
     204           2 : Reference< XInterface > SAL_CALL XMLFilterDialogComponent_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw ( Exception )
     205             : {
     206           2 :     return (OWeakObject*)new XMLFilterDialogComponent( comphelper::getComponentContext(rSMgr) );
     207             : }
     208             : 
     209           2 : OUString SAL_CALL XMLFilterDialogComponent::getImplementationName() throw(com::sun::star::uno::RuntimeException, std::exception)
     210             : {
     211           2 :     return XMLFilterDialogComponent_getImplementationName();
     212             : }
     213             : 
     214             : namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
     215             : 
     216           0 : Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId( void ) throw( RuntimeException, std::exception )
     217             : {
     218           0 :     return css::uno::Sequence<sal_Int8>();
     219             : }
     220             : 
     221             : 
     222             : 
     223             : namespace
     224             : {
     225           0 :     class DialogComponentTypes
     226             :     {
     227             :     private:
     228             :         OTypeCollection m_aTypes;
     229             :     public:
     230           0 :         DialogComponentTypes() :
     231             :             m_aTypes(
     232           0 :                 cppu::UnoType<XComponent>::get(),
     233           0 :                 cppu::UnoType<XTypeProvider>::get(),
     234           0 :                 cppu::UnoType<XAggregation>::get(),
     235           0 :                 cppu::UnoType<XWeak>::get(),
     236           0 :                 cppu::UnoType<XServiceInfo>::get(),
     237           0 :                 cppu::UnoType<XInitialization>::get(),
     238           0 :                 cppu::UnoType<XTerminateListener>::get(),
     239           0 :                 cppu::UnoType<com::sun::star::ui::dialogs::XExecutableDialog>::get())
     240             :         {
     241           0 :         }
     242           0 :         OTypeCollection& getTypeCollection() { return m_aTypes; }
     243             :     };
     244             : 
     245             :     struct theDialogComponentTypes : rtl::Static<DialogComponentTypes, theDialogComponentTypes> {};
     246             : }
     247             : 
     248           0 : Sequence< Type > XMLFilterDialogComponent::getTypes() throw (RuntimeException, std::exception)
     249             : {
     250           0 :     return theDialogComponentTypes::get().getTypeCollection().getTypes();
     251             : }
     252             : 
     253           0 : Sequence< OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException, std::exception)
     254             : {
     255           0 :     return XMLFilterDialogComponent_getSupportedServiceNames();
     256             : }
     257             : 
     258           0 : sal_Bool SAL_CALL XMLFilterDialogComponent::supportsService(const OUString& ServiceName) throw(RuntimeException, std::exception)
     259             : {
     260           0 :     return cppu::supportsService( this, ServiceName );
     261             : }
     262             : 
     263             : /** Called in dispose method after the listeners were notified.
     264             : */
     265           2 : void SAL_CALL XMLFilterDialogComponent::disposing()
     266             : {
     267           2 :     ::SolarMutexGuard aGuard;
     268             : 
     269           2 :     if( mpDialog )
     270             :     {
     271           0 :         delete mpDialog;
     272           0 :         mpDialog = NULL;
     273             :     }
     274             : 
     275           2 :     if (pXSLTResMgr)
     276             :     {
     277           0 :         delete pXSLTResMgr;
     278           0 :         pXSLTResMgr = NULL;
     279           2 :     }
     280           2 : }
     281             : 
     282             : 
     283             : 
     284             : // XTerminateListener
     285           0 : void SAL_CALL XMLFilterDialogComponent::queryTermination( const EventObject& /* Event */ ) throw (TerminationVetoException, RuntimeException, std::exception)
     286             : {
     287           0 :     ::SolarMutexGuard aGuard;
     288             : 
     289           0 :     if (!mpDialog)
     290           0 :         return;
     291             : 
     292             :     // we will never give a veto here
     293           0 :     if (!mpDialog->isClosable())
     294             :     {
     295           0 :         mpDialog->ToTop();
     296             :         throw TerminationVetoException(
     297             :             "The office cannot be closed while the XMLFilterDialog is running",
     298           0 :             static_cast<XTerminateListener*>(this));
     299             :     }
     300             :     else
     301           0 :         mpDialog->Close();
     302             : }
     303             : 
     304             : 
     305             : 
     306           0 : void SAL_CALL XMLFilterDialogComponent::notifyTermination( const EventObject& /* Event */ ) throw (RuntimeException, std::exception)
     307             : {
     308             :     // we are going down, so dispose us!
     309           0 :     dispose();
     310           0 : }
     311             : 
     312           0 : void SAL_CALL XMLFilterDialogComponent::disposing( const EventObject& /* Source */ ) throw (RuntimeException, std::exception)
     313             : {
     314           0 : }
     315             : 
     316             : 
     317           0 : void SAL_CALL XMLFilterDialogComponent::setTitle( const OUString& /* _rTitle */ ) throw(RuntimeException, std::exception)
     318             : {
     319           0 : }
     320             : 
     321             : 
     322           0 : sal_Int16 SAL_CALL XMLFilterDialogComponent::execute(  ) throw(RuntimeException, std::exception)
     323             : {
     324           0 :     ::SolarMutexGuard aGuard;
     325             : 
     326           0 :     if( NULL == pXSLTResMgr )
     327             :     {
     328           0 :         pXSLTResMgr = ResMgr::CreateResMgr( "xsltdlg", Application::GetSettings().GetUILanguageTag() );
     329             :     }
     330             : 
     331           0 :     if( NULL == mpDialog )
     332             :     {
     333           0 :         vcl::Window* pParent = DIALOG_NO_PARENT;
     334           0 :         if (mxParent.is())
     335           0 :             pParent = VCLUnoHelper::GetWindow(mxParent);
     336             : 
     337           0 :         Reference< XComponent > xComp( this );
     338           0 :         mpDialog = new XMLFilterSettingsDialog(pParent, mxContext);
     339           0 :         mpDialog->Execute();
     340             :     }
     341           0 :     else if( !mpDialog->IsVisible() )
     342             :     {
     343           0 :         mpDialog->Execute();
     344             :     }
     345           0 :     mpDialog->ToTop();
     346             : 
     347           0 :     return 0;
     348             : }
     349             : 
     350             : 
     351           0 : void SAL_CALL XMLFilterDialogComponent::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException, std::exception)
     352             : {
     353           0 :     const Any* pArguments = aArguments.getConstArray();
     354           0 :     for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
     355             :     {
     356           0 :         PropertyValue aProperty;
     357           0 :         if(*pArguments >>= aProperty)
     358             :         {
     359           0 :             if( aProperty.Name == "ParentWindow" )
     360             :             {
     361           0 :                 aProperty.Value >>= mxParent;
     362             :             }
     363             :         }
     364           0 :     }
     365           0 : }
     366             : 
     367             : 
     368             : extern "C"
     369             : {
     370           2 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL xsltdlg_component_getFactory(
     371             :     const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
     372             : {
     373           2 :     void * pRet = 0;
     374             : 
     375           2 :     if( pServiceManager )
     376             :     {
     377           2 :         Reference< XSingleServiceFactory > xFactory;
     378             : 
     379           4 :         OUString implName = OUString::createFromAscii( pImplName );
     380           2 :         if ( implName.equals(XMLFilterDialogComponent_getImplementationName()) )
     381             :         {
     382           4 :             xFactory = createOneInstanceFactory(
     383             :                 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
     384             :                 OUString::createFromAscii( pImplName ),
     385           2 :                 XMLFilterDialogComponent_createInstance, XMLFilterDialogComponent_getSupportedServiceNames() );
     386             : 
     387             :         }
     388             : 
     389           2 :         if (xFactory.is())
     390             :         {
     391           2 :             xFactory->acquire();
     392           2 :             pRet = xFactory.get();
     393           2 :         }
     394             :     }
     395             : 
     396           2 :     return pRet;
     397             : }
     398           6 : }
     399             : 
     400             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10