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 const uno::Reference
< lang::XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
196 UnoControlContainer
* pContainer
= new UnoControlContainer( xFactory
, pWindow
->GetComponentInterface( sal_True
) );
197 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> x
= pContainer
;
199 UnoControlModel
* pContainerModel
= new UnoControlContainerModel( xFactory
);
200 pContainer
->setModel( (::com::sun::star::awt::XControlModel
*)pContainerModel
);
205 float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth
)
207 if( eWidth
== WIDTH_DONTKNOW
)
208 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
209 else if( eWidth
== WIDTH_ULTRA_CONDENSED
)
210 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED
;
211 else if( eWidth
== WIDTH_EXTRA_CONDENSED
)
212 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED
;
213 else if( eWidth
== WIDTH_CONDENSED
)
214 return ::com::sun::star::awt::FontWidth::CONDENSED
;
215 else if( eWidth
== WIDTH_SEMI_CONDENSED
)
216 return ::com::sun::star::awt::FontWidth::SEMICONDENSED
;
217 else if( eWidth
== WIDTH_NORMAL
)
218 return ::com::sun::star::awt::FontWidth::NORMAL
;
219 else if( eWidth
== WIDTH_SEMI_EXPANDED
)
220 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED
;
221 else if( eWidth
== WIDTH_EXPANDED
)
222 return ::com::sun::star::awt::FontWidth::EXPANDED
;
223 else if( eWidth
== WIDTH_EXTRA_EXPANDED
)
224 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
;
225 else if( eWidth
== WIDTH_ULTRA_EXPANDED
)
226 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
;
228 OSL_FAIL( "Unknown FontWidth" );
229 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
232 FontWidth
VCLUnoHelper::ConvertFontWidth( float f
)
234 if( f
<= ::com::sun::star::awt::FontWidth::DONTKNOW
)
235 return WIDTH_DONTKNOW
;
236 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRACONDENSED
)
237 return WIDTH_ULTRA_CONDENSED
;
238 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRACONDENSED
)
239 return WIDTH_EXTRA_CONDENSED
;
240 else if( f
<= ::com::sun::star::awt::FontWidth::CONDENSED
)
241 return WIDTH_CONDENSED
;
242 else if( f
<= ::com::sun::star::awt::FontWidth::SEMICONDENSED
)
243 return WIDTH_SEMI_CONDENSED
;
244 else if( f
<= ::com::sun::star::awt::FontWidth::NORMAL
)
246 else if( f
<= ::com::sun::star::awt::FontWidth::SEMIEXPANDED
)
247 return WIDTH_SEMI_EXPANDED
;
248 else if( f
<= ::com::sun::star::awt::FontWidth::EXPANDED
)
249 return WIDTH_EXPANDED
;
250 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
)
251 return WIDTH_EXTRA_EXPANDED
;
252 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
)
253 return WIDTH_ULTRA_EXPANDED
;
255 OSL_FAIL( "Unknown FontWidth" );
256 return WIDTH_DONTKNOW
;
259 float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight
)
261 if( eWeight
== WEIGHT_DONTKNOW
)
262 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
263 else if( eWeight
== WEIGHT_THIN
)
264 return ::com::sun::star::awt::FontWeight::THIN
;
265 else if( eWeight
== WEIGHT_ULTRALIGHT
)
266 return ::com::sun::star::awt::FontWeight::ULTRALIGHT
;
267 else if( eWeight
== WEIGHT_LIGHT
)
268 return ::com::sun::star::awt::FontWeight::LIGHT
;
269 else if( eWeight
== WEIGHT_SEMILIGHT
)
270 return ::com::sun::star::awt::FontWeight::SEMILIGHT
;
271 else if( ( eWeight
== WEIGHT_NORMAL
) || ( eWeight
== WEIGHT_MEDIUM
) )
272 return ::com::sun::star::awt::FontWeight::NORMAL
;
273 else if( eWeight
== WEIGHT_SEMIBOLD
)
274 return ::com::sun::star::awt::FontWeight::SEMIBOLD
;
275 else if( eWeight
== WEIGHT_BOLD
)
276 return ::com::sun::star::awt::FontWeight::BOLD
;
277 else if( eWeight
== WEIGHT_ULTRABOLD
)
278 return ::com::sun::star::awt::FontWeight::ULTRABOLD
;
279 else if( eWeight
== WEIGHT_BLACK
)
280 return ::com::sun::star::awt::FontWeight::BLACK
;
282 OSL_FAIL( "Unknown FontWeigth" );
283 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
286 FontWeight
VCLUnoHelper::ConvertFontWeight( float f
)
288 if( f
<= ::com::sun::star::awt::FontWeight::DONTKNOW
)
289 return WEIGHT_DONTKNOW
;
290 else if( f
<= ::com::sun::star::awt::FontWeight::THIN
)
292 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRALIGHT
)
293 return WEIGHT_ULTRALIGHT
;
294 else if( f
<= ::com::sun::star::awt::FontWeight::LIGHT
)
296 else if( f
<= ::com::sun::star::awt::FontWeight::SEMILIGHT
)
297 return WEIGHT_SEMILIGHT
;
298 else if( f
<= ::com::sun::star::awt::FontWeight::NORMAL
)
299 return WEIGHT_NORMAL
;
300 else if( f
<= ::com::sun::star::awt::FontWeight::SEMIBOLD
)
301 return WEIGHT_SEMIBOLD
;
302 else if( f
<= ::com::sun::star::awt::FontWeight::BOLD
)
304 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRABOLD
)
305 return WEIGHT_ULTRABOLD
;
306 else if( f
<= ::com::sun::star::awt::FontWeight::BLACK
)
309 OSL_FAIL( "Unknown FontWeigth" );
310 return WEIGHT_DONTKNOW
;
314 ::com::sun::star::awt::FontDescriptor
VCLUnoHelper::CreateFontDescriptor( const Font
& rFont
)
316 ::com::sun::star::awt::FontDescriptor aFD
;
317 aFD
.Name
= rFont
.GetName();
318 aFD
.StyleName
= rFont
.GetStyleName();
319 aFD
.Height
= (sal_Int16
)rFont
.GetSize().Height();
320 aFD
.Width
= (sal_Int16
)rFont
.GetSize().Width();
321 aFD
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamily());
322 aFD
.CharSet
= rFont
.GetCharSet();
323 aFD
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
324 aFD
.CharacterWidth
= VCLUnoHelper::ConvertFontWidth( rFont
.GetWidthType() );
325 aFD
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
326 aFD
.Slant
= (::com::sun::star::awt::FontSlant
)rFont
.GetItalic();
327 aFD
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
328 aFD
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
329 aFD
.Orientation
= rFont
.GetOrientation();
330 aFD
.Kerning
= rFont
.IsKerning();
331 aFD
.WordLineMode
= rFont
.IsWordLineMode();
332 aFD
.Type
= 0; // ??? => Nur an Metric...
336 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor
& rDescr
, const Font
& rInitFont
)
338 Font
aFont( rInitFont
);
339 if ( !rDescr
.Name
.isEmpty() )
340 aFont
.SetName( rDescr
.Name
);
341 if ( !rDescr
.StyleName
.isEmpty() )
342 aFont
.SetStyleName( rDescr
.StyleName
);
344 aFont
.SetSize( Size( rDescr
.Width
, rDescr
.Height
) );
345 if ( (FontFamily
)rDescr
.Family
!= FAMILY_DONTKNOW
)
346 aFont
.SetFamily( (FontFamily
)rDescr
.Family
);
347 if ( (CharSet
)rDescr
.CharSet
!= RTL_TEXTENCODING_DONTKNOW
)
348 aFont
.SetCharSet( (CharSet
)rDescr
.CharSet
);
349 if ( (FontPitch
)rDescr
.Pitch
!= PITCH_DONTKNOW
)
350 aFont
.SetPitch( (FontPitch
)rDescr
.Pitch
);
351 if ( rDescr
.CharacterWidth
)
352 aFont
.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr
.CharacterWidth
) );
354 aFont
.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr
.Weight
) );
355 if ( (FontItalic
)rDescr
.Slant
!= ITALIC_DONTKNOW
)
356 aFont
.SetItalic( (FontItalic
)rDescr
.Slant
);
357 if ( (FontUnderline
)rDescr
.Underline
!= UNDERLINE_DONTKNOW
)
358 aFont
.SetUnderline( (FontUnderline
)rDescr
.Underline
);
359 if ( (FontStrikeout
)rDescr
.Strikeout
!= STRIKEOUT_DONTKNOW
)
360 aFont
.SetStrikeout( (FontStrikeout
)rDescr
.Strikeout
);
363 aFont
.SetOrientation( (short)rDescr
.Orientation
);
364 aFont
.SetKerning( rDescr
.Kerning
);
365 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
370 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFont
>& rxFont
)
373 VCLXFont
* pVCLXFont
= VCLXFont::GetImplementation( rxFont
);
375 aFont
= pVCLXFont
->GetFont();
380 ::com::sun::star::awt::SimpleFontMetric
VCLUnoHelper::CreateFontMetric( const FontMetric
& rFontMetric
)
382 ::com::sun::star::awt::SimpleFontMetric aFM
;
383 aFM
.Ascent
= (sal_Int16
)rFontMetric
.GetAscent();
384 aFM
.Descent
= (sal_Int16
)rFontMetric
.GetDescent();
385 aFM
.Leading
= (sal_Int16
)rFontMetric
.GetIntLeading();
386 aFM
.Slant
= (sal_Int16
)rFontMetric
.GetSlant();
387 aFM
.FirstChar
= 0x0020;
388 aFM
.LastChar
= 0xFFFD;
392 sal_Bool
VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect
)
394 return ( !rRect
.X
&& !rRect
.Y
&& !rRect
.Width
&& !rRect
.Height
);
397 MapUnit
VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit
)
399 switch( nUnoEmbedMapUnit
)
401 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
:
403 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
:
405 case ::com::sun::star::embed::EmbedMapUnits::ONE_MM
:
407 case ::com::sun::star::embed::EmbedMapUnits::ONE_CM
:
409 case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
:
410 return MAP_1000TH_INCH
;
411 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
:
412 return MAP_100TH_INCH
;
413 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
:
414 return MAP_10TH_INCH
;
415 case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
:
417 case ::com::sun::star::embed::EmbedMapUnits::POINT
:
419 case ::com::sun::star::embed::EmbedMapUnits::TWIP
:
421 case ::com::sun::star::embed::EmbedMapUnits::PIXEL
:
425 OSL_FAIL( "Unexpected UNO map mode is provided!\n" );
426 return MAP_LASTENUMDUMMY
;
429 sal_Int32
VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit
)
431 switch( nVCLMapUnit
)
434 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
;
436 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
;
438 return ::com::sun::star::embed::EmbedMapUnits::ONE_MM
;
440 return ::com::sun::star::embed::EmbedMapUnits::ONE_CM
;
441 case MAP_1000TH_INCH
:
442 return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
;
444 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
;
446 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
;
448 return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
;
450 return ::com::sun::star::embed::EmbedMapUnits::POINT
;
452 return ::com::sun::star::embed::EmbedMapUnits::TWIP
;
454 return ::com::sun::star::embed::EmbedMapUnits::PIXEL
;
455 default: ; // avoid compiler warning
458 OSL_FAIL( "Unexpected VCL map mode is provided!\n" );
462 using namespace ::com::sun::star::util
;
464 //====================================================================
465 //= file-local helpers
466 //====================================================================
469 enum UnitConversionDirection
471 FieldUnitToMeasurementUnit
,
472 MeasurementUnitToFieldUnit
475 sal_Int16
convertMeasurementUnit( sal_Int16 _nUnit
, UnitConversionDirection eDirection
, sal_Int16
& _rFieldToUNOValueFactor
)
477 static struct _unit_table
479 FieldUnit eFieldUnit
;
480 sal_Int16 nMeasurementUnit
;
481 sal_Int16 nFieldToMeasureFactor
;
483 { FUNIT_NONE
, -1 , -1},
484 { FUNIT_MM
, MeasureUnit::MM
, 1 }, // must precede MM_10TH
485 { FUNIT_MM
, MeasureUnit::MM_10TH
, 10 },
486 { FUNIT_100TH_MM
, MeasureUnit::MM_100TH
, 1 },
487 { FUNIT_CM
, MeasureUnit::CM
, 1 },
488 { FUNIT_M
, MeasureUnit::M
, 1 },
489 { FUNIT_KM
, MeasureUnit::KM
, 1 },
490 { FUNIT_TWIP
, MeasureUnit::TWIP
, 1 },
491 { FUNIT_POINT
, MeasureUnit::POINT
, 1 },
492 { FUNIT_PICA
, MeasureUnit::PICA
, 1 },
493 { FUNIT_INCH
, MeasureUnit::INCH
, 1 }, // must precede INCH_*TH
494 { FUNIT_INCH
, MeasureUnit::INCH_10TH
, 10 },
495 { FUNIT_INCH
, MeasureUnit::INCH_100TH
, 100 },
496 { FUNIT_INCH
, MeasureUnit::INCH_1000TH
, 1000 },
497 { FUNIT_FOOT
, MeasureUnit::FOOT
, 1 },
498 { FUNIT_MILE
, MeasureUnit::MILE
, 1 },
500 for ( size_t i
= 0; i
< SAL_N_ELEMENTS( aUnits
); ++i
)
502 if ( eDirection
== FieldUnitToMeasurementUnit
)
504 if ( ( aUnits
[ i
].eFieldUnit
== (FieldUnit
)_nUnit
) && ( aUnits
[ i
].nFieldToMeasureFactor
== _rFieldToUNOValueFactor
) )
505 return aUnits
[ i
].nMeasurementUnit
;
509 if ( aUnits
[ i
].nMeasurementUnit
== _nUnit
)
511 _rFieldToUNOValueFactor
= aUnits
[ i
].nFieldToMeasureFactor
;
512 return (sal_Int16
)aUnits
[ i
].eFieldUnit
;
516 if ( eDirection
== FieldUnitToMeasurementUnit
)
519 _rFieldToUNOValueFactor
= 1;
520 return (sal_Int16
)FUNIT_NONE
;
523 //========================================================================
524 //= MeasurementUnitConversion
525 //========================================================================
526 //------------------------------------------------------------------------
527 sal_Int16
VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit
, sal_Int16 _nUNOToFieldValueFactor
)
529 return convertMeasurementUnit( (sal_Int16
)_nFieldUnit
, FieldUnitToMeasurementUnit
, _nUNOToFieldValueFactor
);
532 //------------------------------------------------------------------------
533 FieldUnit
VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit
, sal_Int16
& _rFieldToUNOValueFactor
)
535 return (FieldUnit
)convertMeasurementUnit( _nMeasurementUnit
, MeasurementUnitToFieldUnit
, _rFieldToUNOValueFactor
);
539 MapUnit
/* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16
/* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit
) throw (::com::sun::star::lang::IllegalArgumentException
)
542 switch(_nMeasureUnit
)
544 case com::sun::star::util::MeasureUnit::MM_100TH
:
545 eMode
= MAP_100TH_MM
;
549 case com::sun::star::util::MeasureUnit::MM_10TH
:
553 case com::sun::star::util::MeasureUnit::MM
:
557 case com::sun::star::util::MeasureUnit::CM
:
561 case com::sun::star::util::MeasureUnit::INCH_1000TH
:
562 eMode
= MAP_1000TH_INCH
;
565 case com::sun::star::util::MeasureUnit::INCH_100TH
:
566 eMode
= MAP_100TH_INCH
;
569 case com::sun::star::util::MeasureUnit::INCH_10TH
:
570 eMode
= MAP_10TH_INCH
;
573 case com::sun::star::util::MeasureUnit::INCH
:
577 case com::sun::star::util::MeasureUnit::POINT
:
581 case com::sun::star::util::MeasureUnit::TWIP
:
585 case com::sun::star::util::MeasureUnit::PIXEL
:
590 case com::sun::star::util::MeasureUnit::M:
592 case com::sun::star::util::MeasureUnit::KM:
594 case com::sun::star::util::MeasureUnit::PICA:
596 case com::sun::star::util::MeasureUnit::FOOT:
598 case com::sun::star::util::MeasureUnit::MILE:
600 case com::sun::star::util::MeasureUnit::PERCENT:
603 case com::sun::star::util::MeasureUnit::APPFONT
:
607 case com::sun::star::util::MeasureUnit::SYSFONT
:
612 case com::sun::star::util::MeasureUnit::RELATIVE:
613 eMode = MAP_RELATIVE;
615 case com::sun::star::util::MeasureUnit::REALAPPFONT:
616 eMode = MAP_REALAPPFONT;
621 throw ::com::sun::star::lang::IllegalArgumentException("Unsupported measure unit.", NULL
, 1 );
626 ::Size
VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size
const& _aSize
)
628 ::Size
aVCLSize(_aSize
.Width
, _aSize
.Height
);
632 com::sun::star::awt::Size
VCLUnoHelper::ConvertToAWTSize(::Size
/* VCLSize */ const& _aSize
)
634 com::sun::star::awt::Size
aAWTSize(_aSize
.Width(), _aSize
.Height());
639 ::Point
VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point
const& _aPoint
)
641 ::Point
aVCLPoint(_aPoint
.X
, _aPoint
.Y
);
645 com::sun::star::awt::Point
VCLUnoHelper::ConvertToAWTPoint(::Point
/* VCLPoint */ const& _aPoint
)
647 com::sun::star::awt::Point
aAWTPoint(_aPoint
.X(), _aPoint
.Y());
651 ::Rectangle
VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle
const & _rRect
)
653 return ::Rectangle( _rRect
.X
, _rRect
.Y
, _rRect
.X
+ _rRect
.Width
- 1, _rRect
.Y
+ _rRect
.Height
- 1 );
656 ::com::sun::star::awt::Rectangle
VCLUnoHelper::ConvertToAWTRect( ::Rectangle
const & _rRect
)
658 return ::com::sun::star::awt::Rectangle( _rRect
.Left(), _rRect
.Top(), _rRect
.GetWidth(), _rRect
.GetHeight() );
661 awt::MouseEvent
VCLUnoHelper::createMouseEvent( const ::MouseEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
663 awt::MouseEvent aMouseEvent
;
664 aMouseEvent
.Source
= _rxContext
;
666 aMouseEvent
.Modifiers
= 0;
667 if ( _rVclEvent
.IsShift() )
668 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::SHIFT
;
669 if ( _rVclEvent
.IsMod1() )
670 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD1
;
671 if ( _rVclEvent
.IsMod2() )
672 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD2
;
674 aMouseEvent
.Buttons
= 0;
675 if ( _rVclEvent
.IsLeft() )
676 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::LEFT
;
677 if ( _rVclEvent
.IsRight() )
678 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::RIGHT
;
679 if ( _rVclEvent
.IsMiddle() )
680 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::MIDDLE
;
682 aMouseEvent
.X
= _rVclEvent
.GetPosPixel().X();
683 aMouseEvent
.Y
= _rVclEvent
.GetPosPixel().Y();
684 aMouseEvent
.ClickCount
= _rVclEvent
.GetClicks();
685 aMouseEvent
.PopupTrigger
= sal_False
;
690 awt::KeyEvent
VCLUnoHelper::createKeyEvent( const ::KeyEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
692 awt::KeyEvent aKeyEvent
;
693 aKeyEvent
.Source
= _rxContext
;
695 aKeyEvent
.Modifiers
= 0;
696 if ( _rVclEvent
.GetKeyCode().IsShift() )
697 aKeyEvent
.Modifiers
|= awt::KeyModifier::SHIFT
;
698 if ( _rVclEvent
.GetKeyCode().IsMod1() )
699 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD1
;
700 if ( _rVclEvent
.GetKeyCode().IsMod2() )
701 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD2
;
702 if ( _rVclEvent
.GetKeyCode().IsMod3() )
703 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD3
;
705 aKeyEvent
.KeyCode
= _rVclEvent
.GetKeyCode().GetCode();
706 aKeyEvent
.KeyChar
= _rVclEvent
.GetCharCode();
707 aKeyEvent
.KeyFunc
= ::sal::static_int_cast
< sal_Int16
>( _rVclEvent
.GetKeyCode().GetFunction());
712 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */