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