15 * Description: |
15 * Description: |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 #include "ImageHandler.h" |
19 #include "ImageHandler.h" |
|
20 #include "debug.h" |
20 |
21 |
21 // ============================================================================= |
22 // ============================================================================= |
22 // CImageHandler, a utility class for loading images. |
23 // CImageHandler, a utility class for loading images. |
23 // ============================================================================= |
24 // ============================================================================= |
24 |
25 |
119 |
120 |
120 EXPORT_C void CImageHandler::LoadFileAndScaleL(CFbsBitmap* aScaledBitmap, |
121 EXPORT_C void CImageHandler::LoadFileAndScaleL(CFbsBitmap* aScaledBitmap, |
121 const TFileName& aFileName, |
122 const TFileName& aFileName, |
122 const TSize &aSize, |
123 const TSize &aSize, |
123 MImageHandlerCallback& aCallback, |
124 MImageHandlerCallback& aCallback, |
|
125 TUint aHandle, |
124 TInt aSelectedFrame) |
126 TInt aSelectedFrame) |
125 { |
127 { |
|
128 DP1("CImageHandler::LoadFileAndScaleL, iCallbackQueue.Count()=%d", iCallbackQue.Count()); |
|
129 |
126 if(!IsActive()) |
130 if(!IsActive()) |
127 { |
131 { |
128 __ASSERT_ALWAYS(!IsActive(),User::Invariant()); |
132 __ASSERT_ALWAYS(!IsActive(),User::Invariant()); |
129 iSize = aSize; |
133 iSize = aSize; |
130 iScaledBitmap = aScaledBitmap; |
134 iScaledBitmap = aScaledBitmap; |
131 iScaledBitmap->Reset(); |
135 iScaledBitmap->Reset(); |
132 iScaledBitmap->Create(aSize, EColor16M); |
136 iScaledBitmap->Create(aSize, EColor16M); |
133 iCallback = &aCallback; |
137 iCallback = &aCallback; |
|
138 iHandle = aHandle; |
134 LoadFileL(aFileName, aSelectedFrame); |
139 LoadFileL(aFileName, aSelectedFrame); |
135 } |
140 } |
136 else |
141 else |
137 { |
142 { |
|
143 for (int i=0;i<iCallbackQue.Count();i++) |
|
144 { |
|
145 if (iCallbackQue[i].iFileName.Compare(aFileName) == 0) |
|
146 { |
|
147 User::Leave(KErrAlreadyExists); |
|
148 } |
|
149 } |
|
150 |
138 TImageStruct imageStruct; |
151 TImageStruct imageStruct; |
139 imageStruct.iCallBack = &aCallback; |
152 imageStruct.iCallBack = &aCallback; |
140 imageStruct.iScaledImage = aScaledBitmap; |
153 imageStruct.iScaledImage = aScaledBitmap; |
141 imageStruct.iScaledSize = aSize; |
154 imageStruct.iScaledSize = aSize; |
142 imageStruct.iFileName = aFileName; |
155 imageStruct.iFileName = aFileName; |
|
156 imageStruct.iHandle = aHandle; |
143 iCallbackQue.Append(imageStruct); |
157 iCallbackQue.Append(imageStruct); |
144 } |
158 } |
145 } |
159 } |
146 |
160 |
147 EXPORT_C CFbsBitmap* CImageHandler::ScaledBitmap() |
161 EXPORT_C CFbsBitmap* CImageHandler::ScaledBitmap() |
177 // CActive::RunL() implementation. Called on image load success/failure. |
191 // CActive::RunL() implementation. Called on image load success/failure. |
178 // ----------------------------------------------------------------------------- |
192 // ----------------------------------------------------------------------------- |
179 // |
193 // |
180 void CImageHandler::RunL() |
194 void CImageHandler::RunL() |
181 { |
195 { |
|
196 DP1("CImageHandler::RunL(), iCallbackQueue.Count()=%d", iCallbackQue.Count()); |
182 if ((! iStatus.Int()) && (iSize.iWidth != 0) && (iSize.iHeight != 0)) |
197 if ((! iStatus.Int()) && (iSize.iWidth != 0) && (iSize.iHeight != 0)) |
183 { |
198 { |
184 ScaleL(); |
199 ScaleL(); |
185 iSize.SetSize(0,0); |
200 iSize.SetSize(0,0); |
186 } |
201 } |
187 else |
202 else |
188 { |
203 { |
189 // Invoke callback. |
204 // Invoke callback. |
190 iCallback->ImageOperationCompleteL(iStatus.Int()); |
205 iCallback->ImageOperationCompleteL(iStatus.Int(), iHandle); |
191 if(iCallbackQue.Count()) |
206 if(iCallbackQue.Count()) |
192 { |
207 { |
193 TInt loaderror = KErrNotFound; |
208 TInt loaderror = KErrNotFound; |
194 while(loaderror != KErrNone && iCallbackQue.Count()) |
209 while(loaderror != KErrNone && iCallbackQue.Count()) |
195 { |
210 { |
196 TImageStruct imageStruct= iCallbackQue[0]; |
211 TImageStruct imageStruct= iCallbackQue[0]; |
197 iCallbackQue.Remove(0); |
212 iCallbackQue.Remove(0); |
198 TRAP(loaderror, LoadFileAndScaleL(imageStruct.iScaledImage, imageStruct.iFileName, imageStruct.iScaledSize, *imageStruct.iCallBack)); |
213 TRAP(loaderror, LoadFileAndScaleL(imageStruct.iScaledImage, imageStruct.iFileName, imageStruct.iScaledSize, *imageStruct.iCallBack, imageStruct.iHandle)); |
199 } |
214 } |
200 } |
215 } |
201 } |
216 } |
202 |
217 |
203 } |
218 } |