|
1 /* |
|
2 * Copyright (c) 2006 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: Setting item for message colour |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <akncolourselectiongrid.h> |
|
20 #include <akniconutils.h> |
|
21 #include <aknlayoutscalable_avkon.cdl.h> |
|
22 #include <aknconsts.h> |
|
23 #include <avkon.mbg> |
|
24 #include <chatng.rsg> |
|
25 |
|
26 #include "ccacoloursettingitem.h" |
|
27 #include "MCASettingSapExt.h" |
|
28 #include "ccaappsettingsdialog.h" |
|
29 #include "chatdefinitions.h" |
|
30 // The Settings have been moved to Cenrep (also retained in the Resource file), |
|
31 // so the enums for keys and central repository header is added here |
|
32 #include "VariantKeys.h" |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Constructor. |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CCAColourSettingItem::CCAColourSettingItem( |
|
41 MCASettingSapExt& aSAPExtension, |
|
42 TBool& aBuffer, |
|
43 TInt aIdentifier ) |
|
44 : CAknSettingItem( aIdentifier ), |
|
45 iExternalValue( aBuffer ), |
|
46 iSAPExtension( aSAPExtension ) |
|
47 { |
|
48 // No implementation needed |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // 2nd phase constructor. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void CCAColourSettingItem::ConstructL( |
|
56 const TDesC& aKey, |
|
57 const TInt aOrdinal, |
|
58 const TDesC& aSettingTitle, |
|
59 CArrayPtr<CGulIcon>* aIconArray ) |
|
60 { |
|
61 iSAPKey = aKey.AllocL(); |
|
62 CAknSettingItem::ConstructL( |
|
63 EFalse, |
|
64 aOrdinal, |
|
65 aSettingTitle, |
|
66 aIconArray, |
|
67 0, |
|
68 EAknCtPopupSettingList, |
|
69 0, |
|
70 0 ); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Destructor. |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CCAColourSettingItem::~CCAColourSettingItem() |
|
78 { |
|
79 delete iDefaultText; |
|
80 delete iSAPKey; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // From class CAknSettingItem. |
|
85 // @see CAknSettingItem |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CCAColourSettingItem::StoreL() |
|
89 { |
|
90 iExternalValue = iInternalValue; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // From class CAknSettingItem. |
|
95 // @see CAknSettingItem |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CCAColourSettingItem::LoadL() |
|
99 { |
|
100 iInternalValue = iExternalValue; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // From class CAknSettingItem. |
|
105 // EditItemL overridden to launch colour selection grid. |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CCAColourSettingItem::EditItemL( TBool /*aCalledFromMenu*/ ) |
|
109 { |
|
110 TBool retVal = EFalse; |
|
111 CEikonEnv* env = CEikonEnv::Static(); |
|
112 |
|
113 // Array for TRgb colour values |
|
114 CArrayFixFlat<TRgb>* colors = new( ELeave ) CArrayFixFlat<TRgb>( KArrayGranularity ); |
|
115 CleanupStack::PushL( colors ); |
|
116 |
|
117 // Read colours from resources |
|
118 CDesCArrayFlat* indices = env->ReadDesCArrayResourceL( R_MESSAGE_COLORS ); |
|
119 CleanupStack::PushL( indices ); |
|
120 |
|
121 // Convert to TRgb's |
|
122 TInt cnt = indices->Count(); |
|
123 for ( TInt i = 0; i < cnt; ++i ) |
|
124 { |
|
125 TInt col; |
|
126 TLex lex( indices->MdcaPoint( i ) ); |
|
127 User::LeaveIfError( lex.Val( col ) ); |
|
128 colors->AppendL( AKN_LAF_COLOR( col ) ); |
|
129 } |
|
130 CleanupStack::PopAndDestroy( indices ); |
|
131 |
|
132 // Get current colour |
|
133 TRgb color( iSAPExtension.IntValueL( *iSAPKey ) ); |
|
134 TInt startValue = color.Value(); |
|
135 TBool noneChosen = ( startValue == KErrNotFound ); |
|
136 |
|
137 // Construct colour selection grid |
|
138 CAknDialog *dlg = CAknColourSelectionGrid::NewL( |
|
139 colors, |
|
140 ETrue, |
|
141 noneChosen, |
|
142 color ); |
|
143 |
|
144 // Use own resource to customize the "none" text. |
|
145 retVal = dlg->ExecuteLD( R_CHATCLIENT_COLOR_GRID_DLG ); |
|
146 |
|
147 TInt colVal = KErrNotFound; |
|
148 if ( !noneChosen ) |
|
149 { |
|
150 colVal = color.Value(); |
|
151 } |
|
152 |
|
153 if ( !retVal ) |
|
154 { |
|
155 colVal = startValue; |
|
156 } |
|
157 else |
|
158 { |
|
159 // Set new value to SAP |
|
160 iSAPExtension.SetIntValueL( *iSAPKey, colVal ); |
|
161 } |
|
162 |
|
163 CleanupStack::PopAndDestroy( colors ); |
|
164 |
|
165 // ETrue: User specific color selected |
|
166 // EFalse: Default color used |
|
167 iInternalValue = ( colVal != KErrNotFound ); |
|
168 |
|
169 UpdateListBoxTextL(); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // From class CAknSettingItem. |
|
174 // @see CAknSettingItem |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 const TDesC& CCAColourSettingItem::SettingTextL() |
|
178 { |
|
179 // When using user defined colour return empty |
|
180 // descriptor, otherwise return default text |
|
181 if ( iInternalValue ) |
|
182 { |
|
183 return KEmptyDesC; |
|
184 } |
|
185 else |
|
186 { |
|
187 return *iDefaultText; |
|
188 } |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // From class CAknSettingItem. |
|
193 // @see CAknSettingItem |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CCAColourSettingItem::CompleteConstructionL() |
|
197 { |
|
198 // Check that correct ConstructL was used |
|
199 if ( !iSAPKey ) |
|
200 { |
|
201 User::Panic( KPanicText, EChatColourSettingItemWronglyConstructed ); |
|
202 } |
|
203 |
|
204 // Read default colour text from resources |
|
205 CEikonEnv* env = CEikonEnv::Static(); |
|
206 iDefaultText = env->AllocReadResourceAsDes16L( |
|
207 R_QTN_CHAT_SET_COLOUR_DEFAULT ); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // From class CAknSettingItem. |
|
212 // @see CAknSettingItem |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 CFbsBitmap* CCAColourSettingItem::CreateBitmapL() |
|
216 { |
|
217 // If custom colour is in use create bitmap with that colour to be |
|
218 // shown inside the setting item |
|
219 |
|
220 // Create rect of correct size to be used for resizing the icon |
|
221 TRect origin; |
|
222 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, origin ); |
|
223 |
|
224 TAknLayoutRect layoutRect; |
|
225 layoutRect.LayoutRect( origin, |
|
226 AknLayoutScalable_Avkon::listscroll_gen_pane( 0 ) ); |
|
227 layoutRect.LayoutRect( layoutRect.Rect(), |
|
228 AknLayoutScalable_Avkon::list_gen_pane( 0 ) ); |
|
229 layoutRect.LayoutRect( layoutRect.Rect(), |
|
230 AknLayoutScalable_Avkon::list_setting_number_pane( 0 ) ); |
|
231 layoutRect.LayoutRect( layoutRect.Rect(), |
|
232 AknLayoutScalable_Avkon::set_value_pane( 0 ) ); |
|
233 TRect rect( layoutRect.Rect() ); |
|
234 |
|
235 // Move rect to 0,0 |
|
236 rect.Move( -rect.iTl.iX, -rect.iTl.iY ); |
|
237 |
|
238 // Get current color from SAP |
|
239 TRgb color( iSAPExtension.IntValueL( *iSAPKey ) ); |
|
240 |
|
241 CFbsBitmap* bitmap = NULL; |
|
242 CFbsBitmap* mask = NULL; |
|
243 |
|
244 // Create icon |
|
245 AknIconUtils::CreateIconL( |
|
246 bitmap, |
|
247 mask, |
|
248 KAvkonBitmapFile, |
|
249 EMbmAvkonQgn_prop_empty, |
|
250 EMbmAvkonQgn_prop_empty_mask |
|
251 ); |
|
252 |
|
253 if ( iInternalValue ) |
|
254 { |
|
255 // Set colour |
|
256 AknIconUtils::SetIconColor( bitmap, color ); |
|
257 |
|
258 // Create solid mask to make |
|
259 // colour box visible |
|
260 delete mask; |
|
261 mask = NULL; |
|
262 CleanupStack::PushL( bitmap ); |
|
263 mask = AknIconUtils::CreateIconL( KAvkonBitmapFile, |
|
264 EMbmAvkonQgn_prop_empty ); |
|
265 CleanupStack::Pop( bitmap ); // No leaving code after this, CGulIcon |
|
266 // takes ownership in NewL |
|
267 } |
|
268 |
|
269 // Resize bitmaps |
|
270 AknIconUtils::SetSize( bitmap, rect.Size() ); |
|
271 AknIconUtils::SetSize( mask, rect.Size() ); |
|
272 |
|
273 // icon takes ownership of bitmaps |
|
274 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
275 // Ownership of icon gets transferred |
|
276 CFbsBitmap* returnedBitmap = SetIconMaskAndReturnBitmap( icon ); |
|
277 return returnedBitmap; // Caller takes ownership |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // CCAColourSettingItem::SetIconMaskAndReturnBitmap |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 CFbsBitmap* CCAColourSettingItem::SetIconMaskAndReturnBitmap( CGulIcon* aIcon ) |
|
285 { |
|
286 CFbsBitmap* returnedBitmap = NULL; |
|
287 |
|
288 if ( aIcon ) |
|
289 { |
|
290 // Drop ownership of bitmaps from icon |
|
291 aIcon->SetBitmapsOwnedExternally( ETrue ); |
|
292 // Get bitmaps |
|
293 CFbsBitmap* bitmap = aIcon->Bitmap(); |
|
294 CFbsBitmap* mask = aIcon->Mask(); |
|
295 delete aIcon; // Does not own bitmaps anymore, so let it go |
|
296 |
|
297 // Always return the bitmap and transfer ownership if there is one |
|
298 if ( bitmap ) |
|
299 { |
|
300 returnedBitmap = bitmap; |
|
301 } |
|
302 |
|
303 // Set the mask if there is a bitmap, an icon and a mask |
|
304 TBool maskOwnershipTransferred = EFalse; |
|
305 if ( bitmap && mask && HasIcon() ) |
|
306 { |
|
307 maskOwnershipTransferred = SetIconMask( mask ); |
|
308 } |
|
309 if ( !maskOwnershipTransferred ) |
|
310 { |
|
311 // Ownership didn't transfer |
|
312 delete mask; |
|
313 } |
|
314 } |
|
315 |
|
316 return returnedBitmap; // Caller takes ownership |
|
317 } |