1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/compbase.hxx>
46 typedef ::cppu::WeakComponentImplHelper
< css::form::runtime::XFormOperations
47 , css::lang::XInitialization
48 , css::lang::XServiceInfo
49 , css::beans::XPropertyChangeListener
50 , css::util::XModifyListener
51 , css::sdbc::XRowSetListener
52 > FormOperations_Base
;
54 class FormOperations
:public ::cppu::BaseMutex
55 ,public FormOperations_Base
61 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
62 css::uno::Reference
< css::form::runtime::XFormController
> m_xController
;
63 css::uno::Reference
< css::sdbc::XRowSet
> m_xCursor
;
64 css::uno::Reference
< css::sdbc::XResultSetUpdate
> m_xUpdateCursor
;
65 css::uno::Reference
< css::beans::XPropertySet
> m_xCursorProperties
;
66 css::uno::Reference
< css::form::XLoadable
> m_xLoadableForm
;
67 css::uno::Reference
< css::form::runtime::XFeatureInvalidation
> m_xFeatureInvalidation
;
68 mutable css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> m_xParser
;
70 bool m_bInitializedParser
;
71 bool m_bActiveControlModified
;
75 m_nMethodNestingLevel
;
79 explicit FormOperations( const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
81 // XServiceInfo - static versions
82 static OUString
getImplementationName_Static( ) throw(css::uno::RuntimeException
);
83 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static( ) throw(css::uno::RuntimeException
);
85 struct MethodAccess
{ friend class MethodGuard
; private: MethodAccess() { } };
87 inline void enterMethod( MethodAccess
) const
90 impl_checkDisposed_throw();
92 ++m_nMethodNestingLevel
;
96 inline void leaveMethod( MethodAccess
) const
100 --m_nMethodNestingLevel
;
105 virtual ~FormOperations();
108 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) throw (css::uno::Exception
, css::uno::RuntimeException
, std::exception
) override
;
111 virtual OUString SAL_CALL
getImplementationName( ) throw (css::uno::RuntimeException
, std::exception
) override
;
112 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (css::uno::RuntimeException
, std::exception
) override
;
113 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (css::uno::RuntimeException
, std::exception
) override
;
116 virtual css::uno::Reference
< css::sdbc::XRowSet
> SAL_CALL
getCursor() throw (css::uno::RuntimeException
, std::exception
) override
;
117 virtual css::uno::Reference
< css::sdbc::XResultSetUpdate
> SAL_CALL
getUpdateCursor() throw (css::uno::RuntimeException
, std::exception
) override
;
118 virtual css::uno::Reference
< css::form::runtime::XFormController
> SAL_CALL
getController() throw (css::uno::RuntimeException
, std::exception
) override
;
119 virtual css::uno::Reference
< css::form::runtime::XFeatureInvalidation
> SAL_CALL
getFeatureInvalidation() throw (css::uno::RuntimeException
, std::exception
) override
;
120 virtual void SAL_CALL
setFeatureInvalidation(const css::uno::Reference
< css::form::runtime::XFeatureInvalidation
> & the_value
) throw (css::uno::RuntimeException
, std::exception
) override
;
121 virtual css::form::runtime::FeatureState SAL_CALL
getState(::sal_Int16 Feature
) throw (css::uno::RuntimeException
, std::exception
) override
;
122 virtual sal_Bool SAL_CALL
isEnabled(::sal_Int16 Feature
) throw (css::uno::RuntimeException
, std::exception
) override
;
123 virtual void SAL_CALL
execute(::sal_Int16 Feature
) throw (css::uno::RuntimeException
, css::lang::IllegalArgumentException
, css::sdbc::SQLException
, css::lang::WrappedTargetException
, std::exception
) override
;
124 virtual void SAL_CALL
executeWithArguments(::sal_Int16 Feature
, const css::uno::Sequence
< css::beans::NamedValue
>& Arguments
) throw (css::uno::RuntimeException
, css::lang::IllegalArgumentException
, css::sdbc::SQLException
, css::lang::WrappedTargetException
, std::exception
) override
;
125 virtual sal_Bool SAL_CALL
commitCurrentRecord(sal_Bool
& RecordInserted
) throw (css::uno::RuntimeException
, css::sdbc::SQLException
, std::exception
) override
;
126 virtual sal_Bool SAL_CALL
commitCurrentControl() throw (css::uno::RuntimeException
, css::sdbc::SQLException
, std::exception
) override
;
127 virtual sal_Bool SAL_CALL
isInsertionRow() throw (css::uno::RuntimeException
, css::lang::WrappedTargetException
, std::exception
) override
;
128 virtual sal_Bool SAL_CALL
isModifiedRow() throw (css::uno::RuntimeException
, css::lang::WrappedTargetException
, std::exception
) override
;
131 virtual void SAL_CALL
cursorMoved( const css::lang::EventObject
& event
) throw (css::uno::RuntimeException
, std::exception
) override
;
132 virtual void SAL_CALL
rowChanged( const css::lang::EventObject
& event
) throw (css::uno::RuntimeException
, std::exception
) override
;
133 virtual void SAL_CALL
rowSetChanged( const css::lang::EventObject
& event
) throw (css::uno::RuntimeException
, std::exception
) override
;
136 virtual void SAL_CALL
modified( const css::lang::EventObject
& _rSource
) throw( css::uno::RuntimeException
, std::exception
) override
;
138 // XPropertyChangeListener
139 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& evt
) throw (css::uno::RuntimeException
, std::exception
) override
;
142 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw (css::uno::RuntimeException
, std::exception
) override
;
144 // XComponent/OComponentHelper
145 virtual void SAL_CALL
disposing() override
;
148 // service constructors
149 void createWithFormController( const css::uno::Reference
< css::form::runtime::XFormController
>& _rxController
);
150 void createWithForm( const css::uno::Reference
< css::form::XForm
>& _rxForm
);
152 /** determines whether or not we're already disposed
154 inline bool impl_isDisposed_nothrow() const { return !m_xCursor
.is(); }
156 /** checks whether the instance is already disposed, and throws an exception if so
158 void impl_checkDisposed_throw() const;
160 /** initializes the instance after m_xController has been set
162 m_xController is not <NULL/>
164 void impl_initFromController_throw();
166 /** initializes the instance after m_xCursor has been set
168 m_xCursor is not <NULL/>
170 void impl_initFromForm_throw();
172 /// invalidate the full palette of features which we know
173 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard
& _rClearForCallback
) const;
175 /** invalidate the features which depend on the "modified" state of the current control
178 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard
& _rClearForCallback
) const;
180 /** ensures that our parse is initialized, or at least that we attempted to do so
184 void impl_ensureInitializedParser_nothrow();
186 /// disposes our parser, if we have one
187 void impl_disposeParser_nothrow();
189 /** determines whether our cursor can be moved left
192 bool impl_canMoveLeft_throw() const;
194 /** determines whether our cursor can be moved right
197 bool impl_canMoveRight_throw() const;
199 /// determines whether we're positioned on the insertion row
200 bool impl_isInsertionRow_throw() const;
202 /// retrieves the RowCount property of the form
203 sal_Int32
impl_getRowCount_throw() const;
205 /// retrieves the RowCountFinal property of the form
206 bool impl_isRowCountFinal_throw() const;
208 /// retrieves the IsModified property of the form
209 bool impl_isModifiedRow_throw() const;
211 /// determines whether we can parse the query of our form
212 bool impl_isParseable_throw() const;
214 /// determines if we have an active filter or order condition
215 bool impl_hasFilterOrOrder_throw() const;
217 /// determines whether our form is in "insert-only" mode
218 bool impl_isInsertOnlyForm_throw() const;
220 /** retrieces the column to which the current control of our controller is bound
224 css::uno::Reference
< css::beans::XPropertySet
>
225 impl_getCurrentBoundField_nothrow( ) const;
227 /** returns the control model of the current control
229 If the current control is a grid control, then the returned model is the
230 model of the current <em>column</em> in the grid.
235 css::uno::Reference
< css::awt::XControlModel
>
236 impl_getCurrentControlModel_throw() const;
238 /// determines if we have a valid cursor
239 inline bool impl_hasCursor_nothrow() const { return m_xCursorProperties
.is(); }
241 /** determines the model position from a grid control column's view position
243 A grid control can have columns which are currently hidden, so the index of a
244 column in the view is not necessarily the same as its index in the model.
246 static sal_Int16
impl_gridView2ModelPos_nothrow( const css::uno::Reference
< css::container::XIndexAccess
>& _rxColumns
, sal_Int16 _nViewPos
);
248 /** moves our cursor one position to the left, caring for different possible
251 Before the movement is done, the current row is saved, if necessary.
256 void impl_moveLeft_throw() const;
258 /** moves our cursor one position to the right, caring for different possible
261 Before the movement is done, the current row is saved, if necessary.
266 void impl_moveRight_throw( ) const;
268 /** impl-version of commitCurrentRecord, which can be called without caring for
269 an output parameter, and within const-contexts
274 bool impl_commitCurrentRecord_throw( sal_Bool
* _pRecordInserted
= nullptr ) const;
276 /** impl-version of commitCurrentControl, which can be called in const-contexts
281 bool impl_commitCurrentControl_throw() const;
283 /// resets all control models in our own form
284 void impl_resetAllControls_nothrow() const;
286 /// executes the "auto sort ascending" and "auto sort descending" features
287 void impl_executeAutoSort_throw( bool _bUp
) const;
289 /// executes the "auto filter" feature
290 void impl_executeAutoFilter_throw( ) const;
292 /// executes the interactive sort resp. filter feature
293 void impl_executeFilterOrSort_throw( bool _bFilter
) const;
296 /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
300 a functionoid with no arguments to do the work
301 @param _nErrorResourceId
302 the id of the resources string to use as error message
304 template < typename FunctObj
>
305 void impl_doActionInSQLContext_throw( FunctObj f
, sal_uInt16 _nErrorResourceId
) const;
307 // functionoid to call appendOrderByColumn
308 class impl_appendOrderByColumn_throw
311 impl_appendOrderByColumn_throw(const FormOperations
*pFO
,
312 css::uno::Reference
< css::beans::XPropertySet
> xField
,
319 void operator()() { m_pFO
->m_xParser
->appendOrderByColumn(m_xField
, m_bUp
); }
321 const FormOperations
*m_pFO
;
322 css::uno::Reference
< css::beans::XPropertySet
> m_xField
;
326 // functionoid to call appendFilterByColumn
327 class impl_appendFilterByColumn_throw
330 impl_appendFilterByColumn_throw(const FormOperations
*pFO
,
331 css::uno::Reference
< css::beans::XPropertySet
> xField
)
336 void operator()() { m_pFO
->m_xParser
->appendFilterByColumn( m_xField
, true, css::sdb::SQLFilterOperator::EQUAL
); }
338 const FormOperations
*m_pFO
;
339 css::uno::Reference
< css::beans::XPropertySet
> m_xField
;
343 FormOperations( const FormOperations
& ) = delete;
344 FormOperations
& operator=( const FormOperations
& ) = delete;
349 FormOperations
& m_rOwner
;
353 explicit MethodGuard( FormOperations
& _rOwner
)
357 m_rOwner
.enterMethod( FormOperations::MethodAccess() );
360 inline ~MethodGuard()
368 m_rOwner
.leaveMethod( FormOperations::MethodAccess() );
378 #endif // INCLUDED_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */