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