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
PresenterSpritePane(const Reference<XComponentContext> & rxContext,const::rtl::Reference<PresenterController> & rpPresenterController)31 PresenterSpritePane::PresenterSpritePane (const Reference<XComponentContext>& rxContext,
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);
39 mxPresenterHelper.set(
40 xFactory->createInstanceWithContext(
41 "com.sun.star.comp.Draw.PresenterHelper",
42 mxComponentContext),
43 UNO_QUERY_THROW);
44 }
45
~PresenterSpritePane()46 PresenterSpritePane::~PresenterSpritePane()
47 {
48 }
49
disposing()50 void PresenterSpritePane::disposing()
51 {
52 mpSprite->SetFactory(nullptr);
53 mxParentCanvas = nullptr;
54 PresenterPaneBase::disposing();
55 }
56
57 //----- XPane -----------------------------------------------------------------
58
getWindow()59 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow()
60 {
61 ThrowIfDisposed();
62 return mxContentWindow;
63 }
64
getCanvas()65 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas()
66 {
67 ThrowIfDisposed();
68
69 if ( ! mxContentCanvas.is())
70 UpdateCanvases();
71
72 return mxContentCanvas;
73 }
74
75 //----- XWindowListener -------------------------------------------------------
76
windowResized(const awt::WindowEvent & rEvent)77 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
78 {
79 PresenterPaneBase::windowResized(rEvent);
80
81 mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
82 LayoutContextWindow();
83 UpdateCanvases();
84 }
85
windowMoved(const awt::WindowEvent & rEvent)86 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
87 {
88 PresenterPaneBase::windowMoved(rEvent);
89
90 awt::Rectangle aBox (
91 mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
92 mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
93 mpSprite->Update();
94 }
95
windowShown(const lang::EventObject & rEvent)96 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
97 {
98 PresenterPaneBase::windowShown(rEvent);
99
100 mpSprite->Show();
101 ToTop();
102
103 if (mxContentWindow.is())
104 {
105 LayoutContextWindow();
106 mxContentWindow->setVisible(true);
107 }
108 }
109
windowHidden(const lang::EventObject & rEvent)110 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
111 {
112 PresenterPaneBase::windowHidden(rEvent);
113
114 mpSprite->Hide();
115 if (mxContentWindow.is())
116 mxContentWindow->setVisible(false);
117 }
118
119 //----- XPaintListener --------------------------------------------------------
120
windowPaint(const awt::PaintEvent &)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
UpdateCanvases()133 void PresenterSpritePane::UpdateCanvases()
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(
145 mxParentCanvas,
146 mxParentWindow,
147 mxBorderCanvas,
148 mxBorderWindow,
149 mxContentWindow);
150
151 const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
152 PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
153 }
154
CreateCanvases(const css::uno::Reference<css::rendering::XSpriteCanvas> & rxParentCanvas)155 void PresenterSpritePane::CreateCanvases (
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: */
174