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