LibreOffice Module svx (master)  1
itemwin.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 <com/sun/star/drawing/FillStyle.hpp>
21 #include <com/sun/star/frame/XDispatchProvider.hpp>
22 #include <com/sun/star/frame/XFrame.hpp>
23 
24 #include <sfx2/tbxctrl.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <sfx2/module.hxx>
27 
28 #include <vcl/event.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/settings.hxx>
31 
32 #include <svx/dialmgr.hxx>
33 #include <svx/strings.hrc>
34 
35 #include <svx/xlnwtit.hxx>
36 #include <svx/xtable.hxx>
37 #include <svx/itemwin.hxx>
38 #include <svtools/unitconv.hxx>
39 #include "linemetricbox.hxx"
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::frame;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
46 
48  vcl::Window* pParent, const Reference< XFrame >& rFrame )
49  : InterimItemWindow(pParent, "svx/ui/metricfieldbox.ui", "MetricFieldBox")
50  , m_xWidget(m_xBuilder->weld_metric_spin_button("metricfield", FieldUnit::MM))
51  , nCurValue(0)
52  , eDestPoolUnit(MapUnit::Map100thMM)
53  , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame))
54  , mxFrame(rFrame)
55 {
56  m_xWidget->set_range(0, 5000, FieldUnit::NONE);
57  m_xWidget->connect_value_changed(LINK(this, SvxMetricField, ModifyHdl));
58  m_xWidget->connect_focus_in(LINK(this, SvxMetricField, FocusInHdl));
59  m_xWidget->get_widget().connect_key_press(LINK(this, SvxMetricField, KeyInputHdl));
60 
62 
63  SetSizePixel(m_xWidget->get_preferred_size());
64 }
65 
67 {
68  m_xWidget.reset();
70 }
71 
73 {
74  disposeOnce();
75 }
76 
77 void SvxMetricField::set_sensitive(bool bSensitive)
78 {
79  Enable(bSensitive);
80  m_xWidget->set_sensitive(bSensitive);
81  if (!bSensitive)
82  m_xWidget->set_text("");
83 }
84 
86 {
87  if ( pItem )
88  {
89  // tdf#132169 we always get the value in MapUnit::Map100thMM but have
90  // to set it in the core metric of the target application
91  if (pItem->GetValue() != GetCoreValue(*m_xWidget, MapUnit::Map100thMM))
92  SetMetricValue(*m_xWidget, pItem->GetValue(), MapUnit::Map100thMM);
93  }
94  else
95  m_xWidget->set_text("");
96 }
97 
99 {
100  auto nTmp = GetCoreValue(*m_xWidget, eDestPoolUnit);
101  XLineWidthItem aLineWidthItem( nTmp );
102 
103  Any a;
104  Sequence< PropertyValue > aArgs( 1 );
105  aArgs[0].Name = "LineWidth";
106  aLineWidthItem.QueryValue( a );
107  aArgs[0].Value = a;
108  SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
109  ".uno:LineWidth",
110  aArgs );
111 }
112 
114 {
115  if( SfxViewShell::Current() )
116  {
117  vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
118  if ( pShellWnd )
119  pShellWnd->GrabFocus();
120  }
121 }
122 
124 {
125  eDestPoolUnit = eUnit;
126 }
127 
129 {
131  if ( eDlgUnit != eTmpUnit )
132  {
133  eDlgUnit = eTmpUnit;
135  }
136 }
137 
139 {
140  nCurValue = m_xWidget->get_value(FieldUnit::NONE);
141 }
142 
143 IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
144 {
145  bool bHandled = false;
146 
147  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
148 
149  if (nCode == KEY_ESCAPE)
150  {
151  m_xWidget->set_value(nCurValue, FieldUnit::NONE);
152  ModifyHdl(*m_xWidget);
153  ReleaseFocus_Impl();
154  bHandled = true;
155  }
156 
157  return bHandled || ChildKeyInput(rKEvt);
158 }
159 
161 {
162  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
163  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
164  {
165  SetSizePixel(m_xWidget->get_preferred_size());
166  }
167 
169 }
170 
172 {
173  if (m_xWidget)
174  m_xWidget->grab_focus();
176 }
177 
179 {
180  rListBox.freeze();
181 
182  rListBox.append_text(SvxResId(RID_SVXSTR_INVISIBLE));
183  rListBox.append_text(SvxResId(RID_SVXSTR_COLOR));
184  rListBox.append_text(SvxResId(RID_SVXSTR_GRADIENT));
185  rListBox.append_text(SvxResId(RID_SVXSTR_HATCH));
186  rListBox.append_text(SvxResId(RID_SVXSTR_BITMAP));
187  rListBox.append_text(SvxResId(RID_SVXSTR_PATTERN));
188 
189  rListBox.thaw();
190 
191  rListBox.set_active(1); // solid color
192 }
193 
194 namespace
195 {
196  void formatBitmapExToSize(BitmapEx& rBitmapEx, const Size& rSize)
197  {
198  if(!rBitmapEx.IsEmpty() && !rSize.IsEmpty())
199  {
201  pVirtualDevice->SetOutputSizePixel(rSize);
202 
203  if(rBitmapEx.IsTransparent())
204  {
205  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
206 
207  if(rStyleSettings.GetPreviewUsesCheckeredBackground())
208  {
209  const Point aNull(0, 0);
210  static const sal_uInt32 nLen(8);
211  static const Color aW(COL_WHITE);
212  static const Color aG(0xef, 0xef, 0xef);
213 
214  pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
215  }
216  else
217  {
218  pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
219  pVirtualDevice->Erase();
220  }
221  }
222 
223  if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
224  {
225  rBitmapEx.Scale(rSize);
226  pVirtualDevice->DrawBitmapEx(Point(0, 0), rBitmapEx);
227  }
228  else
229  {
230  const Size aBitmapSize(rBitmapEx.GetSizePixel());
231 
232  for(long y(0); y < rSize.Height(); y += aBitmapSize.Height())
233  {
234  for(long x(0); x < rSize.Width(); x += aBitmapSize.Width())
235  {
236  pVirtualDevice->DrawBitmapEx(
237  Point(x, y),
238  rBitmapEx);
239  }
240  }
241  }
242 
243  rBitmapEx = pVirtualDevice->GetBitmapEx(Point(0, 0), rSize);
244  }
245  }
246 } // end of anonymous namespace
247 
249 {
250  if( !pList.is() )
251  return;
252 
253  long nCount = pList->Count();
255  rBox.freeze();
256 
257  for( long i = 0; i < nCount; i++ )
258  {
259  const XHatchEntry* pEntry = pList->GetHatch(i);
260  const BitmapEx aBitmapEx = pList->GetUiBitmap( i );
261  if( !aBitmapEx.IsEmpty() )
262  {
263  const Size aBmpSize(aBitmapEx.GetSizePixel());
264  pVD->SetOutputSizePixel(aBmpSize, false);
265  pVD->DrawBitmapEx(Point(), aBitmapEx);
266  rBox.append("", pEntry->GetName(), *pVD);
267  }
268  else
269  rBox.append_text(pEntry->GetName());
270  }
271 
272  rBox.thaw();
273 }
274 
276 {
277  if( !pList.is() )
278  return;
279 
280  long nCount = pList->Count();
282  rBox.freeze();
283 
284  for( long i = 0; i < nCount; i++ )
285  {
286  const XGradientEntry* pEntry = pList->GetGradient(i);
287  const BitmapEx aBitmapEx = pList->GetUiBitmap( i );
288  if( !aBitmapEx.IsEmpty() )
289  {
290  const Size aBmpSize(aBitmapEx.GetSizePixel());
291  pVD->SetOutputSizePixel(aBmpSize, false);
292  pVD->DrawBitmapEx(Point(), aBitmapEx);
293  rBox.append("", pEntry->GetName(), *pVD);
294  }
295  else
296  rBox.append_text(pEntry->GetName());
297  }
298 
299  rBox.thaw();
300 }
301 
303 {
304  if( !pList.is() )
305  return;
306 
307  long nCount = pList->Count();
308  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
309  const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
311  pVD->SetOutputSizePixel(aSize, false);
312  rBox.freeze();
313 
314  for( long i = 0; i < nCount; i++ )
315  {
316  const XBitmapEntry* pEntry = pList->GetBitmap( i );
317  BitmapEx aBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
318  formatBitmapExToSize(aBitmapEx, aSize);
319  pVD->DrawBitmapEx(Point(), aBitmapEx);
320  rBox.append("", pEntry->GetName(), *pVD);
321  }
322 
323  rBox.thaw();
324 }
325 
327 {
328  if( !pList.is() )
329  return;
330 
331  long nCount = pList->Count();
332  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
333  const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
335  pVD->SetOutputSizePixel(aSize, false);
336  rBox.freeze();
337 
338  for( long i = 0; i < nCount; i++ )
339  {
340  const XBitmapEntry* pEntry = pList->GetBitmap( i );
341  BitmapEx aBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
342  formatBitmapExToSize(aBitmapEx, aSize);
343  pVD->DrawBitmapEx(Point(), aBitmapEx);
344  rBox.append("", pEntry->GetName(), *pVD);
345  }
346 
347  rBox.thaw();
348 
349 }
350 
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
MapUnit eDestPoolUnit
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
sal_Int32 GetValue() const
FieldUnit eDlgUnit
std::unique_ptr< weld::MetricSpinButton > m_xWidget
FieldUnit
SvxMetricField(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: itemwin.cxx:47
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: itemwin.cxx:160
virtual ~SvxMetricField() override
Definition: itemwin.cxx:72
long Height() const
SVX_DLLPUBLIC void Fill(weld::ComboBox &, const XHatchListRef &pList)
Definition: itemwin.cxx:248
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
virtual void GetFocus() override
Definition: itemwin.cxx:171
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
virtual void dispose() override
Definition: itemwin.cxx:66
virtual void SetSizePixel(const Size &rNewSize)
static void ReleaseFocus_Impl()
Definition: itemwin.cxx:113
bool GetPreviewUsesCheckeredBackground() const
DataChangedEventType GetType() const
void append(const OUString &rId, const OUString &rStr)
float x
const Size & GetListBoxPreviewDefaultPixelSize() const
void set_sensitive(bool bSensitive)
Definition: itemwin.cxx:77
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Definition: dlgutil.cxx:31
virtual void thaw()=0
void Enable(bool bEnable=true, bool bChild=true)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
int nCount
virtual void GetFocus() override
AllSettingsFlags GetFlags() const
static SfxViewShell * Current()
sal_uInt16 nCode
const GraphicObject & GetGraphicObject() const
Definition: xtable.hxx:125
css::uno::Reference< css::frame::XFrame > mxFrame
float y
const OUString & GetName() const
static FieldUnit GetModuleFieldUnit(css::uno::Reference< css::frame::XFrame > const &i_frame)
bool IsEmpty() const
SVX_DLLPUBLIC void Fill(weld::ComboBox &rListBox)
Definition: itemwin.cxx:178
bool IsEmpty() const
int i
uno_Any a
virtual void freeze()=0
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
const Color & GetFieldColor() const
void Update(const XLineWidthItem *pItem)
Definition: itemwin.cxx:85
void SetDestCoreUnit(MapUnit eUnit)
Definition: itemwin.cxx:123
virtual void set_active(int pos)=0
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
bool IsTransparent() const
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
void GrabFocus()
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: xattr.cxx:918
void RefreshDlgUnit()
Definition: itemwin.cxx:128
const Graphic & GetGraphic() const
constexpr sal_uInt16 KEY_ESCAPE
virtual void dispose() override
vcl::Window * GetWindow() const
IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: itemwin.cxx:143
IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton &, void)
Definition: itemwin.cxx:98
MapUnit
void append_text(const OUString &rStr)
const Size & GetSizePixel() const
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
virtual void DataChanged(const DataChangedEvent &rDCEvt)