20 #include <config_features.h>
39 #include <com/sun/star/document/UpdateDocMode.hpp>
63 #include <fontcfg.hxx>
65 #include <navicfg.hxx>
69 #include <strings.hrc>
70 #include <com/sun/star/container/XChild.hpp>
71 #include <com/sun/star/sdbc/XConnection.hpp>
72 #include <com/sun/star/sdb/TextConnectionSettings.hpp>
73 #include <com/sun/star/sdbc/XDataSource.hpp>
74 #include <com/sun/star/task/OfficeRestartManager.hpp>
75 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
81 #include <rtl/ref.hxx>
83 #include <officecfg/Office/Common.hxx>
91 #define ShellClass_SwModule
93 #include <swslots.hxx>
99 GetStaticInterface()->RegisterStatusBar(StatusBarId::WriterStatusBar);
102 SfxVisibilityFlags::Standard | SfxVisibilityFlags::Client | SfxVisibilityFlags::Viewer,
103 ToolbarId::Module_Toolbox);
113 bool bWebView =
dynamic_cast<SwWebView*
>( pActView ) !=
nullptr;
119 case FN_BUSINESS_CARD:
123 bool bDisable =
false;
125 if( !pCurrView || dynamic_cast< const SwView *>( pCurrView ) ==
nullptr )
152 case SID_ATTR_METRIC:
172 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
177 else if (xConfigItem->GetConnection().is()
178 && !xConfigItem->GetConnection()->isClosed())
181 bool bValid = xConfigItem->IsResultSetFirstLast(bFirst, bLast);
206 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
213 !xConfigItem->GetConnection().is() ||
214 xConfigItem->GetConnection()->isClosed() ||
215 !xConfigItem->GetResultSet().is() ||
216 xConfigItem->GetCurrentDBData().sDataSource.isEmpty() ||
217 xConfigItem->GetCurrentDBData().sCommand.isEmpty() ||
226 OSL_FAIL(
"::StateOther: default");
241 xMMConfig = std::make_shared<SwMailMergeConfigItem>();
242 xMMConfig->SetSourceView(
this);
250 uno::Sequence< beans::PropertyValue> aDBValues;
251 if (static_cast<const SfxUnoAnyItem*>(pItem)->GetValue() >>= aDBValues)
259 uno::Reference< sdbc::XConnection> xConnection;
260 uno::Reference< sdbc::XDataSource> xSource;
261 uno::Reference< sdbcx::XColumnsSupplier> xColumnsSupplier;
264 uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
266 xSource.set(xChild->getParent(), uno::UNO_QUERY);
267 xMMConfig->SetCurrentConnection(
269 xColumnsSupplier, aDBData);
274 std::vector<OUString> aDBNameList;
275 std::vector<OUString> aAllDBNames;
277 if (!aDBNameList.empty())
279 OUString sDBName(aDBNameList[0]);
286 xMMConfig->SetCurrentDBData(aDBData);
295 #if HAVE_FEATURE_DBCONNECTIVITY
300 SwView* lcl_LoadDoc(
SwView* pView,
const OUString& rURL)
302 SwView* pNewView =
nullptr;
311 SfxCallMode::SYNCHRON,
312 { &
aURL, &aHidden, &aReferer, &aTargetFrameName }));
313 SfxShell* pShell = pItem ? pItem->GetShell() :
nullptr;
320 pNewView =
dynamic_cast<SwView*
>(pViewShell);
334 SfxStringItem aFactory(SID_NEWDOCDIRECT, SwDocShell::Factory().GetFilterContainer()->GetName());
337 SID_NEWDOCDIRECT, SfxCallMode::SYNCHRON, { &aFactory }));
340 pNewView = pViewFrame ?
dynamic_cast<SwView*
>( pViewFrame->
GetViewShell() ) :
nullptr;
353 void EndDialogHdl(sal_Int32 nResponse);
354 DECL_LINK( DestroyDialogHdl,
void*,
void );
355 DECL_LINK( DestroyWizardHdl,
void*,
void );
359 void ExecutionFinished();
360 void ExecuteWizard();
363 SwMailMergeWizardExecutor();
364 virtual ~SwMailMergeWizardExecutor()
override;
366 void ExecuteMailMergeWizard(
const SfxItemSet * pArgs );
369 SwMailMergeWizardExecutor::SwMailMergeWizardExecutor()
370 : m_pView( nullptr ),
371 m_pView2Close( nullptr ),
376 SwMailMergeWizardExecutor::~SwMailMergeWizardExecutor()
378 OSL_ENSURE( m_pWizard ==
nullptr,
"SwMailMergeWizardExecutor: m_pWizard must be Null!" );
381 bool lcl_hasAllComponentsAvailable()
387 catch (
const css::uno::Exception &)
390 "sw.core",
"assuming Base to be missing; caught ");
395 void SwMailMergeWizardExecutor::ExecuteMailMergeWizard(
const SfxItemSet * pArgs )
397 if(!lcl_hasAllComponentsAvailable())
403 using namespace org::freedesktop::PackageKit;
406 const css::uno::Sequence< OUString > vPackages{
"libreoffice-base" };
407 xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString());
411 catch (
const css::uno::Exception &)
415 "trying to install LibreOffice Base, caught");
418 if (!xRestartManager->isRestartRequested(
false))
423 nullptr, VclMessageType::Info, VclButtonsType::Ok,
424 SwResId(STR_NO_BASE_FOR_MERGE)));
431 if (!xRestartManager->isRestartRequested(
false))
436 nullptr, VclMessageType::Info, VclButtonsType::Ok,
437 SwResId(STR_NO_BASE_FOR_MERGE)));
445 OSL_FAIL(
"SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" );
457 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->EnsureMailMergeConfigItem(pArgs);
465 void SwMailMergeWizardExecutor::ExecutionFinished()
467 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
479 m_pView->ShowUIElement(
"private:resource/toolbar/mailmerge");
493 m_pView->GetViewFrame()->GetBindings().Invalidate(slotIds);
500 void SwMailMergeWizardExecutor::ExecuteWizard()
502 m_pWizard->StartExecuteAsync([
this](sal_Int32 nResult){
503 EndDialogHdl(nResult);
507 void SwMailMergeWizardExecutor::EndDialogHdl(sal_Int32 nRet)
509 sal_uInt16 nRestartPage = m_pWizard->GetRestartPage();
515 SwView* pNewView = lcl_LoadDoc(m_pView, m_pWizard->GetReloadDocument());
519 m_pWizardToDestroyInCallback = m_pWizard;
521 LINK(
this, SwMailMergeWizardExecutor, DestroyWizardHdl ),
nullptr );
524 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
529 xMMConfig->DocumentReloaded();
531 xMMConfig->SetSourceView( m_pView );
533 m_pWizard->ShowPage( nRestartPage );
546 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
547 SwView* pTargetView = xMMConfig->GetTargetView();
548 OSL_ENSURE(pTargetView,
"No target view has been created");
552 m_pWizardToDestroyInCallback = m_pWizard;
554 LINK(
this, SwMailMergeWizardExecutor, DestroyWizardHdl ),
nullptr );
558 m_pWizard->ShowPage( nRestartPage );
572 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
573 SwView* pTargetView = xMMConfig->GetTargetView();
574 SwView* pSourceView = xMMConfig->GetSourceView();
575 OSL_ENSURE(pTargetView && pSourceView,
"source or target view not available" );
576 if(pTargetView && pSourceView)
578 m_pView2Close = pTargetView;
582 m_pView = pSourceView;
583 xMMConfig->SetTargetView(
nullptr);
586 m_pWizardToDestroyInCallback = m_pWizard;
588 LINK(
this, SwMailMergeWizardExecutor, CloseFrameHdl ), m_pWizard );
592 m_pWizard->ShowPage( nRestartPage );
608 LINK(
this, SwMailMergeWizardExecutor, CancelHdl ), m_pWizard );
613 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
614 SwView* pSourceView = xMMConfig ? xMMConfig->GetSourceView() :
nullptr;
626 IMPL_LINK_NOARG(SwMailMergeWizardExecutor, DestroyDialogHdl,
void*,
void)
628 m_pWizard.disposeAndClear();
633 IMPL_LINK_NOARG(SwMailMergeWizardExecutor, DestroyWizardHdl,
void*,
void)
635 m_pWizardToDestroyInCallback.disposeAndClear();
640 std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem();
643 if (xMMConfig->GetTargetView())
645 xMMConfig->GetTargetView()->GetViewFrame()->DoClose();
646 xMMConfig->SetTargetView(
nullptr);
648 if (xMMConfig->GetSourceView())
650 auto pViewFrame(xMMConfig->GetSourceView()->GetViewFrame());
662 m_pWizard.disposeAndClear();
670 m_pView2Close->GetViewFrame()->DoClose();
671 m_pView2Close =
nullptr;
673 m_pWizardToDestroyInCallback.disposeAndClear();
677 #endif // HAVE_FEATURE_DBCONNECTIVITY
684 sal_uInt16 nWhich = rReq.
GetSlot();
691 case FN_BUSINESS_CARD:
700 case SID_ATTR_METRIC:
701 if(pArgs && SfxItemState::SET == pArgs->
GetItemState(nWhich,
false, &pItem))
708 case FieldUnit::INCH:
709 case FieldUnit::PICA:
710 case FieldUnit::POINT:
713 bool bWebView =
dynamic_cast<SwWebView*
>( pActView ) !=
nullptr;
728 nWhich,
false, &pItem ))
729 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
736 #if HAVE_FEATURE_DBCONNECTIVITY
741 xEx->ExecuteMailMergeWizard( pArgs );
755 const bool bHadConnection
756 = xConfigItem->GetConnection().is() && !xConfigItem->GetConnection()->isClosed();
758 sal_Int32
nPos = xConfigItem->GetResultSetPosition();
771 const SwDBData& rDBData = xConfigItem->GetCurrentDBData();
772 uno::Sequence<uno::Any> vSelection({ uno::makeAny(xConfigItem->GetResultSetPosition()) });
774 {
"Selection", uno::makeAny(vSelection)},
775 {
"DataSourceName", uno::makeAny(rDBData.
sDataSource)},
776 {
"Command", uno::makeAny(rDBData.
sCommand)},
778 {
"ActiveConnection", uno::makeAny(xConfigItem->GetConnection().getTyped())},
779 {
"Filter", uno::makeAny(xConfigItem->GetFilter())},
780 {
"Cursor", uno::makeAny(xConfigItem->GetResultSet())}
785 rSh.GetDBManager()->Merge(aMergeDesc);
788 SfxBindings& rBindings = rSh.GetView().GetViewFrame()->GetBindings();
795 if (!bHadConnection && xConfigItem->GetConnection().is()
796 && !xConfigItem->GetConnection()->isClosed())
811 if (xConfigItem && xConfigItem->GetTargetView())
812 xConfigItem->GetTargetView()->GetViewFrame()->GetFrame().Appear();
822 xConfigItem->SetTargetView(
nullptr);
841 if(
const SfxEventHint* pEvHint = dynamic_cast<const SfxEventHint*>( &rHint) )
847 switch( pEvHint->GetEventId() )
849 case SfxEventHintId::LoadFinished:
855 if (pTemplateItem && pTemplateItem->
GetValue())
864 case SfxEventHintId::CreateDoc:
869 bool bUpdateFields =
true;
870 if( pUpdateDocItem && pUpdateDocItem->
GetValue() == document::UpdateDocMode::NO_UPDATE)
871 bUpdateFields =
false;
879 std::vector<OUString> aDBNameList;
881 if(!aDBNameList.empty())
892 else if(
const SfxItemSetHint* pSfxItemSetHint = dynamic_cast<const SfxItemSetHint*>(&rHint))
894 if( SfxItemState::SET == pSfxItemSetHint->GetItemSet().GetItemState(SID_ATTR_PATHNAME))
904 if (rHint.
GetId() == SfxHintId::Deinitializing)
949 bool bAccessibility =
false;
953 bAccessibility =
true;
961 if(dynamic_cast< const SwView *>( pViewShell ) !=
nullptr ||
962 dynamic_cast< const SwPagePreview *
>( pViewShell ) !=
nullptr ||
963 dynamic_cast< const SwSrcView *>( pViewShell ) !=
nullptr)
967 if(
auto pSwView = dynamic_cast<SwView *>( pViewShell ))
969 else if(
auto pPagePreview = dynamic_cast<SwPagePreview *>( pViewShell ))
983 if(
auto pDocShell = dynamic_cast<const SwDocShell*>(pObjSh) )
1069 static_cast<SwDocShell*
>( &xDocSh )->GetDoc()->initXForms(
true );
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SfxViewFrame * GetViewFrame() const
#define LINK(Instance, Class, Member)
static void ShowDBObj(SwView const &rView, const SwDBData &rData)
SvtAccessibilityOptions & GetAccessibilityOptions()
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
void RevokeLastRegistrations()
Revoke not committed registrations in case of mail merge cancel.
#define FN_MAILMERGE_EXCLUDE_ENTRY
#define FN_MAILMERGE_SAVE_DOCUMENTS
void SetMailMergeConfigItem(std::shared_ptr< SwMailMergeConfigItem > const &rConfigItem)
#define SFX_IMPL_INTERFACE(Class, SuperClass)
std::shared_ptr< SwMailMergeConfigItem > EnsureMailMergeConfigItem(const SfxItemSet *pArgs=nullptr)
OUString GetTitle(sal_uInt16 nMaxLen=0) const
#define RET_TARGET_CREATED
std::unique_ptr< SwDBConfig > m_pDBConfig
SwDocShell * GetDocShell()
SfxFrame * GetFrame() const
std::shared_ptr< SwMailMergeConfigItem > const & GetMailMergeConfigItem() const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
#define DECL_LINK(Member, ArgType, RetType)
SfxDispatcher * GetDispatcher()
static const AllSettings & GetSettings()
::utl::SharedUNOComponent< css::sdbc::XConnection > SharedConnection
static void NewXForms(SfxRequest &rReq)
#define FN_MAILMERGE_NEXT_ENTRY
sal_uInt16 GetValue() const
void InvalidateItem(sal_uInt16 nWhich)
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
std::unique_ptr< SwMasterUsrPref, o3tl::default_delete< SwMasterUsrPref > > m_pWebUsrPref
static SfxObjectShell * Current()
const SwMasterUsrPref * GetUsrPref(bool bWeb) const
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
std::unique_ptr< SwChapterNumRules > m_pChapterNumRules
static SfxViewFrame * DisplayNewDocument(SfxObjectShell const &i_rDoc, const SfxRequest &i_rCreateDocRequest)
SwDBConfig * GetDBConfig()
SwWrtShell & GetWrtShell() const
#define FN_PARAM_DATABASE_PROPERTIES
Used by the UI to modify the document model.
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
vcl::Window & GetWindow() const
const SwView & GetView() const
#define FN_MAILMERGE_EMAIL_DOCUMENTS
virtual void ExecuteMMResultPrintDialog(weld::Window *pParent)=0
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void StateOther(SfxItemSet &)
void InsertEnv(SfxRequest &)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
std::unique_ptr< SwPrintOptions > m_pWebPrintOptions
SfxFrame & GetFrame() const
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static SfxViewShell * Current()
SfxViewFrame * GetCurrentViewFrame() const
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
void CommitLastRegistrations()
Accept not committed registrations.
virtual void ExecuteMMResultSaveDialog(weld::Window *pParent)=0
SfxObjectCreateMode GetCreateMode() const
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool m_bAuthorInitialised
virtual void ExecuteMMResultEmailDialog(weld::Window *pParent)=0
std::unique_ptr< SvtAccessibilityOptions > m_pAccessibilityOptions
SwDoc * GetDoc()
returns Doc. But be careful!
bool HasSelection() const
void GetAllUsedDB(std::vector< OUString > &rDBNameList, std::vector< OUString > const *pAllDBNames)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define FN_MAILMERGE_CURRENT_ENTRY
std::unique_ptr< SwStdFontConfig > m_pStdFontConfig
void GetAllUsedDB(std::vector< OUString > &rDBNameList, const std::vector< OUString > *pAllDBNames=nullptr)
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
bool IsInsTableFormatNum(bool bHTML) const
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
SvtUserOptions & GetUserOptions()
SfxItemSet * GetItemSet() const
static SwAbstractDialogFactory * Create()
SfxViewFrame * GetTopViewFrame() const
#define FN_MAILMERGE_PRINT_DOCUMENTS
OUString SwResId(const char *pId)
virtual VclPtr< AbstractMailMergeWizard > CreateMailMergeWizard(SwView &rView, std::shared_ptr< SwMailMergeConfigItem > &rConfigItem)=0
static void ApplyColorConfigValues(const svtools::ColorConfig &rConfig)
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
#define FN_MAILMERGE_LAST_ENTRY
SfxViewShell * GetViewShell() const
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
void UpdateGlosPath(bool bFull)
SwDocShell * GetDocShell()
std::unique_ptr< svtools::ColorConfig > m_pColorConfig
void InsertLab(SfxRequest &, bool bLabel)
void SetReturnValue(const SfxPoolItem &)
bool isExportLocked() const
weld::Window * GetFrameWeld() const
void Update(sal_uInt16 nId)
#define TOOLS_INFO_EXCEPTION(area, stream)
#define RET_REMOVE_TARGET
static std::shared_ptr< SwMailMergeConfigItem > PerformMailMerge(SwView const *pView)
std::unique_ptr< SwModuleOptions, o3tl::default_delete< SwModuleOptions > > m_pModuleConfig
std::unique_ptr< SwToolbarConfigItem > m_pWebToolbarConfig
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
#define FN_MAILMERGE_PREV_ENTRY
void DisableItem(sal_uInt16 nWhich)
bool has(DataAccessDescriptorProperty _eWhich) const
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
#define FN_MAILMERGE_FIRST_ENTRY
#define FN_MAILMERGE_CREATE_DOCUMENTS
virtual void SetFixFields(const DateTime *pNewDateTime)=0
bool DoInitNew(SfxMedium *pMedium=nullptr)
std::unique_ptr< SwMasterUsrPref, o3tl::default_delete< SwMasterUsrPref > > m_pUsrPref
Reference< XComponentContext > getProcessComponentContext()
std::unique_ptr< SwPrintOptions > m_pPrintOptions
std::unique_ptr< SvtCTLOptions > m_pCTLOptions
svtools::ColorConfig & GetColorConfig()
vcl::Window * GetWindow() const
std::unique_ptr< SwNavigationConfig > m_pNavigationConfig
std::unique_ptr< SwToolbarConfigItem > m_pToolbarConfig
void ExecOther(SfxRequest &)
std::unique_ptr< SvtUserOptions > m_pUserOptions
const MiscSettings & GetMiscSettings() const
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
SvtCTLOptions & GetCTLOptions()
bool GetDisablePrinting() const
SelectionType GetSelectionType() const
#define FN_SET_MODOPT_TBLNUMFMT
#define FN_MAILMERGE_WIZARD
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
virtual SfxObjectShell * GetObjectShell()
SwDBManager * GetDBManager() const
#define SFX_OBJECTBAR_APPLICATION
SfxMedium * GetMedium() const
SwGlossaryList * GetGlossaryList()