diff options
Diffstat (limited to 'svx/source/sidebar/line')
-rw-r--r-- | svx/source/sidebar/line/LinePropertyPanel.cxx | 172 | ||||
-rw-r--r-- | svx/source/sidebar/line/LinePropertyPanel.hxx | 100 | ||||
-rw-r--r-- | svx/source/sidebar/line/LinePropertyPanelBase.cxx | 484 | ||||
-rw-r--r-- | svx/source/sidebar/line/LineWidthPopup.cxx | 226 | ||||
-rw-r--r-- | svx/source/sidebar/line/LineWidthValueSet.cxx | 172 | ||||
-rw-r--r-- | svx/source/sidebar/line/LineWidthValueSet.hxx | 55 |
6 files changed, 1209 insertions, 0 deletions
diff --git a/svx/source/sidebar/line/LinePropertyPanel.cxx b/svx/source/sidebar/line/LinePropertyPanel.cxx new file mode 100644 index 000000000..070512cd3 --- /dev/null +++ b/svx/source/sidebar/line/LinePropertyPanel.cxx @@ -0,0 +1,172 @@ +/* -*- 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 "LinePropertyPanel.hxx" +#include <svx/svxids.hrc> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <svx/xlnwtit.hxx> +#include <svx/xlntrit.hxx> +#include <svx/xlncapit.hxx> +#include <svx/xlinjoit.hxx> + +using namespace css; +using namespace css::uno; + +namespace svx::sidebar { + +LinePropertyPanel::LinePropertyPanel( + vcl::Window* pParent, + const uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings) +: LinePropertyPanelBase(pParent, rxFrame), + maStyleControl(SID_ATTR_LINE_STYLE, *pBindings, *this), + maDashControl (SID_ATTR_LINE_DASH, *pBindings, *this), + maWidthControl(SID_ATTR_LINE_WIDTH, *pBindings, *this), + maTransControl(SID_ATTR_LINE_TRANSPARENCE, *pBindings, *this), + maEdgeStyle(SID_ATTR_LINE_JOINT, *pBindings, *this), + maCapStyle(SID_ATTR_LINE_CAP, *pBindings, *this), + mpBindings(pBindings), + maContext() +{ + setMapUnit(maWidthControl.GetCoreMetric()); +} + +LinePropertyPanel::~LinePropertyPanel() +{ + disposeOnce(); +} + +void LinePropertyPanel::dispose() +{ + maStyleControl.dispose(); + maDashControl.dispose(); + maWidthControl.dispose(); + maTransControl.dispose(); + maEdgeStyle.dispose(); + maCapStyle.dispose(); + + LinePropertyPanelBase::dispose(); +} + +VclPtr<vcl::Window> LinePropertyPanel::Create ( + vcl::Window* pParent, + const uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings) +{ + if (pParent == nullptr) + throw lang::IllegalArgumentException("no parent Window given to LinePropertyPanel::Create", nullptr, 0); + if ( ! rxFrame.is()) + throw lang::IllegalArgumentException("no XFrame given to LinePropertyPanel::Create", nullptr, 1); + if (pBindings == nullptr) + throw lang::IllegalArgumentException("no SfxBindings given to LinePropertyPanel::Create", nullptr, 2); + + return VclPtr<LinePropertyPanel>::Create(pParent, rxFrame, pBindings); +} + +void LinePropertyPanel::NotifyItemUpdate( + sal_uInt16 nSID, + SfxItemState eState, + const SfxPoolItem* pState) +{ + const bool bDisabled(SfxItemState::DISABLED == eState); + const bool bSetOrDefault = eState >= SfxItemState::DEFAULT; + + switch(nSID) + { + case SID_ATTR_LINE_TRANSPARENCE: + { + updateLineTransparence(bDisabled, bSetOrDefault, pState); + break; + } + case SID_ATTR_LINE_WIDTH: + { + updateLineWidth(bDisabled, bSetOrDefault, pState); + break; + } + case SID_ATTR_LINE_JOINT: + { + updateLineJoint(bDisabled, bSetOrDefault, pState); + break; + } + case SID_ATTR_LINE_CAP: + { + updateLineCap(bDisabled, bSetOrDefault, pState); + break; + } + } + ActivateControls(); +} + +void LinePropertyPanel::HandleContextChange( + const vcl::EnumContext& rContext) +{ + if(maContext == rContext) + { + // Nothing to do + return; + } + + maContext = rContext; + bool bShowArrows = false; + + switch(maContext.GetCombinedContext_DI()) + { + case CombinedEnumContext(Application::Calc, Context::DrawLine): + case CombinedEnumContext(Application::DrawImpress, Context::DrawLine): + case CombinedEnumContext(Application::DrawImpress, Context::Draw): + case CombinedEnumContext(Application::WriterVariants, Context::Draw): + // TODO : Implement DrawLine context in Writer + bShowArrows = true; + break; + } + + if (!bShowArrows) + disableArrowHead(); + else + enableArrowHead(); +} + +void LinePropertyPanel::setLineJoint(const XLineJointItem* pItem) +{ + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_LINE_JOINT, + SfxCallMode::RECORD, { pItem }); +} + +void LinePropertyPanel::setLineCap(const XLineCapItem* pItem) +{ + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_LINE_CAP, + SfxCallMode::RECORD, { pItem }); +} + +void LinePropertyPanel::setLineTransparency(const XLineTransparenceItem& rItem) +{ + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_LINE_STYLE, + SfxCallMode::RECORD, { &rItem }); +} + +void LinePropertyPanel::setLineWidth(const XLineWidthItem& rItem) +{ + GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_LINE_WIDTH, + SfxCallMode::RECORD, { &rItem }); +} + +} // end of namespace svx::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/line/LinePropertyPanel.hxx b/svx/source/sidebar/line/LinePropertyPanel.hxx new file mode 100644 index 000000000..767564fe6 --- /dev/null +++ b/svx/source/sidebar/line/LinePropertyPanel.hxx @@ -0,0 +1,100 @@ +/* -*- 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_SVX_SOURCE_SIDEBAR_LINE_LINEPROPERTYPANEL_HXX +#define INCLUDED_SVX_SOURCE_SIDEBAR_LINE_LINEPROPERTYPANEL_HXX + +#include <sfx2/sidebar/ControllerItem.hxx> +#include <sfx2/sidebar/IContextChangeReceiver.hxx> +#include <svx/sidebar/LinePropertyPanelBase.hxx> +#include <vcl/EnumContext.hxx> + +class XLineStyleItem; +class XLineDashItem; +class XLineStartItem; +class XLineEndItem; +class XLineEndList; +class XDashList; +class ListBox; +class ToolBox; +class FloatingWindow; + +namespace svx +{ +namespace sidebar +{ + +class LinePropertyPanel : public LinePropertyPanelBase, + public sfx2::sidebar::IContextChangeReceiver, + public sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ +public: + virtual ~LinePropertyPanel() override; + virtual void dispose() override; + + static VclPtr<vcl::Window> Create( + vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings); + + virtual void HandleContextChange( + const vcl::EnumContext& rContext) override; + + 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() { return mpBindings;} + + // constructor/destructor + LinePropertyPanel( + vcl::Window* pParent, + const css::uno::Reference<css::frame::XFrame>& rxFrame, + SfxBindings* pBindings); + + virtual void setLineWidth(const XLineWidthItem& rItem) override; + +protected: + + virtual void setLineTransparency(const XLineTransparenceItem& rItem) override; + virtual void setLineJoint(const XLineJointItem* pItem) override; + virtual void setLineCap(const XLineCapItem* pItem) override; + +private: + //ControllerItem + sfx2::sidebar::ControllerItem maStyleControl; + sfx2::sidebar::ControllerItem maDashControl; + sfx2::sidebar::ControllerItem maWidthControl; + sfx2::sidebar::ControllerItem maTransControl; + sfx2::sidebar::ControllerItem maEdgeStyle; + sfx2::sidebar::ControllerItem maCapStyle; + + SfxBindings* mpBindings; + vcl::EnumContext maContext; +}; + +} } // end of namespace svx::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/line/LinePropertyPanelBase.cxx b/svx/source/sidebar/line/LinePropertyPanelBase.cxx new file mode 100644 index 000000000..f2c1b4553 --- /dev/null +++ b/svx/source/sidebar/line/LinePropertyPanelBase.cxx @@ -0,0 +1,484 @@ +/* -*- 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 <svx/sidebar/LinePropertyPanelBase.hxx> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <sfx2/weldutils.hxx> +#include <svx/linectrl.hxx> +#include <svx/xlnwtit.hxx> +#include <svx/xlntrit.hxx> +#include <svx/xlncapit.hxx> +#include <svx/xlinjoit.hxx> +#include <bitmaps.hlst> + +using namespace css; +using namespace css::uno; + +const char SELECTWIDTH[] = "SelectWidth"; + +namespace svx::sidebar { + +// trigger disabling the arrows if the none line style is selected +class DisableArrowsWrapper +{ +private: + LinePropertyPanelBase& m_rPanel; + +public: + DisableArrowsWrapper(LinePropertyPanelBase& rPanel) + : m_rPanel(rPanel) + { + } + + bool operator()(const OUString& rCommand, const css::uno::Any& rValue) + { + if (rCommand == ".uno:XLineStyle") + { + css::drawing::LineStyle eLineStyle(css::drawing::LineStyle_NONE); + rValue >>= eLineStyle; + m_rPanel.SetNoneLineStyle(eLineStyle == css::drawing::LineStyle_NONE); + } + return false; + } +}; + +namespace +{ + SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(ToolbarUnoDispatcher& rToolBoxColor) + { + css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(".uno:XLineStyle"); + SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get()); + return pToolBoxLineStyleControl; + } +} + + +LinePropertyPanelBase::LinePropertyPanelBase( + vcl::Window* pParent, + const uno::Reference<css::frame::XFrame>& rxFrame) +: PanelLayout(pParent, "LinePropertyPanel", "svx/ui/sidebarline.ui", rxFrame), + mxTBColor(m_xBuilder->weld_toolbar("color")), + mxColorDispatch(new ToolbarUnoDispatcher(*mxTBColor, *m_xBuilder, rxFrame)), + mxLineStyleTB(m_xBuilder->weld_toolbar("linestyle")), + mxLineStyleDispatch(new ToolbarUnoDispatcher(*mxLineStyleTB, *m_xBuilder, rxFrame)), + mxFTWidth(m_xBuilder->weld_label("widthlabel")), + mxTBWidth(m_xBuilder->weld_toolbar("width")), + mxFTTransparency(m_xBuilder->weld_label("translabel")), + mxMFTransparent(m_xBuilder->weld_metric_spin_button("linetransparency", FieldUnit::PERCENT)), + mxFTEdgeStyle(m_xBuilder->weld_label("cornerlabel")), + mxLBEdgeStyle(m_xBuilder->weld_combo_box("edgestyle")), + mxFTCapStyle(m_xBuilder->weld_label("caplabel")), + mxLBCapStyle(m_xBuilder->weld_combo_box("linecapstyle")), + mxGridLineProps(m_xBuilder->weld_widget("lineproperties")), + mxBoxArrowProps(m_xBuilder->weld_widget("arrowproperties")), + mxLineWidthPopup(new LineWidthPopup(mxTBWidth.get(), *this)), + mxDisableArrowsWrapper(new DisableArrowsWrapper(*this)), + mnTrans(0), + meMapUnit(MapUnit::MapMM), + mnWidthCoreValue(0), + maIMGNone(BMP_NONE_ICON), + mbWidthValuable(true), + mbArrowSupported(true), + mbNoneLineStyle(false) +{ + Initialize(); +} + +LinePropertyPanelBase::~LinePropertyPanelBase() +{ + disposeOnce(); +} + +void LinePropertyPanelBase::dispose() +{ + mxLineWidthPopup.reset(); + mxFTWidth.reset(); + mxTBWidth.reset(); + mxColorDispatch.reset(); + mxTBColor.reset(); + mxFTTransparency.reset(); + mxMFTransparent.reset(); + mxLineStyleDispatch.reset(); + mxLineStyleTB.reset(); + mxFTEdgeStyle.reset(); + mxLBEdgeStyle.reset(); + mxFTCapStyle.reset(); + mxLBCapStyle.reset(); + mxGridLineProps.reset(); + mxBoxArrowProps.reset(); + + PanelLayout::dispose(); +} + +void LinePropertyPanelBase::Initialize() +{ + mxTBWidth->set_item_popover(SELECTWIDTH, mxLineWidthPopup->getTopLevel()); + + maIMGWidthIcon[0] = BMP_WIDTH1_ICON; + maIMGWidthIcon[1] = BMP_WIDTH2_ICON; + maIMGWidthIcon[2] = BMP_WIDTH3_ICON; + maIMGWidthIcon[3] = BMP_WIDTH4_ICON; + maIMGWidthIcon[4] = BMP_WIDTH5_ICON; + maIMGWidthIcon[5] = BMP_WIDTH6_ICON; + maIMGWidthIcon[6] = BMP_WIDTH7_ICON; + maIMGWidthIcon[7] = BMP_WIDTH8_ICON; + + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[0]); + mxTBWidth->connect_clicked(LINK(this, LinePropertyPanelBase, ToolboxWidthSelectHdl)); + + mxMFTransparent->connect_value_changed(LINK(this, LinePropertyPanelBase, ChangeTransparentHdl)); + + mxLBEdgeStyle->connect_changed( LINK( this, LinePropertyPanelBase, ChangeEdgeStyleHdl ) ); + + mxLBCapStyle->connect_changed( LINK( this, LinePropertyPanelBase, ChangeCapStyleHdl ) ); + + SvxLineStyleToolBoxControl* pLineStyleControl = getLineStyleToolBoxControl(*mxLineStyleDispatch); + pLineStyleControl->setLineStyleSelectFunction(*mxDisableArrowsWrapper); +} + +void LinePropertyPanelBase::updateLineTransparence(bool bDisabled, bool bSetOrDefault, + const SfxPoolItem* pState) +{ + if(bDisabled) + { + mxFTTransparency->set_sensitive(false); + mxMFTransparent->set_sensitive(false); + } + else + { + mxFTTransparency->set_sensitive(true); + mxMFTransparent->set_sensitive(true); + } + + if(bSetOrDefault) + { + if (const XLineTransparenceItem* pItem = dynamic_cast<const XLineTransparenceItem*>(pState)) + { + mnTrans = pItem->GetValue(); + mxMFTransparent->set_value(mnTrans, FieldUnit::PERCENT); + return; + } + } + + mxMFTransparent->set_value(0, FieldUnit::PERCENT);//add + mxMFTransparent->set_text(OUString()); +} + +void LinePropertyPanelBase::updateLineWidth(bool bDisabled, bool bSetOrDefault, + const SfxPoolItem* pState) +{ + if(bDisabled) + { + mxTBWidth->set_sensitive(false); + mxFTWidth->set_sensitive(false); + } + else + { + mxTBWidth->set_sensitive(true); + mxFTWidth->set_sensitive(true); + } + + if(bSetOrDefault) + { + if (const XLineWidthItem* pItem = dynamic_cast<const XLineWidthItem*>(pState)) + { + mnWidthCoreValue = pItem->GetValue(); + mbWidthValuable = true; + SetWidthIcon(); + return; + } + } + + mbWidthValuable = false; + SetWidthIcon(); +} + +void LinePropertyPanelBase::updateLineJoint(bool bDisabled, bool bSetOrDefault, + const SfxPoolItem* pState) +{ + if(bDisabled) + { + mxLBEdgeStyle->set_sensitive(false); + mxFTEdgeStyle->set_sensitive(false); + } + else + { + mxLBEdgeStyle->set_sensitive(true); + mxFTEdgeStyle->set_sensitive(true); + } + + if(bSetOrDefault) + { + if (const XLineJointItem* pItem = dynamic_cast<const XLineJointItem*>(pState)) + { + sal_Int32 nEntryPos(0); + + switch(pItem->GetValue()) + { + case drawing::LineJoint_ROUND: + { + nEntryPos = 1; + break; + } + case drawing::LineJoint_NONE: + { + nEntryPos = 2; + break; + } + case drawing::LineJoint_MIDDLE: + case drawing::LineJoint_MITER: + { + nEntryPos = 3; + break; + } + case drawing::LineJoint_BEVEL: + { + nEntryPos = 4; + break; + } + + default: + break; + } + + if(nEntryPos) + { + mxLBEdgeStyle->set_active(nEntryPos - 1); + return; + } + } + } + + mxLBEdgeStyle->set_active(-1); +} + +void LinePropertyPanelBase::updateLineCap(bool bDisabled, bool bSetOrDefault, + const SfxPoolItem* pState) +{ + if(bDisabled) + { + mxLBCapStyle->set_sensitive(false); + mxFTCapStyle->set_sensitive(false); + } + else + { + mxLBCapStyle->set_sensitive(true); + mxLBCapStyle->set_sensitive(true); + } + + if(bSetOrDefault) + { + if (const XLineCapItem* pItem = dynamic_cast<const XLineCapItem*>(pState)) + { + sal_Int32 nEntryPos(0); + + switch(pItem->GetValue()) + { + case drawing::LineCap_BUTT: + { + nEntryPos = 1; + break; + } + case drawing::LineCap_ROUND: + { + nEntryPos = 2; + break; + } + case drawing::LineCap_SQUARE: + { + nEntryPos = 3; + break; + } + + default: + break; + } + + if(nEntryPos) + { + mxLBCapStyle->set_active(nEntryPos - 1); + return; + } + } + } + + mxLBCapStyle->set_active(-1); +} + +IMPL_LINK_NOARG(LinePropertyPanelBase, ChangeEdgeStyleHdl, weld::ComboBox&, void) +{ + const sal_Int32 nPos(mxLBEdgeStyle->get_active()); + + if (nPos != -1 && mxLBEdgeStyle->get_value_changed_from_saved()) + { + std::unique_ptr<XLineJointItem> pItem; + + switch(nPos) + { + case 0: // rounded + { + pItem.reset(new XLineJointItem(drawing::LineJoint_ROUND)); + break; + } + case 1: // none + { + pItem.reset(new XLineJointItem(drawing::LineJoint_NONE)); + break; + } + case 2: // mitered + { + pItem.reset(new XLineJointItem(drawing::LineJoint_MITER)); + break; + } + case 3: // beveled + { + pItem.reset(new XLineJointItem(drawing::LineJoint_BEVEL)); + break; + } + } + + setLineJoint(pItem.get()); + } +} + +IMPL_LINK_NOARG(LinePropertyPanelBase, ChangeCapStyleHdl, weld::ComboBox&, void) +{ + const sal_Int32 nPos(mxLBCapStyle->get_active()); + + if (nPos != -1 && mxLBCapStyle->get_value_changed_from_saved()) + { + std::unique_ptr<XLineCapItem> pItem; + + switch(nPos) + { + case 0: // flat + { + pItem.reset(new XLineCapItem(drawing::LineCap_BUTT)); + break; + } + case 1: // round + { + pItem.reset(new XLineCapItem(drawing::LineCap_ROUND)); + break; + } + case 2: // square + { + pItem.reset(new XLineCapItem(drawing::LineCap_SQUARE)); + break; + } + } + + setLineCap(pItem.get()); + } +} + +IMPL_LINK_NOARG(LinePropertyPanelBase, ToolboxWidthSelectHdl, const OString&, void) +{ + mxTBWidth->set_menu_item_active(SELECTWIDTH, !mxTBWidth->get_menu_item_active(SELECTWIDTH)); +} + +void LinePropertyPanelBase::EndLineWidthPopup() +{ + mxTBWidth->set_menu_item_active(SELECTWIDTH, false); +} + +IMPL_LINK_NOARG( LinePropertyPanelBase, ChangeTransparentHdl, weld::MetricSpinButton&, void ) +{ + sal_uInt16 nVal = static_cast<sal_uInt16>(mxMFTransparent->get_value(FieldUnit::PERCENT)); + XLineTransparenceItem aItem( nVal ); + + setLineTransparency(aItem); +} + +void LinePropertyPanelBase::SetWidthIcon(int n) +{ + if (n == 0) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGNone); + else + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[n-1]); +} + +void LinePropertyPanelBase::SetWidthIcon() +{ + if(!mbWidthValuable) + { + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGNone); + return; + } + + long nVal = LogicToLogic(mnWidthCoreValue * 10, meMapUnit, MapUnit::MapPoint); + + if(nVal <= 6) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[0]); + else if (nVal <= 9) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[1]); + else if (nVal <= 12) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[2]); + else if (nVal <= 19) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[3]); + else if (nVal <= 26) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[4]); + else if (nVal <= 37) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[5]); + else if (nVal <= 52) + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[6]); + else + mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[7]); + +} + +void LinePropertyPanelBase::SetWidth(long nWidth) +{ + mnWidthCoreValue = nWidth; + mbWidthValuable = true; + mxLineWidthPopup->SetWidthSelect(mnWidthCoreValue, mbWidthValuable, meMapUnit); +} + +void LinePropertyPanelBase::ActivateControls() +{ + mxGridLineProps->set_sensitive(!mbNoneLineStyle); + mxBoxArrowProps->set_sensitive(!mbNoneLineStyle); + mxLineStyleTB->set_item_sensitive(".uno:LineEndStyle", !mbNoneLineStyle); + + mxBoxArrowProps->set_visible(mbArrowSupported); + mxLineStyleTB->set_item_visible(".uno:LineEndStyle", mbArrowSupported); +} + +void LinePropertyPanelBase::setMapUnit(MapUnit eMapUnit) +{ + meMapUnit = eMapUnit; + mxLineWidthPopup->SetWidthSelect(mnWidthCoreValue, mbWidthValuable, meMapUnit); +} + +void LinePropertyPanelBase::disableArrowHead() +{ + mbArrowSupported = false; + ActivateControls(); +} + +void LinePropertyPanelBase::enableArrowHead() +{ + mbArrowSupported = true; + ActivateControls(); +} + +} // end of namespace svx::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/line/LineWidthPopup.cxx b/svx/source/sidebar/line/LineWidthPopup.cxx new file mode 100644 index 000000000..c65afbe63 --- /dev/null +++ b/svx/source/sidebar/line/LineWidthPopup.cxx @@ -0,0 +1,226 @@ +/* -*- 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 <svx/sidebar/LineWidthPopup.hxx> +#include <svx/sidebar/LinePropertyPanelBase.hxx> +#include <com/sun/star/beans/NamedValue.hpp> +#include <svx/dialmgr.hxx> +#include <svx/strings.hrc> +#include <svx/xlnwtit.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/viewoptions.hxx> +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> +#include "LineWidthValueSet.hxx" +#include <bitmaps.hlst> + +namespace svx::sidebar { + +LineWidthPopup::LineWidthPopup(weld::Widget* pParent, LinePropertyPanelBase& rParent) + : m_rParent(rParent) + , m_sPt(SvxResId(RID_SVXSTR_PT)) + , m_eMapUnit(MapUnit::MapTwip) + , m_bVSFocus(true) + , m_bCustom(false) + , m_nCustomWidth(0) + , m_aIMGCus(StockImage::Yes, RID_SVXBMP_WIDTH_CUSTOM) + , m_aIMGCusGray(StockImage::Yes, RID_SVXBMP_WIDTH_CUSTOM_GRAY) + , m_xBuilder(Application::CreateBuilder(pParent, "svx/ui/floatinglineproperty.ui")) + , m_xTopLevel(m_xBuilder->weld_container("FloatingLineProperty")) + , m_xMFWidth(m_xBuilder->weld_metric_spin_button("spin", FieldUnit::POINT)) + , m_xVSWidth(new LineWidthValueSet()) + , m_xVSWidthWin(new weld::CustomWeld(*m_xBuilder, "lineset", *m_xVSWidth)) +{ + m_xTopLevel->connect_focus_in(LINK(this, LineWidthPopup, FocusHdl)); + + m_xVSWidth->SetStyle(m_xVSWidth->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT); + + maStrUnits[0] = "0.5"; + maStrUnits[1] = "0.8"; + maStrUnits[2] = "1.0"; + maStrUnits[3] = "1.5"; + maStrUnits[4] = "2.3"; + maStrUnits[5] = "3.0"; + maStrUnits[6] = "4.5"; + maStrUnits[7] = "6.0"; + maStrUnits[8] = SvxResId(RID_SVXSTR_WIDTH_LAST_CUSTOM); + + const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() ); + const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0]; + + for(int i = 0; i <= 7 ; i++) + { + maStrUnits[i] = maStrUnits[i].replace('.', cSep);//Modify + maStrUnits[i] += " "; + maStrUnits[i] += m_sPt; + } + + for (sal_uInt16 i = 1 ; i <= 9; ++i) + { + m_xVSWidth->InsertItem(i); + m_xVSWidth->SetItemText(i, maStrUnits[i-1]); + } + + m_xVSWidth->SetUnit(maStrUnits); + m_xVSWidth->SetItemData(1, reinterpret_cast<void*>(5)); + m_xVSWidth->SetItemData(2, reinterpret_cast<void*>(8)); + m_xVSWidth->SetItemData(3, reinterpret_cast<void*>(10)); + m_xVSWidth->SetItemData(4, reinterpret_cast<void*>(15)); + m_xVSWidth->SetItemData(5, reinterpret_cast<void*>(23)); + m_xVSWidth->SetItemData(6, reinterpret_cast<void*>(30)); + m_xVSWidth->SetItemData(7, reinterpret_cast<void*>(45)); + m_xVSWidth->SetItemData(8, reinterpret_cast<void*>(60)); + m_xVSWidth->SetImage(m_aIMGCusGray); + + m_xVSWidth->SetSelItem(0); + + m_xVSWidth->SetSelectHdl(LINK(this, LineWidthPopup, VSSelectHdl)); + m_xMFWidth->connect_value_changed(LINK(this, LineWidthPopup, MFModifyHdl)); +} + +LineWidthPopup::~LineWidthPopup() +{ +} + +IMPL_LINK_NOARG(LineWidthPopup, VSSelectHdl, ValueSet*, void) +{ + sal_uInt16 iPos = m_xVSWidth->GetSelectedItemId(); + if (iPos >= 1 && iPos <= 8) + { + sal_IntPtr nVal = OutputDevice::LogicToLogic(reinterpret_cast<sal_IntPtr>(m_xVSWidth->GetItemData( iPos )), MapUnit::MapPoint, m_eMapUnit); + nVal = m_xMFWidth->denormalize(nVal); + XLineWidthItem aWidthItem( nVal ); + m_rParent.setLineWidth(aWidthItem); + m_rParent.SetWidthIcon(iPos); + m_rParent.SetWidth(nVal); + } + else if (iPos == 9) + {//last custom + //modified + if (m_bCustom) + { + long nVal = OutputDevice::LogicToLogic(m_nCustomWidth , MapUnit::MapPoint, m_eMapUnit); + nVal = m_xMFWidth->denormalize(nVal); + XLineWidthItem aWidthItem( nVal ); + m_rParent.setLineWidth(aWidthItem); + m_rParent.SetWidth(nVal); + } + else + { + m_xVSWidth->SetNoSelection(); //add , set no selection and keep the last select item + m_xVSWidth->SetFormat(); + m_xVSWidth->Invalidate(); + } + //modify end + } + + if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && m_bCustom)) //add + { + m_rParent.EndLineWidthPopup(); + } +} + +IMPL_LINK_NOARG(LineWidthPopup, MFModifyHdl, weld::MetricSpinButton&, void) +{ + if (m_xVSWidth->GetSelItem()) + { + m_xVSWidth->SetSelItem(0); + m_xVSWidth->SetFormat(); + m_xVSWidth->Invalidate(); + } + long nTmp = static_cast<long>(m_xMFWidth->get_value(FieldUnit::NONE)); + long nVal = OutputDevice::LogicToLogic( nTmp, MapUnit::MapPoint, m_eMapUnit ); + sal_Int32 nNewWidth = static_cast<short>(m_xMFWidth->denormalize( nVal )); + XLineWidthItem aWidthItem(nNewWidth); + m_rParent.setLineWidth(aWidthItem); +} + +void LineWidthPopup::SetWidthSelect(long lValue, bool bValuable, MapUnit eMapUnit) +{ + m_bVSFocus = true; + m_xVSWidth->SetSelItem(0); + m_eMapUnit = eMapUnit; + SvtViewOptions aWinOpt( EViewType::Window, "PopupPanel_LineWidth" ); + 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_nCustomWidth = aWinData.toInt32(); + m_bCustom = true; + m_xVSWidth->SetImage(m_aIMGCus); + m_xVSWidth->SetCusEnable(true); + + OUString aStrTip = OUString::number( static_cast<double>(m_nCustomWidth) / 10) + + m_sPt; + m_xVSWidth->SetItemText(9, aStrTip); + } + else + { + m_bCustom = false; + m_xVSWidth->SetImage(m_aIMGCusGray); + m_xVSWidth->SetCusEnable(false); + m_xVSWidth->SetItemText(9, maStrUnits[8]); + } + + if (bValuable) + { + sal_Int64 nVal = OutputDevice::LogicToLogic(lValue, eMapUnit, MapUnit::Map100thMM ); + nVal = m_xMFWidth->normalize(nVal); + m_xMFWidth->set_value( nVal, FieldUnit::MM_100TH ); + } + else + { + m_xMFWidth->set_text( "" ); + } + + OUString strCurrValue = m_xMFWidth->get_text(); + sal_uInt16 i = 0; + for(; i < 8; i++) + { + if (strCurrValue == maStrUnits[i]) + { + m_xVSWidth->SetSelItem(i+1); + break; + } + } + + if (i>=8) + { + m_bVSFocus = false; + m_xVSWidth->SetSelItem(0); + } + + m_xVSWidth->SetFormat(); + m_xVSWidth->Invalidate(); +} + +IMPL_LINK_NOARG(LineWidthPopup, FocusHdl, weld::Widget&, void) +{ + if (m_bVSFocus) + m_xVSWidth->GrabFocus(); + else + m_xMFWidth->grab_focus(); +} + +} // end of namespace svx::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/line/LineWidthValueSet.cxx b/svx/source/sidebar/line/LineWidthValueSet.cxx new file mode 100644 index 000000000..e78fd51ae --- /dev/null +++ b/svx/source/sidebar/line/LineWidthValueSet.cxx @@ -0,0 +1,172 @@ +/* -*- 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 "LineWidthValueSet.hxx" + +#include <i18nlangtag/mslangid.hxx> +#include <vcl/event.hxx> +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> + +namespace svx::sidebar { + +LineWidthValueSet::LineWidthValueSet() + : ValueSet(nullptr) + , nSelItem(0) + , bCusEnable(false) +{ +} + +void LineWidthValueSet::Resize() +{ + SetColCount(); + SetLineCount(9); + ValueSet::Resize(); +} + +LineWidthValueSet::~LineWidthValueSet() +{ +} + +void LineWidthValueSet::SetUnit(std::array<OUString,9> const & strUnits) +{ + maStrUnits = strUnits; +} + +void LineWidthValueSet::SetSelItem(sal_uInt16 nSel) +{ + nSelItem = nSel; + if(nSel == 0) + { + SelectItem(1); // ,false); // 'false' nut supported by AOO + SetNoSelection(); + } + else + { + SelectItem(nSelItem); + GrabFocus(); + } +} + +void LineWidthValueSet::SetImage(const Image& img) +{ + imgCus = img; +} + +void LineWidthValueSet::SetCusEnable(bool bEnable) +{ + bCusEnable = bEnable; +} + +void LineWidthValueSet::UserDraw( const UserDrawEvent& rUDEvt ) +{ + tools::Rectangle aRect = rUDEvt.GetRect(); + vcl::RenderContext* pDev = rUDEvt.GetRenderContext(); + sal_uInt16 nItemId = rUDEvt.GetItemId(); + + long nRectHeight = aRect.GetHeight(); + long nRectWidth = aRect.GetWidth(); + Point aBLPos = aRect.TopLeft(); + + //const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); + //Color aBackColor(0,0,200); + //const Color aTextColor = rStyleSettings.GetFieldTextColor(); + vcl::Font aOldFont = pDev->GetFont(); + Color aOldColor = pDev->GetLineColor(); + Color aOldFillColor = pDev->GetFillColor(); + + vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne)); + Size aSize = aFont.GetFontSize(); + aSize.setHeight( nRectHeight*3/5 ); + aFont.SetFontSize( aSize ); + + Point aLineStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - nItemId )/2); + Point aLineEnd(aBLPos.X() + nRectWidth * 7 / 9 - 10, aBLPos.Y() + ( nRectHeight - nItemId )/2); + if (nItemId == 9) + { + Point aImgStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - 23 ) / 2); + pDev->DrawImage(aImgStart, imgCus); + + tools::Rectangle aStrRect = aRect; + aStrRect.AdjustTop(nRectHeight/6 ); + aStrRect.AdjustBottom( -(nRectHeight/6) ); + aStrRect.AdjustLeft(imgCus.GetSizePixel().Width() + 20 ); + if(bCusEnable) + aFont.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor()); + else + aFont.SetColor(Application::GetSettings().GetStyleSettings().GetDisableColor()); + + pDev->SetFont(aFont); + pDev->DrawText(aStrRect, maStrUnits[ nItemId - 1 ], DrawTextFlags::EndEllipsis); + } + else + { + if( nSelItem == nItemId ) + { + tools::Rectangle aBackRect = aRect; + aBackRect.AdjustTop(3 ); + aBackRect.AdjustBottom( -2 ); + pDev->SetFillColor(Color(50,107,197)); + pDev->DrawRect(aBackRect); + } + else + { + pDev->SetFillColor( COL_TRANSPARENT ); + pDev->DrawRect(aRect); + } + + //draw text + if(nSelItem == nItemId ) + aFont.SetColor(COL_WHITE); + else + aFont.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor()); + pDev->SetFont(aFont); + Point aStart(aBLPos.X() + nRectWidth * 7 / 9 , aBLPos.Y() + nRectHeight/6); + pDev->DrawText(aStart, maStrUnits[ nItemId - 1 ]); //can't set DrawTextFlags::EndEllipsis here ,or the text will disappear + + //draw line + if( nSelItem == nItemId ) + pDev->SetLineColor(COL_WHITE); + else + pDev->SetLineColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor()); + + for(sal_uInt16 i = 1; i <= nItemId; i++) + { + pDev->DrawLine(aLineStart,aLineEnd ); + aLineStart.setY(aLineStart.getY() + 1); + aLineEnd.setY (aLineEnd.getY() + 1); + } + } + + Invalidate( aRect ); + pDev->SetLineColor(aOldColor); + pDev->SetFillColor(aOldFillColor); + pDev->SetFont(aOldFont); +} + +void LineWidthValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea) +{ + ValueSet::SetDrawingArea(pDrawingArea); + Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(80, 12 * 9), MapMode(MapUnit::MapAppFont))); + pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); + SetOutputSizePixel(aSize); +} + +} // end of namespace svx::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/line/LineWidthValueSet.hxx b/svx/source/sidebar/line/LineWidthValueSet.hxx new file mode 100644 index 000000000..225e706a6 --- /dev/null +++ b/svx/source/sidebar/line/LineWidthValueSet.hxx @@ -0,0 +1,55 @@ +/* -*- 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_SVX_SOURCE_SIDEBAR_LINE_LINEWIDTHVALUESET_HXX +#define INCLUDED_SVX_SOURCE_SIDEBAR_LINE_LINEWIDTHVALUESET_HXX + +#include <svtools/valueset.hxx> +#include <vcl/image.hxx> +#include <array> + +namespace svx::sidebar { + +class LineWidthValueSet final : public ValueSet +{ +public: + explicit LineWidthValueSet(); + virtual ~LineWidthValueSet() override; + + void SetUnit(std::array<OUString,9> const & strUnits); + void SetSelItem(sal_uInt16 nSel); + sal_uInt16 GetSelItem() const { return nSelItem;} + void SetImage(const Image& img); + void SetCusEnable(bool bEnable); + + virtual void UserDraw( const UserDrawEvent& rUDEvt ) override; + virtual void Resize() override; + virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; + +private: + sal_uInt16 nSelItem; + std::array<OUString,9> maStrUnits; + Image imgCus; + bool bCusEnable; +}; + +} // end of namespace svx::sidebar + +#endif // INCLUDED_SVX_SOURCE_SIDEBAR_LINE_LINEWIDTHVALUESET_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |