bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / gdi / FileDefinitionWidgetDraw.cxx
blob0eb0484d4cbe9bce6ddbd96fd64c3d3a5a37178f
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 <FileDefinitionWidgetDraw.hxx>
12 #include <widgetdraw/WidgetDefinitionReader.hxx>
14 #include <sal/config.h>
15 #include <svdata.hxx>
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>
37 using namespace css;
39 namespace vcl
41 namespace
43 OUString lcl_getThemeDefinitionPath()
45 OUString sPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/theme_definitions/");
46 rtl::Bootstrap::expandMacros(sPath);
47 return 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;
77 if (!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);
85 return spDefinition;
88 } // end anonymous namespace
90 FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics& rGraphics)
91 : m_rGraphics(rGraphics)
92 , m_bIsActive(false)
94 if (comphelper::LibreOfficeKit::isActive())
95 m_pWidgetDefinition = getWidgetDefinitionForTheme("online");
96 #ifdef IOS
97 if (!m_pWidgetDefinition)
98 m_pWidgetDefinition = getWidgetDefinitionForTheme("ios");
99 #endif
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;
113 m_bIsActive = true;
117 bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType, ControlPart ePart)
119 switch (eType)
121 case ControlType::Generic:
122 case ControlType::Pushbutton:
123 case ControlType::Radiobutton:
124 case ControlType::Checkbox:
125 return true;
126 case ControlType::Combobox:
127 if (ePart == ControlPart::HasBackgroundTexture)
128 return false;
129 return true;
130 case ControlType::Editbox:
131 case ControlType::EditboxNoBorder:
132 case ControlType::MultilineEditbox:
133 return true;
134 case ControlType::Listbox:
135 if (ePart == ControlPart::HasBackgroundTexture)
136 return false;
137 return true;
138 case ControlType::Spinbox:
139 if (ePart == ControlPart::AllButtons)
140 return false;
141 return true;
142 case ControlType::SpinButtons:
143 return false;
144 case ControlType::TabItem:
145 case ControlType::TabPane:
146 case ControlType::TabHeader:
147 case ControlType::TabBody:
148 return true;
149 case ControlType::Scrollbar:
150 if (ePart == ControlPart::DrawBackgroundHorz
151 || ePart == ControlPart::DrawBackgroundVert)
152 return false;
153 return true;
154 case ControlType::Slider:
155 case ControlType::Fixedline:
156 case ControlType::Toolbar:
157 return true;
158 case ControlType::Menubar:
159 case ControlType::MenuPopup:
160 return true;
161 case ControlType::Progress:
162 return true;
163 case ControlType::IntroProgress:
164 return false;
165 case ControlType::Tooltip:
166 return true;
167 case ControlType::WindowBackground:
168 case ControlType::Frame:
169 case ControlType::ListNode:
170 case ControlType::ListNet:
171 case ControlType::ListHeader:
172 return true;
175 return false;
178 bool FileDefinitionWidgetDraw::hitTestNativeControl(
179 ControlType /*eType*/, ControlPart /*ePart*/,
180 const tools::Rectangle& /*rBoundingControlRegion*/, const Point& /*aPos*/, bool& /*rIsInside*/)
182 return false;
185 namespace
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;
235 double x, y;
237 x = pLinearGradient->x1;
238 y = pLinearGradient->y1;
240 if (x > aSVGRect.getCenterX())
241 x = x + fDeltaX;
242 if (y > aSVGRect.getCenterY())
243 y = y + fDeltaY;
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())
253 x = x + fDeltaX;
254 if (y > aSVGRect.getCenterY())
255 y = y + fDeltaY;
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,
278 nullptr);
281 break;
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())
299 x = x + fDeltaX;
300 if (y > aSVGRect.getCenterY())
301 y = y + fDeltaY;
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,
325 nullptr);
329 break;
331 default:
332 break;
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);
368 break;
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);
391 break;
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);
403 BitmapEx aBitmap;
404 if (aIterator == rCacheImages.end())
406 SvFileStream aFileStream(rWidgetDraw.msSource, StreamMode::READ);
408 vcl::bitmap::loadFromSvg(aFileStream, "", aBitmap, nScaleFactor);
409 if (!!aBitmap)
411 rCacheImages.insert(std::make_pair(rCacheKey, aBitmap));
414 else
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);
423 if (!!aBitmap)
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);
433 else
435 rGraphics.DrawBitmap(aTR, *pSalBitmap, nullptr);
439 break;
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);
463 aBuffer[nSize] = 0;
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>());
473 if (pDrawRoot)
475 rCacheDrawCommands.insert(
476 std::make_pair(rWidgetDraw.msSource, *pDrawRoot));
477 drawFromDrawCommands(*pDrawRoot, rGraphics, nX, nY, nWidth, nHeight);
481 else
483 drawFromDrawCommands(aIterator->second, rGraphics, nX, nY, nWidth, nHeight);
486 break;
491 } // end anonymous namespace
493 bool FileDefinitionWidgetDraw::resolveDefinition(ControlType eType, ControlPart ePart,
494 ControlState eState,
495 const ImplControlValue& rValue, long nX, long nY,
496 long nWidth, long nHeight)
498 bool bOK = false;
499 auto const& pPart = m_pWidgetDefinition->getDefinition(eType, ePart);
500 if (pPart)
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,
509 nHeight);
510 bOK = true;
514 return bOK;
517 bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart ePart,
518 const tools::Rectangle& rControlRegion,
519 ControlState eState,
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();
531 bool bOK = false;
533 switch (eType)
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);
544 break;
545 case ControlType::Radiobutton:
547 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
549 break;
550 case ControlType::Checkbox:
552 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
554 break;
555 case ControlType::Combobox:
557 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
559 break;
560 case ControlType::Editbox:
561 case ControlType::EditboxNoBorder:
562 case ControlType::MultilineEditbox:
564 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
566 break;
567 case ControlType::Listbox:
569 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
571 break;
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,
589 nUpperHeight);
592 if (bOK)
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,
604 nLowerHeight);
607 else
609 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
612 break;
613 case ControlType::SpinButtons:
614 break;
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);
622 break;
623 case ControlType::Scrollbar:
625 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
627 break;
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);
642 if (bOK)
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);
652 if (bOK)
653 bOK = resolveDefinition(eType, ControlPart::TrackVertLower, eState, rValue, nY,
654 nCenterY, nWidth, nY + nHeight - nCenterY);
657 if (bOK)
659 bOK = resolveDefinition(eType, ControlPart::Button,
660 eState | pSliderValue->mnThumbState, rValue, nThumbX,
661 nThumbY, nThumbWidth, nThumbHeight);
664 break;
665 case ControlType::Fixedline:
667 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
669 break;
670 case ControlType::Toolbar:
672 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
674 break;
675 case ControlType::Menubar:
676 case ControlType::MenuPopup:
678 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
680 break;
681 case ControlType::Progress:
683 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
685 break;
686 case ControlType::IntroProgress:
687 break;
688 case ControlType::Tooltip:
690 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
692 break;
693 case ControlType::WindowBackground:
694 case ControlType::Frame:
696 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
698 break;
699 case ControlType::ListNode:
700 case ControlType::ListNet:
701 case ControlType::ListHeader:
703 bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
705 break;
706 default:
707 break;
710 m_rGraphics.setAntiAliasB2DDraw(bOldAA);
712 return bOK;
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());
722 switch (eType)
724 case ControlType::Spinbox:
726 auto const& pButtonUpPart
727 = m_pWidgetDefinition->getDefinition(eType, ControlPart::ButtonUp);
728 if (!pButtonUpPart)
729 return false;
730 Size aButtonSizeUp(pButtonUpPart->mnWidth, pButtonUpPart->mnHeight);
732 auto const& pButtonDownPart
733 = m_pWidgetDefinition->getDefinition(eType, ControlPart::ButtonDown);
734 if (!pButtonDownPart)
735 return false;
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(),
748 aLocation.Y());
749 rNativeContentRegion = tools::Rectangle(aPoint, aButtonSizeUp);
750 rNativeBoundingRegion = rNativeContentRegion;
751 return true;
753 else if (ePart == ControlPart::ButtonDown)
755 rNativeContentRegion = tools::Rectangle(aLocation, aButtonSizeDown);
756 rNativeBoundingRegion = rNativeContentRegion;
757 return true;
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;
767 return true;
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;
775 return true;
778 else if (sOrientation == "edit-decrease-increase")
780 if (ePart == ControlPart::ButtonUp)
782 Point aPoint(aLocation.X() + rBoundingControlRegion.GetWidth()
783 - aButtonSizeUp.Width(),
784 aLocation.Y());
785 rNativeContentRegion = tools::Rectangle(aPoint, aButtonSizeUp);
786 rNativeBoundingRegion = rNativeContentRegion;
787 return true;
789 else if (ePart == ControlPart::ButtonDown)
791 Point aPoint(aLocation.X() + rBoundingControlRegion.GetWidth()
792 - (aButtonSizeDown.Width() + aButtonSizeUp.Width()),
793 aLocation.Y());
794 rNativeContentRegion = tools::Rectangle(aPoint, aButtonSizeDown);
795 rNativeBoundingRegion = rNativeContentRegion;
796 return true;
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;
805 return true;
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;
813 return true;
817 break;
818 case ControlType::Checkbox:
820 auto const& pPart = m_pWidgetDefinition->getDefinition(eType, ControlPart::Entire);
821 if (!pPart)
822 return false;
824 Size aSize(pPart->mnWidth, pPart->mnHeight);
825 rNativeContentRegion = tools::Rectangle(Point(), aSize);
826 return true;
828 case ControlType::Radiobutton:
830 auto const& pPart = m_pWidgetDefinition->getDefinition(eType, ControlPart::Entire);
831 if (!pPart)
832 return false;
834 Size aSize(pPart->mnWidth, pPart->mnHeight);
835 rNativeContentRegion = tools::Rectangle(Point(), aSize);
836 return true;
838 case ControlType::TabItem:
840 auto const& pPart = m_pWidgetDefinition->getDefinition(eType, ControlPart::Entire);
841 if (!pPart)
842 return false;
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;
851 return true;
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);
860 if (pPart)
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);
867 return true;
869 break;
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;
877 return true;
879 else
881 rNativeBoundingRegion = rBoundingControlRegion;
882 rNativeContentRegion = rNativeBoundingRegion;
883 return true;
886 break;
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(),
897 aLocation.Y() + 1);
898 rNativeContentRegion = tools::Rectangle(aPoint, aComboButtonSize);
899 rNativeBoundingRegion = rNativeContentRegion;
900 return true;
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;
908 return true;
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);
916 return true;
919 break;
920 case ControlType::Slider:
921 if (ePart == ControlPart::ThumbHorz || ePart == ControlPart::ThumbVert)
923 rNativeContentRegion = tools::Rectangle(aLocation, Size(28, 28));
924 rNativeBoundingRegion = rNativeContentRegion;
925 return true;
927 break;
928 default:
929 break;
932 return false;
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);
1021 return true;
1024 } // end vcl namespace
1026 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */