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

Generated by: LCOV version 1.10