bump product version to 5.0.4.1
[LibreOffice.git] / sdext / source / presenter / PresenterSpritePane.cxx
bloba12015e0076fd65188516a58f9a4ec3d1d8f787d
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 "PresenterSpritePane.hxx"
21 #include "PresenterGeometryHelper.hxx"
22 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
23 #include <com/sun/star/rendering/CompositeOperation.hpp>
24 #include <osl/mutex.hxx>
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::drawing::framework;
30 namespace sdext { namespace presenter {
32 //===== PresenterSpritePane =========================================================
34 PresenterSpritePane::PresenterSpritePane (const Reference<XComponentContext>& rxContext,
35 const ::rtl::Reference<PresenterController>& rpPresenterController)
36 : PresenterPaneBase(rxContext, rpPresenterController),
37 mxParentWindow(),
38 mxParentCanvas(),
39 mpSprite(new PresenterSprite())
41 Reference<lang::XMultiComponentFactory> xFactory (
42 mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
43 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
44 xFactory->createInstanceWithContext(
45 OUString("com.sun.star.comp.Draw.PresenterHelper"),
46 mxComponentContext),
47 UNO_QUERY_THROW);
50 PresenterSpritePane::~PresenterSpritePane()
54 void PresenterSpritePane::disposing()
56 mpSprite->SetFactory(NULL);
57 mxParentWindow = NULL;
58 mxParentCanvas = NULL;
59 PresenterPaneBase::disposing();
62 //----- XPane -----------------------------------------------------------------
64 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow()
65 throw (RuntimeException, std::exception)
67 ThrowIfDisposed();
68 return mxContentWindow;
71 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas()
72 throw (RuntimeException, std::exception)
74 ThrowIfDisposed();
76 if ( ! mxContentCanvas.is())
77 UpdateCanvases();
79 return mxContentCanvas;
82 //----- XWindowListener -------------------------------------------------------
84 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
85 throw (RuntimeException, std::exception)
87 (void)rEvent;
88 PresenterPaneBase::windowResized(rEvent);
90 mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
91 LayoutContextWindow();
92 UpdateCanvases();
95 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
96 throw (RuntimeException, std::exception)
98 (void)rEvent;
99 PresenterPaneBase::windowMoved(rEvent);
101 awt::Rectangle aBox (
102 mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
103 mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
104 mpSprite->Update();
107 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
108 throw (RuntimeException, std::exception)
110 (void)rEvent;
111 PresenterPaneBase::windowShown(rEvent);
113 mpSprite->Show();
114 ToTop();
116 if (mxContentWindow.is())
118 LayoutContextWindow();
119 mxContentWindow->setVisible(sal_True);
123 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
124 throw (RuntimeException, std::exception)
126 (void)rEvent;
127 PresenterPaneBase::windowHidden(rEvent);
129 mpSprite->Hide();
130 if (mxContentWindow.is())
131 mxContentWindow->setVisible(sal_False);
134 //----- XPaintListener --------------------------------------------------------
136 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent& rEvent)
137 throw (RuntimeException, std::exception)
139 (void)rEvent;
140 ThrowIfDisposed();
143 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
144 if (xSpriteCanvas.is())
145 xSpriteCanvas->updateScreen(sal_False);
151 ::boost::shared_ptr<PresenterSprite> PresenterSpritePane::GetSprite()
153 return mpSprite;
156 void PresenterSpritePane::UpdateCanvases()
158 Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
159 if (xContentCanvasComponent.is())
161 if (xContentCanvasComponent.is())
162 xContentCanvasComponent->dispose();
165 // The border canvas is the content canvas of the sprite.
166 mxBorderCanvas = mpSprite->GetCanvas();
168 // The content canvas is a wrapper of the border canvas.
169 if (mxBorderCanvas.is())
170 mxContentCanvas = mxPresenterHelper->createSharedCanvas(
171 mxParentCanvas,
172 mxParentWindow,
173 mxBorderCanvas,
174 mxBorderWindow,
175 mxContentWindow);
177 const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
178 PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
181 void PresenterSpritePane::CreateCanvases (
182 const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
183 const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
185 OSL_ASSERT(!mxParentWindow.is() || mxParentWindow==rxParentWindow);
186 OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
187 mxParentWindow = rxParentWindow;
188 mxParentCanvas = rxParentCanvas;
190 mpSprite->SetFactory(mxParentCanvas);
191 if (mxBorderWindow.is())
193 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
194 mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
197 UpdateCanvases();
200 } } // end of namespace ::sd::presenter
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */