/src/libreoffice/toolkit/source/awt/vclxdevice.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 <sal/config.h> |
21 | | |
22 | | #include <com/sun/star/util/MeasureUnit.hpp> |
23 | | #include <com/sun/star/lang/IllegalArgumentException.hpp> |
24 | | |
25 | | #include <toolkit/awt/vclxdevice.hxx> |
26 | | #include <toolkit/awt/vclxfont.hxx> |
27 | | #include <awt/vclxbitmap.hxx> |
28 | | #include <toolkit/helper/vclunohelper.hxx> |
29 | | |
30 | | #include <vcl/svapp.hxx> |
31 | | #include <vcl/outdev.hxx> |
32 | | #include <vcl/virdev.hxx> |
33 | | #include <vcl/bitmap.hxx> |
34 | | #include <vcl/metric.hxx> |
35 | | #include <vcl/unohelp.hxx> |
36 | | |
37 | | |
38 | | VCLXDevice::VCLXDevice() |
39 | 89.7k | { |
40 | 89.7k | } |
41 | | |
42 | | VCLXDevice::~VCLXDevice() |
43 | 63.6k | { |
44 | | //TODO: why was this empty, and everything done in ~VCLXVirtualDevice? |
45 | 63.6k | SolarMutexGuard g; |
46 | 63.6k | mpOutputDevice.reset(); |
47 | 63.6k | } |
48 | | |
49 | | // css::awt::XDevice, |
50 | | css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( ) |
51 | 0 | { |
52 | 0 | SolarMutexGuard aGuard; |
53 | |
|
54 | 0 | css::uno::Reference< css::awt::XGraphics > xRef; |
55 | |
|
56 | 0 | if ( mpOutputDevice ) |
57 | 0 | xRef = mpOutputDevice->CreateUnoGraphics(); |
58 | |
|
59 | 0 | return xRef; |
60 | 0 | } |
61 | | |
62 | | css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight ) |
63 | 0 | { |
64 | 0 | SolarMutexGuard aGuard; |
65 | |
|
66 | 0 | if ( !GetOutputDevice() ) |
67 | 0 | return nullptr; |
68 | | |
69 | 0 | rtl::Reference<VCLXVirtualDevice> pVDev = new VCLXVirtualDevice; |
70 | 0 | VclPtrInstance<VirtualDevice> pVclVDev( *GetOutputDevice() ); |
71 | 0 | pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) ); |
72 | 0 | pVDev->SetVirtualDevice( pVclVDev ); |
73 | 0 | return pVDev; |
74 | 0 | } |
75 | | |
76 | | css::awt::DeviceInfo VCLXDevice::getInfo() |
77 | 0 | { |
78 | 0 | SolarMutexGuard aGuard; |
79 | |
|
80 | 0 | css::awt::DeviceInfo aInfo; |
81 | |
|
82 | 0 | if (mpOutputDevice) |
83 | 0 | aInfo = mpOutputDevice->GetDeviceInfo(); |
84 | |
|
85 | 0 | return aInfo; |
86 | 0 | } |
87 | | |
88 | | css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( ) |
89 | 0 | { |
90 | 0 | SolarMutexGuard aGuard; |
91 | |
|
92 | 0 | css::uno::Sequence< css::awt::FontDescriptor> aFonts; |
93 | 0 | if( mpOutputDevice ) |
94 | 0 | { |
95 | 0 | int nFonts = mpOutputDevice->GetFontFaceCollectionCount(); |
96 | 0 | if ( nFonts ) |
97 | 0 | { |
98 | 0 | aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts ); |
99 | 0 | css::awt::FontDescriptor* pFonts = aFonts.getArray(); |
100 | 0 | for ( int n = 0; n < nFonts; n++ ) |
101 | 0 | pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetFontMetricFromCollection( n ) ); |
102 | 0 | } |
103 | 0 | } |
104 | 0 | return aFonts; |
105 | 0 | } |
106 | | |
107 | | css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor ) |
108 | 11.3k | { |
109 | 11.3k | SolarMutexGuard aGuard; |
110 | | |
111 | 11.3k | if( !mpOutputDevice ) |
112 | 0 | return nullptr; |
113 | | |
114 | 11.3k | rtl::Reference<VCLXFont> pMetric |
115 | 11.3k | = new VCLXFont(*this, VCLUnoHelper::CreateFont(rDescriptor, mpOutputDevice->GetFont())); |
116 | 11.3k | return pMetric; |
117 | 11.3k | } |
118 | | |
119 | | css::uno::Reference< css::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight ) |
120 | 0 | { |
121 | 0 | SolarMutexGuard aGuard; |
122 | |
|
123 | 0 | if( !mpOutputDevice ) |
124 | 0 | return nullptr; |
125 | | |
126 | 0 | Bitmap aBmp = mpOutputDevice->GetBitmap( Point( nX, nY ), Size( nWidth, nHeight ) ); |
127 | 0 | rtl::Reference<VCLXBitmap> pBmp = new VCLXBitmap; |
128 | 0 | pBmp->SetBitmap( aBmp ); |
129 | 0 | return pBmp; |
130 | 0 | } |
131 | | |
132 | | css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap ) |
133 | 0 | { |
134 | 0 | SolarMutexGuard aGuard; |
135 | |
|
136 | 0 | Bitmap aBmp = VCLUnoHelper::GetBitmap( rxBitmap ); |
137 | 0 | rtl::Reference<VCLXBitmap> pBmp = new VCLXBitmap; |
138 | 0 | pBmp->SetBitmap( aBmp ); |
139 | 0 | return pBmp; |
140 | 0 | } |
141 | | |
142 | | VCLXVirtualDevice::~VCLXVirtualDevice() |
143 | 0 | { |
144 | 0 | SolarMutexGuard aGuard; |
145 | |
|
146 | 0 | mpOutputDevice.disposeAndClear(); |
147 | 0 | } |
148 | | |
149 | | // Interface implementation of css::awt::XUnitConversion |
150 | | |
151 | | css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit ) |
152 | 0 | { |
153 | 0 | SolarMutexGuard aGuard; |
154 | 0 | if (TargetUnit == css::util::MeasureUnit::PERCENT ) |
155 | 0 | { |
156 | | // percentage not allowed here |
157 | 0 | throw css::lang::IllegalArgumentException(); |
158 | 0 | } |
159 | | |
160 | 0 | css::awt::Point aAWTPoint(0,0); |
161 | | // X,Y |
162 | |
|
163 | 0 | if( mpOutputDevice ) |
164 | 0 | { |
165 | 0 | MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit)); |
166 | 0 | ::Point aVCLPoint = vcl::unohelper::ConvertToVCLPoint(aPoint); |
167 | 0 | ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode ); |
168 | 0 | aAWTPoint = vcl::unohelper::ConvertToAWTPoint(aDevPoint); |
169 | 0 | } |
170 | |
|
171 | 0 | return aAWTPoint; |
172 | 0 | } |
173 | | |
174 | | |
175 | | css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit ) |
176 | 0 | { |
177 | 0 | SolarMutexGuard aGuard; |
178 | 0 | if (SourceUnit == css::util::MeasureUnit::PERCENT || |
179 | 0 | SourceUnit == css::util::MeasureUnit::PIXEL ) |
180 | 0 | { |
181 | | // pixel or percentage not allowed here |
182 | 0 | throw css::lang::IllegalArgumentException(); |
183 | 0 | } |
184 | | |
185 | 0 | css::awt::Point aAWTPoint(0,0); |
186 | |
|
187 | 0 | if( mpOutputDevice ) |
188 | 0 | { |
189 | 0 | MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit)); |
190 | 0 | ::Point aVCLPoint = vcl::unohelper::ConvertToVCLPoint(aPoint); |
191 | 0 | ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode ); |
192 | 0 | aAWTPoint = vcl::unohelper::ConvertToAWTPoint(aDevPoint); |
193 | 0 | } |
194 | |
|
195 | 0 | return aAWTPoint; |
196 | 0 | } |
197 | | |
198 | | css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit ) |
199 | 0 | { |
200 | 0 | SolarMutexGuard aGuard; |
201 | 0 | if (TargetUnit == css::util::MeasureUnit::PERCENT) |
202 | 0 | { |
203 | | // percentage not allowed here |
204 | 0 | throw css::lang::IllegalArgumentException(); |
205 | 0 | } |
206 | | |
207 | 0 | css::awt::Size aAWTSize(0,0); |
208 | | // Width, Height |
209 | | |
210 | |
|
211 | 0 | if( mpOutputDevice ) |
212 | 0 | { |
213 | 0 | MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit)); |
214 | 0 | ::Size aVCLSize = vcl::unohelper::ConvertToVCLSize(aSize); |
215 | 0 | ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode ); |
216 | 0 | aAWTSize = vcl::unohelper::ConvertToAWTSize(aDevSz); |
217 | 0 | } |
218 | |
|
219 | 0 | return aAWTSize; |
220 | 0 | } |
221 | | |
222 | | css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit ) |
223 | 0 | { |
224 | 0 | SolarMutexGuard aGuard; |
225 | 0 | if (SourceUnit == css::util::MeasureUnit::PERCENT || |
226 | 0 | SourceUnit == css::util::MeasureUnit::PIXEL) |
227 | 0 | { |
228 | | // pixel or percentage not allowed here |
229 | 0 | throw css::lang::IllegalArgumentException(); |
230 | 0 | } |
231 | | |
232 | 0 | css::awt::Size aAWTSize(0,0); |
233 | | // Width, Height |
234 | 0 | if( mpOutputDevice ) |
235 | 0 | { |
236 | 0 | MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit)); |
237 | 0 | ::Size aVCLSize = vcl::unohelper::ConvertToVCLSize(aSize); |
238 | 0 | ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode ); |
239 | 0 | aAWTSize = vcl::unohelper::ConvertToAWTSize(aDevSz); |
240 | 0 | } |
241 | |
|
242 | 0 | return aAWTSize; |
243 | 0 | } |
244 | | |
245 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |