LibreOffice Module svx (master)  1
LinePropertyPanelBase.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  */
19 
20 #include <memory>
22 #include <com/sun/star/drawing/LineStyle.hpp>
23 #include <sfx2/weldutils.hxx>
24 #include <svx/linectrl.hxx>
25 #include <svx/xlnwtit.hxx>
26 #include <svx/xlntrit.hxx>
27 #include <svx/xlncapit.hxx>
28 #include <svx/xlinjoit.hxx>
29 #include <bitmaps.hlst>
30 
31 using namespace css;
32 using namespace css::uno;
33 
34 const char SELECTWIDTH[] = "SelectWidth";
35 
36 namespace svx::sidebar {
37 
38 // trigger disabling the arrows if the none line style is selected
40 {
41 private:
43 
44 public:
46  : m_rPanel(rPanel)
47  {
48  }
49 
50  bool operator()(const OUString& rCommand, const css::uno::Any& rValue)
51  {
52  if (rCommand == ".uno:XLineStyle")
53  {
54  css::drawing::LineStyle eLineStyle(css::drawing::LineStyle_NONE);
55  rValue >>= eLineStyle;
56  m_rPanel.SetNoneLineStyle(eLineStyle == css::drawing::LineStyle_NONE);
57  }
58  return false;
59  }
60 };
61 
62 namespace
63 {
64  SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(const ToolbarUnoDispatcher& rToolBoxColor)
65  {
66  css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(".uno:XLineStyle");
67  SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get());
68  return pToolBoxLineStyleControl;
69  }
70 }
71 
72 
73 LinePropertyPanelBase::LinePropertyPanelBase(
74  vcl::Window* pParent,
75  const uno::Reference<css::frame::XFrame>& rxFrame)
76 : PanelLayout(pParent, "LinePropertyPanel", "svx/ui/sidebarline.ui", rxFrame),
77  mxTBColor(m_xBuilder->weld_toolbar("color")),
78  mxColorDispatch(new ToolbarUnoDispatcher(*mxTBColor, *m_xBuilder, rxFrame)),
79  mxLineStyleTB(m_xBuilder->weld_toolbar("linestyle")),
80  mxLineStyleDispatch(new ToolbarUnoDispatcher(*mxLineStyleTB, *m_xBuilder, rxFrame)),
81  mxFTWidth(m_xBuilder->weld_label("widthlabel")),
82  mxTBWidth(m_xBuilder->weld_toolbar("width")),
83  mxFTTransparency(m_xBuilder->weld_label("translabel")),
84  mxMFTransparent(m_xBuilder->weld_metric_spin_button("linetransparency", FieldUnit::PERCENT)),
85  mxFTEdgeStyle(m_xBuilder->weld_label("cornerlabel")),
86  mxLBEdgeStyle(m_xBuilder->weld_combo_box("edgestyle")),
87  mxFTCapStyle(m_xBuilder->weld_label("caplabel")),
88  mxLBCapStyle(m_xBuilder->weld_combo_box("linecapstyle")),
89  mxGridLineProps(m_xBuilder->weld_widget("lineproperties")),
90  mxBoxArrowProps(m_xBuilder->weld_widget("arrowproperties")),
91  mxLineWidthPopup(new LineWidthPopup(mxTBWidth.get(), *this)),
92  mxDisableArrowsWrapper(new DisableArrowsWrapper(*this)),
93  mnTrans(0),
94  meMapUnit(MapUnit::MapMM),
95  mnWidthCoreValue(0),
96  maIMGNone(BMP_NONE_ICON),
97  mbWidthValuable(true),
98  mbArrowSupported(true),
99  mbNoneLineStyle(false)
100 {
101  Initialize();
102 }
103 
105 {
106  disposeOnce();
107 }
108 
110 {
111  mxLineWidthPopup.reset();
112  mxFTWidth.reset();
113  mxTBWidth.reset();
114  mxColorDispatch.reset();
115  mxTBColor.reset();
116  mxFTTransparency.reset();
117  mxMFTransparent.reset();
118  mxLineStyleDispatch.reset();
119  mxLineStyleTB.reset();
120  mxFTEdgeStyle.reset();
121  mxLBEdgeStyle.reset();
122  mxFTCapStyle.reset();
123  mxLBCapStyle.reset();
124  mxGridLineProps.reset();
125  mxBoxArrowProps.reset();
126 
128 }
129 
131 {
132  mxTBWidth->set_item_popover(SELECTWIDTH, mxLineWidthPopup->getTopLevel());
133 
134  maIMGWidthIcon[0] = BMP_WIDTH1_ICON;
135  maIMGWidthIcon[1] = BMP_WIDTH2_ICON;
136  maIMGWidthIcon[2] = BMP_WIDTH3_ICON;
137  maIMGWidthIcon[3] = BMP_WIDTH4_ICON;
138  maIMGWidthIcon[4] = BMP_WIDTH5_ICON;
139  maIMGWidthIcon[5] = BMP_WIDTH6_ICON;
140  maIMGWidthIcon[6] = BMP_WIDTH7_ICON;
141  maIMGWidthIcon[7] = BMP_WIDTH8_ICON;
142 
143  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[0]);
144  mxTBWidth->connect_clicked(LINK(this, LinePropertyPanelBase, ToolboxWidthSelectHdl));
145 
146  mxMFTransparent->connect_value_changed(LINK(this, LinePropertyPanelBase, ChangeTransparentHdl));
147 
148  mxLBEdgeStyle->connect_changed( LINK( this, LinePropertyPanelBase, ChangeEdgeStyleHdl ) );
149 
150  mxLBCapStyle->connect_changed( LINK( this, LinePropertyPanelBase, ChangeCapStyleHdl ) );
151 
152  SvxLineStyleToolBoxControl* pLineStyleControl = getLineStyleToolBoxControl(*mxLineStyleDispatch);
154 }
155 
156 void LinePropertyPanelBase::updateLineTransparence(bool bDisabled, bool bSetOrDefault,
157  const SfxPoolItem* pState)
158 {
159  if(bDisabled)
160  {
161  mxFTTransparency->set_sensitive(false);
162  mxMFTransparent->set_sensitive(false);
163  }
164  else
165  {
166  mxFTTransparency->set_sensitive(true);
167  mxMFTransparent->set_sensitive(true);
168  }
169 
170  if(bSetOrDefault)
171  {
172  if (const XLineTransparenceItem* pItem = dynamic_cast<const XLineTransparenceItem*>(pState))
173  {
174  mnTrans = pItem->GetValue();
175  mxMFTransparent->set_value(mnTrans, FieldUnit::PERCENT);
176  return;
177  }
178  }
179 
180  mxMFTransparent->set_value(0, FieldUnit::PERCENT);//add
181  mxMFTransparent->set_text(OUString());
182 }
183 
184 void LinePropertyPanelBase::updateLineWidth(bool bDisabled, bool bSetOrDefault,
185  const SfxPoolItem* pState)
186 {
187  if(bDisabled)
188  {
189  mxTBWidth->set_sensitive(false);
190  mxFTWidth->set_sensitive(false);
191  }
192  else
193  {
194  mxTBWidth->set_sensitive(true);
195  mxFTWidth->set_sensitive(true);
196  }
197 
198  if(bSetOrDefault)
199  {
200  if (const XLineWidthItem* pItem = dynamic_cast<const XLineWidthItem*>(pState))
201  {
202  mnWidthCoreValue = pItem->GetValue();
203  mbWidthValuable = true;
204  SetWidthIcon();
205  return;
206  }
207  }
208 
209  mbWidthValuable = false;
210  SetWidthIcon();
211 }
212 
213 void LinePropertyPanelBase::updateLineJoint(bool bDisabled, bool bSetOrDefault,
214  const SfxPoolItem* pState)
215 {
216  if(bDisabled)
217  {
218  mxLBEdgeStyle->set_sensitive(false);
219  mxFTEdgeStyle->set_sensitive(false);
220  }
221  else
222  {
223  mxLBEdgeStyle->set_sensitive(true);
224  mxFTEdgeStyle->set_sensitive(true);
225  }
226 
227  if(bSetOrDefault)
228  {
229  if (const XLineJointItem* pItem = dynamic_cast<const XLineJointItem*>(pState))
230  {
231  sal_Int32 nEntryPos(0);
232 
233  switch(pItem->GetValue())
234  {
235  case drawing::LineJoint_ROUND:
236  {
237  nEntryPos = 1;
238  break;
239  }
240  case drawing::LineJoint_NONE:
241  {
242  nEntryPos = 2;
243  break;
244  }
245  case drawing::LineJoint_MIDDLE:
246  case drawing::LineJoint_MITER:
247  {
248  nEntryPos = 3;
249  break;
250  }
251  case drawing::LineJoint_BEVEL:
252  {
253  nEntryPos = 4;
254  break;
255  }
256 
257  default:
258  break;
259  }
260 
261  if(nEntryPos)
262  {
263  mxLBEdgeStyle->set_active(nEntryPos - 1);
264  return;
265  }
266  }
267  }
268 
269  mxLBEdgeStyle->set_active(-1);
270 }
271 
272 void LinePropertyPanelBase::updateLineCap(bool bDisabled, bool bSetOrDefault,
273  const SfxPoolItem* pState)
274 {
275  if(bDisabled)
276  {
277  mxLBCapStyle->set_sensitive(false);
278  mxFTCapStyle->set_sensitive(false);
279  }
280  else
281  {
282  mxLBCapStyle->set_sensitive(true);
283  mxLBCapStyle->set_sensitive(true);
284  }
285 
286  if(bSetOrDefault)
287  {
288  if (const XLineCapItem* pItem = dynamic_cast<const XLineCapItem*>(pState))
289  {
290  sal_Int32 nEntryPos(0);
291 
292  switch(pItem->GetValue())
293  {
294  case drawing::LineCap_BUTT:
295  {
296  nEntryPos = 1;
297  break;
298  }
299  case drawing::LineCap_ROUND:
300  {
301  nEntryPos = 2;
302  break;
303  }
304  case drawing::LineCap_SQUARE:
305  {
306  nEntryPos = 3;
307  break;
308  }
309 
310  default:
311  break;
312  }
313 
314  if(nEntryPos)
315  {
316  mxLBCapStyle->set_active(nEntryPos - 1);
317  return;
318  }
319  }
320  }
321 
322  mxLBCapStyle->set_active(-1);
323 }
324 
326 {
327  const sal_Int32 nPos(mxLBEdgeStyle->get_active());
328 
329  if (nPos == -1 || !mxLBEdgeStyle->get_value_changed_from_saved())
330  return;
331 
332  std::unique_ptr<XLineJointItem> pItem;
333 
334  switch(nPos)
335  {
336  case 0: // rounded
337  {
338  pItem.reset(new XLineJointItem(drawing::LineJoint_ROUND));
339  break;
340  }
341  case 1: // none
342  {
343  pItem.reset(new XLineJointItem(drawing::LineJoint_NONE));
344  break;
345  }
346  case 2: // mitered
347  {
348  pItem.reset(new XLineJointItem(drawing::LineJoint_MITER));
349  break;
350  }
351  case 3: // beveled
352  {
353  pItem.reset(new XLineJointItem(drawing::LineJoint_BEVEL));
354  break;
355  }
356  }
357 
358  setLineJoint(pItem.get());
359 }
360 
362 {
363  const sal_Int32 nPos(mxLBCapStyle->get_active());
364 
365  if (!(nPos != -1 && mxLBCapStyle->get_value_changed_from_saved()))
366  return;
367 
368  std::unique_ptr<XLineCapItem> pItem;
369 
370  switch(nPos)
371  {
372  case 0: // flat
373  {
374  pItem.reset(new XLineCapItem(drawing::LineCap_BUTT));
375  break;
376  }
377  case 1: // round
378  {
379  pItem.reset(new XLineCapItem(drawing::LineCap_ROUND));
380  break;
381  }
382  case 2: // square
383  {
384  pItem.reset(new XLineCapItem(drawing::LineCap_SQUARE));
385  break;
386  }
387  }
388 
389  setLineCap(pItem.get());
390 }
391 
392 IMPL_LINK_NOARG(LinePropertyPanelBase, ToolboxWidthSelectHdl, const OString&, void)
393 {
394  mxTBWidth->set_menu_item_active(SELECTWIDTH, !mxTBWidth->get_menu_item_active(SELECTWIDTH));
395 }
396 
398 {
399  mxTBWidth->set_menu_item_active(SELECTWIDTH, false);
400 }
401 
403 {
404  sal_uInt16 nVal = static_cast<sal_uInt16>(mxMFTransparent->get_value(FieldUnit::PERCENT));
405  XLineTransparenceItem aItem( nVal );
406 
407  setLineTransparency(aItem);
408 }
409 
411 {
412  if (n == 0)
413  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGNone);
414  else
415  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[n-1]);
416 }
417 
419 {
420  if(!mbWidthValuable)
421  {
422  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGNone);
423  return;
424  }
425 
426  long nVal = LogicToLogic(mnWidthCoreValue * 10, meMapUnit, MapUnit::MapPoint);
427 
428  if(nVal <= 6)
429  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[0]);
430  else if (nVal <= 9)
431  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[1]);
432  else if (nVal <= 12)
433  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[2]);
434  else if (nVal <= 19)
435  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[3]);
436  else if (nVal <= 26)
437  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[4]);
438  else if (nVal <= 37)
439  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[5]);
440  else if (nVal <= 52)
441  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[6]);
442  else
443  mxTBWidth->set_item_icon_name(SELECTWIDTH, maIMGWidthIcon[7]);
444 
445 }
446 
448 {
449  mnWidthCoreValue = nWidth;
450  mbWidthValuable = true;
452 }
453 
455 {
456  mxGridLineProps->set_sensitive(!mbNoneLineStyle);
457  mxBoxArrowProps->set_sensitive(!mbNoneLineStyle);
458  mxLineStyleTB->set_item_visible(".uno:LineEndStyle", mbArrowSupported);
459  mxLineStyleTB->set_item_sensitive(".uno:LineEndStyle", !mbNoneLineStyle);
460 }
461 
463 {
464  meMapUnit = eMapUnit;
466 }
467 
469 {
470  mbArrowSupported = false;
472 }
473 
475 {
476  mbArrowSupported = true;
478 }
479 
480 } // end of namespace svx::sidebar
481 
482 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::unique_ptr< weld::Label > mxFTTransparency
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
void updateLineWidth(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
std::unique_ptr< weld::ComboBox > mxLBCapStyle
std::unique_ptr< weld::Toolbar > mxTBColor
constexpr OUStringLiteral PERCENT(u"Percent")
std::unique_ptr< weld::Widget > mxGridLineProps
std::unique_ptr< ToolbarUnoDispatcher > mxColorDispatch
std::unique_ptr< weld::Label > mxFTEdgeStyle
std::unique_ptr< weld::Label > mxFTCapStyle
Reference< XController > xController
std::unique_ptr< ToolbarUnoDispatcher > mxLineStyleDispatch
void SetNoneLineStyle(bool bNoneLineStyle)
std::unique_ptr< weld::Widget > mxBoxArrowProps
void updateLineTransparence(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
std::unique_ptr< weld::Toolbar > mxLineStyleTB
void setLineStyleSelectFunction(const LineStyleSelectFunction &aLineStyleSelectFunction)
Definition: linectrl.cxx:171
const char SELECTWIDTH[]
css::uno::Reference< css::frame::XToolbarController > GetControllerForCommand(const OUString &rCommand) const
virtual void dispose() override
void updateLineCap(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
void updateLineJoint(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
std::unique_ptr< weld::ComboBox > mxLBEdgeStyle
std::unique_ptr< DisableArrowsWrapper > mxDisableArrowsWrapper
bool operator()(const OUString &rCommand, const css::uno::Any &rValue)
MapUnit
std::unique_ptr< weld::Toolbar > mxTBWidth
std::unique_ptr< LineWidthPopup > mxLineWidthPopup
std::unique_ptr< weld::Label > mxFTWidth
std::unique_ptr< weld::MetricSpinButton > mxMFTransparent
sal_uInt16 nPos
DisableArrowsWrapper(LinePropertyPanelBase &rPanel)