1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SDEXT_PRESENTER_BITMAP_CONTAINER_HXX
25 #define SDEXT_PRESENTER_BITMAP_CONTAINER_HXX
26 
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
29 #include <com/sun/star/container/XNameAccess.hpp>
30 #include <com/sun/star/drawing/XPresenterHelper.hpp>
31 #include <com/sun/star/rendering/XBitmap.hpp>
32 #include <com/sun/star/rendering/XCanvas.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/util/Color.hpp>
35 #include <boost/noncopyable.hpp>
36 #include <boost/scoped_ptr.hpp>
37 #include <map>
38 #include <vector>
39 #include <boost/shared_ptr.hpp>
40 
41 namespace css = ::com::sun::star;
42 
43 
44 namespace sdext { namespace presenter {
45 
46 /** Manage a set of bitmap groups as they are used for buttons: three
47     bitmaps, one for the normal state, one for a mouse over effect and one
48     to show that the button has been pressed.
49     A bitmap group is defined by some entries in the configuration.
50 */
51 class PresenterBitmapContainer
52     : private ::boost::noncopyable
53 {
54 public:
55     /** There is one bitmap for the normal state, one for a mouse over effect and one
56         to show that a button has been pressed.
57     */
58     class BitmapDescriptor
59     {
60     public:
61         BitmapDescriptor (void);
62         BitmapDescriptor (const ::boost::shared_ptr<BitmapDescriptor>& rpDefault);
63 
64         enum Mode {Normal, MouseOver, ButtonDown, Disabled, Mask};
65         css::uno::Reference<css::rendering::XBitmap> GetNormalBitmap (void) const;
66         css::uno::Reference<css::rendering::XBitmap> GetBitmap (
67             const Mode eMode,
68             const bool bMissingDefaultsToNormal = true) const;
69         void SetBitmap (
70             const Mode eMode,
71             const css::uno::Reference<css::rendering::XBitmap>& rxBitmap);
72 
73         sal_Int32 mnWidth;
74         sal_Int32 mnHeight;
75         sal_Int32 mnXOffset;
76         sal_Int32 mnYOffset;
77         sal_Int32 mnXHotSpot;
78         sal_Int32 mnYHotSpot;
79         css::util::Color maReplacementColor;
80         enum TexturingMode { Once, Repeat, Stretch };
81         TexturingMode meHorizontalTexturingMode;
82         TexturingMode meVerticalTexturingMode;
83 
84     private:
85         css::uno::Reference<css::rendering::XBitmap> mxNormalBitmap;
86         css::uno::Reference<css::rendering::XBitmap> mxMouseOverBitmap;
87         css::uno::Reference<css::rendering::XBitmap> mxButtonDownBitmap;
88         css::uno::Reference<css::rendering::XBitmap> mxDisabledBitmap;
89         css::uno::Reference<css::rendering::XBitmap> mxMaskBitmap;
90     };
91 
92     /** Create a new bitmap container from a section of the configuration.
93         @param rxComponentContext
94             The component context is used to create new API objects.
95         @param rxCanvas
96             Bitmaps are created specifically for this canvas.
97         @param rsConfigurationBase
98             The name of a configuration node whose sub-tree defines the
99             bitmap sets.
100     */
101     PresenterBitmapContainer (
102         const ::rtl::OUString& rsConfigurationBase,
103         const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
104         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
105         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
106         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper = NULL);
107     PresenterBitmapContainer (
108         const css::uno::Reference<css::container::XNameAccess>& rsRootNode,
109         const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
110         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
111         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
112         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper = NULL);
113     ~PresenterBitmapContainer (void);
114 
115     void Initialize (
116         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext);
117 
118     /** Return the bitmap set that is associated with the given name.
119     */
120     ::boost::shared_ptr<BitmapDescriptor> GetBitmap (const ::rtl::OUString& rsName) const;
121 
122     static ::boost::shared_ptr<BitmapDescriptor> LoadBitmap (
123         const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
124         const ::rtl::OUString& rsPathToBitmapNode,
125         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
126         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
127         const ::boost::shared_ptr<BitmapDescriptor>& rpDefaultBitmap);
128 
129 private:
130     ::boost::shared_ptr<PresenterBitmapContainer> mpParentContainer;
131     typedef ::std::map<rtl::OUString, ::boost::shared_ptr<BitmapDescriptor> > BitmapContainer;
132     BitmapContainer maIconContainer;
133     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
134     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
135 
136     void LoadBitmaps (
137         const css::uno::Reference<css::container::XNameAccess>& rsRootNode);
138     void ProcessBitmap (
139         const ::rtl::OUString& rsKey,
140         const css::uno::Reference<css::beans::XPropertySet>& rProperties);
141     static ::boost::shared_ptr<BitmapDescriptor> LoadBitmap (
142         const css::uno::Reference<css::beans::XPropertySet>& rxProperties,
143         const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
144         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
145         const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault);
146     static BitmapDescriptor::TexturingMode
147         StringToTexturingMode (const ::rtl::OUString& rsTexturingMode);
148 };
149 
150 
151 typedef PresenterBitmapContainer::BitmapDescriptor PresenterBitmapDescriptor;
152 typedef ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> SharedBitmapDescriptor;
153 
154 } } // end of namespace ::sdext::presenter
155 
156 #endif
157