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 {
98 }
99 
101 {
102  sal_uInt16 iPos = m_xVSWidth->GetSelectedItemId();
103  if (iPos >= 1 && iPos <= 8)
104  {
105  sal_IntPtr nVal = OutputDevice::LogicToLogic(reinterpret_cast<sal_IntPtr>(m_xVSWidth->GetItemData( iPos )), MapUnit::MapPoint, 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  long nVal = OutputDevice::LogicToLogic(m_nCustomWidth , MapUnit::MapPoint, m_eMapUnit);
118  nVal = m_xMFWidth->denormalize(nVal);
119  XLineWidthItem aWidthItem( nVal );
120  m_rParent.setLineWidth(aWidthItem);
121  m_rParent.SetWidth(nVal);
122  }
123  else
124  {
125  m_xVSWidth->SetNoSelection(); //add , set no selection and keep the last select item
126  m_xVSWidth->SetFormat();
127  m_xVSWidth->Invalidate();
128  }
129  //modify end
130  }
131 
132  if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && m_bCustom)) //add
133  {
134  m_rParent.EndLineWidthPopup();
135  }
136 }
137 
139 {
140  if (m_xVSWidth->GetSelItem())
141  {
142  m_xVSWidth->SetSelItem(0);
143  m_xVSWidth->SetFormat();
144  m_xVSWidth->Invalidate();
145  }
146  long nTmp = static_cast<long>(m_xMFWidth->get_value(FieldUnit::NONE));
147  long nVal = OutputDevice::LogicToLogic( nTmp, MapUnit::MapPoint, m_eMapUnit );
148  sal_Int32 nNewWidth = static_cast<short>(m_xMFWidth->denormalize( nVal ));
149  XLineWidthItem aWidthItem(nNewWidth);
150  m_rParent.setLineWidth(aWidthItem);
151 }
152 
153 void LineWidthPopup::SetWidthSelect(long lValue, bool bValuable, MapUnit eMapUnit)
154 {
155  m_bVSFocus = true;
156  m_xVSWidth->SetSelItem(0);
157  m_eMapUnit = eMapUnit;
158  SvtViewOptions aWinOpt( EViewType::Window, "PopupPanel_LineWidth" );
159  if (aWinOpt.Exists())
160  {
161  css::uno::Sequence <css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
162  OUString aTmp;
163  if ( aSeq.hasElements())
164  aSeq[0].Value >>= aTmp;
165 
166  OUString aWinData( aTmp );
167  m_nCustomWidth = aWinData.toInt32();
168  m_bCustom = true;
169  m_xVSWidth->SetImage(m_aIMGCus);
170  m_xVSWidth->SetCusEnable(true);
171 
172  OUString aStrTip = OUString::number( static_cast<double>(m_nCustomWidth) / 10) +
173  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
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMFWidth
Value
sal_uInt16 sal_Unicode
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
std::array< OUString, 9 > maStrUnits
void SetWidthSelect(long lValue, bool bValuable, MapUnit eMapUnit)
::cppu::OWeakObject & m_rParent
const OUString & getNumDecimalSep() const
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
std::unique_ptr< LineWidthValueSet > m_xVSWidth
std::unique_ptr< weld::Container > m_xTopLevel