LibreOffice Module toolkit (master) 1
vclunohelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
41#include <awt/vclxbitmap.hxx>
42#include <awt/vclxregion.hxx>
44#include <awt/vclxgraphics.hxx>
49
50#include <com/sun/star/awt/Toolkit.hpp>
51#include <com/sun/star/awt/Size.hpp>
52#include <com/sun/star/awt/Point.hpp>
53
54using namespace ::com::sun::star;
55
56
57uno::Reference< css::awt::XToolkit> VCLUnoHelper::CreateToolkit()
58{
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;
62}
63
64BitmapEx VCLUnoHelper::GetBitmap( const css::uno::Reference< css::awt::XBitmap>& rxBitmap )
65{
66 BitmapEx aBmp;
67
68 css::uno::Reference< css::graphic::XGraphic > xGraphic( rxBitmap, css::uno::UNO_QUERY );
69 if( xGraphic.is() )
70 {
71 Graphic aGraphic( xGraphic );
72 aBmp = aGraphic.GetBitmapEx();
73 }
74 else if ( rxBitmap.is() )
75 {
76 VCLXBitmap* pVCLBitmap = dynamic_cast<VCLXBitmap*>( rxBitmap.get() );
77 if ( pVCLBitmap )
78 aBmp = pVCLBitmap->GetBitmap();
79 else
80 {
81 Bitmap aDIB, aMask;
82 {
83 css::uno::Sequence<sal_Int8> aBytes = rxBitmap->getDIB();
84 SvMemoryStream aMem( aBytes.getArray(), aBytes.getLength(), StreamMode::READ );
85 ReadDIB(aDIB, aMem, true);
86 }
87 {
88 css::uno::Sequence<sal_Int8> aBytes = rxBitmap->getMaskDIB();
89 SvMemoryStream aMem( aBytes.getArray(), aBytes.getLength(), StreamMode::READ );
90 ReadDIB(aMask, aMem, true);
91 }
92 aMask.Invert(); // Convert from transparency to alpha
93 aBmp = BitmapEx( aDIB, aMask );
94 }
95 }
96 return aBmp;
97}
98
99css::uno::Reference< css::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
100{
101 Graphic aGraphic( rBitmap );
102 css::uno::Reference< css::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), css::uno::UNO_QUERY );
103 return xBmp;
104}
105
106vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow>& rxWindow )
107{
108 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
109 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
110}
111
112vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow2>& rxWindow )
113{
114 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
115 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
116}
117
118vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindowPeer>& rxWindow )
119{
120 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() );
121 return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr;
122}
123
124vcl::Region VCLUnoHelper::GetRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion )
125{
126 vcl::Region aRegion;
127 VCLXRegion* pVCLRegion = dynamic_cast<VCLXRegion*>( rxRegion.get() );
128 if ( pVCLRegion )
129 aRegion = pVCLRegion->GetRegion();
130 else
131 {
132 const css::uno::Sequence< css::awt::Rectangle > aRects = rxRegion->getRectangles();
133 for ( const auto& rRect : aRects )
134 aRegion.Union( VCLRectangle( rRect ) );
135 }
136 return aRegion;
137}
138
139css::uno::Reference< css::awt::XWindow> VCLUnoHelper::GetInterface( vcl::Window* pWindow )
140{
141 css::uno::Reference< css::awt::XWindow > xWin;
142 if ( pWindow )
143 {
144 css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
145 xWin.set(xPeer, css::uno::UNO_QUERY);
146 }
147 return xWin;
148}
149
150OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XDevice>& rxDevice )
151{
152 VclPtr<OutputDevice> pOutDev;
153 VCLXDevice* pDev = dynamic_cast<VCLXDevice*>( rxDevice.get() );
154 if ( pDev )
155 pOutDev = pDev->GetOutputDevice();
156 return pOutDev;
157}
158
159OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XGraphics>& rxGraphics )
160{
161 OutputDevice* pOutDev = nullptr;
162 VCLXGraphics* pGrf = dynamic_cast<VCLXGraphics*>( rxGraphics.get() );
163 if ( pGrf )
164 pOutDev = pGrf->GetOutputDevice();
165 return pOutDev;
166}
167
168tools::Polygon VCLUnoHelper::CreatePolygon( const css::uno::Sequence< sal_Int32 >& DataX,
169 const css::uno::Sequence< sal_Int32 >& DataY )
170{
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++ )
176 {
177 Point aPnt;
178 aPnt.setX( pDataX[n] );
179 aPnt.setY( pDataY[n] );
180 aPoly[n] = aPnt;
181 }
182 return aPoly;
183}
184
185css::uno::Reference< css::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( vcl::Window* pWindow )
186{
188
189 rtl::Reference<UnoControlModel> pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
190 pContainer->setModel( pContainerModel );
191
192 return pContainer;
193}
194
195css::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const vcl::Font& rFont )
196{
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;
215}
216
217vcl::Font VCLUnoHelper::CreateFont( const css::awt::FontDescriptor& rDescr, const vcl::Font& rInitFont )
218{
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) );
242
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 );
247
248 return aFont;
249}
250
251vcl::Font VCLUnoHelper::CreateFont( const css::uno::Reference< css::awt::XFont >& rxFont )
252{
253 vcl::Font aFont;
254 VCLXFont* pVCLXFont = dynamic_cast<VCLXFont*>( rxFont.get() );
255 if ( pVCLXFont )
256 aFont = pVCLXFont->GetFont();
257 return aFont;
258}
259
260
261css::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric )
262{
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;
271}
272
273bool VCLUnoHelper::IsZero(const css::awt::Rectangle& rRect)
274{
275 return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
276}
277
278MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
279{
280 switch( nUnoEmbedMapUnit )
281 {
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;
304 }
305
306 OSL_FAIL( "Unexpected UNO map mode is provided!" );
307 return MapUnit::LASTENUMDUMMY;
308}
309
311{
312 switch( nVCLMapUnit )
313 {
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
337 }
338
339 OSL_FAIL( "Unexpected VCL map mode is provided!" );
340 return -1;
341}
342
343using namespace ::com::sun::star::util;
344
345
346namespace
347{
348 enum UnitConversionDirection
349 {
350 FieldUnitToMeasurementUnit,
351 MeasurementUnitToFieldUnit
352 };
353
354 sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor )
355 {
356 static struct _unit_table
357 {
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 },
378 };
379 for (auto & aUnit : aUnits)
380 {
381 if ( eDirection == FieldUnitToMeasurementUnit )
382 {
383 if ( ( aUnit.eFieldUnit == static_cast<FieldUnit>(_nUnit) ) && ( aUnit.nFieldToMeasureFactor == _rFieldToUNOValueFactor ) )
384 return aUnit.nMeasurementUnit;
385 }
386 else
387 {
388 if ( aUnit.nMeasurementUnit == _nUnit )
389 {
390 _rFieldToUNOValueFactor = aUnit.nFieldToMeasureFactor;
391 return static_cast<sal_Int16>(aUnit.eFieldUnit);
392 }
393 }
394 }
395 if ( eDirection == FieldUnitToMeasurementUnit )
396 return -1;
397
398 _rFieldToUNOValueFactor = 1;
399 return sal_Int16(FieldUnit::NONE);
400 }
401}
402
403//= MeasurementUnitConversion
404
405
406sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor )
407{
408 return convertMeasurementUnit( static_cast<sal_Int16>(_nFieldUnit), FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor );
409}
410
411
412FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor )
413{
414 return static_cast<FieldUnit>(convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor ));
415}
416
417
418MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit)
419{
421 switch(_nMeasureUnit)
422 {
423 case css::util::MeasureUnit::MM_100TH:
424 eMode = MapUnit::Map100thMM;
425 break;
426
427 case css::util::MeasureUnit::MM_10TH:
428 eMode = MapUnit::Map10thMM;
429 break;
430
431 case css::util::MeasureUnit::MM:
432 eMode = MapUnit::MapMM;
433 break;
434
435 case css::util::MeasureUnit::CM:
436 eMode = MapUnit::MapCM;
437 break;
438
439 case css::util::MeasureUnit::INCH_1000TH:
440 eMode = MapUnit::Map1000thInch;
441 break;
442
443 case css::util::MeasureUnit::INCH_100TH:
444 eMode = MapUnit::Map100thInch;
445 break;
446
447 case css::util::MeasureUnit::INCH_10TH:
448 eMode = MapUnit::Map10thInch;
449 break;
450
451 case css::util::MeasureUnit::INCH:
452 eMode = MapUnit::MapInch;
453 break;
454
455 case css::util::MeasureUnit::POINT:
456 eMode = MapUnit::MapPoint;
457 break;
458
459 case css::util::MeasureUnit::TWIP:
460 eMode = MapUnit::MapTwip;
461 break;
462
463 case css::util::MeasureUnit::PIXEL:
464 eMode = MapUnit::MapPixel;
465 break;
466
467 case css::util::MeasureUnit::APPFONT:
468 eMode = MapUnit::MapAppFont;
469 break;
470
471 case css::util::MeasureUnit::SYSFONT:
472 eMode = MapUnit::MapSysFont;
473 break;
474
475 default:
476 throw css::lang::IllegalArgumentException("Unsupported measure unit.", nullptr, 1 );
477 }
478 return eMode;
479}
480
481::Size VCLUnoHelper::ConvertToVCLSize(css::awt::Size const& _aSize)
482{
483 ::Size aVCLSize(_aSize.Width, _aSize.Height);
484 return aVCLSize;
485}
486
487css::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
488{
489 css::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
490 return aAWTSize;
491}
492
493
494::Point VCLUnoHelper::ConvertToVCLPoint(css::awt::Point const& _aPoint)
495{
496 ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
497 return aVCLPoint;
498}
499
500css::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
501{
502 css::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
503 return aAWTPoint;
504}
505
506::tools::Rectangle VCLUnoHelper::ConvertToVCLRect( css::awt::Rectangle const & _rRect )
507{
508 return ::tools::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 );
509}
510
511css::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::tools::Rectangle const & _rRect )
512{
513 return css::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() );
514}
515
516awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
517{
518 awt::MouseEvent aMouseEvent;
519 aMouseEvent.Source = _rxContext;
520
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;
528
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;
536
537 aMouseEvent.X = _rVclEvent.GetPosPixel().X();
538 aMouseEvent.Y = _rVclEvent.GetPosPixel().Y();
539 aMouseEvent.ClickCount = _rVclEvent.GetClicks();
540 aMouseEvent.PopupTrigger = false;
541
542 return aMouseEvent;
543}
544
545::MouseEvent VCLUnoHelper::createVCLMouseEvent( const awt::MouseEvent& _rAwtEvent )
546{
547 ::MouseEvent aMouseEvent( Point( _rAwtEvent.X, _rAwtEvent.Y ), _rAwtEvent.ClickCount,
548 ::MouseEventModifiers::NONE, _rAwtEvent.Buttons, _rAwtEvent.Modifiers );
549
550 return aMouseEvent;
551}
552
553awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
554{
555 awt::KeyEvent aKeyEvent;
556 aKeyEvent.Source = _rxContext;
557
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;
567
568 aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode();
569 aKeyEvent.KeyChar = _rVclEvent.GetCharCode();
570 aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction());
571
572 return aKeyEvent;
573}
574
575::KeyEvent VCLUnoHelper::createVCLKeyEvent( const awt::KeyEvent& _rAwtEvent )
576{
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 );
582
583 return ::KeyEvent (nChar, aKeyCode);
584
585}
586
587::PointerStyle VCLUnoHelper::getMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer)
588{
589 ::PointerStyle eType = ::PointerStyle::Arrow; // default ?
590 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer);
591 if (pWindow)
592 eType = pWindow->GetPointer();
593 return eType;
594}
595
596void VCLUnoHelper::setMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer, ::PointerStyle ePointer)
597{
598 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer);
599 if (!pWindow)
600 return;
601 pWindow->SetPointer(ePointer);
602}
603
604/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Invert()
tools::Long GetDescent() const
tools::Long GetAscent() const
tools::Long GetInternalLeading() const
tools::Long GetSlant() const
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
::KeyEvent createVCLKeyEvent(const css::awt::KeyEvent &_rAwtEvent)
static css::awt::SimpleFontMetric CreateFontMetric(const FontMetric &rFontMetric)
static css::uno::Reference< css::awt::XToolkit > CreateToolkit()
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
static css::awt::Rectangle ConvertToAWTRect(::tools::Rectangle const &_rRect)
static css::awt::FontDescriptor CreateFontDescriptor(const vcl::Font &rFont)
convert Font to css::awt::FontDescriptor
static sal_Int16 ConvertToMeasurementUnit(FieldUnit _nFieldUnit, sal_Int16 _rFieldToUNOValueFactor)
small helper to convert between MeasurementUnit and FieldUnit
static css::awt::KeyEvent createKeyEvent(const ::KeyEvent &_rVclEvent, const css::uno::Reference< css::uno::XInterface > &_rxContext)
::PointerStyle getMousePointer(const css::uno::Reference< css::awt::XWindowPeer > &rWindowPeer)
static OutputDevice * GetOutputDevice(const css::uno::Reference< css::awt::XDevice > &rxDevice)
static sal_Int32 VCL2UnoEmbedMapUnit(MapUnit nVCLMapUnit)
static void setMousePointer(const css::uno::Reference< css::awt::XWindowPeer > &rWindowPeer, ::PointerStyle mousepointer)
static vcl::Region GetRegion(const css::uno::Reference< css::awt::XRegion > &rxRegion)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static BitmapEx GetBitmap(const css::uno::Reference< css::awt::XBitmap > &rxBitmap)
static css::uno::Reference< css::awt::XControlContainer > CreateControlContainer(vcl::Window *pWindow)
static css::awt::Size ConvertToAWTSize(::Size const &_aSize)
static css::awt::Point ConvertToAWTPoint(::Point const &_aPoint)
static MapUnit ConvertToMapModeUnit(sal_Int16 _nMeasureUnit)
static css::uno::Reference< css::awt::XBitmap > CreateBitmap(const BitmapEx &rBitmap)
static tools::Polygon CreatePolygon(const css::uno::Sequence< sal_Int32 > &DataX, const css::uno::Sequence< sal_Int32 > &DataY)
static css::awt::MouseEvent createMouseEvent(const ::MouseEvent &_rVclEvent, const css::uno::Reference< css::uno::XInterface > &_rxContext)
static FieldUnit ConvertToFieldUnit(sal_Int16 _nMeasurementUnit, sal_Int16 &_rFieldToUNOValueFactor)
::Size ConvertToVCLSize(css::awt::Size const &_aSize)
::tools::Rectangle ConvertToVCLRect(css::awt::Rectangle const &_rRect)
static bool IsZero(const css::awt::Rectangle &rRect)
::Point ConvertToVCLPoint(css::awt::Point const &_aPoint)
static vcl::Font CreateFont(const css::awt::FontDescriptor &rDescr, const vcl::Font &rInitFont)
::MouseEvent createVCLMouseEvent(const css::awt::MouseEvent &_rAwtEvent)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
const BitmapEx & GetBitmap() const
Definition: vclxbitmap.hxx:50
A UNO wrapper for the VCL OutputDevice.
Definition: vclxdevice.hxx:37
const VclPtr< OutputDevice > & GetOutputDevice() const
Definition: vclxdevice.hxx:49
const vcl::Font & GetFont() const
Definition: vclxfont.hxx:55
OutputDevice * GetOutputDevice() const
const vcl::Region & GetRegion() const
Definition: vclxregion.hxx:43
vcl::Window * GetWindow() const
Definition: vclxwindow.hxx:131
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
void SetFontSize(const Size &)
void SetOrientation(Degree10 nLineOrientation)
FontFamily GetFamilyType()
FontWidth GetWidthType()
void SetWidthType(FontWidth)
void SetStyleName(const OUString &rStyleName)
void SetWordLineMode(bool bWordLine)
void SetPitch(FontPitch ePitch)
bool IsKerning() const
const OUString & GetStyleName() const
FontStrikeout GetStrikeout() const
FontItalic GetItalic()
void SetItalic(FontItalic)
void SetWeight(FontWeight)
const OUString & GetFamilyName() const
void SetFamily(FontFamily)
void SetUnderline(FontLineStyle)
void SetCharSet(rtl_TextEncoding)
const Size & GetFontSize() const
void SetKerning(FontKerning nKerning)
FontPitch GetPitch()
FontWeight GetWeight()
void SetFamilyName(const OUString &rFamilyName)
FontLineStyle GetUnderline() const
rtl_TextEncoding GetCharSet() const
bool IsWordLineMode() const
Degree10 GetOrientation() const
void SetStrikeout(FontStrikeout)
void Union(const tools::Rectangle &rRegion)
virtual css::uno::Reference< css::awt::XVclWindowPeer > GetComponentInterface(bool bCreate=true)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
Definition: convert.hxx:54
bool VCL_DLLPUBLIC ReadDIB(Bitmap &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat=false)
FieldUnit
DocumentType eType
FontKerning
FontLineStyle
LINESTYLE_DONTKNOW
FontStrikeout
STRIKEOUT_DONTKNOW
FontPitch
PITCH_DONTKNOW
FontFamily
FAMILY_DONTKNOW
Mode eMode
sal_Int64 n
MapUnit
VCL_DLLPUBLIC css::awt::FontSlant ConvertFontSlant(FontItalic eWeight)
VCL_DLLPUBLIC float ConvertFontWidth(FontWidth eWidth)
VCL_DLLPUBLIC float ConvertFontWeight(FontWeight eWeight)
PointerStyle
UNDERLYING_TYPE get() const
sal_uInt16 sal_Unicode