Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / sidebar / WrapPropertyPanel.cxx
blobef7990729f87e4c02974dcb65433b728c5376e9a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WrapPropertyPanel.hxx"
22 #include <editeng/editids.hrc>
23 #include <svx/spacinglistbox.hxx>
24 #include <svx/svdtrans.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <editeng/lrspitem.hxx>
28 #include <editeng/ulspitem.hxx>
29 #include <hintids.hxx>
30 #include <strings.hrc>
31 #include <uitool.hxx>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 namespace sw::sidebar {
36 std::unique_ptr<PanelLayout> WrapPropertyPanel::Create (
37 weld::Widget* pParent,
38 const css::uno::Reference< css::frame::XFrame >& rxFrame,
39 SfxBindings* pBindings)
41 if (pParent == nullptr)
42 throw css::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", nullptr, 0);
43 if ( ! rxFrame.is())
44 throw css::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", nullptr, 1);
45 if (pBindings == nullptr)
46 throw css::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", nullptr, 2);
48 return std::make_unique<WrapPropertyPanel>(pParent, rxFrame, pBindings);
51 WrapPropertyPanel::WrapPropertyPanel(
52 weld::Widget* pParent,
53 const css::uno::Reference< css::frame::XFrame >& rxFrame,
54 SfxBindings* pBindings )
55 : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui")
56 , mpBindings(pBindings)
57 // spacing
58 , m_nTop(0)
59 , m_nBottom(0)
60 , m_nLeft(0)
61 , m_nRight(0)
62 // resources
63 , m_aCustomEntry(SwResId(STR_WRAP_PANEL_CUSTOM_STR))
64 // controller items
65 , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this)
66 , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this)
67 , mxWrapOptions(m_xBuilder->weld_toolbar("wrapoptions"))
68 , mxWrapOptionsDispatch(new ToolbarUnoDispatcher(*mxWrapOptions, *m_xBuilder, rxFrame))
69 , mxSpacingLB(m_xBuilder->weld_combo_box("spacingLB"))
71 FieldUnit eMetric = ::GetDfltMetric(false);
72 SpacingListBox::Fill(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxSpacingLB);
74 Initialize();
77 WrapPropertyPanel::~WrapPropertyPanel()
80 mxWrapOptionsDispatch.reset();
81 mxWrapOptions.reset();
83 maSwLRSpacingControl.dispose();
84 maSwULSpacingControl.dispose();
87 void WrapPropertyPanel::Initialize()
89 mxSpacingLB->connect_changed(LINK(this, WrapPropertyPanel, SpacingLBHdl));
91 mpBindings->Update( SID_ATTR_LRSPACE );
92 mpBindings->Update( SID_ATTR_ULSPACE );
95 void WrapPropertyPanel::UpdateSpacingLB()
97 if( (m_nLeft == m_nRight) && (m_nTop == m_nBottom) && (m_nLeft == m_nTop) )
99 sal_Int32 nCount = mxSpacingLB->get_count();
100 for (sal_Int32 i = 0; i < nCount; i++)
102 if (mxSpacingLB->get_id(i).toUInt32() == m_nLeft)
104 mxSpacingLB->set_active(i);
105 int nCustomEntry = mxSpacingLB->find_text(m_aCustomEntry);
106 if (nCustomEntry != -1)
107 mxSpacingLB->remove(nCustomEntry);
108 return;
113 if (mxSpacingLB->find_text(m_aCustomEntry) == -1)
114 mxSpacingLB->append_text(m_aCustomEntry);
115 mxSpacingLB->set_active_text(m_aCustomEntry);
118 IMPL_LINK(WrapPropertyPanel, SpacingLBHdl, weld::ComboBox&, rBox, void)
120 sal_uInt16 nVal = rBox.get_active_id().toUInt32();
122 SvxLRSpaceItem aLRItem(nVal, nVal, 0, RES_LR_SPACE);
123 SvxULSpaceItem aULItem(nVal, nVal, RES_UL_SPACE);
125 m_nTop = m_nBottom = m_nLeft = m_nRight = nVal;
126 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_LRSPACE,
127 SfxCallMode::RECORD, { &aLRItem });
128 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_ULSPACE,
129 SfxCallMode::RECORD, { &aULItem });
132 void WrapPropertyPanel::NotifyItemUpdate(
133 const sal_uInt16 nSId,
134 const SfxItemState eState,
135 const SfxPoolItem* pState)
137 switch(nSId)
139 case SID_ATTR_LRSPACE:
141 if(eState >= SfxItemState::DEFAULT)
143 const SvxLRSpaceItem* pItem = dynamic_cast< const SvxLRSpaceItem* >(pState);
144 if(pItem)
146 m_nLeft = pItem->GetLeft();
147 m_nRight = pItem->GetRight();
149 UpdateSpacingLB();
153 break;
154 case SID_ATTR_ULSPACE:
156 if(eState >= SfxItemState::DEFAULT)
158 const SvxULSpaceItem* pItem = dynamic_cast< const SvxULSpaceItem* >(pState);
159 if(pItem)
161 m_nTop = pItem->GetUpper();
162 m_nBottom = pItem->GetLower();
164 UpdateSpacingLB();
168 break;
172 } // end of namespace ::sw::sidebar
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */