|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: smiely engine class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <fbs.h> |
|
19 #include <bitdev.h> |
|
20 #include <bitstd.h> |
|
21 #include <AknIconUtils.h> |
|
22 #include <coeutils.h> |
|
23 #include <AknIconObserver.h> |
|
24 |
|
25 #include "smileymodel.h" |
|
26 #include "smileybmpobserver.h" |
|
27 #include "smileyiconrecord.h" |
|
28 #include "smileyimagedata.h" |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 // --------------------------------------------------------------------------- |
|
32 // CSmileyImageData::CSmileyImageData |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CSmileyImageData::CSmileyImageData( CSmileyBmpObserver* aObserver ) : |
|
36 iObserver( aObserver ) |
|
37 { |
|
38 if ( iObserver ) |
|
39 { |
|
40 iObserver->SetImageData( this ); |
|
41 } |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CSmileyImageData::~CSmileyImageData |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CSmileyImageData::~CSmileyImageData() |
|
49 { |
|
50 AknIconUtils::SetObserver( iBmp, NULL ); |
|
51 delete iBmp; |
|
52 delete iMask; |
|
53 delete iStaticBmp; |
|
54 delete iStaticMask; |
|
55 for ( TInt i( 0 ); i < iRefArray.Count(); i++ ) |
|
56 { |
|
57 iRefArray[i]->SetImageData( NULL ); |
|
58 } |
|
59 iRefArray.Reset(); |
|
60 iRefArray.Close(); |
|
61 delete iObserver; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CSmileyImageData::Bitmap |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CFbsBitmap* CSmileyImageData::Bitmap() |
|
69 { |
|
70 return iBmp; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CSmileyImageData::Mask |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CFbsBitmap* CSmileyImageData::Mask() |
|
78 { |
|
79 return iMask; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CSmileyImageData::CreateImageL |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CSmileyImageData::CreateImageL( const TDesC& aIconFileName, TImageInfo& aInfo ) |
|
87 { |
|
88 DeleteImage(); |
|
89 CreateBmpAndMaskL( aIconFileName, aInfo ); |
|
90 if ( !iStaticBmp ) |
|
91 { |
|
92 CreateStaticBmpAndMaskForAnimationL( aIconFileName, aInfo ); |
|
93 } |
|
94 SetBitmapSize( iBmpSize, ETrue ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CSmileyImageData::DeleteImage |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CSmileyImageData::DeleteImage() |
|
102 { |
|
103 AknIconUtils::SetObserver( iBmp, NULL ); |
|
104 delete iBmp; |
|
105 iBmp = NULL; |
|
106 delete iMask; |
|
107 iMask = NULL; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CSmileyImageData::RefArrayCount |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CSmileyImageData::RefArrayCount() |
|
115 { |
|
116 return iRefArray.Count(); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CSmileyImageData::AddToRefArray |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CSmileyImageData::AddToRefArray( CSmileyIcon* aNode ) |
|
124 { |
|
125 for ( TInt i( 0 ); i < iRefArray.Count(); i++ ) |
|
126 { |
|
127 if ( iRefArray[i] == aNode ) |
|
128 { |
|
129 return; |
|
130 } |
|
131 } |
|
132 iRefArray.Append( aNode ); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CSmileyImageData::RemoveFromaRefArray |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CSmileyImageData::RemoveFromRefArray( CSmileyIcon* aNode ) |
|
140 { |
|
141 for ( TInt i( 0 ); i < iRefArray.Count(); i++ ) |
|
142 { |
|
143 if ( iRefArray[i] == aNode ) |
|
144 { |
|
145 iRefArray.Remove( i ); |
|
146 break; |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CSmileyImageData::RefIcon |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 CSmileyIcon* CSmileyImageData::RefIcon( TInt aIndex ) |
|
156 { |
|
157 CSmileyIcon* icon( NULL ); |
|
158 if ( aIndex >= 0 && aIndex < iRefArray.Count() ) |
|
159 { |
|
160 icon = iRefArray[aIndex]; |
|
161 } |
|
162 return icon; |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CSmileyImageData::Code |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TText CSmileyImageData::Code() |
|
170 { |
|
171 return iCode; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CSmileyImageData::SetCode |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CSmileyImageData::SetCode( TText aCode ) |
|
179 { |
|
180 iCode = aCode; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CSmileyImageData::BitmapSize |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 TSize CSmileyImageData::BitmapSize() |
|
188 { |
|
189 return iBmpSize; |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CSmileyImageData::BitmapSize |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CSmileyImageData::SetBitmapSize( TSize aBmpSize, TBool aForceSet ) |
|
197 { |
|
198 TBool sizeChanged = ( iBmpSize != aBmpSize ); |
|
199 iBmpSize = aBmpSize; |
|
200 if ( sizeChanged || aForceSet ) |
|
201 { |
|
202 if ( iBmp ) |
|
203 { |
|
204 AknIconUtils::SetSize( iBmp, iBmpSize ); |
|
205 } |
|
206 if ( iStaticBmp ) |
|
207 { |
|
208 AknIconUtils::SetSize( iStaticBmp, iBmpSize ); |
|
209 } |
|
210 } |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CSmileyImageData::IsAnimationFinished |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TBool CSmileyImageData::IsAnimationFinished() |
|
218 { |
|
219 return ( iIsAnimation && iBmp == NULL ); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CSmileyImageData::IsAnimation |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 TBool CSmileyImageData::IsAnimation() |
|
227 { |
|
228 return iIsAnimation; |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CSmileyImageData::StoredBmp |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 CFbsBitmap* CSmileyImageData::StaticBmp() |
|
236 { |
|
237 return iStaticBmp; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CSmileyImageData::StoredMask |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 CFbsBitmap* CSmileyImageData::StaticMask() |
|
245 { |
|
246 return iStaticMask; |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CSmileyImageData::CreateBmpAndMaskL |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CSmileyImageData::CreateBmpAndMaskL( const TDesC& aIconFileName, |
|
254 TImageInfo& aInfo ) |
|
255 { |
|
256 iIsAnimation = aInfo.iIsAnimation; |
|
257 if ( aInfo.iMaskId != 0 ) |
|
258 { |
|
259 AknIconUtils::CreateIconL( iBmp, iMask, aIconFileName, aInfo.iBmpId, |
|
260 aInfo.iMaskId ); |
|
261 } |
|
262 else |
|
263 { |
|
264 AknIconUtils::CreateIconL( iBmp, iMask, aIconFileName, aInfo.iBmpId, |
|
265 aInfo.iBmpId ); |
|
266 } |
|
267 if ( iIsAnimation ) |
|
268 { |
|
269 AknIconUtils::SetObserver( iBmp, iObserver ); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CSmileyImageData::CreateStaticBmpAndMaskForAnimationL |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CSmileyImageData::CreateStaticBmpAndMaskForAnimationL( |
|
278 const TDesC& aIconFileName, TImageInfo& aInfo ) |
|
279 { |
|
280 if ( aInfo.iIsAnimation ) |
|
281 { |
|
282 if ( aInfo.iStaticMaskId != 0 ) |
|
283 { |
|
284 AknIconUtils::CreateIconL( iStaticBmp, iStaticMask, aIconFileName, |
|
285 aInfo.iStaticBmpId, aInfo.iStaticMaskId ); |
|
286 } |
|
287 else |
|
288 { |
|
289 AknIconUtils::CreateIconL( iStaticBmp, iStaticMask, aIconFileName, |
|
290 aInfo.iStaticBmpId, aInfo.iStaticBmpId ); |
|
291 } |
|
292 } |
|
293 } |
|
294 |
|
295 |