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