Line data Source code
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 "PresenterGeometryHelper.hxx"
22 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
23 : #include <com/sun/star/rendering/CompositeOperation.hpp>
24 : #include <osl/mutex.hxx>
25 :
26 : using namespace ::com::sun::star;
27 : using namespace ::com::sun::star::uno;
28 : using namespace ::com::sun::star::drawing::framework;
29 :
30 : namespace sdext { namespace presenter {
31 :
32 : //===== PresenterSpritePane =========================================================
33 :
34 0 : PresenterSpritePane::PresenterSpritePane (const Reference<XComponentContext>& rxContext,
35 : const ::rtl::Reference<PresenterController>& rpPresenterController)
36 : : PresenterPaneBase(rxContext, rpPresenterController),
37 : mxParentWindow(),
38 : mxParentCanvas(),
39 0 : mpSprite(new PresenterSprite())
40 : {
41 : Reference<lang::XMultiComponentFactory> xFactory (
42 0 : mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
43 0 : mxPresenterHelper = Reference<drawing::XPresenterHelper>(
44 0 : xFactory->createInstanceWithContext(
45 : OUString("com.sun.star.comp.Draw.PresenterHelper"),
46 0 : mxComponentContext),
47 0 : UNO_QUERY_THROW);
48 0 : }
49 :
50 0 : PresenterSpritePane::~PresenterSpritePane()
51 : {
52 0 : }
53 :
54 0 : void PresenterSpritePane::disposing()
55 : {
56 0 : mpSprite->SetFactory(NULL);
57 0 : mxParentWindow = NULL;
58 0 : mxParentCanvas = NULL;
59 0 : PresenterPaneBase::disposing();
60 0 : }
61 :
62 : //----- XPane -----------------------------------------------------------------
63 :
64 0 : Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow()
65 : throw (RuntimeException, std::exception)
66 : {
67 0 : ThrowIfDisposed();
68 0 : return mxContentWindow;
69 : }
70 :
71 0 : Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas()
72 : throw (RuntimeException, std::exception)
73 : {
74 0 : ThrowIfDisposed();
75 :
76 0 : if ( ! mxContentCanvas.is())
77 0 : UpdateCanvases();
78 :
79 0 : return mxContentCanvas;
80 : }
81 :
82 : //----- XWindowListener -------------------------------------------------------
83 :
84 0 : void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
85 : throw (RuntimeException, std::exception)
86 : {
87 : (void)rEvent;
88 0 : PresenterPaneBase::windowResized(rEvent);
89 :
90 0 : mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
91 0 : LayoutContextWindow();
92 0 : UpdateCanvases();
93 0 : }
94 :
95 0 : void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
96 : throw (RuntimeException, std::exception)
97 : {
98 : (void)rEvent;
99 0 : PresenterPaneBase::windowMoved(rEvent);
100 :
101 : awt::Rectangle aBox (
102 0 : mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
103 0 : mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
104 0 : mpSprite->Update();
105 0 : }
106 :
107 0 : void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
108 : throw (RuntimeException, std::exception)
109 : {
110 : (void)rEvent;
111 0 : PresenterPaneBase::windowShown(rEvent);
112 :
113 0 : mpSprite->Show();
114 0 : ToTop();
115 :
116 0 : if (mxContentWindow.is())
117 : {
118 0 : LayoutContextWindow();
119 0 : mxContentWindow->setVisible(sal_True);
120 : }
121 0 : }
122 :
123 0 : void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
124 : throw (RuntimeException, std::exception)
125 : {
126 : (void)rEvent;
127 0 : PresenterPaneBase::windowHidden(rEvent);
128 :
129 0 : mpSprite->Hide();
130 0 : if (mxContentWindow.is())
131 0 : mxContentWindow->setVisible(sal_False);
132 0 : }
133 :
134 : //----- XPaintListener --------------------------------------------------------
135 :
136 0 : void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent& rEvent)
137 : throw (RuntimeException, std::exception)
138 : {
139 : (void)rEvent;
140 0 : ThrowIfDisposed();
141 :
142 : /*
143 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
144 : if (xSpriteCanvas.is())
145 : xSpriteCanvas->updateScreen(sal_False);
146 : */
147 0 : }
148 :
149 :
150 :
151 0 : ::boost::shared_ptr<PresenterSprite> PresenterSpritePane::GetSprite()
152 : {
153 0 : return mpSprite;
154 : }
155 :
156 0 : void PresenterSpritePane::UpdateCanvases()
157 : {
158 0 : Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
159 0 : if (xContentCanvasComponent.is())
160 : {
161 0 : if (xContentCanvasComponent.is())
162 0 : xContentCanvasComponent->dispose();
163 : }
164 :
165 : // The border canvas is the content canvas of the sprite.
166 0 : mxBorderCanvas = mpSprite->GetCanvas();
167 :
168 : // The content canvas is a wrapper of the border canvas.
169 0 : if (mxBorderCanvas.is())
170 0 : mxContentCanvas = mxPresenterHelper->createSharedCanvas(
171 : mxParentCanvas,
172 : mxParentWindow,
173 : mxBorderCanvas,
174 : mxBorderWindow,
175 0 : mxContentWindow);
176 :
177 0 : const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
178 0 : PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
179 0 : }
180 :
181 0 : void PresenterSpritePane::CreateCanvases (
182 : const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
183 : const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
184 : {
185 : OSL_ASSERT(!mxParentWindow.is() || mxParentWindow==rxParentWindow);
186 : OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
187 0 : mxParentWindow = rxParentWindow;
188 0 : mxParentCanvas = rxParentCanvas;
189 :
190 0 : mpSprite->SetFactory(mxParentCanvas);
191 0 : if (mxBorderWindow.is())
192 : {
193 0 : const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
194 0 : mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
195 : }
196 :
197 0 : UpdateCanvases();
198 0 : }
199 :
200 : } } // end of namespace ::sd::presenter
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|