/src/libreoffice/toolkit/source/helper/vclunohelper.cxx
Line | Count | Source |
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/fldunit.hxx> |
21 | | #include <tools/mapunit.hxx> |
22 | | #include <tools/stream.hxx> |
23 | | #include <vcl/dibtools.hxx> |
24 | | #include <vcl/event.hxx> |
25 | | #include <vcl/graph.hxx> |
26 | | #include <vcl/graphic/BitmapHelper.hxx> |
27 | | #include <vcl/metric.hxx> |
28 | | #include <vcl/ptrstyle.hxx> |
29 | | #include <vcl/unohelp.hxx> |
30 | | #include <vcl/window.hxx> |
31 | | #include <com/sun/star/util/MeasureUnit.hpp> |
32 | | #include <com/sun/star/awt/XBitmap.hpp> |
33 | | #include <com/sun/star/awt/XWindow.hpp> |
34 | | #include <com/sun/star/awt/XDevice.hpp> |
35 | | #include <com/sun/star/awt/SimpleFontMetric.hpp> |
36 | | #include <com/sun/star/awt/FontDescriptor.hpp> |
37 | | #include <com/sun/star/awt/XControlContainer.hpp> |
38 | | #include <com/sun/star/awt/KeyModifier.hpp> |
39 | | #include <com/sun/star/awt/MouseButton.hpp> |
40 | | #include <com/sun/star/embed/EmbedMapUnits.hpp> |
41 | | #include <com/sun/star/graphic/XGraphic.hpp> |
42 | | #include <toolkit/helper/vclunohelper.hxx> |
43 | | #include <awt/vclxbitmap.hxx> |
44 | | #include <awt/vclxregion.hxx> |
45 | | #include <toolkit/awt/vclxwindow.hxx> |
46 | | #include <awt/vclxgraphics.hxx> |
47 | | #include <toolkit/awt/vclxfont.hxx> |
48 | | #include <toolkit/controls/unocontrolcontainer.hxx> |
49 | | #include <toolkit/controls/unocontrolcontainermodel.hxx> |
50 | | #include <comphelper/processfactory.hxx> |
51 | | |
52 | | #include <com/sun/star/awt/Toolkit.hpp> |
53 | | |
54 | | using namespace ::com::sun::star; |
55 | | |
56 | | |
57 | | uno::Reference< css::awt::XToolkit> VCLUnoHelper::CreateToolkit() |
58 | 0 | { |
59 | 0 | const uno::Reference< uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext(); |
60 | 0 | uno::Reference< awt::XToolkit> xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW ); |
61 | 0 | return xToolkit; |
62 | 0 | } |
63 | | |
64 | | Bitmap VCLUnoHelper::GetBitmap( const css::uno::Reference< css::awt::XBitmap>& rxBitmap ) |
65 | 0 | { |
66 | 0 | if (VCLXBitmap* pVCLBitmap = dynamic_cast<VCLXBitmap*>(rxBitmap.get())) |
67 | 0 | return pVCLBitmap->GetBitmap(); |
68 | | |
69 | 0 | return vcl::GetBitmap(rxBitmap); |
70 | 0 | } |
71 | | |
72 | | css::uno::Reference< css::awt::XBitmap> VCLUnoHelper::CreateBitmap( const Bitmap& rBitmap ) |
73 | 0 | { |
74 | 0 | return Graphic(rBitmap).GetXGraphic().query<css::awt::XBitmap>(); |
75 | 0 | } |
76 | | |
77 | | vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindow>& rxWindow ) |
78 | 607k | { |
79 | 607k | VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() ); |
80 | 607k | return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr; |
81 | 607k | } |
82 | | |
83 | | vcl::Window* VCLUnoHelper::GetWindow( const css::uno::Reference< css::awt::XWindowPeer>& rxWindow ) |
84 | 0 | { |
85 | 0 | VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( rxWindow.get() ); |
86 | 0 | return pVCLXWindow ? pVCLXWindow->GetWindow() : nullptr; |
87 | 0 | } |
88 | | |
89 | | vcl::Region VCLUnoHelper::GetRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion ) |
90 | 0 | { |
91 | 0 | vcl::Region aRegion; |
92 | 0 | VCLXRegion* pVCLRegion = dynamic_cast<VCLXRegion*>( rxRegion.get() ); |
93 | 0 | if ( pVCLRegion ) |
94 | 0 | aRegion = pVCLRegion->GetRegion(); |
95 | 0 | else |
96 | 0 | { |
97 | 0 | const css::uno::Sequence< css::awt::Rectangle > aRects = rxRegion->getRectangles(); |
98 | 0 | for ( const auto& rRect : aRects ) |
99 | 0 | aRegion.Union(vcl::unohelper::ConvertToVCLRect(rRect)); |
100 | 0 | } |
101 | 0 | return aRegion; |
102 | 0 | } |
103 | | |
104 | | css::uno::Reference< css::awt::XWindow> VCLUnoHelper::GetInterface( vcl::Window* pWindow ) |
105 | 13.0k | { |
106 | 13.0k | css::uno::Reference< css::awt::XWindow > xWin; |
107 | 13.0k | if ( pWindow ) |
108 | 13.0k | { |
109 | 13.0k | css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface(); |
110 | 13.0k | xWin.set(xPeer, css::uno::UNO_QUERY); |
111 | 13.0k | } |
112 | 13.0k | return xWin; |
113 | 13.0k | } |
114 | | |
115 | | OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XDevice>& rxDevice ) |
116 | 155k | { |
117 | 155k | VclPtr<OutputDevice> pOutDev; |
118 | 155k | VCLXDevice* pDev = dynamic_cast<VCLXDevice*>( rxDevice.get() ); |
119 | 155k | if ( pDev ) |
120 | 155k | pOutDev = pDev->GetOutputDevice(); |
121 | 155k | return pOutDev; |
122 | 155k | } |
123 | | |
124 | | OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XGraphics>& rxGraphics ) |
125 | 0 | { |
126 | 0 | OutputDevice* pOutDev = nullptr; |
127 | 0 | VCLXGraphics* pGrf = dynamic_cast<VCLXGraphics*>( rxGraphics.get() ); |
128 | 0 | if ( pGrf ) |
129 | 0 | pOutDev = pGrf->GetOutputDevice(); |
130 | 0 | return pOutDev; |
131 | 0 | } |
132 | | |
133 | | tools::Polygon VCLUnoHelper::CreatePolygon( const css::uno::Sequence< sal_Int32 >& DataX, |
134 | | const css::uno::Sequence< sal_Int32 >& DataY ) |
135 | 0 | { |
136 | 0 | sal_Int32 nLen = DataX.getLength(); |
137 | 0 | const sal_Int32* pDataX = DataX.getConstArray(); |
138 | 0 | const sal_Int32* pDataY = DataY.getConstArray(); |
139 | 0 | tools::Polygon aPoly( static_cast<sal_uInt16>(nLen) ); |
140 | 0 | for ( sal_Int32 n = 0; n < nLen; n++ ) |
141 | 0 | { |
142 | 0 | Point aPnt; |
143 | 0 | aPnt.setX( pDataX[n] ); |
144 | 0 | aPnt.setY( pDataY[n] ); |
145 | 0 | aPoly[n] = aPnt; |
146 | 0 | } |
147 | 0 | return aPoly; |
148 | 0 | } |
149 | | |
150 | | rtl::Reference<UnoControlContainer> VCLUnoHelper::CreateControlContainer( vcl::Window* pWindow ) |
151 | 32 | { |
152 | 32 | rtl::Reference<UnoControlContainer> pContainer = new UnoControlContainer( pWindow->GetComponentInterface() ); |
153 | | |
154 | 32 | rtl::Reference<UnoControlModel> pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() ); |
155 | 32 | pContainer->setModel( pContainerModel ); |
156 | | |
157 | 32 | return pContainer; |
158 | 32 | } |
159 | | |
160 | | css::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const vcl::Font& rFont ) |
161 | 0 | { |
162 | 0 | css::awt::FontDescriptor aFD; |
163 | 0 | aFD.Name = rFont.GetFamilyName(); |
164 | 0 | aFD.StyleName = rFont.GetStyleName(); |
165 | 0 | aFD.Height = static_cast<sal_Int16>(rFont.GetFontSize().Height()); |
166 | 0 | aFD.Width = static_cast<sal_Int16>(rFont.GetFontSize().Width()); |
167 | 0 | aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType()); |
168 | 0 | aFD.CharSet = rFont.GetCharSet(); |
169 | 0 | aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch()); |
170 | 0 | aFD.CharacterWidth = vcl::unohelper::ConvertFontWidth(rFont.GetWidthType()); |
171 | 0 | aFD.Weight = vcl::unohelper::ConvertFontWeight(rFont.GetWeight()); |
172 | 0 | aFD.Slant = vcl::unohelper::ConvertFontSlant(rFont.GetItalic()); |
173 | 0 | aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline()); |
174 | 0 | aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout()); |
175 | 0 | aFD.Orientation = rFont.GetOrientation().get() / 10.0; |
176 | 0 | aFD.Kerning = rFont.IsKerning(); |
177 | 0 | aFD.WordLineMode = rFont.IsWordLineMode(); |
178 | 0 | aFD.Type = 0; // ??? => Only in Metric... |
179 | 0 | return aFD; |
180 | 0 | } |
181 | | |
182 | | vcl::Font VCLUnoHelper::CreateFont( const css::awt::FontDescriptor& rDescr, const vcl::Font& rInitFont ) |
183 | 10.9k | { |
184 | 10.9k | vcl::Font aFont( rInitFont ); |
185 | 10.9k | if ( !rDescr.Name.isEmpty() ) |
186 | 10.9k | aFont.SetFamilyName( rDescr.Name ); |
187 | 10.9k | if ( !rDescr.StyleName.isEmpty() ) |
188 | 0 | aFont.SetStyleName( rDescr.StyleName ); |
189 | 10.9k | if ( rDescr.Height ) |
190 | 10.9k | aFont.SetFontSize( Size( rDescr.Width, rDescr.Height ) ); |
191 | 10.9k | if ( static_cast<FontFamily>(rDescr.Family) != FAMILY_DONTKNOW ) |
192 | 8.29k | aFont.SetFamily( static_cast<FontFamily>(rDescr.Family) ); |
193 | 10.9k | if ( static_cast<rtl_TextEncoding>(rDescr.CharSet) != RTL_TEXTENCODING_DONTKNOW ) |
194 | 1.29k | aFont.SetCharSet( static_cast<rtl_TextEncoding>(rDescr.CharSet) ); |
195 | 10.9k | if ( static_cast<FontPitch>(rDescr.Pitch) != PITCH_DONTKNOW ) |
196 | 0 | aFont.SetPitch( static_cast<FontPitch>(rDescr.Pitch) ); |
197 | 10.9k | if ( rDescr.CharacterWidth ) |
198 | 10.9k | aFont.SetWidthType(vcl::unohelper::ConvertFontWidth(rDescr.CharacterWidth)); |
199 | 10.9k | if ( rDescr.Weight ) |
200 | 10.9k | aFont.SetWeight(vcl::unohelper::ConvertFontWeight(rDescr.Weight)); |
201 | 10.9k | if ( rDescr.Slant != css::awt::FontSlant_DONTKNOW ) |
202 | 10.9k | aFont.SetItalic(vcl::unohelper::ConvertFontSlant(rDescr.Slant)); |
203 | 10.9k | if ( static_cast<FontLineStyle>(rDescr.Underline) != LINESTYLE_DONTKNOW ) |
204 | 10.9k | aFont.SetUnderline( static_cast<FontLineStyle>(rDescr.Underline) ); |
205 | 10.9k | if ( static_cast<FontStrikeout>(rDescr.Strikeout) != STRIKEOUT_DONTKNOW ) |
206 | 10.9k | aFont.SetStrikeout( static_cast<FontStrikeout>(rDescr.Strikeout) ); |
207 | | |
208 | | // Not DONTKNOW |
209 | 10.9k | aFont.SetOrientation( Degree10(static_cast<sal_Int16>(rDescr.Orientation * 10)) ); |
210 | 10.9k | aFont.SetKerning( static_cast<FontKerning>(rDescr.Kerning) ); |
211 | 10.9k | aFont.SetWordLineMode( rDescr.WordLineMode ); |
212 | | |
213 | 10.9k | return aFont; |
214 | 10.9k | } |
215 | | |
216 | | vcl::Font VCLUnoHelper::CreateFont( const css::uno::Reference< css::awt::XFont >& rxFont ) |
217 | 0 | { |
218 | 0 | vcl::Font aFont; |
219 | 0 | VCLXFont* pVCLXFont = dynamic_cast<VCLXFont*>( rxFont.get() ); |
220 | 0 | if ( pVCLXFont ) |
221 | 0 | aFont = pVCLXFont->GetFont(); |
222 | 0 | return aFont; |
223 | 0 | } |
224 | | |
225 | | |
226 | | css::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric ) |
227 | 0 | { |
228 | 0 | css::awt::SimpleFontMetric aFM; |
229 | 0 | aFM.Ascent = static_cast<sal_Int16>(rFontMetric.GetAscent()); |
230 | 0 | aFM.Descent = static_cast<sal_Int16>(rFontMetric.GetDescent()); |
231 | 0 | aFM.Leading = static_cast<sal_Int16>(rFontMetric.GetInternalLeading()); |
232 | 0 | aFM.Slant = static_cast<sal_Int16>(rFontMetric.GetSlant()); |
233 | 0 | aFM.FirstChar = 0x0020; |
234 | 0 | aFM.LastChar = 0xFFFD; |
235 | 0 | return aFM; |
236 | 0 | } |
237 | | |
238 | | bool VCLUnoHelper::IsZero(const css::awt::Rectangle& rRect) |
239 | 99.7k | { |
240 | 99.7k | return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height ); |
241 | 99.7k | } |
242 | | |
243 | | MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit ) |
244 | 0 | { |
245 | 0 | switch( nUnoEmbedMapUnit ) |
246 | 0 | { |
247 | 0 | case css::embed::EmbedMapUnits::ONE_100TH_MM: |
248 | 0 | return MapUnit::Map100thMM; |
249 | 0 | case css::embed::EmbedMapUnits::ONE_10TH_MM: |
250 | 0 | return MapUnit::Map10thMM; |
251 | 0 | case css::embed::EmbedMapUnits::ONE_MM: |
252 | 0 | return MapUnit::MapMM; |
253 | 0 | case css::embed::EmbedMapUnits::ONE_CM: |
254 | 0 | return MapUnit::MapCM; |
255 | 0 | case css::embed::EmbedMapUnits::ONE_1000TH_INCH: |
256 | 0 | return MapUnit::Map1000thInch; |
257 | 0 | case css::embed::EmbedMapUnits::ONE_100TH_INCH: |
258 | 0 | return MapUnit::Map100thInch; |
259 | 0 | case css::embed::EmbedMapUnits::ONE_10TH_INCH: |
260 | 0 | return MapUnit::Map10thInch; |
261 | 0 | case css::embed::EmbedMapUnits::ONE_INCH: |
262 | 0 | return MapUnit::MapInch; |
263 | 0 | case css::embed::EmbedMapUnits::POINT: |
264 | 0 | return MapUnit::MapPoint; |
265 | 0 | case css::embed::EmbedMapUnits::TWIP: |
266 | 0 | return MapUnit::MapTwip; |
267 | 0 | case css::embed::EmbedMapUnits::PIXEL: |
268 | 0 | return MapUnit::MapPixel; |
269 | 0 | } |
270 | | |
271 | 0 | OSL_FAIL( "Unexpected UNO map mode is provided!" ); |
272 | 0 | return MapUnit::LASTENUMDUMMY; |
273 | 0 | } |
274 | | |
275 | | sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit ) |
276 | 0 | { |
277 | 0 | switch( nVCLMapUnit ) |
278 | 0 | { |
279 | 0 | case MapUnit::Map100thMM: |
280 | 0 | return css::embed::EmbedMapUnits::ONE_100TH_MM; |
281 | 0 | case MapUnit::Map10thMM: |
282 | 0 | return css::embed::EmbedMapUnits::ONE_10TH_MM; |
283 | 0 | case MapUnit::MapMM: |
284 | 0 | return css::embed::EmbedMapUnits::ONE_MM; |
285 | 0 | case MapUnit::MapCM: |
286 | 0 | return css::embed::EmbedMapUnits::ONE_CM; |
287 | 0 | case MapUnit::Map1000thInch: |
288 | 0 | return css::embed::EmbedMapUnits::ONE_1000TH_INCH; |
289 | 0 | case MapUnit::Map100thInch: |
290 | 0 | return css::embed::EmbedMapUnits::ONE_100TH_INCH; |
291 | 0 | case MapUnit::Map10thInch: |
292 | 0 | return css::embed::EmbedMapUnits::ONE_10TH_INCH; |
293 | 0 | case MapUnit::MapInch: |
294 | 0 | return css::embed::EmbedMapUnits::ONE_INCH; |
295 | 0 | case MapUnit::MapPoint: |
296 | 0 | return css::embed::EmbedMapUnits::POINT; |
297 | 0 | case MapUnit::MapTwip: |
298 | 0 | return css::embed::EmbedMapUnits::TWIP; |
299 | 0 | case MapUnit::MapPixel: |
300 | 0 | return css::embed::EmbedMapUnits::PIXEL; |
301 | 0 | default: ; // avoid compiler warning |
302 | 0 | } |
303 | | |
304 | 0 | OSL_FAIL( "Unexpected VCL map mode is provided!" ); |
305 | 0 | return -1; |
306 | 0 | } |
307 | | |
308 | | using namespace ::com::sun::star::util; |
309 | | |
310 | | |
311 | | namespace |
312 | | { |
313 | | enum UnitConversionDirection |
314 | | { |
315 | | FieldUnitToMeasurementUnit, |
316 | | MeasurementUnitToFieldUnit |
317 | | }; |
318 | | |
319 | | sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor ) |
320 | 0 | { |
321 | 0 | static struct _unit_table |
322 | 0 | { |
323 | 0 | FieldUnit eFieldUnit; |
324 | 0 | sal_Int16 nMeasurementUnit; |
325 | 0 | sal_Int16 nFieldToMeasureFactor; |
326 | 0 | } const aUnits[] = { |
327 | 0 | { FieldUnit::NONE, -1 , -1}, |
328 | 0 | { FieldUnit::MM, MeasureUnit::MM, 1 }, // must precede MM_10TH |
329 | 0 | { FieldUnit::MM, MeasureUnit::MM_10TH, 10 }, |
330 | 0 | { FieldUnit::MM_100TH, MeasureUnit::MM_100TH, 1 }, |
331 | 0 | { FieldUnit::CM, MeasureUnit::CM, 1 }, |
332 | 0 | { FieldUnit::M, MeasureUnit::M, 1 }, |
333 | 0 | { FieldUnit::KM, MeasureUnit::KM, 1 }, |
334 | 0 | { FieldUnit::TWIP, MeasureUnit::TWIP, 1 }, |
335 | 0 | { FieldUnit::POINT, MeasureUnit::POINT, 1 }, |
336 | 0 | { FieldUnit::PICA, MeasureUnit::PICA, 1 }, |
337 | 0 | { FieldUnit::INCH, MeasureUnit::INCH, 1 }, // must precede INCH_*TH |
338 | 0 | { FieldUnit::INCH, MeasureUnit::INCH_10TH, 10 }, |
339 | 0 | { FieldUnit::INCH, MeasureUnit::INCH_100TH, 100 }, |
340 | 0 | { FieldUnit::INCH, MeasureUnit::INCH_1000TH, 1000 }, |
341 | 0 | { FieldUnit::FOOT, MeasureUnit::FOOT, 1 }, |
342 | 0 | { FieldUnit::MILE, MeasureUnit::MILE, 1 }, |
343 | 0 | }; |
344 | 0 | for (auto & aUnit : aUnits) |
345 | 0 | { |
346 | 0 | if ( eDirection == FieldUnitToMeasurementUnit ) |
347 | 0 | { |
348 | 0 | if ( ( aUnit.eFieldUnit == static_cast<FieldUnit>(_nUnit) ) && ( aUnit.nFieldToMeasureFactor == _rFieldToUNOValueFactor ) ) |
349 | 0 | return aUnit.nMeasurementUnit; |
350 | 0 | } |
351 | 0 | else |
352 | 0 | { |
353 | 0 | if ( aUnit.nMeasurementUnit == _nUnit ) |
354 | 0 | { |
355 | 0 | _rFieldToUNOValueFactor = aUnit.nFieldToMeasureFactor; |
356 | 0 | return static_cast<sal_Int16>(aUnit.eFieldUnit); |
357 | 0 | } |
358 | 0 | } |
359 | 0 | } |
360 | 0 | if ( eDirection == FieldUnitToMeasurementUnit ) |
361 | 0 | return -1; |
362 | | |
363 | 0 | _rFieldToUNOValueFactor = 1; |
364 | 0 | return sal_Int16(FieldUnit::NONE); |
365 | 0 | } |
366 | | } |
367 | | |
368 | | //= MeasurementUnitConversion |
369 | | |
370 | | |
371 | | sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor ) |
372 | 0 | { |
373 | 0 | return convertMeasurementUnit( static_cast<sal_Int16>(_nFieldUnit), FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor ); |
374 | 0 | } |
375 | | |
376 | | |
377 | | FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor ) |
378 | 0 | { |
379 | 0 | return static_cast<FieldUnit>(convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor )); |
380 | 0 | } |
381 | | |
382 | | |
383 | | MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit) |
384 | 0 | { |
385 | 0 | MapUnit eMode; |
386 | 0 | switch(_nMeasureUnit) |
387 | 0 | { |
388 | 0 | case css::util::MeasureUnit::MM_100TH: |
389 | 0 | eMode = MapUnit::Map100thMM; |
390 | 0 | break; |
391 | | |
392 | 0 | case css::util::MeasureUnit::MM_10TH: |
393 | 0 | eMode = MapUnit::Map10thMM; |
394 | 0 | break; |
395 | | |
396 | 0 | case css::util::MeasureUnit::MM: |
397 | 0 | eMode = MapUnit::MapMM; |
398 | 0 | break; |
399 | | |
400 | 0 | case css::util::MeasureUnit::CM: |
401 | 0 | eMode = MapUnit::MapCM; |
402 | 0 | break; |
403 | | |
404 | 0 | case css::util::MeasureUnit::INCH_1000TH: |
405 | 0 | eMode = MapUnit::Map1000thInch; |
406 | 0 | break; |
407 | | |
408 | 0 | case css::util::MeasureUnit::INCH_100TH: |
409 | 0 | eMode = MapUnit::Map100thInch; |
410 | 0 | break; |
411 | | |
412 | 0 | case css::util::MeasureUnit::INCH_10TH: |
413 | 0 | eMode = MapUnit::Map10thInch; |
414 | 0 | break; |
415 | | |
416 | 0 | case css::util::MeasureUnit::INCH: |
417 | 0 | eMode = MapUnit::MapInch; |
418 | 0 | break; |
419 | | |
420 | 0 | case css::util::MeasureUnit::POINT: |
421 | 0 | eMode = MapUnit::MapPoint; |
422 | 0 | break; |
423 | | |
424 | 0 | case css::util::MeasureUnit::TWIP: |
425 | 0 | eMode = MapUnit::MapTwip; |
426 | 0 | break; |
427 | | |
428 | 0 | case css::util::MeasureUnit::PIXEL: |
429 | 0 | eMode = MapUnit::MapPixel; |
430 | 0 | break; |
431 | | |
432 | 0 | case css::util::MeasureUnit::APPFONT: |
433 | 0 | eMode = MapUnit::MapAppFont; |
434 | 0 | break; |
435 | | |
436 | 0 | case css::util::MeasureUnit::SYSFONT: |
437 | 0 | eMode = MapUnit::MapSysFont; |
438 | 0 | break; |
439 | | |
440 | 0 | default: |
441 | 0 | throw css::lang::IllegalArgumentException(u"Unsupported measure unit."_ustr, nullptr, 1 ); |
442 | 0 | } |
443 | 0 | return eMode; |
444 | 0 | } |
445 | | |
446 | | awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext ) |
447 | 0 | { |
448 | 0 | awt::MouseEvent aMouseEvent; |
449 | 0 | aMouseEvent.Source = _rxContext; |
450 | |
|
451 | 0 | aMouseEvent.Modifiers = 0; |
452 | 0 | if ( _rVclEvent.IsShift() ) |
453 | 0 | aMouseEvent.Modifiers |= css::awt::KeyModifier::SHIFT; |
454 | 0 | if ( _rVclEvent.IsMod1() ) |
455 | 0 | aMouseEvent.Modifiers |= css::awt::KeyModifier::MOD1; |
456 | 0 | if ( _rVclEvent.IsMod2() ) |
457 | 0 | aMouseEvent.Modifiers |= css::awt::KeyModifier::MOD2; |
458 | |
|
459 | 0 | aMouseEvent.Buttons = 0; |
460 | 0 | if ( _rVclEvent.IsLeft() ) |
461 | 0 | aMouseEvent.Buttons |= css::awt::MouseButton::LEFT; |
462 | 0 | if ( _rVclEvent.IsRight() ) |
463 | 0 | aMouseEvent.Buttons |= css::awt::MouseButton::RIGHT; |
464 | 0 | if ( _rVclEvent.IsMiddle() ) |
465 | 0 | aMouseEvent.Buttons |= css::awt::MouseButton::MIDDLE; |
466 | |
|
467 | 0 | aMouseEvent.X = _rVclEvent.GetPosPixel().X(); |
468 | 0 | aMouseEvent.Y = _rVclEvent.GetPosPixel().Y(); |
469 | 0 | aMouseEvent.ClickCount = _rVclEvent.GetClicks(); |
470 | 0 | aMouseEvent.PopupTrigger = false; |
471 | |
|
472 | 0 | return aMouseEvent; |
473 | 0 | } |
474 | | |
475 | | ::MouseEvent VCLUnoHelper::createVCLMouseEvent( const awt::MouseEvent& _rAwtEvent ) |
476 | 0 | { |
477 | 0 | ::MouseEvent aMouseEvent( Point( _rAwtEvent.X, _rAwtEvent.Y ), _rAwtEvent.ClickCount, |
478 | 0 | ::MouseEventModifiers::NONE, _rAwtEvent.Buttons, _rAwtEvent.Modifiers ); |
479 | |
|
480 | 0 | return aMouseEvent; |
481 | 0 | } |
482 | | |
483 | | awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext ) |
484 | 0 | { |
485 | 0 | awt::KeyEvent aKeyEvent; |
486 | 0 | aKeyEvent.Source = _rxContext; |
487 | |
|
488 | 0 | aKeyEvent.Modifiers = 0; |
489 | 0 | if ( _rVclEvent.GetKeyCode().IsShift() ) |
490 | 0 | aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT; |
491 | 0 | if ( _rVclEvent.GetKeyCode().IsMod1() ) |
492 | 0 | aKeyEvent.Modifiers |= awt::KeyModifier::MOD1; |
493 | 0 | if ( _rVclEvent.GetKeyCode().IsMod2() ) |
494 | 0 | aKeyEvent.Modifiers |= awt::KeyModifier::MOD2; |
495 | 0 | if ( _rVclEvent.GetKeyCode().IsMod3() ) |
496 | 0 | aKeyEvent.Modifiers |= awt::KeyModifier::MOD3; |
497 | |
|
498 | 0 | aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode(); |
499 | 0 | aKeyEvent.KeyChar = _rVclEvent.GetCharCode(); |
500 | 0 | aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction()); |
501 | |
|
502 | 0 | return aKeyEvent; |
503 | 0 | } |
504 | | |
505 | | ::KeyEvent VCLUnoHelper::createVCLKeyEvent( const awt::KeyEvent& _rAwtEvent ) |
506 | 0 | { |
507 | 0 | sal_Unicode nChar = _rAwtEvent.KeyChar; |
508 | 0 | vcl::KeyCode aKeyCode( _rAwtEvent.KeyCode, _rAwtEvent.Modifiers & awt::KeyModifier::SHIFT, |
509 | 0 | _rAwtEvent.Modifiers & awt::KeyModifier::MOD1, |
510 | 0 | _rAwtEvent.Modifiers & awt::KeyModifier::MOD2, |
511 | 0 | _rAwtEvent.Modifiers & awt::KeyModifier::MOD3 ); |
512 | |
|
513 | 0 | return ::KeyEvent (nChar, aKeyCode); |
514 | |
|
515 | 0 | } |
516 | | |
517 | | ::PointerStyle VCLUnoHelper::getMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer) |
518 | 0 | { |
519 | 0 | ::PointerStyle eType = ::PointerStyle::Arrow; // default ? |
520 | 0 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer); |
521 | 0 | if (pWindow) |
522 | 0 | eType = pWindow->GetPointer(); |
523 | 0 | return eType; |
524 | 0 | } |
525 | | |
526 | | void VCLUnoHelper::setMousePointer(const css::uno::Reference<css::awt::XWindowPeer>& rWindowPeer, ::PointerStyle ePointer) |
527 | 0 | { |
528 | 0 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rWindowPeer); |
529 | 0 | if (!pWindow) |
530 | 0 | return; |
531 | 0 | pWindow->SetPointer(ePointer); |
532 | 0 | } |
533 | | |
534 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |