xref: /aoo42x/main/vcl/source/gdi/outdevnative.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "vcl/outdev.hxx"
32*cdf0e10cSrcweir #include "vcl/window.hxx"
33*cdf0e10cSrcweir #include "vcl/salnativewidgets.hxx"
34*cdf0e10cSrcweir #include "vcl/pdfextoutdevdata.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "salgdi.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir // -----------------------------------------------------------------------
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir static bool lcl_enableNativeWidget( const OutputDevice& i_rDevice )
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir     const OutDevType eType( i_rDevice.GetOutDevType() );
43*cdf0e10cSrcweir     switch ( eType )
44*cdf0e10cSrcweir     {
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir     case OUTDEV_WINDOW:
47*cdf0e10cSrcweir         return dynamic_cast< const Window* >( &i_rDevice )->IsNativeWidgetEnabled();
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     case OUTDEV_VIRDEV:
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir         const ::vcl::ExtOutDevData* pOutDevData( i_rDevice.GetExtOutDevData() );
52*cdf0e10cSrcweir         const ::vcl::PDFExtOutDevData* pPDFData( dynamic_cast< const ::vcl::PDFExtOutDevData* >( pOutDevData ) );
53*cdf0e10cSrcweir         if ( pPDFData != NULL )
54*cdf0e10cSrcweir             return false;
55*cdf0e10cSrcweir         return true;
56*cdf0e10cSrcweir     }
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     default:
59*cdf0e10cSrcweir         return false;
60*cdf0e10cSrcweir     }
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir ImplControlValue::~ImplControlValue()
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir ScrollbarValue::~ScrollbarValue()
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir SliderValue::~SliderValue()
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir TabitemValue::~TabitemValue()
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir SpinbuttonValue::~SpinbuttonValue()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir ToolbarValue::~ToolbarValue()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir MenubarValue::~MenubarValue()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir MenupopupValue::~MenupopupValue()
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir PushButtonValue::~PushButtonValue()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir // -----------------------------------------------------------------------
100*cdf0e10cSrcweir // These functions are mainly passthrough functions that allow access to
101*cdf0e10cSrcweir // the SalFrame behind a Window object for native widget rendering purposes.
102*cdf0e10cSrcweir // -----------------------------------------------------------------------
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir // -----------------------------------------------------------------------
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir sal_Bool OutputDevice::IsNativeControlSupported( ControlType nType, ControlPart nPart )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     if( !lcl_enableNativeWidget( *this ) )
109*cdf0e10cSrcweir         return sal_False;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     if ( !mpGraphics )
112*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
113*cdf0e10cSrcweir             return sal_False;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     return( mpGraphics->IsNativeControlSupported(nType, nPart) );
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir // -----------------------------------------------------------------------
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir sal_Bool OutputDevice::HitTestNativeControl( ControlType nType,
122*cdf0e10cSrcweir                               ControlPart nPart,
123*cdf0e10cSrcweir                               const Rectangle& rControlRegion,
124*cdf0e10cSrcweir                               const Point& aPos,
125*cdf0e10cSrcweir                               sal_Bool& rIsInside )
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     if( !lcl_enableNativeWidget( *this ) )
128*cdf0e10cSrcweir         return sal_False;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     if ( !mpGraphics )
131*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
132*cdf0e10cSrcweir             return sal_False;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     Point aWinOffs( mnOutOffX, mnOutOffY );
135*cdf0e10cSrcweir     Rectangle screenRegion( rControlRegion );
136*cdf0e10cSrcweir     screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     return( mpGraphics->HitTestNativeControl(nType, nPart, screenRegion, Point( aPos.X() + mnOutOffX, aPos.Y() + mnOutOffY ),
139*cdf0e10cSrcweir         rIsInside, this ) );
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir // -----------------------------------------------------------------------
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir static boost::shared_ptr< ImplControlValue > lcl_transformControlValue( const ImplControlValue& rVal, OutputDevice& rDev )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     boost::shared_ptr< ImplControlValue > aResult;
147*cdf0e10cSrcweir     switch( rVal.getType() )
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir     case CTRL_SLIDER:
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             const SliderValue* pSlVal = static_cast<const SliderValue*>(&rVal);
152*cdf0e10cSrcweir             SliderValue* pNew = new SliderValue( *pSlVal );
153*cdf0e10cSrcweir             aResult.reset( pNew );
154*cdf0e10cSrcweir             pNew->maThumbRect = rDev.ImplLogicToDevicePixel( pSlVal->maThumbRect );
155*cdf0e10cSrcweir         }
156*cdf0e10cSrcweir         break;
157*cdf0e10cSrcweir     case CTRL_SCROLLBAR:
158*cdf0e10cSrcweir         {
159*cdf0e10cSrcweir             const ScrollbarValue* pScVal = static_cast<const ScrollbarValue*>(&rVal);
160*cdf0e10cSrcweir             ScrollbarValue* pNew = new ScrollbarValue( *pScVal );
161*cdf0e10cSrcweir             aResult.reset( pNew );
162*cdf0e10cSrcweir             pNew->maThumbRect = rDev.ImplLogicToDevicePixel( pScVal->maThumbRect );
163*cdf0e10cSrcweir             pNew->maButton1Rect = rDev.ImplLogicToDevicePixel( pScVal->maButton1Rect );
164*cdf0e10cSrcweir             pNew->maButton2Rect = rDev.ImplLogicToDevicePixel( pScVal->maButton2Rect );
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir         break;
167*cdf0e10cSrcweir     case CTRL_SPINBUTTONS:
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             const SpinbuttonValue* pSpVal = static_cast<const SpinbuttonValue*>(&rVal);
170*cdf0e10cSrcweir             SpinbuttonValue* pNew = new SpinbuttonValue( *pSpVal );
171*cdf0e10cSrcweir             aResult.reset( pNew );
172*cdf0e10cSrcweir             pNew->maUpperRect = rDev.ImplLogicToDevicePixel( pSpVal->maUpperRect );
173*cdf0e10cSrcweir             pNew->maLowerRect = rDev.ImplLogicToDevicePixel( pSpVal->maLowerRect );
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir         break;
176*cdf0e10cSrcweir     case CTRL_TOOLBAR:
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             const ToolbarValue* pTVal = static_cast<const ToolbarValue*>(&rVal);
179*cdf0e10cSrcweir             ToolbarValue* pNew = new ToolbarValue( *pTVal );
180*cdf0e10cSrcweir             aResult.reset( pNew );
181*cdf0e10cSrcweir             pNew->maGripRect = rDev.ImplLogicToDevicePixel( pTVal->maGripRect );
182*cdf0e10cSrcweir         }
183*cdf0e10cSrcweir         break;
184*cdf0e10cSrcweir     case CTRL_TAB_ITEM:
185*cdf0e10cSrcweir         {
186*cdf0e10cSrcweir             const TabitemValue* pTIVal = static_cast<const TabitemValue*>(&rVal);
187*cdf0e10cSrcweir             TabitemValue* pNew = new TabitemValue( *pTIVal );
188*cdf0e10cSrcweir             aResult.reset( pNew );
189*cdf0e10cSrcweir         }
190*cdf0e10cSrcweir         break;
191*cdf0e10cSrcweir     case CTRL_MENUBAR:
192*cdf0e10cSrcweir         {
193*cdf0e10cSrcweir             const MenubarValue* pMVal = static_cast<const MenubarValue*>(&rVal);
194*cdf0e10cSrcweir             MenubarValue* pNew = new MenubarValue( *pMVal );
195*cdf0e10cSrcweir             aResult.reset( pNew );
196*cdf0e10cSrcweir         }
197*cdf0e10cSrcweir         break;
198*cdf0e10cSrcweir     case CTRL_PUSHBUTTON:
199*cdf0e10cSrcweir         {
200*cdf0e10cSrcweir             const PushButtonValue* pBVal = static_cast<const PushButtonValue*>(&rVal);
201*cdf0e10cSrcweir             PushButtonValue* pNew = new PushButtonValue( *pBVal );
202*cdf0e10cSrcweir             aResult.reset( pNew );
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir         break;
205*cdf0e10cSrcweir     case CTRL_GENERIC:
206*cdf0e10cSrcweir             aResult.reset( new ImplControlValue( rVal ) );
207*cdf0e10cSrcweir             break;
208*cdf0e10cSrcweir 	case CTRL_MENU_POPUP:
209*cdf0e10cSrcweir 		{
210*cdf0e10cSrcweir 			const MenupopupValue* pMVal = static_cast<const MenupopupValue*>(&rVal);
211*cdf0e10cSrcweir 			MenupopupValue* pNew = new MenupopupValue( *pMVal );
212*cdf0e10cSrcweir             pNew->maItemRect = rDev.ImplLogicToDevicePixel( pMVal->maItemRect );
213*cdf0e10cSrcweir 			aResult.reset( pNew );
214*cdf0e10cSrcweir 		}
215*cdf0e10cSrcweir 		break;
216*cdf0e10cSrcweir     default:
217*cdf0e10cSrcweir         OSL_ENSURE( 0, "unknown ImplControlValue type !" );
218*cdf0e10cSrcweir         break;
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir     return aResult;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir sal_Bool OutputDevice::DrawNativeControl( ControlType nType,
224*cdf0e10cSrcweir                             ControlPart nPart,
225*cdf0e10cSrcweir                             const Rectangle& rControlRegion,
226*cdf0e10cSrcweir                             ControlState nState,
227*cdf0e10cSrcweir                             const ImplControlValue& aValue,
228*cdf0e10cSrcweir                             ::rtl::OUString aCaption )
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir     if( !lcl_enableNativeWidget( *this ) )
231*cdf0e10cSrcweir         return sal_False;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     // make sure the current clip region is initialized correctly
234*cdf0e10cSrcweir     if ( !mpGraphics )
235*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
236*cdf0e10cSrcweir             return sal_False;
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     if ( mbInitClipRegion )
239*cdf0e10cSrcweir         ImplInitClipRegion();
240*cdf0e10cSrcweir     if ( mbOutputClipped )
241*cdf0e10cSrcweir         return sal_True;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if ( mbInitLineColor )
244*cdf0e10cSrcweir         ImplInitLineColor();
245*cdf0e10cSrcweir     if ( mbInitFillColor )
246*cdf0e10cSrcweir         ImplInitFillColor();
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     // Convert the coordinates from relative to Window-absolute, so we draw
249*cdf0e10cSrcweir     // in the correct place in platform code
250*cdf0e10cSrcweir     boost::shared_ptr< ImplControlValue > aScreenCtrlValue( lcl_transformControlValue( aValue, *this ) );
251*cdf0e10cSrcweir     Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     Region aTestRegion( GetActiveClipRegion() );
254*cdf0e10cSrcweir     aTestRegion.Intersect( rControlRegion );
255*cdf0e10cSrcweir     if( aTestRegion == rControlRegion )
256*cdf0e10cSrcweir         nState |= CTRL_CACHING_ALLOWED;   // control is not clipped, caching allowed
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     sal_Bool bRet = mpGraphics->DrawNativeControl(nType, nPart, screenRegion, nState, *aScreenCtrlValue, aCaption, this );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     return bRet;
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir // -----------------------------------------------------------------------
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir sal_Bool OutputDevice::DrawNativeControlText(ControlType nType,
267*cdf0e10cSrcweir                             ControlPart nPart,
268*cdf0e10cSrcweir                             const Rectangle& rControlRegion,
269*cdf0e10cSrcweir                             ControlState nState,
270*cdf0e10cSrcweir                             const ImplControlValue& aValue,
271*cdf0e10cSrcweir                             ::rtl::OUString aCaption )
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir     if( !lcl_enableNativeWidget( *this ) )
274*cdf0e10cSrcweir         return sal_False;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     // make sure the current clip region is initialized correctly
277*cdf0e10cSrcweir     if ( !mpGraphics )
278*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
279*cdf0e10cSrcweir             return false;
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     if ( mbInitClipRegion )
282*cdf0e10cSrcweir         ImplInitClipRegion();
283*cdf0e10cSrcweir     if ( mbOutputClipped )
284*cdf0e10cSrcweir         return true;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     if ( mbInitLineColor )
287*cdf0e10cSrcweir         ImplInitLineColor();
288*cdf0e10cSrcweir     if ( mbInitFillColor )
289*cdf0e10cSrcweir         ImplInitFillColor();
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     // Convert the coordinates from relative to Window-absolute, so we draw
292*cdf0e10cSrcweir     // in the correct place in platform code
293*cdf0e10cSrcweir     boost::shared_ptr< ImplControlValue > aScreenCtrlValue( lcl_transformControlValue( aValue, *this ) );
294*cdf0e10cSrcweir     Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     sal_Bool bRet = mpGraphics->DrawNativeControlText(nType, nPart, screenRegion, nState, *aScreenCtrlValue, aCaption, this );
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir     return bRet;
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir // -----------------------------------------------------------------------
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir sal_Bool OutputDevice::GetNativeControlRegion(  ControlType nType,
305*cdf0e10cSrcweir                                 ControlPart nPart,
306*cdf0e10cSrcweir                                 const Rectangle& rControlRegion,
307*cdf0e10cSrcweir                                 ControlState nState,
308*cdf0e10cSrcweir                                 const ImplControlValue& aValue,
309*cdf0e10cSrcweir                                 ::rtl::OUString aCaption,
310*cdf0e10cSrcweir                                 Rectangle &rNativeBoundingRegion,
311*cdf0e10cSrcweir                                 Rectangle &rNativeContentRegion )
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir     if( !lcl_enableNativeWidget( *this ) )
314*cdf0e10cSrcweir         return sal_False;
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     if ( !mpGraphics )
317*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
318*cdf0e10cSrcweir             return sal_False;
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     // Convert the coordinates from relative to Window-absolute, so we draw
321*cdf0e10cSrcweir     // in the correct place in platform code
322*cdf0e10cSrcweir     boost::shared_ptr< ImplControlValue > aScreenCtrlValue( lcl_transformControlValue( aValue, *this ) );
323*cdf0e10cSrcweir     Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     sal_Bool bRet = mpGraphics->GetNativeControlRegion(nType, nPart, screenRegion, nState, *aScreenCtrlValue,
326*cdf0e10cSrcweir                                 aCaption, rNativeBoundingRegion,
327*cdf0e10cSrcweir                                 rNativeContentRegion, this );
328*cdf0e10cSrcweir     if( bRet )
329*cdf0e10cSrcweir     {
330*cdf0e10cSrcweir         // transform back native regions
331*cdf0e10cSrcweir         rNativeBoundingRegion = ImplDevicePixelToLogic( rNativeBoundingRegion );
332*cdf0e10cSrcweir         rNativeContentRegion = ImplDevicePixelToLogic( rNativeContentRegion );
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     return bRet;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 
339