|
1 /******************************************************************************* |
|
2 * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #include <avkon.mbg> |
|
14 #include <AknsUtils.h> |
|
15 #include <barsread.h> |
|
16 #include <aknconsts.h> |
|
17 #include <gulicon.h> |
|
18 #include <eikprogi.h> |
|
19 #include <swtlaffacade.h> |
|
20 #include <avkon.rsg> |
|
21 #include <AknBitmapAnimation.h> |
|
22 #include <AknsDrawUtils.h> |
|
23 #include <AknUtils.h> |
|
24 #include "swtrotateimage.h" |
|
25 #include "swtfont.h" |
|
26 #include "swtprogressbar.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 TInt CSwtProgressBar::AnimationCallBack(TAny* aPtr) |
|
31 { |
|
32 CSwtProgressBar* progressBar = static_cast<CSwtProgressBar*>(aPtr); |
|
33 |
|
34 if (progressBar) |
|
35 { |
|
36 progressBar->iImageIndex++; |
|
37 if (progressBar->iImageIndex>=progressBar->iBarImages.Count()) |
|
38 { |
|
39 progressBar->iImageIndex=0; |
|
40 } |
|
41 // Intentionally not drawing while urgent painting |
|
42 progressBar->Paint(TRect(progressBar->CoeControl().PositionRelativeToScreen(), |
|
43 progressBar->GetWidgetSize())); |
|
44 } |
|
45 |
|
46 return KErrNone; |
|
47 } |
|
48 |
|
49 /** |
|
50 * 1st & 2nd phase constructors wrapper |
|
51 */ |
|
52 CSwtProgressBar* CSwtProgressBar::NewL(MSwtDisplay& aDisplay, |
|
53 TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle) |
|
54 { |
|
55 CSwtProgressBar* self = new(ELeave) CSwtProgressBar(aDisplay, aPeer, aParent, aStyle); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 self->InitControlBaseL(); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 CSwtProgressBar::CSwtProgressBar(MSwtDisplay& aDisplay, |
|
64 TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle) |
|
65 : ASwtControlBase(aDisplay, aPeer, &aParent, aStyle) |
|
66 , iMinimum(KDefaultProgressBarMinValue) |
|
67 , iMaximum(KDefaultProgressBarMaxValue) |
|
68 , iSelection(KDefaultProgressBarSelectionValue) |
|
69 { |
|
70 SetComponentsToInheritVisibility(ETrue); |
|
71 |
|
72 SetFocusing(EFalse); |
|
73 } |
|
74 |
|
75 |
|
76 CSwtProgressBar::~CSwtProgressBar() |
|
77 { |
|
78 DeleteImages(); |
|
79 iImagesToDelete.Close(); |
|
80 |
|
81 iBarImages.Close(); |
|
82 iBarMasks.Close(); |
|
83 |
|
84 delete iImagesRotator; |
|
85 delete iAnimationPeriodic; |
|
86 |
|
87 #ifdef _lint |
|
88 iBarFrameLeftImage = NULL; |
|
89 iBarFrameLeftMask = NULL; |
|
90 iBarFrameRightImage = NULL; |
|
91 iBarFrameRightMask = NULL; |
|
92 iBarFrameCenterImage= NULL; |
|
93 iBarFrameCenterMask = NULL; |
|
94 iImagesRotator = NULL; |
|
95 iAnimationPeriodic = NULL; |
|
96 #endif |
|
97 } |
|
98 |
|
99 /** |
|
100 * 2nd phase constructor |
|
101 */ |
|
102 void CSwtProgressBar::ConstructL() |
|
103 { |
|
104 // Get parent |
|
105 CCoeControl& coeParent = iParent->Control()->CoeControl(); |
|
106 |
|
107 // Synchronize with parent's state |
|
108 SetContainerWindowL(coeParent); |
|
109 |
|
110 if (iStyle & KSwtStyleVertical) |
|
111 { |
|
112 iImagesRotator = CAORotateImage::NewL(); |
|
113 } |
|
114 |
|
115 LoadImagesL(); |
|
116 |
|
117 // Synchronize with parent's state |
|
118 CAknControl::MakeVisible(coeParent.IsVisible()); |
|
119 CAknControl::SetDimmed(coeParent.IsDimmed()); |
|
120 |
|
121 SetBackground(this); // Back will be drawn by ASwtControlBase::Draw |
|
122 |
|
123 ActivateL(); |
|
124 } |
|
125 |
|
126 void CSwtProgressBar::LoadImagesL() |
|
127 { |
|
128 TFileName avkonbmpFilename(AknIconUtils::AvkonIconFileName()); |
|
129 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
130 CFbsBitmap* bitmap = NULL; |
|
131 CFbsBitmap* mask = NULL; |
|
132 |
|
133 if (iImagesRotator) |
|
134 { |
|
135 iImagesRotator->Cancel(); |
|
136 iImagesRotator->RemoveAllImages(); |
|
137 } |
|
138 |
|
139 DeleteImages(); |
|
140 |
|
141 if (iStyle & KSwtStyleSmooth) |
|
142 { |
|
143 AknsUtils::CreateIconL(skin, KAknsIIDQgnGrafBarProgress, bitmap, mask, |
|
144 KAvkonBitmapFile, EMbmAvkonQgn_graf_bar_progress, EMbmAvkonQgn_graf_bar_progress_mask); |
|
145 |
|
146 iImagesToDelete.Append(bitmap); |
|
147 iImagesToDelete.Append(mask); |
|
148 User::LeaveIfError(iBarImages.Append(bitmap)); |
|
149 User::LeaveIfError(iBarMasks.Append(mask)); |
|
150 } |
|
151 else |
|
152 { |
|
153 // If no specific style for the ProgressBar is speficied so use the Indeterminate style. |
|
154 ASSERT(iStyle & KSwtStyleIndeterminate); |
|
155 |
|
156 TInt aResourceId = R_QGN_GRAF_WAIT_BAR_ANIM; |
|
157 |
|
158 CAknBitmapAnimation* aknAnimation = CAknBitmapAnimation::NewL(); |
|
159 aknAnimation ->SetScaleModeForAnimationFrames(EAspectRatioNotPreserved); |
|
160 |
|
161 TAknsItemID iid; |
|
162 iid.Set(EAknsMajorAvkon, aResourceId); |
|
163 if (!aknAnimation ->ConstructFromSkinL(iid)) |
|
164 { |
|
165 TResourceReader readerForAnimation; |
|
166 iDisplay.CoeEnv()->CreateResourceReaderLC(readerForAnimation,aResourceId); |
|
167 aknAnimation->ConstructFromResourceL(readerForAnimation); |
|
168 CleanupStack::PopAndDestroy(); |
|
169 } |
|
170 |
|
171 TInt endFrame = aknAnimation ->BitmapAnimData()->FrameArray().Count()-1; |
|
172 iFrameIntervalInMilliSeconds = aknAnimation ->BitmapAnimData()->FrameIntervalInMilliSeconds(); |
|
173 |
|
174 for (TInt i=0; i<=endFrame; i++) |
|
175 { |
|
176 aknAnimation ->BitmapAnimData()->FrameArray().At(i)->SetBitmapsOwnedExternally(ETrue); |
|
177 bitmap = aknAnimation ->BitmapAnimData()->FrameArray().At(i)->Bitmap(); |
|
178 mask = aknAnimation ->BitmapAnimData()->FrameArray().At(i)->Mask(); |
|
179 |
|
180 iImagesToDelete.Append(bitmap); |
|
181 iImagesToDelete.Append(mask); |
|
182 |
|
183 User::LeaveIfError(iBarImages.Append(bitmap)); |
|
184 if (mask) |
|
185 { |
|
186 User::LeaveIfError(iBarMasks.Append(mask)); |
|
187 } |
|
188 } |
|
189 |
|
190 delete aknAnimation; |
|
191 } |
|
192 |
|
193 // The long frame bitmap. |
|
194 AknsUtils::CreateIconL(skin, KAknsIIDQgnGrafBarFrameSideL, |
|
195 iBarFrameLeftImage, iBarFrameLeftMask, KAvkonBitmapFile, |
|
196 EMbmAvkonQgn_graf_bar_frame_side_l, |
|
197 EMbmAvkonQgn_graf_bar_frame_side_l_mask); |
|
198 iImagesToDelete.Append(iBarFrameLeftImage); |
|
199 iImagesToDelete.Append(iBarFrameLeftMask); |
|
200 |
|
201 AknsUtils::CreateIconL(skin, KAknsIIDQgnGrafBarFrameCenter, |
|
202 iBarFrameCenterImage, iBarFrameCenterMask, KAvkonBitmapFile, |
|
203 EMbmAvkonQgn_graf_bar_frame_center, |
|
204 EMbmAvkonQgn_graf_bar_frame_center_mask); |
|
205 iImagesToDelete.Append(iBarFrameCenterImage); |
|
206 iImagesToDelete.Append(iBarFrameCenterMask); |
|
207 |
|
208 |
|
209 AknsUtils::CreateIconL(skin, KAknsIIDQgnGrafBarFrameSideR, |
|
210 iBarFrameRightImage, iBarFrameRightMask, KAvkonBitmapFile, |
|
211 EMbmAvkonQgn_graf_bar_frame_side_r, |
|
212 EMbmAvkonQgn_graf_bar_frame_side_r_mask); |
|
213 iImagesToDelete.Append(iBarFrameRightImage); |
|
214 iImagesToDelete.Append(iBarFrameRightMask); |
|
215 |
|
216 if (iStyle & KSwtStyleIndeterminate && IsVisible()) |
|
217 { |
|
218 StartAnimation(); |
|
219 } |
|
220 } |
|
221 |
|
222 void CSwtProgressBar::DeleteImages() |
|
223 { |
|
224 StopAnimation(); |
|
225 |
|
226 for (TInt i=0; i < iImagesToDelete.Count(); i++) |
|
227 { |
|
228 delete iImagesToDelete[i]; |
|
229 iImagesToDelete[i] = NULL; |
|
230 } |
|
231 iImagesToDelete.Reset(); |
|
232 iBarImages.Reset(); |
|
233 iBarMasks.Reset(); |
|
234 } |
|
235 |
|
236 |
|
237 void CSwtProgressBar::UpdateSelection() |
|
238 { |
|
239 if (iSelection > iMaximum) |
|
240 { |
|
241 iSelection = iMaximum; |
|
242 } |
|
243 else if (iSelection < iMinimum) |
|
244 { |
|
245 iSelection = iMinimum; |
|
246 } |
|
247 |
|
248 if ((iStyle & KSwtStyleIndeterminate) == 0) |
|
249 { |
|
250 Redraw(); |
|
251 } |
|
252 } |
|
253 |
|
254 void CSwtProgressBar::AddBitmapToRotator(CFbsBitmap*& aBitmap) |
|
255 { |
|
256 if (iImagesRotator && aBitmap) |
|
257 { |
|
258 TInt error = KErrNone; |
|
259 if (IsBitmapConversionNeeded(aBitmap)) |
|
260 { |
|
261 if (aBitmap->IsCompressedInRAM()) |
|
262 { |
|
263 AknIconUtils::DisableCompression(aBitmap); |
|
264 } |
|
265 |
|
266 if (IsBitmapConversionNeeded(aBitmap)) |
|
267 { |
|
268 TRAP(error, (aBitmap = CreatePlainBitmapL(aBitmap))); |
|
269 |
|
270 if (error == KErrNone) |
|
271 iImagesToDelete.Append(aBitmap); |
|
272 } |
|
273 } |
|
274 |
|
275 if (error == KErrNone) |
|
276 iImagesRotator->AddImage(aBitmap); |
|
277 } |
|
278 } |
|
279 |
|
280 TBool CSwtProgressBar::IsBitmapConversionNeeded(CFbsBitmap* aBitmap) const |
|
281 { |
|
282 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
283 return aBitmap->IsCompressedInRAM() |
|
284 || aBitmap->ExtendedBitmapType() != TUid::Null(); |
|
285 #else |
|
286 return aBitmap->IsCompressedInRAM(); |
|
287 #endif |
|
288 } |
|
289 |
|
290 // The CBitmapRotator which do the rotation of the Bitmap doesn't |
|
291 // work with |
|
292 // a) compressed bitmaps |
|
293 // A assert stop in CFbsBitmap::GetVerticalScanLine during the rotation, |
|
294 // but the documentation say this should works with |
|
295 // compressed and uncompressed bitmap 0-: |
|
296 // b) extended bitmaps |
|
297 // When extended bitmap is passed to rotator, it fails with error |
|
298 CFbsBitmap* CSwtProgressBar::CreatePlainBitmapL(CFbsBitmap* aSrcBitmap) const |
|
299 { |
|
300 CFbsBitmap* trgBitmap = aSrcBitmap; |
|
301 if (IsBitmapConversionNeeded(aSrcBitmap)) |
|
302 { |
|
303 // Create target uncompressed bitmap |
|
304 trgBitmap = new(ELeave) CFbsBitmap(); |
|
305 CleanupStack::PushL(trgBitmap); |
|
306 trgBitmap->Create(aSrcBitmap->SizeInPixels(), aSrcBitmap->DisplayMode()); |
|
307 |
|
308 // create bitmap device |
|
309 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(trgBitmap); |
|
310 CleanupStack::PushL(bitmapDevice); |
|
311 |
|
312 // create graphic context |
|
313 CFbsBitGc* bitmapGc = NULL; |
|
314 bitmapDevice->CreateContext(bitmapGc); |
|
315 CleanupStack::PushL(bitmapGc); |
|
316 |
|
317 // blit old bitmap into new |
|
318 bitmapGc->BitBlt(TPoint(0,0),aSrcBitmap,TRect(aSrcBitmap->SizeInPixels())); |
|
319 |
|
320 // clear stack |
|
321 CleanupStack::PopAndDestroy(bitmapGc); |
|
322 CleanupStack::PopAndDestroy(bitmapDevice); |
|
323 CleanupStack::Pop(trgBitmap); |
|
324 } |
|
325 |
|
326 ASSERT(!trgBitmap->IsCompressedInRAM()); |
|
327 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
328 ASSERT(trgBitmap->ExtendedBitmapType() == TUid::Null()); |
|
329 #endif |
|
330 return trgBitmap; |
|
331 } |
|
332 |
|
333 |
|
334 TSize CSwtProgressBar::LayoutPreferedSizeSize() const |
|
335 { |
|
336 TInt w(CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EESwtCtrlWaitPane, |
|
337 TRect(0, 0, 0, 0), 0).Rect().Width()); |
|
338 TInt h(CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EESwtCtrlWaitPaneH, |
|
339 TRect(0, 0, 0, 0), 0).Rect().Height()); |
|
340 return TSize(w, h); |
|
341 } |
|
342 |
|
343 |
|
344 // |
|
345 // Virtual methods from CCoeControl |
|
346 // |
|
347 |
|
348 TSize CSwtProgressBar::MinimumSize() |
|
349 { |
|
350 TSize preferedSize(LayoutPreferedSizeSize()); |
|
351 |
|
352 if (iStyle & KSwtStyleVertical) |
|
353 { |
|
354 preferedSize = TSize(preferedSize.iHeight, preferedSize.iWidth); |
|
355 } |
|
356 |
|
357 return BorderOuterRect(preferedSize).Size(); |
|
358 } |
|
359 |
|
360 void CSwtProgressBar::SetDimmed(TBool aDimmed) |
|
361 { |
|
362 CAknControl::SetDimmed(aDimmed); |
|
363 |
|
364 FocusabilityChanged(); |
|
365 } |
|
366 |
|
367 |
|
368 void CSwtProgressBar::MakeVisible(TBool aVisible) |
|
369 { |
|
370 CAknControl::MakeVisible(aVisible); |
|
371 |
|
372 if (iStyle & KSwtStyleIndeterminate) |
|
373 { |
|
374 if (aVisible) |
|
375 StartAnimation(); |
|
376 else |
|
377 StopAnimation(); |
|
378 } |
|
379 |
|
380 FocusabilityChanged(); |
|
381 } |
|
382 |
|
383 void CSwtProgressBar::HandleResourceChange(TInt aType) |
|
384 { |
|
385 TRAP_IGNORE(SwtHandleResourceChangeL(aType)); |
|
386 } |
|
387 |
|
388 |
|
389 void CSwtProgressBar::SwtHandleResourceChangeL(TInt aType) |
|
390 { |
|
391 CAknControl::HandleResourceChange(aType); |
|
392 |
|
393 // Update the Control if the Skin Change |
|
394 if (aType == KAknsMessageSkinChange || aType == KEikDynamicLayoutVariantSwitch) |
|
395 { |
|
396 if (aType == KAknsMessageSkinChange) |
|
397 { |
|
398 LoadImagesL(); |
|
399 SizeChanged(); |
|
400 } |
|
401 } |
|
402 } |
|
403 |
|
404 |
|
405 void CSwtProgressBar::FocusChanged(TDrawNow aDrawNow) |
|
406 { |
|
407 CAknControl::FocusChanged(ENoDrawNow); |
|
408 // Spread focus information |
|
409 HandleFocusChanged(aDrawNow); |
|
410 } |
|
411 |
|
412 |
|
413 void CSwtProgressBar::SizeChanged() |
|
414 { |
|
415 TRect innerRect(BorderInnerRect()); |
|
416 TAknLayoutRect frameLayout; |
|
417 |
|
418 innerRect.SetSize(TSize(Max(innerRect.Width(), 1), Max(innerRect.Height(), 1))); |
|
419 |
|
420 if (iImagesRotator) |
|
421 { |
|
422 innerRect.SetSize(TSize(innerRect.Height(), innerRect.Width())); |
|
423 |
|
424 iImagesRotator->RemoveAllImages(); |
|
425 DeleteImages(); |
|
426 |
|
427 TRAP_IGNORE(LoadImagesL()); |
|
428 } |
|
429 |
|
430 SetImagesSize(innerRect.Size()); |
|
431 |
|
432 if (iImagesRotator) |
|
433 { |
|
434 AddAllImagesToRotate(); |
|
435 //Active object already cancelled at this point |
|
436 iImagesRotator->Start(this); |
|
437 } |
|
438 |
|
439 HandleSizeChanged(); |
|
440 } |
|
441 |
|
442 void CSwtProgressBar::PositionChanged() |
|
443 { |
|
444 HandlePositionChanged(); |
|
445 } |
|
446 |
|
447 TTypeUid::Ptr CSwtProgressBar::MopSupplyObject(TTypeUid aId) |
|
448 { |
|
449 TTypeUid::Ptr id = ASwtControlBase::SwtMopSupplyObject(aId); |
|
450 |
|
451 if (id.Pointer() == NULL) |
|
452 { |
|
453 return CAknControl::MopSupplyObject(aId); |
|
454 } |
|
455 else |
|
456 { |
|
457 return id; |
|
458 } |
|
459 } |
|
460 |
|
461 void CSwtProgressBar::Draw(const TRect& /*aRect*/) const |
|
462 { |
|
463 if (iImagesRotator) |
|
464 { |
|
465 if (!iImagesRotator->IsFinish()) |
|
466 { |
|
467 iImagesRotator->SetRedrawAfterRotation(ETrue); |
|
468 return; |
|
469 } |
|
470 } |
|
471 |
|
472 CWindowGc& gc = SystemGc(); |
|
473 |
|
474 // Draw the image of the ProgressBar. |
|
475 TRect innerRect(BorderInnerRect()); |
|
476 |
|
477 DrawProgressBar(gc, innerRect); |
|
478 |
|
479 DrawFrame(gc, innerRect); |
|
480 } |
|
481 |
|
482 void CSwtProgressBar::DrawProgressBar(CWindowGc& gc, TRect targetRect) const |
|
483 { |
|
484 CFbsBitmap* bitmap = iBarImages[iImageIndex]; |
|
485 CFbsBitmap* bitmapMask = iBarMasks[iImageIndex]; |
|
486 |
|
487 |
|
488 // If this is the Smooth style |
|
489 if (iStyle & KSwtStyleSmooth) |
|
490 { |
|
491 // Fill area with background to apears empty. |
|
492 // Calculate the numbers of pixels which must be fill. |
|
493 TInt filledPixels = (iStyle & KSwtStyleVertical)?(targetRect.Height()):(targetRect.Width()); |
|
494 |
|
495 // Indeterminate style progressbar always fills the whole space, |
|
496 // regardless of selection. |
|
497 if ((iStyle & KSwtStyleIndeterminate) == 0) |
|
498 { |
|
499 filledPixels = filledPixels * (iSelection-iMinimum) / (iMaximum - iMinimum); |
|
500 } |
|
501 |
|
502 if (iStyle & KSwtStyleVertical) |
|
503 { |
|
504 targetRect.Move(0, targetRect.Height() - filledPixels); |
|
505 targetRect.SetHeight(filledPixels); |
|
506 } |
|
507 else |
|
508 { |
|
509 TInt origWidth = targetRect.Width(); |
|
510 targetRect.SetWidth(filledPixels); |
|
511 if (AknLayoutUtils::LayoutMirrored()) |
|
512 { |
|
513 targetRect.Move(origWidth-filledPixels, 0); |
|
514 } |
|
515 } |
|
516 } |
|
517 |
|
518 // Left of the frame |
|
519 gc.BitBltMasked(targetRect.iTl, bitmap, targetRect.Size(), bitmapMask, EFalse); |
|
520 } |
|
521 |
|
522 void CSwtProgressBar::DrawFrame(CWindowGc& gc,const TRect& targetRect) const |
|
523 { |
|
524 // Draw the Long Bar Frame. |
|
525 if (iBarFrameLeftImage && iBarFrameCenterImage && iBarFrameRightImage) |
|
526 { |
|
527 TPoint leftPos(TPoint::EUninitialized); |
|
528 TPoint centerPos(TPoint::EUninitialized); |
|
529 TPoint rightPos(TPoint::EUninitialized); |
|
530 |
|
531 TSize lSize(iBarFrameLeftImage->SizeInPixels()); |
|
532 TSize rSize(iBarFrameRightImage->SizeInPixels()); |
|
533 TSize cSize(iBarFrameCenterImage->SizeInPixels()); |
|
534 |
|
535 if (iStyle & KSwtStyleVertical) |
|
536 { |
|
537 rightPos = targetRect.iTl; |
|
538 centerPos = rightPos + TPoint(0, iBarFrameRightImage->SizeInPixels().iHeight); |
|
539 leftPos = centerPos + TPoint(0, iBarFrameCenterImage->SizeInPixels().iHeight); |
|
540 } |
|
541 else |
|
542 { |
|
543 leftPos = targetRect.iTl; |
|
544 centerPos = leftPos + TPoint(iBarFrameLeftImage->SizeInPixels().iWidth, 0); |
|
545 rightPos = centerPos + TPoint(iBarFrameCenterImage->SizeInPixels().iWidth, 0); |
|
546 } |
|
547 |
|
548 // Left of the frame |
|
549 gc.BitBltMasked(leftPos, iBarFrameLeftImage, iBarFrameLeftImage->SizeInPixels(), iBarFrameLeftMask, EFalse); |
|
550 |
|
551 // Center of the frame |
|
552 gc.BitBltMasked(centerPos, iBarFrameCenterImage, iBarFrameCenterImage->SizeInPixels(), iBarFrameCenterMask, EFalse); |
|
553 |
|
554 // Right of the frame |
|
555 gc.BitBltMasked(rightPos, iBarFrameRightImage, iBarFrameRightImage->SizeInPixels(), iBarFrameRightMask, EFalse); |
|
556 } |
|
557 } |
|
558 // |
|
559 // Virtual methods from MSwtControl |
|
560 // |
|
561 |
|
562 CCoeControl& CSwtProgressBar::CoeControl() |
|
563 { |
|
564 return *this; |
|
565 } |
|
566 |
|
567 const CCoeControl& CSwtProgressBar::CoeControl() const |
|
568 { |
|
569 return *this; |
|
570 } |
|
571 |
|
572 TBool CSwtProgressBar::IsFocusable(TInt aReason /*=KSwtFocusByApi*/) const |
|
573 { |
|
574 const CCoeControl& coeCtrl = CoeControl(); |
|
575 |
|
576 // Invisible or disabled controls can never get the focus (not even forced) |
|
577 if (!coeCtrl.IsVisible() || coeCtrl.IsDimmed()) |
|
578 return EFalse; |
|
579 else |
|
580 return aReason == KSwtFocusByForce; |
|
581 } |
|
582 |
|
583 void CSwtProgressBar::ProcessKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/) |
|
584 { |
|
585 // Do nothing |
|
586 } |
|
587 |
|
588 TKeyResponse CSwtProgressBar::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
589 { |
|
590 return HandleKeyL(aKeyEvent, aType, ETrue); |
|
591 } |
|
592 |
|
593 TSize CSwtProgressBar::ComputeSizeL(TInt aWHint, TInt aHHint) |
|
594 { |
|
595 TSize size(MinimumSize()); |
|
596 |
|
597 if (aWHint != KSwtDefault) |
|
598 { |
|
599 size.iWidth = aWHint; |
|
600 } |
|
601 if (aHHint != KSwtDefault) |
|
602 { |
|
603 size.iHeight = aHHint; |
|
604 } |
|
605 |
|
606 return size; |
|
607 } |
|
608 |
|
609 // |
|
610 // Virtual methods from MSwtProgressBar |
|
611 // |
|
612 |
|
613 MSwtControl* CSwtProgressBar::Control() |
|
614 { |
|
615 return this; |
|
616 } |
|
617 |
|
618 TInt CSwtProgressBar::GetMaximum() const |
|
619 { |
|
620 return iMaximum; |
|
621 } |
|
622 |
|
623 TInt CSwtProgressBar::GetMinimum() const |
|
624 { |
|
625 return iMinimum; |
|
626 } |
|
627 |
|
628 TInt CSwtProgressBar::GetSelection() const |
|
629 { |
|
630 return iSelection; |
|
631 } |
|
632 |
|
633 void CSwtProgressBar::SetMaximum(TInt aValue) |
|
634 { |
|
635 if (aValue != iMaximum && aValue > iMinimum) |
|
636 { |
|
637 iMaximum = aValue; |
|
638 UpdateSelection(); |
|
639 } |
|
640 } |
|
641 |
|
642 void CSwtProgressBar::SetMinimum(TInt aValue) |
|
643 { |
|
644 if (aValue != iMinimum && aValue >= 0 && aValue < iMaximum) |
|
645 { |
|
646 iMinimum = aValue; |
|
647 UpdateSelection(); |
|
648 } |
|
649 } |
|
650 |
|
651 void CSwtProgressBar::SetSelection(TInt aValue) |
|
652 { |
|
653 if (aValue == iSelection) |
|
654 { |
|
655 return; |
|
656 } |
|
657 |
|
658 iSelection = aValue; |
|
659 |
|
660 UpdateSelection(); |
|
661 } |
|
662 |
|
663 void CSwtProgressBar::StartAnimation() |
|
664 { |
|
665 if ((iStyle & KSwtStyleIndeterminate) == 0) |
|
666 return; |
|
667 |
|
668 if (iAnimationPeriodic == NULL) |
|
669 { |
|
670 iAnimationPeriodic = CPeriodic::New(CActive::EPriorityStandard); |
|
671 } |
|
672 else |
|
673 { |
|
674 iAnimationPeriodic->Cancel(); |
|
675 } |
|
676 |
|
677 TCallBack callback(AnimationCallBack, this); |
|
678 iAnimationPeriodic->Start(TTimeIntervalMicroSeconds32(iFrameIntervalInMilliSeconds*1000), |
|
679 TTimeIntervalMicroSeconds32(iFrameIntervalInMilliSeconds*1000), callback); |
|
680 } |
|
681 |
|
682 void CSwtProgressBar::StopAnimation() |
|
683 { |
|
684 if ((iStyle & KSwtStyleIndeterminate) == 0) |
|
685 return; |
|
686 |
|
687 if (iAnimationPeriodic) |
|
688 { |
|
689 iAnimationPeriodic->Cancel(); |
|
690 } |
|
691 } |
|
692 |
|
693 void CSwtProgressBar::AddAllImagesToRotate() |
|
694 { |
|
695 ASSERT(iBarImages.Count() == iBarMasks.Count()); |
|
696 if (iStyle & KSwtStyleVertical) |
|
697 { |
|
698 for (TInt indexInImages = 0; indexInImages < iBarImages.Count(); indexInImages ++) |
|
699 { |
|
700 AddBitmapToRotator(iBarImages[indexInImages]); |
|
701 AddBitmapToRotator(iBarMasks[indexInImages]); |
|
702 } |
|
703 |
|
704 // If control size is (0,0), the frame images returned by the skin don't get a |
|
705 // bitmap associated with them. Adding a NULL bitmap to the rotator would cause |
|
706 // a crash, so check here that each image that we add has a bitmap. |
|
707 if (iBarFrameLeftImage->Handle() && iBarFrameLeftMask->Handle()) |
|
708 { |
|
709 AddBitmapToRotator(iBarFrameLeftImage); |
|
710 AddBitmapToRotator(iBarFrameLeftMask); |
|
711 } |
|
712 |
|
713 if (iBarFrameCenterImage->Handle() && iBarFrameCenterMask->Handle()) |
|
714 { |
|
715 AddBitmapToRotator(iBarFrameCenterImage); |
|
716 AddBitmapToRotator(iBarFrameCenterMask); |
|
717 } |
|
718 |
|
719 if (iBarFrameRightImage->Handle() && iBarFrameRightMask->Handle()) |
|
720 { |
|
721 AddBitmapToRotator(iBarFrameRightImage); |
|
722 AddBitmapToRotator(iBarFrameRightMask); |
|
723 } |
|
724 } |
|
725 } |
|
726 |
|
727 void CSwtProgressBar::SetImagesSize(const TSize& aImageSize) |
|
728 { |
|
729 TAknLayoutRect frameLayout; |
|
730 ASSERT(iBarImages.Count() == iBarMasks.Count()); |
|
731 |
|
732 for (TInt i=0; i < iBarImages.Count(); i++) |
|
733 { |
|
734 AknIconUtils::SetSize(iBarImages[i], aImageSize, EAspectRatioNotPreserved); |
|
735 |
|
736 if (iBarMasks[i]) |
|
737 { |
|
738 AknIconUtils::SetSize(iBarMasks[i], aImageSize, EAspectRatioNotPreserved); |
|
739 } |
|
740 } |
|
741 |
|
742 TSize leftSize(CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EWaitBorderPaneG1, aImageSize, 0).Rect().Size()); |
|
743 TSize centerSize(CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EWaitBorderPaneG2, aImageSize, 0).Rect().Size()); |
|
744 |
|
745 TSize rightSize(CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EWaitBorderPaneG3, aImageSize, 0).Rect().Size()); |
|
746 |
|
747 AknIconUtils::SetSize(iBarFrameLeftImage, leftSize, EAspectRatioNotPreserved); |
|
748 AknIconUtils::SetSize(iBarFrameLeftMask, leftSize, EAspectRatioNotPreserved); |
|
749 |
|
750 AknIconUtils::SetSize(iBarFrameCenterImage, centerSize, EAspectRatioNotPreserved); |
|
751 AknIconUtils::SetSize(iBarFrameCenterMask, centerSize, EAspectRatioNotPreserved); |
|
752 |
|
753 AknIconUtils::SetSize(iBarFrameRightImage, rightSize, EAspectRatioNotPreserved); |
|
754 AknIconUtils::SetSize(iBarFrameRightMask, rightSize, EAspectRatioNotPreserved); |
|
755 } |