nss: upgrade to release 3.73
[LibreOffice.git] / vcl / headless / CustomWidgetDraw.cxx
blob6ff10a34c7bb90f1ad9553294e64394de06f56b8
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 static bool s_bMissingLibrary = false;
28 if (s_pWidgetImplementation || s_bMissingLibrary)
29 return;
31 OUString aUrl("${LO_LIB_DIR}/" SVLIBRARY("vcl_widget_theme"));
32 rtl::Bootstrap::expandMacros(aUrl);
33 osl::Module aLibrary;
34 aLibrary.load(aUrl, SAL_LOADMODULE_GLOBAL);
35 auto fCreateWidgetThemeLibraryFunction
36 = reinterpret_cast<vcl::WidgetThemeLibrary*(SAL_CALL*)()>(
37 aLibrary.getFunctionSymbol("CreateWidgetThemeLibrary"));
38 aLibrary.release();
40 if (fCreateWidgetThemeLibraryFunction)
41 s_pWidgetImplementation = (*fCreateWidgetThemeLibraryFunction)();
43 // Init
44 if (s_pWidgetImplementation)
46 ImplSVData* pSVData = ImplGetSVData();
47 pSVData->maNWFData.mbNoFocusRects = true;
48 pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
50 else
51 s_bMissingLibrary = true;
52 #endif
55 CustomWidgetDraw::~CustomWidgetDraw() {}
57 bool CustomWidgetDraw::isNativeControlSupported(ControlType eType, ControlPart ePart)
59 return s_pWidgetImplementation
60 && s_pWidgetImplementation->isNativeControlSupported(eType, ePart);
63 bool CustomWidgetDraw::hitTestNativeControl(ControlType /*eType*/, ControlPart /*ePart*/,
64 const tools::Rectangle& /*rBoundingControlRegion*/,
65 const Point& /*aPos*/, bool& /*rIsInside*/)
67 return false;
70 bool CustomWidgetDraw::drawNativeControl(ControlType eType, ControlPart ePart,
71 const tools::Rectangle& rControlRegion,
72 ControlState eState, const ImplControlValue& rValue,
73 const OUString& /*aCaptions*/,
74 const Color& /*rBackgroundColor*/)
76 if (!s_pWidgetImplementation)
77 return false;
79 bool bOldAA = m_rGraphics.getAntiAlias();
80 m_rGraphics.setAntiAlias(true);
82 cairo_t* pCairoContext = m_rGraphics.getCairoContext(false);
83 m_rGraphics.clipRegion(pCairoContext);
85 cairo_translate(pCairoContext, rControlRegion.Left(), rControlRegion.Top());
87 tools::Long nWidth = rControlRegion.GetWidth();
88 tools::Long nHeight = rControlRegion.GetHeight();
90 bool bOK = false;
92 ControlDrawParameters aParameters{ pCairoContext, ePart, eState };
94 switch (eType)
96 case ControlType::Generic:
99 break;
100 case ControlType::Pushbutton:
102 const PushButtonValue* pPushButtonValue = static_cast<const PushButtonValue*>(&rValue);
103 if (pPushButtonValue)
104 aParameters.bIsAction = pPushButtonValue->mbIsAction;
105 bOK = s_pWidgetImplementation->drawPushButton(aParameters, nWidth, nHeight);
107 break;
108 case ControlType::Radiobutton:
110 aParameters.eButtonValue = rValue.getTristateVal();
111 bOK = s_pWidgetImplementation->drawRadiobutton(aParameters, nWidth, nHeight);
113 break;
114 case ControlType::Checkbox:
116 aParameters.eButtonValue = rValue.getTristateVal();
117 bOK = s_pWidgetImplementation->drawCheckbox(aParameters, nWidth, nHeight);
119 break;
120 case ControlType::Combobox:
122 bOK = s_pWidgetImplementation->drawCombobox(aParameters, nWidth, nHeight);
124 break;
125 case ControlType::Editbox:
127 bOK = s_pWidgetImplementation->drawEditbox(aParameters, nWidth, nHeight);
129 break;
130 case ControlType::EditboxNoBorder:
132 bOK = s_pWidgetImplementation->drawEditbox(aParameters, nWidth, nHeight);
134 break;
135 case ControlType::MultilineEditbox:
137 bOK = s_pWidgetImplementation->drawEditbox(aParameters, nWidth, nHeight);
139 break;
140 case ControlType::Listbox:
142 bOK = s_pWidgetImplementation->drawListbox(aParameters, nWidth, nHeight);
144 break;
145 case ControlType::Spinbox:
147 if (rValue.getType() == ControlType::SpinButtons)
149 const SpinbuttonValue* pSpinVal = static_cast<const SpinbuttonValue*>(&rValue);
151 ControlPart upBtnPart = pSpinVal->mnUpperPart;
152 ControlState upBtnState = pSpinVal->mnUpperState;
154 ControlPart downBtnPart = pSpinVal->mnLowerPart;
155 ControlState downBtnState = pSpinVal->mnLowerState;
157 ControlDrawParameters aParametersUp{ pCairoContext, upBtnPart, upBtnState };
158 cairo_save(pCairoContext);
159 cairo_translate(pCairoContext,
160 pSpinVal->maUpperRect.Left() - rControlRegion.Left(),
161 pSpinVal->maUpperRect.Top() - rControlRegion.Top());
162 bOK = s_pWidgetImplementation->drawSpinbox(aParametersUp,
163 pSpinVal->maUpperRect.GetWidth(),
164 pSpinVal->maUpperRect.GetHeight());
165 cairo_restore(pCairoContext);
168 if (bOK)
170 ControlDrawParameters aParametersDown{ pCairoContext, downBtnPart,
171 downBtnState };
172 cairo_save(pCairoContext);
173 cairo_translate(pCairoContext,
174 pSpinVal->maLowerRect.Left() - rControlRegion.Left(),
175 pSpinVal->maLowerRect.Top() - rControlRegion.Top());
176 bOK = s_pWidgetImplementation->drawSpinbox(aParametersDown,
177 pSpinVal->maLowerRect.GetWidth(),
178 pSpinVal->maLowerRect.GetHeight());
179 cairo_restore(pCairoContext);
182 else
184 bOK = s_pWidgetImplementation->drawSpinbox(aParameters, nWidth, nHeight);
187 break;
188 case ControlType::SpinButtons:
190 bOK = s_pWidgetImplementation->drawSpinButtons(aParameters, nWidth, nHeight);
192 break;
193 case ControlType::TabItem:
195 bOK = s_pWidgetImplementation->drawTabItem(aParameters, nWidth, nHeight);
197 break;
198 case ControlType::TabPane:
200 bOK = s_pWidgetImplementation->drawTabPane(aParameters, nWidth, nHeight);
202 break;
203 case ControlType::TabHeader:
205 bOK = s_pWidgetImplementation->drawTabHeader(aParameters, nWidth, nHeight);
207 break;
208 case ControlType::TabBody:
210 bOK = s_pWidgetImplementation->drawTabBody(aParameters, nWidth, nHeight);
212 break;
213 case ControlType::Scrollbar:
215 bOK = s_pWidgetImplementation->drawScrollbar(aParameters, nWidth, nHeight);
217 break;
218 case ControlType::Slider:
220 cairo_save(pCairoContext);
221 bOK = s_pWidgetImplementation->drawSlider(aParameters, nWidth, nHeight);
222 cairo_restore(pCairoContext);
224 if (bOK)
226 const SliderValue* pSliderValue = static_cast<const SliderValue*>(&rValue);
228 ControlDrawParameters aParametersButton{ pCairoContext, ControlPart::Button,
229 eState | pSliderValue->mnThumbState };
230 cairo_save(pCairoContext);
231 cairo_translate(pCairoContext,
232 pSliderValue->maThumbRect.Left() - rControlRegion.Left(),
233 pSliderValue->maThumbRect.Top() - rControlRegion.Top());
234 bOK = s_pWidgetImplementation->drawSlider(aParametersButton,
235 pSliderValue->maThumbRect.GetWidth(),
236 pSliderValue->maThumbRect.GetHeight());
237 cairo_restore(pCairoContext);
240 break;
241 case ControlType::Fixedline:
243 bOK = s_pWidgetImplementation->drawFixedline(aParameters, nWidth, nHeight);
245 break;
246 case ControlType::Toolbar:
248 bOK = s_pWidgetImplementation->drawToolbar(aParameters, nWidth, nHeight);
250 break;
251 case ControlType::Menubar:
252 break;
253 case ControlType::MenuPopup:
254 break;
255 case ControlType::Progress:
257 aParameters.nValue = rValue.getNumericVal();
258 bOK = s_pWidgetImplementation->drawProgress(aParameters, nWidth, nHeight);
260 break;
261 case ControlType::IntroProgress:
262 break;
263 case ControlType::Tooltip:
264 break;
265 case ControlType::WindowBackground:
267 bOK = s_pWidgetImplementation->drawWindowsBackground(aParameters, nWidth, nHeight);
269 break;
270 case ControlType::Frame:
272 bOK = s_pWidgetImplementation->drawFrame(aParameters, nWidth, nHeight);
274 break;
275 case ControlType::ListNode:
277 aParameters.eButtonValue = rValue.getTristateVal();
278 bOK = s_pWidgetImplementation->drawListNode(aParameters, nWidth, nHeight);
280 break;
281 case ControlType::ListNet:
283 bOK = s_pWidgetImplementation->drawListNet(aParameters, nWidth, nHeight);
285 break;
286 case ControlType::ListHeader:
288 bOK = s_pWidgetImplementation->drawListHeader(aParameters, nWidth, nHeight);
290 break;
293 basegfx::B2DRange aExtents(rControlRegion.Left(), rControlRegion.Top(), rControlRegion.Right(),
294 rControlRegion.Bottom());
296 m_rGraphics.releaseCairoContext(pCairoContext, true, aExtents);
298 m_rGraphics.setAntiAlias(bOldAA);
300 return bOK;
303 bool CustomWidgetDraw::getNativeControlRegion(
304 ControlType eType, ControlPart ePart, const tools::Rectangle& rBoundingControlRegion,
305 ControlState eState, const ImplControlValue& /*aValue*/, const OUString& /*aCaption*/,
306 tools::Rectangle& rNativeBoundingRegion, tools::Rectangle& rNativeContentRegion)
308 // Translate to POD rectangle and back.
309 const rectangle_t aRegion
310 = { rBoundingControlRegion.getX(), rBoundingControlRegion.getY(),
311 rBoundingControlRegion.GetWidth(), rBoundingControlRegion.GetHeight() };
312 if (s_pWidgetImplementation)
314 rectangle_t aNativeBoundingRegion;
315 rectangle_t aNativeContentRegion;
316 s_pWidgetImplementation->getRegion(eType, ePart, eState, aRegion, aNativeBoundingRegion,
317 aNativeContentRegion);
319 rNativeBoundingRegion
320 = tools::Rectangle(aNativeBoundingRegion.x, aNativeBoundingRegion.y,
321 aNativeBoundingRegion.width, aNativeBoundingRegion.height);
322 rNativeContentRegion
323 = tools::Rectangle(aNativeBoundingRegion.x, aNativeBoundingRegion.y,
324 aNativeBoundingRegion.width, aNativeBoundingRegion.height);
327 return false;
330 bool CustomWidgetDraw::updateSettings(AllSettings& rSettings)
332 if (!s_pWidgetImplementation)
333 return false;
335 WidgetDrawStyle aStyle;
336 aStyle.nSize = sizeof(WidgetDrawStyle);
338 if (s_pWidgetImplementation->updateSettings(aStyle))
340 StyleSettings aStyleSet = rSettings.GetStyleSettings();
342 aStyleSet.SetFaceColor(aStyle.maFaceColor);
343 aStyleSet.SetCheckedColor(aStyle.maCheckedColor);
344 aStyleSet.SetLightColor(aStyle.maLightColor);
345 aStyleSet.SetLightBorderColor(aStyle.maLightBorderColor);
346 aStyleSet.SetShadowColor(aStyle.maShadowColor);
347 aStyleSet.SetDarkShadowColor(aStyle.maDarkShadowColor);
348 aStyleSet.SetDefaultButtonTextColor(aStyle.maDefaultButtonTextColor);
349 aStyleSet.SetButtonTextColor(aStyle.maButtonTextColor);
350 aStyleSet.SetDefaultActionButtonTextColor(aStyle.maDefaultActionButtonTextColor);
351 aStyleSet.SetActionButtonTextColor(aStyle.maActionButtonTextColor);
352 aStyleSet.SetFlatButtonTextColor(aStyle.maFlatButtonTextColor);
353 aStyleSet.SetDefaultButtonRolloverTextColor(aStyle.maDefaultButtonRolloverTextColor);
354 aStyleSet.SetButtonRolloverTextColor(aStyle.maButtonRolloverTextColor);
355 aStyleSet.SetDefaultActionButtonRolloverTextColor(
356 aStyle.maDefaultActionButtonRolloverTextColor);
357 aStyleSet.SetActionButtonRolloverTextColor(aStyle.maActionButtonRolloverTextColor);
358 aStyleSet.SetFlatButtonRolloverTextColor(aStyle.maFlatButtonRolloverTextColor);
359 aStyleSet.SetDefaultButtonPressedRolloverTextColor(
360 aStyle.maDefaultButtonPressedRolloverTextColor);
361 aStyleSet.SetButtonPressedRolloverTextColor(aStyle.maButtonPressedRolloverTextColor);
362 aStyleSet.SetDefaultActionButtonPressedRolloverTextColor(
363 aStyle.maDefaultActionButtonPressedRolloverTextColor);
364 aStyleSet.SetActionButtonPressedRolloverTextColor(
365 aStyle.maActionButtonPressedRolloverTextColor);
366 aStyleSet.SetFlatButtonPressedRolloverTextColor(
367 aStyle.maFlatButtonPressedRolloverTextColor);
368 aStyleSet.SetRadioCheckTextColor(aStyle.maRadioCheckTextColor);
369 aStyleSet.SetGroupTextColor(aStyle.maGroupTextColor);
370 aStyleSet.SetLabelTextColor(aStyle.maLabelTextColor);
371 aStyleSet.SetWindowColor(aStyle.maWindowColor);
372 aStyleSet.SetWindowTextColor(aStyle.maWindowTextColor);
373 aStyleSet.SetDialogColor(aStyle.maDialogColor);
374 aStyleSet.SetDialogTextColor(aStyle.maDialogTextColor);
375 aStyleSet.SetWorkspaceColor(aStyle.maWorkspaceColor);
376 aStyleSet.SetMonoColor(aStyle.maMonoColor);
377 aStyleSet.SetFieldColor(Color(aStyle.maFieldColor));
378 aStyleSet.SetFieldTextColor(aStyle.maFieldTextColor);
379 aStyleSet.SetFieldRolloverTextColor(aStyle.maFieldRolloverTextColor);
380 aStyleSet.SetActiveColor(aStyle.maActiveColor);
381 aStyleSet.SetActiveTextColor(aStyle.maActiveTextColor);
382 aStyleSet.SetActiveBorderColor(aStyle.maActiveBorderColor);
383 aStyleSet.SetDeactiveColor(aStyle.maDeactiveColor);
384 aStyleSet.SetDeactiveTextColor(aStyle.maDeactiveTextColor);
385 aStyleSet.SetDeactiveBorderColor(aStyle.maDeactiveBorderColor);
386 aStyleSet.SetMenuColor(aStyle.maMenuColor);
387 aStyleSet.SetMenuBarColor(aStyle.maMenuBarColor);
388 aStyleSet.SetMenuBarRolloverColor(aStyle.maMenuBarRolloverColor);
389 aStyleSet.SetMenuBorderColor(aStyle.maMenuBorderColor);
390 aStyleSet.SetMenuTextColor(aStyle.maMenuTextColor);
391 aStyleSet.SetMenuBarTextColor(aStyle.maMenuBarTextColor);
392 aStyleSet.SetMenuBarRolloverTextColor(aStyle.maMenuBarRolloverTextColor);
393 aStyleSet.SetMenuBarHighlightTextColor(aStyle.maMenuBarHighlightTextColor);
394 aStyleSet.SetMenuHighlightColor(aStyle.maMenuHighlightColor);
395 aStyleSet.SetMenuHighlightTextColor(aStyle.maMenuHighlightTextColor);
396 aStyleSet.SetHighlightColor(aStyle.maHighlightColor);
397 aStyleSet.SetHighlightTextColor(aStyle.maHighlightTextColor);
398 aStyleSet.SetActiveTabColor(aStyle.maActiveTabColor);
399 aStyleSet.SetInactiveTabColor(aStyle.maInactiveTabColor);
400 aStyleSet.SetTabTextColor(aStyle.maTabTextColor);
401 aStyleSet.SetTabRolloverTextColor(aStyle.maTabRolloverTextColor);
402 aStyleSet.SetTabHighlightTextColor(aStyle.maTabHighlightTextColor);
403 aStyleSet.SetDisableColor(aStyle.maDisableColor);
404 aStyleSet.SetHelpColor(aStyle.maHelpColor);
405 aStyleSet.SetHelpTextColor(aStyle.maHelpTextColor);
406 aStyleSet.SetLinkColor(aStyle.maLinkColor);
407 aStyleSet.SetVisitedLinkColor(aStyle.maVisitedLinkColor);
408 aStyleSet.SetToolTextColor(aStyle.maToolTextColor);
409 aStyleSet.SetFontColor(aStyle.maFontColor);
411 rSettings.SetStyleSettings(aStyleSet);
413 return true;
416 return false;
419 } // end vcl namespace
421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */