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 .
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>
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 struct MethodAccess
{ friend class MethodGuard
; private: MethodAccess() { } };
83 void enterMethod( MethodAccess
) const
86 impl_checkDisposed_throw();
88 ++m_nMethodNestingLevel
;
92 void leaveMethod( MethodAccess
) const
96 --m_nMethodNestingLevel
;
101 virtual ~FormOperations() override
;
104 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
107 virtual OUString SAL_CALL
getImplementationName( ) override
;
108 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
109 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
112 virtual css::uno::Reference
< css::sdbc::XRowSet
> SAL_CALL
getCursor() override
;
113 virtual css::uno::Reference
< css::sdbc::XResultSetUpdate
> SAL_CALL
getUpdateCursor() override
;
114 virtual css::uno::Reference
< css::form::runtime::XFormController
> SAL_CALL
getController() override
;
115 virtual css::uno::Reference
< css::form::runtime::XFeatureInvalidation
> SAL_CALL
getFeatureInvalidation() override
;
116 virtual void SAL_CALL
setFeatureInvalidation(const css::uno::Reference
< css::form::runtime::XFeatureInvalidation
> & the_value
) override
;
117 virtual css::form::runtime::FeatureState SAL_CALL
getState(::sal_Int16 Feature
) override
;
118 virtual sal_Bool SAL_CALL
isEnabled(::sal_Int16 Feature
) override
;
119 virtual void SAL_CALL
execute(::sal_Int16 Feature
) override
;
120 virtual void SAL_CALL
executeWithArguments(::sal_Int16 Feature
, const css::uno::Sequence
< css::beans::NamedValue
>& Arguments
) override
;
121 virtual sal_Bool SAL_CALL
commitCurrentRecord(sal_Bool
& RecordInserted
) override
;
122 virtual sal_Bool SAL_CALL
commitCurrentControl() override
;
123 virtual sal_Bool SAL_CALL
isInsertionRow() override
;
124 virtual sal_Bool SAL_CALL
isModifiedRow() override
;
127 virtual void SAL_CALL
cursorMoved( const css::lang::EventObject
& event
) override
;
128 virtual void SAL_CALL
rowChanged( const css::lang::EventObject
& event
) override
;
129 virtual void SAL_CALL
rowSetChanged( const css::lang::EventObject
& event
) override
;
132 virtual void SAL_CALL
modified( const css::lang::EventObject
& _rSource
) override
;
134 // XPropertyChangeListener
135 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& evt
) override
;
138 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
140 // XComponent/OComponentHelper
141 virtual void SAL_CALL
disposing() override
;
144 // service constructors
145 void createWithFormController( const css::uno::Reference
< css::form::runtime::XFormController
>& _rxController
);
146 void createWithForm( const css::uno::Reference
< css::form::XForm
>& _rxForm
);
148 /** checks whether the instance is already disposed, and throws an exception if so
150 void impl_checkDisposed_throw() const;
152 /** initializes the instance after m_xController has been set
154 m_xController is not <NULL/>
156 void impl_initFromController_throw();
158 /** initializes the instance after m_xCursor has been set
160 m_xCursor is not <NULL/>
162 void impl_initFromForm_throw();
164 /// invalidate the full palette of features which we know
165 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard
& _rClearForCallback
) const;
167 /** invalidate the features which depend on the "modified" state of the current control
170 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard
& _rClearForCallback
) const;
172 /** ensures that our parse is initialized, or at least that we attempted to do so
176 void impl_ensureInitializedParser_nothrow();
178 /// disposes our parser, if we have one
179 void impl_disposeParser_nothrow();
181 /** determines whether our cursor can be moved left
184 bool impl_canMoveLeft_throw() const;
186 /** determines whether our cursor can be moved right
189 bool impl_canMoveRight_throw() const;
191 /// determines whether we're positioned on the insertion row
192 bool impl_isInsertionRow_throw() const;
194 /// retrieves the RowCount property of the form
195 sal_Int32
impl_getRowCount_throw() const;
197 /// retrieves the RowCountFinal property of the form
198 bool impl_isRowCountFinal_throw() const;
200 /// retrieves the IsModified property of the form
201 bool impl_isModifiedRow_throw() const;
203 /// determines whether we can parse the query of our form
204 bool impl_isParseable_throw() const;
206 /// determines if we have an active filter or order condition
207 bool impl_hasFilterOrOrder_throw() const;
209 /// determines whether our form is in "insert-only" mode
210 bool impl_isInsertOnlyForm_throw() const;
212 /** retrieves the column to which the current control of our controller is bound
216 css::uno::Reference
< css::beans::XPropertySet
>
217 impl_getCurrentBoundField_nothrow( ) const;
219 /** returns the control model of the current control
221 If the current control is a grid control, then the returned model is the
222 model of the current <em>column</em> in the grid.
227 css::uno::Reference
< css::awt::XControlModel
>
228 impl_getCurrentControlModel_throw() const;
230 /// determines if we have a valid cursor
231 bool impl_hasCursor_nothrow() const { return m_xCursorProperties
.is(); }
233 /** determines the model position from a grid control column's view position
235 A grid control can have columns which are currently hidden, so the index of a
236 column in the view is not necessarily the same as its index in the model.
238 static sal_Int32
impl_gridView2ModelPos_nothrow( const css::uno::Reference
< css::container::XIndexAccess
>& _rxColumns
, sal_Int16 _nViewPos
);
240 /** moves our cursor one position to the left, caring for different possible
243 Before the movement is done, the current row is saved, if necessary.
248 void impl_moveLeft_throw() const;
250 /** moves our cursor one position to the right, caring for different possible
253 Before the movement is done, the current row is saved, if necessary.
258 void impl_moveRight_throw( ) const;
260 /** impl-version of commitCurrentRecord, which can be called without caring for
261 an output parameter, and within const-contexts
266 bool impl_commitCurrentRecord_throw( sal_Bool
* _pRecordInserted
= nullptr ) const;
268 /** impl-version of commitCurrentControl, which can be called in const-contexts
273 bool impl_commitCurrentControl_throw() const;
275 /// resets all control models in our own form
276 void impl_resetAllControls_nothrow() const;
278 /// executes the "auto sort ascending" and "auto sort descending" features
279 void impl_executeAutoSort_throw( bool _bUp
) const;
281 /// executes the "auto filter" feature
282 void impl_executeAutoFilter_throw( ) const;
284 /// executes the interactive sort resp. filter feature
285 void impl_executeFilterOrSort_throw( bool _bFilter
) const;
288 /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
292 a functionoid with no arguments to do the work
293 @param pErrorResourceId
294 the id of the resources string to use as error message
296 template < typename FunctObj
>
297 void impl_doActionInSQLContext_throw( FunctObj f
, TranslateId pErrorResourceId
) const;
299 // functionoid to call appendOrderByColumn
300 class impl_appendOrderByColumn_throw
303 impl_appendOrderByColumn_throw(const FormOperations
*pFO
,
304 css::uno::Reference
< css::beans::XPropertySet
> const & xField
,
311 void operator()() { m_pFO
->m_xParser
->appendOrderByColumn(m_xField
, m_bUp
); }
313 const FormOperations
*m_pFO
;
314 css::uno::Reference
< css::beans::XPropertySet
> m_xField
;
318 // functionoid to call appendFilterByColumn
319 class impl_appendFilterByColumn_throw
322 impl_appendFilterByColumn_throw(const FormOperations
*pFO
,
323 css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> const & xParser
,
324 css::uno::Reference
< css::beans::XPropertySet
> const & xField
)
331 if (dbtools::isAggregateColumn( m_xParser
, m_xField
))
332 m_pFO
->m_xParser
->appendHavingClauseByColumn( m_xField
, true, css::sdb::SQLFilterOperator::EQUAL
);
334 m_pFO
->m_xParser
->appendFilterByColumn( m_xField
, true, css::sdb::SQLFilterOperator::EQUAL
);
337 const FormOperations
*m_pFO
;
338 css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> m_xParser
;
339 css::uno::Reference
< css::beans::XPropertySet
> m_xField
;
343 FormOperations( const FormOperations
& ) = delete;
344 FormOperations
& operator=( const FormOperations
& ) = delete;
348 css::uno::Reference
<css::awt::XWindow
> GetDialogParent() const;
352 FormOperations
& m_rOwner
;
356 explicit MethodGuard( FormOperations
& _rOwner
)
360 m_rOwner
.enterMethod( FormOperations::MethodAccess() );
371 m_rOwner
.leaveMethod( FormOperations::MethodAccess() );
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */