1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/drawing/FillStyle.hpp>
21 #include <com/sun/star/frame/XDispatchProvider.hpp>
22 #include <com/sun/star/frame/XFrame.hpp>
24 #include <comphelper/propertyvalue.hxx>
25 #include <sfx2/tbxctrl.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <sfx2/module.hxx>
29 #include <vcl/event.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/virdev.hxx>
34 #include <svx/dialmgr.hxx>
35 #include <svx/strings.hrc>
37 #include <svx/xlnwtit.hxx>
38 #include <svx/xtable.hxx>
39 #include <svx/itemwin.hxx>
40 #include <svtools/unitconv.hxx>
41 #include "linemetricbox.hxx"
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::frame
;
46 using namespace ::com::sun::star::beans
;
48 SvxMetricField::SvxMetricField(
49 vcl::Window
* pParent
, const Reference
< XFrame
>& rFrame
)
50 : InterimItemWindow(pParent
, u
"svx/ui/metricfieldbox.ui"_ustr
, u
"MetricFieldBox"_ustr
)
51 , m_xWidget(m_xBuilder
->weld_metric_spin_button(u
"metricfield"_ustr
, FieldUnit::MM
))
53 , eDestPoolUnit(MapUnit::Map100thMM
)
54 , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame
))
57 InitControlBase(&m_xWidget
->get_widget());
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
));
64 SetFieldUnit(*m_xWidget
, eDlgUnit
);
66 SetSizePixel(m_xWidget
->get_preferred_size());
69 void SvxMetricField::dispose()
72 InterimItemWindow::dispose();
75 SvxMetricField::~SvxMetricField()
80 void SvxMetricField::set_sensitive(bool bSensitive
)
83 m_xWidget
->set_sensitive(bSensitive
);
85 m_xWidget
->set_text(u
""_ustr
);
88 void SvxMetricField::Update( const XLineWidthItem
* pItem
)
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
);
98 m_xWidget
->set_text(u
""_ustr
);
101 IMPL_LINK_NOARG(SvxMetricField
, ModifyHdl
, weld::MetricSpinButton
&, void)
103 auto nTmp
= GetCoreValue(*m_xWidget
, eDestPoolUnit
);
104 XLineWidthItem
aLineWidthItem( nTmp
);
107 aLineWidthItem
.QueryValue( a
);
108 Sequence
< PropertyValue
> aArgs
{ comphelper::makePropertyValue(u
"LineWidth"_ustr
, a
) };
109 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
110 u
".uno:LineWidth"_ustr
,
114 void SvxMetricField::ReleaseFocus_Impl()
116 if (const SfxViewShell
* pViewShell
= SfxViewShell::Current())
118 vcl::Window
* pShellWnd
= pViewShell
->GetWindow();
120 pShellWnd
->GrabFocus();
124 void SvxMetricField::SetDestCoreUnit( MapUnit eUnit
)
126 eDestPoolUnit
= eUnit
;
129 void SvxMetricField::RefreshDlgUnit()
131 FieldUnit eTmpUnit
= SfxModule::GetModuleFieldUnit( mxFrame
);
132 if ( eDlgUnit
!= eTmpUnit
)
135 SetFieldUnit(*m_xWidget
, eDlgUnit
);
139 IMPL_LINK_NOARG(SvxMetricField
, FocusInHdl
, weld::Widget
&, void)
141 nCurValue
= m_xWidget
->get_value(FieldUnit::NONE
);
144 IMPL_LINK(SvxMetricField
, KeyInputHdl
, const KeyEvent
&, rKEvt
, bool)
146 bool bHandled
= false;
148 sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
150 if (nCode
== KEY_ESCAPE
)
152 m_xWidget
->set_value(nCurValue
, FieldUnit::NONE
);
153 ModifyHdl(*m_xWidget
);
158 return bHandled
|| ChildKeyInput(rKEvt
);
161 void SvxMetricField::DataChanged( const DataChangedEvent
& rDCEvt
)
163 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
164 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
166 SetSizePixel(m_xWidget
->get_preferred_size());
169 InterimItemWindow::DataChanged( rDCEvt
);
172 void SvxFillTypeBox::Fill(weld::ComboBox
& rListBox
)
176 rListBox
.append_text(SvxResId(RID_SVXSTR_INVISIBLE
));
177 rListBox
.append_text(SvxResId(RID_SVXSTR_COLOR
));
178 rListBox
.append_text(SvxResId(RID_SVXSTR_GRADIENT
));
179 rListBox
.append_text(SvxResId(RID_SVXSTR_HATCH
));
180 rListBox
.append_text(SvxResId(RID_SVXSTR_BITMAP
));
181 rListBox
.append_text(SvxResId(RID_SVXSTR_PATTERN
));
182 rListBox
.append_text(SvxResId(RID_SVXSTR_USE_BACKGROUND
));
186 rListBox
.set_active(1); // solid color
191 void formatBitmapExToSize(BitmapEx
& rBitmapEx
, const Size
& rSize
)
193 if(rBitmapEx
.IsEmpty() || rSize
.IsEmpty())
196 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
197 pVirtualDevice
->SetOutputSizePixel(rSize
);
199 if(rBitmapEx
.IsAlpha())
201 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
203 if(rStyleSettings
.GetPreviewUsesCheckeredBackground())
205 const Point
aNull(0, 0);
206 static const sal_uInt32
nLen(8);
207 static const Color
aW(COL_WHITE
);
208 static const Color
aG(0xef, 0xef, 0xef);
210 pVirtualDevice
->DrawCheckered(aNull
, rSize
, nLen
, aW
, aG
);
214 pVirtualDevice
->SetBackground(rStyleSettings
.GetFieldColor());
215 pVirtualDevice
->Erase();
219 if(rBitmapEx
.GetSizePixel().Width() >= rSize
.Width() && rBitmapEx
.GetSizePixel().Height() >= rSize
.Height())
221 rBitmapEx
.Scale(rSize
);
222 pVirtualDevice
->DrawBitmapEx(Point(0, 0), rBitmapEx
);
226 const Size
aBitmapSize(rBitmapEx
.GetSizePixel());
228 for(tools::Long
y(0); y
< rSize
.Height(); y
+= aBitmapSize
.Height())
230 for(tools::Long
x(0); x
< rSize
.Width(); x
+= aBitmapSize
.Width())
232 pVirtualDevice
->DrawBitmapEx(
239 rBitmapEx
= pVirtualDevice
->GetBitmapEx(Point(0, 0), rSize
);
241 } // end of anonymous namespace
243 void SvxFillAttrBox::Fill(weld::ComboBox
& rBox
, const XHatchListRef
&pList
)
248 tools::Long nCount
= pList
->Count();
249 ScopedVclPtrInstance
< VirtualDevice
> pVD
;
252 for( tools::Long i
= 0; i
< nCount
; i
++ )
254 const XHatchEntry
* pEntry
= pList
->GetHatch(i
);
255 const BitmapEx aBitmapEx
= pList
->GetUiBitmap( i
);
256 if( !aBitmapEx
.IsEmpty() )
258 const Size
aBmpSize(aBitmapEx
.GetSizePixel());
259 pVD
->SetOutputSizePixel(aBmpSize
, false);
260 pVD
->DrawBitmapEx(Point(), aBitmapEx
);
261 rBox
.append(u
""_ustr
, pEntry
->GetName(), *pVD
);
264 rBox
.append_text(pEntry
->GetName());
270 void SvxFillAttrBox::Fill(weld::ComboBox
& rBox
, const XGradientListRef
&pList
)
275 tools::Long nCount
= pList
->Count();
276 ScopedVclPtrInstance
< VirtualDevice
> pVD
;
279 for( tools::Long i
= 0; i
< nCount
; i
++ )
281 const XGradientEntry
* pEntry
= pList
->GetGradient(i
);
282 const BitmapEx aBitmapEx
= pList
->GetUiBitmap( i
);
283 if( !aBitmapEx
.IsEmpty() )
285 const Size
aBmpSize(aBitmapEx
.GetSizePixel());
286 pVD
->SetOutputSizePixel(aBmpSize
, false);
287 pVD
->DrawBitmapEx(Point(), aBitmapEx
);
288 rBox
.append(u
""_ustr
, pEntry
->GetName(), *pVD
);
291 rBox
.append_text(pEntry
->GetName());
297 void SvxFillAttrBox::Fill(weld::ComboBox
& rBox
, const XBitmapListRef
&pList
)
302 tools::Long nCount
= pList
->Count();
303 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
304 const Size
aSize(rStyleSettings
.GetListBoxPreviewDefaultPixelSize());
305 ScopedVclPtrInstance
< VirtualDevice
> pVD
;
306 pVD
->SetOutputSizePixel(aSize
, false);
309 for( tools::Long i
= 0; i
< nCount
; i
++ )
311 const XBitmapEntry
* pEntry
= pList
->GetBitmap( i
);
312 BitmapEx aBitmapEx
= pEntry
->GetGraphicObject().GetGraphic().GetBitmapEx();
313 formatBitmapExToSize(aBitmapEx
, aSize
);
314 pVD
->DrawBitmapEx(Point(), aBitmapEx
);
315 rBox
.append(u
""_ustr
, pEntry
->GetName(), *pVD
);
321 void SvxFillAttrBox::Fill(weld::ComboBox
& rBox
, const XPatternListRef
&pList
)
326 tools::Long nCount
= pList
->Count();
327 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
328 const Size
aSize(rStyleSettings
.GetListBoxPreviewDefaultPixelSize());
329 ScopedVclPtrInstance
< VirtualDevice
> pVD
;
330 pVD
->SetOutputSizePixel(aSize
, false);
333 for( tools::Long i
= 0; i
< nCount
; i
++ )
335 const XBitmapEntry
* pEntry
= pList
->GetBitmap( i
);
336 BitmapEx aBitmapEx
= pEntry
->GetGraphicObject().GetGraphic().GetBitmapEx();
337 formatBitmapExToSize(aBitmapEx
, aSize
);
338 pVD
->DrawBitmapEx(Point(), aBitmapEx
);
339 rBox
.append(u
""_ustr
, pEntry
->GetName(), *pVD
);
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */