update emoji autocorrect entries from po-files
[LibreOffice.git] / forms / source / runtime / formoperations.hxx
blob9635af010566ede2f970deee5b87f6f164cae749
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
21 #define INCLUDED_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
23 #include <com/sun/star/form/runtime/XFormOperations.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/form/XForm.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/form/XLoadable.hpp>
29 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
30 #include <com/sun/star/util/XModifyListener.hpp>
31 #include <com/sun/star/container/XIndexAccess.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <cppuhelper/basemutex.hxx>
37 #include <cppuhelper/compbase6.hxx>
40 namespace frm
45 //= FormOperations
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;
55 class FormOperations :public ::cppu::BaseMutex
56 ,public FormOperations_Base
58 public:
59 class MethodGuard;
61 private:
62 css::uno::Reference<css::uno::XComponentContext> m_xContext;
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;
73 bool m_bInitializedParser;
74 bool m_bActiveControlModified;
75 bool m_bConstructed;
76 #ifdef DBG_UTIL
77 mutable long
78 m_nMethodNestingLevel;
79 #endif
81 public:
82 FormOperations( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
84 // XServiceInfo - static versions
85 static OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException);
86 static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
88 struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
90 inline void enterMethod( MethodAccess ) const
92 m_aMutex.acquire();
93 impl_checkDisposed_throw();
94 #ifdef DBG_UTIL
95 ++m_nMethodNestingLevel;
96 #endif
99 inline void leaveMethod( MethodAccess ) const
101 m_aMutex.release();
102 #ifdef DBG_UTIL
103 --m_nMethodNestingLevel;
104 #endif
107 protected:
108 virtual ~FormOperations();
110 // XInitialization
111 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, std::exception) SAL_OVERRIDE;
113 // XServiceInfo
114 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 // XFormOperations
119 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > SAL_CALL getCursor() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > SAL_CALL getController() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
123 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, std::exception) SAL_OVERRIDE;
124 virtual ::com::sun::star::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
125 virtual sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
126 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, std::exception) SAL_OVERRIDE;
127 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, std::exception) SAL_OVERRIDE;
128 virtual sal_Bool SAL_CALL commitCurrentRecord(sal_Bool & RecordInserted) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException, std::exception) SAL_OVERRIDE;
129 virtual sal_Bool SAL_CALL commitCurrentControl() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException, std::exception) SAL_OVERRIDE;
130 virtual sal_Bool SAL_CALL isInsertionRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
131 virtual sal_Bool SAL_CALL isModifiedRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
133 // XRowSetListener
134 virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
136 virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 // XModifyListener
139 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
141 // XPropertyChangeListener
142 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 // XEventListener
145 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 // XComponent/OComponentHelper
148 virtual void SAL_CALL disposing() SAL_OVERRIDE;
150 private:
151 // service constructors
152 void createWithFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
153 void createWithForm( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
155 /** determines whether or not we're already disposed
157 inline bool impl_isDisposed_nothrow() const { return !m_xCursor.is(); }
159 /** checks whether the instance is already disposed, and throws an exception if so
161 void impl_checkDisposed_throw() const;
163 /** initializes the instance after m_xController has been set
164 @precond
165 m_xController is not <NULL/>
167 void impl_initFromController_throw();
169 /** initializes the instance after m_xCursor has been set
170 @precond
171 m_xCursor is not <NULL/>
173 void impl_initFromForm_throw();
175 /// invalidate the full palette of features which we know
176 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
178 /** invalidate the features which depend on the "modified" state of the current control
179 of our controller
181 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
183 /** ensures that our parse is initialized, or at least that we attempted to do so
184 @precond
185 we're not disposed
187 void impl_ensureInitializedParser_nothrow();
189 /// disposes our parser, if we have one
190 void impl_disposeParser_nothrow();
192 /** determines whether our cursor can be moved left
193 @precond hasCursor()
195 bool impl_canMoveLeft_throw() const;
197 /** determines whether our cursor can be moved right
198 @precond hasCursor()
200 bool impl_canMoveRight_throw() const;
202 /// determines whether we're positioned on the insertion row
203 bool impl_isInsertionRow_throw() const;
205 /// retrieves the RowCount property of the form
206 sal_Int32 impl_getRowCount_throw() const;
208 /// retrieves the RowCountFinal property of the form
209 bool impl_isRowCountFinal_throw() const;
211 /// retrieves the IsModified property of the form
212 bool impl_isModifiedRow_throw() const;
214 /// determines whether we can parse the query of our form
215 bool impl_isParseable_throw() const;
217 /// determines if we have an active filter or order condition
218 bool impl_hasFilterOrOrder_throw() const;
220 /// determines whether our form is in "insert-only" mode
221 bool impl_isInsertOnlyForm_throw() const;
223 /** retrieces the column to which the current control of our controller is bound
224 @precond
225 m_xController.is()
227 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
228 impl_getCurrentBoundField_nothrow( ) const;
230 /** returns the control model of the current control
232 If the current control is a grid control, then the returned model is the
233 model of the current <em>column</em> in the grid.
235 @precond
236 m_xController.is()
238 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
239 impl_getCurrentControlModel_throw() const;
241 /// determines if we have a valid cursor
242 inline bool impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
244 /** determines the model position from a grid control column's view position
246 A grid control can have columns which are currently hidden, so the index of a
247 column in the view is not necessarily the same as its index in the model.
249 static sal_Int16 impl_gridView2ModelPos_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos );
251 /** moves our cursor one position to the left, caring for different possible
252 cursor states.
254 Before the movement is done, the current row is saved, if necessary.
256 @precond
257 canMoveLeft()
259 bool impl_moveLeft_throw() const;
261 /** moves our cursor one position to the right, caring for different possible
262 cursor states.
264 Before the movement is done, the current row is saved, if necessary.
266 @precond
267 canMoveRight()
269 bool impl_moveRight_throw( ) const;
271 /** impl-version of commitCurrentRecord, which can be called without caring for
272 an output parameter, and within const-contexts
274 @precond
275 our mutex is locked
277 bool impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = NULL ) const;
279 /** impl-version of commitCurrentControl, which can be called in const-contexts
281 @precond
282 our mutex is locked
284 bool impl_commitCurrentControl_throw() const;
286 /// resets all control models in our own form
287 void impl_resetAllControls_nothrow() const;
289 /// executes the "auto sort ascending" and "auto sort descending" features
290 void impl_executeAutoSort_throw( bool _bUp ) const;
292 /// executes the "auto filter" feature
293 void impl_executeAutoFilter_throw( ) const;
295 /// executes the interactive sort resp. filter feature
296 void impl_executeFilterOrSort_throw( bool _bFilter ) const;
298 private:
299 /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
300 and rethrows them
302 @param f
303 a fuctionoid with no arguments to do the work
304 @param _nErrorResourceId
305 the id of the resources string to use as error message
307 template < typename FunctObj >
308 void impl_doActionInSQLContext_throw( FunctObj f, sal_uInt16 _nErrorResourceId ) const;
310 // functionoid to call appendOrderByColumn
311 class impl_appendOrderByColumn_throw
313 public:
314 impl_appendOrderByColumn_throw(const FormOperations *pFO,
315 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField,
316 bool bUp)
317 : m_pFO(pFO)
318 , m_xField(xField)
319 , m_bUp(bUp)
322 void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
323 private:
324 const FormOperations *m_pFO;
325 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
326 bool m_bUp;
329 // functionoid to call appendFilterByColumn
330 class impl_appendFilterByColumn_throw
332 public:
333 impl_appendFilterByColumn_throw(const FormOperations *pFO,
334 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField)
335 : m_pFO(pFO)
336 , m_xField(xField)
339 void operator()() { m_pFO->m_xParser->appendFilterByColumn( m_xField, sal_True, ::com::sun::star::sdb::SQLFilterOperator::EQUAL ); }
340 private:
341 const FormOperations *m_pFO;
342 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
345 private:
346 FormOperations( const FormOperations& ) SAL_DELETED_FUNCTION;
347 FormOperations& operator=( const FormOperations& ) SAL_DELETED_FUNCTION;
349 public:
350 class MethodGuard
352 FormOperations& m_rOwner;
353 bool m_bCleared;
355 public:
356 inline MethodGuard( FormOperations& _rOwner )
357 :m_rOwner( _rOwner )
358 ,m_bCleared( false )
360 m_rOwner.enterMethod( FormOperations::MethodAccess() );
363 inline ~MethodGuard()
365 clear();
368 inline void clear()
370 if ( !m_bCleared )
371 m_rOwner.leaveMethod( FormOperations::MethodAccess() );
372 m_bCleared = true;
378 } // namespace frm
381 #endif // INCLUDED_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */