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