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_DBACCESS_SOURCE_UI_INC_BRWCTRLR_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_INC_BRWCTRLR_HXX
23 #include <dbaccess/genericcontroller.hxx>
24 #include "moduledbu.hxx"
25 #include "brwview.hxx"
26 #include "sbagrid.hxx"
28 #include <com/sun/star/form/XLoadable.hpp>
29 #include <com/sun/star/container/XContainerListener.hpp>
30 #include <com/sun/star/sdb/XSQLErrorListener.hpp>
31 #include <com/sun/star/sdbc/XRowSet.hpp>
32 #include <com/sun/star/form/XResetListener.hpp>
33 #include <com/sun/star/form/XDatabaseParameterListener.hpp>
34 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
35 #include <com/sun/star/form/XFormComponent.hpp>
36 #include <com/sun/star/awt/XFocusListener.hpp>
37 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
38 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
39 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
40 #include <com/sun/star/frame/XModule.hpp>
42 #include <vcl/timer.hxx>
43 #include <svtools/transfer.hxx>
44 #include <osl/mutex.hxx>
45 #include <osl/thread.hxx>
46 #include <cppuhelper/implbase.hxx>
47 #include <svtools/cliplistener.hxx>
49 struct FmFoundRecordInformation
;
50 struct FmSearchContext
;
54 class SQLExceptionInfo
;
60 typedef ::cppu::ImplInheritanceHelper
< OGenericUnoController
61 , css::sdb::XSQLErrorListener
62 , css::form::XDatabaseParameterListener
63 , css::form::XConfirmDeleteListener
64 , css::form::XLoadListener
65 , css::form::XResetListener
66 , css::awt::XFocusListener
67 , css::container::XContainerListener
68 , css::beans::XPropertyChangeListener
70 > SbaXDataBrowserController_Base
;
72 class SbaXDataBrowserController
:public SbaXDataBrowserController_Base
73 ,public SbaGridListener
77 // for implementing the XFormController
78 class FormControllerImpl
;
79 friend class FormControllerImpl
;
80 OModuleClient m_aModuleClient
;
82 css::uno::Reference
< css::sdbc::XRowSet
> m_xRowSet
; // our rowset
83 css::uno::Reference
< css::sdbcx::XColumnsSupplier
> m_xColumnsSupplier
; // queried from the rowset member
84 css::uno::Reference
< css::form::XLoadable
> m_xLoadable
; // queried from the rowset member as well
85 css::uno::Reference
< css::form::XFormComponent
> m_xGridModel
; // the model of our grid
86 css::uno::Reference
< css::util::XNumberFormatter
> m_xFormatter
; // a number formatter working with the connection's NumberFormatsSupplier
87 css::uno::Reference
< css::uno::XAggregation
> m_xFormControllerImpl
;
88 mutable css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
>
89 m_xParser
; // for sorting 'n filtering
91 sal_Int32 m_nRowSetPrivileges
; // cached Privileges property of m_xRowSet
93 AutoTimer m_aInvalidateClipboard
; // for testing the state of the CUT/COPY/PASTE-slots
95 TransferableDataHelper m_aSystemClipboard
; // content of the clipboard
96 TransferableClipboardListener
*
97 m_pClipbordNotifier
; // notifier for changes in the clipboard
99 OAsynchronousLink m_aAsyncGetCellFocus
;
100 OAsynchronousLink m_aAsyncDisplayError
;
101 ::dbtools::SQLExceptionInfo m_aCurrentError
;
103 OUString m_sStateSaveRecord
;
104 OUString m_sStateUndoRecord
;
105 OUString m_sModuleIdentifier
;
107 // members for asynchronous load operations
108 FormControllerImpl
* m_pFormControllerImpl
; // implementing the XFormController
110 sal_uInt16 m_nFormActionNestingLevel
; // see enter-/leaveFormAction
112 bool m_bLoadCanceled
: 1; // the load was canceled somehow
113 bool m_bCannotSelectUnfiltered
: 1; // received an DATA_CANNOT_SELECT_UNFILTERED error
116 class FormErrorHelper
118 SbaXDataBrowserController
* m_pOwner
;
120 FormErrorHelper(SbaXDataBrowserController
* pOwner
) : m_pOwner(pOwner
) { m_pOwner
->enterFormAction(); }
121 virtual ~FormErrorHelper() { m_pOwner
->leaveFormAction(); }
123 friend class FormErrorHelper
;
127 const css::uno::Reference
< css::sdbc::XRowSet
>& getRowSet() const { return m_xRowSet
; }
128 const css::uno::Reference
< css::sdbcx::XColumnsSupplier
>& getColumnsSupplier()const { return m_xColumnsSupplier
; }
129 const css::uno::Reference
< css::form::XLoadable
>& getLoadable() const { return m_xLoadable
; }
131 const css::uno::Reference
< css::form::XFormComponent
>& getFormComponent() const { return m_xGridModel
; }
132 css::uno::Reference
< css::awt::XControlModel
> getControlModel() const { return css::uno::Reference
< css::awt::XControlModel
> (m_xGridModel
, css::uno::UNO_QUERY
); }
133 const css::uno::Reference
< css::util::XNumberFormatter
>& getNumberFormatter()const { return m_xFormatter
; }
135 bool isValid() const { return m_xRowSet
.is() && m_xGridModel
.is(); }
136 bool isValidCursor() const; // checks the css::data::XDatabaseCursor-interface of m_xRowSet
137 bool isLoaded() const;
138 bool loadingCancelled() const { return m_bLoadCanceled
; }
139 void onStartLoading( const css::uno::Reference
< css::form::XLoadable
>& _rxLoadable
);
140 void setLoadingCancelled() { m_bLoadCanceled
= true; }
143 SbaXDataBrowserController(const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
145 UnoDataBrowserView
* getBrowserView() const { return static_cast< UnoDataBrowserView
*>(getView()); }
147 virtual bool Construct(vcl::Window
* pParent
) override
;
150 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) throw (css::uno::RuntimeException
, std::exception
) override
;
153 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) throw (css::uno::RuntimeException
, std::exception
) override
;
154 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw (css::uno::RuntimeException
, std::exception
) override
;
156 // css::lang::XEventListener
157 virtual void SAL_CALL
disposing(const css::lang::EventObject
& Source
) throw( css::uno::RuntimeException
, std::exception
) override
;
159 // css::util::XModifyListener
160 virtual void SAL_CALL
modified(const css::lang::EventObject
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
162 // css::container::XContainerListener
163 virtual void SAL_CALL
elementInserted(const css::container::ContainerEvent
& Event
) throw( css::uno::RuntimeException
, std::exception
) override
;
164 virtual void SAL_CALL
elementRemoved(const css::container::ContainerEvent
& Event
) throw( css::uno::RuntimeException
, std::exception
) override
;
165 virtual void SAL_CALL
elementReplaced(const css::container::ContainerEvent
& Event
) throw( css::uno::RuntimeException
, std::exception
) override
;
167 // XPropertyChangeListener
168 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& evt
) throw (css::uno::RuntimeException
, std::exception
) override
;
171 virtual void SAL_CALL
setIdentifier( const OUString
& Identifier
) throw (css::uno::RuntimeException
, std::exception
) override
;
172 virtual OUString SAL_CALL
getIdentifier( ) throw (css::uno::RuntimeException
, std::exception
) override
;
174 // css::awt::XFocusListener
175 virtual void SAL_CALL
focusGained(const css::awt::FocusEvent
& e
) throw( css::uno::RuntimeException
, std::exception
) override
;
176 virtual void SAL_CALL
focusLost(const css::awt::FocusEvent
& e
) throw( css::uno::RuntimeException
, std::exception
) override
;
178 // css::frame::XController
179 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) throw( css::uno::RuntimeException
, std::exception
) override
;
181 // css::lang::XComponent
182 virtual void SAL_CALL
disposing() override
;
184 // css::frame::XFrameActionListener
185 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
187 // css::sdb::XSQLErrorListener
188 virtual void SAL_CALL
errorOccured(const css::sdb::SQLErrorEvent
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
190 // css::form::XDatabaseParameterListener
191 virtual sal_Bool SAL_CALL
approveParameter(const css::form::DatabaseParameterEvent
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
193 // css::form::XConfirmDeleteListener
194 virtual sal_Bool SAL_CALL
confirmDelete(const css::sdb::RowChangeEvent
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
196 // css::form::XLoadListener
197 virtual void SAL_CALL
loaded(const css::lang::EventObject
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
198 virtual void SAL_CALL
unloading(const css::lang::EventObject
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
199 virtual void SAL_CALL
unloaded(const css::lang::EventObject
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
200 virtual void SAL_CALL
reloading(const css::lang::EventObject
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
201 virtual void SAL_CALL
reloaded(const css::lang::EventObject
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
203 // css::form::XResetListener
204 virtual sal_Bool SAL_CALL
approveReset(const css::lang::EventObject
& rEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
205 virtual void SAL_CALL
resetted(const css::lang::EventObject
& rEvent
) throw( css::uno::RuntimeException
, std::exception
) override
;
208 virtual void RowChanged() override
;
209 virtual void ColumnChanged() override
;
210 virtual void SelectionChanged() override
;
211 virtual void CellActivated() override
;
212 virtual void CellDeactivated() override
;
213 virtual void BeforeDrop() override
;
214 virtual void AfterDrop() override
;
219 virtual ~SbaXDataBrowserController();
221 // all the features which should be handled by this class
222 virtual void describeSupportedFeatures() override
;
223 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
224 virtual FeatureState
GetState(sal_uInt16 nId
) const override
;
226 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
228 virtual void startFrameListening( const css::uno::Reference
< css::frame::XFrame
>& _rxFrame
) override
;
229 virtual void stopFrameListening( const css::uno::Reference
< css::frame::XFrame
>& _rxFrame
) override
;
231 virtual css::uno::Reference
< css::sdbc::XRowSet
> CreateForm();
232 // our default implementation simply instantiates a stardiv.one.form.component.Form service
233 // (probably this needs not to be overridden, but you may return anything you want as long as it
234 // supports the css::form::DatabaseForm service. For instance you may want to create an adapter here which
235 // is synchronized with a foreign css::form::DatabaseForm you got elsewhere)
236 virtual bool InitializeForm(
237 const css::uno::Reference
< css::beans::XPropertySet
>& i_formProperties
) = 0;
238 // called immediately after a successful CreateForm
239 // do any initialization (data source etc.) here. the form should be fully functional after that.
240 // return sal_False if you didn't succeed (don't throw exceptions, they won't be caught)
242 virtual bool InitializeGridModel(const css::uno::Reference
< css::form::XFormComponent
> & xGrid
);
244 css::uno::Reference
< css::form::XFormComponent
> CreateGridModel();
245 // our default implementation simply instantiates a stardiv.one.form.component.Grid service
246 // you most probably don't want to override this behavior
248 // the default implementation of disposing distributes the events to the following disposingXXX functions
249 void disposingGridControl(const css::lang::EventObject
& Source
); // calls removeControlListeners
250 void disposingGridModel(const css::lang::EventObject
& Source
); // calls removeModelListeners
251 void disposingFormModel(const css::lang::EventObject
& Source
);
252 void disposingColumnModel(const css::lang::EventObject
& Source
);
254 // want to be a listener to the grid control ? use this !
255 void addControlListeners(const css::uno::Reference
< css::awt::XControl
> & _xGridControl
);
256 void removeControlListeners(const css::uno::Reference
< css::awt::XControl
> & _xGridControl
);
258 // want to be a listener to the grid model ? use this !
259 virtual void addModelListeners(const css::uno::Reference
< css::awt::XControlModel
> & _xGridControlModel
);
260 virtual void removeModelListeners(const css::uno::Reference
< css::awt::XControlModel
> & _xGridControlModel
);
262 // want to be a listener grid columns ? use this !
263 virtual void AddColumnListener(const css::uno::Reference
< css::beans::XPropertySet
> & xCol
);
264 virtual void RemoveColumnListener(const css::uno::Reference
< css::beans::XPropertySet
> & xCol
);
266 // call after "major changes" (e.g. the completion of the async load).
267 // invalidates all toolbox slots and all supported features.
269 virtual bool LoadForm();
271 // the default implementation does an direct load or starts a load thread, depending on the multithread capabilities
272 // of the data source.
273 // the default implementation also calls LoadFinished after a synchronous load, so be sure to do the same if you override
274 // this method and don't call the base class' method
276 virtual void LoadFinished(bool bWasSynch
);
277 // called if the loading (the _complete_ loading process) is done (no matter if synchron or asynchron).
279 virtual void criticalFail();
280 // called whenever a reload operation on the rowset failed
281 // (a "operation" is not only a simple reload: If the user sets a filter, an reloading the form
282 // after setting this filter fails, the filter is reset and the form is reloaded, again. Only the
283 // whole process (_both_ XLoadable::reload calls _together_) form the "reload operation"
285 // empty the frame where our view resides
286 bool CommitCurrent();
287 // commit the current column (i.e. cell)
288 bool SaveModified(bool bAskFor
= true);
289 // save the modified record
291 css::uno::Reference
< css::beans::XPropertySet
> getBoundField() const;
292 // a PropertySet corresponding to the cursor field a column is bound to.
293 // The field for the current column will be retrieved.
295 void enterFormAction();
296 void leaveFormAction();
298 // init the formatter if form changes
299 void initFormatter();
301 /// loads or reloads the form
302 bool reloadForm(const css::uno::Reference
< css::form::XLoadable
>& _rxLoadable
);
304 virtual bool preReloadForm(){ return false; }
305 virtual void postReloadForm(){}
307 css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
>
308 createParser_nothrow();
311 void setCurrentModified( bool _bSet
);
313 // execute the filter or sort slot
314 void ExecuteFilterSortCrit(bool bFilter
);
316 // execute the search slot
317 void ExecuteSearch();
319 void initializeParser() const; // changes the mutable member m_xParser
320 void applyParserFilter(const OUString
& _rOldFilter
, bool _bOldFilterApplied
,const ::OUString
& _sOldHaving
,const css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
>& _xParser
);
321 void applyParserOrder(const OUString
& _rOldOrder
,const css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
>& _xParser
);
323 sal_Int16
getCurrentColumnPosition();
324 void setCurrentColumnPosition( sal_Int16 _nPos
);
325 void addColumnListeners(const css::uno::Reference
< css::awt::XControlModel
> & _xGridControlModel
);
327 void impl_checkForCannotSelectUnfiltered( const ::dbtools::SQLExceptionInfo
& _rError
);
329 // time to check the CUT/COPY/PASTE-slot-states
330 DECL_LINK_TYPED( OnInvalidateClipboard
, Timer
*, void );
331 DECL_LINK_TYPED( OnClipboardChanged
, TransferableDataHelper
*, void );
334 DECL_LINK_TYPED(OnSearchContextRequest
, FmSearchContext
&, sal_uInt32
);
335 DECL_LINK_TYPED(OnFoundData
, FmFoundRecordInformation
&, void);
336 DECL_LINK_TYPED(OnCanceledNotFound
, FmFoundRecordInformation
&, void);
338 DECL_LINK_TYPED( OnAsyncGetCellFocus
, void*, void );
339 DECL_LINK_TYPED( OnAsyncDisplayError
, void*, void );
343 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_BRWCTRLR_HXX
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */