update dev300-m58
[ooovba.git] / sdext / source / presenter / PresenterPaneContainer.cxx
blob8bd3a5b0480127f3979ff1c44240300c5376a5d2
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 bool bIsOpaque,
82 const ViewInitializationFunction& rViewInitialization,
83 const double nLeft,
84 const double nTop,
85 const double nRight,
86 const double nBottom)
88 if ( ! rxPaneId.is())
89 return;
91 SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
92 if (pPane.get() == NULL)
94 // No entry found for the given pane id. Create a new one.
95 SharedPaneDescriptor pDescriptor (new PaneDescriptor());
96 pDescriptor->mxPaneId = rxPaneId;
97 pDescriptor->msViewURL = rsViewURL;
98 pDescriptor->mxPane = NULL;
99 if (rsTitle.indexOf('%') < 0)
101 pDescriptor->msTitle = rsTitle;
102 pDescriptor->msTitleTemplate = OUString();
104 else
106 pDescriptor->msTitleTemplate = rsTitle;
107 pDescriptor->msTitle = OUString();
109 pDescriptor->maViewInitialization = rViewInitialization;
110 pDescriptor->mnLeft = nLeft;
111 pDescriptor->mnTop = nTop;
112 pDescriptor->mnRight = nRight;
113 pDescriptor->mnBottom = nBottom;
114 pDescriptor->mbIsActive = true;
115 pDescriptor->mbIsOpaque = bIsOpaque;
116 pDescriptor->maSpriteProvider = PaneDescriptor::SpriteProvider();
117 pDescriptor->mbIsSprite = false;
118 pDescriptor->maCalloutAnchorLocation = awt::Point(-1,-1);
119 pDescriptor->mbHasCalloutAnchor = false;
121 maPanes.push_back(pDescriptor);
128 void SAL_CALL PresenterPaneContainer::disposing (void)
130 PaneList::iterator iPane (maPanes.begin());
131 PaneList::const_iterator iEnd (maPanes.end());
132 for ( ; iPane!=iEnd; ++iPane)
133 if ((*iPane)->mxPaneId.is())
134 RemovePane((*iPane)->mxPaneId);
140 PresenterPaneContainer::SharedPaneDescriptor
141 PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
143 SharedPaneDescriptor pDescriptor;
145 if (rxPane.is())
147 OUString sPaneURL;
148 Reference<XResourceId> xPaneId (rxPane->getResourceId());
149 if (xPaneId.is())
150 sPaneURL = xPaneId->getResourceURL();
152 pDescriptor = FindPaneURL(sPaneURL);
153 if (pDescriptor.get() == NULL)
154 PreparePane(xPaneId, OUString(), OUString(),
155 false, ViewInitializationFunction(), 0,0,0,0);
156 pDescriptor = FindPaneURL(sPaneURL);
157 if (pDescriptor.get() != NULL)
159 Reference<awt::XWindow> xWindow (rxPane->getWindow());
160 pDescriptor->mxContentWindow = xWindow;
161 pDescriptor->mxPaneId = xPaneId;
162 pDescriptor->mxPane = rxPane;
163 pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
165 // When there is a call out anchor location set then tell the
166 // window about it.
167 if (pDescriptor->mbHasCalloutAnchor)
168 pDescriptor->mxPane->SetCalloutAnchor(pDescriptor->maCalloutAnchorLocation);
170 if (xWindow.is())
171 xWindow->addEventListener(this);
175 return pDescriptor;
181 PresenterPaneContainer::SharedPaneDescriptor
182 PresenterPaneContainer::StoreBorderWindow(
183 const Reference<XResourceId>& rxPaneId,
184 const Reference<awt::XWindow>& rxBorderWindow)
186 // The content window may not be present. Use the resource URL of the
187 // pane id as key.
188 OUString sPaneURL;
189 if (rxPaneId.is())
190 sPaneURL = rxPaneId->getResourceURL();
192 SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
193 if (pDescriptor.get() != NULL)
195 pDescriptor->mxBorderWindow = rxBorderWindow;
196 return pDescriptor;
198 else
199 return SharedPaneDescriptor();
205 PresenterPaneContainer::SharedPaneDescriptor
206 PresenterPaneContainer::StoreView (
207 const Reference<XView>& rxView,
208 const SharedBitmapDescriptor& rpViewBackground)
210 SharedPaneDescriptor pDescriptor;
212 if (rxView.is())
214 OUString sPaneURL;
215 Reference<XResourceId> xViewId (rxView->getResourceId());
216 if (xViewId.is())
218 Reference<XResourceId> xPaneId (xViewId->getAnchor());
219 if (xPaneId.is())
220 sPaneURL = xPaneId->getResourceURL();
223 pDescriptor = FindPaneURL(sPaneURL);
224 if (pDescriptor.get() != NULL)
226 pDescriptor->mxView = rxView;
227 pDescriptor->mpViewBackground = rpViewBackground;
228 pDescriptor->mxPane->SetBackground(rpViewBackground);
231 if ( ! pDescriptor->maViewInitialization.empty())
232 pDescriptor->maViewInitialization(rxView);
234 // Activate or deactivate the pane/view.
235 if ( ! pDescriptor->maActivator.empty())
236 pDescriptor->maActivator(pDescriptor->mbIsActive);
238 catch (RuntimeException&)
240 OSL_ASSERT(false);
245 return pDescriptor;
251 PresenterPaneContainer::SharedPaneDescriptor
252 PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
254 SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
255 if (pDescriptor.get() != NULL)
257 if (pDescriptor->mxContentWindow.is())
258 pDescriptor->mxContentWindow->removeEventListener(this);
259 pDescriptor->mxContentWindow = NULL;
260 pDescriptor->mxBorderWindow = NULL;
261 pDescriptor->mxPane = NULL;
262 pDescriptor->mxView = NULL;
263 pDescriptor->mbIsActive = false;
265 return pDescriptor;
272 PresenterPaneContainer::SharedPaneDescriptor
273 PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
275 SharedPaneDescriptor pDescriptor;
277 if (rxView.is())
279 OUString sPaneURL;
280 Reference<XResourceId> xViewId (rxView->getResourceId());
281 if (xViewId.is())
283 Reference<XResourceId> xPaneId (xViewId->getAnchor());
284 if (xPaneId.is())
285 sPaneURL = xPaneId->getResourceURL();
288 pDescriptor = FindPaneURL(sPaneURL);
289 if (pDescriptor.get() != NULL)
291 pDescriptor->mxView = NULL;
292 pDescriptor->mpViewBackground = SharedBitmapDescriptor();
296 return pDescriptor;
302 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
303 const Reference<awt::XWindow>& rxBorderWindow)
305 PaneList::const_iterator iPane;
306 PaneList::iterator iEnd (maPanes.end());
307 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
309 if ((*iPane)->mxBorderWindow == rxBorderWindow)
310 return *iPane;
312 return SharedPaneDescriptor();
318 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
319 const Reference<awt::XWindow>& rxContentWindow)
321 PaneList::const_iterator iPane;
322 PaneList::iterator iEnd (maPanes.end());
323 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
325 if ((*iPane)->mxContentWindow == rxContentWindow)
326 return *iPane;
328 return SharedPaneDescriptor();
334 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
335 const OUString& rsPaneURL)
337 PaneList::const_iterator iPane;
338 PaneList::const_iterator iEnd (maPanes.end());
339 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
341 if ((*iPane)->mxPaneId->getResourceURL() == rsPaneURL)
342 return *iPane;
344 return SharedPaneDescriptor();
350 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
351 const Reference<XResourceId>& rxPaneId)
353 PaneList::iterator iEnd (maPanes.end());
355 if ( ! rxPaneId.is())
356 return SharedPaneDescriptor();
358 PaneList::iterator iPane;
359 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
361 if (rxPaneId->compareTo((*iPane)->mxPaneId) == 0)
362 return *iPane;
364 return SharedPaneDescriptor();
370 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
371 const OUString& rsViewURL)
373 PaneList::iterator iEnd (maPanes.end());
374 PaneList::iterator iPane;
375 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
377 if (rsViewURL == (*iPane)->msViewURL)
378 return *iPane;
380 return SharedPaneDescriptor();
386 ::rtl::OUString PresenterPaneContainer::GetPaneURLForViewURL (const ::rtl::OUString& rsViewURL)
388 SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
389 if (pDescriptor.get() != NULL)
390 if (pDescriptor->mxPaneId.is())
391 return pDescriptor->mxPaneId->getResourceURL();
392 return OUString();
398 void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
400 if (rpDescriptor.get() != NULL)
402 // Find iterator for pDescriptor.
403 PaneList::iterator iPane;
404 PaneList::iterator iEnd (maPanes.end());
405 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
406 if (iPane->get() == rpDescriptor.get())
407 break;
408 OSL_ASSERT(iPane!=iEnd);
409 if (iPane == iEnd)
410 return;
412 if (mxPresenterHelper.is())
413 mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
415 maPanes.erase(iPane);
416 maPanes.push_back(rpDescriptor);
423 //----- XEventListener --------------------------------------------------------
425 void SAL_CALL PresenterPaneContainer::disposing (
426 const com::sun::star::lang::EventObject& rEvent)
427 throw (com::sun::star::uno::RuntimeException)
429 SharedPaneDescriptor pDescriptor (
430 FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
431 if (pDescriptor.get() != NULL)
433 RemovePane(pDescriptor->mxPaneId);
440 //===== PresenterPaneContainer::PaneDescriptor ================================
442 void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
444 mbIsActive = bIsActive;
445 if ( ! maActivator.empty())
446 maActivator(mbIsActive);
449 } } // end of namespace ::sdext::presenter