Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / source / helper / vclunohelper.cxx
blob45580c37cac89c838fb612d7a30b51acfac73e94
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 aBmp = BitmapEx( aDIB, aMask );
95 return aBmp;
98 css::uno::Reference< css::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
100 Graphic aGraphic( rBitmap );
101 css::uno::Reference< css::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), css::uno::UNO_QUERY );
102 return xBmp;
105 vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow>& rxWindow )
107 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
108 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
111 vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow2>& rxWindow )
113 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
114 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
117 vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindowPeer>& rxWindow )
119 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
120 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
123 vcl::Region VCLUnoHelper::GetRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion )
125 vcl::Region aRegion;
126 VCLXRegion* pVCLRegion = dynamic_cast<VCLXRegion*>( rxRegion.get() );
127 if ( pVCLRegion )
128 aRegion = pVCLRegion->GetRegion();
129 else
131 const css::uno::Sequence< css::awt::Rectangle > aRects = rxRegion->getRectangles();
132 for ( const auto& rRect : aRects )
133 aRegion.Union( VCLRectangle( rRect ) );
135 return aRegion;
138 css::uno::Reference< css::awt::XWindow> VCLUnoHelper::GetInterface( vcl::Window* pWindow )
140 css::uno::Reference< css::awt::XWindow > xWin;
141 if ( pWindow )
143 css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
144 xWin.set(xPeer, css::uno::UNO_QUERY);
146 return xWin;
149 OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XDevice>& rxDevice )
151 VclPtr<OutputDevice> pOutDev;
152 VCLXDevice* pDev = dynamic_cast<VCLXDevice*>( rxDevice.get() );
153 if ( pDev )
154 pOutDev = pDev->GetOutputDevice();
155 return pOutDev;
158 OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XGraphics>& rxGraphics )
160 OutputDevice* pOutDev = nullptr;
161 VCLXGraphics* pGrf = dynamic_cast<VCLXGraphics*>( rxGraphics.get() );
162 if ( pGrf )
163 pOutDev = pGrf->GetOutputDevice();
164 return pOutDev;
167 tools::Polygon VCLUnoHelper::CreatePolygon( const css::uno::Sequence< sal_Int32 >& DataX,
168 const css::uno::Sequence< sal_Int32 >& DataY )
170 sal_Int32 nLen = DataX.getLength();
171 const sal_Int32* pDataX = DataX.getConstArray();
172 const sal_Int32* pDataY = DataY.getConstArray();
173 tools::Polygon aPoly( static_cast<sal_uInt16>(nLen) );
174 for ( sal_Int32 n = 0; n < nLen; n++ )
176 Point aPnt;
177 aPnt.setX( pDataX[n] );
178 aPnt.setY( pDataY[n] );
179 aPoly[n] = aPnt;
181 return aPoly;
184 css::uno::Reference< css::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( vcl::Window* pWindow )
186 rtl::Reference<UnoControlContainer> pContainer = new UnoControlContainer( pWindow->GetComponentInterface() );
188 rtl::Reference<UnoControlModel> pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
189 pContainer->setModel( pContainerModel );
191 return pContainer;
194 css::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const vcl::Font& rFont )
196 css::awt::FontDescriptor aFD;
197 aFD.Name = rFont.GetFamilyName();
198 aFD.StyleName = rFont.GetStyleName();
199 aFD.Height = static_cast<sal_Int16>(rFont.GetFontSize().Height());
200 aFD.Width = static_cast<sal_Int16>(rFont.GetFontSize().Width());
201 aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
202 aFD.CharSet = rFont.GetCharSet();
203 aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
204 aFD.CharacterWidth = vcl::unohelper::ConvertFontWidth(rFont.GetWidthType());
205 aFD.Weight = vcl::unohelper::ConvertFontWeight(rFont.GetWeight());
206 aFD.Slant = vcl::unohelper::ConvertFontSlant(rFont.GetItalic());
207 aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
208 aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
209 aFD.Orientation = rFont.GetOrientation().get() / 10.0;
210 aFD.Kerning = rFont.IsKerning();
211 aFD.WordLineMode = rFont.IsWordLineMode();
212 aFD.Type = 0; // ??? => Only in Metric...
213 return aFD;
216 vcl::Font VCLUnoHelper::CreateFont( const css::awt::FontDescriptor& rDescr, const vcl::Font& rInitFont )
218 vcl::Font aFont( rInitFont );
219 if ( !rDescr.Name.isEmpty() )
220 aFont.SetFamilyName( rDescr.Name );
221 if ( !rDescr.StyleName.isEmpty() )
222 aFont.SetStyleName( rDescr.StyleName );
223 if ( rDescr.Height )
224 aFont.SetFontSize( Size( rDescr.Width, rDescr.Height ) );
225 if ( static_cast<FontFamily>(rDescr.Family) != FAMILY_DONTKNOW )
226 aFont.SetFamily( static_cast<FontFamily>(rDescr.Family) );
227 if ( static_cast<rtl_TextEncoding>(rDescr.CharSet) != RTL_TEXTENCODING_DONTKNOW )
228 aFont.SetCharSet( static_cast<rtl_TextEncoding>(rDescr.CharSet) );
229 if ( static_cast<FontPitch>(rDescr.Pitch) != PITCH_DONTKNOW )
230 aFont.SetPitch( static_cast<FontPitch>(rDescr.Pitch) );
231 if ( rDescr.CharacterWidth )
232 aFont.SetWidthType(vcl::unohelper::ConvertFontWidth(rDescr.CharacterWidth));
233 if ( rDescr.Weight )
234 aFont.SetWeight(vcl::unohelper::ConvertFontWeight(rDescr.Weight));
235 if ( rDescr.Slant != css::awt::FontSlant_DONTKNOW )
236 aFont.SetItalic(vcl::unohelper::ConvertFontSlant(rDescr.Slant));
237 if ( static_cast<FontLineStyle>(rDescr.Underline) != LINESTYLE_DONTKNOW )
238 aFont.SetUnderline( static_cast<FontLineStyle>(rDescr.Underline) );
239 if ( static_cast<FontStrikeout>(rDescr.Strikeout) != STRIKEOUT_DONTKNOW )
240 aFont.SetStrikeout( static_cast<FontStrikeout>(rDescr.Strikeout) );
242 // Not DONTKNOW
243 aFont.SetOrientation( Degree10(static_cast<sal_Int16>(rDescr.Orientation * 10)) );
244 aFont.SetKerning( static_cast<FontKerning>(rDescr.Kerning) );
245 aFont.SetWordLineMode( rDescr.WordLineMode );
247 return aFont;
250 vcl::Font VCLUnoHelper::CreateFont( const css::uno::Reference< css::awt::XFont >& rxFont )
252 vcl::Font aFont;
253 VCLXFont* pVCLXFont = dynamic_cast<VCLXFont*>( rxFont.get() );
254 if ( pVCLXFont )
255 aFont = pVCLXFont->GetFont();
256 return aFont;
260 css::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric )
262 css::awt::SimpleFontMetric aFM;
263 aFM.Ascent = static_cast<sal_Int16>(rFontMetric.GetAscent());
264 aFM.Descent = static_cast<sal_Int16>(rFontMetric.GetDescent());
265 aFM.Leading = static_cast<sal_Int16>(rFontMetric.GetInternalLeading());
266 aFM.Slant = static_cast<sal_Int16>(rFontMetric.GetSlant());
267 aFM.FirstChar = 0x0020;
268 aFM.LastChar = 0xFFFD;
269 return aFM;
272 bool VCLUnoHelper::IsZero(const css::awt::Rectangle& rRect)
274 return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
277 MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
279 switch( nUnoEmbedMapUnit )
281 case css::embed::EmbedMapUnits::ONE_100TH_MM:
282 return MapUnit::Map100thMM;
283 case css::embed::EmbedMapUnits::ONE_10TH_MM:
284 return MapUnit::Map10thMM;
285 case css::embed::EmbedMapUnits::ONE_MM:
286 return MapUnit::MapMM;
287 case css::embed::EmbedMapUnits::ONE_CM:
288 return MapUnit::MapCM;
289 case css::embed::EmbedMapUnits::ONE_1000TH_INCH:
290 return MapUnit::Map1000thInch;
291 case css::embed::EmbedMapUnits::ONE_100TH_INCH:
292 return MapUnit::Map100thInch;
293 case css::embed::EmbedMapUnits::ONE_10TH_INCH:
294 return MapUnit::Map10thInch;
295 case css::embed::EmbedMapUnits::ONE_INCH:
296 return MapUnit::MapInch;
297 case css::embed::EmbedMapUnits::POINT:
298 return MapUnit::MapPoint;
299 case css::embed::EmbedMapUnits::TWIP:
300 return MapUnit::MapTwip;
301 case css::embed::EmbedMapUnits::PIXEL:
302 return MapUnit::MapPixel;
305 OSL_FAIL( "Unexpected UNO map mode is provided!" );
306 return MapUnit::LASTENUMDUMMY;
309 sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit )
311 switch( nVCLMapUnit )
313 case MapUnit::Map100thMM:
314 return css::embed::EmbedMapUnits::ONE_100TH_MM;
315 case MapUnit::Map10thMM:
316 return css::embed::EmbedMapUnits::ONE_10TH_MM;
317 case MapUnit::MapMM:
318 return css::embed::EmbedMapUnits::ONE_MM;
319 case MapUnit::MapCM:
320 return css::embed::EmbedMapUnits::ONE_CM;
321 case MapUnit::Map1000thInch:
322 return css::embed::EmbedMapUnits::ONE_1000TH_INCH;
323 case MapUnit::Map100thInch:
324 return css::embed::EmbedMapUnits::ONE_100TH_INCH;
325 case MapUnit::Map10thInch:
326 return css::embed::EmbedMapUnits::ONE_10TH_INCH;
327 case MapUnit::MapInch:
328 return css::embed::EmbedMapUnits::ONE_INCH;
329 case MapUnit::MapPoint:
330 return css::embed::EmbedMapUnits::POINT;
331 case MapUnit::MapTwip:
332 return css::embed::EmbedMapUnits::TWIP;
333 case MapUnit::MapPixel:
334 return css::embed::EmbedMapUnits::PIXEL;
335 default: ; // avoid compiler warning
338 OSL_FAIL( "Unexpected VCL map mode is provided!" );
339 return -1;
342 using namespace ::com::sun::star::util;
345 namespace
347 enum UnitConversionDirection
349 FieldUnitToMeasurementUnit,
350 MeasurementUnitToFieldUnit
353 sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor )
355 static struct _unit_table
357 FieldUnit eFieldUnit;
358 sal_Int16 nMeasurementUnit;
359 sal_Int16 nFieldToMeasureFactor;
360 } const aUnits[] = {
361 { FieldUnit::NONE, -1 , -1},
362 { FieldUnit::MM, MeasureUnit::MM, 1 }, // must precede MM_10TH
363 { FieldUnit::MM, MeasureUnit::MM_10TH, 10 },
364 { FieldUnit::MM_100TH, MeasureUnit::MM_100TH, 1 },
365 { FieldUnit::CM, MeasureUnit::CM, 1 },
366 { FieldUnit::M, MeasureUnit::M, 1 },
367 { FieldUnit::KM, MeasureUnit::KM, 1 },
368 { FieldUnit::TWIP, MeasureUnit::TWIP, 1 },
369 { FieldUnit::POINT, MeasureUnit::POINT, 1 },
370 { FieldUnit::PICA, MeasureUnit::PICA, 1 },
371 { FieldUnit::INCH, MeasureUnit::INCH, 1 }, // must precede INCH_*TH
372 { FieldUnit::INCH, MeasureUnit::INCH_10TH, 10 },
373 { FieldUnit::INCH, MeasureUnit::INCH_100TH, 100 },
374 { FieldUnit::INCH, MeasureUnit::INCH_1000TH, 1000 },
375 { FieldUnit::FOOT, MeasureUnit::FOOT, 1 },
376 { FieldUnit::MILE, MeasureUnit::MILE, 1 },
378 for (auto & aUnit : aUnits)
380 if ( eDirection == FieldUnitToMeasurementUnit )
382 if ( ( aUnit.eFieldUnit == static_cast<FieldUnit>(_nUnit) ) && ( aUnit.nFieldToMeasureFactor == _rFieldToUNOValueFactor ) )
383 return aUnit.nMeasurementUnit;
385 else
387 if ( aUnit.nMeasurementUnit == _nUnit )
389 _rFieldToUNOValueFactor = aUnit.nFieldToMeasureFactor;
390 return static_cast<sal_Int16>(aUnit.eFieldUnit);
394 if ( eDirection == FieldUnitToMeasurementUnit )
395 return -1;
397 _rFieldToUNOValueFactor = 1;
398 return sal_Int16(FieldUnit::NONE);
402 //= MeasurementUnitConversion
405 sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor )
407 return convertMeasurementUnit( static_cast<sal_Int16>(_nFieldUnit), FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor );
411 FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor )
413 return static_cast<FieldUnit>(convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor ));
417 MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit)
419 MapUnit eMode;
420 switch(_nMeasureUnit)
422 case css::util::MeasureUnit::MM_100TH:
423 eMode = MapUnit::Map100thMM;
424 break;
426 case css::util::MeasureUnit::MM_10TH:
427 eMode = MapUnit::Map10thMM;
428 break;
430 case css::util::MeasureUnit::MM:
431 eMode = MapUnit::MapMM;
432 break;
434 case css::util::MeasureUnit::CM:
435 eMode = MapUnit::MapCM;
436 break;
438 case css::util::MeasureUnit::INCH_1000TH:
439 eMode = MapUnit::Map1000thInch;
440 break;
442 case css::util::MeasureUnit::INCH_100TH:
443 eMode = MapUnit::Map100thInch;
444 break;
446 case css::util::MeasureUnit::INCH_10TH:
447 eMode = MapUnit::Map10thInch;
448 break;
450 case css::util::MeasureUnit::INCH:
451 eMode = MapUnit::MapInch;
452 break;
454 case css::util::MeasureUnit::POINT:
455 eMode = MapUnit::MapPoint;
456 break;
458 case css::util::MeasureUnit::TWIP:
459 eMode = MapUnit::MapTwip;
460 break;
462 case css::util::MeasureUnit::PIXEL:
463 eMode = MapUnit::MapPixel;
464 break;
466 case css::util::MeasureUnit::APPFONT:
467 eMode = MapUnit::MapAppFont;
468 break;
470 case css::util::MeasureUnit::SYSFONT:
471 eMode = MapUnit::MapSysFont;
472 break;
474 default:
475 throw css::lang::IllegalArgumentException("Unsupported measure unit.", nullptr, 1 );
477 return eMode;
480 ::Size VCLUnoHelper::ConvertToVCLSize(css::awt::Size const& _aSize)
482 ::Size aVCLSize(_aSize.Width, _aSize.Height);
483 return aVCLSize;
486 css::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
488 css::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
489 return aAWTSize;
493 ::Point VCLUnoHelper::ConvertToVCLPoint(css::awt::Point const& _aPoint)
495 ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
496 return aVCLPoint;
499 css::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
501 css::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
502 return aAWTPoint;
505 ::tools::Rectangle VCLUnoHelper::ConvertToVCLRect( css::awt::Rectangle const & _rRect )
507 return ::tools::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 );
510 css::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::tools::Rectangle const & _rRect )
512 return css::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() );
515 awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
517 awt::MouseEvent aMouseEvent;
518 aMouseEvent.Source = _rxContext;
520 aMouseEvent.Modifiers = 0;
521 if ( _rVclEvent.IsShift() )
522 aMouseEvent.Modifiers |= css::awt::KeyModifier::SHIFT;
523 if ( _rVclEvent.IsMod1() )
524 aMouseEvent.Modifiers |= css::awt::KeyModifier::MOD1;
525 if ( _rVclEvent.IsMod2() )
526 aMouseEvent.Modifiers |= css::awt::KeyModifier::MOD2;
528 aMouseEvent.Buttons = 0;
529 if ( _rVclEvent.IsLeft() )
530 aMouseEvent.Buttons |= css::awt::MouseButton::LEFT;
531 if ( _rVclEvent.IsRight() )
532 aMouseEvent.Buttons |= css::awt::MouseButton::RIGHT;
533 if ( _rVclEvent.IsMiddle() )
534 aMouseEvent.Buttons |= css::awt::MouseButton::MIDDLE;
536 aMouseEvent.X = _rVclEvent.GetPosPixel().X();
537 aMouseEvent.Y = _rVclEvent.GetPosPixel().Y();
538 aMouseEvent.ClickCount = _rVclEvent.GetClicks();
539 aMouseEvent.PopupTrigger = false;
541 return aMouseEvent;
544 ::MouseEvent VCLUnoHelper::createVCLMouseEvent( const awt::MouseEvent& _rAwtEvent )
546 ::MouseEvent aMouseEvent( Point( _rAwtEvent.X, _rAwtEvent.Y ), _rAwtEvent.ClickCount,
547 ::MouseEventModifiers::NONE, _rAwtEvent.Buttons, _rAwtEvent.Modifiers );
549 return aMouseEvent;
552 awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
554 awt::KeyEvent aKeyEvent;
555 aKeyEvent.Source = _rxContext;
557 aKeyEvent.Modifiers = 0;
558 if ( _rVclEvent.GetKeyCode().IsShift() )
559 aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT;
560 if ( _rVclEvent.GetKeyCode().IsMod1() )
561 aKeyEvent.Modifiers |= awt::KeyModifier::MOD1;
562 if ( _rVclEvent.GetKeyCode().IsMod2() )
563 aKeyEvent.Modifiers |= awt::KeyModifier::MOD2;
564 if ( _rVclEvent.GetKeyCode().IsMod3() )
565 aKeyEvent.Modifiers |= awt::KeyModifier::MOD3;
567 aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode();
568 aKeyEvent.KeyChar = _rVclEvent.GetCharCode();
569 aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction());
571 return aKeyEvent;
574 ::KeyEvent VCLUnoHelper::createVCLKeyEvent( const awt::KeyEvent& _rAwtEvent )
576 sal_Unicode nChar = _rAwtEvent.KeyChar;
577 vcl::KeyCode aKeyCode( _rAwtEvent.KeyCode, _rAwtEvent.Modifiers & awt::KeyModifier::SHIFT,
578 _rAwtEvent.Modifiers & awt::KeyModifier::MOD1,
579 _rAwtEvent.Modifiers & awt::KeyModifier::MOD2,
580 _rAwtEvent.Modifiers & awt::KeyModifier::MOD3 );
582 return ::KeyEvent (nChar, aKeyCode);
586 ::PointerStyle VCLUnoHelper::getMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer)
588 ::PointerStyle eType = ::PointerStyle::Arrow; // default ?
589 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer);
590 if (pWindow)
591 eType = pWindow->GetPointer();
592 return eType;
595 void VCLUnoHelper::setMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer, ::PointerStyle ePointer)
597 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer);
598 if (!pWindow)
599 return;
600 pWindow->SetPointer(ePointer);
603 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */