1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclunohelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
34 #include <tools/debug.hxx>
35 #include <tools/stream.hxx>
36 #include <vcl/bitmap.hxx>
37 #include <vcl/window.hxx>
38 #include <com/sun/star/util/MeasureUnit.hpp>
39 #include <com/sun/star/awt/XBitmap.hpp>
40 #include <com/sun/star/awt/XWindow.hpp>
41 #include <com/sun/star/awt/XDevice.hpp>
42 #include <com/sun/star/awt/XPointer.hpp>
43 #include <com/sun/star/awt/SimpleFontMetric.hpp>
44 #include <com/sun/star/awt/FontDescriptor.hpp>
45 #include <com/sun/star/awt/XControlContainer.hpp>
46 #include <com/sun/star/awt/FontWeight.hpp>
47 #include <com/sun/star/awt/FontWidth.hpp>
48 #include <com/sun/star/awt/KeyModifier.hpp>
49 #include <com/sun/star/awt/MouseButton.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/embed/EmbedMapUnits.hpp>
53 #include <com/sun/star/graphic/XGraphic.hpp>
55 #include <toolkit/helper/vclunohelper.hxx>
56 #include <toolkit/helper/convert.hxx>
57 #include <toolkit/awt/vclxbitmap.hxx>
58 #include <toolkit/awt/vclxregion.hxx>
59 #include <toolkit/awt/vclxwindow.hxx>
60 #include <toolkit/awt/vclxgraphics.hxx>
61 #include <toolkit/awt/vclxpointer.hxx>
62 #include <toolkit/awt/vclxfont.hxx>
63 #include <toolkit/controls/unocontrolcontainer.hxx>
64 #include <toolkit/controls/unocontrolcontainermodel.hxx>
66 #include <vcl/graph.hxx>
67 #include <comphelper/processfactory.hxx>
69 #include <com/sun/star/awt/Size.hpp>
70 #include <com/sun/star/awt/Point.hpp>
72 using namespace ::com::sun::star
;
74 // ----------------------------------------------------
76 // ----------------------------------------------------
78 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> VCLUnoHelper::CreateToolkit()
80 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
81 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xI
= xMSF
->createInstance( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit
) );
83 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> xToolkit
;
85 xToolkit
= ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
>( xI
, ::com::sun::star::uno::UNO_QUERY
);
90 BitmapEx
VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
>& rxBitmap
)
94 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> xGraphic( rxBitmap
, ::com::sun::star::uno::UNO_QUERY
);
97 Graphic
aGraphic( xGraphic
);
98 aBmp
= aGraphic
.GetBitmapEx();
100 else if ( rxBitmap
.is() )
102 VCLXBitmap
* pVCLBitmap
= VCLXBitmap::GetImplementation( rxBitmap
);
104 aBmp
= pVCLBitmap
->GetBitmap();
109 ::com::sun::star::uno::Sequence
<sal_Int8
> aBytes
= rxBitmap
->getDIB();
110 SvMemoryStream
aMem( (char*) aBytes
.getArray(), aBytes
.getLength(), STREAM_READ
);
114 ::com::sun::star::uno::Sequence
<sal_Int8
> aBytes
= rxBitmap
->getMaskDIB();
115 SvMemoryStream
aMem( (char*) aBytes
.getArray(), aBytes
.getLength(), STREAM_READ
);
118 aBmp
= BitmapEx( aDIB
, aMask
);
124 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> VCLUnoHelper::CreateBitmap( const BitmapEx
& rBitmap
)
126 Graphic
aGraphic( rBitmap
);
127 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> xBmp( aGraphic
.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY
);
131 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& rxWindow
)
133 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
134 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
137 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
>& rxWindow
)
139 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
140 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
143 Window
* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& rxWindow
)
145 VCLXWindow
* pVCLXWindow
= VCLXWindow::GetImplementation( rxWindow
);
146 return pVCLXWindow
? pVCLXWindow
->GetWindow() : NULL
;
149 Region
VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XRegion
>& rxRegion
)
152 VCLXRegion
* pVCLRegion
= VCLXRegion::GetImplementation( rxRegion
);
154 aRegion
= pVCLRegion
->GetRegion();
157 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::Rectangle
> aRects
= rxRegion
->getRectangles();
158 sal_Int32 nRects
= aRects
.getLength();
159 for ( sal_Int32 n
= 0; n
< nRects
; n
++ )
160 aRegion
.Union( VCLRectangle( aRects
.getArray()[n
] ) );
165 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> VCLUnoHelper::GetInterface( Window
* pWindow
)
167 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> xWin
;
170 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xPeer
= pWindow
->GetComponentInterface();
171 xWin
= xWin
.query( xPeer
);
176 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPointer
> VCLUnoHelper::CreatePointer()
178 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPointer
> xPointer
= new VCLXPointer
;
182 OutputDevice
* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
>& rxDevice
)
184 OutputDevice
* pOutDev
= NULL
;
185 VCLXDevice
* pDev
= VCLXDevice::GetImplementation( rxDevice
);
187 pOutDev
= pDev
->GetOutputDevice();
191 OutputDevice
* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
>& rxGraphics
)
193 OutputDevice
* pOutDev
= NULL
;
194 VCLXGraphics
* pGrf
= VCLXGraphics::GetImplementation( rxGraphics
);
196 pOutDev
= pGrf
->GetOutputDevice();
200 Polygon
VCLUnoHelper::CreatePolygon( const ::com::sun::star::uno::Sequence
< sal_Int32
>& DataX
, const ::com::sun::star::uno::Sequence
< sal_Int32
>& DataY
)
202 sal_uInt32 nLen
= DataX
.getLength();
203 const sal_Int32
* pDataX
= DataX
.getConstArray();
204 const sal_Int32
* pDataY
= DataY
.getConstArray();
205 Polygon
aPoly( (sal_uInt16
) nLen
);
206 for ( sal_uInt16 n
= 0; n
< nLen
; n
++ )
209 aPnt
.X() = pDataX
[n
];
210 aPnt
.Y() = pDataY
[n
];
216 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> VCLUnoHelper::CreateControlContainer( Window
* pWindow
)
218 UnoControlContainer
* pContainer
= new UnoControlContainer( pWindow
->GetComponentInterface( sal_True
) );
219 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> x
= pContainer
;
221 UnoControlModel
* pContainerModel
= new UnoControlContainerModel
;
222 pContainer
->setModel( (::com::sun::star::awt::XControlModel
*)pContainerModel
);
227 float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth
)
229 if( eWidth
== WIDTH_DONTKNOW
)
230 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
231 else if( eWidth
== WIDTH_ULTRA_CONDENSED
)
232 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED
;
233 else if( eWidth
== WIDTH_EXTRA_CONDENSED
)
234 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED
;
235 else if( eWidth
== WIDTH_CONDENSED
)
236 return ::com::sun::star::awt::FontWidth::CONDENSED
;
237 else if( eWidth
== WIDTH_SEMI_CONDENSED
)
238 return ::com::sun::star::awt::FontWidth::SEMICONDENSED
;
239 else if( eWidth
== WIDTH_NORMAL
)
240 return ::com::sun::star::awt::FontWidth::NORMAL
;
241 else if( eWidth
== WIDTH_SEMI_EXPANDED
)
242 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED
;
243 else if( eWidth
== WIDTH_EXPANDED
)
244 return ::com::sun::star::awt::FontWidth::EXPANDED
;
245 else if( eWidth
== WIDTH_EXTRA_EXPANDED
)
246 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
;
247 else if( eWidth
== WIDTH_ULTRA_EXPANDED
)
248 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
;
250 DBG_ERROR( "Unknown FontWidth" );
251 return ::com::sun::star::awt::FontWidth::DONTKNOW
;
254 FontWidth
VCLUnoHelper::ConvertFontWidth( float f
)
256 if( f
<= ::com::sun::star::awt::FontWidth::DONTKNOW
)
257 return WIDTH_DONTKNOW
;
258 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRACONDENSED
)
259 return WIDTH_ULTRA_CONDENSED
;
260 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRACONDENSED
)
261 return WIDTH_EXTRA_CONDENSED
;
262 else if( f
<= ::com::sun::star::awt::FontWidth::CONDENSED
)
263 return WIDTH_CONDENSED
;
264 else if( f
<= ::com::sun::star::awt::FontWidth::SEMICONDENSED
)
265 return WIDTH_SEMI_CONDENSED
;
266 else if( f
<= ::com::sun::star::awt::FontWidth::NORMAL
)
268 else if( f
<= ::com::sun::star::awt::FontWidth::SEMIEXPANDED
)
269 return WIDTH_SEMI_EXPANDED
;
270 else if( f
<= ::com::sun::star::awt::FontWidth::EXPANDED
)
271 return WIDTH_EXPANDED
;
272 else if( f
<= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED
)
273 return WIDTH_EXTRA_EXPANDED
;
274 else if( f
<= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED
)
275 return WIDTH_ULTRA_EXPANDED
;
277 DBG_ERROR( "Unknown FontWidth" );
278 return WIDTH_DONTKNOW
;
281 float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight
)
283 if( eWeight
== WEIGHT_DONTKNOW
)
284 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
285 else if( eWeight
== WEIGHT_THIN
)
286 return ::com::sun::star::awt::FontWeight::THIN
;
287 else if( eWeight
== WEIGHT_ULTRALIGHT
)
288 return ::com::sun::star::awt::FontWeight::ULTRALIGHT
;
289 else if( eWeight
== WEIGHT_LIGHT
)
290 return ::com::sun::star::awt::FontWeight::LIGHT
;
291 else if( eWeight
== WEIGHT_SEMILIGHT
)
292 return ::com::sun::star::awt::FontWeight::SEMILIGHT
;
293 else if( ( eWeight
== WEIGHT_NORMAL
) || ( eWeight
== WEIGHT_MEDIUM
) )
294 return ::com::sun::star::awt::FontWeight::NORMAL
;
295 else if( eWeight
== WEIGHT_SEMIBOLD
)
296 return ::com::sun::star::awt::FontWeight::SEMIBOLD
;
297 else if( eWeight
== WEIGHT_BOLD
)
298 return ::com::sun::star::awt::FontWeight::BOLD
;
299 else if( eWeight
== WEIGHT_ULTRABOLD
)
300 return ::com::sun::star::awt::FontWeight::ULTRABOLD
;
301 else if( eWeight
== WEIGHT_BLACK
)
302 return ::com::sun::star::awt::FontWeight::BLACK
;
304 DBG_ERROR( "Unknown FontWeigth" );
305 return ::com::sun::star::awt::FontWeight::DONTKNOW
;
308 FontWeight
VCLUnoHelper::ConvertFontWeight( float f
)
310 if( f
<= ::com::sun::star::awt::FontWeight::DONTKNOW
)
311 return WEIGHT_DONTKNOW
;
312 else if( f
<= ::com::sun::star::awt::FontWeight::THIN
)
314 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRALIGHT
)
315 return WEIGHT_ULTRALIGHT
;
316 else if( f
<= ::com::sun::star::awt::FontWeight::LIGHT
)
318 else if( f
<= ::com::sun::star::awt::FontWeight::SEMILIGHT
)
319 return WEIGHT_SEMILIGHT
;
320 else if( f
<= ::com::sun::star::awt::FontWeight::NORMAL
)
321 return WEIGHT_NORMAL
;
322 else if( f
<= ::com::sun::star::awt::FontWeight::SEMIBOLD
)
323 return WEIGHT_SEMIBOLD
;
324 else if( f
<= ::com::sun::star::awt::FontWeight::BOLD
)
326 else if( f
<= ::com::sun::star::awt::FontWeight::ULTRABOLD
)
327 return WEIGHT_ULTRABOLD
;
328 else if( f
<= ::com::sun::star::awt::FontWeight::BLACK
)
331 DBG_ERROR( "Unknown FontWeigth" );
332 return WEIGHT_DONTKNOW
;
336 ::com::sun::star::awt::FontDescriptor
VCLUnoHelper::CreateFontDescriptor( const Font
& rFont
)
338 ::com::sun::star::awt::FontDescriptor aFD
;
339 aFD
.Name
= rFont
.GetName();
340 aFD
.StyleName
= rFont
.GetStyleName();
341 aFD
.Height
= (sal_Int16
)rFont
.GetSize().Height();
342 aFD
.Width
= (sal_Int16
)rFont
.GetSize().Width();
343 aFD
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamily());
344 aFD
.CharSet
= rFont
.GetCharSet();
345 aFD
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
346 aFD
.CharacterWidth
= VCLUnoHelper::ConvertFontWidth( rFont
.GetWidthType() );
347 aFD
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
348 aFD
.Slant
= (::com::sun::star::awt::FontSlant
)rFont
.GetItalic();
349 aFD
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
350 aFD
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
351 aFD
.Orientation
= rFont
.GetOrientation();
352 aFD
.Kerning
= rFont
.IsKerning();
353 aFD
.WordLineMode
= rFont
.IsWordLineMode();
354 aFD
.Type
= 0; // ??? => Nur an Metric...
358 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor
& rDescr
, const Font
& rInitFont
)
360 Font
aFont( rInitFont
);
361 if ( rDescr
.Name
.getLength() )
362 aFont
.SetName( rDescr
.Name
);
363 if ( rDescr
.StyleName
.getLength() )
364 aFont
.SetStyleName( rDescr
.StyleName
);
366 aFont
.SetSize( Size( rDescr
.Width
, rDescr
.Height
) );
367 if ( (FontFamily
)rDescr
.Family
!= FAMILY_DONTKNOW
)
368 aFont
.SetFamily( (FontFamily
)rDescr
.Family
);
369 if ( (CharSet
)rDescr
.CharSet
!= RTL_TEXTENCODING_DONTKNOW
)
370 aFont
.SetCharSet( (CharSet
)rDescr
.CharSet
);
371 if ( (FontPitch
)rDescr
.Pitch
!= PITCH_DONTKNOW
)
372 aFont
.SetPitch( (FontPitch
)rDescr
.Pitch
);
373 if ( rDescr
.CharacterWidth
)
374 aFont
.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr
.CharacterWidth
) );
376 aFont
.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr
.Weight
) );
377 if ( (FontItalic
)rDescr
.Slant
!= ITALIC_DONTKNOW
)
378 aFont
.SetItalic( (FontItalic
)rDescr
.Slant
);
379 if ( (FontUnderline
)rDescr
.Underline
!= UNDERLINE_DONTKNOW
)
380 aFont
.SetUnderline( (FontUnderline
)rDescr
.Underline
);
381 if ( (FontStrikeout
)rDescr
.Strikeout
!= STRIKEOUT_DONTKNOW
)
382 aFont
.SetStrikeout( (FontStrikeout
)rDescr
.Strikeout
);
385 aFont
.SetOrientation( (short)rDescr
.Orientation
);
386 aFont
.SetKerning( rDescr
.Kerning
);
387 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
392 Font
VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFont
>& rxFont
)
395 VCLXFont
* pVCLXFont
= VCLXFont::GetImplementation( rxFont
);
397 aFont
= pVCLXFont
->GetFont();
402 ::com::sun::star::awt::SimpleFontMetric
VCLUnoHelper::CreateFontMetric( const FontMetric
& rFontMetric
)
404 ::com::sun::star::awt::SimpleFontMetric aFM
;
405 aFM
.Ascent
= (sal_Int16
)rFontMetric
.GetAscent();
406 aFM
.Descent
= (sal_Int16
)rFontMetric
.GetDescent();
407 aFM
.Leading
= (sal_Int16
)rFontMetric
.GetIntLeading();
408 aFM
.Slant
= (sal_Int16
)rFontMetric
.GetSlant();
409 aFM
.FirstChar
= 0x0020;
410 aFM
.LastChar
= 0xFFFD;
414 sal_Bool
VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect
)
416 return ( !rRect
.X
&& !rRect
.Y
&& !rRect
.Width
&& !rRect
.Height
);
419 MapUnit
VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit
)
421 switch( nUnoEmbedMapUnit
)
423 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
:
425 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
:
427 case ::com::sun::star::embed::EmbedMapUnits::ONE_MM
:
429 case ::com::sun::star::embed::EmbedMapUnits::ONE_CM
:
431 case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
:
432 return MAP_1000TH_INCH
;
433 case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
:
434 return MAP_100TH_INCH
;
435 case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
:
436 return MAP_10TH_INCH
;
437 case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
:
439 case ::com::sun::star::embed::EmbedMapUnits::POINT
:
441 case ::com::sun::star::embed::EmbedMapUnits::TWIP
:
443 case ::com::sun::star::embed::EmbedMapUnits::PIXEL
:
447 OSL_ENSURE( sal_False
, "Unexpected UNO map mode is provided!\n" );
448 return MAP_LASTENUMDUMMY
;
451 sal_Int32
VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit
)
453 switch( nVCLMapUnit
)
456 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM
;
458 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM
;
460 return ::com::sun::star::embed::EmbedMapUnits::ONE_MM
;
462 return ::com::sun::star::embed::EmbedMapUnits::ONE_CM
;
463 case MAP_1000TH_INCH
:
464 return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH
;
466 return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH
;
468 return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH
;
470 return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH
;
472 return ::com::sun::star::embed::EmbedMapUnits::POINT
;
474 return ::com::sun::star::embed::EmbedMapUnits::TWIP
;
476 return ::com::sun::star::embed::EmbedMapUnits::PIXEL
;
477 default: ; // avoid compiler warning
480 OSL_ENSURE( sal_False
, "Unexpected VCL map mode is provided!\n" );
484 using namespace ::com::sun::star::util
;
486 //====================================================================
487 //= file-local helpers
488 //====================================================================
491 enum UnitConversionDirection
493 FieldUnitToMeasurementUnit
,
494 MeasurementUnitToFieldUnit
497 sal_Int16
convertMeasurementUnit( sal_Int16 _nUnit
, UnitConversionDirection eDirection
, sal_Int16
& _rFieldToUNOValueFactor
)
499 static struct _unit_table
501 FieldUnit eFieldUnit
;
502 sal_Int16 nMeasurementUnit
;
503 sal_Int16 nFieldToMeasureFactor
;
505 { FUNIT_NONE
, -1 , -1},
506 { FUNIT_MM
, MeasureUnit::MM
, 1 }, // must precede MM_10TH
507 { FUNIT_MM
, MeasureUnit::MM_10TH
, 10 },
508 { FUNIT_100TH_MM
, MeasureUnit::MM_100TH
, 1 },
509 { FUNIT_CM
, MeasureUnit::CM
, 1 },
510 { FUNIT_M
, MeasureUnit::M
, 1 },
511 { FUNIT_KM
, MeasureUnit::KM
, 1 },
512 { FUNIT_TWIP
, MeasureUnit::TWIP
, 1 },
513 { FUNIT_POINT
, MeasureUnit::POINT
, 1 },
514 { FUNIT_PICA
, MeasureUnit::PICA
, 1 },
515 { FUNIT_INCH
, MeasureUnit::INCH
, 1 }, // must precede INCH_*TH
516 { FUNIT_INCH
, MeasureUnit::INCH_10TH
, 10 },
517 { FUNIT_INCH
, MeasureUnit::INCH_100TH
, 100 },
518 { FUNIT_INCH
, MeasureUnit::INCH_1000TH
, 1000 },
519 { FUNIT_FOOT
, MeasureUnit::FOOT
, 1 },
520 { FUNIT_MILE
, MeasureUnit::MILE
, 1 },
522 for ( size_t i
= 0; i
< sizeof( aUnits
) / sizeof( aUnits
[0] ); ++i
)
524 if ( eDirection
== FieldUnitToMeasurementUnit
)
526 if ( ( aUnits
[ i
].eFieldUnit
== (FieldUnit
)_nUnit
) && ( aUnits
[ i
].nFieldToMeasureFactor
== _rFieldToUNOValueFactor
) )
527 return aUnits
[ i
].nMeasurementUnit
;
531 if ( aUnits
[ i
].nMeasurementUnit
== _nUnit
)
533 _rFieldToUNOValueFactor
= aUnits
[ i
].nFieldToMeasureFactor
;
534 return (sal_Int16
)aUnits
[ i
].eFieldUnit
;
538 if ( eDirection
== FieldUnitToMeasurementUnit
)
541 _rFieldToUNOValueFactor
= 1;
542 return (sal_Int16
)FUNIT_NONE
;
545 //========================================================================
546 //= MeasurementUnitConversion
547 //========================================================================
548 //------------------------------------------------------------------------
549 sal_Int16
VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit
, sal_Int16 _nUNOToFieldValueFactor
)
551 return convertMeasurementUnit( (sal_Int16
)_nFieldUnit
, FieldUnitToMeasurementUnit
, _nUNOToFieldValueFactor
);
554 //------------------------------------------------------------------------
555 FieldUnit
VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit
, sal_Int16
& _rFieldToUNOValueFactor
)
557 return (FieldUnit
)convertMeasurementUnit( _nMeasurementUnit
, MeasurementUnitToFieldUnit
, _rFieldToUNOValueFactor
);
561 MapUnit
/* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16
/* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit
) throw (::com::sun::star::lang::IllegalArgumentException
)
564 switch(_nMeasureUnit
)
566 case com::sun::star::util::MeasureUnit::MM_100TH
:
567 eMode
= MAP_100TH_MM
;
571 case com::sun::star::util::MeasureUnit::MM_10TH
:
575 case com::sun::star::util::MeasureUnit::MM
:
579 case com::sun::star::util::MeasureUnit::CM
:
583 case com::sun::star::util::MeasureUnit::INCH_1000TH
:
584 eMode
= MAP_1000TH_INCH
;
587 case com::sun::star::util::MeasureUnit::INCH_100TH
:
588 eMode
= MAP_100TH_INCH
;
591 case com::sun::star::util::MeasureUnit::INCH_10TH
:
592 eMode
= MAP_10TH_INCH
;
595 case com::sun::star::util::MeasureUnit::INCH
:
599 case com::sun::star::util::MeasureUnit::POINT
:
603 case com::sun::star::util::MeasureUnit::TWIP
:
607 case com::sun::star::util::MeasureUnit::PIXEL
:
612 case com::sun::star::util::MeasureUnit::M:
614 case com::sun::star::util::MeasureUnit::KM:
616 case com::sun::star::util::MeasureUnit::PICA:
618 case com::sun::star::util::MeasureUnit::FOOT:
620 case com::sun::star::util::MeasureUnit::MILE:
622 case com::sun::star::util::MeasureUnit::PERCENT:
625 case com::sun::star::util::MeasureUnit::APPFONT
:
629 case com::sun::star::util::MeasureUnit::SYSFONT
:
634 case com::sun::star::util::MeasureUnit::RELATIVE:
635 eMode = MAP_RELATIVE;
637 case com::sun::star::util::MeasureUnit::REALAPPFONT:
638 eMode = MAP_REALAPPFONT;
643 throw ::com::sun::star::lang::IllegalArgumentException(::rtl::OUString::createFromAscii("Unsupported measure unit."), NULL
, 1 );
648 sal_Int16
/* com.sun.star.util.MeasureUnit.* */ VCLUnoHelper::ConvertToMeasurementUnit(MapUnit
/* MapModeUnit */ _eMapModeUnit
) throw (::com::sun::star::lang::IllegalArgumentException
)
650 sal_Int16 nMeasureUnit
= 0;
651 switch (_eMapModeUnit
)
654 nMeasureUnit
= com::sun::star::util::MeasureUnit::MM_100TH
;
658 nMeasureUnit
= com::sun::star::util::MeasureUnit::MM_10TH
;
662 nMeasureUnit
= com::sun::star::util::MeasureUnit::MM
;
666 nMeasureUnit
= com::sun::star::util::MeasureUnit::CM
;
669 case MAP_1000TH_INCH
:
670 nMeasureUnit
= com::sun::star::util::MeasureUnit::INCH_1000TH
;
674 nMeasureUnit
= com::sun::star::util::MeasureUnit::INCH_100TH
;
678 nMeasureUnit
= com::sun::star::util::MeasureUnit::INCH_10TH
;
682 nMeasureUnit
= com::sun::star::util::MeasureUnit::INCH
;
686 nMeasureUnit
= com::sun::star::util::MeasureUnit::POINT
;
690 nMeasureUnit
= com::sun::star::util::MeasureUnit::TWIP
;
694 nMeasureUnit
= com::sun::star::util::MeasureUnit::PIXEL
;
698 nMeasureUnit
= com::sun::star::util::MeasureUnit::APPFONT
;
702 nMeasureUnit
= com::sun::star::util::MeasureUnit::SYSFONT
;
709 case MAP_REALAPPFONT:
713 throw ::com::sun::star::lang::IllegalArgumentException(::rtl::OUString::createFromAscii("Unsupported MapMode unit."), NULL
, 1 );
718 ::Size
VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size
const& _aSize
)
720 ::Size
aVCLSize(_aSize
.Width
, _aSize
.Height
);
724 com::sun::star::awt::Size
VCLUnoHelper::ConvertToAWTSize(::Size
/* VCLSize */ const& _aSize
)
726 com::sun::star::awt::Size
aAWTSize(_aSize
.Width(), _aSize
.Height());
731 ::Point
VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point
const& _aPoint
)
733 ::Point
aVCLPoint(_aPoint
.X
, _aPoint
.Y
);
737 com::sun::star::awt::Point
VCLUnoHelper::ConvertToAWTPoint(::Point
/* VCLPoint */ const& _aPoint
)
739 com::sun::star::awt::Point
aAWTPoint(_aPoint
.X(), _aPoint
.Y());
743 ::Rectangle
VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle
const & _rRect
)
745 return ::Rectangle( _rRect
.X
, _rRect
.Y
, _rRect
.X
+ _rRect
.Width
- 1, _rRect
.Y
+ _rRect
.Height
- 1 );
748 ::com::sun::star::awt::Rectangle
VCLUnoHelper::ConvertToAWTRect( ::Rectangle
const & _rRect
)
750 return ::com::sun::star::awt::Rectangle( _rRect
.Left(), _rRect
.Top(), _rRect
.GetWidth(), _rRect
.GetHeight() );
753 awt::MouseEvent
VCLUnoHelper::createMouseEvent( const ::MouseEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
755 awt::MouseEvent aMouseEvent
;
756 aMouseEvent
.Source
= _rxContext
;
758 aMouseEvent
.Modifiers
= 0;
759 if ( _rVclEvent
.IsShift() )
760 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::SHIFT
;
761 if ( _rVclEvent
.IsMod1() )
762 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD1
;
763 if ( _rVclEvent
.IsMod2() )
764 aMouseEvent
.Modifiers
|= ::com::sun::star::awt::KeyModifier::MOD2
;
766 aMouseEvent
.Buttons
= 0;
767 if ( _rVclEvent
.IsLeft() )
768 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::LEFT
;
769 if ( _rVclEvent
.IsRight() )
770 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::RIGHT
;
771 if ( _rVclEvent
.IsMiddle() )
772 aMouseEvent
.Buttons
|= ::com::sun::star::awt::MouseButton::MIDDLE
;
774 aMouseEvent
.X
= _rVclEvent
.GetPosPixel().X();
775 aMouseEvent
.Y
= _rVclEvent
.GetPosPixel().Y();
776 aMouseEvent
.ClickCount
= _rVclEvent
.GetClicks();
777 aMouseEvent
.PopupTrigger
= sal_False
;
782 awt::KeyEvent
VCLUnoHelper::createKeyEvent( const ::KeyEvent
& _rVclEvent
, const uno::Reference
< uno::XInterface
>& _rxContext
)
784 awt::KeyEvent aKeyEvent
;
785 aKeyEvent
.Source
= _rxContext
;
787 aKeyEvent
.Modifiers
= 0;
788 if ( _rVclEvent
.GetKeyCode().IsShift() )
789 aKeyEvent
.Modifiers
|= awt::KeyModifier::SHIFT
;
790 if ( _rVclEvent
.GetKeyCode().IsMod1() )
791 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD1
;
792 if ( _rVclEvent
.GetKeyCode().IsMod2() )
793 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD2
;
794 if ( _rVclEvent
.GetKeyCode().IsMod3() )
795 aKeyEvent
.Modifiers
|= awt::KeyModifier::MOD3
;
797 aKeyEvent
.KeyCode
= _rVclEvent
.GetKeyCode().GetCode();
798 aKeyEvent
.KeyChar
= _rVclEvent
.GetCharCode();
799 aKeyEvent
.KeyFunc
= ::sal::static_int_cast
< sal_Int16
>( _rVclEvent
.GetKeyCode().GetFunction());