1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterTheme.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterTheme.hxx"
36 #include "PresenterBitmapContainer.hxx"
37 #include "PresenterCanvasHelper.hxx"
38 #include "PresenterComponent.hxx"
39 #include "PresenterConfigurationAccess.hxx"
40 #include "PresenterHelper.hxx"
41 #include <com/sun/star/awt/Point.hpp>
42 #include <com/sun/star/beans/UnknownPropertyException.hpp>
43 #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
44 #include <com/sun/star/drawing/XPresenterHelper.hpp>
45 #include <com/sun/star/lang/IllegalArgumentException.hpp>
46 #include <com/sun/star/rendering/PanoseWeight.hpp>
47 #include <com/sun/star/rendering/XBitmap.hpp>
48 #include <com/sun/star/util/Color.hpp>
49 #include <boost/bind.hpp>
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::uno
;
54 using namespace ::std
;
55 using ::rtl::OUString
;
57 #define A2S(s) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)))
59 namespace sdext
{ namespace presenter
{
66 const static sal_Int32 mnInvalidValue
= -10000;
68 BorderSize (void) : mnLeft(mnInvalidValue
),
69 mnTop(mnInvalidValue
),
70 mnRight(mnInvalidValue
),
71 mnBottom(mnInvalidValue
) {}
78 vector
<sal_Int32
> ToVector (void)
80 vector
<sal_Int32
> aSequence (4);
81 aSequence
[0] = mnLeft
== mnInvalidValue
? 0 : mnLeft
;
82 aSequence
[1] = mnTop
== mnInvalidValue
? 0 : mnTop
;
83 aSequence
[2] = mnRight
== mnInvalidValue
? 0 : mnRight
;
84 aSequence
[3] = mnBottom
== mnInvalidValue
? 0 : mnBottom
;
89 void Merge (const BorderSize
& rBorderSize
)
91 if (mnLeft
== mnInvalidValue
)
92 mnLeft
= rBorderSize
.mnLeft
;
93 if (mnTop
== mnInvalidValue
)
94 mnTop
= rBorderSize
.mnTop
;
95 if (mnRight
== mnInvalidValue
)
96 mnRight
= rBorderSize
.mnRight
;
97 if (mnBottom
== mnInvalidValue
)
98 mnBottom
= rBorderSize
.mnBottom
;
103 /** Reading a theme from the configurations is done in various classes. The
104 ReadContext gives access to frequently used objects and functions to make
105 the configuration handling easier.
110 Reference
<XComponentContext
> mxComponentContext
;
111 Reference
<rendering::XCanvas
> mxCanvas
;
112 Reference
<drawing::XPresenterHelper
> mxPresenterHelper
;
116 const Reference
<XComponentContext
>& rxContext
,
117 const Reference
<rendering::XCanvas
>& rxCanvas
);
120 /** Read data describing a font from the node that can be reached from
121 the given root via the given path.
125 static PresenterTheme::SharedFontDescriptor
ReadFont (
126 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxTheme
,
127 const ::rtl::OUString
& rsFontPath
,
128 const PresenterTheme::SharedFontDescriptor
& rpDefault
);
129 static PresenterTheme::SharedFontDescriptor
ReadFont (
130 const Reference
<beans::XPropertySet
>& rxFontProperties
,
131 const PresenterTheme::SharedFontDescriptor
& rpDefault
);
133 ::boost::shared_ptr
<PresenterTheme::Theme
> ReadTheme (
134 PresenterConfigurationAccess
& rConfiguration
,
135 const OUString
& rsThemeName
);
137 BorderSize
ReadBorderSize (const Reference
<container::XNameAccess
>& rxNode
);
139 void SetBitmapSourceExtension (const OUString
& rsExtensionName
);
143 const Reference
<container::XNameAccess
>& rxNode
,
144 const OUString
& rsName
) const;
150 /** A PaneStyle describes how a pane is rendered.
158 const SharedBitmapDescriptor
GetBitmap (const OUString
& sBitmapName
) const;
160 OUString msStyleName
;
161 ::boost::shared_ptr
<PaneStyle
> mpParentStyle
;
162 PresenterTheme::SharedFontDescriptor mpFont
;
163 BorderSize maInnerBorderSize
;
164 BorderSize maOuterBorderSize
;
165 ::boost::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
167 PresenterTheme::SharedFontDescriptor
GetFont (void) const;
171 void UpdateBorderSize (BorderSize
& rBorderSize
, bool bInner
);
174 typedef ::boost::shared_ptr
<PaneStyle
> SharedPaneStyle
;
179 class PaneStyleContainer
: vector
<SharedPaneStyle
>
183 ReadContext
& rReadContext
,
184 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
186 SharedPaneStyle
GetPaneStyle (const OUString
& rsStyleName
) const;
189 void ProcessPaneStyle (
190 ReadContext
& rReadContext
,
191 const ::rtl::OUString
& rsKey
,
192 const ::std::vector
<css::uno::Any
>& rValues
);
198 /** A ViewStyle describes how a view is displayed.
206 const SharedBitmapDescriptor
GetBitmap (const OUString
& sBitmapName
) const;
208 PresenterTheme::SharedFontDescriptor
GetFont (void) const;
210 OUString msStyleName
;
211 ::boost::shared_ptr
<ViewStyle
> mpParentStyle
;
212 PresenterTheme::SharedFontDescriptor mpFont
;
213 ::boost::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
214 SharedBitmapDescriptor mpBackground
;
217 typedef ::boost::shared_ptr
<ViewStyle
> SharedViewStyle
;
222 class ViewStyleContainer
: vector
<SharedViewStyle
>
226 ReadContext
& rReadContext
,
227 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
229 SharedViewStyle
GetViewStyle (const OUString
& rsStyleName
) const;
232 void ProcessViewStyle(
233 ReadContext
& rReadContext
,
234 const Reference
<beans::XPropertySet
>& rxProperties
);
243 typedef ::boost::shared_ptr
<ViewDescriptor
> SharedViewDescriptor
;
244 typedef ::std::vector
<SharedViewDescriptor
> ViewDescriptorContainer
;
248 class StyleAssociationContainer
252 ReadContext
& rReadContext
,
253 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
);
255 OUString
GetStyleName (const OUString
& rsResourceName
) const;
258 typedef map
<OUString
, OUString
> StyleAssociations
;
259 StyleAssociations maStyleAssociations
;
261 void ProcessStyleAssociation(
262 ReadContext
& rReadContext
,
263 const ::rtl::OUString
& rsKey
,
264 const ::std::vector
<css::uno::Any
>& rValues
);
267 } // end of anonymous namespace
270 class PresenterTheme::Theme
274 const OUString
& rsName
,
275 const Reference
<container::XHierarchicalNameAccess
>& rThemeRoot
,
276 const OUString
& rsNodeName
);
280 PresenterConfigurationAccess
& rConfiguration
,
281 ReadContext
& rReadContext
);
283 OUString msThemeName
;
284 OUString msConfigurationNodeName
;
285 ::boost::shared_ptr
<Theme
> mpParentTheme
;
286 SharedBitmapDescriptor mpBackground
;
287 PaneStyleContainer maPaneStyles
;
288 ViewStyleContainer maViewStyles
;
289 ViewDescriptorContainer maViewDescriptors
;
290 StyleAssociationContainer maStyleAssociations
;
291 Reference
<container::XHierarchicalNameAccess
> mxThemeRoot
;
292 ::boost::shared_ptr
<PresenterBitmapContainer
> mpIconContainer
;
293 typedef map
<rtl::OUString
,SharedFontDescriptor
> FontContainer
;
294 FontContainer maFontContainer
;
296 SharedPaneStyle
GetPaneStyle (const OUString
& rsStyleName
) const;
297 SharedViewStyle
GetViewStyle (const OUString
& rsStyleName
) const;
301 ReadContext
& rReadContext
,
302 const OUString
& rsKey
,
303 const Reference
<beans::XPropertySet
>& rxProperties
);
309 //===== PresenterTheme ========================================================
311 PresenterTheme::PresenterTheme (
312 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
313 const rtl::OUString
& rsThemeName
,
314 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
)
315 : mxContext(rxContext
),
316 msThemeName(rsThemeName
),
321 mpTheme
= ReadTheme();
327 PresenterTheme::~PresenterTheme (void)
334 void SAL_CALL
PresenterTheme::disposing (void)
341 ::boost::shared_ptr
<PresenterTheme::Theme
> PresenterTheme::ReadTheme (void)
343 ReadContext
aReadContext(mxContext
, mxCanvas
);
345 PresenterConfigurationAccess
aConfiguration (
347 OUString::createFromAscii("/org.openoffice.Office.extension.PresenterScreen/"),
348 PresenterConfigurationAccess::READ_ONLY
);
350 return aReadContext
.ReadTheme(aConfiguration
, msThemeName
);
356 bool PresenterTheme::HasCanvas (void) const
358 return mxCanvas
.is();
364 void PresenterTheme::ProvideCanvas (const Reference
<rendering::XCanvas
>& rxCanvas
)
366 if ( ! mxCanvas
.is() && rxCanvas
.is())
376 OUString
PresenterTheme::GetStyleName (const ::rtl::OUString
& rsResourceURL
) const
379 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
380 while (sStyleName
.getLength()==0 && pTheme
.get()!=NULL
)
382 sStyleName
= pTheme
->maStyleAssociations
.GetStyleName(rsResourceURL
);
383 pTheme
= pTheme
->mpParentTheme
;
391 ::std::vector
<sal_Int32
> PresenterTheme::GetBorderSize (
392 const ::rtl::OUString
& rsStyleName
,
393 const bool bOuter
) const
395 OSL_ASSERT(mpTheme
.get() != NULL
);
397 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
398 if (pPaneStyle
.get() != NULL
)
400 return pPaneStyle
->maOuterBorderSize
.ToVector();
402 return pPaneStyle
->maInnerBorderSize
.ToVector();
405 return ::std::vector
<sal_Int32
>(4,0);
412 PresenterTheme::SharedFontDescriptor
PresenterTheme::ReadFont (
413 const Reference
<container::XHierarchicalNameAccess
>& rxNode
,
414 const OUString
& rsFontPath
,
415 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
417 return ReadContext::ReadFont(rxNode
, rsFontPath
, rpDefault
);
423 bool PresenterTheme::ConvertToColor (
424 const Any
& rColorSequence
,
427 Sequence
<sal_Int8
> aByteSequence
;
428 if (rColorSequence
>>= aByteSequence
)
430 const sal_Int32
nByteCount (aByteSequence
.getLength());
431 const sal_uInt8
* pArray
= reinterpret_cast<const sal_uInt8
*>(aByteSequence
.getConstArray());
433 for (sal_Int32 nIndex
=0; nIndex
<nByteCount
; ++nIndex
)
435 rColor
= (rColor
<< 8) | *pArray
++;
446 ::boost::shared_ptr
<PresenterConfigurationAccess
> PresenterTheme::GetNodeForViewStyle (
447 const ::rtl::OUString
& rsStyleName
,
448 const PresenterConfigurationAccess::WriteMode
) const
450 if (mpTheme
.get() == NULL
)
451 return ::boost::shared_ptr
<PresenterConfigurationAccess
>();
453 // Open configuration for writing.
454 ::boost::shared_ptr
<PresenterConfigurationAccess
> pConfiguration (
455 new PresenterConfigurationAccess(
457 OUString::createFromAscii("/org.openoffice.Office.extension.PresenterScreen/"),
458 PresenterConfigurationAccess::READ_WRITE
));
460 // Get configuration node for the view style container of the current
462 if (pConfiguration
->GoToChild(
463 A2S("Presenter/Themes/") + mpTheme
->msConfigurationNodeName
+ A2S("/ViewStyles")))
465 pConfiguration
->GoToChild(
466 ::boost::bind(&PresenterConfigurationAccess::IsStringPropertyEqual
,
471 return pConfiguration
;
477 ::rtl::OUString
PresenterTheme::GetThemeName (void) const
479 if (mpTheme
.get() != NULL
)
480 return mpTheme
->msThemeName
;
488 SharedBitmapDescriptor
PresenterTheme::GetBitmap (
489 const OUString
& rsStyleName
,
490 const OUString
& rsBitmapName
) const
492 if (mpTheme
.get() != NULL
)
494 if (rsStyleName
.getLength() == 0)
496 if (rsBitmapName
== A2S("Background"))
498 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
499 while (pTheme
.get()!=NULL
&& pTheme
->mpBackground
.get()==NULL
)
500 pTheme
= pTheme
->mpParentTheme
;
501 if (pTheme
.get() != NULL
)
502 return pTheme
->mpBackground
;
504 return SharedBitmapDescriptor();
509 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
510 if (pPaneStyle
.get() != NULL
)
512 SharedBitmapDescriptor
pBitmap (pPaneStyle
->GetBitmap(rsBitmapName
));
513 if (pBitmap
.get() != NULL
)
517 SharedViewStyle
pViewStyle (mpTheme
->GetViewStyle(rsStyleName
));
518 if (pViewStyle
.get() != NULL
)
520 SharedBitmapDescriptor
pBitmap (pViewStyle
->GetBitmap(rsBitmapName
));
521 if (pBitmap
.get() != NULL
)
527 return SharedBitmapDescriptor();
533 SharedBitmapDescriptor
PresenterTheme::GetBitmap (
534 const OUString
& rsBitmapName
) const
536 if (mpTheme
.get() != NULL
)
538 if (rsBitmapName
== A2S("Background"))
540 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
541 while (pTheme
.get()!=NULL
&& pTheme
->mpBackground
.get()==NULL
)
542 pTheme
= pTheme
->mpParentTheme
;
543 if (pTheme
.get() != NULL
)
544 return pTheme
->mpBackground
;
546 return SharedBitmapDescriptor();
550 if (mpTheme
->mpIconContainer
.get() != NULL
)
551 return mpTheme
->mpIconContainer
->GetBitmap(rsBitmapName
);
555 return SharedBitmapDescriptor();
561 ::boost::shared_ptr
<PresenterBitmapContainer
> PresenterTheme::GetBitmapContainer (void) const
563 if (mpTheme
.get() != NULL
)
564 return mpTheme
->mpIconContainer
;
566 return ::boost::shared_ptr
<PresenterBitmapContainer
>();
572 PresenterTheme::SharedFontDescriptor
PresenterTheme::GetFont (
573 const OUString
& rsStyleName
) const
575 if (mpTheme
.get() != NULL
)
577 SharedPaneStyle
pPaneStyle (mpTheme
->GetPaneStyle(rsStyleName
));
578 if (pPaneStyle
.get() != NULL
)
579 return pPaneStyle
->GetFont();
581 SharedViewStyle
pViewStyle (mpTheme
->GetViewStyle(rsStyleName
));
582 if (pViewStyle
.get() != NULL
)
583 return pViewStyle
->GetFont();
585 ::boost::shared_ptr
<Theme
> pTheme (mpTheme
);
586 while (pTheme
.get() != NULL
)
588 Theme::FontContainer::const_iterator
iFont (pTheme
->maFontContainer
.find(rsStyleName
));
589 if (iFont
!= pTheme
->maFontContainer
.end())
590 return iFont
->second
;
592 pTheme
= pTheme
->mpParentTheme
;
596 return SharedFontDescriptor();
602 //===== FontDescriptor ========================================================
604 PresenterTheme::FontDescriptor::FontDescriptor (void)
609 msAnchor(OUString::createFromAscii("Left")),
618 PresenterTheme::FontDescriptor::FontDescriptor (
619 const ::boost::shared_ptr
<FontDescriptor
>& rpDescriptor
)
624 msAnchor(OUString::createFromAscii("Left")),
628 if (rpDescriptor
.get() != NULL
)
630 msFamilyName
= rpDescriptor
->msFamilyName
;
631 msStyleName
= rpDescriptor
->msStyleName
;
632 mnSize
= rpDescriptor
->mnSize
;
633 mnColor
= rpDescriptor
->mnColor
;
634 msAnchor
= rpDescriptor
->msAnchor
;
635 mnXOffset
= rpDescriptor
->mnXOffset
;
636 mnYOffset
= rpDescriptor
->mnYOffset
;
643 bool PresenterTheme::FontDescriptor::PrepareFont (
644 const Reference
<rendering::XCanvas
>& rxCanvas
)
649 if ( ! rxCanvas
.is())
653 const double nCellSize (GetCellSizeForDesignSize(rxCanvas
, mnSize
));
654 mxFont
= CreateFont(rxCanvas
, nCellSize
);
662 Reference
<rendering::XCanvasFont
> PresenterTheme::FontDescriptor::CreateFont (
663 const Reference
<rendering::XCanvas
>& rxCanvas
,
664 const double nCellSize
) const
666 rendering::FontRequest aFontRequest
;
667 aFontRequest
.FontDescription
.FamilyName
= msFamilyName
;
668 if (msFamilyName
.getLength() == 0)
669 aFontRequest
.FontDescription
.FamilyName
= A2S("Tahoma");
670 aFontRequest
.FontDescription
.StyleName
= msStyleName
;
671 aFontRequest
.CellSize
= nCellSize
;
673 // Make an attempt at translating the style name(s)into a corresponding
675 if (msStyleName
== A2S("Bold"))
676 aFontRequest
.FontDescription
.FontDescription
.Weight
= rendering::PanoseWeight::HEAVY
;
678 return rxCanvas
->createFont(
680 Sequence
<beans::PropertyValue
>(),
681 geometry::Matrix2D(1,0,0,1));
687 double PresenterTheme::FontDescriptor::GetCellSizeForDesignSize (
688 const Reference
<rendering::XCanvas
>& rxCanvas
,
689 const double nDesignSize
) const
691 // Use the given design size as initial value in calculating the cell
693 double nCellSize (nDesignSize
);
695 if ( ! rxCanvas
.is())
697 // We need the canvas to do the conversion. Return the design size,
698 // it is the our best guess in this circumstance.
702 Reference
<rendering::XCanvasFont
> xFont (CreateFont(rxCanvas
, nCellSize
));
706 geometry::RealRectangle2D
aBox (PresenterCanvasHelper::GetTextBoundingBox (xFont
, A2S("X")));
708 const double nAscent (-aBox
.Y1
);
709 const double nDescent (aBox
.Y2
);
710 const double nScale
= (nAscent
+nDescent
) / nAscent
;
711 return nDesignSize
* nScale
;
717 //===== Theme =================================================================
719 PresenterTheme::Theme::Theme (
720 const OUString
& rsName
,
721 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
,
722 const OUString
& rsNodeName
)
723 : msThemeName(rsName
),
724 msConfigurationNodeName(rsNodeName
),
728 maStyleAssociations(),
729 mxThemeRoot(rxThemeRoot
),
737 PresenterTheme::Theme::~Theme (void)
744 void PresenterTheme::Theme::Read (
745 PresenterConfigurationAccess
& rConfiguration
,
746 ReadContext
& rReadContext
)
748 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, A2S("ThemeName"))
751 // Parent theme name.
752 OUString sParentThemeName
;
753 if ((PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, A2S("ParentTheme"))
754 >>= sParentThemeName
)
755 && sParentThemeName
.getLength()>0)
757 mpParentTheme
= rReadContext
.ReadTheme(rConfiguration
, sParentThemeName
);
760 // Read the extension that contains the bitmaps referenced in this
762 OUString sBitmapSourceExtension
;
763 if ((PresenterConfigurationAccess::GetConfigurationNode(
764 mxThemeRoot
, A2S("BitmapSourceExtension")) >>= sBitmapSourceExtension
)
765 && sBitmapSourceExtension
.getLength()>0)
767 rReadContext
.SetBitmapSourceExtension(sBitmapSourceExtension
);
771 rReadContext
.SetBitmapSourceExtension(PresenterComponent::gsExtensionIdentifier
);
775 mpBackground
= PresenterBitmapContainer::LoadBitmap(
778 rReadContext
.mxPresenterHelper
,
779 rReadContext
.msBasePath
,
780 rReadContext
.mxCanvas
,
781 SharedBitmapDescriptor());
783 // Style associations.
784 maStyleAssociations
.Read(rReadContext
, mxThemeRoot
);
787 maPaneStyles
.Read(rReadContext
, mxThemeRoot
);
790 maViewStyles
.Read(rReadContext
, mxThemeRoot
);
793 mpIconContainer
.reset(
794 new PresenterBitmapContainer(
795 Reference
<container::XNameAccess
>(
796 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, A2S("Bitmaps")),
798 mpParentTheme
.get()!=NULL
799 ? mpParentTheme
->mpIconContainer
800 : ::boost::shared_ptr
<PresenterBitmapContainer
>(),
801 rReadContext
.mxComponentContext
,
802 rReadContext
.mxCanvas
,
803 rReadContext
.msBasePath
));
806 Reference
<container::XNameAccess
> xFontNode(
807 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot
, A2S("Fonts")),
809 PresenterConfigurationAccess::ForAll(
811 ::boost::bind(&PresenterTheme::Theme::ProcessFont
,
812 this, ::boost::ref(rReadContext
), _1
, _2
));
818 SharedPaneStyle
PresenterTheme::Theme::GetPaneStyle (const OUString
& rsStyleName
) const
820 SharedPaneStyle
pPaneStyle (maPaneStyles
.GetPaneStyle(rsStyleName
));
821 if (pPaneStyle
.get() != NULL
)
823 else if (mpParentTheme
.get() != NULL
)
824 return mpParentTheme
->GetPaneStyle(rsStyleName
);
826 return SharedPaneStyle();
832 SharedViewStyle
PresenterTheme::Theme::GetViewStyle (const OUString
& rsStyleName
) const
834 SharedViewStyle
pViewStyle (maViewStyles
.GetViewStyle(rsStyleName
));
835 if (pViewStyle
.get() != NULL
)
837 else if (mpParentTheme
.get() != NULL
)
838 return mpParentTheme
->GetViewStyle(rsStyleName
);
840 return SharedViewStyle();
846 void PresenterTheme::Theme::ProcessFont(
847 ReadContext
& rReadContext
,
848 const OUString
& rsKey
,
849 const Reference
<beans::XPropertySet
>& rxProperties
)
852 maFontContainer
[rsKey
] = ReadContext::ReadFont(rxProperties
, SharedFontDescriptor());
860 //===== ReadContext ===========================================================
862 ReadContext::ReadContext (
863 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
864 const Reference
<rendering::XCanvas
>& rxCanvas
)
865 : mxComponentContext(rxContext
),
870 Reference
<lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager());
873 mxPresenterHelper
= Reference
<drawing::XPresenterHelper
>(
874 xFactory
->createInstanceWithContext(
875 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
880 // Get base path to bitmaps.
881 SetBitmapSourceExtension(PresenterComponent::gsExtensionIdentifier
);
887 ReadContext::~ReadContext (void)
894 PresenterTheme::SharedFontDescriptor
ReadContext::ReadFont (
895 const Reference
<container::XHierarchicalNameAccess
>& rxNode
,
896 const OUString
& rsFontPath
,
897 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
900 return PresenterTheme::SharedFontDescriptor();
904 Reference
<container::XHierarchicalNameAccess
> xFont (
905 PresenterConfigurationAccess::GetConfigurationNode(
910 Reference
<beans::XPropertySet
> xProperties (xFont
, UNO_QUERY_THROW
);
911 return ReadFont(xProperties
, rpDefault
);
918 return PresenterTheme::SharedFontDescriptor();
924 PresenterTheme::SharedFontDescriptor
ReadContext::ReadFont (
925 const Reference
<beans::XPropertySet
>& rxProperties
,
926 const PresenterTheme::SharedFontDescriptor
& rpDefault
)
928 ::boost::shared_ptr
<PresenterTheme::FontDescriptor
> pDescriptor (
929 new PresenterTheme::FontDescriptor(rpDefault
));
931 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("FamilyName")) >>= pDescriptor
->msFamilyName
;
932 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("Style")) >>= pDescriptor
->msStyleName
;
933 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("Size")) >>= pDescriptor
->mnSize
;
934 PresenterTheme::ConvertToColor(
935 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("Color")),
936 pDescriptor
->mnColor
);
937 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("Anchor")) >>= pDescriptor
->msAnchor
;
938 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("XOffset")) >>= pDescriptor
->mnXOffset
;
939 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("YOffset")) >>= pDescriptor
->mnYOffset
;
947 Any
ReadContext::GetByName (
948 const Reference
<container::XNameAccess
>& rxNode
,
949 const OUString
& rsName
) const
951 OSL_ASSERT(rxNode
.is());
952 if (rxNode
->hasByName(rsName
))
953 return rxNode
->getByName(rsName
);
961 ::boost::shared_ptr
<PresenterTheme::Theme
> ReadContext::ReadTheme (
962 PresenterConfigurationAccess
& rConfiguration
,
963 const OUString
& rsThemeName
)
965 ::boost::shared_ptr
<PresenterTheme::Theme
> pTheme
;
967 OUString
sCurrentThemeName (rsThemeName
);
968 if (sCurrentThemeName
.getLength() == 0)
970 // No theme name given. Look up the CurrentTheme property.
971 rConfiguration
.GetConfigurationNode(A2S("Presenter/CurrentTheme")) >>= sCurrentThemeName
;
972 if (sCurrentThemeName
.getLength() == 0)
974 // Still no name. Use "DefaultTheme".
975 sCurrentThemeName
= A2S("DefaultTheme");
979 Reference
<container::XNameAccess
> xThemes (
980 rConfiguration
.GetConfigurationNode(A2S("Presenter/Themes")),
984 // Iterate over all themes and search the one with the given name.
985 Sequence
<OUString
> aKeys (xThemes
->getElementNames());
986 for (sal_Int32 nItemIndex
=0; nItemIndex
<aKeys
.getLength(); ++nItemIndex
)
988 const OUString
& rsKey (aKeys
[nItemIndex
]);
989 Reference
<container::XHierarchicalNameAccess
> xTheme (
990 xThemes
->getByName(rsKey
), UNO_QUERY
);
994 PresenterConfigurationAccess::GetConfigurationNode(xTheme
, A2S("ThemeName"))
996 if (sThemeName
== sCurrentThemeName
)
998 pTheme
.reset(new PresenterTheme::Theme(sThemeName
,xTheme
,rsKey
));
1005 if (pTheme
.get() != NULL
)
1007 pTheme
->Read(rConfiguration
, *this);
1016 BorderSize
ReadContext::ReadBorderSize (const Reference
<container::XNameAccess
>& rxNode
)
1018 BorderSize aBorderSize
;
1022 GetByName(rxNode
, A2S("Left")) >>= aBorderSize
.mnLeft
;
1023 GetByName(rxNode
, A2S("Top")) >>= aBorderSize
.mnTop
;
1024 GetByName(rxNode
, A2S("Right")) >>= aBorderSize
.mnRight
;
1025 GetByName(rxNode
, A2S("Bottom")) >>= aBorderSize
.mnBottom
;
1034 void ReadContext::SetBitmapSourceExtension (const OUString
& rsExtensionIdentifier
)
1036 // Get base path to bitmaps.
1037 msBasePath
= PresenterComponent::GetBasePath(mxComponentContext
, rsExtensionIdentifier
);
1043 //===== PaneStyleContainer ====================================================
1045 void PaneStyleContainer::Read (
1046 ReadContext
& rReadContext
,
1047 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
1049 Reference
<container::XNameAccess
> xPaneStyleList (
1050 PresenterConfigurationAccess::GetConfigurationNode(
1054 if (xPaneStyleList
.is())
1056 ::std::vector
<rtl::OUString
> aProperties
;
1057 aProperties
.reserve(6);
1058 aProperties
.push_back(A2S("StyleName"));
1059 aProperties
.push_back(A2S("ParentStyle"));
1060 aProperties
.push_back(A2S("TitleFont"));
1061 aProperties
.push_back(A2S("InnerBorderSize"));
1062 aProperties
.push_back(A2S("OuterBorderSize"));
1063 aProperties
.push_back(A2S("BorderBitmapList"));
1064 PresenterConfigurationAccess::ForAll(
1067 ::boost::bind(&PaneStyleContainer::ProcessPaneStyle
,
1068 this, ::boost::ref(rReadContext
), _1
, _2
));
1075 void PaneStyleContainer::ProcessPaneStyle(
1076 ReadContext
& rReadContext
,
1077 const OUString
& rsKey
,
1078 const ::std::vector
<Any
>& rValues
)
1082 if (rValues
.size() != 6)
1085 ::boost::shared_ptr
<PaneStyle
> pStyle (new PaneStyle());
1087 rValues
[0] >>= pStyle
->msStyleName
;
1089 OUString sParentStyleName
;
1090 if (rValues
[1] >>= sParentStyleName
)
1092 // Find parent style.
1093 PaneStyleContainer::const_iterator iStyle
;
1094 for (iStyle
=begin(); iStyle
!=end(); ++iStyle
)
1095 if ((*iStyle
)->msStyleName
.equals(sParentStyleName
))
1097 pStyle
->mpParentStyle
= *iStyle
;
1102 Reference
<container::XHierarchicalNameAccess
> xFontNode (rValues
[2], UNO_QUERY
);
1103 pStyle
->mpFont
= rReadContext
.ReadFont(
1104 xFontNode
, A2S(""), PresenterTheme::SharedFontDescriptor());
1106 Reference
<container::XNameAccess
> xInnerBorderSizeNode (rValues
[3], UNO_QUERY
);
1107 pStyle
->maInnerBorderSize
= rReadContext
.ReadBorderSize(xInnerBorderSizeNode
);
1108 Reference
<container::XNameAccess
> xOuterBorderSizeNode (rValues
[4], UNO_QUERY
);
1109 pStyle
->maOuterBorderSize
= rReadContext
.ReadBorderSize(xOuterBorderSizeNode
);
1111 if (pStyle
->mpParentStyle
.get() != NULL
)
1113 pStyle
->maInnerBorderSize
.Merge(pStyle
->mpParentStyle
->maInnerBorderSize
);
1114 pStyle
->maOuterBorderSize
.Merge(pStyle
->mpParentStyle
->maOuterBorderSize
);
1117 if (rReadContext
.mxCanvas
.is())
1119 Reference
<container::XNameAccess
> xBitmapsNode (rValues
[5], UNO_QUERY
);
1120 pStyle
->mpBitmaps
.reset(new PresenterBitmapContainer(
1122 pStyle
->mpParentStyle
.get()!=NULL
1123 ? pStyle
->mpParentStyle
->mpBitmaps
1124 : ::boost::shared_ptr
<PresenterBitmapContainer
>(),
1125 rReadContext
.mxComponentContext
,
1126 rReadContext
.mxCanvas
,
1127 rReadContext
.msBasePath
,
1128 rReadContext
.mxPresenterHelper
));
1137 SharedPaneStyle
PaneStyleContainer::GetPaneStyle (const OUString
& rsStyleName
) const
1139 const_iterator
iEnd (end());
1140 for (const_iterator iStyle
=begin(); iStyle
!=iEnd
; ++iStyle
)
1141 if ((*iStyle
)->msStyleName
== rsStyleName
)
1143 return SharedPaneStyle();
1149 //===== PaneStyle =============================================================
1151 PaneStyle::PaneStyle (void)
1155 maInnerBorderSize(),
1156 maOuterBorderSize(),
1164 PaneStyle::~PaneStyle (void)
1171 void PaneStyle::UpdateBorderSize (BorderSize
& rBorderSize
, bool bInner
)
1173 if (mpParentStyle
.get() != NULL
)
1174 mpParentStyle
->UpdateBorderSize(rBorderSize
, bInner
);
1176 BorderSize
& rThisBorderSize (bInner
? maInnerBorderSize
: maOuterBorderSize
);
1177 if (rThisBorderSize
.mnLeft
>= 0)
1178 rBorderSize
.mnLeft
= rThisBorderSize
.mnLeft
;
1179 if (rThisBorderSize
.mnTop
>= 0)
1180 rBorderSize
.mnTop
= rThisBorderSize
.mnTop
;
1181 if (rThisBorderSize
.mnRight
>= 0)
1182 rBorderSize
.mnRight
= rThisBorderSize
.mnRight
;
1183 if (rThisBorderSize
.mnBottom
>= 0)
1184 rBorderSize
.mnBottom
= rThisBorderSize
.mnBottom
;
1190 const SharedBitmapDescriptor
PaneStyle::GetBitmap (const OUString
& rsBitmapName
) const
1192 if (mpBitmaps
.get() != NULL
)
1194 const SharedBitmapDescriptor pBitmap
= mpBitmaps
->GetBitmap(rsBitmapName
);
1195 if (pBitmap
.get() != NULL
)
1199 if (mpParentStyle
.get() != NULL
)
1200 return mpParentStyle
->GetBitmap(rsBitmapName
);
1202 return SharedBitmapDescriptor();
1208 PresenterTheme::SharedFontDescriptor
PaneStyle::GetFont (void) const
1210 if (mpFont
.get() != NULL
)
1212 else if (mpParentStyle
.get() != NULL
)
1213 return mpParentStyle
->GetFont();
1215 return PresenterTheme::SharedFontDescriptor();
1221 //===== ViewStyleContainer ====================================================
1223 void ViewStyleContainer::Read (
1224 ReadContext
& rReadContext
,
1225 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
1229 Reference
<container::XNameAccess
> xViewStyleList (
1230 PresenterConfigurationAccess::GetConfigurationNode(
1234 if (xViewStyleList
.is())
1236 PresenterConfigurationAccess::ForAll(
1238 ::boost::bind(&ViewStyleContainer::ProcessViewStyle
,
1239 this, ::boost::ref(rReadContext
), _2
));
1246 void ViewStyleContainer::ProcessViewStyle(
1247 ReadContext
& rReadContext
,
1248 const Reference
<beans::XPropertySet
>& rxProperties
)
1250 ::boost::shared_ptr
<ViewStyle
> pStyle (new ViewStyle());
1252 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("StyleName"))
1253 >>= pStyle
->msStyleName
;
1255 OUString sParentStyleName
;
1256 if (PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("ParentStyle"))
1257 >>= sParentStyleName
)
1259 // Find parent style.
1260 ViewStyleContainer::const_iterator iStyle
;
1261 for (iStyle
=begin(); iStyle
!=end(); ++iStyle
)
1262 if ((*iStyle
)->msStyleName
.equals(sParentStyleName
))
1264 pStyle
->mpParentStyle
= *iStyle
;
1265 pStyle
->mpFont
= (*iStyle
)->mpFont
;
1266 pStyle
->mpBackground
= (*iStyle
)->mpBackground
;
1271 const OUString sPathToFont
; // empty string
1272 Reference
<container::XHierarchicalNameAccess
> xFontNode (
1273 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("Font")), UNO_QUERY
);
1274 PresenterTheme::SharedFontDescriptor
pFont (
1275 rReadContext
.ReadFont(xFontNode
, sPathToFont
, PresenterTheme::SharedFontDescriptor()));
1276 if (pFont
.get() != NULL
)
1277 pStyle
->mpFont
= pFont
;
1279 Reference
<container::XHierarchicalNameAccess
> xBackgroundNode (
1280 PresenterConfigurationAccess::GetProperty(rxProperties
, A2S("Background")),
1282 SharedBitmapDescriptor
pBackground (PresenterBitmapContainer::LoadBitmap(
1285 rReadContext
.mxPresenterHelper
,
1286 rReadContext
.msBasePath
,
1287 rReadContext
.mxCanvas
,
1288 SharedBitmapDescriptor()));
1289 if (pBackground
.get() != NULL
&& pBackground
->GetNormalBitmap().is())
1290 pStyle
->mpBackground
= pBackground
;
1298 SharedViewStyle
ViewStyleContainer::GetViewStyle (const OUString
& rsStyleName
) const
1300 const_iterator
iEnd (end());
1301 for (const_iterator iStyle
=begin(); iStyle
!=iEnd
; ++iStyle
)
1302 if ((*iStyle
)->msStyleName
== rsStyleName
)
1304 return SharedViewStyle();
1310 //===== ViewStyle =============================================================
1312 ViewStyle::ViewStyle (void)
1323 ViewStyle::~ViewStyle (void)
1330 const SharedBitmapDescriptor
ViewStyle::GetBitmap (const OUString
& rsBitmapName
) const
1332 if (rsBitmapName
== A2S("Background"))
1333 return mpBackground
;
1335 return SharedBitmapDescriptor();
1341 PresenterTheme::SharedFontDescriptor
ViewStyle::GetFont (void) const
1343 if (mpFont
.get() != NULL
)
1345 else if (mpParentStyle
.get() != NULL
)
1346 return mpParentStyle
->GetFont();
1348 return PresenterTheme::SharedFontDescriptor();
1354 //===== StyleAssociationContainer =============================================
1356 void StyleAssociationContainer::Read (
1357 ReadContext
& rReadContext
,
1358 const Reference
<container::XHierarchicalNameAccess
>& rxThemeRoot
)
1360 Reference
<container::XNameAccess
> xStyleAssociationList (
1361 PresenterConfigurationAccess::GetConfigurationNode(
1363 A2S("StyleAssociations")),
1365 if (xStyleAssociationList
.is())
1367 ::std::vector
<rtl::OUString
> aProperties (2);
1368 aProperties
[0] = A2S("ResourceURL");
1369 aProperties
[1] = A2S("StyleName");
1370 PresenterConfigurationAccess::ForAll(
1371 xStyleAssociationList
,
1373 ::boost::bind(&StyleAssociationContainer::ProcessStyleAssociation
,
1374 this, ::boost::ref(rReadContext
), _1
, _2
));
1381 OUString
StyleAssociationContainer::GetStyleName (const OUString
& rsResourceName
) const
1383 StyleAssociations::const_iterator
iAssociation (maStyleAssociations
.find(rsResourceName
));
1384 if (iAssociation
!= maStyleAssociations
.end())
1385 return iAssociation
->second
;
1393 void StyleAssociationContainer::ProcessStyleAssociation(
1394 ReadContext
& rReadContext
,
1395 const OUString
& rsKey
,
1396 const ::std::vector
<Any
>& rValues
)
1401 if (rValues
.size() != 2)
1404 OUString sResourceURL
;
1405 OUString sStyleName
;
1406 if ((rValues
[0] >>= sResourceURL
)
1407 && (rValues
[1] >>= sStyleName
))
1409 maStyleAssociations
[sResourceURL
] = sStyleName
;
1416 } // end of anonymous namespace
1418 } } // end of namespace ::sdext::presenter