tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / dbaccess / source / ui / inc / brwctrlr.hxx
blobe5e1db401a6a94ff6eb0a3a4bf95c76d6f4c9a2a
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 #pragma once
22 #include <dbaccess/genericcontroller.hxx>
23 #include "brwview.hxx"
24 #include "sbagrid.hxx"
26 #include <com/sun/star/form/XLoadable.hpp>
27 #include <com/sun/star/container/XContainerListener.hpp>
28 #include <com/sun/star/sdb/XSQLErrorListener.hpp>
29 #include <com/sun/star/sdbc/XRowSet.hpp>
30 #include <com/sun/star/form/XResetListener.hpp>
31 #include <com/sun/star/form/XDatabaseParameterListener.hpp>
32 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
33 #include <com/sun/star/form/XFormComponent.hpp>
34 #include <com/sun/star/awt/XFocusListener.hpp>
35 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
37 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
38 #include <com/sun/star/frame/XModule.hpp>
40 #include <vcl/timer.hxx>
41 #include <vcl/transfer.hxx>
42 #include <cppuhelper/implbase.hxx>
43 #include <svtools/cliplistener.hxx>
45 struct FmFoundRecordInformation;
46 struct FmSearchContext;
48 namespace dbtools
50 class SQLExceptionInfo;
53 namespace dbaui
56 typedef ::cppu::ImplInheritanceHelper < OGenericUnoController
57 , css::sdb::XSQLErrorListener
58 , css::form::XDatabaseParameterListener
59 , css::form::XConfirmDeleteListener
60 , css::form::XLoadListener
61 , css::form::XResetListener
62 , css::awt::XFocusListener
63 , css::container::XContainerListener
64 , css::beans::XPropertyChangeListener
65 , css::frame::XModule
66 > SbaXDataBrowserController_Base;
68 class SbaXDataBrowserController :public SbaXDataBrowserController_Base
69 ,public SbaGridListener
71 // attributes
72 private:
73 // for implementing the XFormController
74 class FormControllerImpl;
75 friend class FormControllerImpl;
77 css::uno::Reference< css::sdbc::XRowSet > m_xRowSet; // our rowset
78 css::uno::Reference< css::sdbcx::XColumnsSupplier > m_xColumnsSupplier; // queried from the rowset member
79 css::uno::Reference< css::form::XLoadable > m_xLoadable; // queried from the rowset member as well
80 css::uno::Reference< css::form::XFormComponent > m_xGridModel; // the model of our grid
81 css::uno::Reference< css::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier
82 mutable css::uno::Reference< css::sdb::XSingleSelectQueryComposer >
83 m_xParser; // for sorting 'n filtering
85 sal_Int32 m_nRowSetPrivileges; // cached Privileges property of m_xRowSet
87 AutoTimer m_aInvalidateClipboard; // for testing the state of the CUT/COPY/PASTE-slots
89 TransferableDataHelper m_aSystemClipboard; // content of the clipboard
90 rtl::Reference<TransferableClipboardListener>
91 m_pClipboardNotifier; // notifier for changes in the clipboard
93 OAsynchronousLink m_aAsyncGetCellFocus;
94 OAsynchronousLink m_aAsyncDisplayError;
95 ::dbtools::SQLExceptionInfo m_aCurrentError;
97 OUString m_sStateSaveRecord;
98 OUString m_sStateUndoRecord;
99 OUString m_sModuleIdentifier;
101 // members for asynchronous load operations
102 rtl::Reference<FormControllerImpl> m_xFormControllerImpl; // implementing the XFormController
104 sal_uInt16 m_nFormActionNestingLevel; // see enter-/leaveFormAction
106 bool m_bLoadCanceled : 1; // the load was canceled somehow
107 bool m_bCannotSelectUnfiltered : 1; // received a DATA_CANNOT_SELECT_UNFILTERED error
109 protected:
110 class FormErrorHelper final
112 SbaXDataBrowserController* m_pOwner;
113 public:
114 FormErrorHelper(SbaXDataBrowserController* pOwner) : m_pOwner(pOwner) { m_pOwner->enterFormAction(); }
115 ~FormErrorHelper() { m_pOwner->leaveFormAction(); }
117 friend class FormErrorHelper;
119 // attribute access
120 protected:
121 const css::uno::Reference< css::sdbc::XRowSet >& getRowSet() const { return m_xRowSet; }
122 const css::uno::Reference< css::form::XLoadable >& getLoadable() const { return m_xLoadable; }
124 const css::uno::Reference< css::form::XFormComponent >& getFormComponent() const { return m_xGridModel; }
125 css::uno::Reference< css::awt::XControlModel > getControlModel() const { return css::uno::Reference< css::awt::XControlModel > (m_xGridModel, css::uno::UNO_QUERY); }
126 const css::uno::Reference< css::util::XNumberFormatter >& getNumberFormatter()const { return m_xFormatter; }
128 bool isValid() const { return m_xRowSet.is() && m_xGridModel.is(); }
129 bool isValidCursor() const; // checks the css::data::XDatabaseCursor-interface of m_xRowSet
130 bool isLoaded() const;
131 bool loadingCancelled() const { return m_bLoadCanceled; }
132 void onStartLoading( const css::uno::Reference< css::form::XLoadable >& _rxLoadable );
133 void setLoadingCancelled() { m_bLoadCanceled = true; }
135 public:
136 SbaXDataBrowserController(const css::uno::Reference< css::uno::XComponentContext >& _rM);
138 UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(getView()); }
139 // late construction
140 virtual bool Construct(vcl::Window* pParent) override;
142 // UNO
143 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override;
145 // XTypeProvider
146 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
147 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
149 // css::lang::XEventListener
150 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
152 // css::util::XModifyListener
153 virtual void SAL_CALL modified(const css::lang::EventObject& aEvent) override;
155 // css::container::XContainerListener
156 virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& Event) override;
157 virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& Event) override;
158 virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& Event) override;
160 // XPropertyChangeListener
161 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
163 // XModule
164 virtual void SAL_CALL setIdentifier( const OUString& Identifier ) override;
165 virtual OUString SAL_CALL getIdentifier( ) override;
167 // css::awt::XFocusListener
168 virtual void SAL_CALL focusGained(const css::awt::FocusEvent& e) override;
169 virtual void SAL_CALL focusLost(const css::awt::FocusEvent& e) override;
171 // css::frame::XController
172 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override;
174 // css::lang::XComponent
175 virtual void SAL_CALL disposing() override;
177 // css::frame::XFrameActionListener
178 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) override;
180 // css::sdb::XSQLErrorListener
181 virtual void SAL_CALL errorOccured(const css::sdb::SQLErrorEvent& aEvent) override;
183 // css::form::XDatabaseParameterListener
184 virtual sal_Bool SAL_CALL approveParameter(const css::form::DatabaseParameterEvent& aEvent) override;
186 // css::form::XConfirmDeleteListener
187 virtual sal_Bool SAL_CALL confirmDelete(const css::sdb::RowChangeEvent& aEvent) override;
189 // css::form::XLoadListener
190 virtual void SAL_CALL loaded(const css::lang::EventObject& aEvent) override;
191 virtual void SAL_CALL unloading(const css::lang::EventObject& aEvent) override;
192 virtual void SAL_CALL unloaded(const css::lang::EventObject& aEvent) override;
193 virtual void SAL_CALL reloading(const css::lang::EventObject& aEvent) override;
194 virtual void SAL_CALL reloaded(const css::lang::EventObject& aEvent) override;
196 // css::form::XResetListener
197 virtual sal_Bool SAL_CALL approveReset(const css::lang::EventObject& rEvent) override;
198 virtual void SAL_CALL resetted(const css::lang::EventObject& rEvent) override;
200 // SbaGridListener
201 virtual void RowChanged() override;
202 virtual void ColumnChanged() override;
203 virtual void SelectionChanged() override;
204 virtual void CellActivated() override;
205 virtual void CellDeactivated() override;
206 virtual void BeforeDrop() override;
207 virtual void AfterDrop() override;
209 public:
211 protected:
212 virtual ~SbaXDataBrowserController() override;
214 // all the features which should be handled by this class
215 virtual void describeSupportedFeatures() override;
216 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
217 virtual FeatureState GetState(sal_uInt16 nId) const override;
218 // execute a feature
219 virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
221 virtual void startFrameListening( const css::uno::Reference< css::frame::XFrame >& _rxFrame ) override;
222 virtual void stopFrameListening( const css::uno::Reference< css::frame::XFrame >& _rxFrame ) override;
224 virtual css::uno::Reference< css::sdbc::XRowSet > CreateForm();
225 // our default implementation simply instantiates a stardiv.one.form.component.Form service
226 // (probably this needs not to be overridden, but you may return anything you want as long as it
227 // supports the css::form::DatabaseForm service. For instance you may want to create an adapter here which
228 // is synchronized with a foreign css::form::DatabaseForm you got elsewhere)
229 virtual bool InitializeForm(
230 const css::uno::Reference< css::beans::XPropertySet >& i_formProperties ) = 0;
231 // called immediately after a successful CreateForm
232 // do any initialization (data source etc.) here. the form should be fully functional after that.
233 // return sal_False if you didn't succeed (don't throw exceptions, they won't be caught)
235 css::uno::Reference< css::form::XFormComponent > CreateGridModel();
236 // our default implementation simply instantiates a stardiv.one.form.component.Grid service
237 // you most probably don't want to override this behavior
239 // the default implementation of disposing distributes the events to the following disposingXXX functions
240 void disposingFormModel(const css::lang::EventObject& Source);
241 void disposingColumnModel(const css::lang::EventObject& Source);
243 // want to be a listener to the grid control ? use this !
244 void addControlListeners(const css::uno::Reference< css::awt::XControl > & _xGridControl);
245 void removeControlListeners(const css::uno::Reference< css::awt::XControl > & _xGridControl);
247 // want to be a listener to the grid model ? use this !
248 virtual void addModelListeners(const css::uno::Reference< css::awt::XControlModel > & _xGridControlModel);
249 virtual void removeModelListeners(const css::uno::Reference< css::awt::XControlModel > & _xGridControlModel);
251 // want to be a listener grid columns ? use this !
252 virtual void AddColumnListener(const css::uno::Reference< css::beans::XPropertySet > & xCol);
253 virtual void RemoveColumnListener(const css::uno::Reference< css::beans::XPropertySet > & xCol);
255 // call after "major changes" (e.g. the completion of the async load).
256 // invalidates all toolbox slots and all supported features.
258 virtual bool LoadForm();
259 // load the form
260 // the default implementation does a direct load or starts a load thread, depending on the multithread capabilities
261 // of the data source.
262 // the default implementation also calls LoadFinished after a synchronous load, so be sure to do the same if you override
263 // this method and don't call the base class' method
265 virtual void LoadFinished(bool bWasSynch);
266 // called if the loading (the _complete_ loading process) is done (no matter if synchron or asynchron).
268 virtual void criticalFail();
269 // called whenever a reload operation on the rowset failed
270 // (an "operation" is not only a simple reload: if the user sets a filter, and reloading the form
271 // after setting this filter fails, the filter is reset and the form is reloaded, again. Only the
272 // whole process (_both_ XLoadable::reload calls _together_) form the "reload operation"
274 // empty the frame where our view resides
275 bool CommitCurrent();
276 // commit the current column (i.e. cell)
277 bool SaveModified(bool bAskFor = true);
278 // save the modified record
280 css::uno::Reference< css::beans::XPropertySet > getBoundField() const;
281 // a PropertySet corresponding to the cursor field a column is bound to.
282 // The field for the current column will be retrieved.
284 void enterFormAction();
285 void leaveFormAction();
287 // init the formatter if form changes
288 void initFormatter();
290 /// loads or reloads the form
291 bool reloadForm(const css::uno::Reference< css::form::XLoadable >& _rxLoadable);
293 virtual bool preReloadForm(){ return false; }
294 virtual void postReloadForm(){}
296 css::uno::Reference< css::sdb::XSingleSelectQueryComposer >
297 createParser_nothrow();
299 private:
300 void setCurrentModified( bool _bSet );
302 // execute the filter or sort slot
303 void ExecuteFilterSortCrit(bool bFilter);
305 // execute the search slot
306 void ExecuteSearch();
308 void initializeParser() const; // changes the mutable member m_xParser
309 void applyParserFilter(const OUString& _rOldFilter, bool _bOldFilterApplied,const ::OUString& _sOldHaving,const css::uno::Reference< css::sdb::XSingleSelectQueryComposer >& _xParser);
310 void applyParserOrder(const OUString& _rOldOrder,const css::uno::Reference< css::sdb::XSingleSelectQueryComposer >& _xParser);
312 sal_Int16 getCurrentColumnPosition() const;
313 void setCurrentColumnPosition( sal_Int16 _nPos );
314 void addColumnListeners(const css::uno::Reference< css::awt::XControlModel > & _xGridControlModel);
316 void impl_checkForCannotSelectUnfiltered( const ::dbtools::SQLExceptionInfo& _rError );
318 // time to check the CUT/COPY/PASTE-slot-states
319 DECL_LINK( OnInvalidateClipboard, Timer*, void );
320 DECL_LINK( OnClipboardChanged, TransferableDataHelper*, void );
322 // search callbacks
323 DECL_LINK(OnSearchContextRequest, FmSearchContext&, sal_uInt32);
324 DECL_LINK(OnFoundData, FmFoundRecordInformation&, void);
325 DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation&, void);
327 DECL_LINK( OnAsyncGetCellFocus, void*, void );
328 DECL_LINK( OnAsyncDisplayError, void*, void );
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */