Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / itemwin.cxx
blob1a9b6d3bcf53a39d20ca5ce90ce3dd9f159d377b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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::lang;
47 using namespace ::com::sun::star::beans;
49 SvxMetricField::SvxMetricField(
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)
58 InitControlBase(&m_xWidget->get_widget());
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));
65 SetFieldUnit(*m_xWidget, eDlgUnit);
67 SetSizePixel(m_xWidget->get_preferred_size());
70 void SvxMetricField::dispose()
72 m_xWidget.reset();
73 InterimItemWindow::dispose();
76 SvxMetricField::~SvxMetricField()
78 disposeOnce();
81 void SvxMetricField::set_sensitive(bool bSensitive)
83 Enable(bSensitive);
84 m_xWidget->set_sensitive(bSensitive);
85 if (!bSensitive)
86 m_xWidget->set_text("");
89 void SvxMetricField::Update( const XLineWidthItem* pItem )
91 if ( pItem )
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);
98 else
99 m_xWidget->set_text("");
102 IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton&, void)
104 auto nTmp = GetCoreValue(*m_xWidget, eDestPoolUnit);
105 XLineWidthItem aLineWidthItem( nTmp );
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 );
115 void SvxMetricField::ReleaseFocus_Impl()
117 if( SfxViewShell::Current() )
119 vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
120 if ( pShellWnd )
121 pShellWnd->GrabFocus();
125 void SvxMetricField::SetDestCoreUnit( MapUnit eUnit )
127 eDestPoolUnit = eUnit;
130 void SvxMetricField::RefreshDlgUnit()
132 FieldUnit eTmpUnit = SfxModule::GetModuleFieldUnit( mxFrame );
133 if ( eDlgUnit != eTmpUnit )
135 eDlgUnit = eTmpUnit;
136 SetFieldUnit(*m_xWidget, eDlgUnit);
140 IMPL_LINK_NOARG(SvxMetricField, FocusInHdl, weld::Widget&, void)
142 nCurValue = m_xWidget->get_value(FieldUnit::NONE);
145 IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
147 bool bHandled = false;
149 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
151 if (nCode == KEY_ESCAPE)
153 m_xWidget->set_value(nCurValue, FieldUnit::NONE);
154 ModifyHdl(*m_xWidget);
155 ReleaseFocus_Impl();
156 bHandled = true;
159 return bHandled || ChildKeyInput(rKEvt);
162 void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt )
164 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
165 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
167 SetSizePixel(m_xWidget->get_preferred_size());
170 InterimItemWindow::DataChanged( rDCEvt );
173 void SvxFillTypeBox::Fill(weld::ComboBox& rListBox)
175 rListBox.freeze();
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));
185 rListBox.thaw();
187 rListBox.set_active(1); // solid color
190 namespace
192 void formatBitmapExToSize(BitmapEx& rBitmapEx, const Size& rSize)
194 if(rBitmapEx.IsEmpty() || rSize.IsEmpty())
195 return;
197 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
198 pVirtualDevice->SetOutputSizePixel(rSize);
200 if(rBitmapEx.IsAlpha())
202 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
204 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
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);
211 pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
213 else
215 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
216 pVirtualDevice->Erase();
220 if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
222 rBitmapEx.Scale(rSize);
223 pVirtualDevice->DrawBitmapEx(Point(0, 0), rBitmapEx);
225 else
227 const Size aBitmapSize(rBitmapEx.GetSizePixel());
229 for(tools::Long y(0); y < rSize.Height(); y += aBitmapSize.Height())
231 for(tools::Long x(0); x < rSize.Width(); x += aBitmapSize.Width())
233 pVirtualDevice->DrawBitmapEx(
234 Point(x, y),
235 rBitmapEx);
240 rBitmapEx = pVirtualDevice->GetBitmapEx(Point(0, 0), rSize);
242 } // end of anonymous namespace
244 void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XHatchListRef &pList)
246 if( !pList.is() )
247 return;
249 tools::Long nCount = pList->Count();
250 ScopedVclPtrInstance< VirtualDevice > pVD;
251 rBox.freeze();
253 for( tools::Long i = 0; i < nCount; i++ )
255 const XHatchEntry* pEntry = pList->GetHatch(i);
256 const BitmapEx aBitmapEx = pList->GetUiBitmap( i );
257 if( !aBitmapEx.IsEmpty() )
259 const Size aBmpSize(aBitmapEx.GetSizePixel());
260 pVD->SetOutputSizePixel(aBmpSize, false);
261 pVD->DrawBitmapEx(Point(), aBitmapEx);
262 rBox.append("", pEntry->GetName(), *pVD);
264 else
265 rBox.append_text(pEntry->GetName());
268 rBox.thaw();
271 void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XGradientListRef &pList)
273 if( !pList.is() )
274 return;
276 tools::Long nCount = pList->Count();
277 ScopedVclPtrInstance< VirtualDevice > pVD;
278 rBox.freeze();
280 for( tools::Long i = 0; i < nCount; i++ )
282 const XGradientEntry* pEntry = pList->GetGradient(i);
283 const BitmapEx aBitmapEx = pList->GetUiBitmap( i );
284 if( !aBitmapEx.IsEmpty() )
286 const Size aBmpSize(aBitmapEx.GetSizePixel());
287 pVD->SetOutputSizePixel(aBmpSize, false);
288 pVD->DrawBitmapEx(Point(), aBitmapEx);
289 rBox.append("", pEntry->GetName(), *pVD);
291 else
292 rBox.append_text(pEntry->GetName());
295 rBox.thaw();
298 void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XBitmapListRef &pList)
300 if( !pList.is() )
301 return;
303 tools::Long nCount = pList->Count();
304 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
305 const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
306 ScopedVclPtrInstance< VirtualDevice > pVD;
307 pVD->SetOutputSizePixel(aSize, false);
308 rBox.freeze();
310 for( tools::Long i = 0; i < nCount; i++ )
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);
319 rBox.thaw();
322 void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XPatternListRef &pList)
324 if( !pList.is() )
325 return;
327 tools::Long nCount = pList->Count();
328 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
329 const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
330 ScopedVclPtrInstance< VirtualDevice > pVD;
331 pVD->SetOutputSizePixel(aSize, false);
332 rBox.freeze();
334 for( tools::Long i = 0; i < nCount; i++ )
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);
343 rBox.thaw();
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */