LibreOffice Module forms (master) 1
formoperations.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
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>
33
37#include <tools/long.hxx>
38#include <unotools/resmgr.hxx>
39#include <utility>
40
41namespace frm
42{
43
44
45 //= FormOperations
46
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
54
57 {
58 public:
59 class MethodGuard;
60
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;
70
74 #ifdef DBG_UTIL
75 mutable tools::Long
77 #endif
78
79 public:
80 explicit FormOperations( const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
81
82 struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
83
85 {
86 m_aMutex.acquire();
88 #ifdef DBG_UTIL
90 #endif
91 }
92
94 {
95 m_aMutex.release();
96 #ifdef DBG_UTIL
98 #endif
99 }
100
101 protected:
102 virtual ~FormOperations() override;
103
104 // XInitialization
105 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
106
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;
111
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;
126
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;
131
132 // XModifyListener
133 virtual void SAL_CALL modified( const css::lang::EventObject& _rSource ) override;
134
135 // XPropertyChangeListener
136 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
137
138 // XEventListener
139 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
140
141 // XComponent/OComponentHelper
142 virtual void SAL_CALL disposing() override;
143
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 );
148
151 void impl_checkDisposed_throw() const;
152
158
164
166 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
167
171 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
172
178
181
185 bool impl_canMoveLeft_throw() const;
186
190 bool impl_canMoveRight_throw() const;
191
193 bool impl_isInsertionRow_throw() const;
194
196 sal_Int32 impl_getRowCount_throw() const;
197
199 bool impl_isRowCountFinal_throw() const;
200
202 bool impl_isModifiedRow_throw() const;
203
205 bool impl_isParseable_throw() const;
206
208 bool impl_hasFilterOrOrder_throw() const;
209
211 bool impl_isInsertOnlyForm_throw() const;
212
217 css::uno::Reference< css::beans::XPropertySet >
219
228 css::uno::Reference< css::awt::XControlModel >
230
232 bool impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
233
239 static sal_Int32 impl_gridView2ModelPos_nothrow( const css::uno::Reference< css::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos );
240
249 void impl_moveLeft_throw() const;
250
259 void impl_moveRight_throw( ) const;
260
267 bool impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = nullptr ) const;
268
275
278
280 void impl_executeAutoSort_throw( bool _bUp ) const;
281
283 void impl_executeAutoFilter_throw( ) const;
284
286 void impl_executeFilterOrSort_throw( bool _bFilter ) const;
287
288 private:
297 template < typename FunctObj >
298 void impl_doActionInSQLContext_throw( FunctObj f, TranslateId pErrorResourceId ) const;
299
300 // functionoid to call appendOrderByColumn
302 {
303 public:
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)
310 {};
311
312 void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
313 private:
315 css::uno::Reference< css::beans::XPropertySet > m_xField;
316 bool m_bUp;
317 };
318
319 // functionoid to call appendFilterByColumn
321 {
322 public:
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))
329 {};
330
331 void operator()() {
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 );
336 }
337 private:
339 css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xParser;
340 css::uno::Reference< css::beans::XPropertySet > m_xField;
341 };
342
343 private:
344 FormOperations( const FormOperations& ) = delete;
346
347 public:
348
349 css::uno::Reference<css::awt::XWindow> GetDialogParent() const;
350
352 {
355
356 public:
357 explicit MethodGuard( FormOperations& _rOwner )
358 :m_rOwner( _rOwner )
359 ,m_bCleared( false )
360 {
362 }
363
365 {
366 clear();
367 }
368
369 void clear()
370 {
371 if ( !m_bCleared )
373 m_bCleared = true;
374 }
375 };
376 };
377
378
379} // namespace frm
380
381
382/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mutable::osl::Mutex m_aMutex
MethodGuard(FormOperations &_rOwner)
impl_appendFilterByColumn_throw(const FormOperations *pFO, css::uno::Reference< css::sdb::XSingleSelectQueryComposer > xParser, css::uno::Reference< css::beans::XPropertySet > xField)
css::uno::Reference< css::beans::XPropertySet > m_xField
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xParser
css::uno::Reference< css::beans::XPropertySet > m_xField
impl_appendOrderByColumn_throw(const FormOperations *pFO, css::uno::Reference< css::beans::XPropertySet > xField, bool bUp)
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xParser
void impl_ensureInitializedParser_nothrow()
ensures that our parse is initialized, or at least that we attempted to do so @precond we're not disp...
bool impl_commitCurrentRecord_throw(sal_Bool *_pRecordInserted=nullptr) const
impl-version of commitCurrentRecord, which can be called without caring for an output parameter,...
void impl_executeAutoSort_throw(bool _bUp) const
executes the "auto sort ascending" and "auto sort descending" features
virtual sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) override
void impl_executeAutoFilter_throw() const
executes the "auto filter" feature
virtual void SAL_CALL modified(const css::lang::EventObject &_rSource) override
virtual sal_Bool SAL_CALL isModifiedRow() override
FormOperations(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
bool impl_hasFilterOrOrder_throw() const
determines if we have an active filter or order condition
void impl_resetAllControls_nothrow() const
resets all control models in our own form
void impl_disposeParser_nothrow()
disposes our parser, if we have one
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Reference< css::form::runtime::XFormController > SAL_CALL getController() override
FormOperations & operator=(const FormOperations &)=delete
bool impl_canMoveLeft_throw() const
determines whether our cursor can be moved left @precond hasCursor()
css::uno::Reference< css::form::runtime::XFeatureInvalidation > m_xFeatureInvalidation
css::uno::Reference< css::awt::XWindow > GetDialogParent() const
void impl_doActionInSQLContext_throw(FunctObj f, TranslateId pErrorResourceId) const
calls a (member) function, catches SQLExceptions, extends them with additional context information,...
tools::Long m_nMethodNestingLevel
void impl_checkDisposed_throw() const
checks whether the instance is already disposed, and throws an exception if so
bool impl_hasCursor_nothrow() const
determines if we have a valid cursor
void impl_initFromForm_throw()
initializes the instance after m_xCursor has been set @precond m_xCursor is not <NULL>
bool impl_isInsertOnlyForm_throw() const
determines whether our form is in "insert-only" mode
virtual void SAL_CALL setFeatureInvalidation(const css::uno::Reference< css::form::runtime::XFeatureInvalidation > &the_value) override
bool impl_isRowCountFinal_throw() const
retrieves the RowCountFinal property of the form
void impl_invalidateModifyDependentFeatures_nothrow(MethodGuard &_rClearForCallback) const
invalidate the features which depend on the "modified" state of the current control of our controller
void impl_invalidateAllSupportedFeatures_nothrow(MethodGuard &_rClearForCallback) const
invalidate the full palette of features which we know
css::uno::Reference< css::form::XLoadable > m_xLoadableForm
bool impl_isModifiedRow_throw() const
retrieves the IsModified property of the form
sal_Int32 impl_getRowCount_throw() const
retrieves the RowCount property of the form
virtual css::uno::Reference< css::sdbc::XRowSet > SAL_CALL getCursor() override
void impl_initFromController_throw()
initializes the instance after m_xController has been set @precond m_xController is not <NULL>
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
bool impl_canMoveRight_throw() const
determines whether our cursor can be moved right @precond hasCursor()
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() override
virtual void SAL_CALL cursorMoved(const css::lang::EventObject &event) override
css::uno::Reference< css::form::runtime::XFormController > m_xController
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void createWithFormController(const css::uno::Reference< css::form::runtime::XFormController > &_rxController)
void enterMethod(MethodAccess) const
void impl_executeFilterOrSort_throw(bool _bFilter) const
executes the interactive sort resp. filter feature
bool impl_isParseable_throw() const
determines whether we can parse the query of our form
css::uno::Reference< css::sdbc::XResultSetUpdate > m_xUpdateCursor
virtual css::uno::Reference< css::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() override
virtual sal_Bool SAL_CALL commitCurrentRecord(sal_Bool &RecordInserted) override
bool impl_isInsertionRow_throw() const
determines whether we're positioned on the insertion row
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Reference< css::beans::XPropertySet > m_xCursorProperties
FormOperations(const FormOperations &)=delete
virtual css::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) override
virtual void SAL_CALL execute(::sal_Int16 Feature) override
virtual void SAL_CALL executeWithArguments(::sal_Int16 Feature, const css::uno::Sequence< css::beans::NamedValue > &Arguments) override
bool impl_commitCurrentControl_throw() const
impl-version of commitCurrentControl, which can be called in const-contexts
virtual void SAL_CALL disposing() override
void impl_moveLeft_throw() const
moves our cursor one position to the left, caring for different possible cursor states.
virtual void SAL_CALL rowSetChanged(const css::lang::EventObject &event) override
css::uno::Reference< css::beans::XPropertySet > impl_getCurrentBoundField_nothrow() const
retrieves the column to which the current control of our controller is bound @precond m_xController....
virtual sal_Bool SAL_CALL commitCurrentControl() override
virtual sal_Bool SAL_CALL isInsertionRow() override
static sal_Int32 impl_gridView2ModelPos_nothrow(const css::uno::Reference< css::container::XIndexAccess > &_rxColumns, sal_Int16 _nViewPos)
determines the model position from a grid control column's view position
void leaveMethod(MethodAccess) const
css::uno::Reference< css::awt::XControlModel > impl_getCurrentControlModel_throw() const
returns the control model of the current control
virtual ~FormOperations() override
css::uno::Reference< css::sdbc::XRowSet > m_xCursor
virtual OUString SAL_CALL getImplementationName() override
void createWithForm(const css::uno::Reference< css::form::XForm > &_rxForm)
void impl_moveRight_throw() const
moves our cursor one position to the right, caring for different possible cursor states.
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual void SAL_CALL rowChanged(const css::lang::EventObject &event) override
bool isAggregateColumn(const Reference< XSingleSelectQueryComposer > &_xParser, const Reference< XPropertySet > &_xField)
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
::cppu::WeakComponentImplHelper< css::form::runtime::XFormOperations, css::lang::XInitialization, css::lang::XServiceInfo, css::beans::XPropertyChangeListener, css::util::XModifyListener, css::sdbc::XRowSetListener > FormOperations_Base
long Long
unsigned char sal_Bool