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

Generated by: LCOV version 1.10