diff options
Diffstat (limited to '')
-rw-r--r-- | sw/source/ui/config/mailconfigpage.cxx | 482 | ||||
-rw-r--r-- | sw/source/ui/config/optcomp.cxx | 498 | ||||
-rw-r--r-- | sw/source/ui/config/optload.cxx | 910 | ||||
-rw-r--r-- | sw/source/ui/config/optpage.cxx | 2194 |
4 files changed, 4084 insertions, 0 deletions
diff --git a/sw/source/ui/config/mailconfigpage.cxx b/sw/source/ui/config/mailconfigpage.cxx new file mode 100644 index 000000000..14160f27e --- /dev/null +++ b/sw/source/ui/config/mailconfigpage.cxx @@ -0,0 +1,482 @@ +/* -*- 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 . + */ + +#include <swtypes.hxx> +#include <mailconfigpage.hxx> +#include <mmconfigitem.hxx> +#include <mailmergehelper.hxx> +#include <vcl/svapp.hxx> +#include <vcl/weld.hxx> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/mail/MailServiceType.hpp> +#include <com/sun/star/mail/XMailService.hpp> +#include <com/sun/star/mail/MailServiceProvider.hpp> +#include <strings.hrc> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::mail; +using namespace ::com::sun::star::beans; + +class SwTestAccountSettingsDialog : public SfxDialogController +{ + ImplSVEvent* m_pPostedEvent; + OUString m_sCompleted; + OUString m_sFailed; + OUString m_sErrorServer; + bool m_bStop; + + SwMailConfigPage* m_pParent; + + std::unique_ptr<weld::Button> m_xStopPB; + std::unique_ptr<weld::TextView> m_xErrorsED; + std::unique_ptr<weld::Label> m_xEstablish; + std::unique_ptr<weld::Label> m_xFind; + std::unique_ptr<weld::Label> m_xResult1; + std::unique_ptr<weld::Label> m_xResult2; + std::unique_ptr<weld::Image> m_xImage1; + std::unique_ptr<weld::Image> m_xImage2; + std::unique_ptr<weld::Image> m_xImage3; + std::unique_ptr<weld::Image> m_xImage4; + + void Test(); + DECL_LINK(StopHdl, weld::Button&, void); + DECL_LINK(TestHdl, void*, void); +public: + explicit SwTestAccountSettingsDialog(SwMailConfigPage* pParent); + virtual ~SwTestAccountSettingsDialog() override; +}; + +namespace { + +class SwAuthenticationSettingsDialog : public SfxDialogController +{ + SwMailMergeConfigItem& m_rConfigItem; + + std::unique_ptr<weld::CheckButton> m_xAuthenticationCB; + std::unique_ptr<weld::RadioButton> m_xSeparateAuthenticationRB; + std::unique_ptr<weld::RadioButton> m_xSMTPAfterPOPRB; + std::unique_ptr<weld::Label> m_xOutgoingServerFT; + std::unique_ptr<weld::Label> m_xUserNameFT; + std::unique_ptr<weld::Entry> m_xUserNameED; + std::unique_ptr<weld::Label> m_xOutPasswordFT; + std::unique_ptr<weld::Entry> m_xOutPasswordED; + std::unique_ptr<weld::Label> m_xIncomingServerFT; + std::unique_ptr<weld::Label> m_xServerFT; + std::unique_ptr<weld::Entry> m_xServerED; + std::unique_ptr<weld::Label> m_xPortFT; + std::unique_ptr<weld::SpinButton> m_xPortNF; + std::unique_ptr<weld::Label> m_xProtocolFT; + std::unique_ptr<weld::RadioButton> m_xPOP3RB; + std::unique_ptr<weld::RadioButton> m_xIMAPRB; + std::unique_ptr<weld::Label> m_xInUsernameFT; + std::unique_ptr<weld::Entry> m_xInUsernameED; + std::unique_ptr<weld::Label> m_xInPasswordFT; + std::unique_ptr<weld::Entry> m_xInPasswordED; + std::unique_ptr<weld::Button> m_xOKPB; + + DECL_LINK(OKHdl_Impl, weld::Button&, void); + DECL_LINK(CheckBoxHdl_Impl, weld::Toggleable&, void); + DECL_LINK(RadioButtonHdl_Impl, weld::Toggleable&, void); + DECL_LINK(InServerHdl_Impl, weld::Toggleable&, void); + +public: + SwAuthenticationSettingsDialog(weld::Window* pParent, SwMailMergeConfigItem& rItem); +}; + +} + +SwMailConfigPage::SwMailConfigPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/mailconfigpage.ui", "MailConfigPage", &rSet) + , m_pConfigItem(new SwMailMergeConfigItem) + , m_xDisplayNameED(m_xBuilder->weld_entry("displayname")) + , m_xAddressED(m_xBuilder->weld_entry("address")) + , m_xReplyToCB(m_xBuilder->weld_check_button("replytocb")) + , m_xReplyToFT(m_xBuilder->weld_label("replyto_label")) + , m_xReplyToED(m_xBuilder->weld_entry("replyto")) + , m_xServerED(m_xBuilder->weld_entry("server")) + , m_xPortNF(m_xBuilder->weld_spin_button("port")) + , m_xSecureCB(m_xBuilder->weld_check_button("secure")) + , m_xServerAuthenticationPB(m_xBuilder->weld_button("serverauthentication")) + , m_xTestPB(m_xBuilder->weld_button("test")) +{ + m_xReplyToCB->connect_toggled(LINK(this, SwMailConfigPage, ReplyToHdl)); + m_xServerAuthenticationPB->connect_clicked(LINK(this, SwMailConfigPage, AuthenticationHdl)); + m_xTestPB->connect_clicked(LINK(this, SwMailConfigPage, TestHdl)); + m_xSecureCB->connect_toggled(LINK(this, SwMailConfigPage, SecureHdl)); +} + +SwMailConfigPage::~SwMailConfigPage() +{ + m_pConfigItem.reset(); +} + +std::unique_ptr<SfxTabPage> SwMailConfigPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet) +{ + return std::make_unique<SwMailConfigPage>(pPage, pController, *rAttrSet); +} + +bool SwMailConfigPage::FillItemSet( SfxItemSet* /*rSet*/ ) +{ + if (m_xDisplayNameED->get_value_changed_from_saved()) + m_pConfigItem->SetMailDisplayName(m_xDisplayNameED->get_text()); + if (m_xAddressED->get_value_changed_from_saved()) + m_pConfigItem->SetMailAddress(m_xAddressED->get_text()); + if (m_xReplyToCB->get_state_changed_from_saved() ) + m_pConfigItem->SetMailReplyTo(m_xReplyToCB->get_active()); + if (m_xReplyToED->get_value_changed_from_saved()) + m_pConfigItem->SetMailReplyTo(m_xReplyToED->get_text()); + if (m_xServerED->get_value_changed_from_saved()) + m_pConfigItem->SetMailServer(m_xServerED->get_text()); + + m_pConfigItem->SetMailPort(m_xPortNF->get_value()); + m_pConfigItem->SetSecureConnection(m_xSecureCB->get_active()); + + m_pConfigItem->Commit(); + return true; +} + +void SwMailConfigPage::Reset( const SfxItemSet* /*rSet*/ ) +{ + m_xDisplayNameED->set_text(m_pConfigItem->GetMailDisplayName()); + m_xAddressED->set_text(m_pConfigItem->GetMailAddress()); + + m_xReplyToED->set_text(m_pConfigItem->GetMailReplyTo()) ; + m_xReplyToCB->set_active(m_pConfigItem->IsMailReplyTo()); + ReplyToHdl(*m_xReplyToCB); + + m_xServerED->set_text(m_pConfigItem->GetMailServer()); + m_xPortNF->set_value(m_pConfigItem->GetMailPort()); + + m_xSecureCB->set_active(m_pConfigItem->IsSecureConnection()); + + m_xDisplayNameED->save_value(); + m_xAddressED->save_value(); + m_xReplyToCB->save_state(); + m_xReplyToED->save_value(); + m_xServerED->save_value(); + m_xPortNF->save_value(); + m_xSecureCB->save_state(); +} + +IMPL_LINK(SwMailConfigPage, ReplyToHdl, weld::Toggleable&, rBox, void) +{ + bool bEnable = rBox.get_active(); + m_xReplyToFT->set_sensitive(bEnable); + m_xReplyToED->set_sensitive(bEnable); +} + +IMPL_LINK_NOARG(SwMailConfigPage, AuthenticationHdl, weld::Button&, void) +{ + m_pConfigItem->SetMailAddress(m_xAddressED->get_text()); + + SwAuthenticationSettingsDialog aDlg(GetFrameWeld(), *m_pConfigItem); + aDlg.run(); +} + +IMPL_LINK_NOARG(SwMailConfigPage, TestHdl, weld::Button&, void) +{ + SwTestAccountSettingsDialog aDlg(this); + aDlg.run(); +} + +IMPL_LINK(SwMailConfigPage, SecureHdl, weld::Toggleable&, rBox, void) +{ + bool bEnable = rBox.get_active(); + m_pConfigItem->SetSecureConnection(bEnable); + m_pConfigItem->SetMailPort(m_xPortNF->get_value()); + m_xPortNF->set_value(m_pConfigItem->GetMailPort()); +} + +SwTestAccountSettingsDialog::SwTestAccountSettingsDialog(SwMailConfigPage* pParent) + : SfxDialogController(pParent->GetFrameWeld(), "modules/swriter/ui/testmailsettings.ui", "TestMailSettings") + , m_bStop(false) + , m_pParent(pParent) + , m_xStopPB(m_xBuilder->weld_button("stop")) + , m_xErrorsED(m_xBuilder->weld_text_view("errors")) + , m_xEstablish(m_xBuilder->weld_label("establish")) + , m_xFind(m_xBuilder->weld_label("find")) + , m_xResult1(m_xBuilder->weld_label("result1")) + , m_xResult2(m_xBuilder->weld_label("result2")) + , m_xImage1(m_xBuilder->weld_image("image1")) + , m_xImage2(m_xBuilder->weld_image("image2")) + , m_xImage3(m_xBuilder->weld_image("image3")) + , m_xImage4(m_xBuilder->weld_image("image4")) +{ + m_xErrorsED->set_size_request(m_xErrorsED->get_approximate_digit_width() * 72, + m_xErrorsED->get_height_rows(8)); + m_sErrorServer = m_xErrorsED->get_text(); + m_xErrorsED->set_text(""); + m_sCompleted = m_xResult1->get_label(); + m_sFailed = m_xResult2->get_label(); + + m_xStopPB->connect_clicked(LINK(this, SwTestAccountSettingsDialog, StopHdl)); + + m_pPostedEvent = Application::PostUserEvent(LINK(this, SwTestAccountSettingsDialog, TestHdl)); +} + +SwTestAccountSettingsDialog::~SwTestAccountSettingsDialog() +{ + if (m_pPostedEvent) + { + Application::RemoveUserEvent(m_pPostedEvent); + } +} + +IMPL_LINK_NOARG(SwTestAccountSettingsDialog, StopHdl, weld::Button&, void) +{ + m_bStop = true; +} + +IMPL_LINK_NOARG(SwTestAccountSettingsDialog, TestHdl, void*, void) +{ + m_pPostedEvent = nullptr; + weld::WaitObject aWait(m_xDialog.get()); + Test(); +} + +void SwTestAccountSettingsDialog::Test() +{ + uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); + + OUString sException; + + bool bIsLoggedIn = false; + bool bIsServer = false; + try + { + uno::Reference< mail::XMailService > xInMailService; + uno::Reference< mail::XMailServiceProvider > xMailServiceProvider( + mail::MailServiceProvider::create(xContext) ); + uno::Reference< mail::XMailService > xMailService = + xMailServiceProvider->create( + mail::MailServiceType_SMTP); + if(m_bStop) + return; + uno::Reference<XConnectionListener> xConnectionListener(new SwConnectionListener()); + + if(m_pParent->m_pConfigItem->IsAuthentication() && + m_pParent->m_pConfigItem->IsSMTPAfterPOP()) + { + xInMailService = xMailServiceProvider->create( + m_pParent->m_pConfigItem->IsInServerPOP() ? + mail::MailServiceType_POP3 : mail::MailServiceType_IMAP); + if(m_bStop) + return; + //authenticate at the POP or IMAP server first + uno::Reference<XAuthenticator> xAuthenticator = + new SwAuthenticator( + m_pParent->m_pConfigItem->GetInServerUserName(), + m_pParent->m_pConfigItem->GetInServerPassword(), + m_xDialog.get()); + + xInMailService->addConnectionListener(xConnectionListener); + //check connection + uno::Reference< uno::XCurrentContext> xConnectionContext = + new SwConnectionContext( + m_pParent->m_pConfigItem->GetInServerName(), + m_pParent->m_pConfigItem->GetInServerPort(), + "Insecure"); + xInMailService->connect(xConnectionContext, xAuthenticator); + } + if(m_bStop) + return; + uno::Reference<XAuthenticator> xAuthenticator; + if(m_pParent->m_pConfigItem->IsAuthentication() && + !m_pParent->m_pConfigItem->IsSMTPAfterPOP() && + !m_pParent->m_pConfigItem->GetMailUserName().isEmpty()) + xAuthenticator = + new SwAuthenticator( + m_pParent->m_pConfigItem->GetMailUserName(), + m_pParent->m_pConfigItem->GetMailPassword(), + m_xDialog.get()); + else + xAuthenticator = new SwAuthenticator(); + + xMailService->addConnectionListener(xConnectionListener); + if(m_bStop) + return; + //just to check if the server exists + xMailService->getSupportedConnectionTypes(); + if(m_bStop) + return; + bIsServer = true; + //check connection + uno::Reference< uno::XCurrentContext> xConnectionContext = + new SwConnectionContext( + m_pParent->m_xServerED->get_text(), + m_pParent->m_xPortNF->get_value(), + m_pParent->m_xSecureCB->get_active() ? OUString("Ssl") : OUString("Insecure")); + xMailService->connect(xConnectionContext, xAuthenticator); + bIsLoggedIn = xMailService->isConnected(); + if( xInMailService.is() ) + xInMailService->disconnect(); + if( xMailService->isConnected()) + xMailService->disconnect(); + } + catch (const uno::Exception& e) + { + sException = e.Message; + } + + m_xResult1->set_label(bIsServer ? m_sCompleted : m_sFailed); + m_xImage1->set_visible(!bIsServer); + m_xImage3->set_visible(bIsServer); + + m_xResult2->set_label(bIsLoggedIn ? m_sCompleted : m_sFailed); + m_xImage2->set_visible(!bIsLoggedIn); + m_xImage4->set_visible(bIsLoggedIn); + + if (!bIsServer || !bIsLoggedIn) + { + OUString aErrorMessage(m_sErrorServer); + if (!sException.isEmpty()) + aErrorMessage += "\n--\n" + sException; + m_xErrorsED->set_text(aErrorMessage); + } +} + +SwMailConfigDlg::SwMailConfigDlg(weld::Window* pParent, const SfxItemSet& rSet) + : SfxSingleTabDialogController(pParent, &rSet) +{ + // create TabPage + SetTabPage(SwMailConfigPage::Create(get_content_area(), this, &rSet)); + m_xDialog->set_title(SwResId(STR_MAILCONFIG_DLG_TITLE)); +} + +SwAuthenticationSettingsDialog::SwAuthenticationSettingsDialog( + weld::Window* pParent, SwMailMergeConfigItem& rItem) + : SfxDialogController(pParent, "modules/swriter/ui/authenticationsettingsdialog.ui", "AuthenticationSettingsDialog") + , m_rConfigItem(rItem) + , m_xAuthenticationCB(m_xBuilder->weld_check_button("authentication")) + , m_xSeparateAuthenticationRB(m_xBuilder->weld_radio_button("separateauthentication")) + , m_xSMTPAfterPOPRB(m_xBuilder->weld_radio_button("smtpafterpop")) + , m_xOutgoingServerFT(m_xBuilder->weld_label("label1")) + , m_xUserNameFT(m_xBuilder->weld_label("username_label")) + , m_xUserNameED(m_xBuilder->weld_entry("username")) + , m_xOutPasswordFT(m_xBuilder->weld_label("outpassword_label")) + , m_xOutPasswordED(m_xBuilder->weld_entry("outpassword")) + , m_xIncomingServerFT(m_xBuilder->weld_label("label2")) + , m_xServerFT(m_xBuilder->weld_label("server_label")) + , m_xServerED(m_xBuilder->weld_entry("server")) + , m_xPortFT(m_xBuilder->weld_label("port_label")) + , m_xPortNF(m_xBuilder->weld_spin_button("port")) + , m_xProtocolFT(m_xBuilder->weld_label("label3")) + , m_xPOP3RB(m_xBuilder->weld_radio_button("pop3")) + , m_xIMAPRB(m_xBuilder->weld_radio_button("imap")) + , m_xInUsernameFT(m_xBuilder->weld_label("inusername_label")) + , m_xInUsernameED(m_xBuilder->weld_entry("inusername")) + , m_xInPasswordFT(m_xBuilder->weld_label("inpassword_label")) + , m_xInPasswordED(m_xBuilder->weld_entry("inpassword")) + , m_xOKPB(m_xBuilder->weld_button("ok")) +{ + m_xAuthenticationCB->connect_toggled( LINK( this, SwAuthenticationSettingsDialog, CheckBoxHdl_Impl)); + Link<weld::Toggleable&,void> aRBLink = LINK( this, SwAuthenticationSettingsDialog, RadioButtonHdl_Impl ); + m_xSeparateAuthenticationRB->connect_toggled( aRBLink ); + m_xSMTPAfterPOPRB->connect_toggled( aRBLink ); + m_xOKPB->connect_clicked( LINK( this, SwAuthenticationSettingsDialog, OKHdl_Impl)); + m_xPOP3RB->connect_toggled(LINK(this, SwAuthenticationSettingsDialog, InServerHdl_Impl)); + + m_xAuthenticationCB->set_active(m_rConfigItem.IsAuthentication()); + if (m_rConfigItem.IsSMTPAfterPOP()) + m_xSMTPAfterPOPRB->set_active(true); + else + m_xSeparateAuthenticationRB->set_active(true); + m_xUserNameED->set_text(m_rConfigItem.GetMailUserName()); + m_xOutPasswordED->set_text(m_rConfigItem.GetMailPassword()); + + m_xServerED->set_text(m_rConfigItem.GetInServerName()); + m_xPortNF->set_value(m_rConfigItem.GetInServerPort()); + if (m_rConfigItem.IsInServerPOP()) + m_xPOP3RB->set_active(true); + else + m_xIMAPRB->set_active(true); + m_xInUsernameED->set_text(m_rConfigItem.GetInServerUserName()); + m_xInPasswordED->set_text(m_rConfigItem.GetInServerPassword()); + + CheckBoxHdl_Impl(*m_xAuthenticationCB); +} + +IMPL_LINK_NOARG(SwAuthenticationSettingsDialog, OKHdl_Impl, weld::Button&, void) +{ + m_rConfigItem.SetAuthentication( m_xAuthenticationCB->get_active() ); + m_rConfigItem.SetSMTPAfterPOP(m_xSMTPAfterPOPRB->get_active()); + m_rConfigItem.SetMailUserName(m_xUserNameED->get_text()); + m_rConfigItem.SetMailPassword(m_xOutPasswordED->get_text()); + m_rConfigItem.SetInServerName(m_xServerED->get_text()); + m_rConfigItem.SetInServerPort(m_xPortNF->get_value()); + m_rConfigItem.SetInServerPOP(m_xPOP3RB->get_active()); + m_rConfigItem.SetInServerUserName(m_xInUsernameED->get_text()); + m_rConfigItem.SetInServerPassword(m_xInPasswordED->get_text()); + m_xDialog->response(RET_OK); +} + +IMPL_LINK( SwAuthenticationSettingsDialog, CheckBoxHdl_Impl, weld::Toggleable&, rBox, void) +{ + bool bChecked = rBox.get_active(); + m_xSeparateAuthenticationRB->set_sensitive(bChecked); + m_xSMTPAfterPOPRB->set_sensitive(bChecked); + RadioButtonHdl_Impl(*m_xSeparateAuthenticationRB); +} + +IMPL_LINK_NOARG(SwAuthenticationSettingsDialog, RadioButtonHdl_Impl, weld::Toggleable&, void) +{ + bool bSeparate = m_xSeparateAuthenticationRB->get_active(); + bool bIsEnabled = m_xSeparateAuthenticationRB->get_sensitive(); + bool bNotSeparate = !bSeparate && bIsEnabled; + bSeparate &= bIsEnabled; + + if (bSeparate && m_xUserNameED->get_text().isEmpty()) + m_xUserNameED->set_text(m_rConfigItem.GetMailAddress()); + else if (!bSeparate && m_xUserNameED->get_text() == m_rConfigItem.GetMailAddress()) + m_xUserNameED->set_text(""); + + if (bNotSeparate && m_xInUsernameED->get_text().isEmpty()) + m_xInUsernameED->set_text(m_rConfigItem.GetMailAddress()); + else if (!bNotSeparate && m_xInUsernameED->get_text() == m_rConfigItem.GetMailAddress()) + m_xInUsernameED->set_text(""); + + m_xOutgoingServerFT->set_sensitive(bSeparate); + m_xUserNameFT->set_sensitive(bSeparate); + m_xUserNameED->set_sensitive(bSeparate); + m_xOutPasswordFT->set_sensitive(bSeparate); + m_xOutPasswordED->set_sensitive(bSeparate); + + m_xIncomingServerFT->set_sensitive(bNotSeparate); + m_xServerFT->set_sensitive(bNotSeparate); + m_xServerED->set_sensitive(bNotSeparate); + m_xPortFT->set_sensitive(bNotSeparate); + m_xPortNF->set_sensitive(bNotSeparate); + m_xInUsernameFT->set_sensitive(bNotSeparate); + m_xInUsernameED->set_sensitive(bNotSeparate); + m_xProtocolFT->set_sensitive(bNotSeparate); + m_xPOP3RB->set_sensitive(bNotSeparate); + m_xIMAPRB->set_sensitive(bNotSeparate); + m_xInPasswordFT->set_sensitive(bNotSeparate); + m_xInPasswordED->set_sensitive(bNotSeparate); +} + +IMPL_LINK_NOARG( SwAuthenticationSettingsDialog, InServerHdl_Impl, weld::Toggleable&, void) +{ + bool bPOP = m_xPOP3RB->get_active(); + m_rConfigItem.SetInServerPOP(bPOP); + m_xPortNF->set_value(m_rConfigItem.GetInServerPort()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/config/optcomp.cxx b/sw/source/ui/config/optcomp.cxx new file mode 100644 index 000000000..ec8ac3ddf --- /dev/null +++ b/sw/source/ui/config/optcomp.cxx @@ -0,0 +1,498 @@ +/* -*- 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 . + */ + +#include <optcomp.hxx> + +#include <cmdid.h> +#include <docsh.hxx> +#include <uiitems.hxx> +#include <view.hxx> +#include <wrtsh.hxx> + +#include <vcl/svapp.hxx> +#include <vcl/weld.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/fcontnr.hxx> +#include <IDocumentSettingAccess.hxx> +#include <vector> +#include <svtools/restartdialog.hxx> +#include <comphelper/processfactory.hxx> +#include <officecfg/Office/Compatibility.hxx> +#include <osl/diagnose.h> + +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::uno; +using namespace ::std; + +struct SwCompatibilityOptPage_Impl +{ + std::vector< SvtCompatibilityEntry > m_aList; +}; + +SwCompatibilityOptPage::SwCompatibilityOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optcompatpage.ui", "OptCompatPage", &rSet) + , m_pWrtShell(nullptr) + , m_pImpl(new SwCompatibilityOptPage_Impl) + , m_nSavedOptions(0) + , m_bSavedMSFormsMenuOption(false) + , m_xMain(m_xBuilder->weld_frame("compatframe")) + , m_xGlobalOptionsFrame(m_xBuilder->weld_frame("globalcompatframe")) + , m_xFormattingLB(m_xBuilder->weld_combo_box("format")) + , m_xGlobalOptionsLB(m_xBuilder->weld_combo_box("globaloptions")) + , m_xOptionsLB(m_xBuilder->weld_tree_view("options")) + , m_xGlobalOptionsCLB(m_xBuilder->weld_tree_view("globaloptioncheckbox")) + , m_xDefaultPB(m_xBuilder->weld_button("default")) +{ + m_xOptionsLB->enable_toggle_buttons(weld::ColumnToggleType::Check); + m_xGlobalOptionsCLB->enable_toggle_buttons(weld::ColumnToggleType::Check); + + int nPos = 0; + for (int i = static_cast<int>(SvtCompatibilityEntry::Index::Module) + 1; + i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID) - 1; // omit AddTableLineSpacing + ++i) + { + int nCoptIdx = i - 2; /* Do not consider "Name" & "Module" indexes */ + + const OUString sEntry = m_xFormattingLB->get_text(nCoptIdx); + m_xOptionsLB->append(); + m_xOptionsLB->set_toggle(nPos, TRISTATE_FALSE); + m_xOptionsLB->set_text(nPos, sEntry, 0); + ++nPos; + } + + m_sUserEntry = m_xFormattingLB->get_text(m_xFormattingLB->get_count() - 1); + + m_xFormattingLB->clear(); + + // Set MSOCompatibleFormsMenu entry attributes + const bool bReadOnly = officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::isReadOnly(); + m_xGlobalOptionsCLB->set_sensitive(!bReadOnly); + + m_xGlobalOptionsCLB->append(); + const bool bChecked = officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::get(); + m_xGlobalOptionsCLB->set_toggle(0, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE); + m_xGlobalOptionsCLB->set_text(0, m_xGlobalOptionsLB->get_text(0), 0); + + m_xGlobalOptionsLB->clear(); + + // tdf#125799, we let only the doc options grow/shrink but give this one more than its bare + // min request height because there's only one row in it and that looks somewhat abrupt + m_xGlobalOptionsCLB->set_size_request(-1, m_xGlobalOptionsCLB->get_preferred_size().Height() * 2); + + InitControls( rSet ); + + // set handler + m_xFormattingLB->connect_changed( LINK( this, SwCompatibilityOptPage, SelectHdl ) ); + m_xDefaultPB->connect_clicked( LINK( this, SwCompatibilityOptPage, UseAsDefaultHdl ) ); +} + +SwCompatibilityOptPage::~SwCompatibilityOptPage() +{ +} + +static sal_uInt32 convertBools2Ulong_Impl +( + bool _bUsePrtMetrics, + bool _bAddSpacing, + bool _bAddSpacingAtPages, + bool _bUseOurTabStops, + bool _bNoExtLeading, + bool _bUseLineSpacing, + bool _bAddTableSpacing, + bool _bAddTableLineSpacing, + bool _bUseObjPos, + bool _bUseOurTextWrapping, + bool _bConsiderWrappingStyle, + bool _bExpandWordSpace, + bool _bProtectForm, + bool _bMsWordCompTrailingBlanks, + bool bSubtractFlysAnchoredAtFlys, + bool bEmptyDbFieldHidesPara +) +{ + sal_uInt32 nRet = 0; + sal_uInt32 nSetBit = 1; + + if ( _bUsePrtMetrics ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bAddSpacing ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bAddSpacingAtPages ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bUseOurTabStops ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bNoExtLeading ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bUseLineSpacing ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bAddTableSpacing ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if (_bAddTableLineSpacing) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bUseObjPos ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bUseOurTextWrapping ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bConsiderWrappingStyle ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bExpandWordSpace ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bProtectForm ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if ( _bMsWordCompTrailingBlanks ) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if (bSubtractFlysAnchoredAtFlys) + nRet |= nSetBit; + nSetBit = nSetBit << 1; + if (bEmptyDbFieldHidesPara) + nRet |= nSetBit; + + return nRet; +} + +void SwCompatibilityOptPage::InitControls( const SfxItemSet& rSet ) +{ + // init objectshell and detect document name + OUString sDocTitle; + SfxObjectShell* pObjShell = nullptr; + if ( const SwPtrItem* pItem = rSet.GetItemIfSet( FN_PARAM_WRTSHELL, false ) ) + m_pWrtShell = static_cast<SwWrtShell*>(pItem->GetValue()); + if ( m_pWrtShell ) + { + pObjShell = m_pWrtShell->GetView().GetDocShell(); + if ( pObjShell ) + sDocTitle = pObjShell->GetTitle(); + } + else + { + m_xMain->set_sensitive(false); + m_xGlobalOptionsFrame->set_sensitive(false); + } + const OUString& rText = m_xMain->get_label(); + m_xMain->set_label(rText.replaceAll("%DOCNAME", sDocTitle)); + + // loading file formats + const std::vector< SvtCompatibilityEntry > aList = m_aConfigItem.GetList(); + + for ( const SvtCompatibilityEntry& rEntry : aList ) + { + const OUString sEntryName = rEntry.getValue<OUString>( SvtCompatibilityEntry::Index::Name ); + const bool bIsUserEntry = ( sEntryName == SvtCompatibilityEntry::USER_ENTRY_NAME ); + const bool bIsDefaultEntry = ( sEntryName == SvtCompatibilityEntry::DEFAULT_ENTRY_NAME ); + + m_pImpl->m_aList.push_back( rEntry ); + + if ( bIsDefaultEntry ) + continue; + + OUString sNewEntry; + if ( bIsUserEntry ) + sNewEntry = m_sUserEntry; + + else if ( pObjShell && !sEntryName.isEmpty() ) + { + SfxFilterContainer* pFacCont = pObjShell->GetFactory().GetFilterContainer(); + std::shared_ptr<const SfxFilter> pFilter = pFacCont->GetFilter4FilterName( sEntryName ); + if ( pFilter ) + sNewEntry = pFilter->GetUIName(); + } + + if ( sNewEntry.isEmpty() ) + sNewEntry = sEntryName; + + sal_uInt32 nOptions = convertBools2Ulong_Impl( + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UsePrtMetrics ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::AddSpacing ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::AddSpacingAtPages ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UseOurTabStops ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::NoExtLeading ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UseLineSpacing ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::AddTableSpacing ), + rEntry.getValue<bool>(SvtCompatibilityEntry::Index::AddTableLineSpacing), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UseObjectPositioning ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UseOurTextWrapping ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::ConsiderWrappingStyle ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::ExpandWordSpace ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::ProtectForm ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::MsWordTrailingBlanks ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::SubtractFlysAnchoredAtFlys ), + rEntry.getValue<bool>( SvtCompatibilityEntry::Index::EmptyDbFieldHidesPara ) ); + m_xFormattingLB->append(OUString::number(nOptions), sNewEntry); + } +} + +IMPL_LINK_NOARG(SwCompatibilityOptPage, SelectHdl, weld::ComboBox&, void) +{ + sal_uInt32 nOptions = m_xFormattingLB->get_active_id().toUInt32(); + SetCurrentOptions(nOptions); +} + +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) + return; + + auto pItem = std::find_if(m_pImpl->m_aList.begin(), m_pImpl->m_aList.end(), + [](const SvtCompatibilityEntry& rItem) + { + const OUString sEntryName = rItem.getValue<OUString>( SvtCompatibilityEntry::Index::Name ); + const bool bIsDefaultEntry = ( sEntryName == SvtCompatibilityEntry::DEFAULT_ENTRY_NAME ); + return bIsDefaultEntry; + }); + if (pItem != m_pImpl->m_aList.end()) + { + const sal_Int32 nCount = m_xOptionsLB->n_children(); + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + bool bChecked = m_xOptionsLB->get_toggle(i); + + int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */ + pItem->setValue<bool>( SvtCompatibilityEntry::Index(nCoptIdx), bChecked ); + if (nCoptIdx == int(SvtCompatibilityEntry::Index::AddTableSpacing)) + { + bool const isLineSpacing = m_xOptionsLB->get_toggle(i) == TRISTATE_TRUE; + pItem->setValue<bool>(SvtCompatibilityEntry::Index::AddTableLineSpacing, isLineSpacing); + } + else + { + assert(m_xOptionsLB->get_toggle(i) != TRISTATE_INDET); + } + } + } + + WriteOptions(); +} + +void SwCompatibilityOptPage::SetCurrentOptions( sal_uInt32 nOptions ) +{ + const int nCount = m_xOptionsLB->n_children(); + OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" ); + for (int i = 0; i < nCount; ++i) + { + bool bChecked = ( ( nOptions & 0x00000001 ) == 0x00000001 ); + TriState value = bChecked ? TRISTATE_TRUE : TRISTATE_FALSE; + if (i == int(SvtCompatibilityEntry::Index::AddTableSpacing) - 2) + { // hack: map 2 bools to 1 tristate + nOptions = nOptions >> 1; + if (value == TRISTATE_TRUE + && (nOptions & 0x00000001) != 0x00000001) // ADD_PARA_LINE_SPACING_TO_TABLE_CELLS + { + value = TRISTATE_INDET; // 3 values possible here + } + } + m_xOptionsLB->set_toggle(i, value); + nOptions = nOptions >> 1; + } +} + +sal_uInt32 SwCompatibilityOptPage::GetDocumentOptions() const +{ + sal_uInt32 nRet = 0; + if ( m_pWrtShell ) + { + const IDocumentSettingAccess& rIDocumentSettingAccess = m_pWrtShell->getIDocumentSettingAccess(); + nRet = convertBools2Ulong_Impl( + !rIDocumentSettingAccess.get( DocumentSettingId::USE_VIRTUAL_DEVICE ), + rIDocumentSettingAccess.get( DocumentSettingId::PARA_SPACE_MAX ), + rIDocumentSettingAccess.get( DocumentSettingId::PARA_SPACE_MAX_AT_PAGES ), + !rIDocumentSettingAccess.get( DocumentSettingId::TAB_COMPAT ), + !rIDocumentSettingAccess.get( DocumentSettingId::ADD_EXT_LEADING ), + rIDocumentSettingAccess.get( DocumentSettingId::OLD_LINE_SPACING ), + rIDocumentSettingAccess.get( DocumentSettingId::ADD_PARA_SPACING_TO_TABLE_CELLS ), + rIDocumentSettingAccess.get( DocumentSettingId::ADD_PARA_LINE_SPACING_TO_TABLE_CELLS ), + rIDocumentSettingAccess.get( DocumentSettingId::USE_FORMER_OBJECT_POS ), + rIDocumentSettingAccess.get( DocumentSettingId::USE_FORMER_TEXT_WRAPPING ), + rIDocumentSettingAccess.get( DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION ), + !rIDocumentSettingAccess.get( DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK ), + rIDocumentSettingAccess.get( DocumentSettingId::PROTECT_FORM ), + rIDocumentSettingAccess.get( DocumentSettingId::MS_WORD_COMP_TRAILING_BLANKS ), + rIDocumentSettingAccess.get( DocumentSettingId::SUBTRACT_FLYS ), + rIDocumentSettingAccess.get( DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA ) ); + } + return nRet; +} + +void SwCompatibilityOptPage::WriteOptions() +{ + m_aConfigItem.Clear(); + for ( const auto& rItem : m_pImpl->m_aList ) + m_aConfigItem.AppendItem(rItem); +} + +std::unique_ptr<SfxTabPage> SwCompatibilityOptPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet) +{ + return std::make_unique<SwCompatibilityOptPage>(pPage, pController, *rAttrSet); +} + +bool SwCompatibilityOptPage::FillItemSet( SfxItemSet* ) +{ + bool bModified = false; + if ( m_pWrtShell ) + { + sal_uInt32 nSavedOptions = m_nSavedOptions; + const int nCount = m_xOptionsLB->n_children(); + OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" ); + + for (int i = 0; i < nCount; ++i) + { + TriState const current = m_xOptionsLB->get_toggle(i); + TriState saved = ((nSavedOptions & 0x00000001) == 0x00000001) ? TRISTATE_TRUE : TRISTATE_FALSE; + if (i == int(SvtCompatibilityEntry::Index::AddTableSpacing) - 2) + { // hack: map 2 bools to 1 tristate + nSavedOptions = nSavedOptions >> 1; + if (saved == TRISTATE_TRUE + && ((nSavedOptions & 0x00000001) != 0x00000001)) + { + saved = TRISTATE_INDET; + } + } + if (current != saved) + { + bool const bChecked(current != TRISTATE_FALSE); + assert(current != TRISTATE_INDET); // can't *change* it to that + int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */ + switch ( SvtCompatibilityEntry::Index(nCoptIdx) ) + { + case SvtCompatibilityEntry::Index::UsePrtMetrics: + m_pWrtShell->SetUseVirDev( !bChecked ); + break; + + case SvtCompatibilityEntry::Index::AddSpacing: + m_pWrtShell->SetParaSpaceMax( bChecked ); + break; + + case SvtCompatibilityEntry::Index::AddSpacingAtPages: + m_pWrtShell->SetParaSpaceMaxAtPages( bChecked ); + break; + + case SvtCompatibilityEntry::Index::UseOurTabStops: + m_pWrtShell->SetTabCompat( !bChecked ); + break; + + case SvtCompatibilityEntry::Index::NoExtLeading: + m_pWrtShell->SetAddExtLeading( !bChecked ); + break; + + case SvtCompatibilityEntry::Index::UseLineSpacing: + m_pWrtShell->SetUseFormerLineSpacing( bChecked ); + break; + + case SvtCompatibilityEntry::Index::AddTableSpacing: + m_pWrtShell->SetAddParaSpacingToTableCells( bChecked ); + break; + + case SvtCompatibilityEntry::Index::UseObjectPositioning: + m_pWrtShell->SetUseFormerObjectPositioning( bChecked ); + break; + + case SvtCompatibilityEntry::Index::UseOurTextWrapping: + m_pWrtShell->SetUseFormerTextWrapping( bChecked ); + break; + + case SvtCompatibilityEntry::Index::ConsiderWrappingStyle: + m_pWrtShell->SetConsiderWrapOnObjPos( bChecked ); + break; + + case SvtCompatibilityEntry::Index::ExpandWordSpace: + m_pWrtShell->SetDoNotJustifyLinesWithManualBreak( !bChecked ); + break; + + case SvtCompatibilityEntry::Index::ProtectForm: + m_pWrtShell->SetProtectForm( bChecked ); + break; + + case SvtCompatibilityEntry::Index::MsWordTrailingBlanks: + m_pWrtShell->SetMsWordCompTrailingBlanks( bChecked ); + break; + + case SvtCompatibilityEntry::Index::SubtractFlysAnchoredAtFlys: + m_pWrtShell->SetSubtractFlysAnchoredAtFlys(bChecked); + break; + + case SvtCompatibilityEntry::Index::EmptyDbFieldHidesPara: + m_pWrtShell->SetEmptyDbFieldHidesPara(bChecked); + break; + + default: + break; + } + bModified = true; + } + + nSavedOptions = nSavedOptions >> 1; + } + } + + if ( bModified ) + WriteOptions(); + + bool bNewMSFormsMenuOption = m_xGlobalOptionsCLB->get_toggle(0); + if (m_bSavedMSFormsMenuOption != bNewMSFormsMenuOption) + { + std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::set(bNewMSFormsMenuOption, batch); + batch->commit(); + + m_bSavedMSFormsMenuOption = bNewMSFormsMenuOption; + bModified = true; + + // Show a message about that the option needs a restart to be applied + { + SolarMutexGuard aGuard; + if (svtools::executeRestartDialog(comphelper::getProcessComponentContext(), + GetFrameWeld(), svtools::RESTART_REASON_MSCOMPATIBLE_FORMS_MENU)) + { + GetDialogController()->response(RET_OK); + } + } + } + + return bModified; +} + +void SwCompatibilityOptPage::Reset( const SfxItemSet* ) +{ + m_xOptionsLB->select(0); + + sal_uInt32 nOptions = GetDocumentOptions(); + SetCurrentOptions( nOptions ); + m_nSavedOptions = nOptions; + + m_bSavedMSFormsMenuOption = officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::get(); + m_xGlobalOptionsCLB->set_toggle(0, m_bSavedMSFormsMenuOption ? TRISTATE_TRUE : TRISTATE_FALSE); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/config/optload.cxx b/sw/source/ui/config/optload.cxx new file mode 100644 index 000000000..af62e10f7 --- /dev/null +++ b/sw/source/ui/config/optload.cxx @@ -0,0 +1,910 @@ +/* -*- 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 . + */ + +#include <officecfg/Office/Writer.hxx> +#include <comphelper/string.hxx> +#include <swtypes.hxx> +#include <uiitems.hxx> +#include <modcfg.hxx> +#include <swmodule.hxx> +#include <usrpref.hxx> +#include <wrtsh.hxx> +#include <linkenum.hxx> +#include <uitool.hxx> +#include <view.hxx> + +#include <strings.hrc> +#include <optload.hrc> +#include <cmdid.h> + +#include <optload.hxx> +#include <sfx2/htmlmode.hxx> +#include <fldmgr.hxx> +#include <poolfmt.hxx> +#include <expfld.hxx> + +#include <svtools/insdlg.hxx> +#include <svtools/unitconv.hxx> +#include <tools/resary.hxx> +#include <vcl/settings.hxx> + +#include <comphelper/classids.hxx> +#include <unotools/configmgr.hxx> +#include <SwStyleNameMapper.hxx> +#include <numrule.hxx> + +#include <doc.hxx> +#include <svl/cjkoptions.hxx> + +using namespace ::com::sun::star; + +#include <svl/eitem.hxx> + +sal_uInt32 SwFieldUnitTable::Count() +{ + return SAL_N_ELEMENTS(STR_ARR_METRIC); +} + +OUString SwFieldUnitTable::GetString(sal_uInt32 nPos) +{ + if (RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count()) + return SwResId(STR_ARR_METRIC[nPos].first); + return OUString(); +} + +FieldUnit SwFieldUnitTable::GetValue(sal_uInt32 nPos) +{ + if (RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count()) + return STR_ARR_METRIC[nPos].second; + return FieldUnit::NONE; +} + +SwLoadOptPage::SwLoadOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optgeneralpage.ui", "OptGeneralPage", &rSet) + , m_pWrtShell(nullptr) + , m_nLastTab(0) + , m_nOldLinkMode(MANUAL) + , m_xAlwaysRB(m_xBuilder->weld_radio_button("always")) + , m_xRequestRB(m_xBuilder->weld_radio_button("onrequest")) + , m_xNeverRB(m_xBuilder->weld_radio_button("never")) + , m_xAutoUpdateFields(m_xBuilder->weld_check_button("updatefields")) + , m_xAutoUpdateCharts(m_xBuilder->weld_check_button("updatecharts")) + , m_xMetricLB(m_xBuilder->weld_combo_box("metric")) + , m_xTabFT(m_xBuilder->weld_label("tablabel")) + , m_xTabMF(m_xBuilder->weld_metric_spin_button("tab", FieldUnit::CM)) + , m_xUseSquaredPageMode(m_xBuilder->weld_check_button("squaremode")) + , m_xUseCharUnit(m_xBuilder->weld_check_button("usecharunit")) + , m_xWordCountED(m_xBuilder->weld_entry("wordcount")) + , m_xShowStandardizedPageCount(m_xBuilder->weld_check_button("standardizedpageshow")) + , m_xStandardizedPageSizeNF(m_xBuilder->weld_spin_button("standardpagesize")) +{ + for (sal_uInt32 i = 0; i < SwFieldUnitTable::Count(); ++i) + { + const OUString sMetric = SwFieldUnitTable::GetString(i); + FieldUnit eFUnit = SwFieldUnitTable::GetValue(i); + + switch ( eFUnit ) + { + case FieldUnit::MM: + case FieldUnit::CM: + case FieldUnit::POINT: + case FieldUnit::PICA: + case FieldUnit::INCH: + { + // use only these metrics + m_xMetricLB->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric); + break; + } + default:; //prevent warning + } + } + m_xMetricLB->connect_changed(LINK(this, SwLoadOptPage, MetricHdl)); + + const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_HTML_MODE, false); + if (pItem && pItem->GetValue() & HTMLMODE_ON) + { + m_xTabFT->hide(); + m_xTabMF->hide(); + } + + if(!SvtCJKOptions::IsAsianTypographyEnabled()) + { + m_xUseSquaredPageMode->hide(); + m_xUseCharUnit->hide(); + } + + m_xShowStandardizedPageCount->connect_toggled(LINK(this, SwLoadOptPage, StandardizedPageCountCheckHdl)); +} + +SwLoadOptPage::~SwLoadOptPage() +{ +} + +std::unique_ptr<SfxTabPage> SwLoadOptPage::Create( weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet ) +{ + return std::make_unique<SwLoadOptPage>(pPage, pController, *rAttrSet ); +} + +IMPL_LINK_NOARG(SwLoadOptPage, StandardizedPageCountCheckHdl, weld::Toggleable&, void) +{ + m_xStandardizedPageSizeNF->set_sensitive(m_xShowStandardizedPageCount->get_active()); +} + +bool SwLoadOptPage::FillItemSet( SfxItemSet* rSet ) +{ + bool bRet = false; + SwModule* pMod = SW_MOD(); + + sal_Int32 nNewLinkMode = AUTOMATIC; + if (m_xNeverRB->get_active()) + nNewLinkMode = NEVER; + else if (m_xRequestRB->get_active()) + nNewLinkMode = MANUAL; + + SwFieldUpdateFlags eFieldFlags = m_xAutoUpdateFields->get_active() ? + m_xAutoUpdateCharts->get_active() ? AUTOUPD_FIELD_AND_CHARTS : AUTOUPD_FIELD_ONLY : AUTOUPD_OFF; + + if (m_xAutoUpdateFields->get_state_changed_from_saved() || + m_xAutoUpdateCharts->get_state_changed_from_saved()) + { + pMod->ApplyFieldUpdateFlags(eFieldFlags); + if(m_pWrtShell) + { + m_pWrtShell->SetFieldUpdateFlags(eFieldFlags); + m_pWrtShell->SetModified(); + } + } + + if (nNewLinkMode != m_nOldLinkMode) + { + pMod->ApplyLinkMode(nNewLinkMode); + if (m_pWrtShell) + { + m_pWrtShell->SetLinkUpdMode( nNewLinkMode ); + m_pWrtShell->SetModified(); + } + + bRet = true; + } + + const sal_Int32 nMPos = m_xMetricLB->get_active(); + if (m_xMetricLB->get_value_changed_from_saved()) + { + // Double-Cast for VA3.0 + const sal_uInt16 nFieldUnit = m_xMetricLB->get_id(nMPos).toUInt32(); + rSet->Put( SfxUInt16Item( SID_ATTR_METRIC, nFieldUnit ) ); + bRet = true; + } + + if (m_xTabMF->get_visible() && m_xTabMF->get_value_changed_from_saved()) + { + rSet->Put(SfxUInt16Item(SID_ATTR_DEFTABSTOP, + o3tl::narrowing<sal_uInt16>(m_xTabMF->denormalize(m_xTabMF->get_value(FieldUnit::TWIP))))); + bRet = true; + } + + bool bIsUseCharUnitFlag = m_xUseCharUnit->get_active(); + bIsUseCharUnitFlag = bIsUseCharUnitFlag && SvtCJKOptions::IsAsianTypographyEnabled(); + if( (bIsUseCharUnitFlag ? 1 : 0) != m_xUseCharUnit->get_saved_state()) + { + rSet->Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, bIsUseCharUnitFlag )); + bRet = true; + } + + if (m_xWordCountED->get_value_changed_from_saved()) + { + std::shared_ptr< comphelper::ConfigurationChanges > batch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::WordCount::AdditionalSeparators::set(m_xWordCountED->get_text(), batch); + batch->commit(); + bRet = true; + } + + if (m_xShowStandardizedPageCount->get_state_changed_from_saved()) + { + std::shared_ptr< comphelper::ConfigurationChanges > batch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::set( + m_xShowStandardizedPageCount->get_active(), + batch); + batch->commit(); + bRet = true; + } + + if (m_xStandardizedPageSizeNF->get_value_changed_from_saved()) + { + std::shared_ptr< comphelper::ConfigurationChanges > batch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::WordCount::StandardizedPageSize::set( + m_xStandardizedPageSizeNF->get_value(), + batch); + batch->commit(); + bRet = true; + } + + if (m_xUseSquaredPageMode->get_state_changed_from_saved()) + { + bool bIsSquaredPageModeFlag = m_xUseSquaredPageMode->get_active(); + pMod->ApplyDefaultPageMode( bIsSquaredPageModeFlag ); + if ( m_pWrtShell ) + { + SwDoc* pDoc = m_pWrtShell->GetDoc(); + pDoc->SetDefaultPageMode( bIsSquaredPageModeFlag ); + m_pWrtShell->SetModified(); + } + bRet = true; + } + + return bRet; +} + +void SwLoadOptPage::Reset( const SfxItemSet* rSet) +{ + const SwMasterUsrPref* pUsrPref = SW_MOD()->GetUsrPref(false); + const SwPtrItem* pShellItem = rSet->GetItemIfSet(FN_PARAM_WRTSHELL, false); + + if(pShellItem) + m_pWrtShell = static_cast<SwWrtShell*>(pShellItem->GetValue()); + + SwFieldUpdateFlags eFieldFlags = AUTOUPD_GLOBALSETTING; + m_nOldLinkMode = GLOBALSETTING; + if (m_pWrtShell) + { + eFieldFlags = m_pWrtShell->GetFieldUpdateFlags(); + m_nOldLinkMode = m_pWrtShell->GetLinkUpdMode(); + } + if(GLOBALSETTING == m_nOldLinkMode) + m_nOldLinkMode = pUsrPref->GetUpdateLinkMode(); + if(AUTOUPD_GLOBALSETTING == eFieldFlags) + eFieldFlags = pUsrPref->GetFieldUpdateFlags(); + + m_xAutoUpdateFields->set_active(eFieldFlags != AUTOUPD_OFF); + m_xAutoUpdateCharts->set_active(eFieldFlags == AUTOUPD_FIELD_AND_CHARTS); + + switch (m_nOldLinkMode) + { + case NEVER: m_xNeverRB->set_active(true); break; + case MANUAL: m_xRequestRB->set_active(true); break; + case AUTOMATIC: m_xAlwaysRB->set_active(true); break; + } + + m_xAutoUpdateFields->save_state(); + m_xAutoUpdateCharts->save_state(); + m_xMetricLB->set_active(-1); + if ( rSet->GetItemState( SID_ATTR_METRIC ) >= SfxItemState::DEFAULT ) + { + const SfxUInt16Item& rItem = rSet->Get( SID_ATTR_METRIC ); + FieldUnit eFieldUnit = static_cast<FieldUnit>(rItem.GetValue()); + + for (sal_Int32 i = 0, nEntryCount = m_xMetricLB->get_count(); i < nEntryCount; ++i) + { + if (m_xMetricLB->get_id(i).toUInt32() == static_cast<sal_uInt32>(eFieldUnit)) + { + m_xMetricLB->set_active(i); + break; + } + } + ::SetFieldUnit(*m_xTabMF, eFieldUnit); + } + m_xMetricLB->save_value(); + if(const SfxUInt16Item* pItem = rSet->GetItemIfSet(SID_ATTR_DEFTABSTOP, false)) + { + m_nLastTab = pItem->GetValue(); + m_xTabMF->set_value(m_xTabMF->normalize(m_nLastTab), FieldUnit::TWIP); + } + m_xTabMF->save_value(); + + //default page mode loading + if(m_pWrtShell) + { + bool bSquaredPageMode = m_pWrtShell->GetDoc()->IsSquaredPageMode(); + m_xUseSquaredPageMode->set_active( bSquaredPageMode ); + m_xUseSquaredPageMode->save_state(); + } + + if(const SfxBoolItem* pItem = rSet->GetItemIfSet(SID_ATTR_APPLYCHARUNIT, false)) + { + bool bUseCharUnit = pItem->GetValue(); + m_xUseCharUnit->set_active(bUseCharUnit); + } + else + { + m_xUseCharUnit->set_active(pUsrPref->IsApplyCharUnit()); + } + m_xUseCharUnit->save_state(); + + m_xWordCountED->set_text(officecfg::Office::Writer::WordCount::AdditionalSeparators::get()); + m_xWordCountED->set_sensitive(!officecfg::Office::Writer::WordCount::AdditionalSeparators::isReadOnly()); + m_xWordCountED->save_value(); + m_xShowStandardizedPageCount->set_active(officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::get()); + m_xShowStandardizedPageCount->set_sensitive(!officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::isReadOnly()); + m_xShowStandardizedPageCount->save_state(); + m_xStandardizedPageSizeNF->set_value(officecfg::Office::Writer::WordCount::StandardizedPageSize::get()); + m_xStandardizedPageSizeNF->set_sensitive(!officecfg::Office::Writer::WordCount::StandardizedPageSize::isReadOnly()); + m_xStandardizedPageSizeNF->save_value(); + m_xStandardizedPageSizeNF->set_sensitive(m_xShowStandardizedPageCount->get_active()); +} + +IMPL_LINK_NOARG(SwLoadOptPage, MetricHdl, weld::ComboBox&, void) +{ + const sal_Int32 nMPos = m_xMetricLB->get_active(); + 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(); + tools::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) + : SfxSingleTabDialogController(pParent, &rSet, "modules/swriter/ui/captiondialog.ui", + "CaptionDialog") +{ + // create TabPage + SetTabPage(SwCaptionOptPage::Create(get_content_area(), this, &rSet)); +} + +SwCaptionPreview::SwCaptionPreview() + : mbFontInitialized(false) +{ +} + +void SwCaptionPreview::ApplySettings(vcl::RenderContext& rRenderContext) +{ + const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings(); + Wallpaper aBack(rSettings.GetWindowColor()); + rRenderContext.SetBackground(aBack); + rRenderContext.SetFillColor(aBack.GetColor()); + rRenderContext.SetLineColor(aBack.GetColor()); + rRenderContext.SetTextColor(rSettings.GetWindowTextColor()); + + if (!mbFontInitialized) + { + maFont = rRenderContext.GetFont(); + maFont.SetFontHeight(maFont.GetFontHeight() * 120 / 100); + mbFontInitialized = true; + } + rRenderContext.SetFont(maFont); +} + +void SwCaptionPreview::SetPreviewText(const OUString& rText) +{ + if (rText != maText) + { + maText = rText; + Invalidate(); + } +} + +void SwCaptionPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea) +{ + CustomWidgetController::SetDrawingArea(pDrawingArea); + Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(106 , 20), MapMode(MapUnit::MapAppFont))); + pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); +} + +void SwCaptionPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) +{ + ApplySettings(rRenderContext); + + rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel())); + rRenderContext.DrawText(Point(4, 6), maText); +} + +IMPL_LINK(SwCaptionOptPage, TextFilterHdl, OUString&, rTest, bool) +{ + rTest = m_aTextFilter.filter(rTest); + return true; +} + +SwCaptionOptPage::SwCaptionOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optcaptionpage.ui", "OptCaptionPage", &rSet) + , m_sSWTable(SwResId(STR_CAPTION_TABLE)) + , m_sSWFrame(SwResId(STR_CAPTION_FRAME)) + , m_sSWGraphic(SwResId(STR_CAPTION_GRAPHIC)) + , m_sOLE(SwResId(STR_CAPTION_OLE)) + , m_sBegin(SwResId(STR_CAPTION_BEGINNING)) + , m_sEnd(SwResId(STR_CAPTION_END)) + , m_sAbove(SwResId(STR_CAPTION_ABOVE)) + , m_sBelow(SwResId(STR_CAPTION_BELOW)) + , m_sNone(SwResId(SW_STR_NONE)) + , m_nPrevSelectedEntry(-1) + , pMgr(new SwFieldMgr) + , bHTMLMode(false) + , m_aTextFilter(m_sNone) + , m_xCheckLB(m_xBuilder->weld_tree_view("objects")) + , m_xLbCaptionOrder(m_xBuilder->weld_combo_box("captionorder")) + , m_xSettingsGroup(m_xBuilder->weld_widget("settings")) + , m_xCategoryBox(m_xBuilder->weld_combo_box("category")) + , m_xFormatText(m_xBuilder->weld_label("numberingft")) + , m_xFormatBox(m_xBuilder->weld_combo_box("numbering")) + , m_xNumberingSeparatorFT(m_xBuilder->weld_label("numseparatorft")) + , m_xNumberingSeparatorED(m_xBuilder->weld_entry("numseparator")) + , m_xTextText(m_xBuilder->weld_label("separatorft")) + , m_xTextEdit(m_xBuilder->weld_entry("separator")) + , m_xPosBox(m_xBuilder->weld_combo_box("position")) + , m_xNumCapt(m_xBuilder->weld_widget("numcaption")) + , m_xLbLevel(m_xBuilder->weld_combo_box("level")) + , m_xEdDelim(m_xBuilder->weld_entry("chapseparator")) + , m_xCategory(m_xBuilder->weld_widget("categoryformat")) + , m_xCharStyleLB(m_xBuilder->weld_combo_box("charstyle")) + , m_xApplyBorderCB(m_xBuilder->weld_check_button("applyborder")) + , m_xPreview(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreview)) +{ + m_xCategoryBox->connect_entry_insert_text(LINK(this, SwCaptionOptPage, TextFilterHdl)); + + m_xCheckLB->enable_toggle_buttons(weld::ColumnToggleType::Check); + + SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_ABB, m_sIllustration); + SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_TABLE, m_sTable); + SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_FRAME, m_sText); + SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_DRAWING, m_sDrawing); + + + // m_xFormatBox + sal_uInt16 nSelFormat = SVX_NUM_ARABIC; + SwWrtShell* pSh = ::GetActiveWrtShell(); + + if (pSh) + { + for ( auto i = pMgr->GetFieldTypeCount(); i; ) + { + SwFieldType* pFieldType = pMgr->GetFieldType(SwFieldIds::Unknown, --i); + if (!pFieldType->GetName().isEmpty() + && pFieldType->GetName() == m_xCategoryBox->get_active_text()) + { + nSelFormat = o3tl::narrowing<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat()); + break; + } + } + + ::FillCharStyleListBox( *m_xCharStyleLB, pSh->GetView().GetDocShell(), true, true ); + } + + const sal_uInt16 nCount = pMgr->GetFormatCount(SwFieldTypesEnum::Sequence, false); + for ( sal_uInt16 i = 0; i < nCount; ++i ) + { + const sal_uInt16 nFormatId = pMgr->GetFormatId(SwFieldTypesEnum::Sequence, i); + m_xFormatBox->append(OUString::number(nFormatId), pMgr->GetFormatStr(SwFieldTypesEnum::Sequence, i)); + if (nFormatId == nSelFormat) + m_xFormatBox->set_active(i); + } + + for (int i = 0; i < MAXLEVEL; ++i) + m_xLbLevel->append_text(OUString::number(i + 1)); + + sal_Unicode nLvl = MAXLEVEL; + OUString sDelim(": "); + + if (pSh) + { + SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(pMgr->GetFieldType( + SwFieldIds::SetExp, m_xCategoryBox->get_active_text() )); + if( pFieldType ) + { + sDelim = pFieldType->GetDelimiter(); + nLvl = pFieldType->GetOutlineLvl(); + } + } + + m_xLbLevel->set_active(nLvl < MAXLEVEL ? nLvl + 1 : 0); + m_xEdDelim->set_text(sDelim); + + m_xCategoryBox->connect_changed(LINK(this, SwCaptionOptPage, ModifyComboHdl)); + Link<weld::Entry&,void> aLk = LINK(this, SwCaptionOptPage, ModifyEntryHdl); + m_xNumberingSeparatorED->connect_changed(aLk); + m_xTextEdit->connect_changed(aLk); + + m_xCategoryBox->connect_changed(LINK(this, SwCaptionOptPage, SelectHdl)); + m_xFormatBox->connect_changed(LINK(this, SwCaptionOptPage, SelectListBoxHdl)); + + m_xLbCaptionOrder->connect_changed(LINK(this, SwCaptionOptPage, OrderHdl)); + + m_xCheckLB->connect_changed(LINK(this, SwCaptionOptPage, ShowEntryHdl)); + m_xCheckLB->connect_toggled(LINK(this, SwCaptionOptPage, ToggleEntryHdl)); +} + +SwCaptionOptPage::~SwCaptionOptPage() +{ + DelUserData(); + pMgr.reset(); + m_xPreview.reset(); +} + +std::unique_ptr<SfxTabPage> SwCaptionOptPage::Create(weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet) +{ + return std::make_unique<SwCaptionOptPage>(pPage, pController, *rAttrSet); +} + +bool SwCaptionOptPage::FillItemSet( SfxItemSet* ) +{ + bool bRet = false; + SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); + + SaveEntry(m_xCheckLB->get_selected_index()); // apply current entry + + int nCheckCount = 0; + for (int i = 0, nCount = m_xCheckLB->n_children(); i < nCount; ++i) + { + if (m_xCheckLB->get_toggle(i) == TRISTATE_TRUE) + ++nCheckCount; + InsCaptionOpt* pData = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(i)); + bRet |= pModOpt->SetCapOption(bHTMLMode, pData); + } + + pModOpt->SetInsWithCaption(bHTMLMode, nCheckCount > 0); + + int nPos = m_xLbCaptionOrder->get_active(); + pModOpt->SetCaptionOrderNumberingFirst(nPos == 1); + + return bRet; +} + +void SwCaptionOptPage::Reset( const SfxItemSet* rSet) +{ + if(const SfxUInt16Item* pItem = rSet->GetItemIfSet(SID_HTML_MODE, false)) + { + bHTMLMode = 0 != (pItem->GetValue() & HTMLMODE_ON); + } + + DelUserData(); + m_xCheckLB->clear(); // remove all entries + + // Writer objects + int nPos = 0; + m_xCheckLB->append(); + m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE); + m_xCheckLB->set_text(nPos, m_sSWTable, 0); + SetOptions(nPos++, TABLE_CAP); + m_xCheckLB->append(); + m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE); + m_xCheckLB->set_text(nPos, m_sSWFrame, 0); + SetOptions(nPos++, FRAME_CAP); + m_xCheckLB->append(); + m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE); + m_xCheckLB->set_text(nPos, m_sSWGraphic, 0); + SetOptions(nPos++, GRAPHIC_CAP); + + // get Productname and -version + const OUString sWithoutVersion( utl::ConfigManager::getProductName() ); + const OUString sComplete( + sWithoutVersion + " " + + utl::ConfigManager::getProductVersion() ); + + SvObjectServerList aObjS; + aObjS.FillInsertObjects(); + aObjS.Remove( SvGlobalName( SO3_SW_CLASSID ) ); // remove Writer-ID + + for ( sal_uLong i = 0; i < aObjS.Count(); ++i ) + { + const SvGlobalName &rOleId = aObjS[i].GetClassName(); + OUString sClass; + if (rOleId == SvGlobalName(SO3_OUT_CLASSID)) + sClass = m_sOLE; + else + sClass = aObjS[i].GetHumanName(); + // don't show product version + sClass = sClass.replaceFirst( sComplete, sWithoutVersion ); + m_xCheckLB->append(); + m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE); + m_xCheckLB->set_text(nPos, sClass, 0); + SetOptions( nPos++, OLE_CAP, &rOleId ); + } + m_xLbCaptionOrder->set_active( + SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst() ? 1 : 0); + m_xCheckLB->select(0); + ShowEntryHdl(*m_xCheckLB); +} + +void SwCaptionOptPage::SetOptions(const sal_uLong nPos, + const SwCapObjType eObjType, const SvGlobalName *pOleId) +{ + SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); + const InsCaptionOpt* pOpt = pModOpt->GetCapOption(bHTMLMode, eObjType, pOleId); + + if (pOpt) + { + InsCaptionOpt* pIns = new InsCaptionOpt(*pOpt); + m_xCheckLB->set_id(nPos, weld::toId(pIns)); + m_xCheckLB->set_toggle(nPos, pOpt->UseCaption() ? TRISTATE_TRUE : TRISTATE_FALSE); + } + else + { + InsCaptionOpt* pIns = new InsCaptionOpt(eObjType, pOleId); + m_xCheckLB->set_id(nPos, weld::toId(pIns)); + } +} + +void SwCaptionOptPage::DelUserData() +{ + for (int i = 0, nCount = m_xCheckLB->n_children(); i < nCount; ++i) + { + delete weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(i)); + m_xCheckLB->set_id(i, "0"); + } +} + +void SwCaptionOptPage::UpdateEntry(int nSelEntry) +{ + if (nSelEntry != -1) + { + bool bChecked = m_xCheckLB->get_toggle(nSelEntry) == TRISTATE_TRUE; + + m_xSettingsGroup->set_sensitive(bChecked); + bool bNumSep = bChecked && m_xLbCaptionOrder->get_active() == 1; + m_xNumberingSeparatorED->set_sensitive( bNumSep ); + m_xNumberingSeparatorFT->set_sensitive( bNumSep ); + + m_xNumCapt->set_sensitive(bChecked); + m_xCategory->set_sensitive(bChecked); + m_xPreview->set_sensitive(bChecked); + + + InsCaptionOpt* pOpt = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(nSelEntry)); + + m_xCategoryBox->clear(); + m_xCategoryBox->append_text(m_sNone); + if (::GetActiveWrtShell()) + { + const size_t nCount = pMgr->GetFieldTypeCount(); + + for (size_t i = 0; i < nCount; ++i) + { + SwFieldType *pType = pMgr->GetFieldType( SwFieldIds::Unknown, i ); + if( pType->Which() == SwFieldIds::SetExp && + static_cast<SwSetExpFieldType *>( pType)->GetType() & nsSwGetSetExpType::GSE_SEQ ) + { + m_xCategoryBox->append_text(pType->GetName()); + } + } + } + else + { + m_xCategoryBox->append_text(m_sIllustration); + m_xCategoryBox->append_text(m_sTable); + m_xCategoryBox->append_text(m_sText); + m_xCategoryBox->append_text(m_sDrawing); + } + + if (!pOpt->GetCategory().isEmpty()) + { + if (m_xCategoryBox->find_text(pOpt->GetCategory()) == -1) + m_xCategoryBox->insert_text(0, pOpt->GetCategory()); + m_xCategoryBox->set_active_text(pOpt->GetCategory()); + } + else + m_xCategoryBox->set_active_text(m_sNone); + + if (m_xCategoryBox->get_active_text().isEmpty()) + { + sal_Int32 nPos = 0; + switch(pOpt->GetObjType()) + { + case OLE_CAP: + case GRAPHIC_CAP: nPos = 1; break; + case TABLE_CAP: nPos = 2; break; + case FRAME_CAP: nPos = 3; break; + } + m_xCategoryBox->set_active(nPos); + } + + for (sal_Int32 i = 0; i < m_xFormatBox->get_count(); i++) + { + if (pOpt->GetNumType() == m_xFormatBox->get_id(i).toUInt32()) + { + m_xFormatBox->set_active(i); + break; + } + } + m_xTextEdit->set_text(pOpt->GetCaption()); + + m_xPosBox->clear(); + switch (pOpt->GetObjType()) + { + case GRAPHIC_CAP: + case TABLE_CAP: + case OLE_CAP: + m_xPosBox->append_text(m_sAbove); + m_xPosBox->append_text(m_sBelow); + break; + case FRAME_CAP: + m_xPosBox->append_text(m_sBegin); + m_xPosBox->append_text(m_sEnd); + break; + } + m_xPosBox->set_active(pOpt->GetPos()); + + sal_Int32 nLevelPos = ( pOpt->GetLevel() < MAXLEVEL ) ? pOpt->GetLevel() + 1 : 0; + m_xLbLevel->set_active(nLevelPos); + m_xEdDelim->set_text(pOpt->GetSeparator()); + m_xNumberingSeparatorED->set_text(pOpt->GetNumSeparator()); + if (!pOpt->GetCharacterStyle().isEmpty()) + m_xCharStyleLB->set_active_text(pOpt->GetCharacterStyle()); + else + m_xCharStyleLB->set_active(0); + m_xApplyBorderCB->set_sensitive(m_xCategoryBox->get_sensitive() && + pOpt->GetObjType() != TABLE_CAP && pOpt->GetObjType() != FRAME_CAP ); + m_xApplyBorderCB->set_active(pOpt->CopyAttributes()); + } + + ModifyHdl(); +} + +IMPL_LINK_NOARG(SwCaptionOptPage, ShowEntryHdl, weld::TreeView&, void) +{ + if (m_nPrevSelectedEntry != -1) + SaveEntry(m_nPrevSelectedEntry); + UpdateEntry(m_xCheckLB->get_selected_index()); + m_nPrevSelectedEntry = m_xCheckLB->get_selected_index(); +} + +IMPL_LINK(SwCaptionOptPage, ToggleEntryHdl, const weld::TreeView::iter_col&, rRowCol, void) +{ + UpdateEntry(m_xCheckLB->get_iter_index_in_parent(rRowCol.first)); +} + +void SwCaptionOptPage::SaveEntry(int nEntry) +{ + if (nEntry == -1) + return; + + InsCaptionOpt* pOpt = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(nEntry)); + + pOpt->UseCaption() = m_xCheckLB->get_toggle(nEntry) == TRISTATE_TRUE; + const OUString aName(m_xCategoryBox->get_active_text()); + if (aName == m_sNone) + pOpt->SetCategory(""); + else + pOpt->SetCategory(comphelper::string::strip(aName, ' ')); + pOpt->SetNumType(m_xFormatBox->get_active_id().toUInt32()); + pOpt->SetCaption(m_xTextEdit->get_sensitive() ? m_xTextEdit->get_text() : OUString() ); + pOpt->SetPos(m_xPosBox->get_active()); + int nPos = m_xLbLevel->get_active(); + sal_Int32 nLevel = (nPos > 0) ? nPos - 1 : MAXLEVEL; + pOpt->SetLevel(nLevel); + pOpt->SetSeparator(m_xEdDelim->get_text()); + pOpt->SetNumSeparator(m_xNumberingSeparatorED->get_text()); + if (m_xCharStyleLB->get_active() == -1) + pOpt->SetCharacterStyle(""); + else + pOpt->SetCharacterStyle(m_xCharStyleLB->get_active_text()); + pOpt->CopyAttributes() = m_xApplyBorderCB->get_active(); +} + +void SwCaptionOptPage::ModifyHdl() +{ + const OUString sFieldTypeName = m_xCategoryBox->get_active_text(); + + if (SfxSingleTabDialogController* pDlg = dynamic_cast<SfxSingleTabDialogController*>(GetDialogController())) + pDlg->GetOKButton().set_sensitive(!sFieldTypeName.isEmpty()); + bool bEnable = m_xCategoryBox->get_sensitive() && sFieldTypeName != m_sNone; + + m_xFormatText->set_sensitive(bEnable); + m_xFormatBox->set_sensitive(bEnable); + m_xTextText->set_sensitive(bEnable); + m_xTextEdit->set_sensitive(bEnable); + + InvalidatePreview(); +} + +IMPL_LINK_NOARG(SwCaptionOptPage, ModifyEntryHdl, weld::Entry&, void) +{ + ModifyHdl(); +} + +IMPL_LINK_NOARG(SwCaptionOptPage, ModifyComboHdl, weld::ComboBox&, void) +{ + ModifyHdl(); +} + +IMPL_LINK_NOARG(SwCaptionOptPage, SelectHdl, weld::ComboBox&, void) +{ + InvalidatePreview(); +} + +IMPL_LINK_NOARG(SwCaptionOptPage, SelectListBoxHdl, weld::ComboBox&, void) +{ + InvalidatePreview(); +} + +IMPL_LINK(SwCaptionOptPage, OrderHdl, weld::ComboBox&, rBox, void) +{ + InvalidatePreview(); + + int nSelEntry = m_xCheckLB->get_selected_index(); + bool bChecked = false; + if (nSelEntry != -1) + { + bChecked = m_xCheckLB->get_toggle(nSelEntry) == TRISTATE_TRUE; + } + + int nPos = rBox.get_active(); + m_xNumberingSeparatorFT->set_sensitive(bChecked && nPos == 1); + m_xNumberingSeparatorED->set_sensitive(bChecked && nPos == 1); +} + +void SwCaptionOptPage::InvalidatePreview() +{ + OUString aStr; + + if (m_xCategoryBox->get_active_text() != m_sNone) + { + //#i61007# order of captions + bool bOrderNumberingFirst = m_xLbCaptionOrder->get_active() == 1; + // number + const sal_uInt16 nNumFormat = m_xFormatBox->get_active_id().toUInt32(); + if (SVX_NUM_NUMBER_NONE != nNumFormat) + { + //#i61007# order of captions + if( !bOrderNumberingFirst ) + { + // category + aStr += m_xCategoryBox->get_active_text() + " "; + } + + if (SwWrtShell *pSh = ::GetActiveWrtShell()) + { + SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(pMgr->GetFieldType( + SwFieldIds::SetExp, m_xCategoryBox->get_active_text() )); + if( pFieldType && pFieldType->GetOutlineLvl() < MAXLEVEL ) + { + sal_uInt8 nLvl = pFieldType->GetOutlineLvl(); + SwNumberTree::tNumberVector aNumVector; + for( sal_uInt8 i = 0; i <= nLvl; ++i ) + aNumVector.push_back(1); + + const OUString sNumber( pSh->GetOutlineNumRule()->MakeNumString( + aNumVector, false )); + if( !sNumber.isEmpty() ) + aStr += sNumber + pFieldType->GetDelimiter(); + } + } + + switch( nNumFormat ) + { + case SVX_NUM_CHARS_UPPER_LETTER: aStr += "A"; break; + case SVX_NUM_CHARS_UPPER_LETTER_N: aStr += "A"; break; + case SVX_NUM_CHARS_LOWER_LETTER: aStr += "a"; break; + case SVX_NUM_CHARS_LOWER_LETTER_N: aStr += "a"; break; + case SVX_NUM_ROMAN_UPPER: aStr += "I"; break; + case SVX_NUM_ROMAN_LOWER: aStr += "i"; break; + //case ARABIC: + default: aStr += "1"; break; + } + } + //#i61007# order of captions + if( bOrderNumberingFirst ) + { + aStr += m_xNumberingSeparatorED->get_text() + m_xCategoryBox->get_active_text(); + } + aStr += m_xTextEdit->get_text(); + } + m_aPreview.SetPreviewText(aStr); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/config/optpage.cxx b/sw/source/ui/config/optpage.cxx new file mode 100644 index 000000000..4374751f0 --- /dev/null +++ b/sw/source/ui/config/optpage.cxx @@ -0,0 +1,2194 @@ +/* -*- 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 . + */ + +#include <sal/config.h> + +#include <utility> + +#include <optpage.hxx> +#include <doc.hxx> +#include <hintids.hxx> +#include <cmdid.h> +#include <fmtcol.hxx> +#include <charatr.hxx> +#include <swtypes.hxx> +#include <view.hxx> +#include <docsh.hxx> +#include <IDocumentDeviceAccess.hxx> +#include <IDocumentSettingAccess.hxx> + +#include <swmodule.hxx> +#include <wrtsh.hxx> +#include <cfgitems.hxx> +#include <poolfmt.hxx> +#include <uiitems.hxx> +#include <printdata.hxx> +#include <modcfg.hxx> +#include <crstate.hxx> +#include <viewopt.hxx> +#include <globals.hrc> +#include <strings.hrc> +#include <swwrtshitem.hxx> + +#include <editeng/fhgtitem.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/langitem.hxx> +#include <editeng/svxenum.hxx> +#include <officecfg/Office/Common.hxx> +#include <sal/macros.h> +#include <sfx2/dialoghelper.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/viewfrm.hxx> +#include <svl/ctloptions.hxx> +#include <svl/eitem.hxx> +#include <svl/cjkoptions.hxx> +#include <svtools/ctrltool.hxx> +#include <svtools/unitconv.hxx> +#include <sfx2/htmlmode.hxx> + +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> + +#include <optload.hxx> + +using namespace ::com::sun::star; + +namespace { + +void drawRect(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, const Color &rFillColor, const Color &rLineColor) +{ + rRenderContext.SetFillColor(rFillColor); + rRenderContext.SetLineColor(rLineColor); + rRenderContext.DrawRect(rRect); +} + +} + +// Tools->Options->Writer->View +// Tools->Options->Writer/Web->View +SwContentOptPage::SwContentOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/viewoptionspage.ui", "ViewOptionsPage", &rCoreSet) + , m_xCrossCB(m_xBuilder->weld_check_button("helplines")) + , m_xHMetric(m_xBuilder->weld_combo_box("hrulercombobox")) + , m_xVRulerCBox(m_xBuilder->weld_check_button("vruler")) + , m_xVRulerRightCBox(m_xBuilder->weld_check_button("vrulerright")) + , m_xVMetric(m_xBuilder->weld_combo_box("vrulercombobox")) + , m_xSmoothCBox(m_xBuilder->weld_check_button("smoothscroll")) + , m_xGrfCB(m_xBuilder->weld_check_button("graphics")) + , m_xTableCB(m_xBuilder->weld_check_button("tables")) + , m_xDrwCB(m_xBuilder->weld_check_button("drawings")) + , m_xPostItCB(m_xBuilder->weld_check_button("comments")) + , m_xSettingsFrame(m_xBuilder->weld_frame("settingsframe")) + , m_xSettingsLabel(m_xBuilder->weld_label("settingslabel")) + , m_xMetricLabel(m_xBuilder->weld_label("measureunitlabel")) + , m_xMetricLB(m_xBuilder->weld_combo_box("measureunit")) + , m_xShowInlineTooltips(m_xBuilder->weld_check_button("changestooltip")) + , m_xOutlineLabel(m_xBuilder->weld_label("outlinelabel")) + , m_xShowOutlineContentVisibilityButton(m_xBuilder->weld_check_button("outlinecontentvisibilitybutton")) + , m_xTreatSubOutlineLevelsAsContent(m_xBuilder->weld_check_button("suboutlinelevelsascontent")) + , m_xShowChangesInMargin(m_xBuilder->weld_check_button("changesinmargin")) + , m_xFieldHiddenCB(m_xBuilder->weld_check_button("hiddentextfield")) + , m_xFieldHiddenParaCB(m_xBuilder->weld_check_button("hiddenparafield")) +{ + m_xShowOutlineContentVisibilityButton->connect_toggled(LINK(this, SwContentOptPage, ShowOutlineContentVisibilityButtonHdl)); + + /* This part is visible only with Writer/Web->View dialogue. */ + const SfxUInt16Item* pItem = rCoreSet.GetItemIfSet(SID_HTML_MODE, false ); + if (!pItem || !(pItem->GetValue() & HTMLMODE_ON)) + { + m_xSettingsFrame->hide(); + m_xSettingsLabel->hide(); + m_xMetricLabel->hide(); + m_xMetricLB->hide(); + } + + if(!SvtCJKOptions::IsVerticalTextEnabled() ) + m_xVRulerRightCBox->hide(); + m_xVRulerCBox->connect_toggled(LINK(this, SwContentOptPage, VertRulerHdl )); + + for (size_t i = 0; i < SwFieldUnitTable::Count(); ++i) + { + const OUString sMetric = SwFieldUnitTable::GetString(i); + FieldUnit eFUnit = SwFieldUnitTable::GetValue(i); + + switch ( eFUnit ) + { + case FieldUnit::MM: + case FieldUnit::CM: + case FieldUnit::POINT: + case FieldUnit::PICA: + case FieldUnit::INCH: + case FieldUnit::CHAR: // add two units , 'character' and 'line' , their ticks are not fixed + case FieldUnit::LINE: + { + // only use these metrics + // a horizontal ruler has not the 'line' unit + // there isn't 'line' unit in HTML format + if (eFUnit != FieldUnit::LINE) + { + m_xMetricLB->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric); + m_xHMetric->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric); + } + // a vertical ruler has not the 'character' unit + if (eFUnit != FieldUnit::CHAR) + { + m_xVMetric->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric); + } + break; + } + default:;//prevent warning + } + } +} + +SwContentOptPage::~SwContentOptPage() +{ +} + +std::unique_ptr<SfxTabPage> SwContentOptPage::Create( weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet) +{ + return std::make_unique<SwContentOptPage>(pPage, pController, *rAttrSet); +} + +static void lcl_SelectMetricLB(weld::ComboBox& rMetric, TypedWhichId<SfxUInt16Item> nSID, const SfxItemSet& rSet) +{ + const SfxPoolItem* pItem; + if( rSet.GetItemState( nSID, false, &pItem ) >= SfxItemState::DEFAULT ) + { + FieldUnit eFieldUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); + for (sal_Int32 i = 0, nEntryCount = rMetric.get_count(); i < nEntryCount; ++i) + { + if (rMetric.get_id(i).toUInt32() == static_cast<sal_uInt32>(eFieldUnit)) + { + rMetric.set_active(i); + break; + } + } + } + rMetric.save_value(); +} + +void SwContentOptPage::Reset(const SfxItemSet* rSet) +{ + const SwElemItem* pElemAttr = rSet->GetItemIfSet( FN_PARAM_ELEM , false ); + if(pElemAttr) + { + m_xTableCB->set_active(pElemAttr->m_bTable); + m_xGrfCB->set_active(pElemAttr->m_bGraphic); + m_xDrwCB->set_active(pElemAttr->m_bDrawing); + m_xPostItCB->set_active(pElemAttr->m_bNotes); + m_xCrossCB->set_active(pElemAttr->m_bCrosshair); + m_xVRulerCBox->set_active(pElemAttr->m_bVertRuler); + m_xVRulerRightCBox->set_active(pElemAttr->m_bVertRulerRight); + m_xSmoothCBox->set_active(pElemAttr->m_bSmoothScroll); + m_xShowInlineTooltips->set_active(pElemAttr->m_bShowInlineTooltips); + m_xShowOutlineContentVisibilityButton->set_active(pElemAttr->m_bShowOutlineContentVisibilityButton); + m_xTreatSubOutlineLevelsAsContent->set_active(pElemAttr->m_bTreatSubOutlineLevelsAsContent); + m_xTreatSubOutlineLevelsAsContent->set_sensitive(pElemAttr->m_bShowOutlineContentVisibilityButton); + m_xShowChangesInMargin->set_active(pElemAttr->m_bShowChangesInMargin); + m_xFieldHiddenCB->set_active( pElemAttr->m_bFieldHiddenText ); + m_xFieldHiddenParaCB->set_active( pElemAttr->m_bShowHiddenPara ); + } + m_xMetricLB->set_active(-1); + lcl_SelectMetricLB(*m_xMetricLB, SID_ATTR_METRIC, *rSet); + lcl_SelectMetricLB(*m_xHMetric, FN_HSCROLL_METRIC, *rSet); + lcl_SelectMetricLB(*m_xVMetric, FN_VSCROLL_METRIC, *rSet); +} + +bool SwContentOptPage::FillItemSet(SfxItemSet* rSet) +{ + const SwElemItem* pOldAttr = GetOldItem(GetItemSet(), FN_PARAM_ELEM); + + SwElemItem aElem; + aElem.m_bTable = m_xTableCB->get_active(); + aElem.m_bGraphic = m_xGrfCB->get_active(); + aElem.m_bDrawing = m_xDrwCB->get_active(); + aElem.m_bNotes = m_xPostItCB->get_active(); + aElem.m_bCrosshair = m_xCrossCB->get_active(); + aElem.m_bVertRuler = m_xVRulerCBox->get_active(); + aElem.m_bVertRulerRight = m_xVRulerRightCBox->get_active(); + aElem.m_bSmoothScroll = m_xSmoothCBox->get_active(); + aElem.m_bShowInlineTooltips = m_xShowInlineTooltips->get_active(); + aElem.m_bShowOutlineContentVisibilityButton = m_xShowOutlineContentVisibilityButton->get_active(); + aElem.m_bTreatSubOutlineLevelsAsContent = m_xTreatSubOutlineLevelsAsContent->get_active(); + aElem.m_bShowChangesInMargin = m_xShowChangesInMargin->get_active(); + aElem.m_bFieldHiddenText = m_xFieldHiddenCB->get_active(); + aElem.m_bShowHiddenPara = m_xFieldHiddenParaCB->get_active(); + + bool bRet = !pOldAttr || aElem != *pOldAttr; + if(bRet) + bRet = nullptr != rSet->Put(aElem); + + sal_Int32 nMPos = m_xMetricLB->get_active(); + sal_Int32 nGlobalMetricPos = nMPos; + if ( m_xMetricLB->get_value_changed_from_saved() ) + { + const sal_uInt16 nFieldUnit = m_xMetricLB->get_id(nMPos).toUInt32(); + rSet->Put( SfxUInt16Item( SID_ATTR_METRIC, nFieldUnit ) ); + bRet = true; + } + + nMPos = m_xHMetric->get_active(); + if ( m_xHMetric->get_value_changed_from_saved() || nMPos != nGlobalMetricPos ) + { + const sal_uInt16 nFieldUnit = m_xHMetric->get_id(nMPos).toUInt32(); + rSet->Put( SfxUInt16Item( FN_HSCROLL_METRIC, nFieldUnit ) ); + bRet = true; + } + nMPos = m_xVMetric->get_active(); + if ( m_xVMetric->get_value_changed_from_saved() || nMPos != nGlobalMetricPos ) + { + const sal_uInt16 nFieldUnit = m_xVMetric->get_id(nMPos).toUInt32(); + rSet->Put( SfxUInt16Item( FN_VSCROLL_METRIC, nFieldUnit ) ); + bRet = true; + } + + return bRet; +} + +IMPL_LINK(SwContentOptPage, VertRulerHdl, weld::Toggleable&, rBox, void) +{ + m_xVRulerRightCBox->set_sensitive(rBox.get_sensitive() && rBox.get_active()); +} + +IMPL_LINK(SwContentOptPage, ShowOutlineContentVisibilityButtonHdl, weld::Toggleable&, rBox, void) +{ + m_xTreatSubOutlineLevelsAsContent->set_sensitive(rBox.get_active()); +} + +// TabPage Printer additional settings +SwAddPrinterTabPage::SwAddPrinterTabPage(weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet& rCoreSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/printoptionspage.ui", "PrintOptionsPage", &rCoreSet) + , sNone(SwResId(SW_STR_NONE)) + , bAttrModified(false) + , bPreview(false) + , m_xGrfCB(m_xBuilder->weld_check_button("graphics")) + , m_xCtrlFieldCB(m_xBuilder->weld_check_button("formcontrols")) + , m_xBackgroundCB(m_xBuilder->weld_check_button("background")) + , m_xBlackFontCB(m_xBuilder->weld_check_button("inblack")) + , m_xPrintHiddenTextCB(m_xBuilder->weld_check_button("hiddentext")) + , m_xPrintTextPlaceholderCB(m_xBuilder->weld_check_button("textplaceholder")) + , m_xPagesFrame(m_xBuilder->weld_widget("pagesframe")) + , m_xLeftPageCB(m_xBuilder->weld_check_button("leftpages")) + , m_xRightPageCB(m_xBuilder->weld_check_button("rightpages")) + , m_xProspectCB(m_xBuilder->weld_check_button("brochure")) + , m_xProspectCB_RTL(m_xBuilder->weld_check_button("rtl")) + , m_xCommentsFrame(m_xBuilder->weld_widget("commentsframe")) + , m_xNoRB(m_xBuilder->weld_radio_button("none")) + , m_xOnlyRB(m_xBuilder->weld_radio_button("only")) + , m_xEndRB(m_xBuilder->weld_radio_button("end")) + , m_xEndPageRB(m_xBuilder->weld_radio_button("endpage")) + , m_xInMarginsRB(m_xBuilder->weld_radio_button("inmargins")) + , m_xPrintEmptyPagesCB(m_xBuilder->weld_check_button("blankpages")) + , m_xPaperFromSetupCB(m_xBuilder->weld_check_button("papertray")) + , m_xFaxLB(m_xBuilder->weld_combo_box("fax")) +{ + Link<weld::Toggleable&,void> aLk = LINK( this, SwAddPrinterTabPage, AutoClickHdl); + m_xGrfCB->connect_toggled( aLk ); + m_xRightPageCB->connect_toggled( aLk ); + m_xLeftPageCB->connect_toggled( aLk ); + m_xCtrlFieldCB->connect_toggled( aLk ); + m_xBackgroundCB->connect_toggled( aLk ); + m_xBlackFontCB->connect_toggled( aLk ); + m_xPrintHiddenTextCB->connect_toggled( aLk ); + m_xPrintTextPlaceholderCB->connect_toggled( aLk ); + m_xProspectCB->connect_toggled( aLk ); + m_xProspectCB_RTL->connect_toggled( aLk ); + m_xPaperFromSetupCB->connect_toggled( aLk ); + m_xPrintEmptyPagesCB->connect_toggled( aLk ); + m_xEndPageRB->connect_toggled( aLk ); + m_xInMarginsRB->connect_toggled( aLk ); + m_xEndRB->connect_toggled( aLk ); + m_xOnlyRB->connect_toggled( aLk ); + m_xNoRB->connect_toggled( aLk ); + m_xFaxLB->connect_changed( LINK( this, SwAddPrinterTabPage, SelectHdl ) ); + + const SfxUInt16Item* pItem = rCoreSet.GetItemIfSet(SID_HTML_MODE, false ); + if(pItem && pItem->GetValue() & HTMLMODE_ON) + { + m_xLeftPageCB->hide(); + m_xRightPageCB->hide(); + m_xPrintHiddenTextCB->hide(); + m_xPrintTextPlaceholderCB->hide(); + m_xPrintEmptyPagesCB->hide(); + } + m_xProspectCB_RTL->set_sensitive(false); + SvtCTLOptions aCTLOptions; + m_xProspectCB_RTL->set_visible(aCTLOptions.IsCTLFontEnabled()); +} + +SwAddPrinterTabPage::~SwAddPrinterTabPage() +{ +} + +void SwAddPrinterTabPage::SetPreview(bool bPrev) +{ + bPreview = bPrev; + m_xCommentsFrame->set_sensitive(!bPreview); + m_xPagesFrame->set_sensitive(!bPreview); +} + +std::unique_ptr<SfxTabPage> SwAddPrinterTabPage::Create( weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet ) +{ + return std::make_unique<SwAddPrinterTabPage>(pPage, pController, *rAttrSet); +} + +bool SwAddPrinterTabPage::FillItemSet( SfxItemSet* rCoreSet ) +{ + if ( bAttrModified ) + { + SwAddPrinterItem aAddPrinterAttr; + aAddPrinterAttr.m_bPrintGraphic = m_xGrfCB->get_active(); + aAddPrinterAttr.m_bPrintTable = true; // always enabled since CWS printerpullgpages /*m_xTabCB->get_active();*/ + aAddPrinterAttr.m_bPrintDraw = m_xGrfCB->get_active(); // UI merged with m_xGrfCB in CWS printerpullgpages + aAddPrinterAttr.m_bPrintControl = m_xCtrlFieldCB->get_active(); + aAddPrinterAttr.m_bPrintPageBackground = m_xBackgroundCB->get_active(); + aAddPrinterAttr.m_bPrintBlackFont = m_xBlackFontCB->get_active(); + aAddPrinterAttr.m_bPrintHiddenText = m_xPrintHiddenTextCB->get_active(); + aAddPrinterAttr.m_bPrintTextPlaceholder = m_xPrintTextPlaceholderCB->get_active(); + + aAddPrinterAttr.m_bPrintLeftPages = m_xLeftPageCB->get_active(); + aAddPrinterAttr.m_bPrintRightPages = m_xRightPageCB->get_active(); + aAddPrinterAttr.m_bPrintReverse = false; // handled by vcl itself since CWS printerpullpages /*m_xReverseCB->get_active()*/; + aAddPrinterAttr.m_bPrintProspect = m_xProspectCB->get_active(); + aAddPrinterAttr.m_bPrintProspectRTL = m_xProspectCB_RTL->get_active(); + aAddPrinterAttr.m_bPaperFromSetup = m_xPaperFromSetupCB->get_active(); + aAddPrinterAttr.m_bPrintEmptyPages = m_xPrintEmptyPagesCB->get_active(); + aAddPrinterAttr.m_bPrintSingleJobs = true; // handled by vcl in new print dialog since CWS printerpullpages /*m_xSingleJobsCB->get_active()*/; + + if (m_xNoRB->get_active()) aAddPrinterAttr.m_nPrintPostIts = + SwPostItMode::NONE; + if (m_xOnlyRB->get_active()) aAddPrinterAttr.m_nPrintPostIts = + SwPostItMode::Only; + if (m_xEndRB->get_active()) aAddPrinterAttr.m_nPrintPostIts = + SwPostItMode::EndDoc; + if (m_xEndPageRB->get_active()) aAddPrinterAttr.m_nPrintPostIts = + SwPostItMode::EndPage; + if (m_xInMarginsRB->get_active()) aAddPrinterAttr.m_nPrintPostIts = + SwPostItMode::InMargins; + + const OUString sFax = m_xFaxLB->get_active_text(); + aAddPrinterAttr.m_sFaxName = sNone == sFax ? OUString() : sFax; + rCoreSet->Put(aAddPrinterAttr); + } + return bAttrModified; +} + +void SwAddPrinterTabPage::Reset( const SfxItemSet* ) +{ + const SfxItemSet& rSet = GetItemSet(); + + if( const SwAddPrinterItem* pAddPrinterAttr = rSet.GetItemIfSet( FN_PARAM_ADDPRINTER , false ) ) + { + m_xGrfCB->set_active(pAddPrinterAttr->m_bPrintGraphic || pAddPrinterAttr->m_bPrintDraw); + m_xCtrlFieldCB->set_active( pAddPrinterAttr->m_bPrintControl); + m_xBackgroundCB->set_active( pAddPrinterAttr->m_bPrintPageBackground); + m_xBlackFontCB->set_active( pAddPrinterAttr->m_bPrintBlackFont); + m_xPrintHiddenTextCB->set_active( pAddPrinterAttr->m_bPrintHiddenText); + m_xPrintTextPlaceholderCB->set_active(pAddPrinterAttr->m_bPrintTextPlaceholder); + m_xLeftPageCB->set_active( pAddPrinterAttr->m_bPrintLeftPages); + m_xRightPageCB->set_active( pAddPrinterAttr->m_bPrintRightPages); + m_xPaperFromSetupCB->set_active(pAddPrinterAttr->m_bPaperFromSetup); + m_xPrintEmptyPagesCB->set_active(pAddPrinterAttr->m_bPrintEmptyPages); + m_xProspectCB->set_active( pAddPrinterAttr->m_bPrintProspect); + m_xProspectCB_RTL->set_active( pAddPrinterAttr->m_bPrintProspectRTL); + + m_xNoRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::NONE ) ; + m_xOnlyRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::Only ) ; + m_xEndRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::EndDoc ) ; + m_xEndPageRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::EndPage ) ; + m_xInMarginsRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::InMargins ) ; + auto nFound = m_xFaxLB->find_text(pAddPrinterAttr->m_sFaxName); + if (nFound != -1) + m_xFaxLB->set_active(nFound); + else + m_xFaxLB->set_active(0); + } + if (m_xProspectCB->get_active()) + { + m_xProspectCB_RTL->set_sensitive(true); + m_xNoRB->set_sensitive( false ); + m_xOnlyRB->set_sensitive( false ); + m_xEndRB->set_sensitive( false ); + m_xEndPageRB->set_sensitive( false ); + } + else + m_xProspectCB_RTL->set_sensitive( false ); +} + +IMPL_LINK_NOARG(SwAddPrinterTabPage, AutoClickHdl, weld::Toggleable&, void) +{ + bAttrModified = true; + bool bIsProspect = m_xProspectCB->get_active(); + if (!bIsProspect) + m_xProspectCB_RTL->set_active( false ); + m_xProspectCB_RTL->set_sensitive( bIsProspect ); + m_xNoRB->set_sensitive( !bIsProspect ); + m_xOnlyRB->set_sensitive( !bIsProspect ); + m_xEndRB->set_sensitive( !bIsProspect ); + m_xEndPageRB->set_sensitive( !bIsProspect ); + m_xInMarginsRB->set_sensitive( !bIsProspect ); +} + +void SwAddPrinterTabPage::SetFax( const std::vector<OUString>& rFaxLst ) +{ + m_xFaxLB->append_text(sNone); + for(const auto & i : rFaxLst) + { + m_xFaxLB->append_text(i); + } + m_xFaxLB->set_active(0); +} + +IMPL_LINK_NOARG(SwAddPrinterTabPage, SelectHdl, weld::ComboBox&, void) +{ + bAttrModified=true; +} + +void SwAddPrinterTabPage::PageCreated( const SfxAllItemSet& aSet) +{ + const SfxBoolItem* pListItem = aSet.GetItem<SfxBoolItem>(SID_FAX_LIST, false); + const SfxBoolItem* pPreviewItem = aSet.GetItem<SfxBoolItem>(SID_PREVIEWFLAG_TYPE, false); + if (pPreviewItem) + { + SetPreview(pPreviewItem->GetValue()); + Reset(&aSet); + } + if (pListItem && pListItem->GetValue()) + { + std::vector<OUString> aFaxList; + const std::vector<OUString>& rPrinters = Printer::GetPrinterQueues(); + for (const auto & rPrinter : rPrinters) + aFaxList.insert(aFaxList.begin(), rPrinter); + SetFax( aFaxList ); + } +} + +// Tabpage Standardfonts +SwStdFontTabPage::SwStdFontTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optfonttabpage.ui", "OptFontTabPage", &rSet) + , m_pPrt(nullptr) + , m_pFontConfig(nullptr) + , m_pWrtShell(nullptr) + , m_eLanguage( GetAppLanguage() ) + , m_bListDefault(false) + , m_bSetListDefault(true) + , m_bLabelDefault(false) + , m_bSetLabelDefault(true) + , m_bIdxDefault(false) + , m_bSetIdxDefault(true) + , m_bDisposePrinter(false) + , m_nFontGroup(FONT_GROUP_DEFAULT) + , m_sScriptWestern(SwResId(ST_SCRIPT_WESTERN)) + , m_sScriptAsian(SwResId(ST_SCRIPT_ASIAN)) + , m_sScriptComplex(SwResId(ST_SCRIPT_CTL)) + , m_xLabelFT(m_xBuilder->weld_label("label1")) + , m_xStandardBox(m_xBuilder->weld_combo_box("standardbox")) + , m_xStandardHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("standardheight"))) + , m_xTitleBox(m_xBuilder->weld_combo_box("titlebox")) + , m_xTitleHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("titleheight"))) + , m_xListBox(m_xBuilder->weld_combo_box("listbox")) + , m_xListHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("listheight"))) + , m_xLabelBox(m_xBuilder->weld_combo_box("labelbox")) + , m_xLabelHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("labelheight"))) + , m_xIdxBox(m_xBuilder->weld_combo_box("idxbox")) + , m_xIndexHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("indexheight"))) + , m_xStandardPB(m_xBuilder->weld_button("standard")) +{ + m_xStandardBox->make_sorted(); + m_xTitleBox->make_sorted(); + m_xListBox->make_sorted(); + m_xLabelBox->make_sorted(); + m_xIdxBox->make_sorted(); + + m_xStandardPB->connect_clicked(LINK(this, SwStdFontTabPage, StandardHdl)); + m_xStandardBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)); + m_xListBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)); + m_xLabelBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)); + m_xIdxBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)); + Link<weld::Widget&,void> aFocusLink = LINK( this, SwStdFontTabPage, LoseFocusHdl); + m_xStandardBox->connect_focus_out( aFocusLink ); + m_xTitleBox->connect_focus_out( aFocusLink ); + m_xListBox->connect_focus_out( aFocusLink ); + m_xLabelBox->connect_focus_out( aFocusLink ); + m_xIdxBox->connect_focus_out( aFocusLink ); +} + +SwStdFontTabPage::~SwStdFontTabPage() +{ + m_xIndexHeightLB.reset(); + m_xLabelHeightLB.reset(); + m_xListHeightLB.reset(); + m_xTitleHeightLB.reset(); + m_xStandardHeightLB.reset(); + m_pFontList.reset(); + if (m_bDisposePrinter) + m_pPrt.disposeAndClear(); + else + m_pPrt.clear(); +} + +std::unique_ptr<SfxTabPage> SwStdFontTabPage::Create( weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet ) +{ + return std::make_unique<SwStdFontTabPage>(pPage, pController, *rAttrSet); +} + +static void lcl_SetColl(SwWrtShell* pWrtShell, sal_uInt16 nType, + SfxPrinter const * pPrt, const OUString& rStyle, + sal_uInt16 nFontWhich) +{ + vcl::Font aFont( rStyle, Size( 0, 10 ) ); + if( pPrt ) + aFont = pPrt->GetFontMetric( aFont ); + SwTextFormatColl *pColl = pWrtShell->GetTextCollFromPool(nType); + pColl->SetFormatAttr(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(), + OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich)); +} + +static void lcl_SetColl(SwWrtShell* pWrtShell, sal_uInt16 nType, + sal_Int32 nHeight, sal_uInt16 nFontHeightWhich) +{ + float fSize = static_cast<float>(nHeight) / 10; + nHeight = CalcToUnit( fSize, MapUnit::MapTwip ); + SwTextFormatColl *pColl = pWrtShell->GetTextCollFromPool(nType); + pColl->SetFormatAttr(SvxFontHeightItem(nHeight, 100, nFontHeightWhich)); +} + +bool SwStdFontTabPage::FillItemSet( SfxItemSet* ) +{ + SW_MOD()->GetModuleConfig()->SetDefaultFontInCurrDocOnly(false); + + const OUString sStandard = m_xStandardBox->get_active_text(); + const OUString sTitle = m_xTitleBox->get_active_text(); + const OUString sList = m_xListBox->get_active_text(); + const OUString sLabel = m_xLabelBox->get_active_text(); + const OUString sIdx = m_xIdxBox->get_active_text(); + + bool bStandardHeightChanged = m_xStandardHeightLB->get_value_changed_from_saved(); + bool bTitleHeightChanged = m_xTitleHeightLB->get_value_changed_from_saved(); + bool bListHeightChanged = m_xListHeightLB->get_value_changed_from_saved(); + bool bLabelHeightChanged = m_xLabelHeightLB->get_value_changed_from_saved(); + bool bIndexHeightChanged = m_xIndexHeightLB->get_value_changed_from_saved(); + + m_pFontConfig->SetFontStandard(sStandard, m_nFontGroup); + m_pFontConfig->SetFontOutline(sTitle, m_nFontGroup); + m_pFontConfig->SetFontList(sList, m_nFontGroup); + m_pFontConfig->SetFontCaption(sLabel, m_nFontGroup); + m_pFontConfig->SetFontIndex(sIdx, m_nFontGroup); + if(bStandardHeightChanged) + { + float fSize = static_cast<float>(m_xStandardHeightLB->get_value()) / 10; + m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_STANDARD, m_nFontGroup ); + } + if(bTitleHeightChanged) + { + float fSize = static_cast<float>(m_xTitleHeightLB->get_value()) / 10; + m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_OUTLINE, m_nFontGroup ); + } + if(bListHeightChanged) + { + float fSize = static_cast<float>(m_xListHeightLB->get_value()) / 10; + m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_LIST, m_nFontGroup ); + } + if(bLabelHeightChanged) + { + float fSize = static_cast<float>(m_xLabelHeightLB->get_value()) / 10; + m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_CAPTION, m_nFontGroup ); + } + if(bIndexHeightChanged) + { + float fSize = static_cast<float>(m_xIndexHeightLB->get_value()) / 10; + m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_INDEX, m_nFontGroup ); + } + + if(m_pWrtShell) + { + m_pWrtShell->StartAllAction(); + SfxPrinter* pPrinter = m_pWrtShell->getIDocumentDeviceAccess().getPrinter( false ); + bool bMod = false; + const sal_uInt16 nFontWhich = + m_nFontGroup == FONT_GROUP_DEFAULT ? RES_CHRATR_FONT : + FONT_GROUP_CJK == m_nFontGroup ? RES_CHRATR_CJK_FONT : RES_CHRATR_CTL_FONT; + const sal_uInt16 nFontHeightWhich = + m_nFontGroup == FONT_GROUP_DEFAULT ? RES_CHRATR_FONTSIZE : + FONT_GROUP_CJK == m_nFontGroup ? RES_CHRATR_CJK_FONTSIZE : RES_CHRATR_CTL_FONTSIZE; + if(sStandard != m_sShellStd) + { + vcl::Font aFont( sStandard, Size( 0, 10 ) ); + if( pPrinter ) + aFont = pPrinter->GetFontMetric( aFont ); + m_pWrtShell->SetDefault(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(), + OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich)); + SwTextFormatColl *pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_STANDARD); + pColl->ResetFormatAttr(nFontWhich); + bMod = true; + } + if(bStandardHeightChanged) + { + float fSize = static_cast<float>(m_xStandardHeightLB->get_value()) / 10; + m_pWrtShell->SetDefault(SvxFontHeightItem( CalcToUnit( fSize, MapUnit::MapTwip ), 100, nFontHeightWhich ) ); + SwTextFormatColl *pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_STANDARD); + pColl->ResetFormatAttr(nFontHeightWhich); + bMod = true; + } + + if(sTitle != m_sShellTitle ) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_HEADLINE_BASE, pPrinter, sTitle, nFontWhich); + bMod = true; + } + if(bTitleHeightChanged) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_HEADLINE_BASE, + sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xTitleHeightLB->get_value()), nFontHeightWhich); + bMod = true; + } + if(sList != m_sShellList && (!m_bListDefault || !m_bSetListDefault )) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_NUMBER_BULLET_BASE, pPrinter, sList, nFontWhich); + bMod = true; + } + if(bListHeightChanged) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_NUMBER_BULLET_BASE, + sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xListHeightLB->get_value()), nFontHeightWhich); + bMod = true; + } + if(sLabel != m_sShellLabel && (!m_bLabelDefault || !m_bSetLabelDefault)) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_LABEL, pPrinter, sLabel, nFontWhich); + bMod = true; + } + if(bLabelHeightChanged) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_LABEL, + sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xLabelHeightLB->get_value()), nFontHeightWhich); + bMod = true; + } + if(sIdx != m_sShellIndex && (!m_bIdxDefault || !m_bSetIdxDefault)) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_REGISTER_BASE, pPrinter, sIdx, nFontWhich); + bMod = true; + } + if(bIndexHeightChanged) + { + lcl_SetColl(m_pWrtShell, RES_POOLCOLL_REGISTER_BASE, + sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xIndexHeightLB->get_value()), nFontHeightWhich); + bMod = true; + } + if ( bMod ) + m_pWrtShell->SetModified(); + m_pWrtShell->EndAllAction(); + } + return false; +} + +void SwStdFontTabPage::Reset( const SfxItemSet* rSet) +{ + const TypedWhichId<SvxLanguageItem> nLangSlot = m_nFontGroup == FONT_GROUP_DEFAULT ? SID_ATTR_LANGUAGE : + FONT_GROUP_CJK == m_nFontGroup ? SID_ATTR_CHAR_CJK_LANGUAGE : SID_ATTR_CHAR_CTL_LANGUAGE; + + if( const SvxLanguageItem* pLang = rSet->GetItemIfSet(nLangSlot, false) ) + m_eLanguage = pLang->GetValue(); + + OUString sToReplace = m_sScriptWestern; + if(FONT_GROUP_CJK == m_nFontGroup ) + sToReplace = m_sScriptAsian; + else if(FONT_GROUP_CTL == m_nFontGroup ) + sToReplace = m_sScriptComplex; + m_xLabelFT->set_label(m_xLabelFT->get_label().replaceFirst("%1", sToReplace)); + + if (m_bDisposePrinter) + { + m_pPrt.disposeAndClear(); + m_bDisposePrinter = false; + } + + if(const SwPtrItem* pItem = rSet->GetItemIfSet(FN_PARAM_PRINTER, false)) + { + m_pPrt = static_cast<SfxPrinter*>(pItem->GetValue()); + } + else + { + auto pPrinterSet = std::make_unique<SfxItemSetFixed + <SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN, + SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC>>( *rSet->GetPool() ); + m_pPrt = VclPtr<SfxPrinter>::Create(std::move(pPrinterSet)); + m_bDisposePrinter = true; + } + m_pFontList.reset(new FontList( m_pPrt )); + // #i94536# prevent duplication of font entries when 'reset' button is pressed + if( !m_xStandardBox->get_count() ) + { + // get the set of distinct available family names + std::set< OUString > aFontNames; + int nFontNames = m_pPrt->GetFontFaceCollectionCount(); + for( int i = 0; i < nFontNames; i++ ) + { + FontMetric aFontMetric( m_pPrt->GetFontMetricFromCollection( i ) ); + aFontNames.insert( aFontMetric.GetFamilyName() ); + } + + // insert to listboxes + for( const auto& rFontName : aFontNames ) + { + m_xStandardBox->append_text( rFontName ); + m_xTitleBox->append_text( rFontName ); + m_xListBox->append_text( rFontName ); + m_xLabelBox->append_text( rFontName ); + m_xIdxBox->append_text( rFontName ); + } + } + if(const SwPtrItem* pItem = rSet->GetItemIfSet(FN_PARAM_STDFONTS, false)) + { + m_pFontConfig = static_cast<SwStdFontConfig*>(pItem->GetValue()); + } + + if(const SwPtrItem* pItem = rSet->GetItemIfSet(FN_PARAM_WRTSHELL, false)) + { + m_pWrtShell = static_cast<SwWrtShell*>(pItem->GetValue()); + } + OUString sStdBackup; + OUString sOutBackup; + OUString sListBackup; + OUString sCapBackup; + OUString sIdxBackup; + sal_Int32 nStandardHeight = -1; + sal_Int32 nTitleHeight = -1; + sal_Int32 nListHeight = -1; + sal_Int32 nLabelHeight = -1; + sal_Int32 nIndexHeight = -1; + + if(!m_pWrtShell) + { + sStdBackup = m_pFontConfig->GetFontStandard(m_nFontGroup); + sOutBackup = m_pFontConfig->GetFontOutline(m_nFontGroup); + sListBackup= m_pFontConfig->GetFontList(m_nFontGroup); + sCapBackup = m_pFontConfig->GetFontCaption(m_nFontGroup); + sIdxBackup = m_pFontConfig->GetFontIndex(m_nFontGroup); + nStandardHeight = m_pFontConfig->GetFontHeight( FONT_STANDARD, m_nFontGroup, m_eLanguage ); + nTitleHeight = m_pFontConfig->GetFontHeight( FONT_OUTLINE , m_nFontGroup, m_eLanguage ); + nListHeight = m_pFontConfig->GetFontHeight( FONT_LIST , m_nFontGroup, m_eLanguage ); + nLabelHeight = m_pFontConfig->GetFontHeight( FONT_CAPTION , m_nFontGroup, m_eLanguage ); + nIndexHeight = m_pFontConfig->GetFontHeight( FONT_INDEX , m_nFontGroup, m_eLanguage ); + if( nStandardHeight <= 0) + nStandardHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_STANDARD + m_nFontGroup * FONT_PER_GROUP, m_eLanguage); + if( nTitleHeight <= 0) + nTitleHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_OUTLINE + m_nFontGroup * FONT_PER_GROUP, m_eLanguage); + if( nListHeight <= 0) + nListHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_LIST + m_nFontGroup * FONT_PER_GROUP, m_eLanguage); + if( nLabelHeight <= 0) + nLabelHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_CAPTION + m_nFontGroup * FONT_PER_GROUP, m_eLanguage); + if( nIndexHeight <= 0) + nIndexHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_INDEX + m_nFontGroup * FONT_PER_GROUP, m_eLanguage); + } + else + { + SwTextFormatColl *pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_STANDARD); + const SvxFontItem& rFont = !m_nFontGroup ? pColl->GetFont() : + FONT_GROUP_CJK == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont(); + m_sShellStd = sStdBackup = rFont.GetFamilyName(); + + const sal_uInt16 nFontHeightWhich = + m_nFontGroup == FONT_GROUP_DEFAULT ? RES_CHRATR_FONTSIZE : + FONT_GROUP_CJK == m_nFontGroup ? RES_CHRATR_CJK_FONTSIZE : RES_CHRATR_CTL_FONTSIZE; + const SvxFontHeightItem& rFontHeightStandard = static_cast<const SvxFontHeightItem& >(pColl->GetFormatAttr(nFontHeightWhich)); + nStandardHeight = static_cast<sal_Int32>(rFontHeightStandard.GetHeight()); + + pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_HEADLINE_BASE); + const SvxFontItem& rFontHL = !m_nFontGroup ? pColl->GetFont() : + FONT_GROUP_CJK == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont(); + m_sShellTitle = sOutBackup = rFontHL.GetFamilyName(); + + const SvxFontHeightItem& rFontHeightTitle = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr( nFontHeightWhich )); + nTitleHeight = static_cast<sal_Int32>(rFontHeightTitle.GetHeight()); + + const sal_uInt16 nFontWhich = + m_nFontGroup == FONT_GROUP_DEFAULT ? RES_CHRATR_FONT : + FONT_GROUP_CJK == m_nFontGroup ? RES_CHRATR_CJK_FONT : RES_CHRATR_CTL_FONT; + pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_NUMBER_BULLET_BASE); + const SvxFontItem& rFontLS = !m_nFontGroup ? pColl->GetFont() : + FONT_GROUP_CJK == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont(); + m_bListDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false); + m_sShellList = sListBackup = rFontLS.GetFamilyName(); + + const SvxFontHeightItem& rFontHeightList = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr(nFontHeightWhich)); + nListHeight = static_cast<sal_Int32>(rFontHeightList.GetHeight()); + + pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_LABEL); + m_bLabelDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false); + const SvxFontItem& rFontCP = !m_nFontGroup ? pColl->GetFont() : + FONT_GROUP_CJK == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont(); + m_sShellLabel = sCapBackup = rFontCP.GetFamilyName(); + const SvxFontHeightItem& rFontHeightLabel = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr(nFontHeightWhich)); + nLabelHeight = static_cast<sal_Int32>(rFontHeightLabel.GetHeight()); + + pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_REGISTER_BASE); + m_bIdxDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false); + const SvxFontItem& rFontIDX = !m_nFontGroup ? pColl->GetFont() : + FONT_GROUP_CJK == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont(); + m_sShellIndex = sIdxBackup = rFontIDX.GetFamilyName(); + const SvxFontHeightItem& rFontHeightIndex = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr(nFontHeightWhich)); + nIndexHeight = static_cast<sal_Int32>(rFontHeightIndex.GetHeight()); + } + m_xStandardBox->set_entry_text(sStdBackup ); + m_xTitleBox->set_entry_text(sOutBackup ); + m_xListBox->set_entry_text(sListBackup); + m_xLabelBox->set_entry_text(sCapBackup ); + m_xIdxBox->set_entry_text(sIdxBackup ); + + m_xStandardHeightLB->Fill( m_pFontList.get() ); + m_xTitleHeightLB->Fill( m_pFontList.get() ); + m_xListHeightLB->Fill( m_pFontList.get() ); + m_xLabelHeightLB->Fill( m_pFontList.get() ); + m_xIndexHeightLB->Fill( m_pFontList.get() ); + + m_xStandardHeightLB->set_value( CalcToPoint( nStandardHeight, MapUnit::MapTwip, 10 ) ); + m_xTitleHeightLB->set_value( CalcToPoint( nTitleHeight , MapUnit::MapTwip, 10 ) ); + m_xListHeightLB->set_value( CalcToPoint( nListHeight , MapUnit::MapTwip, 10 ) ); + m_xLabelHeightLB->set_value( CalcToPoint( nLabelHeight , MapUnit::MapTwip, 10 )); + m_xIndexHeightLB->set_value( CalcToPoint( nIndexHeight , MapUnit::MapTwip, 10 )); + + m_xStandardBox->save_value(); + m_xTitleBox->save_value(); + m_xListBox->save_value(); + m_xLabelBox->save_value(); + m_xIdxBox->save_value(); + + m_xStandardHeightLB->save_value(); + m_xTitleHeightLB->save_value(); + m_xListHeightLB->save_value(); + m_xLabelHeightLB->save_value(); + m_xIndexHeightLB->save_value(); +} + +IMPL_LINK_NOARG(SwStdFontTabPage, StandardHdl, weld::Button&, void) +{ + sal_uInt8 nFontOffset = m_nFontGroup * FONT_PER_GROUP; + m_xStandardBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_STANDARD + nFontOffset, m_eLanguage)); + m_xTitleBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_OUTLINE + nFontOffset, m_eLanguage)); + m_xListBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_LIST + nFontOffset, m_eLanguage)); + m_xLabelBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_CAPTION + nFontOffset, m_eLanguage)); + m_xIdxBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_INDEX + nFontOffset, m_eLanguage)); + + m_xStandardBox->save_value(); + m_xTitleBox->save_value(); + m_xListBox->save_value(); + m_xLabelBox->save_value(); + m_xIdxBox->save_value(); + + m_xStandardHeightLB->set_value( CalcToPoint( + SwStdFontConfig::GetDefaultHeightFor(FONT_STANDARD + nFontOffset, m_eLanguage), + MapUnit::MapTwip, 10 )); + m_xTitleHeightLB->set_value(CalcToPoint( + SwStdFontConfig::GetDefaultHeightFor(FONT_OUTLINE + + nFontOffset, m_eLanguage), MapUnit::MapTwip, 10 )); + m_xListHeightLB->set_value(CalcToPoint( + SwStdFontConfig::GetDefaultHeightFor(FONT_LIST + nFontOffset, m_eLanguage), + MapUnit::MapTwip, 10 )); + m_xLabelHeightLB->set_value(CalcToPoint( + SwStdFontConfig::GetDefaultHeightFor(FONT_CAPTION + nFontOffset, m_eLanguage), + MapUnit::MapTwip, 10 )); + m_xIndexHeightLB->set_value(CalcToPoint( + SwStdFontConfig::GetDefaultHeightFor(FONT_INDEX + nFontOffset, m_eLanguage), + MapUnit::MapTwip, 10 )); +} + +IMPL_LINK( SwStdFontTabPage, ModifyHdl, weld::ComboBox&, rBox, void ) +{ + if (&rBox == m_xStandardBox.get()) + { + const OUString sEntry = rBox.get_active_text(); + if(m_bSetListDefault && m_bListDefault) + m_xListBox->set_entry_text(sEntry); + if(m_bSetLabelDefault && m_bLabelDefault) + m_xLabelBox->set_entry_text(sEntry); + if(m_bSetIdxDefault && m_bIdxDefault) + m_xIdxBox->set_entry_text(sEntry); + } + else if (&rBox == m_xListBox.get()) + { + m_bSetListDefault = false; + } + else if (&rBox == m_xLabelBox.get()) + { + m_bSetLabelDefault = false; + } + else if (&rBox == m_xIdxBox.get()) + { + m_bSetIdxDefault = false; + } +} + +IMPL_LINK( SwStdFontTabPage, LoseFocusHdl, weld::Widget&, rControl, void ) +{ + weld::ComboBox& rBox = dynamic_cast<weld::ComboBox&>(rControl); + FontSizeBox* pHeightLB = nullptr; + + if (&rBox == m_xStandardBox.get()) + { + pHeightLB = m_xStandardHeightLB.get(); + } + else if (&rBox == m_xTitleBox.get()) + { + pHeightLB = m_xTitleHeightLB.get(); + } + else if (&rBox == m_xListBox.get()) + { + pHeightLB = m_xListHeightLB.get(); + } + else if (&rBox == m_xLabelBox.get()) + { + pHeightLB = m_xLabelHeightLB.get(); + } + else /*if (&rBox == m_xIndexHeightLB.get())*/ + { + pHeightLB = m_xIndexHeightLB.get(); + } + + pHeightLB->Fill( m_pFontList.get() ); +} + +void SwStdFontTabPage::PageCreated( const SfxAllItemSet& aSet) +{ + const SfxUInt16Item* pFlagItem = aSet.GetItem<SfxUInt16Item>(SID_FONTMODE_TYPE, false); + if (pFlagItem) + m_nFontGroup = sal::static_int_cast< sal_uInt8, sal_uInt16>( pFlagItem->GetValue() ); +} + +SwTableOptionsTabPage::SwTableOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/opttablepage.ui", "OptTablePage", &rSet) + , m_pWrtShell(nullptr) + , m_bHTMLMode(false) + , m_xHeaderCB(m_xBuilder->weld_check_button("header")) + , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatheader")) + , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplit")) + , m_xBorderCB(m_xBuilder->weld_check_button("border")) + , m_xNumFormattingCB(m_xBuilder->weld_check_button("numformatting")) + , m_xNumFormatFormattingCB(m_xBuilder->weld_check_button("numfmtformatting")) + , m_xNumAlignmentCB(m_xBuilder->weld_check_button("numalignment")) + , m_xRowMoveMF(m_xBuilder->weld_metric_spin_button("rowmove", FieldUnit::CM)) + , m_xColMoveMF(m_xBuilder->weld_metric_spin_button("colmove", FieldUnit::CM)) + , m_xRowInsertMF(m_xBuilder->weld_metric_spin_button("rowinsert", FieldUnit::CM)) + , m_xColInsertMF(m_xBuilder->weld_metric_spin_button("colinsert", FieldUnit::CM)) + , m_xFixRB(m_xBuilder->weld_radio_button("fix")) + , m_xFixPropRB(m_xBuilder->weld_radio_button("fixprop")) + , m_xVarRB(m_xBuilder->weld_radio_button("var")) +{ + Link<weld::Toggleable&,void> aLnk(LINK(this, SwTableOptionsTabPage, CheckBoxHdl)); + m_xNumFormattingCB->connect_toggled(aLnk); + m_xNumFormatFormattingCB->connect_toggled(aLnk); + m_xHeaderCB->connect_toggled(aLnk); +} + +SwTableOptionsTabPage::~SwTableOptionsTabPage() +{ +} + +std::unique_ptr<SfxTabPage> SwTableOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet ) +{ + return std::make_unique<SwTableOptionsTabPage>(pPage, pController, *rAttrSet); +} + +bool SwTableOptionsTabPage::FillItemSet( SfxItemSet* ) +{ + bool bRet = false; + SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); + + if (m_xRowMoveMF->get_value_changed_from_saved()) + pModOpt->SetTableHMove( o3tl::narrowing<sal_uInt16>(m_xRowMoveMF->denormalize( m_xRowMoveMF->get_value(FieldUnit::TWIP)))); + + if (m_xColMoveMF->get_value_changed_from_saved()) + pModOpt->SetTableVMove( o3tl::narrowing<sal_uInt16>(m_xColMoveMF->denormalize( m_xColMoveMF->get_value(FieldUnit::TWIP)))); + + if (m_xRowInsertMF->get_value_changed_from_saved()) + pModOpt->SetTableHInsert(o3tl::narrowing<sal_uInt16>(m_xRowInsertMF->denormalize( m_xRowInsertMF->get_value(FieldUnit::TWIP)))); + + if (m_xColInsertMF->get_value_changed_from_saved()) + pModOpt->SetTableVInsert(o3tl::narrowing<sal_uInt16>(m_xColInsertMF->denormalize( m_xColInsertMF->get_value(FieldUnit::TWIP)))); + + TableChgMode eMode; + if (m_xFixRB->get_active()) + eMode = TableChgMode::FixedWidthChangeAbs; + else if(m_xFixPropRB->get_active()) + eMode = TableChgMode::FixedWidthChangeProp; + else + eMode = TableChgMode::VarWidthChangeAbs; + if(eMode != pModOpt->GetTableMode()) + { + pModOpt->SetTableMode(eMode); + // the table-keyboard-mode has changed, now the current + // table should know about that too. + if(m_pWrtShell && SelectionType::Table & m_pWrtShell->GetSelectionType()) + { + m_pWrtShell->SetTableChgMode(eMode); + static sal_uInt16 aInva[] = + { FN_TABLE_MODE_FIX, + FN_TABLE_MODE_FIX_PROP, + FN_TABLE_MODE_VARIABLE, + 0 + }; + m_pWrtShell->GetView().GetViewFrame()->GetBindings().Invalidate( aInva ); + } + + bRet = true; + } + + SwInsertTableOptions aInsOpts( SwInsertTableFlags::NONE, 0 ); + + if (m_xHeaderCB->get_active()) + aInsOpts.mnInsMode |= SwInsertTableFlags::Headline; + + if (m_xRepeatHeaderCB->get_sensitive()) + aInsOpts.mnRowsToRepeat = m_xRepeatHeaderCB->get_active() ? 1 : 0; + + if (!m_xDontSplitCB->get_active()) + aInsOpts.mnInsMode |= SwInsertTableFlags::SplitLayout; + + if (m_xBorderCB->get_active()) + aInsOpts.mnInsMode |= SwInsertTableFlags::DefaultBorder; + + if (m_xHeaderCB->get_state_changed_from_saved() || + m_xRepeatHeaderCB->get_state_changed_from_saved() || + m_xDontSplitCB->get_state_changed_from_saved() || + m_xBorderCB->get_state_changed_from_saved()) + { + pModOpt->SetInsTableFlags(m_bHTMLMode, aInsOpts); + } + + if (m_xNumFormattingCB->get_state_changed_from_saved()) + { + pModOpt->SetInsTableFormatNum(m_bHTMLMode, m_xNumFormattingCB->get_active()); + bRet = true; + } + + if (m_xNumFormatFormattingCB->get_state_changed_from_saved()) + { + pModOpt->SetInsTableChangeNumFormat(m_bHTMLMode, m_xNumFormatFormattingCB->get_active()); + bRet = true; + } + + if (m_xNumAlignmentCB->get_state_changed_from_saved()) + { + pModOpt->SetInsTableAlignNum(m_bHTMLMode, m_xNumAlignmentCB->get_active()); + bRet = true; + } + + return bRet; +} + +void SwTableOptionsTabPage::Reset( const SfxItemSet* rSet) +{ + const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); + if ( rSet->GetItemState( SID_ATTR_METRIC ) >= SfxItemState::DEFAULT ) + { + const SfxUInt16Item& rItem = rSet->Get( SID_ATTR_METRIC ); + FieldUnit eFieldUnit = static_cast<FieldUnit>(rItem.GetValue()); + ::SetFieldUnit( *m_xRowMoveMF, eFieldUnit ); + ::SetFieldUnit( *m_xColMoveMF, eFieldUnit ); + ::SetFieldUnit( *m_xRowInsertMF, eFieldUnit ); + ::SetFieldUnit( *m_xColInsertMF, eFieldUnit ); + } + + m_xRowMoveMF->set_value(m_xRowMoveMF->normalize(pModOpt->GetTableHMove()), FieldUnit::TWIP); + m_xColMoveMF->set_value(m_xColMoveMF->normalize(pModOpt->GetTableVMove()), FieldUnit::TWIP); + m_xRowInsertMF->set_value(m_xRowInsertMF->normalize(pModOpt->GetTableHInsert()), FieldUnit::TWIP); + m_xColInsertMF->set_value(m_xColInsertMF->normalize(pModOpt->GetTableVInsert()), FieldUnit::TWIP); + + switch(pModOpt->GetTableMode()) + { + case TableChgMode::FixedWidthChangeAbs: m_xFixRB->set_active(true); break; + case TableChgMode::FixedWidthChangeProp: m_xFixPropRB->set_active(true); break; + case TableChgMode::VarWidthChangeAbs: m_xVarRB->set_active(true); break; + } + if(const SfxUInt16Item* pItem = rSet->GetItemIfSet(SID_HTML_MODE, false)) + { + m_bHTMLMode = 0 != (pItem->GetValue() & HTMLMODE_ON); + } + + // hide certain controls for html + if (m_bHTMLMode) + { + m_xRepeatHeaderCB->hide(); + m_xDontSplitCB->hide(); + } + + SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(m_bHTMLMode); + const SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode; + + m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline)); + m_xRepeatHeaderCB->set_active((!m_bHTMLMode) && (aInsOpts.mnRowsToRepeat > 0)); + m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout)); + m_xBorderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::DefaultBorder)); + + m_xNumFormattingCB->set_active(pModOpt->IsInsTableFormatNum(m_bHTMLMode)); + m_xNumFormatFormattingCB->set_active(pModOpt->IsInsTableChangeNumFormat(m_bHTMLMode)); + m_xNumAlignmentCB->set_active(pModOpt->IsInsTableAlignNum(m_bHTMLMode)); + + m_xHeaderCB->save_state(); + m_xRepeatHeaderCB->save_state(); + m_xDontSplitCB->save_state(); + m_xBorderCB->save_state(); + m_xNumFormattingCB->save_state(); + m_xNumFormatFormattingCB->save_state(); + m_xNumAlignmentCB->save_state(); + m_xRowMoveMF->save_value(); + m_xColMoveMF->save_value(); + m_xRowInsertMF->save_value(); + m_xColInsertMF->save_value(); + + CheckBoxHdl(*m_xHeaderCB); +} + +IMPL_LINK_NOARG(SwTableOptionsTabPage, CheckBoxHdl, weld::Toggleable&, void) +{ + m_xNumFormatFormattingCB->set_sensitive(m_xNumFormattingCB->get_active()); + m_xNumAlignmentCB->set_sensitive(m_xNumFormattingCB->get_active()); + m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active()); +} + +void SwTableOptionsTabPage::PageCreated( const SfxAllItemSet& aSet) +{ + const SwWrtShellItem* pWrtSh = aSet.GetItem<SwWrtShellItem>(SID_WRT_SHELL, false); + if (pWrtSh) + m_pWrtShell = pWrtSh->GetValue(); +} + +SwShdwCursorOptionsTabPage::SwShdwCursorOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optformataidspage.ui", "OptFormatAidsPage", &rSet) + , m_pWrtShell(nullptr) + , m_xParaCB(m_xBuilder->weld_check_button("paragraph")) + , m_xSHyphCB(m_xBuilder->weld_check_button("hyphens")) + , m_xSpacesCB(m_xBuilder->weld_check_button("spaces")) + , m_xHSpacesCB(m_xBuilder->weld_check_button("nonbreak")) + , m_xTabCB(m_xBuilder->weld_check_button("tabs")) + , m_xTabLabel(m_xBuilder->weld_label("tabs_label")) + , m_xBreakCB(m_xBuilder->weld_check_button("break")) + , m_xCharHiddenCB(m_xBuilder->weld_check_button("hiddentext")) + , m_xBookmarkCB(m_xBuilder->weld_check_button("bookmarks")) + , m_xBookmarkLabel(m_xBuilder->weld_label("bookmarks_label")) + , m_xDirectCursorFrame(m_xBuilder->weld_frame("directcrsrframe")) + , m_xOnOffCB(m_xBuilder->weld_check_button("cursoronoff")) + , m_xDirectCursorFillMode(m_xBuilder->weld_combo_box("cxDirectCursorFillMode")) + , m_xCursorProtFrame(m_xBuilder->weld_frame("crsrprotframe")) + , m_xImageFrame(m_xBuilder->weld_frame("frmImage")) + , m_xCursorInProtCB(m_xBuilder->weld_check_button("cursorinprot")) + , m_xDefaultAnchorType(m_xBuilder->weld_combo_box("cxDefaultAnchor")) + , m_xMathBaselineAlignmentCB(m_xBuilder->weld_check_button("mathbaseline")) +{ + SwFillMode eMode = SwFillMode::Tab; + bool bIsOn = false; + + if( const SwShadowCursorItem* pItem = rSet.GetItemIfSet( FN_PARAM_SHADOWCURSOR, false )) + { + eMode = pItem->GetMode(); + bIsOn = pItem->IsOn(); + } + m_xOnOffCB->set_active( bIsOn ); + + m_xDirectCursorFillMode->set_active( static_cast<int>(eMode) ); + const SfxUInt16Item* pHtmlModeItem = rSet.GetItemIfSet(SID_HTML_MODE, false); + if(!pHtmlModeItem || !(pHtmlModeItem->GetValue() & HTMLMODE_ON)) + return; + + m_xTabCB->hide(); + m_xTabLabel->hide(); + m_xCharHiddenCB->hide(); + m_xBookmarkCB->hide(); + m_xBookmarkLabel->hide(); + + m_xDirectCursorFrame->hide(); + m_xOnOffCB->hide(); + m_xDirectCursorFillMode->hide(); + m_xCursorProtFrame->hide(); + m_xCursorInProtCB->hide(); + m_xImageFrame->hide(); +} + +SwShdwCursorOptionsTabPage::~SwShdwCursorOptionsTabPage() +{ +} + +std::unique_ptr<SfxTabPage> SwShdwCursorOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet ) +{ + return std::make_unique<SwShdwCursorOptionsTabPage>(pPage, pController, *rSet); +} + +void SwShdwCursorOptionsTabPage::PageCreated( const SfxAllItemSet& aSet ) +{ + const SwWrtShellItem* pWrtSh = aSet.GetItem<SwWrtShellItem>(SID_WRT_SHELL, false); + if (pWrtSh) + m_pWrtShell = pWrtSh->GetValue(); +} + +bool SwShdwCursorOptionsTabPage::FillItemSet( SfxItemSet* rSet ) +{ + SwShadowCursorItem aOpt; + aOpt.SetOn( m_xOnOffCB->get_active() ); + + SwFillMode eMode = static_cast<SwFillMode>(m_xDirectCursorFillMode->get_active()); + aOpt.SetMode( eMode ); + + bool bRet = false; + const SwShadowCursorItem* pShadowCursorItem = rSet->GetItemIfSet( FN_PARAM_SHADOWCURSOR, false ); + if( !pShadowCursorItem || *pShadowCursorItem != aOpt ) + { + rSet->Put( aOpt ); + bRet = true; + } + + if (m_pWrtShell) { + m_pWrtShell->GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::MATH_BASELINE_ALIGNMENT, + m_xMathBaselineAlignmentCB->get_active() ); + bRet |= m_xMathBaselineAlignmentCB->get_state_changed_from_saved(); + } + + if( m_xCursorInProtCB->get_state_changed_from_saved()) + { + rSet->Put(SfxBoolItem(FN_PARAM_CRSR_IN_PROTECTED, m_xCursorInProtCB->get_active())); + bRet = true; + } + + const SwDocDisplayItem* pOldAttr = GetOldItem(GetItemSet(), FN_PARAM_DOCDISP); + + SwDocDisplayItem aDisp; + + aDisp.m_bParagraphEnd = m_xParaCB->get_active(); + aDisp.m_bTab = m_xTabCB->get_active(); + aDisp.m_bSpace = m_xSpacesCB->get_active(); + aDisp.m_bNonbreakingSpace = m_xHSpacesCB->get_active(); + aDisp.m_bSoftHyphen = m_xSHyphCB->get_active(); + aDisp.m_bCharHiddenText = m_xCharHiddenCB->get_active(); + aDisp.m_bBookmarks = m_xBookmarkCB->get_active(); + aDisp.m_bManualBreak = m_xBreakCB->get_active(); + aDisp.m_xDefaultAnchor = m_xDefaultAnchorType->get_active(); + + bRet |= (!pOldAttr || aDisp != *pOldAttr); + if(bRet) + bRet = nullptr != rSet->Put(aDisp); + + return bRet; +} + +void SwShdwCursorOptionsTabPage::Reset( const SfxItemSet* rSet ) +{ + SwFillMode eMode = SwFillMode::Tab; + bool bIsOn = false; + + if( const SwShadowCursorItem* pItem = rSet->GetItemIfSet( FN_PARAM_SHADOWCURSOR, false )) + { + eMode = pItem->GetMode(); + bIsOn = pItem->IsOn(); + } + m_xOnOffCB->set_active( bIsOn ); + + m_xDirectCursorFillMode->set_active( static_cast<int>(eMode) ); + if (m_pWrtShell) { + m_xMathBaselineAlignmentCB->set_active( m_pWrtShell->GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ) ); + m_xMathBaselineAlignmentCB->save_state(); + } else { + m_xMathBaselineAlignmentCB->hide(); + } + + if( const SfxBoolItem* pItem = rSet->GetItemIfSet( FN_PARAM_CRSR_IN_PROTECTED, false ) ) + m_xCursorInProtCB->set_active(pItem->GetValue()); + m_xCursorInProtCB->save_state(); + + const SwDocDisplayItem* pDocDisplayAttr = rSet->GetItemIfSet( FN_PARAM_DOCDISP, false ); + if(pDocDisplayAttr) + { + m_xParaCB->set_active( pDocDisplayAttr->m_bParagraphEnd ); + m_xTabCB->set_active( pDocDisplayAttr->m_bTab ); + m_xSpacesCB->set_active( pDocDisplayAttr->m_bSpace ); + m_xHSpacesCB->set_active( pDocDisplayAttr->m_bNonbreakingSpace ); + m_xSHyphCB->set_active( pDocDisplayAttr->m_bSoftHyphen ); + m_xCharHiddenCB->set_active( pDocDisplayAttr->m_bCharHiddenText ); + m_xBookmarkCB->set_active(pDocDisplayAttr->m_bBookmarks); + m_xBreakCB->set_active( pDocDisplayAttr->m_bManualBreak ); + m_xDefaultAnchorType->set_active( pDocDisplayAttr->m_xDefaultAnchor ); + } +} + +namespace { + +// TabPage for Redlining +struct CharAttr +{ + sal_uInt16 nItemId; + sal_uInt16 nAttr; +}; + +} + +// Edit corresponds to Paste-attributes +CharAttr const aRedlineAttr[] = +{ + { SID_ATTR_CHAR_CASEMAP, sal_uInt16(SvxCaseMap::NotMapped) }, + { SID_ATTR_CHAR_WEIGHT, WEIGHT_BOLD }, + { SID_ATTR_CHAR_POSTURE, ITALIC_NORMAL }, + { SID_ATTR_CHAR_UNDERLINE, LINESTYLE_SINGLE }, + { SID_ATTR_CHAR_UNDERLINE, LINESTYLE_DOUBLE }, + { SID_ATTR_CHAR_STRIKEOUT, STRIKEOUT_SINGLE }, + { SID_ATTR_CHAR_CASEMAP, sal_uInt16(SvxCaseMap::Uppercase) }, + { SID_ATTR_CHAR_CASEMAP, sal_uInt16(SvxCaseMap::Lowercase) }, + { SID_ATTR_CHAR_CASEMAP, sal_uInt16(SvxCaseMap::SmallCaps) }, + { SID_ATTR_CHAR_CASEMAP, sal_uInt16(SvxCaseMap::Capitalize) }, + { SID_ATTR_BRUSH, 0 } +}; +// Items from aRedlineAttr relevant for InsertAttr: strikethrough is +// not used +static sal_uInt16 aInsertAttrMap[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 }; + +// Items from aRedlineAttr relevant for DeleteAttr: underline and +// double underline is not used +static sal_uInt16 aDeletedAttrMap[] = { 0, 1, 2, 5, 6, 7, 8, 9, 10 }; + +// Items from aRedlineAttr relevant for ChangeAttr: strikethrough is +// not used +static sal_uInt16 aChangedAttrMap[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 }; + +// Preview of selection +SwMarkPreview::SwMarkPreview() + : m_aTransCol(COL_TRANSPARENT) + , m_aMarkCol(COL_LIGHTRED) + , nMarkPos(0) + +{ + InitColors(); +} + +SwMarkPreview::~SwMarkPreview() +{ +} + +void SwMarkPreview::InitColors() +{ + // m_aTransCol and m_aMarkCol are _not_ changed because they are set from outside! + + const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + m_aBgCol = rSettings.GetWindowColor(); + + bool bHC = rSettings.GetHighContrastMode(); + m_aLineCol = bHC? SwViewOption::GetFontColor() : COL_BLACK; + m_aShadowCol = bHC? m_aBgCol : rSettings.GetShadowColor(); + m_aTextCol = bHC? SwViewOption::GetFontColor() : COL_GRAY; + m_aPrintAreaCol = m_aTextCol; +} + +void SwMarkPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle &/*rRect*/) +{ + const Size aSz(GetOutputSizePixel()); + + // Page + aPage.SetSize(Size(aSz.Width() - 3, aSz.Height() - 3)); + + const tools::Long nOutWPix = aPage.GetWidth(); + const tools::Long nOutHPix = aPage.GetHeight(); + + // PrintArea + const tools::Long nLBorder = 8; + const tools::Long nRBorder = 8; + const tools::Long nTBorder = 4; + const tools::Long nBBorder = 4; + + aLeftPagePrtArea = tools::Rectangle(Point(nLBorder, nTBorder), Point((nOutWPix - 1) - nRBorder, (nOutHPix - 1) - nBBorder)); + const tools::Long nWidth = aLeftPagePrtArea.GetWidth(); + const tools::Long nCorr = (nWidth & 1) != 0 ? 0 : 1; + aLeftPagePrtArea.SetSize(Size(nWidth / 2 - (nLBorder + nRBorder) / 2 + nCorr, aLeftPagePrtArea.GetHeight())); + + aRightPagePrtArea = aLeftPagePrtArea; + aRightPagePrtArea.Move(aLeftPagePrtArea.GetWidth() + nLBorder + nRBorder + 1, 0); + + // draw shadow + tools::Rectangle aShadow(aPage); + aShadow += Point(3, 3); + drawRect(rRenderContext, aShadow, m_aShadowCol, m_aTransCol); + + // draw page + drawRect(rRenderContext, aPage, m_aBgCol, m_aLineCol); + + // draw separator + tools::Rectangle aPageSeparator(aPage); + aPageSeparator.SetSize(Size(2, aPageSeparator.GetHeight())); + aPageSeparator.Move(aPage.GetWidth() / 2 - 1, 0); + drawRect(rRenderContext, aPageSeparator, m_aLineCol, m_aTransCol); + + PaintPage(rRenderContext, aLeftPagePrtArea); + PaintPage(rRenderContext, aRightPagePrtArea); + + tools::Rectangle aLeftMark(Point(aPage.Left() + 2, aLeftPagePrtArea.Top() + 4), Size(aLeftPagePrtArea.Left() - 4, 2)); + tools::Rectangle aRightMark(Point(aRightPagePrtArea.Right() + 2, aRightPagePrtArea.Bottom() - 6), Size(aLeftPagePrtArea.Left() - 4, 2)); + + switch (nMarkPos) + { + case 1: // left + aRightMark.SetPos(Point(aRightPagePrtArea.Left() - 2 - aRightMark.GetWidth(), aRightMark.Top())); + break; + + case 2: // right + aLeftMark.SetPos(Point(aLeftPagePrtArea.Right() + 2, aLeftMark.Top())); + break; + + case 3: // outside + break; + + case 4: // inside + aLeftMark.SetPos(Point(aLeftPagePrtArea.Right() + 2, aLeftMark.Top())); + aRightMark.SetPos(Point(aRightPagePrtArea.Left() - 2 - aRightMark.GetWidth(), aRightMark.Top())); + break; + + case 0: // none + default: + return; + } + drawRect(rRenderContext, aLeftMark, m_aMarkCol, m_aTransCol); + drawRect(rRenderContext, aRightMark, m_aMarkCol, m_aTransCol); +} + +void SwMarkPreview::PaintPage(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect) +{ + // draw PrintArea + drawRect(rRenderContext, rRect, m_aTransCol, m_aPrintAreaCol); + + // draw Testparagraph + + tools::Rectangle aTextLine = rRect; + aTextLine.SetSize(Size(aTextLine.GetWidth(), 2)); + aTextLine.AdjustLeft(4 ); + aTextLine.AdjustRight( -4 ); + aTextLine.Move(0, 4); + + const tools::Long nStep = aTextLine.GetHeight() + 2; + const tools::Long nLines = rRect.GetHeight() / (aTextLine.GetHeight() + 2) - 1; + + // simulate text + for (tools::Long i = 0; i < nLines; ++i) + { + if (i == (nLines - 1)) + aTextLine.SetSize(Size(aTextLine.GetWidth() / 2, aTextLine.GetHeight())); + + if (aPage.Contains(aTextLine)) + drawRect(rRenderContext, aTextLine, m_aTextCol, m_aTransCol); + + aTextLine.Move(0, nStep); + } + aTextLine.Move(0, -nStep); +} + +void SwMarkPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea) +{ + Size aInitialSize = getPreviewOptionsSize(pDrawingArea->get_ref_device()); + pDrawingArea->set_size_request(aInitialSize.Width(), aInitialSize.Height()); + weld::CustomWidgetController::SetDrawingArea(pDrawingArea); + SetOutputSizePixel(aInitialSize); +} + +namespace +{ + void lcl_FillRedlineAttrListBox( + weld::ComboBox& rLB, const AuthorCharAttr& rAttrToSelect, + const sal_uInt16* pAttrMap, const size_t nAttrMapSize) + { + for (size_t i = 0; i != nAttrMapSize; ++i) + { + CharAttr const & rAttr(aRedlineAttr[pAttrMap[i]]); + rLB.set_id(i, weld::toId(&rAttr)); + if (rAttr.nItemId == rAttrToSelect.m_nItemId && + rAttr.nAttr == rAttrToSelect.m_nAttr) + rLB.set_active(i); + } + } +} + +SwRedlineOptionsTabPage::SwRedlineOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optredlinepage.ui", "OptRedLinePage", &rSet) + , m_xInsertLB(m_xBuilder->weld_combo_box("insert")) + , m_xInsertColorLB(new ColorListBox(m_xBuilder->weld_menu_button("insertcolor"), + [this]{ return GetDialogController()->getDialog(); })) + , m_xInsertedPreviewWN(new SvxFontPrevWindow) + , m_xInsertedPreview(new weld::CustomWeld(*m_xBuilder, "insertedpreview", *m_xInsertedPreviewWN)) + , m_xDeletedLB(m_xBuilder->weld_combo_box("deleted")) + , m_xDeletedColorLB(new ColorListBox(m_xBuilder->weld_menu_button("deletedcolor"), + [this]{ return GetDialogController()->getDialog(); })) + , m_xDeletedPreviewWN(new SvxFontPrevWindow) + , m_xDeletedPreview(new weld::CustomWeld(*m_xBuilder, "deletedpreview", *m_xDeletedPreviewWN)) + , m_xChangedLB(m_xBuilder->weld_combo_box("changed")) + , m_xChangedColorLB(new ColorListBox(m_xBuilder->weld_menu_button("changedcolor"), + [this]{ return GetDialogController()->getDialog(); })) + , m_xChangedPreviewWN(new SvxFontPrevWindow) + , m_xChangedPreview(new weld::CustomWeld(*m_xBuilder, "changedpreview", *m_xChangedPreviewWN)) + , m_xMarkPosLB(m_xBuilder->weld_combo_box("markpos")) + , m_xMarkColorLB(new ColorListBox(m_xBuilder->weld_menu_button("markcolor"), + [this]{ return GetDialogController()->getDialog(); })) + , m_xMarkPreviewWN(new SwMarkPreview) + , m_xMarkPreview(new weld::CustomWeld(*m_xBuilder, "markpreview", *m_xMarkPreviewWN)) +{ + Size aPreviewSize(getPreviewOptionsSize(m_xMarkPreviewWN->GetDrawingArea()->get_ref_device())); + + m_xInsertColorLB->SetSlotId(SID_AUTHOR_COLOR, true); + m_xDeletedColorLB->SetSlotId(SID_AUTHOR_COLOR, true); + m_xChangedColorLB->SetSlotId(SID_AUTHOR_COLOR, true); + + m_xInsertedPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height()); + m_xDeletedPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height()); + m_xChangedPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height()); + m_xMarkPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height()); + + for (sal_Int32 i = 0, nEntryCount = m_xInsertLB->get_count(); i < nEntryCount; ++i) + { + const OUString sEntry(m_xInsertLB->get_text(i)); + m_xDeletedLB->append_text(sEntry); + m_xChangedLB->append_text(sEntry); + }; + + // remove strikethrough from insert and change and underline + double + // underline from delete + m_xInsertLB->remove(5); + m_xChangedLB->remove(5); + m_xDeletedLB->remove(4); + m_xDeletedLB->remove(3); + + Link<weld::ComboBox&,void> aLk = LINK(this, SwRedlineOptionsTabPage, AttribHdl); + m_xInsertLB->connect_changed( aLk ); + m_xDeletedLB->connect_changed( aLk ); + m_xChangedLB->connect_changed( aLk ); + + Link<ColorListBox&,void> aLk2 = LINK(this, SwRedlineOptionsTabPage, ColorHdl); + m_xInsertColorLB->SetSelectHdl( aLk2 ); + m_xDeletedColorLB->SetSelectHdl( aLk2 ); + m_xChangedColorLB->SetSelectHdl( aLk2 ); + + m_xMarkPosLB->connect_changed(LINK(this, SwRedlineOptionsTabPage, ChangedMaskPrevHdl)); + m_xMarkColorLB->SetSelectHdl(LINK(this, SwRedlineOptionsTabPage, ChangedMaskColorPrevHdl)); +} + +SwRedlineOptionsTabPage::~SwRedlineOptionsTabPage() +{ + m_xInsertColorLB.reset(); + m_xInsertedPreview.reset(); + m_xInsertedPreviewWN.reset(); + m_xDeletedColorLB.reset(); + m_xDeletedPreview.reset(); + m_xDeletedPreviewWN.reset(); + m_xChangedColorLB.reset(); + m_xChangedPreview.reset(); + m_xChangedPreviewWN.reset(); + m_xMarkColorLB.reset(); + m_xMarkPreview.reset(); + m_xMarkPreviewWN.reset(); +} + +std::unique_ptr<SfxTabPage> SwRedlineOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet) +{ + return std::make_unique<SwRedlineOptionsTabPage>(pPage, pController, *rSet); +} + +bool SwRedlineOptionsTabPage::FillItemSet( SfxItemSet* ) +{ + CharAttr *pAttr; + SwModuleOptions *pOpt = SW_MOD()->GetModuleConfig(); + + AuthorCharAttr aInsertedAttr; + AuthorCharAttr aDeletedAttr; + AuthorCharAttr aChangedAttr; + + AuthorCharAttr aOldInsertAttr(pOpt->GetInsertAuthorAttr()); + AuthorCharAttr aOldDeletedAttr(pOpt->GetDeletedAuthorAttr()); + AuthorCharAttr aOldChangedAttr(pOpt->GetFormatAuthorAttr()); + + Color nOldMarkColor = pOpt->GetMarkAlignColor(); + sal_uInt16 nOldMarkMode = pOpt->GetMarkAlignMode(); + + sal_Int32 nPos = m_xInsertLB->get_active(); + if (nPos != -1) + { + pAttr = weld::fromId<CharAttr*>(m_xInsertLB->get_id(nPos)); + aInsertedAttr.m_nItemId = pAttr->nItemId; + aInsertedAttr.m_nAttr = pAttr->nAttr; + aInsertedAttr.m_nColor = m_xInsertColorLB->GetSelectEntryColor(); + pOpt->SetInsertAuthorAttr(aInsertedAttr); + } + + nPos = m_xDeletedLB->get_active(); + if (nPos != -1) + { + pAttr = weld::fromId<CharAttr*>(m_xDeletedLB->get_id(nPos)); + aDeletedAttr.m_nItemId = pAttr->nItemId; + aDeletedAttr.m_nAttr = pAttr->nAttr; + aDeletedAttr.m_nColor = m_xDeletedColorLB->GetSelectEntryColor(); + pOpt->SetDeletedAuthorAttr(aDeletedAttr); + } + + nPos = m_xChangedLB->get_active(); + if (nPos != -1) + { + pAttr = weld::fromId<CharAttr*>(m_xChangedLB->get_id(nPos)); + aChangedAttr.m_nItemId = pAttr->nItemId; + aChangedAttr.m_nAttr = pAttr->nAttr; + aChangedAttr.m_nColor = m_xChangedColorLB->GetSelectEntryColor(); + pOpt->SetFormatAuthorAttr(aChangedAttr); + } + + nPos = 0; + switch (m_xMarkPosLB->get_active()) + { + case 0: nPos = text::HoriOrientation::NONE; break; + case 1: nPos = text::HoriOrientation::LEFT; break; + case 2: nPos = text::HoriOrientation::RIGHT; break; + case 3: nPos = text::HoriOrientation::OUTSIDE; break; + case 4: nPos = text::HoriOrientation::INSIDE; break; + } + pOpt->SetMarkAlignMode(nPos); + pOpt->SetMarkAlignColor(m_xMarkColorLB->GetSelectEntryColor()); + + if (!(aInsertedAttr == aOldInsertAttr) || + !(aDeletedAttr == aOldDeletedAttr) || + !(aChangedAttr == aOldChangedAttr) || + nOldMarkColor != pOpt->GetMarkAlignColor() || + nOldMarkMode != pOpt->GetMarkAlignMode() ) + { + // update all documents + SwDocShell* pDocShell = static_cast<SwDocShell*>(SfxObjectShell::GetFirst(checkSfxObjectShell<SwDocShell>)); + + while( pDocShell ) + { + pDocShell->GetWrtShell()->UpdateRedlineAttr(); + pDocShell = static_cast<SwDocShell*>(SfxObjectShell::GetNext(*pDocShell, checkSfxObjectShell<SwDocShell>)); + } + } + + return false; +} + +void SwRedlineOptionsTabPage::Reset( const SfxItemSet* ) +{ + const SwModuleOptions *pOpt = SW_MOD()->GetModuleConfig(); + + const AuthorCharAttr &rInsertAttr = pOpt->GetInsertAuthorAttr(); + const AuthorCharAttr &rDeletedAttr = pOpt->GetDeletedAuthorAttr(); + const AuthorCharAttr &rChangedAttr = pOpt->GetFormatAuthorAttr(); + + // initialise preview + InitFontStyle(*m_xInsertedPreviewWN, SwResId(STR_OPT_PREVIEW_INSERTED)); + InitFontStyle(*m_xDeletedPreviewWN, SwResId(STR_OPT_PREVIEW_DELETED)); + InitFontStyle(*m_xChangedPreviewWN, SwResId(STR_OPT_PREVIEW_CHANGED)); + + Color nColor = rInsertAttr.m_nColor; + m_xInsertColorLB->SelectEntry(nColor); + + nColor = rDeletedAttr.m_nColor; + m_xDeletedColorLB->SelectEntry(nColor); + + nColor = rChangedAttr.m_nColor; + m_xChangedColorLB->SelectEntry(nColor); + + m_xMarkColorLB->SelectEntry(pOpt->GetMarkAlignColor()); + + m_xInsertLB->set_active(0); + m_xDeletedLB->set_active(0); + m_xChangedLB->set_active(0); + + lcl_FillRedlineAttrListBox(*m_xInsertLB, rInsertAttr, aInsertAttrMap, SAL_N_ELEMENTS(aInsertAttrMap)); + lcl_FillRedlineAttrListBox(*m_xDeletedLB, rDeletedAttr, aDeletedAttrMap, SAL_N_ELEMENTS(aDeletedAttrMap)); + lcl_FillRedlineAttrListBox(*m_xChangedLB, rChangedAttr, aChangedAttrMap, SAL_N_ELEMENTS(aChangedAttrMap)); + + sal_Int32 nPos = 0; + switch (pOpt->GetMarkAlignMode()) + { + case text::HoriOrientation::NONE: nPos = 0; break; + case text::HoriOrientation::LEFT: nPos = 1; break; + case text::HoriOrientation::RIGHT: nPos = 2; break; + case text::HoriOrientation::OUTSIDE: nPos = 3; break; + case text::HoriOrientation::INSIDE: nPos = 4; break; + } + m_xMarkPosLB->set_active(nPos); + + // show settings in preview + AttribHdl(*m_xInsertLB); + ColorHdl(*m_xInsertColorLB); + AttribHdl(*m_xDeletedLB); + ColorHdl(*m_xInsertColorLB); + AttribHdl(*m_xChangedLB); + ColorHdl(*m_xChangedColorLB); + + ChangedMaskPrev(); +} + +IMPL_LINK( SwRedlineOptionsTabPage, AttribHdl, weld::ComboBox&, rLB, void ) +{ + SvxFontPrevWindow *pPrev = nullptr; + ColorListBox *pColorLB; + + if (&rLB == m_xInsertLB.get()) + { + pColorLB = m_xInsertColorLB.get(); + pPrev = m_xInsertedPreviewWN.get(); + } + else if (&rLB == m_xDeletedLB.get()) + { + pColorLB = m_xDeletedColorLB.get(); + pPrev = m_xDeletedPreviewWN.get(); + } + else + { + pColorLB = m_xChangedColorLB.get(); + pPrev = m_xChangedPreviewWN.get(); + } + + SvxFont& rFont = pPrev->GetFont(); + SvxFont& rCJKFont = pPrev->GetCJKFont(); + + rFont.SetWeight(WEIGHT_NORMAL); + rCJKFont.SetWeight(WEIGHT_NORMAL); + rFont.SetItalic(ITALIC_NONE); + rCJKFont.SetItalic(ITALIC_NONE); + rFont.SetUnderline(LINESTYLE_NONE); + rCJKFont.SetUnderline(LINESTYLE_NONE); + rFont.SetStrikeout(STRIKEOUT_NONE); + rCJKFont.SetStrikeout(STRIKEOUT_NONE); + rFont.SetCaseMap(SvxCaseMap::NotMapped); + rCJKFont.SetCaseMap(SvxCaseMap::NotMapped); + + Color aColor = pColorLB->GetSelectEntryColor(); + + if (aColor == COL_NONE_COLOR) + { + rFont.SetColor( COL_BLACK ); + rCJKFont.SetColor( COL_BLACK ); + } + else if (aColor == COL_TRANSPARENT) + { + rFont.SetColor( COL_RED ); + rCJKFont.SetColor( COL_RED ); + } + else + { + rFont.SetColor(aColor); + rCJKFont.SetColor(aColor); + } + + sal_Int32 nPos = rLB.get_active(); + if( nPos == -1) + nPos = 0; + + CharAttr* pAttr = weld::fromId<CharAttr*>(rLB.get_id(nPos)); + //switch off preview background color + pPrev->ResetColor(); + switch (pAttr->nItemId) + { + case SID_ATTR_CHAR_WEIGHT: + rFont.SetWeight( static_cast<FontWeight>(pAttr->nAttr) ); + rCJKFont.SetWeight( static_cast<FontWeight>(pAttr->nAttr) ); + break; + + case SID_ATTR_CHAR_POSTURE: + rFont.SetItalic( static_cast<FontItalic>(pAttr->nAttr) ); + rCJKFont.SetItalic( static_cast<FontItalic>(pAttr->nAttr) ); + break; + + case SID_ATTR_CHAR_UNDERLINE: + rFont.SetUnderline( static_cast<FontLineStyle>(pAttr->nAttr) ); + rCJKFont.SetUnderline( static_cast<FontLineStyle>(pAttr->nAttr) ); + break; + + case SID_ATTR_CHAR_STRIKEOUT: + rFont.SetStrikeout( static_cast<FontStrikeout>(pAttr->nAttr) ); + rCJKFont.SetStrikeout( static_cast<FontStrikeout>(pAttr->nAttr) ); + break; + + case SID_ATTR_CHAR_CASEMAP: + rFont.SetCaseMap( static_cast<SvxCaseMap>(pAttr->nAttr) ); + rCJKFont.SetCaseMap( static_cast<SvxCaseMap>(pAttr->nAttr) ); + break; + + case SID_ATTR_BRUSH: + { + Color aBgColor = pColorLB->GetSelectEntryColor(); + if (aBgColor != COL_NONE_COLOR) + pPrev->SetColor(aBgColor); + else + pPrev->SetColor(COL_LIGHTGRAY); + rFont.SetColor( COL_BLACK ); + rCJKFont.SetColor( COL_BLACK ); + } + break; + } + + pPrev->Invalidate(); +} + +IMPL_LINK(SwRedlineOptionsTabPage, ColorHdl, ColorListBox&, rListBox, void) +{ + ColorListBox* pColorLB = &rListBox; + SvxFontPrevWindow *pPrev = nullptr; + weld::ComboBox* pLB; + + if (pColorLB == m_xInsertColorLB.get()) + { + pLB = m_xInsertLB.get(); + pPrev = m_xInsertedPreviewWN.get(); + } + else if (pColorLB == m_xDeletedColorLB.get()) + { + pLB = m_xDeletedLB.get(); + pPrev = m_xDeletedPreviewWN.get(); + } + else + { + pLB = m_xChangedLB.get(); + pPrev = m_xChangedPreviewWN.get(); + } + + SvxFont& rFont = pPrev->GetFont(); + SvxFont& rCJKFont = pPrev->GetCJKFont(); + sal_Int32 nPos = pLB->get_active(); + if( nPos == -1) + nPos = 0; + + CharAttr* pAttr = weld::fromId<CharAttr*>(pLB->get_id(nPos)); + + if( pAttr->nItemId == SID_ATTR_BRUSH ) + { + rFont.SetColor( COL_BLACK ); + rCJKFont.SetColor( COL_BLACK ); + + Color aBgColor = pColorLB->GetSelectEntryColor(); + if (aBgColor != COL_NONE_COLOR) + pPrev->SetColor(aBgColor); + else + pPrev->SetColor(COL_LIGHTGRAY); + } + else + { + Color aColor = pColorLB->GetSelectEntryColor(); + + if (aColor == COL_NONE_COLOR) + { + rFont.SetColor( COL_BLACK ); + rCJKFont.SetColor( COL_BLACK ); + } + else if (aColor == COL_TRANSPARENT) + { + rFont.SetColor( COL_RED ); + rCJKFont.SetColor( COL_RED ); + } + else + { + rFont.SetColor(aColor); + rCJKFont.SetColor(aColor); + } + } + + pPrev->Invalidate(); +} + +void SwRedlineOptionsTabPage::ChangedMaskPrev() +{ + m_xMarkPreviewWN->SetMarkPos(m_xMarkPosLB->get_active()); + m_xMarkPreviewWN->SetColor(m_xMarkColorLB->GetSelectEntryColor()); + + m_xMarkPreviewWN->Invalidate(); +} + +IMPL_LINK_NOARG(SwRedlineOptionsTabPage, ChangedMaskPrevHdl, weld::ComboBox&, void) +{ + ChangedMaskPrev(); +} + +IMPL_LINK_NOARG(SwRedlineOptionsTabPage, ChangedMaskColorPrevHdl, ColorListBox&, void) +{ + ChangedMaskPrev(); +} + +void SwRedlineOptionsTabPage::InitFontStyle(SvxFontPrevWindow& rExampleWin, const OUString& rText) +{ + const AllSettings& rAllSettings = Application::GetSettings(); + LanguageType eLangType = rAllSettings.GetUILanguageTag().getLanguageType(); + Color aBackCol( rAllSettings.GetStyleSettings().GetWindowColor() ); + SvxFont& rFont = rExampleWin.GetFont(); + SvxFont& rCJKFont = rExampleWin.GetCJKFont(); + SvxFont& rCTLFont = rExampleWin.GetCTLFont(); + + OutputDevice& rDevice = rExampleWin.GetDrawingArea()->get_ref_device(); + + vcl::Font aFont( OutputDevice::GetDefaultFont( DefaultFontType::SERIF, eLangType, + GetDefaultFontFlags::OnlyOne, &rDevice ) ); + vcl::Font aCJKFont( OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT, eLangType, + GetDefaultFontFlags::OnlyOne, &rDevice ) ); + vcl::Font aCTLFont( OutputDevice::GetDefaultFont( DefaultFontType::CTL_TEXT, eLangType, + GetDefaultFontFlags::OnlyOne, &rDevice ) ); + const Size aDefSize( 0, 12 ); + aFont.SetFontSize( aDefSize ); + aCJKFont.SetFontSize( aDefSize ); + aCTLFont.SetFontSize( aDefSize ); + + aFont.SetFillColor( aBackCol ); + aCJKFont.SetFillColor( aBackCol ); + aCTLFont.SetFillColor( aBackCol ); + + aFont.SetWeight( WEIGHT_NORMAL ); + aCJKFont.SetWeight( WEIGHT_NORMAL ); + aCTLFont.SetWeight( WEIGHT_NORMAL ); + + rFont = aFont; + rCJKFont = aCJKFont; + rCTLFont = aCTLFont; + + const Size aNewSize( 0, rExampleWin.GetOutputSizePixel().Height() * 2 / 3 ); + rFont.SetFontSize( aNewSize ); + rCJKFont.SetFontSize( aNewSize ); + + rExampleWin.SetFont( rFont, rCJKFont,rCTLFont ); + rExampleWin.SetPreviewText(rText); +} + +SwCompareOptionsTabPage::SwCompareOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/optcomparison.ui", "OptComparison", &rSet) + , m_xAutoRB(m_xBuilder->weld_radio_button("auto")) + , m_xWordRB(m_xBuilder->weld_radio_button("byword")) + , m_xCharRB(m_xBuilder->weld_radio_button("bycharacter")) + , m_xRsidCB(m_xBuilder->weld_check_button("useRSID")) + , m_xIgnoreCB(m_xBuilder->weld_check_button("ignore")) + , m_xLenNF(m_xBuilder->weld_spin_button("ignorelen")) + , m_xStoreRsidCB(m_xBuilder->weld_check_button("storeRSID")) +{ + Link<weld::Toggleable&,void> aLnk( LINK( this, SwCompareOptionsTabPage, ComparisonHdl ) ); + m_xAutoRB->connect_toggled( aLnk ); + m_xWordRB->connect_toggled( aLnk ); + m_xCharRB->connect_toggled( aLnk ); + + m_xIgnoreCB->connect_toggled( LINK( this, SwCompareOptionsTabPage, IgnoreHdl) ); +} + +SwCompareOptionsTabPage::~SwCompareOptionsTabPage() +{ +} + +std::unique_ptr<SfxTabPage> SwCompareOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet ) +{ + return std::make_unique<SwCompareOptionsTabPage>(pPage, pController, *rAttrSet); +} + +bool SwCompareOptionsTabPage::FillItemSet( SfxItemSet* ) +{ + bool bRet = false; + SwModuleOptions *pOpt = SW_MOD()->GetModuleConfig(); + + if( m_xAutoRB->get_state_changed_from_saved() || + m_xWordRB->get_state_changed_from_saved() || + m_xCharRB->get_state_changed_from_saved() ) + { + SwCompareMode eCmpMode = SwCompareMode::Auto; + + if ( m_xAutoRB->get_active() ) eCmpMode = SwCompareMode::Auto; + if ( m_xWordRB->get_active() ) eCmpMode = SwCompareMode::ByWord; + if ( m_xCharRB->get_active() ) eCmpMode = SwCompareMode::ByChar; + + pOpt->SetCompareMode( eCmpMode ); + bRet = true; + } + + if( m_xRsidCB->get_state_changed_from_saved() ) + { + pOpt->SetUseRsid( m_xRsidCB->get_active() ); + bRet = true; + } + + if( m_xIgnoreCB->get_state_changed_from_saved() ) + { + pOpt->SetIgnorePieces( m_xIgnoreCB->get_active() ); + bRet = true; + } + + if( m_xLenNF->get_value_changed_from_saved() ) + { + pOpt->SetPieceLen( m_xLenNF->get_value() ); + bRet = true; + } + + if (m_xStoreRsidCB->get_state_changed_from_saved()) + { + pOpt->SetStoreRsid(m_xStoreRsidCB->get_active()); + bRet = true; + } + + return bRet; +} + +void SwCompareOptionsTabPage::Reset( const SfxItemSet* ) +{ + SwModuleOptions *pOpt = SW_MOD()->GetModuleConfig(); + + SwCompareMode eCmpMode = pOpt->GetCompareMode(); + if( eCmpMode == SwCompareMode::Auto ) + { + m_xAutoRB->set_active(true); + m_xRsidCB->set_sensitive(false); + m_xIgnoreCB->set_sensitive(false); + m_xLenNF->set_sensitive(false); + } + else if( eCmpMode == SwCompareMode::ByWord ) + { + m_xWordRB->set_active(true); + m_xRsidCB->set_sensitive(true); + m_xIgnoreCB->set_sensitive(true); + m_xLenNF->set_sensitive(true); + } + else if( eCmpMode == SwCompareMode::ByChar) + { + m_xCharRB->set_active(true); + m_xRsidCB->set_sensitive(true); + m_xIgnoreCB->set_sensitive(true); + m_xLenNF->set_sensitive(true); + } + m_xAutoRB->save_state(); + m_xWordRB->save_state(); + m_xCharRB->save_state(); + + m_xRsidCB->set_active( pOpt->IsUseRsid() ); + m_xRsidCB->save_state(); + + m_xIgnoreCB->set_active( pOpt->IsIgnorePieces() ); + m_xIgnoreCB->save_state(); + + m_xLenNF->set_sensitive( m_xIgnoreCB->get_active() && eCmpMode != SwCompareMode::Auto ); + + m_xLenNF->set_value( pOpt->GetPieceLen() ); + m_xLenNF->save_value(); + + m_xStoreRsidCB->set_active(pOpt->IsStoreRsid()); + m_xStoreRsidCB->save_state(); +} + +IMPL_LINK(SwCompareOptionsTabPage, ComparisonHdl, weld::Toggleable&, rButton, void) +{ + if (!rButton.get_active()) + return; + + bool bChecked = !m_xAutoRB->get_active(); + m_xRsidCB->set_sensitive( bChecked ); + m_xIgnoreCB->set_sensitive( bChecked ); + m_xLenNF->set_sensitive( bChecked && m_xIgnoreCB->get_active() ); +} + +IMPL_LINK_NOARG(SwCompareOptionsTabPage, IgnoreHdl, weld::Toggleable&, void) +{ + m_xLenNF->set_sensitive(m_xIgnoreCB->get_active()); +} + +#ifdef DBG_UTIL + +SwTestTabPage::SwTestTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet) + : SfxTabPage(pPage, pController, "modules/swriter/ui/opttestpage.ui", "OptTestPage", &rCoreSet) + , bAttrModified( false ) + , m_xTest1CBox(m_xBuilder->weld_check_button("unused")) + , m_xTest2CBox(m_xBuilder->weld_check_button("dynamic")) + , m_xTest3CBox(m_xBuilder->weld_check_button("nocalm")) + , m_xTest4CBox(m_xBuilder->weld_check_button("wysiwygdbg")) + , m_xTest5CBox(m_xBuilder->weld_check_button("noidle")) + , m_xTest6CBox(m_xBuilder->weld_check_button("noscreenadj")) + , m_xTest7CBox(m_xBuilder->weld_check_button("winformat")) + , m_xTest8CBox(m_xBuilder->weld_check_button("noscroll")) + , m_xTest9CBox(m_xBuilder->weld_check_button("DrawingLayerNotLoading")) + , m_xTest10CBox(m_xBuilder->weld_check_button("AutoFormatByInput")) +{ + Init(); +} + +SwTestTabPage::~SwTestTabPage() +{ +} + +std::unique_ptr<SfxTabPage> SwTestTabPage::Create( weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet* rAttrSet ) +{ + return std::make_unique<SwTestTabPage>(pPage, pController, *rAttrSet); +} + +bool SwTestTabPage::FillItemSet( SfxItemSet* rCoreSet ) +{ + + if ( bAttrModified ) + { + SwTestItem aTestItem; + aTestItem.m_bTest1=m_xTest1CBox->get_active(); + aTestItem.m_bTest2=m_xTest2CBox->get_active(); + aTestItem.m_bTest3=m_xTest3CBox->get_active(); + aTestItem.m_bTest4=m_xTest4CBox->get_active(); + aTestItem.m_bTest5=m_xTest5CBox->get_active(); + aTestItem.m_bTest6=m_xTest6CBox->get_active(); + aTestItem.m_bTest7=m_xTest7CBox->get_active(); + aTestItem.m_bTest8=m_xTest8CBox->get_active(); + aTestItem.m_bTest9=m_xTest9CBox->get_active(); + aTestItem.m_bTest10=m_xTest10CBox->get_active(); + rCoreSet->Put(aTestItem); + } + return bAttrModified; +} + +void SwTestTabPage::Reset( const SfxItemSet* ) +{ + const SfxItemSet& rSet = GetItemSet(); + const SwTestItem* pTestAttr = rSet.GetItemIfSet( FN_PARAM_SWTEST, false ); + if(!pTestAttr) + 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() +{ + // handler + Link<weld::Toggleable&,void> aLk = LINK( this, SwTestTabPage, AutoClickHdl ); + m_xTest1CBox->connect_toggled( aLk ); + m_xTest2CBox->connect_toggled( aLk ); + m_xTest3CBox->connect_toggled( aLk ); + m_xTest4CBox->connect_toggled( aLk ); + m_xTest5CBox->connect_toggled( aLk ); + m_xTest6CBox->connect_toggled( aLk ); + m_xTest7CBox->connect_toggled( aLk ); + m_xTest8CBox->connect_toggled( aLk ); + m_xTest9CBox->connect_toggled( aLk ); + m_xTest10CBox->connect_toggled( aLk ); +} + +IMPL_LINK_NOARG(SwTestTabPage, AutoClickHdl, weld::Toggleable&, void) +{ + bAttrModified = true; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |