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