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 if (!s_pWidgetImplementation
)
29 OUString
aUrl("${LO_LIB_DIR}/" SVLIBRARY("vcl_widget_theme"));
30 rtl::Bootstrap::expandMacros(aUrl
);
32 aLibrary
.load(aUrl
, SAL_LOADMODULE_GLOBAL
);
33 auto fCreateWidgetThemeLibraryFunction
34 = reinterpret_cast<vcl::WidgetThemeLibrary
*(SAL_CALL
*)()>(
35 aLibrary
.getFunctionSymbol("CreateWidgetThemeLibrary"));
38 if (fCreateWidgetThemeLibraryFunction
)
39 s_pWidgetImplementation
= (*fCreateWidgetThemeLibraryFunction
)();
42 if (s_pWidgetImplementation
)
44 ImplSVData
* pSVData
= ImplGetSVData();
45 pSVData
->maNWFData
.mbNoFocusRects
= true;
46 pSVData
->maNWFData
.mbNoFocusRectsForFlatButtons
= true;
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*/)
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
)
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();
88 ControlDrawParameters aParameters
{ pCairoContext
, ePart
, eState
};
92 case ControlType::Generic
:
96 case ControlType::Pushbutton
:
98 const PushButtonValue
* pPushButtonValue
= static_cast<const PushButtonValue
*>(&rValue
);
100 aParameters
.bIsAction
= pPushButtonValue
->mbIsAction
;
101 bOK
= s_pWidgetImplementation
->drawPushButton(aParameters
, nWidth
, nHeight
);
104 case ControlType::Radiobutton
:
106 aParameters
.eButtonValue
= rValue
.getTristateVal();
107 bOK
= s_pWidgetImplementation
->drawRadiobutton(aParameters
, nWidth
, nHeight
);
110 case ControlType::Checkbox
:
112 aParameters
.eButtonValue
= rValue
.getTristateVal();
113 bOK
= s_pWidgetImplementation
->drawCheckbox(aParameters
, nWidth
, nHeight
);
116 case ControlType::Combobox
:
118 bOK
= s_pWidgetImplementation
->drawCombobox(aParameters
, nWidth
, nHeight
);
121 case ControlType::Editbox
:
123 bOK
= s_pWidgetImplementation
->drawEditbox(aParameters
, nWidth
, nHeight
);
126 case ControlType::EditboxNoBorder
:
128 bOK
= s_pWidgetImplementation
->drawEditbox(aParameters
, nWidth
, nHeight
);
131 case ControlType::MultilineEditbox
:
133 bOK
= s_pWidgetImplementation
->drawEditbox(aParameters
, nWidth
, nHeight
);
136 case ControlType::Listbox
:
138 bOK
= s_pWidgetImplementation
->drawListbox(aParameters
, nWidth
, nHeight
);
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
);
166 ControlDrawParameters aParametersDown
{ pCairoContext
, downBtnPart
,
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
);
180 bOK
= s_pWidgetImplementation
->drawSpinbox(aParameters
, nWidth
, nHeight
);
184 case ControlType::SpinButtons
:
186 bOK
= s_pWidgetImplementation
->drawSpinButtons(aParameters
, nWidth
, nHeight
);
189 case ControlType::TabItem
:
191 bOK
= s_pWidgetImplementation
->drawTabItem(aParameters
, nWidth
, nHeight
);
194 case ControlType::TabPane
:
196 bOK
= s_pWidgetImplementation
->drawTabPane(aParameters
, nWidth
, nHeight
);
199 case ControlType::TabHeader
:
201 bOK
= s_pWidgetImplementation
->drawTabHeader(aParameters
, nWidth
, nHeight
);
204 case ControlType::TabBody
:
206 bOK
= s_pWidgetImplementation
->drawTabBody(aParameters
, nWidth
, nHeight
);
209 case ControlType::Scrollbar
:
211 bOK
= s_pWidgetImplementation
->drawScrollbar(aParameters
, nWidth
, nHeight
);
214 case ControlType::Slider
:
216 cairo_save(pCairoContext
);
217 bOK
= s_pWidgetImplementation
->drawSlider(aParameters
, nWidth
, nHeight
);
218 cairo_restore(pCairoContext
);
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
);
237 case ControlType::Fixedline
:
239 bOK
= s_pWidgetImplementation
->drawFixedline(aParameters
, nWidth
, nHeight
);
242 case ControlType::Toolbar
:
244 bOK
= s_pWidgetImplementation
->drawToolbar(aParameters
, nWidth
, nHeight
);
247 case ControlType::Menubar
:
249 case ControlType::MenuPopup
:
251 case ControlType::Progress
:
253 aParameters
.nValue
= rValue
.getNumericVal();
254 bOK
= s_pWidgetImplementation
->drawProgress(aParameters
, nWidth
, nHeight
);
257 case ControlType::IntroProgress
:
259 case ControlType::Tooltip
:
261 case ControlType::WindowBackground
:
263 bOK
= s_pWidgetImplementation
->drawWindowsBackground(aParameters
, nWidth
, nHeight
);
266 case ControlType::Frame
:
268 bOK
= s_pWidgetImplementation
->drawFrame(aParameters
, nWidth
, nHeight
);
271 case ControlType::ListNode
:
273 aParameters
.eButtonValue
= rValue
.getTristateVal();
274 bOK
= s_pWidgetImplementation
->drawListNode(aParameters
, nWidth
, nHeight
);
277 case ControlType::ListNet
:
279 bOK
= s_pWidgetImplementation
->drawListNet(aParameters
, nWidth
, nHeight
);
282 case ControlType::ListHeader
:
284 bOK
= s_pWidgetImplementation
->drawListHeader(aParameters
, nWidth
, nHeight
);
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
);
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
);
319 = tools::Rectangle(aNativeBoundingRegion
.x
, aNativeBoundingRegion
.y
,
320 aNativeBoundingRegion
.width
, aNativeBoundingRegion
.height
);
326 bool CustomWidgetDraw::updateSettings(AllSettings
& rSettings
)
328 if (!s_pWidgetImplementation
)
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
.SetActionButtonTextColor(aStyle
.maActionButtonTextColor
);
346 aStyleSet
.SetDefaultActionButtonTextColor(aStyle
.maDefaultActionButtonTextColor
);
347 aStyleSet
.SetButtonRolloverTextColor(aStyle
.maButtonRolloverTextColor
);
348 aStyleSet
.SetActionButtonRolloverTextColor(aStyle
.maActionButtonRolloverTextColor
);
349 aStyleSet
.SetRadioCheckTextColor(aStyle
.maRadioCheckTextColor
);
350 aStyleSet
.SetGroupTextColor(aStyle
.maGroupTextColor
);
351 aStyleSet
.SetLabelTextColor(aStyle
.maLabelTextColor
);
352 aStyleSet
.SetWindowColor(aStyle
.maWindowColor
);
353 aStyleSet
.SetWindowTextColor(aStyle
.maWindowTextColor
);
354 aStyleSet
.SetDialogColor(aStyle
.maDialogColor
);
355 aStyleSet
.SetDialogTextColor(aStyle
.maDialogTextColor
);
356 aStyleSet
.SetWorkspaceColor(aStyle
.maWorkspaceColor
);
357 aStyleSet
.SetMonoColor(aStyle
.maMonoColor
);
358 aStyleSet
.SetFieldColor(Color(aStyle
.maFieldColor
));
359 aStyleSet
.SetFieldTextColor(aStyle
.maFieldTextColor
);
360 aStyleSet
.SetFieldRolloverTextColor(aStyle
.maFieldRolloverTextColor
);
361 aStyleSet
.SetActiveColor(aStyle
.maActiveColor
);
362 aStyleSet
.SetActiveTextColor(aStyle
.maActiveTextColor
);
363 aStyleSet
.SetActiveBorderColor(aStyle
.maActiveBorderColor
);
364 aStyleSet
.SetDeactiveColor(aStyle
.maDeactiveColor
);
365 aStyleSet
.SetDeactiveTextColor(aStyle
.maDeactiveTextColor
);
366 aStyleSet
.SetDeactiveBorderColor(aStyle
.maDeactiveBorderColor
);
367 aStyleSet
.SetMenuColor(aStyle
.maMenuColor
);
368 aStyleSet
.SetMenuBarColor(aStyle
.maMenuBarColor
);
369 aStyleSet
.SetMenuBarRolloverColor(aStyle
.maMenuBarRolloverColor
);
370 aStyleSet
.SetMenuBorderColor(aStyle
.maMenuBorderColor
);
371 aStyleSet
.SetMenuTextColor(aStyle
.maMenuTextColor
);
372 aStyleSet
.SetMenuBarTextColor(aStyle
.maMenuBarTextColor
);
373 aStyleSet
.SetMenuBarRolloverTextColor(aStyle
.maMenuBarRolloverTextColor
);
374 aStyleSet
.SetMenuBarHighlightTextColor(aStyle
.maMenuBarHighlightTextColor
);
375 aStyleSet
.SetMenuHighlightColor(aStyle
.maMenuHighlightColor
);
376 aStyleSet
.SetMenuHighlightTextColor(aStyle
.maMenuHighlightTextColor
);
377 aStyleSet
.SetHighlightColor(aStyle
.maHighlightColor
);
378 aStyleSet
.SetHighlightTextColor(aStyle
.maHighlightTextColor
);
379 aStyleSet
.SetActiveTabColor(aStyle
.maActiveTabColor
);
380 aStyleSet
.SetInactiveTabColor(aStyle
.maInactiveTabColor
);
381 aStyleSet
.SetTabTextColor(aStyle
.maTabTextColor
);
382 aStyleSet
.SetTabRolloverTextColor(aStyle
.maTabRolloverTextColor
);
383 aStyleSet
.SetTabHighlightTextColor(aStyle
.maTabHighlightTextColor
);
384 aStyleSet
.SetDisableColor(aStyle
.maDisableColor
);
385 aStyleSet
.SetHelpColor(aStyle
.maHelpColor
);
386 aStyleSet
.SetHelpTextColor(aStyle
.maHelpTextColor
);
387 aStyleSet
.SetLinkColor(aStyle
.maLinkColor
);
388 aStyleSet
.SetVisitedLinkColor(aStyle
.maVisitedLinkColor
);
389 aStyleSet
.SetToolTextColor(aStyle
.maToolTextColor
);
390 aStyleSet
.SetFontColor(aStyle
.maFontColor
);
392 rSettings
.SetStyleSettings(aStyleSet
);
400 } // end vcl namespace
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */