LibreOffice Module sd (master) 1
PresenterPaneBase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "PresenterPaneBase.hxx"
23#include <com/sun/star/awt/PosSize.hpp>
24#include <com/sun/star/awt/XWindow2.hpp>
25#include <utility>
26
27using namespace css;
28using namespace css::uno;
29using namespace css::drawing::framework;
30
31namespace sdext::presenter {
32
33//===== PresenterPaneBase =====================================================
34
36 const Reference<XComponentContext>& rxContext,
37 ::rtl::Reference<PresenterController> xPresenterController)
39 mpPresenterController(std::move(xPresenterController)),
40 mxComponentContext(rxContext)
41{
43 mxPresenterHelper = mpPresenterController->GetPresenterHelper();
44}
45
46PresenterPaneBase::~PresenterPaneBase()
47{
48}
49
50void PresenterPaneBase::disposing()
51{
52 if (mxBorderWindow.is())
53 {
54 mxBorderWindow->removeWindowListener(this);
55 mxBorderWindow->removePaintListener(this);
56 }
57
58 {
59 Reference<XComponent> xComponent (mxContentCanvas, UNO_QUERY);
60 mxContentCanvas = nullptr;
61 if (xComponent.is())
62 xComponent->dispose();
63 }
65 {
66 Reference<XComponent> xComponent = mxContentWindow;
67 mxContentWindow = nullptr;
68 if (xComponent.is())
69 xComponent->dispose();
70 }
71
72 {
73 Reference<XComponent> xComponent (mxBorderCanvas, UNO_QUERY);
74 mxBorderCanvas = nullptr;
75 if (xComponent.is())
76 xComponent->dispose();
77 }
78
79 {
80 Reference<XComponent> xComponent = mxBorderWindow;
81 mxBorderWindow = nullptr;
82 if (xComponent.is())
83 xComponent->dispose();
84 }
85
86 mxComponentContext = nullptr;
87}
88
89void PresenterPaneBase::SetTitle (const OUString& rsTitle)
90{
91 msTitle = rsTitle;
92
94 OSL_ASSERT(mpPresenterController->GetPaintManager() != nullptr);
95
96 mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
97}
98
99const OUString& PresenterPaneBase::GetTitle() const
100{
101 return msTitle;
102}
103
104const Reference<drawing::framework::XPaneBorderPainter>&
105 PresenterPaneBase::GetPaneBorderPainter() const
106{
107 return mxBorderPainter;
108}
109
110//----- XInitialization -------------------------------------------------------
111
112void SAL_CALL PresenterPaneBase::initialize (const Sequence<Any>& rArguments)
113{
114 ThrowIfDisposed();
115
116 if ( ! mxComponentContext.is())
117 {
118 throw RuntimeException(
119 "PresenterSpritePane: missing component context",
120 static_cast<XWeak*>(this));
121 }
122
123 if (rArguments.getLength() != 5 && rArguments.getLength() != 6)
124 {
125 throw RuntimeException(
126 "PresenterSpritePane: invalid number of arguments",
127 static_cast<XWeak*>(this));
128 }
129
130 try
131 {
132 // Get the resource id from the first argument.
133 if ( ! (rArguments[0] >>= mxPaneId))
134 {
135 throw lang::IllegalArgumentException(
136 "PresenterPane: invalid pane id",
137 static_cast<XWeak*>(this),
138 0);
139 }
140
141 if ( ! (rArguments[1] >>= mxParentWindow))
142 {
143 throw lang::IllegalArgumentException(
144 "PresenterPane: invalid parent window",
145 static_cast<XWeak*>(this),
146 1);
147 }
148
149 Reference<rendering::XSpriteCanvas> xParentCanvas;
150 if ( ! (rArguments[2] >>= xParentCanvas))
151 {
152 throw lang::IllegalArgumentException(
153 "PresenterPane: invalid parent canvas",
154 static_cast<XWeak*>(this),
155 2);
156 }
157
158 if ( ! (rArguments[3] >>= msTitle))
159 {
160 throw lang::IllegalArgumentException(
161 "PresenterPane: invalid title",
162 static_cast<XWeak*>(this),
163 3);
164 }
165
166 if ( ! (rArguments[4] >>= mxBorderPainter))
167 {
168 throw lang::IllegalArgumentException(
169 "PresenterPane: invalid border painter",
170 static_cast<XWeak*>(this),
171 4);
172 }
173
174 bool bIsWindowVisibleOnCreation (true);
175 if (rArguments.getLength()>5 && ! (rArguments[5] >>= bIsWindowVisibleOnCreation))
176 {
177 throw lang::IllegalArgumentException(
178 "PresenterPane: invalid window visibility flag",
179 static_cast<XWeak*>(this),
180 5);
181 }
182
183 CreateWindows(bIsWindowVisibleOnCreation);
184
185 if (mxBorderWindow.is())
186 {
187 mxBorderWindow->addWindowListener(this);
188 mxBorderWindow->addPaintListener(this);
189 }
190
191 CreateCanvases(xParentCanvas);
192
193 // Raise new windows.
194 ToTop();
195 }
196 catch (Exception&)
197 {
198 mxContentWindow = nullptr;
199 mxComponentContext = nullptr;
200 throw;
201 }
202}
203
204//----- XResourceId -----------------------------------------------------------
205
206Reference<XResourceId> SAL_CALL PresenterPaneBase::getResourceId()
207{
208 ThrowIfDisposed();
209 return mxPaneId;
210}
211
212sal_Bool SAL_CALL PresenterPaneBase::isAnchorOnly()
213{
214 return true;
215}
216
217//----- XWindowListener -------------------------------------------------------
218
219void SAL_CALL PresenterPaneBase::windowResized (const awt::WindowEvent&)
220{
221 ThrowIfDisposed();
222}
223
224void SAL_CALL PresenterPaneBase::windowMoved (const awt::WindowEvent&)
225{
226 ThrowIfDisposed();
227}
228
229void SAL_CALL PresenterPaneBase::windowShown (const lang::EventObject&)
230{
231 ThrowIfDisposed();
232}
233
234void SAL_CALL PresenterPaneBase::windowHidden (const lang::EventObject&)
235{
236 ThrowIfDisposed();
237}
238
239//----- lang::XEventListener --------------------------------------------------
240
241void SAL_CALL PresenterPaneBase::disposing (const lang::EventObject& rEvent)
242{
243 if (rEvent.Source == mxBorderWindow)
244 {
245 mxBorderWindow = nullptr;
246 }
247}
248
249
250void PresenterPaneBase::CreateWindows (
251 const bool bIsWindowVisibleOnCreation)
252{
253 if (!(mxPresenterHelper.is() && mxParentWindow.is()))
254 return;
255
256 mxBorderWindow = mxPresenterHelper->createWindow(
257 mxParentWindow,
258 false,
259 bIsWindowVisibleOnCreation,
260 false,
261 false);
262 mxContentWindow = mxPresenterHelper->createWindow(
263 mxBorderWindow,
264 false,
265 bIsWindowVisibleOnCreation,
266 false,
267 false);
268}
269
270const Reference<awt::XWindow>& PresenterPaneBase::GetBorderWindow() const
271{
272 return mxBorderWindow;
273}
274
275void PresenterPaneBase::ToTop()
276{
277 if (mxPresenterHelper.is())
278 mxPresenterHelper->toTop(mxContentWindow);
279}
280
281void PresenterPaneBase::PaintBorder (const awt::Rectangle& rUpdateBox)
282{
283 OSL_ASSERT(mxPaneId.is());
284
285 if (!(mxBorderPainter.is() && mxBorderWindow.is() && mxBorderCanvas.is()))
286 return;
287
288 awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
289 awt::Rectangle aLocalBorderBox (0,0, aBorderBox.Width, aBorderBox.Height);
290
291 //TODO: paint border background?
292
293 mxBorderPainter->paintBorder(
294 mxPaneId->getResourceURL(),
295 mxBorderCanvas,
296 aLocalBorderBox,
297 rUpdateBox,
298 msTitle);
299}
300
301void PresenterPaneBase::LayoutContextWindow()
302{
303 OSL_ASSERT(mxPaneId.is());
304 OSL_ASSERT(mxBorderWindow.is());
305 OSL_ASSERT(mxContentWindow.is());
306 if (!(mxBorderPainter.is() && mxPaneId.is() && mxBorderWindow.is() && mxContentWindow.is()))
307 return;
308
309 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
310 const awt::Rectangle aInnerBox (mxBorderPainter->removeBorder(
311 mxPaneId->getResourceURL(),
312 aBorderBox,
313 drawing::framework::BorderType_TOTAL_BORDER));
314 mxContentWindow->setPosSize(
315 aInnerBox.X - aBorderBox.X,
316 aInnerBox.Y - aBorderBox.Y,
317 aInnerBox.Width,
318 aInnerBox.Height,
319 awt::PosSize::POSSIZE);
320}
321
322bool PresenterPaneBase::IsVisible() const
323{
324 Reference<awt::XWindow2> xWindow2 (mxBorderPainter, UNO_QUERY);
325 if (xWindow2.is())
326 return xWindow2->isVisible();
327
328 return false;
329}
330
331void PresenterPaneBase::ThrowIfDisposed()
332{
333 if (rBHelper.bDisposed || rBHelper.bInDispose)
334 {
335 throw lang::DisposedException (
336 "PresenterPane object has already been disposed",
337 static_cast<uno::XWeak*>(this));
338 }
339}
340
341} // end of namespace ::sdext::presenter
342
343/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< PresenterController > mpPresenterController
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
Reference< drawing::XPresenterHelper > mxPresenterHelper
PresenterPaneBase(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ::rtl::Reference< PresenterController > xPresenterController)
std::mutex m_aMutex
@ Exception
::cppu::WeakComponentImplHelper< css::drawing::framework::XPane, css::lang::XInitialization, css::awt::XWindowListener, css::awt::XPaintListener > PresenterPaneBaseInterfaceBase
unsigned char sal_Bool