xref: /AOO41X/main/toolkit/source/helper/vclunohelper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <tools/stream.hxx>
33*cdf0e10cSrcweir #include <vcl/bitmap.hxx>
34*cdf0e10cSrcweir #include <vcl/window.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/util/MeasureUnit.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/awt/XPointer.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/awt/SimpleFontMetric.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/awt/XControlContainer.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/awt/FontWidth.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/awt/MouseButton.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
53*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
54*cdf0e10cSrcweir #include <toolkit/awt/vclxbitmap.hxx>
55*cdf0e10cSrcweir #include <toolkit/awt/vclxregion.hxx>
56*cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
57*cdf0e10cSrcweir #include <toolkit/awt/vclxgraphics.hxx>
58*cdf0e10cSrcweir #include <toolkit/awt/vclxpointer.hxx>
59*cdf0e10cSrcweir #include <toolkit/awt/vclxfont.hxx>
60*cdf0e10cSrcweir #include <toolkit/controls/unocontrolcontainer.hxx>
61*cdf0e10cSrcweir #include <toolkit/controls/unocontrolcontainermodel.hxx>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <vcl/graph.hxx>
64*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir using namespace ::com::sun::star;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //	----------------------------------------------------
72*cdf0e10cSrcweir //	class VCLUnoHelper
73*cdf0e10cSrcweir //	----------------------------------------------------
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> VCLUnoHelper::CreateToolkit()
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
78*cdf0e10cSrcweir 	::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> xToolkit;
81*cdf0e10cSrcweir 	if ( xI.is() )
82*cdf0e10cSrcweir 		xToolkit = ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>( xI, ::com::sun::star::uno::UNO_QUERY );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	return xToolkit;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir BitmapEx VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap>& rxBitmap )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	BitmapEx aBmp;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic( rxBitmap, ::com::sun::star::uno::UNO_QUERY );
92*cdf0e10cSrcweir 	if( xGraphic.is() )
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		Graphic aGraphic( xGraphic );
95*cdf0e10cSrcweir 		aBmp = aGraphic.GetBitmapEx();
96*cdf0e10cSrcweir 	}
97*cdf0e10cSrcweir 	else if ( rxBitmap.is() )
98*cdf0e10cSrcweir 	{
99*cdf0e10cSrcweir 		VCLXBitmap* pVCLBitmap = VCLXBitmap::GetImplementation( rxBitmap );
100*cdf0e10cSrcweir 		if ( pVCLBitmap )
101*cdf0e10cSrcweir 			aBmp = pVCLBitmap->GetBitmap();
102*cdf0e10cSrcweir 		else
103*cdf0e10cSrcweir 		{
104*cdf0e10cSrcweir 			Bitmap aDIB, aMask;
105*cdf0e10cSrcweir 			{
106*cdf0e10cSrcweir 				::com::sun::star::uno::Sequence<sal_Int8> aBytes = rxBitmap->getDIB();
107*cdf0e10cSrcweir 				SvMemoryStream aMem( (char*) aBytes.getArray(), aBytes.getLength(), STREAM_READ );
108*cdf0e10cSrcweir 				aMem >> aDIB;
109*cdf0e10cSrcweir 			}
110*cdf0e10cSrcweir 			{
111*cdf0e10cSrcweir 				::com::sun::star::uno::Sequence<sal_Int8> aBytes = rxBitmap->getMaskDIB();
112*cdf0e10cSrcweir 				SvMemoryStream aMem( (char*) aBytes.getArray(), aBytes.getLength(), STREAM_READ );
113*cdf0e10cSrcweir 				aMem >> aMask;
114*cdf0e10cSrcweir 			}
115*cdf0e10cSrcweir 			aBmp = BitmapEx( aDIB, aMask );
116*cdf0e10cSrcweir 		}
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 	return aBmp;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	Graphic aGraphic( rBitmap );
124*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY );
125*cdf0e10cSrcweir 	return xBmp;
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& rxWindow )
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir 	VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
131*cdf0e10cSrcweir 	return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2>& rxWindow )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir 	VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
137*cdf0e10cSrcweir 	return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer>& rxWindow )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir 	VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
143*cdf0e10cSrcweir 	return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir Region VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion )
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	Region aRegion;
149*cdf0e10cSrcweir 	VCLXRegion* pVCLRegion = VCLXRegion::GetImplementation( rxRegion );
150*cdf0e10cSrcweir 	if ( pVCLRegion )
151*cdf0e10cSrcweir 		aRegion = pVCLRegion->GetRegion();
152*cdf0e10cSrcweir 	else
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > aRects = rxRegion->getRectangles();
155*cdf0e10cSrcweir 		sal_Int32 nRects = aRects.getLength();
156*cdf0e10cSrcweir 		for ( sal_Int32 n = 0; n < nRects; n++ )
157*cdf0e10cSrcweir 			aRegion.Union( VCLRectangle( aRects.getArray()[n] ) );
158*cdf0e10cSrcweir 	}
159*cdf0e10cSrcweir 	return aRegion;
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow> VCLUnoHelper::GetInterface( Window* pWindow )
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWin;
165*cdf0e10cSrcweir 	if ( pWindow )
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
168*cdf0e10cSrcweir 		xWin = xWin.query( xPeer );
169*cdf0e10cSrcweir 	}
170*cdf0e10cSrcweir 	return xWin;
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer> VCLUnoHelper::CreatePointer()
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer> xPointer = new VCLXPointer;
176*cdf0e10cSrcweir 	return xPointer;
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>& rxDevice )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	OutputDevice* pOutDev = NULL;
182*cdf0e10cSrcweir 	VCLXDevice* pDev = VCLXDevice::GetImplementation( rxDevice );
183*cdf0e10cSrcweir 	if ( pDev )
184*cdf0e10cSrcweir 		pOutDev = pDev->GetOutputDevice();
185*cdf0e10cSrcweir 	return pOutDev;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics>& rxGraphics )
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	OutputDevice* pOutDev = NULL;
191*cdf0e10cSrcweir 	VCLXGraphics* pGrf = VCLXGraphics::GetImplementation( rxGraphics );
192*cdf0e10cSrcweir 	if ( pGrf )
193*cdf0e10cSrcweir 		pOutDev = pGrf->GetOutputDevice();
194*cdf0e10cSrcweir 	return pOutDev;
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir Polygon VCLUnoHelper::CreatePolygon( const ::com::sun::star::uno::Sequence< sal_Int32 >& DataX, const ::com::sun::star::uno::Sequence< sal_Int32 >& DataY )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	sal_uInt32 nLen = DataX.getLength();
200*cdf0e10cSrcweir 	const sal_Int32* pDataX = DataX.getConstArray();
201*cdf0e10cSrcweir 	const sal_Int32* pDataY = DataY.getConstArray();
202*cdf0e10cSrcweir 	Polygon aPoly( (sal_uInt16) nLen );
203*cdf0e10cSrcweir 	for ( sal_uInt16 n = 0; n < nLen; n++ )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		Point aPnt;
206*cdf0e10cSrcweir 		aPnt.X() = pDataX[n];
207*cdf0e10cSrcweir 		aPnt.Y() = pDataY[n];
208*cdf0e10cSrcweir 		aPoly[n] = aPnt;
209*cdf0e10cSrcweir 	}
210*cdf0e10cSrcweir 	return aPoly;
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( Window* pWindow )
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
216*cdf0e10cSrcweir 	UnoControlContainer* pContainer = new UnoControlContainer( xFactory, pWindow->GetComponentInterface( sal_True ) );
217*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > x = pContainer;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     UnoControlModel* pContainerModel = new UnoControlContainerModel( xFactory );
220*cdf0e10cSrcweir 	pContainer->setModel( (::com::sun::star::awt::XControlModel*)pContainerModel );
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	return x;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth )
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	if( eWidth == WIDTH_DONTKNOW )
228*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::DONTKNOW;
229*cdf0e10cSrcweir 	else if( eWidth == WIDTH_ULTRA_CONDENSED )
230*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
231*cdf0e10cSrcweir 	else if( eWidth == WIDTH_EXTRA_CONDENSED )
232*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
233*cdf0e10cSrcweir 	else if( eWidth == WIDTH_CONDENSED )
234*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::CONDENSED;
235*cdf0e10cSrcweir 	else if( eWidth == WIDTH_SEMI_CONDENSED )
236*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
237*cdf0e10cSrcweir 	else if( eWidth == WIDTH_NORMAL )
238*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::NORMAL;
239*cdf0e10cSrcweir 	else if( eWidth == WIDTH_SEMI_EXPANDED )
240*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
241*cdf0e10cSrcweir 	else if( eWidth == WIDTH_EXPANDED )
242*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::EXPANDED;
243*cdf0e10cSrcweir 	else if( eWidth == WIDTH_EXTRA_EXPANDED )
244*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
245*cdf0e10cSrcweir 	else if( eWidth == WIDTH_ULTRA_EXPANDED )
246*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 	DBG_ERROR( "Unknown FontWidth" );
249*cdf0e10cSrcweir 	return ::com::sun::star::awt::FontWidth::DONTKNOW;
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir FontWidth VCLUnoHelper::ConvertFontWidth( float f )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir 	if( f <= ::com::sun::star::awt::FontWidth::DONTKNOW )
255*cdf0e10cSrcweir 		return WIDTH_DONTKNOW;
256*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::ULTRACONDENSED )
257*cdf0e10cSrcweir 		return WIDTH_ULTRA_CONDENSED;
258*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::EXTRACONDENSED )
259*cdf0e10cSrcweir 		return WIDTH_EXTRA_CONDENSED;
260*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::CONDENSED )
261*cdf0e10cSrcweir 		return WIDTH_CONDENSED;
262*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::SEMICONDENSED )
263*cdf0e10cSrcweir 		return WIDTH_SEMI_CONDENSED;
264*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::NORMAL )
265*cdf0e10cSrcweir 		return WIDTH_NORMAL;
266*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::SEMIEXPANDED )
267*cdf0e10cSrcweir 		return WIDTH_SEMI_EXPANDED;
268*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::EXPANDED )
269*cdf0e10cSrcweir 		return WIDTH_EXPANDED;
270*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED )
271*cdf0e10cSrcweir 		return WIDTH_EXTRA_EXPANDED;
272*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED )
273*cdf0e10cSrcweir 		return WIDTH_ULTRA_EXPANDED;
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 	DBG_ERROR( "Unknown FontWidth" );
276*cdf0e10cSrcweir 	return WIDTH_DONTKNOW;
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight )
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	if( eWeight == WEIGHT_DONTKNOW )
282*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::DONTKNOW;
283*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_THIN )
284*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::THIN;
285*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_ULTRALIGHT )
286*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
287*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_LIGHT )
288*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::LIGHT;
289*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_SEMILIGHT )
290*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::SEMILIGHT;
291*cdf0e10cSrcweir 	else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
292*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::NORMAL;
293*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_SEMIBOLD )
294*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::SEMIBOLD;
295*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_BOLD )
296*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::BOLD;
297*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_ULTRABOLD )
298*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::ULTRABOLD;
299*cdf0e10cSrcweir 	else if( eWeight == WEIGHT_BLACK )
300*cdf0e10cSrcweir 		return ::com::sun::star::awt::FontWeight::BLACK;
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 	DBG_ERROR( "Unknown FontWeigth" );
303*cdf0e10cSrcweir 	return ::com::sun::star::awt::FontWeight::DONTKNOW;
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir FontWeight VCLUnoHelper::ConvertFontWeight( float f )
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir 	if( f <= ::com::sun::star::awt::FontWeight::DONTKNOW )
309*cdf0e10cSrcweir 		return WEIGHT_DONTKNOW;
310*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::THIN )
311*cdf0e10cSrcweir 		return WEIGHT_THIN;
312*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::ULTRALIGHT )
313*cdf0e10cSrcweir 		return WEIGHT_ULTRALIGHT;
314*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::LIGHT )
315*cdf0e10cSrcweir 		return WEIGHT_LIGHT;
316*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::SEMILIGHT )
317*cdf0e10cSrcweir 		return WEIGHT_SEMILIGHT;
318*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::NORMAL )
319*cdf0e10cSrcweir 		return WEIGHT_NORMAL;
320*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::SEMIBOLD )
321*cdf0e10cSrcweir 		return WEIGHT_SEMIBOLD;
322*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::BOLD )
323*cdf0e10cSrcweir 		return WEIGHT_BOLD;
324*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::ULTRABOLD )
325*cdf0e10cSrcweir 		return WEIGHT_ULTRABOLD;
326*cdf0e10cSrcweir 	else if( f <= ::com::sun::star::awt::FontWeight::BLACK )
327*cdf0e10cSrcweir 		return WEIGHT_BLACK;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 	DBG_ERROR( "Unknown FontWeigth" );
330*cdf0e10cSrcweir 	return WEIGHT_DONTKNOW;
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir ::com::sun::star::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const Font& rFont )
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir 	::com::sun::star::awt::FontDescriptor aFD;
337*cdf0e10cSrcweir     aFD.Name = rFont.GetName();
338*cdf0e10cSrcweir     aFD.StyleName = rFont.GetStyleName();
339*cdf0e10cSrcweir     aFD.Height = (sal_Int16)rFont.GetSize().Height();
340*cdf0e10cSrcweir     aFD.Width = (sal_Int16)rFont.GetSize().Width();
341*cdf0e10cSrcweir     aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
342*cdf0e10cSrcweir     aFD.CharSet = rFont.GetCharSet();
343*cdf0e10cSrcweir     aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
344*cdf0e10cSrcweir     aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() );
345*cdf0e10cSrcweir     aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
346*cdf0e10cSrcweir     aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
347*cdf0e10cSrcweir     aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
348*cdf0e10cSrcweir     aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
349*cdf0e10cSrcweir     aFD.Orientation = rFont.GetOrientation();
350*cdf0e10cSrcweir     aFD.Kerning = rFont.IsKerning();
351*cdf0e10cSrcweir     aFD.WordLineMode = rFont.IsWordLineMode();
352*cdf0e10cSrcweir     aFD.Type = 0;	// ??? => Nur an Metric...
353*cdf0e10cSrcweir 	return aFD;
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir Font VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr, const Font& rInitFont )
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir 	Font aFont( rInitFont );
359*cdf0e10cSrcweir 	if ( rDescr.Name.getLength() )
360*cdf0e10cSrcweir 		aFont.SetName( rDescr.Name );
361*cdf0e10cSrcweir 	if ( rDescr.StyleName.getLength() )
362*cdf0e10cSrcweir     	aFont.SetStyleName( rDescr.StyleName );
363*cdf0e10cSrcweir 	if ( rDescr.Height )
364*cdf0e10cSrcweir     	aFont.SetSize( Size( rDescr.Width, rDescr.Height ) );
365*cdf0e10cSrcweir 	if ( (FontFamily)rDescr.Family != FAMILY_DONTKNOW )
366*cdf0e10cSrcweir     	aFont.SetFamily( (FontFamily)rDescr.Family );
367*cdf0e10cSrcweir 	if ( (CharSet)rDescr.CharSet != RTL_TEXTENCODING_DONTKNOW )
368*cdf0e10cSrcweir     	aFont.SetCharSet( (CharSet)rDescr.CharSet );
369*cdf0e10cSrcweir 	if ( (FontPitch)rDescr.Pitch != PITCH_DONTKNOW )
370*cdf0e10cSrcweir     	aFont.SetPitch( (FontPitch)rDescr.Pitch );
371*cdf0e10cSrcweir 	if ( rDescr.CharacterWidth )
372*cdf0e10cSrcweir     	aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) );
373*cdf0e10cSrcweir 	if ( rDescr.Weight )
374*cdf0e10cSrcweir     	aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) );
375*cdf0e10cSrcweir 	if ( (FontItalic)rDescr.Slant != ITALIC_DONTKNOW )
376*cdf0e10cSrcweir     	aFont.SetItalic( (FontItalic)rDescr.Slant );
377*cdf0e10cSrcweir 	if ( (FontUnderline)rDescr.Underline != UNDERLINE_DONTKNOW )
378*cdf0e10cSrcweir     	aFont.SetUnderline( (FontUnderline)rDescr.Underline );
379*cdf0e10cSrcweir 	if ( (FontStrikeout)rDescr.Strikeout != STRIKEOUT_DONTKNOW )
380*cdf0e10cSrcweir     	aFont.SetStrikeout( (FontStrikeout)rDescr.Strikeout );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	// Kein DONTKNOW
383*cdf0e10cSrcweir     aFont.SetOrientation( (short)rDescr.Orientation );
384*cdf0e10cSrcweir 	aFont.SetKerning( rDescr.Kerning );
385*cdf0e10cSrcweir     aFont.SetWordLineMode( rDescr.WordLineMode );
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 	return aFont;
388*cdf0e10cSrcweir }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir Font VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >& rxFont )
391*cdf0e10cSrcweir {
392*cdf0e10cSrcweir 	Font aFont;
393*cdf0e10cSrcweir 	VCLXFont* pVCLXFont = VCLXFont::GetImplementation( rxFont );
394*cdf0e10cSrcweir 	if ( pVCLXFont )
395*cdf0e10cSrcweir 		aFont = pVCLXFont->GetFont();
396*cdf0e10cSrcweir 	return aFont;
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir ::com::sun::star::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric )
401*cdf0e10cSrcweir {
402*cdf0e10cSrcweir 	::com::sun::star::awt::SimpleFontMetric aFM;
403*cdf0e10cSrcweir 	aFM.Ascent = (sal_Int16)rFontMetric.GetAscent();
404*cdf0e10cSrcweir     aFM.Descent = (sal_Int16)rFontMetric.GetDescent();
405*cdf0e10cSrcweir     aFM.Leading = (sal_Int16)rFontMetric.GetIntLeading();
406*cdf0e10cSrcweir     aFM.Slant = (sal_Int16)rFontMetric.GetSlant();
407*cdf0e10cSrcweir     aFM.FirstChar = 0x0020;
408*cdf0e10cSrcweir     aFM.LastChar = 0xFFFD;
409*cdf0e10cSrcweir 	return aFM;
410*cdf0e10cSrcweir }
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir sal_Bool VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect )
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir 	return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir 	switch( nUnoEmbedMapUnit )
420*cdf0e10cSrcweir 	{
421*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM:
422*cdf0e10cSrcweir 			return MAP_100TH_MM;
423*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM:
424*cdf0e10cSrcweir 			return MAP_10TH_MM;
425*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_MM:
426*cdf0e10cSrcweir 			return MAP_MM;
427*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_CM:
428*cdf0e10cSrcweir 			return MAP_CM;
429*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH:
430*cdf0e10cSrcweir 			return MAP_1000TH_INCH;
431*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH:
432*cdf0e10cSrcweir 			return MAP_100TH_INCH;
433*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH:
434*cdf0e10cSrcweir 			return MAP_10TH_INCH;
435*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH:
436*cdf0e10cSrcweir 			return MAP_INCH;
437*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::POINT:
438*cdf0e10cSrcweir 			return MAP_POINT;
439*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::TWIP:
440*cdf0e10cSrcweir 			return MAP_TWIP;
441*cdf0e10cSrcweir 		case ::com::sun::star::embed::EmbedMapUnits::PIXEL:
442*cdf0e10cSrcweir 			return MAP_PIXEL;
443*cdf0e10cSrcweir 	}
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "Unexpected UNO map mode is provided!\n" );
446*cdf0e10cSrcweir 	return MAP_LASTENUMDUMMY;
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit )
450*cdf0e10cSrcweir {
451*cdf0e10cSrcweir 	switch( nVCLMapUnit )
452*cdf0e10cSrcweir 	{
453*cdf0e10cSrcweir 		case MAP_100TH_MM:
454*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM;
455*cdf0e10cSrcweir 		case MAP_10TH_MM:
456*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM;
457*cdf0e10cSrcweir 		case MAP_MM:
458*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_MM;
459*cdf0e10cSrcweir 		case MAP_CM:
460*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_CM;
461*cdf0e10cSrcweir 		case MAP_1000TH_INCH:
462*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH;
463*cdf0e10cSrcweir 		case MAP_100TH_INCH:
464*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH;
465*cdf0e10cSrcweir 		case MAP_10TH_INCH:
466*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH;
467*cdf0e10cSrcweir 		case MAP_INCH:
468*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH;
469*cdf0e10cSrcweir 		case MAP_POINT:
470*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::POINT;
471*cdf0e10cSrcweir 		case MAP_TWIP:
472*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::TWIP;
473*cdf0e10cSrcweir 		case MAP_PIXEL:
474*cdf0e10cSrcweir 			return ::com::sun::star::embed::EmbedMapUnits::PIXEL;
475*cdf0e10cSrcweir 		default: ; // avoid compiler warning
476*cdf0e10cSrcweir 	}
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "Unexpected VCL map mode is provided!\n" );
479*cdf0e10cSrcweir 	return -1;
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir using namespace ::com::sun::star::util;
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir //====================================================================
485*cdf0e10cSrcweir //= file-local helpers
486*cdf0e10cSrcweir //====================================================================
487*cdf0e10cSrcweir namespace
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     enum UnitConversionDirection
490*cdf0e10cSrcweir     {
491*cdf0e10cSrcweir         FieldUnitToMeasurementUnit,
492*cdf0e10cSrcweir         MeasurementUnitToFieldUnit
493*cdf0e10cSrcweir     };
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir     sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor )
496*cdf0e10cSrcweir     {
497*cdf0e10cSrcweir         static struct _unit_table
498*cdf0e10cSrcweir         {
499*cdf0e10cSrcweir             FieldUnit eFieldUnit;
500*cdf0e10cSrcweir             sal_Int16 nMeasurementUnit;
501*cdf0e10cSrcweir             sal_Int16 nFieldToMeasureFactor;
502*cdf0e10cSrcweir         } aUnits[] = {
503*cdf0e10cSrcweir             { FUNIT_NONE,       -1 , -1},
504*cdf0e10cSrcweir             { FUNIT_MM,         MeasureUnit::MM,            1 },    // must precede MM_10TH
505*cdf0e10cSrcweir             { FUNIT_MM,         MeasureUnit::MM_10TH,       10 },
506*cdf0e10cSrcweir             { FUNIT_100TH_MM,   MeasureUnit::MM_100TH,      1 },
507*cdf0e10cSrcweir             { FUNIT_CM,         MeasureUnit::CM,            1 },
508*cdf0e10cSrcweir             { FUNIT_M,          MeasureUnit::M,             1 },
509*cdf0e10cSrcweir             { FUNIT_KM,         MeasureUnit::KM,            1 },
510*cdf0e10cSrcweir             { FUNIT_TWIP,       MeasureUnit::TWIP,          1 },
511*cdf0e10cSrcweir             { FUNIT_POINT,      MeasureUnit::POINT,         1 },
512*cdf0e10cSrcweir             { FUNIT_PICA,       MeasureUnit::PICA,          1 },
513*cdf0e10cSrcweir             { FUNIT_INCH,       MeasureUnit::INCH,          1 },    // must precede INCH_*TH
514*cdf0e10cSrcweir             { FUNIT_INCH,       MeasureUnit::INCH_10TH,     10 },
515*cdf0e10cSrcweir             { FUNIT_INCH,       MeasureUnit::INCH_100TH,    100 },
516*cdf0e10cSrcweir             { FUNIT_INCH,       MeasureUnit::INCH_1000TH,   1000 },
517*cdf0e10cSrcweir             { FUNIT_FOOT,       MeasureUnit::FOOT,          1 },
518*cdf0e10cSrcweir             { FUNIT_MILE,       MeasureUnit::MILE,          1 },
519*cdf0e10cSrcweir         };
520*cdf0e10cSrcweir         for ( size_t i = 0; i < sizeof( aUnits ) / sizeof( aUnits[0] ); ++i )
521*cdf0e10cSrcweir         {
522*cdf0e10cSrcweir             if ( eDirection == FieldUnitToMeasurementUnit )
523*cdf0e10cSrcweir             {
524*cdf0e10cSrcweir                 if ( ( aUnits[ i ].eFieldUnit == (FieldUnit)_nUnit ) && ( aUnits[ i ].nFieldToMeasureFactor == _rFieldToUNOValueFactor ) )
525*cdf0e10cSrcweir                     return aUnits[ i ].nMeasurementUnit;
526*cdf0e10cSrcweir             }
527*cdf0e10cSrcweir             else
528*cdf0e10cSrcweir             {
529*cdf0e10cSrcweir                 if ( aUnits[ i ].nMeasurementUnit == _nUnit )
530*cdf0e10cSrcweir                 {
531*cdf0e10cSrcweir                     _rFieldToUNOValueFactor = aUnits[ i ].nFieldToMeasureFactor;
532*cdf0e10cSrcweir                     return (sal_Int16)aUnits[ i ].eFieldUnit;
533*cdf0e10cSrcweir                 }
534*cdf0e10cSrcweir             }
535*cdf0e10cSrcweir         }
536*cdf0e10cSrcweir         if ( eDirection == FieldUnitToMeasurementUnit )
537*cdf0e10cSrcweir             return -1;
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir         _rFieldToUNOValueFactor = 1;
540*cdf0e10cSrcweir         return (sal_Int16)FUNIT_NONE;
541*cdf0e10cSrcweir     }
542*cdf0e10cSrcweir }
543*cdf0e10cSrcweir //========================================================================
544*cdf0e10cSrcweir //= MeasurementUnitConversion
545*cdf0e10cSrcweir //========================================================================
546*cdf0e10cSrcweir //------------------------------------------------------------------------
547*cdf0e10cSrcweir sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor )
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir     return convertMeasurementUnit( (sal_Int16)_nFieldUnit, FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor );
550*cdf0e10cSrcweir }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir //------------------------------------------------------------------------
553*cdf0e10cSrcweir FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor )
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir     return (FieldUnit)convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor );
556*cdf0e10cSrcweir }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit) throw (::com::sun::star::lang::IllegalArgumentException)
560*cdf0e10cSrcweir {
561*cdf0e10cSrcweir     MapUnit eMode;
562*cdf0e10cSrcweir     switch(_nMeasureUnit)
563*cdf0e10cSrcweir     {
564*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::MM_100TH:
565*cdf0e10cSrcweir         eMode = MAP_100TH_MM;
566*cdf0e10cSrcweir         break;
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::MM_10TH:
570*cdf0e10cSrcweir         eMode = MAP_10TH_MM;
571*cdf0e10cSrcweir         break;
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::MM:
574*cdf0e10cSrcweir         eMode = MAP_MM;
575*cdf0e10cSrcweir         break;
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::CM:
578*cdf0e10cSrcweir         eMode = MAP_CM;
579*cdf0e10cSrcweir         break;
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::INCH_1000TH:
582*cdf0e10cSrcweir         eMode = MAP_1000TH_INCH;
583*cdf0e10cSrcweir         break;
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::INCH_100TH:
586*cdf0e10cSrcweir         eMode = MAP_100TH_INCH;
587*cdf0e10cSrcweir         break;
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::INCH_10TH:
590*cdf0e10cSrcweir         eMode = MAP_10TH_INCH;
591*cdf0e10cSrcweir         break;
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::INCH:
594*cdf0e10cSrcweir         eMode = MAP_INCH;
595*cdf0e10cSrcweir         break;
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::POINT:
598*cdf0e10cSrcweir         eMode = MAP_POINT;
599*cdf0e10cSrcweir         break;
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::TWIP:
602*cdf0e10cSrcweir         eMode = MAP_TWIP;
603*cdf0e10cSrcweir         break;
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::PIXEL:
606*cdf0e10cSrcweir         eMode = MAP_PIXEL;
607*cdf0e10cSrcweir         break;
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir /*
610*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::M:
611*cdf0e10cSrcweir         break;
612*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::KM:
613*cdf0e10cSrcweir         break;
614*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::PICA:
615*cdf0e10cSrcweir         break;
616*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::FOOT:
617*cdf0e10cSrcweir         break;
618*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::MILE:
619*cdf0e10cSrcweir         break;
620*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::PERCENT:
621*cdf0e10cSrcweir         break;
622*cdf0e10cSrcweir */
623*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::APPFONT:
624*cdf0e10cSrcweir         eMode = MAP_APPFONT;
625*cdf0e10cSrcweir         break;
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::SYSFONT:
628*cdf0e10cSrcweir         eMode = MAP_SYSFONT;
629*cdf0e10cSrcweir         break;
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir /*
632*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::RELATIVE:
633*cdf0e10cSrcweir         eMode = MAP_RELATIVE;
634*cdf0e10cSrcweir         break;
635*cdf0e10cSrcweir     case com::sun::star::util::MeasureUnit::REALAPPFONT:
636*cdf0e10cSrcweir         eMode = MAP_REALAPPFONT;
637*cdf0e10cSrcweir         break;
638*cdf0e10cSrcweir */
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     default:
641*cdf0e10cSrcweir         throw ::com::sun::star::lang::IllegalArgumentException(::rtl::OUString::createFromAscii("Unsupported measure unit."), NULL, 1 );
642*cdf0e10cSrcweir     }
643*cdf0e10cSrcweir     return eMode;
644*cdf0e10cSrcweir }
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir sal_Int16 /* com.sun.star.util.MeasureUnit.* */ VCLUnoHelper::ConvertToMeasurementUnit(MapUnit /* MapModeUnit */ _eMapModeUnit)  throw (::com::sun::star::lang::IllegalArgumentException)
647*cdf0e10cSrcweir {
648*cdf0e10cSrcweir     sal_Int16 nMeasureUnit = 0;
649*cdf0e10cSrcweir     switch (_eMapModeUnit)
650*cdf0e10cSrcweir     {
651*cdf0e10cSrcweir     case MAP_100TH_MM:
652*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::MM_100TH;
653*cdf0e10cSrcweir         break;
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir     case MAP_10TH_MM:
656*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::MM_10TH;
657*cdf0e10cSrcweir         break;
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir     case MAP_MM:
660*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::MM;
661*cdf0e10cSrcweir         break;
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir     case MAP_CM:
664*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::CM;
665*cdf0e10cSrcweir         break;
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir     case MAP_1000TH_INCH:
668*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::INCH_1000TH;
669*cdf0e10cSrcweir         break;
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir     case MAP_100TH_INCH:
672*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::INCH_100TH;
673*cdf0e10cSrcweir         break;
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir     case MAP_10TH_INCH:
676*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::INCH_10TH;
677*cdf0e10cSrcweir         break;
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     case MAP_INCH:
680*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::INCH;
681*cdf0e10cSrcweir         break;
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir     case MAP_POINT:
684*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::POINT;
685*cdf0e10cSrcweir         break;
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir     case MAP_TWIP:
688*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::TWIP;
689*cdf0e10cSrcweir         break;
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir     case MAP_PIXEL:
692*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::PIXEL;
693*cdf0e10cSrcweir         break;
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir     case MAP_APPFONT:
696*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::APPFONT;
697*cdf0e10cSrcweir         break;
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir     case MAP_SYSFONT:
700*cdf0e10cSrcweir         nMeasureUnit = com::sun::star::util::MeasureUnit::SYSFONT;
701*cdf0e10cSrcweir         break;
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir /*
704*cdf0e10cSrcweir     case MAP_RELATIVE:
705*cdf0e10cSrcweir         break;
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir     case MAP_REALAPPFONT:
708*cdf0e10cSrcweir         break;
709*cdf0e10cSrcweir */
710*cdf0e10cSrcweir     default:
711*cdf0e10cSrcweir         throw ::com::sun::star::lang::IllegalArgumentException(::rtl::OUString::createFromAscii("Unsupported MapMode unit."), NULL, 1 );
712*cdf0e10cSrcweir     }
713*cdf0e10cSrcweir     return nMeasureUnit;
714*cdf0e10cSrcweir }
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir ::Size VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size const& _aSize)
717*cdf0e10cSrcweir {
718*cdf0e10cSrcweir     ::Size aVCLSize(_aSize.Width, _aSize.Height);
719*cdf0e10cSrcweir     return aVCLSize;
720*cdf0e10cSrcweir }
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir com::sun::star::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
723*cdf0e10cSrcweir {
724*cdf0e10cSrcweir     com::sun::star::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
725*cdf0e10cSrcweir     return aAWTSize;
726*cdf0e10cSrcweir }
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir ::Point VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point const& _aPoint)
730*cdf0e10cSrcweir {
731*cdf0e10cSrcweir     ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
732*cdf0e10cSrcweir     return aVCLPoint;
733*cdf0e10cSrcweir }
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir com::sun::star::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
736*cdf0e10cSrcweir {
737*cdf0e10cSrcweir     com::sun::star::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
738*cdf0e10cSrcweir     return aAWTPoint;
739*cdf0e10cSrcweir }
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir ::Rectangle VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle const & _rRect )
742*cdf0e10cSrcweir {
743*cdf0e10cSrcweir     return ::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 );
744*cdf0e10cSrcweir }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir ::com::sun::star::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::Rectangle const & _rRect )
747*cdf0e10cSrcweir {
748*cdf0e10cSrcweir     return ::com::sun::star::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() );
749*cdf0e10cSrcweir }
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
752*cdf0e10cSrcweir {
753*cdf0e10cSrcweir     awt::MouseEvent aMouseEvent;
754*cdf0e10cSrcweir     aMouseEvent.Source = _rxContext;
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir 	aMouseEvent.Modifiers = 0;
757*cdf0e10cSrcweir 	if ( _rVclEvent.IsShift() )
758*cdf0e10cSrcweir 		aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
759*cdf0e10cSrcweir 	if ( _rVclEvent.IsMod1() )
760*cdf0e10cSrcweir 	aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
761*cdf0e10cSrcweir 	if ( _rVclEvent.IsMod2() )
762*cdf0e10cSrcweir 		aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 	aMouseEvent.Buttons = 0;
765*cdf0e10cSrcweir 	if ( _rVclEvent.IsLeft() )
766*cdf0e10cSrcweir 		aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT;
767*cdf0e10cSrcweir 	if ( _rVclEvent.IsRight() )
768*cdf0e10cSrcweir 		aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT;
769*cdf0e10cSrcweir 	if ( _rVclEvent.IsMiddle() )
770*cdf0e10cSrcweir 		aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE;
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 	aMouseEvent.X = _rVclEvent.GetPosPixel().X();
773*cdf0e10cSrcweir 	aMouseEvent.Y = _rVclEvent.GetPosPixel().Y();
774*cdf0e10cSrcweir 	aMouseEvent.ClickCount = _rVclEvent.GetClicks();
775*cdf0e10cSrcweir 	aMouseEvent.PopupTrigger = sal_False;
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir     return aMouseEvent;
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
781*cdf0e10cSrcweir {
782*cdf0e10cSrcweir     awt::KeyEvent aKeyEvent;
783*cdf0e10cSrcweir     aKeyEvent.Source = _rxContext;
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir 	aKeyEvent.Modifiers = 0;
786*cdf0e10cSrcweir 	if ( _rVclEvent.GetKeyCode().IsShift() )
787*cdf0e10cSrcweir 		aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT;
788*cdf0e10cSrcweir 	if ( _rVclEvent.GetKeyCode().IsMod1() )
789*cdf0e10cSrcweir 		aKeyEvent.Modifiers |= awt::KeyModifier::MOD1;
790*cdf0e10cSrcweir 	if ( _rVclEvent.GetKeyCode().IsMod2() )
791*cdf0e10cSrcweir 		aKeyEvent.Modifiers |= awt::KeyModifier::MOD2;
792*cdf0e10cSrcweir     if ( _rVclEvent.GetKeyCode().IsMod3() )
793*cdf0e10cSrcweir             aKeyEvent.Modifiers |= awt::KeyModifier::MOD3;
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir 	aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode();
796*cdf0e10cSrcweir 	aKeyEvent.KeyChar = _rVclEvent.GetCharCode();
797*cdf0e10cSrcweir     aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction());
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir     return aKeyEvent;
800*cdf0e10cSrcweir }
801