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