1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/log.hxx>
22 #include <vcl/pdfextoutdevdata.hxx>
23 #include <vcl/salnativewidgets.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/window.hxx>
28 #include <toolbarvalue.hxx>
29 #include <menubarvalue.hxx>
33 ImplControlValue::~ImplControlValue()
37 ImplControlValue
* ImplControlValue::clone() const
39 assert( typeid( const ImplControlValue
) == typeid( *this ));
40 return new ImplControlValue( *this );
43 ScrollbarValue::~ScrollbarValue()
47 ScrollbarValue
* ScrollbarValue::clone() const
49 assert( typeid( const ScrollbarValue
) == typeid( *this ));
50 return new ScrollbarValue( *this );
53 SliderValue::~SliderValue()
57 SliderValue
* SliderValue::clone() const
59 assert( typeid( const SliderValue
) == typeid( *this ));
60 return new SliderValue( *this );
63 int TabPaneValue::m_nOverlap
= 0;
65 TabPaneValue
* TabPaneValue::clone() const
67 assert(typeid(const TabPaneValue
) == typeid(*this));
68 return new TabPaneValue(*this);
71 TabitemValue::~TabitemValue()
75 TabitemValue
* TabitemValue::clone() const
77 assert( typeid( const TabitemValue
) == typeid( *this ));
78 return new TabitemValue( *this );
81 SpinbuttonValue::~SpinbuttonValue()
85 SpinbuttonValue
* SpinbuttonValue::clone() const
87 assert( typeid( const SpinbuttonValue
) == typeid( *this ));
88 return new SpinbuttonValue( *this );
91 ToolbarValue::~ToolbarValue()
95 ToolbarValue
* ToolbarValue::clone() const
97 assert( typeid( const ToolbarValue
) == typeid( *this ));
98 return new ToolbarValue( *this );
101 MenubarValue::~MenubarValue()
105 MenubarValue
* MenubarValue::clone() const
107 assert( typeid( const MenubarValue
) == typeid( *this ));
108 return new MenubarValue( *this );
111 MenupopupValue::~MenupopupValue()
115 MenupopupValue
* MenupopupValue::clone() const
117 assert( typeid( const MenupopupValue
) == typeid( *this ));
118 return new MenupopupValue( *this );
121 PushButtonValue::~PushButtonValue()
125 PushButtonValue
* PushButtonValue::clone() const
127 assert( typeid( const PushButtonValue
) == typeid( *this ));
128 return new PushButtonValue( *this );
131 // These functions are mainly passthrough functions that allow access to
132 // the SalFrame behind a Window object for native widget rendering purposes.
134 bool OutputDevice::IsNativeControlSupported( ControlType nType
, ControlPart nPart
) const
136 if( !CanEnableNativeWidget() )
139 if ( !mpGraphics
&& !AcquireGraphics() )
143 return mpGraphics
->IsNativeControlSupported(nType
, nPart
);
146 bool OutputDevice::HitTestNativeScrollbar(
148 const tools::Rectangle
& rControlRegion
,
150 bool& rIsInside
) const
152 if( !CanEnableNativeWidget() )
155 if ( !mpGraphics
&& !AcquireGraphics() )
159 Point
aWinOffs( mnOutOffX
, mnOutOffY
);
160 tools::Rectangle
screenRegion( rControlRegion
);
161 screenRegion
.Move( aWinOffs
.X(), aWinOffs
.Y());
163 return mpGraphics
->HitTestNativeScrollbar( nPart
, screenRegion
, Point( aPos
.X() + mnOutOffX
, aPos
.Y() + mnOutOffY
),
167 static std::unique_ptr
< ImplControlValue
> TransformControlValue( const ImplControlValue
& rVal
, const OutputDevice
& rDev
)
169 std::unique_ptr
< ImplControlValue
> aResult
;
170 switch( rVal
.getType() )
172 case ControlType::Slider
:
174 const SliderValue
* pSlVal
= static_cast<const SliderValue
*>(&rVal
);
175 SliderValue
* pNew
= new SliderValue( *pSlVal
);
176 aResult
.reset( pNew
);
177 pNew
->maThumbRect
= rDev
.ImplLogicToDevicePixel( pSlVal
->maThumbRect
);
180 case ControlType::Scrollbar
:
182 const ScrollbarValue
* pScVal
= static_cast<const ScrollbarValue
*>(&rVal
);
183 ScrollbarValue
* pNew
= new ScrollbarValue( *pScVal
);
184 aResult
.reset( pNew
);
185 pNew
->maThumbRect
= rDev
.ImplLogicToDevicePixel( pScVal
->maThumbRect
);
186 pNew
->maButton1Rect
= rDev
.ImplLogicToDevicePixel( pScVal
->maButton1Rect
);
187 pNew
->maButton2Rect
= rDev
.ImplLogicToDevicePixel( pScVal
->maButton2Rect
);
190 case ControlType::SpinButtons
:
192 const SpinbuttonValue
* pSpVal
= static_cast<const SpinbuttonValue
*>(&rVal
);
193 SpinbuttonValue
* pNew
= new SpinbuttonValue( *pSpVal
);
194 aResult
.reset( pNew
);
195 pNew
->maUpperRect
= rDev
.ImplLogicToDevicePixel( pSpVal
->maUpperRect
);
196 pNew
->maLowerRect
= rDev
.ImplLogicToDevicePixel( pSpVal
->maLowerRect
);
199 case ControlType::Toolbar
:
201 const ToolbarValue
* pTVal
= static_cast<const ToolbarValue
*>(&rVal
);
202 ToolbarValue
* pNew
= new ToolbarValue( *pTVal
);
203 aResult
.reset( pNew
);
204 pNew
->maGripRect
= rDev
.ImplLogicToDevicePixel( pTVal
->maGripRect
);
207 case ControlType::TabPane
:
209 const TabPaneValue
* pTIVal
= static_cast<const TabPaneValue
*>(&rVal
);
210 TabPaneValue
* pNew
= new TabPaneValue(*pTIVal
);
211 pNew
->m_aTabHeaderRect
= rDev
.ImplLogicToDevicePixel(pTIVal
->m_aTabHeaderRect
);
212 pNew
->m_aSelectedTabRect
= rDev
.ImplLogicToDevicePixel(pTIVal
->m_aSelectedTabRect
);
216 case ControlType::TabItem
:
218 const TabitemValue
* pTIVal
= static_cast<const TabitemValue
*>(&rVal
);
219 TabitemValue
* pNew
= new TabitemValue( *pTIVal
);
220 pNew
->maContentRect
= rDev
.ImplLogicToDevicePixel(pTIVal
->maContentRect
);
221 aResult
.reset( pNew
);
224 case ControlType::Menubar
:
226 const MenubarValue
* pMVal
= static_cast<const MenubarValue
*>(&rVal
);
227 MenubarValue
* pNew
= new MenubarValue( *pMVal
);
228 aResult
.reset( pNew
);
231 case ControlType::Pushbutton
:
233 const PushButtonValue
* pBVal
= static_cast<const PushButtonValue
*>(&rVal
);
234 PushButtonValue
* pNew
= new PushButtonValue( *pBVal
);
235 aResult
.reset( pNew
);
238 case ControlType::Generic
:
239 aResult
= std::make_unique
<ImplControlValue
>( rVal
);
241 case ControlType::MenuPopup
:
243 const MenupopupValue
* pMVal
= static_cast<const MenupopupValue
*>(&rVal
);
244 MenupopupValue
* pNew
= new MenupopupValue( *pMVal
);
245 pNew
->maItemRect
= rDev
.ImplLogicToDevicePixel( pMVal
->maItemRect
);
246 aResult
.reset( pNew
);
255 bool OutputDevice::DrawNativeControl( ControlType nType
,
257 const tools::Rectangle
& rControlRegion
,
259 const ImplControlValue
& aValue
,
260 const OUString
& aCaption
,
261 const Color
& rBackgroundColor
)
263 assert(!is_double_buffered_window());
265 if( !CanEnableNativeWidget() )
268 // make sure the current clip region is initialized correctly
269 if ( !mpGraphics
&& !AcquireGraphics() )
273 if ( mbInitClipRegion
)
275 if ( mbOutputClipped
)
278 if ( mbInitLineColor
)
280 if ( mbInitFillColor
)
283 // Convert the coordinates from relative to Window-absolute, so we draw
284 // in the correct place in platform code
285 std::unique_ptr
< ImplControlValue
> aScreenCtrlValue( TransformControlValue( aValue
, *this ) );
286 tools::Rectangle
screenRegion( ImplLogicToDevicePixel( rControlRegion
) );
288 bool bRet
= mpGraphics
->DrawNativeControl(nType
, nPart
, screenRegion
, nState
, *aScreenCtrlValue
, aCaption
, *this, rBackgroundColor
);
293 bool OutputDevice::GetNativeControlRegion( ControlType nType
,
295 const tools::Rectangle
& rControlRegion
,
297 const ImplControlValue
& aValue
,
298 tools::Rectangle
&rNativeBoundingRegion
,
299 tools::Rectangle
&rNativeContentRegion
) const
301 if( !CanEnableNativeWidget() )
304 if ( !mpGraphics
&& !AcquireGraphics() )
308 // Convert the coordinates from relative to Window-absolute, so we draw
309 // in the correct place in platform code
310 std::unique_ptr
< ImplControlValue
> aScreenCtrlValue( TransformControlValue( aValue
, *this ) );
311 tools::Rectangle
screenRegion( ImplLogicToDevicePixel( rControlRegion
) );
313 bool bRet
= mpGraphics
->GetNativeControlRegion(nType
, nPart
, screenRegion
, nState
, *aScreenCtrlValue
,
314 rNativeBoundingRegion
,
315 rNativeContentRegion
, *this );
318 // transform back native regions
319 rNativeBoundingRegion
= ImplDevicePixelToLogic( rNativeBoundingRegion
);
320 rNativeContentRegion
= ImplDevicePixelToLogic( rNativeContentRegion
);
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */