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 .
21 #include <tools/stream.hxx>
22 #include <vcl/bitmap.hxx>
23 #include <vcl/window.hxx>
24 #include <sal/macros.h>
25 #include <com/sun/star/util/MeasureUnit.hpp>
26 #include <com/sun/star/awt/XBitmap.hpp>
27 #include <com/sun/star/awt/XWindow.hpp>
28 #include <com/sun/star/awt/XDevice.hpp>
29 #include <com/sun/star/awt/XPointer.hpp>
30 #include <com/sun/star/awt/SimpleFontMetric.hpp>
31 #include <com/sun/star/awt/FontDescriptor.hpp>
32 #include <com/sun/star/awt/XControlContainer.hpp>
33 #include <com/sun/star/awt/FontWeight.hpp>
34 #include <com/sun/star/awt/FontWidth.hpp>
35 #include <com/sun/star/awt/KeyModifier.hpp>
36 #include <com/sun/star/awt/MouseButton.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/embed/EmbedMapUnits.hpp>
40 #include <com/sun/star/graphic/XGraphic.hpp>
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <toolkit/helper/convert.hxx>
44 #include <toolkit/awt/vclxbitmap.hxx>
45 #include <toolkit/awt/vclxregion.hxx>
46 #include <toolkit/awt/vclxwindow.hxx>
47 #include <toolkit/awt/vclxgraphics.hxx>
48 #include <toolkit/awt/vclxpointer.hxx>
49 #include <toolkit/awt/vclxfont.hxx>
50 #include <toolkit/controls/unocontrolcontainer.hxx>
51 #include <toolkit/controls/unocontrolcontainermodel.hxx>
53 #include <vcl/graph.hxx>
54 #include <comphelper/processfactory.hxx>
56 #include <com/sun/star/awt/Toolkit.hpp>
57 #include <com/sun/star/awt/Size.hpp>
58 #include <com/sun/star/awt/Point.hpp>
60 using namespace ::com::sun::star
;
62 // ----------------------------------------------------
64 // ----------------------------------------------------
66 uno::Reference
< ::com::sun::star::awt::XToolkit
> VCLUnoHelper::CreateToolkit()
68 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
69 uno::Reference
< awt::XToolkit
> xToolkit( awt::Toolkit::create(xContext
), uno::UNO_QUERY_THROW
);
73 BitmapEx
VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
>& rxBitmap
)
77 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> xGraphic( rxBitmap
, ::com::sun::star::uno::UNO_QUERY
);
80 Graphic
aGraphic( xGraphic
);
81 aBmp
= aGraphic
.GetBitmapEx();
83 else if ( rxBitmap
.is() )
85 VCLXBitmap
* pVCLBitmap
= VCLXBitmap::GetImplementation( rxBitmap
);
87 aBmp
= pVCLBitmap
->GetBitmap();
92 ::com::sun::star::uno::Sequence
<sal_Int8
> aBytes
= rxBitmap
->getDIB();
93 SvMemoryStream
aMem( (char*) aBytes
.getArray(), aBytes
.getLength(), STREAM_READ
);
97 ::com::sun::star::uno::Sequence
<sal_Int8
> aBytes
= rxBitmap
->getMaskDIB();
98 SvMemoryStream
aMem( (char*) aBytes
.getArray(), aBytes
.getLength(), STREAM_READ
);
101 aBmp
= BitmapEx( aDIB
, aMask
);
107 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> VCLUnoHelper::CreateBitmap( const BitmapEx
& rBitmap
)
109 Graphic
aGraphic( rBitmap
);
110 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> xBmp( aGraphic
.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY
);
114 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& rxWindow
)
116 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
117 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
120 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
>& rxWindow
)
122 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
123 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
126 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& rxWindow
)
128 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
129 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
132 Region
VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XRegion
>& rxRegion
)
135 VCLXRegion
* pVCLRegion
= VCLXRegion::GetImplementation( rxRegion
);
137 aRegion
= pVCLRegion
->GetRegion();
140 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::Rectangle
> aRects
= rxRegion
->getRectangles();
141 sal_Int32 nRects
= aRects
.getLength();
142 for ( sal_Int32 n
= 0; n
< nRects
; n
++ )
143 aRegion
.Union( VCLRectangle( aRects
.getArray()[n
] ) );
148 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> VCLUnoHelper::GetInterface( Window
* pWindow
)
150 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> xWin
;
153 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xPeer
= pWindow
->GetComponentInterface();
154 xWin
= xWin
.query( xPeer
);
159 OutputDevice
* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
>& rxDevice
)
161 OutputDevice
* pOutDev
= NULL
;
162 VCLXDevice
* pDev
= VCLXDevice::GetImplementation( rxDevice
);
164 pOutDev
= pDev
->GetOutputDevice();
168 OutputDevice
* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
>& rxGraphics
)
170 OutputDevice
* pOutDev
= NULL
;
171 VCLXGraphics
* pGrf
= VCLXGraphics::GetImplementation( rxGraphics
);
173 pOutDev
= pGrf
->GetOutputDevice();
177 Polygon
VCLUnoHelper::CreatePolygon( const ::com::sun::star::uno::Sequence
< sal_Int32
>& DataX
, const ::com::sun::star::uno::Sequence
< sal_Int32
>& DataY
)
179 sal_uInt32 nLen
= DataX
.getLength();
180 const sal_Int32
* pDataX
= DataX
.getConstArray();
181 const sal_Int32
* pDataY
= DataY
.getConstArray();
182 Polygon
aPoly( (sal_uInt16
) nLen
);
183 for ( sal_uInt16 n
= 0; n
< nLen
; n
++ )
186 aPnt
.X() = pDataX
[n
];
187 aPnt
.Y() = pDataY
[n
];
193 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> VCLUnoHelper::CreateControlContainer( Window
* pWindow
)
195 UnoControlContainer
* pContainer
= new UnoControlContainer( pWindow
->GetComponentInterface( sal_True
) );
196 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> x
= pContainer
;
198 UnoControlModel
* pContainerModel
= new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
199 pContainer
->setModel( (::com::sun::star::awt::XControlModel
*)pContainerModel
);
204 float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth
)
206 if( eWidth
== WIDTH_DONTKNOW
)
207 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
208 else if( eWidth
== WIDTH_ULTRA_CONDENSED
)
209 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED
;
210 else if( eWidth
== WIDTH_EXTRA_CONDENSED
)
211 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED
;
212 else if( eWidth
== WIDTH_CONDENSED
)
213 return ::com::sun::star::awt::FontWidth::CONDENSED
;
214 else if( eWidth
== WIDTH_SEMI_CONDENSED
)
215 return ::com::sun::star::awt::FontWidth::SEMICONDENSED
;
216 else if( eWidth
== WIDTH_NORMAL
)
217 return ::com::sun::star::awt::FontWidth::NORMAL
;
218 else if( eWidth
== WIDTH_SEMI_EXPANDED
)
219 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED
;
220 else if( eWidth
== WIDTH_EXPANDED
)
221 return ::com::sun::star::awt::FontWidth::EXPANDED
;
222 else if( eWidth
== WIDTH_EXTRA_EXPANDED
)
223 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
;
224 else if( eWidth
== WIDTH_ULTRA_EXPANDED
)
225 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
;
227 OSL_FAIL( "Unknown FontWidth" );
228 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
231 FontWidth
VCLUnoHelper::ConvertFontWidth( float f
)
233 if( f
<= ::com::sun::star::awt::FontWidth::DONTKNOW
)
234 return WIDTH_DONTKNOW
;
235 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRACONDENSED
)
236 return WIDTH_ULTRA_CONDENSED
;
237 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRACONDENSED
)
238 return WIDTH_EXTRA_CONDENSED
;
239 else if( f
<= ::com::sun::star::awt::FontWidth::CONDENSED
)
240 return WIDTH_CONDENSED
;
241 else if( f
<= ::com::sun::star::awt::FontWidth::SEMICONDENSED
)
242 return WIDTH_SEMI_CONDENSED
;
243 else if( f
<= ::com::sun::star::awt::FontWidth::NORMAL
)
245 else if( f
<= ::com::sun::star::awt::FontWidth::SEMIEXPANDED
)
246 return WIDTH_SEMI_EXPANDED
;
247 else if( f
<= ::com::sun::star::awt::FontWidth::EXPANDED
)
248 return WIDTH_EXPANDED
;
249 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
)
250 return WIDTH_EXTRA_EXPANDED
;
251 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
)
252 return WIDTH_ULTRA_EXPANDED
;
254 OSL_FAIL( "Unknown FontWidth" );
255 return WIDTH_DONTKNOW
;
258 float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight
)
260 if( eWeight
== WEIGHT_DONTKNOW
)
261 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
262 else if( eWeight
== WEIGHT_THIN
)
263 return ::com::sun::star::awt::FontWeight::THIN
;
264 else if( eWeight
== WEIGHT_ULTRALIGHT
)
265 return ::com::sun::star::awt::FontWeight::ULTRALIGHT
;
266 else if( eWeight
== WEIGHT_LIGHT
)
267 return ::com::sun::star::awt::FontWeight::LIGHT
;
268 else if( eWeight
== WEIGHT_SEMILIGHT
)
269 return ::com::sun::star::awt::FontWeight::SEMILIGHT
;
270 else if( ( eWeight
== WEIGHT_NORMAL
) || ( eWeight
== WEIGHT_MEDIUM
) )
271 return ::com::sun::star::awt::FontWeight::NORMAL
;
272 else if( eWeight
== WEIGHT_SEMIBOLD
)
273 return ::com::sun::star::awt::FontWeight::SEMIBOLD
;
274 else if( eWeight
== WEIGHT_BOLD
)
275 return ::com::sun::star::awt::FontWeight::BOLD
;
276 else if( eWeight
== WEIGHT_ULTRABOLD
)
277 return ::com::sun::star::awt::FontWeight::ULTRABOLD
;
278 else if( eWeight
== WEIGHT_BLACK
)
279 return ::com::sun::star::awt::FontWeight::BLACK
;
281 OSL_FAIL( "Unknown FontWeight" );
282 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
285 FontWeight
VCLUnoHelper::ConvertFontWeight( float f
)
287 if( f
<= ::com::sun::star::awt::FontWeight::DONTKNOW
)
288 return WEIGHT_DONTKNOW
;
289 else if( f
<= ::com::sun::star::awt::FontWeight::THIN
)
291 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRALIGHT
)
292 return WEIGHT_ULTRALIGHT
;
293 else if( f
<= ::com::sun::star::awt::FontWeight::LIGHT
)
295 else if( f
<= ::com::sun::star::awt::FontWeight::SEMILIGHT
)
296 return WEIGHT_SEMILIGHT
;
297 else if( f
<= ::com::sun::star::awt::FontWeight::NORMAL
)
298 return WEIGHT_NORMAL
;
299 else if( f
<= ::com::sun::star::awt::FontWeight::SEMIBOLD
)
300 return WEIGHT_SEMIBOLD
;
301 else if( f
<= ::com::sun::star::awt::FontWeight::BOLD
)
303 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRABOLD
)
304 return WEIGHT_ULTRABOLD
;
305 else if( f
<= ::com::sun::star::awt::FontWeight::BLACK
)
308 OSL_FAIL( "Unknown FontWeight" );
309 return WEIGHT_DONTKNOW
;
313 ::com::sun::star::awt::FontDescriptor
VCLUnoHelper::CreateFontDescriptor( const Font
& rFont
)
315 ::com::sun::star::awt::FontDescriptor aFD
;
316 aFD
.Name
= rFont
.GetName();
317 aFD
.StyleName
= rFont
.GetStyleName();
318 aFD
.Height
= (sal_Int16
)rFont
.GetSize().Height();
319 aFD
.Width
= (sal_Int16
)rFont
.GetSize().Width();
320 aFD
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamily());
321 aFD
.CharSet
= rFont
.GetCharSet();
322 aFD
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
323 aFD
.CharacterWidth
= VCLUnoHelper::ConvertFontWidth( rFont
.GetWidthType() );
324 aFD
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
325 aFD
.Slant
= (::com::sun::star::awt::FontSlant
)rFont
.GetItalic();
326 aFD
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
327 aFD
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
328 aFD
.Orientation
= rFont
.GetOrientation();
329 aFD
.Kerning
= rFont
.IsKerning();
330 aFD
.WordLineMode
= rFont
.IsWordLineMode();
331 aFD
.Type
= 0; // ??? => Nur an Metric...
335 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor
& rDescr
, const Font
& rInitFont
)
337 Font
aFont( rInitFont
);
338 if ( !rDescr
.Name
.isEmpty() )
339 aFont
.SetName( rDescr
.Name
);
340 if ( !rDescr
.StyleName
.isEmpty() )
341 aFont
.SetStyleName( rDescr
.StyleName
);
343 aFont
.SetSize( Size( rDescr
.Width
, rDescr
.Height
) );
344 if ( (FontFamily
)rDescr
.Family
!= FAMILY_DONTKNOW
)
345 aFont
.SetFamily( (FontFamily
)rDescr
.Family
);
346 if ( (CharSet
)rDescr
.CharSet
!= RTL_TEXTENCODING_DONTKNOW
)
347 aFont
.SetCharSet( (CharSet
)rDescr
.CharSet
);
348 if ( (FontPitch
)rDescr
.Pitch
!= PITCH_DONTKNOW
)
349 aFont
.SetPitch( (FontPitch
)rDescr
.Pitch
);
350 if ( rDescr
.CharacterWidth
)
351 aFont
.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr
.CharacterWidth
) );
353 aFont
.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr
.Weight
) );
354 if ( (FontItalic
)rDescr
.Slant
!= ITALIC_DONTKNOW
)
355 aFont
.SetItalic( (FontItalic
)rDescr
.Slant
);
356 if ( (FontUnderline
)rDescr
.Underline
!= UNDERLINE_DONTKNOW
)
357 aFont
.SetUnderline( (FontUnderline
)rDescr
.Underline
);
358 if ( (FontStrikeout
)rDescr
.Strikeout
!= STRIKEOUT_DONTKNOW
)
359 aFont
.SetStrikeout( (FontStrikeout
)rDescr
.Strikeout
);
362 aFont
.SetOrientation( (short)rDescr
.Orientation
);
363 aFont
.SetKerning( rDescr
.Kerning
);
364 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
369 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFont
>& rxFont
)
372 VCLXFont
* pVCLXFont
= VCLXFont::GetImplementation( rxFont
);
374 aFont
= pVCLXFont
->GetFont();
379 ::com::sun::star::awt::SimpleFontMetric
VCLUnoHelper::CreateFontMetric( const FontMetric
& rFontMetric
)
381 ::com::sun::star::awt::SimpleFontMetric aFM
;
382 aFM
.Ascent
= (sal_Int16
)rFontMetric
.GetAscent();
383 aFM
.Descent
= (sal_Int16
)rFontMetric
.GetDescent();
384 aFM
.Leading
= (sal_Int16
)rFontMetric
.GetIntLeading();
385 aFM
.Slant
= (sal_Int16
)rFontMetric
.GetSlant();
386 aFM
.FirstChar
= 0x0020;
387 aFM
.LastChar
= 0xFFFD;
391 sal_Bool
VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect
)
393 return ( !rRect
.X
&& !rRect
.Y
&& !rRect
.Width
&& !rRect
.Height
);
396 MapUnit
VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit
)
398 switch( nUnoEmbedMapUnit
)
400 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
:
402 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
:
404 case ::com::sun::star::embed::EmbedMapUnits::ONE_MM
:
406 case ::com::sun::star::embed::EmbedMapUnits::ONE_CM
:
408 case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
:
409 return MAP_1000TH_INCH
;
410 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
:
411 return MAP_100TH_INCH
;
412 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
:
413 return MAP_10TH_INCH
;
414 case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
:
416 case ::com::sun::star::embed::EmbedMapUnits::POINT
:
418 case ::com::sun::star::embed::EmbedMapUnits::TWIP
:
420 case ::com::sun::star::embed::EmbedMapUnits::PIXEL
:
424 OSL_FAIL( "Unexpected UNO map mode is provided!\n" );
425 return MAP_LASTENUMDUMMY
;
428 sal_Int32
VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit
)
430 switch( nVCLMapUnit
)
433 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
;
435 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
;
437 return ::com::sun::star::embed::EmbedMapUnits::ONE_MM
;
439 return ::com::sun::star::embed::EmbedMapUnits::ONE_CM
;
440 case MAP_1000TH_INCH
:
441 return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
;
443 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
;
445 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
;
447 return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
;
449 return ::com::sun::star::embed::EmbedMapUnits::POINT
;
451 return ::com::sun::star::embed::EmbedMapUnits::TWIP
;
453 return ::com::sun::star::embed::EmbedMapUnits::PIXEL
;
454 default: ; // avoid compiler warning
457 OSL_FAIL( "Unexpected VCL map mode is provided!\n" );
461 using namespace ::com::sun::star::util
;
463 //====================================================================
464 //= file-local helpers
465 //====================================================================
468 enum UnitConversionDirection
470 FieldUnitToMeasurementUnit
,
471 MeasurementUnitToFieldUnit
474 sal_Int16
convertMeasurementUnit( sal_Int16 _nUnit
, UnitConversionDirection eDirection
, sal_Int16
& _rFieldToUNOValueFactor
)
476 static struct _unit_table
478 FieldUnit eFieldUnit
;
479 sal_Int16 nMeasurementUnit
;
480 sal_Int16 nFieldToMeasureFactor
;
482 { FUNIT_NONE
, -1 , -1},
483 { FUNIT_MM
, MeasureUnit::MM
, 1 }, // must precede MM_10TH
484 { FUNIT_MM
, MeasureUnit::MM_10TH
, 10 },
485 { FUNIT_100TH_MM
, MeasureUnit::MM_100TH
, 1 },
486 { FUNIT_CM
, MeasureUnit::CM
, 1 },
487 { FUNIT_M
, MeasureUnit::M
, 1 },
488 { FUNIT_KM
, MeasureUnit::KM
, 1 },
489 { FUNIT_TWIP
, MeasureUnit::TWIP
, 1 },
490 { FUNIT_POINT
, MeasureUnit::POINT
, 1 },
491 { FUNIT_PICA
, MeasureUnit::PICA
, 1 },
492 { FUNIT_INCH
, MeasureUnit::INCH
, 1 }, // must precede INCH_*TH
493 { FUNIT_INCH
, MeasureUnit::INCH_10TH
, 10 },
494 { FUNIT_INCH
, MeasureUnit::INCH_100TH
, 100 },
495 { FUNIT_INCH
, MeasureUnit::INCH_1000TH
, 1000 },
496 { FUNIT_FOOT
, MeasureUnit::FOOT
, 1 },
497 { FUNIT_MILE
, MeasureUnit::MILE
, 1 },
499 for ( size_t i
= 0; i
< SAL_N_ELEMENTS( aUnits
); ++i
)
501 if ( eDirection
== FieldUnitToMeasurementUnit
)
503 if ( ( aUnits
[ i
].eFieldUnit
== (FieldUnit
)_nUnit
) && ( aUnits
[ i
].nFieldToMeasureFactor
== _rFieldToUNOValueFactor
) )
504 return aUnits
[ i
].nMeasurementUnit
;
508 if ( aUnits
[ i
].nMeasurementUnit
== _nUnit
)
510 _rFieldToUNOValueFactor
= aUnits
[ i
].nFieldToMeasureFactor
;
511 return (sal_Int16
)aUnits
[ i
].eFieldUnit
;
515 if ( eDirection
== FieldUnitToMeasurementUnit
)
518 _rFieldToUNOValueFactor
= 1;
519 return (sal_Int16
)FUNIT_NONE
;
522 //========================================================================
523 //= MeasurementUnitConversion
524 //========================================================================
525 //------------------------------------------------------------------------
526 sal_Int16
VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit
, sal_Int16 _nUNOToFieldValueFactor
)
528 return convertMeasurementUnit( (sal_Int16
)_nFieldUnit
, FieldUnitToMeasurementUnit
, _nUNOToFieldValueFactor
);
531 //------------------------------------------------------------------------
532 FieldUnit
VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit
, sal_Int16
& _rFieldToUNOValueFactor
)
534 return (FieldUnit
)convertMeasurementUnit( _nMeasurementUnit
, MeasurementUnitToFieldUnit
, _rFieldToUNOValueFactor
);
538 MapUnit
/* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16
/* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit
) throw (::com::sun::star::lang::IllegalArgumentException
)
541 switch(_nMeasureUnit
)
543 case com::sun::star::util::MeasureUnit::MM_100TH
:
544 eMode
= MAP_100TH_MM
;
548 case com::sun::star::util::MeasureUnit::MM_10TH
:
552 case com::sun::star::util::MeasureUnit::MM
:
556 case com::sun::star::util::MeasureUnit::CM
:
560 case com::sun::star::util::MeasureUnit::INCH_1000TH
:
561 eMode
= MAP_1000TH_INCH
;
564 case com::sun::star::util::MeasureUnit::INCH_100TH
:
565 eMode
= MAP_100TH_INCH
;
568 case com::sun::star::util::MeasureUnit::INCH_10TH
:
569 eMode
= MAP_10TH_INCH
;
572 case com::sun::star::util::MeasureUnit::INCH
:
576 case com::sun::star::util::MeasureUnit::POINT
:
580 case com::sun::star::util::MeasureUnit::TWIP
:
584 case com::sun::star::util::MeasureUnit::PIXEL
:
589 case com::sun::star::util::MeasureUnit::M:
591 case com::sun::star::util::MeasureUnit::KM:
593 case com::sun::star::util::MeasureUnit::PICA:
595 case com::sun::star::util::MeasureUnit::FOOT:
597 case com::sun::star::util::MeasureUnit::MILE:
599 case com::sun::star::util::MeasureUnit::PERCENT:
602 case com::sun::star::util::MeasureUnit::APPFONT
:
606 case com::sun::star::util::MeasureUnit::SYSFONT
:
611 case com::sun::star::util::MeasureUnit::RELATIVE:
612 eMode = MAP_RELATIVE;
614 case com::sun::star::util::MeasureUnit::REALAPPFONT:
615 eMode = MAP_REALAPPFONT;
620 throw ::com::sun::star::lang::IllegalArgumentException("Unsupported measure unit.", NULL
, 1 );
625 ::Size
VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size
const& _aSize
)
627 ::Size
aVCLSize(_aSize
.Width
, _aSize
.Height
);
631 com::sun::star::awt::Size
VCLUnoHelper::ConvertToAWTSize(::Size
/* VCLSize */ const& _aSize
)
633 com::sun::star::awt::Size
aAWTSize(_aSize
.Width(), _aSize
.Height());
638 ::Point
VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point
const& _aPoint
)
640 ::Point
aVCLPoint(_aPoint
.X
, _aPoint
.Y
);
644 com::sun::star::awt::Point
VCLUnoHelper::ConvertToAWTPoint(::Point
/* VCLPoint */ const& _aPoint
)
646 com::sun::star::awt::Point
aAWTPoint(_aPoint
.X(), _aPoint
.Y());
650 ::Rectangle
VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle
const & _rRect
)
652 return ::Rectangle( _rRect
.X
, _rRect
.Y
, _rRect
.X
+ _rRect
.Width
- 1, _rRect
.Y
+ _rRect
.Height
- 1 );
655 ::com::sun::star::awt::Rectangle
VCLUnoHelper::ConvertToAWTRect( ::Rectangle
const & _rRect
)
657 return ::com::sun::star::awt::Rectangle( _rRect
.Left(), _rRect
.Top(), _rRect
.GetWidth(), _rRect
.GetHeight() );
660 awt::MouseEvent
VCLUnoHelper::createMouseEvent( const ::MouseEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
662 awt::MouseEvent aMouseEvent
;
663 aMouseEvent
.Source
= _rxContext
;
665 aMouseEvent
.Modifiers
= 0;
666 if ( _rVclEvent
.IsShift() )
667 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::SHIFT
;
668 if ( _rVclEvent
.IsMod1() )
669 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD1
;
670 if ( _rVclEvent
.IsMod2() )
671 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD2
;
673 aMouseEvent
.Buttons
= 0;
674 if ( _rVclEvent
.IsLeft() )
675 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::LEFT
;
676 if ( _rVclEvent
.IsRight() )
677 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::RIGHT
;
678 if ( _rVclEvent
.IsMiddle() )
679 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::MIDDLE
;
681 aMouseEvent
.X
= _rVclEvent
.GetPosPixel().X();
682 aMouseEvent
.Y
= _rVclEvent
.GetPosPixel().Y();
683 aMouseEvent
.ClickCount
= _rVclEvent
.GetClicks();
684 aMouseEvent
.PopupTrigger
= sal_False
;
689 awt::KeyEvent
VCLUnoHelper::createKeyEvent( const ::KeyEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
691 awt::KeyEvent aKeyEvent
;
692 aKeyEvent
.Source
= _rxContext
;
694 aKeyEvent
.Modifiers
= 0;
695 if ( _rVclEvent
.GetKeyCode().IsShift() )
696 aKeyEvent
.Modifiers
|= awt::KeyModifier::SHIFT
;
697 if ( _rVclEvent
.GetKeyCode().IsMod1() )
698 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD1
;
699 if ( _rVclEvent
.GetKeyCode().IsMod2() )
700 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD2
;
701 if ( _rVclEvent
.GetKeyCode().IsMod3() )
702 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD3
;
704 aKeyEvent
.KeyCode
= _rVclEvent
.GetKeyCode().GetCode();
705 aKeyEvent
.KeyChar
= _rVclEvent
.GetCharCode();
706 aKeyEvent
.KeyFunc
= ::sal::static_int_cast
< sal_Int16
>( _rVclEvent
.GetKeyCode().GetFunction());
711 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */