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