Revert "tdf#158280 Replace usage of InputDialog with SvxNameDialog"
[LibreOffice.git] / vcl / source / outdev / nativecontrols.cxx
blob1b035c72bd2d97f520bdb4643affc909dd339b40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <salgdi.hxx>
28 #include <toolbarvalue.hxx>
29 #include <menubarvalue.hxx>
31 #include <cassert>
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() )
137 return false;
139 if ( !mpGraphics && !AcquireGraphics() )
140 return false;
141 assert(mpGraphics);
143 return mpGraphics->IsNativeControlSupported(nType, nPart);
146 bool OutputDevice::HitTestNativeScrollbar(
147 ControlPart nPart,
148 const tools::Rectangle& rControlRegion,
149 const Point& aPos,
150 bool& rIsInside ) const
152 if( !CanEnableNativeWidget() )
153 return false;
155 if ( !mpGraphics && !AcquireGraphics() )
156 return false;
157 assert(mpGraphics);
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 ),
164 rIsInside, *this );
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 );
179 break;
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 );
189 break;
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 );
198 break;
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 );
206 break;
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);
213 aResult.reset(pNew);
215 break;
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 );
223 break;
224 case ControlType::Menubar:
226 const MenubarValue* pMVal = static_cast<const MenubarValue*>(&rVal);
227 MenubarValue* pNew = new MenubarValue( *pMVal );
228 aResult.reset( pNew );
230 break;
231 case ControlType::Pushbutton:
233 const PushButtonValue* pBVal = static_cast<const PushButtonValue*>(&rVal);
234 PushButtonValue* pNew = new PushButtonValue( *pBVal );
235 aResult.reset( pNew );
237 break;
238 case ControlType::Generic:
239 aResult = std::make_unique<ImplControlValue>( rVal );
240 break;
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 );
248 break;
249 default:
250 std::abort();
251 break;
253 return aResult;
255 bool OutputDevice::DrawNativeControl( ControlType nType,
256 ControlPart nPart,
257 const tools::Rectangle& rControlRegion,
258 ControlState nState,
259 const ImplControlValue& aValue,
260 const OUString& aCaption,
261 const Color& rBackgroundColor )
263 assert(!is_double_buffered_window());
265 if( !CanEnableNativeWidget() )
266 return false;
268 // make sure the current clip region is initialized correctly
269 if ( !mpGraphics && !AcquireGraphics() )
270 return false;
271 assert(mpGraphics);
273 if ( mbInitClipRegion )
274 InitClipRegion();
275 if ( mbOutputClipped )
276 return true;
278 if ( mbInitLineColor )
279 InitLineColor();
280 if ( mbInitFillColor )
281 InitFillColor();
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);
290 return bRet;
293 bool OutputDevice::GetNativeControlRegion( ControlType nType,
294 ControlPart nPart,
295 const tools::Rectangle& rControlRegion,
296 ControlState nState,
297 const ImplControlValue& aValue,
298 tools::Rectangle &rNativeBoundingRegion,
299 tools::Rectangle &rNativeContentRegion ) const
301 if( !CanEnableNativeWidget() )
302 return false;
304 if ( !mpGraphics && !AcquireGraphics() )
305 return false;
306 assert(mpGraphics);
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 );
316 if( bRet )
318 // transform back native regions
319 rNativeBoundingRegion = ImplDevicePixelToLogic( rNativeBoundingRegion );
320 rNativeContentRegion = ImplDevicePixelToLogic( rNativeContentRegion );
323 return bRet;
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */