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
25#include <sfx2/tbxctrl.hxx>
26#include <sfx2/viewsh.hxx>
27#include <sfx2/module.hxx>
28
29#include <vcl/event.hxx>
30#include <vcl/svapp.hxx>
31#include <vcl/settings.hxx>
32#include <vcl/virdev.hxx>
33
34#include <svx/dialmgr.hxx>
35#include <svx/strings.hrc>
36
37#include <svx/xlnwtit.hxx>
38#include <svx/xtable.hxx>
39#include <svx/itemwin.hxx>
40#include <svtools/unitconv.hxx>
41#include "linemetricbox.hxx"
42
43using namespace ::com::sun::star;
44using namespace ::com::sun::star::uno;
45using namespace ::com::sun::star::frame;
46using namespace ::com::sun::star::lang;
47using namespace ::com::sun::star::beans;
48
50 vcl::Window* pParent, const Reference< XFrame >& rFrame )
51 : InterimItemWindow(pParent, "svx/ui/metricfieldbox.ui", "MetricFieldBox")
52 , m_xWidget(m_xBuilder->weld_metric_spin_button("metricfield", FieldUnit::MM))
53 , nCurValue(0)
54 , eDestPoolUnit(MapUnit::Map100thMM)
55 , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame))
56 , mxFrame(rFrame)
57{
58 InitControlBase(&m_xWidget->get_widget());
59
60 m_xWidget->set_range(0, 5000, FieldUnit::NONE);
61 m_xWidget->connect_value_changed(LINK(this, SvxMetricField, ModifyHdl));
62 m_xWidget->connect_focus_in(LINK(this, SvxMetricField, FocusInHdl));
63 m_xWidget->get_widget().connect_key_press(LINK(this, SvxMetricField, KeyInputHdl));
64
66
67 SetSizePixel(m_xWidget->get_preferred_size());
68}
69
71{
72 m_xWidget.reset();
74}
75
77{
79}
80
81void SvxMetricField::set_sensitive(bool bSensitive)
82{
83 Enable(bSensitive);
84 m_xWidget->set_sensitive(bSensitive);
85 if (!bSensitive)
86 m_xWidget->set_text("");
87}
88
90{
91 if ( pItem )
92 {
93 // tdf#132169 we always get the value in MapUnit::Map100thMM but have
94 // to set it in the core metric of the target application
95 if (pItem->GetValue() != GetCoreValue(*m_xWidget, MapUnit::Map100thMM))
96 SetMetricValue(*m_xWidget, pItem->GetValue(), MapUnit::Map100thMM);
97 }
98 else
99 m_xWidget->set_text("");
100}
101
103{
104 auto nTmp = GetCoreValue(*m_xWidget, eDestPoolUnit);
105 XLineWidthItem aLineWidthItem( nTmp );
106
107 Any a;
108 aLineWidthItem.QueryValue( a );
109 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("LineWidth", a) };
110 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
111 ".uno:LineWidth",
112 aArgs );
113}
114
116{
118 {
120 if ( pShellWnd )
121 pShellWnd->GrabFocus();
122 }
123}
124
126{
127 eDestPoolUnit = eUnit;
128}
129
131{
133 if ( eDlgUnit != eTmpUnit )
134 {
135 eDlgUnit = eTmpUnit;
137 }
138}
139
141{
142 nCurValue = m_xWidget->get_value(FieldUnit::NONE);
143}
144
145IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
146{
147 bool bHandled = false;
148
149 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
150
151 if (nCode == KEY_ESCAPE)
152 {
153 m_xWidget->set_value(nCurValue, FieldUnit::NONE);
154 ModifyHdl(*m_xWidget);
155 ReleaseFocus_Impl();
156 bHandled = true;
157 }
158
159 return bHandled || ChildKeyInput(rKEvt);
160}
161
163{
164 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
165 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
166 {
167 SetSizePixel(m_xWidget->get_preferred_size());
168 }
169
171}
172
174{
175 rListBox.freeze();
176
177 rListBox.append_text(SvxResId(RID_SVXSTR_INVISIBLE));
178 rListBox.append_text(SvxResId(RID_SVXSTR_COLOR));
179 rListBox.append_text(SvxResId(RID_SVXSTR_GRADIENT));
180 rListBox.append_text(SvxResId(RID_SVXSTR_HATCH));
181 rListBox.append_text(SvxResId(RID_SVXSTR_BITMAP));
182 rListBox.append_text(SvxResId(RID_SVXSTR_PATTERN));
183 rListBox.append_text(SvxResId(RID_SVXSTR_USE_BACKGROUND));
184
185 rListBox.thaw();
186
187 rListBox.set_active(1); // solid color
188}
189
190namespace
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.IsAlpha())
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(tools::Long y(0); y < rSize.Height(); y += aBitmapSize.Height())
230 {
231 for(tools::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 tools::Long nCount = pList->Count();
251 rBox.freeze();
252
253 for( tools::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 tools::Long nCount = pList->Count();
278 rBox.freeze();
279
280 for( tools::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 tools::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( tools::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 tools::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( tools::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: */
std::unique_ptr< weld::Image > m_xWidget
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
bool IsAlpha() const
bool IsEmpty() const
const Size & GetSizePixel() const
sal_Int32 GetValue() const
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
const Graphic & GetGraphic() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
virtual void dispose() override
void InitControlBase(weld::Widget *pWidget)
static FieldUnit GetModuleFieldUnit(css::uno::Reference< css::frame::XFrame > const &i_frame)
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
vcl::Window * GetWindow() const
bool IsEmpty() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool GetPreviewUsesCheckeredBackground() const
const Color & GetFieldColor() const
const Size & GetListBoxPreviewDefaultPixelSize() const
std::unique_ptr< weld::MetricSpinButton > m_xWidget
virtual ~SvxMetricField() override
Definition: itemwin.cxx:76
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: itemwin.cxx:162
static void ReleaseFocus_Impl()
Definition: itemwin.cxx:115
void SetDestCoreUnit(MapUnit eUnit)
Definition: itemwin.cxx:125
void set_sensitive(bool bSensitive)
Definition: itemwin.cxx:81
FieldUnit eDlgUnit
css::uno::Reference< css::frame::XFrame > mxFrame
MapUnit eDestPoolUnit
void Update(const XLineWidthItem *pItem)
Definition: itemwin.cxx:89
SvxMetricField(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: itemwin.cxx:49
void RefreshDlgUnit()
Definition: itemwin.cxx:130
virtual void dispose() override
Definition: itemwin.cxx:70
const GraphicObject & GetGraphicObject() const
Definition: xtable.hxx:125
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: xattr.cxx:997
const OUString & GetName() const
virtual void SetSizePixel(const Size &rNewSize)
void GrabFocus()
void Enable(bool bEnable=true, bool bChild=true)
virtual void DataChanged(const DataChangedEvent &rDCEvt)
void append(const weld::ComboBoxEntry &rItem)
virtual void set_active(int pos)=0
void append_text(const OUString &rStr)
virtual void freeze()=0
virtual void thaw()=0
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Definition: dlgutil.cxx:31
float y
float x
FieldUnit
IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: itemwin.cxx:145
IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton &, void)
Definition: itemwin.cxx:102
uno_Any a
constexpr sal_uInt16 KEY_ESCAPE
MapUnit
SVX_DLLPUBLIC void Fill(weld::ComboBox &, const XHatchListRef &pList)
Definition: itemwin.cxx:244
SVX_DLLPUBLIC void Fill(weld::ComboBox &rListBox)
Definition: itemwin.cxx:173
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
long Long
SVT_DLLPUBLIC sal_Int64 GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
SVT_DLLPUBLIC void SetMetricValue(weld::MetricSpinButton &rField, sal_Int64 nCoreValue, MapUnit eUnit)
SVT_DLLPUBLIC void SetFieldUnit(weld::MetricSpinButton &rCtrl, FieldUnit eUnit, bool bAll=false)