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 "PresenterPaneBase.hxx"
21 : #include "PresenterCanvasHelper.hxx"
22 : #include "PresenterController.hxx"
23 : #include "PresenterGeometryHelper.hxx"
24 : #include "PresenterPaintManager.hxx"
25 : #include "PresenterTextView.hxx"
26 : #include <com/sun/star/awt/PosSize.hpp>
27 : #include <com/sun/star/awt/XWindow2.hpp>
28 : #include <com/sun/star/awt/XWindowPeer.hpp>
29 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
30 : #include <com/sun/star/drawing/CanvasFeature.hpp>
31 : #include <com/sun/star/rendering/CompositeOperation.hpp>
32 : #include <com/sun/star/rendering/TexturingMode.hpp>
33 : #include <osl/mutex.hxx>
34 :
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::uno;
37 : using namespace ::com::sun::star::drawing::framework;
38 : using ::rtl::OUString;
39 :
40 : namespace sdext { namespace presenter {
41 :
42 : //===== PresenterPaneBase =====================================================
43 :
44 0 : PresenterPaneBase::PresenterPaneBase (
45 : const Reference<XComponentContext>& rxContext,
46 : const ::rtl::Reference<PresenterController>& rpPresenterController)
47 : : PresenterPaneBaseInterfaceBase(m_aMutex),
48 : mpPresenterController(rpPresenterController),
49 : mxParentWindow(),
50 : mxBorderWindow(),
51 : mxBorderCanvas(),
52 : mxContentWindow(),
53 : mxContentCanvas(),
54 : mxPaneId(),
55 : mxBorderPainter(),
56 : mxPresenterHelper(),
57 : msTitle(),
58 : mxComponentContext(rxContext),
59 : mpViewBackground(),
60 : mbHasCallout(false),
61 0 : maCalloutAnchor()
62 : {
63 0 : if (mpPresenterController.get() != NULL)
64 0 : mxPresenterHelper = mpPresenterController->GetPresenterHelper();
65 0 : }
66 :
67 0 : PresenterPaneBase::~PresenterPaneBase (void)
68 : {
69 0 : }
70 :
71 0 : void PresenterPaneBase::disposing (void)
72 : {
73 0 : if (mxBorderWindow.is())
74 : {
75 0 : mxBorderWindow->removeWindowListener(this);
76 0 : mxBorderWindow->removePaintListener(this);
77 : }
78 :
79 : {
80 0 : Reference<XComponent> xComponent (mxContentCanvas, UNO_QUERY);
81 0 : mxContentCanvas = NULL;
82 0 : if (xComponent.is())
83 0 : xComponent->dispose();
84 : }
85 :
86 : {
87 0 : Reference<XComponent> xComponent (mxContentWindow, UNO_QUERY);
88 0 : mxContentWindow = NULL;
89 0 : if (xComponent.is())
90 0 : xComponent->dispose();
91 : }
92 :
93 : {
94 0 : Reference<XComponent> xComponent (mxBorderCanvas, UNO_QUERY);
95 0 : mxBorderCanvas = NULL;
96 0 : if (xComponent.is())
97 0 : xComponent->dispose();
98 : }
99 :
100 : {
101 0 : Reference<XComponent> xComponent (mxBorderWindow, UNO_QUERY);
102 0 : mxBorderWindow = NULL;
103 0 : if (xComponent.is())
104 0 : xComponent->dispose();
105 : }
106 :
107 0 : mxComponentContext = NULL;
108 0 : }
109 :
110 0 : void PresenterPaneBase::SetTitle (const OUString& rsTitle)
111 : {
112 0 : msTitle = rsTitle;
113 :
114 : OSL_ASSERT(mpPresenterController.get()!=NULL);
115 : OSL_ASSERT(mpPresenterController->GetPaintManager().get()!=NULL);
116 :
117 0 : mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
118 0 : }
119 :
120 0 : ::rtl::OUString PresenterPaneBase::GetTitle (void) const
121 : {
122 0 : return msTitle;
123 : }
124 :
125 : Reference<drawing::framework::XPaneBorderPainter>
126 0 : PresenterPaneBase::GetPaneBorderPainter (void) const
127 : {
128 0 : return mxBorderPainter;
129 : }
130 :
131 0 : void PresenterPaneBase::SetCalloutAnchor (const css::awt::Point& rCalloutAnchor)
132 : {
133 0 : mbHasCallout = true;
134 : // Anchor is given in the coorindate system of the parent window.
135 : // Transform it into the local coordinate system.
136 0 : maCalloutAnchor = rCalloutAnchor;
137 0 : const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
138 0 : maCalloutAnchor.X -= aBorderBox.X;
139 0 : maCalloutAnchor.Y -= aBorderBox.Y;
140 :
141 : // Move the bottom of the border window so that it goes through the
142 : // callout anchor (special case for bottom callout).
143 0 : sal_Int32 nHeight (rCalloutAnchor.Y - aBorderBox.Y);
144 0 : if (mxBorderPainter.is() && mxPaneId.is())
145 0 : nHeight += mxBorderPainter->getCalloutOffset(mxPaneId->getResourceURL()).Y;
146 :
147 0 : if (nHeight != aBorderBox.Height)
148 : {
149 0 : mxBorderWindow->setPosSize(
150 : aBorderBox.X,
151 : aBorderBox.Y,
152 : aBorderBox.Width,
153 : nHeight,
154 0 : awt::PosSize::HEIGHT);
155 : }
156 :
157 0 : mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
158 0 : }
159 :
160 0 : awt::Point PresenterPaneBase::GetCalloutAnchor (void) const
161 : {
162 0 : return maCalloutAnchor;
163 : }
164 :
165 : //----- XInitialization -------------------------------------------------------
166 :
167 0 : void SAL_CALL PresenterPaneBase::initialize (const Sequence<Any>& rArguments)
168 : throw (Exception, RuntimeException)
169 : {
170 0 : ThrowIfDisposed();
171 :
172 0 : if ( ! mxComponentContext.is())
173 : {
174 : throw RuntimeException(
175 : OUString("PresenterSpritePane: missing component context"),
176 0 : static_cast<XWeak*>(this));
177 : }
178 :
179 0 : if (rArguments.getLength() == 5 || rArguments.getLength() == 6)
180 : {
181 : try
182 : {
183 : // Get the resource id from the first argument.
184 0 : if ( ! (rArguments[0] >>= mxPaneId))
185 : {
186 : throw lang::IllegalArgumentException(
187 : OUString("PresenterPane: invalid pane id"),
188 : static_cast<XWeak*>(this),
189 0 : 0);
190 : }
191 :
192 0 : if ( ! (rArguments[1] >>= mxParentWindow))
193 : {
194 : throw lang::IllegalArgumentException(
195 : OUString("PresenterPane: invalid parent window"),
196 : static_cast<XWeak*>(this),
197 0 : 1);
198 : }
199 :
200 0 : Reference<rendering::XSpriteCanvas> xParentCanvas;
201 0 : if ( ! (rArguments[2] >>= xParentCanvas))
202 : {
203 : throw lang::IllegalArgumentException(
204 : OUString("PresenterPane: invalid parent canvas"),
205 : static_cast<XWeak*>(this),
206 0 : 2);
207 : }
208 :
209 0 : if ( ! (rArguments[3] >>= msTitle))
210 : {
211 : throw lang::IllegalArgumentException(
212 : OUString("PresenterPane: invalid title"),
213 : static_cast<XWeak*>(this),
214 0 : 3);
215 : }
216 :
217 0 : if ( ! (rArguments[4] >>= mxBorderPainter))
218 : {
219 : throw lang::IllegalArgumentException(
220 : OUString("PresenterPane: invalid border painter"),
221 : static_cast<XWeak*>(this),
222 0 : 4);
223 : }
224 :
225 0 : bool bIsWindowVisibleOnCreation (true);
226 0 : if (rArguments.getLength()>5 && ! (rArguments[5] >>= bIsWindowVisibleOnCreation))
227 : {
228 : throw lang::IllegalArgumentException(
229 : OUString("PresenterPane: invalid window visibility flag"),
230 : static_cast<XWeak*>(this),
231 0 : 5);
232 : }
233 :
234 0 : CreateWindows(mxParentWindow, bIsWindowVisibleOnCreation);
235 :
236 0 : if (mxBorderWindow.is())
237 : {
238 0 : mxBorderWindow->addWindowListener(this);
239 0 : mxBorderWindow->addPaintListener(this);
240 : }
241 :
242 0 : CreateCanvases(mxParentWindow, xParentCanvas);
243 :
244 : // Raise new windows.
245 0 : ToTop();
246 : }
247 0 : catch (Exception&)
248 : {
249 0 : mxContentWindow = NULL;
250 0 : mxComponentContext = NULL;
251 0 : throw;
252 : }
253 : }
254 : else
255 : {
256 : throw RuntimeException(
257 : OUString("PresenterSpritePane: invalid number of arguments"),
258 0 : static_cast<XWeak*>(this));
259 : }
260 0 : }
261 :
262 : //----- XResourceId -----------------------------------------------------------
263 :
264 0 : Reference<XResourceId> SAL_CALL PresenterPaneBase::getResourceId (void)
265 : throw (RuntimeException)
266 : {
267 0 : ThrowIfDisposed();
268 0 : return mxPaneId;
269 : }
270 :
271 0 : sal_Bool SAL_CALL PresenterPaneBase::isAnchorOnly (void)
272 : throw (RuntimeException)
273 : {
274 0 : return true;
275 : }
276 :
277 : //----- XWindowListener -------------------------------------------------------
278 :
279 0 : void SAL_CALL PresenterPaneBase::windowResized (const awt::WindowEvent& rEvent)
280 : throw (RuntimeException)
281 : {
282 : (void)rEvent;
283 0 : ThrowIfDisposed();
284 0 : }
285 :
286 0 : void SAL_CALL PresenterPaneBase::windowMoved (const awt::WindowEvent& rEvent)
287 : throw (RuntimeException)
288 : {
289 : (void)rEvent;
290 0 : ThrowIfDisposed();
291 0 : }
292 :
293 0 : void SAL_CALL PresenterPaneBase::windowShown (const lang::EventObject& rEvent)
294 : throw (RuntimeException)
295 : {
296 : (void)rEvent;
297 0 : ThrowIfDisposed();
298 0 : }
299 :
300 0 : void SAL_CALL PresenterPaneBase::windowHidden (const lang::EventObject& rEvent)
301 : throw (RuntimeException)
302 : {
303 : (void)rEvent;
304 0 : ThrowIfDisposed();
305 0 : }
306 :
307 : //----- lang::XEventListener --------------------------------------------------
308 :
309 0 : void SAL_CALL PresenterPaneBase::disposing (const lang::EventObject& rEvent)
310 : throw (RuntimeException)
311 : {
312 0 : if (rEvent.Source == mxBorderWindow)
313 : {
314 0 : mxBorderWindow = NULL;
315 : }
316 0 : }
317 :
318 : //-----------------------------------------------------------------------------
319 :
320 0 : void PresenterPaneBase::CreateWindows (
321 : const Reference<awt::XWindow>& rxParentWindow,
322 : const bool bIsWindowVisibleOnCreation)
323 : {
324 0 : if (mxPresenterHelper.is() && rxParentWindow.is())
325 : {
326 :
327 0 : mxBorderWindow = mxPresenterHelper->createWindow(
328 : rxParentWindow,
329 : sal_False,
330 : bIsWindowVisibleOnCreation,
331 : sal_False,
332 0 : sal_False);
333 0 : mxContentWindow = mxPresenterHelper->createWindow(
334 : mxBorderWindow,
335 : sal_False,
336 : bIsWindowVisibleOnCreation,
337 : sal_False,
338 0 : sal_False);
339 : }
340 0 : }
341 :
342 0 : Reference<awt::XWindow> PresenterPaneBase::GetBorderWindow (void) const
343 : {
344 0 : return mxBorderWindow;
345 : }
346 :
347 0 : void PresenterPaneBase::ToTop (void)
348 : {
349 0 : if (mxPresenterHelper.is())
350 0 : mxPresenterHelper->toTop(mxContentWindow);
351 0 : }
352 :
353 0 : void PresenterPaneBase::SetBackground (const SharedBitmapDescriptor& rpBackground)
354 : {
355 0 : mpViewBackground = rpBackground;
356 0 : }
357 :
358 0 : void PresenterPaneBase::PaintBorderBackground (
359 : const awt::Rectangle& rBorderBox,
360 : const awt::Rectangle& rUpdateBox)
361 : {
362 : (void)rBorderBox;
363 : (void)rUpdateBox;
364 : /*
365 : // The outer box of the border is given. We need the center and inner
366 : // box as well.
367 : awt::Rectangle aCenterBox (
368 : mxBorderPainter->removeBorder(
369 : mxPaneId->getResourceURL(),
370 : rBorderBox,
371 : drawing::framework::BorderType_OUTER_BORDER));
372 : awt::Rectangle aInnerBox (
373 : mxBorderPainter->removeBorder(
374 : mxPaneId->getResourceURL(),
375 : rBorderBox,
376 : drawing::framework::BorderType_TOTAL_BORDER));
377 : mpPresenterController->GetCanvasHelper()->Paint(
378 : mpViewBackground,
379 : mxBorderCanvas,
380 : rUpdateBox,
381 : aCenterBox,
382 : aInnerBox);
383 : */
384 0 : }
385 :
386 0 : void PresenterPaneBase::PaintBorder (const awt::Rectangle& rUpdateBox)
387 : {
388 : OSL_ASSERT(mxPaneId.is());
389 :
390 0 : if (mxBorderPainter.is() && mxBorderWindow.is() && mxBorderCanvas.is())
391 : {
392 0 : awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
393 0 : awt::Rectangle aLocalBorderBox (0,0, aBorderBox.Width, aBorderBox.Height);
394 :
395 0 : PaintBorderBackground(aLocalBorderBox, rUpdateBox);
396 :
397 0 : if (mbHasCallout)
398 0 : mxBorderPainter->paintBorderWithCallout(
399 0 : mxPaneId->getResourceURL(),
400 : mxBorderCanvas,
401 : aLocalBorderBox,
402 : rUpdateBox,
403 : msTitle,
404 0 : maCalloutAnchor);
405 : else
406 0 : mxBorderPainter->paintBorder(
407 0 : mxPaneId->getResourceURL(),
408 : mxBorderCanvas,
409 : aLocalBorderBox,
410 : rUpdateBox,
411 0 : msTitle);
412 : }
413 0 : }
414 :
415 0 : void PresenterPaneBase::LayoutContextWindow (void)
416 : {
417 : OSL_ASSERT(mxPaneId.is());
418 : OSL_ASSERT(mxBorderWindow.is());
419 : OSL_ASSERT(mxContentWindow.is());
420 0 : if (mxBorderPainter.is() && mxPaneId.is() && mxBorderWindow.is() && mxContentWindow.is())
421 : {
422 0 : const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
423 0 : const awt::Rectangle aInnerBox (mxBorderPainter->removeBorder(
424 0 : mxPaneId->getResourceURL(),
425 : aBorderBox,
426 0 : drawing::framework::BorderType_TOTAL_BORDER));
427 0 : mxContentWindow->setPosSize(
428 : aInnerBox.X - aBorderBox.X,
429 : aInnerBox.Y - aBorderBox.Y,
430 : aInnerBox.Width,
431 : aInnerBox.Height,
432 0 : awt::PosSize::POSSIZE);
433 : }
434 0 : }
435 :
436 0 : bool PresenterPaneBase::IsVisible (void) const
437 : {
438 0 : Reference<awt::XWindow2> xWindow2 (mxBorderPainter, UNO_QUERY);
439 0 : if (xWindow2.is())
440 0 : return xWindow2->isVisible();
441 :
442 0 : return false;
443 : }
444 :
445 0 : void PresenterPaneBase::ThrowIfDisposed (void)
446 : throw (::com::sun::star::lang::DisposedException)
447 : {
448 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
449 : {
450 : throw lang::DisposedException (
451 : ::rtl::OUString( "PresenterPane object has already been disposed"),
452 0 : static_cast<uno::XWeak*>(this));
453 : }
454 0 : }
455 :
456 : } } // end of namespace ::sd::presenter
457 :
458 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|