1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26
27
28
29 #include "browserids.hxx"
30 #include "brwctrlr.hxx"
31 #include "brwview.hxx"
32 #include "dbu_brw.hrc"
33 #include "dbustrings.hrc"
34 #include "queryfilter.hxx"
35 #include "queryorder.hxx"
36 #include "sqlmessage.hxx"
37
38 /** === begin UNO includes === **/
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/container/XNamed.hpp>
42 #include <com/sun/star/form/FormButtonType.hpp>
43 #include <com/sun/star/form/FormSubmitEncoding.hpp>
44 #include <com/sun/star/form/FormSubmitMethod.hpp>
45 #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
46 #include <com/sun/star/form/XBoundControl.hpp>
47 #include <com/sun/star/form/XChangeBroadcaster.hpp>
48 #include <com/sun/star/form/XChangeListener.hpp>
49 #include <com/sun/star/form/XDatabaseParameterBroadcaster.hpp>
50 #include <com/sun/star/form/XLoadable.hpp>
51 #include <com/sun/star/form/XReset.hpp>
52 #include <com/sun/star/form/XResetListener.hpp>
53 #include <com/sun/star/form/XSubmit.hpp>
54 #include <com/sun/star/form/XSubmitListener.hpp>
55 #include <com/sun/star/form/runtime/XFormController.hpp>
56 #include <com/sun/star/sdb/CommandType.hpp>
57 #include <com/sun/star/sdb/ErrorCondition.hpp>
58 #include <com/sun/star/sdb/ParametersRequest.hpp>
59 #include <com/sun/star/sdb/SQLContext.hpp>
60 #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
61 #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
62 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
63 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
64 #include <com/sun/star/sdbc/XConnection.hpp>
65 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
66 #include <com/sun/star/sdbc/XRowSetListener.hpp>
67 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
68 #include <com/sun/star/sdbcx/Privilege.hpp>
69 #include <com/sun/star/sdbcx/XRowLocate.hpp>
70 #include <com/sun/star/task/XInteractionHandler.hpp>
71 #include <com/sun/star/uno/TypeClass.hpp>
72 #include <com/sun/star/util/XCancellable.hpp>
73 /** === end UNO includes === **/
74
75 #include <comphelper/enumhelper.hxx>
76 #include <comphelper/extract.hxx>
77 #include <comphelper/interaction.hxx>
78 #include <comphelper/sequence.hxx>
79 #include <connectivity/dbexception.hxx>
80 #include <connectivity/dbtools.hxx>
81 #include <connectivity/sqlerror.hxx>
82 #include <cppuhelper/exc_hlp.hxx>
83 #include <cppuhelper/implbase2.hxx>
84 #include <cppuhelper/typeprovider.hxx>
85 #include <osl/mutex.hxx>
86 #include <rtl/logfile.hxx>
87 #include <sfx2/app.hxx>
88 #include <sfx2/sfx.hrc>
89 #include <svx/fmsearch.hxx>
90 #include <svx/svxdlg.hxx>
91 #include <tools/color.hxx>
92 #include <tools/diagnose_ex.h>
93 #include <vcl/msgbox.hxx>
94 #include <vcl/waitobj.hxx>
95
96 using namespace ::com::sun::star::uno;
97 using namespace ::com::sun::star::awt;
98 using namespace ::com::sun::star::sdb;
99 using namespace ::com::sun::star::sdbc;
100 using namespace ::com::sun::star::sdbcx;
101 using namespace ::com::sun::star::task;
102 using namespace ::com::sun::star::beans;
103 using namespace ::com::sun::star::frame;
104 using namespace ::com::sun::star::form;
105 using namespace ::com::sun::star::util;
106 using namespace ::com::sun::star::lang;
107 using namespace ::com::sun::star::container;
108 using namespace ::dbtools;
109 using namespace ::comphelper;
110 using namespace ::svt;
111
112 #define HANDLE_SQL_ERRORS( action, successflag, context, message ) \
113 try \
114 { \
115 successflag = sal_False; \
116 action; \
117 successflag = sal_True; \
118 } \
119 catch(SQLException& e) \
120 { \
121 SQLException aError = ::dbtools::prependErrorInfo(e, *this, context); \
122 ::com::sun::star::sdb::SQLErrorEvent aEvent; \
123 aEvent.Reason <<= aError; \
124 errorOccured(aEvent); \
125 } \
126 catch(Exception&) \
127 { \
128 DBG_UNHANDLED_EXCEPTION(); \
129 } \
130
131 #define DO_SAFE( action, message ) try { action; } catch(Exception&) { DBG_ERROR(message); } ;
132
133 //..................................................................
134 namespace dbaui
135 {
136 //..................................................................
137
138 //==================================================================
139 // OParameterContinuation
140 //==================================================================
141 class OParameterContinuation : public OInteraction< XInteractionSupplyParameters >
142 {
143 Sequence< PropertyValue > m_aValues;
144
145 public:
OParameterContinuation()146 OParameterContinuation() { }
147
getValues() const148 Sequence< PropertyValue > getValues() const { return m_aValues; }
149
150 // XInteractionSupplyParameters
151 virtual void SAL_CALL setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException);
152 };
153
154 //------------------------------------------------------------------
setParameters(const Sequence<PropertyValue> & _rValues)155 void SAL_CALL OParameterContinuation::setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException)
156 {
157 m_aValues = _rValues;
158 }
159
160
161 //==============================================================================
162 // a helper class implementing a runtime::XFormController, will be aggregated by SbaXDataBrowserController
163 // (we can't derive from XFormController as it's base class is XTabController and the XTabController::getModel collides
164 // with the XController::getModel implemented in our base class SbaXDataBrowserController)
165 class SbaXDataBrowserController::FormControllerImpl
166 : public ::cppu::WeakAggImplHelper2< ::com::sun::star::form::runtime::XFormController,
167 ::com::sun::star::frame::XFrameActionListener >
168 {
169 friend class SbaXDataBrowserController;
170 ::cppu::OInterfaceContainerHelper m_aActivateListeners;
171 SbaXDataBrowserController* m_pOwner;
172
173 public:
174 FormControllerImpl(SbaXDataBrowserController* pOwner);
175
176 // XFormController
177 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations > SAL_CALL getFormOperations() throw (::com::sun::star::uno::RuntimeException);
178 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getCurrentControl(void) throw( ::com::sun::star::uno::RuntimeException );
179 virtual void SAL_CALL addActivateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( ::com::sun::star::uno::RuntimeException );
180 virtual void SAL_CALL removeActivateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( ::com::sun::star::uno::RuntimeException );
181 virtual void SAL_CALL addChildController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _ChildController ) throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
182 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormControllerContext > SAL_CALL getContext() throw (::com::sun::star::uno::RuntimeException);
183 virtual void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormControllerContext >& _context ) throw (::com::sun::star::uno::RuntimeException);
184 virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > SAL_CALL getInteractionHandler() throw (::com::sun::star::uno::RuntimeException);
185 virtual void SAL_CALL setInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _interactionHandler ) throw (::com::sun::star::uno::RuntimeException);
186
187 // XChild, base of XFormController
188 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw (::com::sun::star::uno::RuntimeException);
189 virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
190
191 // XComponent, base of XFormController
192 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
193 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
194 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
195
196 // XIndexAccess, base of XFormController
197 virtual ::sal_Int32 SAL_CALL getCount( ) throw (::com::sun::star::uno::RuntimeException);
198 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
199
200 // XElementAccess, base of XIndexAccess
201 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException);
202 virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException);
203
204 // XEnumerationAccess, base of XElementAccess
205 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw (::com::sun::star::uno::RuntimeException);
206
207 // XModifyBroadcaster, base of XFormController
208 virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
209 virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
210
211 // XConfirmDeleteBroadcaster, base of XFormController
212 virtual void SAL_CALL addConfirmDeleteListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XConfirmDeleteListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
213 virtual void SAL_CALL removeConfirmDeleteListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XConfirmDeleteListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
214
215 // XSQLErrorBroadcaster, base of XFormController
216 virtual void SAL_CALL addSQLErrorListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLErrorListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
217 virtual void SAL_CALL removeSQLErrorListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLErrorListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
218
219 // XRowSetApproveBroadcaster, base of XFormController
220 virtual void SAL_CALL addRowSetApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XRowSetApproveListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
221 virtual void SAL_CALL removeRowSetApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XRowSetApproveListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
222
223 // XDatabaseParameterBroadcaster2, base of XFormController
224 virtual void SAL_CALL addDatabaseParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
225 virtual void SAL_CALL removeDatabaseParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
226
227 // XDatabaseParameterBroadcaster, base of XDatabaseParameterBroadcaster2
228 virtual void SAL_CALL addParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
229 virtual void SAL_CALL removeParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
230
231 // XModeSelector, base of XFormController
232 virtual void SAL_CALL setMode( const ::rtl::OUString& aMode ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
233 virtual ::rtl::OUString SAL_CALL getMode( ) throw (::com::sun::star::uno::RuntimeException);
234 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedModes( ) throw (::com::sun::star::uno::RuntimeException);
235 virtual ::sal_Bool SAL_CALL supportsMode( const ::rtl::OUString& aMode ) throw (::com::sun::star::uno::RuntimeException);
236
237 // XTabController, base of XFormController
238 virtual void SAL_CALL setModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel > & Model) throw( ::com::sun::star::uno::RuntimeException );
239 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel > SAL_CALL getModel(void) throw( ::com::sun::star::uno::RuntimeException );
240 virtual void SAL_CALL setContainer(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > & _Container) throw( ::com::sun::star::uno::RuntimeException );
241 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > SAL_CALL getContainer(void) throw( ::com::sun::star::uno::RuntimeException );
242 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > > SAL_CALL getControls(void) throw( ::com::sun::star::uno::RuntimeException );
243 virtual void SAL_CALL autoTabOrder(void) throw( ::com::sun::star::uno::RuntimeException );
244 virtual void SAL_CALL activateTabOrder(void) throw( ::com::sun::star::uno::RuntimeException );
245 virtual void SAL_CALL activateFirst(void) throw( ::com::sun::star::uno::RuntimeException );
246 virtual void SAL_CALL activateLast(void) throw( ::com::sun::star::uno::RuntimeException );
247
248 // XFrameActionListener
249 virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
250
251 // XEventListener
252 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
253
254 protected:
255 ~FormControllerImpl();
256 };
257
258
DBG_NAME(FormControllerImpl)259 DBG_NAME(FormControllerImpl)
260 //------------------------------------------------------------------
261 SbaXDataBrowserController::FormControllerImpl::FormControllerImpl(SbaXDataBrowserController* _pOwner)
262 :m_aActivateListeners(_pOwner->getMutex())
263 ,m_pOwner(_pOwner)
264 {
265 DBG_CTOR(FormControllerImpl,NULL);
266
267 OSL_ENSURE(m_pOwner, "SbaXDataBrowserController::FormControllerImpl::FormControllerImpl : invalid Owner !");
268 }
269
270 //------------------------------------------------------------------
~FormControllerImpl()271 SbaXDataBrowserController::FormControllerImpl::~FormControllerImpl()
272 {
273
274 DBG_DTOR(FormControllerImpl,NULL);
275 }
276
277 //------------------------------------------------------------------
getFormOperations()278 Reference< runtime::XFormOperations > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getFormOperations() throw (RuntimeException)
279 {
280 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::getFormOperations: not supported!" );
281 return NULL;
282 }
283
284 //------------------------------------------------------------------
getCurrentControl(void)285 Reference< ::com::sun::star::awt::XControl > SbaXDataBrowserController::FormControllerImpl::getCurrentControl(void) throw( RuntimeException )
286 {
287 return m_pOwner->getBrowserView() ? m_pOwner->getBrowserView()->getGridControl() : Reference< ::com::sun::star::awt::XControl > ();
288 }
289
290 //------------------------------------------------------------------
addActivateListener(const Reference<::com::sun::star::form::XFormControllerListener> & l)291 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException )
292 {
293 m_aActivateListeners.addInterface(l);
294 }
295
296 //------------------------------------------------------------------
removeActivateListener(const Reference<::com::sun::star::form::XFormControllerListener> & l)297 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException )
298 {
299 m_aActivateListeners.removeInterface(l);
300 }
301
302 //------------------------------------------------------------------
addChildController(const Reference<runtime::XFormController> &)303 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addChildController( const Reference< runtime::XFormController >& /*_ChildController*/ ) throw( RuntimeException, IllegalArgumentException )
304 {
305 // not supported
306 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
307 }
308
309 //------------------------------------------------------------------
getContext()310 Reference< runtime::XFormControllerContext > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContext() throw (RuntimeException)
311 {
312 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::getContext: no support!!" );
313 return NULL;
314 }
315
316 //------------------------------------------------------------------
setContext(const Reference<runtime::XFormControllerContext> &)317 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContext( const Reference< runtime::XFormControllerContext >& /*_context*/ ) throw (RuntimeException)
318 {
319 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::setContext: no support!!" );
320 }
321
322 //------------------------------------------------------------------
getInteractionHandler()323 Reference< XInteractionHandler > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getInteractionHandler() throw (RuntimeException)
324 {
325 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::getInteractionHandler: no support!!" );
326 return NULL;
327 }
328
329 //------------------------------------------------------------------
setInteractionHandler(const Reference<XInteractionHandler> &)330 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setInteractionHandler( const Reference< XInteractionHandler >& /*_interactionHandler*/ ) throw (RuntimeException)
331 {
332 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::setInteractionHandler: no support!!" );
333 }
334
335 //------------------------------------------------------------------
getParent()336 Reference< XInterface > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getParent( ) throw (RuntimeException)
337 {
338 // don't have any parent form controllers
339 return NULL;
340 }
341
342 //------------------------------------------------------------------
setParent(const Reference<XInterface> &)343 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setParent( const Reference< XInterface >& /*Parent*/ ) throw (NoSupportException, RuntimeException)
344 {
345 throw NoSupportException( ::rtl::OUString(), *this );
346 }
347
348 //------------------------------------------------------------------
dispose()349 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::dispose( ) throw (RuntimeException)
350 {
351 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::dispose: no, you do *not* want to do this!" );
352 }
353
354 //------------------------------------------------------------------
addEventListener(const Reference<XEventListener> &)355 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addEventListener( const Reference< XEventListener >& /*xListener*/ ) throw (RuntimeException)
356 {
357 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addEventListener: no support!!" );
358 }
359
360 //------------------------------------------------------------------
removeEventListener(const Reference<XEventListener> &)361 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeEventListener( const Reference< XEventListener >& /*aListener*/ ) throw (RuntimeException)
362 {
363 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeEventListener: no support!!" );
364 }
365
366 //------------------------------------------------------------------
getCount()367 ::sal_Int32 SAL_CALL SbaXDataBrowserController::FormControllerImpl::getCount( ) throw (RuntimeException)
368 {
369 // no sub controllers, never
370 return 0;
371 }
372
373 //------------------------------------------------------------------
getByIndex(::sal_Int32)374 Any SAL_CALL SbaXDataBrowserController::FormControllerImpl::getByIndex( ::sal_Int32 /*Index*/ ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
375 {
376 // no sub controllers, never
377 throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
378 }
379
380 //------------------------------------------------------------------
getElementType()381 Type SAL_CALL SbaXDataBrowserController::FormControllerImpl::getElementType( ) throw (RuntimeException)
382 {
383 return ::cppu::UnoType< runtime::XFormController >::get();
384 }
385
386 //------------------------------------------------------------------
hasElements()387 ::sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::hasElements( ) throw (RuntimeException)
388 {
389 // no sub controllers, never
390 return false;
391 }
392
393 //------------------------------------------------------------------
createEnumeration()394 Reference< XEnumeration > SAL_CALL SbaXDataBrowserController::FormControllerImpl::createEnumeration( ) throw (RuntimeException)
395 {
396 return new ::comphelper::OEnumerationByIndex( this );
397 }
398
399 //------------------------------------------------------------------
addModifyListener(const Reference<XModifyListener> &)400 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException)
401 {
402 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addModifyListener: no support!" );
403 }
404
405 //------------------------------------------------------------------
removeModifyListener(const Reference<XModifyListener> &)406 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException)
407 {
408 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeModifyListener: no support!" );
409 }
410
411 //------------------------------------------------------------------
addConfirmDeleteListener(const Reference<XConfirmDeleteListener> &)412 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException)
413 {
414 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener: no support!" );
415 }
416
417 //------------------------------------------------------------------
removeConfirmDeleteListener(const Reference<XConfirmDeleteListener> &)418 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException)
419 {
420 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener: no support!" );
421 }
422
423 //------------------------------------------------------------------
addSQLErrorListener(const Reference<XSQLErrorListener> &)424 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException)
425 {
426 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener: no support!" );
427 }
428
429 //------------------------------------------------------------------
removeSQLErrorListener(const Reference<XSQLErrorListener> &)430 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException)
431 {
432 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener: no support!" );
433 }
434
435 //------------------------------------------------------------------
addRowSetApproveListener(const Reference<XRowSetApproveListener> &)436 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException)
437 {
438 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener: no support!" );
439 }
440
441 //------------------------------------------------------------------
removeRowSetApproveListener(const Reference<XRowSetApproveListener> &)442 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException)
443 {
444 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener: no support!" );
445 }
446
447 //------------------------------------------------------------------
addDatabaseParameterListener(const Reference<XDatabaseParameterListener> &)448 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
449 {
450 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener: no support!" );
451 }
452
453 //------------------------------------------------------------------
removeDatabaseParameterListener(const Reference<XDatabaseParameterListener> &)454 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
455 {
456 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener: no support!" );
457 }
458
459 //------------------------------------------------------------------
addParameterListener(const Reference<XDatabaseParameterListener> &)460 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
461 {
462 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::addParameterListener: no support!" );
463 }
464
465 //------------------------------------------------------------------
removeParameterListener(const Reference<XDatabaseParameterListener> &)466 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
467 {
468 OSL_ENSURE( false, "SbaXDataBrowserController::FormControllerImpl::removeParameterListener: no support!" );
469 }
470
471 //------------------------------------------------------------------
setMode(const::rtl::OUString & _rMode)472 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setMode( const ::rtl::OUString& _rMode ) throw (NoSupportException, RuntimeException)
473 {
474 if ( !supportsMode( _rMode ) )
475 throw NoSupportException();
476 }
477
478 //------------------------------------------------------------------
getMode()479 ::rtl::OUString SAL_CALL SbaXDataBrowserController::FormControllerImpl::getMode( ) throw (RuntimeException)
480 {
481 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) );
482 }
483
484 //------------------------------------------------------------------
getSupportedModes()485 Sequence< ::rtl::OUString > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getSupportedModes( ) throw (RuntimeException)
486 {
487 Sequence< ::rtl::OUString > aModes(1);
488 aModes[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) );
489 return aModes;
490 }
491
492 //------------------------------------------------------------------
supportsMode(const::rtl::OUString & aMode)493 ::sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::supportsMode( const ::rtl::OUString& aMode ) throw (RuntimeException)
494 {
495 return aMode.compareToAscii( "DataMode" ) == 0;
496 }
497
498 //------------------------------------------------------------------
setModel(const Reference<::com::sun::star::awt::XTabControllerModel> &)499 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setModel(const Reference< ::com::sun::star::awt::XTabControllerModel > & /*Model*/) throw( RuntimeException )
500 {
501 OSL_ENSURE(sal_False, "SbaXDataBrowserController::FormControllerImpl::setModel : invalid call, can't change my model !");
502 }
503
504 //------------------------------------------------------------------
getModel(void)505 Reference< ::com::sun::star::awt::XTabControllerModel > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getModel(void) throw( RuntimeException )
506 {
507 return Reference< XTabControllerModel >(m_pOwner->getRowSet(), UNO_QUERY);
508 }
509
510 //------------------------------------------------------------------
setContainer(const Reference<::com::sun::star::awt::XControlContainer> &)511 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContainer(const Reference< ::com::sun::star::awt::XControlContainer > & /*_Container*/) throw( RuntimeException )
512 {
513 OSL_ENSURE(sal_False, "SbaXDataBrowserController::FormControllerImpl::setContainer : invalid call, can't change my container !");
514 }
515
516 //------------------------------------------------------------------
getContainer(void)517 Reference< ::com::sun::star::awt::XControlContainer > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContainer(void) throw( RuntimeException )
518 {
519 if (m_pOwner->getBrowserView())
520 return m_pOwner->getBrowserView()->getContainer();
521 return Reference< ::com::sun::star::awt::XControlContainer > ();
522 }
523
524 //------------------------------------------------------------------
getControls(void)525 Sequence< Reference< ::com::sun::star::awt::XControl > > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getControls(void) throw( RuntimeException )
526 {
527 if (m_pOwner->getBrowserView())
528 {
529 Reference< ::com::sun::star::awt::XControl > xGrid = m_pOwner->getBrowserView()->getGridControl();
530 return Sequence< Reference< ::com::sun::star::awt::XControl > >(&xGrid, 1);
531 }
532 return Sequence< Reference< ::com::sun::star::awt::XControl > >();
533 }
534
535 //------------------------------------------------------------------
autoTabOrder(void)536 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::autoTabOrder(void) throw( RuntimeException )
537 {
538 OSL_ENSURE(sal_False, "SbaXDataBrowserController::FormControllerImpl::autoTabOrder : nothing to do (always have only one control) !");
539 }
540
541 //------------------------------------------------------------------
activateTabOrder(void)542 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateTabOrder(void) throw( RuntimeException )
543 {
544 OSL_ENSURE(sal_False, "SbaXDataBrowserController::FormControllerImpl::activateTabOrder : nothing to do (always have only one control) !");
545 }
546
547 //------------------------------------------------------------------
activateFirst(void)548 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateFirst(void) throw( RuntimeException )
549 {
550 if (m_pOwner->getBrowserView())
551 m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
552 }
553
554 //------------------------------------------------------------------
activateLast(void)555 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateLast(void) throw( RuntimeException )
556 {
557 if (m_pOwner->getBrowserView())
558 m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
559 }
560
561 //------------------------------------------------------------------
frameAction(const::com::sun::star::frame::FrameActionEvent &)562 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::frameAction(const ::com::sun::star::frame::FrameActionEvent& /*aEvent*/) throw( RuntimeException )
563 {
564 }
565
566 //------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject &)567 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::disposing(const ::com::sun::star::lang::EventObject& /*Source*/) throw( RuntimeException )
568 {
569 // nothing to do
570 // we don't add ourself as listener to any broadcasters, so we are not resposible for removing us
571 }
572
573 //==================================================================
574 //= SbaXDataBrowserController
575 //==================================================================
576 //------------------------------------------------------------------
getTypes()577 Sequence< Type > SAL_CALL SbaXDataBrowserController::getTypes( ) throw (RuntimeException)
578 {
579 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getTypes" );
580 return ::comphelper::concatSequences(
581 SbaXDataBrowserController_Base::getTypes(),
582 m_pFormControllerImpl->getTypes()
583 );
584 }
585
586 //------------------------------------------------------------------
getImplementationId()587 Sequence< sal_Int8 > SAL_CALL SbaXDataBrowserController::getImplementationId( ) throw (RuntimeException)
588 {
589 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getImplementationId" );
590 static ::cppu::OImplementationId * pId = 0;
591 if (! pId)
592 {
593 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
594 if (! pId)
595 {
596 static ::cppu::OImplementationId aId;
597 pId = &aId;
598 }
599 }
600 return pId->getImplementationId();
601 }
602
603 //------------------------------------------------------------------
queryInterface(const Type & _rType)604 Any SAL_CALL SbaXDataBrowserController::queryInterface(const Type& _rType) throw (RuntimeException)
605 {
606 // check for our additional interfaces
607 Any aRet = SbaXDataBrowserController_Base::queryInterface(_rType);
608
609 // check for our aggregate (implementing the XFormController)
610 if (!aRet.hasValue())
611 aRet = m_xFormControllerImpl->queryAggregation(_rType);
612
613 // no more to offer
614 return aRet;
615 }
616
DBG_NAME(SbaXDataBrowserController)617 DBG_NAME(SbaXDataBrowserController)
618 //------------------------------------------------------------------------------
619 SbaXDataBrowserController::SbaXDataBrowserController(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM)
620 :SbaXDataBrowserController_Base(_rM)
621 ,m_nRowSetPrivileges(0)
622 ,m_pClipbordNotifier( NULL )
623 ,m_aAsyncGetCellFocus(LINK(this, SbaXDataBrowserController, OnAsyncGetCellFocus))
624 ,m_aAsyncDisplayError( LINK( this, SbaXDataBrowserController, OnAsyncDisplayError ) )
625 ,m_sStateSaveRecord(ModuleRes(RID_STR_SAVE_CURRENT_RECORD))
626 ,m_sStateUndoRecord(ModuleRes(RID_STR_UNDO_MODIFY_RECORD))
627 ,m_sModuleIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataSourceBrowser" ) ) )
628 ,m_pFormControllerImpl(NULL)
629 ,m_nPendingLoadFinished(0)
630 ,m_nFormActionNestingLevel(0)
631 ,m_bLoadCanceled( sal_False )
632 ,m_bClosingKillOpen( sal_False )
633 ,m_bCannotSelectUnfiltered( true )
634 {
635 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SbaXDataBrowserController" );
636 DBG_CTOR(SbaXDataBrowserController,NULL);
637
638 // create the form controller aggregate
639 ::comphelper::increment(m_refCount);
640 {
641 m_pFormControllerImpl = new FormControllerImpl(this);
642 m_xFormControllerImpl = m_pFormControllerImpl;
643 m_xFormControllerImpl->setDelegator(*this);
644 }
645 ::comphelper::decrement(m_refCount);
646
647 m_aInvalidateClipboard.SetTimeoutHdl(LINK(this, SbaXDataBrowserController, OnInvalidateClipboard));
648 m_aInvalidateClipboard.SetTimeout(300);
649 }
650
651 //------------------------------------------------------------------------------
~SbaXDataBrowserController()652 SbaXDataBrowserController::~SbaXDataBrowserController()
653 {
654 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::~SbaXDataBrowserController" );
655 // deleteView();
656 // release the aggregated form controller
657 if (m_xFormControllerImpl.is())
658 {
659 Reference< XInterface > xEmpty;
660 m_xFormControllerImpl->setDelegator(xEmpty);
661 }
662
663 DBG_DTOR(SbaXDataBrowserController,NULL);
664 }
665
666 // -----------------------------------------------------------------------
startFrameListening(const Reference<XFrame> & _rxFrame)667 void SbaXDataBrowserController::startFrameListening( const Reference< XFrame >& _rxFrame )
668 {
669 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::startFrameListening" );
670 SbaXDataBrowserController_Base::startFrameListening( _rxFrame );
671
672 Reference< XFrameActionListener > xAggListener;
673 if ( m_xFormControllerImpl.is() )
674 m_xFormControllerImpl->queryAggregation( XFrameActionListener::static_type() ) >>= xAggListener;
675
676 if ( _rxFrame.is() && xAggListener.is() )
677 _rxFrame->addFrameActionListener( xAggListener );
678 }
679
680 // -----------------------------------------------------------------------
stopFrameListening(const Reference<XFrame> & _rxFrame)681 void SbaXDataBrowserController::stopFrameListening( const Reference< XFrame >& _rxFrame )
682 {
683 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::stopFrameListening" );
684 SbaXDataBrowserController_Base::stopFrameListening( _rxFrame );
685
686 Reference< XFrameActionListener > xAggListener;
687 if ( m_xFormControllerImpl.is() )
688 m_xFormControllerImpl->queryAggregation( XFrameActionListener::static_type() ) >>= xAggListener;
689
690 if ( _rxFrame.is() && xAggListener.is() )
691 _rxFrame->removeFrameActionListener( xAggListener );
692 }
693
694 // -----------------------------------------------------------------------------
onStartLoading(const Reference<XLoadable> & _rxLoadable)695 void SbaXDataBrowserController::onStartLoading( const Reference< XLoadable >& _rxLoadable )
696 {
697 m_bLoadCanceled = sal_False;
698 m_bCannotSelectUnfiltered = false;
699
700 Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
701 if ( xWarnings.is() )
702 xWarnings->clearWarnings();
703 }
704
705 // -----------------------------------------------------------------------------
impl_checkForCannotSelectUnfiltered(const SQLExceptionInfo & _rError)706 void SbaXDataBrowserController::impl_checkForCannotSelectUnfiltered( const SQLExceptionInfo& _rError )
707 {
708 ::connectivity::SQLError aError( getORB() );
709 ::connectivity::ErrorCode nErrorCode( aError.getErrorCode( ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED ) );
710 if ( ((const SQLException*)_rError)->ErrorCode == nErrorCode )
711 {
712 m_bCannotSelectUnfiltered = true;
713 InvalidateFeature( ID_BROWSER_FILTERCRIT );
714 }
715 }
716
717 // -----------------------------------------------------------------------------
reloadForm(const Reference<XLoadable> & _rxLoadable)718 sal_Bool SbaXDataBrowserController::reloadForm( const Reference< XLoadable >& _rxLoadable )
719 {
720 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::reloadForm" );
721 WaitObject aWO(getBrowserView());
722
723 onStartLoading( _rxLoadable );
724
725 FormErrorHelper aReportError(this);
726 if (_rxLoadable->isLoaded())
727 _rxLoadable->reload();
728 else
729 _rxLoadable->load();
730
731 m_xParser.clear();
732 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
733 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
734 xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
735 #if 0
736 {
737 const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY );
738 const Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xRowSetProps->getPropertyValue( PROPERTY_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY );
739 if ( xAnalyzer.is() )
740 {
741 const Reference< XIndexAccess > xOrderColumns( xAnalyzer->getOrderColumns(), UNO_SET_THROW );
742 const sal_Int32 nOrderColumns( xOrderColumns->getCount() );
743 for ( sal_Int32 c=0; c<nOrderColumns; ++c )
744 {
745 const Reference< XPropertySet > xOrderColumn( xOrderColumns->getByIndex(c), UNO_QUERY_THROW );
746 ::rtl::OUString sColumnName;
747 OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumnName);
748 ::rtl::OUString sTableName;
749 OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName);
750 (void)sColumnName;
751 (void)sTableName;
752 }
753 }
754 }
755 #endif
756
757 Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
758 if ( xWarnings.is() )
759 {
760 try
761 {
762 SQLExceptionInfo aInfo( xWarnings->getWarnings() );
763 if ( aInfo.isValid() )
764 {
765 showError( aInfo );
766 impl_checkForCannotSelectUnfiltered( aInfo );
767 }
768 }
769 catch(const SQLException& e)
770 {
771 (void)e;
772 }
773 }
774
775 return _rxLoadable->isLoaded();
776 }
777
778 // -----------------------------------------------------------------------------
initFormatter()779 void SbaXDataBrowserController::initFormatter()
780 {
781 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::initFormatter" );
782 // ---------------------------------------------------------------
783 // create a formatter working with the connections format supplier
784 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), sal_True,getORB()));
785
786 if(xSupplier.is())
787 {
788 // create a new formatter
789 m_xFormatter = Reference< ::com::sun::star::util::XNumberFormatter > (
790 getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")), UNO_QUERY);
791 if (m_xFormatter.is())
792 m_xFormatter->attachNumberFormatsSupplier(xSupplier);
793 }
794 else // clear the formatter
795 m_xFormatter = NULL;
796 }
797 // -----------------------------------------------------------------------------
describeSupportedFeatures()798 void SbaXDataBrowserController::describeSupportedFeatures()
799 {
800 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::describeSupportedFeatures" );
801 SbaXDataBrowserController_Base::describeSupportedFeatures();
802 implDescribeSupportedFeature( ".uno:FormSlots/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
803 implDescribeSupportedFeature( ".uno:FormController/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
804 implDescribeSupportedFeature( ".uno:RecUndo", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
805 implDescribeSupportedFeature( ".uno:FormSlots/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
806 implDescribeSupportedFeature( ".uno:FormController/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
807 implDescribeSupportedFeature( ".uno:RecSave", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
808 implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVERECORD, CommandGroup::DOCUMENT );
809 implDescribeSupportedFeature( ".uno:RecSearch", SID_FM_SEARCH, CommandGroup::CONTROLS );
810 implDescribeSupportedFeature( ".uno:AutoFilter", SID_FM_AUTOFILTER, CommandGroup::CONTROLS );
811 implDescribeSupportedFeature( ".uno:Refresh", SID_FM_REFRESH, CommandGroup::CONTROLS );
812 implDescribeSupportedFeature( ".uno:OrderCrit", SID_FM_ORDERCRIT, CommandGroup::CONTROLS );
813 implDescribeSupportedFeature( ".uno:RemoveFilterSort", SID_FM_REMOVE_FILTER_SORT,CommandGroup::CONTROLS );
814 implDescribeSupportedFeature( ".uno:FormFiltered", SID_FM_FORM_FILTERED, CommandGroup::CONTROLS );
815 implDescribeSupportedFeature( ".uno:FilterCrit", SID_FM_FILTERCRIT, CommandGroup::CONTROLS );
816 implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP, CommandGroup::CONTROLS );
817 implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN, CommandGroup::CONTROLS );
818 implDescribeSupportedFeature( ".uno:FormSlots/deleteRecord", SID_FM_DELETEROWS, CommandGroup::EDIT );
819 implDescribeSupportedFeature( ".uno:FormSlots/insertRecord", ID_BROWSER_INSERT_ROW, CommandGroup::INSERT );
820 }
821 //------------------------------------------------------------------------------
Construct(Window * pParent)822 sal_Bool SbaXDataBrowserController::Construct(Window* pParent)
823 {
824 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::Construct" );
825 // ---------------------------------------------
826 // create/initialize the form and the grid model
827 m_xRowSet = CreateForm();
828 if (!m_xRowSet.is())
829 return sal_False;
830
831 m_xColumnsSupplier.set(m_xRowSet,UNO_QUERY);
832 m_xLoadable.set(m_xRowSet,UNO_QUERY);
833
834 Reference< XPropertySet > xFormProperties( m_xRowSet, UNO_QUERY );
835 if ( !InitializeForm( xFormProperties ) )
836 return sal_False;
837
838 m_xGridModel = CreateGridModel();
839 if (!m_xGridModel.is())
840 return sal_False;
841
842 // set the formatter if available
843 initFormatter();
844 // ---------------------------------------------------------------
845
846 // we want to have a grid with a "flat" border
847 Reference< XPropertySet > xGridSet(m_xGridModel, UNO_QUERY);
848 if ( xGridSet.is() )
849 xGridSet->setPropertyValue(PROPERTY_BORDER, makeAny((sal_Int16)2));
850
851 // ----------
852 // marry them
853 Reference< ::com::sun::star::container::XNameContainer > xNameCont(m_xRowSet, UNO_QUERY);
854 {
855 String sText(ModuleRes(STR_DATASOURCE_GRIDCONTROL_NAME));
856 xNameCont->insertByName(::rtl::OUString(sText), makeAny(m_xGridModel));
857 }
858
859 // ---------------
860 // create the view
861 setView( * new UnoDataBrowserView( pParent, *this, getORB() ) );
862 if (!getBrowserView())
863 return sal_False;
864
865 // late construction
866 sal_Bool bSuccess = sal_False;
867 try
868 {
869 getBrowserView()->Construct(getControlModel());
870 bSuccess = sal_True;
871 }
872 catch(SQLException&)
873 {
874 }
875 catch(Exception&)
876 {
877 DBG_ERROR("SbaXDataBrowserController::Construct : the construction of UnoDataBrowserView failed !");
878 }
879
880 if (!bSuccess)
881 {
882 // deleteView();
883 return sal_False;
884 }
885
886 // now that we have a view we can create the clipboard listener
887 m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
888 m_aSystemClipboard.StartClipboardListening( );
889
890 m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, SbaXDataBrowserController, OnClipboardChanged ) );
891 m_pClipbordNotifier->acquire();
892 m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
893
894 // this call create the toolbox
895 SbaXDataBrowserController_Base::Construct(pParent);
896
897 getBrowserView()->Show();
898
899 // set the callbacks for the grid control
900 SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
901 DBG_ASSERT(pVclGrid, "SbaXDataBrowserController::Construct : have no VCL control !");
902 pVclGrid->SetMasterListener(this);
903
904 // --------------------------
905 // add listeners ...
906
907 // ... to the form model
908 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
909 if (xFormSet.is())
910 {
911 xFormSet->addPropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
912 xFormSet->addPropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
913 xFormSet->addPropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
914 xFormSet->addPropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
915 xFormSet->addPropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
916 xFormSet->addPropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
917 xFormSet->addPropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
918 xFormSet->addPropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
919 }
920 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
921 if (xFormError.is())
922 xFormError->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
923
924 if (m_xLoadable.is())
925 m_xLoadable->addLoadListener(this);
926
927 Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY);
928 if (xFormParameter.is())
929 xFormParameter->addParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
930
931 addModelListeners(getControlModel());
932 addControlListeners(getBrowserView()->getGridControl());
933
934 // -------------
935 // load the form
936 return LoadForm();
937 }
938
939 //------------------------------------------------------------------------------
LoadForm()940 sal_Bool SbaXDataBrowserController::LoadForm()
941 {
942 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::LoadForm" );
943 reloadForm( m_xLoadable );
944 return sal_True;
945 }
946 //------------------------------------------------------------------------------
AddColumnListener(const Reference<XPropertySet> &)947 void SbaXDataBrowserController::AddColumnListener(const Reference< XPropertySet > & /*xCol*/)
948 {
949 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::AddColumnListener" );
950 // we're not interested in any column properties ...
951 }
952
953 //------------------------------------------------------------------------------
RemoveColumnListener(const Reference<XPropertySet> &)954 void SbaXDataBrowserController::RemoveColumnListener(const Reference< XPropertySet > & /*xCol*/)
955 {
956 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::RemoveColumnListener" );
957 }
958 //------------------------------------------------------------------------------
CreateForm()959 Reference< XRowSet > SbaXDataBrowserController::CreateForm()
960 {
961 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CreateForm" );
962 return Reference< XRowSet > (getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.form.component.Form")), UNO_QUERY);
963 }
964
965 //------------------------------------------------------------------------------
CreateGridModel()966 Reference< ::com::sun::star::form::XFormComponent > SbaXDataBrowserController::CreateGridModel()
967 {
968 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CreateGridModel" );
969 return Reference< ::com::sun::star::form::XFormComponent > (getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.form.component.GridControl")), UNO_QUERY);
970 }
971
972 // -------------------------------------------------------------------------
addModelListeners(const Reference<::com::sun::star::awt::XControlModel> & _xGridControlModel)973 void SbaXDataBrowserController::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
974 {
975 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::addModelListeners" );
976 // ... all the grid columns
977 addColumnListeners(_xGridControlModel);
978
979 // (we are interested in all columns the grid has (and only in these) so we have to listen to the container, too)
980 Reference< ::com::sun::star::container::XContainer > xColContainer(_xGridControlModel, UNO_QUERY);
981 if (xColContainer.is())
982 xColContainer->addContainerListener((::com::sun::star::container::XContainerListener*)this);
983
984 Reference< ::com::sun::star::form::XReset > xReset(_xGridControlModel, UNO_QUERY);
985 if (xReset.is())
986 xReset->addResetListener((::com::sun::star::form::XResetListener*)this);
987 }
988
989 // -------------------------------------------------------------------------
removeModelListeners(const Reference<XControlModel> & _xGridControlModel)990 void SbaXDataBrowserController::removeModelListeners(const Reference< XControlModel > & _xGridControlModel)
991 {
992 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::removeModelListeners" );
993 // every single column model
994 Reference< XIndexContainer > xColumns(_xGridControlModel, UNO_QUERY);
995 if (xColumns.is())
996 {
997 sal_Int32 nCount = xColumns->getCount();
998 for (sal_uInt16 i=0; i < nCount; ++i)
999 {
1000 Reference< XPropertySet > xCol(xColumns->getByIndex(i),UNO_QUERY);
1001 RemoveColumnListener(xCol);
1002 }
1003 }
1004
1005 Reference< XContainer > xColContainer(_xGridControlModel, UNO_QUERY);
1006 if (xColContainer.is())
1007 xColContainer->removeContainerListener( this );
1008
1009 Reference< XReset > xReset(_xGridControlModel, UNO_QUERY);
1010 if (xReset.is())
1011 xReset->removeResetListener( this );
1012 }
1013
1014 // -------------------------------------------------------------------------
addControlListeners(const Reference<::com::sun::star::awt::XControl> & _xGridControl)1015 void SbaXDataBrowserController::addControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
1016 {
1017 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::addControlListeners" );
1018 // to ge the 'modified' for the current cell
1019 Reference< XModifyBroadcaster > xBroadcaster(getBrowserView()->getGridControl(), UNO_QUERY);
1020 if (xBroadcaster.is())
1021 xBroadcaster->addModifyListener(static_cast<XModifyListener*>(this));
1022
1023 // introduce ourself as dispatch provider for the grid
1024 Reference< XDispatchProviderInterception > xInterception(getBrowserView()->getGridControl(), UNO_QUERY);
1025 if (xInterception.is())
1026 xInterception->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
1027
1028 // add as focus listener to the control (needed for the form controller functionality)
1029 Reference< XWindow > xWindow(_xGridControl, UNO_QUERY);
1030 if (xWindow.is())
1031 xWindow->addFocusListener(this);
1032 }
1033
1034 // -------------------------------------------------------------------------
removeControlListeners(const Reference<::com::sun::star::awt::XControl> & _xGridControl)1035 void SbaXDataBrowserController::removeControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
1036 {
1037 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::removeControlListeners" );
1038 Reference< XModifyBroadcaster > xBroadcaster(_xGridControl, UNO_QUERY);
1039 if (xBroadcaster.is())
1040 xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
1041
1042 Reference< XDispatchProviderInterception > xInterception(_xGridControl, UNO_QUERY);
1043 if (xInterception.is())
1044 xInterception->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
1045
1046 Reference< XWindow > xWindow(_xGridControl, UNO_QUERY);
1047 if (xWindow.is())
1048 xWindow->removeFocusListener(this);
1049 }
1050
1051 //------------------------------------------------------------------
focusGained(const FocusEvent &)1052 void SAL_CALL SbaXDataBrowserController::focusGained(const FocusEvent& /*e*/) throw( RuntimeException )
1053 {
1054 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::focusGained" );
1055 // notify our activate listeners (registered on the form controller aggregate)
1056 EventObject aEvt(*this);
1057 ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
1058 while (aIter.hasMoreElements())
1059 static_cast<XFormControllerListener*>(aIter.next())->formActivated(aEvt);
1060 }
1061
1062 //------------------------------------------------------------------
focusLost(const FocusEvent & e)1063 void SAL_CALL SbaXDataBrowserController::focusLost(const FocusEvent& e) throw( RuntimeException )
1064 {
1065 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::focusLost" );
1066 // some general checks
1067 if (!getBrowserView() || !getBrowserView()->getGridControl().is())
1068 return;
1069 Reference< XVclWindowPeer > xMyGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
1070 if (!xMyGridPeer.is())
1071 return;
1072 Reference< XWindowPeer > xNextControlPeer(e.NextFocus, UNO_QUERY);
1073 if (!xNextControlPeer.is())
1074 return;
1075
1076 // don't do a notification if it remains in the family (i.e. a child of the grid control gets the focus)
1077 if (xMyGridPeer->isChild(xNextControlPeer))
1078 return;
1079
1080 if (xMyGridPeer == xNextControlPeer)
1081 return;
1082
1083 // notify the listeners that the "form" we represent has been deactivated
1084 EventObject aEvt(*this);
1085 ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
1086 while (aIter.hasMoreElements())
1087 static_cast<XFormControllerListener*>(aIter.next())->formDeactivated(aEvt);
1088
1089 // commit the changes of the grid control (as we're deactivated)
1090 Reference< XBoundComponent > xCommitable(getBrowserView()->getGridControl(), UNO_QUERY);
1091 if (xCommitable.is())
1092 xCommitable->commit();
1093 else
1094 OSL_ENSURE(sal_False, "SbaXDataBrowserController::focusLost : why is my control not commitable ?");
1095 }
1096
1097 // -------------------------------------------------------------------------
disposingGridControl(const::com::sun::star::lang::EventObject &)1098 void SbaXDataBrowserController::disposingGridControl(const ::com::sun::star::lang::EventObject& /*Source*/)
1099 {
1100 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingGridControl" );
1101 removeControlListeners(getBrowserView()->getGridControl());
1102 }
1103
1104 // -------------------------------------------------------------------------
disposingGridModel(const::com::sun::star::lang::EventObject &)1105 void SbaXDataBrowserController::disposingGridModel(const ::com::sun::star::lang::EventObject& /*Source*/)
1106 {
1107 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingGridModel" );
1108 removeModelListeners(getControlModel());
1109 }
1110
1111 // -------------------------------------------------------------------------
disposingFormModel(const::com::sun::star::lang::EventObject & Source)1112 void SbaXDataBrowserController::disposingFormModel(const ::com::sun::star::lang::EventObject& Source)
1113 {
1114 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingFormModel" );
1115 Reference< XPropertySet > xSourceSet(Source.Source, UNO_QUERY);
1116 if (xSourceSet.is())
1117 {
1118 xSourceSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
1119 xSourceSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
1120 xSourceSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
1121 xSourceSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
1122 xSourceSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
1123 xSourceSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
1124 xSourceSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
1125 xSourceSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
1126 }
1127
1128 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(Source.Source, UNO_QUERY);
1129 if (xFormError.is())
1130 xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
1131
1132 if (m_xLoadable.is())
1133 m_xLoadable->removeLoadListener(this);
1134
1135 Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(Source.Source, UNO_QUERY);
1136 if (xFormParameter.is())
1137 xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
1138 }
1139
1140 // -------------------------------------------------------------------------
disposingColumnModel(const::com::sun::star::lang::EventObject & Source)1141 void SbaXDataBrowserController::disposingColumnModel(const ::com::sun::star::lang::EventObject& Source)
1142 {
1143 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingColumnModel" );
1144 RemoveColumnListener(Reference< XPropertySet > (Source.Source, UNO_QUERY));
1145 }
1146
1147 // -------------------------------------------------------------------------
disposing(const EventObject & Source)1148 void SbaXDataBrowserController::disposing(const EventObject& Source) throw( RuntimeException )
1149 {
1150 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposing" );
1151 // if it's a component other than our aggregate, forward it to the aggregate
1152 if ( m_xFormControllerImpl != Source.Source )
1153 {
1154 Reference< XEventListener > xAggListener;
1155 m_xFormControllerImpl->queryAggregation( ::getCppuType( &xAggListener ) ) >>= xAggListener;
1156 if ( xAggListener.is( ))
1157 xAggListener->disposing( Source );
1158 }
1159
1160 // is it the grid control ?
1161 if (getBrowserView())
1162 {
1163 Reference< ::com::sun::star::awt::XControl > xSourceControl(Source.Source, UNO_QUERY);
1164 if (xSourceControl == getBrowserView()->getGridControl())
1165 disposingGridControl(Source);
1166 }
1167
1168 // it's model (the container of the columns) ?
1169 if (getControlModel() == Source.Source)
1170 disposingGridModel(Source);
1171
1172 // the form's model ?
1173 if ((getRowSet() == Source.Source))
1174 disposingFormModel(Source);
1175
1176 // from a single column model ?
1177 Reference< XPropertySet > xSourceSet(Source.Source, UNO_QUERY);
1178 if (xSourceSet.is())
1179 {
1180 Reference< XPropertySetInfo > xInfo = xSourceSet->getPropertySetInfo();
1181 // we assume that columns have a Width property and all other sets we are listening to don't have
1182 if (xInfo->hasPropertyByName(PROPERTY_WIDTH))
1183 disposingColumnModel(Source);
1184 }
1185 SbaXDataBrowserController_Base::OGenericUnoController::disposing( Source );
1186 }
1187
1188 // -----------------------------------------------------------------------
setIdentifier(const::rtl::OUString & _Identifier)1189 void SAL_CALL SbaXDataBrowserController::setIdentifier( const ::rtl::OUString& _Identifier ) throw (RuntimeException)
1190 {
1191 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::setIdentifier" );
1192 ::osl::MutexGuard aGuard( getMutex() );
1193 m_sModuleIdentifier = _Identifier;
1194 }
1195
1196 // -----------------------------------------------------------------------
getIdentifier()1197 ::rtl::OUString SAL_CALL SbaXDataBrowserController::getIdentifier( ) throw (RuntimeException)
1198 {
1199 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getIdentifier" );
1200 ::osl::MutexGuard aGuard( getMutex() );
1201 return m_sModuleIdentifier;
1202 }
1203
1204 // -----------------------------------------------------------------------
propertyChange(const PropertyChangeEvent & evt)1205 void SbaXDataBrowserController::propertyChange(const PropertyChangeEvent& evt) throw ( RuntimeException )
1206 {
1207 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::propertyChange" );
1208 Reference< XPropertySet > xSource(evt.Source, UNO_QUERY);
1209 if (!xSource.is())
1210 return;
1211
1212 ::vos::OGuard aGuard(Application::GetSolarMutex());
1213 // the IsModified changed to sal_False ?
1214 if ( (evt.PropertyName.equals(PROPERTY_ISMODIFIED))
1215 && (::comphelper::getBOOL(evt.NewValue) == sal_False)
1216 )
1217 { // -> the current field isn't modified anymore, too
1218 setCurrentModified( sal_False );
1219 }
1220
1221 // switching to a new record ?
1222 if ( (evt.PropertyName.equals(PROPERTY_ISNEW))
1223 && (::comphelper::getBOOL(evt.NewValue) == sal_True)
1224 )
1225 {
1226 if (::comphelper::getINT32(xSource->getPropertyValue(PROPERTY_ROWCOUNT)) == 0)
1227 // if we're switching to a new record and didn't have any records before we need to invalidate
1228 // all slots (as the cursor was invalid before the mode change and so the slots were disabled)
1229 InvalidateAll();
1230 }
1231
1232
1233 if (evt.PropertyName.equals(PROPERTY_FILTER))
1234 {
1235 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1236 }
1237 else if (evt.PropertyName.equals(PROPERTY_HAVING_CLAUSE))
1238 {
1239 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1240 }
1241 else if (evt.PropertyName.equals(PROPERTY_ORDER))
1242 {
1243 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1244 }
1245
1246 // a new record count ? -> may be our search availability has changed
1247 if (evt.PropertyName.equals(PROPERTY_ROWCOUNT))
1248 {
1249 sal_Int32 nNewValue = 0, nOldValue = 0;
1250 evt.NewValue >>= nNewValue;
1251 evt.OldValue >>= nOldValue;
1252 if((nOldValue == 0 && nNewValue != 0) || (nOldValue != 0 && nNewValue == 0))
1253 InvalidateAll();
1254 }
1255 }
1256
1257 //------------------------------------------------------------------------
modified(const::com::sun::star::lang::EventObject &)1258 void SbaXDataBrowserController::modified(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
1259 {
1260 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::modified" );
1261 setCurrentModified( sal_True );
1262 }
1263
1264 // -----------------------------------------------------------------------
elementInserted(const::com::sun::star::container::ContainerEvent & evt)1265 void SbaXDataBrowserController::elementInserted(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException )
1266 {
1267 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::elementInserted" );
1268 DBG_ASSERT(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
1269 "SbaXDataBrowserController::elementInserted: where did this come from (not from the grid model)?!");
1270 Reference< XPropertySet > xNewColumn(evt.Element,UNO_QUERY);
1271 if ( xNewColumn.is() )
1272 AddColumnListener(xNewColumn);
1273 }
1274
1275 // -----------------------------------------------------------------------
elementRemoved(const::com::sun::star::container::ContainerEvent & evt)1276 void SbaXDataBrowserController::elementRemoved(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException )
1277 {
1278 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::elementRemoved" );
1279 DBG_ASSERT(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
1280 "SbaXDataBrowserController::elementRemoved: where did this come from (not from the grid model)?!");
1281 Reference< XPropertySet > xOldColumn(evt.Element,UNO_QUERY);
1282 if ( xOldColumn.is() )
1283 RemoveColumnListener(xOldColumn);
1284 }
1285
1286 // -----------------------------------------------------------------------
elementReplaced(const::com::sun::star::container::ContainerEvent & evt)1287 void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException )
1288 {
1289 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::elementReplaced" );
1290 DBG_ASSERT(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
1291 "SbaXDataBrowserController::elementReplaced: where did this come from (not from the grid model)?!");
1292 Reference< XPropertySet > xOldColumn(evt.ReplacedElement,UNO_QUERY);
1293 if ( xOldColumn.is() )
1294 RemoveColumnListener(xOldColumn);
1295
1296 Reference< XPropertySet > xNewColumn(evt.Element,UNO_QUERY);
1297 if ( xNewColumn.is() )
1298 AddColumnListener(xNewColumn);
1299 }
1300
1301 // -----------------------------------------------------------------------
suspend(sal_Bool)1302 sal_Bool SbaXDataBrowserController::suspend(sal_Bool /*bSuspend*/) throw( RuntimeException )
1303 {
1304 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::suspend" );
1305 DBG_ASSERT(m_nPendingLoadFinished == 0, "SbaXDataBrowserController::suspend : there shouldn't be a pending load !");
1306
1307 m_aAsyncGetCellFocus.CancelCall();
1308 m_aAsyncDisplayError.CancelCall();
1309 m_aAsyncInvalidateAll.CancelCall();
1310
1311 sal_Bool bSuccess = SaveModified();
1312 return bSuccess;
1313 }
1314 // -----------------------------------------------------------------------
disposing()1315 void SbaXDataBrowserController::disposing()
1316 {
1317 // the base class
1318 SbaXDataBrowserController_Base::OGenericUnoController::disposing();
1319
1320 // the data source
1321 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1322 if (xFormSet.is())
1323 {
1324 xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
1325 xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
1326 xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
1327 xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
1328 xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
1329 xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
1330 xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
1331 xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
1332 }
1333
1334 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
1335 if (xFormError.is())
1336 xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
1337
1338 if (m_xLoadable.is())
1339 m_xLoadable->removeLoadListener(this);
1340
1341 Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY);
1342 if (xFormParameter.is())
1343 xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
1344
1345 removeModelListeners(getControlModel());
1346
1347 if ( getView() && m_pClipbordNotifier )
1348 {
1349 m_pClipbordNotifier->ClearCallbackLink();
1350 m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
1351 m_pClipbordNotifier->release();
1352 m_pClipbordNotifier = NULL;
1353 }
1354
1355 if (getBrowserView())
1356 {
1357 removeControlListeners(getBrowserView()->getGridControl());
1358 // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...)
1359 clearView();
1360 }
1361
1362 if(m_aInvalidateClipboard.IsActive())
1363 m_aInvalidateClipboard.Stop();
1364
1365 // dispose the row set
1366 try
1367 {
1368 ::comphelper::disposeComponent(m_xRowSet);
1369
1370 m_xRowSet = NULL;
1371 m_xColumnsSupplier = NULL;
1372 m_xLoadable = NULL;
1373 }
1374 catch(Exception&)
1375 {
1376 DBG_UNHANDLED_EXCEPTION();
1377 }
1378 m_xParser.clear();
1379 // don't dispose, just reset - it's owned by the RowSet
1380 }
1381 //------------------------------------------------------------------------------
frameAction(const::com::sun::star::frame::FrameActionEvent & aEvent)1382 void SbaXDataBrowserController::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
1383 {
1384 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::frameAction" );
1385 ::osl::MutexGuard aGuard( getMutex() );
1386
1387 SbaXDataBrowserController_Base::frameAction( aEvent );
1388
1389 if ( aEvent.Source == getFrame() )
1390 switch ( aEvent.Action )
1391 {
1392 case FrameAction_FRAME_ACTIVATED:
1393 case FrameAction_FRAME_UI_ACTIVATED:
1394 // ensure that the active cell (if any) has the focus
1395 m_aAsyncGetCellFocus.Call();
1396 // start the clipboard timer
1397 if (getBrowserView() && getBrowserView()->getVclControl() && !m_aInvalidateClipboard.IsActive())
1398 {
1399 m_aInvalidateClipboard.Start();
1400 OnInvalidateClipboard( NULL );
1401 }
1402 break;
1403 case FrameAction_FRAME_DEACTIVATING:
1404 case FrameAction_FRAME_UI_DEACTIVATING:
1405 // stop the clipboard invalidator
1406 if (getBrowserView() && getBrowserView()->getVclControl() && m_aInvalidateClipboard.IsActive())
1407 {
1408 m_aInvalidateClipboard.Stop();
1409 OnInvalidateClipboard( NULL );
1410 }
1411 // remove the "get cell focus"-event
1412 m_aAsyncGetCellFocus.CancelCall();
1413 break;
1414 default:
1415 break;
1416 }
1417 }
1418
1419 //------------------------------------------------------------------------------
1420 IMPL_LINK( SbaXDataBrowserController, OnAsyncDisplayError, void*, /* _pNotInterestedIn */ )
1421 {
1422 if ( m_aCurrentError.isValid() )
1423 {
1424 OSQLMessageBox aDlg( getBrowserView(), m_aCurrentError );
1425 aDlg.Execute();
1426 }
1427 return 0L;
1428 }
1429
1430 //------------------------------------------------------------------------------
errorOccured(const::com::sun::star::sdb::SQLErrorEvent & aEvent)1431 void SbaXDataBrowserController::errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( RuntimeException )
1432 {
1433 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::errorOccured" );
1434 ::osl::MutexGuard aGuard( getMutex() );
1435
1436 SQLExceptionInfo aInfo( aEvent.Reason );
1437 if ( !aInfo.isValid() )
1438 return;
1439
1440 if ( m_nFormActionNestingLevel )
1441 {
1442 OSL_ENSURE( !m_aCurrentError.isValid(), "SbaXDataBrowserController::errorOccured: can handle one error per transaction only!" );
1443 m_aCurrentError = aInfo;
1444 }
1445 else
1446 {
1447 m_aCurrentError = aInfo;
1448 m_aAsyncDisplayError.Call();
1449 }
1450 }
1451
1452 //------------------------------------------------------------------------------
approveParameter(const::com::sun::star::form::DatabaseParameterEvent & aEvent)1453 sal_Bool SbaXDataBrowserController::approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( RuntimeException )
1454 {
1455 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::approveParameter" );
1456 if (aEvent.Source != getRowSet())
1457 {
1458 // not my data source -> allow anything
1459 DBG_ERROR("SbaXDataBrowserController::approveParameter : invalid event source !");
1460 return sal_True;
1461 }
1462
1463 Reference< ::com::sun::star::container::XIndexAccess > xParameters = aEvent.Parameters;
1464 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1465 // this may be executed in a non-main thread and we want to use vcl ...
1466 Window* pParent = Application::GetDefDialogParent();
1467 // don't use the content as parent if it isn't visible
1468 // (and don't use NULL as parent : this may be displayed in the beamer and really shouldn't be task-local)
1469 // 69297 - FS - 25.10.99
1470 if (getBrowserView() && getBrowserView()->IsVisible())
1471 pParent = getBrowserView();
1472
1473 // default handling: instantiate an interaction handler and let it handle the parameter request
1474 try
1475 {
1476 // two continuations allowed: OK and Cancel
1477 OParameterContinuation* pParamValues = new OParameterContinuation;
1478 OInteractionAbort* pAbort = new OInteractionAbort;
1479 // the request
1480 ParametersRequest aRequest;
1481 aRequest.Parameters = xParameters;
1482 aRequest.Connection = getConnection(Reference< XRowSet >(aEvent.Source, UNO_QUERY));
1483 OInteractionRequest* pParamRequest = new OInteractionRequest(makeAny(aRequest));
1484 Reference< XInteractionRequest > xParamRequest(pParamRequest);
1485 // some knittings
1486 pParamRequest->addContinuation(pParamValues);
1487 pParamRequest->addContinuation(pAbort);
1488
1489 // create the handler, let it handle the request
1490 Reference< XInteractionHandler > xHandler(getORB()->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY);
1491 if (xHandler.is())
1492 xHandler->handle(xParamRequest);
1493
1494 if (!pParamValues->wasSelected())
1495 { // canceled
1496 setLoadingCancelled();
1497 return sal_False;
1498 }
1499
1500 // transfer the values into the parameter supplier
1501 Sequence< PropertyValue > aFinalValues = pParamValues->getValues();
1502 if (aFinalValues.getLength() != aRequest.Parameters->getCount())
1503 {
1504 DBG_ERROR("SbaXDataBrowserController::approveParameter: the InteractionHandler returned nonsense!");
1505 setLoadingCancelled();
1506 return sal_False;
1507 }
1508 const PropertyValue* pFinalValues = aFinalValues.getConstArray();
1509 for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues)
1510 {
1511 Reference< XPropertySet > xParam;
1512 ::cppu::extractInterface(xParam, aRequest.Parameters->getByIndex(i));
1513 DBG_ASSERT(xParam.is(), "SbaXDataBrowserController::approveParameter: one of the parameters is no property set!");
1514 if (xParam.is())
1515 {
1516 #ifdef DBG_UTIL
1517 ::rtl::OUString sName;
1518 xParam->getPropertyValue(PROPERTY_NAME) >>= sName;
1519 DBG_ASSERT(sName.equals(pFinalValues->Name), "SbaXDataBrowserController::approveParameter: suspicious value names!");
1520 #endif
1521 try { xParam->setPropertyValue(PROPERTY_VALUE, pFinalValues->Value); }
1522 catch(Exception&)
1523 {
1524 DBG_ERROR("SbaXDataBrowserController::approveParameter: setting one of the properties failed!");
1525 }
1526 }
1527 }
1528 }
1529 catch( const Exception& )
1530 {
1531 DBG_UNHANDLED_EXCEPTION();
1532 }
1533
1534 return sal_True;
1535 }
1536
1537
1538 //------------------------------------------------------------------------------
approveReset(const::com::sun::star::lang::EventObject &)1539 sal_Bool SbaXDataBrowserController::approveReset(const ::com::sun::star::lang::EventObject& /*rEvent*/) throw( RuntimeException )
1540 {
1541 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::approveReset" );
1542 return sal_True;
1543 }
1544
1545 //------------------------------------------------------------------------------
resetted(const::com::sun::star::lang::EventObject & rEvent)1546 void SbaXDataBrowserController::resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( RuntimeException )
1547 {
1548 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::resetted" );
1549 DBG_ASSERT(rEvent.Source == getControlModel(), "SbaXDataBrowserController::resetted : where did this come from ?");
1550 (void)rEvent;
1551 setCurrentModified( sal_False );
1552 }
1553
1554 //------------------------------------------------------------------------------
confirmDelete(const::com::sun::star::sdb::RowChangeEvent &)1555 sal_Bool SbaXDataBrowserController::confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& /*aEvent*/) throw( RuntimeException )
1556 {
1557 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::confirmDelete" );
1558 if (QueryBox(getBrowserView(), ModuleRes(QUERY_BRW_DELETE_ROWS)).Execute() != RET_YES)
1559 return sal_False;
1560
1561 return sal_True;
1562 }
1563 //------------------------------------------------------------------------------
GetState(sal_uInt16 nId) const1564 FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const
1565 {
1566 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::GetState" );
1567 FeatureState aReturn;
1568 // (disabled automatically)
1569
1570 try
1571 {
1572 // no chance without a view
1573 if (!getBrowserView() || !getBrowserView()->getVclControl())
1574 return aReturn;
1575
1576 switch (nId)
1577 {
1578 case ID_BROWSER_REMOVEFILTER:
1579 if (!m_xParser.is())
1580 {
1581 aReturn.bEnabled = false;
1582 return aReturn;
1583 }
1584 // any filter or sort order set ?
1585 aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength();
1586 return aReturn;
1587 }
1588 // no chance without valid models
1589 if (isValid() && !isValidCursor())
1590 return aReturn;
1591
1592 switch (nId)
1593 {
1594 case ID_BROWSER_SEARCH:
1595 {
1596 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1597 sal_Int32 nCount = ::comphelper::getINT32(xFormSet->getPropertyValue(PROPERTY_ROWCOUNT));
1598 aReturn.bEnabled = nCount != 0;
1599 }
1600 break;
1601 case ID_BROWSER_INSERT_ROW:
1602 {
1603 // check if it is available
1604 sal_Bool bInsertPrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
1605 sal_Bool bAllowInsertions = sal_True;
1606 try
1607 {
1608 Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1609 OSL_VERIFY( xRowSetProps->getPropertyValue( ::rtl::OUString::createFromAscii( "AllowInserts" ) ) >>= bAllowInsertions );
1610 }
1611 catch( const Exception& )
1612 {
1613 DBG_UNHANDLED_EXCEPTION();
1614 }
1615 aReturn.bEnabled = bInsertPrivilege && bAllowInsertions;
1616 }
1617 break;
1618 case SID_FM_DELETEROWS:
1619 {
1620 // check if it is available
1621 sal_Bool bDeletePrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
1622 sal_Bool bAllowDeletions = sal_True;
1623 sal_Int32 nRowCount = 0;
1624 sal_Bool bInsertionRow = sal_False;
1625 try
1626 {
1627 Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1628 OSL_VERIFY( xRowSetProps->getPropertyValue( ::rtl::OUString::createFromAscii( "AllowDeletes" ) ) >>= bAllowDeletions );
1629 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ROWCOUNT ) >>= nRowCount );
1630 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ISNEW ) >>= bInsertionRow );
1631 }
1632 catch( const Exception& )
1633 {
1634 DBG_UNHANDLED_EXCEPTION();
1635 }
1636 aReturn.bEnabled = bDeletePrivilege && bAllowDeletions && ( nRowCount != 0 ) && !bInsertionRow;
1637 }
1638 break;
1639
1640 case ID_BROWSER_COPY:
1641 if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
1642 {
1643 aReturn.bEnabled = m_aCurrentFrame.isActive();
1644 break;
1645 }
1646 // run through
1647 case ID_BROWSER_PASTE:
1648 case ID_BROWSER_CUT:
1649 {
1650 CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
1651 if (xCurrentController.Is() && xCurrentController->ISA(EditCellController))
1652 {
1653 Edit& rEdit = (Edit&)xCurrentController->GetWindow();
1654 sal_Bool bHasLen = (rEdit.GetSelection().Len() != 0);
1655 sal_Bool bIsReadOnly = rEdit.IsReadOnly();
1656 switch (nId)
1657 {
1658 case ID_BROWSER_CUT: aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen && !bIsReadOnly; break;
1659 case SID_COPY : aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen; break;
1660 case ID_BROWSER_PASTE:
1661 aReturn.bEnabled = m_aCurrentFrame.isActive() && !bIsReadOnly;
1662 if(aReturn.bEnabled)
1663 {
1664 aReturn.bEnabled = aReturn.bEnabled && IsFormatSupported( m_aSystemClipboard.GetDataFlavorExVector(), FORMAT_STRING );
1665 }
1666 break;
1667 }
1668 }
1669 }
1670 break;
1671
1672 case ID_BROWSER_SORTUP:
1673 case ID_BROWSER_SORTDOWN:
1674 case ID_BROWSER_AUTOFILTER:
1675 {
1676 // a native statement can't be filtered or sorted
1677 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1678 if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
1679 break;
1680
1681 Reference< XPropertySet > xCurrentField = getBoundField();
1682 if (!xCurrentField.is())
1683 break;
1684
1685 aReturn.bEnabled = ::comphelper::getBOOL(xCurrentField->getPropertyValue(PROPERTY_ISSEARCHABLE));
1686 const Reference< XRowSet > xRow = getRowSet();
1687 aReturn.bEnabled = aReturn.bEnabled
1688 && xRow.is()
1689 && !xRow->isBeforeFirst()
1690 && !xRow->isAfterLast()
1691 && !xRow->rowDeleted()
1692 && ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
1693 }
1694 break;
1695
1696 case ID_BROWSER_FILTERCRIT:
1697 if ( m_bCannotSelectUnfiltered && m_xParser.is() )
1698 {
1699 aReturn.bEnabled = sal_True;
1700 break;
1701 }
1702 // no break
1703 case ID_BROWSER_ORDERCRIT:
1704 {
1705 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1706 if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
1707 break;
1708
1709 aReturn.bEnabled = getRowSet().is()
1710 && ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
1711 }
1712 break;
1713
1714 case ID_BROWSER_REFRESH:
1715 aReturn.bEnabled = sal_True;
1716 break;
1717
1718 case ID_BROWSER_REDO:
1719 aReturn.bEnabled = sal_False; // simply forget it ;). no redo possible.
1720 break;
1721
1722 case ID_BROWSER_UNDORECORD:
1723 case ID_BROWSER_SAVERECORD:
1724 {
1725 if (!m_bCurrentlyModified)
1726 {
1727 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1728 if (xFormSet.is())
1729 aReturn.bEnabled = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED));
1730 }
1731 else
1732 aReturn.bEnabled = sal_True;
1733
1734 aReturn.sTitle = (ID_BROWSER_UNDORECORD == nId) ? m_sStateUndoRecord : m_sStateSaveRecord;
1735 }
1736 break;
1737 case ID_BROWSER_EDITDOC:
1738 {
1739 // check if it is available
1740 Reference< XPropertySet > xDataSourceSet(getRowSet(), UNO_QUERY);
1741 if (!xDataSourceSet.is())
1742 break; // no datasource -> no edit mode
1743
1744 sal_Int32 nDataSourcePrivileges = ::comphelper::getINT32(xDataSourceSet->getPropertyValue(PROPERTY_PRIVILEGES));
1745 sal_Bool bInsertAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::INSERT) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue(::rtl::OUString::createFromAscii("AllowInserts")));
1746 sal_Bool bUpdateAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::UPDATE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue(::rtl::OUString::createFromAscii("AllowUpdates")));
1747 sal_Bool bDeleteAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::DELETE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue(::rtl::OUString::createFromAscii("AllowDeletes")));
1748 if (!bInsertAllowedAndPossible && !bUpdateAllowedAndPossible && !bDeleteAllowedAndPossible)
1749 break; // no insert/update/delete -> no edit mode
1750
1751 if (!isValidCursor() || !isLoaded())
1752 break; // no cursor -> no edit mode
1753
1754 aReturn.bEnabled = sal_True;
1755
1756 sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
1757 aReturn.bChecked = nGridMode > DbGridControl::OPT_READONLY;
1758 }
1759 break;
1760 case ID_BROWSER_FILTERED:
1761 {
1762 aReturn.bEnabled = sal_False;
1763 Reference< XPropertySet > xActiveSet(getRowSet(), UNO_QUERY);
1764 ::rtl::OUString aFilter = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_FILTER));
1765 ::rtl::OUString aHaving = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_HAVING_CLAUSE));
1766 if ( aFilter.getLength() || aHaving.getLength() )
1767 {
1768 xActiveSet->getPropertyValue( PROPERTY_APPLYFILTER ) >>= aReturn.bChecked;
1769 aReturn.bEnabled = sal_True;
1770 }
1771 else
1772 {
1773 aReturn.bChecked = sal_False;
1774 aReturn.bEnabled = sal_False;
1775 }
1776 }
1777 break;
1778 default:
1779 return SbaXDataBrowserController_Base::GetState(nId);
1780 }
1781 }
1782 catch(const Exception& )
1783 {
1784 DBG_UNHANDLED_EXCEPTION();
1785 }
1786
1787 return aReturn;
1788 }
1789
1790 //------------------------------------------------------------------------------
applyParserOrder(const::rtl::OUString & _rOldOrder,const Reference<XSingleSelectQueryComposer> & _xParser)1791 void SbaXDataBrowserController::applyParserOrder(const ::rtl::OUString& _rOldOrder,const Reference< XSingleSelectQueryComposer >& _xParser)
1792 {
1793 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::applyParserOrder" );
1794 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1795 if (!m_xLoadable.is())
1796 {
1797 OSL_ENSURE(sal_False, "SbaXDataBrowserController::applyParserOrder: invalid row set!");
1798 return;
1799 }
1800
1801 sal_uInt16 nPos = getCurrentColumnPosition();
1802 sal_Bool bSuccess = sal_False;
1803 try
1804 {
1805 xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_xParser->getOrder()));
1806 bSuccess = reloadForm(m_xLoadable);
1807 }
1808 catch(Exception&)
1809 {
1810 }
1811
1812 if (!bSuccess)
1813 {
1814 xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_rOldOrder));
1815 //DO_SAFE( _xParser->setOrder(_rOldOrder), "SbaXDataBrowserController::applyParserOrder: could not restore the old order of my parser !" );
1816
1817 try
1818 {
1819 if (loadingCancelled() || !reloadForm(m_xLoadable))
1820 criticalFail();
1821 }
1822 catch(Exception&)
1823 {
1824 criticalFail();
1825 }
1826 InvalidateAll();
1827 }
1828 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1829
1830 setCurrentColumnPosition(nPos);
1831 }
1832
1833 //------------------------------------------------------------------------------
applyParserFilter(const::rtl::OUString & _rOldFilter,sal_Bool _bOldFilterApplied,const::rtl::OUString & _sOldHaving,const Reference<XSingleSelectQueryComposer> & _xParser)1834 void SbaXDataBrowserController::applyParserFilter(const ::rtl::OUString& _rOldFilter, sal_Bool _bOldFilterApplied,const ::rtl::OUString& _sOldHaving,const Reference< XSingleSelectQueryComposer >& _xParser)
1835 {
1836 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::applyParserFilter" );
1837 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1838 if (!m_xLoadable.is())
1839 {
1840 OSL_ENSURE(sal_False, "SbaXDataBrowserController::applyParserFilter: invalid row set!");
1841 return;
1842 }
1843
1844 sal_uInt16 nPos = getCurrentColumnPosition();
1845
1846 sal_Bool bSuccess = sal_False;
1847 try
1848 {
1849 FormErrorHelper aError(this);
1850 xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_xParser->getFilter()));
1851 xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_xParser->getHavingClause()));
1852 xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(sal_Bool(sal_True)));
1853
1854 bSuccess = reloadForm(m_xLoadable);
1855 }
1856 catch(Exception&)
1857 {
1858 }
1859
1860 if (!bSuccess)
1861 {
1862 xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_rOldFilter));
1863 xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_sOldHaving));
1864 xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(_bOldFilterApplied));
1865
1866 try
1867 {
1868 if (loadingCancelled() || !reloadForm(m_xLoadable))
1869 criticalFail();
1870 }
1871 catch(Exception&)
1872 {
1873 criticalFail();
1874 }
1875 InvalidateAll();
1876 }
1877 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1878
1879 setCurrentColumnPosition(nPos);
1880 }
1881
1882 //------------------------------------------------------------------------------
createParser_nothrow()1883 Reference< XSingleSelectQueryComposer > SbaXDataBrowserController::createParser_nothrow()
1884 {
1885 Reference< XSingleSelectQueryComposer > xComposer;
1886 try
1887 {
1888 const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1889 const Reference< XMultiServiceFactory > xFactory(
1890 xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY_THROW );
1891 xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1892
1893 ::rtl::OUString sActiveCommand;
1894 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sActiveCommand );
1895 if ( sActiveCommand.getLength() > 0 )
1896 {
1897 xComposer->setElementaryQuery( sActiveCommand );
1898 }
1899 else
1900 {
1901 ::rtl::OUString sCommand;
1902 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
1903 sal_Int32 nCommandType = CommandType::COMMAND;
1904 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND_TYPE ) >>= nCommandType );
1905 xComposer->setCommand( sCommand, nCommandType );
1906 }
1907
1908 ::rtl::OUString sFilter;
1909 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_FILTER ) >>= sFilter );
1910 xComposer->setFilter( sFilter );
1911
1912 ::rtl::OUString sHavingClause;
1913 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_HAVING_CLAUSE ) >>= sHavingClause );
1914 xComposer->setHavingClause( sHavingClause );
1915
1916 ::rtl::OUString sOrder;
1917 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ORDER ) >>= sOrder );
1918 xComposer->setOrder( sOrder );
1919 }
1920 catch ( const Exception& )
1921 {
1922 DBG_UNHANDLED_EXCEPTION();
1923 }
1924 return xComposer;
1925 }
1926 //------------------------------------------------------------------------------
ExecuteFilterSortCrit(sal_Bool bFilter)1927 void SbaXDataBrowserController::ExecuteFilterSortCrit(sal_Bool bFilter)
1928 {
1929 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::ExecuteFilterSortCrit" );
1930 if (!SaveModified())
1931 return;
1932
1933 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1934
1935 const ::rtl::OUString sOldVal = bFilter ? m_xParser->getFilter() : m_xParser->getOrder();
1936 const ::rtl::OUString sOldHaving = m_xParser->getHavingClause();
1937 Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
1938 try
1939 {
1940 Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSup = getColumnsSupplier();
1941 Reference< XConnection> xCon(xFormSet->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
1942 if(bFilter)
1943 {
1944 DlgFilterCrit aDlg( getBrowserView(), getORB(), xCon, xParser, xSup->getColumns() );
1945 String aFilter;
1946 if ( !aDlg.Execute() )
1947 return; // if so we don't need to update the grid
1948 aDlg.BuildWherePart();
1949 }
1950 else
1951 {
1952 DlgOrderCrit aDlg( getBrowserView(),xCon,xParser,xSup->getColumns() );
1953 String aOrder;
1954 if(!aDlg.Execute())
1955 {
1956 return; // if so we don't need to actualize the grid
1957 }
1958 aDlg.BuildOrderPart();
1959 }
1960 }
1961 catch(const SQLException& )
1962 {
1963 SQLExceptionInfo aError( ::cppu::getCaughtException() );
1964 showError( aError );
1965 return;
1966 }
1967 catch(Exception&)
1968 {
1969 return;
1970 }
1971
1972 ::rtl::OUString sNewVal = bFilter ? xParser->getFilter() : xParser->getOrder();
1973 sal_Bool bOldFilterApplied(sal_False);
1974 if (bFilter)
1975 {
1976 try { bOldFilterApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER)); } catch(Exception&) { } ;
1977 }
1978
1979 ::rtl::OUString sNewHaving = xParser->getHavingClause();
1980 if ( sOldVal.equals(sNewVal) && (!bFilter || sOldHaving.equals(sNewHaving)) )
1981 // nothing to be done
1982 return;
1983
1984 if (bFilter)
1985 applyParserFilter(sOldVal, bOldFilterApplied,sOldHaving,xParser);
1986 else
1987 applyParserOrder(sOldVal,xParser);
1988
1989 ::comphelper::disposeComponent(xParser);
1990 }
1991
1992 //------------------------------------------------------------------------------
ExecuteSearch()1993 void SbaXDataBrowserController::ExecuteSearch()
1994 {
1995 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::ExecuteSearch" );
1996 // calculate the control source of the active field
1997 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
1998 DBG_ASSERT(xGrid.is(), "SbaXDataBrowserController::ExecuteSearch : the control should have an ::com::sun::star::form::XGrid interface !");
1999
2000 Reference< ::com::sun::star::form::XGridPeer > xGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
2001 Reference< ::com::sun::star::container::XIndexContainer > xColumns = xGridPeer->getColumns();
2002 DBG_ASSERT(xGridPeer.is() && xColumns.is(), "SbaXDataBrowserController::ExecuteSearch : invalid peer !");
2003
2004 sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
2005 sal_Int16 nModelCol = getBrowserView()->View2ModelPos(nViewCol);
2006
2007 Reference< XPropertySet > xCurrentCol(xColumns->getByIndex(nModelCol),UNO_QUERY);
2008 String sActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(PROPERTY_CONTROLSOURCE));
2009
2010 // the text within the current cell
2011 String sInitialText;
2012 Reference< ::com::sun::star::container::XIndexAccess > xColControls(xGridPeer, UNO_QUERY);
2013 Reference< XInterface > xCurControl(xColControls->getByIndex(nViewCol),UNO_QUERY);
2014 ::rtl::OUString aInitialText;
2015 if (IsSearchableControl(xCurControl, &aInitialText))
2016 sInitialText = aInitialText.getStr();
2017
2018 // prohibit the synchronization of the grid's display with the cursor's position
2019 Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2020 DBG_ASSERT(xModelSet.is(), "SbaXDataBrowserController::ExecuteSearch : no model set ?!");
2021 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"), ::comphelper::makeBoolAny(sal_Bool(sal_False)));
2022 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("AlwaysShowCursor"), ::comphelper::makeBoolAny(sal_Bool(sal_True)));
2023 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("CursorColor"), makeAny(sal_Int32(COL_LIGHTRED)));
2024
2025 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xNFS(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), sal_True,getORB()));
2026
2027 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2028 AbstractFmSearchDialog* pDialog = NULL;
2029 if ( pFact )
2030 {
2031 ::std::vector< String > aContextNames;
2032 aContextNames.push_back( String::CreateFromAscii("Standard") );
2033 pDialog = pFact->CreateFmSearchDialog(getBrowserView(), sInitialText, aContextNames, 0, LINK(this, SbaXDataBrowserController, OnSearchContextRequest));
2034 }
2035 DBG_ASSERT( pDialog, "SbaXDataBrowserController::ExecuteSearch: could not get the search dialog!" );
2036 if ( pDialog )
2037 {
2038 pDialog->SetActiveField( sActiveField );
2039 pDialog->SetFoundHandler( LINK( this, SbaXDataBrowserController, OnFoundData ) );
2040 pDialog->SetCanceledNotFoundHdl( LINK( this, SbaXDataBrowserController, OnCanceledNotFound ) );
2041 pDialog->Execute();
2042 delete pDialog;
2043 }
2044
2045 // restore the grid's normal operating state
2046 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"), ::comphelper::makeBoolAny(sal_Bool(sal_True)));
2047 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("AlwaysShowCursor"), ::comphelper::makeBoolAny(sal_Bool(sal_False)));
2048 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("CursorColor"), Any());
2049 }
2050
2051 //------------------------------------------------------------------------------
Execute(sal_uInt16 nId,const Sequence<PropertyValue> & _rArgs)2052 void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& _rArgs)
2053 {
2054 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::Execute" );
2055 sal_Bool bSortUp = sal_True;
2056
2057 switch (nId)
2058 {
2059 default:
2060 SbaXDataBrowserController_Base::Execute( nId, _rArgs );
2061 return;
2062
2063 case ID_BROWSER_INSERT_ROW:
2064 try
2065 {
2066 if (SaveModified())
2067 {
2068 getRowSet()->afterLast();
2069 // check if it is available
2070 Reference< XResultSetUpdate > xUpdateCursor(getRowSet(), UNO_QUERY_THROW);
2071 xUpdateCursor->moveToInsertRow();
2072 }
2073 }
2074 catch(Exception&)
2075 {
2076 OSL_ENSURE(0,"Exception caught!");
2077 }
2078 break;
2079 case SID_FM_DELETEROWS:
2080
2081 if (SaveModified())
2082 {
2083 SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
2084 if ( pVclGrid )
2085 {
2086 if( !pVclGrid->GetSelectRowCount() )
2087 {
2088 pVclGrid->DeactivateCell();
2089 pVclGrid->SelectRow(pVclGrid->GetCurRow());
2090 }
2091 pVclGrid->DeleteSelectedRows();
2092 }
2093 }
2094 break;
2095
2096 case ID_BROWSER_FILTERED:
2097 if (SaveModified())
2098 {
2099 Reference< XPropertySet > xActiveSet(getRowSet(), UNO_QUERY);
2100 sal_Bool bApplied = ::comphelper::getBOOL(xActiveSet->getPropertyValue(PROPERTY_APPLYFILTER));
2101 xActiveSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(sal_Bool(!bApplied)));
2102 reloadForm(m_xLoadable);
2103 }
2104 InvalidateFeature(ID_BROWSER_FILTERED);
2105 break;
2106 case ID_BROWSER_EDITDOC:
2107 {
2108 sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
2109 if (nGridMode == DbGridControl::OPT_READONLY)
2110 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_UPDATE | DbGridControl::OPT_INSERT | DbGridControl::OPT_DELETE);
2111 // the options not supported by the data source will be removed automatically
2112 else
2113 {
2114 if ( !SaveModified( ) )
2115 // give the user a chance to save the current record (if neccessary)
2116 break;
2117
2118 // maybe the user wanted to reject the modified record ?
2119 if (GetState(ID_BROWSER_UNDORECORD).bEnabled)
2120 Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
2121
2122 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_READONLY);
2123 }
2124 InvalidateFeature(ID_BROWSER_EDITDOC);
2125 }
2126 break;
2127
2128 case ID_BROWSER_SEARCH:
2129 if ( SaveModified( ) )
2130 ExecuteSearch();
2131 break;
2132
2133 case ID_BROWSER_COPY:
2134 if ( getBrowserView()->getVclControl()->GetSelectRowCount() > 0 )
2135 {
2136 getBrowserView()->getVclControl()->CopySelectedRowsToClipboard();
2137 break;
2138 }
2139 // run through
2140 case ID_BROWSER_CUT:
2141 case ID_BROWSER_PASTE:
2142 {
2143 CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
2144 if (!xCurrentController.Is())
2145 // should be intercepted by GetState. Normally.
2146 // Unfortunately ID_BROWSER_PASTE is a 'fast call' slot, which means it may be executed without checking if it is
2147 // enabled. This would be really deadly herein if the current cell has no controller ...
2148 // (FS - 13.04.99 - #64694#)
2149 return;
2150
2151 Edit& rEdit = (Edit&)xCurrentController->GetWindow();
2152 switch (nId)
2153 {
2154 case ID_BROWSER_CUT : rEdit.Cut(); break;
2155 case SID_COPY : rEdit.Copy(); break;
2156 case ID_BROWSER_PASTE : rEdit.Paste(); break;
2157 }
2158 if (ID_BROWSER_CUT == nId || ID_BROWSER_PASTE == nId)
2159 {
2160 xCurrentController->SetModified();
2161 rEdit.Modify();
2162 }
2163 }
2164 break;
2165
2166 case ID_BROWSER_SORTDOWN:
2167 bSortUp = sal_False;
2168 // DON'T break
2169 case ID_BROWSER_SORTUP:
2170 {
2171 if (!SaveModified())
2172 break;
2173
2174 if (!isValidCursor())
2175 break;
2176
2177 // only one sort order
2178 Reference< XPropertySet > xField(getBoundField(), UNO_QUERY);
2179 if (!xField.is())
2180 break;
2181
2182 Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
2183 const ::rtl::OUString sOldSort = xParser->getOrder();
2184 sal_Bool bParserSuccess = sal_False;
2185 HANDLE_SQL_ERRORS(
2186 xParser->setOrder(::rtl::OUString()); xParser->appendOrderByColumn(xField, bSortUp),
2187 bParserSuccess,
2188 UniString(ModuleRes(SBA_BROWSER_SETTING_ORDER)),
2189 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2190 )
2191
2192 if (bParserSuccess)
2193 applyParserOrder(sOldSort,xParser);
2194 }
2195 break;
2196
2197 case ID_BROWSER_AUTOFILTER:
2198 {
2199 if (!SaveModified())
2200 break;
2201
2202 if (!isValidCursor())
2203 break;
2204
2205 Reference< XPropertySet > xField(getBoundField(), UNO_QUERY);
2206 if (!xField.is())
2207 break;
2208
2209 // check if the column is a aggregate function
2210 sal_Bool bHaving = sal_False;
2211 ::rtl::OUString sName;
2212 xField->getPropertyValue(PROPERTY_NAME) >>= sName;
2213 Reference< XColumnsSupplier > xColumnsSupplier(m_xParser, UNO_QUERY);
2214 Reference< ::com::sun::star::container::XNameAccess > xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > ();
2215 if ( xCols.is() && xCols->hasByName(sName) )
2216 {
2217 Reference<XPropertySet> xProp(xCols->getByName(sName),UNO_QUERY);
2218 static ::rtl::OUString sAgg(RTL_CONSTASCII_USTRINGPARAM("AggregateFunction"));
2219 if ( xProp->getPropertySetInfo()->hasPropertyByName(sAgg) )
2220 xProp->getPropertyValue(sAgg) >>= bHaving;
2221 }
2222
2223 Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
2224 const ::rtl::OUString sOldFilter = xParser->getFilter();
2225 const ::rtl::OUString sOldHaving = xParser->getHavingClause();
2226
2227 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2228 sal_Bool bApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER));
2229 // do we have a filter but it's not applied ?
2230 // -> completely overwrite it, else append one
2231 if (!bApplied)
2232 {
2233 DO_SAFE( (bHaving ? xParser->setHavingClause(::rtl::OUString()) : xParser->setFilter(::rtl::OUString())), "SbaXDataBrowserController::Execute : caught an exception while resetting the new filter !" );
2234 }
2235
2236 sal_Bool bParserSuccess = sal_False;
2237
2238 sal_Int32 nOp = SQLFilterOperator::EQUAL;
2239 if ( xField.is() )
2240 {
2241 sal_Int32 nType = 0;
2242 xField->getPropertyValue(PROPERTY_TYPE) >>= nType;
2243 switch(nType)
2244 {
2245 case DataType::VARCHAR:
2246 case DataType::CHAR:
2247 case DataType::LONGVARCHAR:
2248 nOp = SQLFilterOperator::LIKE;
2249 break;
2250 default:
2251 nOp = SQLFilterOperator::EQUAL;
2252 }
2253 }
2254
2255 if ( bHaving )
2256 {
2257 HANDLE_SQL_ERRORS(
2258 xParser->appendHavingClauseByColumn(xField,sal_True,nOp),
2259 bParserSuccess,
2260 UniString(ModuleRes(SBA_BROWSER_SETTING_FILTER)),
2261 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2262 )
2263 }
2264 else
2265 {
2266 HANDLE_SQL_ERRORS(
2267 xParser->appendFilterByColumn(xField,sal_True,nOp),
2268 bParserSuccess,
2269 UniString(ModuleRes(SBA_BROWSER_SETTING_FILTER)),
2270 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2271 )
2272 }
2273
2274 if (bParserSuccess)
2275 applyParserFilter(sOldFilter, bApplied,sOldHaving,xParser);
2276
2277 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2278 InvalidateFeature(ID_BROWSER_FILTERED);
2279 }
2280 break;
2281
2282 case ID_BROWSER_ORDERCRIT:
2283 ExecuteFilterSortCrit(sal_False);
2284 break;
2285
2286 case ID_BROWSER_FILTERCRIT:
2287 ExecuteFilterSortCrit(sal_True);
2288 InvalidateFeature(ID_BROWSER_FILTERED);
2289 break;
2290
2291 case ID_BROWSER_REMOVEFILTER:
2292 {
2293 if (!SaveModified())
2294 break;
2295
2296 sal_Bool bNeedPostReload = preReloadForm();
2297 // reset the filter and the sort property simutaneously so only _one_ new statement has to be
2298 // sent
2299 Reference< XPropertySet > xSet(getRowSet(), UNO_QUERY);
2300 if ( xSet.is() )
2301 {
2302 xSet->setPropertyValue(PROPERTY_FILTER,makeAny(::rtl::OUString()));
2303 xSet->setPropertyValue(PROPERTY_HAVING_CLAUSE,makeAny(::rtl::OUString()));
2304 xSet->setPropertyValue(PROPERTY_ORDER,makeAny(::rtl::OUString()));
2305 }
2306 try
2307 {
2308 reloadForm(m_xLoadable);
2309 if ( bNeedPostReload )
2310 postReloadForm();
2311 }
2312 catch(Exception&)
2313 {
2314 }
2315 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2316 InvalidateFeature(ID_BROWSER_FILTERED);
2317 }
2318 break;
2319
2320 case ID_BROWSER_REFRESH:
2321 if ( SaveModified( ) )
2322 {
2323 if (!reloadForm(m_xLoadable))
2324 criticalFail();
2325 }
2326 break;
2327
2328 case ID_BROWSER_SAVERECORD:
2329 if ( SaveModified( sal_False ) )
2330 setCurrentModified( sal_False );
2331 break;
2332
2333 case ID_BROWSER_UNDORECORD:
2334 {
2335 try
2336 {
2337 // restore the cursor state
2338 Reference< XResultSetUpdate > xCursor(getRowSet(), UNO_QUERY);
2339 Reference< XPropertySet > xSet(xCursor, UNO_QUERY);
2340 Any aVal = xSet->getPropertyValue(PROPERTY_ISNEW);
2341 if (aVal.hasValue() && ::comphelper::getBOOL(aVal))
2342 {
2343 xCursor->moveToInsertRow();
2344 // no need to reset the grid model after we moved to the insert row, this is done implicitly by the
2345 // form
2346 // (and in some cases it may be deadly to do the reset explicitly after the form did it implicitly,
2347 // cause the form's reset may be async, and this leads to some nice deadlock scenarios ....)
2348 }
2349 else
2350 {
2351 xCursor->cancelRowUpdates();
2352
2353 // restore the grids state
2354 Reference< ::com::sun::star::form::XReset > xReset(getControlModel(), UNO_QUERY);
2355 if (xReset.is())
2356 xReset->reset();
2357 }
2358 }
2359 catch(SQLException&)
2360 {
2361 }
2362
2363 setCurrentModified( sal_False );
2364 }
2365 }
2366 }
2367
2368 //------------------------------------------------------------------------------
SaveModified(sal_Bool bAskFor)2369 sal_Bool SbaXDataBrowserController::SaveModified(sal_Bool bAskFor)
2370 {
2371 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SaveModified" );
2372 if ( bAskFor && GetState(ID_BROWSER_SAVERECORD).bEnabled )
2373 {
2374 getBrowserView()->getVclControl()->GrabFocus();
2375
2376 QueryBox aQry(getBrowserView()->getVclControl(), ModuleRes(QUERY_BRW_SAVEMODIFIED));
2377
2378 switch (aQry.Execute())
2379 {
2380 case RET_NO:
2381 Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
2382 return sal_True;
2383 case RET_CANCEL:
2384 return sal_False;
2385 }
2386 }
2387
2388 if ( !CommitCurrent() ) // das aktuelle Control committen lassen
2389 return sal_False;
2390
2391 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2392 sal_Bool bResult = sal_False;
2393 try
2394 {
2395 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED)))
2396 {
2397 Reference< XResultSetUpdate > xCursor(getRowSet(), UNO_QUERY);
2398 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISNEW)))
2399 xCursor->insertRow();
2400 else
2401 xCursor->updateRow();
2402 }
2403 bResult = sal_True;
2404 }
2405 catch(SQLException&)
2406 {
2407 }
2408 catch(Exception&)
2409 {
2410 DBG_ERROR("SbaXDataBrowserController::SaveModified : could not save the current record !");
2411 bResult = sal_False;
2412 }
2413
2414 InvalidateFeature(ID_BROWSER_SAVERECORD);
2415 InvalidateFeature(ID_BROWSER_UNDORECORD);
2416 return bResult;
2417 }
2418
2419 //------------------------------------------------------------------------------
CommitCurrent()2420 sal_Bool SbaXDataBrowserController::CommitCurrent()
2421 {
2422 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CommitCurrent" );
2423 if (!getBrowserView())
2424 return sal_True;
2425
2426 Reference< ::com::sun::star::awt::XControl > xActiveControl(getBrowserView()->getGridControl());
2427 Reference< ::com::sun::star::form::XBoundControl > xLockingTest(xActiveControl, UNO_QUERY);
2428 sal_Bool bControlIsLocked = xLockingTest.is() && xLockingTest->getLock();
2429 if (xActiveControl.is() && !bControlIsLocked)
2430 {
2431 // zunaechst das Control fragen ob es das IFace unterstuetzt
2432 Reference< ::com::sun::star::form::XBoundComponent > xBoundControl(xActiveControl, UNO_QUERY);
2433 if (!xBoundControl.is())
2434 xBoundControl = Reference< ::com::sun::star::form::XBoundComponent > (xActiveControl->getModel(), UNO_QUERY);
2435 if (xBoundControl.is() && !xBoundControl->commit())
2436 return sal_False;
2437 }
2438 return sal_True;
2439 }
2440
2441 //------------------------------------------------------------------------------
setCurrentModified(sal_Bool _bSet)2442 void SbaXDataBrowserController::setCurrentModified( sal_Bool _bSet )
2443 {
2444 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::setCurrentModified" );
2445 m_bCurrentlyModified = _bSet;
2446 InvalidateFeature( ID_BROWSER_SAVERECORD );
2447 InvalidateFeature( ID_BROWSER_UNDORECORD );
2448 }
2449
2450 //------------------------------------------------------------------------------
RowChanged()2451 void SbaXDataBrowserController::RowChanged()
2452 {
2453 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::RowChanged" );
2454 setCurrentModified( sal_False );
2455 }
2456
2457 //------------------------------------------------------------------------------
ColumnChanged()2458 void SbaXDataBrowserController::ColumnChanged()
2459 {
2460 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::ColumnChanged" );
2461 InvalidateFeature(ID_BROWSER_SORTUP);
2462 InvalidateFeature(ID_BROWSER_SORTDOWN);
2463 InvalidateFeature(ID_BROWSER_ORDERCRIT);
2464 InvalidateFeature(ID_BROWSER_FILTERCRIT);
2465 InvalidateFeature(ID_BROWSER_AUTOFILTER);
2466 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2467
2468 setCurrentModified( sal_False );
2469 }
2470
2471 //------------------------------------------------------------------------------
SelectionChanged()2472 void SbaXDataBrowserController::SelectionChanged()
2473 {
2474 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SelectionChanged" );
2475 // not interested in
2476 }
2477
2478 //------------------------------------------------------------------------------
CellActivated()2479 void SbaXDataBrowserController::CellActivated()
2480 {
2481 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CellActivated" );
2482 m_aInvalidateClipboard.Start();
2483 OnInvalidateClipboard( NULL );
2484 }
2485
2486 //------------------------------------------------------------------------------
CellDeactivated()2487 void SbaXDataBrowserController::CellDeactivated()
2488 {
2489 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CellDeactivated" );
2490 m_aInvalidateClipboard.Stop();
2491 OnInvalidateClipboard( NULL );
2492 }
2493
2494 //------------------------------------------------------------------------------
IMPL_LINK(SbaXDataBrowserController,OnClipboardChanged,void *,EMPTYARG)2495 IMPL_LINK( SbaXDataBrowserController, OnClipboardChanged, void*, EMPTYARG )
2496 {
2497 ::vos::OGuard aGuard(Application::GetSolarMutex());
2498 return OnInvalidateClipboard( NULL );
2499 }
2500
2501 //------------------------------------------------------------------------------
IMPL_LINK(SbaXDataBrowserController,OnInvalidateClipboard,AutoTimer *,_pTimer)2502 IMPL_LINK(SbaXDataBrowserController, OnInvalidateClipboard, AutoTimer*, _pTimer)
2503 {
2504 InvalidateFeature(ID_BROWSER_CUT);
2505 InvalidateFeature(ID_BROWSER_COPY);
2506
2507 // if the invalidation was triggered by the timer, we do not need to invalidate PASTE.
2508 // The timer is only for checking the CUT/COPY slots regulariry, which depend on the
2509 // selection state of the active cell
2510 // TODO: get a callback at the Edit which allows to be notified when the selection
2511 // changes. This would be much better than this cycle-eating polling mechanism here ....
2512 if ( _pTimer != &m_aInvalidateClipboard )
2513 InvalidateFeature(ID_BROWSER_PASTE);
2514
2515 return 0L;
2516 }
2517
2518 // -------------------------------------------------------------------------
getBoundField(sal_uInt16 nViewPos) const2519 Reference< XPropertySet > SbaXDataBrowserController::getBoundField(sal_uInt16 nViewPos) const
2520 {
2521 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SaveData" );
2522 Reference< XPropertySet > xEmptyReturn;
2523
2524 // get the current column from the grid
2525 if (nViewPos == (sal_uInt16)-1)
2526 {
2527 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2528 if (!xGrid.is())
2529 return xEmptyReturn;
2530 nViewPos = xGrid->getCurrentColumnPosition();
2531 }
2532 sal_uInt16 nCurrentCol = getBrowserView()->View2ModelPos(nViewPos);
2533 if (nCurrentCol == (sal_uInt16)-1)
2534 return xEmptyReturn;
2535
2536 // get the according column from the model
2537 Reference< ::com::sun::star::container::XIndexContainer > xCols(getControlModel(), UNO_QUERY);
2538 Reference< XPropertySet > xCurrentCol(xCols->getByIndex(nCurrentCol),UNO_QUERY);
2539 if (!xCurrentCol.is())
2540 return xEmptyReturn;
2541
2542 xEmptyReturn.set(xCurrentCol->getPropertyValue(PROPERTY_BOUNDFIELD) ,UNO_QUERY);
2543 return xEmptyReturn;
2544 }
2545
2546 //------------------------------------------------------------------------------
IMPL_LINK(SbaXDataBrowserController,OnSearchContextRequest,FmSearchContext *,pContext)2547 IMPL_LINK(SbaXDataBrowserController, OnSearchContextRequest, FmSearchContext*, pContext)
2548 {
2549 Reference< ::com::sun::star::container::XIndexAccess > xPeerContainer(getBrowserView()->getGridControl(), UNO_QUERY);
2550
2551 // check all grid columns for their control source
2552 Reference< ::com::sun::star::container::XIndexAccess > xModelColumns(getFormComponent(), UNO_QUERY);
2553 DBG_ASSERT(xModelColumns.is(), "SbaXDataBrowserController::OnSearchContextRequest : there is a grid control without columns !");
2554 // the case 'no columns' should be indicated with an empty container, I think ...
2555 DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "SbaXDataBrowserController::OnSearchContextRequest : impossible : have more view than model columns !");
2556
2557 String sFieldList;
2558 for (sal_Int32 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
2559 {
2560 Reference< XInterface > xCurrentColumn(xPeerContainer->getByIndex(nViewPos),UNO_QUERY);
2561 if (!xCurrentColumn.is())
2562 continue;
2563
2564 // can we use this column control fo searching ?
2565 if (!IsSearchableControl(xCurrentColumn))
2566 continue;
2567
2568 sal_uInt16 nModelPos = getBrowserView()->View2ModelPos((sal_uInt16)nViewPos);
2569 Reference< XPropertySet > xCurrentColModel(xModelColumns->getByIndex(nModelPos),UNO_QUERY);
2570 ::rtl::OUString aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(PROPERTY_CONTROLSOURCE));
2571
2572 sFieldList += aName.getStr();
2573 sFieldList += ';';
2574
2575 pContext->arrFields.push_back(xCurrentColumn);
2576 }
2577 sFieldList.EraseTrailingChars(';');
2578
2579 pContext->xCursor.set(getRowSet(),UNO_QUERY);
2580 pContext->strUsedFields = sFieldList;
2581
2582 // if the cursor is in a mode other than STANDARD -> reset
2583 Reference< XPropertySet > xCursorSet(pContext->xCursor, UNO_QUERY);
2584 DBG_ASSERT(xCursorSet.is() && !::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISMODIFIED)),
2585 "SbaXDataBrowserController::OnSearchContextRequest : please do not call for cursors with modified rows !");
2586 if (xCursorSet.is() && ::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISNEW)))
2587 {
2588 Reference< XResultSetUpdate > xUpdateCursor(pContext->xCursor, UNO_QUERY);
2589 xUpdateCursor->moveToCurrentRow();
2590 }
2591 return pContext->arrFields.size();
2592 }
2593
2594 //------------------------------------------------------------------------------
IMPL_LINK(SbaXDataBrowserController,OnFoundData,FmFoundRecordInformation *,pInfo)2595 IMPL_LINK(SbaXDataBrowserController, OnFoundData, FmFoundRecordInformation*, pInfo)
2596 {
2597 Reference< ::com::sun::star::sdbcx::XRowLocate > xCursor(getRowSet(), UNO_QUERY);
2598 DBG_ASSERT(xCursor.is(), "SbaXDataBrowserController::OnFoundData : shit happens. sometimes. but this is simply impossible !");
2599
2600 // move the cursor
2601 xCursor->moveToBookmark(pInfo->aPosition);
2602
2603 // let the grid snyc it's display with the cursor
2604 Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2605 DBG_ASSERT(xModelSet.is(), "SbaXDataBrowserController::OnFoundData : no model set ?!");
2606 Any aOld = xModelSet->getPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"));
2607 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"), ::comphelper::makeBoolAny(sal_Bool(sal_True)));
2608 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"), aOld);
2609
2610 // and move to the field
2611 Reference< ::com::sun::star::container::XIndexAccess > aColumnControls(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
2612 sal_uInt16 nViewPos;
2613
2614 for ( nViewPos = 0; nViewPos < aColumnControls->getCount(); ++nViewPos )
2615 {
2616 Reference< XInterface > xCurrent(aColumnControls->getByIndex(nViewPos),UNO_QUERY);
2617 if (IsSearchableControl(xCurrent))
2618 {
2619 if (pInfo->nFieldPos)
2620 --pInfo->nFieldPos;
2621 else
2622 break;
2623 }
2624 }
2625
2626 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2627 xGrid->setCurrentColumnPosition(nViewPos);
2628
2629 return 0;
2630 }
2631
2632 //------------------------------------------------------------------------------
IMPL_LINK(SbaXDataBrowserController,OnCanceledNotFound,FmFoundRecordInformation *,pInfo)2633 IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformation*, pInfo)
2634 {
2635 Reference< ::com::sun::star::sdbcx::XRowLocate > xCursor(getRowSet(), UNO_QUERY);
2636
2637 try
2638 {
2639 DBG_ASSERT(xCursor.is(), "SbaXDataBrowserController::OnCanceledNotFound : shit happens. sometimes. but this is simply impossible !");
2640 // move the cursor
2641 xCursor->moveToBookmark(pInfo->aPosition);
2642 }
2643 catch( const Exception& )
2644 {
2645 DBG_UNHANDLED_EXCEPTION();
2646 }
2647
2648 try
2649 {
2650 // let the grid snyc it's display with the cursor
2651 Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2652 DBG_ASSERT(xModelSet.is(), "SbaXDataBrowserController::OnCanceledNotFound : no model set ?!");
2653 Any aOld = xModelSet->getPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"));
2654 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"), ::comphelper::makeBoolAny(sal_Bool(sal_True)));
2655 xModelSet->setPropertyValue(::rtl::OUString::createFromAscii("DisplayIsSynchron"), aOld);
2656 }
2657 catch( const Exception& )
2658 {
2659 DBG_UNHANDLED_EXCEPTION();
2660 }
2661
2662 return 0L;
2663 }
2664
2665 //------------------------------------------------------------------------------
IMPL_LINK(SbaXDataBrowserController,OnAsyncGetCellFocus,void *,EMPTYARG)2666 IMPL_LINK(SbaXDataBrowserController, OnAsyncGetCellFocus, void*, EMPTYARG)
2667 {
2668 SbaGridControl* pVclGrid = getBrowserView() ? getBrowserView()->getVclControl() : NULL;
2669 // if we have a controller, but the window for the controller doesn't have the focus, we correct this
2670 if(pVclGrid)
2671 {
2672 if (!pVclGrid->IsEditing())
2673 return 0L;
2674
2675 if (pVclGrid->HasChildPathFocus())
2676 pVclGrid->Controller()->GetWindow().GrabFocus();
2677 }
2678
2679 return 0L;
2680 }
2681
2682 //------------------------------------------------------------------------------
criticalFail()2683 void SbaXDataBrowserController::criticalFail()
2684 {
2685 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::criticalFail" );
2686 InvalidateAll();
2687 m_nRowSetPrivileges = 0;
2688 }
2689
2690 //------------------------------------------------------------------------------
LoadFinished(sal_Bool)2691 void SbaXDataBrowserController::LoadFinished(sal_Bool /*bWasSynch*/)
2692 {
2693 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::LoadFinished" );
2694 m_nRowSetPrivileges = 0;
2695
2696 if (isValid() && !loadingCancelled())
2697 {
2698 // obtain cached values
2699 try
2700 {
2701 Reference< XPropertySet > xFormProps( m_xLoadable, UNO_QUERY_THROW );
2702 OSL_VERIFY( xFormProps->getPropertyValue( PROPERTY_PRIVILEGES ) >>= m_nRowSetPrivileges );
2703 }
2704 catch( const Exception& )
2705 {
2706 DBG_UNHANDLED_EXCEPTION();
2707 }
2708
2709 // --------------------------------
2710 // switch the control to alive mode
2711 getBrowserView()->getGridControl()->setDesignMode(sal_False);
2712
2713 // -------------------------------
2714 initializeParser();
2715
2716 // -------------------------------
2717 InvalidateAll();
2718
2719 m_aAsyncGetCellFocus.Call();
2720 }
2721 }
2722 // -----------------------------------------------------------------------------
initializeParser() const2723 void SbaXDataBrowserController::initializeParser() const
2724 {
2725 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::initializeParser" );
2726 if ( !m_xParser.is() )
2727 {
2728 // ----------------------------------------------
2729 // create a parser (needed for filtering/sorting)
2730 try
2731 {
2732 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2733 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
2734 { // (only if the statement isn't native)
2735 // (it is allowed to use the PROPERTY_ISPASSTHROUGH : _after_ loading a form it is valid)
2736 xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
2737 }
2738 }
2739 catch(Exception&)
2740 {
2741 DBG_UNHANDLED_EXCEPTION();
2742 m_xParser = NULL;
2743 // no further handling, we ignore the error
2744 }
2745 }
2746 }
2747 //------------------------------------------------------------------------------
loaded(const EventObject &)2748 void SbaXDataBrowserController::loaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2749 {
2750 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::loaded" );
2751 // not interested in
2752 // we're loading within an separate thread and have a handling for it's "finished event"
2753 }
2754
2755 //------------------------------------------------------------------------------
unloading(const EventObject &)2756 void SbaXDataBrowserController::unloading(const EventObject& /*aEvent*/) throw( RuntimeException )
2757 {
2758 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::unloading" );
2759 // not interested in
2760 }
2761
2762 //------------------------------------------------------------------------------
unloaded(const EventObject &)2763 void SbaXDataBrowserController::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2764 {
2765 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::unloaded" );
2766 m_xParser.clear();
2767 InvalidateAll();
2768 // do this asynchron, there are other listeners reacting on this message ...
2769 // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
2770 // change as a reaction on that event. as we have no chance to be notified of this change (which is
2771 // the one we're interested in) we give them time to do what they want to before invalidating our
2772 // bound-field-dependent slots ....
2773 }
2774
2775 //------------------------------------------------------------------------------
reloading(const EventObject &)2776 void SbaXDataBrowserController::reloading(const EventObject& /*aEvent*/) throw( RuntimeException )
2777 {
2778 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::reloading" );
2779 // not interested in
2780 }
2781
2782 //------------------------------------------------------------------------------
reloaded(const EventObject &)2783 void SbaXDataBrowserController::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2784 {
2785 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::reloaded" );
2786 InvalidateAll();
2787 // do this asynchronously, there are other listeners reacting on this message ...
2788 // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
2789 // change as a reaction on that event. as we have no chance to be notified of this change (which is
2790 // the one we're interested in) we give them time to do what they want to before invalidating our
2791 // bound-field-dependent slots ....
2792 }
2793 //------------------------------------------------------------------------------
enterFormAction()2794 void SbaXDataBrowserController::enterFormAction()
2795 {
2796 if ( !m_nFormActionNestingLevel )
2797 // first action -> reset
2798 m_aCurrentError.clear();
2799
2800 ++m_nFormActionNestingLevel;
2801 }
2802
2803 //------------------------------------------------------------------------------
leaveFormAction()2804 void SbaXDataBrowserController::leaveFormAction()
2805 {
2806 DBG_ASSERT( m_nFormActionNestingLevel > 0, "SbaXDataBrowserController::leaveFormAction : invalid call !" );
2807 if ( --m_nFormActionNestingLevel > 0 )
2808 return;
2809
2810 if ( !m_aCurrentError.isValid() )
2811 return;
2812
2813 m_aAsyncDisplayError.Call();
2814 }
2815
2816 // -------------------------------------------------------------------------
isLoaded() const2817 sal_Bool SbaXDataBrowserController::isLoaded() const
2818 {
2819 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::isLoaded" );
2820 return m_xLoadable.is() && m_xLoadable->isLoaded();
2821 }
2822
2823 // -------------------------------------------------------------------------
isValidCursor() const2824 sal_Bool SbaXDataBrowserController::isValidCursor() const
2825 {
2826 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::isValidCursor" );
2827 if (!m_xColumnsSupplier.is())
2828 return sal_False;
2829 Reference< ::com::sun::star::container::XNameAccess > xCols = m_xColumnsSupplier->getColumns();
2830 if (!xCols.is() || !xCols->hasElements())
2831 return sal_False;
2832
2833 sal_Bool bIsValid = !(m_xRowSet->isBeforeFirst() || m_xRowSet->isAfterLast());
2834 if ( !bIsValid )
2835 {
2836 Reference<XPropertySet> xProp(m_xRowSet,UNO_QUERY);
2837 bIsValid = ::cppu::any2bool(xProp->getPropertyValue(PROPERTY_ISNEW));
2838 if ( !bIsValid )
2839 {
2840 bIsValid = m_xParser.is();
2841 }
2842 } // if ( !bIsValid )
2843 return bIsValid;
2844 }
2845
2846 //==================================================================
2847 // LoadFormHelper
2848 //==================================================================
2849
2850 class LoadFormHelper :public ::cppu::WeakImplHelper2< ::com::sun::star::form::XLoadListener,
2851 XRowSetListener>
2852 {
2853 enum STATE { STARTED, LOADED, POSITIONED, DISPOSED };
2854 STATE m_eState;
2855
2856 Reference< XRowSet > m_xForm;
2857
2858 ::osl::Mutex m_aAccessSafety;
2859
2860 public:
2861 LoadFormHelper(const Reference< XRowSet > & _rxForm);
2862
2863 // ::com::sun::star::form::XLoadListener
2864 virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException );
2865 virtual void SAL_CALL unloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException );
2866 virtual void SAL_CALL unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException );
2867 virtual void SAL_CALL reloading(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException );
2868 virtual void SAL_CALL reloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException );
2869
2870 // XRowSetListener
2871 virtual void SAL_CALL cursorMoved(const ::com::sun::star::lang::EventObject& event) throw( RuntimeException );
2872 virtual void SAL_CALL rowChanged(const ::com::sun::star::lang::EventObject& event) throw( RuntimeException );
2873 virtual void SAL_CALL rowSetChanged(const ::com::sun::star::lang::EventObject& event) throw( RuntimeException );
2874
2875 // ::com::sun::star::lang::XEventListener
2876 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( RuntimeException );
2877
2878
2879 bool WaitUntilReallyLoaded(bool _bOnlyIfLoaded);
2880 // waits 'til the first positioned event after the loaded event. returns true if successfull,
2881 // false if the form was disposed or unloaded before or while waiting
2882 // if _bOnlyIfLoaded is false and the form isn't loaded already loaded, false will be returned
2883 // (without any wating)
2884
2885 void cancel();
2886
2887 protected:
2888 ~LoadFormHelper();
2889
2890 void implDispose();
2891 };
2892
DBG_NAME(LoadFormHelper)2893 DBG_NAME(LoadFormHelper)
2894 //------------------------------------------------------------------------------
2895 LoadFormHelper::LoadFormHelper(const Reference< XRowSet > & _rxForm)
2896 :m_eState(STARTED)
2897 ,m_xForm(_rxForm)
2898 {
2899 DBG_CTOR(LoadFormHelper,NULL);
2900
2901 Reference< ::com::sun::star::form::XLoadable > (m_xForm, UNO_QUERY)->addLoadListener(this);
2902 m_xForm->addRowSetListener(this);
2903 }
2904
2905 //------------------------------------------------------------------------------
~LoadFormHelper()2906 LoadFormHelper::~LoadFormHelper()
2907 {
2908 ::osl::MutexGuard aGuard(m_aAccessSafety);
2909 implDispose();
2910
2911 DBG_DTOR(LoadFormHelper,NULL);
2912 }
2913
2914 //------------------------------------------------------------------------------
implDispose()2915 void LoadFormHelper::implDispose()
2916 {
2917 if (DISPOSED != m_eState)
2918 {
2919
2920 Reference< ::com::sun::star::form::XLoadable > (m_xForm, UNO_QUERY)->removeLoadListener(this);
2921 m_xForm->removeRowSetListener(this);
2922 m_xForm = NULL;
2923 m_eState = DISPOSED;
2924 }
2925 }
2926
2927 //------------------------------------------------------------------------------
loaded(const::com::sun::star::lang::EventObject &)2928 void SAL_CALL LoadFormHelper::loaded(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
2929 {
2930 ::osl::MutexGuard aGuard(m_aAccessSafety);
2931 DBG_ASSERT(m_eState == STARTED || m_eState == DISPOSED, "LoadFormHelper::loaded : wrong call !");
2932 if (m_eState == STARTED)
2933 m_eState = LOADED;
2934 }
2935
2936 //------------------------------------------------------------------------------
unloaded(const::com::sun::star::lang::EventObject &)2937 void SAL_CALL LoadFormHelper::unloaded(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
2938 {
2939 ::osl::MutexGuard aGuard(m_aAccessSafety);
2940 DBG_ERROR("LoadFormHelper::unloaded : shouldn't be called !");
2941 implDispose();
2942 }
2943
2944 //------------------------------------------------------------------------------
unloading(const::com::sun::star::lang::EventObject &)2945 void SAL_CALL LoadFormHelper::unloading(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
2946 {
2947 }
2948
2949 //------------------------------------------------------------------------------
reloading(const::com::sun::star::lang::EventObject &)2950 void SAL_CALL LoadFormHelper::reloading(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
2951 {
2952 }
2953
2954 //------------------------------------------------------------------------------
reloaded(const::com::sun::star::lang::EventObject &)2955 void SAL_CALL LoadFormHelper::reloaded(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
2956 {
2957 }
2958
2959 //------------------------------------------------------------------------------
cursorMoved(const::com::sun::star::lang::EventObject &)2960 void SAL_CALL LoadFormHelper::cursorMoved(const ::com::sun::star::lang::EventObject& /*event*/) throw( RuntimeException )
2961 {
2962 ::osl::MutexGuard aGuard(m_aAccessSafety);
2963 if (m_eState == LOADED)
2964 m_eState = POSITIONED;
2965 }
2966
2967 //------------------------------------------------------------------------------
rowChanged(const::com::sun::star::lang::EventObject &)2968 void SAL_CALL LoadFormHelper::rowChanged(const ::com::sun::star::lang::EventObject& /*event*/) throw( RuntimeException )
2969 {
2970 }
2971
2972 //------------------------------------------------------------------------------
rowSetChanged(const::com::sun::star::lang::EventObject &)2973 void SAL_CALL LoadFormHelper::rowSetChanged(const ::com::sun::star::lang::EventObject& /*event*/) throw( RuntimeException )
2974 {
2975 }
2976
2977 //------------------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject &)2978 void SAL_CALL LoadFormHelper::disposing(const ::com::sun::star::lang::EventObject& /*Source*/) throw( RuntimeException )
2979 {
2980 ::osl::MutexGuard aGuard(m_aAccessSafety);
2981 implDispose();
2982 }
2983
2984 //------------------------------------------------------------------------------
cancel()2985 void LoadFormHelper::cancel()
2986 {
2987 implDispose();
2988 }
2989
2990 //------------------------------------------------------------------------------
WaitUntilReallyLoaded(bool _bOnlyIfLoaded)2991 bool LoadFormHelper::WaitUntilReallyLoaded(bool _bOnlyIfLoaded)
2992 {
2993 ::osl::ResettableMutexGuard aGuard( m_aAccessSafety );
2994 if (DISPOSED == m_eState)
2995 return false;
2996
2997 if (_bOnlyIfLoaded && (STARTED == m_eState))
2998 // we did't get a "loaded" event ....
2999 return false;
3000
3001 sal_Bool bDone = (POSITIONED == m_eState);
3002 aGuard.clear();
3003
3004 while (!bDone)
3005 {
3006 aGuard.reset();
3007 bDone = (POSITIONED == m_eState);
3008 aGuard.clear();
3009 }
3010
3011 aGuard.reset();
3012 implDispose();
3013
3014 return true;
3015 }
3016
3017 // -----------------------------------------------------------------------------
getCurrentColumnPosition()3018 sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition()
3019 {
3020 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getCurrentColumnPosition" );
3021 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
3022 sal_Int16 nViewPos = -1;
3023 try
3024 {
3025 if ( xGrid.is() )
3026 nViewPos = xGrid->getCurrentColumnPosition();
3027 }
3028 catch(Exception&) {}
3029 return nViewPos;
3030 }
3031 // -----------------------------------------------------------------------------
setCurrentColumnPosition(sal_Int16 _nPos)3032 void SbaXDataBrowserController::setCurrentColumnPosition( sal_Int16 _nPos )
3033 {
3034 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::setCurrentColumnPosition" );
3035 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
3036 try
3037 {
3038 if ( -1 != _nPos )
3039 xGrid->setCurrentColumnPosition(_nPos);
3040 }
3041 catch(Exception&) {}
3042 }
3043 // -----------------------------------------------------------------------------
BeforeDrop()3044 void SbaXDataBrowserController::BeforeDrop()
3045 {
3046 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::BeforeDrop" );
3047 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
3048 if (xFormError.is())
3049 xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
3050 }
3051 // -----------------------------------------------------------------------------
AfterDrop()3052 void SbaXDataBrowserController::AfterDrop()
3053 {
3054 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::AfterDrop" );
3055 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
3056 if (xFormError.is())
3057 xFormError->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
3058 }
3059 // -----------------------------------------------------------------------------
addColumnListeners(const Reference<::com::sun::star::awt::XControlModel> & _xGridControlModel)3060 void SbaXDataBrowserController::addColumnListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
3061 {
3062 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::addColumnListeners" );
3063 // ... all the grid columns
3064 Reference< ::com::sun::star::container::XIndexContainer > xColumns(_xGridControlModel, UNO_QUERY);
3065 if (xColumns.is())
3066 {
3067 sal_Int32 nCount = xColumns->getCount();
3068 for (sal_uInt16 i=0; i < nCount; ++i)
3069 {
3070 Reference< XPropertySet > xCol(xColumns->getByIndex(i),UNO_QUERY);
3071 AddColumnListener(xCol);
3072 }
3073 }
3074 }
3075 // -----------------------------------------------------------------------------
InitializeGridModel(const Reference<::com::sun::star::form::XFormComponent> &)3076 sal_Bool SbaXDataBrowserController::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & /*xGrid*/)
3077 {
3078 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::InitializeGridModel" );
3079 return sal_True;
3080 }
3081 //..................................................................
3082 } // namespace dbaui
3083 //..................................................................
3084