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_PANE_CONTAINER_HXX
25 #define SDEXT_PRESENTER_PANE_CONTAINER_HXX
26 
27 #include "PresenterTheme.hxx"
28 #include <com/sun/star/awt/Point.hpp>
29 #include <com/sun/star/awt/Rectangle.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/drawing/XPresenterHelper.hpp>
32 #include <com/sun/star/drawing/framework/XResourceId.hpp>
33 #include <com/sun/star/drawing/framework/XPane.hpp>
34 #include <com/sun/star/drawing/framework/XView.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/util/Color.hpp>
37 #include <cppuhelper/basemutex.hxx>
38 #include <cppuhelper/compbase1.hxx>
39 #include <rtl/ref.hxx>
40 #include <vector>
41 #include <boost/function.hpp>
42 #include <boost/noncopyable.hpp>
43 #include <boost/shared_ptr.hpp>
44 
45 namespace css = ::com::sun::star;
46 
47 namespace sdext { namespace presenter {
48 
49 class PresenterPaneBase;
50 class PresenterSprite;
51 
52 namespace {
53     typedef ::cppu::WeakComponentImplHelper1 <
54         css::lang::XEventListener
55     > PresenterPaneContainerInterfaceBase;
56 }
57 
58 /** This class could also be called PresenterPaneAndViewContainer because it
59     stores not only references to all panes that belong to the presenter
60     screen but stores the views displayed in these panes as well.
61 */
62 class PresenterPaneContainer
63     : private ::boost::noncopyable,
64       private ::cppu::BaseMutex,
65       public PresenterPaneContainerInterfaceBase
66 {
67 public:
68     PresenterPaneContainer (
69         const css::uno::Reference<css::uno::XComponentContext>& rxContext);
70     virtual ~PresenterPaneContainer (void);
71 
72     virtual void SAL_CALL disposing (void);
73 
74     typedef ::boost::function1<void, const css::uno::Reference<css::drawing::framework::XView>&>
75         ViewInitializationFunction;
76 
77     /** Each pane descriptor holds references to one pane and the view
78         displayed in this pane as well as the other information that is used
79         to manage the pane window like an XWindow reference, the title, and
80         the coordinates.
81 
82         A initialization function for the view is stored as well.  This
83         function is executed as soon as a view is created.
84     */
85     class PaneDescriptor
86     {
87     public:
88         typedef ::boost::function<void(bool)> Activator;
89         typedef ::boost::function<boost::shared_ptr<PresenterSprite>()> SpriteProvider;
90         css::uno::Reference<css::drawing::framework::XResourceId> mxPaneId;
91         ::rtl::OUString msViewURL;
92         ::rtl::Reference<PresenterPaneBase> mxPane;
93         css::uno::Reference<css::drawing::framework::XView> mxView;
94         css::uno::Reference<css::awt::XWindow> mxContentWindow;
95         css::uno::Reference<css::awt::XWindow> mxBorderWindow;
96         ::rtl::OUString msTitleTemplate;
97         ::rtl::OUString msAccessibleTitleTemplate;
98         ::rtl::OUString msTitle;
99         ViewInitializationFunction maViewInitialization;
100         double mnLeft;
101         double mnTop;
102         double mnRight;
103         double mnBottom;
104         SharedBitmapDescriptor mpViewBackground;
105         bool mbIsActive;
106         bool mbNeedsClipping;
107         bool mbIsOpaque;
108         SpriteProvider maSpriteProvider;
109         bool mbIsSprite;
110         Activator maActivator;
111         css::awt::Point maCalloutAnchorLocation;
112         bool mbHasCalloutAnchor;
113 
114         void SetActivationState (const bool bIsActive);
115     };
116     typedef ::boost::shared_ptr<PaneDescriptor> SharedPaneDescriptor;
117     typedef ::std::vector<SharedPaneDescriptor> PaneList;
118     PaneList maPanes;
119 
120     void PreparePane (
121         const css::uno::Reference<css::drawing::framework::XResourceId>& rxPaneId,
122         const ::rtl::OUString& rsViewURL,
123         const ::rtl::OUString& rsTitle,
124         const ::rtl::OUString& rsAccessibleTitle,
125         const bool bIsOpaque,
126         const ViewInitializationFunction& rViewIntialization,
127         const double nLeft,
128         const double nTop,
129         const double nRight,
130         const double nBottom);
131 
132     SharedPaneDescriptor StorePane (
133         const rtl::Reference<PresenterPaneBase>& rxPane);
134 
135     SharedPaneDescriptor StoreBorderWindow(
136         const css::uno::Reference<css::drawing::framework::XResourceId>& rxPaneId,
137         const css::uno::Reference<css::awt::XWindow>& rxBorderWindow);
138 
139     SharedPaneDescriptor StoreView (
140         const css::uno::Reference<css::drawing::framework::XView>& rxView,
141         const SharedBitmapDescriptor& rpViewBackground);
142 
143     SharedPaneDescriptor RemovePane (
144         const css::uno::Reference<css::drawing::framework::XResourceId>& rxPaneId);
145 
146     SharedPaneDescriptor RemoveView (
147         const css::uno::Reference<css::drawing::framework::XView>& rxView);
148 
149     void CreateBorderWindow (PaneDescriptor& rDescriptor);
150 
151     /** Find the pane whose border window is identical to the given border
152         window.
153     */
154     SharedPaneDescriptor FindBorderWindow (
155         const css::uno::Reference<css::awt::XWindow>& rxBorderWindow);
156 
157     /** Find the pane whose border window is identical to the given content
158         window.
159     */
160     SharedPaneDescriptor FindContentWindow (
161         const css::uno::Reference<css::awt::XWindow>& rxBorderWindow);
162 
163     /** Find the pane whose pane URL is identical to the given URL string.
164     */
165     SharedPaneDescriptor FindPaneURL (const ::rtl::OUString& rsPaneURL);
166 
167     /** Find the pane whose resource id is identical to the given one.
168     */
169     SharedPaneDescriptor FindPaneId (const css::uno::Reference<
170         css::drawing::framework::XResourceId>& rxPaneId);
171 
172     SharedPaneDescriptor FindViewURL (const ::rtl::OUString& rsViewURL);
173 
174     ::rtl::OUString GetPaneURLForViewURL (const ::rtl::OUString& rsViewURL);
175 
176     void ToTop (const SharedPaneDescriptor& rpDescriptor);
177 
178 
179     // XEventListener
180 
181     virtual void SAL_CALL disposing (
182         const com::sun::star::lang::EventObject& rEvent)
183         throw (com::sun::star::uno::RuntimeException);
184 
185 private:
186     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
187 
188     PaneList::const_iterator FindIteratorForPaneURL (const ::rtl::OUString& rsPaneURL);
189 };
190 
191 } } // end of namespace ::sdext::presenter
192 
193 #endif
194