vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / presenter / PresenterPaneContainer.cxx
blob6477d75cb1f3c19be19dce30f75cc7d2f5edac2f
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"
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::drawing::framework;
27 namespace sdext { namespace presenter {
29 PresenterPaneContainer::PresenterPaneContainer (
30 const Reference<XComponentContext>& rxContext)
31 : PresenterPaneContainerInterfaceBase(m_aMutex),
32 maPanes(),
33 mxPresenterHelper()
35 Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
36 if (xFactory.is())
38 mxPresenterHelper.set(
39 xFactory->createInstanceWithContext(
40 "com.sun.star.comp.Draw.PresenterHelper",
41 rxContext),
42 UNO_QUERY_THROW);
46 PresenterPaneContainer::~PresenterPaneContainer()
50 void PresenterPaneContainer::PreparePane (
51 const Reference<XResourceId>& rxPaneId,
52 const OUString& rsViewURL,
53 const OUString& rsTitle,
54 const OUString& rsAccessibleTitle,
55 const bool bIsOpaque,
56 const ViewInitializationFunction& rViewInitialization)
58 if ( ! rxPaneId.is())
59 return;
61 SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
62 if (pPane.get() != nullptr)
63 return;
65 // No entry found for the given pane id. Create a new one.
66 SharedPaneDescriptor pDescriptor (new PaneDescriptor);
67 pDescriptor->mxPaneId = rxPaneId;
68 pDescriptor->msViewURL = rsViewURL;
69 pDescriptor->mxPane = nullptr;
70 if (rsTitle.indexOf('%') < 0)
72 pDescriptor->msTitle = rsTitle;
73 pDescriptor->msTitleTemplate.clear();
75 else
77 pDescriptor->msTitleTemplate = rsTitle;
78 pDescriptor->msTitle.clear();
80 pDescriptor->msAccessibleTitleTemplate = rsAccessibleTitle;
81 pDescriptor->maViewInitialization = rViewInitialization;
82 pDescriptor->mbIsActive = true;
83 pDescriptor->mbIsOpaque = bIsOpaque;
84 pDescriptor->mbIsSprite = false;
86 maPanes.push_back(pDescriptor);
89 void SAL_CALL PresenterPaneContainer::disposing()
91 for (const auto& rxPane : maPanes)
92 if (rxPane->mxPaneId.is())
93 RemovePane(rxPane->mxPaneId);
96 PresenterPaneContainer::SharedPaneDescriptor
97 PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
99 SharedPaneDescriptor pDescriptor;
101 if (rxPane.is())
103 OUString sPaneURL;
104 Reference<XResourceId> xPaneId (rxPane->getResourceId());
105 if (xPaneId.is())
106 sPaneURL = xPaneId->getResourceURL();
108 pDescriptor = FindPaneURL(sPaneURL);
109 if (pDescriptor.get() == nullptr)
110 PreparePane(xPaneId, OUString(), OUString(), OUString(),
111 false, ViewInitializationFunction());
112 pDescriptor = FindPaneURL(sPaneURL);
113 if (pDescriptor.get() != nullptr)
115 Reference<awt::XWindow> xWindow (rxPane->getWindow());
116 pDescriptor->mxContentWindow = xWindow;
117 pDescriptor->mxPaneId = xPaneId;
118 pDescriptor->mxPane = rxPane;
119 pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
121 if (xWindow.is())
122 xWindow->addEventListener(this);
126 return pDescriptor;
129 PresenterPaneContainer::SharedPaneDescriptor
130 PresenterPaneContainer::StoreBorderWindow(
131 const Reference<XResourceId>& rxPaneId,
132 const Reference<awt::XWindow>& rxBorderWindow)
134 // The content window may not be present. Use the resource URL of the
135 // pane id as key.
136 OUString sPaneURL;
137 if (rxPaneId.is())
138 sPaneURL = rxPaneId->getResourceURL();
140 SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
141 if (pDescriptor.get() != nullptr)
143 pDescriptor->mxBorderWindow = rxBorderWindow;
144 return pDescriptor;
146 else
147 return SharedPaneDescriptor();
150 PresenterPaneContainer::SharedPaneDescriptor
151 PresenterPaneContainer::StoreView (
152 const Reference<XView>& rxView)
154 SharedPaneDescriptor pDescriptor;
156 if (rxView.is())
158 OUString sPaneURL;
159 Reference<XResourceId> xViewId (rxView->getResourceId());
160 if (xViewId.is())
162 Reference<XResourceId> xPaneId (xViewId->getAnchor());
163 if (xPaneId.is())
164 sPaneURL = xPaneId->getResourceURL();
167 pDescriptor = FindPaneURL(sPaneURL);
168 if (pDescriptor.get() != nullptr)
170 pDescriptor->mxView = rxView;
173 if (pDescriptor->maViewInitialization)
174 pDescriptor->maViewInitialization(rxView);
176 catch (RuntimeException&)
178 OSL_ASSERT(false);
183 return pDescriptor;
186 PresenterPaneContainer::SharedPaneDescriptor
187 PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
189 SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
190 if (pDescriptor.get() != nullptr)
192 if (pDescriptor->mxContentWindow.is())
193 pDescriptor->mxContentWindow->removeEventListener(this);
194 pDescriptor->mxContentWindow = nullptr;
195 pDescriptor->mxBorderWindow = nullptr;
196 pDescriptor->mxPane = nullptr;
197 pDescriptor->mxView = nullptr;
198 pDescriptor->mbIsActive = false;
200 return pDescriptor;
203 PresenterPaneContainer::SharedPaneDescriptor
204 PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
206 SharedPaneDescriptor pDescriptor;
208 if (rxView.is())
210 OUString sPaneURL;
211 Reference<XResourceId> xViewId (rxView->getResourceId());
212 if (xViewId.is())
214 Reference<XResourceId> xPaneId (xViewId->getAnchor());
215 if (xPaneId.is())
216 sPaneURL = xPaneId->getResourceURL();
219 pDescriptor = FindPaneURL(sPaneURL);
220 if (pDescriptor.get() != nullptr)
222 pDescriptor->mxView = nullptr;
226 return pDescriptor;
229 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
230 const Reference<awt::XWindow>& rxBorderWindow)
232 auto iPane = std::find_if(maPanes.begin(), maPanes.end(),
233 [&rxBorderWindow](const SharedPaneDescriptor& rxPane) { return rxPane->mxBorderWindow == rxBorderWindow; });
234 if (iPane != maPanes.end())
235 return *iPane;
236 return SharedPaneDescriptor();
239 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
240 const Reference<awt::XWindow>& rxContentWindow)
242 auto iPane = std::find_if(maPanes.begin(), maPanes.end(),
243 [&rxContentWindow](const SharedPaneDescriptor& rxPane) { return rxPane->mxContentWindow == rxContentWindow; });
244 if (iPane != maPanes.end())
245 return *iPane;
246 return SharedPaneDescriptor();
249 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
250 const OUString& rsPaneURL)
252 auto iPane = std::find_if(maPanes.begin(), maPanes.end(),
253 [&rsPaneURL](const SharedPaneDescriptor& rxPane) { return rxPane->mxPaneId->getResourceURL() == rsPaneURL; });
254 if (iPane != maPanes.end())
255 return *iPane;
256 return SharedPaneDescriptor();
259 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
260 const Reference<XResourceId>& rxPaneId)
262 if ( ! rxPaneId.is())
263 return SharedPaneDescriptor();
265 auto iPane = std::find_if(maPanes.begin(), maPanes.end(),
266 [&rxPaneId](const SharedPaneDescriptor& rxPane) { return rxPaneId->compareTo(rxPane->mxPaneId) == 0; });
267 if (iPane != maPanes.end())
268 return *iPane;
269 return SharedPaneDescriptor();
272 PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
273 const OUString& rsViewURL)
275 auto iPane = std::find_if(maPanes.begin(), maPanes.end(),
276 [&rsViewURL](const SharedPaneDescriptor& rxPane) { return rsViewURL == rxPane->msViewURL; });
277 if (iPane != maPanes.end())
278 return *iPane;
279 return SharedPaneDescriptor();
282 OUString PresenterPaneContainer::GetPaneURLForViewURL (const OUString& rsViewURL)
284 SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
285 if (pDescriptor.get() != nullptr)
286 if (pDescriptor->mxPaneId.is())
287 return pDescriptor->mxPaneId->getResourceURL();
288 return OUString();
291 void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
293 if (rpDescriptor.get() == nullptr)
294 return;
296 // Find iterator for pDescriptor.
297 PaneList::iterator iEnd (maPanes.end());
298 auto iPane = std::find_if(maPanes.begin(), iEnd,
299 [&rpDescriptor](SharedPaneDescriptor& rxPane) { return rxPane.get() == rpDescriptor.get(); });
300 OSL_ASSERT(iPane!=iEnd);
301 if (iPane == iEnd)
302 return;
304 if (mxPresenterHelper.is())
305 mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
307 maPanes.erase(iPane);
308 maPanes.push_back(rpDescriptor);
311 //----- XEventListener --------------------------------------------------------
313 void SAL_CALL PresenterPaneContainer::disposing (
314 const css::lang::EventObject& rEvent)
316 SharedPaneDescriptor pDescriptor (
317 FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
318 if (pDescriptor.get() != nullptr)
320 RemovePane(pDescriptor->mxPaneId);
324 //===== PresenterPaneContainer::PaneDescriptor ================================
326 void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
328 mbIsActive = bIsActive;
331 } } // end of namespace ::sdext::presenter
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */