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