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 :
21 : #include "sbagrid.hrc"
22 :
23 : #include <svx/svxids.hrc>
24 :
25 : #include <svx/numinf.hxx>
26 : #include <svx/dbaexchange.hxx>
27 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
28 :
29 : #include "sbagrid.hxx"
30 : #include "dlgattr.hxx"
31 : #include "dlgsize.hxx"
32 : #include <com/sun/star/form/XLoadable.hpp>
33 : #include <com/sun/star/sdb/CommandType.hpp>
34 : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
35 : #include <com/sun/star/sdb/XResultSetAccess.hpp>
36 : #include <com/sun/star/form/XForm.hpp>
37 : #include <com/sun/star/container/XIndexContainer.hpp>
38 : #include <com/sun/star/util/NumberFormat.hpp>
39 :
40 : #include <com/sun/star/view/XSelectionSupplier.hpp>
41 : #include <com/sun/star/form/DataSelectionType.hpp>
42 : #include <com/sun/star/awt/TextAlign.hpp>
43 : #include <com/sun/star/awt/XTextComponent.hpp>
44 : #include <com/sun/star/util/Date.hpp>
45 : #include <com/sun/star/util/Time.hpp>
46 : #include <com/sun/star/util/DateTime.hpp>
47 : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
48 : #include <tools/diagnose_ex.h>
49 :
50 : #include <svl/intitem.hxx>
51 :
52 : #include <svx/algitem.hxx>
53 :
54 : #include <tools/multisel.hxx>
55 :
56 : #include <svl/numuno.hxx>
57 :
58 : #include <svl/itempool.hxx>
59 :
60 : #include <svl/itemset.hxx>
61 :
62 : #include <svl/rngitem.hxx>
63 :
64 : #include <vcl/waitobj.hxx>
65 : #include <toolkit/helper/vclunohelper.hxx>
66 :
67 : #include <svl/zforlist.hxx>
68 : #include <cppuhelper/queryinterface.hxx>
69 : #include <connectivity/dbtools.hxx>
70 : #include <connectivity/dbconversion.hxx>
71 : #include <cppuhelper/typeprovider.hxx>
72 : #include <comphelper/extract.hxx>
73 : #include <comphelper/servicehelper.hxx>
74 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
75 : #include <com/sun/star/sdbc/DataType.hpp>
76 : #include <vcl/msgbox.hxx>
77 : #include "dbu_brw.hrc"
78 : #include "browserids.hxx"
79 : #include "dbustrings.hrc"
80 : #include "dbu_reghelper.hxx"
81 : #include "dbexchange.hxx"
82 : #include "TableRowExchange.hxx"
83 : #include "TableRow.hxx"
84 : #include "FieldDescriptions.hxx"
85 : #include <svtools/stringtransfer.hxx>
86 : #include <vcl/stdtext.hxx>
87 : #include "UITools.hxx"
88 : #include "TokenWriter.hxx"
89 : #include <osl/diagnose.h>
90 :
91 : using namespace ::com::sun::star::ui::dialogs;
92 : using namespace ::com::sun::star::uno;
93 : using namespace ::com::sun::star::sdb;
94 : using namespace ::com::sun::star::sdbc;
95 : using namespace ::com::sun::star::sdbcx;
96 : using namespace ::com::sun::star::beans;
97 : using namespace ::com::sun::star::container;
98 : using namespace ::com::sun::star::datatransfer;
99 : using namespace ::com::sun::star::lang;
100 : using namespace ::com::sun::star::view;
101 : using namespace ::com::sun::star::form;
102 : using namespace ::com::sun::star::frame;
103 : using namespace ::com::sun::star::util;
104 : using namespace ::dbaui;
105 : using namespace ::dbtools;
106 : using namespace ::svx;
107 : using namespace ::svt;
108 :
109 0 : extern "C" void SAL_CALL createRegistryInfo_SbaXGridControl()
110 : {
111 0 : static OMultiInstanceAutoRegistration< SbaXGridControl > aAutoRegistration;
112 0 : }
113 : //-------------------------------------------------------------------------
114 0 : ::comphelper::StringSequence SAL_CALL SbaXGridControl::getSupportedServiceNames() throw()
115 : {
116 0 : return getSupportedServiceNames_Static();
117 : }
118 : // -------------------------------------------------------------------------
119 0 : Reference< XInterface > SAL_CALL SbaXGridControl::Create(const Reference<XMultiServiceFactory >& _rxFactory)
120 : {
121 0 : return *(new SbaXGridControl(_rxFactory));
122 : }
123 :
124 : //------------------------------------------------------------------
125 :
126 : //------------------------------------------------------------------
127 : //=======================================================================================
128 : // SbaXGridControl
129 : //=======================================================================================
130 :
131 : //------------------------------------------------------------------------------
132 0 : ::rtl::OUString SAL_CALL SbaXGridControl::getImplementationName() throw()
133 : {
134 0 : return getImplementationName_Static();
135 : }
136 :
137 : //------------------------------------------------------------------------------
138 0 : ::rtl::OUString SbaXGridControl::getImplementationName_Static() throw( RuntimeException )
139 : {
140 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.dbu.SbaXGridControl"));
141 : }
142 :
143 : //------------------------------------------------------------------------------
144 0 : Sequence< ::rtl::OUString> SbaXGridControl::getSupportedServiceNames_Static(void) throw( RuntimeException )
145 : {
146 0 : Sequence< ::rtl::OUString> aSupported(3);
147 0 : aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.control.InteractionGridControl"));
148 0 : aSupported[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.control.GridControl"));
149 0 : aSupported[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControl"));
150 0 : return aSupported;
151 : }
152 : DBG_NAME(SbaXGridControl );
153 : //---------------------------------------------------------------------------------------
154 0 : SbaXGridControl::SbaXGridControl(const Reference< XMultiServiceFactory >& _rM)
155 0 : : FmXGridControl(_rM)
156 : {
157 : DBG_CTOR(SbaXGridControl ,NULL);
158 0 : }
159 :
160 : //---------------------------------------------------------------------------------------
161 0 : SbaXGridControl::~SbaXGridControl()
162 : {
163 : DBG_DTOR(SbaXGridControl ,NULL);
164 0 : }
165 :
166 : //---------------------------------------------------------------------------------------
167 0 : FmXGridPeer* SbaXGridControl::imp_CreatePeer(Window* pParent)
168 : {
169 0 : FmXGridPeer* pReturn = new SbaXGridPeer(m_xServiceFactory);
170 :
171 : // translate properties into WinBits
172 0 : WinBits nStyle = WB_TABSTOP;
173 0 : Reference< XPropertySet > xModelSet(getModel(), UNO_QUERY);
174 0 : if (xModelSet.is())
175 : {
176 : try
177 : {
178 0 : if (::comphelper::getINT16(xModelSet->getPropertyValue(PROPERTY_BORDER)))
179 0 : nStyle |= WB_BORDER;
180 : }
181 0 : catch(Exception&)
182 : {
183 : }
184 :
185 : }
186 :
187 0 : pReturn->Create(pParent, nStyle);
188 0 : return pReturn;
189 : }
190 :
191 : //------------------------------------------------------------------------------
192 0 : Any SAL_CALL SbaXGridControl::queryInterface(const Type& _rType) throw (RuntimeException)
193 : {
194 0 : Any aRet = FmXGridControl::queryInterface(_rType);
195 0 : return aRet.hasValue() ? aRet : ::cppu::queryInterface(_rType,(::com::sun::star::frame::XDispatch*)this);
196 : }
197 :
198 : //------------------------------------------------------------------------------
199 0 : Sequence< Type > SAL_CALL SbaXGridControl::getTypes( ) throw (RuntimeException)
200 : {
201 0 : Sequence< Type > aTypes = FmXGridControl::getTypes();
202 :
203 0 : sal_Int32 nTypes = aTypes.getLength();
204 0 : aTypes.realloc(nTypes + 1);
205 0 : aTypes[nTypes] = ::getCppuType(static_cast< Reference< ::com::sun::star::frame::XDispatch >* >(NULL));
206 :
207 0 : return aTypes;
208 : }
209 :
210 : //------------------------------------------------------------------------------
211 0 : Sequence< sal_Int8 > SAL_CALL SbaXGridControl::getImplementationId( ) throw (RuntimeException)
212 : {
213 : static ::cppu::OImplementationId * pId = 0;
214 0 : if (! pId)
215 : {
216 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
217 0 : if (! pId)
218 : {
219 0 : static ::cppu::OImplementationId aId;
220 0 : pId = &aId;
221 0 : }
222 : }
223 0 : return pId->getImplementationId();
224 : }
225 :
226 : //---------------------------------------------------------------------------------------
227 0 : void SAL_CALL SbaXGridControl::createPeer(const Reference< ::com::sun::star::awt::XToolkit > & rToolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & rParentPeer) throw( RuntimeException )
228 : {
229 0 : FmXGridControl::createPeer(rToolkit, rParentPeer);
230 :
231 : OSL_ENSURE(!mbCreatingPeer, "FmXGridControl::createPeer : recursion!");
232 : // see the base class' createPeer for a comment on this
233 :
234 : // TODO: why the hell this whole class does not use any mutex?
235 :
236 0 : Reference< ::com::sun::star::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
237 0 : for ( StatusMultiplexerArray::iterator aIter = m_aStatusMultiplexer.begin();
238 0 : aIter != m_aStatusMultiplexer.end();
239 : ++aIter)
240 : {
241 0 : if ((*aIter).second && (*aIter).second->getLength())
242 0 : xDisp->addStatusListener((*aIter).second, (*aIter).first);
243 0 : }
244 0 : }
245 :
246 : //---------------------------------------------------------------------------------------
247 0 : void SAL_CALL SbaXGridControl::dispatch(const ::com::sun::star::util::URL& aURL, const Sequence< PropertyValue >& aArgs) throw( RuntimeException )
248 : {
249 0 : Reference< ::com::sun::star::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
250 0 : if (xDisp.is())
251 0 : xDisp->dispatch(aURL, aArgs);
252 0 : }
253 : //---------------------------------------------------------------------------------------
254 0 : void SAL_CALL SbaXGridControl::addStatusListener( const Reference< XStatusListener > & _rxListener, const URL& _rURL ) throw( RuntimeException )
255 : {
256 0 : ::osl::MutexGuard aGuard( GetMutex() );
257 0 : if ( _rxListener.is() )
258 : {
259 0 : SbaXStatusMultiplexer*& pMultiplexer = m_aStatusMultiplexer[ _rURL ];
260 0 : if ( !pMultiplexer )
261 : {
262 0 : pMultiplexer = new SbaXStatusMultiplexer( *this, GetMutex() );
263 0 : pMultiplexer->acquire();
264 : }
265 :
266 0 : pMultiplexer->addInterface( _rxListener );
267 0 : if ( getPeer().is() )
268 : {
269 0 : if ( 1 == pMultiplexer->getLength() )
270 : { // the first external listener for this URL
271 0 : Reference< XDispatch > xDisp( getPeer(), UNO_QUERY );
272 0 : xDisp->addStatusListener( pMultiplexer, _rURL );
273 : }
274 : else
275 : { // already have other listeners for this URL
276 0 : _rxListener->statusChanged( pMultiplexer->getLastEvent() );
277 : }
278 : }
279 0 : }
280 0 : }
281 :
282 : //---------------------------------------------------------------------------------------
283 0 : void SAL_CALL SbaXGridControl::removeStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & _rxListener, const ::com::sun::star::util::URL& _rURL) throw( RuntimeException )
284 : {
285 0 : ::osl::MutexGuard aGuard( GetMutex() );
286 :
287 0 : SbaXStatusMultiplexer*& pMultiplexer = m_aStatusMultiplexer[_rURL];
288 0 : if (!pMultiplexer)
289 : {
290 0 : pMultiplexer = new SbaXStatusMultiplexer(*this,GetMutex());
291 0 : pMultiplexer->acquire();
292 : }
293 :
294 0 : if (getPeer().is() && pMultiplexer->getLength() == 1)
295 : {
296 0 : Reference< ::com::sun::star::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
297 0 : xDisp->removeStatusListener(pMultiplexer, _rURL);
298 : }
299 0 : pMultiplexer->removeInterface( _rxListener );
300 0 : }
301 :
302 : //---------------------------------------------------------------------------------------
303 0 : void SAL_CALL SbaXGridControl::dispose(void) throw( RuntimeException )
304 : {
305 0 : SolarMutexGuard aGuard;
306 :
307 0 : EventObject aEvt;
308 0 : aEvt.Source = *this;
309 :
310 0 : for ( StatusMultiplexerArray::iterator aIter = m_aStatusMultiplexer.begin();
311 0 : aIter != m_aStatusMultiplexer.end();
312 : ++aIter)
313 : {
314 0 : if ((*aIter).second)
315 : {
316 0 : (*aIter).second->disposeAndClear(aEvt);
317 0 : (*aIter).second->release();
318 0 : (*aIter).second = NULL;
319 : }
320 : }
321 0 : StatusMultiplexerArray().swap(m_aStatusMultiplexer);
322 :
323 0 : FmXGridControl::dispose();
324 0 : }
325 :
326 : //=======================================================================================
327 : // SbaXGridPeer
328 : //=======================================================================================
329 : DBG_NAME(SbaXGridPeer )
330 : //---------------------------------------------------------------------------------------
331 0 : SbaXGridPeer::SbaXGridPeer(const Reference< XMultiServiceFactory >& _rM)
332 : : FmXGridPeer(_rM)
333 0 : ,m_aStatusListeners(m_aMutex)
334 : {
335 : DBG_CTOR(SbaXGridPeer ,NULL);
336 0 : }
337 :
338 : //---------------------------------------------------------------------------------------
339 0 : SbaXGridPeer::~SbaXGridPeer()
340 : {
341 : DBG_DTOR(SbaXGridPeer ,NULL);
342 0 : }
343 :
344 : //---------------------------------------------------------------------------------------
345 0 : void SAL_CALL SbaXGridPeer::dispose(void) throw( RuntimeException )
346 : {
347 0 : EventObject aEvt(*this);
348 :
349 0 : m_aStatusListeners.disposeAndClear(aEvt);
350 :
351 0 : FmXGridPeer::dispose();
352 0 : }
353 :
354 : //---------------------------------------------------------------------------------------
355 0 : void SbaXGridPeer::NotifyStatusChanged(const ::com::sun::star::util::URL& _rUrl, const Reference< ::com::sun::star::frame::XStatusListener > & xControl)
356 : {
357 0 : SbaGridControl* pGrid = (SbaGridControl*) GetWindow();
358 0 : if (!pGrid)
359 0 : return;
360 :
361 0 : ::com::sun::star::frame::FeatureStateEvent aEvt;
362 0 : aEvt.Source = *this;
363 0 : aEvt.IsEnabled = !pGrid->IsReadOnlyDB();
364 0 : aEvt.FeatureURL = _rUrl;
365 :
366 0 : ConstMapDispatchToBoolIterator aURLStatePos = m_aDispatchStates.find( classifyDispatchURL( _rUrl ) );
367 0 : if ( m_aDispatchStates.end() != aURLStatePos )
368 0 : aEvt.State <<= aURLStatePos->second;
369 : else
370 0 : aEvt.State <<= sal_False;
371 :
372 0 : if (xControl.is())
373 0 : xControl->statusChanged(aEvt);
374 : else
375 : {
376 0 : ::cppu::OInterfaceContainerHelper * pIter = m_aStatusListeners.getContainer(_rUrl);
377 :
378 0 : if (pIter)
379 : {
380 0 : ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
381 0 : while (aListIter.hasMoreElements())
382 0 : ((::com::sun::star::frame::XStatusListener*)aListIter.next())->statusChanged(aEvt);
383 : }
384 0 : }
385 : }
386 :
387 : //------------------------------------------------------------------------------
388 0 : Any SAL_CALL SbaXGridPeer::queryInterface(const Type& _rType) throw (RuntimeException)
389 : {
390 0 : Any aRet = ::cppu::queryInterface(_rType,(::com::sun::star::frame::XDispatch*)this);
391 0 : if(aRet.hasValue())
392 0 : return aRet;
393 0 : return FmXGridPeer::queryInterface(_rType);
394 : }
395 :
396 : //---------------------------------------------------------------------------------------
397 0 : Reference< ::com::sun::star::frame::XDispatch > SAL_CALL SbaXGridPeer::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
398 : {
399 0 : if ( ( aURL.Complete == ".uno:GridSlots/BrowserAttribs" ) || ( aURL.Complete == ".uno:GridSlots/RowHeight" )
400 0 : || ( aURL.Complete == ".uno:GridSlots/ColumnAttribs" ) || ( aURL.Complete == ".uno:GridSlots/ColumnWidth" )
401 : )
402 : {
403 0 : return (::com::sun::star::frame::XDispatch*)this;
404 : }
405 :
406 0 : return FmXGridPeer::queryDispatch(aURL, aTargetFrameName, nSearchFlags);
407 : }
408 :
409 : //---------------------------------------------------------------------------------------
410 0 : IMPL_LINK( SbaXGridPeer, OnDispatchEvent, void*, /*NOTINTERESTEDIN*/ )
411 : {
412 0 : SbaGridControl* pGrid = static_cast< SbaGridControl* >( GetWindow() );
413 0 : if ( pGrid ) // if this fails, we were disposing before arriving here
414 : {
415 0 : if ( Application::GetMainThreadIdentifier() != ::osl::Thread::getCurrentIdentifier() )
416 : {
417 : // still not in the main thread (see SbaXGridPeer::dispatch). post an event, again
418 : // without moving the special even to the back of the queue
419 0 : pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
420 : }
421 : else
422 : {
423 0 : DispatchArgs aArgs = m_aDispatchArgs.front();
424 0 : m_aDispatchArgs.pop();
425 :
426 0 : SbaXGridPeer::dispatch( aArgs.aURL, aArgs.aArgs );
427 : }
428 : }
429 :
430 0 : return 0;
431 : }
432 :
433 : //---------------------------------------------------------------------------------------
434 0 : SbaXGridPeer::DispatchType SbaXGridPeer::classifyDispatchURL( const URL& _rURL )
435 : {
436 0 : DispatchType eURLType = dtUnknown;
437 0 : if ( _rURL.Complete == ".uno:GridSlots/BrowserAttribs" )
438 0 : eURLType = dtBrowserAttribs;
439 0 : else if ( _rURL.Complete == ".uno:GridSlots/RowHeight" )
440 0 : eURLType = dtRowHeight;
441 0 : else if ( _rURL.Complete == ".uno:GridSlots/ColumnAttribs" )
442 0 : eURLType = dtColumnAttribs;
443 0 : else if ( _rURL.Complete == ".uno:GridSlots/ColumnWidth" )
444 0 : eURLType = dtColumnWidth;
445 0 : return eURLType;
446 : }
447 :
448 : //---------------------------------------------------------------------------------------
449 0 : void SAL_CALL SbaXGridPeer::dispatch(const URL& aURL, const Sequence< PropertyValue >& aArgs) throw( RuntimeException )
450 : {
451 0 : SbaGridControl* pGrid = (SbaGridControl*)GetWindow();
452 0 : if (!pGrid)
453 : return;
454 :
455 0 : if ( Application::GetMainThreadIdentifier() != ::osl::Thread::getCurrentIdentifier() )
456 : {
457 : // we're not in the main thread. This is bad, as we want to raise windows here,
458 : // and VCL does not like windows to be opened in non-main threads (at least on Win32).
459 : // Okay, do this async. No problem with this, as XDispatch::dispatch is defined to be
460 : // a one-way method.
461 :
462 : // save the args
463 0 : DispatchArgs aDispatchArgs;
464 0 : aDispatchArgs.aURL = aURL;
465 0 : aDispatchArgs.aArgs = aArgs;
466 0 : m_aDispatchArgs.push( aDispatchArgs );
467 :
468 : // post an event
469 : // we use the Window::PostUserEvent here, instead of the application::PostUserEvent
470 : // this saves us from keeping track of these events - as soon as the window dies,
471 : // the events are deleted automatically. For the application way, we would need to
472 : // do this ourself.
473 : // As we use our grid as window, and the grid dies before we dy, this should be no problem.
474 0 : pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
475 0 : return;
476 : }
477 :
478 0 : SolarMutexGuard aGuard;
479 0 : sal_Int16 nColId = -1;
480 0 : const PropertyValue* pArgs = aArgs.getConstArray();
481 0 : for (sal_uInt16 i=0; i<aArgs.getLength(); ++i, ++pArgs)
482 : {
483 0 : if (pArgs->Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColumnViewPos")))
484 : {
485 0 : nColId = pGrid->GetColumnIdFromViewPos(::comphelper::getINT16(pArgs->Value));
486 0 : break;
487 : }
488 0 : if (pArgs->Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColumnModelPos")))
489 : {
490 0 : nColId = pGrid->GetColumnIdFromModelPos(::comphelper::getINT16(pArgs->Value));
491 0 : break;
492 : }
493 0 : if (pArgs->Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColumnId")))
494 : {
495 0 : nColId = ::comphelper::getINT16(pArgs->Value);
496 0 : break;
497 : }
498 : }
499 :
500 0 : DispatchType eURLType = classifyDispatchURL( aURL );
501 :
502 0 : if ( dtUnknown != eURLType )
503 : {
504 : // notify any status listeners that the dialog is now active (well, about to be active)
505 0 : MapDispatchToBool::iterator aThisURLState = m_aDispatchStates.insert( MapDispatchToBool::value_type( eURLType, sal_True ) ).first;
506 0 : NotifyStatusChanged( aURL, NULL );
507 :
508 : // execute the dialog
509 0 : switch ( eURLType )
510 : {
511 : case dtBrowserAttribs:
512 0 : pGrid->SetBrowserAttrs();
513 0 : break;
514 :
515 : case dtRowHeight:
516 0 : pGrid->SetRowHeight();
517 0 : break;
518 :
519 : case dtColumnAttribs:
520 : {
521 : OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
522 0 : if (nColId != -1)
523 0 : break;
524 0 : pGrid->SetColAttrs(nColId);
525 : }
526 0 : break;
527 :
528 : case dtColumnWidth:
529 : {
530 : OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
531 0 : if (nColId != -1)
532 0 : break;
533 0 : pGrid->SetColWidth(nColId);
534 : }
535 0 : break;
536 :
537 : case dtUnknown:
538 0 : break;
539 : }
540 :
541 : // notify any status listeners that the dialog vanished
542 0 : m_aDispatchStates.erase( aThisURLState );
543 0 : NotifyStatusChanged( aURL, NULL );
544 0 : }
545 : }
546 :
547 : //---------------------------------------------------------------------------------------
548 0 : void SAL_CALL SbaXGridPeer::addStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( RuntimeException )
549 : {
550 0 : ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL);
551 0 : if (!pCont)
552 0 : m_aStatusListeners.addInterface(aURL,xControl);
553 : else
554 0 : pCont->addInterface(xControl);
555 0 : NotifyStatusChanged(aURL, xControl);
556 0 : }
557 :
558 : //---------------------------------------------------------------------------------------
559 0 : void SAL_CALL SbaXGridPeer::removeStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( RuntimeException )
560 : {
561 0 : ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL);
562 0 : if ( pCont )
563 0 : pCont->removeInterface(xControl);
564 0 : }
565 :
566 : namespace
567 : {
568 : class theSbaXGridPeerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSbaXGridPeerUnoTunnelId > {};
569 : }
570 :
571 0 : const Sequence< sal_Int8 > & SbaXGridPeer::getUnoTunnelId()
572 : {
573 0 : return theSbaXGridPeerUnoTunnelId::get().getSeq();
574 : }
575 :
576 0 : Sequence< Type > SAL_CALL SbaXGridPeer::getTypes() throw (RuntimeException)
577 : {
578 0 : Sequence< Type > aTypes = FmXGridPeer::getTypes();
579 0 : sal_Int32 nOldLen = aTypes.getLength();
580 0 : aTypes.realloc(nOldLen + 1);
581 0 : aTypes.getArray()[nOldLen] = ::getCppuType( static_cast< Reference< ::com::sun::star::frame::XDispatch >* >(0) );
582 :
583 0 : return aTypes;
584 : }
585 :
586 : // return implementation specific data
587 : //------------------------------------------------------------------
588 0 : sal_Int64 SAL_CALL SbaXGridPeer::getSomething( const Sequence< sal_Int8 > & rId ) throw(::com::sun::star::uno::RuntimeException)
589 : {
590 0 : if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) )
591 0 : return reinterpret_cast< sal_Int64 >( this );
592 :
593 0 : return FmXGridPeer::getSomething(rId);
594 : }
595 :
596 : //---------------------------------------------------------------------------------------
597 0 : SbaXGridPeer* SbaXGridPeer::getImplementation(const Reference< XInterface >& _rxIFace)
598 : {
599 : Reference< XUnoTunnel > xTunnel(
600 0 : _rxIFace, UNO_QUERY);
601 0 : if (xTunnel.is())
602 0 : return reinterpret_cast<SbaXGridPeer*>(xTunnel->getSomething(getUnoTunnelId()));
603 0 : return NULL;
604 : }
605 :
606 : //---------------------------------------------------------------------------------------
607 0 : FmGridControl* SbaXGridPeer::imp_CreateControl(Window* pParent, WinBits nStyle)
608 : {
609 0 : return new SbaGridControl(m_xServiceFactory, pParent, this, nStyle);
610 : }
611 :
612 : //==================================================================
613 : // SbaGridHeader
614 : //==================================================================
615 :
616 : //---------------------------------------------------------------------------------------
617 0 : SbaGridHeader::SbaGridHeader(BrowseBox* pParent, WinBits nWinBits)
618 : :FmGridHeader(pParent, nWinBits)
619 0 : ,DragSourceHelper(this)
620 : {
621 0 : }
622 :
623 : //---------------------------------------------------------------------------------------
624 0 : void SbaGridHeader::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
625 : {
626 0 : SolarMutexGuard aGuard;
627 : // in the new DnD API, the solar mutex is not locked when StartDrag get's called
628 :
629 0 : ImplStartColumnDrag( _nAction, _rPosPixel );
630 0 : }
631 :
632 : //---------------------------------------------------------------------------------------
633 0 : void SbaGridHeader::MouseButtonDown( const MouseEvent& _rMEvt )
634 : {
635 0 : if (_rMEvt.IsLeft())
636 0 : if (_rMEvt.GetClicks() != 2)
637 : {
638 : // the base class will start a column move here, which we don't want to allow
639 : // (at the moment. If we store relative positions with the columns, we can allow column moves ....)
640 :
641 : }
642 :
643 0 : FmGridHeader::MouseButtonDown(_rMEvt);
644 0 : }
645 :
646 : //---------------------------------------------------------------------------------------
647 0 : sal_Bool SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos)
648 : {
649 0 : sal_uInt16 nId = GetItemId(_rMousePos);
650 0 : sal_Bool bResizingCol = sal_False;
651 0 : if (HEADERBAR_ITEM_NOTFOUND != nId)
652 : {
653 0 : Rectangle aColRect = GetItemRect(nId);
654 0 : aColRect.Left() += nId ? 3 : 0; // the handle col (nId == 0) does not have a left margin for resizing
655 0 : aColRect.Right() -= 3;
656 0 : bResizingCol = !aColRect.IsInside(_rMousePos);
657 : }
658 0 : if (!bResizingCol)
659 : {
660 : // force the the base class to end it's drag mode
661 0 : EndTracking(ENDTRACK_CANCEL | ENDTRACK_END);
662 :
663 : // because we have 3d-buttons the select handler is called from MouseButtonUp, but StartDrag
664 : // occures earlier (while the mouse button is down)
665 : // so for optical reasons we select the column before really starting the drag operation.
666 0 : notifyColumnSelect(nId);
667 :
668 0 : static_cast<SbaGridControl*>(GetParent())->StartDrag(_nAction,
669 : Point(
670 0 : _rMousePos.X() + GetPosPixel().X(), // we aren't left-justified with our parent, in contrast to the data window
671 0 : _rMousePos.Y() - GetSizePixel().Height()
672 : )
673 0 : );
674 0 : return sal_True;
675 : }
676 :
677 0 : return sal_False;
678 : }
679 :
680 : //---------------------------------------------------------------------------------------
681 0 : void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu)
682 : {
683 0 : FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu);
684 :
685 : // some items are valid only if the db isn't readonly
686 0 : sal_Bool bDBIsReadOnly = ((SbaGridControl*)GetParent())->IsReadOnlyDB();
687 :
688 0 : if (bDBIsReadOnly)
689 : {
690 0 : rMenu.EnableItem(SID_FM_HIDECOL, sal_False);
691 0 : PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(SID_FM_SHOWCOLS);
692 0 : if (pShowColsMenu)
693 : {
694 : // at most 16 items which mean "show column <name>"
695 0 : for (sal_uInt16 i=1; i<16; ++i)
696 0 : pShowColsMenu->EnableItem(i, sal_False);
697 : // "show cols/more..." and "show cols/all"
698 0 : pShowColsMenu->EnableItem(SID_FM_SHOWCOLS_MORE, sal_False);
699 0 : pShowColsMenu->EnableItem(SID_FM_SHOWALLCOLS, sal_False);
700 : }
701 : }
702 :
703 : // prepend some new items
704 0 : sal_Bool bColAttrs = (nColId != (sal_uInt16)-1) && (nColId != 0);
705 0 : if ( bColAttrs && !bDBIsReadOnly)
706 : {
707 0 : PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_COLCTXMENU));
708 0 : sal_uInt16 nPos = 0;
709 0 : sal_uInt16 nModelPos = ((SbaGridControl*)GetParent())->GetModelColumnPos(nColId);
710 0 : Reference< XPropertySet > xField = ((SbaGridControl*)GetParent())->getField(nModelPos);
711 :
712 0 : if ( xField.is() )
713 : {
714 0 : switch( ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE)) )
715 : {
716 : case DataType::BINARY:
717 : case DataType::VARBINARY:
718 : case DataType::LONGVARBINARY:
719 : case DataType::SQLNULL:
720 : case DataType::OBJECT:
721 : case DataType::BLOB:
722 : case DataType::CLOB:
723 : case DataType::REF:
724 0 : break;
725 : default:
726 0 : rMenu.InsertItem(ID_BROWSER_COLATTRSET, aNewItems.GetItemText(ID_BROWSER_COLATTRSET), 0, nPos++);
727 0 : rMenu.SetHelpId(ID_BROWSER_COLATTRSET, aNewItems.GetHelpId(ID_BROWSER_COLATTRSET));
728 0 : rMenu.InsertSeparator(nPos++);
729 : }
730 : }
731 :
732 0 : rMenu.InsertItem(ID_BROWSER_COLWIDTH, aNewItems.GetItemText(ID_BROWSER_COLWIDTH), 0, nPos++);
733 0 : rMenu.SetHelpId(ID_BROWSER_COLWIDTH, aNewItems.GetHelpId(ID_BROWSER_COLWIDTH));
734 0 : rMenu.InsertSeparator(nPos++);
735 : }
736 0 : }
737 :
738 : //---------------------------------------------------------------------------------------
739 0 : void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
740 : {
741 0 : switch (nExecutionResult)
742 : {
743 : case ID_BROWSER_COLWIDTH:
744 0 : ((SbaGridControl*)GetParent())->SetColWidth(nColId);
745 0 : break;
746 :
747 : case ID_BROWSER_COLATTRSET:
748 0 : ((SbaGridControl*)GetParent())->SetColAttrs(nColId);
749 0 : break;
750 : case ID_BROWSER_COLUMNINFO:
751 : {
752 0 : sal_uInt16 nModelPos = ((SbaGridControl*)GetParent())->GetModelColumnPos(nColId);
753 0 : Reference< XPropertySet > xField = ((SbaGridControl*)GetParent())->getField(nModelPos);
754 :
755 0 : if(!xField.is())
756 : break;
757 0 : ::std::vector< ::boost::shared_ptr<OTableRow> > vClipboardList;
758 : // send it to the clipboard
759 0 : vClipboardList.push_back(::boost::shared_ptr<OTableRow>(new OTableRow(xField)));
760 0 : OTableRowExchange* pData = new OTableRowExchange(vClipboardList);
761 0 : Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
762 0 : pData->CopyToClipboard(GetParent());
763 : }
764 0 : break;
765 :
766 0 : default: FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, nExecutionResult);
767 : }
768 0 : }
769 :
770 : //==================================================================
771 : // SbaGridControl
772 : //==================================================================
773 : DBG_NAME(SbaGridControl );
774 : //---------------------------------------------------------------------------------------
775 0 : SbaGridControl::SbaGridControl(Reference< XMultiServiceFactory > _rM,
776 : Window* pParent, FmXGridPeer* _pPeer, WinBits nBits)
777 : :FmGridControl(_rM,pParent, _pPeer, nBits)
778 : ,m_pMasterListener(NULL)
779 : ,m_nAsyncDropEvent(0)
780 : ,m_nCurrentActionColId((sal_uInt16)-1)
781 0 : ,m_bActivatingForDrop(sal_False)
782 : {
783 : DBG_CTOR(SbaGridControl ,NULL);
784 0 : }
785 :
786 : //---------------------------------------------------------------------------------------
787 0 : SbaGridControl::~SbaGridControl()
788 : {
789 : DBG_DTOR(SbaGridControl ,NULL);
790 0 : if (m_nAsyncDropEvent)
791 0 : Application::RemoveUserEvent(m_nAsyncDropEvent);
792 0 : }
793 :
794 : //---------------------------------------------------------------------------------------
795 0 : BrowserHeader* SbaGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
796 : {
797 0 : return new SbaGridHeader(pParent);
798 : }
799 :
800 : //---------------------------------------------------------------------------------------
801 0 : CellController* SbaGridControl::GetController(long nRow, sal_uInt16 nCol)
802 : {
803 0 : if ( m_bActivatingForDrop )
804 0 : return NULL;
805 :
806 0 : return FmGridControl::GetController(nRow, nCol);
807 : }
808 :
809 : //---------------------------------------------------------------------------------------
810 0 : void SbaGridControl::PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu)
811 : {
812 0 : FmGridControl::PreExecuteRowContextMenu(nRow, rMenu);
813 :
814 0 : PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_ROWCTXMENU));
815 0 : sal_uInt16 nPos = 0;
816 :
817 0 : if (!IsReadOnlyDB())
818 : {
819 0 : rMenu.InsertItem(ID_BROWSER_TABLEATTR, aNewItems.GetItemText(ID_BROWSER_TABLEATTR), 0, nPos++);
820 0 : rMenu.SetHelpId(ID_BROWSER_TABLEATTR, aNewItems.GetHelpId(ID_BROWSER_TABLEATTR));
821 :
822 0 : rMenu.InsertItem(ID_BROWSER_ROWHEIGHT, aNewItems.GetItemText(ID_BROWSER_ROWHEIGHT), 0, nPos++);
823 0 : rMenu.SetHelpId(ID_BROWSER_ROWHEIGHT, aNewItems.GetHelpId(ID_BROWSER_ROWHEIGHT));
824 0 : rMenu.InsertSeparator(nPos++);
825 : }
826 :
827 0 : if ( GetSelectRowCount() > 0 )
828 : {
829 0 : rMenu.InsertItem(ID_BROWSER_COPY, aNewItems.GetItemText(SID_COPY), 0, nPos++);
830 0 : rMenu.SetHelpId(ID_BROWSER_COPY, aNewItems.GetHelpId(SID_COPY));
831 :
832 0 : rMenu.InsertSeparator(nPos++);
833 0 : }
834 0 : }
835 :
836 : //------------------------------------------------------------------------------
837 0 : SvNumberFormatter* SbaGridControl::GetDatasourceFormatter()
838 : {
839 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = ::dbtools::getNumberFormats(::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)), sal_True, comphelper::getComponentContext(getServiceManager()));
840 :
841 0 : SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
842 0 : if ( !pSupplierImpl )
843 0 : return NULL;
844 :
845 0 : SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
846 0 : return pFormatter;
847 : }
848 :
849 : //------------------------------------------------------------------------------
850 0 : void SbaGridControl::SetColWidth(sal_uInt16 nColId)
851 : {
852 : // get the (UNO) column model
853 0 : sal_uInt16 nModelPos = GetModelColumnPos(nColId);
854 0 : Reference< XIndexAccess > xCols(GetPeer()->getColumns(), UNO_QUERY);
855 0 : Reference< XPropertySet > xAffectedCol;
856 0 : if (xCols.is() && (nModelPos != (sal_uInt16)-1))
857 0 : ::cppu::extractInterface(xAffectedCol,xCols->getByIndex(nModelPos));
858 :
859 0 : if (xAffectedCol.is())
860 : {
861 0 : Any aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
862 0 : sal_Int32 nCurWidth = aWidth.hasValue() ? ::comphelper::getINT32(aWidth) : -1;
863 :
864 0 : DlgSize aDlgColWidth(this, nCurWidth, sal_False);
865 0 : if (aDlgColWidth.Execute())
866 : {
867 0 : sal_Int32 nValue = aDlgColWidth.GetValue();
868 0 : Any aNewWidth;
869 0 : if (-1 == nValue)
870 : { // set to default
871 0 : Reference< XPropertyState > xPropState(xAffectedCol, UNO_QUERY);
872 0 : if (xPropState.is())
873 : {
874 0 : try { aNewWidth = xPropState->getPropertyDefault(PROPERTY_WIDTH); } catch(Exception&) { } ;
875 0 : }
876 : }
877 : else
878 0 : aNewWidth <<= nValue;
879 0 : try { xAffectedCol->setPropertyValue(PROPERTY_WIDTH, aNewWidth); } catch(Exception&) { } ;
880 0 : }
881 0 : }
882 0 : }
883 :
884 : //------------------------------------------------------------------------------
885 0 : void SbaGridControl::SetRowHeight()
886 : {
887 0 : Reference< XPropertySet > xCols(GetPeer()->getColumns(), UNO_QUERY);
888 0 : if (!xCols.is())
889 0 : return;
890 :
891 0 : Any aHeight = xCols->getPropertyValue(PROPERTY_ROW_HEIGHT);
892 0 : sal_Int32 nCurHeight = aHeight.hasValue() ? ::comphelper::getINT32(aHeight) : -1;
893 :
894 0 : DlgSize aDlgRowHeight(this, nCurHeight, sal_True);
895 0 : if (aDlgRowHeight.Execute())
896 : {
897 0 : sal_Int32 nValue = aDlgRowHeight.GetValue();
898 0 : Any aNewHeight;
899 0 : if ((sal_Int16)-1 == nValue)
900 : { // set to default
901 0 : Reference< XPropertyState > xPropState(xCols, UNO_QUERY);
902 0 : if (xPropState.is())
903 : {
904 : try
905 : {
906 0 : aNewHeight = xPropState->getPropertyDefault(PROPERTY_ROW_HEIGHT);
907 : }
908 0 : catch(Exception&)
909 : { }
910 0 : }
911 : }
912 : else
913 0 : aNewHeight <<= nValue;
914 : try
915 : {
916 0 : xCols->setPropertyValue(PROPERTY_ROW_HEIGHT, aNewHeight);
917 : }
918 0 : catch(Exception&)
919 : {
920 : OSL_FAIL("setPropertyValue: PROPERTY_ROW_HEIGHT throws a exception");
921 0 : }
922 0 : }
923 : }
924 :
925 : //------------------------------------------------------------------------------
926 0 : void SbaGridControl::SetColAttrs(sal_uInt16 nColId)
927 : {
928 0 : SvNumberFormatter* pFormatter = GetDatasourceFormatter();
929 0 : if (!pFormatter)
930 0 : return;
931 :
932 0 : sal_uInt16 nModelPos = GetModelColumnPos(nColId);
933 :
934 : // get the (UNO) column model
935 0 : Reference< XIndexAccess > xCols(GetPeer()->getColumns(), UNO_QUERY);
936 0 : Reference< XPropertySet > xAffectedCol;
937 0 : if (xCols.is() && (nModelPos != (sal_uInt16)-1))
938 0 : ::cppu::extractInterface(xAffectedCol,xCols->getByIndex(nModelPos));
939 :
940 : // get the field the column is bound to
941 0 : Reference< XPropertySet > xField = getField(nModelPos);
942 0 : ::dbaui::callColumnFormatDialog(xAffectedCol,xField,pFormatter,this);//(Window::GetSettings().GetLanguage());
943 : }
944 :
945 :
946 : //------------------------------------------------------------------------------
947 0 : void SbaGridControl::SetBrowserAttrs()
948 : {
949 0 : Reference< XPropertySet > xGridModel(GetPeer()->getColumns(), UNO_QUERY);
950 0 : if (!xGridModel.is())
951 : return;
952 :
953 : try
954 : {
955 0 : PropertyValue aArg;
956 0 : aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IntrospectedObject"));
957 0 : aArg.Value <<= xGridModel;
958 0 : Sequence< Any > aDialogArgs(1);
959 0 : aDialogArgs[0] <<= aArg;
960 :
961 0 : Reference< XInterface > xDialog = getServiceManager()->createInstanceWithArguments(
962 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.ControlFontDialog")),
963 : aDialogArgs
964 0 : );
965 0 : if (!xDialog.is())
966 : {
967 0 : ShowServiceNotAvailableError(this, rtl::OUString("com.sun.star.form.ControlFontDialog"), sal_True);
968 : return;
969 : }
970 :
971 0 : Reference< XExecutableDialog > xExecute(xDialog, UNO_QUERY);
972 : OSL_ENSURE(xExecute.is(), "SbaGridControl::SetBrowserAttrs: missing an interface on the dialog!");
973 0 : if (xExecute.is())
974 0 : xExecute->execute();
975 : }
976 0 : catch( const Exception& )
977 : {
978 : DBG_UNHANDLED_EXCEPTION();
979 0 : }
980 : }
981 :
982 : //---------------------------------------------------------------------------------------
983 0 : void SbaGridControl::PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
984 : {
985 0 : switch (nExecutionResult)
986 : {
987 : case ID_BROWSER_TABLEATTR:
988 0 : SetBrowserAttrs();
989 0 : break;
990 : case ID_BROWSER_ROWHEIGHT:
991 0 : SetRowHeight();
992 0 : break;
993 : case ID_BROWSER_COPY:
994 0 : CopySelectedRowsToClipboard();
995 0 : break;
996 :
997 : default:
998 0 : FmGridControl::PostExecuteRowContextMenu(nRow, rMenu, nExecutionResult);
999 0 : break;
1000 : }
1001 0 : }
1002 :
1003 : //---------------------------------------------------------------------------------------
1004 0 : void SbaGridControl::Select()
1005 : {
1006 : // Some selection has changed ...
1007 0 : FmGridControl::Select();
1008 :
1009 0 : if (m_pMasterListener)
1010 0 : m_pMasterListener->SelectionChanged();
1011 0 : }
1012 :
1013 : //---------------------------------------------------------------------------------------
1014 0 : void SbaGridControl::CursorMoved()
1015 : {
1016 0 : FmGridControl::CursorMoved();
1017 0 : }
1018 :
1019 : //---------------------------------------------------------------------------------------
1020 0 : void SbaGridControl::ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bSetCellFocus /*= sal_True*/ )
1021 : {
1022 0 : FmGridControl::ActivateCell(nRow, nCol, bSetCellFocus);
1023 0 : if (m_pMasterListener)
1024 0 : m_pMasterListener->CellActivated();
1025 0 : }
1026 :
1027 : //---------------------------------------------------------------------------------------
1028 0 : void SbaGridControl::DeactivateCell(sal_Bool bUpdate /*= sal_True*/)
1029 : {
1030 0 : FmGridControl::DeactivateCell(bUpdate);
1031 0 : if (m_pMasterListener)
1032 0 : m_pMasterListener->CellDeactivated();
1033 0 : }
1034 :
1035 : //---------------------------------------------------------------------------------------
1036 0 : void SbaGridControl::onRowChange()
1037 : {
1038 0 : if ( m_pMasterListener )
1039 0 : m_pMasterListener->RowChanged();
1040 0 : }
1041 :
1042 : //---------------------------------------------------------------------------------------
1043 0 : void SbaGridControl::onColumnChange()
1044 : {
1045 0 : if ( m_pMasterListener )
1046 0 : m_pMasterListener->ColumnChanged();
1047 0 : }
1048 :
1049 : //---------------------------------------------------------------------------------------
1050 0 : void SbaGridControl::BeforeDrop()
1051 : {
1052 0 : if (m_pMasterListener)
1053 0 : m_pMasterListener->BeforeDrop();
1054 0 : }
1055 : //---------------------------------------------------------------------------------------
1056 0 : void SbaGridControl::AfterDrop()
1057 : {
1058 0 : if (m_pMasterListener)
1059 0 : m_pMasterListener->AfterDrop();
1060 0 : }
1061 :
1062 :
1063 : //------------------------------------------------------------------------------
1064 0 : Reference< XPropertySet > SbaGridControl::getField(sal_uInt16 nModelPos)
1065 : {
1066 0 : Reference< XPropertySet > xEmptyReturn;
1067 : try
1068 : {
1069 : // first get the name of the column
1070 0 : Reference< XIndexAccess > xCols(GetPeer()->getColumns(), UNO_QUERY);
1071 0 : if ( xCols.is() && xCols->getCount() > nModelPos )
1072 : {
1073 0 : Reference< XPropertySet > xCol(xCols->getByIndex(nModelPos),UNO_QUERY);
1074 0 : if ( xCol.is() )
1075 0 : xEmptyReturn.set(xCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
1076 : }
1077 : else
1078 0 : OSL_FAIL("SbaGridControl::getField getColumns returns NULL or ModelPos is > than count!");
1079 : }
1080 0 : catch(Exception&)
1081 : {
1082 : OSL_FAIL("SbaGridControl::getField Exception occurred!");
1083 : }
1084 :
1085 0 : return xEmptyReturn;
1086 : }
1087 :
1088 : //---------------------------------------------------------------------------------------
1089 0 : sal_Bool SbaGridControl::IsReadOnlyDB() const
1090 : {
1091 : // assume yes if anything fails
1092 0 : sal_Bool bDBIsReadOnly = sal_True;
1093 :
1094 : // the db is the implemented by the parent of the grid control's model ...
1095 0 : Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
1096 0 : if (xColumns.is())
1097 : {
1098 0 : Reference< XRowSet > xDataSource(xColumns->getParent(), UNO_QUERY);
1099 0 : Reference< XChild > xConn(::dbtools::getConnection(xDataSource),UNO_QUERY);
1100 0 : if (xConn.is())
1101 : {
1102 : // ... and the RO-flag simply is implemented by a property
1103 0 : Reference< XPropertySet > xDbProps(xConn->getParent(), UNO_QUERY);
1104 0 : if (xDbProps.is())
1105 : {
1106 0 : Reference< XPropertySetInfo > xInfo = xDbProps->getPropertySetInfo();
1107 0 : if (xInfo->hasPropertyByName(PROPERTY_ISREADONLY))
1108 0 : bDBIsReadOnly = ::comphelper::getBOOL(xDbProps->getPropertyValue(PROPERTY_ISREADONLY));
1109 0 : }
1110 0 : }
1111 : }
1112 0 : return bDBIsReadOnly;
1113 : }
1114 :
1115 : //---------------------------------------------------------------------------------------
1116 0 : void SbaGridControl::MouseButtonDown( const BrowserMouseEvent& rMEvt)
1117 : {
1118 0 : long nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y());
1119 0 : sal_uInt16 nColPos = GetColumnAtXPosPixel(rMEvt.GetPosPixel().X());
1120 0 : sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? (sal_uInt16)-1 : nColPos-1;
1121 : // 'the handle column' and 'no valid column' will both result in a view position of -1 !
1122 :
1123 0 : sal_Bool bHitEmptySpace = (nRow > GetRowCount()) || (nViewPos == (sal_uInt16)-1);
1124 :
1125 0 : if (bHitEmptySpace && (rMEvt.GetClicks() == 2) && rMEvt.IsMod1())
1126 0 : Control::MouseButtonDown(rMEvt);
1127 : else
1128 0 : FmGridControl::MouseButtonDown(rMEvt);
1129 0 : }
1130 :
1131 : //---------------------------------------------------------------------------------------
1132 0 : void SbaGridControl::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
1133 : {
1134 0 : SolarMutexGuard aGuard;
1135 : // in the new DnD API, the solar mutex is not locked when StartDrag get's called
1136 :
1137 0 : sal_Bool bHandled = sal_False;
1138 :
1139 : do
1140 : {
1141 : // determine if dragging is allowed
1142 : // (Yes, this is controller (not view) functionality. But collecting and evaluating all the
1143 : // informations necessary via UNO would be quite difficult (if not impossible) so
1144 : // my laziness says 'do it here' ...)
1145 0 : long nRow = GetRowAtYPosPixel(_rPosPixel.Y());
1146 0 : sal_uInt16 nColPos = GetColumnAtXPosPixel(_rPosPixel.X());
1147 0 : sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? (sal_uInt16)-1 : nColPos-1;
1148 : // 'the handle column' and 'no valid column' will both result in a view position of -1 !
1149 :
1150 0 : sal_Bool bCurrentRowVirtual = IsCurrentAppending() && IsModified();
1151 : // the current row doesn't really exist : the user's appendign a new one and already has entered some data,
1152 : // so the row contains data which has no counter part within the data source
1153 :
1154 0 : long nCorrectRowCount = GetRowCount();
1155 0 : if (GetOptions() & OPT_INSERT)
1156 0 : --nCorrectRowCount; // there is a empty row for inserting records
1157 0 : if (bCurrentRowVirtual)
1158 0 : --nCorrectRowCount;
1159 :
1160 0 : if ((nColPos == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount))
1161 0 : break;
1162 :
1163 0 : sal_Bool bHitHandle = (nColPos == 0);
1164 :
1165 : // check which kind of dragging has to be initiated
1166 0 : if ( bHitHandle // the handle column
1167 : // AND
1168 0 : && ( GetSelectRowCount() // at least one row is selected
1169 : // OR
1170 : || ( (nRow >= 0) // a row below the header
1171 : && !bCurrentRowVirtual // we aren't appending a new record
1172 0 : && (nRow != GetCurrentPos()) // a row which is not the current one
1173 : ) // OR
1174 0 : || ( (0 == GetSelectRowCount()) // no rows selected
1175 : && (-1 == nRow) // hit the header
1176 : )
1177 : )
1178 : )
1179 : { // => start dragging the row
1180 0 : if (GetDataWindow().IsMouseCaptured())
1181 0 : GetDataWindow().ReleaseMouse();
1182 :
1183 0 : if (0 == GetSelectRowCount())
1184 : // no rows selected, but here in this branch
1185 : // -> the user started dragging the upper left corner, which symbolizes the whole table
1186 0 : SelectAll();
1187 :
1188 0 : getMouseEvent().Clear();
1189 0 : DoRowDrag((sal_Int16)nRow);
1190 :
1191 0 : bHandled = sal_True;
1192 : }
1193 0 : else if ( (nRow < 0) // the header
1194 : && (!bHitHandle) // non-handle column
1195 0 : && (nViewPos < GetViewColCount()) // valid (existing) column
1196 : )
1197 : { // => start dragging the column
1198 0 : if (GetDataWindow().IsMouseCaptured())
1199 0 : GetDataWindow().ReleaseMouse();
1200 :
1201 0 : getMouseEvent().Clear();
1202 0 : DoColumnDrag(nViewPos);
1203 :
1204 0 : bHandled = sal_True;
1205 : }
1206 0 : else if ( !bHitHandle // non-handle column
1207 : && (nRow >= 0) // non-header row
1208 : )
1209 : { // => start dragging the field content
1210 0 : if (GetDataWindow().IsMouseCaptured())
1211 0 : GetDataWindow().ReleaseMouse();
1212 :
1213 0 : getMouseEvent().Clear();
1214 0 : DoFieldDrag(nViewPos, (sal_Int16)nRow);
1215 :
1216 0 : bHandled = sal_True;
1217 : }
1218 : }
1219 : while (sal_False);
1220 :
1221 0 : if (!bHandled)
1222 0 : FmGridControl::StartDrag(_nAction, _rPosPixel);
1223 0 : }
1224 :
1225 : //------------------------------------------------------------------------------
1226 0 : void SbaGridControl::Command(const CommandEvent& rEvt)
1227 : {
1228 0 : FmGridControl::Command(rEvt);
1229 0 : }
1230 :
1231 : // -----------------------------------------------------------------------
1232 0 : void SbaGridControl::DoColumnDrag(sal_uInt16 nColumnPos)
1233 : {
1234 0 : Reference< XPropertySet > xDataSource(getDataSource(), UNO_QUERY);
1235 : OSL_ENSURE(xDataSource.is(), "SbaGridControl::DoColumnDrag : invalid data source !");
1236 :
1237 0 : Reference< XPropertySet > xAffectedCol;
1238 0 : Reference< XPropertySet > xAffectedField;
1239 0 : Reference< XConnection > xActiveConnection;
1240 :
1241 : // determine the field to drag
1242 0 : ::rtl::OUString sField;
1243 : try
1244 : {
1245 0 : xActiveConnection = ::dbtools::getConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY));
1246 :
1247 0 : sal_uInt16 nModelPos = GetModelColumnPos(GetColumnIdFromViewPos(nColumnPos));
1248 0 : Reference< XIndexContainer > xCols(GetPeer()->getColumns(), UNO_QUERY);
1249 0 : xAffectedCol.set(xCols->getByIndex(nModelPos),UNO_QUERY);
1250 0 : if (xAffectedCol.is())
1251 : {
1252 0 : xAffectedCol->getPropertyValue(PROPERTY_CONTROLSOURCE) >>= sField;
1253 0 : xAffectedField.set(xAffectedCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
1254 0 : }
1255 : }
1256 0 : catch(Exception&)
1257 : {
1258 : OSL_FAIL("SbaGridControl::DoColumnDrag : something went wrong while getting the column");
1259 : }
1260 0 : if (sField.isEmpty())
1261 0 : return;
1262 :
1263 0 : OColumnTransferable* pDataTransfer = new OColumnTransferable(xDataSource, sField, xAffectedField, xActiveConnection, CTF_FIELD_DESCRIPTOR | CTF_COLUMN_DESCRIPTOR);
1264 0 : Reference< XTransferable > xEnsureDelete = pDataTransfer;
1265 0 : pDataTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1266 : }
1267 :
1268 : // -----------------------------------------------------------------------
1269 0 : void SbaGridControl::CopySelectedRowsToClipboard()
1270 : {
1271 : OSL_ENSURE( GetSelectRowCount() > 0, "SbaGridControl::CopySelectedRowsToClipboard: invalid call!" );
1272 0 : implTransferSelectedRows( (sal_Int16)FirstSelectedRow(), true );
1273 0 : }
1274 :
1275 : // -----------------------------------------------------------------------
1276 0 : void SbaGridControl::DoRowDrag( sal_Int16 nRowPos )
1277 : {
1278 0 : implTransferSelectedRows( nRowPos, false );
1279 0 : }
1280 :
1281 : // -----------------------------------------------------------------------
1282 0 : void SbaGridControl::implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag )
1283 : {
1284 0 : Reference< XPropertySet > xForm( getDataSource(), UNO_QUERY );
1285 : OSL_ENSURE( xForm.is(), "SbaGridControl::implTransferSelectedRows: invalid form!" );
1286 :
1287 : // build the sequence of numbers of selected rows
1288 0 : Sequence< Any > aSelectedRows;
1289 0 : sal_Bool bSelectionBookmarks = sal_True;
1290 :
1291 : // collect the affected rows
1292 0 : if ((GetSelectRowCount() == 0) && (nRowPos >= 0))
1293 : {
1294 0 : aSelectedRows.realloc( 1 );
1295 0 : aSelectedRows[0] <<= (sal_Int32)(nRowPos + 1);
1296 0 : bSelectionBookmarks = sal_False;
1297 : }
1298 0 : else if ( !IsAllSelected() && GetSelectRowCount() )
1299 : {
1300 0 : aSelectedRows = getSelectionBookmarks();
1301 0 : bSelectionBookmarks = sal_True;
1302 : }
1303 :
1304 0 : Reference< XResultSet> xRowSetClone;
1305 : try
1306 : {
1307 0 : ODataClipboard* pTransfer = new ODataClipboard( xForm, aSelectedRows, bSelectionBookmarks, getServiceManager() );
1308 :
1309 0 : Reference< XTransferable > xEnsureDelete = pTransfer;
1310 0 : if ( _bTrueIfClipboardFalseIfDrag )
1311 0 : pTransfer->CopyToClipboard( this );
1312 : else
1313 0 : pTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1314 : }
1315 0 : catch(Exception&)
1316 : {
1317 0 : }
1318 0 : }
1319 :
1320 : // -----------------------------------------------------------------------
1321 0 : void SbaGridControl::DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos)
1322 : {
1323 : // the only thing to do here is dragging the pure cell text
1324 : // the old implementation copied a SBA_FIELDDATAEXCHANGE_FORMAT, too, (which was rather expensive to obtain),
1325 : // but we have no client for this DnD format anymore (the mail part of SO 5.2 was the only client)
1326 :
1327 0 : ::rtl::OUString sCellText;
1328 : try
1329 : {
1330 0 : Reference< XGridFieldDataSupplier > xFieldData(static_cast< XGridPeer* >(GetPeer()), UNO_QUERY);
1331 0 : Sequence<sal_Bool> aSupportingText = xFieldData->queryFieldDataType(::getCppuType(&sCellText));
1332 0 : if (aSupportingText.getConstArray()[nColumnPos])
1333 : {
1334 0 : Sequence< Any> aCellContents = xFieldData->queryFieldData(nRowPos, ::getCppuType(&sCellText));
1335 0 : sCellText = ::comphelper::getString(aCellContents.getConstArray()[nColumnPos]);
1336 0 : ::svt::OStringTransfer::StartStringDrag(sCellText, this, DND_ACTION_COPY);
1337 0 : }
1338 : }
1339 0 : catch(Exception&)
1340 : {
1341 : OSL_FAIL("SbaGridControl::DoFieldDrag : could not retrieve the cell's contents !");
1342 0 : return;
1343 0 : }
1344 :
1345 : }
1346 : /// unary_function Functor object for class ZZ returntype is void
1347 : struct SbaGridControlPrec : ::std::unary_function<DataFlavorExVector::value_type,bool>
1348 : {
1349 : sal_Bool bQueryDrop;
1350 0 : SbaGridControlPrec(sal_Bool _bQueryDrop)
1351 0 : : bQueryDrop(_bQueryDrop)
1352 : {
1353 0 : }
1354 :
1355 0 : inline bool operator()(const DataFlavorExVector::value_type& _aType)
1356 : {
1357 0 : switch (_aType.mnSotId)
1358 : {
1359 : case SOT_FORMATSTR_ID_DBACCESS_TABLE: // table descriptor
1360 : case SOT_FORMATSTR_ID_DBACCESS_QUERY: // query descriptor
1361 : case SOT_FORMATSTR_ID_DBACCESS_COMMAND: // SQL command
1362 0 : return true;
1363 : }
1364 0 : return false;
1365 : }
1366 : };
1367 : //------------------------------------------------------------------------------
1368 0 : sal_Int8 SbaGridControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
1369 : {
1370 0 : sal_Int8 nAction = DND_ACTION_NONE;
1371 :
1372 : // we need a valid connection
1373 0 : if (!::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)).is())
1374 0 : return nAction;
1375 :
1376 0 : if ( IsDropFormatSupported( FORMAT_STRING ) ) do
1377 : { // odd construction, but spares us a lot of (explicit ;) goto's
1378 :
1379 0 : if (!GetEmptyRow().Is())
1380 : // without an empty row we're not in update mode
1381 : break;
1382 :
1383 0 : long nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
1384 0 : sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X(), sal_False);
1385 :
1386 0 : long nCorrectRowCount = GetRowCount();
1387 0 : if (GetOptions() & OPT_INSERT)
1388 0 : --nCorrectRowCount; // there is a empty row for inserting records
1389 0 : if (IsCurrentAppending())
1390 0 : --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1391 :
1392 0 : if ((nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || GetColumnId(nCol) == 0 || GetColumnId(nCol) == BROWSER_INVALIDID )
1393 : // no valid cell under the mouse cursor
1394 : break;
1395 :
1396 0 : Rectangle aRect = GetCellRect(nRow, nCol, sal_False);
1397 0 : if (!aRect.IsInside(rEvt.maPosPixel))
1398 : // not dropped within a cell (a cell isn't as wide as the column - the are small spaces)
1399 : break;
1400 :
1401 0 : if ((IsModified() || (GetCurrentRow().Is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow))
1402 : // there is a current and modified row or cell and he text is to be dropped into another one
1403 : break;
1404 :
1405 0 : CellControllerRef xCurrentController = Controller();
1406 0 : if (xCurrentController.Is() && xCurrentController->IsModified() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId())))
1407 : // the current controller is modified and the user wants to drop in another cell -> no chance
1408 : // (when leaving the modified cell a error may occur - this is deadly while dragging)
1409 : break;
1410 :
1411 0 : Reference< XPropertySet > xField = getField(GetModelColumnPos(nCol));
1412 0 : if (!xField.is())
1413 : // the column is not valid bound (for instance a binary field)
1414 : break;
1415 :
1416 : try
1417 : {
1418 0 : if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY)))
1419 : break;
1420 : }
1421 0 : catch (const Exception& e )
1422 : {
1423 : (void)e; // make compiler happy
1424 : // assume RO
1425 : break;
1426 : }
1427 :
1428 : try
1429 : {
1430 : // assume that text can be dropped into a field if the column has a ::com::sun::star::awt::XTextComponent interface
1431 0 : Reference< XIndexAccess > xColumnControls((::com::sun::star::form::XGridPeer*)GetPeer(), UNO_QUERY);
1432 0 : if (xColumnControls.is())
1433 : {
1434 0 : Reference< ::com::sun::star::awt::XTextComponent > xColControl;
1435 0 : ::cppu::extractInterface(xColControl,xColumnControls->getByIndex(GetViewColumnPos(nCol)));
1436 0 : if (xColControl.is())
1437 : {
1438 0 : m_bActivatingForDrop = sal_True;
1439 0 : GoToRowColumnId(nRow, nCol);
1440 0 : m_bActivatingForDrop = sal_False;
1441 :
1442 0 : nAction = DND_ACTION_COPY;
1443 0 : }
1444 0 : }
1445 : }
1446 0 : catch( const Exception& )
1447 : {
1448 : DBG_UNHANDLED_EXCEPTION();
1449 0 : }
1450 :
1451 : } while (sal_False);
1452 :
1453 0 : if(nAction != DND_ACTION_COPY && GetEmptyRow().Is())
1454 : {
1455 0 : const DataFlavorExVector& _rFlavors = GetDataFlavors();
1456 0 : if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec(sal_True)) != _rFlavors.end())
1457 0 : nAction = DND_ACTION_COPY;
1458 : }
1459 :
1460 0 : return (DND_ACTION_NONE != nAction) ? nAction : FmGridControl::AcceptDrop(rEvt);
1461 : }
1462 :
1463 : //------------------------------------------------------------------------------
1464 0 : sal_Int8 SbaGridControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
1465 : {
1466 : // we need some properties of our data source
1467 0 : Reference< XPropertySet > xDataSource = getDataSource();
1468 0 : if (!xDataSource.is())
1469 0 : return DND_ACTION_NONE;
1470 :
1471 : // we need a valid connection
1472 0 : if (!::dbtools::getConnection(Reference< XRowSet > (xDataSource,UNO_QUERY)).is())
1473 0 : return DND_ACTION_NONE;
1474 :
1475 0 : if ( IsDropFormatSupported( FORMAT_STRING ) )
1476 : {
1477 0 : long nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
1478 0 : sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X(), sal_False);
1479 :
1480 0 : long nCorrectRowCount = GetRowCount();
1481 0 : if (GetOptions() & OPT_INSERT)
1482 0 : --nCorrectRowCount; // there is a empty row for inserting records
1483 0 : if (IsCurrentAppending())
1484 0 : --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1485 :
1486 : OSL_ENSURE((nCol != BROWSER_INVALIDID) && (nRow < nCorrectRowCount), "SbaGridControl::Drop : dropped on an invalid position !");
1487 : // AcceptDrop should have caught this
1488 :
1489 : // from now we work with ids instead of positions
1490 0 : nCol = GetColumnId(nCol);
1491 :
1492 0 : GoToRowColumnId(nRow, nCol);
1493 0 : if (!IsEditing())
1494 0 : ActivateCell();
1495 :
1496 0 : CellControllerRef xCurrentController = Controller();
1497 0 : if (!xCurrentController.Is() || !xCurrentController->ISA(EditCellController))
1498 0 : return DND_ACTION_NONE;
1499 0 : Edit& rEdit = (Edit&)xCurrentController->GetWindow();
1500 :
1501 : // get the dropped string
1502 0 : TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1503 0 : String sDropped;
1504 0 : if ( !aDropped.GetString( FORMAT_STRING, sDropped ) )
1505 0 : return DND_ACTION_NONE;
1506 :
1507 0 : rEdit.SetText( sDropped );
1508 0 : xCurrentController->SetModified();
1509 0 : rEdit.Modify();
1510 : // SetText itself doesn't call a Modify as it isn't a user interaction
1511 :
1512 0 : return DND_ACTION_COPY;
1513 : }
1514 :
1515 0 : if(GetEmptyRow().Is())
1516 : {
1517 0 : const DataFlavorExVector& _rFlavors = GetDataFlavors();
1518 0 : DataFlavorExVector::const_iterator aFind = ::std::find_if(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec(sal_True));
1519 0 : if( aFind != _rFlavors.end())
1520 : {
1521 0 : TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1522 0 : m_aDataDescriptor = ODataAccessObjectTransferable::extractObjectDescriptor(aDropped);
1523 0 : if (m_nAsyncDropEvent)
1524 0 : Application::RemoveUserEvent(m_nAsyncDropEvent);
1525 0 : m_nAsyncDropEvent = Application::PostUserEvent(LINK(this, SbaGridControl, AsynchDropEvent));
1526 0 : return DND_ACTION_COPY;
1527 : }
1528 : }
1529 :
1530 0 : return DND_ACTION_NONE;
1531 : }
1532 :
1533 : //------------------------------------------------------------------------------
1534 0 : Reference< XPropertySet > SbaGridControl::getDataSource() const
1535 : {
1536 0 : Reference< XPropertySet > xReturn;
1537 :
1538 0 : Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
1539 0 : Reference< XPropertySet > xDataSource;
1540 0 : if (xColumns.is())
1541 0 : xReturn = Reference< XPropertySet > (xColumns->getParent(), UNO_QUERY);
1542 :
1543 0 : return xReturn;
1544 : }
1545 : // -----------------------------------------------------------------------------
1546 0 : IMPL_LINK(SbaGridControl, AsynchDropEvent, void*, /*EMPTY_ARG*/)
1547 : {
1548 0 : m_nAsyncDropEvent = 0;
1549 :
1550 0 : Reference< XPropertySet > xDataSource = getDataSource();
1551 0 : if ( xDataSource.is() )
1552 : {
1553 0 : sal_Bool bCountFinal = sal_False;
1554 0 : xDataSource->getPropertyValue(PROPERTY_ISROWCOUNTFINAL) >>= bCountFinal;
1555 0 : if ( !bCountFinal )
1556 0 : setDataSource(NULL); // deattach from grid control
1557 0 : Reference< XResultSetUpdate > xResultSetUpdate(xDataSource,UNO_QUERY);
1558 0 : ODatabaseImportExport* pImExport = new ORowSetImportExport(this,xResultSetUpdate,m_aDataDescriptor,getServiceManager());
1559 0 : Reference<XEventListener> xHolder = pImExport;
1560 0 : Hide();
1561 : try
1562 : {
1563 0 : pImExport->initialize(m_aDataDescriptor);
1564 0 : BeforeDrop();
1565 0 : if(!pImExport->Read())
1566 : {
1567 0 : String sError = String(ModuleRes(STR_NO_COLUMNNAME_MATCHING));
1568 0 : throwGenericSQLException(sError,NULL);
1569 : }
1570 0 : AfterDrop();
1571 0 : Show();
1572 : }
1573 0 : catch(const SQLException& e)
1574 : {
1575 0 : AfterDrop();
1576 0 : Show();
1577 0 : ::dbaui::showError(::dbtools::SQLExceptionInfo(e),this,comphelper::getComponentContext(getServiceManager()));
1578 : }
1579 0 : catch(const Exception& )
1580 : {
1581 0 : AfterDrop();
1582 0 : Show();
1583 : DBG_UNHANDLED_EXCEPTION();
1584 : }
1585 0 : if ( !bCountFinal )
1586 0 : setDataSource(Reference< XRowSet >(xDataSource,UNO_QUERY));
1587 : }
1588 0 : m_aDataDescriptor.clear();
1589 :
1590 0 : return 0L;
1591 : }
1592 : // -------------------------------------------------------------------------
1593 0 : ::rtl::OUString SbaGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
1594 : {
1595 0 : ::rtl::OUString sRet;
1596 0 : if ( ::svt::BBTYPE_BROWSEBOX == eObjType )
1597 : {
1598 0 : SolarMutexGuard aGuard;
1599 0 : sRet = String(ModuleRes(STR_DATASOURCE_GRIDCONTROL_DESC));
1600 : }
1601 : else
1602 0 : sRet = FmGridControl::GetAccessibleObjectDescription( eObjType,_nPosition);
1603 0 : return sRet;
1604 : }
1605 : // -----------------------------------------------------------------------------
1606 0 : void SbaGridControl::DeleteSelectedRows()
1607 : {
1608 0 : FmGridControl::DeleteSelectedRows();
1609 0 : }
1610 :
1611 :
1612 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|