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