LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/uno - genericunodialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 122 0.0 %
Date: 2012-12-27 Functions: 0 17 0.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             : 
      21             : #include "svtools/genericunodialog.hxx"
      22             : 
      23             : #include <com/sun/star/beans/NamedValue.hpp>
      24             : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
      25             : 
      26             : #include <toolkit/awt/vclxwindow.hxx>
      27             : #include <comphelper/extract.hxx>
      28             : #include <cppuhelper/typeprovider.hxx>
      29             : #include <comphelper/property.hxx>
      30             : #include <osl/diagnose.h>
      31             : #include <tools/diagnose_ex.h>
      32             : #include <vcl/msgbox.hxx>
      33             : #include <osl/mutex.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : 
      36             : using namespace ::comphelper;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::lang;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::ucb;
      41             : 
      42             : //.........................................................................
      43             : namespace svt
      44             : {
      45             : //.........................................................................
      46             : 
      47             : //=========================================================================
      48             : //-------------------------------------------------------------------------
      49           0 : OGenericUnoDialog::OGenericUnoDialog(const Reference< XMultiServiceFactory >& _rxORB)
      50           0 :         :OPropertyContainer(GetBroadcastHelper())
      51             :         ,m_pDialog(NULL)
      52             :         ,m_bExecuting(sal_False)
      53             :         ,m_bCanceled(sal_False)
      54             :         ,m_bTitleAmbiguous(sal_True)
      55             :         ,m_bInitialized( false )
      56             :         ,m_bNeedInitialization( false )
      57           0 :         ,m_aContext( _rxORB )
      58             : {
      59             :     registerProperty(::rtl::OUString(UNODIALOG_PROPERTY_TITLE), UNODIALOG_PROPERTY_ID_TITLE, PropertyAttribute::TRANSIENT,
      60           0 :         &m_sTitle, getCppuType(&m_sTitle));
      61             :     registerProperty(::rtl::OUString(UNODIALOG_PROPERTY_PARENT), UNODIALOG_PROPERTY_ID_PARENT, PropertyAttribute::TRANSIENT,
      62           0 :         &m_xParent, getCppuType(&m_xParent));
      63           0 : }
      64             : 
      65             : //-------------------------------------------------------------------------
      66           0 : OGenericUnoDialog::OGenericUnoDialog(const Reference< XComponentContext >& _rxContext)
      67           0 :         :OPropertyContainer(GetBroadcastHelper())
      68             :         ,m_pDialog(NULL)
      69             :         ,m_bExecuting(sal_False)
      70             :         ,m_bCanceled(sal_False)
      71             :         ,m_bTitleAmbiguous(sal_True)
      72             :         ,m_bInitialized( false )
      73             :         ,m_bNeedInitialization( false )
      74           0 :         ,m_aContext(_rxContext)
      75             : {
      76             :     registerProperty(::rtl::OUString(UNODIALOG_PROPERTY_TITLE), UNODIALOG_PROPERTY_ID_TITLE, PropertyAttribute::TRANSIENT,
      77           0 :         &m_sTitle, getCppuType(&m_sTitle));
      78             :     registerProperty(::rtl::OUString(UNODIALOG_PROPERTY_PARENT), UNODIALOG_PROPERTY_ID_PARENT, PropertyAttribute::TRANSIENT,
      79           0 :         &m_xParent, getCppuType(&m_xParent));
      80           0 : }
      81             : 
      82             : //-------------------------------------------------------------------------
      83           0 : OGenericUnoDialog::~OGenericUnoDialog()
      84             : {
      85           0 :     if ( m_pDialog )
      86             :     {
      87           0 :         SolarMutexGuard aSolarGuard;
      88           0 :         ::osl::MutexGuard aGuard( m_aMutex );
      89           0 :         if ( m_pDialog )
      90           0 :             destroyDialog();
      91             :     }
      92           0 : }
      93             : 
      94             : //-------------------------------------------------------------------------
      95           0 : Any SAL_CALL OGenericUnoDialog::queryInterface(const Type& _rType) throw (RuntimeException)
      96             : {
      97           0 :     Any aReturn = OGenericUnoDialogBase::queryInterface(_rType);
      98             : 
      99           0 :     if (!aReturn.hasValue())
     100             :         aReturn = ::cppu::queryInterface(_rType
     101             :             ,static_cast<XPropertySet*>(this)
     102             :             ,static_cast<XMultiPropertySet*>(this)
     103             :             ,static_cast<XFastPropertySet*>(this)
     104           0 :         );
     105             : 
     106           0 :     return aReturn;
     107             : }
     108             : 
     109             : //-------------------------------------------------------------------------
     110           0 : Sequence<Type> SAL_CALL OGenericUnoDialog::getTypes(  ) throw(RuntimeException)
     111             : {
     112             :     return ::comphelper::concatSequences(
     113             :         OGenericUnoDialogBase::getTypes(),
     114             :         ::comphelper::OPropertyContainer::getTypes()
     115           0 :     );
     116             : }
     117             : 
     118             : //-------------------------------------------------------------------------
     119           0 : sal_Bool SAL_CALL OGenericUnoDialog::supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException)
     120             : {
     121           0 :     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
     122           0 :     const ::rtl::OUString* pArray = aSupported.getConstArray();
     123           0 :     for (sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray)
     124           0 :         if (pArray->equals(ServiceName))
     125           0 :             return sal_True;
     126           0 :     return sal_False;
     127             : }
     128             : 
     129             : //-------------------------------------------------------------------------
     130           0 : void OGenericUnoDialog::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw(Exception)
     131             : {
     132             :     // TODO : need some handling if we're currently executing ...
     133             : 
     134           0 :     OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle, rValue);
     135             : 
     136           0 :     if (UNODIALOG_PROPERTY_ID_TITLE == nHandle)
     137             :     {
     138             :         // from now on m_sTitle is valid
     139           0 :         m_bTitleAmbiguous = sal_False;
     140             : 
     141           0 :         if (m_pDialog)
     142           0 :             m_pDialog->SetText(String(m_sTitle));
     143             :     }
     144           0 : }
     145             : 
     146             : //-------------------------------------------------------------------------
     147           0 : sal_Bool OGenericUnoDialog::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue) throw(IllegalArgumentException)
     148             : {
     149           0 :     switch (nHandle)
     150             :     {
     151             :         case UNODIALOG_PROPERTY_ID_PARENT:
     152             :         {
     153           0 :             Reference<starawt::XWindow> xNew;
     154           0 :             ::cppu::extractInterface(xNew, rValue);
     155           0 :             if (xNew != m_xParent)
     156             :             {
     157           0 :                 rConvertedValue <<= xNew;
     158           0 :                 rOldValue <<= m_xParent;
     159           0 :                 return sal_True;
     160             :             }
     161           0 :             return sal_False;
     162             :         }
     163             :     }
     164           0 :     return OPropertyContainer::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
     165             : }
     166             : 
     167             : //-------------------------------------------------------------------------
     168           0 : void SAL_CALL OGenericUnoDialog::setTitle( const ::rtl::OUString& _rTitle ) throw(RuntimeException)
     169             : {
     170           0 :     UnoDialogEntryGuard aGuard( *this );
     171             : 
     172             :     try
     173             :     {
     174           0 :         setPropertyValue(::rtl::OUString(UNODIALOG_PROPERTY_TITLE), makeAny(_rTitle));
     175             :     }
     176           0 :     catch(RuntimeException&)
     177             :     {
     178             :         // allowed to pass
     179           0 :         throw;
     180             :     }
     181           0 :     catch( const Exception& )
     182             :     {
     183             :         DBG_UNHANDLED_EXCEPTION();
     184             :         // not allowed to pass
     185           0 :     }
     186           0 : }
     187             : 
     188             : //-------------------------------------------------------------------------
     189           0 : bool OGenericUnoDialog::impl_ensureDialog_lck()
     190             : {
     191           0 :     if ( m_pDialog )
     192           0 :         return true;
     193             : 
     194             :     // get the parameters for the dialog from the current settings
     195             : 
     196             :     // the parent window
     197           0 :     Window* pParent = NULL;
     198           0 :     VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParent);
     199           0 :     if (pImplementation)
     200           0 :         pParent = pImplementation->GetWindow();
     201             : 
     202             :     // the title
     203           0 :     String sTitle = m_sTitle;
     204             : 
     205           0 :     Dialog* pDialog = createDialog( pParent );
     206             :     OSL_ENSURE( pDialog, "OGenericUnoDialog::impl_ensureDialog_lck: createDialog returned nonsense!" );
     207           0 :     if ( !pDialog )
     208           0 :         return false;
     209             : 
     210             :     // do some initialisations
     211           0 :     if ( !m_bTitleAmbiguous )
     212           0 :         pDialog->SetText( sTitle );
     213             : 
     214             :     // be notified when the dialog is killed by somebody else
     215             :     // #i65958# / 2006-07-07 / frank.schoenheit@sun.com
     216           0 :     pDialog->AddEventListener( LINK( this, OGenericUnoDialog, OnDialogDying ) );
     217             : 
     218           0 :     m_pDialog = pDialog;
     219             : 
     220           0 :     return true;
     221             : }
     222             : 
     223             : //-------------------------------------------------------------------------
     224           0 : sal_Int16 SAL_CALL OGenericUnoDialog::execute(  ) throw(RuntimeException)
     225             : {
     226             :     // both creation and execution of the dialog must be guarded with the SolarMutex, so be generous here
     227           0 :     SolarMutexGuard aSolarGuard;
     228             : 
     229           0 :     Dialog* pDialogToExecute = NULL;
     230             :     // create the dialog, if neccessary
     231             :     {
     232           0 :         UnoDialogEntryGuard aGuard( *this );
     233             : 
     234           0 :         if (m_bExecuting)
     235             :             throw RuntimeException(
     236             :                     ::rtl::OUString( "already executing the dialog (recursive call)" ),
     237             :                     *this
     238           0 :                   );
     239             : 
     240           0 :         m_bCanceled = sal_False;
     241           0 :         m_bExecuting = sal_True;
     242             : 
     243           0 :         if ( !impl_ensureDialog_lck() )
     244           0 :             return 0;
     245             : 
     246           0 :         pDialogToExecute = m_pDialog;
     247             :     }
     248             : 
     249             :     // start execution
     250           0 :     sal_Int16 nReturn(0);
     251           0 :     if ( pDialogToExecute )
     252           0 :         nReturn = pDialogToExecute->Execute();
     253             : 
     254             :     {
     255           0 :         ::osl::MutexGuard aExecutionGuard(m_aExecutionMutex);
     256           0 :         if (m_bCanceled)
     257           0 :             nReturn = RET_CANCEL;
     258             :     }
     259             : 
     260             :     {
     261           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     262             : 
     263             :         // get the settings of the dialog
     264           0 :         executedDialog( nReturn );
     265             : 
     266           0 :         m_bExecuting = sal_False;
     267             :     }
     268             : 
     269             :     // outta here
     270           0 :     return nReturn;
     271             : }
     272             : 
     273             : #ifdef AWT_DIALOG
     274             : //-------------------------------------------------------------------------
     275             : void SAL_CALL OGenericUnoDialog::endExecute(  ) throw(RuntimeException)
     276             : {
     277             :     UnoDialogEntryGuard aGuard( *this );
     278             :     if (!m_bExecuting)
     279             :         throw RuntimeException();
     280             : 
     281             :     {
     282             :         ::osl::MutexGuard aExecutionGuard(m_aExecutionMutex);
     283             :         OSL_ENSURE(m_pDialog, "OGenericUnoDialog::endExecute : executing which dialog ?");
     284             :             // m_bExecuting is true but we have no dialog ?
     285             :         if (!m_pDialog)
     286             :             throw RuntimeException();
     287             : 
     288             :         if (!m_pDialog->IsInExecute())
     289             :             // we tighly missed it ... another thread finished the execution of the dialog,
     290             :             // but did not manage it to reset m_bExecuting, it currently tries to acquire
     291             :             // m_aMutex or m_aExecutionMutex
     292             :             // => nothing to do
     293             :             return;
     294             : 
     295             :         m_pDialog->EndDialog(RET_CANCEL);
     296             :         m_bCanceled = sal_True;
     297             :     }
     298             : }
     299             : #endif
     300             : 
     301             : //-------------------------------------------------------------------------
     302           0 : void OGenericUnoDialog::implInitialize(const Any& _rValue)
     303             : {
     304             :     try
     305             :     {
     306           0 :         PropertyValue aProperty;
     307           0 :         NamedValue aValue;
     308           0 :         if ( _rValue >>= aProperty )
     309             :         {
     310           0 :             setPropertyValue( aProperty.Name, aProperty.Value );
     311             :         }
     312           0 :         else if ( _rValue >>= aValue )
     313             :         {
     314           0 :             setPropertyValue( aValue.Name, aValue.Value );
     315           0 :         }
     316             :     }
     317           0 :     catch(const Exception&)
     318             :     {
     319             :         DBG_UNHANDLED_EXCEPTION();
     320             :     }
     321           0 : }
     322             : 
     323             : //-------------------------------------------------------------------------
     324           0 : void SAL_CALL OGenericUnoDialog::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
     325             : {
     326           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     327           0 :     if ( m_bInitialized )
     328           0 :         throw AlreadyInitializedException( ::rtl::OUString(), *this );
     329             : 
     330           0 :     const Any* pArguments = aArguments.getConstArray();
     331           0 :     for (sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
     332           0 :         implInitialize(*pArguments);
     333             : 
     334           0 :     m_bInitialized = true;
     335           0 : }
     336             : 
     337             : //-------------------------------------------------------------------------
     338           0 : void OGenericUnoDialog::destroyDialog()
     339             : {
     340           0 :     delete m_pDialog;
     341           0 :     m_pDialog = NULL;
     342           0 : }
     343             : 
     344             : //-------------------------------------------------------------------------
     345           0 : IMPL_LINK( OGenericUnoDialog, OnDialogDying, VclWindowEvent*, _pEvent )
     346             : {
     347             :     OSL_ENSURE( _pEvent->GetWindow() == m_pDialog, "OGenericUnoDialog::OnDialogDying: where does this come from?" );
     348           0 :     if ( _pEvent->GetId() == VCLEVENT_OBJECT_DYING )
     349           0 :         m_pDialog = NULL;
     350           0 :     return 0L;
     351             : }
     352             : 
     353             : //.........................................................................
     354             : }   // namespace svt
     355             : //.........................................................................
     356             : 
     357             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10