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: PresenterPaneContainer.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 "PresenterPaneContainer.hxx"
36 #include "PresenterPaneBase.hxx"
37 #include <com/sun/star/awt/XGraphics.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/container/XChild.hpp>
40 #include <com/sun/star/drawing/framework/ResourceId.hpp>
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::drawing::framework
;
46 using ::rtl::OUString
;
48 namespace sdext
{ namespace presenter
{
50 PresenterPaneContainer::PresenterPaneContainer (
51 const Reference
<XComponentContext
>& rxContext
)
52 : PresenterPaneContainerInterfaceBase(m_aMutex
),
56 Reference
<lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager());
59 mxPresenterHelper
= Reference
<drawing::XPresenterHelper
>(
60 xFactory
->createInstanceWithContext(
61 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
70 PresenterPaneContainer::~PresenterPaneContainer (void)
77 void PresenterPaneContainer::PreparePane (
78 const Reference
<XResourceId
>& rxPaneId
,
79 const OUString
& rsViewURL
,
80 const OUString
& rsTitle
,
81 const OUString
& rsAccessibleTitle
,
83 const ViewInitializationFunction
& rViewInitialization
,
92 SharedPaneDescriptor
pPane (FindPaneURL(rxPaneId
->getResourceURL()));
93 if (pPane
.get() == NULL
)
95 // No entry found for the given pane id. Create a new one.
96 SharedPaneDescriptor
pDescriptor (new PaneDescriptor());
97 pDescriptor
->mxPaneId
= rxPaneId
;
98 pDescriptor
->msViewURL
= rsViewURL
;
99 pDescriptor
->mxPane
= NULL
;
100 if (rsTitle
.indexOf('%') < 0)
102 pDescriptor
->msTitle
= rsTitle
;
103 pDescriptor
->msTitleTemplate
= OUString();
107 pDescriptor
->msTitleTemplate
= rsTitle
;
108 pDescriptor
->msTitle
= OUString();
110 pDescriptor
->msAccessibleTitleTemplate
= rsAccessibleTitle
;
111 pDescriptor
->maViewInitialization
= rViewInitialization
;
112 pDescriptor
->mnLeft
= nLeft
;
113 pDescriptor
->mnTop
= nTop
;
114 pDescriptor
->mnRight
= nRight
;
115 pDescriptor
->mnBottom
= nBottom
;
116 pDescriptor
->mbIsActive
= true;
117 pDescriptor
->mbIsOpaque
= bIsOpaque
;
118 pDescriptor
->maSpriteProvider
= PaneDescriptor::SpriteProvider();
119 pDescriptor
->mbIsSprite
= false;
120 pDescriptor
->maCalloutAnchorLocation
= awt::Point(-1,-1);
121 pDescriptor
->mbHasCalloutAnchor
= false;
123 maPanes
.push_back(pDescriptor
);
130 void SAL_CALL
PresenterPaneContainer::disposing (void)
132 PaneList::iterator
iPane (maPanes
.begin());
133 PaneList::const_iterator
iEnd (maPanes
.end());
134 for ( ; iPane
!=iEnd
; ++iPane
)
135 if ((*iPane
)->mxPaneId
.is())
136 RemovePane((*iPane
)->mxPaneId
);
142 PresenterPaneContainer::SharedPaneDescriptor
143 PresenterPaneContainer::StorePane (const rtl::Reference
<PresenterPaneBase
>& rxPane
)
145 SharedPaneDescriptor pDescriptor
;
150 Reference
<XResourceId
> xPaneId (rxPane
->getResourceId());
152 sPaneURL
= xPaneId
->getResourceURL();
154 pDescriptor
= FindPaneURL(sPaneURL
);
155 if (pDescriptor
.get() == NULL
)
156 PreparePane(xPaneId
, OUString(), OUString(), OUString(),
157 false, ViewInitializationFunction(), 0,0,0,0);
158 pDescriptor
= FindPaneURL(sPaneURL
);
159 if (pDescriptor
.get() != NULL
)
161 Reference
<awt::XWindow
> xWindow (rxPane
->getWindow());
162 pDescriptor
->mxContentWindow
= xWindow
;
163 pDescriptor
->mxPaneId
= xPaneId
;
164 pDescriptor
->mxPane
= rxPane
;
165 pDescriptor
->mxPane
->SetTitle(pDescriptor
->msTitle
);
167 // When there is a call out anchor location set then tell the
169 if (pDescriptor
->mbHasCalloutAnchor
)
170 pDescriptor
->mxPane
->SetCalloutAnchor(pDescriptor
->maCalloutAnchorLocation
);
173 xWindow
->addEventListener(this);
183 PresenterPaneContainer::SharedPaneDescriptor
184 PresenterPaneContainer::StoreBorderWindow(
185 const Reference
<XResourceId
>& rxPaneId
,
186 const Reference
<awt::XWindow
>& rxBorderWindow
)
188 // The content window may not be present. Use the resource URL of the
192 sPaneURL
= rxPaneId
->getResourceURL();
194 SharedPaneDescriptor
pDescriptor (FindPaneURL(sPaneURL
));
195 if (pDescriptor
.get() != NULL
)
197 pDescriptor
->mxBorderWindow
= rxBorderWindow
;
201 return SharedPaneDescriptor();
207 PresenterPaneContainer::SharedPaneDescriptor
208 PresenterPaneContainer::StoreView (
209 const Reference
<XView
>& rxView
,
210 const SharedBitmapDescriptor
& rpViewBackground
)
212 SharedPaneDescriptor pDescriptor
;
217 Reference
<XResourceId
> xViewId (rxView
->getResourceId());
220 Reference
<XResourceId
> xPaneId (xViewId
->getAnchor());
222 sPaneURL
= xPaneId
->getResourceURL();
225 pDescriptor
= FindPaneURL(sPaneURL
);
226 if (pDescriptor
.get() != NULL
)
228 pDescriptor
->mxView
= rxView
;
229 pDescriptor
->mpViewBackground
= rpViewBackground
;
230 pDescriptor
->mxPane
->SetBackground(rpViewBackground
);
233 if ( ! pDescriptor
->maViewInitialization
.empty())
234 pDescriptor
->maViewInitialization(rxView
);
236 // Activate or deactivate the pane/view.
237 if ( ! pDescriptor
->maActivator
.empty())
238 pDescriptor
->maActivator(pDescriptor
->mbIsActive
);
240 catch (RuntimeException
&)
253 PresenterPaneContainer::SharedPaneDescriptor
254 PresenterPaneContainer::RemovePane (const Reference
<XResourceId
>& rxPaneId
)
256 SharedPaneDescriptor
pDescriptor (FindPaneId(rxPaneId
));
257 if (pDescriptor
.get() != NULL
)
259 if (pDescriptor
->mxContentWindow
.is())
260 pDescriptor
->mxContentWindow
->removeEventListener(this);
261 pDescriptor
->mxContentWindow
= NULL
;
262 pDescriptor
->mxBorderWindow
= NULL
;
263 pDescriptor
->mxPane
= NULL
;
264 pDescriptor
->mxView
= NULL
;
265 pDescriptor
->mbIsActive
= false;
274 PresenterPaneContainer::SharedPaneDescriptor
275 PresenterPaneContainer::RemoveView (const Reference
<XView
>& rxView
)
277 SharedPaneDescriptor pDescriptor
;
282 Reference
<XResourceId
> xViewId (rxView
->getResourceId());
285 Reference
<XResourceId
> xPaneId (xViewId
->getAnchor());
287 sPaneURL
= xPaneId
->getResourceURL();
290 pDescriptor
= FindPaneURL(sPaneURL
);
291 if (pDescriptor
.get() != NULL
)
293 pDescriptor
->mxView
= NULL
;
294 pDescriptor
->mpViewBackground
= SharedBitmapDescriptor();
304 PresenterPaneContainer::SharedPaneDescriptor
PresenterPaneContainer::FindBorderWindow (
305 const Reference
<awt::XWindow
>& rxBorderWindow
)
307 PaneList::const_iterator iPane
;
308 PaneList::iterator
iEnd (maPanes
.end());
309 for (iPane
=maPanes
.begin(); iPane
!=iEnd
; ++iPane
)
311 if ((*iPane
)->mxBorderWindow
== rxBorderWindow
)
314 return SharedPaneDescriptor();
320 PresenterPaneContainer::SharedPaneDescriptor
PresenterPaneContainer::FindContentWindow (
321 const Reference
<awt::XWindow
>& rxContentWindow
)
323 PaneList::const_iterator iPane
;
324 PaneList::iterator
iEnd (maPanes
.end());
325 for (iPane
=maPanes
.begin(); iPane
!=iEnd
; ++iPane
)
327 if ((*iPane
)->mxContentWindow
== rxContentWindow
)
330 return SharedPaneDescriptor();
336 PresenterPaneContainer::SharedPaneDescriptor
PresenterPaneContainer::FindPaneURL (
337 const OUString
& rsPaneURL
)
339 PaneList::const_iterator iPane
;
340 PaneList::const_iterator
iEnd (maPanes
.end());
341 for (iPane
=maPanes
.begin(); iPane
!=iEnd
; ++iPane
)
343 if ((*iPane
)->mxPaneId
->getResourceURL() == rsPaneURL
)
346 return SharedPaneDescriptor();
352 PresenterPaneContainer::SharedPaneDescriptor
PresenterPaneContainer::FindPaneId (
353 const Reference
<XResourceId
>& rxPaneId
)
355 PaneList::iterator
iEnd (maPanes
.end());
357 if ( ! rxPaneId
.is())
358 return SharedPaneDescriptor();
360 PaneList::iterator iPane
;
361 for (iPane
=maPanes
.begin(); iPane
!=iEnd
; ++iPane
)
363 if (rxPaneId
->compareTo((*iPane
)->mxPaneId
) == 0)
366 return SharedPaneDescriptor();
372 PresenterPaneContainer::SharedPaneDescriptor
PresenterPaneContainer::FindViewURL (
373 const OUString
& rsViewURL
)
375 PaneList::iterator
iEnd (maPanes
.end());
376 PaneList::iterator iPane
;
377 for (iPane
=maPanes
.begin(); iPane
!=iEnd
; ++iPane
)
379 if (rsViewURL
== (*iPane
)->msViewURL
)
382 return SharedPaneDescriptor();
388 ::rtl::OUString
PresenterPaneContainer::GetPaneURLForViewURL (const ::rtl::OUString
& rsViewURL
)
390 SharedPaneDescriptor
pDescriptor (FindViewURL(rsViewURL
));
391 if (pDescriptor
.get() != NULL
)
392 if (pDescriptor
->mxPaneId
.is())
393 return pDescriptor
->mxPaneId
->getResourceURL();
400 void PresenterPaneContainer::ToTop (const SharedPaneDescriptor
& rpDescriptor
)
402 if (rpDescriptor
.get() != NULL
)
404 // Find iterator for pDescriptor.
405 PaneList::iterator iPane
;
406 PaneList::iterator
iEnd (maPanes
.end());
407 for (iPane
=maPanes
.begin(); iPane
!=iEnd
; ++iPane
)
408 if (iPane
->get() == rpDescriptor
.get())
410 OSL_ASSERT(iPane
!=iEnd
);
414 if (mxPresenterHelper
.is())
415 mxPresenterHelper
->toTop(rpDescriptor
->mxBorderWindow
);
417 maPanes
.erase(iPane
);
418 maPanes
.push_back(rpDescriptor
);
425 //----- XEventListener --------------------------------------------------------
427 void SAL_CALL
PresenterPaneContainer::disposing (
428 const com::sun::star::lang::EventObject
& rEvent
)
429 throw (com::sun::star::uno::RuntimeException
)
431 SharedPaneDescriptor
pDescriptor (
432 FindContentWindow(Reference
<awt::XWindow
>(rEvent
.Source
, UNO_QUERY
)));
433 if (pDescriptor
.get() != NULL
)
435 RemovePane(pDescriptor
->mxPaneId
);
442 //===== PresenterPaneContainer::PaneDescriptor ================================
444 void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive
)
446 mbIsActive
= bIsActive
;
447 if ( ! maActivator
.empty())
448 maActivator(mbIsActive
);
451 } } // end of namespace ::sdext::presenter