xref: /AOO41X/main/sdext/source/presenter/PresenterTheme.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sdext.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "PresenterTheme.hxx"
32*cdf0e10cSrcweir #include "PresenterBitmapContainer.hxx"
33*cdf0e10cSrcweir #include "PresenterCanvasHelper.hxx"
34*cdf0e10cSrcweir #include "PresenterComponent.hxx"
35*cdf0e10cSrcweir #include "PresenterConfigurationAccess.hxx"
36*cdf0e10cSrcweir #include "PresenterHelper.hxx"
37*cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/drawing/XPresenterHelper.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/rendering/PanoseWeight.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/rendering/XBitmap.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/util/Color.hpp>
45*cdf0e10cSrcweir #include <boost/bind.hpp>
46*cdf0e10cSrcweir #include <map>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace ::com::sun::star;
49*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50*cdf0e10cSrcweir using namespace ::std;
51*cdf0e10cSrcweir using ::rtl::OUString;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #define A2S(s) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)))
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace sdext { namespace presenter {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir namespace {
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir class BorderSize
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir public:
62*cdf0e10cSrcweir     const static sal_Int32 mnInvalidValue = -10000;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     BorderSize (void) : mnLeft(mnInvalidValue),
65*cdf0e10cSrcweir                         mnTop(mnInvalidValue),
66*cdf0e10cSrcweir                         mnRight(mnInvalidValue),
67*cdf0e10cSrcweir                         mnBottom(mnInvalidValue) {}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     sal_Int32 mnLeft;
70*cdf0e10cSrcweir     sal_Int32 mnTop;
71*cdf0e10cSrcweir     sal_Int32 mnRight;
72*cdf0e10cSrcweir     sal_Int32 mnBottom;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     vector<sal_Int32> ToVector (void)
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         vector<sal_Int32> aSequence (4);
77*cdf0e10cSrcweir         aSequence[0] = mnLeft == mnInvalidValue ? 0 : mnLeft;
78*cdf0e10cSrcweir         aSequence[1] = mnTop == mnInvalidValue ? 0 : mnTop;
79*cdf0e10cSrcweir         aSequence[2] = mnRight == mnInvalidValue ? 0 : mnRight;
80*cdf0e10cSrcweir         aSequence[3] = mnBottom == mnInvalidValue ? 0 : mnBottom;
81*cdf0e10cSrcweir         return aSequence;
82*cdf0e10cSrcweir     };
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     void Merge (const BorderSize& rBorderSize)
86*cdf0e10cSrcweir     {
87*cdf0e10cSrcweir         if (mnLeft == mnInvalidValue)
88*cdf0e10cSrcweir             mnLeft = rBorderSize.mnLeft;
89*cdf0e10cSrcweir         if (mnTop == mnInvalidValue)
90*cdf0e10cSrcweir             mnTop = rBorderSize.mnTop;
91*cdf0e10cSrcweir         if (mnRight == mnInvalidValue)
92*cdf0e10cSrcweir             mnRight = rBorderSize.mnRight;
93*cdf0e10cSrcweir         if (mnBottom == mnInvalidValue)
94*cdf0e10cSrcweir             mnBottom = rBorderSize.mnBottom;
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir };
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir /** Reading a theme from the configurations is done in various classes.  The
100*cdf0e10cSrcweir     ReadContext gives access to frequently used objects and functions to make
101*cdf0e10cSrcweir     the configuration handling easier.
102*cdf0e10cSrcweir */
103*cdf0e10cSrcweir class ReadContext
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir public:
106*cdf0e10cSrcweir     Reference<XComponentContext> mxComponentContext;
107*cdf0e10cSrcweir     Reference<rendering::XCanvas> mxCanvas;
108*cdf0e10cSrcweir     Reference<drawing::XPresenterHelper> mxPresenterHelper;
109*cdf0e10cSrcweir     OUString msBasePath;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     ReadContext (
112*cdf0e10cSrcweir         const Reference<XComponentContext>& rxContext,
113*cdf0e10cSrcweir         const Reference<rendering::XCanvas>& rxCanvas);
114*cdf0e10cSrcweir     ~ReadContext (void);
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     /** Read data describing a font from the node that can be reached from
117*cdf0e10cSrcweir         the given root via the given path.
118*cdf0e10cSrcweir         @param rsFontPath
119*cdf0e10cSrcweir             May be empty.
120*cdf0e10cSrcweir     */
121*cdf0e10cSrcweir     static PresenterTheme::SharedFontDescriptor ReadFont (
122*cdf0e10cSrcweir         const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxTheme,
123*cdf0e10cSrcweir         const ::rtl::OUString& rsFontPath,
124*cdf0e10cSrcweir         const PresenterTheme::SharedFontDescriptor& rpDefault);
125*cdf0e10cSrcweir     static PresenterTheme::SharedFontDescriptor ReadFont (
126*cdf0e10cSrcweir         const Reference<beans::XPropertySet>& rxFontProperties,
127*cdf0e10cSrcweir         const PresenterTheme::SharedFontDescriptor& rpDefault);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterTheme::Theme> ReadTheme (
130*cdf0e10cSrcweir         PresenterConfigurationAccess& rConfiguration,
131*cdf0e10cSrcweir         const OUString& rsThemeName);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     BorderSize ReadBorderSize (const Reference<container::XNameAccess>& rxNode);
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     void SetBitmapSourceExtension (const OUString& rsExtensionName);
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir private:
138*cdf0e10cSrcweir     Any GetByName (
139*cdf0e10cSrcweir         const Reference<container::XNameAccess>& rxNode,
140*cdf0e10cSrcweir         const OUString& rsName) const;
141*cdf0e10cSrcweir };
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir /** A PaneStyle describes how a pane is rendered.
147*cdf0e10cSrcweir */
148*cdf0e10cSrcweir class PaneStyle
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir public:
151*cdf0e10cSrcweir     PaneStyle (void);
152*cdf0e10cSrcweir     ~PaneStyle (void);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     const SharedBitmapDescriptor GetBitmap (const OUString& sBitmapName) const;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     OUString msStyleName;
157*cdf0e10cSrcweir     ::boost::shared_ptr<PaneStyle> mpParentStyle;
158*cdf0e10cSrcweir     PresenterTheme::SharedFontDescriptor mpFont;
159*cdf0e10cSrcweir     BorderSize maInnerBorderSize;
160*cdf0e10cSrcweir     BorderSize maOuterBorderSize;
161*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterBitmapContainer> mpBitmaps;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     PresenterTheme::SharedFontDescriptor GetFont (void) const;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir private:
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     void UpdateBorderSize (BorderSize& rBorderSize, bool bInner);
168*cdf0e10cSrcweir };
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir typedef ::boost::shared_ptr<PaneStyle> SharedPaneStyle;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir class PaneStyleContainer : vector<SharedPaneStyle>
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir public:
178*cdf0e10cSrcweir     void Read (
179*cdf0e10cSrcweir         ReadContext& rReadContext,
180*cdf0e10cSrcweir         const Reference<container::XHierarchicalNameAccess>& rThemeRoot);
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     SharedPaneStyle GetPaneStyle (const OUString& rsStyleName) const;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir private:
185*cdf0e10cSrcweir     void ProcessPaneStyle (
186*cdf0e10cSrcweir         ReadContext& rReadContext,
187*cdf0e10cSrcweir         const ::rtl::OUString& rsKey,
188*cdf0e10cSrcweir         const ::std::vector<css::uno::Any>& rValues);
189*cdf0e10cSrcweir };
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir /** A ViewStyle describes how a view is displayed.
195*cdf0e10cSrcweir */
196*cdf0e10cSrcweir class ViewStyle
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir public:
199*cdf0e10cSrcweir     ViewStyle (void);
200*cdf0e10cSrcweir     ~ViewStyle (void);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     const SharedBitmapDescriptor GetBitmap (const OUString& sBitmapName) const;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     PresenterTheme::SharedFontDescriptor GetFont (void) const;
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     OUString msStyleName;
207*cdf0e10cSrcweir     ::boost::shared_ptr<ViewStyle> mpParentStyle;
208*cdf0e10cSrcweir     PresenterTheme::SharedFontDescriptor mpFont;
209*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterBitmapContainer> mpBitmaps;
210*cdf0e10cSrcweir     SharedBitmapDescriptor mpBackground;
211*cdf0e10cSrcweir };
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir typedef ::boost::shared_ptr<ViewStyle> SharedViewStyle;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir class ViewStyleContainer : vector<SharedViewStyle>
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir public:
221*cdf0e10cSrcweir     void Read (
222*cdf0e10cSrcweir         ReadContext& rReadContext,
223*cdf0e10cSrcweir         const Reference<container::XHierarchicalNameAccess>& rThemeRoot);
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     SharedViewStyle GetViewStyle (const OUString& rsStyleName) const;
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir private:
228*cdf0e10cSrcweir     void ProcessViewStyle(
229*cdf0e10cSrcweir         ReadContext& rReadContext,
230*cdf0e10cSrcweir         const Reference<beans::XPropertySet>& rxProperties);
231*cdf0e10cSrcweir };
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir class ViewDescriptor
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir };
239*cdf0e10cSrcweir typedef ::boost::shared_ptr<ViewDescriptor> SharedViewDescriptor;
240*cdf0e10cSrcweir typedef ::std::vector<SharedViewDescriptor> ViewDescriptorContainer;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir class StyleAssociationContainer
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir public:
247*cdf0e10cSrcweir     void Read (
248*cdf0e10cSrcweir         ReadContext& rReadContext,
249*cdf0e10cSrcweir         const Reference<container::XHierarchicalNameAccess>& rThemeRoot);
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     OUString GetStyleName (const OUString& rsResourceName) const;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir private:
254*cdf0e10cSrcweir     typedef map<OUString, OUString> StyleAssociations;
255*cdf0e10cSrcweir     StyleAssociations maStyleAssociations;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     void ProcessStyleAssociation(
258*cdf0e10cSrcweir         ReadContext& rReadContext,
259*cdf0e10cSrcweir         const ::rtl::OUString& rsKey,
260*cdf0e10cSrcweir         const ::std::vector<css::uno::Any>& rValues);
261*cdf0e10cSrcweir };
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir } // end of anonymous namespace
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir class PresenterTheme::Theme
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir public:
269*cdf0e10cSrcweir     Theme (
270*cdf0e10cSrcweir         const OUString& rsName,
271*cdf0e10cSrcweir         const Reference<container::XHierarchicalNameAccess>& rThemeRoot,
272*cdf0e10cSrcweir         const OUString& rsNodeName);
273*cdf0e10cSrcweir     ~Theme (void);
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     void Read (
276*cdf0e10cSrcweir         PresenterConfigurationAccess& rConfiguration,
277*cdf0e10cSrcweir         ReadContext& rReadContext);
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     OUString msThemeName;
280*cdf0e10cSrcweir     OUString msConfigurationNodeName;
281*cdf0e10cSrcweir     ::boost::shared_ptr<Theme> mpParentTheme;
282*cdf0e10cSrcweir     SharedBitmapDescriptor mpBackground;
283*cdf0e10cSrcweir     PaneStyleContainer maPaneStyles;
284*cdf0e10cSrcweir     ViewStyleContainer maViewStyles;
285*cdf0e10cSrcweir     ViewDescriptorContainer maViewDescriptors;
286*cdf0e10cSrcweir     StyleAssociationContainer maStyleAssociations;
287*cdf0e10cSrcweir     Reference<container::XHierarchicalNameAccess> mxThemeRoot;
288*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterBitmapContainer> mpIconContainer;
289*cdf0e10cSrcweir     typedef map<rtl::OUString,SharedFontDescriptor> FontContainer;
290*cdf0e10cSrcweir     FontContainer maFontContainer;
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     SharedPaneStyle GetPaneStyle (const OUString& rsStyleName) const;
293*cdf0e10cSrcweir     SharedViewStyle GetViewStyle (const OUString& rsStyleName) const;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir private:
296*cdf0e10cSrcweir     void ProcessFont(
297*cdf0e10cSrcweir         ReadContext& rReadContext,
298*cdf0e10cSrcweir         const OUString& rsKey,
299*cdf0e10cSrcweir         const Reference<beans::XPropertySet>& rxProperties);
300*cdf0e10cSrcweir };
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir //===== PresenterTheme ========================================================
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir PresenterTheme::PresenterTheme (
308*cdf0e10cSrcweir     const css::uno::Reference<css::uno::XComponentContext>& rxContext,
309*cdf0e10cSrcweir     const rtl::OUString& rsThemeName,
310*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas)
311*cdf0e10cSrcweir     : mxContext(rxContext),
312*cdf0e10cSrcweir       msThemeName(rsThemeName),
313*cdf0e10cSrcweir       mpTheme(),
314*cdf0e10cSrcweir       mpBitmapContainer(),
315*cdf0e10cSrcweir       mxCanvas(rxCanvas)
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir     mpTheme = ReadTheme();
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir PresenterTheme::~PresenterTheme (void)
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir void SAL_CALL PresenterTheme::disposing (void)
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir ::boost::shared_ptr<PresenterTheme::Theme> PresenterTheme::ReadTheme (void)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     ReadContext aReadContext(mxContext, mxCanvas);
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     PresenterConfigurationAccess aConfiguration (
342*cdf0e10cSrcweir         mxContext,
343*cdf0e10cSrcweir         OUString::createFromAscii("/org.openoffice.Office.extension.PresenterScreen/"),
344*cdf0e10cSrcweir         PresenterConfigurationAccess::READ_ONLY);
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     return aReadContext.ReadTheme(aConfiguration, msThemeName);
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir bool PresenterTheme::HasCanvas (void) const
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir     return mxCanvas.is();
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir void PresenterTheme::ProvideCanvas (const Reference<rendering::XCanvas>& rxCanvas)
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     if ( ! mxCanvas.is() && rxCanvas.is())
363*cdf0e10cSrcweir     {
364*cdf0e10cSrcweir         mxCanvas = rxCanvas;
365*cdf0e10cSrcweir         ReadTheme();
366*cdf0e10cSrcweir     }
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir OUString PresenterTheme::GetStyleName (const ::rtl::OUString& rsResourceURL) const
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir     OUString sStyleName;
375*cdf0e10cSrcweir     ::boost::shared_ptr<Theme> pTheme (mpTheme);
376*cdf0e10cSrcweir     while (sStyleName.getLength()==0 && pTheme.get()!=NULL)
377*cdf0e10cSrcweir     {
378*cdf0e10cSrcweir         sStyleName = pTheme->maStyleAssociations.GetStyleName(rsResourceURL);
379*cdf0e10cSrcweir         pTheme = pTheme->mpParentTheme;
380*cdf0e10cSrcweir     }
381*cdf0e10cSrcweir     return sStyleName;
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir ::std::vector<sal_Int32> PresenterTheme::GetBorderSize (
388*cdf0e10cSrcweir     const ::rtl::OUString& rsStyleName,
389*cdf0e10cSrcweir     const bool bOuter) const
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir     OSL_ASSERT(mpTheme.get() != NULL);
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     SharedPaneStyle pPaneStyle (mpTheme->GetPaneStyle(rsStyleName));
394*cdf0e10cSrcweir     if (pPaneStyle.get() != NULL)
395*cdf0e10cSrcweir         if (bOuter)
396*cdf0e10cSrcweir             return pPaneStyle->maOuterBorderSize.ToVector();
397*cdf0e10cSrcweir         else
398*cdf0e10cSrcweir             return pPaneStyle->maInnerBorderSize.ToVector();
399*cdf0e10cSrcweir     else
400*cdf0e10cSrcweir     {
401*cdf0e10cSrcweir         return ::std::vector<sal_Int32>(4,0);
402*cdf0e10cSrcweir     }
403*cdf0e10cSrcweir }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor PresenterTheme::ReadFont (
409*cdf0e10cSrcweir     const Reference<container::XHierarchicalNameAccess>& rxNode,
410*cdf0e10cSrcweir     const OUString& rsFontPath,
411*cdf0e10cSrcweir     const PresenterTheme::SharedFontDescriptor& rpDefault)
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir     return ReadContext::ReadFont(rxNode, rsFontPath, rpDefault);
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir bool PresenterTheme::ConvertToColor (
420*cdf0e10cSrcweir     const Any& rColorSequence,
421*cdf0e10cSrcweir     sal_uInt32& rColor)
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     Sequence<sal_Int8> aByteSequence;
424*cdf0e10cSrcweir     if (rColorSequence >>= aByteSequence)
425*cdf0e10cSrcweir     {
426*cdf0e10cSrcweir         const sal_Int32 nByteCount (aByteSequence.getLength());
427*cdf0e10cSrcweir         const sal_uInt8* pArray = reinterpret_cast<const sal_uInt8*>(aByteSequence.getConstArray());
428*cdf0e10cSrcweir         rColor = 0;
429*cdf0e10cSrcweir         for (sal_Int32 nIndex=0; nIndex<nByteCount; ++nIndex)
430*cdf0e10cSrcweir         {
431*cdf0e10cSrcweir             rColor = (rColor << 8) | *pArray++;
432*cdf0e10cSrcweir         }
433*cdf0e10cSrcweir         return true;
434*cdf0e10cSrcweir     }
435*cdf0e10cSrcweir     else
436*cdf0e10cSrcweir         return false;
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir ::boost::shared_ptr<PresenterConfigurationAccess> PresenterTheme::GetNodeForViewStyle (
443*cdf0e10cSrcweir     const ::rtl::OUString& rsStyleName,
444*cdf0e10cSrcweir     const PresenterConfigurationAccess::WriteMode) const
445*cdf0e10cSrcweir {
446*cdf0e10cSrcweir     if (mpTheme.get() == NULL)
447*cdf0e10cSrcweir         return ::boost::shared_ptr<PresenterConfigurationAccess>();
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     // Open configuration for writing.
450*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterConfigurationAccess> pConfiguration (
451*cdf0e10cSrcweir         new PresenterConfigurationAccess(
452*cdf0e10cSrcweir             mxContext,
453*cdf0e10cSrcweir             OUString::createFromAscii("/org.openoffice.Office.extension.PresenterScreen/"),
454*cdf0e10cSrcweir             PresenterConfigurationAccess::READ_WRITE));
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     // Get configuration node for the view style container of the current
457*cdf0e10cSrcweir     // theme.
458*cdf0e10cSrcweir     if (pConfiguration->GoToChild(
459*cdf0e10cSrcweir         A2S("Presenter/Themes/") + mpTheme->msConfigurationNodeName + A2S("/ViewStyles")))
460*cdf0e10cSrcweir     {
461*cdf0e10cSrcweir         pConfiguration->GoToChild(
462*cdf0e10cSrcweir             ::boost::bind(&PresenterConfigurationAccess::IsStringPropertyEqual,
463*cdf0e10cSrcweir                 rsStyleName,
464*cdf0e10cSrcweir                 A2S("StyleName"),
465*cdf0e10cSrcweir                 _2));
466*cdf0e10cSrcweir     }
467*cdf0e10cSrcweir     return pConfiguration;
468*cdf0e10cSrcweir }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir ::rtl::OUString PresenterTheme::GetThemeName (void) const
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     if (mpTheme.get() != NULL)
476*cdf0e10cSrcweir         return mpTheme->msThemeName;
477*cdf0e10cSrcweir     else
478*cdf0e10cSrcweir         return OUString();
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir SharedBitmapDescriptor PresenterTheme::GetBitmap (
485*cdf0e10cSrcweir     const OUString& rsStyleName,
486*cdf0e10cSrcweir     const OUString& rsBitmapName) const
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir     if (mpTheme.get() != NULL)
489*cdf0e10cSrcweir     {
490*cdf0e10cSrcweir         if (rsStyleName.getLength() == 0)
491*cdf0e10cSrcweir         {
492*cdf0e10cSrcweir             if (rsBitmapName == A2S("Background"))
493*cdf0e10cSrcweir             {
494*cdf0e10cSrcweir                 ::boost::shared_ptr<Theme> pTheme (mpTheme);
495*cdf0e10cSrcweir                 while (pTheme.get()!=NULL && pTheme->mpBackground.get()==NULL)
496*cdf0e10cSrcweir                     pTheme = pTheme->mpParentTheme;
497*cdf0e10cSrcweir                 if (pTheme.get() != NULL)
498*cdf0e10cSrcweir                     return pTheme->mpBackground;
499*cdf0e10cSrcweir                 else
500*cdf0e10cSrcweir                     return SharedBitmapDescriptor();
501*cdf0e10cSrcweir             }
502*cdf0e10cSrcweir         }
503*cdf0e10cSrcweir         else
504*cdf0e10cSrcweir         {
505*cdf0e10cSrcweir             SharedPaneStyle pPaneStyle (mpTheme->GetPaneStyle(rsStyleName));
506*cdf0e10cSrcweir             if (pPaneStyle.get() != NULL)
507*cdf0e10cSrcweir             {
508*cdf0e10cSrcweir                 SharedBitmapDescriptor pBitmap (pPaneStyle->GetBitmap(rsBitmapName));
509*cdf0e10cSrcweir                 if (pBitmap.get() != NULL)
510*cdf0e10cSrcweir                     return pBitmap;
511*cdf0e10cSrcweir             }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir             SharedViewStyle pViewStyle (mpTheme->GetViewStyle(rsStyleName));
514*cdf0e10cSrcweir             if (pViewStyle.get() != NULL)
515*cdf0e10cSrcweir             {
516*cdf0e10cSrcweir                 SharedBitmapDescriptor pBitmap (pViewStyle->GetBitmap(rsBitmapName));
517*cdf0e10cSrcweir                 if (pBitmap.get() != NULL)
518*cdf0e10cSrcweir                     return pBitmap;
519*cdf0e10cSrcweir             }
520*cdf0e10cSrcweir         }
521*cdf0e10cSrcweir     }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir     return SharedBitmapDescriptor();
524*cdf0e10cSrcweir }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir SharedBitmapDescriptor PresenterTheme::GetBitmap (
530*cdf0e10cSrcweir     const OUString& rsBitmapName) const
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir     if (mpTheme.get() != NULL)
533*cdf0e10cSrcweir     {
534*cdf0e10cSrcweir         if (rsBitmapName == A2S("Background"))
535*cdf0e10cSrcweir         {
536*cdf0e10cSrcweir             ::boost::shared_ptr<Theme> pTheme (mpTheme);
537*cdf0e10cSrcweir             while (pTheme.get()!=NULL && pTheme->mpBackground.get()==NULL)
538*cdf0e10cSrcweir                 pTheme = pTheme->mpParentTheme;
539*cdf0e10cSrcweir             if (pTheme.get() != NULL)
540*cdf0e10cSrcweir                 return pTheme->mpBackground;
541*cdf0e10cSrcweir             else
542*cdf0e10cSrcweir                 return SharedBitmapDescriptor();
543*cdf0e10cSrcweir         }
544*cdf0e10cSrcweir         else
545*cdf0e10cSrcweir         {
546*cdf0e10cSrcweir             if (mpTheme->mpIconContainer.get() != NULL)
547*cdf0e10cSrcweir                 return mpTheme->mpIconContainer->GetBitmap(rsBitmapName);
548*cdf0e10cSrcweir         }
549*cdf0e10cSrcweir     }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir     return SharedBitmapDescriptor();
552*cdf0e10cSrcweir }
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir ::boost::shared_ptr<PresenterBitmapContainer> PresenterTheme::GetBitmapContainer (void) const
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir     if (mpTheme.get() != NULL)
560*cdf0e10cSrcweir         return mpTheme->mpIconContainer;
561*cdf0e10cSrcweir     else
562*cdf0e10cSrcweir         return ::boost::shared_ptr<PresenterBitmapContainer>();
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor PresenterTheme::GetFont (
569*cdf0e10cSrcweir     const OUString& rsStyleName) const
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir     if (mpTheme.get() != NULL)
572*cdf0e10cSrcweir     {
573*cdf0e10cSrcweir         SharedPaneStyle pPaneStyle (mpTheme->GetPaneStyle(rsStyleName));
574*cdf0e10cSrcweir         if (pPaneStyle.get() != NULL)
575*cdf0e10cSrcweir             return pPaneStyle->GetFont();
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir         SharedViewStyle pViewStyle (mpTheme->GetViewStyle(rsStyleName));
578*cdf0e10cSrcweir         if (pViewStyle.get() != NULL)
579*cdf0e10cSrcweir             return pViewStyle->GetFont();
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir         ::boost::shared_ptr<Theme> pTheme (mpTheme);
582*cdf0e10cSrcweir         while (pTheme.get() != NULL)
583*cdf0e10cSrcweir         {
584*cdf0e10cSrcweir             Theme::FontContainer::const_iterator iFont (pTheme->maFontContainer.find(rsStyleName));
585*cdf0e10cSrcweir             if (iFont != pTheme->maFontContainer.end())
586*cdf0e10cSrcweir                 return iFont->second;
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir             pTheme = pTheme->mpParentTheme;
589*cdf0e10cSrcweir         }
590*cdf0e10cSrcweir     }
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir     return SharedFontDescriptor();
593*cdf0e10cSrcweir }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir //===== FontDescriptor ========================================================
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir PresenterTheme::FontDescriptor::FontDescriptor (void)
601*cdf0e10cSrcweir     : msFamilyName(),
602*cdf0e10cSrcweir       msStyleName(),
603*cdf0e10cSrcweir       mnSize(12),
604*cdf0e10cSrcweir       mnColor(0x00000000),
605*cdf0e10cSrcweir       msAnchor(OUString::createFromAscii("Left")),
606*cdf0e10cSrcweir       mnXOffset(0),
607*cdf0e10cSrcweir       mnYOffset(0)
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir PresenterTheme::FontDescriptor::FontDescriptor (
615*cdf0e10cSrcweir     const ::boost::shared_ptr<FontDescriptor>& rpDescriptor)
616*cdf0e10cSrcweir     : msFamilyName(),
617*cdf0e10cSrcweir       msStyleName(),
618*cdf0e10cSrcweir       mnSize(12),
619*cdf0e10cSrcweir       mnColor(0x00000000),
620*cdf0e10cSrcweir       msAnchor(OUString::createFromAscii("Left")),
621*cdf0e10cSrcweir       mnXOffset(0),
622*cdf0e10cSrcweir       mnYOffset(0)
623*cdf0e10cSrcweir {
624*cdf0e10cSrcweir     if (rpDescriptor.get() != NULL)
625*cdf0e10cSrcweir     {
626*cdf0e10cSrcweir         msFamilyName = rpDescriptor->msFamilyName;
627*cdf0e10cSrcweir         msStyleName = rpDescriptor->msStyleName;
628*cdf0e10cSrcweir         mnSize = rpDescriptor->mnSize;
629*cdf0e10cSrcweir         mnColor = rpDescriptor->mnColor;
630*cdf0e10cSrcweir         msAnchor = rpDescriptor->msAnchor;
631*cdf0e10cSrcweir         mnXOffset = rpDescriptor->mnXOffset;
632*cdf0e10cSrcweir         mnYOffset = rpDescriptor->mnYOffset;
633*cdf0e10cSrcweir     }
634*cdf0e10cSrcweir }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir bool PresenterTheme::FontDescriptor::PrepareFont (
640*cdf0e10cSrcweir     const Reference<rendering::XCanvas>& rxCanvas)
641*cdf0e10cSrcweir {
642*cdf0e10cSrcweir     if (mxFont.is())
643*cdf0e10cSrcweir         return true;
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     if ( ! rxCanvas.is())
646*cdf0e10cSrcweir         return false;
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir     const double nCellSize (GetCellSizeForDesignSize(rxCanvas, mnSize));
650*cdf0e10cSrcweir     mxFont = CreateFont(rxCanvas, nCellSize);
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir     return mxFont.is();
653*cdf0e10cSrcweir }
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir Reference<rendering::XCanvasFont> PresenterTheme::FontDescriptor::CreateFont (
659*cdf0e10cSrcweir     const Reference<rendering::XCanvas>& rxCanvas,
660*cdf0e10cSrcweir     const double nCellSize) const
661*cdf0e10cSrcweir {
662*cdf0e10cSrcweir     rendering::FontRequest aFontRequest;
663*cdf0e10cSrcweir     aFontRequest.FontDescription.FamilyName = msFamilyName;
664*cdf0e10cSrcweir     if (msFamilyName.getLength() == 0)
665*cdf0e10cSrcweir         aFontRequest.FontDescription.FamilyName = A2S("Tahoma");
666*cdf0e10cSrcweir     aFontRequest.FontDescription.StyleName = msStyleName;
667*cdf0e10cSrcweir     aFontRequest.CellSize = nCellSize;
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     // Make an attempt at translating the style name(s)into a corresponding
670*cdf0e10cSrcweir     // font description.
671*cdf0e10cSrcweir     if (msStyleName == A2S("Bold"))
672*cdf0e10cSrcweir         aFontRequest.FontDescription.FontDescription.Weight = rendering::PanoseWeight::HEAVY;
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir     return rxCanvas->createFont(
675*cdf0e10cSrcweir         aFontRequest,
676*cdf0e10cSrcweir         Sequence<beans::PropertyValue>(),
677*cdf0e10cSrcweir         geometry::Matrix2D(1,0,0,1));
678*cdf0e10cSrcweir }
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir double PresenterTheme::FontDescriptor::GetCellSizeForDesignSize (
684*cdf0e10cSrcweir     const Reference<rendering::XCanvas>& rxCanvas,
685*cdf0e10cSrcweir     const double nDesignSize) const
686*cdf0e10cSrcweir {
687*cdf0e10cSrcweir     // Use the given design size as initial value in calculating the cell
688*cdf0e10cSrcweir     // size.
689*cdf0e10cSrcweir     double nCellSize (nDesignSize);
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir     if ( ! rxCanvas.is())
692*cdf0e10cSrcweir     {
693*cdf0e10cSrcweir         // We need the canvas to do the conversion.  Return the design size,
694*cdf0e10cSrcweir         // it is the our best guess in this circumstance.
695*cdf0e10cSrcweir         return nDesignSize;
696*cdf0e10cSrcweir     }
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     Reference<rendering::XCanvasFont> xFont (CreateFont(rxCanvas, nCellSize));
699*cdf0e10cSrcweir     if ( ! xFont.is())
700*cdf0e10cSrcweir         return nDesignSize;
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     geometry::RealRectangle2D aBox (PresenterCanvasHelper::GetTextBoundingBox (xFont, A2S("X")));
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     const double nAscent (-aBox.Y1);
705*cdf0e10cSrcweir     const double nDescent (aBox.Y2);
706*cdf0e10cSrcweir     const double nScale = (nAscent+nDescent) / nAscent;
707*cdf0e10cSrcweir     return nDesignSize * nScale;
708*cdf0e10cSrcweir }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir //===== Theme =================================================================
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir PresenterTheme::Theme::Theme (
716*cdf0e10cSrcweir     const OUString& rsName,
717*cdf0e10cSrcweir     const Reference<container::XHierarchicalNameAccess>& rxThemeRoot,
718*cdf0e10cSrcweir     const OUString& rsNodeName)
719*cdf0e10cSrcweir     : msThemeName(rsName),
720*cdf0e10cSrcweir       msConfigurationNodeName(rsNodeName),
721*cdf0e10cSrcweir       mpParentTheme(),
722*cdf0e10cSrcweir       maPaneStyles(),
723*cdf0e10cSrcweir       maViewStyles(),
724*cdf0e10cSrcweir       maStyleAssociations(),
725*cdf0e10cSrcweir       mxThemeRoot(rxThemeRoot),
726*cdf0e10cSrcweir       mpIconContainer()
727*cdf0e10cSrcweir {
728*cdf0e10cSrcweir }
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir PresenterTheme::Theme::~Theme (void)
734*cdf0e10cSrcweir {
735*cdf0e10cSrcweir }
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir void PresenterTheme::Theme::Read (
741*cdf0e10cSrcweir     PresenterConfigurationAccess& rConfiguration,
742*cdf0e10cSrcweir     ReadContext& rReadContext)
743*cdf0e10cSrcweir {
744*cdf0e10cSrcweir     PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot, A2S("ThemeName"))
745*cdf0e10cSrcweir         >>= msThemeName;
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     // Parent theme name.
748*cdf0e10cSrcweir     OUString sParentThemeName;
749*cdf0e10cSrcweir     if ((PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot, A2S("ParentTheme"))
750*cdf0e10cSrcweir             >>= sParentThemeName)
751*cdf0e10cSrcweir         && sParentThemeName.getLength()>0)
752*cdf0e10cSrcweir     {
753*cdf0e10cSrcweir         mpParentTheme = rReadContext.ReadTheme(rConfiguration, sParentThemeName);
754*cdf0e10cSrcweir     }
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir     // Read the extension that contains the bitmaps referenced in this
757*cdf0e10cSrcweir     // theme.
758*cdf0e10cSrcweir     OUString sBitmapSourceExtension;
759*cdf0e10cSrcweir     if ((PresenterConfigurationAccess::GetConfigurationNode(
760*cdf0e10cSrcweir         mxThemeRoot, A2S("BitmapSourceExtension")) >>= sBitmapSourceExtension)
761*cdf0e10cSrcweir         && sBitmapSourceExtension.getLength()>0)
762*cdf0e10cSrcweir     {
763*cdf0e10cSrcweir         rReadContext.SetBitmapSourceExtension(sBitmapSourceExtension);
764*cdf0e10cSrcweir     }
765*cdf0e10cSrcweir     else
766*cdf0e10cSrcweir     {
767*cdf0e10cSrcweir         rReadContext.SetBitmapSourceExtension(PresenterComponent::gsExtensionIdentifier);
768*cdf0e10cSrcweir     }
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir     // Background.
771*cdf0e10cSrcweir     mpBackground = PresenterBitmapContainer::LoadBitmap(
772*cdf0e10cSrcweir         mxThemeRoot,
773*cdf0e10cSrcweir         A2S("Background"),
774*cdf0e10cSrcweir         rReadContext.mxPresenterHelper,
775*cdf0e10cSrcweir         rReadContext.msBasePath,
776*cdf0e10cSrcweir         rReadContext.mxCanvas,
777*cdf0e10cSrcweir         SharedBitmapDescriptor());
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir     // Style associations.
780*cdf0e10cSrcweir     maStyleAssociations.Read(rReadContext, mxThemeRoot);
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir     // Pane styles.
783*cdf0e10cSrcweir     maPaneStyles.Read(rReadContext, mxThemeRoot);
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir     // View styles.
786*cdf0e10cSrcweir     maViewStyles.Read(rReadContext, mxThemeRoot);
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir     // Read bitmaps.
789*cdf0e10cSrcweir     mpIconContainer.reset(
790*cdf0e10cSrcweir         new PresenterBitmapContainer(
791*cdf0e10cSrcweir             Reference<container::XNameAccess>(
792*cdf0e10cSrcweir                 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot, A2S("Bitmaps")),
793*cdf0e10cSrcweir                 UNO_QUERY),
794*cdf0e10cSrcweir             mpParentTheme.get()!=NULL
795*cdf0e10cSrcweir                 ? mpParentTheme->mpIconContainer
796*cdf0e10cSrcweir                 : ::boost::shared_ptr<PresenterBitmapContainer>(),
797*cdf0e10cSrcweir             rReadContext.mxComponentContext,
798*cdf0e10cSrcweir             rReadContext.mxCanvas,
799*cdf0e10cSrcweir             rReadContext.msBasePath));
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir     // Read fonts.
802*cdf0e10cSrcweir     Reference<container::XNameAccess> xFontNode(
803*cdf0e10cSrcweir         PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot, A2S("Fonts")),
804*cdf0e10cSrcweir         UNO_QUERY);
805*cdf0e10cSrcweir     PresenterConfigurationAccess::ForAll(
806*cdf0e10cSrcweir         xFontNode,
807*cdf0e10cSrcweir         ::boost::bind(&PresenterTheme::Theme::ProcessFont,
808*cdf0e10cSrcweir             this, ::boost::ref(rReadContext), _1, _2));
809*cdf0e10cSrcweir }
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir SharedPaneStyle PresenterTheme::Theme::GetPaneStyle (const OUString& rsStyleName) const
815*cdf0e10cSrcweir {
816*cdf0e10cSrcweir     SharedPaneStyle pPaneStyle (maPaneStyles.GetPaneStyle(rsStyleName));
817*cdf0e10cSrcweir     if (pPaneStyle.get() != NULL)
818*cdf0e10cSrcweir         return pPaneStyle;
819*cdf0e10cSrcweir     else if (mpParentTheme.get() != NULL)
820*cdf0e10cSrcweir         return mpParentTheme->GetPaneStyle(rsStyleName);
821*cdf0e10cSrcweir     else
822*cdf0e10cSrcweir         return SharedPaneStyle();
823*cdf0e10cSrcweir }
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir SharedViewStyle PresenterTheme::Theme::GetViewStyle (const OUString& rsStyleName) const
829*cdf0e10cSrcweir {
830*cdf0e10cSrcweir     SharedViewStyle pViewStyle (maViewStyles.GetViewStyle(rsStyleName));
831*cdf0e10cSrcweir     if (pViewStyle.get() != NULL)
832*cdf0e10cSrcweir         return pViewStyle;
833*cdf0e10cSrcweir     else if (mpParentTheme.get() != NULL)
834*cdf0e10cSrcweir         return mpParentTheme->GetViewStyle(rsStyleName);
835*cdf0e10cSrcweir     else
836*cdf0e10cSrcweir         return SharedViewStyle();
837*cdf0e10cSrcweir }
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir void PresenterTheme::Theme::ProcessFont(
843*cdf0e10cSrcweir     ReadContext& rReadContext,
844*cdf0e10cSrcweir     const OUString& rsKey,
845*cdf0e10cSrcweir     const Reference<beans::XPropertySet>& rxProperties)
846*cdf0e10cSrcweir {
847*cdf0e10cSrcweir     (void)rReadContext;
848*cdf0e10cSrcweir     maFontContainer[rsKey] = ReadContext::ReadFont(rxProperties, SharedFontDescriptor());
849*cdf0e10cSrcweir }
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir namespace {
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir //===== ReadContext ===========================================================
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir ReadContext::ReadContext (
859*cdf0e10cSrcweir     const css::uno::Reference<css::uno::XComponentContext>& rxContext,
860*cdf0e10cSrcweir     const Reference<rendering::XCanvas>& rxCanvas)
861*cdf0e10cSrcweir     : mxComponentContext(rxContext),
862*cdf0e10cSrcweir       mxCanvas(rxCanvas),
863*cdf0e10cSrcweir       mxPresenterHelper(),
864*cdf0e10cSrcweir       msBasePath()
865*cdf0e10cSrcweir {
866*cdf0e10cSrcweir     Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
867*cdf0e10cSrcweir     if (xFactory.is())
868*cdf0e10cSrcweir     {
869*cdf0e10cSrcweir         mxPresenterHelper = Reference<drawing::XPresenterHelper>(
870*cdf0e10cSrcweir             xFactory->createInstanceWithContext(
871*cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
872*cdf0e10cSrcweir                 rxContext),
873*cdf0e10cSrcweir             UNO_QUERY_THROW);
874*cdf0e10cSrcweir     }
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir     // Get base path to bitmaps.
877*cdf0e10cSrcweir     SetBitmapSourceExtension(PresenterComponent::gsExtensionIdentifier);
878*cdf0e10cSrcweir }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir ReadContext::~ReadContext (void)
884*cdf0e10cSrcweir {
885*cdf0e10cSrcweir }
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor ReadContext::ReadFont (
891*cdf0e10cSrcweir     const Reference<container::XHierarchicalNameAccess>& rxNode,
892*cdf0e10cSrcweir     const OUString& rsFontPath,
893*cdf0e10cSrcweir     const PresenterTheme::SharedFontDescriptor& rpDefault)
894*cdf0e10cSrcweir {
895*cdf0e10cSrcweir     if ( ! rxNode.is())
896*cdf0e10cSrcweir         return PresenterTheme::SharedFontDescriptor();
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir     try
899*cdf0e10cSrcweir     {
900*cdf0e10cSrcweir         Reference<container::XHierarchicalNameAccess> xFont (
901*cdf0e10cSrcweir             PresenterConfigurationAccess::GetConfigurationNode(
902*cdf0e10cSrcweir                 rxNode,
903*cdf0e10cSrcweir                 rsFontPath),
904*cdf0e10cSrcweir                 UNO_QUERY_THROW);
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir         Reference<beans::XPropertySet> xProperties (xFont, UNO_QUERY_THROW);
907*cdf0e10cSrcweir         return ReadFont(xProperties, rpDefault);
908*cdf0e10cSrcweir     }
909*cdf0e10cSrcweir 	catch (Exception&)
910*cdf0e10cSrcweir 	{
911*cdf0e10cSrcweir         OSL_ASSERT(false);
912*cdf0e10cSrcweir 	}
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir     return PresenterTheme::SharedFontDescriptor();
915*cdf0e10cSrcweir }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor ReadContext::ReadFont (
921*cdf0e10cSrcweir     const Reference<beans::XPropertySet>& rxProperties,
922*cdf0e10cSrcweir     const PresenterTheme::SharedFontDescriptor& rpDefault)
923*cdf0e10cSrcweir {
924*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterTheme::FontDescriptor> pDescriptor (
925*cdf0e10cSrcweir         new PresenterTheme::FontDescriptor(rpDefault));
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("FamilyName")) >>= pDescriptor->msFamilyName;
928*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("Style")) >>= pDescriptor->msStyleName;
929*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("Size")) >>= pDescriptor->mnSize;
930*cdf0e10cSrcweir     PresenterTheme::ConvertToColor(
931*cdf0e10cSrcweir         PresenterConfigurationAccess::GetProperty(rxProperties, A2S("Color")),
932*cdf0e10cSrcweir         pDescriptor->mnColor);
933*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("Anchor")) >>= pDescriptor->msAnchor;
934*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("XOffset")) >>= pDescriptor->mnXOffset;
935*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("YOffset")) >>= pDescriptor->mnYOffset;
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir     return pDescriptor;
938*cdf0e10cSrcweir }
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir Any ReadContext::GetByName (
944*cdf0e10cSrcweir     const Reference<container::XNameAccess>& rxNode,
945*cdf0e10cSrcweir     const OUString& rsName) const
946*cdf0e10cSrcweir {
947*cdf0e10cSrcweir     OSL_ASSERT(rxNode.is());
948*cdf0e10cSrcweir     if (rxNode->hasByName(rsName))
949*cdf0e10cSrcweir         return rxNode->getByName(rsName);
950*cdf0e10cSrcweir     else
951*cdf0e10cSrcweir         return Any();
952*cdf0e10cSrcweir }
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir ::boost::shared_ptr<PresenterTheme::Theme> ReadContext::ReadTheme (
958*cdf0e10cSrcweir     PresenterConfigurationAccess& rConfiguration,
959*cdf0e10cSrcweir     const OUString& rsThemeName)
960*cdf0e10cSrcweir {
961*cdf0e10cSrcweir     ::boost::shared_ptr<PresenterTheme::Theme> pTheme;
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir     OUString sCurrentThemeName (rsThemeName);
964*cdf0e10cSrcweir      if (sCurrentThemeName.getLength() == 0)
965*cdf0e10cSrcweir      {
966*cdf0e10cSrcweir          // No theme name given.  Look up the CurrentTheme property.
967*cdf0e10cSrcweir          rConfiguration.GetConfigurationNode(A2S("Presenter/CurrentTheme")) >>= sCurrentThemeName;
968*cdf0e10cSrcweir          if (sCurrentThemeName.getLength() == 0)
969*cdf0e10cSrcweir          {
970*cdf0e10cSrcweir              // Still no name.  Use "DefaultTheme".
971*cdf0e10cSrcweir              sCurrentThemeName = A2S("DefaultTheme");
972*cdf0e10cSrcweir          }
973*cdf0e10cSrcweir      }
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir     Reference<container::XNameAccess> xThemes (
976*cdf0e10cSrcweir         rConfiguration.GetConfigurationNode(A2S("Presenter/Themes")),
977*cdf0e10cSrcweir         UNO_QUERY);
978*cdf0e10cSrcweir     if (xThemes.is())
979*cdf0e10cSrcweir     {
980*cdf0e10cSrcweir         // Iterate over all themes and search the one with the given name.
981*cdf0e10cSrcweir         Sequence<OUString> aKeys (xThemes->getElementNames());
982*cdf0e10cSrcweir         for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
983*cdf0e10cSrcweir         {
984*cdf0e10cSrcweir             const OUString& rsKey (aKeys[nItemIndex]);
985*cdf0e10cSrcweir             Reference<container::XHierarchicalNameAccess> xTheme (
986*cdf0e10cSrcweir                 xThemes->getByName(rsKey), UNO_QUERY);
987*cdf0e10cSrcweir             if (xTheme.is())
988*cdf0e10cSrcweir             {
989*cdf0e10cSrcweir                 OUString sThemeName;
990*cdf0e10cSrcweir                 PresenterConfigurationAccess::GetConfigurationNode(xTheme, A2S("ThemeName"))
991*cdf0e10cSrcweir                     >>= sThemeName;
992*cdf0e10cSrcweir                 if (sThemeName == sCurrentThemeName)
993*cdf0e10cSrcweir                 {
994*cdf0e10cSrcweir                     pTheme.reset(new PresenterTheme::Theme(sThemeName,xTheme,rsKey));
995*cdf0e10cSrcweir                     break;
996*cdf0e10cSrcweir                 }
997*cdf0e10cSrcweir             }
998*cdf0e10cSrcweir         }
999*cdf0e10cSrcweir     }
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     if (pTheme.get() != NULL)
1002*cdf0e10cSrcweir     {
1003*cdf0e10cSrcweir         pTheme->Read(rConfiguration, *this);
1004*cdf0e10cSrcweir     }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir     return pTheme;
1007*cdf0e10cSrcweir }
1008*cdf0e10cSrcweir 
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir BorderSize ReadContext::ReadBorderSize (const Reference<container::XNameAccess>& rxNode)
1013*cdf0e10cSrcweir {
1014*cdf0e10cSrcweir     BorderSize aBorderSize;
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir     if (rxNode.is())
1017*cdf0e10cSrcweir     {
1018*cdf0e10cSrcweir         GetByName(rxNode, A2S("Left")) >>= aBorderSize.mnLeft;
1019*cdf0e10cSrcweir         GetByName(rxNode, A2S("Top")) >>= aBorderSize.mnTop;
1020*cdf0e10cSrcweir         GetByName(rxNode, A2S("Right")) >>= aBorderSize.mnRight;
1021*cdf0e10cSrcweir         GetByName(rxNode, A2S("Bottom")) >>= aBorderSize.mnBottom;
1022*cdf0e10cSrcweir     }
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir     return aBorderSize;
1025*cdf0e10cSrcweir }
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir void ReadContext::SetBitmapSourceExtension (const OUString& rsExtensionIdentifier)
1031*cdf0e10cSrcweir {
1032*cdf0e10cSrcweir     // Get base path to bitmaps.
1033*cdf0e10cSrcweir     msBasePath = PresenterComponent::GetBasePath(mxComponentContext, rsExtensionIdentifier);
1034*cdf0e10cSrcweir }
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir //===== PaneStyleContainer ====================================================
1040*cdf0e10cSrcweir 
1041*cdf0e10cSrcweir void PaneStyleContainer::Read (
1042*cdf0e10cSrcweir     ReadContext& rReadContext,
1043*cdf0e10cSrcweir     const Reference<container::XHierarchicalNameAccess>& rxThemeRoot)
1044*cdf0e10cSrcweir {
1045*cdf0e10cSrcweir     Reference<container::XNameAccess> xPaneStyleList (
1046*cdf0e10cSrcweir         PresenterConfigurationAccess::GetConfigurationNode(
1047*cdf0e10cSrcweir             rxThemeRoot,
1048*cdf0e10cSrcweir             A2S("PaneStyles")),
1049*cdf0e10cSrcweir         UNO_QUERY);
1050*cdf0e10cSrcweir     if (xPaneStyleList.is())
1051*cdf0e10cSrcweir     {
1052*cdf0e10cSrcweir         ::std::vector<rtl::OUString> aProperties;
1053*cdf0e10cSrcweir         aProperties.reserve(6);
1054*cdf0e10cSrcweir         aProperties.push_back(A2S("StyleName"));
1055*cdf0e10cSrcweir         aProperties.push_back(A2S("ParentStyle"));
1056*cdf0e10cSrcweir         aProperties.push_back(A2S("TitleFont"));
1057*cdf0e10cSrcweir         aProperties.push_back(A2S("InnerBorderSize"));
1058*cdf0e10cSrcweir         aProperties.push_back(A2S("OuterBorderSize"));
1059*cdf0e10cSrcweir         aProperties.push_back(A2S("BorderBitmapList"));
1060*cdf0e10cSrcweir         PresenterConfigurationAccess::ForAll(
1061*cdf0e10cSrcweir             xPaneStyleList,
1062*cdf0e10cSrcweir             aProperties,
1063*cdf0e10cSrcweir             ::boost::bind(&PaneStyleContainer::ProcessPaneStyle,
1064*cdf0e10cSrcweir                 this, ::boost::ref(rReadContext), _1, _2));
1065*cdf0e10cSrcweir     }
1066*cdf0e10cSrcweir }
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir 
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir void PaneStyleContainer::ProcessPaneStyle(
1072*cdf0e10cSrcweir     ReadContext& rReadContext,
1073*cdf0e10cSrcweir     const OUString& rsKey,
1074*cdf0e10cSrcweir     const ::std::vector<Any>& rValues)
1075*cdf0e10cSrcweir {
1076*cdf0e10cSrcweir     (void)rsKey;
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir     if (rValues.size() != 6)
1079*cdf0e10cSrcweir         return;
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir     ::boost::shared_ptr<PaneStyle> pStyle (new PaneStyle());
1082*cdf0e10cSrcweir 
1083*cdf0e10cSrcweir     rValues[0] >>= pStyle->msStyleName;
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir     OUString sParentStyleName;
1086*cdf0e10cSrcweir     if (rValues[1] >>= sParentStyleName)
1087*cdf0e10cSrcweir     {
1088*cdf0e10cSrcweir         // Find parent style.
1089*cdf0e10cSrcweir         PaneStyleContainer::const_iterator iStyle;
1090*cdf0e10cSrcweir         for (iStyle=begin(); iStyle!=end(); ++iStyle)
1091*cdf0e10cSrcweir             if ((*iStyle)->msStyleName.equals(sParentStyleName))
1092*cdf0e10cSrcweir             {
1093*cdf0e10cSrcweir                 pStyle->mpParentStyle = *iStyle;
1094*cdf0e10cSrcweir                 break;
1095*cdf0e10cSrcweir             }
1096*cdf0e10cSrcweir     }
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir     Reference<container::XHierarchicalNameAccess> xFontNode (rValues[2], UNO_QUERY);
1099*cdf0e10cSrcweir     pStyle->mpFont = rReadContext.ReadFont(
1100*cdf0e10cSrcweir         xFontNode, A2S(""), PresenterTheme::SharedFontDescriptor());
1101*cdf0e10cSrcweir 
1102*cdf0e10cSrcweir     Reference<container::XNameAccess> xInnerBorderSizeNode (rValues[3], UNO_QUERY);
1103*cdf0e10cSrcweir     pStyle->maInnerBorderSize = rReadContext.ReadBorderSize(xInnerBorderSizeNode);
1104*cdf0e10cSrcweir     Reference<container::XNameAccess> xOuterBorderSizeNode (rValues[4], UNO_QUERY);
1105*cdf0e10cSrcweir     pStyle->maOuterBorderSize = rReadContext.ReadBorderSize(xOuterBorderSizeNode);
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir     if (pStyle->mpParentStyle.get() != NULL)
1108*cdf0e10cSrcweir     {
1109*cdf0e10cSrcweir         pStyle->maInnerBorderSize.Merge(pStyle->mpParentStyle->maInnerBorderSize);
1110*cdf0e10cSrcweir         pStyle->maOuterBorderSize.Merge(pStyle->mpParentStyle->maOuterBorderSize);
1111*cdf0e10cSrcweir     }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir     if (rReadContext.mxCanvas.is())
1114*cdf0e10cSrcweir     {
1115*cdf0e10cSrcweir         Reference<container::XNameAccess> xBitmapsNode (rValues[5], UNO_QUERY);
1116*cdf0e10cSrcweir         pStyle->mpBitmaps.reset(new PresenterBitmapContainer(
1117*cdf0e10cSrcweir             xBitmapsNode,
1118*cdf0e10cSrcweir             pStyle->mpParentStyle.get()!=NULL
1119*cdf0e10cSrcweir                 ? pStyle->mpParentStyle->mpBitmaps
1120*cdf0e10cSrcweir                 : ::boost::shared_ptr<PresenterBitmapContainer>(),
1121*cdf0e10cSrcweir             rReadContext.mxComponentContext,
1122*cdf0e10cSrcweir             rReadContext.mxCanvas,
1123*cdf0e10cSrcweir             rReadContext.msBasePath,
1124*cdf0e10cSrcweir             rReadContext.mxPresenterHelper));
1125*cdf0e10cSrcweir     }
1126*cdf0e10cSrcweir 
1127*cdf0e10cSrcweir     push_back(pStyle);
1128*cdf0e10cSrcweir }
1129*cdf0e10cSrcweir 
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir 
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir SharedPaneStyle PaneStyleContainer::GetPaneStyle (const OUString& rsStyleName) const
1134*cdf0e10cSrcweir {
1135*cdf0e10cSrcweir     const_iterator iEnd (end());
1136*cdf0e10cSrcweir     for (const_iterator iStyle=begin(); iStyle!=iEnd; ++iStyle)
1137*cdf0e10cSrcweir         if ((*iStyle)->msStyleName == rsStyleName)
1138*cdf0e10cSrcweir             return *iStyle;
1139*cdf0e10cSrcweir     return SharedPaneStyle();
1140*cdf0e10cSrcweir }
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir //===== PaneStyle =============================================================
1146*cdf0e10cSrcweir 
1147*cdf0e10cSrcweir PaneStyle::PaneStyle (void)
1148*cdf0e10cSrcweir     : msStyleName(),
1149*cdf0e10cSrcweir       mpParentStyle(),
1150*cdf0e10cSrcweir       mpFont(),
1151*cdf0e10cSrcweir       maInnerBorderSize(),
1152*cdf0e10cSrcweir       maOuterBorderSize(),
1153*cdf0e10cSrcweir       mpBitmaps()
1154*cdf0e10cSrcweir {
1155*cdf0e10cSrcweir }
1156*cdf0e10cSrcweir 
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir PaneStyle::~PaneStyle (void)
1161*cdf0e10cSrcweir {
1162*cdf0e10cSrcweir }
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir 
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 
1167*cdf0e10cSrcweir void PaneStyle::UpdateBorderSize (BorderSize& rBorderSize, bool bInner)
1168*cdf0e10cSrcweir {
1169*cdf0e10cSrcweir     if (mpParentStyle.get() != NULL)
1170*cdf0e10cSrcweir         mpParentStyle->UpdateBorderSize(rBorderSize, bInner);
1171*cdf0e10cSrcweir 
1172*cdf0e10cSrcweir     BorderSize& rThisBorderSize (bInner ? maInnerBorderSize : maOuterBorderSize);
1173*cdf0e10cSrcweir     if (rThisBorderSize.mnLeft >= 0)
1174*cdf0e10cSrcweir         rBorderSize.mnLeft = rThisBorderSize.mnLeft;
1175*cdf0e10cSrcweir     if (rThisBorderSize.mnTop >= 0)
1176*cdf0e10cSrcweir         rBorderSize.mnTop = rThisBorderSize.mnTop;
1177*cdf0e10cSrcweir     if (rThisBorderSize.mnRight >= 0)
1178*cdf0e10cSrcweir         rBorderSize.mnRight = rThisBorderSize.mnRight;
1179*cdf0e10cSrcweir     if (rThisBorderSize.mnBottom >= 0)
1180*cdf0e10cSrcweir         rBorderSize.mnBottom = rThisBorderSize.mnBottom;
1181*cdf0e10cSrcweir }
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir 
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir const SharedBitmapDescriptor PaneStyle::GetBitmap (const OUString& rsBitmapName) const
1187*cdf0e10cSrcweir {
1188*cdf0e10cSrcweir     if (mpBitmaps.get() != NULL)
1189*cdf0e10cSrcweir     {
1190*cdf0e10cSrcweir         const SharedBitmapDescriptor pBitmap = mpBitmaps->GetBitmap(rsBitmapName);
1191*cdf0e10cSrcweir         if (pBitmap.get() != NULL)
1192*cdf0e10cSrcweir             return pBitmap;
1193*cdf0e10cSrcweir     }
1194*cdf0e10cSrcweir 
1195*cdf0e10cSrcweir     if (mpParentStyle.get() != NULL)
1196*cdf0e10cSrcweir         return mpParentStyle->GetBitmap(rsBitmapName);
1197*cdf0e10cSrcweir     else
1198*cdf0e10cSrcweir         return SharedBitmapDescriptor();
1199*cdf0e10cSrcweir }
1200*cdf0e10cSrcweir 
1201*cdf0e10cSrcweir 
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor PaneStyle::GetFont (void) const
1205*cdf0e10cSrcweir {
1206*cdf0e10cSrcweir     if (mpFont.get() != NULL)
1207*cdf0e10cSrcweir         return mpFont;
1208*cdf0e10cSrcweir     else if (mpParentStyle.get() != NULL)
1209*cdf0e10cSrcweir         return mpParentStyle->GetFont();
1210*cdf0e10cSrcweir     else
1211*cdf0e10cSrcweir         return PresenterTheme::SharedFontDescriptor();
1212*cdf0e10cSrcweir }
1213*cdf0e10cSrcweir 
1214*cdf0e10cSrcweir 
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir //===== ViewStyleContainer ====================================================
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir void ViewStyleContainer::Read (
1220*cdf0e10cSrcweir     ReadContext& rReadContext,
1221*cdf0e10cSrcweir     const Reference<container::XHierarchicalNameAccess>& rxThemeRoot)
1222*cdf0e10cSrcweir {
1223*cdf0e10cSrcweir     (void)rReadContext;
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir     Reference<container::XNameAccess> xViewStyleList (
1226*cdf0e10cSrcweir         PresenterConfigurationAccess::GetConfigurationNode(
1227*cdf0e10cSrcweir             rxThemeRoot,
1228*cdf0e10cSrcweir             A2S("ViewStyles")),
1229*cdf0e10cSrcweir         UNO_QUERY);
1230*cdf0e10cSrcweir     if (xViewStyleList.is())
1231*cdf0e10cSrcweir     {
1232*cdf0e10cSrcweir         PresenterConfigurationAccess::ForAll(
1233*cdf0e10cSrcweir             xViewStyleList,
1234*cdf0e10cSrcweir             ::boost::bind(&ViewStyleContainer::ProcessViewStyle,
1235*cdf0e10cSrcweir                 this, ::boost::ref(rReadContext), _2));
1236*cdf0e10cSrcweir     }
1237*cdf0e10cSrcweir }
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir void ViewStyleContainer::ProcessViewStyle(
1243*cdf0e10cSrcweir     ReadContext& rReadContext,
1244*cdf0e10cSrcweir     const Reference<beans::XPropertySet>& rxProperties)
1245*cdf0e10cSrcweir {
1246*cdf0e10cSrcweir     ::boost::shared_ptr<ViewStyle> pStyle (new ViewStyle());
1247*cdf0e10cSrcweir 
1248*cdf0e10cSrcweir     PresenterConfigurationAccess::GetProperty(rxProperties, A2S("StyleName"))
1249*cdf0e10cSrcweir         >>= pStyle->msStyleName;
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir     OUString sParentStyleName;
1252*cdf0e10cSrcweir     if (PresenterConfigurationAccess::GetProperty(rxProperties, A2S("ParentStyle"))
1253*cdf0e10cSrcweir         >>= sParentStyleName)
1254*cdf0e10cSrcweir     {
1255*cdf0e10cSrcweir         // Find parent style.
1256*cdf0e10cSrcweir         ViewStyleContainer::const_iterator iStyle;
1257*cdf0e10cSrcweir         for (iStyle=begin(); iStyle!=end(); ++iStyle)
1258*cdf0e10cSrcweir             if ((*iStyle)->msStyleName.equals(sParentStyleName))
1259*cdf0e10cSrcweir             {
1260*cdf0e10cSrcweir                 pStyle->mpParentStyle = *iStyle;
1261*cdf0e10cSrcweir                 pStyle->mpFont = (*iStyle)->mpFont;
1262*cdf0e10cSrcweir                 pStyle->mpBackground = (*iStyle)->mpBackground;
1263*cdf0e10cSrcweir                 break;
1264*cdf0e10cSrcweir             }
1265*cdf0e10cSrcweir     }
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir     const OUString sPathToFont; // empty string
1268*cdf0e10cSrcweir     Reference<container::XHierarchicalNameAccess> xFontNode (
1269*cdf0e10cSrcweir         PresenterConfigurationAccess::GetProperty(rxProperties, A2S("Font")), UNO_QUERY);
1270*cdf0e10cSrcweir     PresenterTheme::SharedFontDescriptor pFont (
1271*cdf0e10cSrcweir         rReadContext.ReadFont(xFontNode, sPathToFont, PresenterTheme::SharedFontDescriptor()));
1272*cdf0e10cSrcweir     if (pFont.get() != NULL)
1273*cdf0e10cSrcweir         pStyle->mpFont = pFont;
1274*cdf0e10cSrcweir 
1275*cdf0e10cSrcweir     Reference<container::XHierarchicalNameAccess> xBackgroundNode (
1276*cdf0e10cSrcweir         PresenterConfigurationAccess::GetProperty(rxProperties, A2S("Background")),
1277*cdf0e10cSrcweir         UNO_QUERY);
1278*cdf0e10cSrcweir     SharedBitmapDescriptor pBackground (PresenterBitmapContainer::LoadBitmap(
1279*cdf0e10cSrcweir         xBackgroundNode,
1280*cdf0e10cSrcweir         OUString(),
1281*cdf0e10cSrcweir         rReadContext.mxPresenterHelper,
1282*cdf0e10cSrcweir         rReadContext.msBasePath,
1283*cdf0e10cSrcweir         rReadContext.mxCanvas,
1284*cdf0e10cSrcweir         SharedBitmapDescriptor()));
1285*cdf0e10cSrcweir     if (pBackground.get() != NULL && pBackground->GetNormalBitmap().is())
1286*cdf0e10cSrcweir         pStyle->mpBackground = pBackground;
1287*cdf0e10cSrcweir 
1288*cdf0e10cSrcweir     push_back(pStyle);
1289*cdf0e10cSrcweir }
1290*cdf0e10cSrcweir 
1291*cdf0e10cSrcweir 
1292*cdf0e10cSrcweir 
1293*cdf0e10cSrcweir 
1294*cdf0e10cSrcweir SharedViewStyle ViewStyleContainer::GetViewStyle (const OUString& rsStyleName) const
1295*cdf0e10cSrcweir {
1296*cdf0e10cSrcweir     const_iterator iEnd (end());
1297*cdf0e10cSrcweir     for (const_iterator iStyle=begin(); iStyle!=iEnd; ++iStyle)
1298*cdf0e10cSrcweir         if ((*iStyle)->msStyleName == rsStyleName)
1299*cdf0e10cSrcweir             return *iStyle;
1300*cdf0e10cSrcweir     return SharedViewStyle();
1301*cdf0e10cSrcweir }
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir 
1306*cdf0e10cSrcweir //===== ViewStyle =============================================================
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir ViewStyle::ViewStyle (void)
1309*cdf0e10cSrcweir     : msStyleName(),
1310*cdf0e10cSrcweir       mpParentStyle(),
1311*cdf0e10cSrcweir       mpFont(),
1312*cdf0e10cSrcweir       mpBackground()
1313*cdf0e10cSrcweir {
1314*cdf0e10cSrcweir }
1315*cdf0e10cSrcweir 
1316*cdf0e10cSrcweir 
1317*cdf0e10cSrcweir 
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir ViewStyle::~ViewStyle (void)
1320*cdf0e10cSrcweir {
1321*cdf0e10cSrcweir }
1322*cdf0e10cSrcweir 
1323*cdf0e10cSrcweir 
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir const SharedBitmapDescriptor ViewStyle::GetBitmap (const OUString& rsBitmapName) const
1327*cdf0e10cSrcweir {
1328*cdf0e10cSrcweir     if (rsBitmapName == A2S("Background"))
1329*cdf0e10cSrcweir         return mpBackground;
1330*cdf0e10cSrcweir     else
1331*cdf0e10cSrcweir         return SharedBitmapDescriptor();
1332*cdf0e10cSrcweir }
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir 
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor ViewStyle::GetFont (void) const
1338*cdf0e10cSrcweir {
1339*cdf0e10cSrcweir     if (mpFont.get() != NULL)
1340*cdf0e10cSrcweir         return mpFont;
1341*cdf0e10cSrcweir     else if (mpParentStyle.get() != NULL)
1342*cdf0e10cSrcweir         return mpParentStyle->GetFont();
1343*cdf0e10cSrcweir     else
1344*cdf0e10cSrcweir         return PresenterTheme::SharedFontDescriptor();
1345*cdf0e10cSrcweir }
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir 
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir //===== StyleAssociationContainer =============================================
1351*cdf0e10cSrcweir 
1352*cdf0e10cSrcweir void StyleAssociationContainer::Read (
1353*cdf0e10cSrcweir     ReadContext& rReadContext,
1354*cdf0e10cSrcweir     const Reference<container::XHierarchicalNameAccess>& rxThemeRoot)
1355*cdf0e10cSrcweir {
1356*cdf0e10cSrcweir     Reference<container::XNameAccess> xStyleAssociationList (
1357*cdf0e10cSrcweir         PresenterConfigurationAccess::GetConfigurationNode(
1358*cdf0e10cSrcweir             rxThemeRoot,
1359*cdf0e10cSrcweir             A2S("StyleAssociations")),
1360*cdf0e10cSrcweir         UNO_QUERY);
1361*cdf0e10cSrcweir     if (xStyleAssociationList.is())
1362*cdf0e10cSrcweir     {
1363*cdf0e10cSrcweir         ::std::vector<rtl::OUString> aProperties (2);
1364*cdf0e10cSrcweir         aProperties[0] = A2S("ResourceURL");
1365*cdf0e10cSrcweir         aProperties[1] = A2S("StyleName");
1366*cdf0e10cSrcweir         PresenterConfigurationAccess::ForAll(
1367*cdf0e10cSrcweir             xStyleAssociationList,
1368*cdf0e10cSrcweir             aProperties,
1369*cdf0e10cSrcweir             ::boost::bind(&StyleAssociationContainer::ProcessStyleAssociation,
1370*cdf0e10cSrcweir                 this, ::boost::ref(rReadContext), _1, _2));
1371*cdf0e10cSrcweir     }
1372*cdf0e10cSrcweir }
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir 
1376*cdf0e10cSrcweir 
1377*cdf0e10cSrcweir OUString StyleAssociationContainer::GetStyleName (const OUString& rsResourceName) const
1378*cdf0e10cSrcweir {
1379*cdf0e10cSrcweir     StyleAssociations::const_iterator iAssociation (maStyleAssociations.find(rsResourceName));
1380*cdf0e10cSrcweir     if (iAssociation != maStyleAssociations.end())
1381*cdf0e10cSrcweir         return iAssociation->second;
1382*cdf0e10cSrcweir     else
1383*cdf0e10cSrcweir         return OUString();
1384*cdf0e10cSrcweir }
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir 
1389*cdf0e10cSrcweir void StyleAssociationContainer::ProcessStyleAssociation(
1390*cdf0e10cSrcweir     ReadContext& rReadContext,
1391*cdf0e10cSrcweir     const OUString& rsKey,
1392*cdf0e10cSrcweir     const ::std::vector<Any>& rValues)
1393*cdf0e10cSrcweir {
1394*cdf0e10cSrcweir     (void)rReadContext;
1395*cdf0e10cSrcweir     (void)rsKey;
1396*cdf0e10cSrcweir 
1397*cdf0e10cSrcweir     if (rValues.size() != 2)
1398*cdf0e10cSrcweir         return;
1399*cdf0e10cSrcweir 
1400*cdf0e10cSrcweir     OUString sResourceURL;
1401*cdf0e10cSrcweir     OUString sStyleName;
1402*cdf0e10cSrcweir     if ((rValues[0] >>= sResourceURL)
1403*cdf0e10cSrcweir         && (rValues[1] >>= sStyleName))
1404*cdf0e10cSrcweir     {
1405*cdf0e10cSrcweir         maStyleAssociations[sResourceURL] = sStyleName;
1406*cdf0e10cSrcweir     }
1407*cdf0e10cSrcweir }
1408*cdf0e10cSrcweir 
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir 
1411*cdf0e10cSrcweir 
1412*cdf0e10cSrcweir } // end of anonymous namespace
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir } } // end of namespace ::sdext::presenter
1415