|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Implementation of CHuiS60Skin. CHuiS60Skin is a HUITK skin |
|
15 * that uses resources from the current S60 skin. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "uiacceltk/HuiS60Skin.h" // Class definition |
|
22 #include "uiacceltk/HuiStatic.h" |
|
23 #include "HuiRenderPlugin.h" |
|
24 #include "uiacceltk/HuiTextureManager.h" |
|
25 #include "uiacceltk/HuiTexture.h" |
|
26 #include "uiacceltk/HuiEnv.h" |
|
27 #include "uiacceltk/HuiGc.h" |
|
28 #include "uiacceltk/HuiUtil.h" |
|
29 #include "uiacceltk/HuiDisplay.h" |
|
30 |
|
31 #include <AknsDrawUtils.h> |
|
32 #include <AknUtils.h> |
|
33 |
|
34 #include "huiskinbackroundlayout.h" |
|
35 |
|
36 |
|
37 struct TBackgroundTexture |
|
38 { |
|
39 TAknsItemID iID; |
|
40 CHuiTexture* iBackgroundTexture; //not owned |
|
41 }; |
|
42 |
|
43 struct TPrivData |
|
44 { |
|
45 RArray<TBackgroundTexture> iBackgrounds; |
|
46 }; |
|
47 |
|
48 |
|
49 |
|
50 EXPORT_C CHuiS60Skin::CHuiS60Skin(CHuiEnv& aEnv) |
|
51 : CHuiSkin(aEnv) |
|
52 { |
|
53 iSpare = NULL; |
|
54 } |
|
55 |
|
56 |
|
57 EXPORT_C void CHuiS60Skin::ConstructL() |
|
58 { |
|
59 iSkinControlContext = CAknsBasicBackgroundControlContext::NewL( |
|
60 KAknsIIDQsnBgScreen, TRect(TPoint(0, 0), HuiUtil::ScreenSize()), ETrue); |
|
61 iSpare = new (ELeave) TPrivData; |
|
62 iSkinChanged = ETrue; |
|
63 } |
|
64 |
|
65 |
|
66 EXPORT_C CHuiS60Skin::~CHuiS60Skin() |
|
67 { |
|
68 FreeBackgrounds(); |
|
69 delete (TPrivData*)(iSpare); |
|
70 delete iSkinControlContext; |
|
71 delete iBackgroundTexture; |
|
72 if (iSkinSrvConnected) |
|
73 iSkinSrvSession.Close(); |
|
74 |
|
75 delete iBackgroundBitmap; |
|
76 } |
|
77 |
|
78 |
|
79 EXPORT_C THuiSkinLocation CHuiS60Skin::Location(THuiSkinElement aElement) |
|
80 { |
|
81 // Changed so that correct cba location is asked from AknLayouUtils |
|
82 switch(aElement) |
|
83 { |
|
84 case EHuiSkinElementSoftKeys: |
|
85 { |
|
86 THuiSkinLocation retValue; |
|
87 AknLayoutUtils::TAknCbaLocation skLocation; |
|
88 skLocation = (AknLayoutUtils::TAknCbaLocation)CHuiStatic::CbaLocation(); |
|
89 switch ( skLocation ) |
|
90 { |
|
91 default: |
|
92 // falltrough |
|
93 case AknLayoutUtils::EAknCbaLocationBottom: |
|
94 { |
|
95 retValue = EHuiSkinLocationBottom; |
|
96 break; |
|
97 } |
|
98 case AknLayoutUtils::EAknCbaLocationRight: |
|
99 { |
|
100 retValue = EHuiSkinLocationRight; |
|
101 break; |
|
102 } |
|
103 case AknLayoutUtils::EAknCbaLocationLeft: |
|
104 { |
|
105 retValue = EHuiSkinLocationLeft; |
|
106 break; |
|
107 } |
|
108 } |
|
109 return retValue; |
|
110 } |
|
111 |
|
112 default: |
|
113 { |
|
114 return EHuiSkinLocationNone; |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 MAknsSkinInstance* CHuiS60Skin::SkinInstance() const |
|
121 { |
|
122 MAknsSkinInstance* skin = 0; |
|
123 if ( CCoeEnv::Static()) |
|
124 { |
|
125 skin = AknsUtils::SkinInstance(); |
|
126 if(!skin ) |
|
127 { |
|
128 TRAP_IGNORE( AknsUtils::InitSkinSupportL() ) |
|
129 skin = AknsUtils::SkinInstance(); |
|
130 } |
|
131 } |
|
132 return skin; |
|
133 } |
|
134 |
|
135 |
|
136 void CHuiS60Skin::UpdateBackgroundL() |
|
137 { |
|
138 if(iBackgroundTexture) |
|
139 { |
|
140 iBackgroundTexture->Reset(); |
|
141 delete iBackgroundTexture; |
|
142 iBackgroundTexture = 0; |
|
143 } |
|
144 |
|
145 HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory in the beginning: %i"), HuiUtil::FreeMemory()); |
|
146 iBackgroundTexture = CreateSkinBackgroundL(KAknsIIDQsnBgScreen); |
|
147 iBackgroundTexture->SetSkinContent(ETrue); |
|
148 iBackgroundTexture->iContentObservers.AppendL(*this); |
|
149 |
|
150 HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory at exit: %i"), HuiUtil::FreeMemory()); |
|
151 } |
|
152 |
|
153 |
|
154 void CHuiS60Skin::SkinContentChanged() |
|
155 { |
|
156 iSkinChanged = ETrue; |
|
157 } |
|
158 |
|
159 void CHuiS60Skin::SkinConfigurationChanged( |
|
160 const TAknsSkinStatusConfigurationChangeReason aReason ) |
|
161 { |
|
162 |
|
163 } |
|
164 void CHuiS60Skin::SkinPackageChanged( |
|
165 const TAknsSkinStatusPackageChangeReason aReason ) |
|
166 { |
|
167 |
|
168 } |
|
169 |
|
170 |
|
171 EXPORT_C const CHuiTexture& CHuiS60Skin::TextureL(TInt aSkinTextureId) |
|
172 { |
|
173 // Create S60 theme specific background texture |
|
174 |
|
175 // If Bitgdi renderer is used, do not create a copy of background |
|
176 // image, but return the default dummy texture. |
|
177 if(aSkinTextureId == EHuiSkinBackgroundTexture && |
|
178 CHuiStatic::Renderer().Id () != EHuiRenderPluginBitgdi) |
|
179 { |
|
180 if(!iBackgroundTexture || iReloadBackground || iSkinChanged) |
|
181 { |
|
182 UpdateBackgroundL(); |
|
183 iReloadBackground = EFalse; |
|
184 } |
|
185 return *iBackgroundTexture; |
|
186 } |
|
187 |
|
188 // Otherwise use the default textures |
|
189 return CHuiSkin::TextureL(aSkinTextureId); |
|
190 } |
|
191 |
|
192 |
|
193 EXPORT_C void CHuiS60Skin::ReleaseTexture(TInt aSkinTextureResource) |
|
194 { |
|
195 HUI_DEBUG(_L("CHuiS60Skin::ReleaseTexture() - Called.")); |
|
196 |
|
197 // Release background texture |
|
198 if(aSkinTextureResource == EHuiSkinBackgroundTexture) |
|
199 { |
|
200 HUI_DEBUG(_L("CHuiS60Skin::ReleaseTexture() - Destroying background texture.")); |
|
201 |
|
202 delete iBackgroundTexture; |
|
203 iBackgroundTexture = NULL; |
|
204 } |
|
205 else |
|
206 { |
|
207 // Otherwise use the default method |
|
208 return CHuiSkin::ReleaseTexture(aSkinTextureResource); |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 EXPORT_C void CHuiS60Skin::NotifyDisplaySizeChangedL() |
|
214 { |
|
215 // The background is now different. |
|
216 iReloadBackground = ETrue; |
|
217 SkinContentChanged(); // for changing the iSkinChanged flag |
|
218 Env().NotifySkinChangedL(); |
|
219 Env().TextStyleManager().NotifyDisplaySizeChangedL(); |
|
220 ReloadBgTexturesL(); |
|
221 } |
|
222 |
|
223 |
|
224 EXPORT_C TRgb CHuiS60Skin::StyleTextColor(THuiPreconfiguredTextStyle aStyle, |
|
225 THuiBackgroundType aBackgroundType) const |
|
226 { |
|
227 // Default text color depends directly on the background type. |
|
228 TRgb defaultColor = (aBackgroundType == EHuiBackgroundTypeLight? KRgbBlack : KRgbWhite); |
|
229 |
|
230 switch(aStyle) |
|
231 { |
|
232 default: |
|
233 break; |
|
234 |
|
235 case EHuiTextStyleSupplement: |
|
236 return TRgb(128, 128, 128); |
|
237 } |
|
238 |
|
239 return defaultColor; |
|
240 } |
|
241 |
|
242 |
|
243 EXPORT_C void CHuiS60Skin::RestoreTextureContentL(CHuiTexture& aTexture) |
|
244 { |
|
245 if(&aTexture == iBackgroundTexture) |
|
246 { |
|
247 iReloadBackground = ETrue; |
|
248 TextureL(EHuiSkinBackgroundTexture); |
|
249 } |
|
250 else |
|
251 { |
|
252 CHuiSkin::RestoreTextureContentL(aTexture); |
|
253 } |
|
254 } |
|
255 |
|
256 EXPORT_C void CHuiS60Skin::SkinExtension(const TUid& aExtensionUid, TAny** aExtensionParameters) |
|
257 { |
|
258 CHuiSkin::SkinExtension(aExtensionUid,aExtensionParameters); |
|
259 } |
|
260 |
|
261 EXPORT_C THuiSkinOrientation CHuiS60Skin::Orientation() const |
|
262 { |
|
263 return CHuiSkin::Orientation(); |
|
264 } |
|
265 |
|
266 EXPORT_C void CHuiS60Skin::SetContext(CHuiGc& aGc) |
|
267 { |
|
268 CHuiSkin::SetContext(aGc); |
|
269 } |
|
270 |
|
271 EXPORT_C CHuiGc& CHuiS60Skin::Context() const |
|
272 { |
|
273 return CHuiSkin::Context(); |
|
274 } |
|
275 |
|
276 EXPORT_C TInt CHuiS60Skin::GetTexture(TInt aSkinTextureResource, const CHuiTexture*& aOutTexture) |
|
277 { |
|
278 return CHuiSkin::GetTexture(aSkinTextureResource, aOutTexture); |
|
279 } |
|
280 |
|
281 |
|
282 void CHuiS60Skin::FreeBackgrounds() |
|
283 { |
|
284 if (CHuiStatic::Renderer().Id () == EHuiRenderPluginBitgdi) |
|
285 { |
|
286 // no need to render the skin backgrounds separately on shitgdi |
|
287 return; |
|
288 } |
|
289 |
|
290 if (!iSpare) |
|
291 { |
|
292 return; |
|
293 } |
|
294 |
|
295 TBackgroundTexture bgTexture; |
|
296 TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); |
|
297 for (TInt index = 0; index < itemCount; index++) |
|
298 { |
|
299 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
|
300 delete bgTexture.iBackgroundTexture; |
|
301 bgTexture.iBackgroundTexture = NULL; |
|
302 } |
|
303 ((TPrivData*)(iSpare))->iBackgrounds.Reset(); |
|
304 |
|
305 } |
|
306 |
|
307 |
|
308 CHuiTexture* CHuiS60Skin::CreateSkinBackgroundL(const TAknsItemID& aID) |
|
309 { |
|
310 // Update the background image. |
|
311 if (!iSkinSrvConnected) |
|
312 { |
|
313 User::LeaveIfError(iSkinSrvSession.Connect(this)); |
|
314 iSkinSrvConnected = ETrue; |
|
315 } |
|
316 |
|
317 MAknsSkinInstance* skin = SkinInstance(); |
|
318 CHuiTexture* texture = CHuiTexture::NewL(); |
|
319 |
|
320 CleanupStack::PushL(texture); |
|
321 if(iSkinChanged) |
|
322 { |
|
323 |
|
324 delete iBackgroundBitmap; |
|
325 iBackgroundBitmap = NULL; |
|
326 |
|
327 if (skin) |
|
328 { |
|
329 TRect dummy; |
|
330 TRect skinRect; |
|
331 GetRectForItem(aID, dummy, skinRect); |
|
332 |
|
333 iBackgroundBitmap = new (ELeave) CFbsBitmap(); |
|
334 User::LeaveIfError( iBackgroundBitmap->Create(skinRect.Size(), EColor64K) ); |
|
335 |
|
336 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iBackgroundBitmap); |
|
337 CleanupStack::PushL(device); |
|
338 |
|
339 CFbsBitGc* gc = 0; |
|
340 User::LeaveIfError( device->CreateContext(gc) ); |
|
341 CleanupStack::PushL(gc); |
|
342 iSkinControlContext->SetRect(skinRect); |
|
343 iSkinControlContext->SetBitmap(aID); |
|
344 |
|
345 AknsDrawUtils::DrawBackground(skin, iSkinControlContext, NULL, *gc, TPoint(0,0), skinRect, |
|
346 KAknsDrawParamDefault); |
|
347 |
|
348 CleanupStack::PopAndDestroy(gc); |
|
349 CleanupStack::PopAndDestroy(device); |
|
350 } |
|
351 else |
|
352 { |
|
353 iBackgroundBitmap = CHuiStatic::GetBgBitmapLC(aID); |
|
354 CleanupStack::Pop( iBackgroundBitmap ); |
|
355 } |
|
356 } |
|
357 texture->UploadL(*iBackgroundBitmap,NULL,EHuiTextureUploadFlagRetainResolution ); |
|
358 |
|
359 CleanupStack::Pop(texture); |
|
360 iSkinChanged = EFalse; |
|
361 return texture; |
|
362 } |
|
363 |
|
364 void CHuiS60Skin::ReloadBgTexturesL() |
|
365 { |
|
366 if (CHuiStatic::Renderer().Id () == EHuiRenderPluginBitgdi ) |
|
367 { |
|
368 // no need to render the skin backgrounds separately on bitgdi |
|
369 return; |
|
370 } |
|
371 TBackgroundTexture bgTexture; |
|
372 TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); |
|
373 for (TInt index = 0; index < itemCount; index++) |
|
374 { |
|
375 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
|
376 delete bgTexture.iBackgroundTexture; |
|
377 bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgTexture.iID); |
|
378 ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture; |
|
379 } |
|
380 } |
|
381 |
|
382 void CHuiS60Skin::UpdateBackgroundsL(const RArray<THuiDisplayBackgroundItem>& aItems) |
|
383 { |
|
384 if (CHuiStatic::Renderer().Id () == EHuiRenderPluginBitgdi) |
|
385 { |
|
386 // no need to render the skin backgrounds separately on shitgdi |
|
387 return; |
|
388 } |
|
389 FreeBackgrounds(); |
|
390 |
|
391 THuiDisplayBackgroundItem bgItem; |
|
392 TBackgroundTexture bgTexture; |
|
393 for (TInt index = 0; index < aItems.Count(); index++) |
|
394 { |
|
395 bgItem = aItems[index]; |
|
396 if (bgItem.ClearMode() == CHuiDisplay::EClearWithSkinBackground) |
|
397 { |
|
398 bgTexture.iID = bgItem.SkinBackground(); |
|
399 bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgItem.SkinBackground()); |
|
400 ((TPrivData*)(iSpare))->iBackgrounds.Append(bgTexture); |
|
401 } |
|
402 } |
|
403 } |
|
404 |
|
405 EXPORT_C CHuiTexture* CHuiS60Skin::BackgroundTexture(const TAknsItemID& aID) |
|
406 { |
|
407 if (CHuiStatic::Renderer().Id () == EHuiRenderPluginBitgdi) |
|
408 { |
|
409 // only opengl has separate skin bg textures. |
|
410 return NULL; |
|
411 } |
|
412 if (!iSpare) |
|
413 { |
|
414 return NULL; |
|
415 } |
|
416 TBackgroundTexture bgTexture; |
|
417 TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); |
|
418 for (TInt index = 0; index < itemCount; index++) |
|
419 { |
|
420 bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index]; |
|
421 if (bgTexture.iID == aID) |
|
422 { |
|
423 return bgTexture.iBackgroundTexture; |
|
424 } |
|
425 } |
|
426 return NULL; |
|
427 } |