Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / inc / brwctrlr.hxx
blob1f30a833c0f605eb6008acd517d2052e977b60b8
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 #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;
52 namespace dbtools
54 class SQLExceptionInfo;
57 namespace dbaui
60 typedef ::cppu::ImplInheritanceHelper < OGenericUnoController
61 , ::com::sun::star::sdb::XSQLErrorListener
62 , ::com::sun::star::form::XDatabaseParameterListener
63 , ::com::sun::star::form::XConfirmDeleteListener
64 , ::com::sun::star::form::XLoadListener
65 , ::com::sun::star::form::XResetListener
66 , ::com::sun::star::awt::XFocusListener
67 , ::com::sun::star::container::XContainerListener
68 , ::com::sun::star::beans::XPropertyChangeListener
69 , ::com::sun::star::frame::XModule
70 > SbaXDataBrowserController_Base;
72 class SbaXDataBrowserController :public SbaXDataBrowserController_Base
73 ,public SbaGridListener
75 // attributes
76 private:
77 // for implementing the XFormController
78 class FormControllerImpl;
79 friend class FormControllerImpl;
80 OModuleClient m_aModuleClient;
82 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // our rowset
83 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > m_xColumnsSupplier; // queried from the rowset member
84 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > m_xLoadable; // queried from the rowset member as well
85 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > m_xGridModel; // the model of our grid
86 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier
87 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xFormControllerImpl;
88 mutable ::com::sun::star::uno::Reference< ::com::sun::star::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
115 protected:
116 class FormErrorHelper
118 SbaXDataBrowserController* m_pOwner;
119 public:
120 FormErrorHelper(SbaXDataBrowserController* pOwner) : m_pOwner(pOwner) { m_pOwner->enterFormAction(); }
121 virtual ~FormErrorHelper() { m_pOwner->leaveFormAction(); }
123 friend class FormErrorHelper;
125 // attribute access
126 protected:
127 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > getRowSet() const { return m_xRowSet; }
128 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > getColumnsSupplier()const { return m_xColumnsSupplier; }
129 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > getLoadable() const { return m_xLoadable; }
131 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > getFormComponent() const { return m_xGridModel; }
132 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > getControlModel() const { return ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > (m_xGridModel, ::com::sun::star::uno::UNO_QUERY); }
133 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > getNumberFormatter()const { return m_xFormatter; }
135 bool isValid() const { return m_xRowSet.is() && m_xGridModel.is(); }
136 bool isValidCursor() const; // checks the ::com::sun::star::data::XDatabaseCursor-interface of m_xRowSet
137 bool isLoaded() const;
138 bool loadingCancelled() const { return m_bLoadCanceled; }
139 void onStartLoading( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable );
140 void setLoadingCancelled() { m_bLoadCanceled = true; }
142 const TransferableDataHelper&
143 getViewClipboard() const { return m_aSystemClipboard; }
145 public:
146 SbaXDataBrowserController(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rM);
148 UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(getView()); }
149 // late construction
150 virtual bool Construct(vcl::Window* pParent) SAL_OVERRIDE;
152 // UNO
153 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 // XTypeProvider
156 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
157 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 // ::com::sun::star::lang::XEventListener
160 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
162 // ::com::sun::star::util::XModifyListener
163 virtual void SAL_CALL modified(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
165 // ::com::sun::star::container::XContainerListener
166 virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
167 virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
168 virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
170 // XPropertyChangeListener
171 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 // XModule
174 virtual void SAL_CALL setIdentifier( const OUString& Identifier ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 virtual OUString SAL_CALL getIdentifier( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 // ::com::sun::star::awt::XFocusListener
178 virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
179 virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
181 // ::com::sun::star::frame::XController
182 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
184 // ::com::sun::star::lang::XComponent
185 virtual void SAL_CALL disposing() SAL_OVERRIDE;
187 // ::com::sun::star::frame::XFrameActionListener
188 virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
190 // ::com::sun::star::sdb::XSQLErrorListener
191 virtual void SAL_CALL errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
193 // ::com::sun::star::form::XDatabaseParameterListener
194 virtual sal_Bool SAL_CALL approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
196 // ::com::sun::star::form::XConfirmDeleteListener
197 virtual sal_Bool SAL_CALL confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
199 // ::com::sun::star::form::XLoadListener
200 virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
201 virtual void SAL_CALL unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
202 virtual void SAL_CALL unloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
203 virtual void SAL_CALL reloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
204 virtual void SAL_CALL reloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
206 // ::com::sun::star::form::XResetListener
207 virtual sal_Bool SAL_CALL approveReset(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
208 virtual void SAL_CALL resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
210 // SbaGridListener
211 virtual void RowChanged() SAL_OVERRIDE;
212 virtual void ColumnChanged() SAL_OVERRIDE;
213 virtual void SelectionChanged() SAL_OVERRIDE;
214 virtual void CellActivated() SAL_OVERRIDE;
215 virtual void CellDeactivated() SAL_OVERRIDE;
216 virtual void BeforeDrop() SAL_OVERRIDE;
217 virtual void AfterDrop() SAL_OVERRIDE;
219 public:
221 protected:
222 virtual ~SbaXDataBrowserController();
224 // all the features which should be handled by this class
225 virtual void describeSupportedFeatures() SAL_OVERRIDE;
226 // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
227 virtual FeatureState GetState(sal_uInt16 nId) const SAL_OVERRIDE;
228 // execute a feature
229 virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs) SAL_OVERRIDE;
231 virtual void startFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ) SAL_OVERRIDE;
232 virtual void stopFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ) SAL_OVERRIDE;
234 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > CreateForm();
235 // our default implementation simply instantiates a stardiv.one.form.component.Form service
236 // (probably this needs not to be overridden, but you may return anything you want as long as it
237 // supports the ::com::sun::star::form::DatabaseForm service. For instance you may want to create an adapter here which
238 // is synchronized with a foreign ::com::sun::star::form::DatabaseForm you got elsewhere)
239 virtual bool InitializeForm(
240 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& i_formProperties ) = 0;
241 // called immediately after a successful CreateForm
242 // do any initialization (data source etc.) here. the form should be fully functional after that.
243 // return sal_False if you didn't succeed (don't throw exceptions, they won't be caught)
245 virtual bool InitializeGridModel(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > & xGrid);
247 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > CreateGridModel();
248 // our default implementation simply instantiates a stardiv.one.form.component.Grid service
249 // you most probably don't want to override this behaviuor
251 // the default implementation of disposing distributes the events to the following disposingXXX functions
252 void disposingGridControl(const ::com::sun::star::lang::EventObject& Source); // calls removeControlListeners
253 void disposingGridModel(const ::com::sun::star::lang::EventObject& Source); // calls removeModelListeners
254 void disposingFormModel(const ::com::sun::star::lang::EventObject& Source);
255 void disposingColumnModel(const ::com::sun::star::lang::EventObject& Source);
257 // want to be a listener to the grid control ? use this !
258 void addControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl);
259 void removeControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl);
261 // want to be a listener to the grid model ? use this !
262 virtual void addModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
263 virtual void removeModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
265 // want to be a listener grid columns ? use this !
266 virtual void AddColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol);
267 virtual void RemoveColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol);
269 // call after "major changes" (e.g. the completion of the async load).
270 // invalidates all toolbox slots and all supported features.
272 virtual bool LoadForm();
273 // load the form
274 // the default implementation does an direct load or starts a load thread, depending on the multithread capabilities
275 // of the data source.
276 // the default implementation also calls LoadFinished after a synchronous load, so be sure to do the same if you override
277 // this method and don't call the base class' method
279 virtual void LoadFinished(bool bWasSynch);
280 // called if the loading (the _complete_ loading process) is done (no matter if synchron or asynchron).
282 virtual void criticalFail();
283 // called whenever a reload operation on the rowset failed
284 // (a "operation" is not only a simple reload: If the user sets a filter, an reloading the form
285 // after setting this filter fails, the filter is reset and the form is reloaded, again. Only the
286 // whole process (_both_ XLoadable::reload calls _together_) form the "reload operation"
288 // empty the frame where our view resides
289 bool CommitCurrent();
290 // commit the current column (i.e. cell)
291 bool SaveModified(bool bAskFor = true);
292 // save the modified record
294 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getBoundField(sal_uInt16 nViewPos = (sal_uInt16)-1) const;
295 // a PropertySet corresponding to the cursor field a column is bound to
296 // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved
298 void enterFormAction();
299 void leaveFormAction();
301 // init the formatter if form changes
302 void initFormatter();
304 /// loads or reloads the form
305 bool reloadForm(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable);
307 virtual bool preReloadForm(){ return false; }
308 virtual void postReloadForm(){}
310 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
311 createParser_nothrow();
313 private:
314 void setCurrentModified( bool _bSet );
316 // execute the filter or sort slot
317 void ExecuteFilterSortCrit(bool bFilter);
319 // execute the search slot
320 void ExecuteSearch();
322 void initializeParser() const; // changes the mutable member m_xParser
323 void applyParserFilter(const OUString& _rOldFilter, bool _bOldFilterApplied,const ::OUString& _sOldHaving,const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xParser);
324 void applyParserOrder(const OUString& _rOldOrder,const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xParser);
326 sal_Int16 getCurrentColumnPosition();
327 void setCurrentColumnPosition( sal_Int16 _nPos );
328 void addColumnListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
330 void impl_checkForCannotSelectUnfiltered( const ::dbtools::SQLExceptionInfo& _rError );
332 // time to check the CUT/COPY/PASTE-slot-states
333 DECL_LINK_TYPED( OnInvalidateClipboard, Timer*, void );
334 DECL_LINK( OnClipboardChanged, void* );
336 // search callbacks
337 DECL_LINK(OnSearchContextRequest, FmSearchContext*);
338 DECL_LINK(OnFoundData, FmFoundRecordInformation*);
339 DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*);
341 DECL_LINK(OnAsyncGetCellFocus, void*);
343 DECL_LINK( OnAsyncDisplayError, void* );
347 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_BRWCTRLR_HXX
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */