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 "PresenterHelper.hxx"
25 #include <com/sun/star/awt/Point.hpp>
26 #include <com/sun/star/beans/UnknownPropertyException.hpp>
27 #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
28 #include <com/sun/star/drawing/XPresenterHelper.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <com/sun/star/rendering/PanoseWeight.hpp>
31 #include <com/sun/star/rendering/XBitmap.hpp>
32 #include <com/sun/star/util/Color.hpp>
33 #include <boost/bind.hpp>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::std
;
40 namespace sdext
{ namespace presenter
{
47 const static sal_Int32 mnInvalidValue
= -10000;
49 BorderSize (void) : mnLeft(mnInvalidValue
),
50 mnTop(mnInvalidValue
),
51 mnRight(mnInvalidValue
),
52 mnBottom(mnInvalidValue
) {}
59 vector
<sal_Int32
> ToVector (void)
61 vector
<sal_Int32
> aSequence (4);
62 aSequence
[0] = mnLeft
== mnInvalidValue
? 0 : mnLeft
;
63 aSequence
[1] = mnTop
== mnInvalidValue
? 0 : mnTop
;
64 aSequence
[2] = mnRight
== mnInvalidValue
? 0 : mnRight
;
65 aSequence
[3] = mnBottom
== mnInvalidValue
? 0 : mnBottom
;
69 void Merge (const BorderSize
& rBorderSize
)
71 if (mnLeft
== mnInvalidValue
)
72 mnLeft
= rBorderSize
.mnLeft
;
73 if (mnTop
== mnInvalidValue
)
74 mnTop
= rBorderSize
.mnTop
;
75 if (mnRight
== mnInvalidValue
)
76 mnRight
= rBorderSize
.mnRight
;
77 if (mnBottom
== mnInvalidValue
)
78 mnBottom
= rBorderSize
.mnBottom
;
82 /** Reading a theme from the configurations is done in various classes. The
83 ReadContext gives access to frequently used objects and functions to make
84 the configuration handling easier.
89 Reference
<XComponentContext
> mxComponentContext
;
90 Reference
<rendering::XCanvas
> mxCanvas
;
91 Reference
<drawing::XPresenterHelper
> mxPresenterHelper
;
94 const Reference
<XComponentContext
>& rxContext
,
95 const Reference
<rendering::XCanvas
>& rxCanvas
);
98 /** Read data describing a font from the node that can be reached from
99 the given root via the given path.
103 static PresenterTheme::SharedFontDescriptor
ReadFont (
104 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxTheme
,
105 const OUString
& rsFontPath
,
106 const PresenterTheme::SharedFontDescriptor
& rpDefault
);
107 static PresenterTheme::SharedFontDescriptor
ReadFont (
108 const Reference
<beans::XPropertySet
>& rxFontProperties
,
109 const PresenterTheme::SharedFontDescriptor
& rpDefault
);
111 ::boost::shared_ptr
<PresenterTheme::Theme
> ReadTheme (
112 PresenterConfigurationAccess
& rConfiguration
,
113 const OUString
& rsThemeName
);
115 BorderSize
ReadBorderSize (const Reference
<container::XNameAccess
>& rxNode
);
119 const Reference
<container::XNameAccess
>& rxNode
,
120 const OUString
& rsName
) const;
123 /** A PaneStyle describes how a pane is rendered.
131 const SharedBitmapDescriptor
GetBitmap (const OUString
& sBitmapName
) const;
133 OUString msStyleName
;
134 ::boost::shared_ptr
<PaneStyle
> mpParentStyle
;
135 PresenterTheme::SharedFontDescriptor mpFont
;
136 BorderSize maInnerBorderSize
;
137 BorderSize maOuterBorderSize
;
138 ::boost::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
140 PresenterTheme::SharedFontDescriptor
GetFont (void) const;
144 void UpdateBorderSize (BorderSize
& rBorderSize
, bool bInner
);
147 typedef ::boost::shared_ptr
<PaneStyle
> SharedPaneStyle
;
149 class PaneStyleContainer
: vector
<SharedPaneStyle
>
153 ReadContext
& rReadContext
,
154 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
156 SharedPaneStyle
GetPaneStyle (const OUString
& rsStyleName
) const;
159 void ProcessPaneStyle (
160 ReadContext
& rReadContext
,
161 const OUString
& rsKey
,
162 const ::std::vector
<css::uno::Any
>& rValues
);
165 /** A ViewStyle describes how a view is displayed.
173 const SharedBitmapDescriptor
GetBitmap (const OUString
& sBitmapName
) const;
175 PresenterTheme::SharedFontDescriptor
GetFont (void) const;
177 OUString msStyleName
;
178 ::boost::shared_ptr
<ViewStyle
> mpParentStyle
;
179 PresenterTheme::SharedFontDescriptor mpFont
;
180 ::boost::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
181 SharedBitmapDescriptor mpBackground
;
184 typedef ::boost::shared_ptr
<ViewStyle
> SharedViewStyle
;
186 class ViewStyleContainer
: vector
<SharedViewStyle
>
190 ReadContext
& rReadContext
,
191 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
193 SharedViewStyle
GetViewStyle (const OUString
& rsStyleName
) const;
196 void ProcessViewStyle(
197 ReadContext
& rReadContext
,
198 const Reference
<beans::XPropertySet
>& rxProperties
);
204 typedef ::boost::shared_ptr
<ViewDescriptor
> SharedViewDescriptor
;
205 typedef ::std::vector
<SharedViewDescriptor
> ViewDescriptorContainer
;
207 class StyleAssociationContainer
211 ReadContext
& rReadContext
,
212 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
214 OUString
GetStyleName (const OUString
& rsResourceName
) const;
217 typedef map
<OUString
, OUString
> StyleAssociations
;
218 StyleAssociations maStyleAssociations
;
220 void ProcessStyleAssociation(
221 ReadContext
& rReadContext
,
222 const OUString
& rsKey
,
223 const ::std::vector
<css::uno::Any
>& rValues
);
226 } // end of anonymous namespace
228 class PresenterTheme::Theme
232 const OUString
& rsName
,
233 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
,
234 const OUString
& rsNodeName
);
238 PresenterConfigurationAccess
& rConfiguration
,
239 ReadContext
& rReadContext
);
241 OUString msThemeName
;
242 OUString msConfigurationNodeName
;
243 ::boost::shared_ptr
<Theme
> mpParentTheme
;
244 SharedBitmapDescriptor mpBackground
;
245 PaneStyleContainer maPaneStyles
;
246 ViewStyleContainer maViewStyles
;
247 ViewDescriptorContainer maViewDescriptors
;
248 StyleAssociationContainer maStyleAssociations
;
249 Reference
<container::XHierarchicalNameAccess
> mxThemeRoot
;
250 ::boost::shared_ptr
<PresenterBitmapContainer
> mpIconContainer
;
251 typedef map
<OUString
,SharedFontDescriptor
> FontContainer
;
252 FontContainer maFontContainer
;
254 SharedPaneStyle
GetPaneStyle (const OUString
& rsStyleName
) const;
255 SharedViewStyle
GetViewStyle (const OUString
& rsStyleName
) const;
259 ReadContext
& rReadContext
,
260 const OUString
& rsKey
,
261 const Reference
<beans::XPropertySet
>& rxProperties
);
264 //===== PresenterTheme ========================================================
266 PresenterTheme::PresenterTheme (
267 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
268 const OUString
& rsThemeName
,
269 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
)
270 : mxContext(rxContext
),
271 msThemeName(rsThemeName
),
276 mpTheme
= ReadTheme();
279 PresenterTheme::~PresenterTheme (void)
283 ::boost::shared_ptr
<PresenterTheme::Theme
> PresenterTheme::ReadTheme (void)
285 ReadContext
aReadContext(mxContext
, mxCanvas
);
287 PresenterConfigurationAccess
aConfiguration (
289 OUString("/org.openoffice.Office.PresenterScreen/"),
290 PresenterConfigurationAccess::READ_ONLY
);
292 return aReadContext
.ReadTheme(aConfiguration
, msThemeName
);
295 bool PresenterTheme::HasCanvas (void) const
297 return mxCanvas
.is();
300 void PresenterTheme::ProvideCanvas (const Reference
<rendering::XCanvas
>& rxCanvas
)
302 if ( ! mxCanvas
.is() && rxCanvas
.is())
309 OUString
PresenterTheme::GetStyleName (const OUString
& rsResourceURL
) const
312 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
313 while (sStyleName
.isEmpty() && pTheme
.get()!=NULL
)
315 sStyleName
= pTheme
->maStyleAssociations
.GetStyleName(rsResourceURL
);
316 pTheme
= pTheme
->mpParentTheme
;
321 ::std::vector
<sal_Int32
> PresenterTheme::GetBorderSize (
322 const OUString
& rsStyleName
,
323 const bool bOuter
) const
325 OSL_ASSERT(mpTheme
.get() != NULL
);
327 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
328 if (pPaneStyle
.get() != NULL
)
330 return pPaneStyle
->maOuterBorderSize
.ToVector();
332 return pPaneStyle
->maInnerBorderSize
.ToVector();
335 return ::std::vector
<sal_Int32
>(4,0);
339 PresenterTheme::SharedFontDescriptor
PresenterTheme::ReadFont (
340 const Reference
<container::XHierarchicalNameAccess
>& rxNode
,
341 const OUString
& rsFontPath
,
342 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
344 return ReadContext::ReadFont(rxNode
, rsFontPath
, rpDefault
);
347 bool PresenterTheme::ConvertToColor (
348 const Any
& rColorSequence
,
351 Sequence
<sal_Int8
> aByteSequence
;
352 if (rColorSequence
>>= aByteSequence
)
354 const sal_Int32
nByteCount (aByteSequence
.getLength());
355 const sal_uInt8
* pArray
= reinterpret_cast<const sal_uInt8
*>(aByteSequence
.getConstArray());
357 for (sal_Int32 nIndex
=0; nIndex
<nByteCount
; ++nIndex
)
359 rColor
= (rColor
<< 8) | *pArray
++;
367 ::boost::shared_ptr
<PresenterConfigurationAccess
> PresenterTheme::GetNodeForViewStyle (
368 const OUString
& rsStyleName
) const
370 if (mpTheme
.get() == NULL
)
371 return ::boost::shared_ptr
<PresenterConfigurationAccess
>();
373 // Open configuration for writing.
374 ::boost::shared_ptr
<PresenterConfigurationAccess
> pConfiguration (
375 new PresenterConfigurationAccess(
377 OUString("/org.openoffice.Office.PresenterScreen/"),
378 PresenterConfigurationAccess::READ_WRITE
));
380 // Get configuration node for the view style container of the current
382 if (pConfiguration
->GoToChild( OUString(
383 "Presenter/Themes/" + mpTheme
->msConfigurationNodeName
+ "/ViewStyles")))
385 pConfiguration
->GoToChild(
386 ::boost::bind(&PresenterConfigurationAccess::IsStringPropertyEqual
,
388 OUString::createFromAscii("StyleName"),
391 return pConfiguration
;
394 SharedBitmapDescriptor
PresenterTheme::GetBitmap (
395 const OUString
& rsStyleName
,
396 const OUString
& rsBitmapName
) const
398 if (mpTheme
.get() != NULL
)
400 if (rsStyleName
.isEmpty())
402 if (rsBitmapName
== "Background")
404 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
405 while (pTheme
.get()!=NULL
&& pTheme
->mpBackground
.get()==NULL
)
406 pTheme
= pTheme
->mpParentTheme
;
407 if (pTheme
.get() != NULL
)
408 return pTheme
->mpBackground
;
410 return SharedBitmapDescriptor();
415 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
416 if (pPaneStyle
.get() != NULL
)
418 SharedBitmapDescriptor
pBitmap (pPaneStyle
->GetBitmap(rsBitmapName
));
419 if (pBitmap
.get() != NULL
)
423 SharedViewStyle
pViewStyle (mpTheme
->GetViewStyle(rsStyleName
));
424 if (pViewStyle
.get() != NULL
)
426 SharedBitmapDescriptor
pBitmap (pViewStyle
->GetBitmap(rsBitmapName
));
427 if (pBitmap
.get() != NULL
)
433 return SharedBitmapDescriptor();
436 SharedBitmapDescriptor
PresenterTheme::GetBitmap (
437 const OUString
& rsBitmapName
) const
439 if (mpTheme
.get() != NULL
)
441 if (rsBitmapName
== "Background")
443 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
444 while (pTheme
.get()!=NULL
&& pTheme
->mpBackground
.get()==NULL
)
445 pTheme
= pTheme
->mpParentTheme
;
446 if (pTheme
.get() != NULL
)
447 return pTheme
->mpBackground
;
449 return SharedBitmapDescriptor();
453 if (mpTheme
->mpIconContainer
.get() != NULL
)
454 return mpTheme
->mpIconContainer
->GetBitmap(rsBitmapName
);
458 return SharedBitmapDescriptor();
461 ::boost::shared_ptr
<PresenterBitmapContainer
> PresenterTheme::GetBitmapContainer (void) const
463 if (mpTheme
.get() != NULL
)
464 return mpTheme
->mpIconContainer
;
466 return ::boost::shared_ptr
<PresenterBitmapContainer
>();
469 PresenterTheme::SharedFontDescriptor
PresenterTheme::GetFont (
470 const OUString
& rsStyleName
) const
472 if (mpTheme
.get() != NULL
)
474 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
475 if (pPaneStyle
.get() != NULL
)
476 return pPaneStyle
->GetFont();
478 SharedViewStyle
pViewStyle (mpTheme
->GetViewStyle(rsStyleName
));
479 if (pViewStyle
.get() != NULL
)
480 return pViewStyle
->GetFont();
482 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
483 while (pTheme
.get() != NULL
)
485 Theme::FontContainer::const_iterator
iFont (pTheme
->maFontContainer
.find(rsStyleName
));
486 if (iFont
!= pTheme
->maFontContainer
.end())
487 return iFont
->second
;
489 pTheme
= pTheme
->mpParentTheme
;
493 return SharedFontDescriptor();
496 //===== FontDescriptor ========================================================
498 PresenterTheme::FontDescriptor::FontDescriptor (
499 const ::boost::shared_ptr
<FontDescriptor
>& rpDescriptor
)
504 msAnchor(OUString("Left")),
508 if (rpDescriptor
.get() != NULL
)
510 msFamilyName
= rpDescriptor
->msFamilyName
;
511 msStyleName
= rpDescriptor
->msStyleName
;
512 mnSize
= rpDescriptor
->mnSize
;
513 mnColor
= rpDescriptor
->mnColor
;
514 msAnchor
= rpDescriptor
->msAnchor
;
515 mnXOffset
= rpDescriptor
->mnXOffset
;
516 mnYOffset
= rpDescriptor
->mnYOffset
;
520 bool PresenterTheme::FontDescriptor::PrepareFont (
521 const Reference
<rendering::XCanvas
>& rxCanvas
)
526 if ( ! rxCanvas
.is())
529 const double nCellSize (GetCellSizeForDesignSize(rxCanvas
, mnSize
));
530 mxFont
= CreateFont(rxCanvas
, nCellSize
);
535 Reference
<rendering::XCanvasFont
> PresenterTheme::FontDescriptor::CreateFont (
536 const Reference
<rendering::XCanvas
>& rxCanvas
,
537 const double nCellSize
) const
539 rendering::FontRequest aFontRequest
;
540 aFontRequest
.FontDescription
.FamilyName
= msFamilyName
;
541 if (msFamilyName
.isEmpty())
542 aFontRequest
.FontDescription
.FamilyName
= "Tahoma";
543 aFontRequest
.FontDescription
.StyleName
= msStyleName
;
544 aFontRequest
.CellSize
= nCellSize
;
546 // Make an attempt at translating the style name(s)into a corresponding
548 if (msStyleName
== "Bold")
549 aFontRequest
.FontDescription
.FontDescription
.Weight
= rendering::PanoseWeight::HEAVY
;
551 return rxCanvas
->createFont(
553 Sequence
<beans::PropertyValue
>(),
554 geometry::Matrix2D(1,0,0,1));
557 double PresenterTheme::FontDescriptor::GetCellSizeForDesignSize (
558 const Reference
<rendering::XCanvas
>& rxCanvas
,
559 const double nDesignSize
) const
561 // Use the given design size as initial value in calculating the cell
563 double nCellSize (nDesignSize
);
565 if ( ! rxCanvas
.is())
567 // We need the canvas to do the conversion. Return the design size,
568 // it is the our best guess in this circumstance.
572 Reference
<rendering::XCanvasFont
> xFont (CreateFont(rxCanvas
, nCellSize
));
576 geometry::RealRectangle2D
aBox (PresenterCanvasHelper::GetTextBoundingBox (xFont
, "X"));
578 const double nAscent (-aBox
.Y1
);
579 const double nDescent (aBox
.Y2
);
580 const double nScale
= (nAscent
+nDescent
) / nAscent
;
581 return nDesignSize
* nScale
;
584 //===== Theme =================================================================
586 PresenterTheme::Theme::Theme (
587 const OUString
& rsName
,
588 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
,
589 const OUString
& rsNodeName
)
590 : msThemeName(rsName
),
591 msConfigurationNodeName(rsNodeName
),
595 maStyleAssociations(),
596 mxThemeRoot(rxThemeRoot
),
601 PresenterTheme::Theme::~Theme (void)
605 void PresenterTheme::Theme::Read (
606 PresenterConfigurationAccess
& rConfiguration
,
607 ReadContext
& rReadContext
)
609 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "ThemeName")
612 // Parent theme name.
613 OUString sParentThemeName
;
614 if ((PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "ParentTheme")
615 >>= sParentThemeName
)
616 && !sParentThemeName
.isEmpty())
618 mpParentTheme
= rReadContext
.ReadTheme(rConfiguration
, sParentThemeName
);
622 mpBackground
= PresenterBitmapContainer::LoadBitmap(
625 rReadContext
.mxPresenterHelper
,
626 rReadContext
.mxCanvas
,
627 SharedBitmapDescriptor());
629 // Style associations.
630 maStyleAssociations
.Read(rReadContext
, mxThemeRoot
);
633 maPaneStyles
.Read(rReadContext
, mxThemeRoot
);
636 maViewStyles
.Read(rReadContext
, mxThemeRoot
);
639 mpIconContainer
.reset(
640 new PresenterBitmapContainer(
641 Reference
<container::XNameAccess
>(
642 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "Bitmaps"),
644 mpParentTheme
.get()!=NULL
645 ? mpParentTheme
->mpIconContainer
646 : ::boost::shared_ptr
<PresenterBitmapContainer
>(),
647 rReadContext
.mxComponentContext
,
648 rReadContext
.mxCanvas
));
651 Reference
<container::XNameAccess
> xFontNode(
652 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, "Fonts"),
654 PresenterConfigurationAccess::ForAll(
656 ::boost::bind(&PresenterTheme::Theme::ProcessFont
,
657 this, ::boost::ref(rReadContext
), _1
, _2
));
660 SharedPaneStyle
PresenterTheme::Theme::GetPaneStyle (const OUString
& rsStyleName
) const
662 SharedPaneStyle
pPaneStyle (maPaneStyles
.GetPaneStyle(rsStyleName
));
663 if (pPaneStyle
.get() != NULL
)
665 else if (mpParentTheme
.get() != NULL
)
666 return mpParentTheme
->GetPaneStyle(rsStyleName
);
668 return SharedPaneStyle();
671 SharedViewStyle
PresenterTheme::Theme::GetViewStyle (const OUString
& rsStyleName
) const
673 SharedViewStyle
pViewStyle (maViewStyles
.GetViewStyle(rsStyleName
));
674 if (pViewStyle
.get() != NULL
)
676 else if (mpParentTheme
.get() != NULL
)
677 return mpParentTheme
->GetViewStyle(rsStyleName
);
679 return SharedViewStyle();
682 void PresenterTheme::Theme::ProcessFont(
683 ReadContext
& rReadContext
,
684 const OUString
& rsKey
,
685 const Reference
<beans::XPropertySet
>& rxProperties
)
688 maFontContainer
[rsKey
] = ReadContext::ReadFont(rxProperties
, SharedFontDescriptor());
693 //===== ReadContext ===========================================================
695 ReadContext::ReadContext (
696 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
697 const Reference
<rendering::XCanvas
>& rxCanvas
)
698 : mxComponentContext(rxContext
),
702 Reference
<lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager());
705 mxPresenterHelper
= Reference
<drawing::XPresenterHelper
>(
706 xFactory
->createInstanceWithContext(
707 OUString("com.sun.star.comp.Draw.PresenterHelper"),
713 ReadContext::~ReadContext (void)
717 PresenterTheme::SharedFontDescriptor
ReadContext::ReadFont (
718 const Reference
<container::XHierarchicalNameAccess
>& rxNode
,
719 const OUString
& rsFontPath
,
720 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
723 return PresenterTheme::SharedFontDescriptor();
727 Reference
<container::XHierarchicalNameAccess
> xFont (
728 PresenterConfigurationAccess::GetConfigurationNode(
733 Reference
<beans::XPropertySet
> xProperties (xFont
, UNO_QUERY_THROW
);
734 return ReadFont(xProperties
, rpDefault
);
741 return PresenterTheme::SharedFontDescriptor();
744 PresenterTheme::SharedFontDescriptor
ReadContext::ReadFont (
745 const Reference
<beans::XPropertySet
>& rxProperties
,
746 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
748 ::boost::shared_ptr
<PresenterTheme::FontDescriptor
> pDescriptor (
749 new PresenterTheme::FontDescriptor(rpDefault
));
751 PresenterConfigurationAccess::GetProperty(rxProperties
, "FamilyName") >>= pDescriptor
->msFamilyName
;
752 PresenterConfigurationAccess::GetProperty(rxProperties
, "Style") >>= pDescriptor
->msStyleName
;
753 PresenterConfigurationAccess::GetProperty(rxProperties
, "Size") >>= pDescriptor
->mnSize
;
754 PresenterTheme::ConvertToColor(
755 PresenterConfigurationAccess::GetProperty(rxProperties
, "Color"),
756 pDescriptor
->mnColor
);
757 PresenterConfigurationAccess::GetProperty(rxProperties
, "Anchor") >>= pDescriptor
->msAnchor
;
758 PresenterConfigurationAccess::GetProperty(rxProperties
, "XOffset") >>= pDescriptor
->mnXOffset
;
759 PresenterConfigurationAccess::GetProperty(rxProperties
, "YOffset") >>= pDescriptor
->mnYOffset
;
764 Any
ReadContext::GetByName (
765 const Reference
<container::XNameAccess
>& rxNode
,
766 const OUString
& rsName
) const
768 OSL_ASSERT(rxNode
.is());
769 if (rxNode
->hasByName(rsName
))
770 return rxNode
->getByName(rsName
);
775 ::boost::shared_ptr
<PresenterTheme::Theme
> ReadContext::ReadTheme (
776 PresenterConfigurationAccess
& rConfiguration
,
777 const OUString
& rsThemeName
)
779 ::boost::shared_ptr
<PresenterTheme::Theme
> pTheme
;
781 OUString
sCurrentThemeName (rsThemeName
);
782 if (sCurrentThemeName
.isEmpty())
784 // No theme name given. Look up the CurrentTheme property.
785 rConfiguration
.GetConfigurationNode("Presenter/CurrentTheme") >>= sCurrentThemeName
;
786 if (sCurrentThemeName
.isEmpty())
788 // Still no name. Use "DefaultTheme".
789 sCurrentThemeName
= "DefaultTheme";
793 Reference
<container::XNameAccess
> xThemes (
794 rConfiguration
.GetConfigurationNode("Presenter/Themes"),
798 // Iterate over all themes and search the one with the given name.
799 Sequence
<OUString
> aKeys (xThemes
->getElementNames());
800 for (sal_Int32 nItemIndex
=0; nItemIndex
< aKeys
.getLength(); ++nItemIndex
)
802 const OUString
& rsKey (aKeys
[nItemIndex
]);
803 Reference
<container::XHierarchicalNameAccess
> xTheme (
804 xThemes
->getByName(rsKey
), UNO_QUERY
);
808 PresenterConfigurationAccess::GetConfigurationNode(xTheme
, "ThemeName")
810 if (sThemeName
== sCurrentThemeName
)
812 pTheme
.reset(new PresenterTheme::Theme(sThemeName
,xTheme
,rsKey
));
819 if (pTheme
.get() != NULL
)
821 pTheme
->Read(rConfiguration
, *this);
827 BorderSize
ReadContext::ReadBorderSize (const Reference
<container::XNameAccess
>& rxNode
)
829 BorderSize aBorderSize
;
833 GetByName(rxNode
, "Left") >>= aBorderSize
.mnLeft
;
834 GetByName(rxNode
, "Top") >>= aBorderSize
.mnTop
;
835 GetByName(rxNode
, "Right") >>= aBorderSize
.mnRight
;
836 GetByName(rxNode
, "Bottom") >>= aBorderSize
.mnBottom
;
842 //===== PaneStyleContainer ====================================================
844 void PaneStyleContainer::Read (
845 ReadContext
& rReadContext
,
846 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
848 Reference
<container::XNameAccess
> xPaneStyleList (
849 PresenterConfigurationAccess::GetConfigurationNode(
853 if (xPaneStyleList
.is())
855 ::std::vector
<OUString
> aProperties
;
856 aProperties
.reserve(6);
857 aProperties
.push_back("StyleName");
858 aProperties
.push_back("ParentStyle");
859 aProperties
.push_back("TitleFont");
860 aProperties
.push_back("InnerBorderSize");
861 aProperties
.push_back("OuterBorderSize");
862 aProperties
.push_back("BorderBitmapList");
863 PresenterConfigurationAccess::ForAll(
866 ::boost::bind(&PaneStyleContainer::ProcessPaneStyle
,
867 this, ::boost::ref(rReadContext
), _1
, _2
));
871 void PaneStyleContainer::ProcessPaneStyle(
872 ReadContext
& rReadContext
,
873 const OUString
& rsKey
,
874 const ::std::vector
<Any
>& rValues
)
878 if (rValues
.size() != 6)
881 ::boost::shared_ptr
<PaneStyle
> pStyle (new PaneStyle());
883 rValues
[0] >>= pStyle
->msStyleName
;
885 OUString sParentStyleName
;
886 if (rValues
[1] >>= sParentStyleName
)
888 // Find parent style.
889 PaneStyleContainer::const_iterator iStyle
;
890 for (iStyle
=begin(); iStyle
!=end(); ++iStyle
)
891 if ((*iStyle
)->msStyleName
.equals(sParentStyleName
))
893 pStyle
->mpParentStyle
= *iStyle
;
898 Reference
<container::XHierarchicalNameAccess
> xFontNode (rValues
[2], UNO_QUERY
);
899 pStyle
->mpFont
= rReadContext
.ReadFont(
900 xFontNode
, "", PresenterTheme::SharedFontDescriptor());
902 Reference
<container::XNameAccess
> xInnerBorderSizeNode (rValues
[3], UNO_QUERY
);
903 pStyle
->maInnerBorderSize
= rReadContext
.ReadBorderSize(xInnerBorderSizeNode
);
904 Reference
<container::XNameAccess
> xOuterBorderSizeNode (rValues
[4], UNO_QUERY
);
905 pStyle
->maOuterBorderSize
= rReadContext
.ReadBorderSize(xOuterBorderSizeNode
);
907 if (pStyle
->mpParentStyle
.get() != NULL
)
909 pStyle
->maInnerBorderSize
.Merge(pStyle
->mpParentStyle
->maInnerBorderSize
);
910 pStyle
->maOuterBorderSize
.Merge(pStyle
->mpParentStyle
->maOuterBorderSize
);
913 if (rReadContext
.mxCanvas
.is())
915 Reference
<container::XNameAccess
> xBitmapsNode (rValues
[5], UNO_QUERY
);
916 pStyle
->mpBitmaps
.reset(new PresenterBitmapContainer(
918 pStyle
->mpParentStyle
.get()!=NULL
919 ? pStyle
->mpParentStyle
->mpBitmaps
920 : ::boost::shared_ptr
<PresenterBitmapContainer
>(),
921 rReadContext
.mxComponentContext
,
922 rReadContext
.mxCanvas
,
923 rReadContext
.mxPresenterHelper
));
929 SharedPaneStyle
PaneStyleContainer::GetPaneStyle (const OUString
& rsStyleName
) const
931 const_iterator
iEnd (end());
932 for (const_iterator iStyle
=begin(); iStyle
!=iEnd
; ++iStyle
)
933 if ((*iStyle
)->msStyleName
== rsStyleName
)
935 return SharedPaneStyle();
938 //===== PaneStyle =============================================================
940 PaneStyle::PaneStyle (void)
950 PaneStyle::~PaneStyle (void)
954 void PaneStyle::UpdateBorderSize (BorderSize
& rBorderSize
, bool bInner
)
956 if (mpParentStyle
.get() != NULL
)
957 mpParentStyle
->UpdateBorderSize(rBorderSize
, bInner
);
959 BorderSize
& rThisBorderSize (bInner
? maInnerBorderSize
: maOuterBorderSize
);
960 if (rThisBorderSize
.mnLeft
>= 0)
961 rBorderSize
.mnLeft
= rThisBorderSize
.mnLeft
;
962 if (rThisBorderSize
.mnTop
>= 0)
963 rBorderSize
.mnTop
= rThisBorderSize
.mnTop
;
964 if (rThisBorderSize
.mnRight
>= 0)
965 rBorderSize
.mnRight
= rThisBorderSize
.mnRight
;
966 if (rThisBorderSize
.mnBottom
>= 0)
967 rBorderSize
.mnBottom
= rThisBorderSize
.mnBottom
;
970 const SharedBitmapDescriptor
PaneStyle::GetBitmap (const OUString
& rsBitmapName
) const
972 if (mpBitmaps
.get() != NULL
)
974 const SharedBitmapDescriptor pBitmap
= mpBitmaps
->GetBitmap(rsBitmapName
);
975 if (pBitmap
.get() != NULL
)
979 if (mpParentStyle
.get() != NULL
)
980 return mpParentStyle
->GetBitmap(rsBitmapName
);
982 return SharedBitmapDescriptor();
985 PresenterTheme::SharedFontDescriptor
PaneStyle::GetFont (void) const
987 if (mpFont
.get() != NULL
)
989 else if (mpParentStyle
.get() != NULL
)
990 return mpParentStyle
->GetFont();
992 return PresenterTheme::SharedFontDescriptor();
995 //===== ViewStyleContainer ====================================================
997 void ViewStyleContainer::Read (
998 ReadContext
& rReadContext
,
999 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
1003 Reference
<container::XNameAccess
> xViewStyleList (
1004 PresenterConfigurationAccess::GetConfigurationNode(
1008 if (xViewStyleList
.is())
1010 PresenterConfigurationAccess::ForAll(
1012 ::boost::bind(&ViewStyleContainer::ProcessViewStyle
,
1013 this, ::boost::ref(rReadContext
), _2
));
1017 void ViewStyleContainer::ProcessViewStyle(
1018 ReadContext
& rReadContext
,
1019 const Reference
<beans::XPropertySet
>& rxProperties
)
1021 ::boost::shared_ptr
<ViewStyle
> pStyle (new ViewStyle());
1023 PresenterConfigurationAccess::GetProperty(rxProperties
, "StyleName")
1024 >>= pStyle
->msStyleName
;
1026 OUString sParentStyleName
;
1027 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "ParentStyle")
1028 >>= sParentStyleName
)
1030 // Find parent style.
1031 ViewStyleContainer::const_iterator iStyle
;
1032 for (iStyle
=begin(); iStyle
!=end(); ++iStyle
)
1033 if ((*iStyle
)->msStyleName
.equals(sParentStyleName
))
1035 pStyle
->mpParentStyle
= *iStyle
;
1036 pStyle
->mpFont
= (*iStyle
)->mpFont
;
1037 pStyle
->mpBackground
= (*iStyle
)->mpBackground
;
1042 const OUString sPathToFont
; // empty string
1043 Reference
<container::XHierarchicalNameAccess
> xFontNode (
1044 PresenterConfigurationAccess::GetProperty(rxProperties
, "Font"), UNO_QUERY
);
1045 PresenterTheme::SharedFontDescriptor
pFont (
1046 rReadContext
.ReadFont(xFontNode
, sPathToFont
, PresenterTheme::SharedFontDescriptor()));
1047 if (pFont
.get() != NULL
)
1048 pStyle
->mpFont
= pFont
;
1050 Reference
<container::XHierarchicalNameAccess
> xBackgroundNode (
1051 PresenterConfigurationAccess::GetProperty(rxProperties
, "Background"),
1053 SharedBitmapDescriptor
pBackground (PresenterBitmapContainer::LoadBitmap(
1056 rReadContext
.mxPresenterHelper
,
1057 rReadContext
.mxCanvas
,
1058 SharedBitmapDescriptor()));
1059 if (pBackground
.get() != NULL
&& pBackground
->GetNormalBitmap().is())
1060 pStyle
->mpBackground
= pBackground
;
1065 SharedViewStyle
ViewStyleContainer::GetViewStyle (const OUString
& rsStyleName
) const
1067 const_iterator
iEnd (end());
1068 for (const_iterator iStyle
=begin(); iStyle
!=iEnd
; ++iStyle
)
1069 if ((*iStyle
)->msStyleName
== rsStyleName
)
1071 return SharedViewStyle();
1074 //===== ViewStyle =============================================================
1076 ViewStyle::ViewStyle (void)
1084 ViewStyle::~ViewStyle (void)
1088 const SharedBitmapDescriptor
ViewStyle::GetBitmap (const OUString
& rsBitmapName
) const
1090 if (rsBitmapName
== "Background")
1091 return mpBackground
;
1093 return SharedBitmapDescriptor();
1096 PresenterTheme::SharedFontDescriptor
ViewStyle::GetFont (void) const
1098 if (mpFont
.get() != NULL
)
1100 else if (mpParentStyle
.get() != NULL
)
1101 return mpParentStyle
->GetFont();
1103 return PresenterTheme::SharedFontDescriptor();
1106 //===== StyleAssociationContainer =============================================
1108 void StyleAssociationContainer::Read (
1109 ReadContext
& rReadContext
,
1110 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
1112 Reference
<container::XNameAccess
> xStyleAssociationList (
1113 PresenterConfigurationAccess::GetConfigurationNode(
1115 "StyleAssociations"),
1117 if (xStyleAssociationList
.is())
1119 ::std::vector
<OUString
> aProperties (2);
1120 aProperties
[0] = "ResourceURL";
1121 aProperties
[1] = "StyleName";
1122 PresenterConfigurationAccess::ForAll(
1123 xStyleAssociationList
,
1125 ::boost::bind(&StyleAssociationContainer::ProcessStyleAssociation
,
1126 this, ::boost::ref(rReadContext
), _1
, _2
));
1130 OUString
StyleAssociationContainer::GetStyleName (const OUString
& rsResourceName
) const
1132 StyleAssociations::const_iterator
iAssociation (maStyleAssociations
.find(rsResourceName
));
1133 if (iAssociation
!= maStyleAssociations
.end())
1134 return iAssociation
->second
;
1139 void StyleAssociationContainer::ProcessStyleAssociation(
1140 ReadContext
& rReadContext
,
1141 const OUString
& rsKey
,
1142 const ::std::vector
<Any
>& rValues
)
1147 if (rValues
.size() != 2)
1150 OUString sResourceURL
;
1151 OUString sStyleName
;
1152 if ((rValues
[0] >>= sResourceURL
)
1153 && (rValues
[1] >>= sStyleName
))
1155 maStyleAssociations
[sResourceURL
] = sStyleName
;
1159 } // end of anonymous namespace
1161 } } // end of namespace ::sdext::presenter
1163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */