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