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/.
11 #include <FileDefinitionWidgetDraw.hxx>
12 #include <widgetdraw/WidgetDefinitionReader.hxx>
14 #include <sal/config.h>
16 #include <rtl/bootstrap.hxx>
17 #include <config_folders.h>
18 #include <osl/file.hxx>
20 #include <basegfx/range/b2drectangle.hxx>
21 #include <basegfx/polygon/b2dpolygontools.hxx>
22 #include <basegfx/tuple/b2dtuple.hxx>
23 #include <basegfx/matrix/b2dhommatrixtools.hxx>
25 #include <tools/stream.hxx>
26 #include <vcl/bitmapex.hxx>
27 #include <vcl/BitmapTools.hxx>
28 #include <vcl/gradient.hxx>
30 #include <comphelper/seqstream.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/lok.hxx>
34 #include <com/sun/star/graphic/SvgTools.hpp>
35 #include <basegfx/DrawCommands.hxx>
43 OUString
lcl_getThemeDefinitionPath()
45 OUString
sPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER
"/theme_definitions/");
46 rtl::Bootstrap::expandMacros(sPath
);
50 bool lcl_directoryExists(OUString
const& sDirectory
)
52 osl::DirectoryItem aDirectoryItem
;
53 osl::FileBase::RC eRes
= osl::DirectoryItem::get(sDirectory
, aDirectoryItem
);
54 return eRes
== osl::FileBase::E_None
;
57 bool lcl_fileExists(OUString
const& sFilename
)
59 osl::File
aFile(sFilename
);
60 osl::FileBase::RC eRC
= aFile
.open(osl_File_OpenFlag_Read
);
61 return osl::FileBase::E_None
== eRC
;
64 std::shared_ptr
<WidgetDefinition
> getWidgetDefinition(OUString
const& rDefinitionFile
,
65 OUString
const& rDefinitionResourcesPath
)
67 auto pWidgetDefinition
= std::make_shared
<WidgetDefinition
>();
68 WidgetDefinitionReader
aReader(rDefinitionFile
, rDefinitionResourcesPath
);
69 if (aReader
.read(*pWidgetDefinition
))
70 return pWidgetDefinition
;
71 return std::shared_ptr
<WidgetDefinition
>();
74 std::shared_ptr
<WidgetDefinition
> const& getWidgetDefinitionForTheme(OUString
const& rThemenName
)
76 static std::shared_ptr
<WidgetDefinition
> spDefinition
;
79 OUString sSharedDefinitionBasePath
= lcl_getThemeDefinitionPath();
80 OUString sThemeFolder
= sSharedDefinitionBasePath
+ rThemenName
+ "/";
81 OUString sThemeDefinitionFile
= sThemeFolder
+ "definition.xml";
82 if (lcl_directoryExists(sThemeFolder
) && lcl_fileExists(sThemeDefinitionFile
))
83 spDefinition
= getWidgetDefinition(sThemeDefinitionFile
, sThemeFolder
);
88 } // end anonymous namespace
90 FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics
& rGraphics
)
91 : m_rGraphics(rGraphics
)
94 if (comphelper::LibreOfficeKit::isActive())
95 m_pWidgetDefinition
= getWidgetDefinitionForTheme("online");
97 if (!m_pWidgetDefinition
)
98 m_pWidgetDefinition
= getWidgetDefinitionForTheme("ios");
101 if (m_pWidgetDefinition
)
103 ImplSVData
* pSVData
= ImplGetSVData();
104 pSVData
->maNWFData
.mbNoFocusRects
= true;
105 pSVData
->maNWFData
.mbNoFocusRectsForFlatButtons
= true;
106 pSVData
->maNWFData
.mbNoActiveTabTextRaise
= true;
107 pSVData
->maNWFData
.mbCenteredTabs
= true;
108 pSVData
->maNWFData
.mbProgressNeedsErase
= true;
109 pSVData
->maNWFData
.mnStatusBarLowerRightOffset
= 10;
110 pSVData
->maNWFData
.mbCanDrawWidgetAnySize
= true;
111 pSVData
->maNWFData
.mnListBoxEntryMargin
= 20;
117 bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType
, ControlPart ePart
)
121 case ControlType::Generic
:
122 case ControlType::Pushbutton
:
123 case ControlType::Radiobutton
:
124 case ControlType::Checkbox
:
126 case ControlType::Combobox
:
127 if (ePart
== ControlPart::HasBackgroundTexture
)
130 case ControlType::Editbox
:
131 case ControlType::EditboxNoBorder
:
132 case ControlType::MultilineEditbox
:
134 case ControlType::Listbox
:
135 if (ePart
== ControlPart::HasBackgroundTexture
)
138 case ControlType::Spinbox
:
139 if (ePart
== ControlPart::AllButtons
)
142 case ControlType::SpinButtons
:
144 case ControlType::TabItem
:
145 case ControlType::TabPane
:
146 case ControlType::TabHeader
:
147 case ControlType::TabBody
:
149 case ControlType::Scrollbar
:
150 if (ePart
== ControlPart::DrawBackgroundHorz
151 || ePart
== ControlPart::DrawBackgroundVert
)
154 case ControlType::Slider
:
155 case ControlType::Fixedline
:
156 case ControlType::Toolbar
:
158 case ControlType::Menubar
:
159 case ControlType::MenuPopup
:
161 case ControlType::Progress
:
163 case ControlType::IntroProgress
:
165 case ControlType::Tooltip
:
167 case ControlType::WindowBackground
:
168 case ControlType::Frame
:
169 case ControlType::ListNode
:
170 case ControlType::ListNet
:
171 case ControlType::ListHeader
:
178 bool FileDefinitionWidgetDraw::hitTestNativeControl(
179 ControlType
/*eType*/, ControlPart
/*ePart*/,
180 const tools::Rectangle
& /*rBoundingControlRegion*/, const Point
& /*aPos*/, bool& /*rIsInside*/)
187 void drawFromDrawCommands(gfx::DrawRoot
const& rDrawRoot
, SalGraphics
& rGraphics
, long nX
, long nY
,
188 long nWidth
, long nHeight
)
190 basegfx::B2DRectangle aSVGRect
= rDrawRoot
.maRectangle
;
192 basegfx::B2DRange
aTargetSurface(nX
, nY
, nX
+ nWidth
+ 1, nY
+ nHeight
+ 1);
194 for (std::shared_ptr
<gfx::DrawBase
> const& pDrawBase
: rDrawRoot
.maChildren
)
196 switch (pDrawBase
->getType())
198 case gfx::DrawCommandType::Rectangle
:
200 auto const& rRectangle
= static_cast<gfx::DrawRectangle
const&>(*pDrawBase
);
202 basegfx::B2DRange
aInputRectangle(rRectangle
.maRectangle
);
204 double fDeltaX
= aTargetSurface
.getWidth() - aSVGRect
.getWidth();
205 double fDeltaY
= aTargetSurface
.getHeight() - aSVGRect
.getHeight();
207 basegfx::B2DRange
aFinalRectangle(
208 aInputRectangle
.getMinX(), aInputRectangle
.getMinY(),
209 aInputRectangle
.getMaxX() + fDeltaX
, aInputRectangle
.getMaxY() + fDeltaY
);
211 aFinalRectangle
.transform(basegfx::utils::createTranslateB2DHomMatrix(
212 aTargetSurface
.getMinX() - 0.5, aTargetSurface
.getMinY() - 0.5));
214 basegfx::B2DPolygon aB2DPolygon
= basegfx::utils::createPolygonFromRect(
215 aFinalRectangle
, rRectangle
.mnRx
/ aFinalRectangle
.getWidth() * 2.0,
216 rRectangle
.mnRy
/ aFinalRectangle
.getHeight() * 2.0);
218 if (rRectangle
.mpFillColor
)
220 rGraphics
.SetLineColor();
221 rGraphics
.SetFillColor(Color(*rRectangle
.mpFillColor
));
222 rGraphics
.DrawPolyPolygon(basegfx::B2DHomMatrix(),
223 basegfx::B2DPolyPolygon(aB2DPolygon
),
224 1.0 - rRectangle
.mnOpacity
, nullptr);
226 else if (rRectangle
.mpFillGradient
)
228 rGraphics
.SetLineColor();
229 rGraphics
.SetFillColor();
230 if (rRectangle
.mpFillGradient
->meType
== gfx::GradientType::Linear
)
232 auto* pLinearGradient
= static_cast<gfx::LinearGradientInfo
*>(
233 rRectangle
.mpFillGradient
.get());
234 SalGradient aGradient
;
237 x
= pLinearGradient
->x1
;
238 y
= pLinearGradient
->y1
;
240 if (x
> aSVGRect
.getCenterX())
242 if (y
> aSVGRect
.getCenterY())
245 aGradient
.maPoint1
= basegfx::B2DPoint(x
, y
);
246 aGradient
.maPoint1
*= basegfx::utils::createTranslateB2DHomMatrix(
247 aTargetSurface
.getMinX() - 0.5, aTargetSurface
.getMinY() - 0.5);
249 x
= pLinearGradient
->x2
;
250 y
= pLinearGradient
->y2
;
252 if (x
> aSVGRect
.getCenterX())
254 if (y
> aSVGRect
.getCenterY())
257 aGradient
.maPoint2
= basegfx::B2DPoint(x
, y
);
258 aGradient
.maPoint2
*= basegfx::utils::createTranslateB2DHomMatrix(
259 aTargetSurface
.getMinX() - 0.5, aTargetSurface
.getMinY() - 0.5);
261 for (gfx::GradientStop
const& rStop
: pLinearGradient
->maGradientStops
)
263 Color
aColor(rStop
.maColor
);
264 aColor
.SetTransparency(rStop
.mfOpacity
* (1.0f
- rRectangle
.mnOpacity
));
265 aGradient
.maStops
.emplace_back(aColor
, rStop
.mfOffset
);
267 rGraphics
.DrawGradient(basegfx::B2DPolyPolygon(aB2DPolygon
), aGradient
);
270 if (rRectangle
.mpStrokeColor
)
272 rGraphics
.SetLineColor(Color(*rRectangle
.mpStrokeColor
));
273 rGraphics
.SetFillColor();
274 rGraphics
.DrawPolyLine(
275 basegfx::B2DHomMatrix(), aB2DPolygon
, 1.0 - rRectangle
.mnOpacity
,
276 basegfx::B2DVector(rRectangle
.mnStrokeWidth
, rRectangle
.mnStrokeWidth
),
277 basegfx::B2DLineJoin::Round
, css::drawing::LineCap_ROUND
, 0.0f
, false,
282 case gfx::DrawCommandType::Path
:
284 auto const& rPath
= static_cast<gfx::DrawPath
const&>(*pDrawBase
);
286 double fDeltaX
= aTargetSurface
.getWidth() - aSVGRect
.getWidth();
287 double fDeltaY
= aTargetSurface
.getHeight() - aSVGRect
.getHeight();
289 basegfx::B2DPolyPolygon
aPolyPolygon(rPath
.maPolyPolygon
);
290 for (auto& rPolygon
: aPolyPolygon
)
292 for (size_t i
= 0; i
< rPolygon
.count(); ++i
)
294 auto& rPoint
= rPolygon
.getB2DPoint(i
);
295 double x
= rPoint
.getX();
296 double y
= rPoint
.getY();
298 if (x
> aSVGRect
.getCenterX())
300 if (y
> aSVGRect
.getCenterY())
302 rPolygon
.setB2DPoint(i
, basegfx::B2DPoint(x
, y
));
305 aPolyPolygon
.transform(basegfx::utils::createTranslateB2DHomMatrix(
306 aTargetSurface
.getMinX() - 0.5, aTargetSurface
.getMinY() - 0.5));
308 if (rPath
.mpFillColor
)
310 rGraphics
.SetLineColor();
311 rGraphics
.SetFillColor(Color(*rPath
.mpFillColor
));
312 rGraphics
.DrawPolyPolygon(basegfx::B2DHomMatrix(), aPolyPolygon
,
313 1.0 - rPath
.mnOpacity
, nullptr);
315 if (rPath
.mpStrokeColor
)
317 rGraphics
.SetLineColor(Color(*rPath
.mpStrokeColor
));
318 rGraphics
.SetFillColor();
319 for (auto const& rPolygon
: aPolyPolygon
)
321 rGraphics
.DrawPolyLine(
322 basegfx::B2DHomMatrix(), rPolygon
, 1.0 - rPath
.mnOpacity
,
323 basegfx::B2DVector(rPath
.mnStrokeWidth
, rPath
.mnStrokeWidth
),
324 basegfx::B2DLineJoin::Round
, css::drawing::LineCap_ROUND
, 0.0f
, false,
337 void munchDrawCommands(std::vector
<std::shared_ptr
<WidgetDrawAction
>> const& rDrawActions
,
338 SalGraphics
& rGraphics
, long nX
, long nY
, long nWidth
, long nHeight
)
340 for (std::shared_ptr
<WidgetDrawAction
> const& pDrawAction
: rDrawActions
)
342 switch (pDrawAction
->maType
)
344 case WidgetDrawActionType::RECTANGLE
:
346 auto const& rWidgetDraw
347 = static_cast<WidgetDrawActionRectangle
const&>(*pDrawAction
);
349 basegfx::B2DRectangle
rRect(
350 nX
+ (nWidth
* rWidgetDraw
.mfX1
), nY
+ (nHeight
* rWidgetDraw
.mfY1
),
351 nX
+ (nWidth
* rWidgetDraw
.mfX2
), nY
+ (nHeight
* rWidgetDraw
.mfY2
));
353 basegfx::B2DPolygon aB2DPolygon
= basegfx::utils::createPolygonFromRect(
354 rRect
, rWidgetDraw
.mnRx
/ rRect
.getWidth() * 2.0,
355 rWidgetDraw
.mnRy
/ rRect
.getHeight() * 2.0);
357 rGraphics
.SetLineColor();
358 rGraphics
.SetFillColor(rWidgetDraw
.maFillColor
);
359 rGraphics
.DrawPolyPolygon(basegfx::B2DHomMatrix(),
360 basegfx::B2DPolyPolygon(aB2DPolygon
), 0.0f
, nullptr);
361 rGraphics
.SetLineColor(rWidgetDraw
.maStrokeColor
);
362 rGraphics
.SetFillColor();
363 rGraphics
.DrawPolyLine(
364 basegfx::B2DHomMatrix(), aB2DPolygon
, 0.0f
,
365 basegfx::B2DVector(rWidgetDraw
.mnStrokeWidth
, rWidgetDraw
.mnStrokeWidth
),
366 basegfx::B2DLineJoin::Round
, css::drawing::LineCap_ROUND
, 0.0f
, false, nullptr);
369 case WidgetDrawActionType::LINE
:
371 auto const& rWidgetDraw
= static_cast<WidgetDrawActionLine
const&>(*pDrawAction
);
372 Point
aRectPoint(nX
+ 1, nY
+ 1);
374 Size
aRectSize(nWidth
- 1, nHeight
- 1);
376 rGraphics
.SetFillColor();
377 rGraphics
.SetLineColor(rWidgetDraw
.maStrokeColor
);
379 basegfx::B2DPolygon aB2DPolygon
{
380 { aRectPoint
.X() + (aRectSize
.Width() * rWidgetDraw
.mfX1
),
381 aRectPoint
.Y() + (aRectSize
.Height() * rWidgetDraw
.mfY1
) },
382 { aRectPoint
.X() + (aRectSize
.Width() * rWidgetDraw
.mfX2
),
383 aRectPoint
.Y() + (aRectSize
.Height() * rWidgetDraw
.mfY2
) },
386 rGraphics
.DrawPolyLine(
387 basegfx::B2DHomMatrix(), aB2DPolygon
, 0.0f
,
388 basegfx::B2DVector(rWidgetDraw
.mnStrokeWidth
, rWidgetDraw
.mnStrokeWidth
),
389 basegfx::B2DLineJoin::Round
, css::drawing::LineCap_ROUND
, 0.0f
, false, nullptr);
392 case WidgetDrawActionType::IMAGE
:
394 double nScaleFactor
= 1.0;
395 if (comphelper::LibreOfficeKit::isActive())
396 nScaleFactor
= comphelper::LibreOfficeKit::getDPIScale();
398 auto const& rWidgetDraw
= static_cast<WidgetDrawActionImage
const&>(*pDrawAction
);
399 auto& rCacheImages
= ImplGetSVData()->maGDIData
.maThemeImageCache
;
400 OUString rCacheKey
= rWidgetDraw
.msSource
+ "@" + OUString::number(nScaleFactor
);
401 auto aIterator
= rCacheImages
.find(rCacheKey
);
404 if (aIterator
== rCacheImages
.end())
406 SvFileStream
aFileStream(rWidgetDraw
.msSource
, StreamMode::READ
);
408 vcl::bitmap::loadFromSvg(aFileStream
, "", aBitmap
, nScaleFactor
);
411 rCacheImages
.insert(std::make_pair(rCacheKey
, aBitmap
));
416 aBitmap
= aIterator
->second
;
419 long nImageWidth
= aBitmap
.GetSizePixel().Width();
420 long nImageHeight
= aBitmap
.GetSizePixel().Height();
421 SalTwoRect
aTR(0, 0, nImageWidth
, nImageHeight
, nX
, nY
, nImageWidth
/ nScaleFactor
,
422 nImageHeight
/ nScaleFactor
);
425 const std::shared_ptr
<SalBitmap
> pSalBitmap
426 = aBitmap
.GetBitmap().ImplGetSalBitmap();
427 if (aBitmap
.IsAlpha())
429 const std::shared_ptr
<SalBitmap
> pSalBitmapAlpha
430 = aBitmap
.GetAlpha().ImplGetSalBitmap();
431 rGraphics
.DrawBitmap(aTR
, *pSalBitmap
, *pSalBitmapAlpha
, nullptr);
435 rGraphics
.DrawBitmap(aTR
, *pSalBitmap
, nullptr);
440 case WidgetDrawActionType::EXTERNAL
:
442 auto const& rWidgetDraw
443 = static_cast<WidgetDrawActionExternal
const&>(*pDrawAction
);
445 auto& rCacheDrawCommands
= ImplGetSVData()->maGDIData
.maThemeDrawCommandsCache
;
447 auto aIterator
= rCacheDrawCommands
.find(rWidgetDraw
.msSource
);
449 gfx::DrawRoot aDrawRoot
;
451 if (aIterator
== rCacheDrawCommands
.end())
453 SvFileStream
aFileStream(rWidgetDraw
.msSource
, StreamMode::READ
);
455 uno::Reference
<uno::XComponentContext
> xContext(
456 comphelper::getProcessComponentContext());
457 const uno::Reference
<graphic::XSvgParser
> xSvgParser
458 = graphic::SvgTools::create(xContext
);
460 std::size_t nSize
= aFileStream
.remainingSize();
461 std::vector
<sal_Int8
> aBuffer(nSize
+ 1);
462 aFileStream
.ReadBytes(aBuffer
.data(), nSize
);
465 uno::Sequence
<sal_Int8
> aData(aBuffer
.data(), nSize
+ 1);
466 uno::Reference
<io::XInputStream
> aInputStream(
467 new comphelper::SequenceInputStream(aData
));
469 uno::Any aAny
= xSvgParser
->getDrawCommands(aInputStream
, "");
470 if (aAny
.has
<sal_uInt64
>())
472 auto* pDrawRoot
= reinterpret_cast<gfx::DrawRoot
*>(aAny
.get
<sal_uInt64
>());
475 rCacheDrawCommands
.insert(
476 std::make_pair(rWidgetDraw
.msSource
, *pDrawRoot
));
477 drawFromDrawCommands(*pDrawRoot
, rGraphics
, nX
, nY
, nWidth
, nHeight
);
483 drawFromDrawCommands(aIterator
->second
, rGraphics
, nX
, nY
, nWidth
, nHeight
);
491 } // end anonymous namespace
493 bool FileDefinitionWidgetDraw::resolveDefinition(ControlType eType
, ControlPart ePart
,
495 const ImplControlValue
& rValue
, long nX
, long nY
,
496 long nWidth
, long nHeight
)
499 auto const& pPart
= m_pWidgetDefinition
->getDefinition(eType
, ePart
);
502 auto const& aStates
= pPart
->getStates(eType
, ePart
, eState
, rValue
);
503 if (!aStates
.empty())
505 // use last defined state
506 auto const& pState
= aStates
.back();
508 munchDrawCommands(pState
->mpWidgetDrawActions
, m_rGraphics
, nX
, nY
, nWidth
,
517 bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType
, ControlPart ePart
,
518 const tools::Rectangle
& rControlRegion
,
520 const ImplControlValue
& rValue
,
521 const OUString
& /*aCaptions*/)
523 bool bOldAA
= m_rGraphics
.getAntiAliasB2DDraw();
524 m_rGraphics
.setAntiAliasB2DDraw(true);
526 long nWidth
= rControlRegion
.GetWidth() - 1;
527 long nHeight
= rControlRegion
.GetHeight() - 1;
528 long nX
= rControlRegion
.Left();
529 long nY
= rControlRegion
.Top();
535 case ControlType::Pushbutton
:
537 /*bool bIsAction = false;
538 const PushButtonValue* pPushButtonValue = static_cast<const PushButtonValue*>(&rValue);
539 if (pPushButtonValue)
540 bIsAction = pPushButtonValue->mbIsAction;*/
542 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
545 case ControlType::Radiobutton
:
547 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
550 case ControlType::Checkbox
:
552 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
555 case ControlType::Combobox
:
557 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
560 case ControlType::Editbox
:
561 case ControlType::EditboxNoBorder
:
562 case ControlType::MultilineEditbox
:
564 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
567 case ControlType::Listbox
:
569 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
572 case ControlType::Spinbox
:
574 if (rValue
.getType() == ControlType::SpinButtons
)
576 const SpinbuttonValue
* pSpinVal
= static_cast<const SpinbuttonValue
*>(&rValue
);
579 ControlPart eUpButtonPart
= pSpinVal
->mnUpperPart
;
580 ControlState eUpButtonState
= pSpinVal
->mnUpperState
;
582 long nUpperX
= pSpinVal
->maUpperRect
.Left();
583 long nUpperY
= pSpinVal
->maUpperRect
.Top();
584 long nUpperWidth
= pSpinVal
->maUpperRect
.GetWidth() - 1;
585 long nUpperHeight
= pSpinVal
->maUpperRect
.GetHeight() - 1;
587 bOK
= resolveDefinition(eType
, eUpButtonPart
, eUpButtonState
,
588 ImplControlValue(), nUpperX
, nUpperY
, nUpperWidth
,
594 ControlPart eDownButtonPart
= pSpinVal
->mnLowerPart
;
595 ControlState eDownButtonState
= pSpinVal
->mnLowerState
;
597 long nLowerX
= pSpinVal
->maLowerRect
.Left();
598 long nLowerY
= pSpinVal
->maLowerRect
.Top();
599 long nLowerWidth
= pSpinVal
->maLowerRect
.GetWidth() - 1;
600 long nLowerHeight
= pSpinVal
->maLowerRect
.GetHeight() - 1;
602 bOK
= resolveDefinition(eType
, eDownButtonPart
, eDownButtonState
,
603 ImplControlValue(), nLowerX
, nLowerY
, nLowerWidth
,
609 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
613 case ControlType::SpinButtons
:
615 case ControlType::TabItem
:
616 case ControlType::TabHeader
:
617 case ControlType::TabPane
:
618 case ControlType::TabBody
:
620 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
623 case ControlType::Scrollbar
:
625 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
628 case ControlType::Slider
:
630 const SliderValue
* pSliderValue
= static_cast<const SliderValue
*>(&rValue
);
631 long nThumbX
= pSliderValue
->maThumbRect
.Left();
632 long nThumbY
= pSliderValue
->maThumbRect
.Top();
633 long nThumbWidth
= pSliderValue
->maThumbRect
.GetWidth() - 1;
634 long nThumbHeight
= pSliderValue
->maThumbRect
.GetHeight() - 1;
636 if (ePart
== ControlPart::TrackHorzArea
)
638 long nCenterX
= nThumbX
+ nThumbWidth
/ 2;
640 bOK
= resolveDefinition(eType
, ControlPart::TrackHorzLeft
, eState
, rValue
, nX
, nY
,
641 nCenterX
- nX
, nHeight
);
643 bOK
= resolveDefinition(eType
, ControlPart::TrackHorzRight
, eState
, rValue
,
644 nCenterX
, nY
, nX
+ nWidth
- nCenterX
, nHeight
);
646 else if (ePart
== ControlPart::TrackVertArea
)
648 long nCenterY
= nThumbY
+ nThumbHeight
/ 2;
650 bOK
= resolveDefinition(eType
, ControlPart::TrackVertUpper
, eState
, rValue
, nX
, nY
,
651 nWidth
, nCenterY
- nY
);
653 bOK
= resolveDefinition(eType
, ControlPart::TrackVertLower
, eState
, rValue
, nY
,
654 nCenterY
, nWidth
, nY
+ nHeight
- nCenterY
);
659 bOK
= resolveDefinition(eType
, ControlPart::Button
,
660 eState
| pSliderValue
->mnThumbState
, rValue
, nThumbX
,
661 nThumbY
, nThumbWidth
, nThumbHeight
);
665 case ControlType::Fixedline
:
667 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
670 case ControlType::Toolbar
:
672 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
675 case ControlType::Menubar
:
676 case ControlType::MenuPopup
:
678 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
681 case ControlType::Progress
:
683 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
686 case ControlType::IntroProgress
:
688 case ControlType::Tooltip
:
690 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
693 case ControlType::WindowBackground
:
694 case ControlType::Frame
:
696 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
699 case ControlType::ListNode
:
700 case ControlType::ListNet
:
701 case ControlType::ListHeader
:
703 bOK
= resolveDefinition(eType
, ePart
, eState
, rValue
, nX
, nY
, nWidth
, nHeight
);
710 m_rGraphics
.setAntiAliasB2DDraw(bOldAA
);
715 bool FileDefinitionWidgetDraw::getNativeControlRegion(
716 ControlType eType
, ControlPart ePart
, const tools::Rectangle
& rBoundingControlRegion
,
717 ControlState
/*eState*/, const ImplControlValue
& /*aValue*/, const OUString
& /*aCaption*/,
718 tools::Rectangle
& rNativeBoundingRegion
, tools::Rectangle
& rNativeContentRegion
)
720 Point
aLocation(rBoundingControlRegion
.TopLeft());
724 case ControlType::Spinbox
:
726 auto const& pButtonUpPart
727 = m_pWidgetDefinition
->getDefinition(eType
, ControlPart::ButtonUp
);
730 Size
aButtonSizeUp(pButtonUpPart
->mnWidth
, pButtonUpPart
->mnHeight
);
732 auto const& pButtonDownPart
733 = m_pWidgetDefinition
->getDefinition(eType
, ControlPart::ButtonDown
);
734 if (!pButtonDownPart
)
736 Size
aButtonSizeDown(pButtonDownPart
->mnWidth
, pButtonDownPart
->mnHeight
);
738 auto const& pEntirePart
739 = m_pWidgetDefinition
->getDefinition(eType
, ControlPart::Entire
);
740 OString sOrientation
= pEntirePart
->msOrientation
;
742 if (sOrientation
.isEmpty() || sOrientation
== "decrease-edit-increase")
744 if (ePart
== ControlPart::ButtonUp
)
746 Point
aPoint(aLocation
.X() + rBoundingControlRegion
.GetWidth()
747 - aButtonSizeUp
.Width(),
749 rNativeContentRegion
= tools::Rectangle(aPoint
, aButtonSizeUp
);
750 rNativeBoundingRegion
= rNativeContentRegion
;
753 else if (ePart
== ControlPart::ButtonDown
)
755 rNativeContentRegion
= tools::Rectangle(aLocation
, aButtonSizeDown
);
756 rNativeBoundingRegion
= rNativeContentRegion
;
759 else if (ePart
== ControlPart::SubEdit
)
761 Point
aPoint(aLocation
.X() + aButtonSizeDown
.Width(), aLocation
.Y());
762 Size
aSize(rBoundingControlRegion
.GetWidth()
763 - (aButtonSizeDown
.Width() + aButtonSizeUp
.Width()),
764 std::max(aButtonSizeUp
.Height(), aButtonSizeDown
.Height()));
765 rNativeContentRegion
= tools::Rectangle(aPoint
, aSize
);
766 rNativeBoundingRegion
= rNativeContentRegion
;
769 else if (ePart
== ControlPart::Entire
)
771 Size
aSize(rBoundingControlRegion
.GetWidth(),
772 std::max(aButtonSizeUp
.Height(), aButtonSizeDown
.Height()));
773 rNativeContentRegion
= tools::Rectangle(aLocation
, aSize
);
774 rNativeBoundingRegion
= rNativeContentRegion
;
778 else if (sOrientation
== "edit-decrease-increase")
780 if (ePart
== ControlPart::ButtonUp
)
782 Point
aPoint(aLocation
.X() + rBoundingControlRegion
.GetWidth()
783 - aButtonSizeUp
.Width(),
785 rNativeContentRegion
= tools::Rectangle(aPoint
, aButtonSizeUp
);
786 rNativeBoundingRegion
= rNativeContentRegion
;
789 else if (ePart
== ControlPart::ButtonDown
)
791 Point
aPoint(aLocation
.X() + rBoundingControlRegion
.GetWidth()
792 - (aButtonSizeDown
.Width() + aButtonSizeUp
.Width()),
794 rNativeContentRegion
= tools::Rectangle(aPoint
, aButtonSizeDown
);
795 rNativeBoundingRegion
= rNativeContentRegion
;
798 else if (ePart
== ControlPart::SubEdit
)
800 Size
aSize(rBoundingControlRegion
.GetWidth()
801 - (aButtonSizeDown
.Width() + aButtonSizeUp
.Width()),
802 std::max(aButtonSizeUp
.Height(), aButtonSizeDown
.Height()));
803 rNativeContentRegion
= tools::Rectangle(aLocation
, aSize
);
804 rNativeBoundingRegion
= rNativeContentRegion
;
807 else if (ePart
== ControlPart::Entire
)
809 Size
aSize(rBoundingControlRegion
.GetWidth(),
810 std::max(aButtonSizeUp
.Height(), aButtonSizeDown
.Height()));
811 rNativeContentRegion
= tools::Rectangle(aLocation
, aSize
);
812 rNativeBoundingRegion
= rNativeContentRegion
;
818 case ControlType::Checkbox
:
820 auto const& pPart
= m_pWidgetDefinition
->getDefinition(eType
, ControlPart::Entire
);
824 Size
aSize(pPart
->mnWidth
, pPart
->mnHeight
);
825 rNativeContentRegion
= tools::Rectangle(Point(), aSize
);
828 case ControlType::Radiobutton
:
830 auto const& pPart
= m_pWidgetDefinition
->getDefinition(eType
, ControlPart::Entire
);
834 Size
aSize(pPart
->mnWidth
, pPart
->mnHeight
);
835 rNativeContentRegion
= tools::Rectangle(Point(), aSize
);
838 case ControlType::TabItem
:
840 auto const& pPart
= m_pWidgetDefinition
->getDefinition(eType
, ControlPart::Entire
);
844 long nWidth
= std::max(rBoundingControlRegion
.GetWidth() + pPart
->mnMarginWidth
,
845 long(pPart
->mnWidth
));
846 long nHeight
= std::max(rBoundingControlRegion
.GetHeight() + pPart
->mnMarginHeight
,
847 long(pPart
->mnHeight
));
849 rNativeBoundingRegion
= tools::Rectangle(aLocation
, Size(nWidth
, nHeight
));
850 rNativeContentRegion
= rNativeBoundingRegion
;
853 case ControlType::Editbox
:
854 case ControlType::EditboxNoBorder
:
855 case ControlType::MultilineEditbox
:
857 sal_Int32 nHeight
= rBoundingControlRegion
.GetHeight();
859 auto const& pPart
= m_pWidgetDefinition
->getDefinition(eType
, ControlPart::Entire
);
861 nHeight
= std::max(nHeight
, pPart
->mnHeight
);
863 Size
aSize(rBoundingControlRegion
.GetWidth(), nHeight
);
864 rNativeContentRegion
= tools::Rectangle(aLocation
, aSize
);
865 rNativeBoundingRegion
= rNativeContentRegion
;
866 rNativeBoundingRegion
.expand(2);
870 case ControlType::Scrollbar
:
872 if (ePart
== ControlPart::ButtonUp
|| ePart
== ControlPart::ButtonDown
873 || ePart
== ControlPart::ButtonLeft
|| ePart
== ControlPart::ButtonRight
)
875 rNativeContentRegion
= tools::Rectangle(aLocation
, Size(0, 0));
876 rNativeBoundingRegion
= rNativeContentRegion
;
881 rNativeBoundingRegion
= rBoundingControlRegion
;
882 rNativeContentRegion
= rNativeBoundingRegion
;
887 case ControlType::Combobox
:
888 case ControlType::Listbox
:
890 auto const& pPart
= m_pWidgetDefinition
->getDefinition(eType
, ControlPart::ButtonDown
);
891 Size
aComboButtonSize(pPart
->mnWidth
, pPart
->mnHeight
);
893 if (ePart
== ControlPart::ButtonDown
)
895 Point
aPoint(aLocation
.X() + rBoundingControlRegion
.GetWidth()
896 - aComboButtonSize
.Width(),
898 rNativeContentRegion
= tools::Rectangle(aPoint
, aComboButtonSize
);
899 rNativeBoundingRegion
= rNativeContentRegion
;
902 else if (ePart
== ControlPart::SubEdit
)
904 Size
aSize(rBoundingControlRegion
.GetWidth() - aComboButtonSize
.Width(),
905 aComboButtonSize
.Height());
906 rNativeContentRegion
= tools::Rectangle(aLocation
+ Point(1, 1), aSize
);
907 rNativeBoundingRegion
= rNativeContentRegion
;
910 else if (ePart
== ControlPart::Entire
)
912 Size
aSize(rBoundingControlRegion
.GetWidth(), aComboButtonSize
.Height());
913 rNativeContentRegion
= tools::Rectangle(aLocation
, aSize
);
914 rNativeBoundingRegion
= rNativeContentRegion
;
915 rNativeBoundingRegion
.expand(1);
920 case ControlType::Slider
:
921 if (ePart
== ControlPart::ThumbHorz
|| ePart
== ControlPart::ThumbVert
)
923 rNativeContentRegion
= tools::Rectangle(aLocation
, Size(28, 28));
924 rNativeBoundingRegion
= rNativeContentRegion
;
935 bool FileDefinitionWidgetDraw::updateSettings(AllSettings
& rSettings
)
937 StyleSettings aStyleSet
= rSettings
.GetStyleSettings();
939 auto pDefinitionStyle
= m_pWidgetDefinition
->mpStyle
;
941 aStyleSet
.SetFaceColor(pDefinitionStyle
->maFaceColor
);
942 aStyleSet
.SetCheckedColor(pDefinitionStyle
->maCheckedColor
);
943 aStyleSet
.SetLightColor(pDefinitionStyle
->maLightColor
);
944 aStyleSet
.SetLightBorderColor(pDefinitionStyle
->maLightBorderColor
);
945 aStyleSet
.SetShadowColor(pDefinitionStyle
->maShadowColor
);
946 aStyleSet
.SetDarkShadowColor(pDefinitionStyle
->maDarkShadowColor
);
947 aStyleSet
.SetButtonTextColor(pDefinitionStyle
->maButtonTextColor
);
948 aStyleSet
.SetDefaultActionButtonTextColor(pDefinitionStyle
->maDefaultActionButtonTextColor
);
949 aStyleSet
.SetActionButtonTextColor(pDefinitionStyle
->maActionButtonTextColor
);
950 aStyleSet
.SetActionButtonRolloverTextColor(pDefinitionStyle
->maActionButtonRolloverTextColor
);
951 aStyleSet
.SetButtonRolloverTextColor(pDefinitionStyle
->maButtonRolloverTextColor
);
952 aStyleSet
.SetRadioCheckTextColor(pDefinitionStyle
->maRadioCheckTextColor
);
953 aStyleSet
.SetGroupTextColor(pDefinitionStyle
->maGroupTextColor
);
954 aStyleSet
.SetLabelTextColor(pDefinitionStyle
->maLabelTextColor
);
955 aStyleSet
.SetWindowColor(pDefinitionStyle
->maWindowColor
);
956 aStyleSet
.SetWindowTextColor(pDefinitionStyle
->maWindowTextColor
);
957 aStyleSet
.SetDialogColor(pDefinitionStyle
->maDialogColor
);
958 aStyleSet
.SetDialogTextColor(pDefinitionStyle
->maDialogTextColor
);
959 aStyleSet
.SetWorkspaceColor(pDefinitionStyle
->maWorkspaceColor
);
960 aStyleSet
.SetMonoColor(pDefinitionStyle
->maMonoColor
);
961 aStyleSet
.SetFieldColor(pDefinitionStyle
->maFieldColor
);
962 aStyleSet
.SetFieldTextColor(pDefinitionStyle
->maFieldTextColor
);
963 aStyleSet
.SetFieldRolloverTextColor(pDefinitionStyle
->maFieldRolloverTextColor
);
964 aStyleSet
.SetActiveColor(pDefinitionStyle
->maActiveColor
);
965 aStyleSet
.SetActiveTextColor(pDefinitionStyle
->maActiveTextColor
);
966 aStyleSet
.SetActiveBorderColor(pDefinitionStyle
->maActiveBorderColor
);
967 aStyleSet
.SetDeactiveColor(pDefinitionStyle
->maDeactiveColor
);
968 aStyleSet
.SetDeactiveTextColor(pDefinitionStyle
->maDeactiveTextColor
);
969 aStyleSet
.SetDeactiveBorderColor(pDefinitionStyle
->maDeactiveBorderColor
);
970 aStyleSet
.SetMenuColor(pDefinitionStyle
->maMenuColor
);
971 aStyleSet
.SetMenuBarColor(pDefinitionStyle
->maMenuBarColor
);
972 aStyleSet
.SetMenuBarRolloverColor(pDefinitionStyle
->maMenuBarRolloverColor
);
973 aStyleSet
.SetMenuBorderColor(pDefinitionStyle
->maMenuBorderColor
);
974 aStyleSet
.SetMenuTextColor(pDefinitionStyle
->maMenuTextColor
);
975 aStyleSet
.SetMenuBarTextColor(pDefinitionStyle
->maMenuBarTextColor
);
976 aStyleSet
.SetMenuBarRolloverTextColor(pDefinitionStyle
->maMenuBarRolloverTextColor
);
977 aStyleSet
.SetMenuBarHighlightTextColor(pDefinitionStyle
->maMenuBarHighlightTextColor
);
978 aStyleSet
.SetMenuHighlightColor(pDefinitionStyle
->maMenuHighlightColor
);
979 aStyleSet
.SetMenuHighlightTextColor(pDefinitionStyle
->maMenuHighlightTextColor
);
980 aStyleSet
.SetHighlightColor(pDefinitionStyle
->maHighlightColor
);
981 aStyleSet
.SetHighlightTextColor(pDefinitionStyle
->maHighlightTextColor
);
982 aStyleSet
.SetActiveTabColor(pDefinitionStyle
->maActiveTabColor
);
983 aStyleSet
.SetInactiveTabColor(pDefinitionStyle
->maInactiveTabColor
);
984 aStyleSet
.SetTabTextColor(pDefinitionStyle
->maTabTextColor
);
985 aStyleSet
.SetTabRolloverTextColor(pDefinitionStyle
->maTabRolloverTextColor
);
986 aStyleSet
.SetTabHighlightTextColor(pDefinitionStyle
->maTabHighlightTextColor
);
987 aStyleSet
.SetDisableColor(pDefinitionStyle
->maDisableColor
);
988 aStyleSet
.SetHelpColor(pDefinitionStyle
->maHelpColor
);
989 aStyleSet
.SetHelpTextColor(pDefinitionStyle
->maHelpTextColor
);
990 aStyleSet
.SetLinkColor(pDefinitionStyle
->maLinkColor
);
991 aStyleSet
.SetVisitedLinkColor(pDefinitionStyle
->maVisitedLinkColor
);
992 aStyleSet
.SetToolTextColor(pDefinitionStyle
->maToolTextColor
);
993 aStyleSet
.SetFontColor(pDefinitionStyle
->maFontColor
);
995 vcl::Font
aFont(FAMILY_SWISS
, Size(0, 10));
996 aFont
.SetCharSet(osl_getThreadTextEncoding());
997 aFont
.SetWeight(WEIGHT_NORMAL
);
998 aFont
.SetFamilyName("Liberation Sans");
999 aStyleSet
.SetAppFont(aFont
);
1000 aStyleSet
.SetHelpFont(aFont
);
1001 aStyleSet
.SetMenuFont(aFont
);
1002 aStyleSet
.SetToolFont(aFont
);
1003 aStyleSet
.SetGroupFont(aFont
);
1004 aStyleSet
.SetLabelFont(aFont
);
1005 aStyleSet
.SetRadioCheckFont(aFont
);
1006 aStyleSet
.SetPushButtonFont(aFont
);
1007 aStyleSet
.SetFieldFont(aFont
);
1008 aStyleSet
.SetIconFont(aFont
);
1009 aStyleSet
.SetTabFont(aFont
);
1011 aFont
.SetWeight(WEIGHT_BOLD
);
1012 aStyleSet
.SetFloatTitleFont(aFont
);
1013 aStyleSet
.SetTitleFont(aFont
);
1015 aStyleSet
.SetTitleHeight(16);
1016 aStyleSet
.SetFloatTitleHeight(12);
1017 aStyleSet
.SetListBoxPreviewDefaultLogicSize(Size(16, 16));
1019 rSettings
.SetStyleSettings(aStyleSet
);
1024 } // end vcl namespace
1026 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */