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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "PresenterTheme.hxx"
21 #include "PresenterBitmapContainer.hxx"
22 #include "PresenterCanvasHelper.hxx"
23 #include "PresenterConfigurationAccess.hxx"
24 #include <com/sun/star/drawing/XPresenterHelper.hpp>
25 #include <com/sun/star/rendering/PanoseWeight.hpp>
26 #include <osl/diagnose.h>
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
34 namespace sdext::presenter
{
41 const static sal_Int32 mnInvalidValue
= -10000;
43 BorderSize() : mnLeft(mnInvalidValue
),
44 mnTop(mnInvalidValue
),
45 mnRight(mnInvalidValue
),
46 mnBottom(mnInvalidValue
) {}
53 std::vector
<sal_Int32
> ToVector()
57 mnLeft
== mnInvalidValue
? 0 : mnLeft
,
58 mnTop
== mnInvalidValue
? 0 : mnTop
,
59 mnRight
== mnInvalidValue
? 0 : mnRight
,
60 mnBottom
== mnInvalidValue
? 0 : mnBottom
64 void Merge (const BorderSize
& rBorderSize
)
66 if (mnLeft
== mnInvalidValue
)
67 mnLeft
= rBorderSize
.mnLeft
;
68 if (mnTop
== mnInvalidValue
)
69 mnTop
= rBorderSize
.mnTop
;
70 if (mnRight
== mnInvalidValue
)
71 mnRight
= rBorderSize
.mnRight
;
72 if (mnBottom
== mnInvalidValue
)
73 mnBottom
= rBorderSize
.mnBottom
;
77 /** Reading a theme from the configurations is done in various classes. The
78 ReadContext gives access to frequently used objects and functions to make
79 the configuration handling easier.
84 Reference
<XComponentContext
> mxComponentContext
;
85 Reference
<rendering::XCanvas
> mxCanvas
;
86 Reference
<drawing::XPresenterHelper
> mxPresenterHelper
;
89 const Reference
<XComponentContext
>& rxContext
,
90 const Reference
<rendering::XCanvas
>& rxCanvas
);
92 /** Read data describing a font from the node that can be reached from
93 the given root via the given path.
97 static PresenterTheme::SharedFontDescriptor
ReadFont (
98 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxTheme
,
99 const PresenterTheme::SharedFontDescriptor
& rpDefault
);
100 static PresenterTheme::SharedFontDescriptor
ReadFont (
101 const Reference
<beans::XPropertySet
>& rxFontProperties
,
102 const PresenterTheme::SharedFontDescriptor
& rpDefault
);
104 std::shared_ptr
<PresenterTheme::Theme
> ReadTheme (
105 PresenterConfigurationAccess
& rConfiguration
,
106 const OUString
& rsThemeName
);
108 static BorderSize
ReadBorderSize (const Reference
<container::XNameAccess
>& rxNode
);
111 static Any
GetByName (
112 const Reference
<container::XNameAccess
>& rxNode
,
113 const OUString
& rsName
);
116 /** A PaneStyle describes how a pane is rendered.
123 SharedBitmapDescriptor
GetBitmap (const OUString
& sBitmapName
) const;
125 OUString msStyleName
;
126 std::shared_ptr
<PaneStyle
> mpParentStyle
;
127 PresenterTheme::SharedFontDescriptor mpFont
;
128 BorderSize maInnerBorderSize
;
129 BorderSize maOuterBorderSize
;
130 std::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
132 PresenterTheme::SharedFontDescriptor
GetFont() const;
135 typedef std::shared_ptr
<PaneStyle
> SharedPaneStyle
;
137 class PaneStyleContainer
140 ::std::vector
<SharedPaneStyle
> mStyles
;
144 const ReadContext
& rReadContext
,
145 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
147 SharedPaneStyle
GetPaneStyle (const OUString
& rsStyleName
) const;
150 void ProcessPaneStyle (
151 ReadContext
const & rReadContext
,
152 const ::std::vector
<css::uno::Any
>& rValues
);
155 /** A ViewStyle describes how a view is displayed.
162 SharedBitmapDescriptor
GetBitmap (std::u16string_view sBitmapName
) const;
164 PresenterTheme::SharedFontDescriptor
GetFont() const;
166 OUString msStyleName
;
167 std::shared_ptr
<ViewStyle
> mpParentStyle
;
168 PresenterTheme::SharedFontDescriptor mpFont
;
169 SharedBitmapDescriptor mpBackground
;
172 typedef std::shared_ptr
<ViewStyle
> SharedViewStyle
;
174 class ViewStyleContainer
177 ::std::vector
<SharedViewStyle
> mStyles
;
181 const ReadContext
& rReadContext
,
182 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
184 SharedViewStyle
GetViewStyle (const OUString
& rsStyleName
) const;
187 void ProcessViewStyle(
188 ReadContext
const & rReadContext
,
189 const Reference
<beans::XPropertySet
>& rxProperties
);
192 class StyleAssociationContainer
196 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
198 OUString
GetStyleName (const OUString
& rsResourceName
) const;
201 typedef std::map
<OUString
, OUString
> StyleAssociations
;
202 StyleAssociations maStyleAssociations
;
204 void ProcessStyleAssociation(
205 const ::std::vector
<css::uno::Any
>& rValues
);
208 } // end of anonymous namespace
210 class PresenterTheme::Theme
214 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
,
218 PresenterConfigurationAccess
& rConfiguration
,
219 ReadContext
& rReadContext
);
221 OUString msConfigurationNodeName
;
222 std::shared_ptr
<Theme
> mpParentTheme
;
223 SharedBitmapDescriptor mpBackground
;
224 PaneStyleContainer maPaneStyles
;
225 ViewStyleContainer maViewStyles
;
226 StyleAssociationContainer maStyleAssociations
;
227 Reference
<container::XHierarchicalNameAccess
> mxThemeRoot
;
228 std::shared_ptr
<PresenterBitmapContainer
> mpIconContainer
;
229 typedef std::map
<OUString
,SharedFontDescriptor
> FontContainer
;
230 FontContainer maFontContainer
;
232 SharedPaneStyle
GetPaneStyle (const OUString
& rsStyleName
) const;
233 SharedViewStyle
GetViewStyle (const OUString
& rsStyleName
) const;
237 const OUString
& rsKey
,
238 const Reference
<beans::XPropertySet
>& rxProperties
);
241 //===== PresenterTheme ========================================================
243 PresenterTheme::PresenterTheme (
244 css::uno::Reference
<css::uno::XComponentContext
> xContext
,
245 css::uno::Reference
<css::rendering::XCanvas
> xCanvas
)
246 : mxContext(std::move(xContext
)),
247 mxCanvas(std::move(xCanvas
))
249 mpTheme
= ReadTheme();
252 PresenterTheme::~PresenterTheme()
256 std::shared_ptr
<PresenterTheme::Theme
> PresenterTheme::ReadTheme()
258 ReadContext
aReadContext(mxContext
, mxCanvas
);
260 PresenterConfigurationAccess
aConfiguration (
262 "/org.openoffice.Office.PresenterScreen/",
263 PresenterConfigurationAccess::READ_ONLY
);
265 return aReadContext
.ReadTheme(aConfiguration
, OUString());
268 bool PresenterTheme::HasCanvas() const
270 return mxCanvas
.is();
273 void PresenterTheme::ProvideCanvas (const Reference
<rendering::XCanvas
>& rxCanvas
)
275 if ( ! mxCanvas
.is() && rxCanvas
.is())
282 OUString
PresenterTheme::GetStyleName (const OUString
& rsResourceURL
) const
285 std::shared_ptr
<Theme
> pTheme (mpTheme
);
286 while (sStyleName
.isEmpty() && pTheme
!= nullptr)
288 sStyleName
= pTheme
->maStyleAssociations
.GetStyleName(rsResourceURL
);
289 pTheme
= pTheme
->mpParentTheme
;
294 ::std::vector
<sal_Int32
> PresenterTheme::GetBorderSize (
295 const OUString
& rsStyleName
,
296 const bool bOuter
) const
298 OSL_ASSERT(mpTheme
!= nullptr);
300 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
303 return pPaneStyle
->maOuterBorderSize
.ToVector();
305 return pPaneStyle
->maInnerBorderSize
.ToVector();
308 return ::std::vector
<sal_Int32
>(4,0);
312 PresenterTheme::SharedFontDescriptor
PresenterTheme::ReadFont (
313 const Reference
<container::XHierarchicalNameAccess
>& rxNode
,
314 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
316 return ReadContext::ReadFont(rxNode
, rpDefault
);
319 bool PresenterTheme::ConvertToColor (
320 const Any
& rColorSequence
,
323 Sequence
<sal_Int8
> aByteSequence
;
324 if (rColorSequence
>>= aByteSequence
)
326 rColor
= std::accumulate(std::cbegin(aByteSequence
), std::cend(aByteSequence
), sal_uInt32(0),
327 [](const sal_uInt32 nRes
, const sal_uInt8 nByte
) { return (nRes
<< 8) | nByte
; });
334 std::shared_ptr
<PresenterConfigurationAccess
> PresenterTheme::GetNodeForViewStyle (
335 const OUString
& rsStyleName
) const
337 if (mpTheme
== nullptr)
338 return std::shared_ptr
<PresenterConfigurationAccess
>();
340 // Open configuration for writing.
341 auto pConfiguration
= std::make_shared
<PresenterConfigurationAccess
>(
343 "/org.openoffice.Office.PresenterScreen/",
344 PresenterConfigurationAccess::READ_WRITE
);
346 // Get configuration node for the view style container of the current
348 if (pConfiguration
->GoToChild( OUString(
349 "Presenter/Themes/" + mpTheme
->msConfigurationNodeName
+ "/ViewStyles")))
351 pConfiguration
->GoToChild(
352 [&rsStyleName
] (OUString
const&, uno::Reference
<beans::XPropertySet
> const& xProps
)
354 return PresenterConfigurationAccess::IsStringPropertyEqual(
355 rsStyleName
, "StyleName", xProps
);
358 return pConfiguration
;
361 SharedBitmapDescriptor
PresenterTheme::GetBitmap (
362 const OUString
& rsStyleName
,
363 const OUString
& rsBitmapName
) const
365 if (mpTheme
!= nullptr)
367 if (rsStyleName
.isEmpty())
369 if (rsBitmapName
== "Background")
371 std::shared_ptr
<Theme
> pTheme (mpTheme
);
372 while (pTheme
!= nullptr && !pTheme
->mpBackground
)
373 pTheme
= pTheme
->mpParentTheme
;
374 if (pTheme
!= nullptr)
375 return pTheme
->mpBackground
;
377 return SharedBitmapDescriptor();
382 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
385 SharedBitmapDescriptor
pBitmap (pPaneStyle
->GetBitmap(rsBitmapName
));
390 SharedViewStyle
pViewStyle (mpTheme
->GetViewStyle(rsStyleName
));
393 SharedBitmapDescriptor
pBitmap (pViewStyle
->GetBitmap(rsBitmapName
));
400 return SharedBitmapDescriptor();
403 SharedBitmapDescriptor
PresenterTheme::GetBitmap (
404 const OUString
& rsBitmapName
) const
406 if (mpTheme
!= nullptr)
408 if (rsBitmapName
== "Background")
410 std::shared_ptr
<Theme
> pTheme (mpTheme
);
411 while (pTheme
!= nullptr && !pTheme
->mpBackground
)
412 pTheme
= pTheme
->mpParentTheme
;
413 if (pTheme
!= nullptr)
414 return pTheme
->mpBackground
;
416 return SharedBitmapDescriptor();
420 if (mpTheme
->mpIconContainer
!= nullptr)
421 return mpTheme
->mpIconContainer
->GetBitmap(rsBitmapName
);
425 return SharedBitmapDescriptor();
428 std::shared_ptr
<PresenterBitmapContainer
> PresenterTheme::GetBitmapContainer() const
430 if (mpTheme
!= nullptr)
431 return mpTheme
->mpIconContainer
;
433 return std::shared_ptr
<PresenterBitmapContainer
>();
436 PresenterTheme::SharedFontDescriptor
PresenterTheme::GetFont (
437 const OUString
& rsStyleName
) const
439 if (mpTheme
!= nullptr)
441 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
443 return pPaneStyle
->GetFont();
445 SharedViewStyle
pViewStyle (mpTheme
->GetViewStyle(rsStyleName
));
447 return pViewStyle
->GetFont();
449 std::shared_ptr
<Theme
> pTheme (mpTheme
);
450 while (pTheme
!= nullptr)
452 Theme::FontContainer::const_iterator
iFont (pTheme
->maFontContainer
.find(rsStyleName
));
453 if (iFont
!= pTheme
->maFontContainer
.end())
454 return iFont
->second
;
456 pTheme
= pTheme
->mpParentTheme
;
460 return SharedFontDescriptor();
463 //===== FontDescriptor ========================================================
465 PresenterTheme::FontDescriptor::FontDescriptor (
466 const std::shared_ptr
<FontDescriptor
>& rpDescriptor
)
469 msAnchor(OUString("Left")),
473 if (rpDescriptor
!= nullptr)
475 msFamilyName
= rpDescriptor
->msFamilyName
;
476 msStyleName
= rpDescriptor
->msStyleName
;
477 mnSize
= rpDescriptor
->mnSize
;
478 mnColor
= rpDescriptor
->mnColor
;
479 msAnchor
= rpDescriptor
->msAnchor
;
480 mnXOffset
= rpDescriptor
->mnXOffset
;
481 mnYOffset
= rpDescriptor
->mnYOffset
;
485 bool PresenterTheme::FontDescriptor::PrepareFont (
486 const Reference
<rendering::XCanvas
>& rxCanvas
)
491 if ( ! rxCanvas
.is())
494 const double nCellSize (GetCellSizeForDesignSize(rxCanvas
, mnSize
));
495 mxFont
= CreateFont(rxCanvas
, nCellSize
);
500 Reference
<rendering::XCanvasFont
> PresenterTheme::FontDescriptor::CreateFont (
501 const Reference
<rendering::XCanvas
>& rxCanvas
,
502 const double nCellSize
) const
504 rendering::FontRequest aFontRequest
;
505 aFontRequest
.FontDescription
.FamilyName
= msFamilyName
;
506 if (msFamilyName
.isEmpty())
507 aFontRequest
.FontDescription
.FamilyName
= "Tahoma";
508 aFontRequest
.FontDescription
.StyleName
= msStyleName
;
509 aFontRequest
.CellSize
= nCellSize
;
511 // Make an attempt at translating the style name(s)into a corresponding
513 if (msStyleName
== "Bold")
514 aFontRequest
.FontDescription
.FontDescription
.Weight
= rendering::PanoseWeight::HEAVY
;
516 return rxCanvas
->createFont(
518 Sequence
<beans::PropertyValue
>(),
519 geometry::Matrix2D(1,0,0,1));
522 double PresenterTheme::FontDescriptor::GetCellSizeForDesignSize (
523 const Reference
<rendering::XCanvas
>& rxCanvas
,
524 const double nDesignSize
) const
526 // Use the given design size as initial value in calculating the cell
528 double nCellSize (nDesignSize
);
530 if ( ! rxCanvas
.is())
532 // We need the canvas to do the conversion. Return the design size,
533 // it is the our best guess in this circumstance.
537 Reference
<rendering::XCanvasFont
> xFont (CreateFont(rxCanvas
, nCellSize
));
541 geometry::RealRectangle2D
aBox (PresenterCanvasHelper::GetTextBoundingBox (xFont
, "X"));
543 const double nAscent (-aBox
.Y1
);
547 const double nDescent (aBox
.Y2
);
548 const double nScale
= (nAscent
+nDescent
) / nAscent
;
549 return nDesignSize
* nScale
;
552 //===== Theme =================================================================
554 PresenterTheme::Theme::Theme (
555 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
,
557 : msConfigurationNodeName(std::move(sNodeName
)),
560 maStyleAssociations(),
561 mxThemeRoot(rxThemeRoot
)
565 void PresenterTheme::Theme::Read (
566 PresenterConfigurationAccess
& rConfiguration
,
567 ReadContext
& rReadContext
)
569 // Parent theme name.
570 OUString sParentThemeName
;
571 if ((PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "ParentTheme")
572 >>= sParentThemeName
)
573 && !sParentThemeName
.isEmpty())
575 mpParentTheme
= rReadContext
.ReadTheme(rConfiguration
, sParentThemeName
);
579 mpBackground
= PresenterBitmapContainer::LoadBitmap(
582 rReadContext
.mxPresenterHelper
,
583 rReadContext
.mxCanvas
,
584 SharedBitmapDescriptor());
586 // Style associations.
587 maStyleAssociations
.Read(mxThemeRoot
);
590 maPaneStyles
.Read(rReadContext
, mxThemeRoot
);
593 maViewStyles
.Read(rReadContext
, mxThemeRoot
);
596 mpIconContainer
= std::make_shared
<PresenterBitmapContainer
>(
597 Reference
<container::XNameAccess
>(
598 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "Bitmaps"), UNO_QUERY
),
599 mpParentTheme
!= nullptr ? mpParentTheme
->mpIconContainer
600 : std::shared_ptr
<PresenterBitmapContainer
>(),
601 rReadContext
.mxComponentContext
, rReadContext
.mxCanvas
);
604 Reference
<container::XNameAccess
> xFontNode(
605 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "Fonts"),
607 PresenterConfigurationAccess::ForAll(
609 [this] (OUString
const& rKey
, uno::Reference
<beans::XPropertySet
> const& xProps
)
611 return this->ProcessFont(rKey
, xProps
);
615 SharedPaneStyle
PresenterTheme::Theme::GetPaneStyle (const OUString
& rsStyleName
) const
617 SharedPaneStyle
pPaneStyle (maPaneStyles
.GetPaneStyle(rsStyleName
));
620 else if (mpParentTheme
!= nullptr)
621 return mpParentTheme
->GetPaneStyle(rsStyleName
);
623 return SharedPaneStyle();
626 SharedViewStyle
PresenterTheme::Theme::GetViewStyle (const OUString
& rsStyleName
) const
628 SharedViewStyle
pViewStyle (maViewStyles
.GetViewStyle(rsStyleName
));
631 else if (mpParentTheme
!= nullptr)
632 return mpParentTheme
->GetViewStyle(rsStyleName
);
634 return SharedViewStyle();
637 void PresenterTheme::Theme::ProcessFont(
638 const OUString
& rsKey
,
639 const Reference
<beans::XPropertySet
>& rxProperties
)
641 maFontContainer
[rsKey
] = ReadContext::ReadFont(rxProperties
, SharedFontDescriptor());
646 //===== ReadContext ===========================================================
648 ReadContext::ReadContext (
649 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
650 const Reference
<rendering::XCanvas
>& rxCanvas
)
651 : mxComponentContext(rxContext
),
654 Reference
<lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager());
657 mxPresenterHelper
.set(
658 xFactory
->createInstanceWithContext(
659 "com.sun.star.comp.Draw.PresenterHelper",
665 PresenterTheme::SharedFontDescriptor
ReadContext::ReadFont (
666 const Reference
<container::XHierarchicalNameAccess
>& rxNode
,
667 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
670 return PresenterTheme::SharedFontDescriptor();
674 Reference
<container::XHierarchicalNameAccess
> xFont (
675 PresenterConfigurationAccess::GetConfigurationNode(
680 Reference
<beans::XPropertySet
> xProperties (xFont
, UNO_QUERY_THROW
);
681 return ReadFont(xProperties
, rpDefault
);
688 return PresenterTheme::SharedFontDescriptor();
691 PresenterTheme::SharedFontDescriptor
ReadContext::ReadFont (
692 const Reference
<beans::XPropertySet
>& rxProperties
,
693 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
695 auto pDescriptor
= std::make_shared
<PresenterTheme::FontDescriptor
>(rpDefault
);
697 PresenterConfigurationAccess::GetProperty(rxProperties
, "FamilyName") >>= pDescriptor
->msFamilyName
;
698 PresenterConfigurationAccess::GetProperty(rxProperties
, "Style") >>= pDescriptor
->msStyleName
;
699 PresenterConfigurationAccess::GetProperty(rxProperties
, "Size") >>= pDescriptor
->mnSize
;
700 PresenterTheme::ConvertToColor(
701 PresenterConfigurationAccess::GetProperty(rxProperties
, "Color"),
702 pDescriptor
->mnColor
);
703 PresenterConfigurationAccess::GetProperty(rxProperties
, "Anchor") >>= pDescriptor
->msAnchor
;
704 PresenterConfigurationAccess::GetProperty(rxProperties
, "XOffset") >>= pDescriptor
->mnXOffset
;
705 PresenterConfigurationAccess::GetProperty(rxProperties
, "YOffset") >>= pDescriptor
->mnYOffset
;
710 Any
ReadContext::GetByName (
711 const Reference
<container::XNameAccess
>& rxNode
,
712 const OUString
& rsName
)
714 OSL_ASSERT(rxNode
.is());
715 if (rxNode
->hasByName(rsName
))
716 return rxNode
->getByName(rsName
);
721 std::shared_ptr
<PresenterTheme::Theme
> ReadContext::ReadTheme (
722 PresenterConfigurationAccess
& rConfiguration
,
723 const OUString
& rsThemeName
)
725 std::shared_ptr
<PresenterTheme::Theme
> pTheme
;
727 OUString
sCurrentThemeName (rsThemeName
);
728 if (sCurrentThemeName
.isEmpty())
730 // No theme name given. Look up the CurrentTheme property.
731 rConfiguration
.GetConfigurationNode("Presenter/CurrentTheme") >>= sCurrentThemeName
;
732 if (sCurrentThemeName
.isEmpty())
734 // Still no name. Use "DefaultTheme".
735 sCurrentThemeName
= "DefaultTheme";
739 Reference
<container::XNameAccess
> xThemes (
740 rConfiguration
.GetConfigurationNode("Presenter/Themes"),
744 // Iterate over all themes and search the one with the given name.
745 const Sequence
<OUString
> aKeys (xThemes
->getElementNames());
746 for (const OUString
& rsKey
: aKeys
)
748 Reference
<container::XHierarchicalNameAccess
> xTheme (
749 xThemes
->getByName(rsKey
), UNO_QUERY
);
753 PresenterConfigurationAccess::GetConfigurationNode(xTheme
, "ThemeName")
755 if (sThemeName
== sCurrentThemeName
)
757 pTheme
= std::make_shared
<PresenterTheme::Theme
>(xTheme
,rsKey
);
764 if (pTheme
!= nullptr)
766 pTheme
->Read(rConfiguration
, *this);
772 BorderSize
ReadContext::ReadBorderSize (const Reference
<container::XNameAccess
>& rxNode
)
774 BorderSize aBorderSize
;
778 GetByName(rxNode
, "Left") >>= aBorderSize
.mnLeft
;
779 GetByName(rxNode
, "Top") >>= aBorderSize
.mnTop
;
780 GetByName(rxNode
, "Right") >>= aBorderSize
.mnRight
;
781 GetByName(rxNode
, "Bottom") >>= aBorderSize
.mnBottom
;
787 //===== PaneStyleContainer ====================================================
789 void PaneStyleContainer::Read (
790 const ReadContext
& rReadContext
,
791 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
793 Reference
<container::XNameAccess
> xPaneStyleList (
794 PresenterConfigurationAccess::GetConfigurationNode(
798 if (!xPaneStyleList
.is())
801 ::std::vector
<OUString
> aProperties
;
802 aProperties
.reserve(6);
803 aProperties
.emplace_back("StyleName");
804 aProperties
.emplace_back("ParentStyle");
805 aProperties
.emplace_back("TitleFont");
806 aProperties
.emplace_back("InnerBorderSize");
807 aProperties
.emplace_back("OuterBorderSize");
808 aProperties
.emplace_back("BorderBitmapList");
809 PresenterConfigurationAccess::ForAll(
812 [this, &rReadContext
] (std::vector
<uno::Any
> const& rValues
)
814 return this->ProcessPaneStyle(rReadContext
, rValues
);
818 void PaneStyleContainer::ProcessPaneStyle(
819 ReadContext
const & rReadContext
,
820 const ::std::vector
<Any
>& rValues
)
822 if (rValues
.size() != 6)
825 auto pStyle
= std::make_shared
<PaneStyle
>();
827 rValues
[0] >>= pStyle
->msStyleName
;
829 OUString sParentStyleName
;
830 if (rValues
[1] >>= sParentStyleName
)
832 // Find parent style.
833 auto iStyle
= std::find_if(mStyles
.begin(), mStyles
.end(),
834 [&sParentStyleName
](const SharedPaneStyle
& rxStyle
) { return rxStyle
->msStyleName
== sParentStyleName
; });
835 if (iStyle
!= mStyles
.end())
836 pStyle
->mpParentStyle
= *iStyle
;
839 Reference
<container::XHierarchicalNameAccess
> xFontNode (rValues
[2], UNO_QUERY
);
840 pStyle
->mpFont
= ReadContext::ReadFont(
841 xFontNode
, PresenterTheme::SharedFontDescriptor());
843 Reference
<container::XNameAccess
> xInnerBorderSizeNode (rValues
[3], UNO_QUERY
);
844 pStyle
->maInnerBorderSize
= ReadContext::ReadBorderSize(xInnerBorderSizeNode
);
845 Reference
<container::XNameAccess
> xOuterBorderSizeNode (rValues
[4], UNO_QUERY
);
846 pStyle
->maOuterBorderSize
= ReadContext::ReadBorderSize(xOuterBorderSizeNode
);
848 if (pStyle
->mpParentStyle
!= nullptr)
850 pStyle
->maInnerBorderSize
.Merge(pStyle
->mpParentStyle
->maInnerBorderSize
);
851 pStyle
->maOuterBorderSize
.Merge(pStyle
->mpParentStyle
->maOuterBorderSize
);
854 if (rReadContext
.mxCanvas
.is())
856 Reference
<container::XNameAccess
> xBitmapsNode (rValues
[5], UNO_QUERY
);
857 pStyle
->mpBitmaps
= std::make_shared
<PresenterBitmapContainer
>(
859 pStyle
->mpParentStyle
!= nullptr ? pStyle
->mpParentStyle
->mpBitmaps
860 : std::shared_ptr
<PresenterBitmapContainer
>(),
861 rReadContext
.mxComponentContext
, rReadContext
.mxCanvas
,
862 rReadContext
.mxPresenterHelper
);
865 mStyles
.push_back(pStyle
);
868 SharedPaneStyle
PaneStyleContainer::GetPaneStyle (const OUString
& rsStyleName
) const
870 auto iStyle
= std::find_if(mStyles
.begin(), mStyles
.end(),
871 [&rsStyleName
](const SharedPaneStyle
& rxStyle
) { return rxStyle
->msStyleName
== rsStyleName
; });
872 if (iStyle
!= mStyles
.end())
874 return SharedPaneStyle();
877 //===== PaneStyle =============================================================
879 PaneStyle::PaneStyle()
883 SharedBitmapDescriptor
PaneStyle::GetBitmap (const OUString
& rsBitmapName
) const
885 if (mpBitmaps
!= nullptr)
887 SharedBitmapDescriptor pBitmap
= mpBitmaps
->GetBitmap(rsBitmapName
);
892 if (mpParentStyle
!= nullptr)
893 return mpParentStyle
->GetBitmap(rsBitmapName
);
895 return SharedBitmapDescriptor();
898 PresenterTheme::SharedFontDescriptor
PaneStyle::GetFont() const
902 else if (mpParentStyle
!= nullptr)
903 return mpParentStyle
->GetFont();
905 return PresenterTheme::SharedFontDescriptor();
908 //===== ViewStyleContainer ====================================================
910 void ViewStyleContainer::Read (
911 const ReadContext
& rReadContext
,
912 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
914 Reference
<container::XNameAccess
> xViewStyleList (
915 PresenterConfigurationAccess::GetConfigurationNode(
919 if (xViewStyleList
.is())
921 PresenterConfigurationAccess::ForAll(
923 [this, &rReadContext
] (OUString
const&, uno::Reference
<beans::XPropertySet
> const& xProps
)
925 return this->ProcessViewStyle(rReadContext
, xProps
);
930 void ViewStyleContainer::ProcessViewStyle(
931 ReadContext
const & rReadContext
,
932 const Reference
<beans::XPropertySet
>& rxProperties
)
934 auto pStyle
= std::make_shared
<ViewStyle
>();
936 PresenterConfigurationAccess::GetProperty(rxProperties
, "StyleName")
937 >>= pStyle
->msStyleName
;
939 OUString sParentStyleName
;
940 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "ParentStyle")
941 >>= sParentStyleName
)
943 // Find parent style.
944 auto iStyle
= std::find_if(mStyles
.begin(), mStyles
.end(),
945 [&sParentStyleName
](const SharedViewStyle
& rxStyle
) { return rxStyle
->msStyleName
== sParentStyleName
; });
946 if (iStyle
!= mStyles
.end())
948 pStyle
->mpParentStyle
= *iStyle
;
949 pStyle
->mpFont
= (*iStyle
)->mpFont
;
950 pStyle
->mpBackground
= (*iStyle
)->mpBackground
;
954 Reference
<container::XHierarchicalNameAccess
> xFontNode (
955 PresenterConfigurationAccess::GetProperty(rxProperties
, "Font"), UNO_QUERY
);
956 PresenterTheme::SharedFontDescriptor
pFont (
957 ReadContext::ReadFont(xFontNode
, PresenterTheme::SharedFontDescriptor()));
959 pStyle
->mpFont
= pFont
;
961 Reference
<container::XHierarchicalNameAccess
> xBackgroundNode (
962 PresenterConfigurationAccess::GetProperty(rxProperties
, "Background"),
964 SharedBitmapDescriptor
pBackground (PresenterBitmapContainer::LoadBitmap(
967 rReadContext
.mxPresenterHelper
,
968 rReadContext
.mxCanvas
,
969 SharedBitmapDescriptor()));
970 if (pBackground
&& pBackground
->GetNormalBitmap().is())
971 pStyle
->mpBackground
= pBackground
;
973 mStyles
.push_back(pStyle
);
976 SharedViewStyle
ViewStyleContainer::GetViewStyle (const OUString
& rsStyleName
) const
978 auto iStyle
= std::find_if(mStyles
.begin(), mStyles
.end(),
979 [&rsStyleName
](const SharedViewStyle
& rxStyle
) { return rxStyle
->msStyleName
== rsStyleName
; });
980 if (iStyle
!= mStyles
.end())
982 return SharedViewStyle();
985 //===== ViewStyle =============================================================
987 ViewStyle::ViewStyle()
991 SharedBitmapDescriptor
ViewStyle::GetBitmap (std::u16string_view rsBitmapName
) const
993 if (rsBitmapName
== u
"Background")
996 return SharedBitmapDescriptor();
999 PresenterTheme::SharedFontDescriptor
ViewStyle::GetFont() const
1003 else if (mpParentStyle
!= nullptr)
1004 return mpParentStyle
->GetFont();
1006 return PresenterTheme::SharedFontDescriptor();
1009 //===== StyleAssociationContainer =============================================
1011 void StyleAssociationContainer::Read (
1012 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
1014 Reference
<container::XNameAccess
> xStyleAssociationList (
1015 PresenterConfigurationAccess::GetConfigurationNode(
1017 "StyleAssociations"),
1019 if (!xStyleAssociationList
.is())
1022 ::std::vector
<OUString
> aProperties
{ "ResourceURL", "StyleName" };
1023 PresenterConfigurationAccess::ForAll(
1024 xStyleAssociationList
,
1026 [this] (std::vector
<uno::Any
> const& rValues
)
1028 return this->ProcessStyleAssociation(rValues
);
1032 OUString
StyleAssociationContainer::GetStyleName (const OUString
& rsResourceName
) const
1034 StyleAssociations::const_iterator
iAssociation (maStyleAssociations
.find(rsResourceName
));
1035 if (iAssociation
!= maStyleAssociations
.end())
1036 return iAssociation
->second
;
1041 void StyleAssociationContainer::ProcessStyleAssociation(
1042 const ::std::vector
<Any
>& rValues
)
1044 if (rValues
.size() != 2)
1047 OUString sResourceURL
;
1048 OUString sStyleName
;
1049 if ((rValues
[0] >>= sResourceURL
)
1050 && (rValues
[1] >>= sStyleName
))
1052 maStyleAssociations
[sResourceURL
] = sStyleName
;
1056 } // end of anonymous namespace
1058 } // end of namespace ::sdext::presenter
1060 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */