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
)
36 , m_sPt(SvxResId(RID_SVXSTR_PT
))
37 , m_eMapUnit(MapUnit::MapTwip
)
41 , m_aIMGCus(StockImage::Yes
, RID_SVXBMP_WIDTH_CUSTOM
)
42 , m_aIMGCusGray(StockImage::Yes
, RID_SVXBMP_WIDTH_CUSTOM_GRAY
)
43 , m_xBuilder(Application::CreateBuilder(pParent
, "svx/ui/floatinglineproperty.ui"))
44 , m_xTopLevel(m_xBuilder
->weld_container("FloatingLineProperty"))
45 , m_xMFWidth(m_xBuilder
->weld_metric_spin_button("spin", FieldUnit::POINT
))
46 , m_xVSWidth(new LineWidthValueSet())
47 , m_xVSWidthWin(new weld::CustomWeld(*m_xBuilder
, "lineset", *m_xVSWidth
))
49 m_xTopLevel
->connect_focus_in(LINK(this, LineWidthPopup
, FocusHdl
));
51 m_xVSWidth
->SetStyle(m_xVSWidth
->GetStyle() | WB_3DLOOK
| WB_NO_DIRECTSELECT
);
53 maStrUnits
[0] = "0.5";
54 maStrUnits
[1] = "0.8";
55 maStrUnits
[2] = "1.0";
56 maStrUnits
[3] = "1.5";
57 maStrUnits
[4] = "2.3";
58 maStrUnits
[5] = "3.0";
59 maStrUnits
[6] = "4.5";
60 maStrUnits
[7] = "6.0";
61 maStrUnits
[8] = SvxResId(RID_SVXSTR_WIDTH_LAST_CUSTOM
);
63 const LocaleDataWrapper
& rLocaleWrapper(Application::GetSettings().GetLocaleDataWrapper());
64 const sal_Unicode cSep
= rLocaleWrapper
.getNumDecimalSep()[0];
66 for (int i
= 0; i
<= 7; i
++)
68 maStrUnits
[i
] = maStrUnits
[i
].replace('.', cSep
); //Modify
70 maStrUnits
[i
] += m_sPt
;
73 for (sal_uInt16 i
= 1; i
<= 9; ++i
)
75 m_xVSWidth
->InsertItem(i
);
76 m_xVSWidth
->SetItemText(i
, maStrUnits
[i
- 1]);
79 m_xVSWidth
->SetUnit(maStrUnits
);
80 m_xVSWidth
->SetItemData(1, reinterpret_cast<void*>(5));
81 m_xVSWidth
->SetItemData(2, reinterpret_cast<void*>(8));
82 m_xVSWidth
->SetItemData(3, reinterpret_cast<void*>(10));
83 m_xVSWidth
->SetItemData(4, reinterpret_cast<void*>(15));
84 m_xVSWidth
->SetItemData(5, reinterpret_cast<void*>(23));
85 m_xVSWidth
->SetItemData(6, reinterpret_cast<void*>(30));
86 m_xVSWidth
->SetItemData(7, reinterpret_cast<void*>(45));
87 m_xVSWidth
->SetItemData(8, reinterpret_cast<void*>(60));
88 m_xVSWidth
->SetImage(m_aIMGCusGray
);
90 m_xVSWidth
->SetSelItem(0);
92 m_xVSWidth
->SetSelectHdl(LINK(this, LineWidthPopup
, VSSelectHdl
));
93 m_xMFWidth
->connect_value_changed(LINK(this, LineWidthPopup
, MFModifyHdl
));
96 LineWidthPopup::~LineWidthPopup() {}
98 IMPL_LINK_NOARG(LineWidthPopup
, VSSelectHdl
, ValueSet
*, void)
100 sal_uInt16 iPos
= m_xVSWidth
->GetSelectedItemId();
101 if (iPos
>= 1 && iPos
<= 8)
103 sal_IntPtr nVal
= OutputDevice::LogicToLogic(
104 reinterpret_cast<sal_IntPtr
>(m_xVSWidth
->GetItemData(iPos
)), MapUnit::MapPoint
,
106 nVal
= m_xMFWidth
->denormalize(nVal
);
107 XLineWidthItem
aWidthItem(nVal
);
108 m_rParent
.setLineWidth(aWidthItem
);
109 m_rParent
.SetWidthIcon(iPos
);
110 m_rParent
.SetWidth(nVal
);
118 = OutputDevice::LogicToLogic(m_nCustomWidth
, MapUnit::MapPoint
, m_eMapUnit
);
119 nVal
= m_xMFWidth
->denormalize(nVal
);
120 XLineWidthItem
aWidthItem(nVal
);
121 m_rParent
.setLineWidth(aWidthItem
);
122 m_rParent
.SetWidth(nVal
);
126 m_xVSWidth
->SetNoSelection(); //add , set no selection and keep the last select item
127 m_xVSWidth
->SetFormat();
128 m_xVSWidth
->Invalidate();
133 if ((iPos
>= 1 && iPos
<= 8) || (iPos
== 9 && m_bCustom
)) //add
135 m_rParent
.EndLineWidthPopup();
139 IMPL_LINK_NOARG(LineWidthPopup
, MFModifyHdl
, weld::MetricSpinButton
&, void)
141 if (m_xVSWidth
->GetSelItem())
143 m_xVSWidth
->SetSelItem(0);
144 m_xVSWidth
->SetFormat();
145 m_xVSWidth
->Invalidate();
147 tools::Long nTmp
= static_cast<tools::Long
>(m_xMFWidth
->get_value(FieldUnit::NONE
));
148 tools::Long nVal
= OutputDevice::LogicToLogic(nTmp
, MapUnit::MapPoint
, m_eMapUnit
);
149 sal_Int32 nNewWidth
= static_cast<short>(m_xMFWidth
->denormalize(nVal
));
150 XLineWidthItem
aWidthItem(nNewWidth
);
151 m_rParent
.setLineWidth(aWidthItem
);
154 void LineWidthPopup::SetWidthSelect(tools::Long lValue
, bool bValuable
, MapUnit eMapUnit
)
157 m_xVSWidth
->SetSelItem(0);
158 m_eMapUnit
= eMapUnit
;
159 SvtViewOptions
aWinOpt(EViewType::Window
, "PopupPanel_LineWidth");
160 if (aWinOpt
.Exists())
162 css::uno::Sequence
<css::beans::NamedValue
> aSeq
= aWinOpt
.GetUserData();
164 if (aSeq
.hasElements())
165 aSeq
[0].Value
>>= aTmp
;
167 OUString
aWinData(aTmp
);
168 m_nCustomWidth
= aWinData
.toInt32();
170 m_xVSWidth
->SetImage(m_aIMGCus
);
171 m_xVSWidth
->SetCusEnable(true);
173 OUString aStrTip
= OUString::number(static_cast<double>(m_nCustomWidth
) / 10) + m_sPt
;
174 m_xVSWidth
->SetItemText(9, aStrTip
);
179 m_xVSWidth
->SetImage(m_aIMGCusGray
);
180 m_xVSWidth
->SetCusEnable(false);
181 m_xVSWidth
->SetItemText(9, maStrUnits
[8]);
186 sal_Int64 nVal
= OutputDevice::LogicToLogic(lValue
, eMapUnit
, MapUnit::Map100thMM
);
187 nVal
= m_xMFWidth
->normalize(nVal
);
188 m_xMFWidth
->set_value(nVal
, FieldUnit::MM_100TH
);
192 m_xMFWidth
->set_text("");
195 OUString strCurrValue
= m_xMFWidth
->get_text();
199 if (strCurrValue
== maStrUnits
[i
])
201 m_xVSWidth
->SetSelItem(i
+ 1);
209 m_xVSWidth
->SetSelItem(0);
212 m_xVSWidth
->SetFormat();
213 m_xVSWidth
->Invalidate();
216 IMPL_LINK_NOARG(LineWidthPopup
, FocusHdl
, weld::Widget
&, void)
219 m_xVSWidth
->GrabFocus();
221 m_xMFWidth
->grab_focus();
224 } // end of namespace svx::sidebar
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */