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>
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
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
;
76 m_nMethodNestingLevel
;
80 explicit FormOperations( const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
82 struct MethodAccess
{ friend class MethodGuard
; private: MethodAccess() { } };
84 void enterMethod( MethodAccess
) const
87 impl_checkDisposed_throw();
89 ++m_nMethodNestingLevel
;
93 void leaveMethod( MethodAccess
) const
97 --m_nMethodNestingLevel
;
102 virtual ~FormOperations() override
;
105 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
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
;
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
;
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
;
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
;
139 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
141 // XComponent/OComponentHelper
142 virtual void SAL_CALL
disposing() override
;
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
155 m_xController is not <NULL/>
157 void impl_initFromController_throw();
159 /** initializes the instance after m_xCursor has been set
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
171 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard
& _rClearForCallback
) const;
173 /** ensures that our parse is initialized, or at least that we attempted to do so
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
185 bool impl_canMoveLeft_throw() const;
187 /** determines whether our cursor can be moved right
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
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.
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
244 Before the movement is done, the current row is saved, if necessary.
249 void impl_moveLeft_throw() const;
251 /** moves our cursor one position to the right, caring for different possible
254 Before the movement is done, the current row is saved, if necessary.
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
267 bool impl_commitCurrentRecord_throw( sal_Bool
* _pRecordInserted
= nullptr ) const;
269 /** impl-version of commitCurrentControl, which can be called in const-contexts
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;
289 /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
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
304 impl_appendOrderByColumn_throw(const FormOperations
*pFO
,
305 css::uno::Reference
< css::beans::XPropertySet
> xField
,
308 , m_xField(std::move(xField
))
312 void operator()() { m_pFO
->m_xParser
->appendOrderByColumn(m_xField
, m_bUp
); }
314 const FormOperations
*m_pFO
;
315 css::uno::Reference
< css::beans::XPropertySet
> m_xField
;
319 // functionoid to call appendFilterByColumn
320 class impl_appendFilterByColumn_throw
323 impl_appendFilterByColumn_throw(const FormOperations
*pFO
,
324 css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> xParser
,
325 css::uno::Reference
< css::beans::XPropertySet
> xField
)
327 , m_xParser(std::move(xParser
))
328 , m_xField(std::move(xField
))
332 if (dbtools::isAggregateColumn( m_xParser
, m_xField
))
333 m_pFO
->m_xParser
->appendHavingClauseByColumn( m_xField
, true, css::sdb::SQLFilterOperator::EQUAL
);
335 m_pFO
->m_xParser
->appendFilterByColumn( m_xField
, true, css::sdb::SQLFilterOperator::EQUAL
);
338 const FormOperations
*m_pFO
;
339 css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> m_xParser
;
340 css::uno::Reference
< css::beans::XPropertySet
> m_xField
;
344 FormOperations( const FormOperations
& ) = delete;
345 FormOperations
& operator=( const FormOperations
& ) = delete;
349 css::uno::Reference
<css::awt::XWindow
> GetDialogParent() const;
353 FormOperations
& m_rOwner
;
357 explicit MethodGuard( FormOperations
& _rOwner
)
361 m_rOwner
.enterMethod( FormOperations::MethodAccess() );
372 m_rOwner
.leaveMethod( FormOperations::MethodAccess() );
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */