bump product version to 6.3.0.0.beta1
[LibreOffice.git] / vcl / headless / CustomWidgetDraw.cxx
blob9e49390b0f3a87f5eec4f952372cd3a2ab7857fa
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 */
11 #include <cairo.h>
12 #include <headless/CustomWidgetDraw.hxx>
13 #include <sal/config.h>
14 #include <rtl/bootstrap.hxx>
15 #include <tools/svlibrary.h>
16 #include <osl/module.hxx>
17 #include <svdata.hxx>
19 namespace vcl
21 WidgetThemeLibrary* CustomWidgetDraw::s_pWidgetImplementation = nullptr;
23 CustomWidgetDraw::CustomWidgetDraw(SvpSalGraphics& rGraphics)
24 : m_rGraphics(rGraphics)
26 #ifndef DISABLE_DYNLOADING
27 if (!s_pWidgetImplementation)
29 OUString aUrl("${LO_LIB_DIR}/" SVLIBRARY("vcl_widget_theme"));
30 rtl::Bootstrap::expandMacros(aUrl);
31 osl::Module aLibrary;
32 aLibrary.load(aUrl, SAL_LOADMODULE_GLOBAL);
33 auto fCreateWidgetThemeLibraryFunction
34 = reinterpret_cast<vcl::WidgetThemeLibrary*(SAL_CALL*)()>(
35 aLibrary.getFunctionSymbol("CreateWidgetThemeLibrary"));
36 aLibrary.release();
38 if (fCreateWidgetThemeLibraryFunction)
39 s_pWidgetImplementation = (*fCreateWidgetThemeLibraryFunction)();
41 // Init
42 if (s_pWidgetImplementation)
44 ImplSVData* pSVData = ImplGetSVData();
45 pSVData->maNWFData.mbNoFocusRects = true;
46 pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
49 #endif
52 CustomWidgetDraw::~CustomWidgetDraw() {}
54 bool CustomWidgetDraw::isNativeControlSupported(ControlType eType, ControlPart ePart)
56 return s_pWidgetImplementation
57 && s_pWidgetImplementation->isNativeControlSupported(eType, ePart);
60 bool CustomWidgetDraw::hitTestNativeControl(ControlType /*eType*/, ControlPart /*ePart*/,
61 const tools::Rectangle& /*rBoundingControlRegion*/,
62 const Point& /*aPos*/, bool& /*rIsInside*/)
64 return false;
67 bool CustomWidgetDraw::drawNativeControl(ControlType eType, ControlPart ePart,
68 const tools::Rectangle& rControlRegion,
69 ControlState eState, const ImplControlValue& rValue,
70 const OUString& /*aCaptions*/)
72 if (!s_pWidgetImplementation)
73 return false;
75 bool bOldAA = m_rGraphics.getAntiAliasB2DDraw();
76 m_rGraphics.setAntiAliasB2DDraw(true);
78 cairo_t* pCairoContext = m_rGraphics.getCairoContext(false);
79 m_rGraphics.clipRegion(pCairoContext);
81 cairo_translate(pCairoContext, rControlRegion.Left(), rControlRegion.Top());
83 long nWidth = rControlRegion.GetWidth();
84 long nHeight = rControlRegion.GetHeight();
86 bool bOK = false;
88 ControlDrawParameters aParameters{ pCairoContext, ePart, eState };
90 switch (eType)
92 case ControlType::Generic:
95 break;
96 case ControlType::Pushbutton:
98 const PushButtonValue* pPushButtonValue = static_cast<const PushButtonValue*>(&rValue);
99 if (pPushButtonValue)
100 aParameters.bIsAction = pPushButtonValue->mbIsAction;
101 bOK = s_pWidgetImplementation->drawPushButton(aParameters, nWidth, nHeight);
103 break;
104 case ControlType::Radiobutton:
106 aParameters.eButtonValue = rValue.getTristateVal();
107 bOK = s_pWidgetImplementation->drawRadiobutton(aParameters, nWidth, nHeight);
109 break;
110 case ControlType::Checkbox:
112 aParameters.eButtonValue = rValue.getTristateVal();
113 bOK = s_pWidgetImplementation->drawCheckbox(aParameters, nWidth, nHeight);
115 break;
116 case ControlType::Combobox:
118 bOK = s_pWidgetImplementation->drawCombobox(aParameters, nWidth, nHeight);
120 break;
121 case ControlType::Editbox:
123 bOK = s_pWidgetImplementation->drawEditbox(aParameters, nWidth, nHeight);
125 break;
126 case ControlType::EditboxNoBorder:
128 bOK = s_pWidgetImplementation->drawEditbox(aParameters, nWidth, nHeight);
130 break;
131 case ControlType::MultilineEditbox:
133 bOK = s_pWidgetImplementation->drawEditbox(aParameters, nWidth, nHeight);
135 break;
136 case ControlType::Listbox:
138 bOK = s_pWidgetImplementation->drawListbox(aParameters, nWidth, nHeight);
140 break;
141 case ControlType::Spinbox:
143 if (rValue.getType() == ControlType::SpinButtons)
145 const SpinbuttonValue* pSpinVal = static_cast<const SpinbuttonValue*>(&rValue);
147 ControlPart upBtnPart = pSpinVal->mnUpperPart;
148 ControlState upBtnState = pSpinVal->mnUpperState;
150 ControlPart downBtnPart = pSpinVal->mnLowerPart;
151 ControlState downBtnState = pSpinVal->mnLowerState;
153 ControlDrawParameters aParametersUp{ pCairoContext, upBtnPart, upBtnState };
154 cairo_save(pCairoContext);
155 cairo_translate(pCairoContext,
156 pSpinVal->maUpperRect.Left() - rControlRegion.Left(),
157 pSpinVal->maUpperRect.Top() - rControlRegion.Top());
158 bOK = s_pWidgetImplementation->drawSpinbox(aParametersUp,
159 pSpinVal->maUpperRect.GetWidth(),
160 pSpinVal->maUpperRect.GetHeight());
161 cairo_restore(pCairoContext);
164 if (bOK)
166 ControlDrawParameters aParametersDown{ pCairoContext, downBtnPart,
167 downBtnState };
168 cairo_save(pCairoContext);
169 cairo_translate(pCairoContext,
170 pSpinVal->maLowerRect.Left() - rControlRegion.Left(),
171 pSpinVal->maLowerRect.Top() - rControlRegion.Top());
172 bOK = s_pWidgetImplementation->drawSpinbox(aParametersDown,
173 pSpinVal->maLowerRect.GetWidth(),
174 pSpinVal->maLowerRect.GetHeight());
175 cairo_restore(pCairoContext);
178 else
180 bOK = s_pWidgetImplementation->drawSpinbox(aParameters, nWidth, nHeight);
183 break;
184 case ControlType::SpinButtons:
186 bOK = s_pWidgetImplementation->drawSpinButtons(aParameters, nWidth, nHeight);
188 break;
189 case ControlType::TabItem:
191 bOK = s_pWidgetImplementation->drawTabItem(aParameters, nWidth, nHeight);
193 break;
194 case ControlType::TabPane:
196 bOK = s_pWidgetImplementation->drawTabPane(aParameters, nWidth, nHeight);
198 break;
199 case ControlType::TabHeader:
201 bOK = s_pWidgetImplementation->drawTabHeader(aParameters, nWidth, nHeight);
203 break;
204 case ControlType::TabBody:
206 bOK = s_pWidgetImplementation->drawTabBody(aParameters, nWidth, nHeight);
208 break;
209 case ControlType::Scrollbar:
211 bOK = s_pWidgetImplementation->drawScrollbar(aParameters, nWidth, nHeight);
213 break;
214 case ControlType::Slider:
216 cairo_save(pCairoContext);
217 bOK = s_pWidgetImplementation->drawSlider(aParameters, nWidth, nHeight);
218 cairo_restore(pCairoContext);
220 if (bOK)
222 const SliderValue* pSliderValue = static_cast<const SliderValue*>(&rValue);
224 ControlDrawParameters aParametersButton{ pCairoContext, ControlPart::Button,
225 eState | pSliderValue->mnThumbState };
226 cairo_save(pCairoContext);
227 cairo_translate(pCairoContext,
228 pSliderValue->maThumbRect.Left() - rControlRegion.Left(),
229 pSliderValue->maThumbRect.Top() - rControlRegion.Top());
230 bOK = s_pWidgetImplementation->drawSlider(aParametersButton,
231 pSliderValue->maThumbRect.GetWidth(),
232 pSliderValue->maThumbRect.GetHeight());
233 cairo_restore(pCairoContext);
236 break;
237 case ControlType::Fixedline:
239 bOK = s_pWidgetImplementation->drawFixedline(aParameters, nWidth, nHeight);
241 break;
242 case ControlType::Toolbar:
244 bOK = s_pWidgetImplementation->drawToolbar(aParameters, nWidth, nHeight);
246 break;
247 case ControlType::Menubar:
248 break;
249 case ControlType::MenuPopup:
250 break;
251 case ControlType::Progress:
253 aParameters.nValue = rValue.getNumericVal();
254 bOK = s_pWidgetImplementation->drawProgress(aParameters, nWidth, nHeight);
256 break;
257 case ControlType::IntroProgress:
258 break;
259 case ControlType::Tooltip:
260 break;
261 case ControlType::WindowBackground:
263 bOK = s_pWidgetImplementation->drawWindowsBackground(aParameters, nWidth, nHeight);
265 break;
266 case ControlType::Frame:
268 bOK = s_pWidgetImplementation->drawFrame(aParameters, nWidth, nHeight);
270 break;
271 case ControlType::ListNode:
273 aParameters.eButtonValue = rValue.getTristateVal();
274 bOK = s_pWidgetImplementation->drawListNode(aParameters, nWidth, nHeight);
276 break;
277 case ControlType::ListNet:
279 bOK = s_pWidgetImplementation->drawListNet(aParameters, nWidth, nHeight);
281 break;
282 case ControlType::ListHeader:
284 bOK = s_pWidgetImplementation->drawListHeader(aParameters, nWidth, nHeight);
286 break;
289 basegfx::B2DRange aExtents(rControlRegion.Left(), rControlRegion.Top(), rControlRegion.Right(),
290 rControlRegion.Bottom());
292 m_rGraphics.releaseCairoContext(pCairoContext, true, aExtents);
294 m_rGraphics.setAntiAliasB2DDraw(bOldAA);
296 return bOK;
299 bool CustomWidgetDraw::getNativeControlRegion(
300 ControlType eType, ControlPart ePart, const tools::Rectangle& rBoundingControlRegion,
301 ControlState eState, const ImplControlValue& /*aValue*/, const OUString& /*aCaption*/,
302 tools::Rectangle& rNativeBoundingRegion, tools::Rectangle& rNativeContentRegion)
304 // Translate to POD rectangle and back.
305 const rectangle_t aRegion
306 = { rBoundingControlRegion.getX(), rBoundingControlRegion.getY(),
307 rBoundingControlRegion.GetWidth(), rBoundingControlRegion.GetHeight() };
308 if (s_pWidgetImplementation)
310 rectangle_t aNativeBoundingRegion;
311 rectangle_t aNativeContentRegion;
312 s_pWidgetImplementation->getRegion(eType, ePart, eState, aRegion, aNativeBoundingRegion,
313 aNativeContentRegion);
315 rNativeBoundingRegion
316 = tools::Rectangle(aNativeBoundingRegion.x, aNativeBoundingRegion.y,
317 aNativeBoundingRegion.width, aNativeBoundingRegion.height);
318 rNativeContentRegion
319 = tools::Rectangle(aNativeBoundingRegion.x, aNativeBoundingRegion.y,
320 aNativeBoundingRegion.width, aNativeBoundingRegion.height);
323 return false;
326 bool CustomWidgetDraw::updateSettings(AllSettings& rSettings)
328 if (!s_pWidgetImplementation)
329 return false;
331 WidgetDrawStyle aStyle;
332 aStyle.nSize = sizeof(WidgetDrawStyle);
334 if (s_pWidgetImplementation->updateSettings(aStyle))
336 StyleSettings aStyleSet = rSettings.GetStyleSettings();
338 aStyleSet.SetFaceColor(aStyle.maFaceColor);
339 aStyleSet.SetCheckedColor(aStyle.maCheckedColor);
340 aStyleSet.SetLightColor(aStyle.maLightColor);
341 aStyleSet.SetLightBorderColor(aStyle.maLightBorderColor);
342 aStyleSet.SetShadowColor(aStyle.maShadowColor);
343 aStyleSet.SetDarkShadowColor(aStyle.maDarkShadowColor);
344 aStyleSet.SetButtonTextColor(aStyle.maButtonTextColor);
345 aStyleSet.SetButtonRolloverTextColor(aStyle.maButtonRolloverTextColor);
346 aStyleSet.SetRadioCheckTextColor(aStyle.maRadioCheckTextColor);
347 aStyleSet.SetGroupTextColor(aStyle.maGroupTextColor);
348 aStyleSet.SetLabelTextColor(aStyle.maLabelTextColor);
349 aStyleSet.SetWindowColor(aStyle.maWindowColor);
350 aStyleSet.SetWindowTextColor(aStyle.maWindowTextColor);
351 aStyleSet.SetDialogColor(aStyle.maDialogColor);
352 aStyleSet.SetDialogTextColor(aStyle.maDialogTextColor);
353 aStyleSet.SetWorkspaceColor(aStyle.maWorkspaceColor);
354 aStyleSet.SetMonoColor(aStyle.maMonoColor);
355 aStyleSet.SetFieldColor(Color(aStyle.maFieldColor));
356 aStyleSet.SetFieldTextColor(aStyle.maFieldTextColor);
357 aStyleSet.SetFieldRolloverTextColor(aStyle.maFieldRolloverTextColor);
358 aStyleSet.SetActiveColor(aStyle.maActiveColor);
359 aStyleSet.SetActiveTextColor(aStyle.maActiveTextColor);
360 aStyleSet.SetActiveBorderColor(aStyle.maActiveBorderColor);
361 aStyleSet.SetDeactiveColor(aStyle.maDeactiveColor);
362 aStyleSet.SetDeactiveTextColor(aStyle.maDeactiveTextColor);
363 aStyleSet.SetDeactiveBorderColor(aStyle.maDeactiveBorderColor);
364 aStyleSet.SetMenuColor(aStyle.maMenuColor);
365 aStyleSet.SetMenuBarColor(aStyle.maMenuBarColor);
366 aStyleSet.SetMenuBarRolloverColor(aStyle.maMenuBarRolloverColor);
367 aStyleSet.SetMenuBorderColor(aStyle.maMenuBorderColor);
368 aStyleSet.SetMenuTextColor(aStyle.maMenuTextColor);
369 aStyleSet.SetMenuBarTextColor(aStyle.maMenuBarTextColor);
370 aStyleSet.SetMenuBarRolloverTextColor(aStyle.maMenuBarRolloverTextColor);
371 aStyleSet.SetMenuBarHighlightTextColor(aStyle.maMenuBarHighlightTextColor);
372 aStyleSet.SetMenuHighlightColor(aStyle.maMenuHighlightColor);
373 aStyleSet.SetMenuHighlightTextColor(aStyle.maMenuHighlightTextColor);
374 aStyleSet.SetHighlightColor(aStyle.maHighlightColor);
375 aStyleSet.SetHighlightTextColor(aStyle.maHighlightTextColor);
376 aStyleSet.SetActiveTabColor(aStyle.maActiveTabColor);
377 aStyleSet.SetInactiveTabColor(aStyle.maInactiveTabColor);
378 aStyleSet.SetTabTextColor(aStyle.maTabTextColor);
379 aStyleSet.SetTabRolloverTextColor(aStyle.maTabRolloverTextColor);
380 aStyleSet.SetTabHighlightTextColor(aStyle.maTabHighlightTextColor);
381 aStyleSet.SetDisableColor(aStyle.maDisableColor);
382 aStyleSet.SetHelpColor(aStyle.maHelpColor);
383 aStyleSet.SetHelpTextColor(aStyle.maHelpTextColor);
384 aStyleSet.SetLinkColor(aStyle.maLinkColor);
385 aStyleSet.SetVisitedLinkColor(aStyle.maVisitedLinkColor);
386 aStyleSet.SetToolTextColor(aStyle.maToolTextColor);
387 aStyleSet.SetFontColor(aStyle.maFontColor);
389 rSettings.SetStyleSettings(aStyleSet);
391 return true;
394 return false;
397 } // end vcl namespace
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */