LCOV - code coverage report
Current view: top level - libreoffice/svx/source/inc - formcontrolling.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 7 28.6 %
Date: 2012-12-27 Functions: 2 6 33.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 SVX_FORMCONTROLLING_HXX
      21             : #define SVX_FORMCONTROLLING_HXX
      22             : 
      23             : #include <com/sun/star/form/runtime/XFormController.hpp>
      24             : #include <com/sun/star/form/XForm.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <com/sun/star/form/runtime/FeatureState.hpp>
      27             : #include <com/sun/star/form/runtime/XFormOperations.hpp>
      28             : #include <com/sun/star/sdb/XSQLErrorListener.hpp>
      29             : 
      30             : #include <cppuhelper/implbase2.hxx>
      31             : #include <comphelper/componentcontext.hxx>
      32             : 
      33             : #include <vector>
      34             : 
      35             : //........................................................................
      36             : namespace svx
      37             : {
      38             : //........................................................................
      39             : 
      40             :     //====================================================================
      41             :     //= FeatureSlotTranslation
      42             :     //====================================================================
      43             :     class FeatureSlotTranslation
      44             :     {
      45             :     public:
      46             :         /// retrieves the feature id for a given feature URL
      47             :         static  sal_Int32       getControllerFeatureSlotIdForURL( const ::rtl::OUString& _rMainURL );
      48             : 
      49             :         /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
      50             :         static  sal_Int16       getFormFeatureForSlotId( sal_Int32 _nSlotId );
      51             : 
      52             :         /// retrieves the slot id for a given css.form.runtime.FormFeature ID
      53             :         static  sal_Int32       getSlotIdForFormFeature( sal_Int16 _nFormFeature );
      54             :     };
      55             : 
      56             :     //====================================================================
      57             :     //= IControllerFeatureInvalidation
      58             :     //====================================================================
      59         236 :     class IControllerFeatureInvalidation
      60             :     {
      61             :     public:
      62             :         /** invalidates the given features
      63             : 
      64             :             Invalidation means that any user interface representation (such as toolbox buttons), or
      65             :             any dispatches associated with the features in question are potentially out-of-date, and
      66             :             need to be updated
      67             : 
      68             :             @param _rFeatures
      69             :                 Ids of the features to be invalidated.
      70             :         */
      71             :         virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0;
      72             : 
      73             :     protected:
      74          63 :         ~IControllerFeatureInvalidation() {}
      75             :     };
      76             : 
      77             :     //====================================================================
      78             :     //= ControllerFeatures
      79             :     //====================================================================
      80             :     class FormControllerHelper;
      81             :     /** easier access to an FormControllerHelper instance
      82             :     */
      83             :     class ControllerFeatures
      84             :     {
      85             :     protected:
      86             :         ::comphelper::ComponentContext  m_aContext;
      87             :         IControllerFeatureInvalidation* m_pInvalidationCallback;    // necessary as long as m_pImpl is not yet constructed
      88             :         FormControllerHelper*           m_pImpl;
      89             : 
      90             :     public:
      91             :         /** standard ctor
      92             : 
      93             :             The instance is not functional until <method>assign</method> is used.
      94             : 
      95             :             @param _rxORB
      96             :                 a multi service factory for creating various needed components
      97             : 
      98             :             @param _pInvalidationCallback
      99             :                 the callback for invalidating feature states
     100             :         */
     101             :         ControllerFeatures(
     102             :             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
     103             :             IControllerFeatureInvalidation* _pInvalidationCallback
     104             :         );
     105             : 
     106             :         /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
     107             : 
     108             :             @param _rxORB
     109             :                 a multi service factory for creating various needed components
     110             : 
     111             :             @param _rxController
     112             :                 The form controller which the helper should be responsible for. Must not
     113             :                 be <NULL/>, and must have a valid model (form).
     114             : 
     115             :             @param _pInvalidationCallback
     116             :                 the callback for invalidating feature states
     117             :         */
     118             :         ControllerFeatures(
     119             :             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
     120             :             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
     121             :             IControllerFeatureInvalidation* _pInvalidationCallback
     122             :         );
     123             : 
     124             :         /// dtor
     125             :         ~ControllerFeatures();
     126             : 
     127             :         /// checks whether the instance is properly assigned to a form and/or controller
     128           0 :         inline bool isAssigned( ) const { return m_pImpl != NULL; }
     129             : 
     130             :         /** assign to a controller
     131             :         */
     132             :         void assign(
     133             :             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController
     134             :         );
     135             : 
     136             :         /// clears the instance so that it cannot be used afterwards
     137             :         void dispose();
     138             : 
     139             :         // access to the instance which implements the functionality. Not to be used when not assigned
     140           0 :         inline const FormControllerHelper* operator->() const { return m_pImpl; }
     141           0 :         inline       FormControllerHelper* operator->()       { return m_pImpl; }
     142             :         inline const FormControllerHelper& operator*() const  { return *m_pImpl; }
     143             :         inline       FormControllerHelper& operator*()        { return *m_pImpl; }
     144             :     };
     145             : 
     146             :     //====================================================================
     147             :     //= FormControllerHelper
     148             :     //====================================================================
     149             :     typedef ::cppu::WeakImplHelper2 <   ::com::sun::star::form::runtime::XFeatureInvalidation
     150             :                                     ,   ::com::sun::star::sdb::XSQLErrorListener
     151             :                                     >   FormControllerHelper_Base;
     152             :     /** is a helper class which manages form controller functionality (such as moveNext etc.).
     153             : 
     154             :         <p>The class helps implementing form controller functionality, by providing
     155             :         methods to determine the state of, and execute, various common form features.<br/>
     156             :         A <em>feature</em> is for instance moving the form associated with the controller
     157             :         to a certain position, or reloading the form, and so on.</p>
     158             :     */
     159             :     class FormControllerHelper : public FormControllerHelper_Base
     160             :     {
     161             :     protected:
     162             :         ::comphelper::ComponentContext  m_aContext;
     163             :         IControllerFeatureInvalidation* m_pInvalidationCallback;
     164             :         ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >
     165             :                                         m_xFormOperations;
     166             : 
     167             :         ::com::sun::star::uno::Any      m_aOperationError;
     168             : 
     169             :     public:
     170             :         /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
     171             : 
     172             :             @param _rContext
     173             :                 the context the component lives in
     174             :             @param _rxController
     175             :                 The form controller which the helper should be responsible for. Must not
     176             :                 be <NULL/>, and must have a valid model (form).
     177             :             @param _pInvalidationCallback
     178             :                 the callback for invalidating feature states
     179             :         */
     180             :         FormControllerHelper(
     181             :             const ::comphelper::ComponentContext& _rContext,
     182             :             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
     183             :             IControllerFeatureInvalidation* _pInvalidationCallback
     184             :         );
     185             : 
     186             :         // forwards to the XFormOperations implementation
     187             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >
     188             :                     getCursor() const;
     189             :         void        getState(
     190             :                         sal_Int32 _nSlotId,
     191             :                         ::com::sun::star::form::runtime::FeatureState& _out_rState
     192             :                     ) const;
     193             :         sal_Bool    isEnabled( sal_Int32 _nSlotId ) const;
     194             :         void        execute( sal_Int32 _nSlotId ) const;
     195             :         void        execute( sal_Int32 _nSlotId, const ::rtl::OUString& _rParamName, const ::com::sun::star::uno::Any& _rParamValue ) const;
     196             :         sal_Bool    commitCurrentRecord() const;
     197             :         sal_Bool    commitCurrentControl( ) const;
     198             :         sal_Bool    isInsertionRow() const;
     199             :         sal_Bool    isModifiedRow() const;
     200             : 
     201             :         bool        canDoFormFilter() const;
     202             : 
     203             :         /** disposes this instance.
     204             : 
     205             :             After this method has been called, the instance is not functional anymore
     206             :         */
     207             :         void        dispose();
     208             : 
     209             :         const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >&
     210             :                     getFormOperations() const { return m_xFormOperations; }
     211             :     protected:
     212             :         /// dtor
     213             :         ~FormControllerHelper();
     214             : 
     215             :         // XFeatureInvalidation
     216             :         virtual void SAL_CALL invalidateFeatures( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& Features ) throw (::com::sun::star::uno::RuntimeException);
     217             :         virtual void SAL_CALL invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException);
     218             : 
     219             :         // XSQLErrorListener
     220             :         virtual void SAL_CALL errorOccured( const ::com::sun::star::sdb::SQLErrorEvent& _Event ) throw (::com::sun::star::uno::RuntimeException);
     221             : 
     222             :         // XEventListener
     223             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
     224             : 
     225             :     private:
     226             :         enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD };
     227             : 
     228             :         bool    impl_operateForm_nothrow(
     229             :                     const FormOperation _eWhat,
     230             :                     const sal_Int16 _nFeature,  /* ignore for COMMIT_* */
     231             :                     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments /* ignore except for EXECUTE_ARGS */
     232             :                 ) const;
     233           0 :         bool    impl_operateForm_nothrow( const FormOperation _eWhat ) const
     234             :         {
     235           0 :             return impl_operateForm_nothrow( _eWhat, 0, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
     236             :         }
     237             :         bool    impl_operateForm_nothrow( const sal_Int16 _nFeature ) const
     238             :         {
     239             :             return impl_operateForm_nothrow( EXECUTE, _nFeature, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
     240             :         }
     241             : 
     242             :     private:
     243             :         FormControllerHelper();                                         // never implemented
     244             :         FormControllerHelper( const FormControllerHelper& );            // never implemented
     245             :         FormControllerHelper& operator=( const FormControllerHelper& ); // never implemented
     246             :     };
     247             : 
     248             : //........................................................................
     249             : }   // namespace svx
     250             : //........................................................................
     251             : 
     252             : #endif // SVX_FORMCONTROLLING_HXX
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10