1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <tools/stream.hxx>
31 #include <vcl/bitmap.hxx>
32 #include <vcl/window.hxx>
33 #include <sal/macros.h>
34 #include <com/sun/star/util/MeasureUnit.hpp>
35 #include <com/sun/star/awt/XBitmap.hpp>
36 #include <com/sun/star/awt/XWindow.hpp>
37 #include <com/sun/star/awt/XDevice.hpp>
38 #include <com/sun/star/awt/XPointer.hpp>
39 #include <com/sun/star/awt/SimpleFontMetric.hpp>
40 #include <com/sun/star/awt/FontDescriptor.hpp>
41 #include <com/sun/star/awt/XControlContainer.hpp>
42 #include <com/sun/star/awt/FontWeight.hpp>
43 #include <com/sun/star/awt/FontWidth.hpp>
44 #include <com/sun/star/awt/KeyModifier.hpp>
45 #include <com/sun/star/awt/MouseButton.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/embed/EmbedMapUnits.hpp>
49 #include <com/sun/star/graphic/XGraphic.hpp>
51 #include <toolkit/helper/vclunohelper.hxx>
52 #include <toolkit/helper/convert.hxx>
53 #include <toolkit/awt/vclxbitmap.hxx>
54 #include <toolkit/awt/vclxregion.hxx>
55 #include <toolkit/awt/vclxwindow.hxx>
56 #include <toolkit/awt/vclxgraphics.hxx>
57 #include <toolkit/awt/vclxpointer.hxx>
58 #include <toolkit/awt/vclxfont.hxx>
59 #include <toolkit/controls/unocontrolcontainer.hxx>
60 #include <toolkit/controls/unocontrolcontainermodel.hxx>
62 #include <vcl/graph.hxx>
63 #include <comphelper/processfactory.hxx>
65 #include <com/sun/star/awt/Size.hpp>
66 #include <com/sun/star/awt/Point.hpp>
68 using namespace ::com::sun::star
;
70 // ----------------------------------------------------
72 // ----------------------------------------------------
74 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> VCLUnoHelper::CreateToolkit()
76 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
77 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xI
= xMSF
->createInstance( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit
) );
79 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> xToolkit
;
81 xToolkit
= ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
>( xI
, ::com::sun::star::uno::UNO_QUERY
);
86 BitmapEx
VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
>& rxBitmap
)
90 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> xGraphic( rxBitmap
, ::com::sun::star::uno::UNO_QUERY
);
93 Graphic
aGraphic( xGraphic
);
94 aBmp
= aGraphic
.GetBitmapEx();
96 else if ( rxBitmap
.is() )
98 VCLXBitmap
* pVCLBitmap
= VCLXBitmap::GetImplementation( rxBitmap
);
100 aBmp
= pVCLBitmap
->GetBitmap();
105 ::com::sun::star::uno::Sequence
<sal_Int8
> aBytes
= rxBitmap
->getDIB();
106 SvMemoryStream
aMem( (char*) aBytes
.getArray(), aBytes
.getLength(), STREAM_READ
);
110 ::com::sun::star::uno::Sequence
<sal_Int8
> aBytes
= rxBitmap
->getMaskDIB();
111 SvMemoryStream
aMem( (char*) aBytes
.getArray(), aBytes
.getLength(), STREAM_READ
);
114 aBmp
= BitmapEx( aDIB
, aMask
);
120 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> VCLUnoHelper::CreateBitmap( const BitmapEx
& rBitmap
)
122 Graphic
aGraphic( rBitmap
);
123 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> xBmp( aGraphic
.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY
);
127 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& rxWindow
)
129 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
130 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
133 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
>& rxWindow
)
135 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
136 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
139 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& rxWindow
)
141 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
142 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
145 Region
VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XRegion
>& rxRegion
)
148 VCLXRegion
* pVCLRegion
= VCLXRegion::GetImplementation( rxRegion
);
150 aRegion
= pVCLRegion
->GetRegion();
153 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::Rectangle
> aRects
= rxRegion
->getRectangles();
154 sal_Int32 nRects
= aRects
.getLength();
155 for ( sal_Int32 n
= 0; n
< nRects
; n
++ )
156 aRegion
.Union( VCLRectangle( aRects
.getArray()[n
] ) );
161 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> VCLUnoHelper::GetInterface( Window
* pWindow
)
163 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> xWin
;
166 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xPeer
= pWindow
->GetComponentInterface();
167 xWin
= xWin
.query( xPeer
);
172 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPointer
> VCLUnoHelper::CreatePointer()
174 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPointer
> xPointer
= new VCLXPointer
;
178 OutputDevice
* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
>& rxDevice
)
180 OutputDevice
* pOutDev
= NULL
;
181 VCLXDevice
* pDev
= VCLXDevice::GetImplementation( rxDevice
);
183 pOutDev
= pDev
->GetOutputDevice();
187 OutputDevice
* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
>& rxGraphics
)
189 OutputDevice
* pOutDev
= NULL
;
190 VCLXGraphics
* pGrf
= VCLXGraphics::GetImplementation( rxGraphics
);
192 pOutDev
= pGrf
->GetOutputDevice();
196 Polygon
VCLUnoHelper::CreatePolygon( const ::com::sun::star::uno::Sequence
< sal_Int32
>& DataX
, const ::com::sun::star::uno::Sequence
< sal_Int32
>& DataY
)
198 sal_uInt32 nLen
= DataX
.getLength();
199 const sal_Int32
* pDataX
= DataX
.getConstArray();
200 const sal_Int32
* pDataY
= DataY
.getConstArray();
201 Polygon
aPoly( (sal_uInt16
) nLen
);
202 for ( sal_uInt16 n
= 0; n
< nLen
; n
++ )
205 aPnt
.X() = pDataX
[n
];
206 aPnt
.Y() = pDataY
[n
];
212 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> VCLUnoHelper::CreateControlContainer( Window
* pWindow
)
214 const uno::Reference
< lang::XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
215 UnoControlContainer
* pContainer
= new UnoControlContainer( xFactory
, pWindow
->GetComponentInterface( sal_True
) );
216 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> x
= pContainer
;
218 UnoControlModel
* pContainerModel
= new UnoControlContainerModel( xFactory
);
219 pContainer
->setModel( (::com::sun::star::awt::XControlModel
*)pContainerModel
);
224 float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth
)
226 if( eWidth
== WIDTH_DONTKNOW
)
227 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
228 else if( eWidth
== WIDTH_ULTRA_CONDENSED
)
229 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED
;
230 else if( eWidth
== WIDTH_EXTRA_CONDENSED
)
231 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED
;
232 else if( eWidth
== WIDTH_CONDENSED
)
233 return ::com::sun::star::awt::FontWidth::CONDENSED
;
234 else if( eWidth
== WIDTH_SEMI_CONDENSED
)
235 return ::com::sun::star::awt::FontWidth::SEMICONDENSED
;
236 else if( eWidth
== WIDTH_NORMAL
)
237 return ::com::sun::star::awt::FontWidth::NORMAL
;
238 else if( eWidth
== WIDTH_SEMI_EXPANDED
)
239 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED
;
240 else if( eWidth
== WIDTH_EXPANDED
)
241 return ::com::sun::star::awt::FontWidth::EXPANDED
;
242 else if( eWidth
== WIDTH_EXTRA_EXPANDED
)
243 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
;
244 else if( eWidth
== WIDTH_ULTRA_EXPANDED
)
245 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
;
247 OSL_FAIL( "Unknown FontWidth" );
248 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
251 FontWidth
VCLUnoHelper::ConvertFontWidth( float f
)
253 if( f
<= ::com::sun::star::awt::FontWidth::DONTKNOW
)
254 return WIDTH_DONTKNOW
;
255 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRACONDENSED
)
256 return WIDTH_ULTRA_CONDENSED
;
257 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRACONDENSED
)
258 return WIDTH_EXTRA_CONDENSED
;
259 else if( f
<= ::com::sun::star::awt::FontWidth::CONDENSED
)
260 return WIDTH_CONDENSED
;
261 else if( f
<= ::com::sun::star::awt::FontWidth::SEMICONDENSED
)
262 return WIDTH_SEMI_CONDENSED
;
263 else if( f
<= ::com::sun::star::awt::FontWidth::NORMAL
)
265 else if( f
<= ::com::sun::star::awt::FontWidth::SEMIEXPANDED
)
266 return WIDTH_SEMI_EXPANDED
;
267 else if( f
<= ::com::sun::star::awt::FontWidth::EXPANDED
)
268 return WIDTH_EXPANDED
;
269 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
)
270 return WIDTH_EXTRA_EXPANDED
;
271 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
)
272 return WIDTH_ULTRA_EXPANDED
;
274 OSL_FAIL( "Unknown FontWidth" );
275 return WIDTH_DONTKNOW
;
278 float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight
)
280 if( eWeight
== WEIGHT_DONTKNOW
)
281 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
282 else if( eWeight
== WEIGHT_THIN
)
283 return ::com::sun::star::awt::FontWeight::THIN
;
284 else if( eWeight
== WEIGHT_ULTRALIGHT
)
285 return ::com::sun::star::awt::FontWeight::ULTRALIGHT
;
286 else if( eWeight
== WEIGHT_LIGHT
)
287 return ::com::sun::star::awt::FontWeight::LIGHT
;
288 else if( eWeight
== WEIGHT_SEMILIGHT
)
289 return ::com::sun::star::awt::FontWeight::SEMILIGHT
;
290 else if( ( eWeight
== WEIGHT_NORMAL
) || ( eWeight
== WEIGHT_MEDIUM
) )
291 return ::com::sun::star::awt::FontWeight::NORMAL
;
292 else if( eWeight
== WEIGHT_SEMIBOLD
)
293 return ::com::sun::star::awt::FontWeight::SEMIBOLD
;
294 else if( eWeight
== WEIGHT_BOLD
)
295 return ::com::sun::star::awt::FontWeight::BOLD
;
296 else if( eWeight
== WEIGHT_ULTRABOLD
)
297 return ::com::sun::star::awt::FontWeight::ULTRABOLD
;
298 else if( eWeight
== WEIGHT_BLACK
)
299 return ::com::sun::star::awt::FontWeight::BLACK
;
301 OSL_FAIL( "Unknown FontWeigth" );
302 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
305 FontWeight
VCLUnoHelper::ConvertFontWeight( float f
)
307 if( f
<= ::com::sun::star::awt::FontWeight::DONTKNOW
)
308 return WEIGHT_DONTKNOW
;
309 else if( f
<= ::com::sun::star::awt::FontWeight::THIN
)
311 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRALIGHT
)
312 return WEIGHT_ULTRALIGHT
;
313 else if( f
<= ::com::sun::star::awt::FontWeight::LIGHT
)
315 else if( f
<= ::com::sun::star::awt::FontWeight::SEMILIGHT
)
316 return WEIGHT_SEMILIGHT
;
317 else if( f
<= ::com::sun::star::awt::FontWeight::NORMAL
)
318 return WEIGHT_NORMAL
;
319 else if( f
<= ::com::sun::star::awt::FontWeight::SEMIBOLD
)
320 return WEIGHT_SEMIBOLD
;
321 else if( f
<= ::com::sun::star::awt::FontWeight::BOLD
)
323 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRABOLD
)
324 return WEIGHT_ULTRABOLD
;
325 else if( f
<= ::com::sun::star::awt::FontWeight::BLACK
)
328 OSL_FAIL( "Unknown FontWeigth" );
329 return WEIGHT_DONTKNOW
;
333 ::com::sun::star::awt::FontDescriptor
VCLUnoHelper::CreateFontDescriptor( const Font
& rFont
)
335 ::com::sun::star::awt::FontDescriptor aFD
;
336 aFD
.Name
= rFont
.GetName();
337 aFD
.StyleName
= rFont
.GetStyleName();
338 aFD
.Height
= (sal_Int16
)rFont
.GetSize().Height();
339 aFD
.Width
= (sal_Int16
)rFont
.GetSize().Width();
340 aFD
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamily());
341 aFD
.CharSet
= rFont
.GetCharSet();
342 aFD
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
343 aFD
.CharacterWidth
= VCLUnoHelper::ConvertFontWidth( rFont
.GetWidthType() );
344 aFD
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
345 aFD
.Slant
= (::com::sun::star::awt::FontSlant
)rFont
.GetItalic();
346 aFD
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
347 aFD
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
348 aFD
.Orientation
= rFont
.GetOrientation();
349 aFD
.Kerning
= rFont
.IsKerning();
350 aFD
.WordLineMode
= rFont
.IsWordLineMode();
351 aFD
.Type
= 0; // ??? => Nur an Metric...
355 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor
& rDescr
, const Font
& rInitFont
)
357 Font
aFont( rInitFont
);
358 if ( !rDescr
.Name
.isEmpty() )
359 aFont
.SetName( rDescr
.Name
);
360 if ( !rDescr
.StyleName
.isEmpty() )
361 aFont
.SetStyleName( rDescr
.StyleName
);
363 aFont
.SetSize( Size( rDescr
.Width
, rDescr
.Height
) );
364 if ( (FontFamily
)rDescr
.Family
!= FAMILY_DONTKNOW
)
365 aFont
.SetFamily( (FontFamily
)rDescr
.Family
);
366 if ( (CharSet
)rDescr
.CharSet
!= RTL_TEXTENCODING_DONTKNOW
)
367 aFont
.SetCharSet( (CharSet
)rDescr
.CharSet
);
368 if ( (FontPitch
)rDescr
.Pitch
!= PITCH_DONTKNOW
)
369 aFont
.SetPitch( (FontPitch
)rDescr
.Pitch
);
370 if ( rDescr
.CharacterWidth
)
371 aFont
.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr
.CharacterWidth
) );
373 aFont
.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr
.Weight
) );
374 if ( (FontItalic
)rDescr
.Slant
!= ITALIC_DONTKNOW
)
375 aFont
.SetItalic( (FontItalic
)rDescr
.Slant
);
376 if ( (FontUnderline
)rDescr
.Underline
!= UNDERLINE_DONTKNOW
)
377 aFont
.SetUnderline( (FontUnderline
)rDescr
.Underline
);
378 if ( (FontStrikeout
)rDescr
.Strikeout
!= STRIKEOUT_DONTKNOW
)
379 aFont
.SetStrikeout( (FontStrikeout
)rDescr
.Strikeout
);
382 aFont
.SetOrientation( (short)rDescr
.Orientation
);
383 aFont
.SetKerning( rDescr
.Kerning
);
384 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
389 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFont
>& rxFont
)
392 VCLXFont
* pVCLXFont
= VCLXFont::GetImplementation( rxFont
);
394 aFont
= pVCLXFont
->GetFont();
399 ::com::sun::star::awt::SimpleFontMetric
VCLUnoHelper::CreateFontMetric( const FontMetric
& rFontMetric
)
401 ::com::sun::star::awt::SimpleFontMetric aFM
;
402 aFM
.Ascent
= (sal_Int16
)rFontMetric
.GetAscent();
403 aFM
.Descent
= (sal_Int16
)rFontMetric
.GetDescent();
404 aFM
.Leading
= (sal_Int16
)rFontMetric
.GetIntLeading();
405 aFM
.Slant
= (sal_Int16
)rFontMetric
.GetSlant();
406 aFM
.FirstChar
= 0x0020;
407 aFM
.LastChar
= 0xFFFD;
411 sal_Bool
VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect
)
413 return ( !rRect
.X
&& !rRect
.Y
&& !rRect
.Width
&& !rRect
.Height
);
416 MapUnit
VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit
)
418 switch( nUnoEmbedMapUnit
)
420 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
:
422 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
:
424 case ::com::sun::star::embed::EmbedMapUnits::ONE_MM
:
426 case ::com::sun::star::embed::EmbedMapUnits::ONE_CM
:
428 case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
:
429 return MAP_1000TH_INCH
;
430 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
:
431 return MAP_100TH_INCH
;
432 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
:
433 return MAP_10TH_INCH
;
434 case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
:
436 case ::com::sun::star::embed::EmbedMapUnits::POINT
:
438 case ::com::sun::star::embed::EmbedMapUnits::TWIP
:
440 case ::com::sun::star::embed::EmbedMapUnits::PIXEL
:
444 OSL_FAIL( "Unexpected UNO map mode is provided!\n" );
445 return MAP_LASTENUMDUMMY
;
448 sal_Int32
VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit
)
450 switch( nVCLMapUnit
)
453 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
;
455 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
;
457 return ::com::sun::star::embed::EmbedMapUnits::ONE_MM
;
459 return ::com::sun::star::embed::EmbedMapUnits::ONE_CM
;
460 case MAP_1000TH_INCH
:
461 return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
;
463 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
;
465 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
;
467 return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
;
469 return ::com::sun::star::embed::EmbedMapUnits::POINT
;
471 return ::com::sun::star::embed::EmbedMapUnits::TWIP
;
473 return ::com::sun::star::embed::EmbedMapUnits::PIXEL
;
474 default: ; // avoid compiler warning
477 OSL_FAIL( "Unexpected VCL map mode is provided!\n" );
481 using namespace ::com::sun::star::util
;
483 //====================================================================
484 //= file-local helpers
485 //====================================================================
488 enum UnitConversionDirection
490 FieldUnitToMeasurementUnit
,
491 MeasurementUnitToFieldUnit
494 sal_Int16
convertMeasurementUnit( sal_Int16 _nUnit
, UnitConversionDirection eDirection
, sal_Int16
& _rFieldToUNOValueFactor
)
496 static struct _unit_table
498 FieldUnit eFieldUnit
;
499 sal_Int16 nMeasurementUnit
;
500 sal_Int16 nFieldToMeasureFactor
;
502 { FUNIT_NONE
, -1 , -1},
503 { FUNIT_MM
, MeasureUnit::MM
, 1 }, // must precede MM_10TH
504 { FUNIT_MM
, MeasureUnit::MM_10TH
, 10 },
505 { FUNIT_100TH_MM
, MeasureUnit::MM_100TH
, 1 },
506 { FUNIT_CM
, MeasureUnit::CM
, 1 },
507 { FUNIT_M
, MeasureUnit::M
, 1 },
508 { FUNIT_KM
, MeasureUnit::KM
, 1 },
509 { FUNIT_TWIP
, MeasureUnit::TWIP
, 1 },
510 { FUNIT_POINT
, MeasureUnit::POINT
, 1 },
511 { FUNIT_PICA
, MeasureUnit::PICA
, 1 },
512 { FUNIT_INCH
, MeasureUnit::INCH
, 1 }, // must precede INCH_*TH
513 { FUNIT_INCH
, MeasureUnit::INCH_10TH
, 10 },
514 { FUNIT_INCH
, MeasureUnit::INCH_100TH
, 100 },
515 { FUNIT_INCH
, MeasureUnit::INCH_1000TH
, 1000 },
516 { FUNIT_FOOT
, MeasureUnit::FOOT
, 1 },
517 { FUNIT_MILE
, MeasureUnit::MILE
, 1 },
519 for ( size_t i
= 0; i
< SAL_N_ELEMENTS( aUnits
); ++i
)
521 if ( eDirection
== FieldUnitToMeasurementUnit
)
523 if ( ( aUnits
[ i
].eFieldUnit
== (FieldUnit
)_nUnit
) && ( aUnits
[ i
].nFieldToMeasureFactor
== _rFieldToUNOValueFactor
) )
524 return aUnits
[ i
].nMeasurementUnit
;
528 if ( aUnits
[ i
].nMeasurementUnit
== _nUnit
)
530 _rFieldToUNOValueFactor
= aUnits
[ i
].nFieldToMeasureFactor
;
531 return (sal_Int16
)aUnits
[ i
].eFieldUnit
;
535 if ( eDirection
== FieldUnitToMeasurementUnit
)
538 _rFieldToUNOValueFactor
= 1;
539 return (sal_Int16
)FUNIT_NONE
;
542 //========================================================================
543 //= MeasurementUnitConversion
544 //========================================================================
545 //------------------------------------------------------------------------
546 sal_Int16
VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit
, sal_Int16 _nUNOToFieldValueFactor
)
548 return convertMeasurementUnit( (sal_Int16
)_nFieldUnit
, FieldUnitToMeasurementUnit
, _nUNOToFieldValueFactor
);
551 //------------------------------------------------------------------------
552 FieldUnit
VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit
, sal_Int16
& _rFieldToUNOValueFactor
)
554 return (FieldUnit
)convertMeasurementUnit( _nMeasurementUnit
, MeasurementUnitToFieldUnit
, _rFieldToUNOValueFactor
);
558 MapUnit
/* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16
/* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit
) throw (::com::sun::star::lang::IllegalArgumentException
)
561 switch(_nMeasureUnit
)
563 case com::sun::star::util::MeasureUnit::MM_100TH
:
564 eMode
= MAP_100TH_MM
;
568 case com::sun::star::util::MeasureUnit::MM_10TH
:
572 case com::sun::star::util::MeasureUnit::MM
:
576 case com::sun::star::util::MeasureUnit::CM
:
580 case com::sun::star::util::MeasureUnit::INCH_1000TH
:
581 eMode
= MAP_1000TH_INCH
;
584 case com::sun::star::util::MeasureUnit::INCH_100TH
:
585 eMode
= MAP_100TH_INCH
;
588 case com::sun::star::util::MeasureUnit::INCH_10TH
:
589 eMode
= MAP_10TH_INCH
;
592 case com::sun::star::util::MeasureUnit::INCH
:
596 case com::sun::star::util::MeasureUnit::POINT
:
600 case com::sun::star::util::MeasureUnit::TWIP
:
604 case com::sun::star::util::MeasureUnit::PIXEL
:
609 case com::sun::star::util::MeasureUnit::M:
611 case com::sun::star::util::MeasureUnit::KM:
613 case com::sun::star::util::MeasureUnit::PICA:
615 case com::sun::star::util::MeasureUnit::FOOT:
617 case com::sun::star::util::MeasureUnit::MILE:
619 case com::sun::star::util::MeasureUnit::PERCENT:
622 case com::sun::star::util::MeasureUnit::APPFONT
:
626 case com::sun::star::util::MeasureUnit::SYSFONT
:
631 case com::sun::star::util::MeasureUnit::RELATIVE:
632 eMode = MAP_RELATIVE;
634 case com::sun::star::util::MeasureUnit::REALAPPFONT:
635 eMode = MAP_REALAPPFONT;
640 throw ::com::sun::star::lang::IllegalArgumentException("Unsupported measure unit.", NULL
, 1 );
645 ::Size
VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size
const& _aSize
)
647 ::Size
aVCLSize(_aSize
.Width
, _aSize
.Height
);
651 com::sun::star::awt::Size
VCLUnoHelper::ConvertToAWTSize(::Size
/* VCLSize */ const& _aSize
)
653 com::sun::star::awt::Size
aAWTSize(_aSize
.Width(), _aSize
.Height());
658 ::Point
VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point
const& _aPoint
)
660 ::Point
aVCLPoint(_aPoint
.X
, _aPoint
.Y
);
664 com::sun::star::awt::Point
VCLUnoHelper::ConvertToAWTPoint(::Point
/* VCLPoint */ const& _aPoint
)
666 com::sun::star::awt::Point
aAWTPoint(_aPoint
.X(), _aPoint
.Y());
670 ::Rectangle
VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle
const & _rRect
)
672 return ::Rectangle( _rRect
.X
, _rRect
.Y
, _rRect
.X
+ _rRect
.Width
- 1, _rRect
.Y
+ _rRect
.Height
- 1 );
675 ::com::sun::star::awt::Rectangle
VCLUnoHelper::ConvertToAWTRect( ::Rectangle
const & _rRect
)
677 return ::com::sun::star::awt::Rectangle( _rRect
.Left(), _rRect
.Top(), _rRect
.GetWidth(), _rRect
.GetHeight() );
680 awt::MouseEvent
VCLUnoHelper::createMouseEvent( const ::MouseEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
682 awt::MouseEvent aMouseEvent
;
683 aMouseEvent
.Source
= _rxContext
;
685 aMouseEvent
.Modifiers
= 0;
686 if ( _rVclEvent
.IsShift() )
687 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::SHIFT
;
688 if ( _rVclEvent
.IsMod1() )
689 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD1
;
690 if ( _rVclEvent
.IsMod2() )
691 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD2
;
693 aMouseEvent
.Buttons
= 0;
694 if ( _rVclEvent
.IsLeft() )
695 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::LEFT
;
696 if ( _rVclEvent
.IsRight() )
697 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::RIGHT
;
698 if ( _rVclEvent
.IsMiddle() )
699 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::MIDDLE
;
701 aMouseEvent
.X
= _rVclEvent
.GetPosPixel().X();
702 aMouseEvent
.Y
= _rVclEvent
.GetPosPixel().Y();
703 aMouseEvent
.ClickCount
= _rVclEvent
.GetClicks();
704 aMouseEvent
.PopupTrigger
= sal_False
;
709 awt::KeyEvent
VCLUnoHelper::createKeyEvent( const ::KeyEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
711 awt::KeyEvent aKeyEvent
;
712 aKeyEvent
.Source
= _rxContext
;
714 aKeyEvent
.Modifiers
= 0;
715 if ( _rVclEvent
.GetKeyCode().IsShift() )
716 aKeyEvent
.Modifiers
|= awt::KeyModifier::SHIFT
;
717 if ( _rVclEvent
.GetKeyCode().IsMod1() )
718 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD1
;
719 if ( _rVclEvent
.GetKeyCode().IsMod2() )
720 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD2
;
721 if ( _rVclEvent
.GetKeyCode().IsMod3() )
722 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD3
;
724 aKeyEvent
.KeyCode
= _rVclEvent
.GetKeyCode().GetCode();
725 aKeyEvent
.KeyChar
= _rVclEvent
.GetCharCode();
726 aKeyEvent
.KeyFunc
= ::sal::static_int_cast
< sal_Int16
>( _rVclEvent
.GetKeyCode().GetFunction());
731 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */