LCOV - code coverage report
Current view: top level - forms/source/runtime - formoperations.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 24 87.5 %
Date: 2012-08-25 Functions: 7 12 58.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.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 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                 :            : 
      33                 :            : #include <comphelper/componentcontext.hxx>
      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                 :            :         ::comphelper::ComponentContext                                                          m_aContext;
      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::lang::XMultiServiceFactory >& _rxContext );
      82                 :            : 
      83                 :            :         // XServiceInfo - static versions
      84                 :            :         static ::rtl::OUString getImplementationName_Static(  ) throw(::com::sun::star::uno::RuntimeException);
      85                 :            :         static ::com::sun::star::uno::Sequence< ::rtl::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                 :         56 :         struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
      90                 :            : 
      91                 :         28 :         inline void enterMethod( MethodAccess ) const
      92                 :            :         {
      93                 :         28 :             m_aMutex.acquire();
      94                 :         28 :             impl_checkDisposed_throw();
      95                 :            :         #ifdef DBG_UTIL
      96                 :            :             ++m_nMethodNestingLevel;
      97                 :            :         #endif
      98                 :         28 :         }
      99                 :            : 
     100                 :         28 :         inline void leaveMethod( MethodAccess ) const
     101                 :            :         {
     102                 :         28 :             m_aMutex.release();
     103                 :            :         #ifdef DBG_UTIL
     104                 :            :             --m_nMethodNestingLevel;
     105                 :            :         #endif
     106                 :         28 :         }
     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 ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
     116                 :            :         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
     117                 :            :         virtual ::com::sun::star::uno::Sequence< ::rtl::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                 :         28 :         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                 :            :         /// typedef for member method of this class
     301                 :            :         typedef void (FormOperations::*Action)( const void* ) const;
     302                 :            : 
     303                 :            :         /** calls a member function, catches SQLExceptions, extends them with additional context information,
     304                 :            :             and rethrows them
     305                 :            : 
     306                 :            :             @param _pAction
     307                 :            :                 the member function to call
     308                 :            :             @param _pParam
     309                 :            :                 the parameters to pass to the member function
     310                 :            :             @param _nErrorResourceId
     311                 :            :                 the id of the resources string to use as error message
     312                 :            :         */
     313                 :            :         void        impl_doActionInSQLContext_throw( Action _pAction, const void* _pParam, sal_uInt16 _nErrorResourceId ) const;
     314                 :            : 
     315                 :            :         // parameter structure for appendOrderByColumn
     316                 :          0 :         struct param_appendOrderByColumn
     317                 :            :         {
     318                 :            :             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
     319                 :            :                         xField;
     320                 :            :             bool        bUp;
     321                 :            :         };
     322                 :            :         void        impl_appendOrderByColumn_throw( const void* _pActionParam ) const;
     323                 :            : 
     324                 :            :         // parameter structure for appendFilterByColumn
     325                 :          0 :         struct param_appendFilterByColumn
     326                 :            :         {
     327                 :            :             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
     328                 :            :                         xField;
     329                 :            :         };
     330                 :            :         void        impl_appendFilterByColumn_throw( const void* _pActionParam ) const;
     331                 :            : 
     332                 :            :     private:
     333                 :            :         FormOperations();                                   // never implemented
     334                 :            :         FormOperations( const FormOperations& );            // never implemented
     335                 :            :         FormOperations& operator=( const FormOperations& ); // never implemented
     336                 :            : 
     337                 :            :     public:
     338                 :            :         class MethodGuard
     339                 :            :         {
     340                 :            :             FormOperations& m_rOwner;
     341                 :            :             bool            m_bCleared;
     342                 :            : 
     343                 :            :         public:
     344                 :         28 :             inline MethodGuard( FormOperations& _rOwner )
     345                 :            :                 :m_rOwner( _rOwner )
     346                 :         28 :                 ,m_bCleared( false )
     347                 :            :             {
     348         [ +  - ]:         28 :                 m_rOwner.enterMethod( FormOperations::MethodAccess() );
     349                 :         28 :             }
     350                 :            : 
     351                 :         28 :             inline ~MethodGuard()
     352                 :            :             {
     353                 :         28 :                 clear();
     354                 :         28 :             }
     355                 :            : 
     356                 :         28 :             inline void clear()
     357                 :            :             {
     358         [ +  - ]:         28 :                 if ( !m_bCleared )
     359         [ +  - ]:         28 :                     m_rOwner.leaveMethod( FormOperations::MethodAccess() );
     360                 :         28 :                 m_bCleared = true;
     361                 :         28 :             }
     362                 :            :         };
     363                 :            :     };
     364                 :            : 
     365                 :            : //........................................................................
     366                 :            : } // namespace frm
     367                 :            : //........................................................................
     368                 :            : 
     369                 :            : #endif // FORMS_FORMOPERATIONS_HXX
     370                 :            : 
     371                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10