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

Generated by: LCOV version 1.10