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_BITMAP_CONTAINER_HXX
29 #define SDEXT_PRESENTER_BITMAP_CONTAINER_HXX
30 
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/drawing/XPresenterHelper.hpp>
35 #include <com/sun/star/rendering/XBitmap.hpp>
36 #include <com/sun/star/rendering/XCanvas.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/util/Color.hpp>
39 #include <boost/noncopyable.hpp>
40 #include <boost/scoped_ptr.hpp>
41 #include <map>
42 #include <vector>
43 #include <boost/shared_ptr.hpp>
44 
45 namespace css = ::com::sun::star;
46 
47 
48 namespace sdext { namespace presenter {
49 
50 /** Manage a set of bitmap groups as they are used for buttons: three
51     bitmaps, one for the normal state, one for a mouse over effect and one
52     to show that the button has been pressed.
53     A bitmap group is defined by some entries in the configuration.
54 */
55 class PresenterBitmapContainer
56     : private ::boost::noncopyable
57 {
58 public:
59     /** There is one bitmap for the normal state, one for a mouse over effect and one
60         to show that a button has been pressed.
61     */
62     class BitmapDescriptor
63     {
64     public:
65         BitmapDescriptor (void);
66         BitmapDescriptor (const ::boost::shared_ptr<BitmapDescriptor>& rpDefault);
67 
68         enum Mode {Normal, MouseOver, ButtonDown, Disabled, Mask};
69         css::uno::Reference<css::rendering::XBitmap> GetNormalBitmap (void) const;
70         css::uno::Reference<css::rendering::XBitmap> GetBitmap (
71             const Mode eMode,
72             const bool bMissingDefaultsToNormal = true) const;
73         void SetBitmap (
74             const Mode eMode,
75             const css::uno::Reference<css::rendering::XBitmap>& rxBitmap);
76 
77         sal_Int32 mnWidth;
78         sal_Int32 mnHeight;
79         sal_Int32 mnXOffset;
80         sal_Int32 mnYOffset;
81         sal_Int32 mnXHotSpot;
82         sal_Int32 mnYHotSpot;
83         css::util::Color maReplacementColor;
84         enum TexturingMode { Once, Repeat, Stretch };
85         TexturingMode meHorizontalTexturingMode;
86         TexturingMode meVerticalTexturingMode;
87 
88     private:
89         css::uno::Reference<css::rendering::XBitmap> mxNormalBitmap;
90         css::uno::Reference<css::rendering::XBitmap> mxMouseOverBitmap;
91         css::uno::Reference<css::rendering::XBitmap> mxButtonDownBitmap;
92         css::uno::Reference<css::rendering::XBitmap> mxDisabledBitmap;
93         css::uno::Reference<css::rendering::XBitmap> mxMaskBitmap;
94     };
95 
96     /** Create a new bitmap container from a section of the configuration.
97         @param rxComponentContext
98             The component context is used to create new API objects.
99         @param rxCanvas
100             Bitmaps are created specifically for this canvas.
101         @param rsConfigurationBase
102             The name of a configuration node whose sub-tree defines the
103             bitmap sets.
104     */
105     PresenterBitmapContainer (
106         const ::rtl::OUString& rsConfigurationBase,
107         const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
108         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
109         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
110         const ::rtl::OUString& rsBasePath,
111         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper = NULL);
112     PresenterBitmapContainer (
113         const css::uno::Reference<css::container::XNameAccess>& rsRootNode,
114         const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
115         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
116         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
117         const ::rtl::OUString& rsBasePath,
118         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper = NULL);
119     ~PresenterBitmapContainer (void);
120 
121     void Initialize (
122         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext);
123 
124     /** Return the bitmap set that is associated with the given name.
125     */
126     ::boost::shared_ptr<BitmapDescriptor> GetBitmap (const ::rtl::OUString& rsName) const;
127 
128     static ::boost::shared_ptr<BitmapDescriptor> LoadBitmap (
129         const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
130         const ::rtl::OUString& rsPathToBitmapNode,
131         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
132         const ::rtl::OUString& rsBitmapBasePath,
133         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
134         const ::boost::shared_ptr<BitmapDescriptor>& rpDefaultBitmap);
135 
136 private:
137     ::boost::shared_ptr<PresenterBitmapContainer> mpParentContainer;
138     typedef ::std::map<rtl::OUString, ::boost::shared_ptr<BitmapDescriptor> > BitmapContainer;
139     BitmapContainer maIconContainer;
140     ::rtl::OUString msBasePath;
141     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
142     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
143 
144     void LoadBitmaps (
145         const css::uno::Reference<css::container::XNameAccess>& rsRootNode);
146     void ProcessBitmap (
147         const ::rtl::OUString& rsKey,
148         const css::uno::Reference<css::beans::XPropertySet>& rProperties);
149     static ::boost::shared_ptr<BitmapDescriptor> LoadBitmap (
150         const css::uno::Reference<css::beans::XPropertySet>& rxProperties,
151         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
152         const ::rtl::OUString& rsBasePath,
153         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
154         const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault);
155     static BitmapDescriptor::TexturingMode
156         StringToTexturingMode (const ::rtl::OUString& rsTexturingMode);
157 };
158 
159 
160 typedef PresenterBitmapContainer::BitmapDescriptor PresenterBitmapDescriptor;
161 typedef ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> SharedBitmapDescriptor;
162 
163 } } // end of namespace ::sdext::presenter
164 
165 #endif
166