xref: /AOO41X/main/sd/source/ui/animations/CustomAnimationList.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectNodeType.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/animations/XIterateContainer.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectPresetClass.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectCommands.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/text/XTextRange.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
41*cdf0e10cSrcweir #include <svx/ShapeTypeHandler.hxx>
42*cdf0e10cSrcweir #include "CustomAnimationList.hxx"
43*cdf0e10cSrcweir #ifndef _SD_CUSTOMANIMATIONPANE_HRC
44*cdf0e10cSrcweir #include "CustomAnimationPane.hrc"
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #ifndef _SD_CUSTOMANIMATION_HRC
47*cdf0e10cSrcweir #include "CustomAnimation.hrc"
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #include "CustomAnimationPreset.hxx"
50*cdf0e10cSrcweir #include <svtools/treelist.hxx>
51*cdf0e10cSrcweir #include <vcl/svapp.hxx>
52*cdf0e10cSrcweir #include "sdresid.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include "res_bmp.hrc"
55*cdf0e10cSrcweir #include "glob.hrc"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <algorithm>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir using namespace ::com::sun::star;
60*cdf0e10cSrcweir using namespace ::com::sun::star::animations;
61*cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir using ::rtl::OUString;
64*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
65*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
66*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
67*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
68*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
69*cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
70*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
71*cdf0e10cSrcweir using ::com::sun::star::text::XTextRange;
72*cdf0e10cSrcweir using ::com::sun::star::drawing::XShape;
73*cdf0e10cSrcweir using ::com::sun::star::drawing::XShapes;
74*cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPage;
75*cdf0e10cSrcweir using ::com::sun::star::container::XChild;
76*cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess;
77*cdf0e10cSrcweir using ::com::sun::star::container::XEnumerationAccess;
78*cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration;
79*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
80*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo;
81*cdf0e10cSrcweir using ::accessibility::ShapeTypeHandler;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir namespace sd {
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir // go recursivly through all shapes in the given XShapes collection and return true as soon as the
86*cdf0e10cSrcweir // given shape is found. nIndex is incremented for each shape with the same shape type as the given
87*cdf0e10cSrcweir // shape is found until the given shape is found.
88*cdf0e10cSrcweir static bool getShapeIndex(  const Reference< XShapes >& xShapes, const Reference< XShape >& xShape, sal_Int32& nIndex )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	const sal_Int32 nCount = xShapes->getCount();
91*cdf0e10cSrcweir 	sal_Int32 n;
92*cdf0e10cSrcweir 	for( n = 0; n < nCount; n++ )
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		Reference< XShape > xChild;
95*cdf0e10cSrcweir 		xShapes->getByIndex( n ) >>= xChild;
96*cdf0e10cSrcweir 		if( xChild == xShape )
97*cdf0e10cSrcweir 			return true;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 		if( xChild->getShapeType() == xShape->getShapeType() )
100*cdf0e10cSrcweir 			nIndex++;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 		Reference< XShapes > xChildContainer( xChild, UNO_QUERY );
103*cdf0e10cSrcweir 		if( xChildContainer.is() )
104*cdf0e10cSrcweir 		{
105*cdf0e10cSrcweir 			if( getShapeIndex( xChildContainer, xShape, nIndex ) )
106*cdf0e10cSrcweir 				return true;
107*cdf0e10cSrcweir 		}
108*cdf0e10cSrcweir 	}
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	return false;
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir // returns the index of the shape type from the given shape
114*cdf0e10cSrcweir static sal_Int32 getShapeIndex( const Reference< XShape >& xShape )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	Reference< XChild > xChild( xShape, UNO_QUERY );
117*cdf0e10cSrcweir 	Reference< XShapes > xPage;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	while( xChild.is() && !xPage.is() )
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		Reference< XInterface > x( xChild->getParent() );
122*cdf0e10cSrcweir 		xChild = Reference< XChild >::query( x );
123*cdf0e10cSrcweir 		Reference< XDrawPage > xTestPage( x, UNO_QUERY );
124*cdf0e10cSrcweir 		if( xTestPage.is() )
125*cdf0e10cSrcweir 			xPage = Reference< XShapes >::query( x );
126*cdf0e10cSrcweir 	}
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	sal_Int32 nIndex = 1;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	if( xPage.is() && getShapeIndex( xPage, xShape, nIndex ) )
131*cdf0e10cSrcweir 		return nIndex;
132*cdf0e10cSrcweir 	else
133*cdf0e10cSrcweir 		return -1;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir OUString getShapeDescription( const Reference< XShape >& xShape, bool bWithText = true )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	OUString aDescription;
139*cdf0e10cSrcweir 	Reference< XPropertySet > xSet( xShape, UNO_QUERY );
140*cdf0e10cSrcweir 	if( xSet.is() )
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		Reference< XPropertySetInfo > xInfo( xSet->getPropertySetInfo() );
143*cdf0e10cSrcweir 		const OUString aPropName( RTL_CONSTASCII_USTRINGPARAM("UINameSingular") );
144*cdf0e10cSrcweir 		if( xInfo->hasPropertyByName( aPropName ) )
145*cdf0e10cSrcweir 			xSet->getPropertyValue( aPropName ) >>= aDescription;
146*cdf0e10cSrcweir 	}
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	aDescription += OUString( RTL_CONSTASCII_USTRINGPARAM(" "));
149*cdf0e10cSrcweir 	aDescription += OUString::valueOf( getShapeIndex( xShape ) );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	if( bWithText )
152*cdf0e10cSrcweir 	{
153*cdf0e10cSrcweir 		Reference< XTextRange > xText( xShape, UNO_QUERY );
154*cdf0e10cSrcweir 		if( xText.is() )
155*cdf0e10cSrcweir 		{
156*cdf0e10cSrcweir 			OUString aText( xText->getString() );
157*cdf0e10cSrcweir 			if( aText.getLength() )
158*cdf0e10cSrcweir 			{
159*cdf0e10cSrcweir 				aDescription += OUString(RTL_CONSTASCII_USTRINGPARAM(": "));
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 				aText = aText.replace( (sal_Unicode)'\n', (sal_Unicode)' ' );
162*cdf0e10cSrcweir 				aText = aText.replace( (sal_Unicode)'\r', (sal_Unicode)' ' );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 				aDescription += aText;
165*cdf0e10cSrcweir 			}
166*cdf0e10cSrcweir 		}
167*cdf0e10cSrcweir 	}
168*cdf0e10cSrcweir 	return aDescription;
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir static OUString getDescription( const Any& rTarget, bool bWithText = true )
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir 	OUString aDescription;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	if( rTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
176*cdf0e10cSrcweir 	{
177*cdf0e10cSrcweir 		ParagraphTarget aParaTarget;
178*cdf0e10cSrcweir 		rTarget >>= aParaTarget;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xText( aParaTarget.Shape, UNO_QUERY_THROW );
181*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xText->createEnumeration(), UNO_QUERY_THROW );
182*cdf0e10cSrcweir 		sal_Int32 nPara = aParaTarget.Paragraph;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() && nPara )
185*cdf0e10cSrcweir 		{
186*cdf0e10cSrcweir 			xEnumeration->nextElement();
187*cdf0e10cSrcweir 			nPara--;
188*cdf0e10cSrcweir 		}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 		DBG_ASSERT( xEnumeration->hasMoreElements(), "sd::CustomAnimationEffect::prepareText(), paragraph out of range!" );
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 		if( xEnumeration->hasMoreElements() )
193*cdf0e10cSrcweir 		{
194*cdf0e10cSrcweir 			Reference< XTextRange > xParagraph;
195*cdf0e10cSrcweir 			xEnumeration->nextElement() >>= xParagraph;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 			if( xParagraph.is() )
198*cdf0e10cSrcweir 				aDescription = xParagraph->getString();
199*cdf0e10cSrcweir 		}
200*cdf0e10cSrcweir 	}
201*cdf0e10cSrcweir 	else
202*cdf0e10cSrcweir 	{
203*cdf0e10cSrcweir 		Reference< XShape > xShape;
204*cdf0e10cSrcweir 		rTarget >>= xShape;
205*cdf0e10cSrcweir 		if( xShape.is() )
206*cdf0e10cSrcweir 			aDescription = getShapeDescription( xShape, bWithText );
207*cdf0e10cSrcweir 	}
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	return aDescription;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir // ====================================================================
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir class CustomAnimationListEntryItem : public SvLBoxString
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir public:
217*cdf0e10cSrcweir 					CustomAnimationListEntryItem( SvLBoxEntry*,sal_uInt16 nFlags, OUString aDescription, CustomAnimationEffectPtr pEffect, CustomAnimationList* pParent  );
218*cdf0e10cSrcweir 	virtual			~CustomAnimationListEntryItem();
219*cdf0e10cSrcweir 	void			InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
220*cdf0e10cSrcweir 	void			Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* );
221*cdf0e10cSrcweir 	SvLBoxItem* 	Create() const;
222*cdf0e10cSrcweir 	void 			Clone( SvLBoxItem* pSource );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir private:
225*cdf0e10cSrcweir 	CustomAnimationList* mpParent;
226*cdf0e10cSrcweir 	OUString		maDescription;
227*cdf0e10cSrcweir 	CustomAnimationEffectPtr mpEffect;
228*cdf0e10cSrcweir };
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir // --------------------------------------------------------------------
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir CustomAnimationListEntryItem::CustomAnimationListEntryItem( SvLBoxEntry* pEntry, sal_uInt16 nFlags, OUString aDescription, CustomAnimationEffectPtr pEffect, CustomAnimationList* pParent  )
233*cdf0e10cSrcweir : SvLBoxString( pEntry, nFlags, aDescription )
234*cdf0e10cSrcweir , mpParent( pParent )
235*cdf0e10cSrcweir , maDescription( aDescription )
236*cdf0e10cSrcweir , mpEffect(pEffect)
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir // --------------------------------------------------------------------
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir CustomAnimationListEntryItem::~CustomAnimationListEntryItem()
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir // --------------------------------------------------------------------
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir void CustomAnimationListEntryItem::InitViewData( SvLBox* pView, SvLBoxEntry* pEntry, SvViewDataItem* pViewData )
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir 	if( !pViewData )
251*cdf0e10cSrcweir 		pViewData = pView->GetViewDataItem( pEntry, this );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 	Size aSize(pView->GetTextWidth( maDescription ) + 2 * 19, pView->GetTextHeight() );
254*cdf0e10cSrcweir 	if( aSize.Height() < 19 )
255*cdf0e10cSrcweir 		aSize.Height() = 19;
256*cdf0e10cSrcweir 	pViewData->aSize = aSize;
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir // --------------------------------------------------------------------
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir void CustomAnimationListEntryItem::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16, SvLBoxEntry* pEntry )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir 	const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	SvViewDataItem* pViewData = mpParent->GetViewDataItem( pEntry, this );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 	Point aPos( rPos );
268*cdf0e10cSrcweir 	Size aSize( pViewData->aSize );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	sal_Int16 nNodeType = mpEffect->getNodeType();
271*cdf0e10cSrcweir 	if( nNodeType == EffectNodeType::ON_CLICK )
272*cdf0e10cSrcweir 	{
273*cdf0e10cSrcweir 		rDev.DrawImage( aPos, mpParent->getImage( IMG_CUSTOMANIMATION_ON_CLICK, bHighContrast ) );
274*cdf0e10cSrcweir 	}
275*cdf0e10cSrcweir 	else if( nNodeType == EffectNodeType::AFTER_PREVIOUS )
276*cdf0e10cSrcweir 	{
277*cdf0e10cSrcweir 		rDev.DrawImage( aPos, mpParent->getImage( IMG_CUSTOMANIMATION_AFTER_PREVIOUS, bHighContrast ) );
278*cdf0e10cSrcweir 	}
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	aPos.X() += 19;
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	sal_uInt16 nImage;
283*cdf0e10cSrcweir 	switch( mpEffect->getPresetClass() )
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 	case EffectPresetClass::ENTRANCE:	nImage = IMG_CUSTOMANIMATION_ENTRANCE_EFFECT; break;
286*cdf0e10cSrcweir 	case EffectPresetClass::EXIT:		nImage =  IMG_CUSTOMANIMATION_EXIT_EFFECT; break;
287*cdf0e10cSrcweir 	case EffectPresetClass::EMPHASIS:	nImage =  IMG_CUSTOMANIMATION_EMPHASIS_EFFECT; break;
288*cdf0e10cSrcweir 	case EffectPresetClass::MOTIONPATH: nImage = IMG_CUSTOMANIMATION_MOTION_PATH; break;
289*cdf0e10cSrcweir 	case EffectPresetClass::OLEACTION:	nImage = IMG_CUSTOMANIMATION_OLE; break;
290*cdf0e10cSrcweir 	case EffectPresetClass::MEDIACALL:
291*cdf0e10cSrcweir 		switch( mpEffect->getCommand() )
292*cdf0e10cSrcweir 		{
293*cdf0e10cSrcweir 		case EffectCommands::TOGGLEPAUSE:	nImage = IMG_CUSTOMANIMATION_MEDIA_PAUSE; break;
294*cdf0e10cSrcweir 		case EffectCommands::STOP:			nImage = IMG_CUSTOMANIMATION_MEDIA_STOP; break;
295*cdf0e10cSrcweir 		case EffectCommands::PLAY:
296*cdf0e10cSrcweir 		default:							nImage = IMG_CUSTOMANIMATION_MEDIA_PLAY; break;
297*cdf0e10cSrcweir 		}
298*cdf0e10cSrcweir 		break;
299*cdf0e10cSrcweir 	default:							nImage = 0xffff;
300*cdf0e10cSrcweir 	}
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 	if( nImage != 0xffff )
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir 		const Image& rImage = mpParent->getImage( nImage, bHighContrast );
305*cdf0e10cSrcweir 		Point aImagePos( aPos );
306*cdf0e10cSrcweir 		aImagePos.Y() += ( aSize.Height() - rImage.GetSizePixel().Height() ) >> 1;
307*cdf0e10cSrcweir 		rDev.DrawImage( aImagePos, rImage );
308*cdf0e10cSrcweir 	}
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 	aPos.X() += 19;
311*cdf0e10cSrcweir 	aPos.Y() += ( aSize.Height() - rDev.GetTextHeight()) >> 1;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     rDev.DrawText( aPos, rDev.GetEllipsisString( maDescription, rDev.GetOutputSizePixel().Width() - aPos.X() ) );
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir // --------------------------------------------------------------------
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir SvLBoxItem* CustomAnimationListEntryItem::Create() const
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir 	return NULL;
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir // --------------------------------------------------------------------
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir void CustomAnimationListEntryItem::Clone( SvLBoxItem* )
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir // ====================================================================
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir class CustomAnimationListEntry : public SvLBoxEntry
332*cdf0e10cSrcweir {
333*cdf0e10cSrcweir public:
334*cdf0e10cSrcweir 	CustomAnimationListEntry();
335*cdf0e10cSrcweir 	CustomAnimationListEntry( CustomAnimationEffectPtr pEffect );
336*cdf0e10cSrcweir 	virtual ~CustomAnimationListEntry();
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 	CustomAnimationEffectPtr getEffect() const { return mpEffect; }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir private:
341*cdf0e10cSrcweir 	CustomAnimationEffectPtr mpEffect;
342*cdf0e10cSrcweir };
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir // --------------------------------------------------------------------
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir CustomAnimationListEntry::CustomAnimationListEntry()
347*cdf0e10cSrcweir {
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir // --------------------------------------------------------------------
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir CustomAnimationListEntry::CustomAnimationListEntry( CustomAnimationEffectPtr pEffect )
353*cdf0e10cSrcweir : mpEffect( pEffect )
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir // --------------------------------------------------------------------
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir CustomAnimationListEntry::~CustomAnimationListEntry()
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir // ====================================================================
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir class CustomAnimationTriggerEntryItem : public SvLBoxString
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir public:
368*cdf0e10cSrcweir 					CustomAnimationTriggerEntryItem( SvLBoxEntry*,sal_uInt16 nFlags, OUString aDescription, CustomAnimationList* pParent  );
369*cdf0e10cSrcweir 	virtual			~CustomAnimationTriggerEntryItem();
370*cdf0e10cSrcweir 	virtual sal_uInt16	IsA();
371*cdf0e10cSrcweir 	void			InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
372*cdf0e10cSrcweir 	void			Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* );
373*cdf0e10cSrcweir 	SvLBoxItem* 	Create() const;
374*cdf0e10cSrcweir 	void 			Clone( SvLBoxItem* pSource );
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir private:
377*cdf0e10cSrcweir 	CustomAnimationList* mpParent;
378*cdf0e10cSrcweir 	OUString		maDescription;
379*cdf0e10cSrcweir };
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir // --------------------------------------------------------------------
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir CustomAnimationTriggerEntryItem::CustomAnimationTriggerEntryItem( SvLBoxEntry* pEntry, sal_uInt16 nFlags, OUString aDescription, CustomAnimationList* pParent  )
384*cdf0e10cSrcweir : SvLBoxString( pEntry, nFlags, aDescription ), mpParent( pParent ), maDescription( aDescription )
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir // --------------------------------------------------------------------
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir CustomAnimationTriggerEntryItem::~CustomAnimationTriggerEntryItem()
391*cdf0e10cSrcweir {
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir // --------------------------------------------------------------------
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir sal_uInt16 CustomAnimationTriggerEntryItem::IsA()
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir 	return (sal_uInt16)-1;
399*cdf0e10cSrcweir }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir // --------------------------------------------------------------------
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir void CustomAnimationTriggerEntryItem::InitViewData( SvLBox* pView, SvLBoxEntry* pEntry, SvViewDataItem* pViewData )
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir 	if( !pViewData )
406*cdf0e10cSrcweir 		pViewData = pView->GetViewDataItem( pEntry, this );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	Size aSize(pView->GetTextWidth( maDescription ) + 2 * 19, pView->GetTextHeight() );
409*cdf0e10cSrcweir 	if( aSize.Height() < 19 )
410*cdf0e10cSrcweir 		aSize.Height() = 19;
411*cdf0e10cSrcweir 	pViewData->aSize = aSize;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir /*
414*cdf0e10cSrcweir 		SvViewData* pViewData = pView->GetViewData( pEntry );
415*cdf0e10cSrcweir 		if( pViewData )
416*cdf0e10cSrcweir 			pViewData->SetSelectable(false);
417*cdf0e10cSrcweir */
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir // --------------------------------------------------------------------
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir void CustomAnimationTriggerEntryItem::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16, SvLBoxEntry* )
423*cdf0e10cSrcweir {
424*cdf0e10cSrcweir 	Size aSize( rDev.GetOutputSizePixel().Width(), static_cast< SvTreeListBox* >(&rDev)->GetEntryHeight() );
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 	Point aPos( 0, rPos.Y() );
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	Rectangle aOutRect( aPos, aSize );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 	// fill the background
431*cdf0e10cSrcweir     Color aColor (rDev.GetSettings().GetStyleSettings().GetDialogColor());
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	rDev.Push();
434*cdf0e10cSrcweir     rDev.SetFillColor (aColor);
435*cdf0e10cSrcweir     rDev.SetLineColor ();
436*cdf0e10cSrcweir     rDev.DrawRect(aOutRect);
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir     // Erase the four corner pixels to make the rectangle appear rounded.
439*cdf0e10cSrcweir     rDev.SetLineColor( rDev.GetSettings().GetStyleSettings().GetWindowColor());
440*cdf0e10cSrcweir     rDev.DrawPixel( aOutRect.TopLeft());
441*cdf0e10cSrcweir     rDev.DrawPixel( Point(aOutRect.Right(), aOutRect.Top()));
442*cdf0e10cSrcweir     rDev.DrawPixel( Point(aOutRect.Left(), aOutRect.Bottom()));
443*cdf0e10cSrcweir     rDev.DrawPixel( Point(aOutRect.Right(), aOutRect.Bottom()));
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 	// draw the category title
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 	int nVertBorder = (( aSize.Height() - rDev.GetTextHeight()) >> 1);
448*cdf0e10cSrcweir 	int nHorzBorder = rDev.LogicToPixel( Size( 3, 3 ), MAP_APPFONT ).Width();
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	aOutRect.nLeft += nHorzBorder;
451*cdf0e10cSrcweir 	aOutRect.nRight -= nHorzBorder;
452*cdf0e10cSrcweir 	aOutRect.nTop += nVertBorder;
453*cdf0e10cSrcweir 	aOutRect.nBottom -= nVertBorder;
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir 	rDev.DrawText (aOutRect, rDev.GetEllipsisString( maDescription, aOutRect.GetWidth() ) );
456*cdf0e10cSrcweir 	rDev.Pop();
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir // --------------------------------------------------------------------
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir SvLBoxItem* CustomAnimationTriggerEntryItem::Create() const
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir 	return NULL;
464*cdf0e10cSrcweir }
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir // --------------------------------------------------------------------
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir void CustomAnimationTriggerEntryItem::Clone( SvLBoxItem* )
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir // ====================================================================
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir CustomAnimationList::CustomAnimationList( ::Window* pParent, const ResId& rResId, ICustomAnimationListController* pController )
475*cdf0e10cSrcweir :	SvTreeListBox( pParent, rResId )
476*cdf0e10cSrcweir ,	mbIgnorePaint( false )
477*cdf0e10cSrcweir ,	mpController( pController )
478*cdf0e10cSrcweir ,	mpLastParentEntry(0)
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir 	SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES | WB_HASBUTTONS | WB_HASBUTTONSATROOT );
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir 	EnableContextMenuHandling();
483*cdf0e10cSrcweir 	SetSelectionMode( MULTIPLE_SELECTION );
484*cdf0e10cSrcweir 	SetIndent(16);
485*cdf0e10cSrcweir 	SetNodeDefaultImages();
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir // --------------------------------------------------------------------
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir const Image&  CustomAnimationList::getImage( sal_uInt16 nId, bool bHighContrast )
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir 	DBG_ASSERT( (nId >= IMG_CUSTOMANIMATION_ON_CLICK) && (nId <= IMG_CUSTOMANIMATION_MEDIA_STOP), "sd::CustomAnimationList::getImage(), illegal index!" );
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 	if( bHighContrast )
495*cdf0e10cSrcweir 		nId += 1;
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 	Image& rImage = maImages[nId - IMG_CUSTOMANIMATION_ON_CLICK];
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 	// load on demand
500*cdf0e10cSrcweir 	if( rImage.GetSizePixel().Width() == 0 )
501*cdf0e10cSrcweir 		rImage = Image(SdResId( nId ) );
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 	return rImage;
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir // --------------------------------------------------------------------
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir CustomAnimationList::~CustomAnimationList()
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir 	if( mpMainSequence.get() )
511*cdf0e10cSrcweir 		mpMainSequence->removeListener( this );
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 	clear();
514*cdf0e10cSrcweir }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir // --------------------------------------------------------------------
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir void CustomAnimationList::KeyInput( const KeyEvent& rKEvt )
519*cdf0e10cSrcweir {
520*cdf0e10cSrcweir 	const int nKeyCode = rKEvt.GetKeyCode().GetCode();
521*cdf0e10cSrcweir 	switch( nKeyCode )
522*cdf0e10cSrcweir 	{
523*cdf0e10cSrcweir 		case KEY_DELETE:	mpController->onContextMenu( CM_REMOVE ); return;
524*cdf0e10cSrcweir 		case KEY_INSERT:	mpController->onContextMenu( CM_CREATE ); return;
525*cdf0e10cSrcweir 		case KEY_SPACE:
526*cdf0e10cSrcweir 			{
527*cdf0e10cSrcweir 				const Point aPos;
528*cdf0e10cSrcweir 				const CommandEvent aCEvt( aPos, COMMAND_CONTEXTMENU );
529*cdf0e10cSrcweir 				Command( aCEvt );
530*cdf0e10cSrcweir 				return;
531*cdf0e10cSrcweir 			}
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 	}
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 	::SvTreeListBox::KeyInput( rKEvt );
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir // --------------------------------------------------------------------
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir /** selects or deselects the given effect.
541*cdf0e10cSrcweir 	Selections of other effects are not changed */
542*cdf0e10cSrcweir void CustomAnimationList::select( CustomAnimationEffectPtr pEffect, bool bSelect /* = true */ )
543*cdf0e10cSrcweir {
544*cdf0e10cSrcweir 	CustomAnimationListEntry* pEntry = static_cast< CustomAnimationListEntry* >(First());
545*cdf0e10cSrcweir 	while( pEntry )
546*cdf0e10cSrcweir 	{
547*cdf0e10cSrcweir 		if( pEntry->getEffect() == pEffect )
548*cdf0e10cSrcweir 		{
549*cdf0e10cSrcweir 			Select( pEntry, bSelect );
550*cdf0e10cSrcweir 			break;
551*cdf0e10cSrcweir 		}
552*cdf0e10cSrcweir 		pEntry = static_cast< CustomAnimationListEntry* >(Next( pEntry ));
553*cdf0e10cSrcweir 	}
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 	if( !pEntry && bSelect )
556*cdf0e10cSrcweir 	{
557*cdf0e10cSrcweir 		append( pEffect );
558*cdf0e10cSrcweir 		select( pEffect );
559*cdf0e10cSrcweir 	}
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir // --------------------------------------------------------------------
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir void CustomAnimationList::clear()
565*cdf0e10cSrcweir {
566*cdf0e10cSrcweir 	Clear();
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 	mpLastParentEntry = 0;
569*cdf0e10cSrcweir 	mxLastTargetShape = 0;
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir // --------------------------------------------------------------------
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir void CustomAnimationList::update( MainSequencePtr pMainSequence )
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir 	if( mpMainSequence.get() )
577*cdf0e10cSrcweir 		mpMainSequence->removeListener( this );
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 	mpMainSequence = pMainSequence;
580*cdf0e10cSrcweir 	update();
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir 	if( mpMainSequence.get() )
583*cdf0e10cSrcweir 		mpMainSequence->addListener( this );
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir // --------------------------------------------------------------------
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir struct stl_append_effect_func : public std::unary_function<CustomAnimationEffectPtr, void>
589*cdf0e10cSrcweir {
590*cdf0e10cSrcweir 	stl_append_effect_func( CustomAnimationList& rList ) : mrList( rList ) {}
591*cdf0e10cSrcweir 	void operator()(CustomAnimationEffectPtr pEffect);
592*cdf0e10cSrcweir 	CustomAnimationList& mrList;
593*cdf0e10cSrcweir };
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir void stl_append_effect_func::operator()(CustomAnimationEffectPtr pEffect)
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir 	mrList.append( pEffect );
598*cdf0e10cSrcweir }
599*cdf0e10cSrcweir // --------------------------------------------------------------------
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir void CustomAnimationList::update()
602*cdf0e10cSrcweir {
603*cdf0e10cSrcweir 	mbIgnorePaint = true;
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 	CustomAnimationListEntry* pEntry = 0;
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 	std::list< CustomAnimationEffectPtr > aExpanded;
608*cdf0e10cSrcweir 	std::list< CustomAnimationEffectPtr > aSelected;
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 	CustomAnimationEffectPtr pFirstVisibleEffect;
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 	if( mpMainSequence.get() )
613*cdf0e10cSrcweir 	{
614*cdf0e10cSrcweir 		// save selection and expand states
615*cdf0e10cSrcweir 		pEntry = static_cast<CustomAnimationListEntry*>(FirstVisible());
616*cdf0e10cSrcweir 		if( pEntry )
617*cdf0e10cSrcweir 			pFirstVisibleEffect = pEntry->getEffect();
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 		pEntry = static_cast<CustomAnimationListEntry*>(First());
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 		while( pEntry )
622*cdf0e10cSrcweir 		{
623*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect( pEntry->getEffect() );
624*cdf0e10cSrcweir 			if( pEffect.get() )
625*cdf0e10cSrcweir 			{
626*cdf0e10cSrcweir 				if( IsExpanded( pEntry ) )
627*cdf0e10cSrcweir 					aExpanded.push_back( pEffect );
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 				if( IsSelected( pEntry ) )
630*cdf0e10cSrcweir 					aSelected.push_back( pEffect );
631*cdf0e10cSrcweir 			}
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 			pEntry = static_cast<CustomAnimationListEntry*>(Next( pEntry ));
634*cdf0e10cSrcweir 		}
635*cdf0e10cSrcweir 	}
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 	// rebuild list
638*cdf0e10cSrcweir 	clear();
639*cdf0e10cSrcweir 	if( mpMainSequence.get() )
640*cdf0e10cSrcweir 	{
641*cdf0e10cSrcweir 		std::for_each( mpMainSequence->getBegin(), mpMainSequence->getEnd(), stl_append_effect_func( *this ) );
642*cdf0e10cSrcweir 		mpLastParentEntry = 0;
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 		const InteractiveSequenceList& rISL = mpMainSequence->getInteractiveSequenceList();
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 		InteractiveSequenceList::const_iterator aIter( rISL.begin() );
647*cdf0e10cSrcweir 		const InteractiveSequenceList::const_iterator aEnd( rISL.end() );
648*cdf0e10cSrcweir 		while( aIter != aEnd )
649*cdf0e10cSrcweir 		{
650*cdf0e10cSrcweir 			InteractiveSequencePtr pIS( (*aIter++) );
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir 			Reference< XShape > xShape( pIS->getTriggerShape() );
653*cdf0e10cSrcweir 			if( xShape.is() )
654*cdf0e10cSrcweir 			{
655*cdf0e10cSrcweir 				SvLBoxEntry* pLBoxEntry = new CustomAnimationListEntry;
656*cdf0e10cSrcweir 				pLBoxEntry->AddItem( new SvLBoxContextBmp( pLBoxEntry, 0, Image(), Image(), 0));
657*cdf0e10cSrcweir 				OUString aDescription = String( SdResId( STR_CUSTOMANIMATION_TRIGGER ) );
658*cdf0e10cSrcweir 				aDescription += OUString( RTL_CONSTASCII_USTRINGPARAM(": ") );
659*cdf0e10cSrcweir 				aDescription += getShapeDescription( xShape, false );
660*cdf0e10cSrcweir 				pLBoxEntry->AddItem( new CustomAnimationTriggerEntryItem( pLBoxEntry, 0, aDescription, this ) );
661*cdf0e10cSrcweir 				Insert( pLBoxEntry );
662*cdf0e10cSrcweir 				SvViewData* pViewData = GetViewData( pLBoxEntry );
663*cdf0e10cSrcweir 				if( pViewData )
664*cdf0e10cSrcweir 					pViewData->SetSelectable(false);
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir 				std::for_each( pIS->getBegin(), pIS->getEnd(), stl_append_effect_func( *this ) );
667*cdf0e10cSrcweir 				mpLastParentEntry = 0;
668*cdf0e10cSrcweir 			}
669*cdf0e10cSrcweir 		}
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 		// restore selection and expand states
672*cdf0e10cSrcweir 		pEntry = static_cast<CustomAnimationListEntry*>(First());
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir 		while( pEntry )
675*cdf0e10cSrcweir 		{
676*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect( pEntry->getEffect() );
677*cdf0e10cSrcweir 			if( pEffect.get() )
678*cdf0e10cSrcweir 			{
679*cdf0e10cSrcweir 				if( std::find( aExpanded.begin(), aExpanded.end(), pEffect ) != aExpanded.end() )
680*cdf0e10cSrcweir 					Expand( pEntry );
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir 				if( std::find( aSelected.begin(), aSelected.end(), pEffect ) != aSelected.end() )
683*cdf0e10cSrcweir 					Select( pEntry );
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir 				if( pFirstVisibleEffect == pEffect )
686*cdf0e10cSrcweir 					MakeVisible( pEntry );
687*cdf0e10cSrcweir 			}
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir 			pEntry = static_cast<CustomAnimationListEntry*>(Next( pEntry ));
690*cdf0e10cSrcweir 		}
691*cdf0e10cSrcweir 	}
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 	mbIgnorePaint = false;
694*cdf0e10cSrcweir 	Invalidate();
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir // --------------------------------------------------------------------
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir /*
700*cdf0e10cSrcweir void CustomAnimationList::update( CustomAnimationEffectPtr pEffect )
701*cdf0e10cSrcweir {
702*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = First();
703*cdf0e10cSrcweir 	while( pEntry )
704*cdf0e10cSrcweir 	{
705*cdf0e10cSrcweir 		if( static_cast< CustomAnimationEffectPtr * >( pEntry->GetUserData() )->get() == pEffect.get() )
706*cdf0e10cSrcweir 		{
707*cdf0e10cSrcweir 			CustomAnimationPresetsPtr pPresets = mpController->getPresets();
708*cdf0e10cSrcweir 			const CustomAnimationPresetPtr pPreset = pPresets->getEffectDescriptor( pEffect->getPresetId() );
709*cdf0e10cSrcweir 			if( pPreset.get() )
710*cdf0e10cSrcweir 				pEffect->setName( pPresets->getUINameForPresetId( pPreset->getPresetId() ) );
711*cdf0e10cSrcweir 			else
712*cdf0e10cSrcweir 				pEffect->setName( pEffect->getPresetId() );
713*cdf0e10cSrcweir 			break;
714*cdf0e10cSrcweir 		}
715*cdf0e10cSrcweir 		pEntry = Next( pEntry );
716*cdf0e10cSrcweir 	}
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 	Invalidate();
719*cdf0e10cSrcweir }
720*cdf0e10cSrcweir */
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir // --------------------------------------------------------------------
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir void CustomAnimationList::append( CustomAnimationEffectPtr pEffect )
725*cdf0e10cSrcweir {
726*cdf0e10cSrcweir 	// create a ui description
727*cdf0e10cSrcweir 	OUString aDescription;
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir 	Any aTarget( pEffect->getTarget() );
730*cdf0e10cSrcweir 	if( aTarget.hasValue() ) try
731*cdf0e10cSrcweir 	{
732*cdf0e10cSrcweir 		aDescription = getDescription( aTarget, pEffect->getTargetSubItem() != ShapeAnimationSubType::ONLY_BACKGROUND );
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir 		SvLBoxEntry* pParentEntry = 0;
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir 		Reference< XShape > xTargetShape( pEffect->getTargetShape() );
737*cdf0e10cSrcweir 		sal_Int32 nGroupId = pEffect->getGroupId();
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 		// if this effect has the same target and group-id as the last root effect,
740*cdf0e10cSrcweir 		// the last root effect is also this effects parent
741*cdf0e10cSrcweir 		if( mpLastParentEntry && (nGroupId != -1) && (mxLastTargetShape == xTargetShape) && (mnLastGroupId == nGroupId) )
742*cdf0e10cSrcweir 			pParentEntry = mpLastParentEntry;
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir 		// create an entry for the effect
745*cdf0e10cSrcweir 		SvLBoxEntry* pEntry = new CustomAnimationListEntry( pEffect );
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 		pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));
748*cdf0e10cSrcweir 		pEntry->AddItem( new CustomAnimationListEntryItem( pEntry, 0, aDescription, pEffect, this ) );
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir 		if( pParentEntry )
751*cdf0e10cSrcweir 		{
752*cdf0e10cSrcweir 			// add a subentry
753*cdf0e10cSrcweir 			Insert( pEntry, pParentEntry );
754*cdf0e10cSrcweir 		}
755*cdf0e10cSrcweir 		else
756*cdf0e10cSrcweir 		{
757*cdf0e10cSrcweir 			// add a root entry
758*cdf0e10cSrcweir 			Insert( pEntry );
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir 			// and the new root entry becomes the possible next group header
761*cdf0e10cSrcweir 			mxLastTargetShape = xTargetShape;
762*cdf0e10cSrcweir 			mnLastGroupId = nGroupId;
763*cdf0e10cSrcweir 			mpLastParentEntry = pEntry;
764*cdf0e10cSrcweir 		}
765*cdf0e10cSrcweir 	}
766*cdf0e10cSrcweir 	catch( Exception& e )
767*cdf0e10cSrcweir 	{
768*cdf0e10cSrcweir 		(void)e;
769*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationList::append(), exception catched!" );
770*cdf0e10cSrcweir 	}
771*cdf0e10cSrcweir }
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir // --------------------------------------------------------------------
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir /*
776*cdf0e10cSrcweir void CustomAnimationList::remove( CustomAnimationEffectPtr pEffect )
777*cdf0e10cSrcweir {
778*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = First();
779*cdf0e10cSrcweir 	while( pEntry )
780*cdf0e10cSrcweir 	{
781*cdf0e10cSrcweir 		if( static_cast< CustomAnimationEffectPtr * >( pEntry->GetUserData() )->get() == pEffect.get() )
782*cdf0e10cSrcweir 		{
783*cdf0e10cSrcweir 			GetModel()->Remove( pEntry );
784*cdf0e10cSrcweir 			if( pEntry == mpLastParentEntry )
785*cdf0e10cSrcweir 			{
786*cdf0e10cSrcweir 				mpLastParentEntry = 0;
787*cdf0e10cSrcweir 				mxLastTargetShape = 0;
788*cdf0e10cSrcweir 			}
789*cdf0e10cSrcweir 			break;
790*cdf0e10cSrcweir 		}
791*cdf0e10cSrcweir 		pEntry = Next( pEntry );
792*cdf0e10cSrcweir 	}
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir 	Invalidate();
795*cdf0e10cSrcweir }
796*cdf0e10cSrcweir */
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir // --------------------------------------------------------------------
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir void selectShape( SvTreeListBox* pTreeList, Reference< XShape > xShape )
801*cdf0e10cSrcweir {
802*cdf0e10cSrcweir 	CustomAnimationListEntry* pEntry = static_cast< CustomAnimationListEntry* >(pTreeList->First());
803*cdf0e10cSrcweir 	while( pEntry )
804*cdf0e10cSrcweir 	{
805*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect( pEntry->getEffect() );
806*cdf0e10cSrcweir 		if( pEffect.get() )
807*cdf0e10cSrcweir 		{
808*cdf0e10cSrcweir 			if( pEffect->getTarget() == xShape )
809*cdf0e10cSrcweir 				pTreeList->Select( pEntry );
810*cdf0e10cSrcweir 		}
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 		pEntry = static_cast< CustomAnimationListEntry* >(pTreeList->Next( pEntry ));
813*cdf0e10cSrcweir 	}
814*cdf0e10cSrcweir }
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir // --------------------------------------------------------------------
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir void CustomAnimationList::onSelectionChanged( Any aSelection )
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir 	try
821*cdf0e10cSrcweir 	{
822*cdf0e10cSrcweir 		SelectAll(sal_False);
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir 		if( aSelection.hasValue() )
825*cdf0e10cSrcweir 		{
826*cdf0e10cSrcweir 			Reference< XIndexAccess > xShapes( aSelection, UNO_QUERY );
827*cdf0e10cSrcweir 			if( xShapes.is() )
828*cdf0e10cSrcweir 			{
829*cdf0e10cSrcweir 				sal_Int32 nCount = xShapes->getCount();
830*cdf0e10cSrcweir 				sal_Int32 nIndex;
831*cdf0e10cSrcweir 				for( nIndex = 0; nIndex < nCount; nIndex++ )
832*cdf0e10cSrcweir 				{
833*cdf0e10cSrcweir 					Reference< XShape > xShape( xShapes->getByIndex( nIndex ), UNO_QUERY );
834*cdf0e10cSrcweir 					if( xShape.is() )
835*cdf0e10cSrcweir 						selectShape( this, xShape );
836*cdf0e10cSrcweir 				}
837*cdf0e10cSrcweir 			}
838*cdf0e10cSrcweir 			else
839*cdf0e10cSrcweir 			{
840*cdf0e10cSrcweir 				Reference< XShape > xShape( aSelection, UNO_QUERY );
841*cdf0e10cSrcweir 				if( xShape.is() )
842*cdf0e10cSrcweir 					selectShape( this, xShape );
843*cdf0e10cSrcweir 			}
844*cdf0e10cSrcweir 		}
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 		SelectHdl();
847*cdf0e10cSrcweir 	}
848*cdf0e10cSrcweir 	catch( Exception& )
849*cdf0e10cSrcweir 	{
850*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationList::onSelectionChanged(), Exception catched!" );
851*cdf0e10cSrcweir 	}
852*cdf0e10cSrcweir }
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir // --------------------------------------------------------------------
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir void CustomAnimationList::SelectHdl()
857*cdf0e10cSrcweir {
858*cdf0e10cSrcweir 	SvTreeListBox::SelectHdl();
859*cdf0e10cSrcweir 	mpController->onSelect();
860*cdf0e10cSrcweir }
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir // --------------------------------------------------------------------
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir bool CustomAnimationList::isExpanded( const CustomAnimationEffectPtr& pEffect ) const
865*cdf0e10cSrcweir {
866*cdf0e10cSrcweir 	CustomAnimationListEntry* pEntry = static_cast<CustomAnimationListEntry*>(First());
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 	while( pEntry )
869*cdf0e10cSrcweir 	{
870*cdf0e10cSrcweir 		if( pEntry->getEffect() == pEffect )
871*cdf0e10cSrcweir 			break;
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 		pEntry = static_cast<CustomAnimationListEntry*>(Next( pEntry ));
874*cdf0e10cSrcweir 	}
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir 	if( pEntry )
877*cdf0e10cSrcweir 		pEntry = static_cast<CustomAnimationListEntry*>(GetParent( pEntry ));
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir 	return (pEntry == 0) || IsExpanded( pEntry );
880*cdf0e10cSrcweir }
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir // --------------------------------------------------------------------
883*cdf0e10cSrcweir EffectSequence CustomAnimationList::getSelection() const
884*cdf0e10cSrcweir {
885*cdf0e10cSrcweir 	EffectSequence aSelection;
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir 	CustomAnimationListEntry* pEntry = dynamic_cast< CustomAnimationListEntry* >(FirstSelected());
888*cdf0e10cSrcweir 	while( pEntry )
889*cdf0e10cSrcweir 	{
890*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect( pEntry->getEffect() );
891*cdf0e10cSrcweir 		if( pEffect.get() )
892*cdf0e10cSrcweir 			aSelection.push_back( pEffect );
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir 		// if the selected effect is not expanded and has children
895*cdf0e10cSrcweir 		// we say that the children are automaticly selected
896*cdf0e10cSrcweir 		if( !IsExpanded( pEntry ) )
897*cdf0e10cSrcweir 		{
898*cdf0e10cSrcweir 			CustomAnimationListEntry* pChild = dynamic_cast< CustomAnimationListEntry* >( FirstChild( pEntry ) );
899*cdf0e10cSrcweir 			while( pChild )
900*cdf0e10cSrcweir 			{
901*cdf0e10cSrcweir 				if( !IsSelected( pChild ) )
902*cdf0e10cSrcweir 				{
903*cdf0e10cSrcweir 					CustomAnimationEffectPtr pChildEffect( pChild->getEffect() );
904*cdf0e10cSrcweir 					if( pChildEffect.get() )
905*cdf0e10cSrcweir 						aSelection.push_back( pChildEffect );
906*cdf0e10cSrcweir 				}
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir 				pChild = dynamic_cast< CustomAnimationListEntry* >(  NextSibling( pChild ) );
909*cdf0e10cSrcweir 			}
910*cdf0e10cSrcweir 		}
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir 		pEntry = static_cast< CustomAnimationListEntry* >(NextSelected( pEntry ));
913*cdf0e10cSrcweir 	}
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir 	return aSelection;
916*cdf0e10cSrcweir }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir // --------------------------------------------------------------------
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir sal_Bool CustomAnimationList::DoubleClickHdl()
921*cdf0e10cSrcweir {
922*cdf0e10cSrcweir 	mpController->onDoubleClick();
923*cdf0e10cSrcweir 	return false;
924*cdf0e10cSrcweir }
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir // --------------------------------------------------------------------
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir PopupMenu* CustomAnimationList::CreateContextMenu()
929*cdf0e10cSrcweir {
930*cdf0e10cSrcweir 	PopupMenu* pMenu = new PopupMenu(SdResId( RID_EFFECT_CONTEXTMENU ));
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir 	sal_Int16 nNodeType = -1;
933*cdf0e10cSrcweir 	sal_Int16 nEntries = 0;
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 	CustomAnimationListEntry* pEntry = static_cast< CustomAnimationListEntry* >(FirstSelected());
936*cdf0e10cSrcweir 	while( pEntry )
937*cdf0e10cSrcweir 	{
938*cdf0e10cSrcweir 		nEntries++;
939*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect( pEntry->getEffect() );
940*cdf0e10cSrcweir 		if( pEffect.get() )
941*cdf0e10cSrcweir 		{
942*cdf0e10cSrcweir 			if( nNodeType == -1 )
943*cdf0e10cSrcweir 			{
944*cdf0e10cSrcweir 				nNodeType = pEffect->getNodeType();
945*cdf0e10cSrcweir 			}
946*cdf0e10cSrcweir 			else
947*cdf0e10cSrcweir 			{
948*cdf0e10cSrcweir 				if( nNodeType != pEffect->getNodeType() )
949*cdf0e10cSrcweir 				{
950*cdf0e10cSrcweir 					nNodeType = -1;
951*cdf0e10cSrcweir 					break;
952*cdf0e10cSrcweir 				}
953*cdf0e10cSrcweir 			}
954*cdf0e10cSrcweir 		}
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir 		pEntry = static_cast< CustomAnimationListEntry* >(NextSelected( pEntry ));
957*cdf0e10cSrcweir 	}
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir 	pMenu->CheckItem( CM_WITH_CLICK, nNodeType == EffectNodeType::ON_CLICK );
960*cdf0e10cSrcweir 	pMenu->CheckItem( CM_WITH_PREVIOUS, nNodeType == EffectNodeType::WITH_PREVIOUS );
961*cdf0e10cSrcweir 	pMenu->CheckItem( CM_AFTER_PREVIOUS, nNodeType == EffectNodeType::AFTER_PREVIOUS );
962*cdf0e10cSrcweir 	pMenu->EnableItem( CM_OPTIONS, nEntries == 1 );
963*cdf0e10cSrcweir 	pMenu->EnableItem( CM_DURATION, nEntries == 1 );
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir 	return pMenu;
966*cdf0e10cSrcweir }
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir // --------------------------------------------------------------------
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir void CustomAnimationList::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
971*cdf0e10cSrcweir {
972*cdf0e10cSrcweir 	mpController->onContextMenu( nSelectedPopupEntry );
973*cdf0e10cSrcweir }
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir // --------------------------------------------------------------------
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir void CustomAnimationList::SetTabs()
978*cdf0e10cSrcweir {
979*cdf0e10cSrcweir 	SvTreeListBox::SetTabs();
980*cdf0e10cSrcweir }
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir // --------------------------------------------------------------------
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir void CustomAnimationList::notify_change()
985*cdf0e10cSrcweir {
986*cdf0e10cSrcweir 	update();
987*cdf0e10cSrcweir 	mpController->onSelect();
988*cdf0e10cSrcweir }
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir void CustomAnimationList::Paint( const Rectangle& rRect )
991*cdf0e10cSrcweir {
992*cdf0e10cSrcweir 	if( mbIgnorePaint )
993*cdf0e10cSrcweir 		return;
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir 	SvTreeListBox::Paint( rRect );
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir 	// draw help text if list box is still empty
998*cdf0e10cSrcweir 	if( First() == 0 )
999*cdf0e10cSrcweir 	{
1000*cdf0e10cSrcweir 		Color aOldColor( GetTextColor() );
1001*cdf0e10cSrcweir 		SetTextColor( GetSettings().GetStyleSettings().GetDisableColor() );
1002*cdf0e10cSrcweir 		::Point aOffset( LogicToPixel( Point( 6, 6 ), MAP_APPFONT ) );
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir 		Rectangle aRect( Point( 0,0 ), GetOutputSizePixel() );
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir 		aRect.Left() += aOffset.X();
1007*cdf0e10cSrcweir 		aRect.Top() += aOffset.Y();
1008*cdf0e10cSrcweir 		aRect.Right() -= aOffset.X();
1009*cdf0e10cSrcweir 		aRect.Bottom() -= aOffset.Y();
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir 		DrawText( aRect, String( SdResId( STR_CUSTOMANIMATION_LIST_HELPTEXT ) ),
1012*cdf0e10cSrcweir 			TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK | TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER );
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir 		SetTextColor( aOldColor );
1015*cdf0e10cSrcweir 	}
1016*cdf0e10cSrcweir }
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir }
1019