1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "PresenterSpritePane.hxx"
21 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
23 using namespace ::com::sun::star
;
24 using namespace ::com::sun::star::uno
;
25 using namespace ::com::sun::star::drawing::framework
;
27 namespace sdext::presenter
{
29 //===== PresenterSpritePane =========================================================
31 PresenterSpritePane::PresenterSpritePane (const Reference
<XComponentContext
>& rxContext
,
32 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
33 : PresenterPaneBase(rxContext
, rpPresenterController
),
34 mpSprite(std::make_shared
<PresenterSprite
>())
36 Reference
<lang::XMultiComponentFactory
> xFactory (
37 mxComponentContext
->getServiceManager(), UNO_SET_THROW
);
38 mxPresenterHelper
.set(
39 xFactory
->createInstanceWithContext(
40 "com.sun.star.comp.Draw.PresenterHelper",
45 PresenterSpritePane::~PresenterSpritePane()
49 void PresenterSpritePane::disposing()
51 mpSprite
->SetFactory(nullptr);
52 mxParentCanvas
= nullptr;
53 PresenterPaneBase::disposing();
56 //----- XPane -----------------------------------------------------------------
58 Reference
<awt::XWindow
> SAL_CALL
PresenterSpritePane::getWindow()
61 return mxContentWindow
;
64 Reference
<rendering::XCanvas
> SAL_CALL
PresenterSpritePane::getCanvas()
68 if ( ! mxContentCanvas
.is())
71 return mxContentCanvas
;
74 //----- XWindowListener -------------------------------------------------------
76 void SAL_CALL
PresenterSpritePane::windowResized (const awt::WindowEvent
& rEvent
)
78 PresenterPaneBase::windowResized(rEvent
);
80 mpSprite
->Resize(geometry::RealSize2D(rEvent
.Width
, rEvent
.Height
));
81 LayoutContextWindow();
85 void SAL_CALL
PresenterSpritePane::windowMoved (const awt::WindowEvent
& rEvent
)
87 PresenterPaneBase::windowMoved(rEvent
);
90 mxPresenterHelper
->getWindowExtentsRelative(mxBorderWindow
, mxParentWindow
));
91 mpSprite
->MoveTo(geometry::RealPoint2D(aBox
.X
, aBox
.Y
));
95 void SAL_CALL
PresenterSpritePane::windowShown (const lang::EventObject
& rEvent
)
97 PresenterPaneBase::windowShown(rEvent
);
102 if (mxContentWindow
.is())
104 LayoutContextWindow();
105 mxContentWindow
->setVisible(true);
109 void SAL_CALL
PresenterSpritePane::windowHidden (const lang::EventObject
& rEvent
)
111 PresenterPaneBase::windowHidden(rEvent
);
114 if (mxContentWindow
.is())
115 mxContentWindow
->setVisible(false);
118 //----- XPaintListener --------------------------------------------------------
120 void SAL_CALL
PresenterSpritePane::windowPaint (const awt::PaintEvent
&)
125 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
126 if (xSpriteCanvas.is())
127 xSpriteCanvas->updateScreen(sal_False);
132 void PresenterSpritePane::UpdateCanvases()
134 Reference
<XComponent
> xContentCanvasComponent (mxContentCanvas
, UNO_QUERY
);
135 if (xContentCanvasComponent
.is())
136 xContentCanvasComponent
->dispose();
138 // The border canvas is the content canvas of the sprite.
139 mxBorderCanvas
= mpSprite
->GetCanvas();
141 // The content canvas is a wrapper of the border canvas.
142 if (mxBorderCanvas
.is())
143 mxContentCanvas
= mxPresenterHelper
->createSharedCanvas(
150 const awt::Rectangle
aWindowBox (mxBorderWindow
->getPosSize());
151 PaintBorder(awt::Rectangle(0,0,aWindowBox
.Width
,aWindowBox
.Height
));
154 void PresenterSpritePane::CreateCanvases (
155 const css::uno::Reference
<css::rendering::XSpriteCanvas
>& rxParentCanvas
)
157 OSL_ASSERT(!mxParentCanvas
.is() || mxParentCanvas
==rxParentCanvas
);
158 mxParentCanvas
= rxParentCanvas
;
160 mpSprite
->SetFactory(mxParentCanvas
);
161 if (mxBorderWindow
.is())
163 const awt::Rectangle
aBorderBox (mxBorderWindow
->getPosSize());
164 mpSprite
->Resize(geometry::RealSize2D(aBorderBox
.Width
, aBorderBox
.Height
));
170 } // end of namespace ::sdext::presenter
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */