Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / source / console / PresenterSpritePane.cxx
blobc90f250fb19212d44cdb7307747320f00213821b
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 "PresenterController.hxx"
21 #include "PresenterSpritePane.hxx"
22 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
24 using namespace ::com::sun::star;
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star::drawing::framework;
28 namespace sdext::presenter {
30 //===== PresenterSpritePane =========================================================
32 PresenterSpritePane::PresenterSpritePane (const Reference<XComponentContext>& rxContext,
33 const ::rtl::Reference<PresenterController>& rpPresenterController)
34 : PresenterPaneBase(rxContext, rpPresenterController),
35 mpSprite(std::make_shared<PresenterSprite>())
37 Reference<lang::XMultiComponentFactory> xFactory (
38 mxComponentContext->getServiceManager(), UNO_SET_THROW);
39 mxPresenterHelper.set(
40 xFactory->createInstanceWithContext(
41 "com.sun.star.comp.Draw.PresenterHelper",
42 mxComponentContext),
43 UNO_QUERY_THROW);
46 PresenterSpritePane::~PresenterSpritePane()
50 void PresenterSpritePane::disposing()
52 mpSprite->SetFactory(nullptr);
53 mxParentCanvas = nullptr;
54 PresenterPaneBase::disposing();
57 //----- XPane -----------------------------------------------------------------
59 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow()
61 ThrowIfDisposed();
62 return mxContentWindow;
65 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas()
67 ThrowIfDisposed();
69 if ( ! mxContentCanvas.is())
70 UpdateCanvases();
72 return mxContentCanvas;
75 //----- XWindowListener -------------------------------------------------------
77 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
79 PresenterPaneBase::windowResized(rEvent);
81 mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
82 LayoutContextWindow();
83 UpdateCanvases();
86 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
88 PresenterPaneBase::windowMoved(rEvent);
90 awt::Rectangle aBox (
91 mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
92 mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
93 mpSprite->Update();
96 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
98 PresenterPaneBase::windowShown(rEvent);
100 mpSprite->Show();
101 ToTop();
103 if (mxContentWindow.is())
105 LayoutContextWindow();
106 mxContentWindow->setVisible(true);
110 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
112 PresenterPaneBase::windowHidden(rEvent);
114 mpSprite->Hide();
115 if (mxContentWindow.is())
116 mxContentWindow->setVisible(false);
119 //----- XPaintListener --------------------------------------------------------
121 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent&)
123 ThrowIfDisposed();
126 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
127 if (xSpriteCanvas.is())
128 xSpriteCanvas->updateScreen(sal_False);
133 void PresenterSpritePane::UpdateCanvases()
135 Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
136 if (xContentCanvasComponent.is())
137 xContentCanvasComponent->dispose();
139 // The border canvas is the content canvas of the sprite.
140 mxBorderCanvas = mpSprite->GetCanvas();
142 // The content canvas is a wrapper of the border canvas.
143 if (mxBorderCanvas.is())
144 mxContentCanvas = mxPresenterHelper->createSharedCanvas(
145 mxParentCanvas,
146 mxParentWindow,
147 mxBorderCanvas,
148 mxBorderWindow,
149 mxContentWindow);
151 const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
152 PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
155 void PresenterSpritePane::CreateCanvases (
156 const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
158 OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
159 mxParentCanvas = rxParentCanvas;
161 mpSprite->SetFactory(mxParentCanvas);
162 if (mxBorderWindow.is())
164 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
165 mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
168 UpdateCanvases();
171 } // end of namespace ::sdext::presenter
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */