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