diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/source/uibase/sidebar | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
30 files changed, 5676 insertions, 0 deletions
diff --git a/sw/source/uibase/sidebar/PageColumnControl.cxx b/sw/source/uibase/sidebar/PageColumnControl.cxx new file mode 100644 index 000000000..1675867ac --- /dev/null +++ b/sw/source/uibase/sidebar/PageColumnControl.cxx @@ -0,0 +1,122 @@ +/* -*- 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 <memory> +#include "PageColumnControl.hxx" +#include <PageColumnPopup.hxx> + +#include <cmdid.h> + +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> +#include <svl/intitem.hxx> +#include <svx/pageitem.hxx> + +namespace sw::sidebar { + +PageColumnControl::PageColumnControl(PageColumnPopup* pControl, weld::Widget* pParent) + : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/swriter/ui/pagecolumncontrol.ui", "PageColumnControl") + , m_xMoreButton(m_xBuilder->weld_button("moreoptions")) + , m_xControl(pControl) +{ + bool bLandscape = false; + const SfxPoolItem *pItem; + if ( SfxViewFrame::Current() ) + { + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem ); + bLandscape = static_cast<const SvxPageItem*>(pItem)->IsLandscape(); + } + + if ( bLandscape ) + { + m_xOneColumn = m_xBuilder->weld_button("column1L"); + m_xTwoColumns = m_xBuilder->weld_button("column2L"); + m_xThreeColumns = m_xBuilder->weld_button("column3L"); + m_xLeft = m_xBuilder->weld_button("columnleftL"); + m_xRight = m_xBuilder->weld_button("columnrightL"); + } + else + { + m_xOneColumn = m_xBuilder->weld_button("column1"); + m_xTwoColumns = m_xBuilder->weld_button( "column2"); + m_xThreeColumns = m_xBuilder->weld_button("column3"); + m_xLeft = m_xBuilder->weld_button("columnleft"); + m_xRight = m_xBuilder->weld_button("columnright"); + } + + m_xOneColumn->show(); + m_xTwoColumns->show(); + m_xThreeColumns->show(); + m_xLeft->show(); + m_xRight->show(); + + m_xOneColumn->connect_clicked( LINK( this, PageColumnControl, ColumnButtonClickHdl_Impl ) ); + m_xTwoColumns->connect_clicked( LINK( this, PageColumnControl, ColumnButtonClickHdl_Impl ) ); + m_xThreeColumns->connect_clicked( LINK( this, PageColumnControl, ColumnButtonClickHdl_Impl ) ); + m_xLeft->connect_clicked( LINK( this, PageColumnControl, ColumnButtonClickHdl_Impl ) ); + m_xRight->connect_clicked( LINK( this, PageColumnControl, ColumnButtonClickHdl_Impl ) ); + + m_xMoreButton->connect_clicked( LINK( this, PageColumnControl, MoreButtonClickHdl_Impl ) ); +} + +void PageColumnControl::GrabFocus() +{ + m_xMoreButton->grab_focus(); +} + +PageColumnControl::~PageColumnControl() +{ +} + +void PageColumnControl::ExecuteColumnChange( const sal_uInt16 nColumnType ) +{ + std::unique_ptr<SfxInt16Item> mpPageColumnTypeItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN) ); + mpPageColumnTypeItem->SetValue( nColumnType ); + if ( SfxViewFrame::Current() ) + SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN, + SfxCallMode::RECORD, { mpPageColumnTypeItem.get() }); +} + +IMPL_LINK( PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button&, rButton, void ) +{ + if ( &rButton == m_xOneColumn.get() ) + ExecuteColumnChange( 1 ); + else if ( &rButton == m_xTwoColumns.get() ) + ExecuteColumnChange( 2 ); + else if ( &rButton == m_xThreeColumns.get() ) + ExecuteColumnChange( 3 ); + else if ( &rButton == m_xLeft.get() ) + ExecuteColumnChange( 4 ); + else if ( &rButton == m_xRight.get() ) + ExecuteColumnChange( 5 ); + + m_xControl->EndPopupMode(); +} + +IMPL_LINK_NOARG( PageColumnControl, MoreButtonClickHdl_Impl, weld::Button&, void ) +{ + if ( SfxViewFrame::Current() ) + SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( FN_FORMAT_PAGE_COLUMN_DLG, SfxCallMode::ASYNCHRON ); + m_xControl->EndPopupMode(); +} + +} // end of namespace sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageColumnControl.hxx b/sw/source/uibase/sidebar/PageColumnControl.hxx new file mode 100644 index 000000000..140c94872 --- /dev/null +++ b/sw/source/uibase/sidebar/PageColumnControl.hxx @@ -0,0 +1,56 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGECOLUMNCONTROL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGECOLUMNCONTROL_HXX + +#include <svtools/toolbarmenu.hxx> +#include <vcl/weld.hxx> + +class PageColumnPopup; + +namespace sw::sidebar { + +class PageColumnControl final : public WeldToolbarPopup +{ +public: + explicit PageColumnControl(PageColumnPopup* pControl, weld::Widget* pParent); + virtual void GrabFocus() override; + virtual ~PageColumnControl() override; + +private: + std::unique_ptr<weld::Button> m_xOneColumn; + std::unique_ptr<weld::Button> m_xTwoColumns; + std::unique_ptr<weld::Button> m_xThreeColumns; + std::unique_ptr<weld::Button> m_xLeft; + std::unique_ptr<weld::Button> m_xRight; + std::unique_ptr<weld::Button> m_xMoreButton; + + rtl::Reference<PageColumnPopup> m_xControl; + + static void ExecuteColumnChange( const sal_uInt16 nColumnType ); + + DECL_LINK( ColumnButtonClickHdl_Impl, weld::Button&, void ); + DECL_LINK( MoreButtonClickHdl_Impl, weld::Button&, void ); +}; + +} // end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageColumnPopup.cxx b/sw/source/uibase/sidebar/PageColumnPopup.cxx new file mode 100644 index 000000000..b0b9e07fc --- /dev/null +++ b/sw/source/uibase/sidebar/PageColumnPopup.cxx @@ -0,0 +1,76 @@ +/* -*- 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 <PageColumnPopup.hxx> +#include "PageColumnControl.hxx" +#include <svl/intitem.hxx> +#include <vcl/toolbox.hxx> + +PageColumnPopup::PageColumnPopup(const css::uno::Reference<css::uno::XComponentContext>& rContext) + : PopupWindowController(rContext, nullptr, OUString()) +{ +} + +void PageColumnPopup::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) +{ + PopupWindowController::initialize(rArguments); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) + pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWNONLY | pToolBox->GetItemBits(nId)); +} + +PageColumnPopup::~PageColumnPopup() +{ +} + +std::unique_ptr<WeldToolbarPopup> PageColumnPopup::weldPopupWindow() +{ + return std::make_unique<sw::sidebar::PageColumnControl>(this, m_pToolbar); +} + +VclPtr<vcl::Window> PageColumnPopup::createVclPopupWindow( vcl::Window* pParent ) +{ + mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, + std::make_unique<sw::sidebar::PageColumnControl>(this, pParent->GetFrameWeld())); + + mxInterimPopover->Show(); + + return mxInterimPopover; +} + +OUString PageColumnPopup::getImplementationName() +{ + return "lo.writer.PageColumnToolBoxControl"; +} + +css::uno::Sequence<OUString> PageColumnPopup::getSupportedServiceNames() +{ + return { "com.sun.star.frame.ToolbarController" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +lo_writer_PageColumnToolBoxControl_get_implementation( + css::uno::XComponentContext* rContext, + css::uno::Sequence<css::uno::Any> const & ) +{ + return cppu::acquire(new PageColumnPopup(rContext)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageFooterPanel.cxx b/sw/source/uibase/sidebar/PageFooterPanel.cxx new file mode 100644 index 000000000..f7efb76a0 --- /dev/null +++ b/sw/source/uibase/sidebar/PageFooterPanel.cxx @@ -0,0 +1,295 @@ +/* -*- 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 <svl/intitem.hxx> +#include <svl/eitem.hxx> +#include <svx/dlgutil.hxx> +#include <svx/rulritem.hxx> +#include <svx/svdtrans.hxx> +#include "PageFooterPanel.hxx" +#include <sfx2/dispatch.hxx> +#include <sfx2/bindings.hxx> +#include <cmdid.h> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +namespace sw::sidebar{ + +VclPtr<vcl::Window> PageFooterPanel::Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings) +{ + if( pParent == nullptr ) + throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFooterPanel::Create", nullptr, 0); + if( !rxFrame.is() ) + throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageFooterPanel::Create", nullptr, 0); + + return VclPtr<PageFooterPanel>::Create(pParent, rxFrame, pBindings); +} + +void PageFooterPanel::SetMarginsAndSpacingFieldUnit() +{ + SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxFooterSpacingLB); + SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxFooterMarginPresetLB); +} + +PageFooterPanel::PageFooterPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings) : + PanelLayout(pParent, "PageFooterPanel", "modules/swriter/ui/pagefooterpanel.ui", rxFrame), + mpBindings( pBindings ), + maHFToggleController(SID_ATTR_PAGE_FOOTER, *pBindings, *this), + maMetricController(SID_ATTR_METRIC, *pBindings,*this), + maFooterLRMarginController(SID_ATTR_PAGE_FOOTER_LRMARGIN, *pBindings, *this), + maFooterSpacingController(SID_ATTR_PAGE_FOOTER_SPACING, *pBindings, *this), + maFooterLayoutController(SID_ATTR_PAGE_FOOTER_LAYOUT, *pBindings, *this), + meFUnit(GetModuleFieldUnit()), + aCustomEntry(), + mpFooterItem( new SfxBoolItem(SID_ATTR_PAGE_FOOTER) ), + mpFooterLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_LRMARGIN)), + mpFooterSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_SPACING)), + mpFooterLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_FOOTER_LAYOUT)), + mxFooterToggle(m_xBuilder->weld_check_button("footertoggle")), + mxFooterSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")), + mxFooterMarginPresetLB(m_xBuilder->weld_combo_box("footermarginpreset")), + mxFooterLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")), + mxCustomEntry(m_xBuilder->weld_label("customlabel")) +{ + Initialize(); +} + +PageFooterPanel::~PageFooterPanel() +{ + disposeOnce(); +} + +void PageFooterPanel::dispose() +{ + mxFooterToggle.reset(); + maMetricController.dispose(); + mxFooterSpacingLB.reset(); + mxFooterLayoutLB.reset(); + mxFooterMarginPresetLB.reset(); + mxCustomEntry.reset(); + + PanelLayout::dispose(); +} + +FieldUnit PageFooterPanel::GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState) +{ + FieldUnit eUnit; + + if (pState && eState >= SfxItemState::DEFAULT) + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue()); + else + eUnit = GetModuleFieldUnit(); + + return eUnit; +} + +void PageFooterPanel::Initialize() +{ + SameContentListBox::Fill(*mxFooterLayoutLB); + + SetMarginsAndSpacingFieldUnit(); + + aCustomEntry = mxCustomEntry->get_label(); + mxFooterToggle->connect_toggled( LINK(this, PageFooterPanel, FooterToggleHdl) ); + mxFooterMarginPresetLB->connect_changed( LINK(this, PageFooterPanel, FooterLRMarginHdl)); + mxFooterSpacingLB->connect_changed( LINK(this, PageFooterPanel, FooterSpacingHdl)); + mxFooterLayoutLB->connect_changed( LINK(this, PageFooterPanel, FooterLayoutHdl)); + + mpBindings->Invalidate(SID_ATTR_METRIC); + mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER); + mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER_LRMARGIN); + mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER_SPACING); + mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER_LAYOUT); +} + +void PageFooterPanel::UpdateFooterCheck() +{ + if (mxFooterToggle->get_active()) + { + mxFooterSpacingLB->set_sensitive(true); + mxFooterLayoutLB->set_sensitive(true); + mxFooterMarginPresetLB->set_sensitive(true); + } + else + { + mxFooterSpacingLB->set_sensitive(false); + mxFooterLayoutLB->set_sensitive(false); + mxFooterMarginPresetLB->set_sensitive(false); + } +} + +void PageFooterPanel::UpdateMarginControl() +{ + sal_uInt16 nLeft = mpFooterLRMarginItem->GetLeft(); + sal_uInt16 nRight = mpFooterLRMarginItem->GetRight(); + sal_uInt16 nCount = mxFooterMarginPresetLB->get_count(); + if(nLeft == nRight) + { + for (sal_uInt16 i = 0; i < nCount; ++i) + { + if (mxFooterMarginPresetLB->get_id(i).toUInt32() == nLeft) + { + mxFooterMarginPresetLB->set_active(i); + int nCustomEntry = mxFooterMarginPresetLB->find_text(aCustomEntry); + if (nCustomEntry != -1) + mxFooterMarginPresetLB->remove(nCustomEntry); + return; + } + } + } + mxFooterMarginPresetLB->append_text(aCustomEntry); + mxFooterMarginPresetLB->set_active_text(aCustomEntry); +} + +void PageFooterPanel::UpdateSpacingControl() +{ + sal_uInt16 nBottom = mpFooterSpacingItem->GetUpper(); + sal_uInt16 nCount = mxFooterSpacingLB->get_count(); + for (sal_uInt16 i = 0; i < nCount; ++i) + { + if (mxFooterSpacingLB->get_id(i).toUInt32() == nBottom) + { + mxFooterSpacingLB->set_active(i); + int nCustomEntry = mxFooterSpacingLB->find_text(aCustomEntry); + if (nCustomEntry != -1) + mxFooterSpacingLB->remove(nCustomEntry); + return; + } + } + mxFooterSpacingLB->append_text(aCustomEntry); + mxFooterSpacingLB->set_active_text(aCustomEntry); +} + +void PageFooterPanel::UpdateLayoutControl() +{ + sal_uInt16 nLayout = mpFooterLayoutItem->GetValue(); + mxFooterLayoutLB->set_active(nLayout); +} + +void PageFooterPanel::NotifyItemUpdate( + const sal_uInt16 nSid, + const SfxItemState eState, + const SfxPoolItem* pState) +{ + if (IsDisposed()) + return; + + switch(nSid) + { + case SID_ATTR_PAGE_FOOTER: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SfxBoolItem*>( pState) ) + { + mpFooterItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) ); + mxFooterToggle->set_active(mpFooterItem->GetValue()); + UpdateFooterCheck(); + } + } + break; + case SID_ATTR_PAGE_FOOTER_LRMARGIN: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SvxLongLRSpaceItem*>( pState) ) + { + mpFooterLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) ); + UpdateMarginControl(); + } + } + break; + case SID_ATTR_PAGE_FOOTER_SPACING: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SvxLongULSpaceItem*>( pState) ) + { + mpFooterSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) ); + UpdateSpacingControl(); + } + } + break; + case SID_ATTR_PAGE_FOOTER_LAYOUT: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SfxInt16Item*>( pState) ) + { + mpFooterLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) ); + UpdateLayoutControl(); + } + } + break; + case SID_ATTR_METRIC: + { + FieldUnit eFUnit = GetCurrentUnit(eState, pState); + if (meFUnit != eFUnit) + { + meFUnit = eFUnit; + SetMarginsAndSpacingFieldUnit(); + UpdateSpacingControl(); + UpdateMarginControl(); + } + } + break; + default: + break; + } +} + +IMPL_LINK_NOARG( PageFooterPanel, FooterToggleHdl, weld::ToggleButton&, void ) +{ + bool IsChecked = mxFooterToggle->get_active(); + mpFooterItem->SetValue(IsChecked); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER, SfxCallMode::RECORD, { mpFooterItem.get() } ); + UpdateFooterCheck(); +} + +IMPL_LINK_NOARG( PageFooterPanel, FooterLRMarginHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nVal = mxFooterMarginPresetLB->get_active_id().toUInt32(); + mpFooterLRMarginItem->SetLeft(nVal); + mpFooterLRMarginItem->SetRight(nVal); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LRMARGIN, + SfxCallMode::RECORD, { mpFooterLRMarginItem.get() } ); +} + +IMPL_LINK_NOARG( PageFooterPanel, FooterSpacingHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nVal = mxFooterSpacingLB->get_active_id().toUInt32(); + mpFooterSpacingItem->SetUpper(nVal); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_SPACING, + SfxCallMode::RECORD, { mpFooterSpacingItem.get() } ); + +} +IMPL_LINK_NOARG( PageFooterPanel, FooterLayoutHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nVal = mxFooterLayoutLB->get_active(); + mpFooterLayoutItem->SetValue(nVal); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LAYOUT, + SfxCallMode::RECORD, { mpFooterLayoutItem.get() } ); +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageFooterPanel.hxx b/sw/source/uibase/sidebar/PageFooterPanel.hxx new file mode 100644 index 000000000..849a3165d --- /dev/null +++ b/sw/source/uibase/sidebar/PageFooterPanel.hxx @@ -0,0 +1,110 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEFOOTERPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEFOOTERPANEL_HXX + +#include <memory> +#include <com/sun/star/frame/XFrame.hpp> + +#include <sfx2/sidebar/PanelLayout.hxx> + +#include <sfx2/sidebar/ControllerItem.hxx> + +#include <svx/rulritem.hxx> + +#include <svl/intitem.hxx> +#include <svl/poolitem.hxx> +#include <svl/eitem.hxx> +#include <svx/spacinglistbox.hxx> +#include <svx/samecontentlistbox.hxx> + +namespace sw::sidebar { + +class PageFooterPanel: + public PanelLayout, + public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ +public: + static VclPtr<vcl::Window> Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + + virtual void NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + + SfxBindings* GetBindings() const { return mpBindings; } + PageFooterPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + virtual ~PageFooterPanel() override; + virtual void dispose() override; + +private: + + SfxBindings* mpBindings; + + ::sfx2::sidebar::ControllerItem maHFToggleController; + ::sfx2::sidebar::ControllerItem maMetricController; + ::sfx2::sidebar::ControllerItem maFooterLRMarginController; + ::sfx2::sidebar::ControllerItem maFooterSpacingController; + ::sfx2::sidebar::ControllerItem maFooterLayoutController; + + FieldUnit meFUnit; + + OUString aCustomEntry; + + void Initialize(); + void SetMarginsAndSpacingFieldUnit(); + void UpdateFooterCheck(); + void UpdateMarginControl(); + void UpdateSpacingControl(); + void UpdateLayoutControl(); + + ::std::unique_ptr<SfxBoolItem> mpFooterItem; + ::std::unique_ptr<SvxLongLRSpaceItem> mpFooterLRMarginItem; + ::std::unique_ptr<SvxLongULSpaceItem> mpFooterSpacingItem; + ::std::unique_ptr<SfxInt16Item> mpFooterLayoutItem; + + std::unique_ptr<weld::CheckButton> mxFooterToggle; + std::unique_ptr<weld::ComboBox> mxFooterSpacingLB; + std::unique_ptr<weld::ComboBox> mxFooterMarginPresetLB; + std::unique_ptr<weld::ComboBox> mxFooterLayoutLB; + std::unique_ptr<weld::Label> mxCustomEntry; + + static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState); + + DECL_LINK( FooterToggleHdl, weld::ToggleButton&, void ); + DECL_LINK( FooterLRMarginHdl, weld::ComboBox&, void); + DECL_LINK( FooterSpacingHdl, weld::ComboBox&, void); + DECL_LINK( FooterLayoutHdl, weld::ComboBox&, void); +}; + +} //end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageFormatPanel.cxx b/sw/source/uibase/sidebar/PageFormatPanel.cxx new file mode 100644 index 000000000..7a13c6553 --- /dev/null +++ b/sw/source/uibase/sidebar/PageFormatPanel.cxx @@ -0,0 +1,432 @@ +/* -*- 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 <sal/log.hxx> +#include <swtypes.hxx> +#include <svl/intitem.hxx> +#include <editeng/sizeitem.hxx> +#include <editeng/paperinf.hxx> +#include <svx/dlgutil.hxx> +#include <svx/rulritem.hxx> +#include <svx/svdtrans.hxx> +#include "PageFormatPanel.hxx" +#include "PageMarginUtils.hxx" +#include <sfx2/dispatch.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/module.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/viewfrm.hxx> +#include <pageformatpanel.hrc> +#include <cmdid.h> +#include <svtools/optionsdrawinglayer.hxx> +#include <unotools/localedatawrapper.hxx> +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +namespace sw::sidebar{ + +VclPtr<vcl::Window> PageFormatPanel::Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings) +{ + if( pParent == nullptr ) + throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFormatPanel::Create", nullptr, 0); + if( !rxFrame.is() ) + throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageFormatPanel::Create", nullptr, 0); + + return VclPtr<PageFormatPanel>::Create(pParent, rxFrame, pBindings); +} + +void PageFormatPanel::SetMarginFieldUnit() +{ + auto nSelected = mxMarginSelectBox->get_active(); + mxMarginSelectBox->clear(); + + const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper(); + if (IsInch(meFUnit)) + { + OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::INCH); + for (size_t i = 0; i < SAL_N_ELEMENTS(RID_PAGEFORMATPANEL_MARGINS_INCH); ++i) + { + OUString sStr = rLocaleData.getNum(RID_PAGEFORMATPANEL_MARGINS_INCH[i].second, 2, true, false) + sSuffix; + mxMarginSelectBox->append_text(SwResId(RID_PAGEFORMATPANEL_MARGINS_INCH[i].first).replaceFirst("%1", sStr)); + } + } + else + { + OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::CM); + for (size_t i = 0; i < SAL_N_ELEMENTS(RID_PAGEFORMATPANEL_MARGINS_CM); ++i) + { + OUString sStr = rLocaleData.getNum(RID_PAGEFORMATPANEL_MARGINS_CM[i].second, 2, true, false) + " " + sSuffix; + mxMarginSelectBox->append_text(SwResId(RID_PAGEFORMATPANEL_MARGINS_CM[i].first).replaceFirst("%1", sStr)); + } + } + mxMarginSelectBox->set_active(nSelected); +} + +PageFormatPanel::PageFormatPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings) : + PanelLayout(pParent, "PageFormatPanel", "modules/swriter/ui/pageformatpanel.ui", rxFrame), + mpBindings( pBindings ), + mxPaperSizeBox(new SvxPaperSizeListBox(m_xBuilder->weld_combo_box("papersize"))), + mxPaperWidth(new SvxRelativeField(m_xBuilder->weld_metric_spin_button("paperwidth", FieldUnit::CM))), + mxPaperHeight(new SvxRelativeField(m_xBuilder->weld_metric_spin_button("paperheight", FieldUnit::CM))), + mxPaperOrientation(m_xBuilder->weld_combo_box("paperorientation")), + mxMarginSelectBox(m_xBuilder->weld_combo_box("marginLB")), + mxCustomEntry(m_xBuilder->weld_label("customlabel")), + maPaperSizeController(SID_ATTR_PAGE_SIZE, *pBindings, *this), + maPaperOrientationController(SID_ATTR_PAGE, *pBindings, *this), + maMetricController(SID_ATTR_METRIC, *pBindings,*this), + maSwPageLRControl(SID_ATTR_PAGE_LRSPACE, *pBindings, *this), + maSwPageULControl(SID_ATTR_PAGE_ULSPACE, *pBindings, *this), + mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ), + mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ), + mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ), + meFUnit(GetModuleFieldUnit()), + meUnit(), + aCustomEntry() +{ + Initialize(); +} + +PageFormatPanel::~PageFormatPanel() +{ + disposeOnce(); +} + +void PageFormatPanel::dispose() +{ + mxPaperSizeBox.reset(); + mxPaperWidth.reset(); + mxPaperHeight.reset(); + mxPaperOrientation.reset(); + mxMarginSelectBox.reset(); + mxCustomEntry.reset(); + + maMetricController.dispose(); + maPaperOrientationController.dispose(); + maPaperSizeController.dispose(); + maSwPageLRControl.dispose(); + maSwPageULControl.dispose(); + mpPageULMarginItem.reset(); + mpPageLRMarginItem.reset(); + mpPageItem.reset(); + + PanelLayout::dispose(); +} + +void PageFormatPanel::Initialize() +{ + mxPaperSizeBox->FillPaperSizeEntries( PaperSizeApp::Std ); + meUnit = maPaperSizeController.GetCoreMetric(); + mxPaperWidth->SetFieldUnit(meFUnit); + mxPaperHeight->SetFieldUnit(meFUnit); + SetMarginFieldUnit(); + aCustomEntry = mxCustomEntry->get_label(); + + const SvtOptionsDrawinglayer aDrawinglayerOpt; + mxPaperWidth->set_max(mxPaperWidth->normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FieldUnit::CM); + mxPaperHeight->set_max(mxPaperHeight->normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FieldUnit::CM); + + mxPaperSizeBox->connect_changed( LINK(this, PageFormatPanel, PaperFormatModifyHdl )); + mxPaperOrientation->connect_changed( LINK(this, PageFormatPanel, PaperFormatModifyHdl )); + mxPaperHeight->connect_value_changed( LINK(this, PageFormatPanel, PaperSizeModifyHdl )); + mxPaperWidth->connect_value_changed( LINK(this, PageFormatPanel, PaperSizeModifyHdl )); + mxMarginSelectBox->connect_changed( LINK(this, PageFormatPanel, PaperModifyMarginHdl)); + + mpBindings->Update(SID_ATTR_METRIC); + mpBindings->Update(SID_ATTR_PAGE); + mpBindings->Update(SID_ATTR_PAGE_SIZE); + mpBindings->Update(SID_ATTR_PAGE_LRSPACE); + mpBindings->Update(SID_ATTR_PAGE_ULSPACE); + + UpdateMarginBox(); +} + +void PageFormatPanel::NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) +{ + switch(nSId) + { + case SID_ATTR_PAGE_SIZE: + { + const SvxSizeItem* pSizeItem = nullptr; + if (eState >= SfxItemState::DEFAULT) + pSizeItem = dynamic_cast< const SvxSizeItem* >(pState); + if (pSizeItem) + { + Size aPaperSize = pSizeItem->GetSize(); + + mxPaperWidth->set_value(mxPaperWidth->normalize(aPaperSize.Width()), FieldUnit::TWIP); + mxPaperHeight->set_value(mxPaperHeight->normalize(aPaperSize.Height()), FieldUnit::TWIP); + + if(mxPaperOrientation->get_active() == 1) + Swap(aPaperSize); + + Paper ePaper = SvxPaperInfo::GetSvxPaper(aPaperSize, meUnit); + mxPaperSizeBox->set_active_id( ePaper ); + } + } + break; + case SID_ATTR_METRIC: + { + meUnit = maPaperSizeController.GetCoreMetric(); + FieldUnit eFUnit = GetCurrentUnit(eState, pState); + if (eFUnit != meFUnit) + { + meFUnit = eFUnit; + mxPaperHeight->SetFieldUnit(meFUnit); + mxPaperWidth->SetFieldUnit(meFUnit); + SetMarginFieldUnit(); + UpdateMarginBox(); + } + } + break; + case SID_ATTR_PAGE: + { + if ( eState >= SfxItemState::DEFAULT && + dynamic_cast< const SvxPageItem *>( pState ) ) + { + mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) ); + if ( mpPageItem->IsLandscape() ) + mxPaperOrientation->set_active(1); + else + mxPaperOrientation->set_active(0); + } + } + break; + case SID_ATTR_PAGE_LRSPACE: + { + if ( eState >= SfxItemState::DEFAULT && + dynamic_cast< const SvxLongLRSpaceItem *>( pState ) ) + { + mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) ); + UpdateMarginBox(); + } + } + break; + case SID_ATTR_PAGE_ULSPACE: + { + if ( eState >= SfxItemState::DEFAULT && + dynamic_cast< const SvxLongULSpaceItem *>( pState ) ) + { + mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) ); + UpdateMarginBox(); + } + } + break; + default: + break; + } +} + +IMPL_LINK_NOARG(PageFormatPanel, PaperFormatModifyHdl, weld::ComboBox&, void) +{ + Paper ePaper = mxPaperSizeBox->get_active_id(); + Size aSize; + + if(ePaper!=PAPER_USER) + aSize = SvxPaperInfo::GetPaperSize(ePaper, meUnit); + else + aSize = Size(mxPaperWidth->GetCoreValue(meUnit), mxPaperHeight->GetCoreValue(meUnit)); + + if (mxPaperOrientation->get_active() == 1 || ePaper==PAPER_USER) + Swap(aSize); + + mpPageItem->SetLandscape(mxPaperOrientation->get_active() == 1); + SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem, mpPageItem.get() }); +} + +IMPL_LINK_NOARG(PageFormatPanel, PaperSizeModifyHdl, weld::MetricSpinButton&, void) +{ + Size aSize(mxPaperWidth->GetCoreValue(meUnit), mxPaperHeight->GetCoreValue(meUnit)); + SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem }); +} + +IMPL_LINK_NOARG(PageFormatPanel, PaperModifyMarginHdl, weld::ComboBox&, void) +{ + bool bMirrored = false; + bool bApplyNewPageMargins = true; + switch (mxMarginSelectBox->get_active()) + { + case 0: + SetNone(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 1: + SetNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 2: + SetModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 3: + SetNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 4: + SetNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 5: + SetNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 6: + SetWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + case 7: + SetMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored); + break; + default: + bApplyNewPageMargins = false; + break; + } + + if(bApplyNewPageMargins) + { + ExecuteMarginLRChange( mnPageLeftMargin, mnPageRightMargin ); + ExecuteMarginULChange( mnPageTopMargin, mnPageBottomMargin ); + if(bMirrored != (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror)) + { + mpPageItem->SetPageUsage( bMirrored ? SvxPageUsage::Mirror : SvxPageUsage::All ); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE, + SfxCallMode::RECORD, { mpPageItem.get() }); + } + } +} + +FieldUnit PageFormatPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState ) +{ + FieldUnit eUnit = FieldUnit::NONE; + + if ( pState && eState >= SfxItemState::DEFAULT ) + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue()); + else + { + SfxViewFrame* pFrame = SfxViewFrame::Current(); + SfxObjectShell* pSh = nullptr; + if ( pFrame ) + pSh = pFrame->GetObjectShell(); + if ( pSh ) + { + SfxModule* pModule = pSh->GetModule(); + if ( pModule ) + { + const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC ); + if ( pItem ) + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); + } + else + { + SAL_WARN("sw.ui", "GetModuleFieldUnit(): no module found"); + } + } + } + + return eUnit; +} + +void PageFormatPanel::ExecuteMarginLRChange( const long nPageLeftMargin, const long nPageRightMargin ) +{ + mpPageLRMarginItem->SetLeft( nPageLeftMargin ); + mpPageLRMarginItem->SetRight( nPageRightMargin ); + mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { mpPageLRMarginItem.get() }); +} + +void PageFormatPanel::ExecuteMarginULChange(const long nPageTopMargin, const long nPageBottomMargin) +{ + mpPageULMarginItem->SetUpper( nPageTopMargin ); + mpPageULMarginItem->SetLower( nPageBottomMargin ); + mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { mpPageULMarginItem.get() }); +} + +void PageFormatPanel::UpdateMarginBox() +{ + mnPageLeftMargin = mpPageLRMarginItem->GetLeft(); + mnPageRightMargin = mpPageLRMarginItem->GetRight(); + mnPageTopMargin = mpPageULMarginItem->GetUpper(); + mnPageBottomMargin = mpPageULMarginItem->GetLower(); + + int nCustomEntry = mxMarginSelectBox->find_text(aCustomEntry); + + bool bMirrored = (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror); + if( IsNone(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(0); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(1); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(2); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(3); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(4); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(5); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(6); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else if( IsMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) ) + { + mxMarginSelectBox->set_active(7); + if (nCustomEntry != -1) + mxMarginSelectBox->remove(nCustomEntry); + } + else + { + if (nCustomEntry == -1) + mxMarginSelectBox->append_text(aCustomEntry); + mxMarginSelectBox->set_active_text(aCustomEntry); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageFormatPanel.hxx b/sw/source/uibase/sidebar/PageFormatPanel.hxx new file mode 100644 index 000000000..4ea09bb50 --- /dev/null +++ b/sw/source/uibase/sidebar/PageFormatPanel.hxx @@ -0,0 +1,112 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEFORMATPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEFORMATPANEL_HXX + +#include <com/sun/star/frame/XFrame.hpp> + +#include <sfx2/sidebar/PanelLayout.hxx> + +#include <sfx2/sidebar/ControllerItem.hxx> + +#include <svx/pageitem.hxx> +#include <svx/rulritem.hxx> +#include <svx/papersizelistbox.hxx> + +#include <tools/fldunit.hxx> +#include <svl/poolitem.hxx> +#include <svx/relfld.hxx> + +#include <memory> + +namespace sw::sidebar { + +class PageFormatPanel: + public PanelLayout, + public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ +public: + static VclPtr<vcl::Window> Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + + virtual void NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + + PageFormatPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + virtual ~PageFormatPanel() override; + virtual void dispose() override; + + static FieldUnit GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState ); + +private: + + SfxBindings* mpBindings; + + std::unique_ptr<SvxPaperSizeListBox> mxPaperSizeBox; + std::unique_ptr<SvxRelativeField> mxPaperWidth; + std::unique_ptr<SvxRelativeField> mxPaperHeight; + std::unique_ptr<weld::ComboBox> mxPaperOrientation; + std::unique_ptr<weld::ComboBox> mxMarginSelectBox; + std::unique_ptr<weld::Label> mxCustomEntry; + + ::sfx2::sidebar::ControllerItem maPaperSizeController; + ::sfx2::sidebar::ControllerItem maPaperOrientationController; + ::sfx2::sidebar::ControllerItem maMetricController; + ::sfx2::sidebar::ControllerItem maSwPageLRControl; + ::sfx2::sidebar::ControllerItem maSwPageULControl; + + std::unique_ptr<SvxPageItem> mpPageItem; + std::unique_ptr<SvxLongLRSpaceItem> mpPageLRMarginItem; + std::unique_ptr<SvxLongULSpaceItem> mpPageULMarginItem; + + FieldUnit meFUnit; + MapUnit meUnit; + + long mnPageLeftMargin; + long mnPageRightMargin; + long mnPageTopMargin; + long mnPageBottomMargin; + OUString aCustomEntry; + + void Initialize(); + void SetMarginFieldUnit(); + void UpdateMarginBox(); + void ExecuteMarginLRChange( const long nPageLeftMargin, const long nPageRightMargin ); + void ExecuteMarginULChange( const long nPageTopMargin, const long nPageBottomMargin); + DECL_LINK(PaperFormatModifyHdl, weld::ComboBox&, void); + DECL_LINK(PaperSizeModifyHdl, weld::MetricSpinButton&, void); + DECL_LINK(PaperModifyMarginHdl, weld::ComboBox&, void ); +}; + +} //end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageHeaderPanel.cxx b/sw/source/uibase/sidebar/PageHeaderPanel.cxx new file mode 100644 index 000000000..a81d07a29 --- /dev/null +++ b/sw/source/uibase/sidebar/PageHeaderPanel.cxx @@ -0,0 +1,296 @@ +/* -*- 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 <svl/intitem.hxx> +#include <svl/eitem.hxx> +#include <svx/dlgutil.hxx> +#include <svx/rulritem.hxx> +#include <svx/svdtrans.hxx> +#include "PageHeaderPanel.hxx" +#include <sfx2/dispatch.hxx> +#include <sfx2/bindings.hxx> +#include <cmdid.h> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +namespace sw::sidebar{ + +VclPtr<vcl::Window> PageHeaderPanel::Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings) +{ + if( pParent == nullptr ) + throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageHeaderPanel::Create", nullptr, 0); + if( !rxFrame.is() ) + throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageHeaderPanel::Create", nullptr, 0); + if( pBindings == nullptr ) + throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageHeaderPanel::Create", nullptr, 0); + + return VclPtr<PageHeaderPanel>::Create(pParent, rxFrame, pBindings); +} + +void PageHeaderPanel::SetMarginsAndSpacingFieldUnit() +{ + SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxHeaderSpacingLB); + SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxHeaderMarginPresetLB); +} + +PageHeaderPanel::PageHeaderPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings + ) : + PanelLayout(pParent, "PageHeaderPanel", "modules/swriter/ui/pageheaderpanel.ui", rxFrame), + mpBindings( pBindings ), + maHFToggleController(SID_ATTR_PAGE_HEADER, *pBindings, *this), + maMetricController(SID_ATTR_METRIC, *pBindings,*this), + maHeaderLRMarginController(SID_ATTR_PAGE_HEADER_LRMARGIN, *pBindings, *this), + maHeaderSpacingController(SID_ATTR_PAGE_HEADER_SPACING, *pBindings, *this), + maHeaderLayoutController(SID_ATTR_PAGE_HEADER_LAYOUT, *pBindings, *this), + meFUnit(GetModuleFieldUnit()), + aCustomEntry(), + mpHeaderItem( new SfxBoolItem(SID_ATTR_PAGE_HEADER) ), + mpHeaderLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_LRMARGIN)), + mpHeaderSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_SPACING)), + mpHeaderLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_HEADER_LAYOUT)), + mxHeaderToggle(m_xBuilder->weld_check_button("headertoggle")), + mxHeaderSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")), + mxHeaderMarginPresetLB(m_xBuilder->weld_combo_box("headermarginpreset")), + mxHeaderLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")), + mxCustomEntry(m_xBuilder->weld_label("customlabel")) +{ + Initialize(); +} + +PageHeaderPanel::~PageHeaderPanel() +{ + disposeOnce(); +} + +void PageHeaderPanel::dispose() +{ + mxHeaderToggle.reset(); + mxHeaderSpacingLB.reset(); + mxHeaderLayoutLB.reset(); + mxHeaderMarginPresetLB.reset(); + mxCustomEntry.reset(); + + PanelLayout::dispose(); +} + +FieldUnit PageHeaderPanel::GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState) +{ + FieldUnit eUnit; + + if (pState && eState >= SfxItemState::DEFAULT) + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue()); + else + eUnit = GetModuleFieldUnit(); + + return eUnit; +} + +void PageHeaderPanel::Initialize() +{ + SameContentListBox::Fill(*mxHeaderLayoutLB); + + SetMarginsAndSpacingFieldUnit(); + + aCustomEntry = mxCustomEntry->get_label(); + mxHeaderToggle->connect_toggled( LINK(this, PageHeaderPanel, HeaderToggleHdl) ); + mxHeaderMarginPresetLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLRMarginHdl)); + mxHeaderSpacingLB->connect_changed( LINK(this, PageHeaderPanel, HeaderSpacingHdl)); + mxHeaderLayoutLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLayoutHdl)); + + mpBindings->Invalidate(SID_ATTR_METRIC); + mpBindings->Invalidate(SID_ATTR_PAGE_HEADER); + mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_LRMARGIN); + mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_SPACING); + mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_LAYOUT); +} + +void PageHeaderPanel::UpdateHeaderCheck() +{ + if (mxHeaderToggle->get_active()) + { + mxHeaderSpacingLB->set_sensitive(true); + mxHeaderLayoutLB->set_sensitive(true); + mxHeaderMarginPresetLB->set_sensitive(true); + } + else + { + mxHeaderSpacingLB->set_sensitive(false); + mxHeaderLayoutLB->set_sensitive(false); + mxHeaderMarginPresetLB->set_sensitive(false); + } +} + +void PageHeaderPanel::UpdateMarginControl() +{ + sal_uInt16 nLeft = mpHeaderLRMarginItem->GetLeft(); + sal_uInt16 nRight = mpHeaderLRMarginItem->GetRight(); + sal_uInt16 nCount = mxHeaderMarginPresetLB->get_count(); + if(nLeft == nRight) + { + for (sal_uInt16 i = 0; i < nCount; ++i) + { + if (mxHeaderMarginPresetLB->get_id(i).toUInt32() == nLeft) + { + mxHeaderMarginPresetLB->set_active(i); + int nCustomEntry = mxHeaderMarginPresetLB->find_text(aCustomEntry); + if (nCustomEntry != -1) + mxHeaderMarginPresetLB->remove(nCustomEntry); + return; + } + } + } + mxHeaderMarginPresetLB->append_text(aCustomEntry); + mxHeaderMarginPresetLB->set_active_text(aCustomEntry); +} + +void PageHeaderPanel::UpdateSpacingControl() +{ + sal_uInt16 nBottom = mpHeaderSpacingItem->GetLower(); + sal_uInt16 nCount = mxHeaderSpacingLB->get_count(); + for (sal_uInt16 i = 0; i < nCount; ++i) + { + if (mxHeaderSpacingLB->get_id(i).toUInt32() == nBottom) + { + mxHeaderSpacingLB->set_active(i); + int nCustomEntry = mxHeaderSpacingLB->find_text(aCustomEntry); + if (nCustomEntry != -1) + mxHeaderSpacingLB->remove(nCustomEntry); + return; + } + } + mxHeaderSpacingLB->append_text(aCustomEntry); + mxHeaderSpacingLB->set_active_text(aCustomEntry); +} + +void PageHeaderPanel::UpdateLayoutControl() +{ + sal_uInt16 nLayout = mpHeaderLayoutItem->GetValue(); + mxHeaderLayoutLB->set_active(nLayout); +} + +void PageHeaderPanel::NotifyItemUpdate( + const sal_uInt16 nSid, + const SfxItemState eState, + const SfxPoolItem* pState) +{ + if (IsDisposed()) + return; + + switch(nSid) + { + case SID_ATTR_PAGE_HEADER: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SfxBoolItem*>( pState) ) + { + mpHeaderItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) ); + mxHeaderToggle->set_active(mpHeaderItem->GetValue()); + UpdateHeaderCheck(); + } + } + break; + case SID_ATTR_PAGE_HEADER_LRMARGIN: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SvxLongLRSpaceItem*>( pState) ) + { + mpHeaderLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) ); + UpdateMarginControl(); + } + } + break; + case SID_ATTR_PAGE_HEADER_SPACING: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SvxLongULSpaceItem*>( pState) ) + { + mpHeaderSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) ); + UpdateSpacingControl(); + } + } + break; + case SID_ATTR_PAGE_HEADER_LAYOUT: + { + if(eState >= SfxItemState::DEFAULT && + dynamic_cast<const SfxInt16Item*>( pState) ) + { + mpHeaderLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) ); + UpdateLayoutControl(); + } + } + break; + case SID_ATTR_METRIC: + { + FieldUnit eFUnit = GetCurrentUnit(eState, pState); + if (meFUnit != eFUnit) + { + meFUnit = eFUnit; + SetMarginsAndSpacingFieldUnit(); + UpdateSpacingControl(); + UpdateMarginControl(); + } + } + break; + default: + break; + } +} + +IMPL_LINK_NOARG( PageHeaderPanel, HeaderToggleHdl, weld::ToggleButton&, void ) +{ + bool IsChecked = mxHeaderToggle->get_active(); + mpHeaderItem->SetValue(IsChecked); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER, SfxCallMode::RECORD, { mpHeaderItem.get() } ); + UpdateHeaderCheck(); +} + +IMPL_LINK_NOARG( PageHeaderPanel, HeaderLRMarginHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nVal = mxHeaderMarginPresetLB->get_active_id().toUInt32(); + mpHeaderLRMarginItem->SetLeft(nVal); + mpHeaderLRMarginItem->SetRight(nVal); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LRMARGIN, + SfxCallMode::RECORD, { mpHeaderLRMarginItem.get() } ); +} + +IMPL_LINK_NOARG( PageHeaderPanel, HeaderSpacingHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nVal = mxHeaderSpacingLB->get_active_id().toUInt32(); + mpHeaderSpacingItem->SetLower(nVal); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_SPACING, + SfxCallMode::RECORD, { mpHeaderSpacingItem.get() } ); +} +IMPL_LINK_NOARG( PageHeaderPanel, HeaderLayoutHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nVal = mxHeaderLayoutLB->get_active(); + mpHeaderLayoutItem->SetValue(nVal); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LAYOUT, + SfxCallMode::RECORD, { mpHeaderLayoutItem.get() } ); +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageHeaderPanel.hxx b/sw/source/uibase/sidebar/PageHeaderPanel.hxx new file mode 100644 index 000000000..c7701f9e7 --- /dev/null +++ b/sw/source/uibase/sidebar/PageHeaderPanel.hxx @@ -0,0 +1,110 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEHEADERPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEHEADERPANEL_HXX + +#include <memory> +#include <com/sun/star/frame/XFrame.hpp> + +#include <sfx2/sidebar/PanelLayout.hxx> + +#include <sfx2/sidebar/ControllerItem.hxx> + +#include <svx/rulritem.hxx> + +#include <svl/intitem.hxx> +#include <svl/poolitem.hxx> +#include <svl/eitem.hxx> +#include <svx/spacinglistbox.hxx> +#include <svx/samecontentlistbox.hxx> + +namespace sw::sidebar { + +class PageHeaderPanel: + public PanelLayout, + public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ +public: + static VclPtr<vcl::Window> Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + + virtual void NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + + SfxBindings* GetBindings() const { return mpBindings; } + PageHeaderPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + virtual ~PageHeaderPanel() override; + virtual void dispose() override; + +private: + + SfxBindings* mpBindings; + + ::sfx2::sidebar::ControllerItem maHFToggleController; + ::sfx2::sidebar::ControllerItem maMetricController; + ::sfx2::sidebar::ControllerItem maHeaderLRMarginController; + ::sfx2::sidebar::ControllerItem maHeaderSpacingController; + ::sfx2::sidebar::ControllerItem maHeaderLayoutController; + + FieldUnit meFUnit; + + OUString aCustomEntry; + + void Initialize(); + void SetMarginsAndSpacingFieldUnit(); + void UpdateHeaderCheck(); + void UpdateMarginControl(); + void UpdateSpacingControl(); + void UpdateLayoutControl(); + + ::std::unique_ptr<SfxBoolItem> mpHeaderItem; + ::std::unique_ptr<SvxLongLRSpaceItem> mpHeaderLRMarginItem; + ::std::unique_ptr<SvxLongULSpaceItem> mpHeaderSpacingItem; + ::std::unique_ptr<SfxInt16Item> mpHeaderLayoutItem; + + std::unique_ptr<weld::CheckButton> mxHeaderToggle; + std::unique_ptr<weld::ComboBox> mxHeaderSpacingLB; + std::unique_ptr<weld::ComboBox> mxHeaderMarginPresetLB; + std::unique_ptr<weld::ComboBox> mxHeaderLayoutLB; + std::unique_ptr<weld::Label> mxCustomEntry; + + static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState); + + DECL_LINK( HeaderToggleHdl, weld::ToggleButton&, void ); + DECL_LINK( HeaderLRMarginHdl, weld::ComboBox&, void); + DECL_LINK( HeaderSpacingHdl, weld::ComboBox&, void); + DECL_LINK( HeaderLayoutHdl, weld::ComboBox&, void); +}; + +} //end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageMarginControl.cxx b/sw/source/uibase/sidebar/PageMarginControl.cxx new file mode 100644 index 000000000..258b5996d --- /dev/null +++ b/sw/source/uibase/sidebar/PageMarginControl.cxx @@ -0,0 +1,586 @@ +/* -*- 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 <memory> +#include <sal/config.h> + +#include "PageMarginControl.hxx" +#include <strings.hrc> + +#include <editeng/sizeitem.hxx> +#include <sfx2/app.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/module.hxx> +#include <sfx2/viewfrm.hxx> +#include <svx/pageitem.hxx> +#include <svx/rulritem.hxx> +#include <svl/itempool.hxx> +#include <svl/intitem.hxx> +#include <svtools/unitconv.hxx> +#include <unotools/viewoptions.hxx> + +#include <swtypes.hxx> +#include <cmdid.h> +#include <PageMarginPopup.hxx> + +#include <com/sun/star/document/XUndoManagerSupplier.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/frame/XFrame.hpp> + +#define SWPAGE_LEFT_GVALUE "Sw_Page_Left" +#define SWPAGE_RIGHT_GVALUE "Sw_Page_Right" +#define SWPAGE_TOP_GVALUE "Sw_Page_Top" +#define SWPAGE_DOWN_GVALUE "Sw_Page_Down" +#define SWPAGE_MIRROR_GVALUE "Sw_Page_Mirrored" + +namespace +{ + FieldUnit lcl_GetFieldUnit() + { + FieldUnit eUnit = FieldUnit::INCH; + const SfxPoolItem* pItem = nullptr; + SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_METRIC, pItem ); + if ( pItem && eState >= SfxItemState::DEFAULT ) + { + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>( pItem )->GetValue()); + } + else + { + return SfxModule::GetCurrentFieldUnit(); + } + + return eUnit; + } + + MapUnit lcl_GetUnit() + { + SfxItemPool &rPool = SfxGetpApp()->GetPool(); + sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_PAGE_SIZE ); + return rPool.GetMetric( nWhich ); + } + + css::uno::Reference< css::document::XUndoManager > getUndoManager( const css::uno::Reference< css::frame::XFrame >& rxFrame ) + { + const css::uno::Reference< css::frame::XController >& xController = rxFrame->getController(); + if ( xController.is() ) + { + const css::uno::Reference< css::frame::XModel >& xModel = xController->getModel(); + if ( xModel.is() ) + { + const css::uno::Reference< css::document::XUndoManagerSupplier > xSuppUndo( xModel, css::uno::UNO_QUERY_THROW ); + return css::uno::Reference< css::document::XUndoManager >( xSuppUndo->getUndoManager(), css::uno::UNO_SET_THROW ); + } + } + + return css::uno::Reference< css::document::XUndoManager > (); + } +} + +namespace sw::sidebar { + +PageMarginControl::PageMarginControl(PageMarginPopup* pControl, weld::Widget* pParent) + : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/swriter/ui/pagemargincontrol.ui", "PageMarginControl") + , m_xLeft(m_xBuilder->weld_label("leftLabel")) + , m_xRight(m_xBuilder->weld_label("rightLabel")) + , m_xInner(m_xBuilder->weld_label("innerLabel")) + , m_xOuter(m_xBuilder->weld_label("outerLabel")) + , m_xLeftMarginEdit(m_xBuilder->weld_metric_spin_button("left", FieldUnit::CM)) + , m_xRightMarginEdit(m_xBuilder->weld_metric_spin_button("right", FieldUnit::CM)) + , m_xTopMarginEdit(m_xBuilder->weld_metric_spin_button("top", FieldUnit::CM)) + , m_xBottomMarginEdit(m_xBuilder->weld_metric_spin_button("bottom", FieldUnit::CM)) + , m_xWidthHeightField(m_xBuilder->weld_metric_spin_button("hidden", FieldUnit::CM)) + , m_xControl(pControl) + , m_nPageLeftMargin(0) + , m_nPageRightMargin(0) + , m_nPageTopMargin(0) + , m_nPageBottomMargin(0) + , m_bMirrored(false) + , m_eUnit( lcl_GetUnit() ) + , m_bUserCustomValuesAvailable( false ) + , m_nUserCustomPageLeftMargin( 0 ) + , m_nUserCustomPageRightMargin( 0 ) + , m_nUserCustomPageTopMargin( 0 ) + , m_nUserCustomPageBottomMargin( 0 ) + , m_bUserCustomMirrored( false ) + , m_bCustomValuesUsed( false ) +{ + m_xWidthHeightField->set_unit(FieldUnit::CM); + m_xWidthHeightField->set_range(0, 9999, FieldUnit::NONE); + m_xWidthHeightField->set_digits(2); + m_xWidthHeightField->set_increments(10, 100, FieldUnit::NONE); + SetFieldUnit( *m_xWidthHeightField, lcl_GetFieldUnit() ); + + bool bLandscape = false; + const SfxPoolItem* pItem; + const SvxSizeItem* pSize = nullptr; + const SvxLongLRSpaceItem* pLRItem = nullptr; + const SvxLongULSpaceItem* pULItem = nullptr; + if ( SfxViewFrame::Current() ) + { + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem ); + bLandscape = static_cast<const SvxPageItem*>( pItem )->IsLandscape(); + m_bMirrored = static_cast<const SvxPageItem*>( pItem )->GetPageUsage() == SvxPageUsage::Mirror; + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pItem ); + pSize = static_cast<const SvxSizeItem*>( pItem ); + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_LRSPACE, pItem ); + pLRItem = static_cast<const SvxLongLRSpaceItem*>( pItem ); + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_ULSPACE, pItem ); + pULItem = static_cast<const SvxLongULSpaceItem*>( pItem ); + } + + if ( pLRItem ) + { + m_nPageLeftMargin = pLRItem->GetLeft(); + m_nPageRightMargin = pLRItem->GetRight(); + } + + if ( pULItem ) + { + m_nPageTopMargin = pULItem->GetUpper(); + m_nPageBottomMargin = pULItem->GetLower(); + } + + if ( bLandscape ) + { + m_xNarrow = m_xBuilder->weld_button("narrowL"); + m_xNormal = m_xBuilder->weld_button("normalL"); + m_xWide = m_xBuilder->weld_button("wideL"); + m_xMirrored = m_xBuilder->weld_button("mirroredL"); + m_xLast = m_xBuilder->weld_button("lastL"); + } + else + { + m_xNarrow = m_xBuilder->weld_button("narrow"); + m_xNormal = m_xBuilder->weld_button("normal"); + m_xWide = m_xBuilder->weld_button("wide"); + m_xMirrored = m_xBuilder->weld_button("mirrored"); + m_xLast = m_xBuilder->weld_button("last"); + } + + m_xNarrow->show(); + m_xNormal->show(); + m_xWide->show(); + m_xMirrored->show(); + m_xLast->show(); + + m_xNarrow->connect_clicked( LINK( this, PageMarginControl, SelectMarginHdl ) ); + m_xNormal->connect_clicked( LINK( this, PageMarginControl, SelectMarginHdl ) ); + m_xWide->connect_clicked( LINK( this, PageMarginControl, SelectMarginHdl ) ); + m_xMirrored->connect_clicked( LINK( this, PageMarginControl, SelectMarginHdl ) ); + m_xLast->connect_clicked( LINK( this, PageMarginControl, SelectMarginHdl ) ); + + m_bUserCustomValuesAvailable = GetUserCustomValues(); + + FillHelpText( m_bUserCustomValuesAvailable ); + + Link<weld::MetricSpinButton&,void> aLinkLR = LINK( this, PageMarginControl, ModifyLRMarginHdl ); + m_xLeftMarginEdit->connect_value_changed( aLinkLR ); + SetMetricValue( *m_xLeftMarginEdit, m_nPageLeftMargin, m_eUnit ); + SetFieldUnit( *m_xLeftMarginEdit, lcl_GetFieldUnit() ); + + m_xRightMarginEdit->connect_value_changed( aLinkLR ); + SetMetricValue( *m_xRightMarginEdit, m_nPageRightMargin, m_eUnit ); + SetFieldUnit( *m_xRightMarginEdit, lcl_GetFieldUnit() ); + + Link<weld::MetricSpinButton&,void> aLinkUL = LINK( this, PageMarginControl, ModifyULMarginHdl ); + m_xTopMarginEdit->connect_value_changed( aLinkUL ); + SetMetricValue( *m_xTopMarginEdit, m_nPageTopMargin, m_eUnit ); + SetFieldUnit( *m_xTopMarginEdit, lcl_GetFieldUnit() ); + + m_xBottomMarginEdit->connect_value_changed( aLinkUL ); + SetMetricValue( *m_xBottomMarginEdit, m_nPageBottomMargin, m_eUnit ); + SetFieldUnit( *m_xBottomMarginEdit, lcl_GetFieldUnit() ); + + m_aPageSize = pSize->GetSize(); + SetMetricFieldMaxValues( m_aPageSize ); + + if ( m_bMirrored ) + { + m_xLeft->hide(); + m_xRight->hide(); + m_xInner->show(); + m_xOuter->show(); + } + else + { + m_xLeft->show(); + m_xRight->show(); + m_xInner->hide(); + m_xOuter->hide(); + } +} + +void PageMarginControl::GrabFocus() +{ + m_xNarrow->grab_focus(); +} + +PageMarginControl::~PageMarginControl() +{ + StoreUserCustomValues(); +} + +void PageMarginControl::SetMetricFieldMaxValues( const Size& rPageSize ) +{ + const long nML = m_xLeftMarginEdit->denormalize( m_xLeftMarginEdit->get_value( FieldUnit::TWIP ) ); + const long nMR = m_xRightMarginEdit->denormalize( m_xRightMarginEdit->get_value( FieldUnit::TWIP ) ); + const long nMT = m_xTopMarginEdit->denormalize( m_xTopMarginEdit->get_value( FieldUnit::TWIP ) ); + const long nMB = m_xBottomMarginEdit->denormalize( m_xBottomMarginEdit->get_value( FieldUnit::TWIP ) ); + + const long nPH = OutputDevice::LogicToLogic( rPageSize.Height(), m_eUnit, MapUnit::MapTwip ); + const long nPW = OutputDevice::LogicToLogic( rPageSize.Width(), m_eUnit, MapUnit::MapTwip ); + + // Left + long nMax = nPW - nMR - MINBODY; + m_xLeftMarginEdit->set_max( m_xLeftMarginEdit->normalize( nMax ), FieldUnit::TWIP ); + + // Right + nMax = nPW - nML - MINBODY; + m_xRightMarginEdit->set_max( m_xRightMarginEdit->normalize( nMax ), FieldUnit::TWIP ); + + //Top + nMax = nPH - nMB - MINBODY; + m_xTopMarginEdit->set_max( m_xTopMarginEdit->normalize( nMax ), FieldUnit::TWIP ); + + //Bottom + nMax = nPH - nMT - MINBODY; + m_xBottomMarginEdit->set_max( m_xTopMarginEdit->normalize( nMax ), FieldUnit::TWIP ); +} + +void PageMarginControl::FillHelpText( const bool bUserCustomValuesAvailable ) +{ + const OUString aLeft = SwResId( STR_MARGIN_TOOLTIP_LEFT ); + const OUString aRight = SwResId( STR_MARGIN_TOOLTIP_RIGHT ); + const OUString aTop = SwResId( STR_MARGIN_TOOLTIP_TOP ); + const OUString aBottom = SwResId( STR_MARGIN_TOOLTIP_BOT ); + + SetMetricValue( *m_xWidthHeightField, SWPAGE_NARROW_VALUE, m_eUnit ); + const OUString aNarrowValText = m_xWidthHeightField->get_text(); + OUString aHelpText = aLeft + + aNarrowValText + + aRight + + aNarrowValText + + aTop + + aNarrowValText + + aBottom + + aNarrowValText; + m_xNarrow->set_tooltip_text( aHelpText ); + + SetMetricValue( *m_xWidthHeightField, SWPAGE_NORMAL_VALUE, m_eUnit ); + const OUString aNormalValText = m_xWidthHeightField->get_text(); + aHelpText = aLeft + + aNormalValText + + aRight + + aNormalValText + + aTop + + aNormalValText + + aBottom + + aNormalValText; + m_xNormal->set_tooltip_text( aHelpText ); + + SetMetricValue( *m_xWidthHeightField, SWPAGE_WIDE_VALUE1, m_eUnit ); + const OUString aWide1ValText = m_xWidthHeightField->get_text(); + SetMetricValue( *m_xWidthHeightField, SWPAGE_WIDE_VALUE2, m_eUnit ); + const OUString aWide2ValText = m_xWidthHeightField->get_text(); + aHelpText = aLeft + + aWide2ValText + + aRight + + aWide2ValText + + aTop + + aWide1ValText + + aBottom + + aWide1ValText; + m_xWide->set_tooltip_text( aHelpText ); + + const OUString aInner = SwResId( STR_MARGIN_TOOLTIP_INNER ); + const OUString aOuter = SwResId( STR_MARGIN_TOOLTIP_OUTER ); + + SetMetricValue( *m_xWidthHeightField, SWPAGE_WIDE_VALUE3, m_eUnit ); + const OUString aWide3ValText = m_xWidthHeightField->get_text(); + aHelpText = aInner + + aWide3ValText + + aOuter + + aWide1ValText + + aTop + + aWide1ValText + + aBottom + + aWide1ValText; + m_xMirrored->set_tooltip_text( aHelpText ); + + if ( bUserCustomValuesAvailable ) + { + aHelpText = m_bUserCustomMirrored ? aInner : aLeft; + SetMetricValue( *m_xWidthHeightField, m_nUserCustomPageLeftMargin, m_eUnit ); + aHelpText += m_xWidthHeightField->get_text(); + aHelpText += m_bUserCustomMirrored ? aOuter : aRight; + SetMetricValue( *m_xWidthHeightField, m_nUserCustomPageRightMargin, m_eUnit ); + aHelpText += m_xWidthHeightField->get_text(); + aHelpText += aTop; + SetMetricValue( *m_xWidthHeightField, m_nUserCustomPageTopMargin, m_eUnit ); + aHelpText += m_xWidthHeightField->get_text(); + aHelpText += aBottom; + SetMetricValue( *m_xWidthHeightField, m_nUserCustomPageBottomMargin, m_eUnit ); + aHelpText += m_xWidthHeightField->get_text(); + } + else + { + aHelpText.clear(); + } + m_xLast->set_tooltip_text( aHelpText ); +} + +IMPL_LINK( PageMarginControl, SelectMarginHdl, weld::Button&, rControl, void ) +{ + bool bMirrored = false; + bool bApplyNewPageMargins = true; + if( &rControl == m_xNarrow.get() ) + { + m_nPageLeftMargin = SWPAGE_NARROW_VALUE; + m_nPageRightMargin = SWPAGE_NARROW_VALUE; + m_nPageTopMargin = SWPAGE_NARROW_VALUE; + m_nPageBottomMargin = SWPAGE_NARROW_VALUE; + bMirrored = false; + } + if( &rControl == m_xNormal.get() ) + { + m_nPageLeftMargin = SWPAGE_NORMAL_VALUE; + m_nPageRightMargin = SWPAGE_NORMAL_VALUE; + m_nPageTopMargin = SWPAGE_NORMAL_VALUE; + m_nPageBottomMargin = SWPAGE_NORMAL_VALUE; + bMirrored = false; + } + if( &rControl == m_xWide.get() ) + { + m_nPageLeftMargin = SWPAGE_WIDE_VALUE2; + m_nPageRightMargin = SWPAGE_WIDE_VALUE2; + m_nPageTopMargin = SWPAGE_WIDE_VALUE1; + m_nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = false; + } + if( &rControl == m_xMirrored.get() ) + { + m_nPageLeftMargin = SWPAGE_WIDE_VALUE3; + m_nPageRightMargin = SWPAGE_WIDE_VALUE1; + m_nPageTopMargin = SWPAGE_WIDE_VALUE1; + m_nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = true; + } + if( &rControl == m_xLast.get() ) + { + if ( m_bUserCustomValuesAvailable ) + { + m_nPageLeftMargin = m_nUserCustomPageLeftMargin; + m_nPageRightMargin = m_nUserCustomPageRightMargin; + m_nPageTopMargin = m_nUserCustomPageTopMargin; + m_nPageBottomMargin = m_nUserCustomPageBottomMargin; + bMirrored = m_bUserCustomMirrored; + } + else + { + bApplyNewPageMargins = false; + } + } + + if ( bApplyNewPageMargins ) + { + const css::uno::Reference< css::document::XUndoManager > xUndoManager( getUndoManager( SfxViewFrame::Current()->GetFrame().GetFrameInterface() ) ); + if ( xUndoManager.is() ) + xUndoManager->enterUndoContext( "" ); + + ExecuteMarginLRChange( m_nPageLeftMargin, m_nPageRightMargin ); + ExecuteMarginULChange( m_nPageTopMargin, m_nPageBottomMargin ); + if ( m_bMirrored != bMirrored ) + { + m_bMirrored = bMirrored; + ExecutePageLayoutChange( m_bMirrored ); + } + + if ( xUndoManager.is() ) + xUndoManager->leaveUndoContext(); + + m_bCustomValuesUsed = false; + m_xControl->EndPopupMode(); + } +} + +void PageMarginControl::ExecuteMarginLRChange( + const long nPageLeftMargin, + const long nPageRightMargin ) +{ + if ( SfxViewFrame::Current() ) + { + std::unique_ptr<SvxLongLRSpaceItem> pPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ); + pPageLRMarginItem->SetLeft( nPageLeftMargin ); + pPageLRMarginItem->SetRight( nPageRightMargin ); + SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, + SfxCallMode::RECORD, { pPageLRMarginItem.get() } ); + pPageLRMarginItem.reset(); + } +} + +void PageMarginControl::ExecuteMarginULChange( + const long nPageTopMargin, + const long nPageBottomMargin ) +{ + if ( SfxViewFrame::Current() ) + { + std::unique_ptr<SvxLongULSpaceItem> pPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ); + pPageULMarginItem->SetUpper( nPageTopMargin ); + pPageULMarginItem->SetLower( nPageBottomMargin ); + SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, + SfxCallMode::RECORD, { pPageULMarginItem.get() } ); + pPageULMarginItem.reset(); + } +} + +void PageMarginControl::ExecutePageLayoutChange( const bool bMirrored ) +{ + if ( SfxViewFrame::Current() ) + { + std::unique_ptr<SvxPageItem> pPageItem( new SvxPageItem( SID_ATTR_PAGE ) ); + pPageItem->SetPageUsage( bMirrored ? SvxPageUsage::Mirror : SvxPageUsage::All ); + SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE, + SfxCallMode::RECORD, { pPageItem.get() } ); + pPageItem.reset(); + } +} + +IMPL_LINK_NOARG( PageMarginControl, ModifyLRMarginHdl, weld::MetricSpinButton&, void ) +{ + m_nPageLeftMargin = GetCoreValue( *m_xLeftMarginEdit, m_eUnit ); + m_nPageRightMargin = GetCoreValue( *m_xRightMarginEdit, m_eUnit ); + ExecuteMarginLRChange( m_nPageLeftMargin, m_nPageRightMargin ); + SetMetricFieldMaxValues( m_aPageSize ); + m_bCustomValuesUsed = true; +} + +IMPL_LINK_NOARG( PageMarginControl, ModifyULMarginHdl, weld::MetricSpinButton&, void ) +{ + m_nPageTopMargin = GetCoreValue( *m_xTopMarginEdit, m_eUnit ); + m_nPageBottomMargin = GetCoreValue( *m_xBottomMarginEdit, m_eUnit ); + ExecuteMarginULChange( m_nPageTopMargin, m_nPageBottomMargin ); + SetMetricFieldMaxValues( m_aPageSize ); + m_bCustomValuesUsed = true; +} + +bool PageMarginControl::GetUserCustomValues() +{ + bool bUserCustomValuesAvailable = false; + + SvtViewOptions aWinOpt( EViewType::Window, SWPAGE_LEFT_GVALUE ); + if ( aWinOpt.Exists() ) + { + css::uno::Sequence < css::beans::NamedValue > aSeq = aWinOpt.GetUserData(); + OUString aTmp; + if ( aSeq.hasElements()) + aSeq[0].Value >>= aTmp; + OUString aWinData( aTmp ); + m_nUserCustomPageLeftMargin = aWinData.toInt32(); + bUserCustomValuesAvailable = true; + } + + SvtViewOptions aWinOpt2( EViewType::Window, SWPAGE_RIGHT_GVALUE ); + if ( aWinOpt2.Exists() ) + { + css::uno::Sequence < css::beans::NamedValue > aSeq = aWinOpt2.GetUserData(); + OUString aTmp; + if ( aSeq.hasElements()) + aSeq[0].Value >>= aTmp; + OUString aWinData( aTmp ); + m_nUserCustomPageRightMargin = aWinData.toInt32(); + bUserCustomValuesAvailable = true; + } + + SvtViewOptions aWinOpt3( EViewType::Window, SWPAGE_TOP_GVALUE ); + if ( aWinOpt3.Exists() ) + { + css::uno::Sequence < css::beans::NamedValue > aSeq = aWinOpt3.GetUserData(); + OUString aTmp; + if ( aSeq.hasElements() ) + aSeq[0].Value >>= aTmp; + OUString aWinData( aTmp ); + m_nUserCustomPageTopMargin = aWinData.toInt32(); + bUserCustomValuesAvailable = true; + } + + SvtViewOptions aWinOpt4( EViewType::Window, SWPAGE_DOWN_GVALUE ); + if ( aWinOpt4.Exists() ) + { + css::uno::Sequence < css::beans::NamedValue > aSeq = aWinOpt4.GetUserData(); + OUString aTmp; + if ( aSeq.hasElements()) + aSeq[0].Value >>= aTmp; + OUString aWinData( aTmp ); + m_nUserCustomPageBottomMargin = aWinData.toInt32(); + bUserCustomValuesAvailable = true; + } + + SvtViewOptions aWinOpt5( EViewType::Window, SWPAGE_MIRROR_GVALUE ); + if ( aWinOpt5.Exists() ) + { + css::uno::Sequence < css::beans::NamedValue > aSeq = aWinOpt5.GetUserData(); + OUString aTmp; + if ( aSeq.hasElements()) + aSeq[0].Value >>= aTmp; + OUString aWinData( aTmp ); + m_bUserCustomMirrored = aWinData.toInt32() != 0; + bUserCustomValuesAvailable = true; + } + + return bUserCustomValuesAvailable; +} + +void PageMarginControl::StoreUserCustomValues() +{ + if ( !m_bCustomValuesUsed ) + { + return; + } + + css::uno::Sequence < css::beans::NamedValue > aSeq( 1 ); + SvtViewOptions aWinOpt( EViewType::Window, SWPAGE_LEFT_GVALUE ); + + aSeq[0].Name = "mnPageLeftMargin"; + aSeq[0].Value <<= OUString::number( m_nPageLeftMargin ); + aWinOpt.SetUserData( aSeq ); + + SvtViewOptions aWinOpt2( EViewType::Window, SWPAGE_RIGHT_GVALUE ); + aSeq[0].Name = "mnPageRightMargin"; + aSeq[0].Value <<= OUString::number( m_nPageRightMargin ); + aWinOpt2.SetUserData( aSeq ); + + SvtViewOptions aWinOpt3( EViewType::Window, SWPAGE_TOP_GVALUE ); + aSeq[0].Name = "mnPageTopMargin"; + aSeq[0].Value <<= OUString::number( m_nPageTopMargin ); + aWinOpt3.SetUserData( aSeq ); + + SvtViewOptions aWinOpt4( EViewType::Window, SWPAGE_DOWN_GVALUE ); + aSeq[0].Name = "mnPageBottomMargin"; + aSeq[0].Value <<= OUString::number( m_nPageBottomMargin ); + aWinOpt4.SetUserData( aSeq ); + + SvtViewOptions aWinOpt5( EViewType::Window, SWPAGE_MIRROR_GVALUE ); + aSeq[0].Name = "mbMirrored"; + aSeq[0].Value <<= OUString::number( (m_bMirrored ? 1 : 0) ); + aWinOpt5.SetUserData( aSeq ); +} + +} // end of namespace sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageMarginControl.hxx b/sw/source/uibase/sidebar/PageMarginControl.hxx new file mode 100644 index 000000000..1c945e815 --- /dev/null +++ b/sw/source/uibase/sidebar/PageMarginControl.hxx @@ -0,0 +1,109 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEMARGINCONTROL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEMARGINCONTROL_HXX + +#include <svtools/toolbarmenu.hxx> + +#define SWPAGE_NARROW_VALUE 720 +#define SWPAGE_NORMAL_VALUE 1136 +#define SWPAGE_WIDE_VALUE1 1440 +#define SWPAGE_WIDE_VALUE2 2880 +#define SWPAGE_WIDE_VALUE3 1800 + +// #i19922# - tdf#126051 see cui/source/tabpages/page.cxx and svx/source/dialog/hdft.cxx +static const long MINBODY = 56; // 1mm in twips rounded + +class PageMarginPopup; + +namespace sw::sidebar { + +class PageMarginControl final : public WeldToolbarPopup +{ +public: + explicit PageMarginControl(PageMarginPopup* pControl, weld::Widget* pParent); + virtual void GrabFocus() override; + virtual ~PageMarginControl() override; + +private: + std::unique_ptr<weld::Button> m_xNarrow; + std::unique_ptr<weld::Button> m_xNormal; + std::unique_ptr<weld::Button> m_xWide; + std::unique_ptr<weld::Button> m_xMirrored; + std::unique_ptr<weld::Button> m_xLast; + + std::unique_ptr<weld::Label> m_xLeft; + std::unique_ptr<weld::Label> m_xRight; + std::unique_ptr<weld::Label> m_xInner; + std::unique_ptr<weld::Label> m_xOuter; + + std::unique_ptr<weld::MetricSpinButton> m_xLeftMarginEdit; + std::unique_ptr<weld::MetricSpinButton> m_xRightMarginEdit; + std::unique_ptr<weld::MetricSpinButton> m_xTopMarginEdit; + std::unique_ptr<weld::MetricSpinButton> m_xBottomMarginEdit; + + // hidden metric field + std::unique_ptr<weld::MetricSpinButton> m_xWidthHeightField; + + rtl::Reference<PageMarginPopup> m_xControl; + + long m_nPageLeftMargin; + long m_nPageRightMargin; + long m_nPageTopMargin; + long m_nPageBottomMargin; + bool m_bMirrored; + + const MapUnit m_eUnit; + + Size m_aPageSize; + + bool m_bUserCustomValuesAvailable; + long m_nUserCustomPageLeftMargin; + long m_nUserCustomPageRightMargin; + long m_nUserCustomPageTopMargin; + long m_nUserCustomPageBottomMargin; + bool m_bUserCustomMirrored; + + bool m_bCustomValuesUsed; + + DECL_LINK( SelectMarginHdl, weld::Button&, void ); + DECL_LINK( ModifyLRMarginHdl, weld::MetricSpinButton&, void ); + DECL_LINK( ModifyULMarginHdl, weld::MetricSpinButton&, void ); + + static void ExecuteMarginLRChange( + const long nPageLeftMargin, + const long nPageRightMargin ); + static void ExecuteMarginULChange( + const long nPageTopMargin, + const long nPageBottomMargin ); + static void ExecutePageLayoutChange( const bool bMirrored ); + + void SetMetricFieldMaxValues(const Size& rPageSize); + + bool GetUserCustomValues(); + void StoreUserCustomValues(); + + void FillHelpText( const bool bUserCustomValuesAvailable ); +}; + +} // end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageMarginPopup.cxx b/sw/source/uibase/sidebar/PageMarginPopup.cxx new file mode 100644 index 000000000..8223386c2 --- /dev/null +++ b/sw/source/uibase/sidebar/PageMarginPopup.cxx @@ -0,0 +1,75 @@ +/* -*- 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 <PageMarginPopup.hxx> +#include "PageMarginControl.hxx" +#include <vcl/toolbox.hxx> + +PageMarginPopup::PageMarginPopup(const css::uno::Reference<css::uno::XComponentContext>& rContext) + : PopupWindowController(rContext, nullptr, OUString()) +{ +} + +void PageMarginPopup::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) +{ + PopupWindowController::initialize(rArguments); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) + pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWNONLY | pToolBox->GetItemBits(nId)); +} + +PageMarginPopup::~PageMarginPopup() +{ +} + +std::unique_ptr<WeldToolbarPopup> PageMarginPopup::weldPopupWindow() +{ + return std::make_unique<sw::sidebar::PageMarginControl>(this, m_pToolbar); +} + +VclPtr<vcl::Window> PageMarginPopup::createVclPopupWindow( vcl::Window* pParent ) +{ + mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, + std::make_unique<sw::sidebar::PageMarginControl>(this, pParent->GetFrameWeld())); + + mxInterimPopover->Show(); + + return mxInterimPopover; +} + +OUString PageMarginPopup::getImplementationName() +{ + return "lo.writer.PageMarginToolBoxControl"; +} + +css::uno::Sequence<OUString> PageMarginPopup::getSupportedServiceNames() +{ + return { "com.sun.star.frame.ToolbarController" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +lo_writer_PageMarginToolBoxControl_get_implementation( + css::uno::XComponentContext* rContext, + css::uno::Sequence<css::uno::Any> const & ) +{ + return cppu::acquire(new PageMarginPopup(rContext)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageMarginUtils.hxx b/sw/source/uibase/sidebar/PageMarginUtils.hxx new file mode 100644 index 000000000..1361361a1 --- /dev/null +++ b/sw/source/uibase/sidebar/PageMarginUtils.hxx @@ -0,0 +1,192 @@ +/* -*- 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 <cmath> +#define SWPAGE_NO_MARGIN 0 +#define SWPAGE_NARROW_VALUE 720 +#define SWPAGE_MODERATE_LR 1080 +#define SWPAGE_NORMAL_VALUE 1136 +#define SWPAGE_WIDE_VALUE1 1440 +#define SWPAGE_WIDE_VALUE2 2880 +#define SWPAGE_WIDE_VALUE3 1800 +#define SWPAGE_UNIT_THRESHOLD 5 + +namespace sw::sidebar{ + +bool IsNone( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_NO_MARGIN ) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetNone( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_NO_MARGIN; + nPageRightMargin = SWPAGE_NO_MARGIN; + nPageTopMargin = SWPAGE_NO_MARGIN; + nPageBottomMargin = SWPAGE_NO_MARGIN; + bMirrored = false; +} + +bool IsNarrow( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetNarrow( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_NARROW_VALUE; + nPageRightMargin = SWPAGE_NARROW_VALUE; + nPageTopMargin = SWPAGE_NARROW_VALUE; + nPageBottomMargin = SWPAGE_NARROW_VALUE; + bMirrored = false; +} + +bool IsModerate( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_MODERATE_LR) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_MODERATE_LR) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetModerate( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_MODERATE_LR; + nPageRightMargin = SWPAGE_MODERATE_LR; + nPageTopMargin = SWPAGE_WIDE_VALUE1; + nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = false; +} + +bool IsNormal075( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetNormal075( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_NORMAL_VALUE; + nPageRightMargin = SWPAGE_NORMAL_VALUE; + nPageTopMargin = SWPAGE_NORMAL_VALUE; + nPageBottomMargin = SWPAGE_NORMAL_VALUE; + bMirrored = false; +} + +bool IsNormal100( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetNormal100( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_WIDE_VALUE1; + nPageRightMargin = SWPAGE_WIDE_VALUE1; + nPageTopMargin = SWPAGE_WIDE_VALUE1; + nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = false; +} + +bool IsNormal125( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetNormal125( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_WIDE_VALUE3; + nPageRightMargin = SWPAGE_WIDE_VALUE3; + nPageTopMargin = SWPAGE_WIDE_VALUE1; + nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = false; +} + +bool IsWide( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE2) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE2) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + !bMirrored ); +} + +void SetWide( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_WIDE_VALUE2; + nPageRightMargin = SWPAGE_WIDE_VALUE2; + nPageTopMargin = SWPAGE_WIDE_VALUE1; + nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = false; +} + +bool IsMirrored( const long nPageLeftMargin, const long nPageRightMargin, + const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored) +{ + return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD && + bMirrored ); +} + +void SetMirrored( long& nPageLeftMargin, long& nPageRightMargin, + long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored) +{ + nPageLeftMargin = SWPAGE_WIDE_VALUE3; + nPageRightMargin = SWPAGE_WIDE_VALUE1; + nPageTopMargin = SWPAGE_WIDE_VALUE1; + nPageBottomMargin = SWPAGE_WIDE_VALUE1; + bMirrored = true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageOrientationControl.cxx b/sw/source/uibase/sidebar/PageOrientationControl.cxx new file mode 100644 index 000000000..d44dd3a5b --- /dev/null +++ b/sw/source/uibase/sidebar/PageOrientationControl.cxx @@ -0,0 +1,194 @@ +/* -*- 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 "PageOrientationControl.hxx" +#include "PageMarginControl.hxx" +#include <PageOrientationPopup.hxx> +#include <com/sun/star/document/XUndoManager.hpp> +#include <com/sun/star/document/XUndoManagerSupplier.hpp> +#include <com/sun/star/frame/XFrame.hpp> + +#include <sfx2/viewsh.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> +#include <cmdid.h> + +namespace { + css::uno::Reference< css::document::XUndoManager > getUndoManager( const css::uno::Reference< css::frame::XFrame >& rxFrame ) + { + const css::uno::Reference< css::frame::XController >& xController = rxFrame->getController(); + if ( xController.is() ) + { + const css::uno::Reference< css::frame::XModel >& xModel = xController->getModel(); + if ( xModel.is() ) + { + const css::uno::Reference< css::document::XUndoManagerSupplier > xSuppUndo( xModel, css::uno::UNO_QUERY_THROW ); + return css::uno::Reference< css::document::XUndoManager >( xSuppUndo->getUndoManager(), css::uno::UNO_SET_THROW ); + } + } + + return css::uno::Reference< css::document::XUndoManager > (); + } +} + +namespace sw::sidebar { + +PageOrientationControl::PageOrientationControl(PageOrientationPopup* pControl, weld::Widget* pParent) + : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/swriter/ui/pageorientationcontrol.ui", "PageOrientationControl") + , m_xPortrait(m_xBuilder->weld_button("portrait")) + , m_xLandscape(m_xBuilder->weld_button("landscape")) + , m_xControl(pControl) + , mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ) + , mpPageSizeItem( new SvxSizeItem(SID_ATTR_PAGE_SIZE) ) + , mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ) + , mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ) +{ + m_xPortrait->connect_clicked( LINK( this, PageOrientationControl,ImplOrientationHdl ) ); + m_xLandscape->connect_clicked( LINK( this, PageOrientationControl,ImplOrientationHdl ) ); +} + +void PageOrientationControl::GrabFocus() +{ + m_xPortrait->grab_focus(); +} + +PageOrientationControl::~PageOrientationControl() +{ +} + +void PageOrientationControl::ExecuteMarginLRChange( + const long nPageLeftMargin, + const long nPageRightMargin ) +{ + mpPageLRMarginItem->SetLeft( nPageLeftMargin ); + mpPageLRMarginItem->SetRight( nPageRightMargin ); + SfxViewShell::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_LRSPACE, + SfxCallMode::RECORD, { mpPageLRMarginItem.get() }); +} + +void PageOrientationControl::ExecuteMarginULChange( + const long nPageTopMargin, + const long nPageBottomMargin ) +{ + mpPageULMarginItem->SetUpper( nPageTopMargin ); + mpPageULMarginItem->SetLower( nPageBottomMargin ); + SfxViewShell::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_ULSPACE, + SfxCallMode::RECORD, { mpPageULMarginItem.get() }); +} + +void PageOrientationControl::ExecuteOrientationChange( const bool bLandscape ) +{ + css::uno::Reference< css::document::XUndoManager > mxUndoManager( + getUndoManager( SfxViewFrame::Current()->GetFrame().GetFrameInterface() ) ); + + if ( mxUndoManager.is() ) + mxUndoManager->enterUndoContext( "" ); + + const SfxPoolItem* pItem; + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, pItem); + mpPageSizeItem.reset( static_cast<SvxSizeItem*>(pItem->Clone()) ); + + // Prevent accidental toggling of page orientation + if ((mpPageSizeItem->GetWidth() > mpPageSizeItem->GetHeight()) == bLandscape) + { + if ( mxUndoManager.is() ) + mxUndoManager->leaveUndoContext(); + return; + } + + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, pItem); + mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pItem->Clone()) ); + + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, pItem); + mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pItem->Clone()) ); + + { + // set new page orientation + mpPageItem->SetLandscape( bLandscape ); + + // swap the width and height of the page size + const long nRotatedWidth = mpPageSizeItem->GetSize().Height(); + const long nRotatedHeight = mpPageSizeItem->GetSize().Width(); + mpPageSizeItem->SetSize(Size(nRotatedWidth, nRotatedHeight)); + + // apply changed attributes + if (SfxViewShell::Current()) + { + SfxViewShell::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, + SfxCallMode::RECORD, { mpPageSizeItem.get(), mpPageItem.get() }); + } + } + + // check, if margin values still fit to the changed page size. + // if not, adjust margin values + { + const long nML = mpPageLRMarginItem->GetLeft(); + const long nMR = mpPageLRMarginItem->GetRight(); + const long nTmpPW = nML + nMR + MINBODY; + + const long nPW = mpPageSizeItem->GetSize().Width(); + + if ( nTmpPW > nPW ) + { + if ( nML <= nMR ) + { + ExecuteMarginLRChange( mpPageLRMarginItem->GetLeft(), nMR - (nTmpPW - nPW ) ); + } + else + { + ExecuteMarginLRChange( nML - (nTmpPW - nPW ), mpPageLRMarginItem->GetRight() ); + } + } + + const long nMT = mpPageULMarginItem->GetUpper(); + const long nMB = mpPageULMarginItem->GetLower(); + const long nTmpPH = nMT + nMB + MINBODY; + + const long nPH = mpPageSizeItem->GetSize().Height(); + + if ( nTmpPH > nPH ) + { + if ( nMT <= nMB ) + { + ExecuteMarginULChange( mpPageULMarginItem->GetUpper(), nMB - ( nTmpPH - nPH ) ); + } + else + { + ExecuteMarginULChange( nMT - ( nTmpPH - nPH ), mpPageULMarginItem->GetLower() ); + } + } + } + + if ( mxUndoManager.is() ) + mxUndoManager->leaveUndoContext(); +} + +IMPL_LINK(PageOrientationControl, ImplOrientationHdl, weld::Button&, rControl, void) +{ + if (&rControl == m_xPortrait.get()) + ExecuteOrientationChange( false ); + else + ExecuteOrientationChange( true ); + + m_xControl->EndPopupMode(); +} + +} // end of namespace sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageOrientationControl.hxx b/sw/source/uibase/sidebar/PageOrientationControl.hxx new file mode 100644 index 000000000..7cb825406 --- /dev/null +++ b/sw/source/uibase/sidebar/PageOrientationControl.hxx @@ -0,0 +1,60 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEORIENTATIONCONTROL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGEORIENTATIONCONTROL_HXX + +#include <memory> +#include <svtools/toolbarmenu.hxx> +#include <svx/pageitem.hxx> +#include <svx/rulritem.hxx> +#include <editeng/sizeitem.hxx> + +class PageOrientationPopup; + +namespace sw::sidebar { + +class PageOrientationControl final : public WeldToolbarPopup +{ +public: + explicit PageOrientationControl(PageOrientationPopup* pControl, weld::Widget* pParent); + virtual void GrabFocus() override; + virtual ~PageOrientationControl() override; + +private: + std::unique_ptr<weld::Button> m_xPortrait; + std::unique_ptr<weld::Button> m_xLandscape; + rtl::Reference<PageOrientationPopup> m_xControl; + + std::unique_ptr<SvxPageItem> mpPageItem; + std::unique_ptr<SvxSizeItem> mpPageSizeItem; + std::unique_ptr<SvxLongLRSpaceItem> mpPageLRMarginItem; + std::unique_ptr<SvxLongULSpaceItem> mpPageULMarginItem; + + void ExecuteMarginULChange(const long nPageTopMargin, const long nPageBottomMargin); + void ExecuteMarginLRChange(const long nPageLeftMargin, const long nPageRightMargin); + void ExecuteOrientationChange(const bool bLandscape); + + DECL_LINK(ImplOrientationHdl, weld::Button&, void); +}; + +} // end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageOrientationPopup.cxx b/sw/source/uibase/sidebar/PageOrientationPopup.cxx new file mode 100644 index 000000000..9b34f3c1d --- /dev/null +++ b/sw/source/uibase/sidebar/PageOrientationPopup.cxx @@ -0,0 +1,76 @@ +/* -*- 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 <PageOrientationPopup.hxx> +#include "PageOrientationControl.hxx" +#include <svx/pageitem.hxx> +#include <vcl/toolbox.hxx> + +PageOrientationPopup::PageOrientationPopup(const css::uno::Reference<css::uno::XComponentContext>& rContext) + : PopupWindowController(rContext, nullptr, OUString()) +{ +} + +void PageOrientationPopup::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) +{ + PopupWindowController::initialize(rArguments); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) + pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWNONLY | pToolBox->GetItemBits(nId)); +} + +PageOrientationPopup::~PageOrientationPopup() +{ +} + +std::unique_ptr<WeldToolbarPopup> PageOrientationPopup::weldPopupWindow() +{ + return std::make_unique<sw::sidebar::PageOrientationControl>(this, m_pToolbar); +} + +VclPtr<vcl::Window> PageOrientationPopup::createVclPopupWindow( vcl::Window* pParent ) +{ + mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, + std::make_unique<sw::sidebar::PageOrientationControl>(this, pParent->GetFrameWeld())); + + mxInterimPopover->Show(); + + return mxInterimPopover; +} + +OUString PageOrientationPopup::getImplementationName() +{ + return "lo.writer.PageOrientationToolBoxControl"; +} + +css::uno::Sequence<OUString> PageOrientationPopup::getSupportedServiceNames() +{ + return { "com.sun.star.frame.ToolbarController" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +lo_writer_PageOrientationToolBoxControl_get_implementation( + css::uno::XComponentContext* rContext, + css::uno::Sequence<css::uno::Any> const & ) +{ + return cppu::acquire(new PageOrientationPopup(rContext)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageSizeControl.cxx b/sw/source/uibase/sidebar/PageSizeControl.cxx new file mode 100644 index 000000000..5abdb4788 --- /dev/null +++ b/sw/source/uibase/sidebar/PageSizeControl.cxx @@ -0,0 +1,238 @@ +/* -*- 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 <memory> +#include "PageSizeControl.hxx" + +#include <cmdid.h> +#include <svx/pageitem.hxx> +#include <svx/sidebar/ValueSetWithTextControl.hxx> + +#include <unotools/localedatawrapper.hxx> +#include <rtl/character.hxx> +#include <editeng/paperinf.hxx> +#include <sfx2/app.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/module.hxx> +#include <sfx2/viewfrm.hxx> + +#include <vcl/settings.hxx> +#include <svl/itempool.hxx> +#include <svl/intitem.hxx> +#include <svtools/unitconv.hxx> +#include <editeng/sizeitem.hxx> + +#include <PageSizePopup.hxx> + +namespace +{ + FieldUnit lcl_GetFieldUnit() + { + FieldUnit eUnit = FieldUnit::INCH; + const SfxPoolItem* pItem = nullptr; + SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_METRIC, pItem ); + if ( pItem && eState >= SfxItemState::DEFAULT ) + { + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); + } + else + { + return SfxModule::GetCurrentFieldUnit(); + } + + return eUnit; + } + + MapUnit lcl_GetUnit() + { + SfxItemPool &rPool = SfxGetpApp()->GetPool(); + sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_PAGE_SIZE ); + return rPool.GetMetric( nWhich ); + } +} + +namespace sw::sidebar { + +PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent) + : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/swriter/ui/pagesizecontrol.ui", "PageSizeControl") + , mxMoreButton(m_xBuilder->weld_button("moreoptions")) + , mxWidthHeightField(m_xBuilder->weld_metric_spin_button("metric", FieldUnit::CM)) + , mxSizeValueSet(new svx::sidebar::ValueSetWithTextControl) + , mxSizeValueSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxSizeValueSet)) + , mxControl(pControl) + , maPaperList() +{ + mxWidthHeightField->set_unit(FieldUnit::CM); + mxWidthHeightField->set_range(0, 9999, FieldUnit::NONE); + mxWidthHeightField->set_digits(2); + mxWidthHeightField->set_increments(10, 100, FieldUnit::NONE); + SetFieldUnit( *mxWidthHeightField, lcl_GetFieldUnit() ); + + maPaperList.push_back( PAPER_A3 ); + maPaperList.push_back( PAPER_A4 ); + maPaperList.push_back( PAPER_A5 ); + maPaperList.push_back( PAPER_B4_ISO ); + maPaperList.push_back( PAPER_B5_ISO ); + maPaperList.push_back( PAPER_ENV_C5 ); + maPaperList.push_back( PAPER_LETTER ); + maPaperList.push_back( PAPER_LEGAL ); + + mxSizeValueSet->SetStyle( mxSizeValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT ); + mxSizeValueSet->SetColor( Application::GetSettings().GetStyleSettings().GetMenuColor() ); + + sal_uInt16 nSelectedItem = 0; + { + OUString aMetricStr; + { + const OUString aText = mxWidthHeightField->get_text(); + for (short i = aText.getLength() - 1; i >= 0; i--) + { + sal_Unicode c = aText[i]; + if ( rtl::isAsciiAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') ) + { + aMetricStr = OUStringChar(c) + aMetricStr; + } + else + { + if (!aMetricStr.isEmpty()) + { + break; + } + } + } + } + + bool bLandscape = false; + const SfxPoolItem* pItem; + const SvxSizeItem* pSize = nullptr; + if ( SfxViewFrame::Current() ) + { + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem ); + bLandscape = static_cast<const SvxPageItem*>(pItem)->IsLandscape(); + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pItem ); + pSize = static_cast<const SvxSizeItem*>(pItem); + } + + const LocaleDataWrapper& localeDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); + OUString aWidthStr; + OUString aHeightStr; + OUString aItemText2; + for ( std::vector< Paper >::size_type nPaperIdx = 0; + nPaperIdx < maPaperList.size(); + ++nPaperIdx ) + { + Size aPaperSize = SvxPaperInfo::GetPaperSize( maPaperList[ nPaperIdx ] ); + if ( bLandscape ) + { + Swap( aPaperSize ); + } + + mxWidthHeightField->set_value( mxWidthHeightField->normalize( aPaperSize.Width() ), FieldUnit::TWIP ); + aWidthStr = localeDataWrapper.getNum( + mxWidthHeightField->get_value(FieldUnit::NONE), + mxWidthHeightField->get_digits(), + true, + true ); + + mxWidthHeightField->set_value( mxWidthHeightField->normalize( aPaperSize.Height() ), FieldUnit::TWIP); + aHeightStr = localeDataWrapper.getNum( + mxWidthHeightField->get_value(FieldUnit::NONE), + mxWidthHeightField->get_digits(), + true, + true ); + + aItemText2 = aWidthStr + " x " + aHeightStr + " " + aMetricStr; + + mxSizeValueSet->AddItem( + SvxPaperInfo::GetName( maPaperList[ nPaperIdx ] ), + aItemText2 ); + + if ( pSize && aPaperSize == pSize->GetSize() ) + { + nSelectedItem = nPaperIdx + 1; + } + } + } + mxSizeValueSet->SetNoSelection(); + mxSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl, ImplSizeHdl ) ); + mxSizeValueSet->Show(); + mxSizeValueSet->Resize(); + + mxSizeValueSet->SelectItem( nSelectedItem ); + mxSizeValueSet->SetFormat(); + mxSizeValueSet->Invalidate(); + + mxMoreButton->connect_clicked( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) ); + mxMoreButton->grab_focus(); +} + +void PageSizeControl::GrabFocus() +{ + mxSizeValueSet->GrabFocus(); +} + +PageSizeControl::~PageSizeControl() +{ +} + +void PageSizeControl::ExecuteSizeChange( const Paper ePaper ) +{ + bool bLandscape = false; + const SfxPoolItem *pItem; + MapUnit eUnit = lcl_GetUnit(); + if ( SfxViewFrame::Current() ) + { + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem ); + bLandscape = static_cast<const SvxPageItem*>(pItem)->IsLandscape(); + + std::unique_ptr<SvxSizeItem> pPageSizeItem( new SvxSizeItem(SID_ATTR_PAGE_SIZE) ); + Size aPageSize = SvxPaperInfo::GetPaperSize( ePaper, eUnit ); + if ( bLandscape ) + { + Swap( aPageSize ); + } + pPageSizeItem->SetSize( aPageSize ); + + SfxViewFrame::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, + SfxCallMode::RECORD, { pPageSizeItem.get() }); + } +} + + +IMPL_LINK_NOARG(PageSizeControl, ImplSizeHdl, ValueSet*, void) +{ + mxSizeValueSet->SetNoSelection(); + const sal_uInt16 nSelectedPaper = mxSizeValueSet->GetSelectedItemId(); + const Paper ePaper = maPaperList[nSelectedPaper - 1]; + ExecuteSizeChange( ePaper ); + + mxControl->EndPopupMode(); +} + +IMPL_LINK_NOARG(PageSizeControl, MoreButtonClickHdl_Impl, weld::Button&, void) +{ + if ( SfxViewFrame::Current() ) + SfxViewFrame::Current()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SfxCallMode::ASYNCHRON ); + mxControl->EndPopupMode(); +} + +} // end of namespace sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageSizeControl.hxx b/sw/source/uibase/sidebar/PageSizeControl.hxx new file mode 100644 index 000000000..be43d0900 --- /dev/null +++ b/sw/source/uibase/sidebar/PageSizeControl.hxx @@ -0,0 +1,62 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESIZECONTROL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESIZECONTROL_HXX + +#include <i18nutil/paper.hxx> + +#include <svtools/toolbarmenu.hxx> +#include <svtools/valueset.hxx> + +#include <vector> + +namespace svx::sidebar { class ValueSetWithTextControl; } +class PageSizePopup; +class ValueSet; + +namespace sw::sidebar { + +class PageSizeControl final : public WeldToolbarPopup +{ +public: + explicit PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent); + virtual void GrabFocus() override; + virtual ~PageSizeControl() override; + +private: + std::unique_ptr<weld::Button> mxMoreButton; + // hidden metric field + std::unique_ptr<weld::MetricSpinButton> mxWidthHeightField; + std::unique_ptr<svx::sidebar::ValueSetWithTextControl> mxSizeValueSet; + std::unique_ptr<weld::CustomWeld> mxSizeValueSetWin; + rtl::Reference<PageSizePopup> mxControl; + + std::vector< Paper > maPaperList; + + static void ExecuteSizeChange( const Paper ePaper ); + + DECL_LINK(ImplSizeHdl, ValueSet*, void); + DECL_LINK(MoreButtonClickHdl_Impl, weld::Button&, void); +}; + +} // end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageSizePopup.cxx b/sw/source/uibase/sidebar/PageSizePopup.cxx new file mode 100644 index 000000000..0c69f73ba --- /dev/null +++ b/sw/source/uibase/sidebar/PageSizePopup.cxx @@ -0,0 +1,76 @@ +/* -*- 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 <PageSizePopup.hxx> +#include "PageSizeControl.hxx" +#include <editeng/sizeitem.hxx> +#include <vcl/toolbox.hxx> + +PageSizePopup::PageSizePopup(const css::uno::Reference<css::uno::XComponentContext>& rContext) + : PopupWindowController(rContext, nullptr, OUString()) +{ +} + +void PageSizePopup::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) +{ + PopupWindowController::initialize(rArguments); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) + pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWNONLY | pToolBox->GetItemBits(nId)); +} + +PageSizePopup::~PageSizePopup() +{ +} + +std::unique_ptr<WeldToolbarPopup> PageSizePopup::weldPopupWindow() +{ + return std::make_unique<sw::sidebar::PageSizeControl>(this, m_pToolbar); +} + +VclPtr<vcl::Window> PageSizePopup::createVclPopupWindow( vcl::Window* pParent ) +{ + mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, + std::make_unique<sw::sidebar::PageSizeControl>(this, pParent->GetFrameWeld())); + + mxInterimPopover->Show(); + + return mxInterimPopover; +} + +OUString PageSizePopup::getImplementationName() +{ + return "lo.writer.PageSizeToolBoxControl"; +} + +css::uno::Sequence<OUString> PageSizePopup::getSupportedServiceNames() +{ + return { "com.sun.star.frame.ToolbarController" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +lo_writer_PageSizeToolBoxControl_get_implementation( + css::uno::XComponentContext* rContext, + css::uno::Sequence<css::uno::Any> const & ) +{ + return cppu::acquire(new PageSizePopup(rContext)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageStylesPanel.cxx b/sw/source/uibase/sidebar/PageStylesPanel.cxx new file mode 100644 index 000000000..1815466c1 --- /dev/null +++ b/sw/source/uibase/sidebar/PageStylesPanel.cxx @@ -0,0 +1,604 @@ +/* -*- 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 <svl/intitem.hxx> +#include <svx/colorbox.hxx> +#include <svx/drawitem.hxx> +#include <svx/xfillit0.hxx> +#include <svx/xflclit.hxx> +#include <svx/xflgrit.hxx> +#include <svx/xflhtit.hxx> +#include <svx/xbtmpit.hxx> +#include <svx/SvxNumOptionsTabPageHelper.hxx> +#include "PageStylesPanel.hxx" +#include <sfx2/dispatch.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/objsh.hxx> +#include <cmdid.h> + +using namespace ::com::sun::star; + +namespace sw::sidebar{ + +namespace { + +enum eFillStyle +{ + NONE, + SOLID, + GRADIENT, + HATCH, + BITMAP, + PATTERN +}; + +} + +const SvxPageUsage aArr[] = +{ + SvxPageUsage::All, + SvxPageUsage::Mirror, + SvxPageUsage::Right, + SvxPageUsage::Left +}; + + +static sal_uInt16 PageUsageToPos_Impl( SvxPageUsage nUsage ) +{ + for ( size_t i = 0; i < SAL_N_ELEMENTS(aArr); ++i ) + if ( aArr[i] == nUsage ) + return i; + return 3; +} + + +static SvxPageUsage PosToPageUsage_Impl( sal_uInt16 nPos ) +{ + if ( nPos >= SAL_N_ELEMENTS(aArr) ) + return SvxPageUsage::NONE; + return aArr[nPos]; +} + +VclPtr<vcl::Window> PageStylesPanel::Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings) +{ + if( pParent == nullptr ) + throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageStylesPanel::Create", nullptr, 0); + if( !rxFrame.is() ) + throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageStylesPanel::Create", nullptr, 0); + if( pBindings == nullptr ) + throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageStylesPanel::Create", nullptr, 0); + + return VclPtr<PageStylesPanel>::Create(pParent, rxFrame, pBindings); +} + +PageStylesPanel::PageStylesPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings + ) : + PanelLayout(pParent, "PageStylesPanel", "modules/swriter/ui/pagestylespanel.ui", rxFrame), + mpBindings( pBindings ), + mpPageColumnItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN) ), + mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ), + maPageColumnControl(SID_ATTR_PAGE_COLUMN, *pBindings, *this), + maPageNumFormatControl( SID_ATTR_PAGE, *pBindings, *this ), + maBgColorControl( SID_ATTR_PAGE_COLOR, *pBindings, *this ), + maBgHatchingControl( SID_ATTR_PAGE_HATCH, *pBindings, *this ), + maBgGradientControl( SID_ATTR_PAGE_GRADIENT, *pBindings, *this ), + maBgBitmapControl( SID_ATTR_PAGE_BITMAP, *pBindings, *this ), + maBgFillStyleControl(SID_ATTR_PAGE_FILLSTYLE, *pBindings, *this), + mxBgColorLB(new ColorListBox(m_xBuilder->weld_menu_button("lbcolor"), GetFrameWeld())), + mxBgHatchingLB(m_xBuilder->weld_combo_box("lbhatching")), + mxBgGradientLB(new ColorListBox(m_xBuilder->weld_menu_button("lbgradient"), GetFrameWeld())), + mxBgBitmapLB(m_xBuilder->weld_combo_box("lbbitmap")), + mxLayoutSelectLB(m_xBuilder->weld_combo_box("layoutbox")), + mxColumnCount(m_xBuilder->weld_combo_box("columnbox")), + mxNumberSelectLB(new SvxPageNumberListBox(m_xBuilder->weld_combo_box("numberbox"))), + mxBgFillType(m_xBuilder->weld_combo_box("bgselect")), + mxCustomEntry(m_xBuilder->weld_label("customlabel")), + aCustomEntry() +{ + Initialize(); +} + +PageStylesPanel::~PageStylesPanel() +{ + disposeOnce(); +} + +void PageStylesPanel::dispose() +{ + mxColumnCount.reset(); + mxNumberSelectLB.reset(); + mxBgFillType.reset(); + mxBgColorLB.reset(); + mxBgHatchingLB.reset(); + mxBgGradientLB.reset(); + mxBgBitmapLB.reset(); + mxLayoutSelectLB.reset(); + mxCustomEntry.reset(); + + maBgBitmapControl.dispose(); + maBgColorControl.dispose(); + maBgFillStyleControl.dispose(); + maBgGradientControl.dispose(); + maBgHatchingControl.dispose(); + maPageColumnControl.dispose(); + maPageNumFormatControl.dispose(); + PanelLayout::dispose(); +} + +void PageStylesPanel::Initialize() +{ + SvxFillTypeBox::Fill(*mxBgFillType); + + aCustomEntry = mxCustomEntry->get_label(); + mpBindings->Invalidate(SID_ATTR_PAGE_COLUMN); + mpBindings->Invalidate(SID_ATTR_PAGE); + mpBindings->Invalidate(SID_ATTR_PAGE_FILLSTYLE); + Update(); + + mxColumnCount->connect_changed( LINK(this, PageStylesPanel, ModifyColumnCountHdl) ); + SvxNumOptionsTabPageHelper::GetI18nNumbering(mxNumberSelectLB->get_widget(), ::std::numeric_limits<sal_uInt16>::max()); + mxNumberSelectLB->connect_changed( LINK(this, PageStylesPanel, ModifyNumberingHdl) ); + mxLayoutSelectLB->connect_changed( LINK(this, PageStylesPanel, ModifyLayoutHdl) ); + mxBgFillType->connect_changed( LINK(this, PageStylesPanel, ModifyFillStyleHdl)); + mxBgColorLB->SetSelectHdl( LINK(this, PageStylesPanel, ModifyFillColorListHdl)); + mxBgGradientLB->SetSelectHdl( LINK(this, PageStylesPanel, ModifyFillColorListHdl)); + mxBgHatchingLB->connect_changed( LINK(this, PageStylesPanel, ModifyFillColorHdl)); + mxBgBitmapLB->connect_changed( LINK(this, PageStylesPanel, ModifyFillColorHdl)); +} + +void PageStylesPanel::Update() +{ + const eFillStyle eXFS = static_cast<eFillStyle>(mxBgFillType->get_active()); + SfxObjectShell* pSh = SfxObjectShell::Current(); + switch(eXFS) + { + case NONE: + { + mxBgColorLB->hide(); + mxBgHatchingLB->hide(); + mxBgGradientLB->hide(); + mxBgBitmapLB->hide(); + } + break; + case SOLID: + { + mxBgBitmapLB->hide(); + mxBgGradientLB->hide(); + mxBgHatchingLB->hide(); + mxBgColorLB->show(); + const Color aColor = GetColorSetOrDefault(); + mxBgColorLB->SelectEntry(aColor); + } + break; + case GRADIENT: + { + mxBgBitmapLB->hide(); + mxBgHatchingLB->hide(); + mxBgColorLB->show(); + mxBgGradientLB->show(); + + const XGradient xGradient = GetGradientSetOrDefault(); + const Color aStartColor = xGradient.GetStartColor(); + mxBgColorLB->SelectEntry(aStartColor); + const Color aEndColor = xGradient.GetEndColor(); + mxBgGradientLB->SelectEntry(aEndColor); + } + break; + + case HATCH: + { + mxBgColorLB->hide(); + mxBgGradientLB->hide(); + mxBgBitmapLB->hide(); + mxBgHatchingLB->show(); + mxBgHatchingLB->clear(); + SvxFillAttrBox::Fill(*mxBgHatchingLB, pSh->GetItem(SID_HATCH_LIST)->GetHatchList()); + + const OUString aHatchName = GetHatchingSetOrDefault(); + mxBgHatchingLB->set_active_text( aHatchName ); + } + break; + + case BITMAP: + case PATTERN: + { + mxBgColorLB->hide(); + mxBgGradientLB->hide(); + mxBgHatchingLB->hide(); + mxBgBitmapLB->show(); + mxBgBitmapLB->clear(); + OUString aBitmapName; + + if( eXFS == BITMAP ) + { + SvxFillAttrBox::Fill(*mxBgBitmapLB, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList()); + aBitmapName = GetBitmapSetOrDefault(); + } + else + { + SvxFillAttrBox::Fill(*mxBgBitmapLB, pSh->GetItem(SID_PATTERN_LIST)->GetPatternList()); + aBitmapName = GetPatternSetOrDefault(); + } + + mxBgBitmapLB->set_active_text( aBitmapName ); + } + break; + + default: + break; + } +} + +Color const & PageStylesPanel::GetColorSetOrDefault() +{ + if ( !mpBgColorItem ) + mpBgColorItem.reset( new XFillColorItem( OUString(), Color(0x72, 0x9f, 0xcf) ) ); + + return mpBgColorItem->GetColorValue(); +} + +XGradient const & PageStylesPanel::GetGradientSetOrDefault() +{ + if( !mpBgGradientItem ) + { + SfxObjectShell* pSh = SfxObjectShell::Current(); + const SvxGradientListItem * pGradListItem = pSh->GetItem(SID_GRADIENT_LIST); + const XGradient aGradient = pGradListItem->GetGradientList()->GetGradient(0)->GetGradient(); + const OUString aGradientName = pGradListItem->GetGradientList()->GetGradient(0)->GetName(); + + mpBgGradientItem.reset( new XFillGradientItem( aGradientName, aGradient ) ); + } + + return mpBgGradientItem->GetGradientValue(); +} + +OUString const & PageStylesPanel::GetHatchingSetOrDefault() +{ + if( !mpBgHatchItem ) + { + SfxObjectShell* pSh = SfxObjectShell::Current(); + const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST); + const XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch(); + const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(0)->GetName(); + + mpBgHatchItem.reset( new XFillHatchItem( aHatchName, aHatch ) ); + } + + return mpBgHatchItem->GetName(); +} + +OUString const & PageStylesPanel::GetBitmapSetOrDefault() +{ + if( !mpBgBitmapItem || mpBgBitmapItem->isPattern() ) + { + SfxObjectShell* pSh = SfxObjectShell::Current(); + const SvxBitmapListItem * pBmpListItem = pSh->GetItem(SID_BITMAP_LIST); + const GraphicObject aGraphObj = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject(); + const OUString aBmpName = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName(); + + mpBgBitmapItem.reset( new XFillBitmapItem( aBmpName, aGraphObj ) ); + } + + return mpBgBitmapItem->GetName(); +} + +OUString const & PageStylesPanel::GetPatternSetOrDefault() +{ + if( !mpBgBitmapItem || !mpBgBitmapItem->isPattern() ) + { + SfxObjectShell* pSh = SfxObjectShell::Current(); + const SvxPatternListItem * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST); + const GraphicObject aGraphObj = pPatternListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject(); + const OUString aPatternName = pPatternListItem->GetPatternList()->GetBitmap(0)->GetName(); + + mpBgBitmapItem.reset( new XFillBitmapItem( aPatternName, aGraphObj ) ); + } + + return mpBgBitmapItem->GetName(); +} + +void PageStylesPanel::NotifyItemUpdate( + const sal_uInt16 nSid, + const SfxItemState eState, + const SfxPoolItem* pState) +{ + if(IsDisposed()) + return; + + switch(nSid) + { + case SID_ATTR_PAGE_COLUMN: + { + if ( eState >= SfxItemState::DEFAULT && + dynamic_cast< const SfxInt16Item *>( pState ) ) + { + mpPageColumnItem.reset( static_cast<SfxInt16Item*>(pState->Clone()) ); + if(mpPageColumnItem->GetValue() <= 5) + { + mxColumnCount->set_active(mpPageColumnItem->GetValue() - 1); + int nIndex = mxColumnCount->find_text(aCustomEntry); + if (nIndex != -1) + mxColumnCount->remove(nIndex); + } + else + { + if (mxColumnCount->find_text(aCustomEntry) == -1) + mxColumnCount->append_text(aCustomEntry); + mxColumnCount->set_active_text(aCustomEntry); + } + } + } + break; + + case SID_ATTR_PAGE: + { + if( eState >= SfxItemState::DEFAULT && + dynamic_cast< const SvxPageItem*>( pState ) ) + { + mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) ); + SvxNumType eNumType = mpPageItem->GetNumType(); + mxNumberSelectLB->set_active_id(eNumType); + + SvxPageUsage nUse = mpPageItem->GetPageUsage(); + mxLayoutSelectLB->set_active( PageUsageToPos_Impl( nUse ) ); + } + } + break; + + case SID_ATTR_PAGE_COLOR: + { + if(eState >= SfxItemState::DEFAULT) + { + mxBgFillType->set_active( static_cast<sal_Int32>(SOLID) ); + mpBgColorItem.reset(pState ? static_cast< XFillColorItem* >(pState->Clone()) : nullptr); + Update(); + } + } + break; + + case SID_ATTR_PAGE_HATCH: + { + if(eState >= SfxItemState::DEFAULT) + { + mxBgFillType->set_active( static_cast<sal_Int32>(HATCH) ); + mpBgHatchItem.reset(pState ? static_cast < XFillHatchItem* >(pState->Clone()) : nullptr); + Update(); + } + } + break; + + case SID_ATTR_PAGE_GRADIENT: + { + if(eState >= SfxItemState::DEFAULT) + { + mxBgFillType->set_active( static_cast<sal_Int32>(GRADIENT) ); + mpBgGradientItem.reset(pState ? static_cast< XFillGradientItem* >(pState->Clone()) : nullptr); + Update(); + } + } + break; + case SID_ATTR_PAGE_BITMAP: + { + if(eState >= SfxItemState::DEFAULT) + { + mpBgBitmapItem.reset(pState ? static_cast< XFillBitmapItem* >(pState->Clone()) : nullptr); + if (mpBgBitmapItem) + { + if (mpBgBitmapItem->isPattern()) + mxBgFillType->set_active( static_cast<sal_Int32>(PATTERN) ); + else + mxBgFillType->set_active( static_cast<sal_Int32>(BITMAP) ); + } + Update(); + } + } + break; + + case SID_ATTR_PAGE_FILLSTYLE: + { + const XFillStyleItem* pFillStyleItem = nullptr; + if (eState >= SfxItemState::DEFAULT) + pFillStyleItem = dynamic_cast< const XFillStyleItem* >(pState); + if (pFillStyleItem) + { + css::drawing::FillStyle eXFS = pFillStyleItem->GetValue(); + switch(eXFS) + { + case drawing::FillStyle_NONE: + mxBgFillType->set_active( static_cast<sal_Int32>(NONE) ); + break; + case drawing::FillStyle_SOLID: + mxBgFillType->set_active( static_cast<sal_Int32>(SOLID) ); + break; + case drawing::FillStyle_GRADIENT: + mxBgFillType->set_active( static_cast<sal_Int32>(GRADIENT) ); + break; + case drawing::FillStyle_HATCH: + mxBgFillType->set_active( static_cast<sal_Int32>(HATCH) ); + break; + case drawing::FillStyle_BITMAP: + if (mpBgBitmapItem->isPattern()) + mxBgFillType->set_active( static_cast<sal_Int32>(PATTERN) ); + else + mxBgFillType->set_active( static_cast<sal_Int32>(BITMAP) ); + break; + default: + break; + } + Update(); + } + } + break; + + default: + break; + } +} + +IMPL_LINK_NOARG( PageStylesPanel, ModifyColumnCountHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nColumnType = mxColumnCount->get_active() + 1; + mpPageColumnItem->SetValue( nColumnType ); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN, + SfxCallMode::RECORD, { mpPageColumnItem.get() }); +} + +IMPL_LINK_NOARG( PageStylesPanel, ModifyNumberingHdl, weld::ComboBox&, void ) +{ + SvxNumType nEntryData = mxNumberSelectLB->get_active_id(); + mpPageItem->SetNumType(nEntryData); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE, SfxCallMode::RECORD, { mpPageItem.get() }); +} + +IMPL_LINK_NOARG( PageStylesPanel, ModifyLayoutHdl, weld::ComboBox&, void ) +{ + sal_uInt16 nUse = mxLayoutSelectLB->get_active(); + mpPageItem->SetPageUsage(PosToPageUsage_Impl(nUse)); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE, SfxCallMode::RECORD, { mpPageItem.get() }); +} + +IMPL_LINK_NOARG(PageStylesPanel, ModifyFillStyleHdl, weld::ComboBox&, void) +{ + const eFillStyle eXFS = static_cast<eFillStyle>(mxBgFillType->get_active()); + Update(); + + switch (eXFS) + { + case NONE: + { + const XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_FILLSTYLE, SfxCallMode::RECORD, { &aXFillStyleItem }); + } + break; + + case SOLID: + { + XFillColorItem aItem( OUString(), mpBgColorItem->GetColorValue() ); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLOR, SfxCallMode::RECORD, { &aItem }); + } + break; + + case GRADIENT: + { + XFillGradientItem aItem( mpBgGradientItem->GetName(), mpBgGradientItem->GetGradientValue() ); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_GRADIENT, SfxCallMode::RECORD, { &aItem }); + } + break; + + case HATCH: + { + XFillHatchItem aItem( mpBgHatchItem->GetName(), mpBgHatchItem->GetHatchValue() ); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, SfxCallMode::RECORD, { &aItem }); + } + break; + + case BITMAP: + case PATTERN: + { + XFillBitmapItem aItem( mpBgBitmapItem->GetName(), mpBgBitmapItem->GetGraphicObject() ); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, SfxCallMode::RECORD, { &aItem }); + } + break; + + default: + break; + } +} + +void PageStylesPanel::ModifyFillColor() +{ + const eFillStyle eXFS = static_cast<eFillStyle>(mxBgFillType->get_active()); + SfxObjectShell* pSh = SfxObjectShell::Current(); + switch(eXFS) + { + case SOLID: + { + XFillColorItem aItem(OUString(), mxBgColorLB->GetSelectEntryColor()); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLOR, SfxCallMode::RECORD, { &aItem }); + } + break; + case GRADIENT: + { + XGradient aGradient; + aGradient.SetStartColor(mxBgColorLB->GetSelectEntryColor()); + aGradient.SetEndColor(mxBgGradientLB->GetSelectEntryColor()); + + XFillGradientItem aItem(aGradient); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_GRADIENT, SfxCallMode::RECORD, { &aItem }); + } + break; + case HATCH: + { + const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST); + sal_uInt16 nPos = mxBgHatchingLB->get_active(); + XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetHatch(); + const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetName(); + + XFillHatchItem aItem(aHatchName, aHatch); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, SfxCallMode::RECORD, { &aItem }); + } + break; + case BITMAP: + case PATTERN: + { + sal_Int16 nPos = mxBgBitmapLB->get_active(); + GraphicObject aBitmap; + OUString aBitmapName; + + if ( eXFS == BITMAP ) + { + SvxBitmapListItem const * pBitmapListItem = pSh->GetItem(SID_BITMAP_LIST); + aBitmap = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetGraphicObject(); + aBitmapName = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetName(); + } + else + { + SvxPatternListItem const * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST); + aBitmap = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetGraphicObject(); + aBitmapName = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetName(); + } + + XFillBitmapItem aItem(aBitmapName, aBitmap); + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, SfxCallMode::RECORD, { &aItem }); + } + break; + default: + break; + } +} + +IMPL_LINK_NOARG(PageStylesPanel, ModifyFillColorHdl, weld::ComboBox&, void) +{ + ModifyFillColor(); +} + +IMPL_LINK_NOARG(PageStylesPanel, ModifyFillColorListHdl, ColorListBox&, void) +{ + ModifyFillColor(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/PageStylesPanel.hxx b/sw/source/uibase/sidebar/PageStylesPanel.hxx new file mode 100644 index 000000000..7e3c09d2e --- /dev/null +++ b/sw/source/uibase/sidebar/PageStylesPanel.hxx @@ -0,0 +1,123 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESTYLESPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESTYLESPANEL_HXX + +#include <memory> +#include <com/sun/star/frame/XFrame.hpp> + +#include <sfx2/sidebar/PanelLayout.hxx> + +#include <sfx2/sidebar/ControllerItem.hxx> + +#include <svx/pageitem.hxx> + +#include <svl/intitem.hxx> +#include <svl/poolitem.hxx> +#include <svx/xbtmpit.hxx> +#include <svx/xflclit.hxx> +#include <svx/xflgrit.hxx> +#include <svx/xflhtit.hxx> +#include <svx/itemwin.hxx> +#include <svx/pagenumberlistbox.hxx> + +class List; +class ColorListBox; +namespace sw::sidebar { + +class PageStylesPanel: + public PanelLayout, + public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ +public: + static VclPtr<vcl::Window> Create( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + + virtual void NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + + SfxBindings* GetBindings() const { return mpBindings; } + PageStylesPanel( + vcl::Window* pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame, + SfxBindings* pBindings); + virtual ~PageStylesPanel() override; + virtual void dispose() override; + +private: + + SfxBindings* mpBindings; + + ::std::unique_ptr<SfxInt16Item> mpPageColumnItem; + ::std::unique_ptr<SvxPageItem> mpPageItem; + ::std::unique_ptr<XFillColorItem> mpBgColorItem; + ::std::unique_ptr<XFillGradientItem> mpBgGradientItem; + ::std::unique_ptr<XFillHatchItem> mpBgHatchItem; + ::std::unique_ptr<XFillBitmapItem> mpBgBitmapItem; + + ::sfx2::sidebar::ControllerItem maPageColumnControl; + ::sfx2::sidebar::ControllerItem maPageNumFormatControl; + ::sfx2::sidebar::ControllerItem maBgColorControl; + ::sfx2::sidebar::ControllerItem maBgHatchingControl; + ::sfx2::sidebar::ControllerItem maBgGradientControl; + ::sfx2::sidebar::ControllerItem maBgBitmapControl; + ::sfx2::sidebar::ControllerItem maBgFillStyleControl; + + std::unique_ptr<ColorListBox> mxBgColorLB; + std::unique_ptr<weld::ComboBox> mxBgHatchingLB; + std::unique_ptr<ColorListBox> mxBgGradientLB; + std::unique_ptr<weld::ComboBox> mxBgBitmapLB; + std::unique_ptr<weld::ComboBox> mxLayoutSelectLB; + std::unique_ptr<weld::ComboBox> mxColumnCount; + std::unique_ptr<SvxPageNumberListBox> mxNumberSelectLB; + std::unique_ptr<weld::ComboBox> mxBgFillType; + std::unique_ptr<weld::Label> mxCustomEntry; + OUString aCustomEntry; + + void Initialize(); + void Update(); + Color const & GetColorSetOrDefault(); + XGradient const & GetGradientSetOrDefault(); + OUString const & GetHatchingSetOrDefault(); + OUString const & GetBitmapSetOrDefault(); + OUString const & GetPatternSetOrDefault(); + + void ModifyFillColor(); + + DECL_LINK( ModifyColumnCountHdl, weld::ComboBox&, void ); + DECL_LINK( ModifyNumberingHdl, weld::ComboBox&, void ); + DECL_LINK( ModifyLayoutHdl, weld::ComboBox&, void ); + DECL_LINK( ModifyFillStyleHdl, weld::ComboBox&, void ); + DECL_LINK( ModifyFillColorHdl, weld::ComboBox&, void ); + DECL_LINK( ModifyFillColorListHdl, ColorListBox&, void ); +}; + +} //end of namespace sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/StylePresetsPanel.cxx b/sw/source/uibase/sidebar/StylePresetsPanel.cxx new file mode 100644 index 000000000..4d82afe29 --- /dev/null +++ b/sw/source/uibase/sidebar/StylePresetsPanel.cxx @@ -0,0 +1,217 @@ +/* -*- 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/. + * + */ + +#include <sal/config.h> + +#include "StylePresetsPanel.hxx" + +#include <vcl/image.hxx> +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> + +#include <sfx2/objsh.hxx> +#include <sfx2/StylePreviewRenderer.hxx> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +#include <sfx2/doctempl.hxx> + +#include <shellio.hxx> +#include <docsh.hxx> + +#include <sfx2/docfile.hxx> + +namespace sw::sidebar { + +namespace { + +void renderPreview(sfx2::StyleManager* pStyleManager, OutputDevice& aOutputDevice, + OUString const & sName, sal_Int32 nHeight, tools::Rectangle const & aRect) +{ + SfxStyleSheetBase* pStyleSheet = pStyleManager->Search(sName, SfxStyleFamily::Para); + + if (pStyleSheet) + { + std::unique_ptr<sfx2::StylePreviewRenderer> pStylePreviewRenderer + = pStyleManager->CreateStylePreviewRenderer(aOutputDevice, pStyleSheet, nHeight); + pStylePreviewRenderer->recalculate(); + pStylePreviewRenderer->render(aRect, sfx2::StylePreviewRenderer::RenderAlign::TOP); + } +} + +BitmapEx GenerateStylePreview(SfxObjectShell& rSource, OUString const & aName) +{ + sfx2::StyleManager* pStyleManager = rSource.GetStyleManager(); + + ScopedVclPtrInstance<VirtualDevice> pVirtualDev(*Application::GetDefaultDevice()); + + float fScalingFactor = pVirtualDev->GetDPIScaleFactor(); + + sal_Int32 nMargin = 6 * fScalingFactor; + + sal_Int32 nPreviewWidth = 144 * fScalingFactor; + + sal_Int32 nNameHeight = 16 * fScalingFactor; + sal_Int32 nTitleHeight = 32 * fScalingFactor; + sal_Int32 nHeadingHeight = 24 * fScalingFactor; + sal_Int32 nTextBodyHeight = 16 * fScalingFactor; + sal_Int32 nBottomMargin = 2 * fScalingFactor; + + sal_Int32 nNameFontSize = 12 * fScalingFactor; + + sal_Int32 nPreviewHeight = nNameHeight + nTitleHeight + nHeadingHeight + nTextBodyHeight + nBottomMargin; + + Size aSize(nPreviewWidth, nPreviewHeight); + + pVirtualDev->SetOutputSizePixel(aSize); + + pVirtualDev->SetLineColor(COL_LIGHTGRAY); + pVirtualDev->SetFillColor(); + + long y = 0; + { + pVirtualDev->SetFillColor(COL_LIGHTGRAY); + tools::Rectangle aNameRect(0, y, nPreviewWidth, nNameHeight); + pVirtualDev->DrawRect(aNameRect); + + vcl::Font aFont; + aFont.SetFontSize(Size(0, nNameFontSize)); + + pVirtualDev->SetFont(aFont); + + Size aTextSize(pVirtualDev->GetTextWidth(aName), pVirtualDev->GetTextHeight()); + + Point aPoint((aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0), + y + (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0)); + + pVirtualDev->DrawText(aPoint, aName); + + y += nNameHeight; + } + + { + tools::Rectangle aRenderRect(Point(nMargin, y), aSize); + renderPreview(pStyleManager, *pVirtualDev, "Title", nTitleHeight, aRenderRect); + y += nTitleHeight; + } + + { + tools::Rectangle aRenderRect(Point(nMargin, y), aSize); + renderPreview(pStyleManager, *pVirtualDev, "Heading 1", nHeadingHeight, aRenderRect); + y += nHeadingHeight; + } + { + tools::Rectangle aRenderRect(Point(nMargin, y), aSize); + renderPreview(pStyleManager, *pVirtualDev, "Text Body", nTextBodyHeight, aRenderRect); + } + + return pVirtualDev->GetBitmapEx(Point(), aSize); +} + +BitmapEx CreatePreview(OUString const & aUrl, OUString const & aName) +{ + SfxMedium aMedium(aUrl, StreamMode::STD_READWRITE); + SfxObjectShell* pObjectShell = SfxObjectShell::Current(); + SfxObjectShellLock xTemplDoc = SfxObjectShell::CreateObjectByFactoryName(pObjectShell->GetFactory().GetFactoryName(), SfxObjectCreateMode::ORGANIZER); + xTemplDoc->DoInitNew(); + if (xTemplDoc->LoadFrom(aMedium)) + { + return GenerateStylePreview(*xTemplDoc, aName); + } + return BitmapEx(); +} + +} + +VclPtr<vcl::Window> StylePresetsPanel::Create (vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame) +{ + if (pParent == nullptr) + throw css::lang::IllegalArgumentException("no parent Window given to StylePresetsPanel::Create", nullptr, 0); + if (!rxFrame.is()) + throw css::lang::IllegalArgumentException("no XFrame given to StylePresetsPanel::Create", nullptr, 1); + + return VclPtr<StylePresetsPanel>::Create(pParent, rxFrame); +} + +StylePresetsPanel::StylePresetsPanel(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame) + : PanelLayout(pParent, "StylePresetsPanel", "modules/swriter/ui/sidebarstylepresets.ui", rxFrame) + , mxValueSet(new ValueSet(nullptr)) + , mxValueSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxValueSet)) +{ + mxValueSet->SetColCount(2); + + mxValueSet->SetDoubleClickHdl(LINK(this, StylePresetsPanel, DoubleClickHdl)); + + RefreshList(); +} + +void StylePresetsPanel::RefreshList() +{ + SfxDocumentTemplates aTemplates; + sal_uInt16 nCount = aTemplates.GetRegionCount(); + for (sal_uInt16 i = 0; i < nCount; ++i) + { + OUString aRegionName(aTemplates.GetFullRegionName(i)); + if (aRegionName == "Styles") + { + for (sal_uInt16 j = 0; j < aTemplates.GetCount(i); ++j) + { + OUString aName = aTemplates.GetName(i,j); + OUString aURL = aTemplates.GetPath(i,j); + BitmapEx aPreview = CreatePreview(aURL, aName); + sal_uInt16 nId = j + 1; + mxValueSet->InsertItem(nId, Image(aPreview), aName); + maTemplateEntries.push_back(std::make_unique<TemplateEntry>(aURL)); + mxValueSet->SetItemData(nId, maTemplateEntries.back().get()); + } + mxValueSet->SetOptimalSize(); + } + } +} + +StylePresetsPanel::~StylePresetsPanel() +{ + disposeOnce(); +} + +void StylePresetsPanel::dispose() +{ + mxValueSetWin.reset(); + mxValueSet.reset(); + + PanelLayout::dispose(); +} + +IMPL_LINK_NOARG(StylePresetsPanel, DoubleClickHdl, ValueSet*, void) +{ + sal_Int32 nItemId = mxValueSet->GetSelectedItemId(); + TemplateEntry* pEntry = static_cast<TemplateEntry*>(mxValueSet->GetItemData(nItemId)); + + SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()); + if (pDocSh) + { + SwgReaderOption aOption; + aOption.SetTextFormats(true); + aOption.SetNumRules(true); + pDocSh->LoadStylesFromFile(pEntry->maURL, aOption, false); + } +} + +void StylePresetsPanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/, + const SfxItemState /*eState*/, + const SfxPoolItem* /*pState*/) +{ +} + +} // end of namespace ::sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/StylePresetsPanel.hxx b/sw/source/uibase/sidebar/StylePresetsPanel.hxx new file mode 100644 index 000000000..c217710be --- /dev/null +++ b/sw/source/uibase/sidebar/StylePresetsPanel.hxx @@ -0,0 +1,71 @@ +/* -*- 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/. + * + */ + +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_STYLEPRESETSPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_STYLEPRESETSPANEL_HXX + +#include <memory> +#include <com/sun/star/frame/XFrame.hpp> + +#include <sfx2/sidebar/PanelLayout.hxx> + +#include <sfx2/sidebar/ControllerItem.hxx> + +#include <svtools/valueset.hxx> + +namespace sw::sidebar { + +class StylePresetsPanel : public PanelLayout, + public sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ + friend class VclPtr<StylePresetsPanel>; +public: + static VclPtr<vcl::Window> Create(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame); + + virtual void NotifyItemUpdate(const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + +private: + struct TemplateEntry + { + explicit TemplateEntry(const OUString& rURL) + : maURL(rURL) + {} + + OUString maURL; + }; + + void RefreshList(); + + StylePresetsPanel(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame); + + virtual ~StylePresetsPanel() override; + virtual void dispose() override; + + std::unique_ptr<ValueSet> mxValueSet; + std::unique_ptr<weld::CustomWeld> mxValueSetWin; + + std::vector<std::unique_ptr<TemplateEntry>> maTemplateEntries; + + DECL_LINK(DoubleClickHdl, ValueSet*, void); +}; + +} // end of namespace sw::sidebar + +#endif // INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_STYLEPRESETSPANEL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/SwPanelFactory.cxx b/sw/source/uibase/sidebar/SwPanelFactory.cxx new file mode 100644 index 000000000..37b6694e4 --- /dev/null +++ b/sw/source/uibase/sidebar/SwPanelFactory.cxx @@ -0,0 +1,204 @@ +/* -*- 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 <com/sun/star/ui/XUIElementFactory.hpp> + +#include "ThemePanel.hxx" +#include "StylePresetsPanel.hxx" +#include "PageStylesPanel.hxx" +#include "PageFormatPanel.hxx" +#include "PageHeaderPanel.hxx" +#include "PageFooterPanel.hxx" +#include "WrapPropertyPanel.hxx" +#include "TableEditPanel.hxx" +#include <navipi.hxx> +#include <redlndlg.hxx> + +#include <sfx2/sidebar/SidebarPanelBase.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <vcl/window.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <comphelper/namedvaluecollection.hxx> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/supportsservice.hxx> + + +using namespace css; +using namespace css::uno; + +namespace { + +typedef ::cppu::WeakComponentImplHelper < + css::ui::XUIElementFactory, css::lang::XServiceInfo + > PanelFactoryInterfaceBase; + +class SwPanelFactory + : private ::cppu::BaseMutex + , public PanelFactoryInterfaceBase +{ +private: + SwPanelFactory(SwPanelFactory const&) = delete; + SwPanelFactory& operator=(SwPanelFactory const&) = delete; + +public: + SwPanelFactory(); + + // XUIElementFactory + css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement( + const OUString& rsResourceURL, + const css::uno::Sequence<css::beans::PropertyValue>& rArguments) override; + + OUString SAL_CALL getImplementationName() override + { return "org.apache.openoffice.comp.sw.sidebar.SwPanelFactory"; } + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override + { return cppu::supportsService(this, ServiceName); } + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override + { return css::uno::Sequence<OUString>{"com.sun.star.ui.UIElementFactory"}; } +}; + +SwPanelFactory::SwPanelFactory() + : PanelFactoryInterfaceBase(m_aMutex) +{ +} + +Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement ( + const OUString& rsResourceURL, + const css::uno::Sequence<css::beans::PropertyValue>& rArguments) +{ + Reference<ui::XUIElement> xElement; + + const ::comphelper::NamedValueCollection aArguments (rArguments); + Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); + Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); + const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); + SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); + + VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); + if ( ! xParentWindow.is() || pParentWindow==nullptr) + throw RuntimeException( + "PanelFactory::createUIElement called without ParentWindow", + nullptr); + if ( ! xFrame.is()) + throw RuntimeException( + "PanelFactory::createUIElement called without Frame", + nullptr); + if (pBindings == nullptr) + throw RuntimeException( + "PanelFactory::createUIElement called without SfxBindings", + nullptr); + + if(rsResourceURL.endsWith("/PageStylesPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::PageStylesPanel::Create( pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(-1,-1,-1)); + } + else if(rsResourceURL.endsWith("/PageFormatPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::PageFormatPanel::Create( pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(-1,-1,-1)); + } + else if(rsResourceURL.endsWith("/PageHeaderPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::PageHeaderPanel::Create( pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(-1,-1,-1)); + } + else if(rsResourceURL.endsWith("/PageFooterPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::PageFooterPanel::Create( pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(-1,-1,-1)); + } + else if (rsResourceURL.endsWith("/WrapPropertyPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::WrapPropertyPanel::Create( pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(-1,-1,-1)); + } + else if (rsResourceURL.endsWith("/NavigatorPanel")) + { + VclPtr<vcl::Window> pPanel = SwNavigationPI::Create( pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(0,-1,-1)); + } + else if (rsResourceURL.endsWith("/ManageChangesPanel")) + { + VclPtrInstance<SwRedlineAcceptPanel> pPanel(pParentWindow, xFrame); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, + xFrame, + pPanel, + ui::LayoutSize(-1,-1,-1)); + } + else if (rsResourceURL.endsWith("/StylePresetsPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::StylePresetsPanel::Create(pParentWindow, xFrame); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, xFrame, pPanel, ui::LayoutSize(-1,-1,-1)); + } + else if (rsResourceURL.endsWith("/ThemePanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::ThemePanel::Create(pParentWindow, xFrame); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, xFrame, pPanel, ui::LayoutSize(-1,-1,-1)); + } + else if (rsResourceURL.endsWith("/TableEditPanel")) + { + VclPtr<vcl::Window> pPanel = sw::sidebar::TableEditPanel::Create(pParentWindow, xFrame, pBindings ); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, xFrame, pPanel, ui::LayoutSize(-1,-1,-1)); + } + + return xElement; +} + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +org_apache_openoffice_comp_sw_sidebar_SwPanelFactory_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence<css::uno::Any> const &) +{ + return cppu::acquire(new SwPanelFactory()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/TableEditPanel.cxx b/sw/source/uibase/sidebar/TableEditPanel.cxx new file mode 100644 index 000000000..46f75cd9a --- /dev/null +++ b/sw/source/uibase/sidebar/TableEditPanel.cxx @@ -0,0 +1,238 @@ +/* -*- 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/. + * + */ + +#include "TableEditPanel.hxx" +#include <sal/config.h> +#include <swtypes.hxx> +#include <cmdid.h> +#include <svl/intitem.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <svtools/unitconv.hxx> +#include <svx/dlgctrl.hxx> +#include <swmodule.hxx> +#include <usrpref.hxx> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +namespace sw::sidebar +{ +VclPtr<vcl::Window> TableEditPanel::Create(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings) +{ + if (pParent == nullptr) + throw css::lang::IllegalArgumentException( + "no parent Window given to TableEditPanel::Create", nullptr, 0); + if (!rxFrame.is()) + throw css::lang::IllegalArgumentException("no XFrame given to TableEditPanel::Create", + nullptr, 1); + + return VclPtr<TableEditPanel>::Create(pParent, rxFrame, pBindings); +} + +void TableEditPanel::NotifyItemUpdate(const sal_uInt16 nSID, const SfxItemState eState, + const SfxPoolItem* pState) +{ + switch (nSID) + { + case SID_ATTR_TABLE_ROW_HEIGHT: + { + bool bDisabled = eState == SfxItemState::DISABLED; + m_xRowHeightEdit->set_sensitive(!bDisabled); + + if (pState && eState >= SfxItemState::DEFAULT) + { + const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState); + if (pItem) + { + long nNewHeight = pItem->GetValue(); + nNewHeight = m_xRowHeightEdit->normalize(nNewHeight); + m_xRowHeightEdit->set_value(nNewHeight, FieldUnit::TWIP); + } + } + else if (eState != SfxItemState::DISABLED) + m_xRowHeightEdit->set_text(""); + + break; + } + case SID_ATTR_TABLE_COLUMN_WIDTH: + { + bool bDisabled = eState == SfxItemState::DISABLED; + m_xColumnWidthEdit->set_sensitive(!bDisabled); + + if (pState && eState >= SfxItemState::DEFAULT) + { + const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState); + if (pItem) + { + long nNewWidth = pItem->GetValue(); + nNewWidth = m_xColumnWidthEdit->normalize(nNewWidth); + m_xColumnWidthEdit->set_value(nNewWidth, FieldUnit::TWIP); + } + } + else if (eState != SfxItemState::DISABLED) + m_xColumnWidthEdit->set_text(""); + + break; + } + } +} + +TableEditPanel::TableEditPanel(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings) + : PanelLayout(pParent, "TableEditPanel", "modules/swriter/ui/sidebartableedit.ui", rxFrame) + , m_pBindings(pBindings) + , m_xRowHeightEdit( + new SvxRelativeField(m_xBuilder->weld_metric_spin_button("rowheight", FieldUnit::CM))) + , m_xColumnWidthEdit( + new SvxRelativeField(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM))) + , m_xInsert(m_xBuilder->weld_toolbar("insert")) + , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame)) + , m_xSelect(m_xBuilder->weld_toolbar("select")) + , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame)) + , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing")) + , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame)) + , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing")) + , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame)) + , m_xDelete(m_xBuilder->weld_toolbar("delete")) + , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame)) + , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge")) + , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame)) + , m_xMisc(m_xBuilder->weld_toolbar("misc")) + , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame)) + , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this) + , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this) + , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this) + , m_aInsertRowsAfterController(FN_TABLE_INSERT_ROW_AFTER, *pBindings, *this) + , m_aInsertColumnsBeforeController(FN_TABLE_INSERT_COL_BEFORE, *pBindings, *this) + , m_aInsertColumnsAfterController(FN_TABLE_INSERT_COL_AFTER, *pBindings, *this) + , m_aDeleteRowsController(FN_TABLE_DELETE_ROW, *pBindings, *this) + , m_aDeleteColumnsController(FN_TABLE_DELETE_COL, *pBindings, *this) + , m_aDeleteTableController(FN_TABLE_DELETE_TABLE, *pBindings, *this) + , m_aSetMinimalRowHeightController(SID_TABLE_MINIMAL_ROW_HEIGHT, *pBindings, *this) + , m_aSetOptimalRowHeightController(FN_TABLE_OPTIMAL_HEIGHT, *pBindings, *this) + , m_aDistributeRowsController(FN_TABLE_BALANCE_ROWS, *pBindings, *this) + , m_aSetMinimalColumnWidthController(SID_TABLE_MINIMAL_COLUMN_WIDTH, *pBindings, *this) + , m_aSetOptimalColumnWidthController(FN_TABLE_ADJUST_CELLS, *pBindings, *this) + , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this) + , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this) +{ + // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent + // grid has homogeneous width set so both columns will have the same + // width). This will align this TableEditPanel's columns with + // ParaPropertyPanel's columns + padWidthForSidebar(*m_xSplitMerge, rxFrame); + + InitRowHeightToolitem(); + InitColumnWidthToolitem(); +} + +TableEditPanel::~TableEditPanel() { disposeOnce(); } + +void TableEditPanel::InitRowHeightToolitem() +{ + Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl); + m_xRowHeightEdit->connect_value_changed(aLink); + + FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric(); + m_xRowHeightEdit->SetFieldUnit(eFieldUnit); + + m_xRowHeightEdit->set_min(MINLAY, FieldUnit::TWIP); + m_xRowHeightEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP); + + limitWidthForSidebar(*m_xRowHeightEdit); +} + +void TableEditPanel::InitColumnWidthToolitem() +{ + Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl); + m_xColumnWidthEdit->connect_value_changed(aLink); + + FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric(); + m_xColumnWidthEdit->SetFieldUnit(eFieldUnit); + + m_xColumnWidthEdit->set_min(MINLAY, FieldUnit::TWIP); + m_xColumnWidthEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP); + + limitWidthForSidebar(*m_xColumnWidthEdit); +} + +void TableEditPanel::dispose() +{ + m_xRowHeightEdit.reset(); + m_xColumnWidthEdit.reset(); + + m_xMiscDispatch.reset(); + m_xMisc.reset(); + + m_xSplitMergeDispatch.reset(); + m_xSplitMerge.reset(); + + m_xDeleteDispatch.reset(); + m_xDelete.reset(); + + m_xColumnSizingDispatch.reset(); + m_xColumnSizing.reset(); + + m_xRowSizingDispatch.reset(); + m_xRowSizing.reset(); + + m_xSelectDispatch.reset(); + m_xSelect.reset(); + + m_xInsertDispatch.reset(); + m_xInsert.reset(); + + m_aRowHeightController.dispose(); + m_aColumnWidthController.dispose(); + m_aInsertRowsBeforeController.dispose(); + m_aInsertRowsAfterController.dispose(); + m_aInsertColumnsBeforeController.dispose(); + m_aInsertColumnsAfterController.dispose(); + m_aDeleteRowsController.dispose(); + m_aDeleteColumnsController.dispose(); + m_aDeleteTableController.dispose(); + m_aSetMinimalRowHeightController.dispose(); + m_aSetOptimalRowHeightController.dispose(); + m_aDistributeRowsController.dispose(); + m_aSetMinimalColumnWidthController.dispose(); + m_aSetOptimalColumnWidthController.dispose(); + m_aDistributeColumnsController.dispose(); + m_aMergeCellsController.dispose(); + + PanelLayout::dispose(); +} + +IMPL_LINK_NOARG(TableEditPanel, RowHeightMofiyHdl, weld::MetricSpinButton&, void) +{ + SwTwips nNewHeight = static_cast<SwTwips>( + m_xRowHeightEdit->denormalize(m_xRowHeightEdit->get_value(FieldUnit::TWIP))); + SfxUInt32Item aRowHeight(SID_ATTR_TABLE_ROW_HEIGHT); + aRowHeight.SetValue(nNewHeight); + + m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD, + { &aRowHeight }); +} + +IMPL_LINK_NOARG(TableEditPanel, ColumnWidthMofiyHdl, weld::MetricSpinButton&, void) +{ + SwTwips nNewWidth = static_cast<SwTwips>( + m_xColumnWidthEdit->denormalize(m_xColumnWidthEdit->get_value(FieldUnit::TWIP))); + SfxUInt32Item aColumnWidth(SID_ATTR_TABLE_COLUMN_WIDTH); + aColumnWidth.SetValue(nNewWidth); + + m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD, + { &aColumnWidth }); +} +} // end of namespace ::sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/TableEditPanel.hxx b/sw/source/uibase/sidebar/TableEditPanel.hxx new file mode 100644 index 000000000..361e86009 --- /dev/null +++ b/sw/source/uibase/sidebar/TableEditPanel.hxx @@ -0,0 +1,93 @@ +/* -*- 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/. + * + */ + +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_TABLEEDITPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_TABLEEDITPANEL_HXX + +#include <com/sun/star/frame/XFrame.hpp> +#include <sfx2/sidebar/PanelLayout.hxx> +#include <sfx2/sidebar/ControllerItem.hxx> +#include <sfx2/weldutils.hxx> +#include <svx/relfld.hxx> + +namespace sw +{ +namespace sidebar +{ +class TableEditPanel : public PanelLayout, + public sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ + friend class VclPtr<TableEditPanel>; + +public: + static VclPtr<vcl::Window> Create(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings); + + virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState(const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override{}; + +private: + TableEditPanel(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings); + virtual ~TableEditPanel() override; + virtual void dispose() override; + + void InitRowHeightToolitem(); + void InitColumnWidthToolitem(); + + SfxBindings* m_pBindings; + + std::unique_ptr<SvxRelativeField> m_xRowHeightEdit; + std::unique_ptr<SvxRelativeField> m_xColumnWidthEdit; + std::unique_ptr<weld::Toolbar> m_xInsert; + std::unique_ptr<ToolbarUnoDispatcher> m_xInsertDispatch; + std::unique_ptr<weld::Toolbar> m_xSelect; + std::unique_ptr<ToolbarUnoDispatcher> m_xSelectDispatch; + std::unique_ptr<weld::Toolbar> m_xRowSizing; + std::unique_ptr<ToolbarUnoDispatcher> m_xRowSizingDispatch; + std::unique_ptr<weld::Toolbar> m_xColumnSizing; + std::unique_ptr<ToolbarUnoDispatcher> m_xColumnSizingDispatch; + std::unique_ptr<weld::Toolbar> m_xDelete; + std::unique_ptr<ToolbarUnoDispatcher> m_xDeleteDispatch; + std::unique_ptr<weld::Toolbar> m_xSplitMerge; + std::unique_ptr<ToolbarUnoDispatcher> m_xSplitMergeDispatch; + std::unique_ptr<weld::Toolbar> m_xMisc; + std::unique_ptr<ToolbarUnoDispatcher> m_xMiscDispatch; + + ::sfx2::sidebar::ControllerItem m_aRowHeightController; + ::sfx2::sidebar::ControllerItem m_aColumnWidthController; + ::sfx2::sidebar::ControllerItem m_aInsertRowsBeforeController; + ::sfx2::sidebar::ControllerItem m_aInsertRowsAfterController; + ::sfx2::sidebar::ControllerItem m_aInsertColumnsBeforeController; + ::sfx2::sidebar::ControllerItem m_aInsertColumnsAfterController; + ::sfx2::sidebar::ControllerItem m_aDeleteRowsController; + ::sfx2::sidebar::ControllerItem m_aDeleteColumnsController; + ::sfx2::sidebar::ControllerItem m_aDeleteTableController; + ::sfx2::sidebar::ControllerItem m_aSetMinimalRowHeightController; + ::sfx2::sidebar::ControllerItem m_aSetOptimalRowHeightController; + ::sfx2::sidebar::ControllerItem m_aDistributeRowsController; + ::sfx2::sidebar::ControllerItem m_aSetMinimalColumnWidthController; + ::sfx2::sidebar::ControllerItem m_aSetOptimalColumnWidthController; + ::sfx2::sidebar::ControllerItem m_aDistributeColumnsController; + ::sfx2::sidebar::ControllerItem m_aMergeCellsController; + + DECL_LINK(RowHeightMofiyHdl, weld::MetricSpinButton&, void); + DECL_LINK(ColumnWidthMofiyHdl, weld::MetricSpinButton&, void); +}; +} +} // end of namespace sw::sidebar + +#endif // INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_TABLEEDITPANEL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx new file mode 100644 index 000000000..290ca4106 --- /dev/null +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -0,0 +1,509 @@ +/* -*- 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/. + * + */ + +#include <sal/config.h> + +#include "ThemePanel.hxx" + +#include <sfx2/objsh.hxx> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +#include <editeng/fontitem.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/image.hxx> +#include <vcl/svapp.hxx> +#include <vcl/virdev.hxx> +#include <charatr.hxx> +#include <charfmt.hxx> +#include <docsh.hxx> +#include <docstyle.hxx> +#include <fmtcol.hxx> +#include <format.hxx> + +namespace +{ + +class FontSet +{ +public: + OUString maName; + OUString msMonoFont; + OUString msHeadingFont; + OUString msBaseFont; +}; + +class ColorVariable +{ +public: + long mnIndex; + sal_Int16 mnTintShade; + + ColorVariable() + : mnIndex(-1) + , mnTintShade() + {} + + ColorVariable(long nIndex, sal_Int16 nTintShade) + : mnIndex(nIndex) + , mnTintShade(nTintShade) + {} +}; + +class StyleRedefinition +{ + ColorVariable maVariable; + +public: + OUString maElementName; + +public: + explicit StyleRedefinition(const OUString& aElementName) + : maElementName(aElementName) + {} + + void setColorVariable(ColorVariable aVariable) + { + maVariable = aVariable; + } + + Color getColor(svx::ColorSet const & rColorSet) + { + Color aColor; + if (maVariable.mnIndex > -1) + { + aColor = rColorSet.getColor(maVariable.mnIndex); + aColor.ApplyTintOrShade(maVariable.mnTintShade); + } + else + { + aColor = COL_BLACK; + } + return aColor; + } +}; + +class StyleSet +{ + std::vector<StyleRedefinition> maStyles; + +public: + explicit StyleSet() + : maStyles() + {} + + void add(StyleRedefinition const & aRedefinition) + { + maStyles.push_back(aRedefinition); + } + + StyleRedefinition* get(const OUString& aString) + { + for (StyleRedefinition & rStyle : maStyles) + { + if (rStyle.maElementName == aString) + { + return &rStyle; + } + } + return nullptr; + } +}; + +StyleSet setupThemes() +{ + StyleSet aSet; + + { + StyleRedefinition aRedefinition("Heading 1"); + aRedefinition.setColorVariable(ColorVariable(10, -1000)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 2"); + aRedefinition.setColorVariable(ColorVariable(7, -500)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 3"); + aRedefinition.setColorVariable(ColorVariable(5, 0)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 4"); + aRedefinition.setColorVariable(ColorVariable(6, -1000)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 5"); + aRedefinition.setColorVariable(ColorVariable(4, -1500)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 6"); + aRedefinition.setColorVariable(ColorVariable(3, -2500)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 7"); + aRedefinition.setColorVariable(ColorVariable(3, -2500)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 8"); + aRedefinition.setColorVariable(ColorVariable(2, 0)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 9"); + aRedefinition.setColorVariable(ColorVariable(2, 0)); + aSet.add(aRedefinition); + } + + { + StyleRedefinition aRedefinition("Heading 10"); + aRedefinition.setColorVariable(ColorVariable(0, 0)); + aSet.add(aRedefinition); + } + + return aSet; +} + +void changeFont(SwFormat* pFormat, SwDocStyleSheet const * pStyle, FontSet const & rFontSet) +{ + if (pStyle->GetName() != "Default Style" && pFormat->GetAttrSet().GetItem(RES_CHRATR_FONT, false) == nullptr) + { + return; + } + + SvxFontItem aFontItem(pFormat->GetFont(false)); + + FontPitch ePitch = aFontItem.GetPitch(); + + if (ePitch == PITCH_FIXED) + { + aFontItem.SetFamilyName(rFontSet.msMonoFont); + } + else + { + if (pStyle->GetName() == "Heading") + { + aFontItem.SetFamilyName(rFontSet.msHeadingFont); + } + else + { + aFontItem.SetFamilyName(rFontSet.msBaseFont); + } + } + + pFormat->SetFormatAttr(aFontItem); +} + +/*void changeBorder(SwTextFormatColl* pCollection, SwDocStyleSheet* pStyle, StyleSet& rStyleSet) +{ + if (pStyle->GetName() == "Heading") + { + SvxBoxItem aBoxItem(pCollection->GetBox()); + editeng::SvxBorderLine aBorderLine; + aBorderLine.SetWidth(40); //20 = 1pt + aBorderLine.SetColor(rColorSet.mBaseColors[0]); + aBoxItem.SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM); + + pCollection->SetFormatAttr(aBoxItem); + } +}*/ + +void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const & rColorSet, StyleRedefinition* pRedefinition) +{ + Color aColor = pRedefinition->getColor(rColorSet); + + SvxColorItem aColorItem(pCollection->GetColor()); + aColorItem.SetValue(aColor); + pCollection->SetFormatAttr(aColorItem); +} + +std::vector<FontSet> initFontSets() +{ + std::vector<FontSet> aFontSets; + { + FontSet aFontSet; + aFontSet.maName = "Liberation Family"; + aFontSet.msHeadingFont = "Liberation Sans"; + aFontSet.msBaseFont = "Liberation Serif"; + aFontSet.msMonoFont = "Liberation Mono"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "DejaVu Family"; + aFontSet.msHeadingFont = "DejaVu Sans"; + aFontSet.msBaseFont = "DejaVu Serif"; + aFontSet.msMonoFont = "DejaVu Sans Mono"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Croscore Modern"; + aFontSet.msHeadingFont = "Caladea"; + aFontSet.msBaseFont = "Carlito"; + aFontSet.msMonoFont = "Liberation Mono"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Carlito"; + aFontSet.msHeadingFont = "Carlito"; + aFontSet.msBaseFont = "Carlito"; + aFontSet.msMonoFont = "Liberation Mono"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Source Sans Family"; + aFontSet.msHeadingFont = "Source Sans Pro"; + aFontSet.msBaseFont = "Source Sans Pro"; + aFontSet.msMonoFont = "Source Code Pro"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Source Sans Family 2"; + aFontSet.msHeadingFont = "Source Sans Pro"; + aFontSet.msBaseFont = "Source Sans Pro Light"; + aFontSet.msMonoFont = "Source Code Pro"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Libertine Family"; + aFontSet.msHeadingFont = "Linux Biolinum G"; + aFontSet.msBaseFont = "Linux Libertine G"; + aFontSet.msMonoFont = "Liberation Mono"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Open Sans"; + aFontSet.msHeadingFont = "Open Sans"; + aFontSet.msBaseFont = "Open Sans"; + aFontSet.msMonoFont = "Droid Sans Mono"; + aFontSets.push_back(aFontSet); + } + { + FontSet aFontSet; + aFontSet.maName = "Droid Sans"; + aFontSet.msHeadingFont = "Droid Sans"; + aFontSet.msBaseFont = "Droid Sans"; + aFontSet.msMonoFont = "Droid Sans Mono"; + aFontSets.push_back(aFontSet); + } + return aFontSets; +} + +FontSet getFontSet(const OUString& rFontVariant, std::vector<FontSet>& aFontSets) +{ + for (const FontSet & rFontSet : aFontSets) + { + if (rFontSet.maName == rFontVariant) + return rFontSet; + } + return aFontSets[0]; +} + +void applyTheme(SfxStyleSheetBasePool* pPool, const OUString& sFontSetName, const OUString& sColorSetName, + StyleSet& rStyleSet, svx::ColorSets& rColorSets) +{ + SwDocStyleSheet* pStyle; + + std::vector<FontSet> aFontSets = initFontSets(); + FontSet aFontSet = getFontSet(sFontSetName, aFontSets); + + svx::ColorSet aColorSet = rColorSets.getColorSet(sColorSetName); + + pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Para)); + while (pStyle) + { + SwTextFormatColl* pCollection = pStyle->GetCollection(); + + changeFont(pCollection, pStyle, aFontSet); + + StyleRedefinition* pRedefinition = rStyleSet.get(pStyle->GetName()); + + if (pRedefinition) + { + changeColor(pCollection, aColorSet, pRedefinition); + } + + pStyle = static_cast<SwDocStyleSheet*>(pPool->Next()); + } + + pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Char)); + while (pStyle) + { + SwCharFormat* pCharFormat = pStyle->GetCharFormat(); + + changeFont(static_cast<SwFormat*>(pCharFormat), pStyle, aFontSet); + + pStyle = static_cast<SwDocStyleSheet*>(pPool->Next()); + } +} + +BitmapEx GenerateColorPreview(const svx::ColorSet& rColorSet) +{ + ScopedVclPtrInstance<VirtualDevice> pVirtualDev(*Application::GetDefaultDevice()); + float fScaleFactor = pVirtualDev->GetDPIScaleFactor(); + long BORDER = 2 * fScaleFactor; + long SIZE = 12 * fScaleFactor; + + Size aSize(BORDER * 7 + SIZE * 6, BORDER * 3 + SIZE * 2); + pVirtualDev->SetOutputSizePixel(aSize); + + long x = BORDER; + long y1 = BORDER; + long y2 = y1 + SIZE + BORDER; + + pVirtualDev->SetLineColor(COL_LIGHTGRAY); + + for (sal_uInt32 i = 0; i < 12; i += 2) + { + pVirtualDev->SetFillColor(rColorSet.getColor(i)); + pVirtualDev->DrawRect(tools::Rectangle(x, y1, x + SIZE, y1 + SIZE)); + + pVirtualDev->SetFillColor(rColorSet.getColor(i + 1)); + pVirtualDev->DrawRect(tools::Rectangle(x, y2, x + SIZE, y2 + SIZE)); + + x += SIZE + BORDER; + } + + return pVirtualDev->GetBitmapEx(Point(), aSize); +} + +} // end anonymous namespace + +namespace sw::sidebar { + +VclPtr<vcl::Window> ThemePanel::Create (vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame) +{ + if (pParent == nullptr) + throw css::lang::IllegalArgumentException("no parent Window given to PagePropertyPanel::Create", nullptr, 0); + if (!rxFrame.is()) + throw css::lang::IllegalArgumentException("no XFrame given to PagePropertyPanel::Create", nullptr, 1); + + return VclPtr<ThemePanel>::Create(pParent, rxFrame); +} + +ThemePanel::ThemePanel(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame) + : PanelLayout(pParent, "ThemePanel", "modules/swriter/ui/sidebartheme.ui", rxFrame) + , mxListBoxFonts(m_xBuilder->weld_tree_view("listbox_fonts")) + , mxValueSetColors(new ValueSet(nullptr)) + , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, "valueset_colors", *mxValueSetColors)) + , mxApplyButton(m_xBuilder->weld_button("apply")) + , maColorSets() +{ + mxValueSetColors->SetColCount(2); + mxValueSetColors->SetLineCount(3); + + mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl)); + mxListBoxFonts->connect_row_activated(LINK(this, ThemePanel, DoubleClickHdl)); + mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickValueSetHdl)); + + std::vector<FontSet> aFontSets = initFontSets(); + for (const FontSet & rFontSet : aFontSets) + mxListBoxFonts->append_text(rFontSet.maName); + mxListBoxFonts->set_size_request(-1, mxListBoxFonts->get_height_rows(aFontSets.size())); + + maColorSets.init(); + + const std::vector<svx::ColorSet>& aColorSets = maColorSets.getColorSets(); + for (size_t i = 0; i < aColorSets.size(); ++i) + { + const svx::ColorSet& rColorSet = aColorSets[i]; + + const OUString& aName = rColorSet.getName(); + BitmapEx aPreview = GenerateColorPreview(rColorSet); + + sal_uInt16 nId = i + 1; + mxValueSetColors->InsertItem(nId, Image(aPreview), aName); + } + + mxValueSetColors->SetOptimalSize(); + + if (!aColorSets.empty()) + mxValueSetColors->SelectItem(1); // ItemId 1, position 0 +} + +ThemePanel::~ThemePanel() +{ + disposeOnce(); +} + +void ThemePanel::dispose() +{ + mxListBoxFonts.reset(); + mxValueSetColorsWin.reset(); + mxValueSetColors.reset(); + mxApplyButton.reset(); + + PanelLayout::dispose(); +} + +IMPL_LINK_NOARG(ThemePanel, ClickHdl, weld::Button&, void) +{ + DoubleClickHdl(); +} + +IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, ValueSet*, void) +{ + DoubleClickHdl(); +} + +IMPL_LINK_NOARG(ThemePanel, DoubleClickHdl, weld::TreeView&, bool) +{ + DoubleClickHdl(); + return true; +} + +void ThemePanel::DoubleClickHdl() +{ + SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()); + if (!pDocSh) + return; + + sal_uInt32 nItemId = mxValueSetColors->GetSelectedItemId(); + if (!nItemId) + return; + OUString sEntryFonts = mxListBoxFonts->get_selected_text(); + sal_uInt32 nIndex = nItemId - 1; + OUString sEntryColors = maColorSets.getColorSet(nIndex).getName(); + + StyleSet aStyleSet = setupThemes(); + + applyTheme(pDocSh->GetStyleSheetPool(), sEntryFonts, sEntryColors, aStyleSet, maColorSets); +} + +void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/, + const SfxItemState /*eState*/, + const SfxPoolItem* /*pState*/) +{ +} + +} // end of namespace ::sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx b/sw/source/uibase/sidebar/ThemePanel.hxx new file mode 100644 index 000000000..a050f2d4c --- /dev/null +++ b/sw/source/uibase/sidebar/ThemePanel.hxx @@ -0,0 +1,63 @@ +/* -*- 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/. + * + */ + +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_THEMEPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_THEMEPANEL_HXX + +#include <com/sun/star/frame/XFrame.hpp> +#include <sfx2/sidebar/PanelLayout.hxx> +#include <sfx2/sidebar/ControllerItem.hxx> +#include <svtools/valueset.hxx> +#include <svx/ColorSets.hxx> + +namespace sw::sidebar { + +class ThemePanel : public PanelLayout, + public sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ + friend class VclPtr<ThemePanel>; +public: + static VclPtr<vcl::Window> Create(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame); + + virtual void NotifyItemUpdate(const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + +private: + ThemePanel(vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame); + virtual ~ThemePanel() override; + + virtual void dispose() override; + + std::unique_ptr<weld::TreeView> mxListBoxFonts; + std::unique_ptr<ValueSet> mxValueSetColors; + std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin; + std::unique_ptr<weld::Button> mxApplyButton; + + svx::ColorSets maColorSets; + + DECL_LINK(ClickHdl, weld::Button&, void); + DECL_LINK(DoubleClickHdl, weld::TreeView&, bool); + DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void); + void DoubleClickHdl(); + +}; + +} // end of namespace sw::sidebar + +#endif // INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_THEMEPANEL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/WrapPropertyPanel.cxx b/sw/source/uibase/sidebar/WrapPropertyPanel.cxx new file mode 100644 index 000000000..bc64fd8b7 --- /dev/null +++ b/sw/source/uibase/sidebar/WrapPropertyPanel.cxx @@ -0,0 +1,189 @@ +/* -*- 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 "WrapPropertyPanel.hxx" + +#include <cmdid.h> +#include <svx/spacinglistbox.hxx> +#include <svx/svdtrans.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <svl/eitem.hxx> +#include <vcl/commandinfoprovider.hxx> +#include <vcl/settings.hxx> +#include <editeng/lrspitem.hxx> +#include <editeng/ulspitem.hxx> +#include <hintids.hxx> +#include <strings.hrc> +#include <uitool.hxx> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <comphelper/lok.hxx> + +namespace sw::sidebar { + +VclPtr<vcl::Window> WrapPropertyPanel::Create ( + vcl::Window* pParent, + const css::uno::Reference< css::frame::XFrame >& rxFrame, + SfxBindings* pBindings) +{ + if (pParent == nullptr) + throw css::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", nullptr, 0); + if ( ! rxFrame.is()) + throw css::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", nullptr, 1); + if (pBindings == nullptr) + throw css::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", nullptr, 2); + + return VclPtr<WrapPropertyPanel>::Create( + pParent, + rxFrame, + pBindings); +} + +WrapPropertyPanel::WrapPropertyPanel( + vcl::Window* pParent, + const css::uno::Reference< css::frame::XFrame >& rxFrame, + SfxBindings* pBindings ) + : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui", rxFrame) + , mpBindings(pBindings) + // spacing + , nTop(0) + , nBottom(0) + , nLeft(0) + , nRight(0) + // resources + , aCustomEntry(SwResId(STR_WRAP_PANEL_CUSTOM_STR)) + // controller items + , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this) + , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this) + , mxWrapOptions(m_xBuilder->weld_toolbar("wrapoptions")) + , mxWrapOptionsDispatch(new ToolbarUnoDispatcher(*mxWrapOptions, *m_xBuilder, rxFrame)) + , mxSpacingLB(m_xBuilder->weld_combo_box("spacingLB")) +{ + FieldUnit eMetric = ::GetDfltMetric(false); + SpacingListBox::Fill(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxSpacingLB); + + Initialize(); +} + +WrapPropertyPanel::~WrapPropertyPanel() +{ + disposeOnce(); +} + +void WrapPropertyPanel::dispose() +{ + mxSpacingLB.reset(); + + mxWrapOptionsDispatch.reset(); + mxWrapOptions.reset(); + + maSwLRSpacingControl.dispose(); + maSwULSpacingControl.dispose(); + + PanelLayout::dispose(); +} + +void WrapPropertyPanel::Initialize() +{ + mxSpacingLB->connect_changed(LINK(this, WrapPropertyPanel, SpacingLBHdl)); + + mpBindings->Update( SID_ATTR_LRSPACE ); + mpBindings->Update( SID_ATTR_ULSPACE ); +} + +void WrapPropertyPanel::UpdateSpacingLB() +{ + if( (nLeft == nRight) && (nTop == nBottom) && (nLeft == nTop) ) + { + sal_Int32 nCount = mxSpacingLB->get_count(); + for (sal_Int32 i = 0; i < nCount; i++) + { + if (mxSpacingLB->get_id(i).toUInt32() == nLeft) + { + mxSpacingLB->set_active(i); + int nCustomEntry = mxSpacingLB->find_text(aCustomEntry); + if (nCustomEntry != -1) + mxSpacingLB->remove(nCustomEntry); + return; + } + } + } + + if (mxSpacingLB->find_text(aCustomEntry) == -1) + mxSpacingLB->append_text(aCustomEntry); + mxSpacingLB->set_active_text(aCustomEntry); +} + +IMPL_LINK(WrapPropertyPanel, SpacingLBHdl, weld::ComboBox&, rBox, void) +{ + sal_uInt16 nVal = rBox.get_active_id().toUInt32(); + + SvxLRSpaceItem aLRItem(nVal, nVal, 0, 0, RES_LR_SPACE); + SvxULSpaceItem aULItem(nVal, nVal, RES_UL_SPACE); + + nTop = nBottom = nLeft = nRight = nVal; + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_LRSPACE, + SfxCallMode::RECORD, { &aLRItem }); + mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_ULSPACE, + SfxCallMode::RECORD, { &aULItem }); +} + +void WrapPropertyPanel::NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) +{ + switch(nSId) + { + case SID_ATTR_LRSPACE: + { + if(eState >= SfxItemState::DEFAULT) + { + const SvxLRSpaceItem* pItem = dynamic_cast< const SvxLRSpaceItem* >(pState); + if(pItem) + { + nLeft = pItem->GetLeft(); + nRight = pItem->GetRight(); + + UpdateSpacingLB(); + } + } + } + break; + case SID_ATTR_ULSPACE: + { + if(eState >= SfxItemState::DEFAULT) + { + const SvxULSpaceItem* pItem = dynamic_cast< const SvxULSpaceItem* >(pState); + if(pItem) + { + nTop = pItem->GetUpper(); + nBottom = pItem->GetLower(); + + UpdateSpacingLB(); + } + } + } + break; + } +} + +} // end of namespace ::sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/WrapPropertyPanel.hxx b/sw/source/uibase/sidebar/WrapPropertyPanel.hxx new file mode 100644 index 000000000..1f4d16d80 --- /dev/null +++ b/sw/source/uibase/sidebar/WrapPropertyPanel.hxx @@ -0,0 +1,88 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_WRAPPROPERTYPANEL_HXX +#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_WRAPPROPERTYPANEL_HXX + +#include <sfx2/sidebar/PanelLayout.hxx> +#include <sfx2/sidebar/ControllerItem.hxx> +#include <sfx2/weldutils.hxx> +#include <com/sun/star/frame/XFrame.hpp> +#include <vcl/weld.hxx> + +namespace sw::sidebar { + + class WrapPropertyPanel + : public PanelLayout + , public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface + { + public: + static VclPtr<vcl::Window> Create( + vcl::Window* pParent, + const css::uno::Reference< css::frame::XFrame>& rxFrame, + SfxBindings* pBindings ); + + // interface of ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface + virtual void NotifyItemUpdate( + const sal_uInt16 nSId, + const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState( + const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override {}; + + virtual ~WrapPropertyPanel() override; + virtual void dispose() override; + + WrapPropertyPanel( + vcl::Window* pParent, + const css::uno::Reference< css::frame::XFrame >& rxFrame, + SfxBindings* pBindings ); + private: + SfxBindings* mpBindings; + + //Spacing + sal_uInt16 nTop; + sal_uInt16 nBottom; + sal_uInt16 nLeft; + sal_uInt16 nRight; + + //custom entry + OUString aCustomEntry; + + // Controller Items + ::sfx2::sidebar::ControllerItem maSwLRSpacingControl; + ::sfx2::sidebar::ControllerItem maSwULSpacingControl; + + std::unique_ptr<weld::Toolbar> mxWrapOptions; + std::unique_ptr<ToolbarUnoDispatcher> mxWrapOptionsDispatch; + + std::unique_ptr<weld::ComboBox> mxSpacingLB; + + void Initialize(); + void UpdateSpacingLB(); + + DECL_LINK(SpacingLBHdl, weld::ComboBox&, void); + }; + +} // end of namespace ::sw::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |