bump product version to 5.0.4.1
[LibreOffice.git] / sdext / source / presenter / PresenterPaneBase.cxx
blob0195c66b827cbb46d5e18d2dafcb7afdb3b4bbb3
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 "PresenterPaneBase.hxx"
21 #include "PresenterCanvasHelper.hxx"
22 #include "PresenterController.hxx"
23 #include "PresenterGeometryHelper.hxx"
24 #include "PresenterPaintManager.hxx"
25 #include "PresenterTextView.hxx"
26 #include <com/sun/star/awt/PosSize.hpp>
27 #include <com/sun/star/awt/XWindow2.hpp>
28 #include <com/sun/star/awt/XWindowPeer.hpp>
29 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
30 #include <com/sun/star/drawing/CanvasFeature.hpp>
31 #include <com/sun/star/rendering/CompositeOperation.hpp>
32 #include <com/sun/star/rendering/TexturingMode.hpp>
33 #include <osl/mutex.hxx>
35 using namespace css;
36 using namespace css::uno;
37 using namespace css::drawing::framework;
39 namespace sdext { namespace presenter {
41 //===== PresenterPaneBase =====================================================
43 PresenterPaneBase::PresenterPaneBase (
44 const Reference<XComponentContext>& rxContext,
45 const ::rtl::Reference<PresenterController>& rpPresenterController)
46 : PresenterPaneBaseInterfaceBase(m_aMutex),
47 mpPresenterController(rpPresenterController),
48 mxParentWindow(),
49 mxBorderWindow(),
50 mxBorderCanvas(),
51 mxContentWindow(),
52 mxContentCanvas(),
53 mxPaneId(),
54 mxBorderPainter(),
55 mxPresenterHelper(),
56 msTitle(),
57 mxComponentContext(rxContext),
58 mpViewBackground(),
59 mbHasCallout(false),
60 maCalloutAnchor()
62 if (mpPresenterController.get() != NULL)
63 mxPresenterHelper = mpPresenterController->GetPresenterHelper();
66 PresenterPaneBase::~PresenterPaneBase()
70 void PresenterPaneBase::disposing()
72 if (mxBorderWindow.is())
74 mxBorderWindow->removeWindowListener(this);
75 mxBorderWindow->removePaintListener(this);
79 Reference<XComponent> xComponent (mxContentCanvas, UNO_QUERY);
80 mxContentCanvas = NULL;
81 if (xComponent.is())
82 xComponent->dispose();
86 Reference<XComponent> xComponent (mxContentWindow, UNO_QUERY);
87 mxContentWindow = NULL;
88 if (xComponent.is())
89 xComponent->dispose();
93 Reference<XComponent> xComponent (mxBorderCanvas, UNO_QUERY);
94 mxBorderCanvas = NULL;
95 if (xComponent.is())
96 xComponent->dispose();
100 Reference<XComponent> xComponent (mxBorderWindow, UNO_QUERY);
101 mxBorderWindow = NULL;
102 if (xComponent.is())
103 xComponent->dispose();
106 mxComponentContext = NULL;
109 void PresenterPaneBase::SetTitle (const OUString& rsTitle)
111 msTitle = rsTitle;
113 OSL_ASSERT(mpPresenterController.get()!=NULL);
114 OSL_ASSERT(mpPresenterController->GetPaintManager().get()!=NULL);
116 mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
119 OUString PresenterPaneBase::GetTitle() const
121 return msTitle;
124 Reference<drawing::framework::XPaneBorderPainter>
125 PresenterPaneBase::GetPaneBorderPainter() const
127 return mxBorderPainter;
130 void PresenterPaneBase::SetCalloutAnchor (const css::awt::Point& rCalloutAnchor)
132 mbHasCallout = true;
133 // Anchor is given in the coorindate system of the parent window.
134 // Transform it into the local coordinate system.
135 maCalloutAnchor = rCalloutAnchor;
136 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
137 maCalloutAnchor.X -= aBorderBox.X;
138 maCalloutAnchor.Y -= aBorderBox.Y;
140 // Move the bottom of the border window so that it goes through the
141 // callout anchor (special case for bottom callout).
142 sal_Int32 nHeight (rCalloutAnchor.Y - aBorderBox.Y);
143 if (mxBorderPainter.is() && mxPaneId.is())
144 nHeight += mxBorderPainter->getCalloutOffset(mxPaneId->getResourceURL()).Y;
146 if (nHeight != aBorderBox.Height)
148 mxBorderWindow->setPosSize(
149 aBorderBox.X,
150 aBorderBox.Y,
151 aBorderBox.Width,
152 nHeight,
153 awt::PosSize::HEIGHT);
156 mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
159 awt::Point PresenterPaneBase::GetCalloutAnchor() const
161 return maCalloutAnchor;
164 //----- XInitialization -------------------------------------------------------
166 void SAL_CALL PresenterPaneBase::initialize (const Sequence<Any>& rArguments)
167 throw (Exception, RuntimeException, std::exception)
169 ThrowIfDisposed();
171 if ( ! mxComponentContext.is())
173 throw RuntimeException(
174 "PresenterSpritePane: missing component context",
175 static_cast<XWeak*>(this));
178 if (rArguments.getLength() == 5 || rArguments.getLength() == 6)
182 // Get the resource id from the first argument.
183 if ( ! (rArguments[0] >>= mxPaneId))
185 throw lang::IllegalArgumentException(
186 "PresenterPane: invalid pane id",
187 static_cast<XWeak*>(this),
191 if ( ! (rArguments[1] >>= mxParentWindow))
193 throw lang::IllegalArgumentException(
194 "PresenterPane: invalid parent window",
195 static_cast<XWeak*>(this),
199 Reference<rendering::XSpriteCanvas> xParentCanvas;
200 if ( ! (rArguments[2] >>= xParentCanvas))
202 throw lang::IllegalArgumentException(
203 "PresenterPane: invalid parent canvas",
204 static_cast<XWeak*>(this),
208 if ( ! (rArguments[3] >>= msTitle))
210 throw lang::IllegalArgumentException(
211 "PresenterPane: invalid title",
212 static_cast<XWeak*>(this),
216 if ( ! (rArguments[4] >>= mxBorderPainter))
218 throw lang::IllegalArgumentException(
219 "PresenterPane: invalid border painter",
220 static_cast<XWeak*>(this),
224 bool bIsWindowVisibleOnCreation (true);
225 if (rArguments.getLength()>5 && ! (rArguments[5] >>= bIsWindowVisibleOnCreation))
227 throw lang::IllegalArgumentException(
228 "PresenterPane: invalid window visibility flag",
229 static_cast<XWeak*>(this),
233 CreateWindows(mxParentWindow, bIsWindowVisibleOnCreation);
235 if (mxBorderWindow.is())
237 mxBorderWindow->addWindowListener(this);
238 mxBorderWindow->addPaintListener(this);
241 CreateCanvases(mxParentWindow, xParentCanvas);
243 // Raise new windows.
244 ToTop();
246 catch (Exception&)
248 mxContentWindow = NULL;
249 mxComponentContext = NULL;
250 throw;
253 else
255 throw RuntimeException(
256 "PresenterSpritePane: invalid number of arguments",
257 static_cast<XWeak*>(this));
261 //----- XResourceId -----------------------------------------------------------
263 Reference<XResourceId> SAL_CALL PresenterPaneBase::getResourceId()
264 throw (RuntimeException, std::exception)
266 ThrowIfDisposed();
267 return mxPaneId;
270 sal_Bool SAL_CALL PresenterPaneBase::isAnchorOnly()
271 throw (RuntimeException, std::exception)
273 return true;
276 //----- XWindowListener -------------------------------------------------------
278 void SAL_CALL PresenterPaneBase::windowResized (const awt::WindowEvent& rEvent)
279 throw (RuntimeException, std::exception)
281 (void)rEvent;
282 ThrowIfDisposed();
285 void SAL_CALL PresenterPaneBase::windowMoved (const awt::WindowEvent& rEvent)
286 throw (RuntimeException, std::exception)
288 (void)rEvent;
289 ThrowIfDisposed();
292 void SAL_CALL PresenterPaneBase::windowShown (const lang::EventObject& rEvent)
293 throw (RuntimeException, std::exception)
295 (void)rEvent;
296 ThrowIfDisposed();
299 void SAL_CALL PresenterPaneBase::windowHidden (const lang::EventObject& rEvent)
300 throw (RuntimeException, std::exception)
302 (void)rEvent;
303 ThrowIfDisposed();
306 //----- lang::XEventListener --------------------------------------------------
308 void SAL_CALL PresenterPaneBase::disposing (const lang::EventObject& rEvent)
309 throw (RuntimeException, std::exception)
311 if (rEvent.Source == mxBorderWindow)
313 mxBorderWindow = NULL;
319 void PresenterPaneBase::CreateWindows (
320 const Reference<awt::XWindow>& rxParentWindow,
321 const bool bIsWindowVisibleOnCreation)
323 if (mxPresenterHelper.is() && rxParentWindow.is())
326 mxBorderWindow = mxPresenterHelper->createWindow(
327 rxParentWindow,
328 sal_False,
329 bIsWindowVisibleOnCreation,
330 sal_False,
331 sal_False);
332 mxContentWindow = mxPresenterHelper->createWindow(
333 mxBorderWindow,
334 sal_False,
335 bIsWindowVisibleOnCreation,
336 sal_False,
337 sal_False);
341 Reference<awt::XWindow> PresenterPaneBase::GetBorderWindow() const
343 return mxBorderWindow;
346 void PresenterPaneBase::ToTop()
348 if (mxPresenterHelper.is())
349 mxPresenterHelper->toTop(mxContentWindow);
352 void PresenterPaneBase::SetBackground (const SharedBitmapDescriptor& rpBackground)
354 mpViewBackground = rpBackground;
357 void PresenterPaneBase::PaintBorderBackground (
358 const awt::Rectangle& rBorderBox,
359 const awt::Rectangle& rUpdateBox)
361 (void)rBorderBox;
362 (void)rUpdateBox;
364 // The outer box of the border is given. We need the center and inner
365 // box as well.
366 awt::Rectangle aCenterBox (
367 mxBorderPainter->removeBorder(
368 mxPaneId->getResourceURL(),
369 rBorderBox,
370 drawing::framework::BorderType_OUTER_BORDER));
371 awt::Rectangle aInnerBox (
372 mxBorderPainter->removeBorder(
373 mxPaneId->getResourceURL(),
374 rBorderBox,
375 drawing::framework::BorderType_TOTAL_BORDER));
376 mpPresenterController->GetCanvasHelper()->Paint(
377 mpViewBackground,
378 mxBorderCanvas,
379 rUpdateBox,
380 aCenterBox,
381 aInnerBox);
385 void PresenterPaneBase::PaintBorder (const awt::Rectangle& rUpdateBox)
387 OSL_ASSERT(mxPaneId.is());
389 if (mxBorderPainter.is() && mxBorderWindow.is() && mxBorderCanvas.is())
391 awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
392 awt::Rectangle aLocalBorderBox (0,0, aBorderBox.Width, aBorderBox.Height);
394 PaintBorderBackground(aLocalBorderBox, rUpdateBox);
396 if (mbHasCallout)
397 mxBorderPainter->paintBorderWithCallout(
398 mxPaneId->getResourceURL(),
399 mxBorderCanvas,
400 aLocalBorderBox,
401 rUpdateBox,
402 msTitle,
403 maCalloutAnchor);
404 else
405 mxBorderPainter->paintBorder(
406 mxPaneId->getResourceURL(),
407 mxBorderCanvas,
408 aLocalBorderBox,
409 rUpdateBox,
410 msTitle);
414 void PresenterPaneBase::LayoutContextWindow()
416 OSL_ASSERT(mxPaneId.is());
417 OSL_ASSERT(mxBorderWindow.is());
418 OSL_ASSERT(mxContentWindow.is());
419 if (mxBorderPainter.is() && mxPaneId.is() && mxBorderWindow.is() && mxContentWindow.is())
421 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
422 const awt::Rectangle aInnerBox (mxBorderPainter->removeBorder(
423 mxPaneId->getResourceURL(),
424 aBorderBox,
425 drawing::framework::BorderType_TOTAL_BORDER));
426 mxContentWindow->setPosSize(
427 aInnerBox.X - aBorderBox.X,
428 aInnerBox.Y - aBorderBox.Y,
429 aInnerBox.Width,
430 aInnerBox.Height,
431 awt::PosSize::POSSIZE);
435 bool PresenterPaneBase::IsVisible() const
437 Reference<awt::XWindow2> xWindow2 (mxBorderPainter, UNO_QUERY);
438 if (xWindow2.is())
439 return xWindow2->isVisible();
441 return false;
444 void PresenterPaneBase::ThrowIfDisposed()
445 throw (::com::sun::star::lang::DisposedException)
447 if (rBHelper.bDisposed || rBHelper.bInDispose)
449 throw lang::DisposedException (
450 "PresenterPane object has already been disposed",
451 static_cast<uno::XWeak*>(this));
455 } } // end of namespace ::sd::presenter
457 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */