LibreOffice Module sdext (master)  1
PresenterSpritePane.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 "PresenterSpritePane.hxx"
21 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
22 
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::drawing::framework;
26 
27 namespace sdext::presenter {
28 
29 //===== PresenterSpritePane =========================================================
30 
32  const ::rtl::Reference<PresenterController>& rpPresenterController)
33  : PresenterPaneBase(rxContext, rpPresenterController),
34  mxParentCanvas(),
35  mpSprite(std::make_shared<PresenterSprite>())
36 {
37  Reference<lang::XMultiComponentFactory> xFactory (
38  mxComponentContext->getServiceManager(), UNO_SET_THROW);
40  xFactory->createInstanceWithContext(
41  "com.sun.star.comp.Draw.PresenterHelper",
43  UNO_QUERY_THROW);
44 }
45 
47 {
48 }
49 
51 {
52  mpSprite->SetFactory(nullptr);
53  mxParentCanvas = nullptr;
55 }
56 
57 //----- XPane -----------------------------------------------------------------
58 
59 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow()
60 {
62  return mxContentWindow;
63 }
64 
65 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas()
66 {
68 
69  if ( ! mxContentCanvas.is())
71 
72  return mxContentCanvas;
73 }
74 
75 //----- XWindowListener -------------------------------------------------------
76 
77 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
78 {
80 
81  mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
84 }
85 
86 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
87 {
89 
90  awt::Rectangle aBox (
91  mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
92  mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
93  mpSprite->Update();
94 }
95 
96 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
97 {
99 
100  mpSprite->Show();
101  ToTop();
102 
103  if (mxContentWindow.is())
104  {
106  mxContentWindow->setVisible(true);
107  }
108 }
109 
110 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
111 {
113 
114  mpSprite->Hide();
115  if (mxContentWindow.is())
116  mxContentWindow->setVisible(false);
117 }
118 
119 //----- XPaintListener --------------------------------------------------------
120 
121 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent&)
122 {
123  ThrowIfDisposed();
124 
125  /*
126  Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
127  if (xSpriteCanvas.is())
128  xSpriteCanvas->updateScreen(sal_False);
129  */
130 }
131 
132 
134 {
135  Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
136  if (xContentCanvasComponent.is())
137  xContentCanvasComponent->dispose();
138 
139  // The border canvas is the content canvas of the sprite.
140  mxBorderCanvas = mpSprite->GetCanvas();
141 
142  // The content canvas is a wrapper of the border canvas.
143  if (mxBorderCanvas.is())
144  mxContentCanvas = mxPresenterHelper->createSharedCanvas(
150 
151  const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
152  PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
153 }
154 
156  const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
157 {
158  OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
159  mxParentCanvas = rxParentCanvas;
160 
161  mpSprite->SetFactory(mxParentCanvas);
162  if (mxBorderWindow.is())
163  {
164  const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
165  mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
166  }
167 
168  UpdateCanvases();
169 }
170 
171 } // end of namespace ::sdext::presenter
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL windowPaint(const css::awt::PaintEvent &rEvent) override
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
virtual void SAL_CALL disposing() override
virtual void SAL_CALL windowHidden(const css::lang::EventObject &rEvent) override
css::uno::Reference< css::awt::XWindow > mxBorderWindow
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &rEvent) override
Base class of the panes used by the presenter screen.
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getWindow() override
virtual void CreateCanvases(const css::uno::Reference< css::rendering::XSpriteCanvas > &rxParentCanvas) override
css::uno::Reference< css::rendering::XCanvas > mxContentCanvas
std::shared_ptr< PresenterSprite > mpSprite
css::uno::Reference< css::rendering::XCanvas > mxBorderCanvas
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &rEvent) override
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &rEvent) override
virtual void SAL_CALL windowShown(const css::lang::EventObject &rEvent) override
virtual void SAL_CALL windowShown(const css::lang::EventObject &rEvent) override
std::weak_ptr< cppcanvas::CustomSprite > mpSprite
virtual css::uno::Reference< css::rendering::XCanvas > SAL_CALL getCanvas() override
css::uno::Reference< css::drawing::XPresenterHelper > mxPresenterHelper
PresenterSpritePane(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const ::rtl::Reference< PresenterController > &rpPresenterController)
virtual void SAL_CALL disposing() override
A wrapper around a css::rendering::XCustomSprite that allows not only setting values like size...
css::uno::Reference< css::awt::XWindow > mxContentWindow
void PaintBorder(const css::awt::Rectangle &rUpdateRectangle)
css::uno::Reference< css::rendering::XSpriteCanvas > mxParentCanvas
css::uno::Reference< css::awt::XWindow > mxParentWindow
Reference< XSingleServiceFactory > xFactory
virtual void SAL_CALL windowHidden(const css::lang::EventObject &rEvent) override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &rEvent) override