calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / dbaccess / source / ui / browser / sbagrid.cxx
blobc3b52a9cfcc5294a34bafa7f5373e02bbf1e1d6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <core_resource.hxx>
22 #include <sot/exchange.hxx>
24 #include <svx/dbaexchange.hxx>
25 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
27 #include <sbagrid.hxx>
28 #include <dlgsize.hxx>
29 #include <com/sun/star/beans/XPropertyState.hpp>
30 #include <com/sun/star/form/XForm.hpp>
31 #include <com/sun/star/container/XIndexContainer.hpp>
33 #include <com/sun/star/view/XSelectionSupplier.hpp>
34 #include <com/sun/star/awt/XTextComponent.hpp>
35 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
36 #include <comphelper/diagnose_ex.hxx>
38 #include <svl/numuno.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
41 #include <vcl/svapp.hxx>
43 #include <cppuhelper/queryinterface.hxx>
44 #include <connectivity/dbtools.hxx>
45 #include <comphelper/propertyvalue.hxx>
46 #include <comphelper/types.hxx>
47 #include <com/sun/star/sdbc/DataType.hpp>
48 #include <com/sun/star/sdbc/SQLException.hpp>
49 #include <strings.hrc>
50 #include <strings.hxx>
51 #include <dbexchange.hxx>
52 #include <svtools/stringtransfer.hxx>
53 #include <UITools.hxx>
54 #include <TokenWriter.hxx>
55 #include <osl/diagnose.h>
56 #include <algorithm>
58 using namespace ::com::sun::star::ui::dialogs;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::sdb;
61 using namespace ::com::sun::star::sdbc;
62 using namespace ::com::sun::star::sdbcx;
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::container;
65 using namespace ::com::sun::star::datatransfer;
66 using namespace ::com::sun::star::lang;
67 using namespace ::com::sun::star::view;
68 using namespace ::com::sun::star::form;
69 using namespace ::com::sun::star::frame;
70 using namespace ::com::sun::star::util;
71 using namespace ::dbaui;
72 using namespace ::dbtools;
73 using namespace ::svx;
74 using namespace ::svt;
76 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
77 com_sun_star_comp_dbu_SbaXGridControl_get_implementation(
78 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
80 return cppu::acquire(new SbaXGridControl(context));
83 css::uno::Sequence<OUString> SAL_CALL SbaXGridControl::getSupportedServiceNames()
85 return { "com.sun.star.form.control.InteractionGridControl", "com.sun.star.form.control.GridControl",
86 "com.sun.star.awt.UnoControl" };
90 // SbaXGridControl
92 OUString SAL_CALL SbaXGridControl::getImplementationName()
94 return "com.sun.star.comp.dbu.SbaXGridControl";
97 SbaXGridControl::SbaXGridControl(const Reference< XComponentContext >& _rM)
98 : FmXGridControl(_rM)
102 SbaXGridControl::~SbaXGridControl()
106 rtl::Reference<FmXGridPeer> SbaXGridControl::imp_CreatePeer(vcl::Window* pParent)
108 rtl::Reference<FmXGridPeer> pReturn = new SbaXGridPeer(m_xContext);
110 // translate properties into WinBits
111 WinBits nStyle = WB_TABSTOP;
112 Reference< XPropertySet > xModelSet(getModel(), UNO_QUERY);
113 if (xModelSet.is())
117 if (::comphelper::getINT16(xModelSet->getPropertyValue(PROPERTY_BORDER)))
118 nStyle |= WB_BORDER;
120 catch(Exception&)
126 pReturn->Create(pParent, nStyle);
127 return pReturn;
130 Any SAL_CALL SbaXGridControl::queryInterface(const Type& _rType)
132 Any aRet = FmXGridControl::queryInterface(_rType);
133 return aRet.hasValue() ? aRet : ::cppu::queryInterface(_rType,static_cast<css::frame::XDispatch*>(this));
136 Sequence< Type > SAL_CALL SbaXGridControl::getTypes( )
138 return comphelper::concatSequences(
139 FmXGridControl::getTypes(),
140 Sequence { cppu::UnoType<css::frame::XDispatch>::get() });
143 Sequence< sal_Int8 > SAL_CALL SbaXGridControl::getImplementationId( )
145 return css::uno::Sequence<sal_Int8>();
148 void SAL_CALL SbaXGridControl::createPeer(const Reference< css::awt::XToolkit > & rToolkit, const Reference< css::awt::XWindowPeer > & rParentPeer)
150 FmXGridControl::createPeer(rToolkit, rParentPeer);
152 OSL_ENSURE(!mbCreatingPeer, "FmXGridControl::createPeer : recursion!");
153 // see the base class' createPeer for a comment on this
155 // TODO: why the hell this whole class does not use any mutex?
157 Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
158 for (auto const& elem : m_aStatusMultiplexer)
160 if (elem.second.is() && elem.second->getLength())
161 xDisp->addStatusListener(elem.second, elem.first);
165 void SAL_CALL SbaXGridControl::dispatch(const css::util::URL& aURL, const Sequence< PropertyValue >& aArgs)
167 Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
168 if (xDisp.is())
169 xDisp->dispatch(aURL, aArgs);
172 void SAL_CALL SbaXGridControl::addStatusListener( const Reference< XStatusListener > & _rxListener, const URL& _rURL )
174 ::osl::MutexGuard aGuard( GetMutex() );
175 if ( !_rxListener.is() )
176 return;
178 rtl::Reference<SbaXStatusMultiplexer>& xMultiplexer = m_aStatusMultiplexer[ _rURL ];
179 if ( !xMultiplexer.is() )
181 xMultiplexer = new SbaXStatusMultiplexer( *this, GetMutex() );
184 xMultiplexer->addInterface( _rxListener );
185 if ( getPeer().is() )
187 if ( 1 == xMultiplexer->getLength() )
188 { // the first external listener for this URL
189 Reference< XDispatch > xDisp( getPeer(), UNO_QUERY );
190 xDisp->addStatusListener( xMultiplexer, _rURL );
192 else
193 { // already have other listeners for this URL
194 _rxListener->statusChanged( xMultiplexer->getLastEvent() );
199 void SAL_CALL SbaXGridControl::removeStatusListener(const Reference< css::frame::XStatusListener > & _rxListener, const css::util::URL& _rURL)
201 ::osl::MutexGuard aGuard( GetMutex() );
203 rtl::Reference<SbaXStatusMultiplexer>& xMultiplexer = m_aStatusMultiplexer[_rURL];
204 if (!xMultiplexer.is())
206 xMultiplexer = new SbaXStatusMultiplexer(*this,GetMutex());
209 if (getPeer().is() && xMultiplexer->getLength() == 1)
211 Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
212 xDisp->removeStatusListener(xMultiplexer, _rURL);
214 xMultiplexer->removeInterface( _rxListener );
217 void SAL_CALL SbaXGridControl::dispose()
219 SolarMutexGuard aGuard;
221 EventObject aEvt;
222 aEvt.Source = *this;
224 for (auto & elem : m_aStatusMultiplexer)
226 if (elem.second.is())
228 elem.second->disposeAndClear(aEvt);
229 elem.second.clear();
232 StatusMultiplexerArray().swap(m_aStatusMultiplexer);
234 FmXGridControl::dispose();
237 // SbaXGridPeer
238 SbaXGridPeer::SbaXGridPeer(const Reference< XComponentContext >& _rM)
239 : FmXGridPeer(_rM)
240 ,m_aStatusListeners(m_aMutex)
244 SbaXGridPeer::~SbaXGridPeer()
248 void SAL_CALL SbaXGridPeer::dispose()
250 EventObject aEvt(*this);
252 m_aStatusListeners.disposeAndClear(aEvt);
254 FmXGridPeer::dispose();
257 void SbaXGridPeer::NotifyStatusChanged(const css::util::URL& _rUrl, const Reference< css::frame::XStatusListener > & xControl)
259 VclPtr< SbaGridControl > pGrid = GetAs< SbaGridControl >();
260 if (!pGrid)
261 return;
263 css::frame::FeatureStateEvent aEvt;
264 aEvt.Source = *this;
265 aEvt.IsEnabled = !pGrid->IsReadOnlyDB();
266 aEvt.FeatureURL = _rUrl;
268 MapDispatchToBool::const_iterator aURLStatePos = m_aDispatchStates.find( classifyDispatchURL( _rUrl ) );
269 if ( m_aDispatchStates.end() != aURLStatePos )
270 aEvt.State <<= aURLStatePos->second;
271 else
272 aEvt.State <<= false;
274 if (xControl.is())
275 xControl->statusChanged(aEvt);
276 else
278 ::comphelper::OInterfaceContainerHelper3<css::frame::XStatusListener> * pIter
279 = m_aStatusListeners.getContainer(_rUrl);
281 if (pIter)
283 pIter->notifyEach( &XStatusListener::statusChanged, aEvt );
288 Any SAL_CALL SbaXGridPeer::queryInterface(const Type& _rType)
290 Any aRet = ::cppu::queryInterface(_rType,static_cast<css::frame::XDispatch*>(this));
291 if(aRet.hasValue())
292 return aRet;
293 return FmXGridPeer::queryInterface(_rType);
296 Reference< css::frame::XDispatch > SAL_CALL SbaXGridPeer::queryDispatch(const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags)
298 if ( ( aURL.Complete == ".uno:GridSlots/BrowserAttribs" ) || ( aURL.Complete == ".uno:GridSlots/RowHeight" )
299 || ( aURL.Complete == ".uno:GridSlots/ColumnAttribs" ) || ( aURL.Complete == ".uno:GridSlots/ColumnWidth" )
302 return static_cast<css::frame::XDispatch*>(this);
305 return FmXGridPeer::queryDispatch(aURL, aTargetFrameName, nSearchFlags);
308 IMPL_LINK_NOARG( SbaXGridPeer, OnDispatchEvent, void*, void )
310 VclPtr< SbaGridControl > pGrid = GetAs< SbaGridControl >();
311 if ( !pGrid ) // if this fails, we were disposing before arriving here
312 return;
314 if ( !Application::IsMainThread() )
316 // still not in the main thread (see SbaXGridPeer::dispatch). post an event, again
317 // without moving the special even to the back of the queue
318 pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
320 else
322 DispatchArgs aArgs = m_aDispatchArgs.front();
323 m_aDispatchArgs.pop();
325 SbaXGridPeer::dispatch( aArgs.aURL, aArgs.aArgs );
329 SbaXGridPeer::DispatchType SbaXGridPeer::classifyDispatchURL( const URL& _rURL )
331 DispatchType eURLType = dtUnknown;
332 if ( _rURL.Complete == ".uno:GridSlots/BrowserAttribs" )
333 eURLType = dtBrowserAttribs;
334 else if ( _rURL.Complete == ".uno:GridSlots/RowHeight" )
335 eURLType = dtRowHeight;
336 else if ( _rURL.Complete == ".uno:GridSlots/ColumnAttribs" )
337 eURLType = dtColumnAttribs;
338 else if ( _rURL.Complete == ".uno:GridSlots/ColumnWidth" )
339 eURLType = dtColumnWidth;
340 return eURLType;
343 void SAL_CALL SbaXGridPeer::dispatch(const URL& aURL, const Sequence< PropertyValue >& aArgs)
345 VclPtr< SbaGridControl > pGrid = GetAs< SbaGridControl >();
346 if (!pGrid)
347 return;
349 if ( !Application::IsMainThread() )
351 // we're not in the main thread. This is bad, as we want to raise windows here,
352 // and VCL does not like windows to be opened in non-main threads (at least on Win32).
353 // Okay, do this async. No problem with this, as XDispatch::dispatch is defined to be
354 // a one-way method.
356 // save the args
357 DispatchArgs aDispatchArgs;
358 aDispatchArgs.aURL = aURL;
359 aDispatchArgs.aArgs = aArgs;
360 m_aDispatchArgs.push( aDispatchArgs );
362 // post an event
363 // we use the Window::PostUserEvent here, instead of the application::PostUserEvent
364 // this saves us from keeping track of these events - as soon as the window dies,
365 // the events are deleted automatically. For the application way, we would need to
366 // do this ourself.
367 // As we use our grid as window, and the grid dies before we die, this should be no problem.
368 pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
369 return;
372 SolarMutexGuard aGuard;
373 sal_Int16 nColId = -1;
374 for (const PropertyValue& rArg : aArgs)
376 if (rArg.Name == "ColumnViewPos")
378 nColId = pGrid->GetColumnIdFromViewPos(::comphelper::getINT16(rArg.Value));
379 break;
381 if (rArg.Name == "ColumnModelPos")
383 nColId = pGrid->GetColumnIdFromModelPos(::comphelper::getINT16(rArg.Value));
384 break;
386 if (rArg.Name == "ColumnId")
388 nColId = ::comphelper::getINT16(rArg.Value);
389 break;
393 DispatchType eURLType = classifyDispatchURL( aURL );
395 if ( dtUnknown == eURLType )
396 return;
398 // notify any status listeners that the dialog is now active (well, about to be active)
399 MapDispatchToBool::const_iterator aThisURLState = m_aDispatchStates.emplace( eURLType, true ).first;
400 NotifyStatusChanged( aURL, nullptr );
402 // execute the dialog
403 switch ( eURLType )
405 case dtBrowserAttribs:
406 pGrid->SetBrowserAttrs();
407 break;
409 case dtRowHeight:
410 pGrid->SetRowHeight();
411 break;
413 case dtColumnAttribs:
415 OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
416 if (nColId != -1)
417 break;
418 pGrid->SetColAttrs(nColId);
420 break;
422 case dtColumnWidth:
424 OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
425 if (nColId != -1)
426 break;
427 pGrid->SetColWidth(nColId);
429 break;
431 case dtUnknown:
432 break;
435 // notify any status listeners that the dialog vanished
436 m_aDispatchStates.erase( aThisURLState );
437 NotifyStatusChanged( aURL, nullptr );
440 void SAL_CALL SbaXGridPeer::addStatusListener(const Reference< css::frame::XStatusListener > & xControl, const css::util::URL& aURL)
442 ::comphelper::OInterfaceContainerHelper3< css::frame::XStatusListener >* pCont
443 = m_aStatusListeners.getContainer(aURL);
444 if (!pCont)
445 m_aStatusListeners.addInterface(aURL,xControl);
446 else
447 pCont->addInterface(xControl);
448 NotifyStatusChanged(aURL, xControl);
451 void SAL_CALL SbaXGridPeer::removeStatusListener(const Reference< css::frame::XStatusListener > & xControl, const css::util::URL& aURL)
453 ::comphelper::OInterfaceContainerHelper3< css::frame::XStatusListener >* pCont = m_aStatusListeners.getContainer(aURL);
454 if ( pCont )
455 pCont->removeInterface(xControl);
458 Sequence< Type > SAL_CALL SbaXGridPeer::getTypes()
460 return comphelper::concatSequences(
461 FmXGridPeer::getTypes(),
462 Sequence { cppu::UnoType<css::frame::XDispatch>::get() });
465 UNO3_GETIMPLEMENTATION2_IMPL(SbaXGridPeer, FmXGridPeer);
467 VclPtr<FmGridControl> SbaXGridPeer::imp_CreateControl(vcl::Window* pParent, WinBits nStyle)
469 return VclPtr<SbaGridControl>::Create( m_xContext, pParent, this, nStyle);
472 // SbaGridHeader
474 SbaGridHeader::SbaGridHeader(BrowseBox* pParent)
475 :FmGridHeader(pParent, WB_STDHEADERBAR | WB_DRAG)
476 ,DragSourceHelper(this)
480 SbaGridHeader::~SbaGridHeader()
482 disposeOnce();
485 void SbaGridHeader::dispose()
487 DragSourceHelper::dispose();
488 FmGridHeader::dispose();
491 void SbaGridHeader::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
493 SolarMutexGuard aGuard;
494 // in the new DnD API, the solar mutex is not locked when StartDrag is called
496 ImplStartColumnDrag( _nAction, _rPosPixel );
499 void SbaGridHeader::MouseButtonDown( const MouseEvent& _rMEvt )
501 if (_rMEvt.IsLeft())
502 if (_rMEvt.GetClicks() != 2)
504 // the base class will start a column move here, which we don't want to allow
505 // (at the moment. If we store relative positions with the columns, we can allow column moves...)
509 FmGridHeader::MouseButtonDown(_rMEvt);
512 void SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos)
514 sal_uInt16 nId = GetItemId(_rMousePos);
515 bool bResizingCol = false;
516 if (HEADERBAR_ITEM_NOTFOUND != nId)
518 tools::Rectangle aColRect = GetItemRect(nId);
519 aColRect.AdjustLeft(nId ? 3 : 0 ); // the handle col (nId == 0) does not have a left margin for resizing
520 aColRect.AdjustRight( -3 );
521 bResizingCol = !aColRect.Contains(_rMousePos);
523 if (bResizingCol)
524 return;
526 // force the base class to end its drag mode
527 EndTracking(TrackingEventFlags::Cancel | TrackingEventFlags::End);
529 // because we have 3d-buttons the select handler is called from MouseButtonUp, but StartDrag
530 // occurs earlier (while the mouse button is down)
531 // so for optical reasons we select the column before really starting the drag operation.
532 notifyColumnSelect(nId);
534 static_cast<SbaGridControl*>(GetParent())->StartDrag(_nAction,
535 Point(
536 _rMousePos.X() + GetPosPixel().X(), // we aren't left-justified with our parent, in contrast to the data window
537 _rMousePos.Y() - GetSizePixel().Height()
542 void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, weld::Menu& rMenu,
543 weld::Menu& rInsertMenu, weld::Menu& rChangeMenu,
544 weld::Menu& rShowMenu)
546 FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu, rInsertMenu, rChangeMenu, rShowMenu);
548 // some items are valid only if the db isn't readonly
549 bool bDBIsReadOnly = static_cast<SbaGridControl*>(GetParent())->IsReadOnlyDB();
551 if (bDBIsReadOnly)
553 rMenu.set_visible("hide", false);
554 rMenu.set_sensitive("hide", false);
555 rMenu.set_visible("show", false);
556 rMenu.set_sensitive("show", false);
559 // prepend some new items
560 bool bColAttrs = (nColId != sal_uInt16(-1)) && (nColId != 0);
561 if ( !bColAttrs || bDBIsReadOnly)
562 return;
564 sal_uInt16 nPos = 0;
565 sal_uInt16 nModelPos = static_cast<SbaGridControl*>(GetParent())->GetModelColumnPos(nColId);
566 Reference< XPropertySet > xField = static_cast<SbaGridControl*>(GetParent())->getField(nModelPos);
568 if ( xField.is() )
570 switch( ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE)) )
572 case DataType::BINARY:
573 case DataType::VARBINARY:
574 case DataType::LONGVARBINARY:
575 case DataType::SQLNULL:
576 case DataType::OBJECT:
577 case DataType::BLOB:
578 case DataType::CLOB:
579 case DataType::REF:
580 break;
581 default:
582 rMenu.insert(nPos++, "colattrset", DBA_RES(RID_STR_COLUMN_FORMAT),
583 nullptr, nullptr, nullptr, TRISTATE_INDET);
584 rMenu.insert_separator(nPos++, "separator1");
588 rMenu.insert(nPos++, "colwidth", DBA_RES(RID_STR_COLUMN_WIDTH),
589 nullptr, nullptr, nullptr, TRISTATE_INDET);
590 rMenu.insert_separator(nPos++, "separator2");
593 void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const weld::Menu& rMenu, const OString& rExecutionResult)
595 if (rExecutionResult == "colwidth")
596 static_cast<SbaGridControl*>(GetParent())->SetColWidth(nColId);
597 else if (rExecutionResult == "colattrset")
598 static_cast<SbaGridControl*>(GetParent())->SetColAttrs(nColId);
599 else
600 FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, rExecutionResult);
603 // SbaGridControl
604 SbaGridControl::SbaGridControl(Reference< XComponentContext > const & _rM,
605 vcl::Window* pParent, FmXGridPeer* _pPeer, WinBits nBits)
606 :FmGridControl(_rM,pParent, _pPeer, nBits)
607 ,m_pMasterListener(nullptr)
608 ,m_nAsyncDropEvent(nullptr)
609 ,m_bActivatingForDrop(false)
613 SbaGridControl::~SbaGridControl()
615 disposeOnce();
618 void SbaGridControl::dispose()
620 if (m_nAsyncDropEvent)
621 Application::RemoveUserEvent(m_nAsyncDropEvent);
622 m_nAsyncDropEvent = nullptr;
623 FmGridControl::dispose();
626 VclPtr<BrowserHeader> SbaGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
628 return VclPtr<SbaGridHeader>::Create(pParent);
631 CellController* SbaGridControl::GetController(sal_Int32 nRow, sal_uInt16 nCol)
633 if ( m_bActivatingForDrop )
634 return nullptr;
636 return FmGridControl::GetController(nRow, nCol);
639 void SbaGridControl::PreExecuteRowContextMenu(weld::Menu& rMenu)
641 FmGridControl::PreExecuteRowContextMenu(rMenu);
643 sal_uInt16 nPos = 0;
645 if (!IsReadOnlyDB())
647 rMenu.insert(nPos++, "tableattr", DBA_RES(RID_STR_TABLE_FORMAT),
648 nullptr, nullptr, nullptr, TRISTATE_INDET);
649 rMenu.insert(nPos++, "rowheight", DBA_RES(RID_STR_ROW_HEIGHT),
650 nullptr, nullptr, nullptr, TRISTATE_INDET);
651 rMenu.insert_separator(nPos++, "separator1");
654 if ( GetSelectRowCount() > 0 )
656 rMenu.insert(nPos++, "copy", DBA_RES(RID_STR_COPY),
657 nullptr, nullptr, nullptr, TRISTATE_INDET);
658 rMenu.insert_separator(nPos++, "separator2");
662 SvNumberFormatter* SbaGridControl::GetDatasourceFormatter()
664 Reference< css::util::XNumberFormatsSupplier > xSupplier = ::dbtools::getNumberFormats(::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)), true, getContext());
666 SvNumberFormatsSupplierObj* pSupplierImpl = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>( xSupplier );
667 if ( !pSupplierImpl )
668 return nullptr;
670 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
671 return pFormatter;
674 void SbaGridControl::SetColWidth(sal_uInt16 nColId)
676 // get the (UNO) column model
677 sal_uInt16 nModelPos = GetModelColumnPos(nColId);
678 Reference< XIndexAccess > xCols = GetPeer()->getColumns();
679 Reference< XPropertySet > xAffectedCol;
680 if (xCols.is() && (nModelPos != sal_uInt16(-1)))
681 xAffectedCol.set(xCols->getByIndex(nModelPos), css::uno::UNO_QUERY);
683 if (!xAffectedCol.is())
684 return;
686 Any aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
687 sal_Int32 nCurWidth = aWidth.hasValue() ? ::comphelper::getINT32(aWidth) : -1;
689 DlgSize aDlgColWidth(GetFrameWeld(), nCurWidth, false);
690 if (aDlgColWidth.run() != RET_OK)
691 return;
693 sal_Int32 nValue = aDlgColWidth.GetValue();
694 Any aNewWidth;
695 if (-1 == nValue)
696 { // set to default
697 Reference< XPropertyState > xPropState(xAffectedCol, UNO_QUERY);
698 if (xPropState.is())
700 try { aNewWidth = xPropState->getPropertyDefault(PROPERTY_WIDTH); } catch(Exception&) { } ;
703 else
704 aNewWidth <<= nValue;
705 try { xAffectedCol->setPropertyValue(PROPERTY_WIDTH, aNewWidth); } catch(Exception&) { } ;
708 void SbaGridControl::SetRowHeight()
710 Reference< XPropertySet > xCols(GetPeer()->getColumns(), UNO_QUERY);
711 if (!xCols.is())
712 return;
714 Any aHeight = xCols->getPropertyValue(PROPERTY_ROW_HEIGHT);
715 sal_Int32 nCurHeight = aHeight.hasValue() ? ::comphelper::getINT32(aHeight) : -1;
717 DlgSize aDlgRowHeight(GetFrameWeld(), nCurHeight, true);
718 if (aDlgRowHeight.run() != RET_OK)
719 return;
721 sal_Int32 nValue = aDlgRowHeight.GetValue();
722 Any aNewHeight;
723 if (sal_Int16(-1) == nValue)
724 { // set to default
725 Reference< XPropertyState > xPropState(xCols, UNO_QUERY);
726 if (xPropState.is())
730 aNewHeight = xPropState->getPropertyDefault(PROPERTY_ROW_HEIGHT);
732 catch(Exception&)
736 else
737 aNewHeight <<= nValue;
740 xCols->setPropertyValue(PROPERTY_ROW_HEIGHT, aNewHeight);
742 catch(Exception&)
744 TOOLS_WARN_EXCEPTION( "dbaccess", "setPropertyValue: PROPERTY_ROW_HEIGHT throws an exception");
748 void SbaGridControl::SetColAttrs(sal_uInt16 nColId)
750 SvNumberFormatter* pFormatter = GetDatasourceFormatter();
751 if (!pFormatter)
752 return;
754 sal_uInt16 nModelPos = GetModelColumnPos(nColId);
756 // get the (UNO) column model
757 Reference< XIndexAccess > xCols = GetPeer()->getColumns();
758 Reference< XPropertySet > xAffectedCol;
759 if (xCols.is() && (nModelPos != sal_uInt16(-1)))
760 xAffectedCol.set(xCols->getByIndex(nModelPos), css::uno::UNO_QUERY);
762 // get the field the column is bound to
763 Reference< XPropertySet > xField = getField(nModelPos);
764 ::dbaui::callColumnFormatDialog(xAffectedCol,xField,pFormatter,GetFrameWeld());
767 void SbaGridControl::SetBrowserAttrs()
769 Reference< XPropertySet > xGridModel(GetPeer()->getColumns(), UNO_QUERY);
770 if (!xGridModel.is())
771 return;
775 Reference< XComponentContext > xContext = getContext();
776 css::uno::Sequence<css::uno::Any> aArguments{
777 Any(comphelper::makePropertyValue("IntrospectedObject", xGridModel)),
778 Any(comphelper::makePropertyValue("ParentWindow", VCLUnoHelper::GetInterface(this)))
780 Reference<XExecutableDialog> xExecute(xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.form.ControlFontDialog",
781 aArguments, xContext), css::uno::UNO_QUERY_THROW);
782 xExecute->execute();
784 catch( const Exception& )
786 DBG_UNHANDLED_EXCEPTION("dbaccess");
790 void SbaGridControl::PostExecuteRowContextMenu(const OString& rExecutionResult)
792 if (rExecutionResult == "tableattr")
793 SetBrowserAttrs();
794 else if (rExecutionResult == "rowheight")
795 SetRowHeight();
796 else if (rExecutionResult == "copy")
797 CopySelectedRowsToClipboard();
798 else
799 FmGridControl::PostExecuteRowContextMenu(rExecutionResult);
802 void SbaGridControl::Select()
804 // Some selection has changed ...
805 FmGridControl::Select();
807 if (m_pMasterListener)
808 m_pMasterListener->SelectionChanged();
811 void SbaGridControl::ActivateCell(sal_Int32 nRow, sal_uInt16 nCol, bool bSetCellFocus /*= sal_True*/ )
813 FmGridControl::ActivateCell(nRow, nCol, bSetCellFocus);
814 if (m_pMasterListener)
815 m_pMasterListener->CellActivated();
818 void SbaGridControl::DeactivateCell(bool bUpdate /*= sal_True*/)
820 FmGridControl::DeactivateCell(bUpdate);
821 if (m_pMasterListener)
822 m_pMasterListener->CellDeactivated();
825 void SbaGridControl::onRowChange()
827 if ( m_pMasterListener )
828 m_pMasterListener->RowChanged();
831 void SbaGridControl::onColumnChange()
833 if ( m_pMasterListener )
834 m_pMasterListener->ColumnChanged();
837 Reference< XPropertySet > SbaGridControl::getField(sal_uInt16 nModelPos)
839 Reference< XPropertySet > xEmptyReturn;
842 // first get the name of the column
843 Reference< XIndexAccess > xCols = GetPeer()->getColumns();
844 if ( xCols.is() && xCols->getCount() > nModelPos )
846 Reference< XPropertySet > xCol(xCols->getByIndex(nModelPos),UNO_QUERY);
847 if ( xCol.is() )
848 xEmptyReturn.set(xCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
850 else
851 OSL_FAIL("SbaGridControl::getField getColumns returns NULL or ModelPos is > than count!");
853 catch (const Exception&)
855 TOOLS_WARN_EXCEPTION("dbaccess", "SbaGridControl::getField Exception occurred");
858 return xEmptyReturn;
861 bool SbaGridControl::IsReadOnlyDB() const
863 // assume yes if anything fails
864 bool bDBIsReadOnly = true;
868 // the db is the implemented by the parent of the grid control's model ...
869 Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
870 if (xColumns.is())
872 Reference< XRowSet > xDataSource(xColumns->getParent(), UNO_QUERY);
873 ::dbtools::ensureRowSetConnection( xDataSource, getContext(), nullptr );
874 Reference< XChild > xConn(::dbtools::getConnection(xDataSource),UNO_QUERY);
875 if (xConn.is())
877 // ... and the RO-flag simply is implemented by a property
878 Reference< XPropertySet > xDbProps(xConn->getParent(), UNO_QUERY);
879 if (xDbProps.is())
881 Reference< XPropertySetInfo > xInfo = xDbProps->getPropertySetInfo();
882 if (xInfo->hasPropertyByName(PROPERTY_ISREADONLY))
883 bDBIsReadOnly = ::comphelper::getBOOL(xDbProps->getPropertyValue(PROPERTY_ISREADONLY));
888 catch (const Exception&)
890 TOOLS_WARN_EXCEPTION("dbaccess", "SbaGridControl::IsReadOnlyDB Exception occurred");
893 return bDBIsReadOnly;
896 void SbaGridControl::MouseButtonDown( const BrowserMouseEvent& rMEvt)
898 sal_Int32 nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y());
899 sal_uInt16 nColPos = GetColumnAtXPosPixel(rMEvt.GetPosPixel().X());
900 sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : nColPos-1;
901 // 'the handle column' and 'no valid column' will both result in a view position of -1 !
903 bool bHitEmptySpace = (nRow > GetRowCount()) || (nViewPos == sal_uInt16(-1));
905 if (bHitEmptySpace && (rMEvt.GetClicks() == 2) && rMEvt.IsMod1())
906 Control::MouseButtonDown(rMEvt);
907 else
908 FmGridControl::MouseButtonDown(rMEvt);
911 void SbaGridControl::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
913 SolarMutexGuard aGuard;
914 // in the new DnD API, the solar mutex is not locked when StartDrag is called
916 bool bHandled = false;
920 // determine if dragging is allowed
921 // (Yes, this is controller (not view) functionality. But collecting and evaluating all the
922 // information necessary via UNO would be quite difficult (if not impossible) so
923 // my laziness says 'do it here'...)
924 sal_Int32 nRow = GetRowAtYPosPixel(_rPosPixel.Y());
925 sal_uInt16 nColPos = GetColumnAtXPosPixel(_rPosPixel.X());
926 sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : nColPos-1;
927 // 'the handle column' and 'no valid column' will both result in a view position of -1 !
929 bool bCurrentRowVirtual = IsCurrentAppending() && IsModified();
930 // the current row doesn't really exist: the user's appending a new one and already has entered some data,
931 // so the row contains data which has no counter part within the data source
933 sal_Int32 nCorrectRowCount = GetRowCount();
934 if (GetOptions() & DbGridControlOptions::Insert)
935 --nCorrectRowCount; // there is an empty row for inserting records
936 if (bCurrentRowVirtual)
937 --nCorrectRowCount;
939 if ((nColPos == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount))
940 break;
942 bool bHitHandle = (nColPos == 0);
944 // check which kind of dragging has to be initiated
945 if ( bHitHandle // the handle column
946 // AND
947 && ( GetSelectRowCount() // at least one row is selected
948 // OR
949 || ( (nRow >= 0) // a row below the header
950 && !bCurrentRowVirtual // we aren't appending a new record
951 && (nRow != GetCurrentPos()) // a row which is not the current one
952 ) // OR
953 || ( (0 == GetSelectRowCount()) // no rows selected
954 && (-1 == nRow) // hit the header
958 { // => start dragging the row
959 if (GetDataWindow().IsMouseCaptured())
960 GetDataWindow().ReleaseMouse();
962 if (0 == GetSelectRowCount())
963 // no rows selected, but here in this branch
964 // -> the user started dragging the upper left corner, which symbolizes the whole table
965 SelectAll();
967 getMouseEvent().Clear();
968 implTransferSelectedRows(static_cast<sal_Int16>(nRow), false);
970 bHandled = true;
972 else if ( (nRow < 0) // the header
973 && (!bHitHandle) // non-handle column
974 && (nViewPos < GetViewColCount()) // valid (existing) column
976 { // => start dragging the column
977 if (GetDataWindow().IsMouseCaptured())
978 GetDataWindow().ReleaseMouse();
980 getMouseEvent().Clear();
981 DoColumnDrag(nViewPos);
983 bHandled = true;
985 else if ( !bHitHandle // non-handle column
986 && (nRow >= 0) // non-header row
988 { // => start dragging the field content
989 if (GetDataWindow().IsMouseCaptured())
990 GetDataWindow().ReleaseMouse();
992 getMouseEvent().Clear();
993 DoFieldDrag(nViewPos, static_cast<sal_Int16>(nRow));
995 bHandled = true;
998 while (false);
1000 if (!bHandled)
1001 FmGridControl::StartDrag(_nAction, _rPosPixel);
1004 void SbaGridControl::DoColumnDrag(sal_uInt16 nColumnPos)
1006 Reference< XPropertySet > xDataSource = getDataSource();
1007 OSL_ENSURE(xDataSource.is(), "SbaGridControl::DoColumnDrag : invalid data source !");
1008 ::dbtools::ensureRowSetConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY), getContext(), nullptr);
1010 Reference< XPropertySet > xAffectedCol;
1011 Reference< XPropertySet > xAffectedField;
1012 Reference< XConnection > xActiveConnection;
1014 // determine the field to drag
1015 OUString sField;
1018 xActiveConnection = ::dbtools::getConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY));
1020 sal_uInt16 nModelPos = GetModelColumnPos(GetColumnIdFromViewPos(nColumnPos));
1021 Reference< XIndexContainer > xCols = GetPeer()->getColumns();
1022 xAffectedCol.set(xCols->getByIndex(nModelPos),UNO_QUERY);
1023 if (xAffectedCol.is())
1025 xAffectedCol->getPropertyValue(PROPERTY_CONTROLSOURCE) >>= sField;
1026 xAffectedField.set(xAffectedCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
1029 catch(Exception&)
1031 OSL_FAIL("SbaGridControl::DoColumnDrag : something went wrong while getting the column");
1033 if (sField.isEmpty())
1034 return;
1036 rtl::Reference<OColumnTransferable> pDataTransfer = new OColumnTransferable(xDataSource, sField, xAffectedField, xActiveConnection, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR);
1037 pDataTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1040 void SbaGridControl::CopySelectedRowsToClipboard()
1042 OSL_ENSURE( GetSelectRowCount() > 0, "SbaGridControl::CopySelectedRowsToClipboard: invalid call!" );
1043 implTransferSelectedRows( static_cast<sal_Int16>(FirstSelectedRow()), true );
1046 void SbaGridControl::implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag )
1048 Reference< XPropertySet > xForm = getDataSource();
1049 OSL_ENSURE( xForm.is(), "SbaGridControl::implTransferSelectedRows: invalid form!" );
1051 // build the sequence of numbers of selected rows
1052 Sequence< Any > aSelectedRows;
1053 bool bSelectionBookmarks = true;
1055 // collect the affected rows
1056 if ((GetSelectRowCount() == 0) && (nRowPos >= 0))
1058 aSelectedRows = { Any(static_cast<sal_Int32>(nRowPos + 1)) };
1059 bSelectionBookmarks = false;
1061 else if ( !IsAllSelected() && GetSelectRowCount() )
1063 aSelectedRows = getSelectionBookmarks();
1064 bSelectionBookmarks = true;
1069 rtl::Reference<ODataClipboard> pTransfer = new ODataClipboard( xForm, aSelectedRows, bSelectionBookmarks, getContext() );
1071 if ( _bTrueIfClipboardFalseIfDrag )
1072 pTransfer->CopyToClipboard( this );
1073 else
1074 pTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1076 catch(Exception&)
1081 void SbaGridControl::DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos)
1083 // the only thing to do here is dragging the pure cell text
1084 // the old implementation copied a SBA_FIELDDATAEXCHANGE_FORMAT, too, (which was rather expensive to obtain),
1085 // but we have no client for this DnD format anymore (the mail part of SO 5.2 was the only client)
1089 OUString sCellText;
1090 Reference< XGridFieldDataSupplier > xFieldData(GetPeer());
1091 Sequence<sal_Bool> aSupportingText = xFieldData->queryFieldDataType(cppu::UnoType<decltype(sCellText)>::get());
1092 if (aSupportingText.getConstArray()[nColumnPos])
1094 Sequence< Any> aCellContents = xFieldData->queryFieldData(nRowPos, cppu::UnoType<decltype(sCellText)>::get());
1095 sCellText = ::comphelper::getString(aCellContents.getConstArray()[nColumnPos]);
1096 ::svt::OStringTransfer::StartStringDrag(sCellText, this, DND_ACTION_COPY);
1099 catch(Exception&)
1101 OSL_FAIL("SbaGridControl::DoFieldDrag : could not retrieve the cell's contents !");
1102 return;
1107 namespace {
1109 /// unary_function Functor object for class ZZ returntype is void
1110 struct SbaGridControlPrec
1112 bool operator()(const DataFlavorExVector::value_type& _aType)
1114 switch (_aType.mnSotId)
1116 case SotClipboardFormatId::DBACCESS_TABLE: // table descriptor
1117 case SotClipboardFormatId::DBACCESS_QUERY: // query descriptor
1118 case SotClipboardFormatId::DBACCESS_COMMAND: // SQL command
1119 return true;
1120 default: break;
1122 return false;
1128 sal_Int8 SbaGridControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
1130 sal_Int8 nAction = DND_ACTION_NONE;
1132 // we need a valid connection
1133 if (!::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)).is())
1134 return nAction;
1136 if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) )
1138 { // odd construction, but spares us a lot of (explicit ;) goto's
1140 if (!GetEmptyRow().is())
1141 // without an empty row we're not in update mode
1142 break;
1144 const sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false);
1145 const sal_uInt16 nCol = GetColumnId(GetColumnAtXPosPixel(rEvt.maPosPixel.X()));
1147 sal_Int32 nCorrectRowCount = GetRowCount();
1148 if (GetOptions() & DbGridControlOptions::Insert)
1149 --nCorrectRowCount; // there is an empty row for inserting records
1150 if (IsCurrentAppending())
1151 --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1153 if ( (nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || (nCol == 0) )
1154 // no valid cell under the mouse cursor
1155 break;
1157 tools::Rectangle aRect = GetCellRect(nRow, nCol, false);
1158 if (!aRect.Contains(rEvt.maPosPixel))
1159 // not dropped within a cell (a cell isn't as wide as the column - the are small spaces)
1160 break;
1162 if ((IsModified() || (GetCurrentRow().is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow))
1163 // there is a current and modified row or cell and he text is to be dropped into another one
1164 break;
1166 CellControllerRef xCurrentController = Controller();
1167 if (xCurrentController.is() && xCurrentController->IsValueChangedFromSaved() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId())))
1168 // the current controller is modified and the user wants to drop in another cell -> no chance
1169 // (when leaving the modified cell an error may occur - this is deadly while dragging)
1170 break;
1172 Reference< XPropertySet > xField = getField(GetModelColumnPos(nCol));
1173 if (!xField.is())
1174 // the column is not valid bound (for instance a binary field)
1175 break;
1179 if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY)))
1180 break;
1182 catch (const Exception& )
1184 // assume RO
1185 break;
1190 // assume that text can be dropped into a field if the column has a css::awt::XTextComponent interface
1191 Reference< XIndexAccess > xColumnControls(GetPeer());
1192 if (xColumnControls.is())
1194 Reference< css::awt::XTextComponent > xColControl(
1195 xColumnControls->getByIndex(GetViewColumnPos(nCol)),
1196 css::uno::UNO_QUERY);
1197 if (xColControl.is())
1199 m_bActivatingForDrop = true;
1200 GoToRowColumnId(nRow, nCol);
1201 m_bActivatingForDrop = false;
1203 nAction = DND_ACTION_COPY;
1207 catch( const Exception& )
1209 DBG_UNHANDLED_EXCEPTION("dbaccess");
1212 } while (false);
1214 if(nAction != DND_ACTION_COPY && GetEmptyRow().is())
1216 const DataFlavorExVector& _rFlavors = GetDataFlavors();
1217 if(std::any_of(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec()))
1218 nAction = DND_ACTION_COPY;
1221 return (DND_ACTION_NONE != nAction) ? nAction : FmGridControl::AcceptDrop(rEvt);
1224 sal_Int8 SbaGridControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
1226 // we need some properties of our data source
1227 Reference< XPropertySet > xDataSource = getDataSource();
1228 if (!xDataSource.is())
1229 return DND_ACTION_NONE;
1231 // we need a valid connection
1232 if (!::dbtools::getConnection(Reference< XRowSet > (xDataSource,UNO_QUERY)).is())
1233 return DND_ACTION_NONE;
1235 if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) )
1237 sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false);
1238 sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X());
1240 sal_Int32 nCorrectRowCount = GetRowCount();
1241 if (GetOptions() & DbGridControlOptions::Insert)
1242 --nCorrectRowCount; // there is an empty row for inserting records
1243 if (IsCurrentAppending())
1244 --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1246 OSL_ENSURE((nCol != BROWSER_INVALIDID) && (nRow < nCorrectRowCount), "SbaGridControl::Drop : dropped on an invalid position !");
1247 // AcceptDrop should have caught this
1249 // from now we work with ids instead of positions
1250 nCol = GetColumnId(nCol);
1252 GoToRowColumnId(nRow, nCol);
1253 if (!IsEditing())
1254 ActivateCell();
1256 CellControllerRef xCurrentController = Controller();
1257 EditCellController* pController = dynamic_cast<EditCellController*>(xCurrentController.get());
1258 if (!pController)
1259 return DND_ACTION_NONE;
1261 // get the dropped string
1262 TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1263 OUString sDropped;
1264 if ( !aDropped.GetString( SotClipboardFormatId::STRING, sDropped ) )
1265 return DND_ACTION_NONE;
1267 IEditImplementation* pEditImplementation = pController->GetEditImplementation();
1268 pEditImplementation->SetText(sDropped);
1269 // SetText itself doesn't call a Modify as it isn't a user interaction
1270 pController->Modify();
1272 return DND_ACTION_COPY;
1275 if(GetEmptyRow().is())
1277 const DataFlavorExVector& _rFlavors = GetDataFlavors();
1278 if( std::any_of(_rFlavors.begin(),_rFlavors.end(), SbaGridControlPrec()) )
1280 TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1281 m_aDataDescriptor = ODataAccessObjectTransferable::extractObjectDescriptor(aDropped);
1282 if (m_nAsyncDropEvent)
1283 Application::RemoveUserEvent(m_nAsyncDropEvent);
1284 m_nAsyncDropEvent = Application::PostUserEvent(LINK(this, SbaGridControl, AsynchDropEvent), nullptr, true);
1285 return DND_ACTION_COPY;
1289 return DND_ACTION_NONE;
1292 Reference< XPropertySet > SbaGridControl::getDataSource() const
1294 Reference< XPropertySet > xReturn;
1296 Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
1297 if (xColumns.is())
1298 xReturn.set(xColumns->getParent(), UNO_QUERY);
1300 return xReturn;
1303 IMPL_LINK_NOARG(SbaGridControl, AsynchDropEvent, void*, void)
1305 m_nAsyncDropEvent = nullptr;
1307 Reference< XPropertySet > xDataSource = getDataSource();
1308 if ( xDataSource.is() )
1310 bool bCountFinal = false;
1311 xDataSource->getPropertyValue(PROPERTY_ISROWCOUNTFINAL) >>= bCountFinal;
1312 if ( !bCountFinal )
1313 setDataSource(nullptr); // detach from grid control
1314 Reference< XResultSetUpdate > xResultSetUpdate(xDataSource,UNO_QUERY);
1315 rtl::Reference<ODatabaseImportExport> pImExport = new ORowSetImportExport(GetFrameWeld(),xResultSetUpdate,m_aDataDescriptor, getContext());
1316 Hide();
1319 pImExport->initialize(m_aDataDescriptor);
1320 if (m_pMasterListener)
1321 m_pMasterListener->BeforeDrop();
1322 if(!pImExport->Read())
1324 OUString sError = DBA_RES(STR_NO_COLUMNNAME_MATCHING);
1325 throwGenericSQLException(sError,nullptr);
1327 if (m_pMasterListener)
1328 m_pMasterListener->AfterDrop();
1329 Show();
1331 catch(const SQLException& e)
1333 if (m_pMasterListener)
1334 m_pMasterListener->AfterDrop();
1335 Show();
1336 ::dbtools::showError( ::dbtools::SQLExceptionInfo(e), VCLUnoHelper::GetInterface(this), getContext() );
1338 catch(const Exception& )
1340 DBG_UNHANDLED_EXCEPTION("dbaccess");
1341 if (m_pMasterListener)
1342 m_pMasterListener->AfterDrop();
1343 Show();
1345 if ( !bCountFinal )
1346 setDataSource(Reference< XRowSet >(xDataSource,UNO_QUERY));
1348 m_aDataDescriptor.clear();
1351 OUString SbaGridControl::GetAccessibleObjectDescription( AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
1353 OUString sRet;
1354 if ( AccessibleBrowseBoxObjType::BrowseBox == eObjType )
1356 SolarMutexGuard aGuard;
1357 sRet = DBA_RES(STR_DATASOURCE_GRIDCONTROL_DESC);
1359 else
1360 sRet = FmGridControl::GetAccessibleObjectDescription( eObjType,_nPosition);
1361 return sRet;
1364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */