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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26
27 #include "PresenterPaneContainer.hxx"
28 #include "PresenterPaneBase.hxx"
29 #include <com/sun/star/awt/XGraphics.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/container/XChild.hpp>
32 #include <com/sun/star/drawing/framework/ResourceId.hpp>
33 #include <vector>
34
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::drawing::framework;
38 using ::rtl::OUString;
39
40 namespace sdext { namespace presenter {
41
PresenterPaneContainer(const Reference<XComponentContext> & rxContext)42 PresenterPaneContainer::PresenterPaneContainer (
43 const Reference<XComponentContext>& rxContext)
44 : PresenterPaneContainerInterfaceBase(m_aMutex),
45 maPanes(),
46 mxPresenterHelper()
47 {
48 Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
49 if (xFactory.is())
50 {
51 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
52 xFactory->createInstanceWithContext(
53 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
54 rxContext),
55 UNO_QUERY_THROW);
56 }
57 }
58
59
60
61
~PresenterPaneContainer(void)62 PresenterPaneContainer::~PresenterPaneContainer (void)
63 {
64 }
65
66
67
68
PreparePane(const Reference<XResourceId> & rxPaneId,const OUString & rsViewURL,const OUString & rsTitle,const OUString & rsAccessibleTitle,const bool bIsOpaque,const ViewInitializationFunction & rViewInitialization,const double nLeft,const double nTop,const double nRight,const double nBottom)69 void PresenterPaneContainer::PreparePane (
70 const Reference<XResourceId>& rxPaneId,
71 const OUString& rsViewURL,
72 const OUString& rsTitle,
73 const OUString& rsAccessibleTitle,
74 const bool bIsOpaque,
75 const ViewInitializationFunction& rViewInitialization,
76 const double nLeft,
77 const double nTop,
78 const double nRight,
79 const double nBottom)
80 {
81 if ( ! rxPaneId.is())
82 return;
83
84 SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
85 if (pPane.get() == NULL)
86 {
87 // No entry found for the given pane id. Create a new one.
88 SharedPaneDescriptor pDescriptor (new PaneDescriptor());
89 pDescriptor->mxPaneId = rxPaneId;
90 pDescriptor->msViewURL = rsViewURL;
91 pDescriptor->mxPane = NULL;
92 if (rsTitle.indexOf('%') < 0)
93 {
94 pDescriptor->msTitle = rsTitle;
95 pDescriptor->msTitleTemplate = OUString();
96 }
97 else
98 {
99 pDescriptor->msTitleTemplate = rsTitle;
100 pDescriptor->msTitle = OUString();
101 }
102 pDescriptor->msAccessibleTitleTemplate = rsAccessibleTitle;
103 pDescriptor->maViewInitialization = rViewInitialization;
104 pDescriptor->mnLeft = nLeft;
105 pDescriptor->mnTop = nTop;
106 pDescriptor->mnRight = nRight;
107 pDescriptor->mnBottom = nBottom;
108 pDescriptor->mbIsActive = true;
109 pDescriptor->mbIsOpaque = bIsOpaque;
110 pDescriptor->maSpriteProvider = PaneDescriptor::SpriteProvider();
111 pDescriptor->mbIsSprite = false;
112 pDescriptor->maCalloutAnchorLocation = awt::Point(-1,-1);
113 pDescriptor->mbHasCalloutAnchor = false;
114
115 maPanes.push_back(pDescriptor);
116 }
117 }
118
119
120
121
disposing(void)122 void SAL_CALL PresenterPaneContainer::disposing (void)
123 {
124 PaneList::iterator iPane (maPanes.begin());
125 PaneList::const_iterator iEnd (maPanes.end());
126 for ( ; iPane!=iEnd; ++iPane)
127 if ((*iPane)->mxPaneId.is())
128 RemovePane((*iPane)->mxPaneId);
129 }
130
131
132
133
134 PresenterPaneContainer::SharedPaneDescriptor
StorePane(const rtl::Reference<PresenterPaneBase> & rxPane)135 PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
136 {
137 SharedPaneDescriptor pDescriptor;
138
139 if (rxPane.is())
140 {
141 OUString sPaneURL;
142 Reference<XResourceId> xPaneId (rxPane->getResourceId());
143 if (xPaneId.is())
144 sPaneURL = xPaneId->getResourceURL();
145
146 pDescriptor = FindPaneURL(sPaneURL);
147 if (pDescriptor.get() == NULL)
148 PreparePane(xPaneId, OUString(), OUString(), OUString(),
149 false, ViewInitializationFunction(), 0,0,0,0);
150 pDescriptor = FindPaneURL(sPaneURL);
151 if (pDescriptor.get() != NULL)
152 {
153 Reference<awt::XWindow> xWindow (rxPane->getWindow());
154 pDescriptor->mxContentWindow = xWindow;
155 pDescriptor->mxPaneId = xPaneId;
156 pDescriptor->mxPane = rxPane;
157 pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
158
159 // When there is a call out anchor location set then tell the
160 // window about it.
161 if (pDescriptor->mbHasCalloutAnchor)
162 pDescriptor->mxPane->SetCalloutAnchor(pDescriptor->maCalloutAnchorLocation);
163
164 if (xWindow.is())
165 xWindow->addEventListener(this);
166 }
167 }
168
169 return pDescriptor;
170 }
171
172
173
174
175 PresenterPaneContainer::SharedPaneDescriptor
StoreBorderWindow(const Reference<XResourceId> & rxPaneId,const Reference<awt::XWindow> & rxBorderWindow)176 PresenterPaneContainer::StoreBorderWindow(
177 const Reference<XResourceId>& rxPaneId,
178 const Reference<awt::XWindow>& rxBorderWindow)
179 {
180 // The content window may not be present. Use the resource URL of the
181 // pane id as key.
182 OUString sPaneURL;
183 if (rxPaneId.is())
184 sPaneURL = rxPaneId->getResourceURL();
185
186 SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
187 if (pDescriptor.get() != NULL)
188 {
189 pDescriptor->mxBorderWindow = rxBorderWindow;
190 return pDescriptor;
191 }
192 else
193 return SharedPaneDescriptor();
194 }
195
196
197
198
199 PresenterPaneContainer::SharedPaneDescriptor
StoreView(const Reference<XView> & rxView,const SharedBitmapDescriptor & rpViewBackground)200 PresenterPaneContainer::StoreView (
201 const Reference<XView>& rxView,
202 const SharedBitmapDescriptor& rpViewBackground)
203 {
204 SharedPaneDescriptor pDescriptor;
205
206 if (rxView.is())
207 {
208 OUString sPaneURL;
209 Reference<XResourceId> xViewId (rxView->getResourceId());
210 if (xViewId.is())
211 {
212 Reference<XResourceId> xPaneId (xViewId->getAnchor());
213 if (xPaneId.is())
214 sPaneURL = xPaneId->getResourceURL();
215 }
216
217 pDescriptor = FindPaneURL(sPaneURL);
218 if (pDescriptor.get() != NULL)
219 {
220 pDescriptor->mxView = rxView;
221 pDescriptor->mpViewBackground = rpViewBackground;
222 pDescriptor->mxPane->SetBackground(rpViewBackground);
223 try
224 {
225 if ( ! pDescriptor->maViewInitialization.empty())
226 pDescriptor->maViewInitialization(rxView);
227
228 // Activate or deactivate the pane/view.
229 if ( ! pDescriptor->maActivator.empty())
230 pDescriptor->maActivator(pDescriptor->mbIsActive);
231 }
232 catch (RuntimeException&)
233 {
234 OSL_ASSERT(false);
235 }
236 }
237 }
238
239 return pDescriptor;
240 }
241
242
243
244
245 PresenterPaneContainer::SharedPaneDescriptor
RemovePane(const Reference<XResourceId> & rxPaneId)246 PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
247 {
248 SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
249 if (pDescriptor.get() != NULL)
250 {
251 if (pDescriptor->mxContentWindow.is())
252 pDescriptor->mxContentWindow->removeEventListener(this);
253 pDescriptor->mxContentWindow = NULL;
254 pDescriptor->mxBorderWindow = NULL;
255 pDescriptor->mxPane = NULL;
256 pDescriptor->mxView = NULL;
257 pDescriptor->mbIsActive = false;
258 }
259 return pDescriptor;
260 }
261
262
263
264
265
266 PresenterPaneContainer::SharedPaneDescriptor
RemoveView(const Reference<XView> & rxView)267 PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
268 {
269 SharedPaneDescriptor pDescriptor;
270
271 if (rxView.is())
272 {
273 OUString sPaneURL;
274 Reference<XResourceId> xViewId (rxView->getResourceId());
275 if (xViewId.is())
276 {
277 Reference<XResourceId> xPaneId (xViewId->getAnchor());
278 if (xPaneId.is())
279 sPaneURL = xPaneId->getResourceURL();
280 }
281
282 pDescriptor = FindPaneURL(sPaneURL);
283 if (pDescriptor.get() != NULL)
284 {
285 pDescriptor->mxView = NULL;
286 pDescriptor->mpViewBackground = SharedBitmapDescriptor();
287 }
288 }
289
290 return pDescriptor;
291 }
292
293
294
295
FindBorderWindow(const Reference<awt::XWindow> & rxBorderWindow)296 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
297 const Reference<awt::XWindow>& rxBorderWindow)
298 {
299 PaneList::const_iterator iPane;
300 PaneList::iterator iEnd (maPanes.end());
301 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
302 {
303 if ((*iPane)->mxBorderWindow == rxBorderWindow)
304 return *iPane;
305 }
306 return SharedPaneDescriptor();
307 }
308
309
310
311
FindContentWindow(const Reference<awt::XWindow> & rxContentWindow)312 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
313 const Reference<awt::XWindow>& rxContentWindow)
314 {
315 PaneList::const_iterator iPane;
316 PaneList::iterator iEnd (maPanes.end());
317 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
318 {
319 if ((*iPane)->mxContentWindow == rxContentWindow)
320 return *iPane;
321 }
322 return SharedPaneDescriptor();
323 }
324
325
326
327
FindPaneURL(const OUString & rsPaneURL)328 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
329 const OUString& rsPaneURL)
330 {
331 PaneList::const_iterator iPane;
332 PaneList::const_iterator iEnd (maPanes.end());
333 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
334 {
335 if ((*iPane)->mxPaneId->getResourceURL() == rsPaneURL)
336 return *iPane;
337 }
338 return SharedPaneDescriptor();
339 }
340
341
342
343
FindPaneId(const Reference<XResourceId> & rxPaneId)344 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
345 const Reference<XResourceId>& rxPaneId)
346 {
347 PaneList::iterator iEnd (maPanes.end());
348
349 if ( ! rxPaneId.is())
350 return SharedPaneDescriptor();
351
352 PaneList::iterator iPane;
353 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
354 {
355 if (rxPaneId->compareTo((*iPane)->mxPaneId) == 0)
356 return *iPane;
357 }
358 return SharedPaneDescriptor();
359 }
360
361
362
363
FindViewURL(const OUString & rsViewURL)364 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
365 const OUString& rsViewURL)
366 {
367 PaneList::iterator iEnd (maPanes.end());
368 PaneList::iterator iPane;
369 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
370 {
371 if (rsViewURL == (*iPane)->msViewURL)
372 return *iPane;
373 }
374 return SharedPaneDescriptor();
375 }
376
377
378
379
GetPaneURLForViewURL(const::rtl::OUString & rsViewURL)380 ::rtl::OUString PresenterPaneContainer::GetPaneURLForViewURL (const ::rtl::OUString& rsViewURL)
381 {
382 SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
383 if (pDescriptor.get() != NULL)
384 if (pDescriptor->mxPaneId.is())
385 return pDescriptor->mxPaneId->getResourceURL();
386 return OUString();
387 }
388
389
390
391
ToTop(const SharedPaneDescriptor & rpDescriptor)392 void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
393 {
394 if (rpDescriptor.get() != NULL)
395 {
396 // Find iterator for pDescriptor.
397 PaneList::iterator iPane;
398 PaneList::iterator iEnd (maPanes.end());
399 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
400 if (iPane->get() == rpDescriptor.get())
401 break;
402 OSL_ASSERT(iPane!=iEnd);
403 if (iPane == iEnd)
404 return;
405
406 if (mxPresenterHelper.is())
407 mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
408
409 maPanes.erase(iPane);
410 maPanes.push_back(rpDescriptor);
411 }
412 }
413
414
415
416
417 //----- XEventListener --------------------------------------------------------
418
disposing(const com::sun::star::lang::EventObject & rEvent)419 void SAL_CALL PresenterPaneContainer::disposing (
420 const com::sun::star::lang::EventObject& rEvent)
421 throw (com::sun::star::uno::RuntimeException)
422 {
423 SharedPaneDescriptor pDescriptor (
424 FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
425 if (pDescriptor.get() != NULL)
426 {
427 RemovePane(pDescriptor->mxPaneId);
428 }
429 }
430
431
432
433
434 //===== PresenterPaneContainer::PaneDescriptor ================================
435
SetActivationState(const bool bIsActive)436 void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
437 {
438 mbIsActive = bIsActive;
439 if ( ! maActivator.empty())
440 maActivator(mbIsActive);
441 }
442
443 } } // end of namespace ::sdext::presenter
444