LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/svtools - genericunodialog.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 9 77.8 %
Date: 2012-08-25 Functions: 5 6 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 8 25.0 %

           Branch data     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                 :            : #ifndef _SVT_GENERICUNODIALOG_HXX_
      21                 :            : #define _SVT_GENERICUNODIALOG_HXX_
      22                 :            : 
      23                 :            : #include "svtools/svtdllapi.h"
      24                 :            : 
      25                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      26                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      27                 :            : #include <com/sun/star/awt/XWindow.hpp>
      28                 :            : #include <com/sun/star/uno/XComponentContext.hpp>
      29                 :            : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      30                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      31                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      32                 :            : #include <com/sun/star/lang/NotInitializedException.hpp>
      33                 :            : 
      34                 :            : #include <cppuhelper/implbase3.hxx>
      35                 :            : #include <cppuhelper/propshlp.hxx>
      36                 :            : #include <comphelper/proparrhlp.hxx>
      37                 :            : #include <comphelper/uno3.hxx>
      38                 :            : #include <comphelper/propertycontainer.hxx>
      39                 :            : #include <comphelper/broadcasthelper.hxx>
      40                 :            : #include <comphelper/componentcontext.hxx>
      41                 :            : #include <tools/link.hxx>
      42                 :            : 
      43                 :            : class Dialog;
      44                 :            : class Window;
      45                 :            : class VclWindowEvent;
      46                 :            : 
      47                 :            : //.........................................................................
      48                 :            : namespace svt
      49                 :            : {
      50                 :            : //.........................................................................
      51                 :            : 
      52                 :            :     //=========================================================================
      53                 :            : #define     UNODIALOG_PROPERTY_ID_TITLE     1
      54                 :            : #define     UNODIALOG_PROPERTY_ID_PARENT    2
      55                 :            : 
      56                 :            : #define     UNODIALOG_PROPERTY_TITLE        "Title"
      57                 :            : #define     UNODIALOG_PROPERTY_PARENT       "ParentWindow"
      58                 :            : 
      59                 :            : 
      60                 :            :     //=========================================================================
      61                 :            :     typedef ::cppu::WeakImplHelper3 <   com::sun::star::ui::dialogs::XExecutableDialog
      62                 :            :                                     ,   com::sun::star::lang::XServiceInfo
      63                 :            :                                     ,   com::sun::star::lang::XInitialization
      64                 :            :                                     >   OGenericUnoDialogBase;
      65                 :            : 
      66                 :            :     /** abstract base class for implementing UNO objects representing dialogs (<type scope="com.sun.star.awt">XDialog</type>)
      67                 :            :     */
      68                 :            :     class SVT_DLLPUBLIC OGenericUnoDialog
      69                 :            :             :public OGenericUnoDialogBase
      70                 :            :             ,public ::comphelper::OMutexAndBroadcastHelper
      71                 :            :             ,public ::comphelper::OPropertyContainer
      72                 :            :     {
      73                 :            :     private:
      74                 :            :         ::osl::Mutex                    m_aExecutionMutex;  /// acess safety for execute/cancel
      75                 :            : 
      76                 :            :     protected:
      77                 :            :         Dialog*                     m_pDialog;                  /// the dialog to execute
      78                 :            :         sal_Bool                    m_bExecuting : 1;           /// we're currently executing the dialog
      79                 :            :         sal_Bool                    m_bCanceled : 1;            /// endDialog was called while we were executing
      80                 :            :         sal_Bool                    m_bTitleAmbiguous : 1;      /// m_sTitle has not been set yet
      81                 :            :         bool                        m_bInitialized : 1;         /// has "initialize" been called?
      82                 :            :         bool                        m_bNeedInitialization : 1;  /// do we need to be initialized before any other API call is allowed?
      83                 :            : 
      84                 :            :         // <properties>
      85                 :            :         ::rtl::OUString                                                 m_sTitle;   /// title of the dialog
      86                 :            :         com::sun::star::uno::Reference<com::sun::star::awt::XWindow>    m_xParent;  /// parent window
      87                 :            :         // </properties>
      88                 :            : 
      89                 :            :         ::comphelper::ComponentContext m_aContext;
      90                 :            : 
      91                 :            :     public:
      92 [ -  + ][ #  # ]:          4 :         inline bool needInitialization() const { return m_bNeedInitialization && !m_bInitialized; }
      93                 :            : 
      94                 :            :     protected:
      95                 :            :         OGenericUnoDialog(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& _rxORB);
      96                 :            :         OGenericUnoDialog(const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& _rxContext);
      97                 :            :         virtual ~OGenericUnoDialog();
      98                 :            : 
      99                 :            :     public:
     100                 :            :         // UNO
     101                 :        236 :         DECLARE_UNO3_DEFAULTS(OGenericUnoDialog, OGenericUnoDialogBase);
     102                 :            :         virtual com::sun::star::uno::Any SAL_CALL queryInterface(const com::sun::star::uno::Type& _rType) throw (com::sun::star::uno::RuntimeException);
     103                 :            : 
     104                 :            :         // XTypeProvider
     105                 :            :         virtual com::sun::star::uno::Sequence<com::sun::star::uno::Type> SAL_CALL getTypes(  ) throw(com::sun::star::uno::RuntimeException);
     106                 :            :         virtual com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId(  ) throw(com::sun::star::uno::RuntimeException) = 0;
     107                 :            : 
     108                 :            :         // XServiceInfo
     109                 :            :         virtual ::rtl::OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException) = 0;
     110                 :            :         virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw(com::sun::star::uno::RuntimeException);
     111                 :            :         virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException) = 0;
     112                 :            : 
     113                 :            :         // OPropertySetHelper
     114                 :            :         virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any& rValue ) throw(com::sun::star::uno::Exception);
     115                 :            :         virtual sal_Bool SAL_CALL convertFastPropertyValue( com::sun::star::uno::Any& rConvertedValue, com::sun::star::uno::Any& rOldValue, sal_Int32 nHandle, const com::sun::star::uno::Any& rValue) throw(com::sun::star::lang::IllegalArgumentException);
     116                 :            : 
     117                 :            :         // XExecutableDialog
     118                 :            :         virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw(::com::sun::star::uno::RuntimeException);
     119                 :            :         virtual sal_Int16 SAL_CALL execute(  ) throw(::com::sun::star::uno::RuntimeException);
     120                 :            : 
     121                 :            :         // XInitialization
     122                 :            :         virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ) throw(com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
     123                 :            : 
     124                 :            :     protected:
     125                 :            :         /** create the concret dialog instance. note that m_aMutex is not locked when this method get's called,
     126                 :            :             but the application-wide solar mutex is (to guard the not thread-safe ctor of the dialog).
     127                 :            :             @param      pParent     the parent window for the new dialog
     128                 :            :         */
     129                 :            :         virtual Dialog* createDialog(Window* _pParent) = 0;
     130                 :            : 
     131                 :            :         /// called to destroy the dialog used. the default implementation just deletes m_pDialog and resets it to NULL
     132                 :            :         virtual void destroyDialog();
     133                 :            : 
     134                 :            :         /** called after the dialog has been executed
     135                 :            :             @param      _nExecutionResult       the execution result as returned by Dialog::Execute
     136                 :            :         */
     137                 :          0 :         virtual void executedDialog(sal_Int16 /*_nExecutionResult*/) { }
     138                 :            : 
     139                 :            :         /** smaller form of <method>initialize</method>.<p/>
     140                 :            :             The <method>initialize</method> method is called with a sequence of <type scope="com.sun.star.uno">Any</type>'s,
     141                 :            :             which is split up into the single elements, which are passed to implInitialize. The default implementation
     142                 :            :             tries to exract an <type scope="com.sun.star.beans">PropertyValue</type> from the value an pass it to the
     143                 :            :             <type scope="com.sun.star.beans">XPropertySet</type> interface of the object.
     144                 :            :         */
     145                 :            :         virtual void implInitialize(const com::sun::star::uno::Any& _rValue);
     146                 :            : 
     147                 :            :     private:
     148                 :            :         DECL_LINK( OnDialogDying, VclWindowEvent* );
     149                 :            : 
     150                 :            :         /** ensures that m_pDialog is not <NULL/>
     151                 :            : 
     152                 :            :             This method does nothing if m_pDialog is already non-<NULL/>. Else, it calls createDialog and does
     153                 :            :             all necessary initializations of the new dialog instance.
     154                 :            : 
     155                 :            :             @precond
     156                 :            :                 m_aMutex is locked
     157                 :            : 
     158                 :            :             @return
     159                 :            :                 <TRUE/> if and only if m_pDialog is non-<NULL/> upon returning from the method. Note that the only
     160                 :            :                 case where m_pDialog is <NULL/> is when createDialog returned <NULL/>, which is will fire an assertion
     161                 :            :                 in non-product builds.
     162                 :            :         */
     163                 :            :         bool    impl_ensureDialog_lck();
     164                 :            :     };
     165                 :            : 
     166                 :            :     /// helper class for guarding access to methods of a OGenericUnoDialog
     167                 :          4 :     class UnoDialogEntryGuard
     168                 :            :     {
     169                 :            :     public:
     170                 :          4 :         UnoDialogEntryGuard( OGenericUnoDialog& _rDialog )
     171                 :          4 :             :m_aGuard( _rDialog.GetMutex() )
     172                 :            :         {
     173         [ -  + ]:          4 :             if ( _rDialog.needInitialization() )
     174         [ #  # ]:          0 :                 throw ::com::sun::star::lang::NotInitializedException();
     175                 :          4 :         }
     176                 :            : 
     177                 :            :     private:
     178                 :            :         ::osl::MutexGuard   m_aGuard;
     179                 :            :     };
     180                 :            : 
     181                 :            : //.........................................................................
     182                 :            : }   // namespace svt
     183                 :            : //.........................................................................
     184                 :            : 
     185                 :            : #endif // _SVT_GENERICUNODIALOG_HXX_
     186                 :            : 
     187                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10