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),
35 {
36  Reference<lang::XMultiComponentFactory> xFactory (
37  mxComponentContext->getServiceManager(), UNO_SET_THROW);
39  xFactory->createInstanceWithContext(
40  "com.sun.star.comp.Draw.PresenterHelper",
42  UNO_QUERY_THROW);
43 }
44 
46 {
47 }
48 
50 {
51  mpSprite->SetFactory(nullptr);
52  mxParentCanvas = nullptr;
54 }
55 
56 //----- XPane -----------------------------------------------------------------
57 
58 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow()
59 {
61  return mxContentWindow;
62 }
63 
64 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas()
65 {
67 
68  if ( ! mxContentCanvas.is())
70 
71  return mxContentCanvas;
72 }
73 
74 //----- XWindowListener -------------------------------------------------------
75 
76 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
77 {
79 
80  mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
83 }
84 
85 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
86 {
88 
89  awt::Rectangle aBox (
90  mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
91  mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
92  mpSprite->Update();
93 }
94 
95 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
96 {
98 
99  mpSprite->Show();
100  ToTop();
101 
102  if (mxContentWindow.is())
103  {
105  mxContentWindow->setVisible(true);
106  }
107 }
108 
109 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
110 {
112 
113  mpSprite->Hide();
114  if (mxContentWindow.is())
115  mxContentWindow->setVisible(false);
116 }
117 
118 //----- XPaintListener --------------------------------------------------------
119 
120 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent&)
121 {
122  ThrowIfDisposed();
123 
124  /*
125  Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
126  if (xSpriteCanvas.is())
127  xSpriteCanvas->updateScreen(sal_False);
128  */
129 }
130 
131 
133 {
134  Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
135  if (xContentCanvasComponent.is())
136  xContentCanvasComponent->dispose();
137 
138  // The border canvas is the content canvas of the sprite.
139  mxBorderCanvas = mpSprite->GetCanvas();
140 
141  // The content canvas is a wrapper of the border canvas.
142  if (mxBorderCanvas.is())
143  mxContentCanvas = mxPresenterHelper->createSharedCanvas(
149 
150  const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
151  PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
152 }
153 
155  const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
156 {
157  OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
158  mxParentCanvas = rxParentCanvas;
159 
160  mpSprite->SetFactory(mxParentCanvas);
161  if (mxBorderWindow.is())
162  {
163  const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
164  mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
165  }
166 
167  UpdateCanvases();
168 }
169 
170 } // end of namespace ::sdext::presenter
171 
172 /* 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
std::shared_ptr< T > make_shared(Args &&...args)
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