bump product version to 7.6.3.2-android
[LibreOffice.git] / forms / source / runtime / formoperations.hxx
bloba8d0ec45a432e6aaf6a9cc0e655bc59d03f61549
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 #pragma once
22 #include <com/sun/star/form/runtime/XFormOperations.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/form/XForm.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/form/XLoadable.hpp>
27 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
28 #include <com/sun/star/util/XModifyListener.hpp>
29 #include <com/sun/star/container/XIndexAccess.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
31 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <cppuhelper/basemutex.hxx>
35 #include <cppuhelper/compbase.hxx>
36 #include <connectivity/dbtools.hxx>
37 #include <tools/long.hxx>
38 #include <unotools/resmgr.hxx>
39 #include <utility>
41 namespace frm
45 //= FormOperations
47 typedef ::cppu::WeakComponentImplHelper < css::form::runtime::XFormOperations
48 , css::lang::XInitialization
49 , css::lang::XServiceInfo
50 , css::beans::XPropertyChangeListener
51 , css::util::XModifyListener
52 , css::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 css::uno::Reference< css::form::runtime::XFormController > m_xController;
64 css::uno::Reference< css::sdbc::XRowSet > m_xCursor;
65 css::uno::Reference< css::sdbc::XResultSetUpdate > m_xUpdateCursor;
66 css::uno::Reference< css::beans::XPropertySet > m_xCursorProperties;
67 css::uno::Reference< css::form::XLoadable > m_xLoadableForm;
68 css::uno::Reference< css::form::runtime::XFeatureInvalidation > m_xFeatureInvalidation;
69 mutable css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xParser;
71 bool m_bInitializedParser;
72 bool m_bActiveControlModified;
73 bool m_bConstructed;
74 #ifdef DBG_UTIL
75 mutable tools::Long
76 m_nMethodNestingLevel;
77 #endif
79 public:
80 explicit FormOperations( const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
82 struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
84 void enterMethod( MethodAccess ) const
86 m_aMutex.acquire();
87 impl_checkDisposed_throw();
88 #ifdef DBG_UTIL
89 ++m_nMethodNestingLevel;
90 #endif
93 void leaveMethod( MethodAccess ) const
95 m_aMutex.release();
96 #ifdef DBG_UTIL
97 --m_nMethodNestingLevel;
98 #endif
101 protected:
102 virtual ~FormOperations() override;
104 // XInitialization
105 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
107 // XServiceInfo
108 virtual OUString SAL_CALL getImplementationName( ) override;
109 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
110 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
112 // XFormOperations
113 virtual css::uno::Reference< css::sdbc::XRowSet > SAL_CALL getCursor() override;
114 virtual css::uno::Reference< css::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() override;
115 virtual css::uno::Reference< css::form::runtime::XFormController > SAL_CALL getController() override;
116 virtual css::uno::Reference< css::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() override;
117 virtual void SAL_CALL setFeatureInvalidation(const css::uno::Reference< css::form::runtime::XFeatureInvalidation > & the_value) override;
118 virtual css::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) override;
119 virtual sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) override;
120 virtual void SAL_CALL execute(::sal_Int16 Feature) override;
121 virtual void SAL_CALL executeWithArguments(::sal_Int16 Feature, const css::uno::Sequence< css::beans::NamedValue >& Arguments) override;
122 virtual sal_Bool SAL_CALL commitCurrentRecord(sal_Bool & RecordInserted) override;
123 virtual sal_Bool SAL_CALL commitCurrentControl() override;
124 virtual sal_Bool SAL_CALL isInsertionRow() override;
125 virtual sal_Bool SAL_CALL isModifiedRow() override;
127 // XRowSetListener
128 virtual void SAL_CALL cursorMoved( const css::lang::EventObject& event ) override;
129 virtual void SAL_CALL rowChanged( const css::lang::EventObject& event ) override;
130 virtual void SAL_CALL rowSetChanged( const css::lang::EventObject& event ) override;
132 // XModifyListener
133 virtual void SAL_CALL modified( const css::lang::EventObject& _rSource ) override;
135 // XPropertyChangeListener
136 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
138 // XEventListener
139 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
141 // XComponent/OComponentHelper
142 virtual void SAL_CALL disposing() override;
144 private:
145 // service constructors
146 void createWithFormController( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
147 void createWithForm( const css::uno::Reference< css::form::XForm >& _rxForm );
149 /** checks whether the instance is already disposed, and throws an exception if so
151 void impl_checkDisposed_throw() const;
153 /** initializes the instance after m_xController has been set
154 @precond
155 m_xController is not <NULL/>
157 void impl_initFromController_throw();
159 /** initializes the instance after m_xCursor has been set
160 @precond
161 m_xCursor is not <NULL/>
163 void impl_initFromForm_throw();
165 /// invalidate the full palette of features which we know
166 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
168 /** invalidate the features which depend on the "modified" state of the current control
169 of our controller
171 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
173 /** ensures that our parse is initialized, or at least that we attempted to do so
174 @precond
175 we're not disposed
177 void impl_ensureInitializedParser_nothrow();
179 /// disposes our parser, if we have one
180 void impl_disposeParser_nothrow();
182 /** determines whether our cursor can be moved left
183 @precond hasCursor()
185 bool impl_canMoveLeft_throw() const;
187 /** determines whether our cursor can be moved right
188 @precond hasCursor()
190 bool impl_canMoveRight_throw() const;
192 /// determines whether we're positioned on the insertion row
193 bool impl_isInsertionRow_throw() const;
195 /// retrieves the RowCount property of the form
196 sal_Int32 impl_getRowCount_throw() const;
198 /// retrieves the RowCountFinal property of the form
199 bool impl_isRowCountFinal_throw() const;
201 /// retrieves the IsModified property of the form
202 bool impl_isModifiedRow_throw() const;
204 /// determines whether we can parse the query of our form
205 bool impl_isParseable_throw() const;
207 /// determines if we have an active filter or order condition
208 bool impl_hasFilterOrOrder_throw() const;
210 /// determines whether our form is in "insert-only" mode
211 bool impl_isInsertOnlyForm_throw() const;
213 /** retrieves the column to which the current control of our controller is bound
214 @precond
215 m_xController.is()
217 css::uno::Reference< css::beans::XPropertySet >
218 impl_getCurrentBoundField_nothrow( ) const;
220 /** returns the control model of the current control
222 If the current control is a grid control, then the returned model is the
223 model of the current <em>column</em> in the grid.
225 @precond
226 m_xController.is()
228 css::uno::Reference< css::awt::XControlModel >
229 impl_getCurrentControlModel_throw() const;
231 /// determines if we have a valid cursor
232 bool impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
234 /** determines the model position from a grid control column's view position
236 A grid control can have columns which are currently hidden, so the index of a
237 column in the view is not necessarily the same as its index in the model.
239 static sal_Int32 impl_gridView2ModelPos_nothrow( const css::uno::Reference< css::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos );
241 /** moves our cursor one position to the left, caring for different possible
242 cursor states.
244 Before the movement is done, the current row is saved, if necessary.
246 @precond
247 canMoveLeft()
249 void impl_moveLeft_throw() const;
251 /** moves our cursor one position to the right, caring for different possible
252 cursor states.
254 Before the movement is done, the current row is saved, if necessary.
256 @precond
257 canMoveRight()
259 void impl_moveRight_throw( ) const;
261 /** impl-version of commitCurrentRecord, which can be called without caring for
262 an output parameter, and within const-contexts
264 @precond
265 our mutex is locked
267 bool impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = nullptr ) const;
269 /** impl-version of commitCurrentControl, which can be called in const-contexts
271 @precond
272 our mutex is locked
274 bool impl_commitCurrentControl_throw() const;
276 /// resets all control models in our own form
277 void impl_resetAllControls_nothrow() const;
279 /// executes the "auto sort ascending" and "auto sort descending" features
280 void impl_executeAutoSort_throw( bool _bUp ) const;
282 /// executes the "auto filter" feature
283 void impl_executeAutoFilter_throw( ) const;
285 /// executes the interactive sort resp. filter feature
286 void impl_executeFilterOrSort_throw( bool _bFilter ) const;
288 private:
289 /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
290 and rethrows them
292 @param f
293 a functionoid with no arguments to do the work
294 @param pErrorResourceId
295 the id of the resources string to use as error message
297 template < typename FunctObj >
298 void impl_doActionInSQLContext_throw( FunctObj f, TranslateId pErrorResourceId ) const;
300 // functionoid to call appendOrderByColumn
301 class impl_appendOrderByColumn_throw
303 public:
304 impl_appendOrderByColumn_throw(const FormOperations *pFO,
305 css::uno::Reference< css::beans::XPropertySet > xField,
306 bool bUp)
307 : m_pFO(pFO)
308 , m_xField(std::move(xField))
309 , m_bUp(bUp)
312 void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
313 private:
314 const FormOperations *m_pFO;
315 css::uno::Reference< css::beans::XPropertySet > m_xField;
316 bool m_bUp;
319 // functionoid to call appendFilterByColumn
320 class impl_appendFilterByColumn_throw
322 public:
323 impl_appendFilterByColumn_throw(const FormOperations *pFO,
324 css::uno::Reference< css::sdb::XSingleSelectQueryComposer > xParser,
325 css::uno::Reference< css::beans::XPropertySet > xField)
326 : m_pFO(pFO)
327 , m_xParser(std::move(xParser))
328 , m_xField(std::move(xField))
331 void operator()() {
332 if (dbtools::isAggregateColumn( m_xParser, m_xField ))
333 m_pFO->m_xParser->appendHavingClauseByColumn( m_xField, true, css::sdb::SQLFilterOperator::EQUAL );
334 else
335 m_pFO->m_xParser->appendFilterByColumn( m_xField, true, css::sdb::SQLFilterOperator::EQUAL );
337 private:
338 const FormOperations *m_pFO;
339 css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xParser;
340 css::uno::Reference< css::beans::XPropertySet > m_xField;
343 private:
344 FormOperations( const FormOperations& ) = delete;
345 FormOperations& operator=( const FormOperations& ) = delete;
347 public:
349 css::uno::Reference<css::awt::XWindow> GetDialogParent() const;
351 class MethodGuard
353 FormOperations& m_rOwner;
354 bool m_bCleared;
356 public:
357 explicit MethodGuard( FormOperations& _rOwner )
358 :m_rOwner( _rOwner )
359 ,m_bCleared( false )
361 m_rOwner.enterMethod( FormOperations::MethodAccess() );
364 ~MethodGuard()
366 clear();
369 void clear()
371 if ( !m_bCleared )
372 m_rOwner.leaveMethod( FormOperations::MethodAccess() );
373 m_bCleared = true;
379 } // namespace frm
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */