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 "vcl/outdev.hxx"
21 : #include "vcl/window.hxx"
22 : #include "vcl/salnativewidgets.hxx"
23 : #include "vcl/pdfextoutdevdata.hxx"
24 :
25 : #include "salgdi.hxx"
26 :
27 0 : static bool lcl_enableNativeWidget( const OutputDevice& i_rDevice )
28 : {
29 0 : const OutDevType eType( i_rDevice.GetOutDevType() );
30 0 : switch ( eType )
31 : {
32 :
33 : case OUTDEV_WINDOW:
34 0 : return dynamic_cast< const Window* >( &i_rDevice )->IsNativeWidgetEnabled();
35 :
36 : case OUTDEV_VIRDEV:
37 : {
38 0 : const ::vcl::ExtOutDevData* pOutDevData( i_rDevice.GetExtOutDevData() );
39 0 : const ::vcl::PDFExtOutDevData* pPDFData( dynamic_cast< const ::vcl::PDFExtOutDevData* >( pOutDevData ) );
40 0 : if ( pPDFData != NULL )
41 0 : return false;
42 0 : return true;
43 : }
44 :
45 : default:
46 0 : return false;
47 : }
48 : }
49 :
50 0 : ImplControlValue::~ImplControlValue()
51 : {
52 0 : }
53 :
54 0 : ImplControlValue* ImplControlValue::clone() const
55 : {
56 : assert( typeid( const ImplControlValue ) == typeid( *this ));
57 0 : return new ImplControlValue( *this );
58 : }
59 :
60 0 : ScrollbarValue::~ScrollbarValue()
61 : {
62 0 : }
63 :
64 0 : ScrollbarValue* ScrollbarValue::clone() const
65 : {
66 : assert( typeid( const ScrollbarValue ) == typeid( *this ));
67 0 : return new ScrollbarValue( *this );
68 : }
69 :
70 0 : SliderValue::~SliderValue()
71 : {
72 0 : }
73 :
74 0 : SliderValue* SliderValue::clone() const
75 : {
76 : assert( typeid( const SliderValue ) == typeid( *this ));
77 0 : return new SliderValue( *this );
78 : }
79 :
80 0 : TabitemValue::~TabitemValue()
81 : {
82 0 : }
83 :
84 0 : TabitemValue* TabitemValue::clone() const
85 : {
86 : assert( typeid( const TabitemValue ) == typeid( *this ));
87 0 : return new TabitemValue( *this );
88 : }
89 :
90 0 : SpinbuttonValue::~SpinbuttonValue()
91 : {
92 0 : }
93 :
94 0 : SpinbuttonValue* SpinbuttonValue::clone() const
95 : {
96 : assert( typeid( const SpinbuttonValue ) == typeid( *this ));
97 0 : return new SpinbuttonValue( *this );
98 : }
99 :
100 0 : ToolbarValue::~ToolbarValue()
101 : {
102 0 : }
103 :
104 0 : ToolbarValue* ToolbarValue::clone() const
105 : {
106 : assert( typeid( const ToolbarValue ) == typeid( *this ));
107 0 : return new ToolbarValue( *this );
108 : }
109 :
110 0 : MenubarValue::~MenubarValue()
111 : {
112 0 : }
113 :
114 0 : MenubarValue* MenubarValue::clone() const
115 : {
116 : assert( typeid( const MenubarValue ) == typeid( *this ));
117 0 : return new MenubarValue( *this );
118 : }
119 :
120 0 : MenupopupValue::~MenupopupValue()
121 : {
122 0 : }
123 :
124 0 : MenupopupValue* MenupopupValue::clone() const
125 : {
126 : assert( typeid( const MenupopupValue ) == typeid( *this ));
127 0 : return new MenupopupValue( *this );
128 : }
129 :
130 0 : PushButtonValue::~PushButtonValue()
131 : {
132 0 : }
133 :
134 0 : PushButtonValue* PushButtonValue::clone() const
135 : {
136 : assert( typeid( const PushButtonValue ) == typeid( *this ));
137 0 : return new PushButtonValue( *this );
138 : }
139 :
140 : // These functions are mainly passthrough functions that allow access to
141 : // the SalFrame behind a Window object for native widget rendering purposes.
142 :
143 0 : bool OutputDevice::IsNativeControlSupported( ControlType nType, ControlPart nPart ) const
144 : {
145 0 : if( !lcl_enableNativeWidget( *this ) )
146 0 : return false;
147 :
148 0 : if ( !mpGraphics )
149 0 : if ( !ImplGetGraphics() )
150 0 : return false;
151 :
152 0 : return( mpGraphics->IsNativeControlSupported(nType, nPart) );
153 : }
154 :
155 0 : bool OutputDevice::HitTestNativeControl( ControlType nType,
156 : ControlPart nPart,
157 : const Rectangle& rControlRegion,
158 : const Point& aPos,
159 : bool& rIsInside ) const
160 : {
161 0 : if( !lcl_enableNativeWidget( *this ) )
162 0 : return false;
163 :
164 0 : if ( !mpGraphics )
165 0 : if ( !ImplGetGraphics() )
166 0 : return false;
167 :
168 0 : Point aWinOffs( mnOutOffX, mnOutOffY );
169 0 : Rectangle screenRegion( rControlRegion );
170 0 : screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
171 :
172 0 : return( mpGraphics->HitTestNativeControl(nType, nPart, screenRegion, Point( aPos.X() + mnOutOffX, aPos.Y() + mnOutOffY ),
173 0 : rIsInside, this ) );
174 : }
175 :
176 0 : static boost::shared_ptr< ImplControlValue > lcl_transformControlValue( const ImplControlValue& rVal, const OutputDevice& rDev )
177 : {
178 0 : boost::shared_ptr< ImplControlValue > aResult;
179 0 : switch( rVal.getType() )
180 : {
181 : case CTRL_SLIDER:
182 : {
183 0 : const SliderValue* pSlVal = static_cast<const SliderValue*>(&rVal);
184 0 : SliderValue* pNew = new SliderValue( *pSlVal );
185 0 : aResult.reset( pNew );
186 0 : pNew->maThumbRect = rDev.ImplLogicToDevicePixel( pSlVal->maThumbRect );
187 : }
188 0 : break;
189 : case CTRL_SCROLLBAR:
190 : {
191 0 : const ScrollbarValue* pScVal = static_cast<const ScrollbarValue*>(&rVal);
192 0 : ScrollbarValue* pNew = new ScrollbarValue( *pScVal );
193 0 : aResult.reset( pNew );
194 0 : pNew->maThumbRect = rDev.ImplLogicToDevicePixel( pScVal->maThumbRect );
195 0 : pNew->maButton1Rect = rDev.ImplLogicToDevicePixel( pScVal->maButton1Rect );
196 0 : pNew->maButton2Rect = rDev.ImplLogicToDevicePixel( pScVal->maButton2Rect );
197 : }
198 0 : break;
199 : case CTRL_SPINBUTTONS:
200 : {
201 0 : const SpinbuttonValue* pSpVal = static_cast<const SpinbuttonValue*>(&rVal);
202 0 : SpinbuttonValue* pNew = new SpinbuttonValue( *pSpVal );
203 0 : aResult.reset( pNew );
204 0 : pNew->maUpperRect = rDev.ImplLogicToDevicePixel( pSpVal->maUpperRect );
205 0 : pNew->maLowerRect = rDev.ImplLogicToDevicePixel( pSpVal->maLowerRect );
206 : }
207 0 : break;
208 : case CTRL_TOOLBAR:
209 : {
210 0 : const ToolbarValue* pTVal = static_cast<const ToolbarValue*>(&rVal);
211 0 : ToolbarValue* pNew = new ToolbarValue( *pTVal );
212 0 : aResult.reset( pNew );
213 0 : pNew->maGripRect = rDev.ImplLogicToDevicePixel( pTVal->maGripRect );
214 : }
215 0 : break;
216 : case CTRL_TAB_ITEM:
217 : {
218 0 : const TabitemValue* pTIVal = static_cast<const TabitemValue*>(&rVal);
219 0 : TabitemValue* pNew = new TabitemValue( *pTIVal );
220 0 : aResult.reset( pNew );
221 : }
222 0 : break;
223 : case CTRL_MENUBAR:
224 : {
225 0 : const MenubarValue* pMVal = static_cast<const MenubarValue*>(&rVal);
226 0 : MenubarValue* pNew = new MenubarValue( *pMVal );
227 0 : aResult.reset( pNew );
228 : }
229 0 : break;
230 : case CTRL_PUSHBUTTON:
231 : {
232 0 : const PushButtonValue* pBVal = static_cast<const PushButtonValue*>(&rVal);
233 0 : PushButtonValue* pNew = new PushButtonValue( *pBVal );
234 0 : aResult.reset( pNew );
235 : }
236 0 : break;
237 : case CTRL_GENERIC:
238 0 : aResult.reset( new ImplControlValue( rVal ) );
239 0 : break;
240 : case CTRL_MENU_POPUP:
241 : {
242 0 : const MenupopupValue* pMVal = static_cast<const MenupopupValue*>(&rVal);
243 0 : MenupopupValue* pNew = new MenupopupValue( *pMVal );
244 0 : pNew->maItemRect = rDev.ImplLogicToDevicePixel( pMVal->maItemRect );
245 0 : aResult.reset( pNew );
246 : }
247 0 : break;
248 : default:
249 : OSL_FAIL( "unknown ImplControlValue type !" );
250 0 : break;
251 : }
252 0 : return aResult;
253 : }
254 0 : bool OutputDevice::DrawNativeControl( ControlType nType,
255 : ControlPart nPart,
256 : const Rectangle& rControlRegion,
257 : ControlState nState,
258 : const ImplControlValue& aValue,
259 : const OUString& aCaption )
260 : {
261 0 : if( !lcl_enableNativeWidget( *this ) )
262 0 : return false;
263 :
264 : // make sure the current clip region is initialized correctly
265 0 : if ( !mpGraphics )
266 0 : if ( !ImplGetGraphics() )
267 0 : return false;
268 :
269 0 : if ( mbInitClipRegion )
270 0 : ImplInitClipRegion();
271 0 : if ( mbOutputClipped )
272 0 : return true;
273 :
274 0 : if ( mbInitLineColor )
275 0 : ImplInitLineColor();
276 0 : if ( mbInitFillColor )
277 0 : ImplInitFillColor();
278 :
279 : // Convert the coordinates from relative to Window-absolute, so we draw
280 : // in the correct place in platform code
281 0 : boost::shared_ptr< ImplControlValue > aScreenCtrlValue( lcl_transformControlValue( aValue, *this ) );
282 0 : Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
283 :
284 0 : Region aTestRegion( GetActiveClipRegion() );
285 0 : aTestRegion.Intersect( rControlRegion );
286 0 : if (aTestRegion == Region(rControlRegion))
287 0 : nState |= CTRL_CACHING_ALLOWED; // control is not clipped, caching allowed
288 :
289 0 : bool bRet = mpGraphics->DrawNativeControl(nType, nPart, screenRegion, nState, *aScreenCtrlValue, aCaption, this );
290 :
291 0 : return bRet;
292 : }
293 :
294 0 : bool OutputDevice::GetNativeControlRegion( ControlType nType,
295 : ControlPart nPart,
296 : const Rectangle& rControlRegion,
297 : ControlState nState,
298 : const ImplControlValue& aValue,
299 : const OUString& aCaption,
300 : Rectangle &rNativeBoundingRegion,
301 : Rectangle &rNativeContentRegion ) const
302 : {
303 0 : if( !lcl_enableNativeWidget( *this ) )
304 0 : return false;
305 :
306 0 : if ( !mpGraphics )
307 0 : if ( !ImplGetGraphics() )
308 0 : return false;
309 :
310 : // Convert the coordinates from relative to Window-absolute, so we draw
311 : // in the correct place in platform code
312 0 : boost::shared_ptr< ImplControlValue > aScreenCtrlValue( lcl_transformControlValue( aValue, *this ) );
313 0 : Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
314 :
315 0 : bool bRet = mpGraphics->GetNativeControlRegion(nType, nPart, screenRegion, nState, *aScreenCtrlValue,
316 : aCaption, rNativeBoundingRegion,
317 0 : rNativeContentRegion, this );
318 0 : if( bRet )
319 : {
320 : // transform back native regions
321 0 : rNativeBoundingRegion = ImplDevicePixelToLogic( rNativeBoundingRegion );
322 0 : rNativeContentRegion = ImplDevicePixelToLogic( rNativeContentRegion );
323 : }
324 :
325 0 : return bRet;
326 3 : }
327 :
328 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|