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>
26 #include <unotools/viewoptions.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/svapp.hxx>
29 #include "LineWidthValueSet.hxx"
30 #include <bitmaps.hlst>
31 
32 namespace svx::sidebar
33 {
35  : m_rParent(rParent)
36  , m_sPt(SvxResId(RID_SVXSTR_PT))
37  , m_eMapUnit(MapUnit::MapTwip)
38  , m_bVSFocus(true)
39  , m_bCustom(false)
40  , m_nCustomWidth(0)
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))
48 {
49  m_xTopLevel->connect_focus_in(LINK(this, LineWidthPopup, FocusHdl));
50 
51  m_xVSWidth->SetStyle(m_xVSWidth->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT);
52 
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);
62 
64  const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
65 
66  for (int i = 0; i <= 7; i++)
67  {
68  maStrUnits[i] = maStrUnits[i].replace('.', cSep); //Modify
69  maStrUnits[i] += " ";
70  maStrUnits[i] += m_sPt;
71  }
72 
73  for (sal_uInt16 i = 1; i <= 9; ++i)
74  {
75  m_xVSWidth->InsertItem(i);
76  m_xVSWidth->SetItemText(i, maStrUnits[i - 1]);
77  }
78 
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);
89 
90  m_xVSWidth->SetSelItem(0);
91 
92  m_xVSWidth->SetSelectHdl(LINK(this, LineWidthPopup, VSSelectHdl));
93  m_xMFWidth->connect_value_changed(LINK(this, LineWidthPopup, MFModifyHdl));
94 }
95 
97 
99 {
100  sal_uInt16 iPos = m_xVSWidth->GetSelectedItemId();
101  if (iPos >= 1 && iPos <= 8)
102  {
103  sal_IntPtr nVal = OutputDevice::LogicToLogic(
104  reinterpret_cast<sal_IntPtr>(m_xVSWidth->GetItemData(iPos)), MapUnit::MapPoint,
105  m_eMapUnit);
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);
111  }
112  else if (iPos == 9)
113  { //last custom
114  //modified
115  if (m_bCustom)
116  {
117  tools::Long 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);
123  }
124  else
125  {
126  m_xVSWidth->SetNoSelection(); //add , set no selection and keep the last select item
127  m_xVSWidth->SetFormat();
128  m_xVSWidth->Invalidate();
129  }
130  //modify end
131  }
132 
133  if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && m_bCustom)) //add
134  {
135  m_rParent.EndLineWidthPopup();
136  }
137 }
138 
140 {
141  if (m_xVSWidth->GetSelItem())
142  {
143  m_xVSWidth->SetSelItem(0);
144  m_xVSWidth->SetFormat();
145  m_xVSWidth->Invalidate();
146  }
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);
152 }
153 
154 void LineWidthPopup::SetWidthSelect(tools::Long lValue, bool bValuable, MapUnit eMapUnit)
155 {
156  m_bVSFocus = true;
157  m_xVSWidth->SetSelItem(0);
158  m_eMapUnit = eMapUnit;
159  SvtViewOptions aWinOpt(EViewType::Window, "PopupPanel_LineWidth");
160  if (aWinOpt.Exists())
161  {
162  css::uno::Sequence<css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
163  OUString aTmp;
164  if (aSeq.hasElements())
165  aSeq[0].Value >>= aTmp;
166 
167  OUString aWinData(aTmp);
168  m_nCustomWidth = aWinData.toInt32();
169  m_bCustom = true;
170  m_xVSWidth->SetImage(m_aIMGCus);
171  m_xVSWidth->SetCusEnable(true);
172 
173  OUString aStrTip = OUString::number(static_cast<double>(m_nCustomWidth) / 10) + m_sPt;
174  m_xVSWidth->SetItemText(9, aStrTip);
175  }
176  else
177  {
178  m_bCustom = false;
179  m_xVSWidth->SetImage(m_aIMGCusGray);
180  m_xVSWidth->SetCusEnable(false);
181  m_xVSWidth->SetItemText(9, maStrUnits[8]);
182  }
183 
184  if (bValuable)
185  {
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);
189  }
190  else
191  {
192  m_xMFWidth->set_text("");
193  }
194 
195  OUString strCurrValue = m_xMFWidth->get_text();
196  sal_uInt16 i = 0;
197  for (; i < 8; i++)
198  {
199  if (strCurrValue == maStrUnits[i])
200  {
201  m_xVSWidth->SetSelItem(i + 1);
202  break;
203  }
204  }
205 
206  if (i >= 8)
207  {
208  m_bVSFocus = false;
209  m_xVSWidth->SetSelItem(0);
210  }
211 
212  m_xVSWidth->SetFormat();
213  m_xVSWidth->Invalidate();
214 }
215 
217 {
218  if (m_bVSFocus)
219  m_xVSWidth->GrabFocus();
220  else
221  m_xMFWidth->grab_focus();
222 }
223 
224 } // end of namespace svx::sidebar
225 
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< css::beans::NamedValue > GetUserData() const
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
long Long
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMFWidth
void SetWidthSelect(tools::Long lValue, bool bValuable, MapUnit eMapUnit)
std::array< OUString, 9 > maStrUnits
Value
sal_uInt16 sal_Unicode
const OUString & getNumDecimalSep() const
OUString SvxResId(std::string_view aId)
Definition: dialmgr.cxx:25
int i
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
LineWidthPopup(weld::Widget *pParent, LinePropertyPanelBase &rParent)
WinBits const WB_3DLOOK
StockImage
#define WB_NO_DIRECTSELECT
bool Exists() const
Sequence< sal_Int8 > aSeq
MapUnit
XSLTFilter & m_rParent
std::unique_ptr< LineWidthValueSet > m_xVSWidth
std::unique_ptr< weld::Container > m_xTopLevel