1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SD_CUSTOMANIMATIONPRESET_HXX
29 #define _SD_CUSTOMANIMATIONPRESET_HXX
30 
31 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
32 #include <boost/shared_ptr.hpp>
33 #endif
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/animations/AnimationNodeType.hpp>
36 
37 #ifndef _UTL_STLTYPES_HXX_
38 #include <comphelper/stl_types.hxx>
39 #endif
40 #include <CustomAnimationEffect.hxx>
41 
42 #include <hash_map>
43 
44 namespace sd {
45 
46 typedef std::hash_map< rtl::OUString, CustomAnimationEffectPtr, comphelper::UStringHash, comphelper::UStringEqual > EffectsSubTypeMap;
47 typedef std::hash_map< rtl::OUString, rtl::OUString, comphelper::UStringHash, comphelper::UStringEqual > UStringMap;
48 typedef std::vector< rtl::OUString > UStringList;
49 
50 class CustomAnimationPreset
51 {
52 	friend class CustomAnimationPresets;
53 
54 public:
55 	CustomAnimationPreset( CustomAnimationEffectPtr pEffect );
56 
57 	void add( CustomAnimationEffectPtr pEffect );
58 
59 	SD_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > create( const rtl::OUString& rstrSubType );
60 
61 	const rtl::OUString& getPresetId() const { return maPresetId; }
62 	const rtl::OUString& getProperty() const { return maProperty; }
63 	const rtl::OUString& getLabel() const { return maLabel; }
64 	sal_Int16 getPresetClass() const { return mnPresetClass; }
65 	double getDuration() const { return mfDuration; }
66 
67 	UStringList getSubTypes();
68 	UStringList getProperties() const;
69 
70 	bool hasProperty( const rtl::OUString& rProperty ) const;
71 	bool isTextOnly() const { return mbIsTextOnly; }
72 
73 private:
74 	rtl::OUString maPresetId;
75 	rtl::OUString maProperty;
76 	sal_Int16 mnPresetClass;
77 	rtl::OUString maLabel;
78 	rtl::OUString maDefaultSubTyp;
79 	double mfDuration;
80 	bool mbIsTextOnly;
81 
82 	EffectsSubTypeMap maSubTypes;
83 };
84 
85 typedef boost::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
86 typedef std::hash_map<rtl::OUString, CustomAnimationPresetPtr, comphelper::UStringHash, comphelper::UStringEqual> EffectDescriptorMap;
87 typedef std::vector< CustomAnimationPresetPtr > EffectDescriptorList;
88 
89 struct PresetCategory
90 {
91 	rtl::OUString maLabel;
92 	EffectDescriptorList maEffects;
93 
94 	PresetCategory( const rtl::OUString& rLabel, const EffectDescriptorList& rEffects )
95 		: maLabel( rLabel ), maEffects( rEffects ) {}
96 };
97 typedef boost::shared_ptr< PresetCategory > PresetCategoryPtr;
98 typedef std::vector< PresetCategoryPtr > PresetCategoryList;
99 
100 class CustomAnimationPresets
101 {
102 public:
103 	CustomAnimationPresets();
104 	virtual ~CustomAnimationPresets();
105 
106 	void init();
107 
108 	SD_DLLPUBLIC static const CustomAnimationPresets& getCustomAnimationPresets();
109 
110 	::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRandomPreset( sal_Int16 nPresetClass ) const;
111 
112 	SD_DLLPUBLIC CustomAnimationPresetPtr getEffectDescriptor( const rtl::OUString& rPresetId ) const;
113 //	const AnimationEffect* getEffect( const rtl::OUString& rPresetId ) const;
114 //	const AnimationEffect* getEffect( const rtl::OUString& rPresetId, const rtl::OUString& rPresetSubType ) const;
115 
116 	const rtl::OUString& getUINameForPresetId( const rtl::OUString& rPresetId ) const;
117 	const rtl::OUString& getUINameForProperty( const rtl::OUString& rProperty ) const;
118 
119 	const PresetCategoryList& getEntrancePresets() const { return maEntrancePresets; }
120 	const PresetCategoryList& getEmphasisPresets() const { return maEmphasisPresets; }
121 	const PresetCategoryList& getExitPresets() const { return maExitPresets; }
122 	const PresetCategoryList& getMotionPathsPresets() const { return maMotionPathsPresets; }
123 	const PresetCategoryList& getMiscPresets() const { return maMiscPresets; }
124 
125 	void changePresetSubType( CustomAnimationEffectPtr pEffect, const rtl::OUString& rPresetSubType ) const;
126 
127 private:
128 	void importEffects();
129 	void importResources();
130 
131 	void importPresets( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xConfigProvider, const rtl::OUString& rNodePath, PresetCategoryList& rPresetMap  );
132 
133 	const rtl::OUString& translateName( const rtl::OUString& rId, const UStringMap& rNameMap ) const;
134 
135 private:
136 	::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > mxRootNode;
137 	EffectDescriptorMap maEffectDiscriptorMap;
138 	UStringMap maEffectNameMap;
139 	UStringMap maPropertyNameMap;
140 
141 	PresetCategoryList maEntrancePresets;
142 	PresetCategoryList maEmphasisPresets;
143 	PresetCategoryList maExitPresets;
144 	PresetCategoryList maMotionPathsPresets;
145 	PresetCategoryList maMiscPresets;
146 
147 	static CustomAnimationPresets*	mpCustomAnimationPresets;
148 };
149 
150 typedef boost::shared_ptr< CustomAnimationPresets > CustomAnimationPresetsPtr;
151 
152 }
153 
154 #endif // _SD_CUSTOMANIMATIONEFFECTS_HXX
155 
156