Avoid potential negative array index access to cached text.
[LibreOffice.git] / toolkit / source / helper / vclunohelper.cxx
blob9f05ae707065f3a3bc333f1ed6040c776fb6d58f
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 <tools/stream.hxx>
21 #include <vcl/dibtools.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/graph.hxx>
24 #include <vcl/metric.hxx>
25 #include <vcl/ptrstyle.hxx>
26 #include <vcl/unohelp.hxx>
27 #include <vcl/window.hxx>
28 #include <com/sun/star/util/MeasureUnit.hpp>
29 #include <com/sun/star/awt/XBitmap.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/awt/XDevice.hpp>
32 #include <com/sun/star/awt/SimpleFontMetric.hpp>
33 #include <com/sun/star/awt/FontDescriptor.hpp>
34 #include <com/sun/star/awt/XControlContainer.hpp>
35 #include <com/sun/star/awt/KeyModifier.hpp>
36 #include <com/sun/star/awt/MouseButton.hpp>
37 #include <com/sun/star/embed/EmbedMapUnits.hpp>
38 #include <com/sun/star/graphic/XGraphic.hpp>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <toolkit/helper/convert.hxx>
41 #include <awt/vclxbitmap.hxx>
42 #include <awt/vclxregion.hxx>
43 #include <toolkit/awt/vclxwindow.hxx>
44 #include <awt/vclxgraphics.hxx>
45 #include <toolkit/awt/vclxfont.hxx>
46 #include <controls/unocontrolcontainer.hxx>
47 #include <controls/unocontrolcontainermodel.hxx>
48 #include <comphelper/processfactory.hxx>
50 #include <com/sun/star/awt/Toolkit.hpp>
51 #include <com/sun/star/awt/Size.hpp>
52 #include <com/sun/star/awt/Point.hpp>
54 using namespace ::com::sun::star;
57 uno::Reference< css::awt::XToolkit> VCLUnoHelper::CreateToolkit()
59 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
60 uno::Reference< awt::XToolkit> xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW );
61 return xToolkit;
64 BitmapEx VCLUnoHelper::GetBitmap( const css::uno::Reference< css::awt::XBitmap>& rxBitmap )
66 BitmapEx aBmp;
68 css::uno::Reference< css::graphic::XGraphic > xGraphic( rxBitmap, css::uno::UNO_QUERY );
69 if( xGraphic.is() )
71 Graphic aGraphic( xGraphic );
72 aBmp = aGraphic.GetBitmapEx();
74 else if ( rxBitmap.is() )
76 VCLXBitmap* pVCLBitmap = dynamic_cast<VCLXBitmap*>( rxBitmap.get() );
77 if ( pVCLBitmap )
78 aBmp = pVCLBitmap->GetBitmap();
79 else
81 Bitmap aDIB, aMask;
83 css::uno::Sequence<sal_Int8> aBytes = rxBitmap->getDIB();
84 SvMemoryStream aMem( aBytes.getArray(), aBytes.getLength(), StreamMode::READ );
85 ReadDIB(aDIB, aMem, true);
88 css::uno::Sequence<sal_Int8> aBytes = rxBitmap->getMaskDIB();
89 SvMemoryStream aMem( aBytes.getArray(), aBytes.getLength(), StreamMode::READ );
90 ReadDIB(aMask, aMem, true);
92 aMask.Invert(); // Convert from transparency to alpha
93 aBmp = BitmapEx( aDIB, aMask );
96 return aBmp;
99 css::uno::Reference< css::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
101 Graphic aGraphic( rBitmap );
102 css::uno::Reference< css::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), css::uno::UNO_QUERY );
103 return xBmp;
106 vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow>& rxWindow )
108 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
109 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
112 vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow2>& rxWindow )
114 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
115 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
118 vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindowPeer>& rxWindow )
120 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
121 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
124 vcl::Region VCLUnoHelper::GetRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion )
126 vcl::Region aRegion;
127 VCLXRegion* pVCLRegion = dynamic_cast<VCLXRegion*>( rxRegion.get() );
128 if ( pVCLRegion )
129 aRegion = pVCLRegion->GetRegion();
130 else
132 const css::uno::Sequence< css::awt::Rectangle > aRects = rxRegion->getRectangles();
133 for ( const auto& rRect : aRects )
134 aRegion.Union( VCLRectangle( rRect ) );
136 return aRegion;
139 css::uno::Reference< css::awt::XWindow> VCLUnoHelper::GetInterface( vcl::Window* pWindow )
141 css::uno::Reference< css::awt::XWindow > xWin;
142 if ( pWindow )
144 css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
145 xWin.set(xPeer, css::uno::UNO_QUERY);
147 return xWin;
150 OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XDevice>& rxDevice )
152 VclPtr<OutputDevice> pOutDev;
153 VCLXDevice* pDev = dynamic_cast<VCLXDevice*>( rxDevice.get() );
154 if ( pDev )
155 pOutDev = pDev->GetOutputDevice();
156 return pOutDev;
159 OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XGraphics>& rxGraphics )
161 OutputDevice* pOutDev = nullptr;
162 VCLXGraphics* pGrf = dynamic_cast<VCLXGraphics*>( rxGraphics.get() );
163 if ( pGrf )
164 pOutDev = pGrf->GetOutputDevice();
165 return pOutDev;
168 tools::Polygon VCLUnoHelper::CreatePolygon( const css::uno::Sequence< sal_Int32 >& DataX,
169 const css::uno::Sequence< sal_Int32 >& DataY )
171 sal_Int32 nLen = DataX.getLength();
172 const sal_Int32* pDataX = DataX.getConstArray();
173 const sal_Int32* pDataY = DataY.getConstArray();
174 tools::Polygon aPoly( static_cast<sal_uInt16>(nLen) );
175 for ( sal_Int32 n = 0; n < nLen; n++ )
177 Point aPnt;
178 aPnt.setX( pDataX[n] );
179 aPnt.setY( pDataY[n] );
180 aPoly[n] = aPnt;
182 return aPoly;
185 css::uno::Reference< css::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( vcl::Window* pWindow )
187 rtl::Reference<UnoControlContainer> pContainer = new UnoControlContainer( pWindow->GetComponentInterface() );
189 rtl::Reference<UnoControlModel> pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
190 pContainer->setModel( pContainerModel );
192 return pContainer;
195 css::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const vcl::Font& rFont )
197 css::awt::FontDescriptor aFD;
198 aFD.Name = rFont.GetFamilyName();
199 aFD.StyleName = rFont.GetStyleName();
200 aFD.Height = static_cast<sal_Int16>(rFont.GetFontSize().Height());
201 aFD.Width = static_cast<sal_Int16>(rFont.GetFontSize().Width());
202 aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
203 aFD.CharSet = rFont.GetCharSet();
204 aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
205 aFD.CharacterWidth = vcl::unohelper::ConvertFontWidth(rFont.GetWidthType());
206 aFD.Weight = vcl::unohelper::ConvertFontWeight(rFont.GetWeight());
207 aFD.Slant = vcl::unohelper::ConvertFontSlant(rFont.GetItalic());
208 aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
209 aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
210 aFD.Orientation = rFont.GetOrientation().get() / 10.0;
211 aFD.Kerning = rFont.IsKerning();
212 aFD.WordLineMode = rFont.IsWordLineMode();
213 aFD.Type = 0; // ??? => Only in Metric...
214 return aFD;
217 vcl::Font VCLUnoHelper::CreateFont( const css::awt::FontDescriptor& rDescr, const vcl::Font& rInitFont )
219 vcl::Font aFont( rInitFont );
220 if ( !rDescr.Name.isEmpty() )
221 aFont.SetFamilyName( rDescr.Name );
222 if ( !rDescr.StyleName.isEmpty() )
223 aFont.SetStyleName( rDescr.StyleName );
224 if ( rDescr.Height )
225 aFont.SetFontSize( Size( rDescr.Width, rDescr.Height ) );
226 if ( static_cast<FontFamily>(rDescr.Family) != FAMILY_DONTKNOW )
227 aFont.SetFamily( static_cast<FontFamily>(rDescr.Family) );
228 if ( static_cast<rtl_TextEncoding>(rDescr.CharSet) != RTL_TEXTENCODING_DONTKNOW )
229 aFont.SetCharSet( static_cast<rtl_TextEncoding>(rDescr.CharSet) );
230 if ( static_cast<FontPitch>(rDescr.Pitch) != PITCH_DONTKNOW )
231 aFont.SetPitch( static_cast<FontPitch>(rDescr.Pitch) );
232 if ( rDescr.CharacterWidth )
233 aFont.SetWidthType(vcl::unohelper::ConvertFontWidth(rDescr.CharacterWidth));
234 if ( rDescr.Weight )
235 aFont.SetWeight(vcl::unohelper::ConvertFontWeight(rDescr.Weight));
236 if ( rDescr.Slant != css::awt::FontSlant_DONTKNOW )
237 aFont.SetItalic(vcl::unohelper::ConvertFontSlant(rDescr.Slant));
238 if ( static_cast<FontLineStyle>(rDescr.Underline) != LINESTYLE_DONTKNOW )
239 aFont.SetUnderline( static_cast<FontLineStyle>(rDescr.Underline) );
240 if ( static_cast<FontStrikeout>(rDescr.Strikeout) != STRIKEOUT_DONTKNOW )
241 aFont.SetStrikeout( static_cast<FontStrikeout>(rDescr.Strikeout) );
243 // Not DONTKNOW
244 aFont.SetOrientation( Degree10(static_cast<sal_Int16>(rDescr.Orientation * 10)) );
245 aFont.SetKerning( static_cast<FontKerning>(rDescr.Kerning) );
246 aFont.SetWordLineMode( rDescr.WordLineMode );
248 return aFont;
251 vcl::Font VCLUnoHelper::CreateFont( const css::uno::Reference< css::awt::XFont >& rxFont )
253 vcl::Font aFont;
254 VCLXFont* pVCLXFont = dynamic_cast<VCLXFont*>( rxFont.get() );
255 if ( pVCLXFont )
256 aFont = pVCLXFont->GetFont();
257 return aFont;
261 css::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric )
263 css::awt::SimpleFontMetric aFM;
264 aFM.Ascent = static_cast<sal_Int16>(rFontMetric.GetAscent());
265 aFM.Descent = static_cast<sal_Int16>(rFontMetric.GetDescent());
266 aFM.Leading = static_cast<sal_Int16>(rFontMetric.GetInternalLeading());
267 aFM.Slant = static_cast<sal_Int16>(rFontMetric.GetSlant());
268 aFM.FirstChar = 0x0020;
269 aFM.LastChar = 0xFFFD;
270 return aFM;
273 bool VCLUnoHelper::IsZero(const css::awt::Rectangle& rRect)
275 return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
278 MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
280 switch( nUnoEmbedMapUnit )
282 case css::embed::EmbedMapUnits::ONE_100TH_MM:
283 return MapUnit::Map100thMM;
284 case css::embed::EmbedMapUnits::ONE_10TH_MM:
285 return MapUnit::Map10thMM;
286 case css::embed::EmbedMapUnits::ONE_MM:
287 return MapUnit::MapMM;
288 case css::embed::EmbedMapUnits::ONE_CM:
289 return MapUnit::MapCM;
290 case css::embed::EmbedMapUnits::ONE_1000TH_INCH:
291 return MapUnit::Map1000thInch;
292 case css::embed::EmbedMapUnits::ONE_100TH_INCH:
293 return MapUnit::Map100thInch;
294 case css::embed::EmbedMapUnits::ONE_10TH_INCH:
295 return MapUnit::Map10thInch;
296 case css::embed::EmbedMapUnits::ONE_INCH:
297 return MapUnit::MapInch;
298 case css::embed::EmbedMapUnits::POINT:
299 return MapUnit::MapPoint;
300 case css::embed::EmbedMapUnits::TWIP:
301 return MapUnit::MapTwip;
302 case css::embed::EmbedMapUnits::PIXEL:
303 return MapUnit::MapPixel;
306 OSL_FAIL( "Unexpected UNO map mode is provided!" );
307 return MapUnit::LASTENUMDUMMY;
310 sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit )
312 switch( nVCLMapUnit )
314 case MapUnit::Map100thMM:
315 return css::embed::EmbedMapUnits::ONE_100TH_MM;
316 case MapUnit::Map10thMM:
317 return css::embed::EmbedMapUnits::ONE_10TH_MM;
318 case MapUnit::MapMM:
319 return css::embed::EmbedMapUnits::ONE_MM;
320 case MapUnit::MapCM:
321 return css::embed::EmbedMapUnits::ONE_CM;
322 case MapUnit::Map1000thInch:
323 return css::embed::EmbedMapUnits::ONE_1000TH_INCH;
324 case MapUnit::Map100thInch:
325 return css::embed::EmbedMapUnits::ONE_100TH_INCH;
326 case MapUnit::Map10thInch:
327 return css::embed::EmbedMapUnits::ONE_10TH_INCH;
328 case MapUnit::MapInch:
329 return css::embed::EmbedMapUnits::ONE_INCH;
330 case MapUnit::MapPoint:
331 return css::embed::EmbedMapUnits::POINT;
332 case MapUnit::MapTwip:
333 return css::embed::EmbedMapUnits::TWIP;
334 case MapUnit::MapPixel:
335 return css::embed::EmbedMapUnits::PIXEL;
336 default: ; // avoid compiler warning
339 OSL_FAIL( "Unexpected VCL map mode is provided!" );
340 return -1;
343 using namespace ::com::sun::star::util;
346 namespace
348 enum UnitConversionDirection
350 FieldUnitToMeasurementUnit,
351 MeasurementUnitToFieldUnit
354 sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor )
356 static struct _unit_table
358 FieldUnit eFieldUnit;
359 sal_Int16 nMeasurementUnit;
360 sal_Int16 nFieldToMeasureFactor;
361 } const aUnits[] = {
362 { FieldUnit::NONE, -1 , -1},
363 { FieldUnit::MM, MeasureUnit::MM, 1 }, // must precede MM_10TH
364 { FieldUnit::MM, MeasureUnit::MM_10TH, 10 },
365 { FieldUnit::MM_100TH, MeasureUnit::MM_100TH, 1 },
366 { FieldUnit::CM, MeasureUnit::CM, 1 },
367 { FieldUnit::M, MeasureUnit::M, 1 },
368 { FieldUnit::KM, MeasureUnit::KM, 1 },
369 { FieldUnit::TWIP, MeasureUnit::TWIP, 1 },
370 { FieldUnit::POINT, MeasureUnit::POINT, 1 },
371 { FieldUnit::PICA, MeasureUnit::PICA, 1 },
372 { FieldUnit::INCH, MeasureUnit::INCH, 1 }, // must precede INCH_*TH
373 { FieldUnit::INCH, MeasureUnit::INCH_10TH, 10 },
374 { FieldUnit::INCH, MeasureUnit::INCH_100TH, 100 },
375 { FieldUnit::INCH, MeasureUnit::INCH_1000TH, 1000 },
376 { FieldUnit::FOOT, MeasureUnit::FOOT, 1 },
377 { FieldUnit::MILE, MeasureUnit::MILE, 1 },
379 for (auto & aUnit : aUnits)
381 if ( eDirection == FieldUnitToMeasurementUnit )
383 if ( ( aUnit.eFieldUnit == static_cast<FieldUnit>(_nUnit) ) && ( aUnit.nFieldToMeasureFactor == _rFieldToUNOValueFactor ) )
384 return aUnit.nMeasurementUnit;
386 else
388 if ( aUnit.nMeasurementUnit == _nUnit )
390 _rFieldToUNOValueFactor = aUnit.nFieldToMeasureFactor;
391 return static_cast<sal_Int16>(aUnit.eFieldUnit);
395 if ( eDirection == FieldUnitToMeasurementUnit )
396 return -1;
398 _rFieldToUNOValueFactor = 1;
399 return sal_Int16(FieldUnit::NONE);
403 //= MeasurementUnitConversion
406 sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor )
408 return convertMeasurementUnit( static_cast<sal_Int16>(_nFieldUnit), FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor );
412 FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor )
414 return static_cast<FieldUnit>(convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor ));
418 MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit)
420 MapUnit eMode;
421 switch(_nMeasureUnit)
423 case css::util::MeasureUnit::MM_100TH:
424 eMode = MapUnit::Map100thMM;
425 break;
427 case css::util::MeasureUnit::MM_10TH:
428 eMode = MapUnit::Map10thMM;
429 break;
431 case css::util::MeasureUnit::MM:
432 eMode = MapUnit::MapMM;
433 break;
435 case css::util::MeasureUnit::CM:
436 eMode = MapUnit::MapCM;
437 break;
439 case css::util::MeasureUnit::INCH_1000TH:
440 eMode = MapUnit::Map1000thInch;
441 break;
443 case css::util::MeasureUnit::INCH_100TH:
444 eMode = MapUnit::Map100thInch;
445 break;
447 case css::util::MeasureUnit::INCH_10TH:
448 eMode = MapUnit::Map10thInch;
449 break;
451 case css::util::MeasureUnit::INCH:
452 eMode = MapUnit::MapInch;
453 break;
455 case css::util::MeasureUnit::POINT:
456 eMode = MapUnit::MapPoint;
457 break;
459 case css::util::MeasureUnit::TWIP:
460 eMode = MapUnit::MapTwip;
461 break;
463 case css::util::MeasureUnit::PIXEL:
464 eMode = MapUnit::MapPixel;
465 break;
467 case css::util::MeasureUnit::APPFONT:
468 eMode = MapUnit::MapAppFont;
469 break;
471 case css::util::MeasureUnit::SYSFONT:
472 eMode = MapUnit::MapSysFont;
473 break;
475 default:
476 throw css::lang::IllegalArgumentException("Unsupported measure unit.", nullptr, 1 );
478 return eMode;
481 ::Size VCLUnoHelper::ConvertToVCLSize(css::awt::Size const& _aSize)
483 ::Size aVCLSize(_aSize.Width, _aSize.Height);
484 return aVCLSize;
487 css::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
489 css::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
490 return aAWTSize;
494 ::Point VCLUnoHelper::ConvertToVCLPoint(css::awt::Point const& _aPoint)
496 ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
497 return aVCLPoint;
500 css::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
502 css::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
503 return aAWTPoint;
506 ::tools::Rectangle VCLUnoHelper::ConvertToVCLRect( css::awt::Rectangle const & _rRect )
508 return ::tools::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 );
511 css::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::tools::Rectangle const & _rRect )
513 return css::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() );
516 awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
518 awt::MouseEvent aMouseEvent;
519 aMouseEvent.Source = _rxContext;
521 aMouseEvent.Modifiers = 0;
522 if ( _rVclEvent.IsShift() )
523 aMouseEvent.Modifiers |= css::awt::KeyModifier::SHIFT;
524 if ( _rVclEvent.IsMod1() )
525 aMouseEvent.Modifiers |= css::awt::KeyModifier::MOD1;
526 if ( _rVclEvent.IsMod2() )
527 aMouseEvent.Modifiers |= css::awt::KeyModifier::MOD2;
529 aMouseEvent.Buttons = 0;
530 if ( _rVclEvent.IsLeft() )
531 aMouseEvent.Buttons |= css::awt::MouseButton::LEFT;
532 if ( _rVclEvent.IsRight() )
533 aMouseEvent.Buttons |= css::awt::MouseButton::RIGHT;
534 if ( _rVclEvent.IsMiddle() )
535 aMouseEvent.Buttons |= css::awt::MouseButton::MIDDLE;
537 aMouseEvent.X = _rVclEvent.GetPosPixel().X();
538 aMouseEvent.Y = _rVclEvent.GetPosPixel().Y();
539 aMouseEvent.ClickCount = _rVclEvent.GetClicks();
540 aMouseEvent.PopupTrigger = false;
542 return aMouseEvent;
545 ::MouseEvent VCLUnoHelper::createVCLMouseEvent( const awt::MouseEvent& _rAwtEvent )
547 ::MouseEvent aMouseEvent( Point( _rAwtEvent.X, _rAwtEvent.Y ), _rAwtEvent.ClickCount,
548 ::MouseEventModifiers::NONE, _rAwtEvent.Buttons, _rAwtEvent.Modifiers );
550 return aMouseEvent;
553 awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
555 awt::KeyEvent aKeyEvent;
556 aKeyEvent.Source = _rxContext;
558 aKeyEvent.Modifiers = 0;
559 if ( _rVclEvent.GetKeyCode().IsShift() )
560 aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT;
561 if ( _rVclEvent.GetKeyCode().IsMod1() )
562 aKeyEvent.Modifiers |= awt::KeyModifier::MOD1;
563 if ( _rVclEvent.GetKeyCode().IsMod2() )
564 aKeyEvent.Modifiers |= awt::KeyModifier::MOD2;
565 if ( _rVclEvent.GetKeyCode().IsMod3() )
566 aKeyEvent.Modifiers |= awt::KeyModifier::MOD3;
568 aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode();
569 aKeyEvent.KeyChar = _rVclEvent.GetCharCode();
570 aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction());
572 return aKeyEvent;
575 ::KeyEvent VCLUnoHelper::createVCLKeyEvent( const awt::KeyEvent& _rAwtEvent )
577 sal_Unicode nChar = _rAwtEvent.KeyChar;
578 vcl::KeyCode aKeyCode( _rAwtEvent.KeyCode, _rAwtEvent.Modifiers & awt::KeyModifier::SHIFT,
579 _rAwtEvent.Modifiers & awt::KeyModifier::MOD1,
580 _rAwtEvent.Modifiers & awt::KeyModifier::MOD2,
581 _rAwtEvent.Modifiers & awt::KeyModifier::MOD3 );
583 return ::KeyEvent (nChar, aKeyCode);
587 ::PointerStyle VCLUnoHelper::getMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer)
589 ::PointerStyle eType = ::PointerStyle::Arrow; // default ?
590 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer);
591 if (pWindow)
592 eType = pWindow->GetPointer();
593 return eType;
596 void VCLUnoHelper::setMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer, ::PointerStyle ePointer)
598 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer);
599 if (!pWindow)
600 return;
601 pWindow->SetPointer(ePointer);
604 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */