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 <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
);
64 BitmapEx
VCLUnoHelper::GetBitmap( const css::uno::Reference
< css::awt::XBitmap
>& rxBitmap
)
68 css::uno::Reference
< css::graphic::XGraphic
> xGraphic( rxBitmap
, css::uno::UNO_QUERY
);
71 Graphic
aGraphic( xGraphic
);
72 aBmp
= aGraphic
.GetBitmapEx();
74 else if ( rxBitmap
.is() )
76 VCLXBitmap
* pVCLBitmap
= dynamic_cast<VCLXBitmap
*>( rxBitmap
.get() );
78 aBmp
= pVCLBitmap
->GetBitmap();
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
);
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
);
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
)
127 VCLXRegion
* pVCLRegion
= dynamic_cast<VCLXRegion
*>( rxRegion
.get() );
129 aRegion
= pVCLRegion
->GetRegion();
132 const css::uno::Sequence
< css::awt::Rectangle
> aRects
= rxRegion
->getRectangles();
133 for ( const auto& rRect
: aRects
)
134 aRegion
.Union( VCLRectangle( rRect
) );
139 css::uno::Reference
< css::awt::XWindow
> VCLUnoHelper::GetInterface( vcl::Window
* pWindow
)
141 css::uno::Reference
< css::awt::XWindow
> xWin
;
144 css::uno::Reference
< css::awt::XWindowPeer
> xPeer
= pWindow
->GetComponentInterface();
145 xWin
.set(xPeer
, css::uno::UNO_QUERY
);
150 OutputDevice
* VCLUnoHelper::GetOutputDevice( const css::uno::Reference
< css::awt::XDevice
>& rxDevice
)
152 VclPtr
<OutputDevice
> pOutDev
;
153 VCLXDevice
* pDev
= dynamic_cast<VCLXDevice
*>( rxDevice
.get() );
155 pOutDev
= pDev
->GetOutputDevice();
159 OutputDevice
* VCLUnoHelper::GetOutputDevice( const css::uno::Reference
< css::awt::XGraphics
>& rxGraphics
)
161 OutputDevice
* pOutDev
= nullptr;
162 VCLXGraphics
* pGrf
= dynamic_cast<VCLXGraphics
*>( rxGraphics
.get() );
164 pOutDev
= pGrf
->GetOutputDevice();
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
++ )
178 aPnt
.setX( pDataX
[n
] );
179 aPnt
.setY( pDataY
[n
] );
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
);
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...
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
);
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
));
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
) );
244 aFont
.SetOrientation( Degree10(static_cast<sal_Int16
>(rDescr
.Orientation
* 10)) );
245 aFont
.SetKerning( static_cast<FontKerning
>(rDescr
.Kerning
) );
246 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
251 vcl::Font
VCLUnoHelper::CreateFont( const css::uno::Reference
< css::awt::XFont
>& rxFont
)
254 VCLXFont
* pVCLXFont
= dynamic_cast<VCLXFont
*>( rxFont
.get() );
256 aFont
= pVCLXFont
->GetFont();
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;
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
;
319 return css::embed::EmbedMapUnits::ONE_MM
;
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!" );
343 using namespace ::com::sun::star::util
;
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
;
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
;
388 if ( aUnit
.nMeasurementUnit
== _nUnit
)
390 _rFieldToUNOValueFactor
= aUnit
.nFieldToMeasureFactor
;
391 return static_cast<sal_Int16
>(aUnit
.eFieldUnit
);
395 if ( eDirection
== FieldUnitToMeasurementUnit
)
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
)
421 switch(_nMeasureUnit
)
423 case css::util::MeasureUnit::MM_100TH
:
424 eMode
= MapUnit::Map100thMM
;
427 case css::util::MeasureUnit::MM_10TH
:
428 eMode
= MapUnit::Map10thMM
;
431 case css::util::MeasureUnit::MM
:
432 eMode
= MapUnit::MapMM
;
435 case css::util::MeasureUnit::CM
:
436 eMode
= MapUnit::MapCM
;
439 case css::util::MeasureUnit::INCH_1000TH
:
440 eMode
= MapUnit::Map1000thInch
;
443 case css::util::MeasureUnit::INCH_100TH
:
444 eMode
= MapUnit::Map100thInch
;
447 case css::util::MeasureUnit::INCH_10TH
:
448 eMode
= MapUnit::Map10thInch
;
451 case css::util::MeasureUnit::INCH
:
452 eMode
= MapUnit::MapInch
;
455 case css::util::MeasureUnit::POINT
:
456 eMode
= MapUnit::MapPoint
;
459 case css::util::MeasureUnit::TWIP
:
460 eMode
= MapUnit::MapTwip
;
463 case css::util::MeasureUnit::PIXEL
:
464 eMode
= MapUnit::MapPixel
;
467 case css::util::MeasureUnit::APPFONT
:
468 eMode
= MapUnit::MapAppFont
;
471 case css::util::MeasureUnit::SYSFONT
:
472 eMode
= MapUnit::MapSysFont
;
476 throw css::lang::IllegalArgumentException("Unsupported measure unit.", nullptr, 1 );
481 ::Size
VCLUnoHelper::ConvertToVCLSize(css::awt::Size
const& _aSize
)
483 ::Size
aVCLSize(_aSize
.Width
, _aSize
.Height
);
487 css::awt::Size
VCLUnoHelper::ConvertToAWTSize(::Size
/* VCLSize */ const& _aSize
)
489 css::awt::Size
aAWTSize(_aSize
.Width(), _aSize
.Height());
494 ::Point
VCLUnoHelper::ConvertToVCLPoint(css::awt::Point
const& _aPoint
)
496 ::Point
aVCLPoint(_aPoint
.X
, _aPoint
.Y
);
500 css::awt::Point
VCLUnoHelper::ConvertToAWTPoint(::Point
/* VCLPoint */ const& _aPoint
)
502 css::awt::Point
aAWTPoint(_aPoint
.X(), _aPoint
.Y());
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;
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
);
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());
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
);
592 eType
= pWindow
->GetPointer();
596 void VCLUnoHelper::setMousePointer(const css::uno::Reference
<css::awt::XWindowPeer
>& rWindowPeer
, ::PointerStyle ePointer
)
598 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(rWindowPeer
);
601 pWindow
->SetPointer(ePointer
);
604 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */