tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / ui / browser / sbagrid.cxx
blob58017ff4c24c7781095cd03ded9068655343fdd7
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::beans;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::datatransfer;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::form;
67 using namespace ::com::sun::star::frame;
68 using namespace ::com::sun::star::util;
69 using namespace ::dbaui;
70 using namespace ::dbtools;
71 using namespace ::svx;
72 using namespace ::svt;
74 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
75 com_sun_star_comp_dbu_SbaXGridControl_get_implementation(
76 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
78 return cppu::acquire(new SbaXGridControl(context));
81 css::uno::Sequence<OUString> SAL_CALL SbaXGridControl::getSupportedServiceNames()
83 return { u"com.sun.star.form.control.InteractionGridControl"_ustr, u"com.sun.star.form.control.GridControl"_ustr,
84 u"com.sun.star.awt.UnoControl"_ustr };
88 // SbaXGridControl
90 OUString SAL_CALL SbaXGridControl::getImplementationName()
92 return u"com.sun.star.comp.dbu.SbaXGridControl"_ustr;
95 SbaXGridControl::SbaXGridControl(const Reference< XComponentContext >& _rM)
96 : FmXGridControl(_rM)
100 SbaXGridControl::~SbaXGridControl()
104 rtl::Reference<FmXGridPeer> SbaXGridControl::imp_CreatePeer(vcl::Window* pParent)
106 rtl::Reference<FmXGridPeer> pReturn = new SbaXGridPeer(m_xContext);
108 // translate properties into WinBits
109 WinBits nStyle = WB_TABSTOP;
110 Reference< XPropertySet > xModelSet(getModel(), UNO_QUERY);
111 if (xModelSet.is())
115 if (::comphelper::getINT16(xModelSet->getPropertyValue(PROPERTY_BORDER)))
116 nStyle |= WB_BORDER;
118 catch(Exception&)
124 pReturn->Create(pParent, nStyle);
125 return pReturn;
128 Any SAL_CALL SbaXGridControl::queryAggregation(const Type& _rType)
130 Any aRet = FmXGridControl::queryAggregation(_rType);
131 return aRet.hasValue() ? aRet : ::cppu::queryInterface(_rType,static_cast<css::frame::XDispatch*>(this));
134 Sequence< Type > SAL_CALL SbaXGridControl::getTypes( )
136 return comphelper::concatSequences(
137 FmXGridControl::getTypes(),
138 Sequence { cppu::UnoType<css::frame::XDispatch>::get() });
141 Sequence< sal_Int8 > SAL_CALL SbaXGridControl::getImplementationId( )
143 return css::uno::Sequence<sal_Int8>();
146 void SAL_CALL SbaXGridControl::createPeer(const Reference< css::awt::XToolkit > & rToolkit, const Reference< css::awt::XWindowPeer > & rParentPeer)
148 FmXGridControl::createPeer(rToolkit, rParentPeer);
150 OSL_ENSURE(!mbCreatingPeer, "FmXGridControl::createPeer : recursion!");
151 // see the base class' createPeer for a comment on this
153 // TODO: why the hell this whole class does not use any mutex?
155 Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
156 for (auto const& elem : m_aStatusMultiplexer)
158 if (elem.second.is() && elem.second->getLength())
159 xDisp->addStatusListener(elem.second, elem.first);
163 void SAL_CALL SbaXGridControl::dispatch(const css::util::URL& aURL, const Sequence< PropertyValue >& aArgs)
165 Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
166 if (xDisp.is())
167 xDisp->dispatch(aURL, aArgs);
170 void SAL_CALL SbaXGridControl::addStatusListener( const Reference< XStatusListener > & _rxListener, const URL& _rURL )
172 ::osl::MutexGuard aGuard( GetMutex() );
173 if ( !_rxListener.is() )
174 return;
176 rtl::Reference<SbaXStatusMultiplexer>& xMultiplexer = m_aStatusMultiplexer[ _rURL ];
177 if ( !xMultiplexer.is() )
179 xMultiplexer = new SbaXStatusMultiplexer( *this, GetMutex() );
182 xMultiplexer->addInterface( _rxListener );
183 if ( getPeer().is() )
185 if ( 1 == xMultiplexer->getLength() )
186 { // the first external listener for this URL
187 Reference< XDispatch > xDisp( getPeer(), UNO_QUERY );
188 xDisp->addStatusListener( xMultiplexer, _rURL );
190 else
191 { // already have other listeners for this URL
192 _rxListener->statusChanged( xMultiplexer->getLastEvent() );
197 void SAL_CALL SbaXGridControl::removeStatusListener(const Reference< css::frame::XStatusListener > & _rxListener, const css::util::URL& _rURL)
199 ::osl::MutexGuard aGuard( GetMutex() );
201 rtl::Reference<SbaXStatusMultiplexer>& xMultiplexer = m_aStatusMultiplexer[_rURL];
202 if (!xMultiplexer.is())
204 xMultiplexer = new SbaXStatusMultiplexer(*this,GetMutex());
207 if (getPeer().is() && xMultiplexer->getLength() == 1)
209 Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
210 xDisp->removeStatusListener(xMultiplexer, _rURL);
212 xMultiplexer->removeInterface( _rxListener );
215 void SAL_CALL SbaXGridControl::dispose()
217 SolarMutexGuard aGuard;
219 EventObject aEvt;
220 aEvt.Source = *this;
222 for (auto & elem : m_aStatusMultiplexer)
224 if (elem.second.is())
226 elem.second->disposeAndClear(aEvt);
227 elem.second.clear();
230 StatusMultiplexerArray().swap(m_aStatusMultiplexer);
232 FmXGridControl::dispose();
235 // SbaXGridPeer
236 SbaXGridPeer::SbaXGridPeer(const Reference< XComponentContext >& _rM)
237 : FmXGridPeer(_rM)
241 SbaXGridPeer::~SbaXGridPeer()
245 void SAL_CALL SbaXGridPeer::dispose()
248 std::unique_lock g(m_aMutex);
249 EventObject aEvt(*this);
250 m_aStatusListeners.disposeAndClear(g, aEvt);
252 FmXGridPeer::dispose();
255 void SbaXGridPeer::NotifyStatusChanged(const css::util::URL& _rUrl, const Reference< css::frame::XStatusListener > & xControl)
257 VclPtr< SbaGridControl > pGrid = GetAs< SbaGridControl >();
258 if (!pGrid)
259 return;
261 css::frame::FeatureStateEvent aEvt;
262 aEvt.Source = *this;
263 aEvt.IsEnabled = !pGrid->IsReadOnlyDB();
264 aEvt.FeatureURL = _rUrl;
266 MapDispatchToBool::const_iterator aURLStatePos = m_aDispatchStates.find( classifyDispatchURL( _rUrl ) );
267 if ( m_aDispatchStates.end() != aURLStatePos )
268 aEvt.State <<= aURLStatePos->second;
269 else
270 aEvt.State <<= false;
272 if (xControl.is())
273 xControl->statusChanged(aEvt);
274 else
276 std::unique_lock g(m_aMutex);
277 ::comphelper::OInterfaceContainerHelper4<css::frame::XStatusListener> * pIter
278 = m_aStatusListeners.getContainer(g, _rUrl);
280 if (pIter)
282 pIter->notifyEach( g, &XStatusListener::statusChanged, aEvt );
287 Any SAL_CALL SbaXGridPeer::queryInterface(const Type& _rType)
289 Any aRet = ::cppu::queryInterface(_rType,static_cast<css::frame::XDispatch*>(this));
290 if(aRet.hasValue())
291 return aRet;
292 return FmXGridPeer::queryInterface(_rType);
295 Reference< css::frame::XDispatch > SAL_CALL SbaXGridPeer::queryDispatch(const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags)
297 if ( ( aURL.Complete == ".uno:GridSlots/BrowserAttribs" ) || ( aURL.Complete == ".uno:GridSlots/RowHeight" )
298 || ( aURL.Complete == ".uno:GridSlots/ColumnAttribs" ) || ( aURL.Complete == ".uno:GridSlots/ColumnWidth" )
301 return static_cast<css::frame::XDispatch*>(this);
304 return FmXGridPeer::queryDispatch(aURL, aTargetFrameName, nSearchFlags);
307 IMPL_LINK_NOARG( SbaXGridPeer, OnDispatchEvent, void*, void )
309 VclPtr< SbaGridControl > pGrid = GetAs< SbaGridControl >();
310 if ( !pGrid ) // if this fails, we were disposing before arriving here
311 return;
313 if ( !Application::IsMainThread() )
315 // still not in the main thread (see SbaXGridPeer::dispatch). post an event, again
316 // without moving the special even to the back of the queue
317 pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
319 else
321 DispatchArgs aArgs = m_aDispatchArgs.front();
322 m_aDispatchArgs.pop();
324 SbaXGridPeer::dispatch( aArgs.aURL, aArgs.aArgs );
328 SbaXGridPeer::DispatchType SbaXGridPeer::classifyDispatchURL( const URL& _rURL )
330 DispatchType eURLType = dtUnknown;
331 if ( _rURL.Complete == ".uno:GridSlots/BrowserAttribs" )
332 eURLType = dtBrowserAttribs;
333 else if ( _rURL.Complete == ".uno:GridSlots/RowHeight" )
334 eURLType = dtRowHeight;
335 else if ( _rURL.Complete == ".uno:GridSlots/ColumnAttribs" )
336 eURLType = dtColumnAttribs;
337 else if ( _rURL.Complete == ".uno:GridSlots/ColumnWidth" )
338 eURLType = dtColumnWidth;
339 return eURLType;
342 void SAL_CALL SbaXGridPeer::dispatch(const URL& aURL, const Sequence< PropertyValue >& aArgs)
344 VclPtr< SbaGridControl > pGrid = GetAs< SbaGridControl >();
345 if (!pGrid)
346 return;
348 if ( !Application::IsMainThread() )
350 // we're not in the main thread. This is bad, as we want to raise windows here,
351 // and VCL does not like windows to be opened in non-main threads (at least on Win32).
352 // Okay, do this async. No problem with this, as XDispatch::dispatch is defined to be
353 // a one-way method.
355 // save the args
356 DispatchArgs aDispatchArgs;
357 aDispatchArgs.aURL = aURL;
358 aDispatchArgs.aArgs = aArgs;
359 m_aDispatchArgs.push( aDispatchArgs );
361 // post an event
362 // we use the Window::PostUserEvent here, instead of the application::PostUserEvent
363 // this saves us from keeping track of these events - as soon as the window dies,
364 // the events are deleted automatically. For the application way, we would need to
365 // do this ourself.
366 // As we use our grid as window, and the grid dies before we die, this should be no problem.
367 pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
368 return;
371 SolarMutexGuard aGuard;
372 sal_Int16 nColId = -1;
373 for (const PropertyValue& rArg : aArgs)
375 if (rArg.Name == "ColumnViewPos")
377 nColId = pGrid->GetColumnIdFromViewPos(::comphelper::getINT16(rArg.Value));
378 break;
380 if (rArg.Name == "ColumnModelPos")
382 nColId = pGrid->GetColumnIdFromModelPos(::comphelper::getINT16(rArg.Value));
383 break;
385 if (rArg.Name == "ColumnId")
387 nColId = ::comphelper::getINT16(rArg.Value);
388 break;
392 DispatchType eURLType = classifyDispatchURL( aURL );
394 if ( dtUnknown == eURLType )
395 return;
397 // notify any status listeners that the dialog is now active (well, about to be active)
398 MapDispatchToBool::const_iterator aThisURLState = m_aDispatchStates.emplace( eURLType, true ).first;
399 NotifyStatusChanged( aURL, nullptr );
401 // execute the dialog
402 switch ( eURLType )
404 case dtBrowserAttribs:
405 pGrid->SetBrowserAttrs();
406 break;
408 case dtRowHeight:
409 pGrid->SetRowHeight();
410 break;
412 case dtColumnAttribs:
414 OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
415 if (nColId != -1)
416 break;
417 pGrid->SetColAttrs(nColId);
419 break;
421 case dtColumnWidth:
423 OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
424 if (nColId != -1)
425 break;
426 pGrid->SetColWidth(nColId);
428 break;
430 case dtUnknown:
431 break;
434 // notify any status listeners that the dialog vanished
435 m_aDispatchStates.erase( aThisURLState );
436 NotifyStatusChanged( aURL, nullptr );
439 void SAL_CALL SbaXGridPeer::addStatusListener(const Reference< css::frame::XStatusListener > & xControl, const css::util::URL& aURL)
442 std::unique_lock g(m_aMutex);
443 ::comphelper::OInterfaceContainerHelper4< css::frame::XStatusListener >* pCont
444 = m_aStatusListeners.getContainer(g, aURL);
445 if (!pCont)
446 m_aStatusListeners.addInterface(g, aURL,xControl);
447 else
448 pCont->addInterface(g, xControl);
450 NotifyStatusChanged(aURL, xControl);
453 void SAL_CALL SbaXGridPeer::removeStatusListener(const Reference< css::frame::XStatusListener > & xControl, const css::util::URL& aURL)
455 std::unique_lock g(m_aMutex);
456 ::comphelper::OInterfaceContainerHelper4< css::frame::XStatusListener >* pCont = m_aStatusListeners.getContainer(g, aURL);
457 if ( pCont )
458 pCont->removeInterface(g, xControl);
461 Sequence< Type > SAL_CALL SbaXGridPeer::getTypes()
463 return comphelper::concatSequences(
464 FmXGridPeer::getTypes(),
465 Sequence { cppu::UnoType<css::frame::XDispatch>::get() });
468 VclPtr<FmGridControl> SbaXGridPeer::imp_CreateControl(vcl::Window* pParent, WinBits nStyle)
470 return VclPtr<SbaGridControl>::Create( m_xContext, pParent, this, nStyle);
473 // SbaGridHeader
475 SbaGridHeader::SbaGridHeader(BrowseBox* pParent)
476 :FmGridHeader(pParent, WB_STDHEADERBAR | WB_DRAG)
477 ,DragSourceHelper(this)
481 SbaGridHeader::~SbaGridHeader()
483 disposeOnce();
486 void SbaGridHeader::dispose()
488 DragSourceHelper::dispose();
489 FmGridHeader::dispose();
492 void SbaGridHeader::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
494 SolarMutexGuard aGuard;
495 // in the new DnD API, the solar mutex is not locked when StartDrag is called
497 ImplStartColumnDrag( _nAction, _rPosPixel );
500 void SbaGridHeader::MouseButtonDown( const MouseEvent& _rMEvt )
502 if (_rMEvt.IsLeft())
503 if (_rMEvt.GetClicks() != 2)
505 // the base class will start a column move here, which we don't want to allow
506 // (at the moment. If we store relative positions with the columns, we can allow column moves...)
510 FmGridHeader::MouseButtonDown(_rMEvt);
513 void SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos)
515 sal_uInt16 nId = GetItemId(_rMousePos);
516 bool bResizingCol = false;
517 if (HEADERBAR_ITEM_NOTFOUND != nId)
519 tools::Rectangle aColRect = GetItemRect(nId);
520 aColRect.AdjustLeft(nId ? 3 : 0 ); // the handle col (nId == 0) does not have a left margin for resizing
521 aColRect.AdjustRight( -3 );
522 bResizingCol = !aColRect.Contains(_rMousePos);
524 if (bResizingCol)
525 return;
527 // force the base class to end its drag mode
528 EndTracking(TrackingEventFlags::Cancel | TrackingEventFlags::End);
530 // because we have 3d-buttons the select handler is called from MouseButtonUp, but StartDrag
531 // occurs earlier (while the mouse button is down)
532 // so for optical reasons we select the column before really starting the drag operation.
533 notifyColumnSelect(nId);
535 static_cast<SbaGridControl*>(GetParent())->StartDrag(_nAction,
536 Point(
537 _rMousePos.X() + GetPosPixel().X(), // we aren't left-justified with our parent, in contrast to the data window
538 _rMousePos.Y() - GetSizePixel().Height()
543 void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, weld::Menu& rMenu,
544 weld::Menu& rInsertMenu, weld::Menu& rChangeMenu,
545 weld::Menu& rShowMenu)
547 FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu, rInsertMenu, rChangeMenu, rShowMenu);
549 // some items are valid only if the db isn't readonly
550 bool bDBIsReadOnly = static_cast<SbaGridControl*>(GetParent())->IsReadOnlyDB();
552 if (bDBIsReadOnly)
554 rMenu.set_visible(u"hide"_ustr, false);
555 rMenu.set_sensitive(u"hide"_ustr, false);
556 rMenu.set_visible(u"show"_ustr, false);
557 rMenu.set_sensitive(u"show"_ustr, false);
560 // prepend some new items
561 bool bColAttrs = (nColId != sal_uInt16(-1)) && (nColId != 0);
562 if ( !bColAttrs || bDBIsReadOnly)
563 return;
565 sal_uInt16 nPos = 0;
566 sal_uInt16 nModelPos = static_cast<SbaGridControl*>(GetParent())->GetModelColumnPos(nColId);
567 Reference< XPropertySet > xField = static_cast<SbaGridControl*>(GetParent())->getField(nModelPos);
569 if ( xField.is() )
571 switch( ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE)) )
573 case DataType::BINARY:
574 case DataType::VARBINARY:
575 case DataType::LONGVARBINARY:
576 case DataType::SQLNULL:
577 case DataType::OBJECT:
578 case DataType::BLOB:
579 case DataType::CLOB:
580 case DataType::REF:
581 break;
582 default:
583 rMenu.insert(nPos++, u"colattrset"_ustr, DBA_RES(RID_STR_COLUMN_FORMAT),
584 nullptr, nullptr, nullptr, TRISTATE_INDET);
585 rMenu.insert_separator(nPos++, u"separator1"_ustr);
589 rMenu.insert(nPos++, u"colwidth"_ustr, DBA_RES(RID_STR_COLUMN_WIDTH),
590 nullptr, nullptr, nullptr, TRISTATE_INDET);
591 rMenu.insert_separator(nPos++, u"separator2"_ustr);
594 void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const weld::Menu& rMenu, const OUString& rExecutionResult)
596 if (rExecutionResult == "colwidth")
597 static_cast<SbaGridControl*>(GetParent())->SetColWidth(nColId);
598 else if (rExecutionResult == "colattrset")
599 static_cast<SbaGridControl*>(GetParent())->SetColAttrs(nColId);
600 else
601 FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, rExecutionResult);
604 // SbaGridControl
605 SbaGridControl::SbaGridControl(Reference< XComponentContext > const & _rM,
606 vcl::Window* pParent, FmXGridPeer* _pPeer, WinBits nBits)
607 :FmGridControl(_rM,pParent, _pPeer, nBits)
608 ,m_pMasterListener(nullptr)
609 ,m_nAsyncDropEvent(nullptr)
610 ,m_bActivatingForDrop(false)
614 SbaGridControl::~SbaGridControl()
616 disposeOnce();
619 void SbaGridControl::dispose()
621 if (m_nAsyncDropEvent)
622 Application::RemoveUserEvent(m_nAsyncDropEvent);
623 m_nAsyncDropEvent = nullptr;
624 FmGridControl::dispose();
627 VclPtr<BrowserHeader> SbaGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
629 return VclPtr<SbaGridHeader>::Create(pParent);
632 CellController* SbaGridControl::GetController(sal_Int32 nRow, sal_uInt16 nCol)
634 if ( m_bActivatingForDrop )
635 return nullptr;
637 return FmGridControl::GetController(nRow, nCol);
640 void SbaGridControl::PreExecuteRowContextMenu(weld::Menu& rMenu)
642 FmGridControl::PreExecuteRowContextMenu(rMenu);
644 sal_uInt16 nPos = 0;
646 if (!IsReadOnlyDB())
648 rMenu.insert(nPos++, u"tableattr"_ustr, DBA_RES(RID_STR_TABLE_FORMAT),
649 nullptr, nullptr, nullptr, TRISTATE_INDET);
650 rMenu.insert(nPos++, u"rowheight"_ustr, DBA_RES(RID_STR_ROW_HEIGHT),
651 nullptr, nullptr, nullptr, TRISTATE_INDET);
652 rMenu.insert_separator(nPos++, u"separator1"_ustr);
655 if ( GetSelectRowCount() > 0 )
657 rMenu.insert(nPos++, u"copy"_ustr, DBA_RES(RID_STR_COPY),
658 nullptr, nullptr, nullptr, TRISTATE_INDET);
659 rMenu.insert_separator(nPos++, u"separator2"_ustr);
663 SvNumberFormatter* SbaGridControl::GetDatasourceFormatter()
665 Reference< css::util::XNumberFormatsSupplier > xSupplier = ::dbtools::getNumberFormats(::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)), true, getContext());
667 SvNumberFormatsSupplierObj* pSupplierImpl = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>( xSupplier );
668 if ( !pSupplierImpl )
669 return nullptr;
671 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
672 return pFormatter;
675 void SbaGridControl::SetColWidth(sal_uInt16 nColId)
677 // get the (UNO) column model
678 sal_uInt16 nModelPos = GetModelColumnPos(nColId);
679 Reference< XIndexAccess > xCols = GetPeer()->getColumns();
680 Reference< XPropertySet > xAffectedCol;
681 if (xCols.is() && (nModelPos != sal_uInt16(-1)))
682 xAffectedCol.set(xCols->getByIndex(nModelPos), css::uno::UNO_QUERY);
684 if (!xAffectedCol.is())
685 return;
687 Any aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
688 sal_Int32 nCurWidth = aWidth.hasValue() ? ::comphelper::getINT32(aWidth) : -1;
690 DlgSize aDlgColWidth(GetFrameWeld(), nCurWidth, false);
691 if (aDlgColWidth.run() != RET_OK)
692 return;
694 sal_Int32 nValue = aDlgColWidth.GetValue();
695 Any aNewWidth;
696 if (-1 == nValue)
697 { // set to default
698 Reference< XPropertyState > xPropState(xAffectedCol, UNO_QUERY);
699 if (xPropState.is())
701 try { aNewWidth = xPropState->getPropertyDefault(PROPERTY_WIDTH); } catch(Exception&) { } ;
704 else
705 aNewWidth <<= nValue;
706 try { xAffectedCol->setPropertyValue(PROPERTY_WIDTH, aNewWidth); } catch(Exception&) { } ;
709 void SbaGridControl::SetRowHeight()
711 Reference< XPropertySet > xCols(GetPeer()->getColumns(), UNO_QUERY);
712 if (!xCols.is())
713 return;
715 Any aHeight = xCols->getPropertyValue(PROPERTY_ROW_HEIGHT);
716 sal_Int32 nCurHeight = aHeight.hasValue() ? ::comphelper::getINT32(aHeight) : -1;
718 DlgSize aDlgRowHeight(GetFrameWeld(), nCurHeight, true);
719 if (aDlgRowHeight.run() != RET_OK)
720 return;
722 sal_Int32 nValue = aDlgRowHeight.GetValue();
723 Any aNewHeight;
724 if (sal_Int16(-1) == nValue)
725 { // set to default
726 Reference< XPropertyState > xPropState(xCols, UNO_QUERY);
727 if (xPropState.is())
731 aNewHeight = xPropState->getPropertyDefault(PROPERTY_ROW_HEIGHT);
733 catch(Exception&)
737 else
738 aNewHeight <<= nValue;
741 xCols->setPropertyValue(PROPERTY_ROW_HEIGHT, aNewHeight);
743 catch(Exception&)
745 TOOLS_WARN_EXCEPTION( "dbaccess", "setPropertyValue: PROPERTY_ROW_HEIGHT throws an exception");
749 void SbaGridControl::SetColAttrs(sal_uInt16 nColId)
751 SvNumberFormatter* pFormatter = GetDatasourceFormatter();
752 if (!pFormatter)
753 return;
755 sal_uInt16 nModelPos = GetModelColumnPos(nColId);
757 // get the (UNO) column model
758 Reference< XIndexAccess > xCols = GetPeer()->getColumns();
759 Reference< XPropertySet > xAffectedCol;
760 if (xCols.is() && (nModelPos != sal_uInt16(-1)))
761 xAffectedCol.set(xCols->getByIndex(nModelPos), css::uno::UNO_QUERY);
763 // get the field the column is bound to
764 Reference< XPropertySet > xField = getField(nModelPos);
765 ::dbaui::callColumnFormatDialog(xAffectedCol,xField,pFormatter,GetFrameWeld());
768 void SbaGridControl::SetBrowserAttrs()
770 Reference< XPropertySet > xGridModel(GetPeer()->getColumns(), UNO_QUERY);
771 if (!xGridModel.is())
772 return;
776 Reference< XComponentContext > xContext = getContext();
777 css::uno::Sequence<css::uno::Any> aArguments{
778 Any(comphelper::makePropertyValue(u"IntrospectedObject"_ustr, xGridModel)),
779 Any(comphelper::makePropertyValue(u"ParentWindow"_ustr, VCLUnoHelper::GetInterface(this)))
781 Reference<XExecutableDialog> xExecute(xContext->getServiceManager()->createInstanceWithArgumentsAndContext(u"com.sun.star.form.ControlFontDialog"_ustr,
782 aArguments, xContext), css::uno::UNO_QUERY_THROW);
783 xExecute->execute();
785 catch( const Exception& )
787 DBG_UNHANDLED_EXCEPTION("dbaccess");
791 void SbaGridControl::PostExecuteRowContextMenu(const OUString& rExecutionResult)
793 if (rExecutionResult == "tableattr")
794 SetBrowserAttrs();
795 else if (rExecutionResult == "rowheight")
796 SetRowHeight();
797 else if (rExecutionResult == "copy")
798 CopySelectedRowsToClipboard();
799 else
800 FmGridControl::PostExecuteRowContextMenu(rExecutionResult);
803 void SbaGridControl::Select()
805 // Some selection has changed ...
806 FmGridControl::Select();
808 if (m_pMasterListener)
809 m_pMasterListener->SelectionChanged();
812 void SbaGridControl::ActivateCell(sal_Int32 nRow, sal_uInt16 nCol, bool bSetCellFocus /*= sal_True*/ )
814 FmGridControl::ActivateCell(nRow, nCol, bSetCellFocus);
815 if (m_pMasterListener)
816 m_pMasterListener->CellActivated();
819 void SbaGridControl::DeactivateCell(bool bUpdate /*= sal_True*/)
821 FmGridControl::DeactivateCell(bUpdate);
822 if (m_pMasterListener)
823 m_pMasterListener->CellDeactivated();
826 void SbaGridControl::onRowChange()
828 if ( m_pMasterListener )
829 m_pMasterListener->RowChanged();
832 void SbaGridControl::onColumnChange()
834 if ( m_pMasterListener )
835 m_pMasterListener->ColumnChanged();
838 Reference< XPropertySet > SbaGridControl::getField(sal_uInt16 nModelPos)
840 Reference< XPropertySet > xEmptyReturn;
843 // first get the name of the column
844 Reference< XIndexAccess > xCols = GetPeer()->getColumns();
845 if ( xCols.is() && xCols->getCount() > nModelPos )
847 Reference< XPropertySet > xCol(xCols->getByIndex(nModelPos),UNO_QUERY);
848 if ( xCol.is() )
849 xEmptyReturn.set(xCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
851 else
852 OSL_FAIL("SbaGridControl::getField getColumns returns NULL or ModelPos is > than count!");
854 catch (const Exception&)
856 TOOLS_WARN_EXCEPTION("dbaccess", "SbaGridControl::getField Exception occurred");
859 return xEmptyReturn;
862 bool SbaGridControl::IsReadOnlyDB() const
864 // assume yes if anything fails
865 bool bDBIsReadOnly = true;
869 // the db is the implemented by the parent of the grid control's model ...
870 Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
871 if (xColumns.is())
873 Reference< XRowSet > xDataSource(xColumns->getParent(), UNO_QUERY);
874 ::dbtools::ensureRowSetConnection( xDataSource, getContext(), nullptr );
875 Reference< XChild > xConn(::dbtools::getConnection(xDataSource),UNO_QUERY);
876 if (xConn.is())
878 // ... and the RO-flag simply is implemented by a property
879 Reference< XPropertySet > xDbProps(xConn->getParent(), UNO_QUERY);
880 if (xDbProps.is())
882 Reference< XPropertySetInfo > xInfo = xDbProps->getPropertySetInfo();
883 if (xInfo->hasPropertyByName(PROPERTY_ISREADONLY))
884 bDBIsReadOnly = ::comphelper::getBOOL(xDbProps->getPropertyValue(PROPERTY_ISREADONLY));
889 catch (const Exception&)
891 TOOLS_WARN_EXCEPTION("dbaccess", "SbaGridControl::IsReadOnlyDB Exception occurred");
894 return bDBIsReadOnly;
897 void SbaGridControl::MouseButtonDown( const BrowserMouseEvent& rMEvt)
899 sal_Int32 nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y());
900 sal_uInt16 nColPos = GetColumnAtXPosPixel(rMEvt.GetPosPixel().X());
901 sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : sal_uInt16(nColPos - 1);
902 // 'the handle column' and 'no valid column' will both result in a view position of -1 !
904 bool bHitEmptySpace = (nRow > GetRowCount()) || (nViewPos == sal_uInt16(-1));
906 if (bHitEmptySpace && (rMEvt.GetClicks() == 2) && rMEvt.IsMod1())
907 Control::MouseButtonDown(rMEvt);
908 else
909 FmGridControl::MouseButtonDown(rMEvt);
912 void SbaGridControl::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
914 SolarMutexGuard aGuard;
915 // in the new DnD API, the solar mutex is not locked when StartDrag is called
917 bool bHandled = false;
921 // determine if dragging is allowed
922 // (Yes, this is controller (not view) functionality. But collecting and evaluating all the
923 // information necessary via UNO would be quite difficult (if not impossible) so
924 // my laziness says 'do it here'...)
925 sal_Int32 nRow = GetRowAtYPosPixel(_rPosPixel.Y());
926 sal_uInt16 nColPos = GetColumnAtXPosPixel(_rPosPixel.X());
927 sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : sal_uInt16(nColPos-1);
928 // 'the handle column' and 'no valid column' will both result in a view position of -1 !
930 bool bCurrentRowVirtual = IsCurrentAppending() && IsModified();
931 // the current row doesn't really exist: the user's appending a new one and already has entered some data,
932 // so the row contains data which has no counter part within the data source
934 sal_Int32 nCorrectRowCount = GetRowCount();
935 if (GetOptions() & DbGridControlOptions::Insert)
936 --nCorrectRowCount; // there is an empty row for inserting records
937 if (bCurrentRowVirtual)
938 --nCorrectRowCount;
940 if ((nColPos == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount))
941 break;
943 bool bHitHandle = (nColPos == 0);
945 // check which kind of dragging has to be initiated
946 if ( bHitHandle // the handle column
947 // AND
948 && ( GetSelectRowCount() // at least one row is selected
949 // OR
950 || ( (nRow >= 0) // a row below the header
951 && !bCurrentRowVirtual // we aren't appending a new record
952 && (nRow != GetCurrentPos()) // a row which is not the current one
953 ) // OR
954 || ( (0 == GetSelectRowCount()) // no rows selected
955 && (-1 == nRow) // hit the header
959 { // => start dragging the row
960 if (GetDataWindow().IsMouseCaptured())
961 GetDataWindow().ReleaseMouse();
963 if (0 == GetSelectRowCount())
964 // no rows selected, but here in this branch
965 // -> the user started dragging the upper left corner, which symbolizes the whole table
966 SelectAll();
968 getMouseEvent().Clear();
969 implTransferSelectedRows(static_cast<sal_Int16>(nRow), false);
971 bHandled = true;
973 else if ( (nRow < 0) // the header
974 && (!bHitHandle) // non-handle column
975 && (nViewPos < GetViewColCount()) // valid (existing) column
977 { // => start dragging the column
978 if (GetDataWindow().IsMouseCaptured())
979 GetDataWindow().ReleaseMouse();
981 getMouseEvent().Clear();
982 DoColumnDrag(nViewPos);
984 bHandled = true;
986 else if ( !bHitHandle // non-handle column
987 && (nRow >= 0) // non-header row
989 { // => start dragging the field content
990 if (GetDataWindow().IsMouseCaptured())
991 GetDataWindow().ReleaseMouse();
993 getMouseEvent().Clear();
994 DoFieldDrag(nViewPos, static_cast<sal_Int16>(nRow));
996 bHandled = true;
999 while (false);
1001 if (!bHandled)
1002 FmGridControl::StartDrag(_nAction, _rPosPixel);
1005 void SbaGridControl::DoColumnDrag(sal_uInt16 nColumnPos)
1007 Reference< XPropertySet > xDataSource = getDataSource();
1008 OSL_ENSURE(xDataSource.is(), "SbaGridControl::DoColumnDrag : invalid data source !");
1009 ::dbtools::ensureRowSetConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY), getContext(), nullptr);
1011 Reference< XPropertySet > xAffectedCol;
1012 Reference< XPropertySet > xAffectedField;
1013 Reference< XConnection > xActiveConnection;
1015 // determine the field to drag
1016 OUString sField;
1019 xActiveConnection = ::dbtools::getConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY));
1021 sal_uInt16 nModelPos = GetModelColumnPos(GetColumnIdFromViewPos(nColumnPos));
1022 Reference< XIndexContainer > xCols = GetPeer()->getColumns();
1023 xAffectedCol.set(xCols->getByIndex(nModelPos),UNO_QUERY);
1024 if (xAffectedCol.is())
1026 xAffectedCol->getPropertyValue(PROPERTY_CONTROLSOURCE) >>= sField;
1027 xAffectedField.set(xAffectedCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
1030 catch(Exception&)
1032 OSL_FAIL("SbaGridControl::DoColumnDrag : something went wrong while getting the column");
1034 if (sField.isEmpty())
1035 return;
1037 rtl::Reference<OColumnTransferable> pDataTransfer = new OColumnTransferable(xDataSource, sField, xAffectedField, xActiveConnection, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR);
1038 pDataTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1041 void SbaGridControl::CopySelectedRowsToClipboard()
1043 OSL_ENSURE( GetSelectRowCount() > 0, "SbaGridControl::CopySelectedRowsToClipboard: invalid call!" );
1044 implTransferSelectedRows( static_cast<sal_Int16>(FirstSelectedRow()), true );
1047 void SbaGridControl::implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag )
1049 Reference< XPropertySet > xForm = getDataSource();
1050 OSL_ENSURE( xForm.is(), "SbaGridControl::implTransferSelectedRows: invalid form!" );
1052 // build the sequence of numbers of selected rows
1053 Sequence< Any > aSelectedRows;
1054 bool bSelectionBookmarks = true;
1056 // collect the affected rows
1057 if ((GetSelectRowCount() == 0) && (nRowPos >= 0))
1059 aSelectedRows = { Any(static_cast<sal_Int32>(nRowPos + 1)) };
1060 bSelectionBookmarks = false;
1062 else if ( !IsAllSelected() && GetSelectRowCount() )
1064 aSelectedRows = getSelectionBookmarks();
1065 bSelectionBookmarks = true;
1070 rtl::Reference<ODataClipboard> pTransfer = new ODataClipboard( xForm, aSelectedRows, bSelectionBookmarks, getContext() );
1072 if ( _bTrueIfClipboardFalseIfDrag )
1073 pTransfer->CopyToClipboard( this );
1074 else
1075 pTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1077 catch(Exception&)
1082 void SbaGridControl::DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos)
1084 // the only thing to do here is dragging the pure cell text
1085 // the old implementation copied a SBA_FIELDDATAEXCHANGE_FORMAT, too, (which was rather expensive to obtain),
1086 // but we have no client for this DnD format anymore (the mail part of SO 5.2 was the only client)
1090 OUString sCellText;
1091 Reference< XGridFieldDataSupplier > xFieldData(GetPeer());
1092 Sequence<sal_Bool> aSupportingText = xFieldData->queryFieldDataType(cppu::UnoType<decltype(sCellText)>::get());
1093 if (aSupportingText[nColumnPos])
1095 Sequence< Any> aCellContents = xFieldData->queryFieldData(nRowPos, cppu::UnoType<decltype(sCellText)>::get());
1096 sCellText = ::comphelper::getString(aCellContents[nColumnPos]);
1097 ::svt::OStringTransfer::StartStringDrag(sCellText, this, DND_ACTION_COPY);
1100 catch(Exception&)
1102 OSL_FAIL("SbaGridControl::DoFieldDrag : could not retrieve the cell's contents !");
1103 return;
1108 namespace {
1110 /// unary_function Functor object for class ZZ returntype is void
1111 struct SbaGridControlPrec
1113 bool operator()(const DataFlavorExVector::value_type& _aType)
1115 switch (_aType.mnSotId)
1117 case SotClipboardFormatId::DBACCESS_TABLE: // table descriptor
1118 case SotClipboardFormatId::DBACCESS_QUERY: // query descriptor
1119 case SotClipboardFormatId::DBACCESS_COMMAND: // SQL command
1120 return true;
1121 default: break;
1123 return false;
1129 sal_Int8 SbaGridControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
1131 sal_Int8 nAction = DND_ACTION_NONE;
1133 // we need a valid connection
1134 if (!::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)).is())
1135 return nAction;
1137 if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) )
1139 { // odd construction, but spares us a lot of (explicit ;) goto's
1141 if (!GetEmptyRow().is())
1142 // without an empty row we're not in update mode
1143 break;
1145 const sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false);
1146 const sal_uInt16 nCol = GetColumnId(GetColumnAtXPosPixel(rEvt.maPosPixel.X()));
1148 sal_Int32 nCorrectRowCount = GetRowCount();
1149 if (GetOptions() & DbGridControlOptions::Insert)
1150 --nCorrectRowCount; // there is an empty row for inserting records
1151 if (IsCurrentAppending())
1152 --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1154 if ( (nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || (nCol == 0) )
1155 // no valid cell under the mouse cursor
1156 break;
1158 tools::Rectangle aRect = GetCellRect(nRow, nCol, false);
1159 if (!aRect.Contains(rEvt.maPosPixel))
1160 // not dropped within a cell (a cell isn't as wide as the column - the are small spaces)
1161 break;
1163 if ((IsModified() || (GetCurrentRow().is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow))
1164 // there is a current and modified row or cell and he text is to be dropped into another one
1165 break;
1167 CellControllerRef xCurrentController = Controller();
1168 if (xCurrentController.is() && xCurrentController->IsValueChangedFromSaved() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId())))
1169 // the current controller is modified and the user wants to drop in another cell -> no chance
1170 // (when leaving the modified cell an error may occur - this is deadly while dragging)
1171 break;
1173 Reference< XPropertySet > xField = getField(GetModelColumnPos(nCol));
1174 if (!xField.is())
1175 // the column is not valid bound (for instance a binary field)
1176 break;
1180 if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY)))
1181 break;
1183 catch (const Exception& )
1185 // assume RO
1186 break;
1191 // assume that text can be dropped into a field if the column has a css::awt::XTextComponent interface
1192 Reference< XIndexAccess > xColumnControls(GetPeer());
1193 if (xColumnControls.is())
1195 Reference< css::awt::XTextComponent > xColControl(
1196 xColumnControls->getByIndex(GetViewColumnPos(nCol)),
1197 css::uno::UNO_QUERY);
1198 if (xColControl.is())
1200 m_bActivatingForDrop = true;
1201 GoToRowColumnId(nRow, nCol);
1202 m_bActivatingForDrop = false;
1204 nAction = DND_ACTION_COPY;
1208 catch( const Exception& )
1210 DBG_UNHANDLED_EXCEPTION("dbaccess");
1213 } while (false);
1215 if(nAction != DND_ACTION_COPY && GetEmptyRow().is())
1217 const DataFlavorExVector& _rFlavors = GetDataFlavors();
1218 if(std::any_of(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec()))
1219 nAction = DND_ACTION_COPY;
1222 return (DND_ACTION_NONE != nAction) ? nAction : FmGridControl::AcceptDrop(rEvt);
1225 sal_Int8 SbaGridControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
1227 // we need some properties of our data source
1228 Reference< XPropertySet > xDataSource = getDataSource();
1229 if (!xDataSource.is())
1230 return DND_ACTION_NONE;
1232 // we need a valid connection
1233 if (!::dbtools::getConnection(Reference< XRowSet > (xDataSource,UNO_QUERY)).is())
1234 return DND_ACTION_NONE;
1236 if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) )
1238 sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false);
1239 sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X());
1241 sal_Int32 nCorrectRowCount = GetRowCount();
1242 if (GetOptions() & DbGridControlOptions::Insert)
1243 --nCorrectRowCount; // there is an empty row for inserting records
1244 if (IsCurrentAppending())
1245 --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1247 OSL_ENSURE((nCol != BROWSER_INVALIDID) && (nRow < nCorrectRowCount), "SbaGridControl::Drop : dropped on an invalid position !");
1248 // AcceptDrop should have caught this
1250 // from now we work with ids instead of positions
1251 nCol = GetColumnId(nCol);
1253 GoToRowColumnId(nRow, nCol);
1254 if (!IsEditing())
1255 ActivateCell();
1257 CellControllerRef xCurrentController = Controller();
1258 EditCellController* pController = dynamic_cast<EditCellController*>(xCurrentController.get());
1259 if (!pController)
1260 return DND_ACTION_NONE;
1262 // get the dropped string
1263 TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1264 OUString sDropped;
1265 if ( !aDropped.GetString( SotClipboardFormatId::STRING, sDropped ) )
1266 return DND_ACTION_NONE;
1268 IEditImplementation* pEditImplementation = pController->GetEditImplementation();
1269 pEditImplementation->SetText(sDropped);
1270 // SetText itself doesn't call a Modify as it isn't a user interaction
1271 pController->Modify();
1273 return DND_ACTION_COPY;
1276 if(GetEmptyRow().is())
1278 const DataFlavorExVector& _rFlavors = GetDataFlavors();
1279 if( std::any_of(_rFlavors.begin(),_rFlavors.end(), SbaGridControlPrec()) )
1281 TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1282 m_aDataDescriptor = ODataAccessObjectTransferable::extractObjectDescriptor(aDropped);
1283 if (m_nAsyncDropEvent)
1284 Application::RemoveUserEvent(m_nAsyncDropEvent);
1285 m_nAsyncDropEvent = Application::PostUserEvent(LINK(this, SbaGridControl, AsynchDropEvent), nullptr, true);
1286 return DND_ACTION_COPY;
1290 return DND_ACTION_NONE;
1293 Reference< XPropertySet > SbaGridControl::getDataSource() const
1295 Reference< XPropertySet > xReturn;
1297 Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
1298 if (xColumns.is())
1299 xReturn.set(xColumns->getParent(), UNO_QUERY);
1301 return xReturn;
1304 IMPL_LINK_NOARG(SbaGridControl, AsynchDropEvent, void*, void)
1306 m_nAsyncDropEvent = nullptr;
1308 Reference< XPropertySet > xDataSource = getDataSource();
1309 if ( xDataSource.is() )
1311 bool bCountFinal = false;
1312 xDataSource->getPropertyValue(PROPERTY_ISROWCOUNTFINAL) >>= bCountFinal;
1313 if ( !bCountFinal )
1314 setDataSource(nullptr); // detach from grid control
1315 Reference< XResultSetUpdate > xResultSetUpdate(xDataSource,UNO_QUERY);
1316 rtl::Reference<ODatabaseImportExport> pImExport = new ORowSetImportExport(GetFrameWeld(),xResultSetUpdate,m_aDataDescriptor, getContext());
1317 Hide();
1320 pImExport->initialize(m_aDataDescriptor);
1321 if (m_pMasterListener)
1322 m_pMasterListener->BeforeDrop();
1323 if(!pImExport->Read())
1325 OUString sError = DBA_RES(STR_NO_COLUMNNAME_MATCHING);
1326 throwGenericSQLException(sError,nullptr);
1328 if (m_pMasterListener)
1329 m_pMasterListener->AfterDrop();
1330 Show();
1332 catch(const SQLException& e)
1334 if (m_pMasterListener)
1335 m_pMasterListener->AfterDrop();
1336 Show();
1337 ::dbtools::showError( ::dbtools::SQLExceptionInfo(e), VCLUnoHelper::GetInterface(this), getContext() );
1339 catch(const Exception& )
1341 DBG_UNHANDLED_EXCEPTION("dbaccess");
1342 if (m_pMasterListener)
1343 m_pMasterListener->AfterDrop();
1344 Show();
1346 if ( !bCountFinal )
1347 setDataSource(Reference< XRowSet >(xDataSource,UNO_QUERY));
1349 m_aDataDescriptor.clear();
1352 OUString SbaGridControl::GetAccessibleObjectDescription( AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
1354 OUString sRet;
1355 if ( AccessibleBrowseBoxObjType::BrowseBox == eObjType )
1357 SolarMutexGuard aGuard;
1358 sRet = DBA_RES(STR_DATASOURCE_GRIDCONTROL_DESC);
1360 else
1361 sRet = FmGridControl::GetAccessibleObjectDescription( eObjType,_nPosition);
1362 return sRet;
1365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */