merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / presenter / PresenterPaneBase.cxx
blob5dec5630f0dd88b2897d658ec95769f0f1257c7f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterPaneBase.cxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterPaneBase.hxx"
36 #include "PresenterCanvasHelper.hxx"
37 #include "PresenterController.hxx"
38 #include "PresenterGeometryHelper.hxx"
39 #include "PresenterPaintManager.hxx"
40 #include "PresenterTextView.hxx"
41 #include <com/sun/star/awt/PosSize.hpp>
42 #include <com/sun/star/awt/XWindow2.hpp>
43 #include <com/sun/star/awt/XWindowPeer.hpp>
44 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
45 #include <com/sun/star/drawing/CanvasFeature.hpp>
46 #include <com/sun/star/rendering/CompositeOperation.hpp>
47 #include <com/sun/star/rendering/TexturingMode.hpp>
48 #include <osl/mutex.hxx>
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::drawing::framework;
53 using ::rtl::OUString;
55 namespace sdext { namespace presenter {
57 //===== PresenterPaneBase =====================================================
59 PresenterPaneBase::PresenterPaneBase (
60 const Reference<XComponentContext>& rxContext,
61 const ::rtl::Reference<PresenterController>& rpPresenterController)
62 : PresenterPaneBaseInterfaceBase(m_aMutex),
63 mpPresenterController(rpPresenterController),
64 mxParentWindow(),
65 mxBorderWindow(),
66 mxBorderCanvas(),
67 mxContentWindow(),
68 mxContentCanvas(),
69 mxPaneId(),
70 mxBorderPainter(),
71 mxPresenterHelper(),
72 msTitle(),
73 mxComponentContext(rxContext),
74 mpViewBackground(),
75 mbHasCallout(false),
76 maCalloutAnchor()
78 if (mpPresenterController.get() != NULL)
79 mxPresenterHelper = mpPresenterController->GetPresenterHelper();
85 PresenterPaneBase::~PresenterPaneBase (void)
92 void PresenterPaneBase::disposing (void)
94 if (mxBorderWindow.is())
96 mxBorderWindow->removeWindowListener(this);
97 mxBorderWindow->removePaintListener(this);
101 Reference<XComponent> xComponent (mxContentCanvas, UNO_QUERY);
102 mxContentCanvas = NULL;
103 if (xComponent.is())
104 xComponent->dispose();
108 Reference<XComponent> xComponent (mxContentWindow, UNO_QUERY);
109 mxContentWindow = NULL;
110 if (xComponent.is())
111 xComponent->dispose();
115 Reference<XComponent> xComponent (mxBorderCanvas, UNO_QUERY);
116 mxBorderCanvas = NULL;
117 if (xComponent.is())
118 xComponent->dispose();
122 Reference<XComponent> xComponent (mxBorderWindow, UNO_QUERY);
123 mxBorderWindow = NULL;
124 if (xComponent.is())
125 xComponent->dispose();
128 mxComponentContext = NULL;
134 void PresenterPaneBase::SetTitle (const OUString& rsTitle)
136 msTitle = rsTitle;
138 OSL_ASSERT(mpPresenterController.get()!=NULL);
139 OSL_ASSERT(mpPresenterController->GetPaintManager().get()!=NULL);
141 mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
147 ::rtl::OUString PresenterPaneBase::GetTitle (void) const
149 return msTitle;
155 Reference<drawing::framework::XPaneBorderPainter>
156 PresenterPaneBase::GetPaneBorderPainter (void) const
158 return mxBorderPainter;
164 void PresenterPaneBase::SetCalloutAnchor (const css::awt::Point& rCalloutAnchor)
166 mbHasCallout = true;
167 // Anchor is given in the coorindate system of the parent window.
168 // Transform it into the local coordinate system.
169 maCalloutAnchor = rCalloutAnchor;
170 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
171 maCalloutAnchor.X -= aBorderBox.X;
172 maCalloutAnchor.Y -= aBorderBox.Y;
174 // Move the bottom of the border window so that it goes through the
175 // callout anchor (special case for bottom callout).
176 sal_Int32 nHeight (rCalloutAnchor.Y - aBorderBox.Y);
177 if (mxBorderPainter.is() && mxPaneId.is())
178 nHeight += mxBorderPainter->getCalloutOffset(mxPaneId->getResourceURL()).Y;
180 if (nHeight != aBorderBox.Height)
182 mxBorderWindow->setPosSize(
183 aBorderBox.X,
184 aBorderBox.Y,
185 aBorderBox.Width,
186 nHeight,
187 awt::PosSize::HEIGHT);
190 mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
196 awt::Point PresenterPaneBase::GetCalloutAnchor (void) const
198 return maCalloutAnchor;
204 ::boost::shared_ptr<PresenterTextView> PresenterPaneBase::GetTextViewForTitle (void)
206 ::boost::shared_ptr<PresenterTextView> pTextView(
207 new PresenterTextView(
208 mxComponentContext,
209 mxBorderCanvas));
210 pTextView->SetText(msTitle);
211 return pTextView;
217 //----- XInitialization -------------------------------------------------------
219 void SAL_CALL PresenterPaneBase::initialize (const Sequence<Any>& rArguments)
220 throw (Exception, RuntimeException)
222 ThrowIfDisposed();
224 if ( ! mxComponentContext.is())
226 throw RuntimeException(
227 OUString::createFromAscii("PresenterSpritePane: missing component context"),
228 static_cast<XWeak*>(this));
231 if (rArguments.getLength() == 5 || rArguments.getLength() == 6)
235 // Get the resource id from the first argument.
236 if ( ! (rArguments[0] >>= mxPaneId))
238 throw lang::IllegalArgumentException(
239 OUString::createFromAscii("PresenterPane: invalid pane id"),
240 static_cast<XWeak*>(this),
244 if ( ! (rArguments[1] >>= mxParentWindow))
246 throw lang::IllegalArgumentException(
247 OUString::createFromAscii("PresenterPane: invalid parent window"),
248 static_cast<XWeak*>(this),
252 Reference<rendering::XSpriteCanvas> xParentCanvas;
253 if ( ! (rArguments[2] >>= xParentCanvas))
255 throw lang::IllegalArgumentException(
256 OUString::createFromAscii("PresenterPane: invalid parent canvas"),
257 static_cast<XWeak*>(this),
261 if ( ! (rArguments[3] >>= msTitle))
263 throw lang::IllegalArgumentException(
264 OUString::createFromAscii("PresenterPane: invalid title"),
265 static_cast<XWeak*>(this),
269 if ( ! (rArguments[4] >>= mxBorderPainter))
271 throw lang::IllegalArgumentException(
272 OUString::createFromAscii("PresenterPane: invalid border painter"),
273 static_cast<XWeak*>(this),
277 bool bIsWindowVisibleOnCreation (true);
278 if (rArguments.getLength()>5 && ! (rArguments[5] >>= bIsWindowVisibleOnCreation))
280 throw lang::IllegalArgumentException(
281 OUString::createFromAscii("PresenterPane: invalid window visibility flag"),
282 static_cast<XWeak*>(this),
286 CreateWindows(mxParentWindow, bIsWindowVisibleOnCreation);
288 if (mxBorderWindow.is())
290 mxBorderWindow->addWindowListener(this);
291 mxBorderWindow->addPaintListener(this);
294 CreateCanvases(mxParentWindow, xParentCanvas);
296 // Raise new windows.
297 ToTop();
299 catch (Exception&)
301 mxContentWindow = NULL;
302 mxComponentContext = NULL;
303 throw;
306 else
308 throw RuntimeException(
309 OUString::createFromAscii("PresenterSpritePane: invalid number of arguments"),
310 static_cast<XWeak*>(this));
317 //----- XResourceId -----------------------------------------------------------
319 Reference<XResourceId> SAL_CALL PresenterPaneBase::getResourceId (void)
320 throw (RuntimeException)
322 ThrowIfDisposed();
323 return mxPaneId;
329 sal_Bool SAL_CALL PresenterPaneBase::isAnchorOnly (void)
330 throw (RuntimeException)
332 return true;
338 //----- XWindowListener -------------------------------------------------------
340 void SAL_CALL PresenterPaneBase::windowResized (const awt::WindowEvent& rEvent)
341 throw (RuntimeException)
343 (void)rEvent;
344 ThrowIfDisposed();
351 void SAL_CALL PresenterPaneBase::windowMoved (const awt::WindowEvent& rEvent)
352 throw (RuntimeException)
354 (void)rEvent;
355 ThrowIfDisposed();
361 void SAL_CALL PresenterPaneBase::windowShown (const lang::EventObject& rEvent)
362 throw (RuntimeException)
364 (void)rEvent;
365 ThrowIfDisposed();
371 void SAL_CALL PresenterPaneBase::windowHidden (const lang::EventObject& rEvent)
372 throw (RuntimeException)
374 (void)rEvent;
375 ThrowIfDisposed();
381 //----- lang::XEventListener --------------------------------------------------
383 void SAL_CALL PresenterPaneBase::disposing (const lang::EventObject& rEvent)
384 throw (RuntimeException)
386 if (rEvent.Source == mxBorderWindow)
388 mxBorderWindow = NULL;
395 //-----------------------------------------------------------------------------
398 void PresenterPaneBase::CreateWindows (
399 const Reference<awt::XWindow>& rxParentWindow,
400 const bool bIsWindowVisibleOnCreation)
402 if (mxPresenterHelper.is() && rxParentWindow.is())
405 mxBorderWindow = mxPresenterHelper->createWindow(
406 rxParentWindow,
407 sal_False,
408 bIsWindowVisibleOnCreation,
409 sal_False,
410 sal_False);
411 mxContentWindow = mxPresenterHelper->createWindow(
412 mxBorderWindow,
413 sal_False,
414 bIsWindowVisibleOnCreation,
415 sal_False,
416 sal_False);
423 Reference<awt::XWindow> PresenterPaneBase::GetBorderWindow (void) const
425 return mxBorderWindow;
431 void PresenterPaneBase::ToTop (void)
433 if (mxPresenterHelper.is())
434 mxPresenterHelper->toTop(mxContentWindow);
440 void PresenterPaneBase::SetBackground (const SharedBitmapDescriptor& rpBackground)
442 mpViewBackground = rpBackground;
448 void PresenterPaneBase::PaintBorderBackground (
449 const awt::Rectangle& rBorderBox,
450 const awt::Rectangle& rUpdateBox)
452 (void)rBorderBox;
453 (void)rUpdateBox;
455 // The outer box of the border is given. We need the center and inner
456 // box as well.
457 awt::Rectangle aCenterBox (
458 mxBorderPainter->removeBorder(
459 mxPaneId->getResourceURL(),
460 rBorderBox,
461 drawing::framework::BorderType_OUTER_BORDER));
462 awt::Rectangle aInnerBox (
463 mxBorderPainter->removeBorder(
464 mxPaneId->getResourceURL(),
465 rBorderBox,
466 drawing::framework::BorderType_TOTAL_BORDER));
467 mpPresenterController->GetCanvasHelper()->Paint(
468 mpViewBackground,
469 mxBorderCanvas,
470 rUpdateBox,
471 aCenterBox,
472 aInnerBox);
479 void PresenterPaneBase::PaintBorder (const awt::Rectangle& rUpdateBox)
481 OSL_ASSERT(mxPaneId.is());
483 if (mxBorderPainter.is() && mxBorderWindow.is() && mxBorderCanvas.is())
485 awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
486 awt::Rectangle aLocalBorderBox (0,0, aBorderBox.Width, aBorderBox.Height);
488 PaintBorderBackground(aLocalBorderBox, rUpdateBox);
490 if (mbHasCallout)
491 mxBorderPainter->paintBorderWithCallout(
492 mxPaneId->getResourceURL(),
493 mxBorderCanvas,
494 aLocalBorderBox,
495 rUpdateBox,
496 msTitle,
497 maCalloutAnchor);
498 else
499 mxBorderPainter->paintBorder(
500 mxPaneId->getResourceURL(),
501 mxBorderCanvas,
502 aLocalBorderBox,
503 rUpdateBox,
504 msTitle);
511 void PresenterPaneBase::LayoutContextWindow (void)
513 OSL_ASSERT(mxPaneId.is());
514 OSL_ASSERT(mxBorderWindow.is());
515 OSL_ASSERT(mxContentWindow.is());
516 if (mxBorderPainter.is() && mxPaneId.is() && mxBorderWindow.is() && mxContentWindow.is())
518 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
519 const awt::Rectangle aInnerBox (mxBorderPainter->removeBorder(
520 mxPaneId->getResourceURL(),
521 aBorderBox,
522 drawing::framework::BorderType_TOTAL_BORDER));
523 mxContentWindow->setPosSize(
524 aInnerBox.X - aBorderBox.X,
525 aInnerBox.Y - aBorderBox.Y,
526 aInnerBox.Width,
527 aInnerBox.Height,
528 awt::PosSize::POSSIZE);
535 bool PresenterPaneBase::IsVisible (void) const
537 Reference<awt::XWindow2> xWindow2 (mxBorderPainter, UNO_QUERY);
538 if (xWindow2.is())
539 return xWindow2->isVisible();
541 return false;
547 void PresenterPaneBase::ThrowIfDisposed (void)
548 throw (::com::sun::star::lang::DisposedException)
550 if (rBHelper.bDisposed || rBHelper.bInDispose)
552 throw lang::DisposedException (
553 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
554 "PresenterPane object has already been disposed")),
555 static_cast<uno::XWeak*>(this));
562 } } // end of namespace ::sd::presenter