merge the formfield patch from ooo-build
[ooovba.git] / forms / source / runtime / formoperations.hxx
blob4f1de98aee928ebe2e1ef6f18bf8ec857d461b58
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formoperations.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef FORMS_FORMOPERATIONS_HXX
32 #define FORMS_FORMOPERATIONS_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/form/runtime/XFormOperations.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/form/XForm.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/form/XLoadable.hpp>
40 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
41 #include <com/sun/star/util/XModifyListener.hpp>
42 #include <com/sun/star/container/XIndexAccess.hpp>
43 #include <com/sun/star/lang/XInitialization.hpp>
44 /** === end UNO includes === **/
46 #include <comphelper/componentcontext.hxx>
48 #include <cppuhelper/basemutex.hxx>
49 #include <cppuhelper/compbase6.hxx>
51 //........................................................................
52 namespace frm
54 //........................................................................
56 //====================================================================
57 //= FormOperations
58 //====================================================================
59 typedef ::cppu::WeakComponentImplHelper6 < ::com::sun::star::form::runtime::XFormOperations
60 , ::com::sun::star::lang::XInitialization
61 , ::com::sun::star::lang::XServiceInfo
62 , ::com::sun::star::beans::XPropertyChangeListener
63 , ::com::sun::star::util::XModifyListener
64 , ::com::sun::star::sdbc::XRowSetListener
65 > FormOperations_Base;
67 class FormOperations :public ::cppu::BaseMutex
68 ,public FormOperations_Base
70 public:
71 class MethodGuard;
73 private:
74 ::comphelper::ComponentContext m_aContext;
75 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormController > m_xController;
76 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xCursor;
77 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > m_xUpdateCursor;
78 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xCursorProperties;
79 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > m_xLoadableForm;
80 ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation >
81 m_xFeatureInvalidation;
82 mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
83 m_xParser;
85 bool m_bInitializedParser;
86 bool m_bActiveControlModified;
87 bool m_bConstructed;
88 #ifdef DBG_UTIL
89 mutable long
90 m_nMethodNestingLevel;
91 #endif
93 public:
94 FormOperations( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxContext );
96 // XServiceInfo - static versions
97 static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException);
98 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
99 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
100 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
102 struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
104 inline void enterMethod( MethodAccess ) const
106 m_aMutex.acquire();
107 impl_checkDisposed_throw();
108 #ifdef DBG_UTIL
109 ++m_nMethodNestingLevel;
110 #endif
113 inline void leaveMethod( MethodAccess ) const
115 m_aMutex.release();
116 #ifdef DBG_UTIL
117 --m_nMethodNestingLevel;
118 #endif
121 protected:
122 virtual ~FormOperations();
124 // XInitialization
125 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);
127 // XServiceInfo
128 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
129 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
130 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
132 // XFormOperations
133 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > SAL_CALL getCursor() throw (::com::sun::star::uno::RuntimeException);
134 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() throw (::com::sun::star::uno::RuntimeException);
135 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormController > SAL_CALL getController() throw (::com::sun::star::uno::RuntimeException);
136 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() throw (::com::sun::star::uno::RuntimeException);
137 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);
138 virtual ::com::sun::star::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException);
139 virtual ::sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException);
140 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);
141 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);
142 virtual ::sal_Bool SAL_CALL commitCurrentRecord(::sal_Bool & RecordInserted) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException);
143 virtual ::sal_Bool SAL_CALL commitCurrentControl() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException);
144 virtual ::sal_Bool SAL_CALL isInsertionRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException);
145 virtual ::sal_Bool SAL_CALL isModifiedRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException);
147 // XRowSetListener
148 virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
149 virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
150 virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
152 // XModifyListener
153 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException );
155 // XPropertyChangeListener
156 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
158 // XEventListener
159 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
161 // XComponent/OComponentHelper
162 virtual void SAL_CALL disposing();
164 private:
165 // service constructors
166 void createWithFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormController >& _rxController );
167 void createWithForm( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
169 /** determines whether or not we're already disposed
171 inline bool impl_isDisposed_nothrow() const { return !m_xCursor.is(); }
173 /** checks whether the instance is already disposed, and throws an exception if so
175 void impl_checkDisposed_throw() const;
177 /** initializes the instance after m_xController has been set
178 @precond
179 m_xController is not <NULL/>
181 void impl_initFromController_throw();
183 /** initializes the instance after m_xCursor has been set
184 @precond
185 m_xCursor is not <NULL/>
187 void impl_initFromForm_throw();
189 /// invalidate the full palette of features which we know
190 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
192 /** invalidate the features which depend on the "modified" state of the current control
193 of our controller
195 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
197 /** ensures that our parse is initialized, or at least that we attempted to do so
198 @precond
199 we're not disposed
201 void impl_ensureInitializedParser_nothrow();
203 /// disposes our parser, if we have one
204 void impl_disposeParser_nothrow();
206 /** determines whether our cursor can be moved left
207 @precond hasCursor()
209 bool impl_canMoveLeft_throw() const;
211 /** determines whether our cursor can be moved right
212 @precond hasCursor()
214 bool impl_canMoveRight_throw() const;
216 /// determines whether we're positioned on the insertion row
217 bool impl_isInsertionRow_throw() const;
219 /// retrieves the RowCount property of the form
220 sal_Int32 impl_getRowCount_throw() const;
222 /// retrieves the RowCountFinal property of the form
223 bool impl_isRowCountFinal_throw() const;
225 /// retrieves the IsModified property of the form
226 bool impl_isModifiedRow_throw() const;
228 /// determines whether we can parse the query of our form
229 bool impl_isParseable_throw() const;
231 /// determines if we have an active filter or order condition
232 bool impl_hasFilterOrOrder_throw() const;
234 /// determines whether our form is in "insert-only" mode
235 bool impl_isInsertOnlyForm_throw() const;
237 /** retrieces the column to which the current control of our controller is bound
238 @precond
239 m_xController.is()
241 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
242 impl_getCurrentBoundField_nothrow( ) const;
244 /** returns the control model of the current control
246 If the current control is a grid control, then the returned model is the
247 model of the current <em>column</em> in the grid.
249 @precond
250 m_xController.is()
252 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
253 impl_getCurrentControlModel_throw() const;
255 /// determines if we have a valid cursor
256 inline bool impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
258 /** determines the model position from a grid control column's view position
260 A grid control can have columns which are currently hidden, so the index of a
261 column in the view is not necessarily the same as its index in the model.
263 sal_Int16 impl_gridView2ModelPos_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos ) const;
265 /** moves our cursor one position to the left, caring for different possible
266 cursor states.
268 Before the movement is done, the current row is saved, if necessary.
270 @precond
271 canMoveLeft()
273 bool impl_moveLeft_throw() const;
275 /** moves our cursor one position to the right, caring for different possible
276 cursor states.
278 Before the movement is done, the current row is saved, if necessary.
280 @precond
281 canMoveRight()
283 bool impl_moveRight_throw( ) const;
285 /** impl-version of commitCurrentRecord, which can be called without caring for
286 an output parameter, and within const-contexts
288 @precond
289 our mutex is locked
291 bool impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = NULL ) const;
293 /** impl-version of commitCurrentControl, which can be called in const-contexts
295 @precond
296 our mutex is locked
298 bool impl_commitCurrentControl_throw() const;
300 /// resets all control models in our own form
301 void impl_resetAllControls_nothrow() const;
303 /// executes the "auto sort ascending" and "auto sort descending" features
304 void impl_executeAutoSort_throw( bool _bUp ) const;
306 /// executes the "auto filter" feature
307 void impl_executeAutoFilter_throw( ) const;
309 /// executes the interactive sort resp. filter feature
310 void impl_executeFilterOrSort_throw( bool _bFilter ) const;
312 private:
313 /// typedef for member method of this class
314 typedef void (FormOperations::*Action)( const void* ) const;
316 /** calls a member function, catches SQLExceptions, extends them with additional context information,
317 and rethrows them
319 @param _pAction
320 the member function to call
321 @param _pParam
322 the parameters to pass to the member function
323 @param _nErrorResourceId
324 the id of the resources string to use as error message
326 void impl_doActionInSQLContext_throw( Action _pAction, const void* _pParam, sal_uInt16 _nErrorResourceId ) const;
328 // parameter structure for appendOrderByColumn
329 struct param_appendOrderByColumn
331 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
332 xField;
333 bool bUp;
335 void impl_appendOrderByColumn_throw( const void* _pActionParam ) const;
337 // parameter structure for appendFilterByColumn
338 struct param_appendFilterByColumn
340 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
341 xField;
343 void impl_appendFilterByColumn_throw( const void* _pActionParam ) const;
345 private:
346 FormOperations(); // never implemented
347 FormOperations( const FormOperations& ); // never implemented
348 FormOperations& operator=( const FormOperations& ); // never implemented
350 public:
351 class MethodGuard
353 FormOperations& m_rOwner;
354 bool m_bCleared;
356 public:
357 inline MethodGuard( FormOperations& _rOwner )
358 :m_rOwner( _rOwner )
359 ,m_bCleared( false )
361 m_rOwner.enterMethod( FormOperations::MethodAccess() );
364 inline ~MethodGuard()
366 clear();
369 inline void clear()
371 if ( !m_bCleared )
372 m_rOwner.leaveMethod( FormOperations::MethodAccess() );
373 m_bCleared = true;
378 //........................................................................
379 } // namespace frm
380 //........................................................................
382 #endif // FORMS_FORMOPERATIONS_HXX