LibreOffice Module svx (master) 1
LineWidthPopup.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
21#include <com/sun/star/beans/NamedValue.hpp>
22#include <svx/dialmgr.hxx>
23#include <svx/strings.hrc>
24#include <svx/xlnwtit.hxx>
27#include <vcl/settings.hxx>
28#include <vcl/svapp.hxx>
29#include "LineWidthValueSet.hxx"
30#include <bitmaps.hlst>
31
32namespace svx::sidebar
33{
35 : WeldToolbarPopup(nullptr, pParent, "svx/ui/floatinglineproperty.ui", "FloatingLineProperty")
36 , m_rParent(rParent)
37 , m_sPt(SvxResId(RID_SVXSTR_PT))
38 , m_eMapUnit(MapUnit::MapTwip)
39 , m_bVSFocus(true)
40 , m_bCustom(false)
41 , m_nCustomWidth(0)
42 , m_aIMGCus(StockImage::Yes, RID_SVXBMP_WIDTH_CUSTOM)
43 , m_aIMGCusGray(StockImage::Yes, RID_SVXBMP_WIDTH_CUSTOM_GRAY)
44 , m_xMFWidth(m_xBuilder->weld_metric_spin_button("spin", FieldUnit::POINT))
45 , m_xVSWidth(new LineWidthValueSet())
46 , m_xVSWidthWin(new weld::CustomWeld(*m_xBuilder, "lineset", *m_xVSWidth))
47{
48 m_xVSWidth->SetStyle(m_xVSWidth->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT);
49
50 maStrUnits[0] = "0.5";
51 maStrUnits[1] = "0.8";
52 maStrUnits[2] = "1.0";
53 maStrUnits[3] = "1.5";
54 maStrUnits[4] = "2.3";
55 maStrUnits[5] = "3.0";
56 maStrUnits[6] = "4.5";
57 maStrUnits[7] = "6.0";
58 maStrUnits[8] = SvxResId(RID_SVXSTR_WIDTH_LAST_CUSTOM);
59
61 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
62
63 for (int i = 0; i <= 7; i++)
64 {
65 maStrUnits[i] = maStrUnits[i].replace('.', cSep); //Modify
66 maStrUnits[i] += " ";
67 maStrUnits[i] += m_sPt;
68 }
69
70 for (sal_uInt16 i = 1; i <= 9; ++i)
71 {
72 m_xVSWidth->InsertItem(i);
73 m_xVSWidth->SetItemText(i, maStrUnits[i - 1]);
74 }
75
76 m_xVSWidth->SetUnit(maStrUnits);
77 m_xVSWidth->SetItemData(1, reinterpret_cast<void*>(5));
78 m_xVSWidth->SetItemData(2, reinterpret_cast<void*>(8));
79 m_xVSWidth->SetItemData(3, reinterpret_cast<void*>(10));
80 m_xVSWidth->SetItemData(4, reinterpret_cast<void*>(15));
81 m_xVSWidth->SetItemData(5, reinterpret_cast<void*>(23));
82 m_xVSWidth->SetItemData(6, reinterpret_cast<void*>(30));
83 m_xVSWidth->SetItemData(7, reinterpret_cast<void*>(45));
84 m_xVSWidth->SetItemData(8, reinterpret_cast<void*>(60));
85 m_xVSWidth->SetImage(m_aIMGCusGray);
86
87 m_xVSWidth->SetSelItem(0);
88
89 m_xVSWidth->SetSelectHdl(LINK(this, LineWidthPopup, VSSelectHdl));
90 m_xMFWidth->connect_value_changed(LINK(this, LineWidthPopup, MFModifyHdl));
91}
92
94
96{
97 sal_uInt16 iPos = m_xVSWidth->GetSelectedItemId();
98 if (iPos >= 1 && iPos <= 8)
99 {
100 sal_IntPtr nVal = OutputDevice::LogicToLogic(
101 reinterpret_cast<sal_IntPtr>(m_xVSWidth->GetItemData(iPos)), MapUnit::MapPoint,
102 m_eMapUnit);
103 nVal = m_xMFWidth->denormalize(nVal);
104 XLineWidthItem aWidthItem(nVal);
105 m_rParent.setLineWidth(aWidthItem);
106 m_rParent.SetWidthIcon(iPos);
107 m_rParent.SetWidth(nVal);
108 }
109 else if (iPos == 9)
110 { //last custom
111 //modified
112 if (m_bCustom)
113 {
114 tools::Long nVal
115 = OutputDevice::LogicToLogic(m_nCustomWidth, MapUnit::MapPoint, m_eMapUnit);
116 nVal = m_xMFWidth->denormalize(nVal);
117 XLineWidthItem aWidthItem(nVal);
118 m_rParent.setLineWidth(aWidthItem);
119 m_rParent.SetWidth(nVal);
120 }
121 else
122 {
123 m_xVSWidth->SetNoSelection(); //add , set no selection and keep the last select item
124 m_xVSWidth->SetFormat();
125 m_xVSWidth->Invalidate();
126 }
127 //modify end
128 }
129
130 if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && m_bCustom)) //add
131 {
132 m_rParent.EndLineWidthPopup();
133 }
134}
135
137{
138 if (m_xVSWidth->GetSelItem())
139 {
140 m_xVSWidth->SetSelItem(0);
141 m_xVSWidth->SetFormat();
142 m_xVSWidth->Invalidate();
143 }
144 tools::Long nTmp = static_cast<tools::Long>(m_xMFWidth->get_value(FieldUnit::NONE));
145 tools::Long nVal = OutputDevice::LogicToLogic(nTmp, MapUnit::MapPoint, m_eMapUnit);
146 sal_Int32 nNewWidth = static_cast<short>(m_xMFWidth->denormalize(nVal));
147 XLineWidthItem aWidthItem(nNewWidth);
148 m_rParent.setLineWidth(aWidthItem);
149}
150
151void LineWidthPopup::SetWidthSelect(tools::Long lValue, bool bValuable, MapUnit eMapUnit)
152{
153 m_bVSFocus = true;
154 m_xVSWidth->SetSelItem(0);
155 m_eMapUnit = eMapUnit;
156 SvtViewOptions aWinOpt(EViewType::Window, "PopupPanel_LineWidth");
157 if (aWinOpt.Exists())
158 {
159 css::uno::Sequence<css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
160 OUString aTmp;
161 if (aSeq.hasElements())
162 aSeq[0].Value >>= aTmp;
163
164 OUString aWinData(aTmp);
165 m_nCustomWidth = aWinData.toInt32();
166 m_bCustom = true;
167 m_xVSWidth->SetImage(m_aIMGCus);
168 m_xVSWidth->SetCusEnable(true);
169
170 OUString aStrTip = OUString::number(static_cast<double>(m_nCustomWidth) / 10) + m_sPt;
171 m_xVSWidth->SetItemText(9, aStrTip);
172 }
173 else
174 {
175 m_bCustom = false;
176 m_xVSWidth->SetImage(m_aIMGCusGray);
177 m_xVSWidth->SetCusEnable(false);
178 m_xVSWidth->SetItemText(9, maStrUnits[8]);
179 }
180
181 if (bValuable)
182 {
183 sal_Int64 nVal = OutputDevice::LogicToLogic(lValue, eMapUnit, MapUnit::Map100thMM);
184 nVal = m_xMFWidth->normalize(nVal);
185 m_xMFWidth->set_value(nVal, FieldUnit::MM_100TH);
186 }
187 else
188 {
189 m_xMFWidth->set_text("");
190 }
191
192 OUString strCurrValue = m_xMFWidth->get_text();
193 sal_uInt16 i = 0;
194 for (; i < 8; i++)
195 {
196 if (strCurrValue == maStrUnits[i])
197 {
198 m_xVSWidth->SetSelItem(i + 1);
199 break;
200 }
201 }
202
203 if (i >= 8)
204 {
205 m_bVSFocus = false;
206 m_xVSWidth->SetSelItem(0);
207 }
208
209 m_xVSWidth->SetFormat();
210 m_xVSWidth->Invalidate();
211}
212
214{
215 if (m_bVSFocus)
216 m_xVSWidth->GrabFocus();
217 else
218 m_xMFWidth->grab_focus();
219}
220
221} // end of namespace svx::sidebar
222
223/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XSLTFilter & m_rParent
static const AllSettings & GetSettings()
const OUString & getNumDecimalSep() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
css::uno::Sequence< css::beans::NamedValue > GetUserData() const
bool Exists() const
std::array< OUString, 9 > maStrUnits
void SetWidthSelect(tools::Long lValue, bool bValuable, MapUnit eMapUnit)
LineWidthPopup(weld::Widget *pParent, LinePropertyPanelBase &rParent)
virtual void GrabFocus() override
std::unique_ptr< weld::MetricSpinButton > m_xMFWidth
std::unique_ptr< LineWidthValueSet > m_xVSWidth
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
FieldUnit
StockImage
Sequence< sal_Int8 > aSeq
MapUnit
Yes
int i
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
long Long
sal_uInt16 sal_Unicode
#define WB_NO_DIRECTSELECT
WinBits const WB_3DLOOK