diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-30 10:38:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-30 21:37:05 +0200 |
commit | 51735e6946dca0528a4b78d06ef43bd84c38e5e1 (patch) | |
tree | 1199c84c158e5512205488d30e73bf0f30fd8a0d | |
parent | c0a4af22ed3cac188274fe51cbf3bcfe47d6acf8 (diff) |
loplugin:flatten in sw/ui/dbui
Change-Id: Iab627f306a1caf52237369471393753bf2c736f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99804
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/source/ui/chrdlg/drpcps.cxx | 74 | ||||
-rw-r--r-- | sw/source/ui/config/optcomp.cxx | 26 | ||||
-rw-r--r-- | sw/source/ui/config/optload.cxx | 26 | ||||
-rw-r--r-- | sw/source/ui/config/optpage.cxx | 26 | ||||
-rw-r--r-- | sw/source/ui/dbui/addresslistdialog.cxx | 281 | ||||
-rw-r--r-- | sw/source/ui/dbui/createaddresslistdialog.cxx | 52 | ||||
-rw-r--r-- | sw/source/ui/dbui/dbinsdlg.cxx | 22 | ||||
-rw-r--r-- | sw/source/ui/dbui/mmaddressblockpage.cxx | 62 | ||||
-rw-r--r-- | sw/source/ui/dbui/mmlayoutpage.cxx | 130 | ||||
-rw-r--r-- | sw/source/ui/dbui/mmoutputtypepage.cxx | 60 | ||||
-rw-r--r-- | sw/source/ui/dbui/selectdbtabledialog.cxx | 22 |
11 files changed, 391 insertions, 390 deletions
diff --git a/sw/source/ui/chrdlg/drpcps.cxx b/sw/source/ui/chrdlg/drpcps.cxx index 9580fbd37242..f407db4b49bc 100644 --- a/sw/source/ui/chrdlg/drpcps.cxx +++ b/sw/source/ui/chrdlg/drpcps.cxx @@ -696,49 +696,49 @@ IMPL_LINK_NOARG(SwDropCapsPage, SelectHdl, weld::ComboBox&, void) void SwDropCapsPage::FillSet( SfxItemSet &rSet ) { - if(bModified) - { - SwFormatDrop aFormat; + if(!bModified) + return; - bool bOn = m_xDropCapsBox->get_active(); - if (bOn) - { - // quantity, lines, gap - aFormat.GetChars() = static_cast<sal_uInt8>(m_xDropCapsField->get_value()); - aFormat.GetLines() = static_cast<sal_uInt8>(m_xLinesField->get_value()); - aFormat.GetDistance() = static_cast<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP))); - aFormat.GetWholeWord() = m_xWholeWordCB->get_active(); - - // template - if (m_xTemplateBox->get_active()) - aFormat.SetCharFormat(rSh.GetCharStyle(m_xTemplateBox->get_active_text())); - } - else - { - aFormat.GetChars() = 1; - aFormat.GetLines() = 1; - aFormat.GetDistance() = 0; - } + SwFormatDrop aFormat; - // set attributes - const SfxPoolItem* pOldItem; - if (nullptr == (pOldItem = GetOldItem(rSet, FN_FORMAT_DROPCAPS)) || aFormat != *pOldItem) - rSet.Put(aFormat); + bool bOn = m_xDropCapsBox->get_active(); + if (bOn) + { + // quantity, lines, gap + aFormat.GetChars() = static_cast<sal_uInt8>(m_xDropCapsField->get_value()); + aFormat.GetLines() = static_cast<sal_uInt8>(m_xLinesField->get_value()); + aFormat.GetDistance() = static_cast<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP))); + aFormat.GetWholeWord() = m_xWholeWordCB->get_active(); + + // template + if (m_xTemplateBox->get_active()) + aFormat.SetCharFormat(rSh.GetCharStyle(m_xTemplateBox->get_active_text())); + } + else + { + aFormat.GetChars() = 1; + aFormat.GetLines() = 1; + aFormat.GetDistance() = 0; + } - // hard text formatting - // Bug 24974: in designer/template catalog this doesn't make sense!! - if (!bFormat && m_xDropCapsBox->get_active()) - { - OUString sText(m_xTextEdit->get_text()); + // set attributes + const SfxPoolItem* pOldItem; + if (nullptr == (pOldItem = GetOldItem(rSet, FN_FORMAT_DROPCAPS)) || aFormat != *pOldItem) + rSet.Put(aFormat); - if (!m_xWholeWordCB->get_active()) - { - sText = sText.copy(0, std::min<sal_Int32>(sText.getLength(), m_xDropCapsField->get_value())); - } + // hard text formatting + // Bug 24974: in designer/template catalog this doesn't make sense!! + if (!bFormat && m_xDropCapsBox->get_active()) + { + OUString sText(m_xTextEdit->get_text()); - SfxStringItem aStr(FN_PARAM_1, sText); - rSet.Put(aStr); + if (!m_xWholeWordCB->get_active()) + { + sText = sText.copy(0, std::min<sal_Int32>(sText.getLength(), m_xDropCapsField->get_value())); } + + SfxStringItem aStr(FN_PARAM_1, sText); + rSet.Put(aStr); } } diff --git a/sw/source/ui/config/optcomp.cxx b/sw/source/ui/config/optcomp.cxx index 293e798e09b4..ac0d1c3ed063 100644 --- a/sw/source/ui/config/optcomp.cxx +++ b/sw/source/ui/config/optcomp.cxx @@ -268,24 +268,24 @@ IMPL_LINK_NOARG(SwCompatibilityOptPage, UseAsDefaultHdl, weld::Button&, void) { std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/querydefaultcompatdialog.ui")); std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("QueryDefaultCompatDialog")); - if (xQueryBox->run() == RET_YES) + if (xQueryBox->run() != RET_YES) + return; + + auto pItem = std::find_if(m_pImpl->m_aList.begin(), m_pImpl->m_aList.end(), + [](const SvtCompatibilityEntry& rItem) { return rItem.isDefaultEntry(); }); + if (pItem != m_pImpl->m_aList.end()) { - auto pItem = std::find_if(m_pImpl->m_aList.begin(), m_pImpl->m_aList.end(), - [](const SvtCompatibilityEntry& rItem) { return rItem.isDefaultEntry(); }); - if (pItem != m_pImpl->m_aList.end()) + const sal_Int32 nCount = m_xOptionsLB->n_children(); + for ( sal_Int32 i = 0; i < nCount; ++i ) { - const sal_Int32 nCount = m_xOptionsLB->n_children(); - for ( sal_Int32 i = 0; i < nCount; ++i ) - { - bool bChecked = m_xOptionsLB->get_toggle(i); + bool bChecked = m_xOptionsLB->get_toggle(i); - int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */ - pItem->setValue<bool>( SvtCompatibilityEntry::Index(nCoptIdx), bChecked ); - } + int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */ + pItem->setValue<bool>( SvtCompatibilityEntry::Index(nCoptIdx), bChecked ); } - - WriteOptions(); } + + WriteOptions(); } void SwCompatibilityOptPage::SetCurrentOptions( sal_uInt32 nOptions ) diff --git a/sw/source/ui/config/optload.cxx b/sw/source/ui/config/optload.cxx index 9a5d934367a7..25b93c773e15 100644 --- a/sw/source/ui/config/optload.cxx +++ b/sw/source/ui/config/optload.cxx @@ -349,19 +349,19 @@ void SwLoadOptPage::Reset( const SfxItemSet* rSet) IMPL_LINK_NOARG(SwLoadOptPage, MetricHdl, weld::ComboBox&, void) { const sal_Int32 nMPos = m_xMetricLB->get_active(); - if(nMPos != -1) - { - // Double-Cast for VA3.0 - FieldUnit eFieldUnit = static_cast<FieldUnit>(m_xMetricLB->get_id(nMPos).toUInt32()); - bool bModified = m_xTabMF->get_value_changed_from_saved(); - long nVal = bModified ? - sal::static_int_cast<sal_Int32, sal_Int64 >( m_xTabMF->denormalize( m_xTabMF->get_value( FieldUnit::TWIP ) )) : - m_nLastTab; - ::SetFieldUnit( *m_xTabMF, eFieldUnit ); - m_xTabMF->set_value( m_xTabMF->normalize( nVal ), FieldUnit::TWIP ); - if (!bModified) - m_xTabMF->save_value(); - } + if(nMPos == -1) + return; + + // Double-Cast for VA3.0 + FieldUnit eFieldUnit = static_cast<FieldUnit>(m_xMetricLB->get_id(nMPos).toUInt32()); + bool bModified = m_xTabMF->get_value_changed_from_saved(); + long nVal = bModified ? + sal::static_int_cast<sal_Int32, sal_Int64 >( m_xTabMF->denormalize( m_xTabMF->get_value( FieldUnit::TWIP ) )) : + m_nLastTab; + ::SetFieldUnit( *m_xTabMF, eFieldUnit ); + m_xTabMF->set_value( m_xTabMF->normalize( nVal ), FieldUnit::TWIP ); + if (!bModified) + m_xTabMF->save_value(); } SwCaptionOptDlg::SwCaptionOptDlg(weld::Window* pParent, const SfxItemSet& rSet) diff --git a/sw/source/ui/config/optpage.cxx b/sw/source/ui/config/optpage.cxx index fda991a7abfb..1fff3ebb657b 100644 --- a/sw/source/ui/config/optpage.cxx +++ b/sw/source/ui/config/optpage.cxx @@ -2173,20 +2173,20 @@ void SwTestTabPage::Reset( const SfxItemSet* ) const SfxItemSet& rSet = GetItemSet(); const SwTestItem* pTestAttr = nullptr; - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_SWTEST , false, + if( SfxItemState::SET != rSet.GetItemState( FN_PARAM_SWTEST , false, reinterpret_cast<const SfxPoolItem**>(&pTestAttr) )) - { - m_xTest1CBox->set_active(pTestAttr->m_bTest1); - m_xTest2CBox->set_active(pTestAttr->m_bTest2); - m_xTest3CBox->set_active(pTestAttr->m_bTest3); - m_xTest4CBox->set_active(pTestAttr->m_bTest4); - m_xTest5CBox->set_active(pTestAttr->m_bTest5); - m_xTest6CBox->set_active(pTestAttr->m_bTest6); - m_xTest7CBox->set_active(pTestAttr->m_bTest7); - m_xTest8CBox->set_active(pTestAttr->m_bTest8); - m_xTest9CBox->set_active(pTestAttr->m_bTest9); - m_xTest10CBox->set_active(pTestAttr->m_bTest10); - } + return; + + m_xTest1CBox->set_active(pTestAttr->m_bTest1); + m_xTest2CBox->set_active(pTestAttr->m_bTest2); + m_xTest3CBox->set_active(pTestAttr->m_bTest3); + m_xTest4CBox->set_active(pTestAttr->m_bTest4); + m_xTest5CBox->set_active(pTestAttr->m_bTest5); + m_xTest6CBox->set_active(pTestAttr->m_bTest6); + m_xTest7CBox->set_active(pTestAttr->m_bTest7); + m_xTest8CBox->set_active(pTestAttr->m_bTest8); + m_xTest9CBox->set_active(pTestAttr->m_bTest9); + m_xTest10CBox->set_active(pTestAttr->m_bTest10); } void SwTestTabPage::Init() diff --git a/sw/source/ui/dbui/addresslistdialog.cxx b/sw/source/ui/dbui/addresslistdialog.cxx index 77291826ebb0..4c0b23195ff6 100644 --- a/sw/source/ui/dbui/addresslistdialog.cxx +++ b/sw/source/ui/dbui/addresslistdialog.cxx @@ -225,52 +225,52 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, weld::Button&, void) { int nSelect = m_xListLB->get_selected_index(); uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); - if (nSelect != -1) - { - const OUString sCommand = m_xListLB->get_text(nSelect, 1); - if (sCommand.isEmpty()) - return; + if (nSelect == -1) + return; - AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64()); - if (pUserData->xConnection.is() ) + const OUString sCommand = m_xListLB->get_text(nSelect, 1); + if (sCommand.isEmpty()) + return; + + AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64()); + if (!pUserData->xConnection.is() ) + return; + + try + { + uno::Reference<lang::XMultiServiceFactory> xConnectFactory(pUserData->xConnection, UNO_QUERY_THROW); + uno::Reference<XSingleSelectQueryComposer> xComposer( + xConnectFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY_THROW); + + uno::Reference<XRowSet> xRowSet( + xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY); + uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY); + xRowProperties->setPropertyValue("DataSourceName", + makeAny(m_xListLB->get_text(nSelect, 0))); + xRowProperties->setPropertyValue("Command", makeAny(sCommand)); + xRowProperties->setPropertyValue("CommandType", makeAny(pUserData->nCommandType)); + xRowProperties->setPropertyValue("ActiveConnection", makeAny(pUserData->xConnection.getTyped())); + xRowSet->execute(); + + OUString sQuery; + xRowProperties->getPropertyValue("ActiveCommand")>>= sQuery; + xComposer->setQuery(sQuery); + if(!pUserData->sFilter.isEmpty()) + xComposer->setFilter(pUserData->sFilter); + + uno::Reference< XExecutableDialog> xDialog = sdb::FilterDialog::createWithQuery( comphelper::getComponentContext(xMgr), + xComposer,xRowSet, uno::Reference<awt::XWindow>() ); + + if ( RET_OK == xDialog->execute() ) { - try - { - uno::Reference<lang::XMultiServiceFactory> xConnectFactory(pUserData->xConnection, UNO_QUERY_THROW); - uno::Reference<XSingleSelectQueryComposer> xComposer( - xConnectFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY_THROW); - - uno::Reference<XRowSet> xRowSet( - xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY); - uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY); - xRowProperties->setPropertyValue("DataSourceName", - makeAny(m_xListLB->get_text(nSelect, 0))); - xRowProperties->setPropertyValue("Command", makeAny(sCommand)); - xRowProperties->setPropertyValue("CommandType", makeAny(pUserData->nCommandType)); - xRowProperties->setPropertyValue("ActiveConnection", makeAny(pUserData->xConnection.getTyped())); - xRowSet->execute(); - - OUString sQuery; - xRowProperties->getPropertyValue("ActiveCommand")>>= sQuery; - xComposer->setQuery(sQuery); - if(!pUserData->sFilter.isEmpty()) - xComposer->setFilter(pUserData->sFilter); - - uno::Reference< XExecutableDialog> xDialog = sdb::FilterDialog::createWithQuery( comphelper::getComponentContext(xMgr), - xComposer,xRowSet, uno::Reference<awt::XWindow>() ); - - if ( RET_OK == xDialog->execute() ) - { - weld::WaitObject aWait(m_xDialog.get()); - pUserData->sFilter = xComposer->getFilter(); - } - ::comphelper::disposeComponent(xRowSet); - } - catch (const Exception&) - { - OSL_FAIL("exception caught in SwAddressListDialog::FilterHdl_Impl"); - } + weld::WaitObject aWait(m_xDialog.get()); + pUserData->sFilter = xComposer->getFilter(); } + ::comphelper::disposeComponent(xRowSet); + } + catch (const Exception&) + { + OSL_FAIL("exception caught in SwAddressListDialog::FilterHdl_Impl"); } } @@ -295,25 +295,26 @@ IMPL_LINK_NOARG(SwAddressListDialog, LoadHdl_Impl, weld::Button&, void) IMPL_LINK_NOARG(SwAddressListDialog, RemoveHdl_Impl, weld::Button&, void) { int nEntry = m_xListLB->get_selected_index(); - if (nEntry != -1) - { - std::unique_ptr<weld::MessageDialog> xQuery(Application::CreateMessageDialog(getDialog(), - VclMessageType::Question, VclButtonsType::YesNo, SwResId(ST_DELETE_CONFIRM))); - if (xQuery->run() == RET_YES) - { // Remove data source connection - SwDBManager::RevokeDataSource(m_xListLB->get_selected_text()); - // Remove item from the list - m_xListLB->remove(nEntry); - // If this was the last item, disable the Remove & Edit buttons and enable Create - if (m_xListLB->n_children() < 1 ) - { - m_xRemovePB->set_sensitive(false); - m_xEditPB->set_sensitive(false); - m_xFilterPB->set_sensitive(false); - m_xCreateListPB->set_sensitive(true); - } + if (nEntry == -1) + return; + + std::unique_ptr<weld::MessageDialog> xQuery(Application::CreateMessageDialog(getDialog(), + VclMessageType::Question, VclButtonsType::YesNo, SwResId(ST_DELETE_CONFIRM))); + if (xQuery->run() != RET_YES) + return; + + // Remove data source connection + SwDBManager::RevokeDataSource(m_xListLB->get_selected_text()); + // Remove item from the list + m_xListLB->remove(nEntry); + // If this was the last item, disable the Remove & Edit buttons and enable Create + if (m_xListLB->n_children() < 1 ) + { + m_xRemovePB->set_sensitive(false); + m_xEditPB->set_sensitive(false); + m_xFilterPB->set_sensitive(false); + m_xCreateListPB->set_sensitive(true); } - } } @@ -321,74 +322,74 @@ IMPL_LINK_NOARG(SwAddressListDialog, RemoveHdl_Impl, weld::Button&, void) IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, weld::Button&, void) { SwCreateAddressListDialog aDlg(m_xDialog.get(), /*sInputURL*/OUString(), m_pAddressPage->GetWizard()->GetConfigItem()); - if (RET_OK == aDlg.run()) + if (RET_OK != aDlg.run()) + return; + + //register the URL a new datasource + const OUString sURL = aDlg.GetURL(); + try { - //register the URL a new datasource - const OUString sURL = aDlg.GetURL(); - try + uno::Reference<XInterface> xNewInstance = m_xDBContext->createInstance(); + INetURLObject aURL( sURL ); + const OUString sNewName = aURL.getBase(); + //find a unique name if sNewName already exists + OUString sFind(sNewName); + sal_Int32 nIndex = 0; + while(m_xDBContext->hasByName(sFind)) { - uno::Reference<XInterface> xNewInstance = m_xDBContext->createInstance(); - INetURLObject aURL( sURL ); - const OUString sNewName = aURL.getBase(); - //find a unique name if sNewName already exists - OUString sFind(sNewName); - sal_Int32 nIndex = 0; - while(m_xDBContext->hasByName(sFind)) - { - sFind = sNewName + OUString::number(++nIndex); - } - uno::Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY); - - //only the 'path' has to be added - INetURLObject aTempURL(aURL); - aTempURL.removeSegment(); - aTempURL.removeFinalSlash(); - const OUString sDBURL("sdbc:flat:" + aTempURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - xDataProperties->setPropertyValue("URL", Any(sDBURL)); - //set the filter to the file name without extension - uno::Sequence<OUString> aFilters { sNewName }; - xDataProperties->setPropertyValue("TableFilter", Any(aFilters)); - - uno::Sequence<PropertyValue> aInfo(4); - PropertyValue* pInfo = aInfo.getArray(); - pInfo[0].Name = "FieldDelimiter"; - pInfo[0].Value <<= OUString('\t'); - pInfo[1].Name = "StringDelimiter"; - pInfo[1].Value <<= OUString('"'); - pInfo[2].Name = "Extension"; - pInfo[2].Value <<= aURL.getExtension();//"csv"; - pInfo[3].Name = "CharSet"; - pInfo[3].Value <<= OUString("UTF-8"); - xDataProperties->setPropertyValue("Info", Any(aInfo)); - - uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW); - uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW); - OUString const sExt(".odb"); - OUString sTmpName; - { - OUString sHomePath(SvtPathOptions().GetWorkPath()); - utl::TempFile aTempFile(sFind, true, &sExt, &sHomePath); - aTempFile.EnableKillingFile(); - sTmpName = aTempFile.GetURL(); - } - xStore->storeAsURL(sTmpName, Sequence< PropertyValue >()); - - m_xDBContext->registerObject( sFind, xNewInstance ); - //now insert the new source into the ListBox - m_xListLB->append(m_xIter.get()); - m_xListLB->set_text(*m_xIter, sFind, 0); - m_xListLB->set_text(*m_xIter, aFilters[0], 1); - m_aUserData.emplace_back(new AddressUserData_Impl); - AddressUserData_Impl* pUserData = m_aUserData.back().get(); - m_xListLB->set_id(*m_xIter, OUString::number(reinterpret_cast<sal_Int64>(pUserData))); - m_xListLB->select(*m_xIter); - ListBoxSelectHdl_Impl(*m_xListLB); - m_xCreateListPB->set_sensitive(false); - m_xRemovePB->set_sensitive(true); + sFind = sNewName + OUString::number(++nIndex); } - catch (const Exception&) + uno::Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY); + + //only the 'path' has to be added + INetURLObject aTempURL(aURL); + aTempURL.removeSegment(); + aTempURL.removeFinalSlash(); + const OUString sDBURL("sdbc:flat:" + aTempURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); + xDataProperties->setPropertyValue("URL", Any(sDBURL)); + //set the filter to the file name without extension + uno::Sequence<OUString> aFilters { sNewName }; + xDataProperties->setPropertyValue("TableFilter", Any(aFilters)); + + uno::Sequence<PropertyValue> aInfo(4); + PropertyValue* pInfo = aInfo.getArray(); + pInfo[0].Name = "FieldDelimiter"; + pInfo[0].Value <<= OUString('\t'); + pInfo[1].Name = "StringDelimiter"; + pInfo[1].Value <<= OUString('"'); + pInfo[2].Name = "Extension"; + pInfo[2].Value <<= aURL.getExtension();//"csv"; + pInfo[3].Name = "CharSet"; + pInfo[3].Value <<= OUString("UTF-8"); + xDataProperties->setPropertyValue("Info", Any(aInfo)); + + uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW); + uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW); + OUString const sExt(".odb"); + OUString sTmpName; { + OUString sHomePath(SvtPathOptions().GetWorkPath()); + utl::TempFile aTempFile(sFind, true, &sExt, &sHomePath); + aTempFile.EnableKillingFile(); + sTmpName = aTempFile.GetURL(); } + xStore->storeAsURL(sTmpName, Sequence< PropertyValue >()); + + m_xDBContext->registerObject( sFind, xNewInstance ); + //now insert the new source into the ListBox + m_xListLB->append(m_xIter.get()); + m_xListLB->set_text(*m_xIter, sFind, 0); + m_xListLB->set_text(*m_xIter, aFilters[0], 1); + m_aUserData.emplace_back(new AddressUserData_Impl); + AddressUserData_Impl* pUserData = m_aUserData.back().get(); + m_xListLB->set_id(*m_xIter, OUString::number(reinterpret_cast<sal_Int64>(pUserData))); + m_xListLB->select(*m_xIter); + ListBoxSelectHdl_Impl(*m_xListLB); + m_xCreateListPB->set_sensitive(false); + m_xRemovePB->set_sensitive(true); + } + catch (const Exception&) + { } } @@ -396,25 +397,25 @@ IMPL_LINK_NOARG(SwAddressListDialog, EditHdl_Impl, weld::Button&, void) { int nEntry = m_xListLB->get_selected_index(); AddressUserData_Impl* pUserData = nEntry != -1 ? reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nEntry).toInt64()) : nullptr; - if (pUserData && !pUserData->sURL.isEmpty()) + if (!(pUserData && !pUserData->sURL.isEmpty())) + return; + + if(pUserData->xResultSet.is()) { - if(pUserData->xResultSet.is()) - { - SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem(); - if(rConfigItem.GetResultSet() != pUserData->xResultSet) - ::comphelper::disposeComponent( pUserData->xResultSet ); - pUserData->xResultSet = nullptr; + SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem(); + if(rConfigItem.GetResultSet() != pUserData->xResultSet) + ::comphelper::disposeComponent( pUserData->xResultSet ); + pUserData->xResultSet = nullptr; - rConfigItem.DisposeResultSet(); - } - pUserData->xSource.clear(); - pUserData->xColumnsSupplier.clear(); - pUserData->xConnection.clear(); - // will automatically close if it was the las reference - SwCreateAddressListDialog aDlg(m_xDialog.get(), pUserData->sURL, - m_pAddressPage->GetWizard()->GetConfigItem()); - aDlg.run(); + rConfigItem.DisposeResultSet(); } + pUserData->xSource.clear(); + pUserData->xColumnsSupplier.clear(); + pUserData->xConnection.clear(); + // will automatically close if it was the las reference + SwCreateAddressListDialog aDlg(m_xDialog.get(), pUserData->sURL, + m_pAddressPage->GetWizard()->GetConfigItem()); + aDlg.run(); }; IMPL_LINK_NOARG(SwAddressListDialog, ListBoxSelectHdl_Impl, weld::TreeView&, void) diff --git a/sw/source/ui/dbui/createaddresslistdialog.cxx b/sw/source/ui/dbui/createaddresslistdialog.cxx index d7c9ca8c9b6d..26475c2a1662 100644 --- a/sw/source/ui/dbui/createaddresslistdialog.cxx +++ b/sw/source/ui/dbui/createaddresslistdialog.cxx @@ -142,21 +142,21 @@ void SwAddressControl_Impl::SetData(SwCSVData& rDBData) void SwAddressControl_Impl::SetCurrentDataSet(sal_uInt32 nSet) { - if(m_bNoDataSet || m_nCurrentDataSet != nSet) + if(!(m_bNoDataSet || m_nCurrentDataSet != nSet)) + return; + + m_bNoDataSet = false; + m_nCurrentDataSet = nSet; + OSL_ENSURE(m_pData->aDBData.size() > m_nCurrentDataSet, "wrong data set index"); + if(m_pData->aDBData.size() > m_nCurrentDataSet) { - m_bNoDataSet = false; - m_nCurrentDataSet = nSet; - OSL_ENSURE(m_pData->aDBData.size() > m_nCurrentDataSet, "wrong data set index"); - if(m_pData->aDBData.size() > m_nCurrentDataSet) + sal_uInt32 nIndex = 0; + for(auto& rLine : m_aLines) { - sal_uInt32 nIndex = 0; - for(auto& rLine : m_aLines) - { - OSL_ENSURE(nIndex < m_pData->aDBData[m_nCurrentDataSet].size(), - "number of columns doesn't match number of Edits"); - rLine->m_xEntry->set_text(m_pData->aDBData[m_nCurrentDataSet][nIndex]); - ++nIndex; - } + OSL_ENSURE(nIndex < m_pData->aDBData[m_nCurrentDataSet].size(), + "number of columns doesn't match number of Edits"); + rLine->m_xEntry->set_text(m_pData->aDBData[m_nCurrentDataSet][nIndex]); + ++nIndex; } } } @@ -428,22 +428,22 @@ IMPL_LINK_NOARG(SwCreateAddressListDialog, OkHdl_Impl, weld::Button&, void) m_sURL = aResult.GetMainURL(INetURLObject::DecodeMechanism::NONE); } } - if(!m_sURL.isEmpty()) - { - SfxMedium aMedium( m_sURL, StreamMode::READWRITE|StreamMode::TRUNC ); - SvStream* pStream = aMedium.GetOutStream(); - pStream->SetLineDelimiter( LINEEND_LF ); - pStream->SetStreamCharSet(RTL_TEXTENCODING_UTF8); + if(m_sURL.isEmpty()) + return; - lcl_WriteValues(&(m_pCSVData->aDBColumnHeaders), pStream); + SfxMedium aMedium( m_sURL, StreamMode::READWRITE|StreamMode::TRUNC ); + SvStream* pStream = aMedium.GetOutStream(); + pStream->SetLineDelimiter( LINEEND_LF ); + pStream->SetStreamCharSet(RTL_TEXTENCODING_UTF8); - for(const auto& rData : m_pCSVData->aDBData) - { - lcl_WriteValues(&rData, pStream); - } - aMedium.Commit(); - m_xDialog->response(RET_OK); + lcl_WriteValues(&(m_pCSVData->aDBColumnHeaders), pStream); + + for(const auto& rData : m_pCSVData->aDBData) + { + lcl_WriteValues(&rData, pStream); } + aMedium.Commit(); + m_xDialog->response(RET_OK); } IMPL_LINK(SwCreateAddressListDialog, DBCursorHdl_Impl, weld::Button&, rButton, void) diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx index 81ee630ba8de..f083e89c9f75 100644 --- a/sw/source/ui/dbui/dbinsdlg.cxx +++ b/sw/source/ui/dbui/dbinsdlg.cxx @@ -573,19 +573,19 @@ IMPL_LINK( SwInsertDBColAutoPilot, TableToFromHdl, weld::Button&, rButton, void } } - if( bChgEnable ) - { - m_xIbDbcolOneTo->set_sensitive( bEnableTo ); - m_xIbDbcolAllTo->set_sensitive( bEnableTo ); - m_xIbDbcolOneFrom->set_sensitive( bEnableFrom ); - m_xIbDbcolAllFrom->set_sensitive( bEnableFrom ); + if( !bChgEnable ) + return; - m_xRbDbFormatFromDb->set_sensitive( false ); - m_xRbDbFormatFromUsr->set_sensitive( false ); - m_xLbDbFormatFromUsr->set_sensitive( false ); + m_xIbDbcolOneTo->set_sensitive( bEnableTo ); + m_xIbDbcolAllTo->set_sensitive( bEnableTo ); + m_xIbDbcolOneFrom->set_sensitive( bEnableFrom ); + m_xIbDbcolAllFrom->set_sensitive( bEnableFrom ); - m_xPbTableFormat->set_sensitive( bEnableFrom ); - } + m_xRbDbFormatFromDb->set_sensitive( false ); + m_xRbDbFormatFromUsr->set_sensitive( false ); + m_xLbDbFormatFromUsr->set_sensitive( false ); + + m_xPbTableFormat->set_sensitive( bEnableFrom ); } IMPL_LINK(SwInsertDBColAutoPilot, DblClickHdl, weld::TreeView&, rBox, bool) diff --git a/sw/source/ui/dbui/mmaddressblockpage.cxx b/sw/source/ui/dbui/mmaddressblockpage.cxx index 7f585248eef4..f83529d4aaa7 100644 --- a/sw/source/ui/dbui/mmaddressblockpage.cxx +++ b/sw/source/ui/dbui/mmaddressblockpage.cxx @@ -129,22 +129,22 @@ void SwMailMergeAddressBlockPage::Activate() m_xStep3->set_visible(bIsLetter); m_xStep4->set_visible(bIsLetter); - if (bIsLetter) - { - m_xHideEmptyParagraphsCB->set_active( rConfigItem.IsHideEmptyParagraphs() ); - m_xDocumentIndexFI->set_label(m_sDocument.replaceFirst("%1", "1")); + if (!bIsLetter) + return; - m_xSettings->Clear(); - const uno::Sequence< OUString> aBlocks = - m_pWizard->GetConfigItem().GetAddressBlocks(); - for(const auto& rAddress : aBlocks) - m_xSettings->AddAddress(rAddress); - m_xSettings->SelectAddress(static_cast<sal_uInt16>(rConfigItem.GetCurrentAddressBlockIndex())); - m_xAddressCB->set_active(rConfigItem.IsAddressBlock()); - AddressBlockHdl_Impl(*m_xAddressCB); - m_xSettings->SetLayout(1, 2); - InsertDataHdl(nullptr); - } + m_xHideEmptyParagraphsCB->set_active( rConfigItem.IsHideEmptyParagraphs() ); + m_xDocumentIndexFI->set_label(m_sDocument.replaceFirst("%1", "1")); + + m_xSettings->Clear(); + const uno::Sequence< OUString> aBlocks = + m_pWizard->GetConfigItem().GetAddressBlocks(); + for(const auto& rAddress : aBlocks) + m_xSettings->AddAddress(rAddress); + m_xSettings->SelectAddress(static_cast<sal_uInt16>(rConfigItem.GetCurrentAddressBlockIndex())); + m_xAddressCB->set_active(rConfigItem.IsAddressBlock()); + AddressBlockHdl_Impl(*m_xAddressCB); + m_xSettings->SetLayout(1, 2); + InsertDataHdl(nullptr); } bool SwMailMergeAddressBlockPage::commitPage( ::vcl::WizardTypes::CommitPageReason _eReason ) @@ -416,24 +416,24 @@ IMPL_LINK(SwSelectAddressBlockDialog, NewCustomizeHdl_Impl, weld::Button&, rButt { xDlg->SetAddress(m_aAddressBlocks[m_xPreview->GetSelectedAddress()]); } - if (RET_OK == xDlg->run()) + if (RET_OK != xDlg->run()) + return; + + const OUString sNew = xDlg->GetAddress(); + if(bCustomize) { - const OUString sNew = xDlg->GetAddress(); - if(bCustomize) - { - m_xPreview->ReplaceSelectedAddress(sNew); - m_aAddressBlocks[m_xPreview->GetSelectedAddress()] = sNew; - } - else - { - m_xPreview->AddAddress(sNew); - m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() + 1); - const sal_Int32 nSelect = m_aAddressBlocks.getLength() - 1; - m_aAddressBlocks[nSelect] = sNew; - m_xPreview->SelectAddress(static_cast<sal_uInt16>(nSelect)); - } - m_xDeletePB->set_sensitive(m_aAddressBlocks.getLength() > 1); + m_xPreview->ReplaceSelectedAddress(sNew); + m_aAddressBlocks[m_xPreview->GetSelectedAddress()] = sNew; } + else + { + m_xPreview->AddAddress(sNew); + m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() + 1); + const sal_Int32 nSelect = m_aAddressBlocks.getLength() - 1; + m_aAddressBlocks[nSelect] = sNew; + m_xPreview->SelectAddress(static_cast<sal_uInt16>(nSelect)); + } + m_xDeletePB->set_sensitive(m_aAddressBlocks.getLength() > 1); } IMPL_LINK_NOARG(SwSelectAddressBlockDialog, IncludeHdl_Impl, weld::ToggleButton&, void) diff --git a/sw/source/ui/dbui/mmlayoutpage.cxx b/sw/source/ui/dbui/mmlayoutpage.cxx index bd8070c5ea0f..6c196b9d5816 100644 --- a/sw/source/ui/dbui/mmlayoutpage.cxx +++ b/sw/source/ui/dbui/mmlayoutpage.cxx @@ -162,45 +162,45 @@ void SwMailMergeLayoutPage::Activate() m_xGreetingLine->set_sensitive(bGreetingLine); //check if greeting and/or address frame have to be inserted/removed - if(m_pExampleWrtShell) // initially there's nothing to check + if(!m_pExampleWrtShell) // initially there's nothing to check + return; + + if(!rConfigItem.IsGreetingInserted() && + m_bIsGreetingInserted != bGreetingLine ) { - if(!rConfigItem.IsGreetingInserted() && - m_bIsGreetingInserted != bGreetingLine ) + if( m_bIsGreetingInserted ) { - if( m_bIsGreetingInserted ) - { - m_pExampleWrtShell->DelFullPara(); - m_bIsGreetingInserted = false; - } - else - { - InsertGreeting(*m_pExampleWrtShell, m_pWizard->GetConfigItem(), true); - m_bIsGreetingInserted = true; - } + m_pExampleWrtShell->DelFullPara(); + m_bIsGreetingInserted = false; } - if(!rConfigItem.IsAddressInserted() && - rConfigItem.IsAddressBlock() != ( nullptr != m_pAddressBlockFormat )) + else { - if( m_pAddressBlockFormat ) - { - m_pExampleWrtShell->Push(); - m_pExampleWrtShell->GotoFly( m_pAddressBlockFormat->GetName() ); - m_pExampleWrtShell->DelRight(); - m_pAddressBlockFormat = nullptr; - m_pExampleWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); - } - else - { - long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP))); - long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP))); - m_pAddressBlockFormat = InsertAddressFrame( - *m_pExampleWrtShell, m_pWizard->GetConfigItem(), - Point(nLeft, nTop), - m_xAlignToBodyCB->get_active(), true); - } + InsertGreeting(*m_pExampleWrtShell, m_pWizard->GetConfigItem(), true); + m_bIsGreetingInserted = true; + } + } + if(!rConfigItem.IsAddressInserted() && + rConfigItem.IsAddressBlock() != ( nullptr != m_pAddressBlockFormat )) + { + if( m_pAddressBlockFormat ) + { + m_pExampleWrtShell->Push(); + m_pExampleWrtShell->GotoFly( m_pAddressBlockFormat->GetName() ); + m_pExampleWrtShell->DelRight(); + m_pAddressBlockFormat = nullptr; + m_pExampleWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); + } + else + { + long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP))); + long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP))); + m_pAddressBlockFormat = InsertAddressFrame( + *m_pExampleWrtShell, m_pWizard->GetConfigItem(), + Point(nLeft, nTop), + m_xAlignToBodyCB->get_active(), true); } - m_xExampleFrame->Invalidate(); } + m_xExampleFrame->Invalidate(); } bool SwMailMergeLayoutPage::commitPage(::vcl::WizardTypes::CommitPageReason eReason) @@ -629,45 +629,45 @@ IMPL_LINK_NOARG(SwMailMergeLayoutPage, PreviewLoadedHdl_Impl, SwOneExampleFrame& IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, weld::ComboBox&, rBox, void) { - if (m_pExampleWrtShell) - { - sal_Int16 eType = DocumentZoomType::BY_VALUE; - short nZoom = 50; - switch (rBox.get_active()) - { - case 0 : eType = DocumentZoomType::ENTIRE_PAGE; break; - case 1 : nZoom = 50; break; - case 2 : nZoom = 75; break; - case 3 : nZoom = 100; break; - } - Any aZoom; - aZoom <<= eType; - m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom); - aZoom <<= nZoom; - m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom); + if (!m_pExampleWrtShell) + return; - m_xExampleFrame->Invalidate(); + sal_Int16 eType = DocumentZoomType::BY_VALUE; + short nZoom = 50; + switch (rBox.get_active()) + { + case 0 : eType = DocumentZoomType::ENTIRE_PAGE; break; + case 1 : nZoom = 50; break; + case 2 : nZoom = 75; break; + case 3 : nZoom = 100; break; } + Any aZoom; + aZoom <<= eType; + m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom); + aZoom <<= nZoom; + m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom); + + m_xExampleFrame->Invalidate(); } IMPL_LINK_NOARG(SwMailMergeLayoutPage, ChangeAddressHdl_Impl, weld::MetricSpinButton&, void) { - if(m_pExampleWrtShell && m_pAddressBlockFormat) - { - long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP))); - long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP))); + if(!(m_pExampleWrtShell && m_pAddressBlockFormat)) + return; - SfxItemSet aSet( - m_pExampleWrtShell->GetAttrPool(), - svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{}); - if (m_xAlignToBodyCB->get_active()) - aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA )); - else - aSet.Put(SwFormatHoriOrient( nLeft, text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME )); - aSet.Put(SwFormatVertOrient( nTop, text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME )); - m_pExampleWrtShell->GetDoc()->SetFlyFrameAttr( *m_pAddressBlockFormat, aSet ); - m_xExampleFrame->Invalidate(); - } + long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP))); + long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP))); + + SfxItemSet aSet( + m_pExampleWrtShell->GetAttrPool(), + svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{}); + if (m_xAlignToBodyCB->get_active()) + aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA )); + else + aSet.Put(SwFormatHoriOrient( nLeft, text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME )); + aSet.Put(SwFormatVertOrient( nTop, text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME )); + m_pExampleWrtShell->GetDoc()->SetFlyFrameAttr( *m_pAddressBlockFormat, aSet ); + m_xExampleFrame->Invalidate(); } IMPL_LINK(SwMailMergeLayoutPage, GreetingsHdl_Impl, weld::Button&, rButton, void) diff --git a/sw/source/ui/dbui/mmoutputtypepage.cxx b/sw/source/ui/dbui/mmoutputtypepage.cxx index f7153c3bc503..d56e369eb85b 100644 --- a/sw/source/ui/dbui/mmoutputtypepage.cxx +++ b/sw/source/ui/dbui/mmoutputtypepage.cxx @@ -242,27 +242,27 @@ SwSendMailDialog::SwSendMailDialog(weld::Window *pParent, SwMailMergeConfigItem& SwSendMailDialog::~SwSendMailDialog() { - if(m_pImpl->xMailDispatcher.is()) + if(!m_pImpl->xMailDispatcher.is()) + return; + + try { - try - { - if(m_pImpl->xMailDispatcher->isStarted()) - m_pImpl->xMailDispatcher->stop(); - if(m_pImpl->xConnectedInMailService.is() && m_pImpl->xConnectedInMailService->isConnected()) - m_pImpl->xConnectedInMailService->disconnect(); - - uno::Reference<mail::XMailMessage> xMessage = - m_pImpl->xMailDispatcher->dequeueMailMessage(); - while(xMessage.is()) - { - SwMailDispatcherListener_Impl::DeleteAttachments( xMessage ); - xMessage = m_pImpl->xMailDispatcher->dequeueMailMessage(); - } - } - catch (const uno::Exception&) + if(m_pImpl->xMailDispatcher->isStarted()) + m_pImpl->xMailDispatcher->stop(); + if(m_pImpl->xConnectedInMailService.is() && m_pImpl->xConnectedInMailService->isConnected()) + m_pImpl->xConnectedInMailService->disconnect(); + + uno::Reference<mail::XMailMessage> xMessage = + m_pImpl->xMailDispatcher->dequeueMailMessage(); + while(xMessage.is()) { + SwMailDispatcherListener_Impl::DeleteAttachments( xMessage ); + xMessage = m_pImpl->xMailDispatcher->dequeueMailMessage(); } } + catch (const uno::Exception&) + { + } } void SwSendMailDialog::AddDocument( SwMailDescriptor const & rDesc ) @@ -279,20 +279,20 @@ void SwSendMailDialog::AddDocument( SwMailDescriptor const & rDesc ) IMPL_LINK( SwSendMailDialog, StopHdl_Impl, weld::Button&, rButton, void ) { m_bCancel = true; - if(m_pImpl->xMailDispatcher.is()) + if(!m_pImpl->xMailDispatcher.is()) + return; + + if(m_pImpl->xMailDispatcher->isStarted()) { - if(m_pImpl->xMailDispatcher->isStarted()) - { - m_pImpl->xMailDispatcher->stop(); - rButton.set_label(m_sContinue); - m_xPaused->show(); - } - else - { - m_pImpl->xMailDispatcher->start(); - rButton.set_label(m_sStop); - m_xPaused->hide(); - } + m_pImpl->xMailDispatcher->stop(); + rButton.set_label(m_sContinue); + m_xPaused->show(); + } + else + { + m_pImpl->xMailDispatcher->start(); + rButton.set_label(m_sStop); + m_xPaused->hide(); } } diff --git a/sw/source/ui/dbui/selectdbtabledialog.cxx b/sw/source/ui/dbui/selectdbtabledialog.cxx index 096c1472f69a..91e6d06f6a11 100644 --- a/sw/source/ui/dbui/selectdbtabledialog.cxx +++ b/sw/source/ui/dbui/selectdbtabledialog.cxx @@ -68,18 +68,18 @@ SwSelectDBTableDialog::SwSelectDBTableDialog(weld::Window* pParent, } } Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY); - if (xQSupplier.is()) + if (!xQSupplier.is()) + return; + + Reference<XNameAccess> xQueries = xQSupplier->getQueries(); + const Sequence<OUString> aQueries = xQueries->getElementNames(); + int nPos = m_xTable->n_children(); + for (const OUString& rQuery : aQueries) { - Reference<XNameAccess> xQueries = xQSupplier->getQueries(); - const Sequence<OUString> aQueries = xQueries->getElementNames(); - int nPos = m_xTable->n_children(); - for (const OUString& rQuery : aQueries) - { - m_xTable->append_text(rQuery); - m_xTable->set_text(nPos, SwResId(ST_QUERY), 1); - m_xTable->set_id(nPos, OUString::number(1)); - ++nPos; - } + m_xTable->append_text(rQuery); + m_xTable->set_text(nPos, SwResId(ST_QUERY), 1); + m_xTable->set_id(nPos, OUString::number(1)); + ++nPos; } } |