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/.
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>
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
)
31 OUString
aUrl("${LO_LIB_DIR}/" SVLIBRARY("vcl_widget_theme"));
32 rtl::Bootstrap::expandMacros(aUrl
);
34 aLibrary
.load(aUrl
, SAL_LOADMODULE_GLOBAL
);
35 auto fCreateWidgetThemeLibraryFunction
36 = reinterpret_cast<vcl::WidgetThemeLibrary
*(SAL_CALL
*)()>(
37 aLibrary
.getFunctionSymbol("CreateWidgetThemeLibrary"));
40 if (fCreateWidgetThemeLibraryFunction
)
41 s_pWidgetImplementation
= (*fCreateWidgetThemeLibraryFunction
)();
44 if (s_pWidgetImplementation
)
46 ImplSVData
* pSVData
= ImplGetSVData();
47 pSVData
->maNWFData
.mbNoFocusRects
= true;
48 pSVData
->maNWFData
.mbNoFocusRectsForFlatButtons
= true;
51 s_bMissingLibrary
= true;
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*/)
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
)
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();
92 ControlDrawParameters aParameters
{ pCairoContext
, ePart
, eState
};
96 case ControlType::Generic
:
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
);
108 case ControlType::Radiobutton
:
110 aParameters
.eButtonValue
= rValue
.getTristateVal();
111 bOK
= s_pWidgetImplementation
->drawRadiobutton(aParameters
, nWidth
, nHeight
);
114 case ControlType::Checkbox
:
116 aParameters
.eButtonValue
= rValue
.getTristateVal();
117 bOK
= s_pWidgetImplementation
->drawCheckbox(aParameters
, nWidth
, nHeight
);
120 case ControlType::Combobox
:
122 bOK
= s_pWidgetImplementation
->drawCombobox(aParameters
, nWidth
, nHeight
);
125 case ControlType::Editbox
:
127 bOK
= s_pWidgetImplementation
->drawEditbox(aParameters
, nWidth
, nHeight
);
130 case ControlType::EditboxNoBorder
:
132 bOK
= s_pWidgetImplementation
->drawEditbox(aParameters
, nWidth
, nHeight
);
135 case ControlType::MultilineEditbox
:
137 bOK
= s_pWidgetImplementation
->drawEditbox(aParameters
, nWidth
, nHeight
);
140 case ControlType::Listbox
:
142 bOK
= s_pWidgetImplementation
->drawListbox(aParameters
, nWidth
, nHeight
);
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
);
170 ControlDrawParameters aParametersDown
{ pCairoContext
, downBtnPart
,
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
);
184 bOK
= s_pWidgetImplementation
->drawSpinbox(aParameters
, nWidth
, nHeight
);
188 case ControlType::SpinButtons
:
190 bOK
= s_pWidgetImplementation
->drawSpinButtons(aParameters
, nWidth
, nHeight
);
193 case ControlType::TabItem
:
195 bOK
= s_pWidgetImplementation
->drawTabItem(aParameters
, nWidth
, nHeight
);
198 case ControlType::TabPane
:
200 bOK
= s_pWidgetImplementation
->drawTabPane(aParameters
, nWidth
, nHeight
);
203 case ControlType::TabHeader
:
205 bOK
= s_pWidgetImplementation
->drawTabHeader(aParameters
, nWidth
, nHeight
);
208 case ControlType::TabBody
:
210 bOK
= s_pWidgetImplementation
->drawTabBody(aParameters
, nWidth
, nHeight
);
213 case ControlType::Scrollbar
:
215 bOK
= s_pWidgetImplementation
->drawScrollbar(aParameters
, nWidth
, nHeight
);
218 case ControlType::Slider
:
220 cairo_save(pCairoContext
);
221 bOK
= s_pWidgetImplementation
->drawSlider(aParameters
, nWidth
, nHeight
);
222 cairo_restore(pCairoContext
);
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
);
241 case ControlType::Fixedline
:
243 bOK
= s_pWidgetImplementation
->drawFixedline(aParameters
, nWidth
, nHeight
);
246 case ControlType::Toolbar
:
248 bOK
= s_pWidgetImplementation
->drawToolbar(aParameters
, nWidth
, nHeight
);
251 case ControlType::Menubar
:
253 case ControlType::MenuPopup
:
255 case ControlType::Progress
:
257 aParameters
.nValue
= rValue
.getNumericVal();
258 bOK
= s_pWidgetImplementation
->drawProgress(aParameters
, nWidth
, nHeight
);
261 case ControlType::IntroProgress
:
263 case ControlType::Tooltip
:
265 case ControlType::WindowBackground
:
267 bOK
= s_pWidgetImplementation
->drawWindowsBackground(aParameters
, nWidth
, nHeight
);
270 case ControlType::Frame
:
272 bOK
= s_pWidgetImplementation
->drawFrame(aParameters
, nWidth
, nHeight
);
275 case ControlType::ListNode
:
277 aParameters
.eButtonValue
= rValue
.getTristateVal();
278 bOK
= s_pWidgetImplementation
->drawListNode(aParameters
, nWidth
, nHeight
);
281 case ControlType::ListNet
:
283 bOK
= s_pWidgetImplementation
->drawListNet(aParameters
, nWidth
, nHeight
);
286 case ControlType::ListHeader
:
288 bOK
= s_pWidgetImplementation
->drawListHeader(aParameters
, nWidth
, nHeight
);
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
);
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
);
323 = tools::Rectangle(aNativeBoundingRegion
.x
, aNativeBoundingRegion
.y
,
324 aNativeBoundingRegion
.width
, aNativeBoundingRegion
.height
);
330 bool CustomWidgetDraw::updateSettings(AllSettings
& rSettings
)
332 if (!s_pWidgetImplementation
)
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
);
419 } // end vcl namespace
421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */