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
.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
);
397 } // end vcl namespace
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */