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