LCOV - code coverage report
Current view: top level - libreoffice/forms/source/runtime - formoperations.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 32 65.6 %
Date: 2012-12-17 Functions: 7 16 43.8 %
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 FORMS_FORMOPERATIONS_HXX
      21             : #define FORMS_FORMOPERATIONS_HXX
      22             : 
      23             : #include <com/sun/star/form/runtime/XFormOperations.hpp>
      24             : #include <com/sun/star/lang/XServiceInfo.hpp>
      25             : #include <com/sun/star/form/XForm.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/form/XLoadable.hpp>
      28             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      29             : #include <com/sun/star/util/XModifyListener.hpp>
      30             : #include <com/sun/star/container/XIndexAccess.hpp>
      31             : #include <com/sun/star/lang/XInitialization.hpp>
      32             : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
      33             : 
      34             : #include <comphelper/componentcontext.hxx>
      35             : 
      36             : #include <cppuhelper/basemutex.hxx>
      37             : #include <cppuhelper/compbase6.hxx>
      38             : 
      39             : //........................................................................
      40             : namespace frm
      41             : {
      42             : //........................................................................
      43             : 
      44             :     //====================================================================
      45             :     //= FormOperations
      46             :     //====================================================================
      47             :     typedef ::cppu::WeakComponentImplHelper6    <   ::com::sun::star::form::runtime::XFormOperations
      48             :                                                 ,   ::com::sun::star::lang::XInitialization
      49             :                                                 ,   ::com::sun::star::lang::XServiceInfo
      50             :                                                 ,   ::com::sun::star::beans::XPropertyChangeListener
      51             :                                                 ,   ::com::sun::star::util::XModifyListener
      52             :                                                 ,   ::com::sun::star::sdbc::XRowSetListener
      53             :                                                 >   FormOperations_Base;
      54             : 
      55             :     class FormOperations    :public ::cppu::BaseMutex
      56             :                             ,public FormOperations_Base
      57             :     {
      58             :     public:
      59             :         class MethodGuard;
      60             : 
      61             :     private:
      62             :         ::comphelper::ComponentContext                                                          m_aContext;
      63             :         ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >    m_xController;
      64             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >                     m_xCursor;
      65             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate >            m_xUpdateCursor;
      66             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >               m_xCursorProperties;
      67             :         ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >                   m_xLoadableForm;
      68             :         ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation >
      69             :                                                                                                 m_xFeatureInvalidation;
      70             :         mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
      71             :                                                                                                 m_xParser;
      72             : 
      73             :         bool    m_bInitializedParser;
      74             :         bool    m_bActiveControlModified;
      75             :         bool    m_bConstructed;
      76             :     #ifdef DBG_UTIL
      77             :         mutable long
      78             :                 m_nMethodNestingLevel;
      79             :     #endif
      80             : 
      81             :     public:
      82             :         FormOperations( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxContext );
      83             : 
      84             :         // XServiceInfo - static versions
      85             :         static ::rtl::OUString getImplementationName_Static(  ) throw(::com::sun::star::uno::RuntimeException);
      86             :         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
      87             :         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
      88             :                         Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
      89             : 
      90          22 :         struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
      91             : 
      92          11 :         inline void enterMethod( MethodAccess ) const
      93             :         {
      94          11 :             m_aMutex.acquire();
      95          11 :             impl_checkDisposed_throw();
      96             :         #ifdef DBG_UTIL
      97             :             ++m_nMethodNestingLevel;
      98             :         #endif
      99          11 :         }
     100             : 
     101          11 :         inline void leaveMethod( MethodAccess ) const
     102             :         {
     103          11 :             m_aMutex.release();
     104             :         #ifdef DBG_UTIL
     105             :             --m_nMethodNestingLevel;
     106             :         #endif
     107          11 :         }
     108             : 
     109             :     protected:
     110             :         virtual ~FormOperations();
     111             : 
     112             :         // XInitialization
     113             :         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);
     114             : 
     115             :         // XServiceInfo
     116             :         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
     117             :         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
     118             :         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
     119             : 
     120             :         // XFormOperations
     121             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > SAL_CALL getCursor() throw (::com::sun::star::uno::RuntimeException);
     122             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() throw (::com::sun::star::uno::RuntimeException);
     123             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > SAL_CALL getController() throw (::com::sun::star::uno::RuntimeException);
     124             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() throw (::com::sun::star::uno::RuntimeException);
     125             :         virtual void SAL_CALL setFeatureInvalidation(const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > & the_value) throw (::com::sun::star::uno::RuntimeException);
     126             :         virtual ::com::sun::star::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException);
     127             :         virtual ::sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException);
     128             :         virtual void SAL_CALL execute(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::WrappedTargetException);
     129             :         virtual void SAL_CALL executeWithArguments(::sal_Int16 Feature, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::WrappedTargetException);
     130             :         virtual ::sal_Bool SAL_CALL commitCurrentRecord(::sal_Bool & RecordInserted) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException);
     131             :         virtual ::sal_Bool SAL_CALL commitCurrentControl() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException);
     132             :         virtual ::sal_Bool SAL_CALL isInsertionRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException);
     133             :         virtual ::sal_Bool SAL_CALL isModifiedRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException);
     134             : 
     135             :         // XRowSetListener
     136             :         virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
     137             :         virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
     138             :         virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
     139             : 
     140             :         // XModifyListener
     141             :         virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException );
     142             : 
     143             :         // XPropertyChangeListener
     144             :         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
     145             : 
     146             :         // XEventListener
     147             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
     148             : 
     149             :         // XComponent/OComponentHelper
     150             :         virtual void SAL_CALL disposing();
     151             : 
     152             :     private:
     153             :         // service constructors
     154             :         void    createWithFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
     155             :         void    createWithForm( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
     156             : 
     157             :         /** determines whether or not we're already disposed
     158             :         */
     159          11 :         inline bool impl_isDisposed_nothrow() const { return !m_xCursor.is(); }
     160             : 
     161             :         /** checks whether the instance is already disposed, and throws an exception if so
     162             :         */
     163             :         void        impl_checkDisposed_throw() const;
     164             : 
     165             :         /** initializes the instance after m_xController has been set
     166             :             @precond
     167             :                 m_xController is not <NULL/>
     168             :         */
     169             :         void        impl_initFromController_throw();
     170             : 
     171             :         /** initializes the instance after m_xCursor has been set
     172             :             @precond
     173             :                 m_xCursor is not <NULL/>
     174             :         */
     175             :         void        impl_initFromForm_throw();
     176             : 
     177             :         /// invalidate the full palette of features which we know
     178             :         void        impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
     179             : 
     180             :         /** invalidate the features which depend on the "modified" state of the current control
     181             :             of our controller
     182             :         */
     183             :         void        impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
     184             : 
     185             :         /** ensures that our parse is initialized, or at least that we attempted to do so
     186             :             @precond
     187             :                 we're not disposed
     188             :         */
     189             :         void        impl_ensureInitializedParser_nothrow();
     190             : 
     191             :         /// disposes our parser, if we have one
     192             :         void        impl_disposeParser_nothrow();
     193             : 
     194             :         /** determines whether our cursor can be moved left
     195             :             @precond hasCursor()
     196             :         */
     197             :         bool        impl_canMoveLeft_throw() const;
     198             : 
     199             :         /** determines whether our cursor can be moved right
     200             :             @precond hasCursor()
     201             :         */
     202             :         bool        impl_canMoveRight_throw() const;
     203             : 
     204             :         /// determines whether we're positioned on the insertion row
     205             :         bool        impl_isInsertionRow_throw() const;
     206             : 
     207             :         /// retrieves the RowCount property of the form
     208             :         sal_Int32   impl_getRowCount_throw() const;
     209             : 
     210             :         /// retrieves the RowCountFinal property of the form
     211             :         bool        impl_isRowCountFinal_throw() const;
     212             : 
     213             :         /// retrieves the IsModified property of the form
     214             :         bool        impl_isModifiedRow_throw() const;
     215             : 
     216             :         /// determines whether we can parse the query of our form
     217             :         bool        impl_isParseable_throw() const;
     218             : 
     219             :         /// determines if we have an active filter or order condition
     220             :         bool        impl_hasFilterOrOrder_throw() const;
     221             : 
     222             :         /// determines whether our form is in "insert-only" mode
     223             :         bool        impl_isInsertOnlyForm_throw() const;
     224             : 
     225             :         /** retrieces the column to which the current control of our controller is bound
     226             :             @precond
     227             :                 m_xController.is()
     228             :         */
     229             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
     230             :                     impl_getCurrentBoundField_nothrow( ) const;
     231             : 
     232             :         /** returns the control model of the current control
     233             : 
     234             :             If the current control is a grid control, then the returned model is the
     235             :             model of the current <em>column</em> in the grid.
     236             : 
     237             :             @precond
     238             :                 m_xController.is()
     239             :         */
     240             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
     241             :                     impl_getCurrentControlModel_throw() const;
     242             : 
     243             :         /// determines if we have a valid cursor
     244           0 :         inline  bool    impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
     245             : 
     246             :         /** determines the model position from a grid control column's view position
     247             : 
     248             :             A grid control can have columns which are currently hidden, so the index of a
     249             :             column in the view is not necessarily the same as its index in the model.
     250             :         */
     251             :         sal_Int16   impl_gridView2ModelPos_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos ) const;
     252             : 
     253             :         /** moves our cursor one position to the left, caring for different possible
     254             :             cursor states.
     255             : 
     256             :             Before the movement is done, the current row is saved, if necessary.
     257             : 
     258             :             @precond
     259             :                 canMoveLeft()
     260             :         */
     261             :         bool        impl_moveLeft_throw() const;
     262             : 
     263             :         /** moves our cursor one position to the right, caring for different possible
     264             :             cursor states.
     265             : 
     266             :             Before the movement is done, the current row is saved, if necessary.
     267             : 
     268             :             @precond
     269             :                 canMoveRight()
     270             :         */
     271             :         bool        impl_moveRight_throw( ) const;
     272             : 
     273             :         /** impl-version of commitCurrentRecord, which can be called without caring for
     274             :             an output parameter, and within const-contexts
     275             : 
     276             :             @precond
     277             :                 our mutex is locked
     278             :         */
     279             :         bool        impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = NULL ) const;
     280             : 
     281             :         /** impl-version of commitCurrentControl, which can be called in const-contexts
     282             : 
     283             :             @precond
     284             :                 our mutex is locked
     285             :         */
     286             :         bool        impl_commitCurrentControl_throw() const;
     287             : 
     288             :         /// resets all control models in our own form
     289             :         void        impl_resetAllControls_nothrow() const;
     290             : 
     291             :         /// executes the "auto sort ascending" and "auto sort descending" features
     292             :         void        impl_executeAutoSort_throw( bool _bUp ) const;
     293             : 
     294             :         /// executes the "auto filter" feature
     295             :         void        impl_executeAutoFilter_throw( ) const;
     296             : 
     297             :         /// executes the interactive sort resp. filter feature
     298             :         void        impl_executeFilterOrSort_throw( bool _bFilter ) const;
     299             : 
     300             :     private:
     301             :         /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
     302             :             and rethrows them
     303             : 
     304             :             @param f
     305             :                 a fuctionoid with no arguments to do the work
     306             :             @param _nErrorResourceId
     307             :                 the id of the resources string to use as error message
     308             :         */
     309             :         template < typename FunctObj >
     310             :         void        impl_doActionInSQLContext_throw( FunctObj f, sal_uInt16 _nErrorResourceId ) const;
     311             : 
     312             :         // functionoid to call appendOrderByColumn
     313           0 :         class impl_appendOrderByColumn_throw
     314             :         {
     315             :         public:
     316           0 :             impl_appendOrderByColumn_throw(const FormOperations *pFO,
     317             :                                            ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField,
     318             :                                            bool bUp)
     319             :                 : m_pFO(pFO)
     320             :                 , m_xField(xField)
     321           0 :                 , m_bUp(bUp)
     322           0 :             {};
     323             : 
     324           0 :             void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
     325             :         private:
     326             :             const FormOperations *m_pFO;
     327             :             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
     328             :             bool m_bUp;
     329             :         };
     330             : 
     331             :         // functionoid to call appendFilterByColumn
     332           0 :         class impl_appendFilterByColumn_throw
     333             :         {
     334             :         public:
     335           0 :             impl_appendFilterByColumn_throw(const FormOperations *pFO,
     336             :                                             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField)
     337             :                 : m_pFO(pFO)
     338           0 :                 , m_xField(xField)
     339           0 :             {};
     340             : 
     341           0 :             void operator()() { m_pFO->m_xParser->appendFilterByColumn( m_xField, sal_True, ::com::sun::star::sdb::SQLFilterOperator::EQUAL ); }
     342             :         private:
     343             :             const FormOperations *m_pFO;
     344             :             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
     345             :         };
     346             : 
     347             :     private:
     348             :         FormOperations();                                   // never implemented
     349             :         FormOperations( const FormOperations& );            // never implemented
     350             :         FormOperations& operator=( const FormOperations& ); // never implemented
     351             : 
     352             :     public:
     353             :         class MethodGuard
     354             :         {
     355             :             FormOperations& m_rOwner;
     356             :             bool            m_bCleared;
     357             : 
     358             :         public:
     359          11 :             inline MethodGuard( FormOperations& _rOwner )
     360             :                 :m_rOwner( _rOwner )
     361          11 :                 ,m_bCleared( false )
     362             :             {
     363          11 :                 m_rOwner.enterMethod( FormOperations::MethodAccess() );
     364          11 :             }
     365             : 
     366          11 :             inline ~MethodGuard()
     367             :             {
     368          11 :                 clear();
     369          11 :             }
     370             : 
     371          11 :             inline void clear()
     372             :             {
     373          11 :                 if ( !m_bCleared )
     374          11 :                     m_rOwner.leaveMethod( FormOperations::MethodAccess() );
     375          11 :                 m_bCleared = true;
     376          11 :             }
     377             :         };
     378             :     };
     379             : 
     380             : //........................................................................
     381             : } // namespace frm
     382             : //........................................................................
     383             : 
     384             : #endif // FORMS_FORMOPERATIONS_HXX
     385             : 
     386             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10