Update ooo320-m1
[ooovba.git] / sdext / source / presenter / PresenterPaneContainer.cxx
blob43a808c384da7cb30c1e4dec85eb408aeac4587f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterPaneContainer.cxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterPaneContainer.hxx"
36 #include "PresenterPaneBase.hxx"
37 #include <com/sun/star/awt/XGraphics.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/container/XChild.hpp>
40 #include <com/sun/star/drawing/framework/ResourceId.hpp>
41 #include <vector>
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing::framework;
46 using ::rtl::OUString;
48 namespace sdext { namespace presenter {
50 PresenterPaneContainer::PresenterPaneContainer (
51 const Reference<XComponentContext>& rxContext)
52 : PresenterPaneContainerInterfaceBase(m_aMutex),
53 maPanes(),
54 mxPresenterHelper()
56 Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
57 if (xFactory.is())
59 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
60 xFactory->createInstanceWithContext(
61 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
62 rxContext),
63 UNO_QUERY_THROW);
70 PresenterPaneContainer::~PresenterPaneContainer (void)
77 void PresenterPaneContainer::PreparePane (
78 const Reference<XResourceId>& rxPaneId,
79 const OUString& rsViewURL,
80 const OUString& rsTitle,
81 const OUString& rsAccessibleTitle,
82 const bool bIsOpaque,
83 const ViewInitializationFunction& rViewInitialization,
84 const double nLeft,
85 const double nTop,
86 const double nRight,
87 const double nBottom)
89 if ( ! rxPaneId.is())
90 return;
92 SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
93 if (pPane.get() == NULL)
95 // No entry found for the given pane id. Create a new one.
96 SharedPaneDescriptor pDescriptor (new PaneDescriptor());
97 pDescriptor->mxPaneId = rxPaneId;
98 pDescriptor->msViewURL = rsViewURL;
99 pDescriptor->mxPane = NULL;
100 if (rsTitle.indexOf('%') < 0)
102 pDescriptor->msTitle = rsTitle;
103 pDescriptor->msTitleTemplate = OUString();
105 else
107 pDescriptor->msTitleTemplate = rsTitle;
108 pDescriptor->msTitle = OUString();
110 pDescriptor->msAccessibleTitleTemplate = rsAccessibleTitle;
111 pDescriptor->maViewInitialization = rViewInitialization;
112 pDescriptor->mnLeft = nLeft;
113 pDescriptor->mnTop = nTop;
114 pDescriptor->mnRight = nRight;
115 pDescriptor->mnBottom = nBottom;
116 pDescriptor->mbIsActive = true;
117 pDescriptor->mbIsOpaque = bIsOpaque;
118 pDescriptor->maSpriteProvider = PaneDescriptor::SpriteProvider();
119 pDescriptor->mbIsSprite = false;
120 pDescriptor->maCalloutAnchorLocation = awt::Point(-1,-1);
121 pDescriptor->mbHasCalloutAnchor = false;
123 maPanes.push_back(pDescriptor);
130 void SAL_CALL PresenterPaneContainer::disposing (void)
132 PaneList::iterator iPane (maPanes.begin());
133 PaneList::const_iterator iEnd (maPanes.end());
134 for ( ; iPane!=iEnd; ++iPane)
135 if ((*iPane)->mxPaneId.is())
136 RemovePane((*iPane)->mxPaneId);
142 PresenterPaneContainer::SharedPaneDescriptor
143 PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
145 SharedPaneDescriptor pDescriptor;
147 if (rxPane.is())
149 OUString sPaneURL;
150 Reference<XResourceId> xPaneId (rxPane->getResourceId());
151 if (xPaneId.is())
152 sPaneURL = xPaneId->getResourceURL();
154 pDescriptor = FindPaneURL(sPaneURL);
155 if (pDescriptor.get() == NULL)
156 PreparePane(xPaneId, OUString(), OUString(), OUString(),
157 false, ViewInitializationFunction(), 0,0,0,0);
158 pDescriptor = FindPaneURL(sPaneURL);
159 if (pDescriptor.get() != NULL)
161 Reference<awt::XWindow> xWindow (rxPane->getWindow());
162 pDescriptor->mxContentWindow = xWindow;
163 pDescriptor->mxPaneId = xPaneId;
164 pDescriptor->mxPane = rxPane;
165 pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
167 // When there is a call out anchor location set then tell the
168 // window about it.
169 if (pDescriptor->mbHasCalloutAnchor)
170 pDescriptor->mxPane->SetCalloutAnchor(pDescriptor->maCalloutAnchorLocation);
172 if (xWindow.is())
173 xWindow->addEventListener(this);
177 return pDescriptor;
183 PresenterPaneContainer::SharedPaneDescriptor
184 PresenterPaneContainer::StoreBorderWindow(
185 const Reference<XResourceId>& rxPaneId,
186 const Reference<awt::XWindow>& rxBorderWindow)
188 // The content window may not be present. Use the resource URL of the
189 // pane id as key.
190 OUString sPaneURL;
191 if (rxPaneId.is())
192 sPaneURL = rxPaneId->getResourceURL();
194 SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
195 if (pDescriptor.get() != NULL)
197 pDescriptor->mxBorderWindow = rxBorderWindow;
198 return pDescriptor;
200 else
201 return SharedPaneDescriptor();
207 PresenterPaneContainer::SharedPaneDescriptor
208 PresenterPaneContainer::StoreView (
209 const Reference<XView>& rxView,
210 const SharedBitmapDescriptor& rpViewBackground)
212 SharedPaneDescriptor pDescriptor;
214 if (rxView.is())
216 OUString sPaneURL;
217 Reference<XResourceId> xViewId (rxView->getResourceId());
218 if (xViewId.is())
220 Reference<XResourceId> xPaneId (xViewId->getAnchor());
221 if (xPaneId.is())
222 sPaneURL = xPaneId->getResourceURL();
225 pDescriptor = FindPaneURL(sPaneURL);
226 if (pDescriptor.get() != NULL)
228 pDescriptor->mxView = rxView;
229 pDescriptor->mpViewBackground = rpViewBackground;
230 pDescriptor->mxPane->SetBackground(rpViewBackground);
233 if ( ! pDescriptor->maViewInitialization.empty())
234 pDescriptor->maViewInitialization(rxView);
236 // Activate or deactivate the pane/view.
237 if ( ! pDescriptor->maActivator.empty())
238 pDescriptor->maActivator(pDescriptor->mbIsActive);
240 catch (RuntimeException&)
242 OSL_ASSERT(false);
247 return pDescriptor;
253 PresenterPaneContainer::SharedPaneDescriptor
254 PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
256 SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
257 if (pDescriptor.get() != NULL)
259 if (pDescriptor->mxContentWindow.is())
260 pDescriptor->mxContentWindow->removeEventListener(this);
261 pDescriptor->mxContentWindow = NULL;
262 pDescriptor->mxBorderWindow = NULL;
263 pDescriptor->mxPane = NULL;
264 pDescriptor->mxView = NULL;
265 pDescriptor->mbIsActive = false;
267 return pDescriptor;
274 PresenterPaneContainer::SharedPaneDescriptor
275 PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
277 SharedPaneDescriptor pDescriptor;
279 if (rxView.is())
281 OUString sPaneURL;
282 Reference<XResourceId> xViewId (rxView->getResourceId());
283 if (xViewId.is())
285 Reference<XResourceId> xPaneId (xViewId->getAnchor());
286 if (xPaneId.is())
287 sPaneURL = xPaneId->getResourceURL();
290 pDescriptor = FindPaneURL(sPaneURL);
291 if (pDescriptor.get() != NULL)
293 pDescriptor->mxView = NULL;
294 pDescriptor->mpViewBackground = SharedBitmapDescriptor();
298 return pDescriptor;
304 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
305 const Reference<awt::XWindow>& rxBorderWindow)
307 PaneList::const_iterator iPane;
308 PaneList::iterator iEnd (maPanes.end());
309 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
311 if ((*iPane)->mxBorderWindow == rxBorderWindow)
312 return *iPane;
314 return SharedPaneDescriptor();
320 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
321 const Reference<awt::XWindow>& rxContentWindow)
323 PaneList::const_iterator iPane;
324 PaneList::iterator iEnd (maPanes.end());
325 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
327 if ((*iPane)->mxContentWindow == rxContentWindow)
328 return *iPane;
330 return SharedPaneDescriptor();
336 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
337 const OUString& rsPaneURL)
339 PaneList::const_iterator iPane;
340 PaneList::const_iterator iEnd (maPanes.end());
341 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
343 if ((*iPane)->mxPaneId->getResourceURL() == rsPaneURL)
344 return *iPane;
346 return SharedPaneDescriptor();
352 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
353 const Reference<XResourceId>& rxPaneId)
355 PaneList::iterator iEnd (maPanes.end());
357 if ( ! rxPaneId.is())
358 return SharedPaneDescriptor();
360 PaneList::iterator iPane;
361 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
363 if (rxPaneId->compareTo((*iPane)->mxPaneId) == 0)
364 return *iPane;
366 return SharedPaneDescriptor();
372 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
373 const OUString& rsViewURL)
375 PaneList::iterator iEnd (maPanes.end());
376 PaneList::iterator iPane;
377 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
379 if (rsViewURL == (*iPane)->msViewURL)
380 return *iPane;
382 return SharedPaneDescriptor();
388 ::rtl::OUString PresenterPaneContainer::GetPaneURLForViewURL (const ::rtl::OUString& rsViewURL)
390 SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
391 if (pDescriptor.get() != NULL)
392 if (pDescriptor->mxPaneId.is())
393 return pDescriptor->mxPaneId->getResourceURL();
394 return OUString();
400 void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
402 if (rpDescriptor.get() != NULL)
404 // Find iterator for pDescriptor.
405 PaneList::iterator iPane;
406 PaneList::iterator iEnd (maPanes.end());
407 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
408 if (iPane->get() == rpDescriptor.get())
409 break;
410 OSL_ASSERT(iPane!=iEnd);
411 if (iPane == iEnd)
412 return;
414 if (mxPresenterHelper.is())
415 mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
417 maPanes.erase(iPane);
418 maPanes.push_back(rpDescriptor);
425 //----- XEventListener --------------------------------------------------------
427 void SAL_CALL PresenterPaneContainer::disposing (
428 const com::sun::star::lang::EventObject& rEvent)
429 throw (com::sun::star::uno::RuntimeException)
431 SharedPaneDescriptor pDescriptor (
432 FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
433 if (pDescriptor.get() != NULL)
435 RemovePane(pDescriptor->mxPaneId);
442 //===== PresenterPaneContainer::PaneDescriptor ================================
444 void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
446 mbIsActive = bIsActive;
447 if ( ! maActivator.empty())
448 maActivator(mbIsActive);
451 } } // end of namespace ::sdext::presenter