57 EXPORT_C void CHuiS60Skin::ConstructL() |
57 EXPORT_C void CHuiS60Skin::ConstructL() |
58 { |
58 { |
59 iSkinControlContext = CAknsBasicBackgroundControlContext::NewL( |
59 iSkinControlContext = CAknsBasicBackgroundControlContext::NewL( |
60 KAknsIIDQsnBgScreen, TRect(TPoint(0, 0), HuiUtil::ScreenSize()), ETrue); |
60 KAknsIIDQsnBgScreen, TRect(TPoint(0, 0), HuiUtil::ScreenSize()), ETrue); |
61 iSpare = new (ELeave) TPrivData; |
61 iSpare = new (ELeave) TPrivData; |
62 iSkinChanged = ETrue; |
|
63 } |
62 } |
64 |
63 |
65 |
64 |
66 EXPORT_C CHuiS60Skin::~CHuiS60Skin() |
65 EXPORT_C CHuiS60Skin::~CHuiS60Skin() |
67 { |
66 { |
141 { |
140 { |
142 iBackgroundTexture = CreateSkinBackgroundL(KAknsIIDQsnBgScreen); |
141 iBackgroundTexture = CreateSkinBackgroundL(KAknsIIDQsnBgScreen); |
143 iBackgroundTexture->SetSkinContent(ETrue); |
142 iBackgroundTexture->SetSkinContent(ETrue); |
144 iBackgroundTexture->iContentObservers.AppendL(*this); |
143 iBackgroundTexture->iContentObservers.AppendL(*this); |
145 } |
144 } |
146 else if(iSkinChanged) |
145 else if(iReloadBackground || !iBackgroundTexture->HasContent() ) |
147 { |
146 { |
148 iBackgroundTexture->Reset(); |
147 iBackgroundTexture->Reset(); |
149 delete iBackgroundBitmap; |
148 delete iBackgroundBitmap; |
150 iBackgroundBitmap = NULL; |
149 iBackgroundBitmap = NULL; |
151 iBackgroundBitmap = CHuiStatic::GetBgBitmapLC(KAknsIIDQsnBgScreen); |
150 iBackgroundBitmap = CHuiStatic::GetBgBitmapLC(KAknsIIDQsnBgScreen); |
161 // there should be already up-to-date background texture |
160 // there should be already up-to-date background texture |
162 } |
161 } |
163 HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory at exit: %i"), HuiUtil::FreeMemory()); |
162 HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory at exit: %i"), HuiUtil::FreeMemory()); |
164 } |
163 } |
165 |
164 |
|
165 void CHuiS60Skin::FreeAllBackgroundTextureResources() |
|
166 { |
|
167 // delete old contents |
|
168 |
|
169 TBackgroundTexture bgTexture; |
|
170 TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); |
|
171 for (TInt index = 0; index < itemCount; index++) |
|
172 { |
|
173 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
|
174 if( bgTexture.iBackgroundTexture ) |
|
175 { |
|
176 bgTexture.iBackgroundTexture->Reset(); |
|
177 } |
|
178 } |
|
179 |
|
180 delete iBackgroundTexture; |
|
181 iBackgroundTexture = NULL; |
|
182 delete iBackgroundBitmap; |
|
183 iBackgroundBitmap = NULL; |
|
184 iBackgroundRect = TRect(0,0,0,0); |
|
185 iCachedSkinItems.ResetAndDestroy(); |
|
186 } |
|
187 |
166 |
188 |
167 EXPORT_C void CHuiS60Skin::SkinContentChanged() |
189 EXPORT_C void CHuiS60Skin::SkinContentChanged() |
168 { |
190 { |
169 iSkinChanged = ETrue; |
191 FreeAllBackgroundTextureResources(); |
170 } |
192 } |
171 |
193 |
172 EXPORT_C void CHuiS60Skin::SkinConfigurationChanged( |
194 EXPORT_C void CHuiS60Skin::SkinConfigurationChanged( |
173 const TAknsSkinStatusConfigurationChangeReason aReason ) |
195 const TAknsSkinStatusConfigurationChangeReason aReason ) |
174 { |
196 { |
189 // If Bitgdi renderer is used, do not create a copy of background |
211 // If Bitgdi renderer is used, do not create a copy of background |
190 // image, but return the default dummy texture. |
212 // image, but return the default dummy texture. |
191 if(aSkinTextureId == EHuiSkinBackgroundTexture && |
213 if(aSkinTextureId == EHuiSkinBackgroundTexture && |
192 CHuiStatic::Renderer().Id () != EHuiRenderPluginBitgdi) |
214 CHuiStatic::Renderer().Id () != EHuiRenderPluginBitgdi) |
193 { |
215 { |
194 if(!iBackgroundTexture || iReloadBackground || iSkinChanged) |
216 if(!iBackgroundTexture || ( iBackgroundTexture && !iBackgroundTexture->HasContent() ) || |
|
217 iReloadBackground ) |
195 { |
218 { |
196 UpdateBackgroundL(); |
219 UpdateBackgroundL(); |
197 iReloadBackground = EFalse; |
220 iReloadBackground = EFalse; |
198 } |
221 } |
199 return *iBackgroundTexture; |
222 return *iBackgroundTexture; |
225 |
248 |
226 |
249 |
227 EXPORT_C void CHuiS60Skin::NotifyDisplaySizeChangedL() |
250 EXPORT_C void CHuiS60Skin::NotifyDisplaySizeChangedL() |
228 { |
251 { |
229 // The background is now different. |
252 // The background is now different. |
230 SkinContentChanged(); // for changing the iSkinChanged flag |
253 SkinContentChanged(); // to delete old contents |
|
254 |
231 Env().NotifySkinChangedL(); |
255 Env().NotifySkinChangedL(); |
232 Env().TextStyleManager().NotifyDisplaySizeChangedL(); |
256 Env().TextStyleManager().NotifyDisplaySizeChangedL(); |
233 ReloadBgTexturesL(); |
257 ReloadBgTexturesL(); |
234 |
|
235 iSkinChanged = EFalse; |
|
236 } |
258 } |
237 |
259 |
238 |
260 |
239 EXPORT_C TRgb CHuiS60Skin::StyleTextColor(THuiPreconfiguredTextStyle aStyle, |
261 EXPORT_C TRgb CHuiS60Skin::StyleTextColor(THuiPreconfiguredTextStyle aStyle, |
240 THuiBackgroundType aBackgroundType) const |
262 THuiBackgroundType aBackgroundType) const |
341 TRect dummy; |
363 TRect dummy; |
342 GetRectForItem(aID, dummy, skinrect); |
364 GetRectForItem(aID, dummy, skinrect); |
343 |
365 |
344 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); |
366 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); |
345 CleanupStack::PushL(bitmap); |
367 CleanupStack::PushL(bitmap); |
346 User::LeaveIfError( bitmap->Create(skinrect.Size(), EColor64K) ); |
368 User::LeaveIfError( bitmap->Create(skinrect.Size(), EColor16MAP) ); |
347 |
369 |
348 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(bitmap); |
370 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(bitmap); |
349 CleanupStack::PushL(device); |
371 CleanupStack::PushL(device); |
350 |
372 |
351 CFbsBitGc* gc = 0; |
373 CFbsBitGc* gc = 0; |
425 TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); |
447 TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); |
426 for (TInt index = 0; index < itemCount; index++) |
448 for (TInt index = 0; index < itemCount; index++) |
427 { |
449 { |
428 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
450 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
429 delete bgTexture.iBackgroundTexture; |
451 delete bgTexture.iBackgroundTexture; |
|
452 bgTexture.iBackgroundTexture = NULL; |
|
453 // put back. In case of a leave NULL texture is stored and we can try to re-create it later |
|
454 ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture; |
430 bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgTexture.iID); |
455 bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgTexture.iID); |
|
456 // texture created succesfully |
431 ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture; |
457 ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture; |
432 } |
458 } |
433 } |
459 } |
434 |
460 |
435 void CHuiS60Skin::UpdateBackgroundsL(const RArray<THuiDisplayBackgroundItem>& aItems) |
461 void CHuiS60Skin::UpdateBackgroundsL(const RArray<THuiDisplayBackgroundItem>& aItems) |
447 { |
473 { |
448 bgItem = aItems[index]; |
474 bgItem = aItems[index]; |
449 if (bgItem.ClearMode() == CHuiDisplay::EClearWithSkinBackground) |
475 if (bgItem.ClearMode() == CHuiDisplay::EClearWithSkinBackground) |
450 { |
476 { |
451 bgTexture.iID = bgItem.SkinBackground(); |
477 bgTexture.iID = bgItem.SkinBackground(); |
452 bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgItem.SkinBackground()); |
478 bgTexture.iBackgroundTexture = NULL; |
453 ((TPrivData*)(iSpare))->iBackgrounds.Append(bgTexture); |
479 TRAPD(err, bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgItem.SkinBackground())); |
|
480 // if texture creation failed because our own internal services were busy |
|
481 // still append NULL texture so we know to try it again later |
|
482 if(err == KErrNone || err == KErrTimedOut ) |
|
483 { |
|
484 ((TPrivData*)(iSpare))->iBackgrounds.Append(bgTexture); |
|
485 } |
|
486 else |
|
487 { |
|
488 User::Leave(err); |
|
489 } |
454 } |
490 } |
455 } |
491 } |
456 } |
492 } |
457 |
493 |
458 EXPORT_C CHuiTexture* CHuiS60Skin::BackgroundTexture(const TAknsItemID& aID) |
494 EXPORT_C CHuiTexture* CHuiS60Skin::BackgroundTexture(const TAknsItemID& aID) |
471 for (TInt index = 0; index < itemCount; index++) |
507 for (TInt index = 0; index < itemCount; index++) |
472 { |
508 { |
473 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
509 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
474 if (bgTexture.iID == aID) |
510 if (bgTexture.iID == aID) |
475 { |
511 { |
|
512 if(!bgTexture.iBackgroundTexture && !bgTexture.iBackgroundTexture->HasContent()) |
|
513 { |
|
514 delete bgTexture.iBackgroundTexture; |
|
515 bgTexture.iBackgroundTexture = NULL; |
|
516 TRAPD(err, bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgTexture.iID)); |
|
517 // put bgTexture back to the array also in leave cases |
|
518 // otherwise we could leave invalid pointer in array |
|
519 ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture; |
|
520 if(err) |
|
521 { |
|
522 return NULL; // creating failed for some reason |
|
523 } |
|
524 } |
476 return bgTexture.iBackgroundTexture; |
525 return bgTexture.iBackgroundTexture; |
477 } |
526 } |
478 } |
527 } |
479 return NULL; |
528 return NULL; |
480 } |
529 } |