1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SDEXT_PRESENTER_PRESENTER_THEME_HXX
29 #define SDEXT_PRESENTER_PRESENTER_THEME_HXX
30 
31 #include "PresenterBitmapContainer.hxx"
32 #include "PresenterConfigurationAccess.hxx"
33 #include "PresenterTheme.hxx"
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <com/sun/star/rendering/XCanvasFont.hpp>
37 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
38 #include <com/sun/star/util/Color.hpp>
39 #include <boost/shared_ptr.hpp>
40 
41 namespace css = ::com::sun::star;
42 
43 namespace sdext { namespace presenter {
44 
45 /** A theme is a set of properties describing fonts, colors, and bitmaps to be used to draw
46     background, pane borders, and view content.
47 
48     At the moment the properties can be accessed via the getPropertyValue() method.
49 
50     For a resource URL of a pane or a view you get the name of the
51     associated PaneStyle or ViewStyle.
52 
53     For the name of pane or view style suffixed with and underscore and the
54     name of configuration property, and maybe additionally suffixed by
55     another underscore and sub property name you get the associated
56     property.
57 
58     Example: you want to access the top left bitmap of a pane border
59         (simplified code):
60 
61     String sStyleName = getPropertyValue("private:resource/pane/Presenter/Pane1");
62     XBitmap xBitmap = getPropertyValue(sStyleName + "_TopLeftBitmap");
63 
64     For the offset of the bitmap you can call
65     Point aOffset = getPropertyValue(sStyleName + "_TopLeftOffset");
66 
67     This is work in progress.
68 */
69 class PresenterTheme
70 {
71 public:
72     PresenterTheme (
73         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
74         const rtl::OUString& rsThemeName,
75         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
76     ~PresenterTheme (void);
77 
78     void SAL_CALL disposing (void);
79 
80     bool HasCanvas (void) const;
81     void ProvideCanvas (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
82 
83     ::rtl::OUString GetStyleName (const ::rtl::OUString& rsResourceURL) const;
84     ::std::vector<sal_Int32> GetBorderSize (
85         const ::rtl::OUString& rsStyleName,
86         const bool bOuter) const;
87 
88     class FontDescriptor;
89     class Theme;
90 
91     class FontDescriptor
92     {
93     public:
94         explicit FontDescriptor (void);
95         explicit FontDescriptor (const ::boost::shared_ptr<FontDescriptor>& rpDescriptor);
96 
97         ::rtl::OUString msFamilyName;
98         ::rtl::OUString msStyleName;
99         sal_Int32 mnSize;
100         sal_uInt32 mnColor;
101         ::rtl::OUString msAnchor;
102         sal_Int32 mnXOffset;
103         sal_Int32 mnYOffset;
104         css::uno::Reference<css::rendering::XCanvasFont> mxFont;
105 
106         bool PrepareFont (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
107 
108     private:
109         css::uno::Reference<css::rendering::XCanvasFont> CreateFont (
110             const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
111             const double nCellSize) const;
112         double GetCellSizeForDesignSize (
113             const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
114             const double nDesignSize) const;
115     };
116     typedef ::boost::shared_ptr<FontDescriptor> SharedFontDescriptor;
117 
118     ::rtl::OUString GetThemeName (void) const;
119 
120     SharedBitmapDescriptor GetBitmap (
121         const ::rtl::OUString& rsStyleName,
122         const ::rtl::OUString& rsBitmapName) const;
123 
124     SharedBitmapDescriptor GetBitmap (
125         const ::rtl::OUString& rsBitmapName) const;
126 
127     ::boost::shared_ptr<PresenterBitmapContainer> GetBitmapContainer (void) const;
128 
129     SharedFontDescriptor GetFont (
130         const ::rtl::OUString& rsStyleName) const;
131 
132     static SharedFontDescriptor ReadFont (
133         const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
134         const ::rtl::OUString& rsFontPath,
135         const SharedFontDescriptor& rDefaultFount);
136 
137     static bool ConvertToColor (
138         const css::uno::Any& rColorSequence,
139         sal_uInt32& rColor);
140 
141     ::boost::shared_ptr<PresenterConfigurationAccess> GetNodeForViewStyle (
142         const ::rtl::OUString& rsStyleName,
143         const PresenterConfigurationAccess::WriteMode) const;
144 
145 private:
146     css::uno::Reference<css::uno::XComponentContext> mxContext;
147     const ::rtl::OUString msThemeName;
148     ::boost::shared_ptr<Theme> mpTheme;
149     ::boost::shared_ptr<PresenterBitmapContainer> mpBitmapContainer;
150     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
151 
152     ::boost::shared_ptr<Theme> ReadTheme (void);
153 };
154 
155 } } // end of namespace ::sd::presenter
156 
157 #endif
158