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