1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterPaneBase.cxx,v $
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 <com/sun/star/awt/PosSize.hpp>
41 #include <com/sun/star/awt/XWindow2.hpp>
42 #include <com/sun/star/awt/XWindowPeer.hpp>
43 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
44 #include <com/sun/star/drawing/CanvasFeature.hpp>
45 #include <com/sun/star/rendering/CompositeOperation.hpp>
46 #include <com/sun/star/rendering/TexturingMode.hpp>
47 #include <osl/mutex.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::drawing::framework
;
52 using ::rtl::OUString
;
54 namespace sdext
{ namespace presenter
{
56 //===== PresenterPaneBase =====================================================
58 PresenterPaneBase::PresenterPaneBase (
59 const Reference
<XComponentContext
>& rxContext
,
60 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
61 : PresenterPaneBaseInterfaceBase(m_aMutex
),
62 mpPresenterController(rpPresenterController
),
72 mxComponentContext(rxContext
),
77 if (mpPresenterController
.get() != NULL
)
78 mxPresenterHelper
= mpPresenterController
->GetPresenterHelper();
84 PresenterPaneBase::~PresenterPaneBase (void)
91 void PresenterPaneBase::disposing (void)
93 if (mxBorderWindow
.is())
95 mxBorderWindow
->removeWindowListener(this);
96 mxBorderWindow
->removePaintListener(this);
100 Reference
<XComponent
> xComponent (mxContentCanvas
, UNO_QUERY
);
101 mxContentCanvas
= NULL
;
103 xComponent
->dispose();
107 Reference
<XComponent
> xComponent (mxContentWindow
, UNO_QUERY
);
108 mxContentWindow
= NULL
;
110 xComponent
->dispose();
114 Reference
<XComponent
> xComponent (mxBorderCanvas
, UNO_QUERY
);
115 mxBorderCanvas
= NULL
;
117 xComponent
->dispose();
121 Reference
<XComponent
> xComponent (mxBorderWindow
, UNO_QUERY
);
122 mxBorderWindow
= NULL
;
124 xComponent
->dispose();
127 mxComponentContext
= NULL
;
133 void PresenterPaneBase::SetTitle (const OUString
& rsTitle
)
137 OSL_ASSERT(mpPresenterController
.get()!=NULL
);
138 OSL_ASSERT(mpPresenterController
->GetPaintManager().get()!=NULL
);
140 mpPresenterController
->GetPaintManager()->Invalidate(mxBorderWindow
);
146 Reference
<drawing::framework::XPaneBorderPainter
>
147 PresenterPaneBase::GetPaneBorderPainter (void) const
149 return mxBorderPainter
;
155 void PresenterPaneBase::SetCalloutAnchor (const css::awt::Point
& rCalloutAnchor
)
158 // Anchor is given in the coorindate system of the parent window.
159 // Transform it into the local coordinate system.
160 maCalloutAnchor
= rCalloutAnchor
;
161 const awt::Rectangle
aBorderBox (mxBorderWindow
->getPosSize());
162 maCalloutAnchor
.X
-= aBorderBox
.X
;
163 maCalloutAnchor
.Y
-= aBorderBox
.Y
;
165 // Move the bottom of the border window so that it goes through the
166 // callout anchor (special case for bottom callout).
167 sal_Int32
nHeight (rCalloutAnchor
.Y
- aBorderBox
.Y
);
168 if (mxBorderPainter
.is() && mxPaneId
.is())
169 nHeight
+= mxBorderPainter
->getCalloutOffset(mxPaneId
->getResourceURL()).Y
;
171 if (nHeight
!= aBorderBox
.Height
)
173 mxBorderWindow
->setPosSize(
178 awt::PosSize::HEIGHT
);
181 mpPresenterController
->GetPaintManager()->Invalidate(mxBorderWindow
);
187 awt::Point
PresenterPaneBase::GetCalloutAnchor (void) const
189 return maCalloutAnchor
;
195 //----- XInitialization -------------------------------------------------------
197 void SAL_CALL
PresenterPaneBase::initialize (const Sequence
<Any
>& rArguments
)
198 throw (Exception
, RuntimeException
)
202 if ( ! mxComponentContext
.is())
204 throw RuntimeException(
205 OUString::createFromAscii("PresenterSpritePane: missing component context"),
206 static_cast<XWeak
*>(this));
209 if (rArguments
.getLength() == 5 || rArguments
.getLength() == 6)
213 // Get the resource id from the first argument.
214 if ( ! (rArguments
[0] >>= mxPaneId
))
216 throw lang::IllegalArgumentException(
217 OUString::createFromAscii("PresenterPane: invalid pane id"),
218 static_cast<XWeak
*>(this),
222 if ( ! (rArguments
[1] >>= mxParentWindow
))
224 throw lang::IllegalArgumentException(
225 OUString::createFromAscii("PresenterPane: invalid parent window"),
226 static_cast<XWeak
*>(this),
230 Reference
<rendering::XSpriteCanvas
> xParentCanvas
;
231 if ( ! (rArguments
[2] >>= xParentCanvas
))
233 throw lang::IllegalArgumentException(
234 OUString::createFromAscii("PresenterPane: invalid parent canvas"),
235 static_cast<XWeak
*>(this),
239 if ( ! (rArguments
[3] >>= msTitle
))
241 throw lang::IllegalArgumentException(
242 OUString::createFromAscii("PresenterPane: invalid title"),
243 static_cast<XWeak
*>(this),
247 if ( ! (rArguments
[4] >>= mxBorderPainter
))
249 throw lang::IllegalArgumentException(
250 OUString::createFromAscii("PresenterPane: invalid border painter"),
251 static_cast<XWeak
*>(this),
255 bool bIsWindowVisibleOnCreation (true);
256 if (rArguments
.getLength()>5 && ! (rArguments
[5] >>= bIsWindowVisibleOnCreation
))
258 throw lang::IllegalArgumentException(
259 OUString::createFromAscii("PresenterPane: invalid window visibility flag"),
260 static_cast<XWeak
*>(this),
264 CreateWindows(mxParentWindow
, bIsWindowVisibleOnCreation
);
266 if (mxBorderWindow
.is())
268 mxBorderWindow
->addWindowListener(this);
269 mxBorderWindow
->addPaintListener(this);
272 CreateCanvases(mxParentWindow
, xParentCanvas
);
274 // Raise new windows.
279 mxContentWindow
= NULL
;
280 mxComponentContext
= NULL
;
286 throw RuntimeException(
287 OUString::createFromAscii("PresenterSpritePane: invalid number of arguments"),
288 static_cast<XWeak
*>(this));
295 //----- XResourceId -----------------------------------------------------------
297 Reference
<XResourceId
> SAL_CALL
PresenterPaneBase::getResourceId (void)
298 throw (RuntimeException
)
307 sal_Bool SAL_CALL
PresenterPaneBase::isAnchorOnly (void)
308 throw (RuntimeException
)
316 //----- XWindowListener -------------------------------------------------------
318 void SAL_CALL
PresenterPaneBase::windowResized (const awt::WindowEvent
& rEvent
)
319 throw (RuntimeException
)
329 void SAL_CALL
PresenterPaneBase::windowMoved (const awt::WindowEvent
& rEvent
)
330 throw (RuntimeException
)
339 void SAL_CALL
PresenterPaneBase::windowShown (const lang::EventObject
& rEvent
)
340 throw (RuntimeException
)
349 void SAL_CALL
PresenterPaneBase::windowHidden (const lang::EventObject
& rEvent
)
350 throw (RuntimeException
)
359 //----- lang::XEventListener --------------------------------------------------
361 void SAL_CALL
PresenterPaneBase::disposing (const lang::EventObject
& rEvent
)
362 throw (RuntimeException
)
364 if (rEvent
.Source
== mxBorderWindow
)
366 mxBorderWindow
= NULL
;
373 //-----------------------------------------------------------------------------
376 void PresenterPaneBase::CreateWindows (
377 const Reference
<awt::XWindow
>& rxParentWindow
,
378 const bool bIsWindowVisibleOnCreation
)
380 if (mxPresenterHelper
.is() && rxParentWindow
.is())
383 mxBorderWindow
= mxPresenterHelper
->createWindow(
386 bIsWindowVisibleOnCreation
,
389 mxContentWindow
= mxPresenterHelper
->createWindow(
392 bIsWindowVisibleOnCreation
,
401 Reference
<awt::XWindow
> PresenterPaneBase::GetBorderWindow (void) const
403 return mxBorderWindow
;
409 void PresenterPaneBase::ToTop (void)
411 if (mxPresenterHelper
.is())
412 mxPresenterHelper
->toTop(mxContentWindow
);
418 void PresenterPaneBase::SetBackground (const SharedBitmapDescriptor
& rpBackground
)
420 mpViewBackground
= rpBackground
;
426 void PresenterPaneBase::PaintBorderBackground (
427 const awt::Rectangle
& rBorderBox
,
428 const awt::Rectangle
& rUpdateBox
)
433 // The outer box of the border is given. We need the center and inner
435 awt::Rectangle aCenterBox (
436 mxBorderPainter->removeBorder(
437 mxPaneId->getResourceURL(),
439 drawing::framework::BorderType_OUTER_BORDER));
440 awt::Rectangle aInnerBox (
441 mxBorderPainter->removeBorder(
442 mxPaneId->getResourceURL(),
444 drawing::framework::BorderType_TOTAL_BORDER));
445 mpPresenterController->GetCanvasHelper()->Paint(
457 void PresenterPaneBase::PaintBorder (const awt::Rectangle
& rUpdateBox
)
459 OSL_ASSERT(mxPaneId
.is());
461 if (mxBorderPainter
.is() && mxBorderWindow
.is() && mxBorderCanvas
.is())
463 awt::Rectangle
aBorderBox (mxBorderWindow
->getPosSize());
464 awt::Rectangle
aLocalBorderBox (0,0, aBorderBox
.Width
, aBorderBox
.Height
);
466 PaintBorderBackground(aLocalBorderBox
, rUpdateBox
);
469 mxBorderPainter
->paintBorderWithCallout(
470 mxPaneId
->getResourceURL(),
477 mxBorderPainter
->paintBorder(
478 mxPaneId
->getResourceURL(),
489 void PresenterPaneBase::LayoutContextWindow (void)
491 OSL_ASSERT(mxPaneId
.is());
492 OSL_ASSERT(mxBorderWindow
.is());
493 OSL_ASSERT(mxContentWindow
.is());
494 if (mxBorderPainter
.is() && mxPaneId
.is() && mxBorderWindow
.is() && mxContentWindow
.is())
496 const awt::Rectangle
aBorderBox (mxBorderWindow
->getPosSize());
497 const awt::Rectangle
aInnerBox (mxBorderPainter
->removeBorder(
498 mxPaneId
->getResourceURL(),
500 drawing::framework::BorderType_TOTAL_BORDER
));
501 mxContentWindow
->setPosSize(
502 aInnerBox
.X
- aBorderBox
.X
,
503 aInnerBox
.Y
- aBorderBox
.Y
,
506 awt::PosSize::POSSIZE
);
513 bool PresenterPaneBase::IsVisible (void) const
515 Reference
<awt::XWindow2
> xWindow2 (mxBorderPainter
, UNO_QUERY
);
517 return xWindow2
->isVisible();
525 void PresenterPaneBase::ThrowIfDisposed (void)
526 throw (::com::sun::star::lang::DisposedException
)
528 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
530 throw lang::DisposedException (
531 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
532 "PresenterPane object has already been disposed")),
533 static_cast<uno::XWeak
*>(this));
540 } } // end of namespace ::sd::presenter