/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
if( (pSh && pSh->HasSelection()) ||
!(nSelection & (SelectionType::Text | SelectionType::Table)))
rSet.DisableItem(nWhich);
} break; case SID_ATTR_METRIC:
rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, static_cast< sal_uInt16 >(::GetDfltMetric(bWebView)))); break; case FN_SET_MODOPT_TBLNUMFMT:
rSet.Put( SfxBoolItem( nWhich, m_pModuleConfig->
IsInsTableFormatNum( bWebView ))); break; case FN_MAILMERGE_WIZARD:
{
SfxObjectShell* pObjectShell = GetObjectShell(); if (pObjectShell && pObjectShell->isExportLocked())
rSet.DisableItem(nWhich); break;
} case FN_MAILMERGE_FIRST_ENTRY: case FN_MAILMERGE_PREV_ENTRY: case FN_MAILMERGE_NEXT_ENTRY: case FN_MAILMERGE_LAST_ENTRY:
{
std::shared_ptr<SwMailMergeConfigItem> xConfigItem; if (SwView* pView = GetActiveView())
xConfigItem = pView->GetMailMergeConfigItem(); if (!xConfigItem)
rSet.DisableItem(nWhich); elseif (xConfigItem->GetConnection().is()
&& !xConfigItem->GetConnection()->isClosed())
{ bool bFirst, bLast; bool bValid = xConfigItem->IsResultSetFirstLast(bFirst, bLast);
if (!bValid ||
(bFirst && (nWhich == FN_MAILMERGE_FIRST_ENTRY || nWhich == FN_MAILMERGE_PREV_ENTRY)) ||
(bLast && (nWhich == FN_MAILMERGE_LAST_ENTRY || nWhich == FN_MAILMERGE_NEXT_ENTRY)))
{
rSet.DisableItem(nWhich);
}
}
} break; case FN_MAILMERGE_CURRENT_ENTRY: case FN_MAILMERGE_EXCLUDE_ENTRY:
{ // just trigger calling statusChanged() of MMExcludeEntryController // resp. MMCurrentEntryController
rSet.InvalidateItem(nWhich);
} break; case FN_MAILMERGE_CREATE_DOCUMENTS: case FN_MAILMERGE_SAVE_DOCUMENTS: case FN_MAILMERGE_PRINT_DOCUMENTS: case FN_MAILMERGE_EMAIL_DOCUMENTS:
{
std::shared_ptr<SwMailMergeConfigItem> xConfigItem; if (SwView* pView = GetActiveView())
xConfigItem = pView->EnsureMailMergeConfigItem();
// #i51949# hide e-Mail option if e-Mail is not supported // #i63267# printing might be disabled // Without attempting to open the database, (in case it is remote or passworded), // hide everything after determining there are no valid results. tdf#121606 if (!xConfigItem ||
xConfigItem->GetCurrentDBData().sDataSource.isEmpty() ||
xConfigItem->GetCurrentDBData().sCommand.isEmpty() ||
(xConfigItem->GetConnection().is() && !xConfigItem->GetConnection()->isClosed() && !xConfigItem->GetResultSet().is()) ||
(nWhich == FN_MAILMERGE_PRINT_DOCUMENTS && Application::GetSettings().GetMiscSettings().GetDisablePrinting()) ||
(nWhich == FN_MAILMERGE_EMAIL_DOCUMENTS && !xConfigItem->IsMailAvailable()))
{
rSet.DisableItem(nWhich);
}
} break; default:
OSL_FAIL("::StateOther: default");
}
nWhich = aIter.NextWhich();
}
}
std::shared_ptr<SwMailMergeConfigItem> SwView::EnsureMailMergeConfigItem(const SfxItemSet* pArgs)
{ // create if it does not exist yet
std::shared_ptr<SwMailMergeConfigItem> xMMConfig = GetMailMergeConfigItem(); if (!xMMConfig)
{
xMMConfig = std::make_shared<SwMailMergeConfigItem>();
xMMConfig->SetSourceView(this);
//set the first used database as default source on the config item const SfxUnoAnyItem* pItem = nullptr; if (pArgs && (pItem = pArgs->GetItemIfSet(
FN_PARAM_DATABASE_PROPERTIES, false)))
{ //mailmerge has been called from the database beamer
uno::Sequence< beans::PropertyValue> aDBValues; if (pItem->GetValue() >>= aDBValues)
{
SwDBData aDBData;
svx::ODataAccessDescriptor aDescriptor(aDBValues);
aDescriptor[svx::DataAccessDescriptorProperty::DataSource] >>= aDBData.sDataSource;
aDescriptor[svx::DataAccessDescriptorProperty::Command] >>= aDBData.sCommand;
aDescriptor[svx::DataAccessDescriptorProperty::CommandType] >>= aDBData.nCommandType;
uno::Reference< sdbc::XConnection> xConnection;
uno::Reference< sdbc::XDataSource> xSource;
uno::Reference< sdbcx::XColumnsSupplier> xColumnsSupplier; if (aDescriptor.has(svx::DataAccessDescriptorProperty::Connection))
aDescriptor[svx::DataAccessDescriptorProperty::Connection] >>= xConnection;
uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY); if (xChild.is())
xSource.set(xChild->getParent(), uno::UNO_QUERY);
xMMConfig->SetCurrentConnection(
xSource, SharedConnection(xConnection, SharedConnection::NoTakeOwnership),
xColumnsSupplier, aDBData);
}
} else
{
std::vector<OUString> aDBNameList;
std::vector<OUString> aAllDBNames;
GetWrtShell().GetAllUsedDB(aDBNameList, &aAllDBNames); if (!aDBNameList.empty())
{ const OUString& sDBName(aDBNameList[0]);
SwDBData aDBData;
sal_Int32 nIdx{ 0 };
aDBData.sDataSource = sDBName.getToken(0, DB_DELIM, nIdx);
aDBData.sCommand = sDBName.getToken(0, DB_DELIM, nIdx);
aDBData.nCommandType = o3tl::toInt32(o3tl::getToken(sDBName, 0, DB_DELIM, nIdx)); //set the currently used database for the wizard
xMMConfig->SetCurrentDBData(aDBData);
}
}
SwMailMergeWizardExecutor::~SwMailMergeWizardExecutor()
{
OSL_ENSURE( m_pWizard == nullptr, "SwMailMergeWizardExecutor: m_pWizard must be Null!" );
}
bool lcl_hasAllComponentsAvailable()
{ try
{ return css::sdb::TextConnectionSettings::create(comphelper::getProcessComponentContext()).is();
} catch (const css::uno::Exception &)
{
TOOLS_INFO_EXCEPTION( "sw.core", "assuming Base to be missing; caught "); returnfalse;
}
}
void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs )
{ if(!lcl_hasAllComponentsAvailable())
{ if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get())
{ try
{ usingnamespace org::freedesktop::PackageKit; usingnamespace svtools;
css::uno::Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext())); const css::uno::Sequence< OUString > vPackages{ u"libreoffice-base"_ustr };
xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString());
SolarMutexGuard aGuard;
(void)executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_MAILMERGE_INSTALL);
} catch (const css::uno::Exception &)
{
TOOLS_INFO_EXCEPTION( "sw.core", "trying to install LibreOffice Base, caught"); auto xRestartManager
= css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext()); if (!xRestartManager->isRestartRequested(false))
{ // Base is absent, and could not initiate its install - ask user to do that manually // Only show the dialog if restart is not initiated yet
std::unique_ptr<weld::MessageDialog> xWarnBox(Application::CreateMessageDialog(
nullptr, VclMessageType::Info, VclButtonsType::Ok,
SwResId(STR_NO_BASE_FOR_MERGE)));
xWarnBox->run();
}
}
} else { auto xRestartManager
= css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext()); if (!xRestartManager->isRestartRequested(false))
{ // Base is absent, and could not initiate its install - ask user to do that manually // Only show the dialog if restart is not initiated yet
std::unique_ptr<weld::MessageDialog> xWarnBox(Application::CreateMessageDialog(
nullptr, VclMessageType::Info, VclButtonsType::Ok,
SwResId(STR_NO_BASE_FOR_MERGE)));
xWarnBox->run();
}
} return;
} if ( m_pView )
{
OSL_FAIL("SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" ); return;
}
m_pView = ::GetActiveView(); if (!m_pView) return;
// keep self alive until done.
acquire();
// create if it does not exist yet
std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->EnsureMailMergeConfigItem(pArgs);
// Destroy wizard asynchronously, since we are deep inside the wizard and dialog // machinery code here
m_pWizardToDestroyInCallback = m_pWizard;
Application::PostUserEvent(
LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl ), nullptr );
// execute the wizard again
ExecuteWizard();
} else
{ // should not happen - just in case no target view has been created
ExecutionFinished();
} break;
} case RET_REMOVE_TARGET:
{
std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
SwView* pTargetView = xMMConfig->GetTargetView();
SwView* pSourceView = xMMConfig->GetSourceView();
OSL_ENSURE(pTargetView && pSourceView, "source or target view not available" ); if(pTargetView && pSourceView)
{
m_pView2Close = pTargetView;
pTargetView->GetViewFrame().GetTopViewFrame()->GetWindow().Hide();
pSourceView->GetViewFrame().GetFrame().AppearWithUpdate(); // the current view has be set when the target is destroyed
m_pView = pSourceView;
xMMConfig->SetTargetView(nullptr);
// execute the wizard again
ExecuteWizard();
} else
{ // should not happen - just in case no target view has been created
ExecutionFinished();
} break;
} case RET_CANCEL:
{ // close frame and destroy wizard asynchronously
Application::PostUserEvent(
LINK( this, SwMailMergeWizardExecutor, CancelHdl ), m_pWizard ); break;
} default: // finish
{
std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
SwView* pSourceView = xMMConfig ? xMMConfig->GetSourceView() : nullptr; if(pSourceView)
{
xMMConfig->GetSourceView()->GetViewFrame().GetFrame().Appear();
}
ExecutionFinished(); break;
}
m_pModuleConfig->SetInsTableFormatNum( bWebView, bSet );
} break; #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS case FN_MAILMERGE_WIZARD:
{ // show the mailmerge wizard
rtl::Reference< SwMailMergeWizardExecutor > xEx( new SwMailMergeWizardExecutor );
xEx->ExecuteMailMergeWizard( pArgs );
} break; case FN_MAILMERGE_FIRST_ENTRY: case FN_MAILMERGE_PREV_ENTRY: case FN_MAILMERGE_NEXT_ENTRY: case FN_MAILMERGE_LAST_ENTRY: case FN_MAILMERGE_CURRENT_ENTRY:
{
SwView* pView = ::GetActiveView(); if (!pView) return;
const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem(); if (!xConfigItem) return;
sal_Int32 nPos = xConfigItem->GetResultSetPosition(); switch (nWhich)
{ case FN_MAILMERGE_FIRST_ENTRY: xConfigItem->MoveResultSet(1); break; case FN_MAILMERGE_PREV_ENTRY: xConfigItem->MoveResultSet(nPos - 1); break; case FN_MAILMERGE_NEXT_ENTRY: xConfigItem->MoveResultSet(nPos + 1); break; case FN_MAILMERGE_LAST_ENTRY: xConfigItem->MoveResultSet(-1); break; case FN_MAILMERGE_CURRENT_ENTRY: /* don't move the result set, just update the document */ break; default: break;
}
// now the record has to be merged into the source document // TODO can we re-use PerformMailMerge() here somehow? const SwDBData& rDBData = xConfigItem->GetCurrentDBData();
uno::Sequence<uno::Any> vSelection({ uno::Any(xConfigItem->GetResultSetPosition()) });
svx::ODataAccessDescriptor aDescriptor(::comphelper::InitPropertySequence({
{"Selection", uno::Any(vSelection)},
{"DataSourceName", uno::Any(rDBData.sDataSource)},
{"Command", uno::Any(rDBData.sCommand)},
{"CommandType", uno::Any(rDBData.nCommandType)},
{"ActiveConnection", uno::Any(xConfigItem->GetConnection().getTyped())},
{"Filter", uno::Any(xConfigItem->GetFilter())},
{"Cursor", uno::Any(xConfigItem->GetResultSet())}
}));
// update enabled / disabled status of the buttons in the toolbar
SfxBindings& rBindings = rSh.GetView().GetViewFrame().GetBindings();
rBindings.Invalidate(FN_MAILMERGE_FIRST_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_PREV_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_NEXT_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_LAST_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_CURRENT_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_EXCLUDE_ENTRY); if (!bHadConnection && xConfigItem->GetConnection().is()
&& !xConfigItem->GetConnection()->isClosed())
{ // The connection has been activated. Update controls that were disabled
rBindings.Invalidate(FN_MAILMERGE_CREATE_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_SAVE_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_PRINT_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_EMAIL_DOCUMENTS);
}
rBindings.Update();
} break; case FN_MAILMERGE_CREATE_DOCUMENTS: case FN_MAILMERGE_SAVE_DOCUMENTS: case FN_MAILMERGE_PRINT_DOCUMENTS: case FN_MAILMERGE_EMAIL_DOCUMENTS:
{
SwView* pView = ::GetActiveView(); if (!pView) return;
std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
assert(xConfigItem); if (!xConfigItem->GetResultSet().is())
{ // The connection has been attempted, but failed or no results found, // so invalidate the toolbar buttons in case they need to be disabled.
SfxBindings& rBindings
= pView->GetWrtShell().GetView().GetViewFrame().GetBindings();
rBindings.Invalidate(FN_MAILMERGE_CREATE_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_SAVE_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_PRINT_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_EMAIL_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_FIRST_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_PREV_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_NEXT_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_LAST_ENTRY);
rBindings.Update(); return;
}
if (nWhich == FN_MAILMERGE_CREATE_DOCUMENTS)
{
xConfigItem = SwDBManager::PerformMailMerge(pView);
// if not LOKit, then update the module defaults (for reload/open/new etc.) if (!bKit && aViewColors != aViewOption.GetColorConfig())
{
aViewOption.SetColorConfig(aViewColors);
ApplyUsrPref(aViewOption, /*SwView=*/nullptr);
}
//invalidate only the current view in tiled rendering mode, or all views otherwise
SfxViewShell* pViewShell = bKit ? SfxViewShell::Current() : SfxViewShell::GetFirst(); while(pViewShell)
{ if(pViewShell->GetWindow())
{ auto pSwView = dynamic_cast<SwView *>(pViewShell); if (pSwView)
{
SwViewOption aNewOptions = *pSwView->GetWrtShell().GetViewOptions();
aNewOptions.SetThemeName(svtools::ColorConfig::GetCurrentSchemeName());
aNewOptions.SetColorConfig(aViewColors); constbool bChanged(aNewOptions != *pSwView->GetWrtShell().GetViewOptions()); if (bChanged)
pSwView->GetWrtShell().ApplyViewOptions(aNewOptions); elseif (bKit)
{
SwXTextDocument* pModel = comphelper::getFromUnoTunnel<SwXTextDocument>(pViewShell->GetCurrentDocument());
SfxLokHelper::notifyViewRenderState(pViewShell, pModel);
}
if (bKit)
{
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_APPLICATION_BACKGROUND_COLOR,
aViewColors.m_aAppBackgroundColor.AsRGBHexString().toUtf8());
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR,
aViewColors.m_aDocColor.AsRGBHexString().toUtf8());
}
if (!bKit)
{
SwPostItMgr* pPostItManager = pSwView->GetPostItMgr(); if (pPostItManager)
pPostItManager->UpdateColors();
}
// if nothing changed, and the hint was OnlyCurrentDocumentColorScheme we can skip invalidate constbool bSkipInvalidate = !bChanged && bKit && eHints == ConfigurationHints::OnlyCurrentDocumentColorScheme; if (!bSkipInvalidate)
pViewShell->GetWindow()->Invalidate();
} elseif (dynamic_cast< const SwPagePreview *>( pViewShell ) != nullptr || dynamic_cast< const SwSrcView *>( pViewShell ) != nullptr)
{
pViewShell->GetWindow()->Invalidate();
}
} if (bKit) break;
pViewShell = SfxViewShell::GetNext( *pViewShell );
}
} elseif( pBrdCst == m_pCTLOptions.get() )
{
m_eCTLTextNumerals = SvtCTLOptions::GetCTLTextNumerals(); const SfxObjectShell* pObjSh = SfxObjectShell::GetFirst(); while( pObjSh )
{ if( auto pDocShell = dynamic_cast<const SwDocShell*>(pObjSh) )
{
SwDoc* pDoc = const_cast<SwDocShell*>(pDocShell)->GetDoc();
SwViewShell* pVSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell(); if ( pVSh )
pVSh->ChgNumberDigits();
}
pObjSh = SfxObjectShell::GetNext(*pObjSh);
}
}
}
const SwMasterUsrPref *SwModule::GetUsrPref(bool bWeb) const
{
SwModule* pNonConstModule = const_cast<SwModule*>(this); if(bWeb && !m_pWebUsrPref)
{ // The SpellChecker is needed in SwMasterUsrPref's Load, but it must not // be created there #58256#
pNonConstModule->m_pWebUsrPref.reset(new SwMasterUsrPref(true));
} elseif(!bWeb && !m_pUsrPref)
{
pNonConstModule->m_pUsrPref.reset(new SwMasterUsrPref(false));
} return bWeb ? m_pWebUsrPref.get() : m_pUsrPref.get();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.