Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "PresenterPaneContainer.hxx"
21 : #include "PresenterPaneBase.hxx"
22 : #include <com/sun/star/awt/XGraphics.hpp>
23 : #include <com/sun/star/beans/XPropertySet.hpp>
24 : #include <com/sun/star/container/XChild.hpp>
25 : #include <com/sun/star/drawing/framework/ResourceId.hpp>
26 : #include <vector>
27 :
28 : using namespace ::com::sun::star;
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::drawing::framework;
31 : using ::rtl::OUString;
32 :
33 : namespace sdext { namespace presenter {
34 :
35 0 : PresenterPaneContainer::PresenterPaneContainer (
36 : const Reference<XComponentContext>& rxContext)
37 : : PresenterPaneContainerInterfaceBase(m_aMutex),
38 : maPanes(),
39 0 : mxPresenterHelper()
40 : {
41 0 : Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
42 0 : if (xFactory.is())
43 : {
44 : mxPresenterHelper = Reference<drawing::XPresenterHelper>(
45 0 : xFactory->createInstanceWithContext(
46 : OUString("com.sun.star.comp.Draw.PresenterHelper"),
47 0 : rxContext),
48 0 : UNO_QUERY_THROW);
49 0 : }
50 0 : }
51 :
52 0 : PresenterPaneContainer::~PresenterPaneContainer (void)
53 : {
54 0 : }
55 :
56 0 : void PresenterPaneContainer::PreparePane (
57 : const Reference<XResourceId>& rxPaneId,
58 : const OUString& rsViewURL,
59 : const OUString& rsTitle,
60 : const OUString& rsAccessibleTitle,
61 : const bool bIsOpaque,
62 : const ViewInitializationFunction& rViewInitialization,
63 : const double nLeft,
64 : const double nTop,
65 : const double nRight,
66 : const double nBottom)
67 : {
68 0 : if ( ! rxPaneId.is())
69 0 : return;
70 :
71 0 : SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
72 0 : if (pPane.get() == NULL)
73 : {
74 : // No entry found for the given pane id. Create a new one.
75 0 : SharedPaneDescriptor pDescriptor (new PaneDescriptor());
76 0 : pDescriptor->mxPaneId = rxPaneId;
77 0 : pDescriptor->msViewURL = rsViewURL;
78 0 : pDescriptor->mxPane = NULL;
79 0 : if (rsTitle.indexOf('%') < 0)
80 : {
81 0 : pDescriptor->msTitle = rsTitle;
82 0 : pDescriptor->msTitleTemplate = OUString();
83 : }
84 : else
85 : {
86 0 : pDescriptor->msTitleTemplate = rsTitle;
87 0 : pDescriptor->msTitle = OUString();
88 : }
89 0 : pDescriptor->msAccessibleTitleTemplate = rsAccessibleTitle;
90 0 : pDescriptor->maViewInitialization = rViewInitialization;
91 0 : pDescriptor->mnLeft = nLeft;
92 0 : pDescriptor->mnTop = nTop;
93 0 : pDescriptor->mnRight = nRight;
94 0 : pDescriptor->mnBottom = nBottom;
95 0 : pDescriptor->mbIsActive = true;
96 0 : pDescriptor->mbIsOpaque = bIsOpaque;
97 0 : pDescriptor->maSpriteProvider = PaneDescriptor::SpriteProvider();
98 0 : pDescriptor->mbIsSprite = false;
99 0 : pDescriptor->maCalloutAnchorLocation = awt::Point(-1,-1);
100 0 : pDescriptor->mbHasCalloutAnchor = false;
101 :
102 0 : maPanes.push_back(pDescriptor);
103 0 : }
104 : }
105 :
106 0 : void SAL_CALL PresenterPaneContainer::disposing (void)
107 : {
108 0 : PaneList::iterator iPane (maPanes.begin());
109 0 : PaneList::const_iterator iEnd (maPanes.end());
110 0 : for ( ; iPane!=iEnd; ++iPane)
111 0 : if ((*iPane)->mxPaneId.is())
112 0 : RemovePane((*iPane)->mxPaneId);
113 0 : }
114 :
115 : PresenterPaneContainer::SharedPaneDescriptor
116 0 : PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
117 : {
118 0 : SharedPaneDescriptor pDescriptor;
119 :
120 0 : if (rxPane.is())
121 : {
122 0 : OUString sPaneURL;
123 0 : Reference<XResourceId> xPaneId (rxPane->getResourceId());
124 0 : if (xPaneId.is())
125 0 : sPaneURL = xPaneId->getResourceURL();
126 :
127 0 : pDescriptor = FindPaneURL(sPaneURL);
128 0 : if (pDescriptor.get() == NULL)
129 : PreparePane(xPaneId, OUString(), OUString(), OUString(),
130 0 : false, ViewInitializationFunction(), 0,0,0,0);
131 0 : pDescriptor = FindPaneURL(sPaneURL);
132 0 : if (pDescriptor.get() != NULL)
133 : {
134 0 : Reference<awt::XWindow> xWindow (rxPane->getWindow());
135 0 : pDescriptor->mxContentWindow = xWindow;
136 0 : pDescriptor->mxPaneId = xPaneId;
137 0 : pDescriptor->mxPane = rxPane;
138 0 : pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
139 :
140 : // When there is a call out anchor location set then tell the
141 : // window about it.
142 0 : if (pDescriptor->mbHasCalloutAnchor)
143 0 : pDescriptor->mxPane->SetCalloutAnchor(pDescriptor->maCalloutAnchorLocation);
144 :
145 0 : if (xWindow.is())
146 0 : xWindow->addEventListener(this);
147 0 : }
148 : }
149 :
150 0 : return pDescriptor;
151 : }
152 :
153 : PresenterPaneContainer::SharedPaneDescriptor
154 0 : PresenterPaneContainer::StoreBorderWindow(
155 : const Reference<XResourceId>& rxPaneId,
156 : const Reference<awt::XWindow>& rxBorderWindow)
157 : {
158 : // The content window may not be present. Use the resource URL of the
159 : // pane id as key.
160 0 : OUString sPaneURL;
161 0 : if (rxPaneId.is())
162 0 : sPaneURL = rxPaneId->getResourceURL();
163 :
164 0 : SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
165 0 : if (pDescriptor.get() != NULL)
166 : {
167 0 : pDescriptor->mxBorderWindow = rxBorderWindow;
168 0 : return pDescriptor;
169 : }
170 : else
171 0 : return SharedPaneDescriptor();
172 : }
173 :
174 : PresenterPaneContainer::SharedPaneDescriptor
175 0 : PresenterPaneContainer::StoreView (
176 : const Reference<XView>& rxView,
177 : const SharedBitmapDescriptor& rpViewBackground)
178 : {
179 0 : SharedPaneDescriptor pDescriptor;
180 :
181 0 : if (rxView.is())
182 : {
183 0 : OUString sPaneURL;
184 0 : Reference<XResourceId> xViewId (rxView->getResourceId());
185 0 : if (xViewId.is())
186 : {
187 0 : Reference<XResourceId> xPaneId (xViewId->getAnchor());
188 0 : if (xPaneId.is())
189 0 : sPaneURL = xPaneId->getResourceURL();
190 : }
191 :
192 0 : pDescriptor = FindPaneURL(sPaneURL);
193 0 : if (pDescriptor.get() != NULL)
194 : {
195 0 : pDescriptor->mxView = rxView;
196 0 : pDescriptor->mpViewBackground = rpViewBackground;
197 0 : pDescriptor->mxPane->SetBackground(rpViewBackground);
198 : try
199 : {
200 0 : if ( ! pDescriptor->maViewInitialization.empty())
201 0 : pDescriptor->maViewInitialization(rxView);
202 :
203 : // Activate or deactivate the pane/view.
204 0 : if ( ! pDescriptor->maActivator.empty())
205 0 : pDescriptor->maActivator(pDescriptor->mbIsActive);
206 : }
207 0 : catch (RuntimeException&)
208 : {
209 : OSL_ASSERT(false);
210 : }
211 0 : }
212 : }
213 :
214 0 : return pDescriptor;
215 : }
216 :
217 : PresenterPaneContainer::SharedPaneDescriptor
218 0 : PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
219 : {
220 0 : SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
221 0 : if (pDescriptor.get() != NULL)
222 : {
223 0 : if (pDescriptor->mxContentWindow.is())
224 0 : pDescriptor->mxContentWindow->removeEventListener(this);
225 0 : pDescriptor->mxContentWindow = NULL;
226 0 : pDescriptor->mxBorderWindow = NULL;
227 0 : pDescriptor->mxPane = NULL;
228 0 : pDescriptor->mxView = NULL;
229 0 : pDescriptor->mbIsActive = false;
230 : }
231 0 : return pDescriptor;
232 : }
233 :
234 : PresenterPaneContainer::SharedPaneDescriptor
235 0 : PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
236 : {
237 0 : SharedPaneDescriptor pDescriptor;
238 :
239 0 : if (rxView.is())
240 : {
241 0 : OUString sPaneURL;
242 0 : Reference<XResourceId> xViewId (rxView->getResourceId());
243 0 : if (xViewId.is())
244 : {
245 0 : Reference<XResourceId> xPaneId (xViewId->getAnchor());
246 0 : if (xPaneId.is())
247 0 : sPaneURL = xPaneId->getResourceURL();
248 : }
249 :
250 0 : pDescriptor = FindPaneURL(sPaneURL);
251 0 : if (pDescriptor.get() != NULL)
252 : {
253 0 : pDescriptor->mxView = NULL;
254 0 : pDescriptor->mpViewBackground = SharedBitmapDescriptor();
255 0 : }
256 : }
257 :
258 0 : return pDescriptor;
259 : }
260 :
261 0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
262 : const Reference<awt::XWindow>& rxBorderWindow)
263 : {
264 0 : PaneList::const_iterator iPane;
265 0 : PaneList::iterator iEnd (maPanes.end());
266 0 : for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
267 : {
268 0 : if ((*iPane)->mxBorderWindow == rxBorderWindow)
269 0 : return *iPane;
270 : }
271 0 : return SharedPaneDescriptor();
272 : }
273 :
274 0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
275 : const Reference<awt::XWindow>& rxContentWindow)
276 : {
277 0 : PaneList::const_iterator iPane;
278 0 : PaneList::iterator iEnd (maPanes.end());
279 0 : for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
280 : {
281 0 : if ((*iPane)->mxContentWindow == rxContentWindow)
282 0 : return *iPane;
283 : }
284 0 : return SharedPaneDescriptor();
285 : }
286 :
287 0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
288 : const OUString& rsPaneURL)
289 : {
290 0 : PaneList::const_iterator iPane;
291 0 : PaneList::const_iterator iEnd (maPanes.end());
292 0 : for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
293 : {
294 0 : if ((*iPane)->mxPaneId->getResourceURL() == rsPaneURL)
295 0 : return *iPane;
296 : }
297 0 : return SharedPaneDescriptor();
298 : }
299 :
300 0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
301 : const Reference<XResourceId>& rxPaneId)
302 : {
303 0 : PaneList::iterator iEnd (maPanes.end());
304 :
305 0 : if ( ! rxPaneId.is())
306 0 : return SharedPaneDescriptor();
307 :
308 0 : PaneList::iterator iPane;
309 0 : for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
310 : {
311 0 : if (rxPaneId->compareTo((*iPane)->mxPaneId) == 0)
312 0 : return *iPane;
313 : }
314 0 : return SharedPaneDescriptor();
315 : }
316 :
317 0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
318 : const OUString& rsViewURL)
319 : {
320 0 : PaneList::iterator iEnd (maPanes.end());
321 0 : PaneList::iterator iPane;
322 0 : for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
323 : {
324 0 : if (rsViewURL == (*iPane)->msViewURL)
325 0 : return *iPane;
326 : }
327 0 : return SharedPaneDescriptor();
328 : }
329 :
330 0 : ::rtl::OUString PresenterPaneContainer::GetPaneURLForViewURL (const ::rtl::OUString& rsViewURL)
331 : {
332 0 : SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
333 0 : if (pDescriptor.get() != NULL)
334 0 : if (pDescriptor->mxPaneId.is())
335 0 : return pDescriptor->mxPaneId->getResourceURL();
336 0 : return OUString();
337 : }
338 :
339 0 : void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
340 : {
341 0 : if (rpDescriptor.get() != NULL)
342 : {
343 : // Find iterator for pDescriptor.
344 0 : PaneList::iterator iPane;
345 0 : PaneList::iterator iEnd (maPanes.end());
346 0 : for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
347 0 : if (iPane->get() == rpDescriptor.get())
348 0 : break;
349 : OSL_ASSERT(iPane!=iEnd);
350 0 : if (iPane == iEnd)
351 0 : return;
352 :
353 0 : if (mxPresenterHelper.is())
354 0 : mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
355 :
356 0 : maPanes.erase(iPane);
357 0 : maPanes.push_back(rpDescriptor);
358 : }
359 : }
360 :
361 : //----- XEventListener --------------------------------------------------------
362 :
363 0 : void SAL_CALL PresenterPaneContainer::disposing (
364 : const com::sun::star::lang::EventObject& rEvent)
365 : throw (com::sun::star::uno::RuntimeException)
366 : {
367 : SharedPaneDescriptor pDescriptor (
368 0 : FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
369 0 : if (pDescriptor.get() != NULL)
370 : {
371 0 : RemovePane(pDescriptor->mxPaneId);
372 0 : }
373 0 : }
374 :
375 : //===== PresenterPaneContainer::PaneDescriptor ================================
376 :
377 0 : void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
378 : {
379 0 : mbIsActive = bIsActive;
380 0 : if ( ! maActivator.empty())
381 0 : maActivator(mbIsActive);
382 0 : }
383 :
384 : } } // end of namespace ::sdext::presenter
385 :
386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|