dbaccess/Library_dbu.mk | 1 dbaccess/source/ui/browser/dataview.cxx | 19 dbaccess/source/ui/browser/dbexchange.cxx | 41 dbaccess/source/ui/browser/dbtreeview.cxx | 18 dbaccess/source/ui/browser/dbtreeview.hxx | 20 dbaccess/source/ui/browser/dsEntriesNoExp.cxx | 171 +-- dbaccess/source/ui/browser/dsbrowserDnD.cxx | 153 +-- dbaccess/source/ui/browser/genericcontroller.cxx | 4 dbaccess/source/ui/browser/unodatbr.cxx | 1002 ++++++++++++----------- dbaccess/source/ui/control/dbtreelistbox.cxx | 16 dbaccess/source/ui/control/listviewitems.cxx | 68 - dbaccess/source/ui/control/tabletree.cxx | 1 dbaccess/source/ui/inc/TableCopyHelper.hxx | 4 dbaccess/source/ui/inc/dbexchange.hxx | 19 dbaccess/source/ui/inc/dbtreelistbox.hxx | 8 dbaccess/source/ui/inc/imageprovider.hxx | 2 dbaccess/source/ui/inc/listviewitems.hxx | 54 - dbaccess/source/ui/inc/unodatbr.hxx | 115 +- dbaccess/source/ui/misc/imageprovider.cxx | 4 dbaccess/uiconfig/ui/dbtreelist.ui | 5 include/dbaccess/IController.hxx | 6 include/dbaccess/dataview.hxx | 2 include/dbaccess/genericcontroller.hxx | 1 include/svx/dbaexchange.hxx | 17 solenv/clang-format/excludelist | 2 svx/source/fmcomp/dbaexchange.cxx | 20 26 files changed, 881 insertions(+), 892 deletions(-)
New commits: commit 5f7cf9ccba25a94c275ec67936dc29f0adb4129a Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Aug 10 19:49:25 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Aug 12 20:22:23 2020 +0200 use InterimDBTreeListBox Change-Id: I2f345f1a4fd6c7a4dc7be831f85a9f728ee477ad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100496 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/dbaccess/Library_dbu.mk b/dbaccess/Library_dbu.mk index 67e852518bae..1a3630727860 100644 --- a/dbaccess/Library_dbu.mk +++ b/dbaccess/Library_dbu.mk @@ -101,7 +101,6 @@ $(eval $(call gb_Library_add_exception_objects,dbu,\ dbaccess/source/ui/control/dbtreelistbox \ dbaccess/source/ui/control/FieldControls \ dbaccess/source/ui/control/FieldDescControl \ - dbaccess/source/ui/control/listviewitems \ dbaccess/source/ui/control/opendoccontrols \ dbaccess/source/ui/control/RelationControl \ dbaccess/source/ui/control/ScrollHelper \ diff --git a/dbaccess/source/ui/browser/dataview.cxx b/dbaccess/source/ui/browser/dataview.cxx index 099199bc2ae4..b293fadd3cc4 100644 --- a/dbaccess/source/ui/browser/dataview.cxx +++ b/dbaccess/source/ui/browser/dataview.cxx @@ -131,12 +131,6 @@ namespace dbaui { Window::StateChanged( nType ); - if ( nType == StateChangedType::ControlBackground ) - { - // Check if we need to get new images for normal/high contrast mode - m_xController->notifyHiContrastChanged(); - } - if ( nType != StateChangedType::InitShow ) return; @@ -158,20 +152,7 @@ namespace dbaui DBG_UNHANDLED_EXCEPTION("dbaccess"); } } - void ODataView::DataChanged( const DataChangedEvent& rDCEvt ) - { - Window::DataChanged( rDCEvt ); - if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) || - (rDCEvt.GetType() == DataChangedEventType::DISPLAY) || - (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) || - ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && - (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) ) - { - // Check if we need to get new images for normal/high contrast mode - m_xController->notifyHiContrastChanged(); - } - } void ODataView::attachFrame(const Reference< XFrame >& _xFrame) { m_pAccel->init(m_xContext, _xFrame); diff --git a/dbaccess/source/ui/browser/dbexchange.cxx b/dbaccess/source/ui/browser/dbexchange.cxx index 2fe0a3b21ed5..a6d649674f07 100644 --- a/dbaccess/source/ui/browser/dbexchange.cxx +++ b/dbaccess/source/ui/browser/dbexchange.cxx @@ -58,6 +58,10 @@ namespace dbaui } } + ODataClipboard::ODataClipboard() + { + } + ODataClipboard::ODataClipboard( const OUString& _rDatasource, const sal_Int32 _nCommandType, @@ -88,6 +92,43 @@ namespace dbaui m_pRtf.set( new ORTFImportExport( getDescriptor(),_rxORB, _rxFormatter ) ); } + void ODataClipboard::Update( + const OUString& rDatasource, + const sal_Int32 nCommandType, + const OUString& rCommand, + const Reference< XConnection >& rxConnection, + const Reference< XNumberFormatter >& rxFormatter, + const Reference< XComponentContext >& rxORB) + { + ClearFormats(); + + ODataAccessObjectTransferable::Update(rDatasource, nCommandType, rCommand, rxConnection); + + lcl_setListener(rxConnection, this, true); + + m_pHtml.set(new OHTMLImportExport(getDescriptor(), rxORB, rxFormatter)); + m_pRtf.set(new ORTFImportExport(getDescriptor(), rxORB, rxFormatter)); + + AddSupportedFormats(); + } + + void ODataClipboard::Update( + const OUString& rDatasource, + const sal_Int32 nCommandType, + const OUString& rCommand, + const Reference< XNumberFormatter >& rxFormatter, + const Reference< XComponentContext >& rxORB) + { + ClearFormats(); + + ODataAccessObjectTransferable::Update(rDatasource, nCommandType, rCommand); + + m_pHtml.set(new OHTMLImportExport(getDescriptor(), rxORB, rxFormatter)); + m_pRtf.set(new ORTFImportExport(getDescriptor(), rxORB, rxFormatter)); + + AddSupportedFormats(); + } + ODataClipboard::ODataClipboard( const Reference< XPropertySet >& i_rAliveForm, const Sequence< Any >& i_rSelectedRows, const bool i_bBookmarkSelection, diff --git a/dbaccess/source/ui/browser/dbtreeview.cxx b/dbaccess/source/ui/browser/dbtreeview.cxx index 38464068bbb7..f5d1d023c869 100644 --- a/dbaccess/source/ui/browser/dbtreeview.cxx +++ b/dbaccess/source/ui/browser/dbtreeview.cxx @@ -29,14 +29,13 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; DBTreeView::DBTreeView( vcl::Window* pParent, WinBits nBits) - : Window( pParent, nBits ) - , m_pTreeListBox(nullptr) + : Window(pParent, nBits) + , m_pTreeListBox(VclPtr<InterimDBTreeListBox>::Create(this)) { - - m_pTreeListBox = VclPtr<DBTreeListBox>::Create(this, WB_BORDER | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT); - m_pTreeListBox->EnableCheckButton(nullptr); +#if 0 m_pTreeListBox->SetDragDropMode( DragDropMode::NONE ); m_pTreeListBox->EnableInplaceEditing( true ); +#endif m_pTreeListBox->SetHelpId(HID_TLB_TREELISTBOX); m_pTreeListBox->Show(); } @@ -52,14 +51,9 @@ void DBTreeView::dispose() vcl::Window::dispose(); } -SvTreeList* DBTreeView::GetTreeModel() -{ - return m_pTreeListBox->GetModel(); -} - -void DBTreeView::SetPreExpandHandler(const Link<SvTreeListEntry*,bool>& _rHdl) +void DBTreeView::SetPreExpandHandler(const Link<const weld::TreeIter&,bool>& rHdl) { - m_pTreeListBox->SetPreExpandHandler(_rHdl); + m_pTreeListBox->GetWidget().connect_expanding(rHdl); } void DBTreeView::setCopyHandler(const Link<LinkParamNone*,void>& _rHdl) diff --git a/dbaccess/source/ui/browser/dbtreeview.hxx b/dbaccess/source/ui/browser/dbtreeview.hxx index 892a6beab394..0070b50f3ee8 100644 --- a/dbaccess/source/ui/browser/dbtreeview.hxx +++ b/dbaccess/source/ui/browser/dbtreeview.hxx @@ -20,20 +20,17 @@ #ifndef INCLUDED_DBACCESS_SOURCE_UI_BROWSER_DBTREEVIEW_HXX #define INCLUDED_DBACCESS_SOURCE_UI_BROWSER_DBTREEVIEW_HXX +#include <vcl/weld.hxx> #include <vcl/window.hxx> -class SvTreeList; -class SvTreeListEntry; - namespace dbaui { - class DBTreeListBox; - // - DBTreeView - + class InterimDBTreeListBox; class DBTreeView : public vcl::Window { private: - VclPtr<DBTreeListBox> m_pTreeListBox; + VclPtr<InterimDBTreeListBox> m_pTreeListBox; protected: // window overridables virtual void Resize() override; @@ -45,17 +42,16 @@ namespace dbaui virtual void dispose() override; /** sets a handler which is called when a list box entry is to be expanded. - <p>When calling the link, the parameter is an SvTreeListEntry marking the entry to be expanded. + <p>When calling the link, the parameter is a TreeIter marking the entry to be expanded. </p> */ - void SetPreExpandHandler(const Link<SvTreeListEntry*,bool>& _rHdl); + void SetPreExpandHandler(const Link<const weld::TreeIter&,bool>& rHdl); - void setCopyHandler(const Link<LinkParamNone*,void>& _rHdl); + void setCopyHandler(const Link<LinkParamNone*,void>& rHdl); - SvTreeList* GetTreeModel(); - void setSelChangeHdl(const Link<LinkParamNone*,void>& _rHdl); + void setSelChangeHdl(const Link<LinkParamNone*,void>& rHdl); - DBTreeListBox& getListBox() const { return *m_pTreeListBox; } + InterimDBTreeListBox& getListBox() const { return *m_pTreeListBox; } virtual void GetFocus() override; }; diff --git a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx index 7e9bfc851360..c6b160c09b23 100644 --- a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx +++ b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx @@ -23,7 +23,6 @@ #include <unodatbr.hxx> #include <browserids.hxx> -#include <listviewitems.hxx> #include <imageprovider.hxx> #include <osl/diagnose.h> #include "dbtreeview.hxx" @@ -37,10 +36,10 @@ using namespace ::svx; namespace dbaui { -SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvTreeListEntry const * _pEntry ) const +SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType(const weld::TreeIter& rEntry) const { - OSL_ENSURE(isContainer(_pEntry), "SbaTableQueryBrowser::getChildType: invalid entry!"); - switch (getEntryType(_pEntry)) + OSL_ENSURE(isContainer(rEntry), "SbaTableQueryBrowser::getChildType: invalid entry!"); + switch (getEntryType(rEntry)) { case etTableContainer: return etTableOrView; @@ -52,88 +51,98 @@ SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvTreeListEn return etUnknown; } -OUString SbaTableQueryBrowser::GetEntryText( SvTreeListEntry* _pEntry ) const +OUString SbaTableQueryBrowser::GetEntryText(const weld::TreeIter& rEntry) const { - return m_pTreeView->getListBox().GetEntryText(_pEntry); + return m_pTreeView->getListBox().GetWidget().get_text(rEntry); } -SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( const SvTreeListEntry* _pEntry ) const +SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType(const weld::TreeIter& rEntry) const { - if (!_pEntry) - return etUnknown; + std::unique_ptr<weld::TreeIter> xRootEntry = m_pTreeView->getListBox().GetRootLevelParent(&rEntry); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); - SvTreeListEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(const_cast<SvTreeListEntry*>(_pEntry)); - SvTreeListEntry* pEntryParent = m_pTreeView->getListBox().GetParent(const_cast<SvTreeListEntry*>(_pEntry)); - SvTreeListEntry* pTables = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES); - SvTreeListEntry* pQueries = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES); + if (rTreeView.iter_compare(*xRootEntry, rEntry) == 0) + return etDatasource; -#ifdef DBG_UTIL - OUString sTest; - if (pTables) sTest = m_pTreeView->getListBox().GetEntryText(pTables); - if (pQueries) sTest = m_pTreeView->getListBox().GetEntryText(pQueries); -#endif + std::unique_ptr<weld::TreeIter> xEntryParent(rTreeView.make_iterator(&rEntry)); + if (!rTreeView.iter_parent(*xEntryParent)) + xEntryParent.reset(); - if (pRootEntry == _pEntry) - return etDatasource; + std::unique_ptr<weld::TreeIter> xTables; + std::unique_ptr<weld::TreeIter> xQueries; + + std::unique_ptr<weld::TreeIter> xContainer = rTreeView.make_iterator(xRootEntry.get()); + if (rTreeView.iter_children(*xContainer)) + { + // 1st child is queries + xQueries = rTreeView.make_iterator(xContainer.get()); + + if (rTreeView.iter_next_sibling(*xContainer)) + { + // 2nd child is tables + xTables = rTreeView.make_iterator(xContainer.get()); + } + } - if (pTables == _pEntry) + if (xTables && rTreeView.iter_compare(*xTables, rEntry) == 0) return etTableContainer; - if (pQueries == _pEntry) + if (xQueries && rTreeView.iter_compare(*xQueries, rEntry) == 0) return etQueryContainer; - if (pTables == pEntryParent) + if (xTables && xEntryParent && rTreeView.iter_compare(*xTables, *xEntryParent) == 0) return etTableOrView; - if (pQueries == pEntryParent) + if (xQueries && xEntryParent) { - DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData()); - if ( pEntryData ) - return pEntryData->eType; + if (rTreeView.iter_compare(*xQueries, *xEntryParent) == 0) + { + DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rEntry).toUInt64()); + if (pEntryData) + return pEntryData->eType; + return etQuery; + } - return etQuery; - } - while( pEntryParent != pQueries ) - { - pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent); - if ( !pEntryParent ) - return etUnknown; + while (rTreeView.iter_compare(*xEntryParent, *xQueries) != 0) + { + if (!rTreeView.iter_parent(*xEntryParent)) + return etUnknown; + } } return etQueryContainer; } -void SbaTableQueryBrowser::select(SvTreeListEntry* _pEntry, bool _bSelect) +void SbaTableQueryBrowser::select(weld::TreeIter* pEntry, bool bSelect) { - SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SvLBoxItemType::String) : nullptr; - if (pTextItem) + if (pEntry) { - static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect); - m_pTreeView->GetTreeModel()->InvalidateEntry(_pEntry); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + rTreeView.set_text_emphasis(*pEntry, bSelect, 0); } - else { + else + { OSL_FAIL("SbaTableQueryBrowser::select: invalid entry!"); } } -void SbaTableQueryBrowser::selectPath(SvTreeListEntry* _pEntry, bool _bSelect) +void SbaTableQueryBrowser::selectPath(weld::TreeIter* pEntry, bool bSelect) { - while (_pEntry) + if (!pEntry) + return; + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xEntry(rTreeView.make_iterator(pEntry)); + do { - select(_pEntry, _bSelect); - _pEntry = m_pTreeView->GetTreeModel()->GetParent(_pEntry); + select(xEntry.get(), bSelect); } + while (rTreeView.iter_parent(*xEntry)); } -bool SbaTableQueryBrowser::isSelected(SvTreeListEntry* _pEntry) +bool SbaTableQueryBrowser::isSelected(const weld::TreeIter& rEntry) const { - SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SvLBoxItemType::String) : nullptr; - if (pTextItem) - return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized(); - else { - OSL_FAIL("SbaTableQueryBrowser::isSelected: invalid entry!"); - } - return false; + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + return rTreeView.get_text_emphasis(rEntry, 0); } void SbaTableQueryBrowser::SelectionChanged() @@ -193,64 +202,6 @@ sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType ) return css::sdb::application::DatabaseObject::TABLE; } -void SbaTableQueryBrowser::notifyHiContrastChanged() -{ - if ( !m_pTreeView ) - return; - - auto pTreeModel = m_pTreeView->GetTreeModel(); - // change all bitmap entries - SvTreeListEntry* pEntryLoop = pTreeModel->First(); - while ( pEntryLoop ) - { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData()); - if ( !pData ) - { - pEntryLoop = pTreeModel->Next(pEntryLoop); - continue; - } - - // the connection to which this entry belongs, if any - std::unique_ptr< ImageProvider > pImageProvider( getImageProviderFor( pEntryLoop ) ); - - // the images for this entry - Image aImage; - if ( pData->eType == etDatasource ) - aImage = ImageProvider::getDatabaseImage(); - else - { - bool bIsFolder = !isObject( pData->eType ); - if ( bIsFolder ) - { - sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) ); - aImage = ImageProvider::getFolderImage( nObjectType ); - } - else - { - sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) ); - pImageProvider->getImages( GetEntryText( pEntryLoop ), nObjectType, aImage ); - } - } - - // find the proper item, and set its icons - sal_uInt16 nCount = pEntryLoop->ItemCount(); - for (sal_uInt16 i=0;i<nCount;++i) - { - SvLBoxItem& rItem = pEntryLoop->GetItem(i); - if (rItem.GetType() != SvLBoxItemType::ContextBmp) - continue; - - SvLBoxContextBmp& rContextBitmapItem = static_cast< SvLBoxContextBmp& >( rItem ); - - rContextBitmapItem.SetBitmap1( aImage ); - rContextBitmapItem.SetBitmap2( aImage ); - break; - } - - pEntryLoop = pTreeModel->Next(pEntryLoop); - } -} - } // namespace dbaui /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/browser/dsbrowserDnD.cxx b/dbaccess/source/ui/browser/dsbrowserDnD.cxx index 0b9888f3f34e..e8425436df37 100644 --- a/dbaccess/source/ui/browser/dsbrowserDnD.cxx +++ b/dbaccess/source/ui/browser/dsbrowserDnD.cxx @@ -59,26 +59,26 @@ namespace dbaui using namespace ::dbtools; using namespace ::svx; - TransferableHelper* SbaTableQueryBrowser::implCopyObject( SvTreeListEntry* _pApplyTo, sal_Int32 _nCommandType ) + bool SbaTableQueryBrowser::implCopyObject(ODataClipboard& rExchange, const weld::TreeIter& rApplyTo, sal_Int32 nCommandType) { try { - OUString aName = GetEntryText( _pApplyTo ); - OUString aDSName = getDataSourceAccessor( m_pTreeView->getListBox().GetRootLevelParent( _pApplyTo ) ); + OUString aName = GetEntryText(rApplyTo); + std::unique_ptr<weld::TreeIter> xRootEntry(m_pTreeView->getListBox().GetRootLevelParent(&rApplyTo)); + OUString aDSName = getDataSourceAccessor(*xRootEntry); - ODataClipboard* pData = nullptr; SharedConnection xConnection; - if ( CommandType::QUERY != _nCommandType ) + if ( CommandType::QUERY != nCommandType ) { - if ( !ensureConnection( _pApplyTo, xConnection) ) - return nullptr; - pData = new ODataClipboard(aDSName, _nCommandType, aName, xConnection, getNumberFormatter(), getORB()); + if (!ensureConnection(&rApplyTo, xConnection)) + return false; + rExchange.Update(aDSName, nCommandType, aName, xConnection, getNumberFormatter(), getORB()); } else - pData = new ODataClipboard(aDSName, _nCommandType, aName, getNumberFormatter(), getORB()); + rExchange.Update(aDSName, nCommandType, aName, getNumberFormatter(), getORB()); // the ownership goes to ODataClipboards - return pData; + return true; } catch(const SQLException& ) { @@ -88,19 +88,21 @@ namespace dbaui { DBG_UNHANDLED_EXCEPTION("dbaccess"); } - return nullptr; + return false; } + sal_Int8 SbaTableQueryBrowser::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors ) { // check if we're a table or query container - SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rEvt.maPosPixel ); - - if ( pHitEntry ) // no drop if no entry was hit... + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xHitEntry(rTreeView.make_iterator()); + // get_dest_row_at_pos with false cause no drop if no entry was hit exactly + if (rTreeView.get_dest_row_at_pos(_rEvt.maPosPixel, xHitEntry.get(), false)) { // it must be a container - EntryType eEntryType = getEntryType( pHitEntry ); + EntryType eEntryType = getEntryType(*xHitEntry); SharedConnection xConnection; - if ( eEntryType == etTableContainer && ensureConnection( pHitEntry, xConnection ) && xConnection.is() ) + if ( eEntryType == etTableContainer && ensureConnection(xHitEntry.get(), xConnection ) && xConnection.is()) { Reference<XChild> xChild(xConnection,UNO_QUERY); Reference<XStorable> xStore; @@ -116,8 +118,12 @@ namespace dbaui } sal_Int8 SbaTableQueryBrowser::executeDrop( const ExecuteDropEvent& _rEvt ) { - SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rEvt.maPosPixel ); - EntryType eEntryType = getEntryType( pHitEntry ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xHitEntry(rTreeView.make_iterator()); + // get_dest_row_at_pos with false cause no drop if no entry was hit exactly + if (!rTreeView.get_dest_row_at_pos(_rEvt.maPosPixel, xHitEntry.get(), false)) + return DND_ACTION_NONE; + EntryType eEntryType = getEntryType(*xHitEntry); if (!isContainer(eEntryType)) { OSL_FAIL("SbaTableQueryBrowser::executeDrop: what the hell did queryDrop do?"); @@ -137,7 +143,7 @@ namespace dbaui m_aAsyncDrop.nAction = _rEvt.mnAction; m_aAsyncDrop.bError = false; m_aAsyncDrop.bHtml = false; - m_aAsyncDrop.pDroppedAt = nullptr; + m_aAsyncDrop.xDroppedAt.reset(); m_aAsyncDrop.aUrl.clear(); // loop through the available formats and see what we can do ... @@ -145,7 +151,7 @@ namespace dbaui if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) ) { m_aAsyncDrop.aDroppedData = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData); - m_aAsyncDrop.pDroppedAt = pHitEntry; + m_aAsyncDrop.xDroppedAt = std::move(xHitEntry); // asynchron because we some dialogs and we aren't allowed to show them while in D&D m_nAsyncDrop = Application::PostUserEvent(LINK(this, SbaTableQueryBrowser, OnAsyncDrop)); @@ -154,12 +160,12 @@ namespace dbaui else { SharedConnection xDestConnection; - if ( ensureConnection( pHitEntry, xDestConnection ) + if ( ensureConnection( xHitEntry.get(), xDestConnection ) && xDestConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xDestConnection ) ) { - m_aAsyncDrop.pDroppedAt = pHitEntry; + m_aAsyncDrop.xDroppedAt = std::move(xHitEntry); // asynchron because we some dialogs and we aren't allowed to show them while in D&D m_nAsyncDrop = Application::PostUserEvent(LINK(this, SbaTableQueryBrowser, OnAsyncDrop)); @@ -170,54 +176,44 @@ namespace dbaui return DND_ACTION_NONE; } - bool SbaTableQueryBrowser::requestDrag( const Point& _rPosPixel ) + bool SbaTableQueryBrowser::requestDrag( const Point& /*rPosPixel*/ ) { - // get the affected list entry - // ensure that the entry which the user clicked at is selected - SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rPosPixel ); - if (!pHitEntry) - // no drag of no entry was hit... - return false; + return false; + } + bool SbaTableQueryBrowser::requestDrag(const weld::TreeIter& rEntry) + { // it must be a query/table - EntryType eEntryType = getEntryType( pHitEntry ); + EntryType eEntryType = getEntryType(rEntry); if (!isObject(eEntryType)) return false; - rtl::Reference<TransferableHelper> pTransfer = implCopyObject( pHitEntry, ( etTableOrView == eEntryType ) ? CommandType::TABLE : CommandType::QUERY); - - if (pTransfer) - pTransfer->StartDrag( &m_pTreeView->getListBox(), DND_ACTION_COPY ); - - return pTransfer.is(); - } - - bool SbaTableQueryBrowser::requestDrag(const weld::TreeIter& /*rEntry*/) - { - return false; + ODataClipboard& rExchange = m_pTreeView->getListBox().GetDataTransfer(); + return implCopyObject(rExchange, rEntry, (etTableOrView == eEntryType) ? CommandType::TABLE : CommandType::QUERY); } IMPL_LINK_NOARG(SbaTableQueryBrowser, OnCopyEntry, LinkParamNone*, void) { - SvTreeListEntry* pSelected = m_pTreeView->getListBox().FirstSelected(); - if( isEntryCopyAllowed( pSelected ) ) - copyEntry( pSelected ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xSelected = rTreeView.make_iterator(); + if (rTreeView.get_selected(xSelected.get()) && isEntryCopyAllowed(*xSelected)) + copyEntry(*xSelected); } - bool SbaTableQueryBrowser::isEntryCopyAllowed(SvTreeListEntry const * _pEntry) const + + bool SbaTableQueryBrowser::isEntryCopyAllowed(const weld::TreeIter& rEntry) const { - EntryType eType = getEntryType(_pEntry); + EntryType eType = getEntryType(rEntry); return ( eType == etTableOrView || eType == etQuery ); } - void SbaTableQueryBrowser::copyEntry(SvTreeListEntry* _pEntry) + + void SbaTableQueryBrowser::copyEntry(weld::TreeIter& rEntry) { - TransferableHelper* pTransfer = nullptr; - Reference< XTransferable> aEnsureDelete; - EntryType eType = getEntryType(_pEntry); - pTransfer = implCopyObject( _pEntry, eType == etQuery ? CommandType::QUERY : CommandType::TABLE); - aEnsureDelete = pTransfer; - if (pTransfer) - pTransfer->CopyToClipboard(getView()); + EntryType eType = getEntryType(rEntry); + rtl::Reference<ODataClipboard> xTransfer(new ODataClipboard); + if (implCopyObject(*xTransfer, rEntry, eType == etQuery ? CommandType::QUERY : CommandType::TABLE)) + xTransfer->CopyToClipboard(getView()); } + IMPL_LINK_NOARG( SbaTableQueryBrowser, OnAsyncDrop, void*, void ) { m_nAsyncDrop = nullptr; @@ -227,45 +223,42 @@ namespace dbaui if ( m_aAsyncDrop.nType == E_TABLE ) { SharedConnection xDestConnection; - if ( ensureConnection( m_aAsyncDrop.pDroppedAt, xDestConnection ) && xDestConnection.is() ) + if ( ensureConnection(m_aAsyncDrop.xDroppedAt.get(), xDestConnection) && xDestConnection.is()) { - SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(m_aAsyncDrop.pDroppedAt); - m_aTableCopyHelper.asyncCopyTagTable( m_aAsyncDrop, getDataSourceAccessor( pDataSourceEntry ), xDestConnection ); + std::unique_ptr<weld::TreeIter> xDataSourceEntry = + m_pTreeView->getListBox().GetRootLevelParent(m_aAsyncDrop.xDroppedAt.get()); + m_aTableCopyHelper.asyncCopyTagTable(m_aAsyncDrop, getDataSourceAccessor(*xDataSourceEntry), xDestConnection); } } m_aAsyncDrop.aDroppedData.clear(); } + void SbaTableQueryBrowser::clearTreeModel() { - if (m_pTreeView) - { - auto pTreeModel = m_pTreeView->GetTreeModel(); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + rTreeView.all_foreach([this, &rTreeView](weld::TreeIter& rEntryLoop){ // clear the user data of the tree model - SvTreeListEntry* pEntryLoop = pTreeModel->First(); - while (pEntryLoop) + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rEntryLoop).toUInt64()); + if (pData) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData()); - if(pData) - { - pEntryLoop->SetUserData(nullptr); - Reference< XContainer > xContainer(pData->xContainer, UNO_QUERY); - if (xContainer.is()) - xContainer->removeContainerListener(this); + rTreeView.set_id(rEntryLoop, OUString()); + Reference<XContainer> xContainer(pData->xContainer, UNO_QUERY); + if (xContainer.is()) + xContainer->removeContainerListener(this); - if ( pData->xConnection.is() ) - { - OSL_ENSURE( impl_isDataSourceEntry( pEntryLoop ), "SbaTableQueryBrowser::clearTreeModel: no data source entry, but a connection?" ); - // connections are to be stored *only* at the data source entries - impl_releaseConnection( pData->xConnection ); - } - - delete pData; + if (pData->xConnection.is()) + { + // connections are to be stored *only* at the data source entries + impl_releaseConnection(pData->xConnection); } - pEntryLoop = pTreeModel->Next(pEntryLoop); + + delete pData; } - } - m_pCurrentlyDisplayed = nullptr; + return false; + }); + + m_xCurrentlyDisplayed.reset(); } } // namespace dbaui diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx index 58f5b55ea940..a53ade551795 100644 --- a/dbaccess/source/ui/browser/genericcontroller.cxx +++ b/dbaccess/source/ui/browser/genericcontroller.cxx @@ -1146,10 +1146,6 @@ bool OGenericUnoController::isCommandEnabled(sal_uInt16 _nCommandId) const return GetState( _nCommandId ).bEnabled; } -void OGenericUnoController::notifyHiContrastChanged() -{ -} - bool OGenericUnoController::isDataSourceReadOnly() const { return false; diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index 4caa3f4cc31f..928764bb00fe 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -81,7 +81,6 @@ #include <cppuhelper/exc_hlp.hxx> #include <i18nlangtag/languagetag.hxx> #include <svl/filenotation.hxx> -#include <vcl/svlbitm.hxx> #include <vcl/treelistbox.hxx> #include <vcl/treelistentry.hxx> #include <svx/dataaccessdescriptor.hxx> @@ -171,7 +170,6 @@ SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XComponentContext >& ,m_aTableCopyHelper(this) ,m_pTreeView(nullptr) ,m_pSplitter(nullptr) - ,m_pCurrentlyDisplayed(nullptr) ,m_nAsyncDrop(nullptr) ,m_bQueryEscapeProcessing( false ) ,m_bShowMenu(false) @@ -317,9 +315,12 @@ bool SbaTableQueryBrowser::Construct(vcl::Window* pParent) getBrowserView()->setTreeView(m_pTreeView); // fill view with data - auto pTreeModel = m_pTreeView->GetTreeModel(); - pTreeModel->SetSortMode(SortAscending); - pTreeModel->SetCompareHdl(LINK(this, SbaTableQueryBrowser, OnTreeEntryCompare)); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + rTreeView.set_sort_order(true); + rTreeView.set_sort_func([this](const weld::TreeIter& rLeft, const weld::TreeIter& rRight){ + return OnTreeEntryCompare(rLeft, rRight); + }); + rTreeView.make_sorted(); m_pTreeView->setSelChangeHdl( LINK( this, SbaTableQueryBrowser, OnSelectionChange ) ); // TODO @@ -461,13 +462,14 @@ void SbaTableQueryBrowser::impl_sanitizeRowSetClauses_nothrow() bool SbaTableQueryBrowser::InitializeForm( const Reference< XPropertySet > & i_formProperties ) { - if(!m_pCurrentlyDisplayed) + if (!m_xCurrentlyDisplayed) return true; // this method set all format settings from the original table or query try { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData()); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); ENSURE_OR_RETURN_FALSE( pData, "SbaTableQueryBrowser::InitializeForm: No user data set at the currently displayed entry!" ); ENSURE_OR_RETURN_FALSE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeForm: No table available!" ); @@ -541,12 +543,13 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm if (xFormAsLoadable.is() && xFormAsLoadable->isLoaded()) { // set the formats from the table - if(m_pCurrentlyDisplayed) + if (m_xCurrentlyDisplayed) { Sequence< OUString> aProperties(6 + ( m_bPreview ? 5 : 0 )); Sequence< Any> aValues(7 + ( m_bPreview ? 5 : 0 )); - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData()); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" ); if ( !pData->xObjectProperties.is() ) return; @@ -751,16 +754,18 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm } } -static Reference<XPropertySet> getColumnHelper(SvTreeListEntry const * _pCurrentlyDisplayed, const Reference<XPropertySet>& _rxSource) +static Reference<XPropertySet> getColumnHelper(const weld::TreeView& rTreeView, + const weld::TreeIter* pCurrentlyDisplayed, + const Reference<XPropertySet>& rxSource) { Reference<XPropertySet> xRet; - if(_pCurrentlyDisplayed) + if (pCurrentlyDisplayed) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pCurrentlyDisplayed->GetUserData()); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pCurrentlyDisplayed).toUInt64()); Reference<XColumnsSupplier> xColumnsSup(pData->xObjectProperties,UNO_QUERY); Reference<XNameAccess> xNames = xColumnsSup->getColumns(); OUString aName; - _rxSource->getPropertyValue(PROPERTY_NAME) >>= aName; + rxSource->getPropertyValue(PROPERTY_NAME) >>= aName; if(xNames.is() && xNames->hasByName(aName)) xRet.set(xNames->getByName(aName),UNO_QUERY); } @@ -769,9 +774,10 @@ static Reference<XPropertySet> getColumnHelper(SvTreeListEntry const * _pCurrent void SbaTableQueryBrowser::transferChangedControlProperty(const OUString& _rProperty, const Any& _rNewValue) { - if(m_pCurrentlyDisplayed) + if (m_xCurrentlyDisplayed) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData()); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); Reference< XPropertySet > xObjectProps = pData->xObjectProperties; OSL_ENSURE(xObjectProps.is(),"SbaTableQueryBrowser::transferChangedControlProperty: no table/query object!"); if (xObjectProps.is()) @@ -783,18 +789,19 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) { SbaXDataBrowserController::propertyChange(evt); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + try { Reference< XPropertySet > xSource(evt.Source, UNO_QUERY); if (!xSource.is()) return; - // one of the many properties which require us to update the definition ? // a column's width ? else if (evt.PropertyName == PROPERTY_WIDTH) { // a column width has changed -> update the model // (the update of the view is done elsewhere) - Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource); + Reference<XPropertySet> xProp = getColumnHelper(rTreeView, m_xCurrentlyDisplayed.get(), xSource); if(xProp.is()) { if(!evt.NewValue.hasValue()) @@ -807,7 +814,7 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) // a column's 'visible' state ? else if (evt.PropertyName == PROPERTY_HIDDEN) { - Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource); + Reference<XPropertySet> xProp = getColumnHelper(rTreeView, m_xCurrentlyDisplayed.get(), xSource); if(xProp.is()) xProp->setPropertyValue(PROPERTY_HIDDEN,evt.NewValue); } @@ -815,7 +822,7 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) // a columns alignment ? else if (evt.PropertyName == PROPERTY_ALIGN) { - Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource); + Reference<XPropertySet> xProp = getColumnHelper(rTreeView, m_xCurrentlyDisplayed.get(), xSource); try { if(xProp.is()) @@ -844,7 +851,7 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) ) { // update the model (means the definition object) - Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource); + Reference<XPropertySet> xProp = getColumnHelper(rTreeView, m_xCurrentlyDisplayed.get(), xSource); if(xProp.is()) xProp->setPropertyValue(PROPERTY_FORMATKEY,evt.NewValue); } @@ -853,9 +860,9 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) // the height of the rows in the grid ? else if (evt.PropertyName == PROPERTY_ROW_HEIGHT) { - if(m_pCurrentlyDisplayed) + if (m_xCurrentlyDisplayed) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData()); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); OSL_ENSURE( pData->xObjectProperties.is(), "No table available!" ); bool bDefault = !evt.NewValue.hasValue(); @@ -959,17 +966,20 @@ void SAL_CALL SbaTableQueryBrowser::statusChanged( const FeatureStateEvent& _rEv void SbaTableQueryBrowser::checkDocumentDataSource() { - SvTreeListEntry* pDataSourceEntry = nullptr; - SvTreeListEntry* pContainerEntry = nullptr; - SvTreeListEntry* pObjectEntry = getObjectEntry( m_aDocumentDataSource, &pDataSourceEntry, &pContainerEntry ); - bool bKnownDocDataSource = (nullptr != pObjectEntry); + std::unique_ptr<weld::TreeIter> xDataSourceEntry; + std::unique_ptr<weld::TreeIter> xContainerEntry; + std::unique_ptr<weld::TreeIter> xObjectEntry = getObjectEntry(m_aDocumentDataSource, &xDataSourceEntry, &xContainerEntry); + bool bKnownDocDataSource = static_cast<bool>(xObjectEntry); if (!bKnownDocDataSource) { - if (nullptr != pDataSourceEntry) - { // at least the data source is known - if (nullptr != pContainerEntry) + if (xDataSourceEntry) + { + // at least the data source is known + if (xContainerEntry) + { bKnownDocDataSource = true; // assume we know it. // TODO: should we expand the object container? This may be too expensive just for checking... + } else { if (m_aDocumentDataSource.has(DataAccessDescriptorProperty::CommandType) @@ -1041,26 +1051,25 @@ namespace } } -OUString SbaTableQueryBrowser::getDataSourceAccessor( SvTreeListEntry* _pDataSourceEntry ) const +OUString SbaTableQueryBrowser::getDataSourceAccessor(const weld::TreeIter& rDataSourceEntry) const { - OSL_ENSURE( _pDataSourceEntry, "SbaTableQueryBrowser::getDataSourceAccessor: invalid entry!" ); - - DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pDataSourceEntry->GetUserData() ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rDataSourceEntry).toUInt64()); OSL_ENSURE( pData, "SbaTableQueryBrowser::getDataSourceAccessor: invalid entry data!" ); OSL_ENSURE( pData->eType == etDatasource, "SbaTableQueryBrowser::getDataSourceAccessor: entry does not denote a data source!" ); - return !pData->sAccessor.isEmpty() ? pData->sAccessor : GetEntryText( _pDataSourceEntry ); + return !pData->sAccessor.isEmpty() ? pData->sAccessor : GetEntryText(rDataSourceEntry); } -SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSource, const OUString& _rCommand, sal_Int32 _nCommandType, - SvTreeListEntry** _ppDataSourceEntry, SvTreeListEntry** _ppContainerEntry, bool _bExpandAncestors, +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSource, const OUString& _rCommand, sal_Int32 nCommandType, + std::unique_ptr<weld::TreeIter>* ppDataSourceEntry, std::unique_ptr<weld::TreeIter>* ppContainerEntry, bool bExpandAncestors, const SharedConnection& _rxConnection ) { - if (_ppDataSourceEntry) - *_ppDataSourceEntry = nullptr; - if (_ppContainerEntry) - *_ppContainerEntry = nullptr; + if (ppDataSourceEntry) + ppDataSourceEntry->reset(); + if (ppContainerEntry) + ppContainerEntry->reset(); - SvTreeListEntry* pObject = nullptr; + std::unique_ptr<weld::TreeIter> xObject; if ( m_pTreeView ) { // look for the data source entry @@ -1070,50 +1079,64 @@ SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSour // #i33699# FilterByEntryDataId aFilter( sDataSourceId ); - SvTreeListEntry* pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, nullptr, &aFilter ); - if ( !pDataSource ) // check if the data source name is a file location + std::unique_ptr<weld::TreeIter> xDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, nullptr, &aFilter ); + if (!xDataSource) // check if the data source name is a file location { if ( bIsDataSourceURL ) { // special case, the data source is a URL // add new entries to the list box model implAddDatasource( _rDataSource, _rxConnection ); - pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, nullptr, &aFilter ); - OSL_ENSURE( pDataSource, "SbaTableQueryBrowser::getObjectEntry: hmm - did not find it again!" ); + xDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, nullptr, &aFilter ); + OSL_ENSURE( xDataSource, "SbaTableQueryBrowser::getObjectEntry: hmm - did not find it again!" ); } } - if (_ppDataSourceEntry) + + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + + if (ppDataSourceEntry) + { // (caller wants to have it...) - *_ppDataSourceEntry = pDataSource; + *ppDataSourceEntry = rTreeView.make_iterator(xDataSource.get()); + } - if (pDataSource) + if (xDataSource) { // expand if required so - if (_bExpandAncestors) - m_pTreeView->getListBox().Expand(pDataSource); + if (bExpandAncestors) + rTreeView.expand_row(*xDataSource); // look for the object container - SvTreeListEntry* pCommandType = nullptr; - switch (_nCommandType) + std::unique_ptr<weld::TreeIter> xCommandType; + if (nCommandType == CommandType::QUERY || nCommandType == CommandType::TABLE) { - case CommandType::TABLE: - pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_TABLES); - break; + xCommandType = rTreeView.make_iterator(xDataSource.get()); + if (!rTreeView.iter_children(*xCommandType)) + xCommandType.reset(); + else + { + // 1st child is queries, so we're already done if looking for CommandType::QUERY - case CommandType::QUERY: - pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_QUERIES); - break; + // 2nd child is tables + if (nCommandType == CommandType::TABLE && !rTreeView.iter_next_sibling(*xCommandType)) + xCommandType.reset(); + } } - if (_ppContainerEntry) - *_ppContainerEntry = pCommandType; + if (ppContainerEntry) + { + // (caller wants to have it...) + *ppContainerEntry = rTreeView.make_iterator(xCommandType.get()); + } - if (pCommandType) + if (xCommandType) { + rTreeView.make_unsorted(); + // expand if required so - if (_bExpandAncestors) + if (bExpandAncestors) { - m_pTreeView->getListBox().Expand(pCommandType); + rTreeView.expand_row(*xCommandType); } // look for the object @@ -1121,7 +1144,7 @@ SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSour do { OUString sPath; - switch (_nCommandType) + switch (nCommandType) { case CommandType::TABLE: sPath = _rCommand; @@ -1135,13 +1158,13 @@ SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSour default: assert(false); } - pObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, pCommandType); - pCommandType = pObject; + xObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, xCommandType.get()); + rTreeView.copy_iterator(*xObject, *xCommandType); if ( nIndex >= 0 ) { - if (ensureEntryObject(pObject)) + if (ensureEntryObject(*xObject)) { - DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( pObject->GetUserData() ); + DBTreeListUserData* pParentData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xObject).toUInt64()); Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY ); sal_Int32 nIndex2 = nIndex; sPath = _rCommand.getToken( 0, '/', nIndex2 ); @@ -1149,7 +1172,7 @@ SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSour { if ( xCollection->hasByName(sPath) ) { - if(!m_pTreeView->getListBox().GetEntryPosByName(sPath,pObject)) + if(!m_pTreeView->getListBox().GetEntryPosByName(sPath, xObject.get())) { Reference<XNameAccess> xChild(xCollection->getByName(sPath),UNO_QUERY); DBTreeListUserData* pEntryData = new DBTreeListUserData; @@ -1158,7 +1181,7 @@ SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSour { pEntryData->eType = etQueryContainer; } - implAppendEntry( pObject, sPath, pEntryData, pEntryData->eType ); + implAppendEntry(xObject.get(), sPath, pEntryData, pEntryData->eType); } } } @@ -1170,23 +1193,25 @@ SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const OUString& _rDataSour } } while ( nIndex >= 0 ); + + rTreeView.make_sorted(); } } } - return pObject; + return xObject; } -SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const svx::ODataAccessDescriptor& _rDescriptor, - SvTreeListEntry** _ppDataSourceEntry, SvTreeListEntry** _ppContainerEntry) +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getObjectEntry(const svx::ODataAccessDescriptor& rDescriptor, + std::unique_ptr<weld::TreeIter>* ppDataSourceEntry, std::unique_ptr<weld::TreeIter>* ppContainerEntry) { // extract the props from the descriptor OUString sDataSource; OUString sCommand; sal_Int32 nCommandType = CommandType::COMMAND; bool bEscapeProcessing = true; - extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing); + extractDescriptorProps(rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing); - return getObjectEntry( sDataSource, sCommand, nCommandType, _ppDataSourceEntry, _ppContainerEntry, false/*_bExpandAncestors*/ ); + return getObjectEntry(sDataSource, sCommand, nCommandType, ppDataSourceEntry, ppContainerEntry, false /*bExpandAncestors*/); } void SbaTableQueryBrowser::connectExternalDispatches() @@ -1307,22 +1332,26 @@ void SAL_CALL SbaTableQueryBrowser::disposing( const css::lang::EventObject& _rS { Reference<XConnection> xCon(_rSource.Source, UNO_QUERY); if ( xCon.is() && m_pTreeView ) - { // our connection is in dispose so we have to find the entry equal with this connection + { + // our connection is in dispose so we have to find the entry equal with this connection // and close it what means to collapse the entry // get the top-level representing the removed data source - SvTreeListEntry* pDSLoop = m_pTreeView->getListBox().FirstChild(nullptr); - while (pDSLoop) + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xDSLoop(rTreeView.make_iterator()); + if (rTreeView.get_iter_first(*xDSLoop)) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pDSLoop->GetUserData()); - if ( pData && pData->xConnection == xCon ) + do { - // we set the connection to null to avoid a second disposing of the connection - pData->xConnection.clear(); - closeConnection(pDSLoop,false); - break; + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDSLoop).toUInt64()); + if ( pData && pData->xConnection == xCon ) + { + // we set the connection to null to avoid a second disposing of the connection + pData->xConnection.clear(); + closeConnection(*xDSLoop, false); + break; + } } - - pDSLoop = pDSLoop->NextSibling(); + while (rTreeView.iter_next_sibling(*xDSLoop)); } } else @@ -1601,15 +1630,19 @@ FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const case ID_TREE_CLOSE_CONN: case ID_TREE_EDIT_DATABASE: { - SvTreeListEntry* pCurrentEntry( m_pTreeView->getListBox().GetCurEntry() ); - EntryType eType = getEntryType( pCurrentEntry ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xCurrentEntry(rTreeView.make_iterator()); + if (!rTreeView.get_cursor(xCurrentEntry.get())) + return aReturn; + + EntryType eType = getEntryType(*xCurrentEntry); if ( eType == etUnknown ) return aReturn; - SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent( pCurrentEntry ); + std::unique_ptr<weld::TreeIter> xDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(xCurrentEntry.get()); DBTreeListUserData* pDSData - = pDataSourceEntry - ? static_cast< DBTreeListUserData* >( pDataSourceEntry->GetUserData() ) + = xDataSourceEntry + ? reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDataSourceEntry).toUInt64()) : nullptr; if ( nId == ID_TREE_CLOSE_CONN ) @@ -1622,11 +1655,11 @@ FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const "/org.openoffice.Office.DataAccess/Policies/Features/Common" ) ); bool bHaveEditDatabase( true ); OSL_VERIFY( aConfig.getNodeValue( "EditDatabaseFromDataSourceView" ) >>= bHaveEditDatabase ); - aReturn.bEnabled = getORB().is() && ( pDataSourceEntry != nullptr ) && bHaveEditDatabase; + aReturn.bEnabled = getORB().is() && xDataSourceEntry && bHaveEditDatabase; } else if ( nId == ID_BROWSER_COPY ) { - aReturn.bEnabled = isEntryCopyAllowed( pCurrentEntry ); + aReturn.bEnabled = isEntryCopyAllowed(*xCurrentEntry); } return aReturn; @@ -1769,13 +1802,24 @@ void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue break; case ID_TREE_EDIT_DATABASE: - implAdministrate( m_pTreeView->getListBox().GetCurEntry() ); + { + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xIter(rTreeView.make_iterator()); + if (rTreeView.get_cursor(xIter.get())) + implAdministrate(*xIter); break; - + } case ID_TREE_CLOSE_CONN: - closeConnection( m_pTreeView->getListBox().GetRootLevelParent( m_pTreeView->getListBox().GetCurEntry() ) ); + { + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xIter(rTreeView.make_iterator()); + if (rTreeView.get_cursor(xIter.get())) + { + xIter = m_pTreeView->getListBox().GetRootLevelParent(xIter.get()); + closeConnection(*xIter); + } break; - + } case ID_TREE_ADMINISTRATE: svx::administrateDatabaseRegistration( getFrameWeld() ); break; @@ -1814,14 +1858,17 @@ void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue // nothing to do break; - SvTreeListEntry* pSelected = m_pCurrentlyDisplayed; + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xSelected = m_xCurrentlyDisplayed ? + rTreeView.make_iterator(m_xCurrentlyDisplayed.get()) : nullptr; + // unload unloadAndCleanup( false ); // reselect the entry - if ( pSelected ) + if ( xSelected ) { - implSelect( pSelected ); + implSelect(xSelected.get()); } else { @@ -1932,7 +1979,10 @@ void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue case ID_BROWSER_COPY: if(m_pTreeView->HasChildPathFocus()) { - copyEntry(m_pTreeView->getListBox().GetCurEntry()); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xCursor(rTreeView.make_iterator()); + if (rTreeView.get_cursor(xCursor.get())) + copyEntry(*xCursor); } else if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing() && getBrowserView()->getVclControl()->GetSelectRowCount() < 1) { @@ -1947,13 +1997,12 @@ void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue void SbaTableQueryBrowser::implAddDatasource( const OUString& _rDataSourceName, const SharedConnection& _rxConnection ) { - Image a, b, c; - OUString d, e; + OUString a, b, c, d, e; implAddDatasource( _rDataSourceName, a, d, b, e, c, _rxConnection ); } -void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, Image& _rDbImage, - OUString& _rQueryName, Image& _rQueryImage, OUString& _rTableName, Image& _rTableImage, +void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, OUString& _rDbImage, + OUString& _rQueryName, OUString& _rQueryImage, OUString& _rTableName, OUString& _rTableImage, const SharedConnection& _rxConnection) { SolarMutexGuard aGuard; @@ -1963,12 +2012,12 @@ void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, Image& _r if (_rTableName.isEmpty()) _rTableName = DBA_RES(RID_STR_TABLES_CONTAINER); - if (!_rQueryImage) - _rQueryImage = ImageProvider::getFolderImage( DatabaseObject::QUERY ); - if (!_rTableImage) - _rTableImage = ImageProvider::getFolderImage( DatabaseObject::TABLE ); + if (_rQueryImage.isEmpty()) + _rQueryImage = ImageProvider::getFolderImageId(DatabaseObject::QUERY); + if (_rTableImage.isEmpty()) + _rTableImage = ImageProvider::getFolderImageId(DatabaseObject::TABLE); - if (!_rDbImage) + if (_rDbImage.isEmpty()) _rDbImage = ImageProvider::getDatabaseImage(); // add the entry for the data source @@ -1977,40 +2026,50 @@ void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, Image& _r OUString sDSDisplayName, sDataSourceId; getDataSourceDisplayName_isURL( _rDbName, sDSDisplayName, sDataSourceId ); - SvTreeListEntry* pDatasourceEntry = m_pTreeView->getListBox().InsertEntry( sDSDisplayName, _rDbImage, _rDbImage ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); DBTreeListUserData* pDSData = new DBTreeListUserData; pDSData->eType = etDatasource; pDSData->sAccessor = sDataSourceId; pDSData->xConnection = _rxConnection; - pDatasourceEntry->SetUserData(pDSData); + OUString sId(OUString::number(reinterpret_cast<sal_uInt64>(pDSData))); + + std::unique_ptr<weld::TreeIter> xDatasourceEntry(rTreeView.make_iterator()); + rTreeView.insert(nullptr, -1, &sDSDisplayName, &sId, nullptr, nullptr, false, xDatasourceEntry.get()); + rTreeView.set_image(*xDatasourceEntry, _rDbImage); + rTreeView.set_text_emphasis(*xDatasourceEntry, false, 0); // the child for the queries container { DBTreeListUserData* pQueriesData = new DBTreeListUserData; pQueriesData->eType = etQueryContainer; + sId = OUString::number(reinterpret_cast<sal_uInt64>(pQueriesData)); - m_pTreeView->getListBox().InsertEntry( - _rQueryName, _rQueryImage, _rQueryImage, pDatasourceEntry, - true /*ChildrenOnDemand*/, TREELIST_APPEND, pQueriesData ); + std::unique_ptr<weld::TreeIter> xRet(rTreeView.make_iterator()); + rTreeView.insert(xDatasourceEntry.get(), -1, &_rQueryName, &sId, + nullptr, nullptr, true /*ChildrenOnDemand*/, xRet.get()); + rTreeView.set_image(*xRet, _rQueryImage); + rTreeView.set_text_emphasis(*xRet, false, 0); } // the child for the tables container { DBTreeListUserData* pTablesData = new DBTreeListUserData; pTablesData->eType = etTableContainer; + sId = OUString::number(reinterpret_cast<sal_uInt64>(pTablesData)); - m_pTreeView->getListBox().InsertEntry( - _rTableName, _rTableImage, _rTableImage, pDatasourceEntry, - true /*ChildrenOnDemand*/, TREELIST_APPEND, pTablesData ); + std::unique_ptr<weld::TreeIter> xRet(rTreeView.make_iterator()); + rTreeView.insert(xDatasourceEntry.get(), -1, &_rTableName, &sId, + nullptr, nullptr, true /*ChildrenOnDemand*/, xRet.get()); + rTreeView.set_image(*xRet, _rTableImage); + rTreeView.set_text_emphasis(*xRet, false, 0); } - } void SbaTableQueryBrowser::initializeTreeModel() { if (m_xDatabaseContext.is()) { - Image aDBImage, aQueriesImage, aTablesImage; + OUString aDBImage, aQueriesImage, aTablesImage; OUString sQueriesName, sTablesName; // fill the model with the names of the registered datasources @@ -2021,11 +2080,14 @@ void SbaTableQueryBrowser::initializeTreeModel() } void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess, - SvTreeListEntry* _pParent, - EntryType _eEntryType) + const weld::TreeIter& rParent, + EntryType eEntryType) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pParent->GetUserData()); - if(pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + rTreeView.make_unsorted(); + + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rParent).toUInt64()); + if (pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables pData->xContainer = _xNameAccess; try @@ -2033,17 +2095,17 @@ void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAcce const Sequence<OUString> aNames = _xNameAccess->getElementNames(); for (const OUString& rName : aNames) { - if( !m_pTreeView->getListBox().GetEntryPosByName(rName,_pParent)) + if( !m_pTreeView->getListBox().GetEntryPosByName(rName, &rParent)) { DBTreeListUserData* pEntryData = new DBTreeListUserData; - pEntryData->eType = _eEntryType; - if ( _eEntryType == etQuery ) + pEntryData->eType = eEntryType; + if ( eEntryType == etQuery ) { Reference<XNameAccess> xChild(_xNameAccess->getByName(rName),UNO_QUERY); if ( xChild.is() ) pEntryData->eType = etQueryContainer; } - implAppendEntry( _pParent, rName, pEntryData, pEntryData->eType ); + implAppendEntry(&rParent, rName, pEntryData, pEntryData->eType); } } } @@ -2051,38 +2113,40 @@ void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAcce { SAL_WARN("dbaccess.ui", "SbaTableQueryBrowser::populateTree: could not fill the tree"); } + + rTreeView.make_sorted(); } -SvTreeListEntry* SbaTableQueryBrowser::implAppendEntry( SvTreeListEntry* _pParent, const OUString& _rName, void* _pUserData, EntryType _eEntryType ) +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::implAppendEntry(const weld::TreeIter* pParent, const OUString& rName, void* pUserData, EntryType eEntryType) { - std::unique_ptr< ImageProvider > pImageProvider( getImageProviderFor( _pParent ) ); + std::unique_ptr<ImageProvider> xImageProvider(getImageProviderFor(pParent)); - Image aImage; - pImageProvider->getImages( _rName, getDatabaseObjectType( _eEntryType ), aImage ); + OUString aImage = xImageProvider->getImageId(rName, getDatabaseObjectType(eEntryType)); - SvTreeListEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, _eEntryType == etQueryContainer , TREELIST_APPEND, _pUserData ); + OUString sId(OUString::number(reinterpret_cast<sal_uInt64>(pUserData))); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xNewEntry(rTreeView.make_iterator()); + rTreeView.insert(pParent, -1, &rName, &sId, nullptr, nullptr, eEntryType == etQueryContainer, xNewEntry.get()); + rTreeView.set_image(*xNewEntry, aImage); + rTreeView.set_text_emphasis(*xNewEntry, false, 0); - m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImage ); - m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImage ); - - return pNewEntry; + return xNewEntry; } -IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvTreeListEntry*, _pParent, bool) +IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, const weld::TreeIter&, rParent, bool) { - if (_pParent->HasChildren()) + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + if (rTreeView.iter_has_child(rParent)) + { // nothing to do... return true; + } - SvTreeListEntry* pFirstParent = m_pTreeView->getListBox().GetRootLevelParent(_pParent); - OSL_ENSURE(pFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!"); + std::unique_ptr<weld::TreeIter> xFirstParent = m_pTreeView->getListBox().GetRootLevelParent(&rParent); + OSL_ENSURE(xFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!"); - DBTreeListUserData* pData = static_cast< DBTreeListUserData* >(_pParent->GetUserData()); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rParent).toInt64()); assert(pData && "SbaTableQueryBrowser::OnExpandEntry: No user data!"); -#if OSL_DEBUG_LEVEL > 0 - SvLBoxString* pString = static_cast<SvLBoxString*>(pFirstParent->GetFirstItem(SvLBoxItemType::String)); - OSL_ENSURE(pString,"SbaTableQueryBrowser::OnExpandEntry: No string item!"); -#endif if (etTableContainer == pData->eType) { @@ -2090,7 +2154,7 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvTreeListEntry*, _pParent, bool) // it could be that we already have a connection SharedConnection xConnection; - ensureConnection( pFirstParent, xConnection ); + ensureConnection(xFirstParent.get(), xConnection); if ( xConnection.is() ) { @@ -2106,12 +2170,12 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvTreeListEntry*, _pParent, bool) // the nameaccess will be overwritten in populateTree Reference<XViewsSupplier> xViewSup(xConnection,UNO_QUERY); if(xViewSup.is()) - populateTree( xViewSup->getViews(), _pParent, etTableOrView ); + populateTree( xViewSup->getViews(), rParent, etTableOrView ); Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY); if(xTabSup.is()) { - populateTree( xTabSup->getTables(), _pParent, etTableOrView ); + populateTree( xTabSup->getTables(), rParent, etTableOrView ); Reference<XContainer> xCont(xTabSup->getTables(),UNO_QUERY); if(xCont.is()) // add as listener to know when elements are inserted or removed @@ -2165,35 +2229,34 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvTreeListEntry*, _pParent, bool) // 0 indicates that an error occurred } else - { // we have to expand the queries or bookmarks - if (ensureEntryObject(_pParent)) + { + // we have to expand the queries or bookmarks + if (ensureEntryObject(rParent)) { - DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( _pParent->GetUserData() ); + DBTreeListUserData* pParentData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rParent).toUInt64()); Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY ); - populateTree( xCollection, _pParent, etQuery ); + populateTree(xCollection, rParent, etQuery); } } return true; } -bool SbaTableQueryBrowser::ensureEntryObject( SvTreeListEntry* _pEntry ) +bool SbaTableQueryBrowser::ensureEntryObject(const weld::TreeIter& rEntry) { - OSL_ENSURE(_pEntry, "SbaTableQueryBrowser::ensureEntryObject: invalid argument!"); - if (!_pEntry) - return false; - - EntryType eType = getEntryType( _pEntry ); + EntryType eType = getEntryType(rEntry); // the user data of the entry - DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData()); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rEntry).toUInt64()); OSL_ENSURE(pEntryData,"ensureEntryObject: user data should already be set!"); - SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry); + std::unique_ptr<weld::TreeIter> xDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(&rEntry); bool bSuccess = false; switch (eType) { case etQueryContainer: + { if ( pEntryData->xContainer.is() ) { // nothing to do @@ -2201,14 +2264,13 @@ bool SbaTableQueryBrowser::ensureEntryObject( SvTreeListEntry* _pEntry ) break; } + std::unique_ptr<weld::TreeIter> xParent(rTreeView.make_iterator(&rEntry)); + if (rTreeView.iter_parent(*xParent)) { - SvTreeListEntry* pParent = m_pTreeView->getListBox().GetParent(_pEntry); - if ( pParent != pDataSourceEntry ) + if (rTreeView.iter_compare(*xParent, *xDataSourceEntry) != 0) { - SvLBoxString* pString = static_cast<SvLBoxString*>(_pEntry->GetFirstItem(SvLBoxItemType::String)); - OSL_ENSURE(pString,"There must be a string item!"); - OUString aName(pString->GetText()); - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pParent->GetUserData()); + OUString aName(rTreeView.get_text(rEntry)); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xParent).toUInt64()); try { Reference< XNameAccess > xNameAccess(pData->xContainer,UNO_QUERY); @@ -2227,7 +2289,7 @@ bool SbaTableQueryBrowser::ensureEntryObject( SvTreeListEntry* _pEntry ) try { Reference< XQueryDefinitionsSupplier > xQuerySup; - m_xDatabaseContext->getByName( getDataSourceAccessor( pDataSourceEntry ) ) >>= xQuerySup; + m_xDatabaseContext->getByName(getDataSourceAccessor(*xDataSourceEntry)) >>= xQuerySup; if (xQuerySup.is()) { Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions(); @@ -2250,13 +2312,12 @@ bool SbaTableQueryBrowser::ensureEntryObject( SvTreeListEntry* _pEntry ) } } break; - + } default: SAL_WARN("dbaccess.ui", "SbaTableQueryBrowser::ensureEntryObject: ooops ... missing some implementation here!"); // TODO ... break; } - return bSuccess; } @@ -2274,7 +2335,7 @@ bool SbaTableQueryBrowser::implSelect(const svx::ODataAccessDescriptor& _rDescri } bool SbaTableQueryBrowser::implLoadAnything(const OUString& _rDataSourceName, const OUString& _rCommand, - const sal_Int32 _nCommandType, const bool _bEscapeProcessing, const SharedConnection& _rxConnection) + const sal_Int32 nCommandType, const bool _bEscapeProcessing, const SharedConnection& _rxConnection) { try { @@ -2286,7 +2347,7 @@ bool SbaTableQueryBrowser::implLoadAnything(const OUString& _rDataSourceName, co xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( _rxConnection.getTyped() ) ); // set this _before_ setting the connection, else the rowset would rebuild it ... - xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, makeAny(_nCommandType)); + xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, makeAny(nCommandType)); xProp->setPropertyValue(PROPERTY_COMMAND, makeAny(_rCommand)); xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, css::uno::makeAny(_bEscapeProcessing)); if ( m_bPreview ) @@ -2357,44 +2418,47 @@ bool SbaTableQueryBrowser::implLoadAnything(const OUString& _rDataSourceName, co } bool SbaTableQueryBrowser::implSelect(const OUString& _rDataSourceName, const OUString& _rCommand, - const sal_Int32 _nCommandType, const bool _bEscapeProcessing, + const sal_Int32 nCommandType, const bool _bEscapeProcessing, const SharedConnection& _rxConnection, bool _bSelectDirect) { - if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != _nCommandType)) + if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != nCommandType)) { - SvTreeListEntry* pDataSource = nullptr; - SvTreeListEntry* pCommandType = nullptr; - SvTreeListEntry* pCommand = getObjectEntry( _rDataSourceName, _rCommand, _nCommandType, &pDataSource, &pCommandType, true, _rxConnection ); + std::unique_ptr<weld::TreeIter> xDataSource; + std::unique_ptr<weld::TreeIter> xCommandType; + std::unique_ptr<weld::TreeIter> xCommand = getObjectEntry( _rDataSourceName, _rCommand, nCommandType, &xDataSource, &xCommandType, true, _rxConnection ); - if (pCommand) + if (xCommand) { + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + bool bSuccess = true; if ( _bSelectDirect ) { - bSuccess = implSelect( pCommand ); + bSuccess = implSelect(xCommand.get()); } else { - m_pTreeView->getListBox().Select( pCommand ); + rTreeView.select(*xCommand); } if ( bSuccess ) { - m_pTreeView->getListBox().MakeVisible(pCommand); - m_pTreeView->getListBox().SetCursor(pCommand); + rTreeView.scroll_to_row(*xCommand); + rTreeView.set_cursor(*xCommand); } } - else if (!pCommandType) + else if (!xCommandType) { - if ( m_pCurrentlyDisplayed ) - { // tell the old entry (if any) it has been deselected - selectPath(m_pCurrentlyDisplayed, false); - m_pCurrentlyDisplayed = nullptr; + if (m_xCurrentlyDisplayed) + { + // tell the old entry (if any) it has been deselected + selectPath(m_xCurrentlyDisplayed.get(), false); + m_xCurrentlyDisplayed.reset(); } // we have a command and need to display this in the rowset - return implLoadAnything(_rDataSourceName, _rCommand, _nCommandType, _bEscapeProcessing, _rxConnection); + return implLoadAnything(_rDataSourceName, _rCommand, nCommandType, _bEscapeProcessing, _rxConnection); } } return false; @@ -2402,27 +2466,33 @@ bool SbaTableQueryBrowser::implSelect(const OUString& _rDataSourceName, const OU IMPL_LINK_NOARG(SbaTableQueryBrowser, OnSelectionChange, LinkParamNone*, void) { - implSelect( m_pTreeView->getListBox().FirstSelected() ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xSelection(rTreeView.make_iterator()); + if (!rTreeView.get_selected(xSelection.get())) + xSelection.reset(); + implSelect(xSelection.get()); } -SvTreeListEntry* SbaTableQueryBrowser::implGetConnectionEntry(SvTreeListEntry* _pEntry) const +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::implGetConnectionEntry(weld::TreeIter& rEntry) const { - SvTreeListEntry* pCurrentEntry = _pEntry; - DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() ); - while(pEntryData->eType != etDatasource ) + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xCurrentEntry(rTreeView.make_iterator(&rEntry)); + DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xCurrentEntry).toInt64()); + while (pEntryData->eType != etDatasource) { - pCurrentEntry = m_pTreeView->GetTreeModel()->GetParent(pCurrentEntry); - pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() ); + rTreeView.iter_parent(*xCurrentEntry); + pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xCurrentEntry).toInt64()); } - return pCurrentEntry; + return xCurrentEntry; } -bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) +bool SbaTableQueryBrowser::implSelect(weld::TreeIter* pEntry) { - if ( !_pEntry ) + if ( !pEntry ) return false; - DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pEntry).toUInt64()); switch (pEntryData->eType) { case etTableOrView: @@ -2433,16 +2503,16 @@ bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) return false; } - OSL_ENSURE(m_pTreeView->GetTreeModel()->HasParent(_pEntry), "SbaTableQueryBrowser::implSelect: invalid entry (1)!"); - OSL_ENSURE(m_pTreeView->GetTreeModel()->HasParent(m_pTreeView->GetTreeModel()->GetParent(_pEntry)), "SbaTableQueryBrowser::implSelect: invalid entry (2)!"); + OSL_ENSURE(rTreeView.get_iter_depth(*pEntry) >= 2, "SbaTableQueryBrowser::implSelect: invalid entry!"); // get the entry for the tables or queries - SvTreeListEntry* pContainer = m_pTreeView->GetTreeModel()->GetParent(_pEntry); - DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pContainer->GetUserData()); + std::unique_ptr<weld::TreeIter> xContainer = rTreeView.make_iterator(pEntry); + rTreeView.iter_parent(*xContainer); + DBTreeListUserData* pContainerData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xContainer).toUInt64()); // get the entry for the datasource - SvTreeListEntry* pConnection = implGetConnectionEntry(pContainer); - DBTreeListUserData* pConData = static_cast<DBTreeListUserData*>(pConnection->GetUserData()); + std::unique_ptr<weld::TreeIter> xConnection = implGetConnectionEntry(*xContainer); + DBTreeListUserData* pConData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xConnection).toUInt64()); // reinitialize the rowset // but first check if it is necessary @@ -2455,20 +2525,22 @@ bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) Reference<XConnection> xOldConnection(xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY); // the name of the table or query - SvLBoxString* pString = static_cast<SvLBoxString*>(_pEntry->GetFirstItem(SvLBoxItemType::String)); - OSL_ENSURE(pString,"There must be a string item!"); - const OUString sSimpleName = pString->GetText(); + const OUString sSimpleName = rTreeView.get_text(*pEntry); OUStringBuffer sNameBuffer(sSimpleName); if ( etQueryContainer == pContainerData->eType ) { - SvTreeListEntry* pTemp = pContainer; - while( m_pTreeView->GetTreeModel()->GetParent(pTemp) != pConnection ) + std::unique_ptr<weld::TreeIter> xTemp = rTreeView.make_iterator(xContainer.get()); + std::unique_ptr<weld::TreeIter> xNextTemp = rTreeView.make_iterator(xTemp.get()); + if (rTreeView.iter_parent(*xNextTemp)) { - sNameBuffer.insert(0,'/'); - pString = static_cast<SvLBoxString*>(pTemp->GetFirstItem(SvLBoxItemType::String)); - OSL_ENSURE(pString,"There must be a string item!"); - sNameBuffer.insert(0,pString->GetText()); - pTemp = m_pTreeView->GetTreeModel()->GetParent(pTemp); + while (rTreeView.iter_compare(*xNextTemp, *xConnection) != 0) + { + sNameBuffer.insert(0,'/'); + sNameBuffer.insert(0, rTreeView.get_text(*xTemp)); + rTreeView.copy_iterator(*xNextTemp, *xTemp); + if (!rTreeView.iter_parent(*xNextTemp)) + break; + } } } OUString aName = sNameBuffer.makeStringAndClear(); @@ -2492,16 +2564,16 @@ bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) weld::WaitObject aWaitCursor(getFrameWeld()); // tell the old entry it has been deselected - selectPath(m_pCurrentlyDisplayed, false); - m_pCurrentlyDisplayed = nullptr; + selectPath(m_xCurrentlyDisplayed.get(), false); + m_xCurrentlyDisplayed.reset(); // not really loaded - m_pCurrentlyDisplayed = _pEntry; + m_xCurrentlyDisplayed = rTreeView.make_iterator(pEntry); // tell the new entry it has been selected - selectPath(m_pCurrentlyDisplayed); + selectPath(m_xCurrentlyDisplayed.get()); // get the name of the data source currently selected - ensureConnection( m_pCurrentlyDisplayed, pConData->xConnection ); + ensureConnection(m_xCurrentlyDisplayed.get(), pConData->xConnection); if ( !pConData->xConnection.is() ) { @@ -2547,7 +2619,7 @@ bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) bool bEscapeProcessing = true; if(xNameAccess.is() && xNameAccess->hasByName(sSimpleName)) { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData()); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pEntry).toUInt64()); if ( !pData->xObjectProperties.is() ) { Reference<XInterface> xObject; @@ -2596,7 +2668,7 @@ bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) } } - OUString sDataSourceName( getDataSourceAccessor( pConnection ) ); + OUString sDataSourceName(getDataSourceAccessor(*xConnection)); bSuccess = implLoadAnything( sDataSourceName, aName, nCommandType, bEscapeProcessing, pConData->xConnection ); if ( !bSuccess ) { // clean up @@ -2634,72 +2706,93 @@ bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry ) return bSuccess; } -SvTreeListEntry* SbaTableQueryBrowser::getEntryFromContainer(const Reference<XNameAccess>& _rxNameAccess) +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getEntryFromContainer(const Reference<XNameAccess>& rxNameAccess) { - DBTreeListBox& rListBox = m_pTreeView->getListBox(); - SvTreeListEntry* pContainer = nullptr; - SvTreeListEntry* pDSLoop = rListBox.FirstChild(nullptr); - while (pDSLoop) - { - pContainer = rListBox.GetEntry(pDSLoop, CONTAINER_QUERIES); - DBTreeListUserData* pQueriesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData()); - if ( pQueriesData && pQueriesData->xContainer == _rxNameAccess ) - break; + std::unique_ptr<weld::TreeIter> xContainer; - pContainer = rListBox.GetEntry(pDSLoop, CONTAINER_TABLES); - DBTreeListUserData* pTablesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData()); - if ( pTablesData && pTablesData->xContainer == _rxNameAccess ) - break; + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + std::unique_ptr<weld::TreeIter> xDSLoop(rTreeView.make_iterator(xContainer.get())); + if (rTreeView.get_iter_first(*xDSLoop)) + { + do + { + xContainer = rTreeView.make_iterator(xDSLoop.get()); + if (rTreeView.iter_children(*xContainer)) + { + // 1st child is queries + DBTreeListUserData* pQueriesData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xContainer).toUInt64()); + if (pQueriesData && pQueriesData->xContainer == rxNameAccess) + break; - pDSLoop = pDSLoop->NextSibling(); - pContainer = nullptr; + if (rTreeView.iter_next_sibling(*xContainer)) + { + // 2nd child is tables + DBTreeListUserData* pTablesData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xContainer).toUInt64()); + if (pTablesData && pTablesData->xContainer == rxNameAccess) + break; + } + } + xContainer.reset(); + } + while (rTreeView.iter_next_sibling(*xDSLoop)); } - return pContainer; + + return xContainer; } -void SAL_CALL SbaTableQueryBrowser::elementInserted( const ContainerEvent& _rEvent ) +void SAL_CALL SbaTableQueryBrowser::elementInserted(const ContainerEvent& rEvent) { SolarMutexGuard aSolarGuard; - Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY); + Reference< XNameAccess > xNames(rEvent.Source, UNO_QUERY); // first search for a definition container where we can insert this element - SvTreeListEntry* pEntry = getEntryFromContainer(xNames); - if(pEntry) // found one + std::unique_ptr<weld::TreeIter> xEntry = getEntryFromContainer(xNames); + if (xEntry) // found one { + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + rTreeView.make_unsorted(); + // insert the new entry into the tree - DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pEntry->GetUserData()); + DBTreeListUserData* pContainerData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xEntry).toUInt64()); OSL_ENSURE(pContainerData, "elementInserted: There must be user data for this type!"); DBTreeListUserData* pNewData = new DBTreeListUserData; bool bIsTable = etTableContainer == pContainerData->eType; if ( bIsTable ) { - _rEvent.Element >>= pNewData->xObjectProperties;// remember the new element + rEvent.Element >>= pNewData->xObjectProperties;// remember the new element pNewData->eType = etTableOrView; } else { - if (static_cast<sal_Int32>(m_pTreeView->getListBox().GetChildCount(pEntry)) < ( xNames->getElementNames().getLength() - 1 ) ) + if (rTreeView.iter_n_children(*xEntry) < xNames->getElementNames().getLength() - 1) { // the item inserts its children on demand, but it has not been expanded yet. So ensure here and // now that it has all items - populateTree(xNames, pEntry, etQuery ); + populateTree(xNames, *xEntry, etQuery); } pNewData->eType = etQuery; } - implAppendEntry( pEntry, ::comphelper::getString( _rEvent.Accessor ), pNewData, pNewData->eType ); + implAppendEntry(xEntry.get(), ::comphelper::getString(rEvent.Accessor), pNewData, pNewData->eType); + + rTreeView.make_sorted(); } else - SbaXDataBrowserController::elementInserted(_rEvent); + SbaXDataBrowserController::elementInserted(rEvent); } -bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const OUString& _sName, SvTreeListEntry const * _pContainer) +bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const OUString& rName, const weld::TreeIter& rContainer) { - return m_pCurrentlyDisplayed - && getEntryType(m_pCurrentlyDisplayed) == getChildType(_pContainer) - && m_pTreeView->getListBox().GetParent(m_pCurrentlyDisplayed) == _pContainer - && m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed) == _sName; + if (!m_xCurrentlyDisplayed) + return false; + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + if (getEntryType(*m_xCurrentlyDisplayed) != getChildType(rContainer)) + return false; + if (rTreeView.get_text(*m_xCurrentlyDisplayed) != rName) + return false; + std::unique_ptr<weld::TreeIter> xParent = rTreeView.make_iterator(m_xCurrentlyDisplayed.get()); + return rTreeView.iter_parent(*xParent) && rTreeView.iter_compare(*xParent, rContainer) == 0; } void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEvent ) @@ -2709,41 +2802,45 @@ void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEven Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY); // get the top-level representing the removed data source // and search for the queries and tables - SvTreeListEntry* pContainer = getEntryFromContainer(xNames); - if ( pContainer ) - { // a query or table has been removed + std::unique_ptr<weld::TreeIter> xContainer = getEntryFromContainer(xNames); + if (xContainer) + { + // a query or table has been removed OUString aName = ::comphelper::getString(_rEvent.Accessor); - if ( isCurrentlyDisplayedChanged( aName, pContainer) ) - { // the element displayed currently has been replaced + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + if (isCurrentlyDisplayedChanged(aName, *xContainer)) + { + // the element displayed currently has been replaced // we need to remember the old value - SvTreeListEntry* pTemp = m_pCurrentlyDisplayed; + std::unique_ptr<weld::TreeIter> xTemp = rTreeView.make_iterator(m_xCurrentlyDisplayed.get()); // unload unloadAndCleanup( false ); // don't dispose the connection - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData()); - pTemp->SetUserData(nullptr); - delete pData; - // the data could be null because we have a table which isn't correct - m_pTreeView->GetTreeModel()->Remove(pTemp); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xTemp).toUInt64()); + rTreeView.set_id(*xTemp, OUString()); + delete pData; // the data could be null because we have a table which isn't correct + rTreeView.remove(*xTemp); } else { // remove the entry from the model - SvTreeListEntry* pChild = m_pTreeView->GetTreeModel()->FirstChild(pContainer); - while(pChild) + std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator(xContainer.get())); + if (rTreeView.get_iter_first(*xChild)) { - if (m_pTreeView->getListBox().GetEntryText(pChild) == aName) + do { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData()); - pChild->SetUserData(nullptr); - delete pData; - m_pTreeView->GetTreeModel()->Remove(pChild); - break; - } - pChild = pChild->NextSibling(); + if (rTreeView.get_text(*xChild) == aName) + { + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xChild).toUInt64()); + rTreeView.set_id(*xChild, OUString()); + delete pData; + rTreeView.remove(*xChild); + break; + } + } while (rTreeView.iter_next_sibling(*xChild)); } } @@ -2759,28 +2856,31 @@ void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEve SolarMutexGuard aSolarGuard; Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY); - SvTreeListEntry* pContainer = getEntryFromContainer(xNames); - if ( pContainer ) - { // a table or query as been replaced + std::unique_ptr<weld::TreeIter> xContainer = getEntryFromContainer(xNames); + if (xContainer) + { + // a table or query as been replaced OUString aName = ::comphelper::getString(_rEvent.Accessor); - if ( isCurrentlyDisplayedChanged( aName, pContainer) ) + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); + if (isCurrentlyDisplayedChanged(aName, *xContainer)) { // the element displayed currently has been replaced // we need to remember the old value - SvTreeListEntry* pTemp = m_pCurrentlyDisplayed; + std::unique_ptr<weld::TreeIter> xTemp = rTreeView.make_iterator(m_xCurrentlyDisplayed.get()); unloadAndCleanup( false ); // don't dispose the connection - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData()); + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xTemp).toUInt64()); if (pData) { if ( etTableOrView == pData->eType ) - { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query + { + // only insert userdata when we have a table because the query is only a commanddefinition object and not a query _rEvent.Element >>= pData->xObjectProperties; // remember the new element } else { - pTemp->SetUserData(nullptr); + rTreeView.set_id(*xTemp, OUString()); delete pData; } } @@ -2788,27 +2888,30 @@ void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEve else { // find the entry for this name - SvTreeListEntry* pChild = m_pTreeView->GetTreeModel()->FirstChild(pContainer); - while(pChild) + std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator(xContainer.get())); + if (rTreeView.get_iter_first(*xChild)) { - if (m_pTreeView->getListBox().GetEntryText(pChild) == aName) + do { - DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData()); - if (pData) + if (rTreeView.get_text(*xChild) == aName) { - if ( etTableOrView == pData->eType ) - { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query - _rEvent.Element >>= pData->xObjectProperties; // remember the new element - } - else + DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xChild).toUInt64()); + if (pData) { - pChild->SetUserData(nullptr); - delete pData; + if ( etTableOrView == pData->eType ) + { + // only insert userdata when we have a table because the query is only a commanddefinition object and not a query + _rEvent.Element >>= pData->xObjectProperties; // remember the new element + } + else + { + rTreeView.set_id(*xChild, OUString()); + delete pData; + } } + break; } - break; - } - pChild = pChild->NextSibling(); + } while (rTreeView.iter_next_sibling(*xChild)); } } @@ -2852,68 +2955,79 @@ void SbaTableQueryBrowser::impl_releaseConnection( SharedConnection& _rxConnecti // will implicitly dispose if we have the ownership, since xConnection is a SharedConnection } -void SbaTableQueryBrowser::disposeConnection( SvTreeListEntry* _pDSEntry ) +void SbaTableQueryBrowser::disposeConnection(weld::TreeIter* pDSEntry) { - OSL_ENSURE( _pDSEntry, "SbaTableQueryBrowser::disposeConnection: invalid entry (NULL)!" ); - OSL_ENSURE( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::disposeConnection: invalid entry (not top-level)!" ); + OSL_ENSURE( pDSEntry, "SbaTableQueryBrowser::disposeConnection: invalid entry (NULL)!" ); + OSL_ENSURE( impl_isDataSourceEntry( pDSEntry ), "SbaTableQueryBrowser::disposeConnection: invalid entry (not top-level)!" ); - if ( _pDSEntry ) + if (pDSEntry) { - DBTreeListUserData* pTreeListData = static_cast< DBTreeListUserData* >( _pDSEntry->GetUserData() ); - if ( pTreeListData ) - impl_releaseConnection( pTreeListData->xConnection ); + weld::TreeView& rTreeView = m_pTreeView->getListBox().GetWidget(); ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits