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

Generated by: LCOV version 1.10