Branch data Line data Source code
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 : : #ifndef _SBA_BWRCTRLR_HXX
21 : : #define _SBA_BWRCTRLR_HXX
22 : :
23 : : #include "genericcontroller.hxx"
24 : : #include "moduledbu.hxx"
25 : : #include "brwview.hxx"
26 : : #include "sbagrid.hxx"
27 : :
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>
41 : :
42 : : #include <vcl/timer.hxx>
43 : : #include <svtools/transfer.hxx>
44 : : #include <osl/mutex.hxx>
45 : : #include <osl/thread.hxx>
46 : : #include <cppuhelper/implbase9.hxx>
47 : : #include <svtools/cliplistener.hxx>
48 : :
49 : : struct FmFoundRecordInformation;
50 : : struct FmSearchContext;
51 : :
52 : : namespace dbtools
53 : : {
54 : : class SQLExceptionInfo;
55 : : }
56 : :
57 : : namespace dbaui
58 : : {
59 : : // =========================================================================
60 : :
61 : : typedef ::cppu::ImplInheritanceHelper9 < OGenericUnoController
62 : : , ::com::sun::star::sdb::XSQLErrorListener
63 : : , ::com::sun::star::form::XDatabaseParameterListener
64 : : , ::com::sun::star::form::XConfirmDeleteListener
65 : : , ::com::sun::star::form::XLoadListener
66 : : , ::com::sun::star::form::XResetListener
67 : : , ::com::sun::star::awt::XFocusListener
68 : : , ::com::sun::star::container::XContainerListener
69 : : , ::com::sun::star::beans::XPropertyChangeListener
70 : : , ::com::sun::star::frame::XModule
71 : : > SbaXDataBrowserController_Base;
72 : :
73 : : class SbaXDataBrowserController :public SbaXDataBrowserController_Base
74 : : ,public SbaGridListener
75 : : {
76 : : // ==========
77 : : // attributes
78 : : private:
79 : : // for implementing the XFormController
80 : : class FormControllerImpl;
81 : : friend class FormControllerImpl;
82 : : OModuleClient m_aModuleClient;
83 : :
84 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // our rowset
85 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > m_xColumnsSupplier; // queried from the rowset member
86 : : ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > m_xLoadable; // queried from the rowset member as well
87 : : ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > m_xGridModel; // the model of our grid
88 : : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier
89 : : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xFormControllerImpl;
90 : : mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
91 : : m_xParser; // for sorting 'n filtering
92 : :
93 : : sal_Int32 m_nRowSetPrivileges; // cached Privileges property of m_xRowSet
94 : :
95 : : AutoTimer m_aInvalidateClipboard; // for testing the state of the CUT/COPY/PASTE-slots
96 : :
97 : : TransferableDataHelper m_aSystemClipboard; // content of the clipboard
98 : : TransferableClipboardListener*
99 : : m_pClipbordNotifier; // notifier for changes in the clipboard
100 : :
101 : : ::osl::Mutex m_aAsyncLoadSafety; // for multi-thread access to our members
102 : :
103 : : OAsyncronousLink m_aAsyncGetCellFocus;
104 : : OAsyncronousLink m_aAsyncDisplayError;
105 : : ::dbtools::SQLExceptionInfo m_aCurrentError;
106 : :
107 : : String m_sStateSaveRecord;
108 : : String m_sStateUndoRecord;
109 : : ::rtl::OUString m_sModuleIdentifier;
110 : :
111 : : // members for asynchronous load operations
112 : : FormControllerImpl* m_pFormControllerImpl; // implementing the XFormController
113 : :
114 : : sal_uLong m_nPendingLoadFinished; // the event used to tell ourself that the load is finished
115 : : sal_uInt16 m_nFormActionNestingLevel; // see enter-/leaveFormAction
116 : :
117 : : sal_Bool m_bLoadCanceled : 1; // the load was canceled somehow
118 : : sal_Bool m_bClosingKillOpen : 1; // are we killing the load thread because we are to be suspended ?
119 : : bool m_bCannotSelectUnfiltered : 1; // recieved an DATA_CANNOT_SELECT_UNFILTERED error
120 : :
121 : : protected:
122 : : class FormErrorHelper
123 : : {
124 : : SbaXDataBrowserController* m_pOwner;
125 : : public:
126 : 6 : FormErrorHelper(SbaXDataBrowserController* pOwner) : m_pOwner(pOwner) { m_pOwner->enterFormAction(); }
127 [ - + ]: 6 : virtual ~FormErrorHelper() { m_pOwner->leaveFormAction(); }
128 : : };
129 : : friend class FormErrorHelper;
130 : :
131 : : // ================
132 : : // attribute access
133 : : protected:
134 : 166 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > getRowSet() const { return m_xRowSet; }
135 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > getColumnsSupplier()const { return m_xColumnsSupplier; }
136 : 4 : ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > getLoadable() const { return m_xLoadable; }
137 : :
138 : 4 : ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > getFormComponent() const { return m_xGridModel; }
139 : 23 : ::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); }
140 : 2 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > getNumberFormatter()const { return m_xFormatter; }
141 : :
142 [ + - ][ + - ]: 261 : sal_Bool isValid() const { return m_xRowSet.is() && m_xGridModel.is(); }
143 : : sal_Bool isValidCursor() const; // checks the ::com::sun::star::data::XDatabaseCursor-interface of m_xRowSet
144 : : sal_Bool isLoaded() const;
145 : 4 : sal_Bool loadingCancelled() const { return m_bLoadCanceled; }
146 : : void onStartLoading( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable );
147 : 0 : void setLoadingCancelled() { m_bLoadCanceled = sal_True; }
148 : :
149 : : const TransferableDataHelper&
150 : : getViewClipboard() const { return m_aSystemClipboard; }
151 : :
152 : : public:
153 : : SbaXDataBrowserController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
154 : :
155 : 960 : UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(getView()); }
156 : : // late construction
157 : : virtual sal_Bool Construct(Window* pParent);
158 : :
159 : : // UNO
160 : : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
161 : :
162 : : // XTypeProvider
163 : : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
164 : : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException);
165 : :
166 : : // ::com::sun::star::lang::XEventListener
167 : : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
168 : :
169 : : // ::com::sun::star::util::XModifyListener
170 : : virtual void SAL_CALL modified(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
171 : :
172 : : // ::com::sun::star::container::XContainerListener
173 : : virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
174 : : virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
175 : : virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
176 : :
177 : : // XPropertyChangeListener
178 : : virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
179 : :
180 : : // XModule
181 : : virtual void SAL_CALL setIdentifier( const ::rtl::OUString& Identifier ) throw (::com::sun::star::uno::RuntimeException);
182 : : virtual ::rtl::OUString SAL_CALL getIdentifier( ) throw (::com::sun::star::uno::RuntimeException);
183 : :
184 : : // ::com::sun::star::awt::XFocusListener
185 : : virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException );
186 : : virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException );
187 : :
188 : : // ::com::sun::star::frame::XController
189 : : virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
190 : :
191 : : // ::com::sun::star::lang::XComponent
192 : : virtual void SAL_CALL disposing();
193 : :
194 : : // ::com::sun::star::frame::XFrameActionListener
195 : : virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
196 : :
197 : : // ::com::sun::star::sdb::XSQLErrorListener
198 : : virtual void SAL_CALL errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
199 : :
200 : : // ::com::sun::star::form::XDatabaseParameterListener
201 : : virtual sal_Bool SAL_CALL approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
202 : :
203 : : // ::com::sun::star::form::XConfirmDeleteListener
204 : : virtual sal_Bool SAL_CALL confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
205 : :
206 : : // ::com::sun::star::form::XLoadListener
207 : : virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
208 : : virtual void SAL_CALL unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
209 : : virtual void SAL_CALL unloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
210 : : virtual void SAL_CALL reloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
211 : : virtual void SAL_CALL reloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
212 : :
213 : : // ::com::sun::star::form::XResetListener
214 : : virtual sal_Bool SAL_CALL approveReset(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException );
215 : : virtual void SAL_CALL resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException );
216 : :
217 : : // SbaGridListener
218 : : virtual void RowChanged();
219 : : virtual void ColumnChanged();
220 : : virtual void SelectionChanged();
221 : : virtual void CellActivated();
222 : : virtual void CellDeactivated();
223 : : virtual void BeforeDrop();
224 : : virtual void AfterDrop();
225 : :
226 : : public:
227 : :
228 : : protected:
229 : : virtual ~SbaXDataBrowserController();
230 : :
231 : : // all the features which should be handled by this class
232 : : virtual void describeSupportedFeatures();
233 : : // 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.
234 : : virtual FeatureState GetState(sal_uInt16 nId) const;
235 : : // execute a feature
236 : : virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
237 : :
238 : : virtual void startFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame );
239 : : virtual void stopFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame );
240 : :
241 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > CreateForm();
242 : : // our default implementation simply instantiates a stardiv.one.form.component.Form service
243 : : // (probably this needs not to be overloaded, but you may return anything you want as long as it
244 : : // supports the ::com::sun::star::form::DatabaseForm service. For instance you may want to create an adapter here which
245 : : // is synchronized with a foreign ::com::sun::star::form::DatabaseForm you got elsewhere)
246 : : virtual sal_Bool InitializeForm(
247 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& i_formProperties ) = 0;
248 : : // called immediately after a successfull CreateForm
249 : : // do any initialization (data source etc.) here. the form should be fully functional after that.
250 : : // return sal_False if you didn't succeed (don't throw exceptions, they won't be caught)
251 : :
252 : : virtual sal_Bool InitializeGridModel(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > & xGrid);
253 : :
254 : :
255 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > CreateGridModel();
256 : : // our default implementation simply instantiates a stardiv.one.form.component.Grid service
257 : : // you most probably don't want to override this behaviuor
258 : :
259 : : // the default implementation of disposing distributes the events to the following disposingXXX functions
260 : : virtual void disposingGridControl(const ::com::sun::star::lang::EventObject& Source); // calls removeControlListeners
261 : : virtual void disposingGridModel(const ::com::sun::star::lang::EventObject& Source); // calls removeModelListeners
262 : : virtual void disposingFormModel(const ::com::sun::star::lang::EventObject& Source);
263 : : virtual void disposingColumnModel(const ::com::sun::star::lang::EventObject& Source);
264 : :
265 : : // want to be a listener to the grid control ? use this !
266 : : virtual void addControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl);
267 : : virtual void removeControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl);
268 : :
269 : : // want to be a listener to the grid model ? use this !
270 : : virtual void addModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
271 : : virtual void removeModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
272 : :
273 : : // want to be a listener grid columns ? use this !
274 : : virtual void AddColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol);
275 : : virtual void RemoveColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol);
276 : :
277 : :
278 : : // call after "major changes" (e.g. the completion of the async load).
279 : : // invalidates all toolbox slots and all supported features.
280 : :
281 : : virtual sal_Bool LoadForm();
282 : : // load the form
283 : : // the default implementation does an direct load or starts a load thread, depending on the multithread capabilities
284 : : // of the data source.
285 : : // the default implementation also calls LoadFinished after a syncronous load, so be sure to do the same if you override
286 : : // this metod and don't call the base class' method
287 : :
288 : : virtual void LoadFinished(sal_Bool bWasSynch);
289 : : // called if the loading (the _complete_ loading process) is done (no matter if synchron or asynchron).
290 : :
291 : : virtual void criticalFail();
292 : : // called whenever a reload operation on the rowset failed
293 : : // (a "operation" is not only a simple reload: If the user sets a filter, an reloading the form
294 : : // after setting this filter fails, the filter is reset and the form is reloaded, again. Only the
295 : : // whole process (_both_ XLoadable::reload calls _together_) form the "reload operation"
296 : :
297 : : // --------------------
298 : :
299 : : // empty the frame where our view resides
300 : : virtual sal_Bool CommitCurrent();
301 : : // commit the current column (i.e. cell)
302 : : virtual sal_Bool SaveModified(sal_Bool bAskFor = sal_True);
303 : : // save the modified record
304 : :
305 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getBoundField(sal_uInt16 nViewPos = (sal_uInt16)-1) const;
306 : : // a PropertySet corresponding to the cursor field a column is bound to
307 : : // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved
308 : :
309 : : void enterFormAction();
310 : : void leaveFormAction();
311 : :
312 : : // init the formatter if form changes
313 : : void initFormatter();
314 : :
315 : : /// loads or reloads the form
316 : : virtual sal_Bool reloadForm(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable);
317 : :
318 : 0 : virtual sal_Bool preReloadForm(){ return sal_False; }
319 : 0 : virtual void postReloadForm(){}
320 : :
321 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
322 : : createParser_nothrow();
323 : :
324 : : private:
325 : : void setCurrentModified( sal_Bool _bSet );
326 : :
327 : : // execute the filter or sort slot
328 : : void ExecuteFilterSortCrit(sal_Bool bFilter);
329 : :
330 : : // execute the search slot
331 : : void ExecuteSearch();
332 : :
333 : : void initializeParser() const; // changes the mutable member m_xParser
334 : : void applyParserFilter(const ::rtl::OUString& _rOldFilter, sal_Bool _bOldFilterApplied,const ::rtl::OUString& _sOldHaving,const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xParser);
335 : : void applyParserOrder(const ::rtl::OUString& _rOldOrder,const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xParser);
336 : :
337 : : sal_Int16 getCurrentColumnPosition();
338 : : void setCurrentColumnPosition( sal_Int16 _nPos );
339 : : void addColumnListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
340 : :
341 : : void impl_checkForCannotSelectUnfiltered( const ::dbtools::SQLExceptionInfo& _rError );
342 : :
343 : : // time to check the CUT/COPY/PASTE-slot-states
344 : : DECL_LINK( OnInvalidateClipboard, AutoTimer* );
345 : : DECL_LINK( OnClipboardChanged, void* );
346 : :
347 : : // search callbacks
348 : : DECL_LINK(OnSearchContextRequest, FmSearchContext*);
349 : : DECL_LINK(OnFoundData, FmFoundRecordInformation*);
350 : : DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*);
351 : :
352 : : DECL_LINK(OnAsyncGetCellFocus, void*);
353 : :
354 : : DECL_LINK( OnAsyncDisplayError, void* );
355 : : };
356 : : }
357 : :
358 : : #endif // _SBA_BWRCTRLR_HXX
359 : :
360 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|