update dev300-m58
[ooovba.git] / dbaccess / source / ui / inc / brwctrlr.hxx
blob0b3da2498f5c3219c23e546ffb2e35192b8c81e3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: brwctrlr.hxx,v $
10 * $Revision: 1.40.6.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SBA_BWRCTRLR_HXX
32 #define _SBA_BWRCTRLR_HXX
34 #include "genericcontroller.hxx"
35 #include "moduledbu.hxx"
36 #include "brwview.hxx"
37 #include "sbagrid.hxx"
39 /** === begin UNO includes === **/
40 #include <com/sun/star/form/XLoadable.hpp>
41 #include <com/sun/star/container/XContainerListener.hpp>
42 #include <com/sun/star/sdb/XSQLErrorListener.hpp>
43 #include <com/sun/star/sdbc/XRowSet.hpp>
44 #include <com/sun/star/form/XResetListener.hpp>
45 #include <com/sun/star/form/XDatabaseParameterListener.hpp>
46 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
47 #include <com/sun/star/form/XFormComponent.hpp>
48 #include <com/sun/star/awt/XFocusListener.hpp>
49 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
50 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
51 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
52 #include <com/sun/star/frame/XModule.hpp>
53 /** === end UNO includes === **/
55 #include <vcl/timer.hxx>
56 #include <svtools/transfer.hxx>
57 #include <osl/mutex.hxx>
58 #include <vos/thread.hxx>
59 #include <svtools/cancel.hxx>
60 #include <cppuhelper/implbase9.hxx>
61 #include <svtools/cliplistener.hxx>
63 class ResMgr;
64 struct FmFoundRecordInformation;
65 struct FmSearchContext;
67 namespace dbtools
69 class SQLExceptionInfo;
72 namespace dbaui
74 // =========================================================================
76 typedef ::cppu::ImplInheritanceHelper9 < OGenericUnoController
77 , ::com::sun::star::sdb::XSQLErrorListener
78 , ::com::sun::star::form::XDatabaseParameterListener
79 , ::com::sun::star::form::XConfirmDeleteListener
80 , ::com::sun::star::form::XLoadListener
81 , ::com::sun::star::form::XResetListener
82 , ::com::sun::star::awt::XFocusListener
83 , ::com::sun::star::container::XContainerListener
84 , ::com::sun::star::beans::XPropertyChangeListener
85 , ::com::sun::star::frame::XModule
86 > SbaXDataBrowserController_Base;
88 class SbaXDataBrowserController :public SbaXDataBrowserController_Base
89 ,public SbaGridListener
91 // ==========
92 // attributes
93 private:
94 // for implementing the XFormController
95 class FormControllerImpl;
96 friend class FormControllerImpl;
97 OModuleClient m_aModuleClient;
99 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // our rowset
100 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > m_xColumnsSupplier; // queried from the rowset member
101 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > m_xLoadable; // queried from the rowset member as well
102 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > m_xGridModel; // the model of our grid
103 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier
104 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xFormControllerImpl;
105 mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
106 m_xParser; // for sorting 'n filtering
108 AutoTimer m_aInvalidateClipboard; // for testing the state of the CUT/COPY/PASTE-slots
110 TransferableDataHelper m_aSystemClipboard; // content of the clipboard
111 TransferableClipboardListener*
112 m_pClipbordNotifier; // notifier for changes in the clipboard
114 ::osl::Mutex m_aAsyncLoadSafety; // for multi-thread access to our members
116 OAsyncronousLink m_aAsyncGetCellFocus;
117 OAsyncronousLink m_aAsyncDisplayError;
118 ::dbtools::SQLExceptionInfo m_aCurrentError;
120 String m_sStateSaveRecord;
121 String m_sStateUndoRecord;
122 ::rtl::OUString m_sModuleIdentifier;
124 // members for asynchronous load operations
125 ::vos::OThread* m_pLoadThread; // the thread wherein the form is loaded
126 FormControllerImpl* m_pFormControllerImpl; // implementing the XFormController
128 ULONG m_nPendingLoadFinished; // the event used to tell ourself that the load is finished
129 sal_uInt16 m_nFormActionNestingLevel; // see enter-/leaveFormAction
131 sal_Bool m_bLoadCanceled : 1; // the load was canceled somehow
132 sal_Bool m_bClosingKillOpen : 1; // are we killing the load thread because we are to be suspended ?
133 bool m_bCannotSelectUnfiltered : 1; // recieved an DATA_CANNOT_SELECT_UNFILTERED error
135 protected:
136 class FormErrorHelper
138 SbaXDataBrowserController* m_pOwner;
139 public:
140 FormErrorHelper(SbaXDataBrowserController* pOwner) : m_pOwner(pOwner) { m_pOwner->enterFormAction(); }
141 virtual ~FormErrorHelper() { m_pOwner->leaveFormAction(); }
143 friend class FormErrorHelper;
145 // ================
146 // attribute access
147 protected:
148 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > getRowSet() const { return m_xRowSet; }
149 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > getColumnsSupplier()const { return m_xColumnsSupplier; }
150 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > getLoadable() const { return m_xLoadable; }
152 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > getFormComponent() const { return m_xGridModel; }
153 ::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); }
154 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > getNumberFormatter()const { return m_xFormatter; }
156 sal_Bool isValid() const { return m_xRowSet.is() && m_xGridModel.is(); }
157 sal_Bool isValidCursor() const; // checks the ::com::sun::star::data::XDatabaseCursor-interface of m_xRowSet
158 sal_Bool isLoaded() const;
159 sal_Bool loadingCancelled() const { return m_bLoadCanceled; }
160 void onStartLoading( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable );
161 void setLoadingCancelled() { m_bLoadCanceled = sal_True; }
163 const TransferableDataHelper&
164 getViewClipboard() const { return m_aSystemClipboard; }
166 public:
167 SbaXDataBrowserController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
169 UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(m_pView); }
170 // late construction
171 virtual sal_Bool Construct(Window* pParent);
173 // UNO
174 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
176 // XTypeProvider
177 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
178 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException);
180 // ::com::sun::star::lang::XEventListener
181 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
183 // ::com::sun::star::util::XModifyListener
184 virtual void SAL_CALL modified(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
186 // ::com::sun::star::container::XContainerListener
187 virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
188 virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
189 virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
191 // XPropertyChangeListener
192 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
194 // XModule
195 virtual void SAL_CALL setIdentifier( const ::rtl::OUString& Identifier ) throw (::com::sun::star::uno::RuntimeException);
196 virtual ::rtl::OUString SAL_CALL getIdentifier( ) throw (::com::sun::star::uno::RuntimeException);
198 // ::com::sun::star::awt::XFocusListener
199 virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException );
200 virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException );
202 // ::com::sun::star::frame::XController
203 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
205 // ::com::sun::star::lang::XComponent
206 virtual void SAL_CALL disposing();
208 // ::com::sun::star::frame::XFrameActionListener
209 virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
211 // ::com::sun::star::sdb::XSQLErrorListener
212 virtual void SAL_CALL errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
214 // ::com::sun::star::form::XDatabaseParameterListener
215 virtual sal_Bool SAL_CALL approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
217 // ::com::sun::star::form::XConfirmDeleteListener
218 virtual sal_Bool SAL_CALL confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
220 // ::com::sun::star::form::XLoadListener
221 virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
222 virtual void SAL_CALL unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
223 virtual void SAL_CALL unloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
224 virtual void SAL_CALL reloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
225 virtual void SAL_CALL reloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException );
227 // ::com::sun::star::form::XResetListener
228 virtual sal_Bool SAL_CALL approveReset(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException );
229 virtual void SAL_CALL resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException );
231 // SbaGridListener
232 virtual void RowChanged();
233 virtual void ColumnChanged();
234 virtual void SelectionChanged();
235 virtual void CellActivated();
236 virtual void CellDeactivated();
237 virtual void BeforeDrop();
238 virtual void AfterDrop();
240 public:
242 protected:
243 virtual ~SbaXDataBrowserController();
245 // all the features which should be handled by this class
246 virtual void describeSupportedFeatures();
247 // 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.
248 virtual FeatureState GetState(sal_uInt16 nId) const;
249 // execute a feature
250 virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
252 virtual void startFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame );
253 virtual void stopFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame );
255 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > CreateForm();
256 // our default implementation simply instantiates a stardiv.one.form.component.Form service
257 // (probably this needs not to be overloaded, but you may return anything you want as long as it
258 // supports the ::com::sun::star::form::DatabaseForm service. For instance you may want to create an adapter here which
259 // is synchronized with a foreign ::com::sun::star::form::DatabaseForm you got elsewhere)
260 virtual sal_Bool InitializeForm(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > & xForm) = 0;
261 // called immediately after a successfull CreateForm
262 // do any initialization (data source etc.) here. the form should be fully functional after that.
263 // return sal_False if you didn't succeed (don't throw exceptions, they won't be caught)
265 virtual sal_Bool InitializeGridModel(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > & xGrid);
268 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > CreateGridModel();
269 // our default implementation simply instantiates a stardiv.one.form.component.Grid service
270 // you most probably don't want to override this behaviuor
272 // the default implementation of disposing distributes the events to the following disposingXXX functions
273 virtual void disposingGridControl(const ::com::sun::star::lang::EventObject& Source); // calls removeControlListeners
274 virtual void disposingGridModel(const ::com::sun::star::lang::EventObject& Source); // calls removeModelListeners
275 virtual void disposingFormModel(const ::com::sun::star::lang::EventObject& Source);
276 virtual void disposingColumnModel(const ::com::sun::star::lang::EventObject& Source);
278 // want to be a listener to the grid control ? use this !
279 virtual void addControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl);
280 virtual void removeControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl);
282 // want to be a listener to the grid model ? use this !
283 virtual void addModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
284 virtual void removeModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
286 // want to be a listener grid columns ? use this !
287 virtual void AddColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol);
288 virtual void RemoveColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol);
291 // call after "major changes" (e.g. the completion of the async load).
292 // invalidates all toolbox slots and all supported features.
294 virtual sal_Bool LoadForm();
295 // load the form
296 // the default implementation does an direct load or starts a load thread, depending on the multithread capabilities
297 // of the data source.
298 // the default implementation also calls LoadFinished after a syncronous load, so be sure to do the same if you override
299 // this metod and don't call the base class' method
301 virtual void LoadFinished(sal_Bool bWasSynch);
302 // called if the loading (the _complete_ loading process) is done (no matter if synchron or asynchron).
304 virtual void criticalFail();
305 // called whenever a reload operation on the rowset failed
306 // (a "operation" is not only a simple reload: If the user sets a filter, an reloading the form
307 // after setting this filter fails, the filter is reset and the form is reloaded, again. Only the
308 // whole process (_both_ XLoadable::reload calls _together_) form the "reload operation"
310 // --------------------
312 // empty the frame where our view resides
313 virtual sal_Bool CommitCurrent();
314 // commit the current column (i.e. cell)
315 virtual sal_Bool SaveModified(sal_Bool bAskFor = sal_True);
316 // save the modified record
318 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getBoundField(sal_uInt16 nViewPos = (sal_uInt16)-1) const;
319 // a PropertySet corresponding to the cursor field a column is bound to
320 // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved
322 sal_Bool PendingLoad() const { return m_pLoadThread != NULL; }
323 // is there an asyncronous load operation in progress ?
325 void enterFormAction();
326 void leaveFormAction();
328 // init the formatter if form changes
329 void initFormatter();
331 /// loads or reloads the form
332 virtual sal_Bool reloadForm(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable);
334 virtual sal_Bool preReloadForm(){ return sal_False; }
335 virtual void postReloadForm(){}
337 private:
338 void setCurrentModified( sal_Bool _bSet );
340 // execute the filter or sort slot
341 void ExecuteFilterSortCrit(sal_Bool bFilter);
343 // execute the search slot
344 void ExecuteSearch();
346 void initializeParser() const; // changes the mutable member m_xParser
347 void applyParserFilter(const ::rtl::OUString& _rOldFilter, sal_Bool _bOldFilterApplied,const ::rtl::OUString& _sOldHaving = ::rtl::OUString());
348 void applyParserOrder(const ::rtl::OUString& _rOldOrder);
350 sal_Int16 getCurrentColumnPosition();
351 void setCurrentColumnPosition( sal_Int16 _nPos );
352 void addColumnListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel);
354 void impl_checkForCannotSelectUnfiltered( const ::dbtools::SQLExceptionInfo& _rError );
356 // time to check the CUT/COPY/PASTE-slot-states
357 DECL_LINK( OnInvalidateClipboard, AutoTimer* );
358 DECL_LINK( OnClipboardChanged, void* );
360 // search callbacks
361 DECL_LINK(OnSearchContextRequest, FmSearchContext*);
362 DECL_LINK(OnFoundData, FmFoundRecordInformation*);
363 DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*);
365 // callbacks for the completed loading process
366 DECL_LINK(OnOpenFinished, void*);
367 DECL_LINK(OnOpenFinishedMainThread, void*);
368 // OnOpenFinsihed is called in a foreign thread (the one which does the loading) so it simply posts the
369 // OnOpenFinishedMainThread-link (which will be called in the main thread, then) as user event.
370 // (the alternative would be to lock the SolarMutex in OnOpenFinished to avoid problems with the needed updates,
371 // but playing with this mutex seems very hazardous to me ....)
372 DECL_LINK(OnAsyncGetCellFocus, void*);
374 DECL_LINK( OnAsyncDisplayError, void* );
377 //==================================================================
378 // LoadFormThread - a thread for asynchronously loading a form
379 //==================================================================
380 class LoadFormThread : public ::vos::OThread
382 ::osl::Mutex m_aAccessSafety; // for securing the multi-thread access
383 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // the data source to be loaded
385 Link m_aTerminationHandler; // the handler to be called upon termination
386 sal_Bool m_bCanceled; // StopIt has been called ?
387 String m_sStopperCaption; // the caption for the ThreadStopper
389 // a ThreadStopper will be instantiated so that the open can be canceled via the UI
390 class ThreadStopper : protected SfxCancellable
392 LoadFormThread* m_pOwner;
394 public:
395 ThreadStopper(LoadFormThread* pOwner, const String& rTitle);
396 virtual ~ThreadStopper() { }
398 virtual void Cancel();
400 virtual void OwnerTerminated();
401 // Normally the Owner (a LoadFormThread) would delete the stopper when terminated.
402 // Unfortunally the application doesn't remove the 'red light' when a SfxCancellable is deleted
403 // if it (the app) can't acquire the solar mutex. The deletion is IGNORED then. So we have to make
404 // sure that a) the stopper is deleted from inside the main thread (where the solar mutex is locked)
405 // and b) that in the time between the termination of the thread and the deletion of the stopper
406 // the latter doesn't access the former.
407 // The OwnerTerminated cares for both aspects.
408 // SO DON'T DELETE THE STOPPER EXPLICITLY !
410 protected:
411 // HACK HACK HACK HACK HACK : this should be private, but MSVC doesn't accept the LINK-macro then ....
412 DECL_LINK(OnDeleteInMainThread, ThreadStopper*);
414 friend class LoadFormThread::ThreadStopper;
416 public:
417 LoadFormThread(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > & _xRowSet, const String& _rStopperCaption) : m_xRowSet(_xRowSet), m_sStopperCaption(_rStopperCaption) { }
419 virtual void SAL_CALL run();
420 virtual void SAL_CALL onTerminated();
422 void SetTerminationHdl(const Link& aTermHdl) { m_aTerminationHandler = aTermHdl; }
423 // the handler will be called synchronously (the parameter is a pointer to the thread)
424 // if no termination handler is set, the thread disposes the data source and deletes
425 // itself upon termination
427 // cancels the process. to be called from another thread (of course ;)
428 void StopIt();
430 // ask if the load canceled
431 sal_Bool WasCanceled() const { return m_bCanceled; }
435 #endif // _SBA_BWRCTRLR_HXX