1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include <svx/sidebar/LineWidthPopup.hxx>
20 #include <svx/sidebar/LinePropertyPanelBase.hxx>
21 #include <com/sun/star/beans/NamedValue.hpp>
22 #include <svx/dialmgr.hxx>
23 #include <svx/strings.hrc>
24 #include <svx/xlnwtit.hxx>
25 #include <unotools/localedatawrapper.hxx>
26 #include <unotools/viewoptions.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/svapp.hxx>
29 #include "LineWidthValueSet.hxx"
30 #include <bitmaps.hlst>
32 namespace svx::sidebar
34 LineWidthPopup::LineWidthPopup(weld::Widget
* pParent
, LinePropertyPanelBase
& rParent
)
35 : WeldToolbarPopup(nullptr, pParent
, "svx/ui/floatinglineproperty.ui", "FloatingLineProperty")
37 , m_sPt(SvxResId(RID_SVXSTR_PT
))
38 , m_eMapUnit(MapUnit::MapTwip
)
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
))
48 m_xVSWidth
->SetStyle(m_xVSWidth
->GetStyle() | WB_3DLOOK
| WB_NO_DIRECTSELECT
);
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
);
60 const LocaleDataWrapper
& rLocaleWrapper(Application::GetSettings().GetLocaleDataWrapper());
61 const sal_Unicode cSep
= rLocaleWrapper
.getNumDecimalSep()[0];
63 for (int i
= 0; i
<= 7; i
++)
65 maStrUnits
[i
] = maStrUnits
[i
].replace('.', cSep
); //Modify
67 maStrUnits
[i
] += m_sPt
;
70 for (sal_uInt16 i
= 1; i
<= 9; ++i
)
72 m_xVSWidth
->InsertItem(i
);
73 m_xVSWidth
->SetItemText(i
, maStrUnits
[i
- 1]);
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
);
87 m_xVSWidth
->SetSelItem(0);
89 m_xVSWidth
->SetSelectHdl(LINK(this, LineWidthPopup
, VSSelectHdl
));
90 m_xMFWidth
->connect_value_changed(LINK(this, LineWidthPopup
, MFModifyHdl
));
93 LineWidthPopup::~LineWidthPopup() {}
95 IMPL_LINK_NOARG(LineWidthPopup
, VSSelectHdl
, ValueSet
*, void)
97 sal_uInt16 iPos
= m_xVSWidth
->GetSelectedItemId();
98 if (iPos
>= 1 && iPos
<= 8)
100 sal_IntPtr nVal
= OutputDevice::LogicToLogic(
101 reinterpret_cast<sal_IntPtr
>(m_xVSWidth
->GetItemData(iPos
)), MapUnit::MapPoint
,
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
);
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
);
123 m_xVSWidth
->SetNoSelection(); //add , set no selection and keep the last select item
124 m_xVSWidth
->SetFormat();
125 m_xVSWidth
->Invalidate();
130 if ((iPos
>= 1 && iPos
<= 8) || (iPos
== 9 && m_bCustom
)) //add
132 m_rParent
.EndLineWidthPopup();
136 IMPL_LINK_NOARG(LineWidthPopup
, MFModifyHdl
, weld::MetricSpinButton
&, void)
138 if (m_xVSWidth
->GetSelItem())
140 m_xVSWidth
->SetSelItem(0);
141 m_xVSWidth
->SetFormat();
142 m_xVSWidth
->Invalidate();
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
);
151 void LineWidthPopup::SetWidthSelect(tools::Long lValue
, bool bValuable
, MapUnit eMapUnit
)
154 m_xVSWidth
->SetSelItem(0);
155 m_eMapUnit
= eMapUnit
;
156 SvtViewOptions
aWinOpt(EViewType::Window
, "PopupPanel_LineWidth");
157 if (aWinOpt
.Exists())
159 css::uno::Sequence
<css::beans::NamedValue
> aSeq
= aWinOpt
.GetUserData();
161 if (aSeq
.hasElements())
162 aSeq
[0].Value
>>= aTmp
;
164 OUString
aWinData(aTmp
);
165 m_nCustomWidth
= aWinData
.toInt32();
167 m_xVSWidth
->SetImage(m_aIMGCus
);
168 m_xVSWidth
->SetCusEnable(true);
170 OUString aStrTip
= OUString::number(static_cast<double>(m_nCustomWidth
) / 10) + m_sPt
;
171 m_xVSWidth
->SetItemText(9, aStrTip
);
176 m_xVSWidth
->SetImage(m_aIMGCusGray
);
177 m_xVSWidth
->SetCusEnable(false);
178 m_xVSWidth
->SetItemText(9, maStrUnits
[8]);
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
);
189 m_xMFWidth
->set_text("");
192 OUString strCurrValue
= m_xMFWidth
->get_text();
196 if (strCurrValue
== maStrUnits
[i
])
198 m_xVSWidth
->SetSelItem(i
+ 1);
206 m_xVSWidth
->SetSelItem(0);
209 m_xVSWidth
->SetFormat();
210 m_xVSWidth
->Invalidate();
213 void LineWidthPopup::GrabFocus()
216 m_xVSWidth
->GrabFocus();
218 m_xMFWidth
->grab_focus();
221 } // end of namespace svx::sidebar
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */