Bump version to 5.0-14
[LibreOffice.git] / sdext / source / presenter / PresenterPaneContainer.cxx
blob74dfb1c288f2e81fc38c9afa32144e7a980eec65
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::drawing::framework;
31 namespace sdext { namespace presenter {
33 PresenterPaneContainer::PresenterPaneContainer (
34 const Reference<XComponentContext>& rxContext)
35 : PresenterPaneContainerInterfaceBase(m_aMutex),
36 maPanes(),
37 mxPresenterHelper()
39 Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
40 if (xFactory.is())
42 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
43 xFactory->createInstanceWithContext(
44 OUString("com.sun.star.comp.Draw.PresenterHelper"),
45 rxContext),
46 UNO_QUERY_THROW);
50 PresenterPaneContainer::~PresenterPaneContainer()
54 void PresenterPaneContainer::PreparePane (
55 const Reference<XResourceId>& rxPaneId,
56 const OUString& rsViewURL,
57 const OUString& rsTitle,
58 const OUString& rsAccessibleTitle,
59 const bool bIsOpaque,
60 const ViewInitializationFunction& rViewInitialization,
61 const double nLeft,
62 const double nTop,
63 const double nRight,
64 const double nBottom)
66 if ( ! rxPaneId.is())
67 return;
69 SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
70 if (pPane.get() == NULL)
72 // No entry found for the given pane id. Create a new one.
73 SharedPaneDescriptor pDescriptor (new PaneDescriptor());
74 pDescriptor->mxPaneId = rxPaneId;
75 pDescriptor->msViewURL = rsViewURL;
76 pDescriptor->mxPane = NULL;
77 if (rsTitle.indexOf('%') < 0)
79 pDescriptor->msTitle = rsTitle;
80 (pDescriptor->msTitleTemplate).clear();
82 else
84 pDescriptor->msTitleTemplate = rsTitle;
85 (pDescriptor->msTitle).clear();
87 pDescriptor->msAccessibleTitleTemplate = rsAccessibleTitle;
88 pDescriptor->maViewInitialization = rViewInitialization;
89 pDescriptor->mnLeft = nLeft;
90 pDescriptor->mnTop = nTop;
91 pDescriptor->mnRight = nRight;
92 pDescriptor->mnBottom = nBottom;
93 pDescriptor->mbIsActive = true;
94 pDescriptor->mbIsOpaque = bIsOpaque;
95 pDescriptor->maSpriteProvider = PaneDescriptor::SpriteProvider();
96 pDescriptor->mbIsSprite = false;
97 pDescriptor->maCalloutAnchorLocation = awt::Point(-1,-1);
98 pDescriptor->mbHasCalloutAnchor = false;
100 maPanes.push_back(pDescriptor);
104 void SAL_CALL PresenterPaneContainer::disposing()
106 PaneList::iterator iPane (maPanes.begin());
107 PaneList::const_iterator iEnd (maPanes.end());
108 for ( ; iPane!=iEnd; ++iPane)
109 if ((*iPane)->mxPaneId.is())
110 RemovePane((*iPane)->mxPaneId);
113 PresenterPaneContainer::SharedPaneDescriptor
114 PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
116 SharedPaneDescriptor pDescriptor;
118 if (rxPane.is())
120 OUString sPaneURL;
121 Reference<XResourceId> xPaneId (rxPane->getResourceId());
122 if (xPaneId.is())
123 sPaneURL = xPaneId->getResourceURL();
125 pDescriptor = FindPaneURL(sPaneURL);
126 if (pDescriptor.get() == NULL)
127 PreparePane(xPaneId, OUString(), OUString(), OUString(),
128 false, ViewInitializationFunction(), 0,0,0,0);
129 pDescriptor = FindPaneURL(sPaneURL);
130 if (pDescriptor.get() != NULL)
132 Reference<awt::XWindow> xWindow (rxPane->getWindow());
133 pDescriptor->mxContentWindow = xWindow;
134 pDescriptor->mxPaneId = xPaneId;
135 pDescriptor->mxPane = rxPane;
136 pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
138 // When there is a call out anchor location set then tell the
139 // window about it.
140 if (pDescriptor->mbHasCalloutAnchor)
141 pDescriptor->mxPane->SetCalloutAnchor(pDescriptor->maCalloutAnchorLocation);
143 if (xWindow.is())
144 xWindow->addEventListener(this);
148 return pDescriptor;
151 PresenterPaneContainer::SharedPaneDescriptor
152 PresenterPaneContainer::StoreBorderWindow(
153 const Reference<XResourceId>& rxPaneId,
154 const Reference<awt::XWindow>& rxBorderWindow)
156 // The content window may not be present. Use the resource URL of the
157 // pane id as key.
158 OUString sPaneURL;
159 if (rxPaneId.is())
160 sPaneURL = rxPaneId->getResourceURL();
162 SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
163 if (pDescriptor.get() != NULL)
165 pDescriptor->mxBorderWindow = rxBorderWindow;
166 return pDescriptor;
168 else
169 return SharedPaneDescriptor();
172 PresenterPaneContainer::SharedPaneDescriptor
173 PresenterPaneContainer::StoreView (
174 const Reference<XView>& rxView,
175 const SharedBitmapDescriptor& rpViewBackground)
177 SharedPaneDescriptor pDescriptor;
179 if (rxView.is())
181 OUString sPaneURL;
182 Reference<XResourceId> xViewId (rxView->getResourceId());
183 if (xViewId.is())
185 Reference<XResourceId> xPaneId (xViewId->getAnchor());
186 if (xPaneId.is())
187 sPaneURL = xPaneId->getResourceURL();
190 pDescriptor = FindPaneURL(sPaneURL);
191 if (pDescriptor.get() != NULL)
193 pDescriptor->mxView = rxView;
194 pDescriptor->mpViewBackground = rpViewBackground;
195 if (pDescriptor->mxPane.is())
196 pDescriptor->mxPane->SetBackground(rpViewBackground);
199 if ( ! pDescriptor->maViewInitialization.empty())
200 pDescriptor->maViewInitialization(rxView);
202 // Activate or deactivate the pane/view.
203 if ( ! pDescriptor->maActivator.empty())
204 pDescriptor->maActivator(pDescriptor->mbIsActive);
206 catch (RuntimeException&)
208 OSL_ASSERT(false);
213 return pDescriptor;
216 PresenterPaneContainer::SharedPaneDescriptor
217 PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
219 SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
220 if (pDescriptor.get() != NULL)
222 if (pDescriptor->mxContentWindow.is())
223 pDescriptor->mxContentWindow->removeEventListener(this);
224 pDescriptor->mxContentWindow = NULL;
225 pDescriptor->mxBorderWindow = NULL;
226 pDescriptor->mxPane = NULL;
227 pDescriptor->mxView = NULL;
228 pDescriptor->mbIsActive = false;
230 return pDescriptor;
233 PresenterPaneContainer::SharedPaneDescriptor
234 PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
236 SharedPaneDescriptor pDescriptor;
238 if (rxView.is())
240 OUString sPaneURL;
241 Reference<XResourceId> xViewId (rxView->getResourceId());
242 if (xViewId.is())
244 Reference<XResourceId> xPaneId (xViewId->getAnchor());
245 if (xPaneId.is())
246 sPaneURL = xPaneId->getResourceURL();
249 pDescriptor = FindPaneURL(sPaneURL);
250 if (pDescriptor.get() != NULL)
252 pDescriptor->mxView = NULL;
253 pDescriptor->mpViewBackground = SharedBitmapDescriptor();
257 return pDescriptor;
260 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
261 const Reference<awt::XWindow>& rxBorderWindow)
263 PaneList::const_iterator iPane;
264 PaneList::iterator iEnd (maPanes.end());
265 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
267 if ((*iPane)->mxBorderWindow == rxBorderWindow)
268 return *iPane;
270 return SharedPaneDescriptor();
273 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
274 const Reference<awt::XWindow>& rxContentWindow)
276 PaneList::const_iterator iPane;
277 PaneList::iterator iEnd (maPanes.end());
278 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
280 if ((*iPane)->mxContentWindow == rxContentWindow)
281 return *iPane;
283 return SharedPaneDescriptor();
286 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
287 const OUString& rsPaneURL)
289 PaneList::const_iterator iPane;
290 PaneList::const_iterator iEnd (maPanes.end());
291 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
293 if ((*iPane)->mxPaneId->getResourceURL() == rsPaneURL)
294 return *iPane;
296 return SharedPaneDescriptor();
299 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
300 const Reference<XResourceId>& rxPaneId)
302 PaneList::iterator iEnd (maPanes.end());
304 if ( ! rxPaneId.is())
305 return SharedPaneDescriptor();
307 PaneList::iterator iPane;
308 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
310 if (rxPaneId->compareTo((*iPane)->mxPaneId) == 0)
311 return *iPane;
313 return SharedPaneDescriptor();
316 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
317 const OUString& rsViewURL)
319 PaneList::iterator iEnd (maPanes.end());
320 PaneList::iterator iPane;
321 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
323 if (rsViewURL == (*iPane)->msViewURL)
324 return *iPane;
326 return SharedPaneDescriptor();
329 OUString PresenterPaneContainer::GetPaneURLForViewURL (const OUString& rsViewURL)
331 SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
332 if (pDescriptor.get() != NULL)
333 if (pDescriptor->mxPaneId.is())
334 return pDescriptor->mxPaneId->getResourceURL();
335 return OUString();
338 void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
340 if (rpDescriptor.get() != NULL)
342 // Find iterator for pDescriptor.
343 PaneList::iterator iPane;
344 PaneList::iterator iEnd (maPanes.end());
345 for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
346 if (iPane->get() == rpDescriptor.get())
347 break;
348 OSL_ASSERT(iPane!=iEnd);
349 if (iPane == iEnd)
350 return;
352 if (mxPresenterHelper.is())
353 mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
355 maPanes.erase(iPane);
356 maPanes.push_back(rpDescriptor);
360 //----- XEventListener --------------------------------------------------------
362 void SAL_CALL PresenterPaneContainer::disposing (
363 const com::sun::star::lang::EventObject& rEvent)
364 throw (com::sun::star::uno::RuntimeException, std::exception)
366 SharedPaneDescriptor pDescriptor (
367 FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
368 if (pDescriptor.get() != NULL)
370 RemovePane(pDescriptor->mxPaneId);
374 //===== PresenterPaneContainer::PaneDescriptor ================================
376 void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
378 mbIsActive = bIsActive;
379 if ( ! maActivator.empty())
380 maActivator(mbIsActive);
383 } } // end of namespace ::sdext::presenter
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */