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 
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::frame;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::beans;
45 
47  vcl::Window* pParent, const Reference< XFrame >& rFrame )
48  : InterimItemWindow(pParent, "svx/ui/metricfieldbox.ui", "MetricFieldBox")
49  , m_xWidget(m_xBuilder->weld_metric_spin_button("metricfield", FieldUnit::MM))
50  , nCurValue(0)
51  , ePoolUnit(MapUnit::MapCM)
52  , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame))
53  , mxFrame(rFrame)
54 {
55  m_xWidget->set_range(0, 5000, FieldUnit::NONE);
56  m_xWidget->connect_value_changed(LINK(this, SvxMetricField, ModifyHdl));
57  m_xWidget->connect_focus_in(LINK(this, SvxMetricField, FocusInHdl));
58  m_xWidget->get_widget().connect_key_press(LINK(this, SvxMetricField, KeyInputHdl));
59 
61 
62  SetSizePixel(m_xWidget->get_preferred_size());
63 }
64 
66 {
67  m_xWidget.reset();
69 }
70 
72 {
73  disposeOnce();
74 }
75 
76 void SvxMetricField::set_sensitive(bool bSensitive)
77 {
78  Enable(bSensitive);
79  m_xWidget->set_sensitive(bSensitive);
80  if (!bSensitive)
81  m_xWidget->set_text("");
82 }
83 
85 {
86  if ( pItem )
87  {
88  if (pItem->GetValue() != GetCoreValue(*m_xWidget, ePoolUnit))
90  }
91  else
92  m_xWidget->set_text("");
93 }
94 
96 {
97  auto nTmp = GetCoreValue(*m_xWidget, ePoolUnit);
98  XLineWidthItem aLineWidthItem( nTmp );
99 
100  Any a;
101  Sequence< PropertyValue > aArgs( 1 );
102  aArgs[0].Name = "LineWidth";
103  aLineWidthItem.QueryValue( a );
104  aArgs[0].Value = a;
105  SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
106  ".uno:LineWidth",
107  aArgs );
108 }
109 
111 {
112  if( SfxViewShell::Current() )
113  {
114  vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
115  if ( pShellWnd )
116  pShellWnd->GrabFocus();
117  }
118 }
119 
121 {
122  ePoolUnit = eUnit;
123 }
124 
126 {
128  if ( eDlgUnit != eTmpUnit )
129  {
130  eDlgUnit = eTmpUnit;
132  }
133 }
134 
136 {
137  nCurValue = m_xWidget->get_value(FieldUnit::NONE);
138 }
139 
140 IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
141 {
142  bool bHandled = false;
143 
144  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
145 
146  if (nCode == KEY_ESCAPE)
147  {
148  m_xWidget->set_value(nCurValue, FieldUnit::NONE);
149  ModifyHdl(*m_xWidget);
150  ReleaseFocus_Impl();
151  bHandled = true;
152  }
153 
154  return bHandled || ChildKeyInput(rKEvt);
155 }
156 
158 {
159  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
160  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
161  {
162  SetSizePixel(m_xWidget->get_preferred_size());
163  }
164 
165  InterimItemWindow::DataChanged( rDCEvt );
166 }
167 
169 {
170  if (m_xWidget)
171  m_xWidget->grab_focus();
173 }
174 
176 {
177  rListBox.freeze();
178 
179  rListBox.append_text(SvxResId(RID_SVXSTR_INVISIBLE));
180  rListBox.append_text(SvxResId(RID_SVXSTR_COLOR));
181  rListBox.append_text(SvxResId(RID_SVXSTR_GRADIENT));
182  rListBox.append_text(SvxResId(RID_SVXSTR_HATCH));
183  rListBox.append_text(SvxResId(RID_SVXSTR_BITMAP));
184  rListBox.append_text(SvxResId(RID_SVXSTR_PATTERN));
185 
186  rListBox.thaw();
187 
188  rListBox.set_active(1); // solid color
189 }
190 
191 namespace
192 {
193  void formatBitmapExToSize(BitmapEx& rBitmapEx, const Size& rSize)
194  {
195  if(!rBitmapEx.IsEmpty() && rSize.Width() > 0 && rSize.Height() > 0)
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  }
243 } // end of anonymous namespace
244 
246 {
247  if( !pList.is() )
248  return;
249 
250  long nCount = pList->Count();
252  rBox.freeze();
253 
254  for( long i = 0; i < nCount; i++ )
255  {
256  const XHatchEntry* pEntry = pList->GetHatch(i);
257  const BitmapEx aBitmapEx = pList->GetUiBitmap( i );
258  if( !aBitmapEx.IsEmpty() )
259  {
260  const Size aBmpSize(aBitmapEx.GetSizePixel());
261  pVD->SetOutputSizePixel(aBmpSize, false);
262  pVD->DrawBitmapEx(Point(), aBitmapEx);
263  rBox.append("", pEntry->GetName(), *pVD);
264  }
265  else
266  rBox.append_text(pEntry->GetName());
267  }
268 
269  rBox.thaw();
270 }
271 
273 {
274  if( !pList.is() )
275  return;
276 
277  long nCount = pList->Count();
279  rBox.freeze();
280 
281  for( long i = 0; i < nCount; i++ )
282  {
283  const XGradientEntry* pEntry = pList->GetGradient(i);
284  const BitmapEx aBitmapEx = pList->GetUiBitmap( i );
285  if( !aBitmapEx.IsEmpty() )
286  {
287  const Size aBmpSize(aBitmapEx.GetSizePixel());
288  pVD->SetOutputSizePixel(aBmpSize, false);
289  pVD->DrawBitmapEx(Point(), aBitmapEx);
290  rBox.append("", pEntry->GetName(), *pVD);
291  }
292  else
293  rBox.append_text(pEntry->GetName());
294  }
295 
296  rBox.thaw();
297 }
298 
300 {
301  if( !pList.is() )
302  return;
303 
304  long nCount = pList->Count();
305  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
306  const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
308  pVD->SetOutputSizePixel(aSize, false);
309  rBox.freeze();
310 
311  for( long i = 0; i < nCount; i++ )
312  {
313  const XBitmapEntry* pEntry = pList->GetBitmap( i );
314  BitmapEx aBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
315  formatBitmapExToSize(aBitmapEx, aSize);
316  pVD->DrawBitmapEx(Point(), aBitmapEx);
317  rBox.append("", pEntry->GetName(), *pVD);
318  }
319 
320  rBox.thaw();
321 }
322 
324 {
325  if( !pList.is() )
326  return;
327 
328  long nCount = pList->Count();
329  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
330  const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
332  pVD->SetOutputSizePixel(aSize, false);
333  rBox.freeze();
334 
335  for( long i = 0; i < nCount; i++ )
336  {
337  const XBitmapEntry* pEntry = pList->GetBitmap( i );
338  BitmapEx aBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
339  formatBitmapExToSize(aBitmapEx, aSize);
340  pVD->DrawBitmapEx(Point(), aBitmapEx);
341  rBox.append("", pEntry->GetName(), *pVD);
342  }
343 
344  rBox.thaw();
345 
346 }
347 
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
sal_Int32 GetValue() const
FieldUnit eDlgUnit
Definition: itemwin.hxx:56
std::unique_ptr< weld::MetricSpinButton > m_xWidget
Definition: itemwin.hxx:53
FieldUnit
SvxMetricField(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: itemwin.cxx:46
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: itemwin.cxx:157
virtual ~SvxMetricField() override
Definition: itemwin.cxx:71
long Height() const
SVX_DLLPUBLIC void Fill(weld::ComboBox &, const XHatchListRef &pList)
Definition: itemwin.cxx:245
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
virtual void GetFocus() override
Definition: itemwin.cxx:168
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
virtual void dispose() override
Definition: itemwin.cxx:65
static void ReleaseFocus_Impl()
Definition: itemwin.cxx:110
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:76
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Definition: dlgutil.cxx:31
virtual void thaw()=0
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
Definition: itemwin.hxx:57
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:175
int i
uno_Any a
MapUnit ePoolUnit
Definition: itemwin.hxx:55
virtual void freeze()=0
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
const Color & GetFieldColor() const
void Update(const XLineWidthItem *pItem)
Definition: itemwin.cxx:84
virtual void set_active(int pos)=0
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
bool IsTransparent() const
void SetCoreUnit(MapUnit eUnit)
Definition: itemwin.cxx:120
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:125
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:140
IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton &, void)
Definition: itemwin.cxx:95
MapUnit
void append_text(const OUString &rStr)
const Size & GetSizePixel() const
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)