nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / sidebar / WrapPropertyPanel.cxx
blob08c6405f7a310f33351a0d691fd2de99a8550b85
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 <cmdid.h>
23 #include <svx/spacinglistbox.hxx>
24 #include <svx/svdtrans.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <svl/eitem.hxx>
28 #include <vcl/commandinfoprovider.hxx>
29 #include <vcl/settings.hxx>
30 #include <editeng/lrspitem.hxx>
31 #include <editeng/ulspitem.hxx>
32 #include <hintids.hxx>
33 #include <strings.hrc>
34 #include <uitool.hxx>
35 #include <com/sun/star/lang/IllegalArgumentException.hpp>
36 #include <comphelper/lok.hxx>
38 namespace sw::sidebar {
40 VclPtr<vcl::Window> WrapPropertyPanel::Create (
41 vcl::Window* pParent,
42 const css::uno::Reference< css::frame::XFrame >& rxFrame,
43 SfxBindings* pBindings)
45 if (pParent == nullptr)
46 throw css::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", nullptr, 0);
47 if ( ! rxFrame.is())
48 throw css::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", nullptr, 1);
49 if (pBindings == nullptr)
50 throw css::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", nullptr, 2);
52 return VclPtr<WrapPropertyPanel>::Create(
53 pParent,
54 rxFrame,
55 pBindings);
58 WrapPropertyPanel::WrapPropertyPanel(
59 vcl::Window* pParent,
60 const css::uno::Reference< css::frame::XFrame >& rxFrame,
61 SfxBindings* pBindings )
62 : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui", rxFrame)
63 , mpBindings(pBindings)
64 // spacing
65 , nTop(0)
66 , nBottom(0)
67 , nLeft(0)
68 , nRight(0)
69 // resources
70 , aCustomEntry(SwResId(STR_WRAP_PANEL_CUSTOM_STR))
71 // controller items
72 , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this)
73 , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this)
74 , mxWrapOptions(m_xBuilder->weld_toolbar("wrapoptions"))
75 , mxWrapOptionsDispatch(new ToolbarUnoDispatcher(*mxWrapOptions, *m_xBuilder, rxFrame))
76 , mxSpacingLB(m_xBuilder->weld_combo_box("spacingLB"))
78 FieldUnit eMetric = ::GetDfltMetric(false);
79 SpacingListBox::Fill(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxSpacingLB);
81 Initialize();
83 m_pInitialFocusWidget = mxWrapOptions.get();
86 WrapPropertyPanel::~WrapPropertyPanel()
88 disposeOnce();
91 void WrapPropertyPanel::dispose()
93 mxSpacingLB.reset();
95 mxWrapOptionsDispatch.reset();
96 mxWrapOptions.reset();
98 maSwLRSpacingControl.dispose();
99 maSwULSpacingControl.dispose();
101 PanelLayout::dispose();
104 void WrapPropertyPanel::Initialize()
106 mxSpacingLB->connect_changed(LINK(this, WrapPropertyPanel, SpacingLBHdl));
108 mpBindings->Update( SID_ATTR_LRSPACE );
109 mpBindings->Update( SID_ATTR_ULSPACE );
112 void WrapPropertyPanel::UpdateSpacingLB()
114 if( (nLeft == nRight) && (nTop == nBottom) && (nLeft == nTop) )
116 sal_Int32 nCount = mxSpacingLB->get_count();
117 for (sal_Int32 i = 0; i < nCount; i++)
119 if (mxSpacingLB->get_id(i).toUInt32() == nLeft)
121 mxSpacingLB->set_active(i);
122 int nCustomEntry = mxSpacingLB->find_text(aCustomEntry);
123 if (nCustomEntry != -1)
124 mxSpacingLB->remove(nCustomEntry);
125 return;
130 if (mxSpacingLB->find_text(aCustomEntry) == -1)
131 mxSpacingLB->append_text(aCustomEntry);
132 mxSpacingLB->set_active_text(aCustomEntry);
135 IMPL_LINK(WrapPropertyPanel, SpacingLBHdl, weld::ComboBox&, rBox, void)
137 sal_uInt16 nVal = rBox.get_active_id().toUInt32();
139 SvxLRSpaceItem aLRItem(nVal, nVal, 0, 0, RES_LR_SPACE);
140 SvxULSpaceItem aULItem(nVal, nVal, RES_UL_SPACE);
142 nTop = nBottom = nLeft = nRight = nVal;
143 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_LRSPACE,
144 SfxCallMode::RECORD, { &aLRItem });
145 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_ULSPACE,
146 SfxCallMode::RECORD, { &aULItem });
149 void WrapPropertyPanel::NotifyItemUpdate(
150 const sal_uInt16 nSId,
151 const SfxItemState eState,
152 const SfxPoolItem* pState)
154 switch(nSId)
156 case SID_ATTR_LRSPACE:
158 if(eState >= SfxItemState::DEFAULT)
160 const SvxLRSpaceItem* pItem = dynamic_cast< const SvxLRSpaceItem* >(pState);
161 if(pItem)
163 nLeft = pItem->GetLeft();
164 nRight = pItem->GetRight();
166 UpdateSpacingLB();
170 break;
171 case SID_ATTR_ULSPACE:
173 if(eState >= SfxItemState::DEFAULT)
175 const SvxULSpaceItem* pItem = dynamic_cast< const SvxULSpaceItem* >(pState);
176 if(pItem)
178 nTop = pItem->GetUpper();
179 nBottom = pItem->GetLower();
181 UpdateSpacingLB();
185 break;
189 } // end of namespace ::sw::sidebar
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */