diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-09-26 20:54:40 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-09-29 15:05:33 +0200 |
commit | b98c1b0617493426f54e15dc354d0d1597d17091 (patch) | |
tree | beb67df09016b2eadd3c3c270781569a1edcbc57 | |
parent | 9cb8f2d0a968d9b14ca41c728361568554c83c7a (diff) |
weld DbaIndexDialog
Change-Id: I5fe97c0bea6d386c4b39d8bf9341c844ccb792ae
Reviewed-on: https://gerrit.libreoffice.org/79745
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | dbaccess/source/ui/dlg/indexdialog.cxx | 614 | ||||
-rw-r--r-- | dbaccess/source/ui/dlg/indexfieldscontrol.cxx | 13 | ||||
-rw-r--r-- | dbaccess/source/ui/inc/indexdialog.hxx | 127 | ||||
-rw-r--r-- | dbaccess/source/ui/inc/indexfieldscontrol.hxx | 3 | ||||
-rw-r--r-- | dbaccess/source/ui/tabledesign/TableController.cxx | 4 | ||||
-rw-r--r-- | dbaccess/uiconfig/ui/indexdesigndialog.ui | 141 | ||||
-rw-r--r-- | extras/source/glade/libreoffice-catalog.xml.in | 7 | ||||
-rw-r--r-- | include/vcl/weld.hxx | 3 | ||||
-rw-r--r-- | solenv/sanitizers/ui/dbaccess.suppr | 1 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 28 |
11 files changed, 371 insertions, 581 deletions
diff --git a/dbaccess/source/ui/dlg/indexdialog.cxx b/dbaccess/source/ui/dlg/indexdialog.cxx index 9d42d02623fb..45eae31ec8be 100644 --- a/dbaccess/source/ui/dlg/indexdialog.cxx +++ b/dbaccess/source/ui/dlg/indexdialog.cxx @@ -28,7 +28,6 @@ #include <bitmaps.hlst> #include <indexfieldscontrol.hxx> #include <indexcollection.hxx> -#include <vcl/builderfactory.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> @@ -67,146 +66,54 @@ namespace dbaui return !(_rLHS == _rRHS); } - // DbaIndexList - DbaIndexList::DbaIndexList(vcl::Window* _pParent, WinBits nWinBits) - :SvTreeListBox(_pParent, nWinBits) - ,m_bSuspendSelectHdl(false) - { - } - - bool DbaIndexList::EditedEntry( SvTreeListEntry* _pEntry, const OUString& _rNewText ) - { - // first check if this is valid SQL92 name - if ( isSQL92CheckEnabled(m_xConnection) ) - { - Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); - if ( xMeta.is() ) - { - OUString sAlias = ::dbtools::convertName2SQLName(_rNewText, xMeta->getExtraNameCharacters()); - if ( ( xMeta->supportsMixedCaseQuotedIdentifiers() ) - ? - sAlias != _rNewText - : - !_rNewText.equalsIgnoreAsciiCase(sAlias)) - return false; - } - } - - if (!SvTreeListBox::EditedEntry(_pEntry, _rNewText)) - return false; - - OUString sOldText = GetEntryText(_pEntry); - SvTreeListBox::SetEntryText(_pEntry, _rNewText); - - bool bValid = true; - if (m_aEndEditHdl.IsSet()) - bValid = m_aEndEditHdl.Call(_pEntry); - - if (bValid) - return true; - - SvTreeListBox::SetEntryText(_pEntry, sOldText); - - return false; - } - - void DbaIndexList::enableSelectHandler() - { - OSL_ENSURE(m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!"); - m_bSuspendSelectHdl = false; - } - - void DbaIndexList::disableSelectHandler() - { - OSL_ENSURE(!m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!"); - m_bSuspendSelectHdl = true; - } - - void DbaIndexList::SelectNoHandlerCall( SvTreeListEntry* _pEntry ) - { - disableSelectHandler(); - Select(_pEntry ); - enableSelectHandler(); - } - - bool DbaIndexList::Select(SvTreeListEntry* pEntry, bool _bSelect) - { - bool bReturn = SvTreeListBox::Select(pEntry, _bSelect); - - if (!m_bSuspendSelectHdl && _bSelect) - m_aSelectHdl.Call(*this); - - return bReturn; - } - - VCL_BUILDER_FACTORY_ARGS(DbaIndexList, WB_BORDER) - // DbaIndexDialog - DbaIndexDialog::DbaIndexDialog( vcl::Window* _pParent, const Sequence< OUString >& _rFieldNames, - const Reference< XNameAccess >& _rxIndexes, - const Reference< XConnection >& _rxConnection, - const Reference< XComponentContext >& _rxContext) - :ModalDialog( _pParent, "IndexDesignDialog", "dbaccess/ui/indexdesigndialog.ui") - ,m_xConnection(_rxConnection) - ,m_pPreviousSelection(nullptr) - ,m_bEditAgain(false) - ,m_xContext(_rxContext) - { - get(m_pActions, "ACTIONS"); - - mnNewCmdId = m_pActions->GetItemId(".index:createNew"); - mnDropCmdId = m_pActions->GetItemId(".index:dropCurrent"); - mnRenameCmdId = m_pActions->GetItemId(".index:renameCurrent"); - mnSaveCmdId = m_pActions->GetItemId(".index:saveCurrent"); - mnResetCmdId = m_pActions->GetItemId(".index:resetCurrent"); - - maScNewCmdImg = m_pActions->GetItemImage(mnNewCmdId); - maScDropCmdImg = m_pActions->GetItemImage(mnDropCmdId); - maScRenameCmdImg = m_pActions->GetItemImage(mnRenameCmdId); - maScSaveCmdImg = m_pActions->GetItemImage(mnSaveCmdId); - maScResetCmdImg = m_pActions->GetItemImage(mnResetCmdId); - maLcNewCmdImg = get<FixedImage>("image1")->GetImage(); - maLcDropCmdImg = get<FixedImage>("image2")->GetImage(); - maLcRenameCmdImg = get<FixedImage>("image3")->GetImage(); - maLcSaveCmdImg = get<FixedImage>("image4")->GetImage(); - maLcResetCmdImg = get<FixedImage>("image5")->GetImage(); - - get(m_pIndexList, "INDEX_LIST"); - Size aSize(LogicToPixel(Size(70, 97), MapMode(MapUnit::MapAppFont))); - m_pIndexList->set_width_request(aSize.Width()); - m_pIndexList->set_height_request(aSize.Height()); - get(m_pIndexDetails, "INDEX_DETAILS"); - get(m_pDescriptionLabel, "DESC_LABEL"); - get(m_pDescription, "DESCRIPTION"); - get(m_pUnique, "UNIQUE"); - get(m_pFieldsLabel, "FIELDS_LABEL"); - get(m_pFields, "FIELDS"); - aSize = LogicToPixel(Size(128, 61), MapMode(MapUnit::MapAppFont)); - m_pFields->set_width_request(aSize.Width()); - m_pFields->set_height_request(aSize.Height()); - get(m_pClose, "close"); - - m_pActions->SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexAction)); - - m_pIndexList->SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexSelected)); - m_pIndexList->SetEndEditHdl(LINK(this, DbaIndexDialog, OnEntryEdited)); - m_pIndexList->SetSelectionMode(SelectionMode::Single); - m_pIndexList->SetHighlightRange(); - m_pIndexList->setConnection(m_xConnection); - - m_pFields->SetSizePixel(Size(300, 100)); - m_pFields->Init(_rFieldNames, ::dbtools::getBooleanDataSourceSetting( m_xConnection, "AddIndexAppendix" )); - - setToolBox(m_pActions); - - m_pIndexes.reset(new OIndexCollection()); + DbaIndexDialog::DbaIndexDialog(weld::Window* pParent, const Sequence< OUString >& _rFieldNames, + const Reference< XNameAccess >& _rxIndexes, + const Reference< XConnection >& _rxConnection, + const Reference< XComponentContext >& _rxContext) + : GenericDialogController(pParent, "dbaccess/ui/indexdesigndialog.ui", "IndexDesignDialog") + , m_xConnection(_rxConnection) + , m_bEditingActive(false) + , m_bEditAgain(false) + , m_bNoHandlerCall(false) + , m_xContext(_rxContext) + , m_xActions(m_xBuilder->weld_toolbar("ACTIONS")) + , m_xIndexList(m_xBuilder->weld_tree_view("INDEX_LIST")) + , m_xIndexDetails(m_xBuilder->weld_label("INDEX_DETAILS")) + , m_xDescriptionLabel(m_xBuilder->weld_label("DESC_LABEL")) + , m_xDescription(m_xBuilder->weld_label("DESCRIPTION")) + , m_xUnique(m_xBuilder->weld_check_button("UNIQUE")) + , m_xFieldsLabel(m_xBuilder->weld_label("FIELDS_LABEL")) + , m_xClose(m_xBuilder->weld_button("close")) + , m_xTable(m_xBuilder->weld_container("FIELDS")) + , m_xTableCtrlParent(m_xTable->CreateChildFrame()) + , m_xFields(VclPtr<IndexFieldsControl>::Create(m_xTableCtrlParent)) + { + m_xIndexList->set_size_request(m_xIndexList->get_approximate_digit_width() * 17, + m_xIndexList->get_height_rows(12)); + + int nWidth = m_xIndexList->get_approximate_digit_width() * 60; + int nHeight = m_xIndexList->get_height_rows(8); + m_xTable->set_size_request(nWidth, nHeight); + + m_xActions->connect_clicked(LINK(this, DbaIndexDialog, OnIndexAction)); + + m_xIndexList->connect_changed(LINK(this, DbaIndexDialog, OnIndexSelected)); + m_xIndexList->connect_editing_started(LINK(this, DbaIndexDialog, OnEntryEditing)); + m_xIndexList->connect_editing_done(LINK(this, DbaIndexDialog, OnEntryEdited)); + + m_xFields->SetSizePixel(Size(nWidth, 100)); + m_xFields->Init(_rFieldNames, ::dbtools::getBooleanDataSourceSetting( m_xConnection, "AddIndexAppendix" )); + m_xFields->Show(); + + m_xIndexes.reset(new OIndexCollection()); try { - m_pIndexes->attach(_rxIndexes); + m_xIndexes->attach(_rxIndexes); } catch(SQLException& e) { - ::dbtools::showError(SQLExceptionInfo(e),VCLUnoHelper::GetInterface(_pParent),_rxContext); + ::dbtools::showError(SQLExceptionInfo(e), pParent->GetXWindow(), _rxContext); } catch(Exception&) { @@ -215,14 +122,14 @@ namespace dbaui fillIndexList(); - m_pUnique->SetClickHdl(LINK(this, DbaIndexDialog, OnModifiedClick)); - m_pFields->SetModifyHdl(LINK(this, DbaIndexDialog, OnModified)); + m_xUnique->connect_clicked(LINK(this, DbaIndexDialog, OnModifiedClick)); + m_xFields->SetModifyHdl(LINK(this, DbaIndexDialog, OnModified)); - m_pClose->SetClickHdl(LINK(this, DbaIndexDialog, OnCloseDialog)); + m_xClose->connect_clicked(LINK(this, DbaIndexDialog, OnCloseDialog)); // if all of the indexes have an empty description, we're not interested in displaying it bool bFound = false; - for (auto const& check : *m_pIndexes) + for (auto const& check : *m_xIndexes) { if (!check.sDescription.isEmpty()) { @@ -233,94 +140,79 @@ namespace dbaui if (!bFound) { // hide the controls which are necessary for the description - m_pDescription->Hide(); - m_pDescriptionLabel->Hide(); + m_xDescription->hide(); + m_xDescriptionLabel->hide(); } } void DbaIndexDialog::updateToolbox() { - m_pActions->EnableItem(mnNewCmdId, !m_pIndexList->IsEditingActive()); - - SvTreeListEntry* pSelected = m_pIndexList->FirstSelected(); - bool bSelectedAnything = nullptr != pSelected; + m_xActions->set_item_sensitive("ID_INDEX_NEW", !m_bEditingActive); - if (pSelected) + int nSelected = m_xIndexList->get_selected_index(); + bool bSelectedAnything = nSelected != -1; + if (bSelectedAnything) { // is the current entry modified? - Indexes::const_iterator aSelectedPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData()); - m_pActions->EnableItem(mnSaveCmdId, aSelectedPos->isModified() || aSelectedPos->isNew()); - m_pActions->EnableItem(mnResetCmdId, aSelectedPos->isModified() || aSelectedPos->isNew()); - bSelectedAnything = bSelectedAnything && !aSelectedPos->bPrimaryKey; + Indexes::const_iterator aSelectedPos = m_xIndexes->begin() + m_xIndexList->get_id(nSelected).toUInt32(); + m_xActions->set_item_sensitive("ID_INDEX_SAVE", aSelectedPos->isModified() || aSelectedPos->isNew()); + m_xActions->set_item_sensitive("ID_INDEX_RESET", aSelectedPos->isModified() || aSelectedPos->isNew()); + bSelectedAnything = !aSelectedPos->bPrimaryKey; } else { - m_pActions->EnableItem(mnSaveCmdId, false); - m_pActions->EnableItem(mnResetCmdId, false); + m_xActions->set_item_sensitive("ID_INDEX_SAVE", false); + m_xActions->set_item_sensitive("ID_INDEX_RESET", false); } - m_pActions->EnableItem(mnDropCmdId, bSelectedAnything); - m_pActions->EnableItem(mnRenameCmdId, bSelectedAnything); + m_xActions->set_item_sensitive("ID_INDEX_DROP", bSelectedAnything); + m_xActions->set_item_sensitive("ID_INDEX_RENAME", bSelectedAnything); } void DbaIndexDialog::fillIndexList() { - Image aPKeyIcon(StockImage::Yes, BMP_PKEYICON); + OUString aPKeyIcon(BMP_PKEYICON); // fill the list with the index names - m_pIndexList->Clear(); - sal_Int32 nPos = 0; - for (auto const& indexLoop : *m_pIndexes) + m_xIndexList->clear(); + sal_uInt32 nPos = 0; + for (auto const& indexLoop : *m_xIndexes) { - SvTreeListEntry* pNewEntry = nullptr; + m_xIndexList->append(OUString::number(nPos), indexLoop.sName); if (indexLoop.bPrimaryKey) - pNewEntry = m_pIndexList->InsertEntry(indexLoop.sName, aPKeyIcon, aPKeyIcon); - else - pNewEntry = m_pIndexList->InsertEntry(indexLoop.sName); - - pNewEntry->SetUserData(reinterpret_cast< void* >(nPos)); + m_xIndexList->set_image(nPos, aPKeyIcon); ++nPos; } - OnIndexSelected(*m_pIndexList); - } + if (nPos) + m_xIndexList->select(0); - DbaIndexDialog::~DbaIndexDialog( ) - { - disposeOnce(); + IndexSelected(); } - void DbaIndexDialog::dispose() + DbaIndexDialog::~DbaIndexDialog( ) { - setToolBox(nullptr); - m_pIndexes.reset(); - m_pActions.clear(); - m_pIndexList.clear(); - m_pIndexDetails.clear(); - m_pDescriptionLabel.clear(); - m_pDescription.clear(); - m_pUnique.clear(); - m_pFieldsLabel.clear(); - m_pFields.clear(); - m_pClose.clear(); - ModalDialog::dispose(); + m_xIndexes.reset(); + m_xFields.disposeAndClear(); + m_xTableCtrlParent->dispose(); + m_xTableCtrlParent.clear(); } - bool DbaIndexDialog::implCommit(SvTreeListEntry const * _pEntry) + bool DbaIndexDialog::implCommit(const weld::TreeIter* pEntry) { - OSL_ENSURE(_pEntry, "DbaIndexDialog::implCommit: invalid entry!"); + assert(pEntry && "DbaIndexDialog::implCommit: invalid entry!"); - Indexes::iterator aCommitPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData()); + Indexes::iterator aCommitPos = m_xIndexes->begin() + m_xIndexList->get_id(*pEntry).toUInt32(); // if it's not a new index, remove it // (we can't modify indexes, only drop'n'insert) if (!aCommitPos->isNew()) - if (!implDropIndex(_pEntry, false)) + if (!implDropIndex(pEntry, false)) return false; // create the new index SQLExceptionInfo aExceptionInfo; try { - m_pIndexes->commitNewIndex(aCommitPos); + m_xIndexes->commitNewIndex(aCommitPos); } catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); } catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); } @@ -330,11 +222,11 @@ namespace dbaui updateToolbox(); if (aExceptionInfo.isValid()) - showError(aExceptionInfo, VCLUnoHelper::GetInterface(this), m_xContext); + showError(aExceptionInfo, m_xDialog->GetXWindow(), m_xContext); else { - m_pUnique->SaveValue(); - m_pFields->SaveValue(); + m_xUnique->save_state(); + m_xFields->SaveValue(); } return !aExceptionInfo.isValid(); @@ -354,7 +246,7 @@ namespace dbaui for ( i = 1; i < 0x7FFFFFFF; ++i ) { sNewIndexName = sNewIndexNameBase + OUString::number(i); - if (m_pIndexes->end() == m_pIndexes->find(sNewIndexName)) + if (m_xIndexes->end() == m_xIndexes->find(sNewIndexName)) break; } if (i == 0x7FFFFFFF) @@ -364,38 +256,41 @@ namespace dbaui return; } - SvTreeListEntry* pNewEntry = m_pIndexList->InsertEntry(sNewIndexName); - m_pIndexes->insert(sNewIndexName); + std::unique_ptr<weld::TreeIter> xNewEntry(m_xIndexList->make_iterator()); + m_xIndexList->insert(nullptr, -1, &sNewIndexName, nullptr, nullptr, nullptr, nullptr, false, xNewEntry.get()); + m_xIndexes->insert(sNewIndexName); // update the user data on the entries in the list box: // they're iterators of the index collection, and thus they have changed when removing the index - for (SvTreeListEntry* pAdjust = m_pIndexList->First(); pAdjust; pAdjust = m_pIndexList->Next(pAdjust)) - { - Indexes::const_iterator aAfterInsertPos = m_pIndexes->find(m_pIndexList->GetEntryText(pAdjust)); - OSL_ENSURE(aAfterInsertPos != m_pIndexes->end(), "DbaIndexDialog::OnNewIndex: problems with one of the entries!"); - pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterInsertPos - m_pIndexes->begin()))); - } + m_xIndexList->all_foreach([this](weld::TreeIter& rEntry){ + Indexes::const_iterator aAfterInsertPos = m_xIndexes->find(m_xIndexList->get_text(rEntry)); + OSL_ENSURE(aAfterInsertPos != m_xIndexes->end(), "DbaIndexDialog::OnNewIndex: problems with one of the entries!"); + m_xIndexList->set_id(rEntry, OUString::number(aAfterInsertPos - m_xIndexes->begin())); + return false; + }); // select the entry and start in-place editing - m_pIndexList->SelectNoHandlerCall(pNewEntry); - OnIndexSelected(*m_pIndexList); - m_pIndexList->EditEntry(pNewEntry); + m_bNoHandlerCall = true; + m_xIndexList->select(*xNewEntry); + m_bNoHandlerCall = false; + IndexSelected(); + m_xIndexList->grab_focus(); + m_xIndexList->start_editing(*xNewEntry); updateToolbox(); } void DbaIndexDialog::OnDropIndex(bool _bConfirm) { + std::unique_ptr<weld::TreeIter> xSelected(m_xIndexList->make_iterator()); // the selected index - SvTreeListEntry* pSelected = m_pIndexList->FirstSelected(); - OSL_ENSURE(pSelected, "DbaIndexDialog::OnDropIndex: invalid call!"); - if (pSelected) + if (m_xIndexList->get_selected(xSelected.get())) { // let the user confirm the drop if (_bConfirm) { OUString sConfirm(DBA_RES(STR_CONFIRM_DROP_INDEX)); - sConfirm = sConfirm.replaceFirst("$name$", m_pIndexList->GetEntryText(pSelected)); - std::unique_ptr<weld::MessageDialog> xConfirm(Application::CreateMessageDialog(GetFrameWeld(), + sConfirm = sConfirm.replaceFirst("$name$", m_xIndexList->get_text(*xSelected)); + std::unique_ptr<weld::MessageDialog> xConfirm(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question, VclButtonsType::YesNo, sConfirm)); if (RET_YES != xConfirm->run()) @@ -403,58 +298,57 @@ namespace dbaui } // do the drop - implDropIndex(pSelected, true); + implDropIndex(xSelected.get(), true); // reflect the new selection in the toolbox updateToolbox(); } } - bool DbaIndexDialog::implDropIndex(SvTreeListEntry const * _pEntry, bool _bRemoveFromCollection) + bool DbaIndexDialog::implDropIndex(const weld::TreeIter* pEntry, bool _bRemoveFromCollection) { // do the drop - Indexes::iterator aDropPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData()); - OSL_ENSURE(aDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: did not find the index in my collection!"); + Indexes::iterator aDropPos = m_xIndexes->begin() + m_xIndexList->get_id(*pEntry).toUInt32(); + OSL_ENSURE(aDropPos != m_xIndexes->end(), "DbaIndexDialog::OnDropIndex: did not find the index in my collection!"); SQLExceptionInfo aExceptionInfo; bool bSuccess = false; try { if (_bRemoveFromCollection) - bSuccess = m_pIndexes->drop(aDropPos); + bSuccess = m_xIndexes->drop(aDropPos); else - bSuccess = m_pIndexes->dropNoRemove(aDropPos); + bSuccess = m_xIndexes->dropNoRemove(aDropPos); } catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); } catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); } catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); } if (aExceptionInfo.isValid()) - showError(aExceptionInfo, VCLUnoHelper::GetInterface(this), m_xContext); + showError(aExceptionInfo, m_xDialog->GetXWindow(), m_xContext); else if (bSuccess && _bRemoveFromCollection) { - SvTreeList* pModel = m_pIndexList->GetModel(); + m_bNoHandlerCall = true; - m_pIndexList->disableSelectHandler(); - pModel->Remove(_pEntry); - m_pIndexList->enableSelectHandler(); + // if the entry to remove is the selected on... + if (m_xPreviousSelection && m_xPreviousSelection->equal(*pEntry)) + m_xPreviousSelection.reset(); + m_xIndexList->remove(*pEntry); + + m_bNoHandlerCall = false; // update the user data on the entries in the list box: // they're iterators of the index collection, and thus they have changed when removing the index - for (SvTreeListEntry* pAdjust = m_pIndexList->First(); pAdjust; pAdjust = m_pIndexList->Next(pAdjust)) - { - Indexes::const_iterator aAfterDropPos = m_pIndexes->find(m_pIndexList->GetEntryText(pAdjust)); - OSL_ENSURE(aAfterDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: problems with one of the remaining entries!"); - pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterDropPos - m_pIndexes->begin()))); - } - - // if the removed entry was the selected on... - if (m_pPreviousSelection == _pEntry) - m_pPreviousSelection = nullptr; + m_xIndexList->all_foreach([this](weld::TreeIter& rEntry){ + Indexes::const_iterator aAfterDropPos = m_xIndexes->find(m_xIndexList->get_text(rEntry)); + OSL_ENSURE(aAfterDropPos != m_xIndexes->end(), "DbaIndexDialog::OnDropIndex: problems with one of the remaining entries!"); + m_xIndexList->set_id(rEntry, OUString::number(aAfterDropPos - m_xIndexes->begin())); + return false; + }); // the Remove automatically selected another entry (if possible), but we disabled the calling of the handler // to prevent that we missed something... call the handler directly - OnIndexSelected(*m_pIndexList); + IndexSelected(); } return !aExceptionInfo.isValid(); @@ -463,26 +357,23 @@ namespace dbaui void DbaIndexDialog::OnRenameIndex() { // the selected index - SvTreeListEntry* pSelected = m_pIndexList->FirstSelected(); - OSL_ENSURE(pSelected, "DbaIndexDialog::OnRenameIndex: invalid call!"); + std::unique_ptr<weld::TreeIter> xSelected(m_xIndexList->make_iterator()); + // the selected index + m_xIndexList->get_selected(xSelected.get()); // save the changes made 'til here // Upon leaving the edit mode, the control will be re-initialized with the // settings from the current entry implSaveModified(false); - m_pIndexList->EditEntry(pSelected); + m_xIndexList->grab_focus(); + m_xIndexList->start_editing(*xSelected); updateToolbox(); } void DbaIndexDialog::OnSaveIndex() { // the selected index -#if OSL_DEBUG_LEVEL > 0 - SvTreeListEntry* pSelected = m_pIndexList->FirstSelected(); - OSL_ENSURE( pSelected, "DbaIndexDialog::OnSaveIndex: invalid call!" ); -#endif - implCommitPreviouslySelected(); updateToolbox(); } @@ -490,10 +381,12 @@ namespace dbaui void DbaIndexDialog::OnResetIndex() { // the selected index - SvTreeListEntry* pSelected = m_pIndexList->FirstSelected(); - OSL_ENSURE(pSelected, "DbaIndexDialog::OnResetIndex: invalid call!"); + std::unique_ptr<weld::TreeIter> xSelected(m_xIndexList->make_iterator()); + // the selected index + m_xIndexList->get_selected(xSelected.get()); + OSL_ENSURE(xSelected, "DbaIndexDialog::OnResetIndex: invalid call!"); - Indexes::iterator aResetPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData()); + Indexes::iterator aResetPos = m_xIndexes->begin() + m_xIndexList->get_id(*xSelected).toUInt32(); if (aResetPos->isNew()) { @@ -504,62 +397,64 @@ namespace dbaui SQLExceptionInfo aExceptionInfo; try { - m_pIndexes->resetIndex(aResetPos); + m_xIndexes->resetIndex(aResetPos); } catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); } catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); } catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); } if (aExceptionInfo.isValid()) - showError(aExceptionInfo, VCLUnoHelper::GetInterface(this), m_xContext); + showError(aExceptionInfo, m_xDialog->GetXWindow(), m_xContext); else - m_pIndexList->SetEntryText(pSelected, aResetPos->sName); + m_xIndexList->set_text(*xSelected, aResetPos->sName); - updateControls(pSelected); + updateControls(xSelected.get()); updateToolbox(); } - IMPL_LINK_NOARG( DbaIndexDialog, OnIndexAction, ToolBox*, void ) + IMPL_LINK(DbaIndexDialog, OnIndexAction, const OString&, rClicked, void) { - sal_uInt16 nClicked = m_pActions->GetCurItemId(); - if (nClicked == mnNewCmdId) + if (rClicked == "ID_INDEX_NEW") OnNewIndex(); - else if (nClicked == mnDropCmdId) + else if (rClicked == "ID_INDEX_DROP") OnDropIndex(); - else if (nClicked == mnRenameCmdId) + else if (rClicked == "ID_INDEX_RENAME") OnRenameIndex(); - else if (nClicked == mnSaveCmdId) + else if (rClicked == "ID_INDEX_SAVE") OnSaveIndex(); - else if (nClicked == mnResetCmdId) + else if (rClicked == "ID_INDEX_RESET") OnResetIndex(); } - IMPL_LINK_NOARG( DbaIndexDialog, OnCloseDialog, Button*, void ) + IMPL_LINK_NOARG(DbaIndexDialog, OnCloseDialog, weld::Button&, void) { - if (m_pIndexList->IsEditingActive()) + if (m_bEditingActive) { OSL_ENSURE(!m_bEditAgain, "DbaIndexDialog::OnCloseDialog: somebody was faster than hell!"); // this means somebody entered a new name, which was invalid, which cause us to posted us an event, // and before the event arrived the user clicked onto "close". VERY fast, this user... - m_pIndexList->EndEditing(); + m_xIndexList->end_editing(); if (m_bEditAgain) // could not commit the new name (started a new - asynchronous - edit trial) return; } // the currently selected entry - const SvTreeListEntry* pSelected = m_pIndexList->FirstSelected(); - OSL_ENSURE(pSelected == m_pPreviousSelection, "DbaIndexDialog::OnCloseDialog: inconsistence!"); + std::unique_ptr<weld::TreeIter> xSelected(m_xIndexList->make_iterator()); + // the selected index + if (!m_xIndexList->get_selected(xSelected.get())) + xSelected.reset(); + + OSL_ENSURE(xSelected && m_xPreviousSelection && xSelected->equal(*m_xPreviousSelection), "DbaIndexDialog::OnCloseDialog: inconsistence!"); sal_Int32 nResponse = RET_NO; - if (pSelected) + if (xSelected) { // the descriptor - Indexes::const_iterator aSelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData()); - + Indexes::const_iterator aSelected = m_xIndexes->begin() + m_xIndexList->get_id(*xSelected).toUInt32(); if (aSelected->isModified() || aSelected->isNew()) { - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "dbaccess/ui/saveindexdialog.ui")); + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), "dbaccess/ui/saveindexdialog.ui")); std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("SaveIndexDialog")); nResponse = xQuery->run(); } @@ -577,38 +472,47 @@ namespace dbaui return; } - EndDialog(RET_OK); + m_xDialog->response(RET_OK); } - IMPL_LINK( DbaIndexDialog, OnEditIndexAgain, void*, p, void ) + IMPL_LINK(DbaIndexDialog, OnEditIndexAgain, void*, p, void) { - SvTreeListEntry* _pEntry = static_cast<SvTreeListEntry*>(p); + weld::TreeIter* pEntry = static_cast<weld::TreeIter*>(p); m_bEditAgain = false; - m_pIndexList->EditEntry(_pEntry); + m_xIndexList->grab_focus(); + m_xIndexList->start_editing(*pEntry); + delete pEntry; } - IMPL_LINK( DbaIndexDialog, OnEntryEdited, SvTreeListEntry*, _pEntry, bool ) + IMPL_STATIC_LINK_NOARG(DbaIndexDialog, OnEntryEditing, const weld::TreeIter&, bool) { - Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData()); + return true; + } - OSL_ENSURE(aPosition >= m_pIndexes->begin() && aPosition < m_pIndexes->end(), - "DbaIndexDialog::OnEntryEdited: invalid entry!"); + IMPL_LINK(DbaIndexDialog, OnEntryEdited, const IterString&, rIterString, bool) + { + const weld::TreeIter& rEntry = rIterString.first; + OUString sNewName = rIterString.second; + + Indexes::iterator aPosition = m_xIndexes->begin() + m_xIndexList->get_id(rEntry).toUInt32(); - OUString sNewName = m_pIndexList->GetEntryText(_pEntry); + OSL_ENSURE(aPosition >= m_xIndexes->begin() && aPosition < m_xIndexes->end(), + "DbaIndexDialog::OnEntryEdited: invalid entry!"); - Indexes::const_iterator aSameName = m_pIndexes->find(sNewName); - if ((aSameName != aPosition) && (m_pIndexes->end() != aSameName)) + Indexes::const_iterator aSameName = m_xIndexes->find(sNewName); + if (aSameName != aPosition && m_xIndexes->end() != aSameName) { OUString sError(DBA_RES(STR_INDEX_NAME_ALREADY_USED)); sError = sError.replaceFirst("$name$", sNewName); - std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, sError)); xError->run(); updateToolbox(); m_bEditAgain = true; - PostUserEvent(LINK(this, DbaIndexDialog, OnEditIndexAgain), _pEntry, true); + std::unique_ptr<weld::TreeIter> xEntry(m_xIndexList->make_iterator(&rEntry)); + Application::PostUserEvent(LINK(this, DbaIndexDialog, OnEditIndexAgain), xEntry.release()); return false; } @@ -633,22 +537,22 @@ namespace dbaui bool DbaIndexDialog::implSaveModified(bool _bPlausibility) { - if (m_pPreviousSelection) + if (m_xPreviousSelection) { // try to commit the previously selected index - if (m_pFields->IsModified() && !m_pFields->SaveModified()) + if (m_xFields->IsModified() && !m_xFields->SaveModified()) return false; - Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData()); + Indexes::iterator aPreviouslySelected = m_xIndexes->begin() + m_xIndexList->get_id(*m_xPreviousSelection).toUInt32(); // the unique flag - aPreviouslySelected->bUnique = m_pUnique->IsChecked(); - if (m_pUnique->GetSavedValue() != m_pUnique->GetState()) + aPreviouslySelected->bUnique = m_xUnique->get_active(); + if (m_xUnique->get_state_changed_from_saved()) aPreviouslySelected->setModified(true); // the fields - m_pFields->commitTo(aPreviouslySelected->aFields); - if (m_pFields->GetSavedValue() != aPreviouslySelected->aFields) + m_xFields->commitTo(aPreviouslySelected->aFields); + if (m_xFields->GetSavedValue() != aPreviouslySelected->aFields) aPreviouslySelected->setModified(true); // plausibility checks @@ -664,11 +568,11 @@ namespace dbaui // need at least one field if (_rPos->aFields.empty()) { - std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, DBA_RES(STR_NEED_INDEX_FIELDS))); xError->run(); - m_pFields->GrabFocus(); + m_xFields->GrabFocus(); return false; } @@ -681,11 +585,11 @@ namespace dbaui // a column is specified twice ... won't work anyway, so prevent this here and now OUString sMessage(DBA_RES(STR_INDEXDESIGN_DOUBLE_COLUMN_NAME)); sMessage = sMessage.replaceFirst("$name$", fieldCheck.sFieldName); - std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, sMessage)); xError->run(); - m_pFields->GrabFocus(); + m_xFields->GrabFocus(); return false; } aExistentFields.insert(fieldCheck.sFieldName); @@ -696,152 +600,110 @@ namespace dbaui bool DbaIndexDialog::implCommitPreviouslySelected() { - if (m_pPreviousSelection) + if (m_xPreviousSelection) { - Indexes::const_iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData()); + Indexes::const_iterator aPreviouslySelected = m_xIndexes->begin() + m_xIndexList->get_id(*m_xPreviousSelection).toUInt32(); if (!implSaveModified()) return false; // commit the index (if necessary) - if (aPreviouslySelected->isModified() && !implCommit(m_pPreviousSelection)) + if (aPreviouslySelected->isModified() && !implCommit(m_xPreviousSelection.get())) return false; } return true; } - IMPL_LINK_NOARG( DbaIndexDialog, OnModifiedClick, Button*, void ) + IMPL_LINK_NOARG(DbaIndexDialog, OnModifiedClick, weld::Button&, void) { - OnModified(*m_pFields); + OnModified(*m_xFields); } + IMPL_LINK_NOARG( DbaIndexDialog, OnModified, IndexFieldsControl&, void ) { - OSL_ENSURE(m_pPreviousSelection, "DbaIndexDialog, OnModified: invalid call!"); - Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData()); + assert(m_xPreviousSelection && "DbaIndexDialog, OnModified: invalid call!"); + Indexes::iterator aPosition = m_xIndexes->begin() + m_xIndexList->get_id(*m_xPreviousSelection).toUInt32(); aPosition->setModified(true); updateToolbox(); } - void DbaIndexDialog::updateControls(const SvTreeListEntry* _pEntry) + void DbaIndexDialog::updateControls(const weld::TreeIter* pEntry) { - if (_pEntry) + if (pEntry) { // the descriptor of the selected index - Indexes::const_iterator aSelectedIndex = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData()); + Indexes::const_iterator aSelectedIndex = m_xIndexes->begin() + m_xIndexList->get_id(*pEntry).toUInt32(); // fill the controls - m_pUnique->Check(aSelectedIndex->bUnique); - m_pUnique->Enable(!aSelectedIndex->bPrimaryKey); - m_pUnique->SaveValue(); + m_xUnique->set_active(aSelectedIndex->bUnique); + m_xUnique->set_sensitive(!aSelectedIndex->bPrimaryKey); + m_xUnique->save_state(); - m_pFields->initializeFrom(aSelectedIndex->aFields); - m_pFields->Enable(!aSelectedIndex->bPrimaryKey); - m_pFields->SaveValue(); + m_xFields->initializeFrom(aSelectedIndex->aFields); + m_xFields->Enable(!aSelectedIndex->bPrimaryKey); + m_xFields->SaveValue(); - m_pDescription->SetText(aSelectedIndex->sDescription); - m_pDescription->Enable(!aSelectedIndex->bPrimaryKey); + m_xDescription->set_label(aSelectedIndex->sDescription); + m_xDescription->set_sensitive(!aSelectedIndex->bPrimaryKey); - m_pDescriptionLabel->Enable(!aSelectedIndex->bPrimaryKey); + m_xDescriptionLabel->set_sensitive(!aSelectedIndex->bPrimaryKey); } else { - m_pUnique->Check(false); - m_pFields->initializeFrom(IndexFields()); - m_pDescription->SetText(OUString()); + m_xUnique->set_active(false); + m_xFields->initializeFrom(IndexFields()); + m_xDescription->set_label(OUString()); } } - IMPL_LINK_NOARG( DbaIndexDialog, OnIndexSelected, DbaIndexList&, void ) + void DbaIndexDialog::IndexSelected() { - m_pIndexList->EndSelection(); +//TODO m_xIndexList->EndSelection(); + + if (m_bEditingActive) + m_xIndexList->end_editing(); - if (m_pIndexList->IsEditingActive()) - m_pIndexList->EndEditing(); + std::unique_ptr<weld::TreeIter> xSelected(m_xIndexList->make_iterator()); + if (!m_xIndexList->get_selected(xSelected.get())) + xSelected.reset(); // commit the old data - if (m_pIndexList->FirstSelected() != m_pPreviousSelection) - { // (this call may happen in case somebody ended an in-place edit with 'return', so we need to check this before committing) + if (m_xPreviousSelection && (!xSelected || !m_xPreviousSelection->equal(*xSelected))) + { + // (this call may happen in case somebody ended an in-place edit with 'return', so we need to check this before committing) if (!implCommitPreviouslySelected()) { - m_pIndexList->SelectNoHandlerCall(m_pPreviousSelection); + m_bNoHandlerCall = true; + m_xIndexList->select(*m_xPreviousSelection); + m_bNoHandlerCall = false; return; } } - bool bHaveSelection = (nullptr != m_pIndexList->FirstSelected()); - // disable/enable the detail controls - m_pIndexDetails->Enable(bHaveSelection); - m_pUnique->Enable(bHaveSelection); - m_pDescriptionLabel->Enable(bHaveSelection); - m_pFieldsLabel->Enable(bHaveSelection); - m_pFields->Enable(bHaveSelection); + m_xIndexDetails->set_sensitive(xSelected != nullptr); + m_xUnique->set_sensitive(xSelected != nullptr); + m_xDescriptionLabel->set_sensitive(xSelected != nullptr); + m_xFieldsLabel->set_sensitive(xSelected != nullptr); + m_xFields->Enable(xSelected != nullptr); - SvTreeListEntry* pNewSelection = m_pIndexList->FirstSelected(); - updateControls(pNewSelection); - if (bHaveSelection) - m_pIndexList->GrabFocus(); + updateControls(xSelected.get()); + if (xSelected) + m_xIndexList->grab_focus(); - m_pPreviousSelection = pNewSelection; + m_xPreviousSelection = std::move(xSelected); updateToolbox(); } - void DbaIndexDialog::StateChanged( StateChangedType nType ) - { - ModalDialog::StateChanged( nType ); - if ( nType == StateChangedType::ControlBackground ) - { - // Check if we need to get new images for normal/high contrast mode - checkImageList(); - } - else if ( nType == StateChangedType::Text ) - { - // The physical toolbar changed its outlook and shows another logical toolbar! - // We have to set the correct high contrast mode on the new tbx manager. - // pMgr->SetHiContrast( IsHiContrastMode() ); - checkImageList(); - } - } - void DbaIndexDialog::DataChanged( const DataChangedEvent& rDCEvt ) - { - ModalDialog::DataChanged( rDCEvt ); - - if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) || - ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) && - ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE )) - { - // Check if we need to get new images for normal/high contrast mode - checkImageList(); - } - } - - void DbaIndexDialog::setImageList(sal_Int16 _eBitmapSet) - { - if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE ) - { - m_pActions->SetItemImage(mnNewCmdId, maLcNewCmdImg); - m_pActions->SetItemImage(mnDropCmdId, maLcDropCmdImg); - m_pActions->SetItemImage(mnRenameCmdId, maLcRenameCmdImg); - m_pActions->SetItemImage(mnSaveCmdId, maLcSaveCmdImg); - m_pActions->SetItemImage(mnResetCmdId, maLcResetCmdImg); - } - else - { - m_pActions->SetItemImage(mnNewCmdId, maScNewCmdImg); - m_pActions->SetItemImage(mnDropCmdId, maScDropCmdImg); - m_pActions->SetItemImage(mnRenameCmdId, maScRenameCmdImg); - m_pActions->SetItemImage(mnSaveCmdId, maScSaveCmdImg); - m_pActions->SetItemImage(mnResetCmdId, maScResetCmdImg); - } - } - - void DbaIndexDialog::resizeControls(const Size&) + IMPL_LINK_NOARG(DbaIndexDialog, OnIndexSelected, weld::TreeView&, void) { + if (m_bNoHandlerCall) + return; + IndexSelected(); } - } // namespace dbaui /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/dlg/indexfieldscontrol.cxx b/dbaccess/source/ui/dlg/indexfieldscontrol.cxx index dc3296a7187a..cbcdf8320205 100644 --- a/dbaccess/source/ui/dlg/indexfieldscontrol.cxx +++ b/dbaccess/source/ui/dlg/indexfieldscontrol.cxx @@ -23,8 +23,8 @@ #include <strings.hrc> #include <osl/diagnose.h> #include <helpids.h> +#include <toolkit/helper/vclunohelper.hxx> #include <vcl/settings.hxx> -#include <vcl/builderfactory.hxx> #include <vcl/svapp.hxx> namespace dbaui @@ -70,8 +70,8 @@ static constexpr auto BROWSER_STANDARD_FLAGS = BrowserMode::COLUMNSELECTION | Br } // IndexFieldsControl - IndexFieldsControl::IndexFieldsControl( vcl::Window* _pParent, WinBits nWinStyle) - : EditBrowseBox(_pParent, EditBrowseBoxFlags::SMART_TAB_TRAVEL | EditBrowseBoxFlags::ACTIVATE_ON_BUTTONDOWN, nWinStyle, BROWSER_STANDARD_FLAGS) + IndexFieldsControl::IndexFieldsControl(const css::uno::Reference<css::awt::XWindow> &rParent) + : EditBrowseBox(VCLUnoHelper::GetWindow(rParent), EditBrowseBoxFlags::SMART_TAB_TRAVEL | EditBrowseBoxFlags::ACTIVATE_ON_BUTTONDOWN, WB_TABSTOP | WB_BORDER, BROWSER_STANDARD_FLAGS) , m_aSeekRow(m_aFields.end()) , m_pSortingCell(nullptr) , m_pFieldNameCell(nullptr) @@ -79,13 +79,6 @@ static constexpr auto BROWSER_STANDARD_FLAGS = BrowserMode::COLUMNSELECTION | Br { } - extern "C" SAL_DLLPUBLIC_EXPORT void makeDbaIndexFieldsControl(VclPtr<vcl::Window> & rRet, const VclPtr<vcl::Window> & pParent, VclBuilder::stringmap &) - { - static_assert(std::is_same_v<std::remove_pointer_t<VclBuilder::customMakeWidget>, - decltype(makeDbaIndexFieldsControl)>); - rRet = VclPtr<IndexFieldsControl>::Create(pParent, WB_BORDER | WB_NOTABSTOP); - } - IndexFieldsControl::~IndexFieldsControl() { disposeOnce(); diff --git a/dbaccess/source/ui/inc/indexdialog.hxx b/dbaccess/source/ui/inc/indexdialog.hxx index ab7311b6b2ea..15598d99c04b 100644 --- a/dbaccess/source/ui/inc/indexdialog.hxx +++ b/dbaccess/source/ui/inc/indexdialog.hxx @@ -20,144 +20,83 @@ #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_INDEXDIALOG_HXX #define INCLUDED_DBACCESS_SOURCE_UI_INC_INDEXDIALOG_HXX -#include <vcl/dialog.hxx> -#include <vcl/fixed.hxx> -#include <vcl/button.hxx> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/XComponentContext.hpp> -#include <vcl/toolbox.hxx> -#include <vcl/treelistbox.hxx> #include <unotools/viewoptions.hxx> +#include <vcl/weld.hxx> #include "indexes.hxx" -#include <dbaccess/ToolBoxHelper.hxx> namespace dbaui { - - // DbaIndexList - class DbaIndexList final : public SvTreeListBox - { - css::uno::Reference< css::sdbc::XConnection > m_xConnection; - Link<DbaIndexList&,void> m_aSelectHdl; - Link<SvTreeListEntry*,bool> m_aEndEditHdl; - bool m_bSuspendSelectHdl; - - public: - DbaIndexList(vcl::Window* _pParent, WinBits nWinBits); - - void SetSelectHdl(const Link<DbaIndexList&,void>& _rHdl) { m_aSelectHdl = _rHdl; } - - void SetEndEditHdl(const Link<SvTreeListEntry*,bool>& _rHdl) { m_aEndEditHdl = _rHdl; } - - virtual bool Select(SvTreeListEntry* pEntry, bool bSelect = true) override; - - void enableSelectHandler(); - void disableSelectHandler(); - - void SelectNoHandlerCall( SvTreeListEntry* pEntry ); - - void setConnection(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection) - { - m_xConnection = _rxConnection; - } - - private: - virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) override; - - using SvTreeListBox::Select; - }; - // DbaIndexDialog class IndexFieldsControl; class OIndexCollection; - class DbaIndexDialog final : public ModalDialog, - public OToolBoxHelper + class DbaIndexDialog final : public weld::GenericDialogController { css::uno::Reference< css::sdbc::XConnection > m_xConnection; - VclPtr<ToolBox> m_pActions; - VclPtr<DbaIndexList> m_pIndexList; - VclPtr<FixedText> m_pIndexDetails; - VclPtr<FixedText> m_pDescriptionLabel; - VclPtr<FixedText> m_pDescription; - VclPtr<CheckBox> m_pUnique; - VclPtr<FixedText> m_pFieldsLabel; - VclPtr<IndexFieldsControl> m_pFields; - VclPtr<PushButton> m_pClose; - - std::unique_ptr<OIndexCollection> m_pIndexes; - SvTreeListEntry* m_pPreviousSelection; + std::unique_ptr<OIndexCollection> m_xIndexes; + std::unique_ptr<weld::TreeIter> m_xPreviousSelection; + bool m_bEditingActive; bool m_bEditAgain; + bool m_bNoHandlerCall; css::uno::Reference< css::uno::XComponentContext > m_xContext; + + std::unique_ptr<weld::Toolbar> m_xActions; + std::unique_ptr<weld::TreeView> m_xIndexList; + std::unique_ptr<weld::Label> m_xIndexDetails; + std::unique_ptr<weld::Label> m_xDescriptionLabel; + std::unique_ptr<weld::Label> m_xDescription; + std::unique_ptr<weld::CheckButton> m_xUnique; + std::unique_ptr<weld::Label> m_xFieldsLabel; + std::unique_ptr<weld::Button> m_xClose; + std::unique_ptr<weld::Container> m_xTable; + css::uno::Reference<css::awt::XWindow> m_xTableCtrlParent; + VclPtr<IndexFieldsControl> m_xFields; + public: DbaIndexDialog( - vcl::Window* _pParent, + weld::Window* _pParent, const css::uno::Sequence< OUString >& _rFieldNames, const css::uno::Reference< css::container::XNameAccess >& _rxIndexes, const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, - const css::uno::Reference< css::uno::XComponentContext >& _rxContext - ); + const css::uno::Reference< css::uno::XComponentContext >& _rxContext); virtual ~DbaIndexDialog() override; - virtual void dispose() override; - - virtual void StateChanged( StateChangedType nStateChange ) override; - virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; - - //TO-DO, remove when all other OToolBoxHelper are converted to .ui - virtual void resizeControls(const Size&) override; - /** will be called when the id of the image list needs to change - @param _eBitmapSet - <svtools/imgdef.hxx> - */ - virtual void setImageList(sal_Int16 _eBitmapSet) override; + typedef std::pair<const weld::TreeIter&, OUString> IterString; private: void fillIndexList(); void updateToolbox(); - void updateControls(const SvTreeListEntry* _pEntry); + void updateControls(const weld::TreeIter* pEntry); - DECL_LINK( OnIndexSelected, DbaIndexList&, void ); - DECL_LINK( OnIndexAction, ToolBox*, void ); - DECL_LINK( OnEntryEdited, SvTreeListEntry*, bool ); - DECL_LINK( OnModifiedClick, Button*, void ); + void IndexSelected(); + + DECL_LINK( OnIndexSelected, weld::TreeView&, void ); + DECL_LINK( OnIndexAction, const OString&, void ); + DECL_STATIC_LINK(DbaIndexDialog, OnEntryEditing, const weld::TreeIter&, bool); + DECL_LINK( OnEntryEdited, const IterString&, bool ); + DECL_LINK( OnModifiedClick, weld::Button&, void ); DECL_LINK( OnModified, IndexFieldsControl&, void ); - DECL_LINK( OnCloseDialog, Button*, void ); + DECL_LINK( OnCloseDialog, weld::Button&, void ); DECL_LINK( OnEditIndexAgain, void*, void ); - sal_uInt16 mnNewCmdId; - sal_uInt16 mnDropCmdId; - sal_uInt16 mnRenameCmdId; - sal_uInt16 mnSaveCmdId; - sal_uInt16 mnResetCmdId; - - Image maScNewCmdImg; - Image maScDropCmdImg; - Image maScRenameCmdImg; - Image maScSaveCmdImg; - Image maScResetCmdImg; - Image maLcNewCmdImg; - Image maLcDropCmdImg; - Image maLcRenameCmdImg; - Image maLcSaveCmdImg; - Image maLcResetCmdImg; - void OnNewIndex(); void OnDropIndex(bool _bConfirm = true); void OnRenameIndex(); void OnSaveIndex(); void OnResetIndex(); - bool implCommit(SvTreeListEntry const * _pEntry); + bool implCommit(const weld::TreeIter* pEntry); bool implSaveModified(bool _bPlausibility = true); bool implCommitPreviouslySelected(); - bool implDropIndex(SvTreeListEntry const * _pEntry, bool _bRemoveFromCollection); + bool implDropIndex(const weld::TreeIter* pEntry, bool _bRemoveFromCollection); bool implCheckPlausibility(const Indexes::const_iterator& _rPos); }; diff --git a/dbaccess/source/ui/inc/indexfieldscontrol.hxx b/dbaccess/source/ui/inc/indexfieldscontrol.hxx index 58b246dc65bf..3a4c8bbddca1 100644 --- a/dbaccess/source/ui/inc/indexfieldscontrol.hxx +++ b/dbaccess/source/ui/inc/indexfieldscontrol.hxx @@ -22,6 +22,7 @@ #include <svtools/editbrowsebox.hxx> #include "indexcollection.hxx" +#include <com/sun/star/awt/XWindow.hpp> #include <com/sun/star/uno/Sequence.hxx> namespace dbaui @@ -48,7 +49,7 @@ namespace dbaui bool m_bAddIndexAppendix; public: - IndexFieldsControl( vcl::Window* _pParent, WinBits nWinStyle); + IndexFieldsControl(const css::uno::Reference<css::awt::XWindow> &rParent); virtual ~IndexFieldsControl() override; virtual void dispose() override; diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index b7b8a11b4579..06e7b1c9976a 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -474,8 +474,8 @@ void OTableController::doEditIndexes() if (!xIndexes.is()) return; - ScopedVclPtrInstance< DbaIndexDialog > aDialog(getView(), aFieldNames, xIndexes, getConnection(), getORB()); - if (RET_OK != aDialog->Execute()) + DbaIndexDialog aDialog(getFrameWeld(), aFieldNames, xIndexes, getConnection(), getORB()); + if (RET_OK != aDialog.run()) return; } diff --git a/dbaccess/uiconfig/ui/indexdesigndialog.ui b/dbaccess/uiconfig/ui/indexdesigndialog.ui index d11e0d077694..96a672bbdc97 100644 --- a/dbaccess/uiconfig/ui/indexdesigndialog.ui +++ b/dbaccess/uiconfig/ui/indexdesigndialog.ui @@ -1,14 +1,26 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.18.3 --> +<!-- Generated with glade 3.22.1 --> <interface domain="dba"> <requires lib="gtk+" version="3.18"/> - <requires lib="LibreOffice" version="1.0"/> + <object class="GtkTreeStore" id="liststore1"> + <columns> + <!-- column-name expander --> + <column type="GdkPixbuf"/> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name id --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkDialog" id="IndexDesignDialog"> <property name="can_focus">False</property> <property name="border_width">6</property> <property name="title" translatable="yes" context="indexdesigndialog|IndexDesignDialog">Indexes</property> <property name="resizable">False</property> <property name="type_hint">dialog</property> + <child> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> <property name="can_focus">False</property> @@ -74,7 +86,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="action_name">.index:createNew</property> <property name="label" translatable="yes" context="indexdesigndialog|ID_INDEX_NEW">New Index</property> <property name="use_underline">True</property> <property name="icon_name">dbaccess/res/sc036.png</property> @@ -89,7 +100,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="action_name">.index:dropCurrent</property> <property name="label" translatable="yes" context="indexdesigndialog|ID_INDEX_DROP">Delete Current Index</property> <property name="use_underline">True</property> <property name="icon_name">dbaccess/res/sc037.png</property> @@ -104,7 +114,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="action_name">.index:renameCurrent</property> <property name="label" translatable="yes" context="indexdesigndialog|ID_INDEX_RENAME">Rename Current Index</property> <property name="use_underline">True</property> <property name="icon_name">dbaccess/res/sc038.png</property> @@ -119,7 +128,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="action_name">.index:saveCurrent</property> <property name="label" translatable="yes" context="indexdesigndialog|ID_INDEX_SAVE">Save Current Index</property> <property name="use_underline">True</property> <property name="icon_name">dbaccess/res/sc039.png</property> @@ -134,7 +142,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="action_name">.index:resetCurrent</property> <property name="label" translatable="yes" context="indexdesigndialog|ID_INDEX_RESET">Reset Current Index</property> <property name="use_underline">True</property> <property name="icon_name">dbaccess/res/sc040.png</property> @@ -150,75 +157,6 @@ <property name="top_attach">0</property> </packing> </child> - <child> - <object class="GtkGrid" id="grid2"> - <property name="can_focus">False</property> - <property name="no_show_all">True</property> - <property name="halign">end</property> - <property name="valign">center</property> - <property name="hexpand">True</property> - <property name="column_spacing">12</property> - <child> - <object class="GtkImage" id="image1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="pixbuf">dbaccess/res/lc036.png</property> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">0</property> - </packing> - </child> - <child> - <object class="GtkImage" id="image2"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="pixbuf">dbaccess/res/lc037.png</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">0</property> - </packing> - </child> - <child> - <object class="GtkImage" id="image3"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="pixbuf">dbaccess/res/lc038.png</property> - </object> - <packing> - <property name="left_attach">2</property> - <property name="top_attach">0</property> - </packing> - </child> - <child> - <object class="GtkImage" id="image4"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="pixbuf">dbaccess/res/lc039.png</property> - </object> - <packing> - <property name="left_attach">3</property> - <property name="top_attach">0</property> - </packing> - </child> - <child> - <object class="GtkImage" id="image5"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="pixbuf">dbaccess/res/lc040.png</property> - </object> - <packing> - <property name="left_attach">4</property> - <property name="top_attach">0</property> - </packing> - </child> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">0</property> - </packing> - </child> </object> <packing> <property name="expand">False</property> @@ -233,13 +171,47 @@ <property name="row_spacing">6</property> <property name="column_spacing">12</property> <child> - <object class="dbulo-DbaIndexList" id="INDEX_LIST"> + <object class="GtkScrolledWindow"> <property name="visible">True</property> - <property name="can_focus">False</property> + <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="DbaIndexList-selection1"/> + <property name="shadow_type">in</property> + <child> + <object class="GtkTreeView" id="INDEX_LIST"> + <property name="width_request">-1</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="model">liststore1</property> + <property name="headers_visible">False</property> + <property name="search_column">1</property> + <property name="enable_tree_lines">True</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="Macro Library List-selection1"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn2"> + <property name="spacing">6</property> + <child> + <object class="GtkCellRendererPixbuf" id="cellrenderertext4"/> + <attributes> + <attribute name="pixbuf">0</attribute> + </attributes> + </child> + <child> + <object class="GtkCellRendererText" id="cellrenderertext2"> + <property name="editable">True</property> + </object> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> + </child> + </object> </child> </object> <packing> @@ -270,8 +242,8 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="halign">start</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="indexdesigndialog|DESC_LABEL">Index identifier:</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">0</property> @@ -312,9 +284,9 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="halign">start</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="indexdesigndialog|FIELDS_LABEL">Fields:</property> <property name="use_underline">True</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">0</property> @@ -323,14 +295,11 @@ </packing> </child> <child> - <object class="dbulo-DbaIndexFieldsControl" id="FIELDS"> + <object class="GtkBox" id="FIELDS"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="IndexFieldsControl-selection"/> - </child> </object> <packing> <property name="left_attach">0</property> diff --git a/extras/source/glade/libreoffice-catalog.xml.in b/extras/source/glade/libreoffice-catalog.xml.in index fd505edb1490..7bd0c3fe56e7 100644 --- a/extras/source/glade/libreoffice-catalog.xml.in +++ b/extras/source/glade/libreoffice-catalog.xml.in @@ -213,13 +213,6 @@ generic-name="Writer Navigator ToolBox" parent="GtkToolbar" icon-name="widget-gtk-toolbar"/> - <glade-widget-class title="IndexFieldsControl" name="dbulo-DbaIndexFieldsControl" - generic-name="IndexFieldsControl" parent="GtkTreeView" - icon-name="widget-gtk-treeview"/> - <glade-widget-class title="DbaIndexList" name="dbulo-DbaIndexList" - generic-name="DbaIndexList" parent="GtkTreeView" - icon-name="widget-gtk-treeview"/> - <glade-widget-class title="Recent Documents View" name="sfxlo-RecentDocsView" generic-name="Icon View" parent="GtkIconView" icon-name="widget-gtk-iconview"/> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 8a1f7ae43d26..5338ce410a62 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -880,6 +880,9 @@ public: m_aEditingDoneHdl = rLink; } + virtual void start_editing(const weld::TreeIter& rEntry) = 0; + virtual void end_editing() = 0; + virtual void connect_visible_range_changed(const Link<TreeView&, void>& rLink) { assert(!m_aVisibleRangeChangedHdl.IsSet() || !rLink.IsSet()); diff --git a/solenv/sanitizers/ui/dbaccess.suppr b/solenv/sanitizers/ui/dbaccess.suppr index 82858ecfb543..99ccc2bc0eb2 100644 --- a/solenv/sanitizers/ui/dbaccess.suppr +++ b/solenv/sanitizers/ui/dbaccess.suppr @@ -36,7 +36,6 @@ dbaccess/uiconfig/ui/generalspecialjdbcdetailspage.ui://GtkEntry[@id='socketEntr dbaccess/uiconfig/ui/indexdesigndialog.ui://GtkLabel[@id='DESC_LABEL'] orphan-label dbaccess/uiconfig/ui/indexdesigndialog.ui://GtkLabel[@id='DESCRIPTION'] orphan-label dbaccess/uiconfig/ui/indexdesigndialog.ui://GtkLabel[@id='FIELDS_LABEL'] orphan-label -dbaccess/uiconfig/ui/indexdesigndialog.ui://dbulo-DbaIndexFieldsControl[@id='FIELDS'] no-labelled-by dbaccess/uiconfig/ui/jdbcconnectionpage.ui://GtkLabel[@id='header'] orphan-label dbaccess/uiconfig/ui/jdbcconnectionpage.ui://GtkLabel[@id='helptext'] orphan-label dbaccess/uiconfig/ui/joindialog.ui://GtkLabel[@id='helptext'] orphan-label diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index fdebbc47f05c..de80c738c59b 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -3717,6 +3717,17 @@ public: weld::TreeView::connect_editing_done(rLink); } + virtual void start_editing(const weld::TreeIter& rIter) override + { + const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); + m_xTreeView->EditEntry(rVclIter.iter); + } + + virtual void end_editing() override + { + m_xTreeView->EndEditing(); + } + void set_image(SvTreeListEntry* pEntry, const Image& rImage, int col) { if (col == -1) diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 9ab4bae06a09..333db6693d13 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -8648,6 +8648,29 @@ public: return ret; } + virtual void start_editing(const weld::TreeIter& rIter) override + { + int col = get_view_col(m_nTextCol); + GtkTreeViewColumn* pColumn = GTK_TREE_VIEW_COLUMN(g_list_nth_data(m_pColumns, col)); + assert(pColumn && "wrong column"); + + const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); + GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore); + GtkTreePath* path = gtk_tree_model_get_path(pModel, const_cast<GtkTreeIter*>(&rGtkIter.iter)); + + gtk_tree_view_set_cursor(m_pTreeView, path, pColumn, true); + + gtk_tree_path_free(path); + } + + virtual void end_editing() override + { + GtkTreeViewColumn *focus_column = nullptr; + gtk_tree_view_get_cursor(m_pTreeView, nullptr, &focus_column); + if (focus_column) + gtk_cell_area_stop_editing(gtk_cell_layout_get_area(GTK_CELL_LAYOUT(focus_column)), true); + } + virtual TreeView* get_drag_source() const override { return g_DragSource; @@ -8720,10 +8743,7 @@ IMPL_LINK_NOARG(GtkInstanceTreeView, async_signal_changed, void*, void) IMPL_LINK_NOARG(GtkInstanceTreeView, async_stop_cell_editing, void*, void) { - GtkTreeViewColumn *focus_column = nullptr; - gtk_tree_view_get_cursor(m_pTreeView, nullptr, &focus_column); - if (focus_column) - gtk_cell_area_stop_editing(gtk_cell_layout_get_area(GTK_CELL_LAYOUT(focus_column)), true); + end_editing(); } class GtkInstanceSpinButton : public GtkInstanceEntry, public virtual weld::SpinButton |