|
1 /* |
|
2 * Copyright (c) 2009 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: PhoneBook2 custom control. Code has been modified to |
|
15 * suit PhoneBook2 requirements. See CColumnListBoxItemDrawer |
|
16 * in EIKCLB.CPP |
|
17 * Ensure that this piece of code is in sync with Avkon EIKCLB.CPP(CColumnListBoxItemDrawer) |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 #include <barsread.h> |
|
23 #include <gdi.h> |
|
24 #include <gulicon.h> |
|
25 #include <gulutil.h> |
|
26 |
|
27 #include <eikenv.h> |
|
28 #include <eiklbi.h> |
|
29 #include <eiktxlbm.h> |
|
30 #include <eikedwin.h> |
|
31 #include <eiklbv.h> |
|
32 #include <AknUtils.h> |
|
33 #include <eiksfont.h> |
|
34 #include <AknsDrawUtils.h> |
|
35 #include <AknsControlContext.h> |
|
36 #include <aknlists.h> |
|
37 #include <eikpanic.h> |
|
38 #include <eikcoctlpanic.h> |
|
39 #include <aknlayoutscalable_avkon.cdl.h> |
|
40 |
|
41 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
42 #include <aknlistloadertfx.h> |
|
43 #include <aknlistboxtfxinternal.h> |
|
44 #endif //RD_UI_TRANSITION_EFFECTS_LIST |
|
45 #include <AknTasHook.h> |
|
46 |
|
47 //Start of Code Added for PhoneBook2 |
|
48 //Added for PhoneBook2 |
|
49 #include "cpbk2contactviewcustomlistboxdata.h" |
|
50 #include "cpbk2contactviewcustomlistboxitemdrawer.h" |
|
51 //End of Code Added for PhoneBook2 |
|
52 |
|
53 // |
|
54 // Class CPbk2ContactViewCustomListBoxItemDrawer |
|
55 // |
|
56 |
|
57 CPbk2ContactViewCustomListBoxItemDrawer::CPbk2ContactViewCustomListBoxItemDrawer() {} |
|
58 CPbk2ContactViewCustomListBoxItemDrawer::CPbk2ContactViewCustomListBoxItemDrawer(MTextListBoxModel* aTextListBoxModel, |
|
59 const CFont* aFont, |
|
60 CPbk2ContactViewCustomListBoxData* aColumnData ) |
|
61 : CTextListItemDrawer(aTextListBoxModel, aFont) |
|
62 { |
|
63 SetData(aColumnData); |
|
64 } |
|
65 |
|
66 CPbk2ContactViewCustomListBoxItemDrawer::~CPbk2ContactViewCustomListBoxItemDrawer() |
|
67 { |
|
68 delete iPropertyArray; |
|
69 } |
|
70 |
|
71 TSize CPbk2ContactViewCustomListBoxItemDrawer::MinimumCellSize() const |
|
72 { |
|
73 CPbk2ContactViewCustomListBoxData* data=ColumnData(); |
|
74 const TInt columns=data->LastColumn(); |
|
75 if (columns==-1) |
|
76 { |
|
77 return CTextListItemDrawer::MinimumCellSize(); |
|
78 } |
|
79 TInt width=0; |
|
80 TInt height=0; |
|
81 TBool graphicsColumn=EFalse; |
|
82 for (TInt ii=0;ii<=columns;ii++) |
|
83 { |
|
84 width+=data->ColumnWidthPixel(ii); |
|
85 if (data->ColumnIsGraphics(ii)) |
|
86 { |
|
87 graphicsColumn=ETrue; |
|
88 } |
|
89 else |
|
90 { |
|
91 const CFont* font=data->ColumnFont(ii); |
|
92 if(font) |
|
93 { |
|
94 height=Max(height,font->HeightInPixels()); |
|
95 } |
|
96 else |
|
97 { |
|
98 height=Max(height, iFont->HeightInPixels()); |
|
99 } |
|
100 } |
|
101 } |
|
102 if (graphicsColumn) |
|
103 { |
|
104 CArrayPtr<CGulIcon>* iconArray=data->IconArray(); |
|
105 if (iconArray) |
|
106 { |
|
107 const TInt count=iconArray->Count(); |
|
108 for (TInt jj=0;jj<count;jj++) |
|
109 height=Max(height,(*iconArray)[jj]->Bitmap()->SizeInPixels().iHeight); |
|
110 } |
|
111 } |
|
112 height = Max (iData->FontBoundValues().iHeightInPixels, height); |
|
113 height+=VerticalInterItemGap(); |
|
114 return TSize(width,height); |
|
115 } |
|
116 |
|
117 TInt CPbk2ContactViewCustomListBoxItemDrawer::ItemWidthInPixels(TInt /*aItemIndex*/) const |
|
118 { |
|
119 CPbk2ContactViewCustomListBoxData* data=ColumnData(); |
|
120 const TInt columns=data->LastColumn(); |
|
121 TInt itemWidth = 0; |
|
122 if (iDrawMark) |
|
123 { |
|
124 itemWidth += (iMarkColumnWidth + iMarkGutter); |
|
125 } |
|
126 for (TInt ii=0;ii<=columns;ii++) |
|
127 { |
|
128 if (!ColumnData()->ColumnIsOptional(ii)) |
|
129 { |
|
130 itemWidth+=data->ColumnWidthPixel(ii); |
|
131 } |
|
132 } |
|
133 return itemWidth; |
|
134 } |
|
135 |
|
136 void CPbk2ContactViewCustomListBoxItemDrawer::SetItemCellSize( |
|
137 const TSize& aSizeInPixels) |
|
138 { |
|
139 CTextListItemDrawer::SetItemCellSize( aSizeInPixels ); |
|
140 |
|
141 // Data needs the cell size to create/reconfigure highlight animations |
|
142 CPbk2ContactViewCustomListBoxData* data = ColumnData(); |
|
143 data->SetItemCellSize( iItemCellSize ); |
|
144 } |
|
145 |
|
146 void CPbk2ContactViewCustomListBoxItemDrawer::DrawCurrentItemRect(const TRect& aRect) const |
|
147 // |
|
148 // Draw the item background |
|
149 // |
|
150 { |
|
151 iGc->SetClippingRect(iViewRect); |
|
152 iGc->SetBrushStyle(CGraphicsContext::ENullBrush); |
|
153 iGc->SetPenColor(iHighlightedBackColor); // KDefaultLbxHighlightRectColor |
|
154 iGc->DrawRect(aRect); |
|
155 iGc->CancelClippingRect(); |
|
156 } |
|
157 |
|
158 /** |
|
159 * Returns a pointer to the column data. Does not imply transfer of ownership. |
|
160 * |
|
161 * @since ER5U |
|
162 */ |
|
163 CPbk2ContactViewCustomListBoxData* CPbk2ContactViewCustomListBoxItemDrawer::ColumnData() const |
|
164 { |
|
165 return STATIC_CAST(CPbk2ContactViewCustomListBoxData*,iData); |
|
166 } |
|
167 |
|
168 void CPbk2ContactViewCustomListBoxItemDrawer::DrawItemMark(TBool /*aItemIsSelected*/, TBool /*aViewIsDimmed*/, const TPoint& /*aMarkPos*/) const |
|
169 { |
|
170 // not used in S60 |
|
171 } |
|
172 |
|
173 |
|
174 void CPbk2ContactViewCustomListBoxItemDrawer::DrawItemText( TInt aItemIndex, |
|
175 const TRect& aItemTextRect, |
|
176 TBool aItemIsCurrent, |
|
177 TBool /*aViewIsEmphasized*/, |
|
178 TBool aItemIsSelected ) const |
|
179 // |
|
180 // Draw the items text |
|
181 // |
|
182 { |
|
183 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
184 MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc ); |
|
185 if ( transApi ) |
|
186 { |
|
187 transApi->StartDrawing( MAknListBoxTfxInternal::EListNotSpecified ); |
|
188 } |
|
189 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
190 iGc->SetPenColor(iTextColor); |
|
191 iGc->SetBrushColor(iBackColor); |
|
192 TPtrC temp=iModel->ItemText(aItemIndex); |
|
193 SetupGc(aItemIndex); |
|
194 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
195 if ( transApi ) |
|
196 { |
|
197 transApi->StopDrawing(); |
|
198 } |
|
199 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
200 |
|
201 TBufC<256> target(KNullDesC); |
|
202 // SERIES60 ITEM MARKS! SAPLAF (the same code is in eikfrlb.cpp and eikclb.cpp) |
|
203 TPtrC repl; |
|
204 TInt pos = -1; |
|
205 |
|
206 TBool removeicon = (!aItemIsSelected && !ItemMarkReverse()) || (aItemIsSelected && ItemMarkReverse()); |
|
207 if ( Flags() & EDrawMarkSelection && ItemMarkPosition() != -1 && removeicon) |
|
208 { |
|
209 repl.Set( ItemMarkReplacement() ); |
|
210 pos = ItemMarkPosition(); |
|
211 } |
|
212 |
|
213 // Try to allocate buffer dynamically. If out of memory, use the fixed size stack buffer. |
|
214 // (+1 is for the last column separator) |
|
215 TInt size = temp.Length() + repl.Length() + 1; |
|
216 if ( pos >= 0 ) |
|
217 { |
|
218 size += pos; // space for other column separators |
|
219 } |
|
220 |
|
221 HBufC* buffer = NULL; |
|
222 if ( size > 256 ) |
|
223 { |
|
224 buffer = HBufC::New( size ); |
|
225 } |
|
226 |
|
227 TPtr des = ( buffer ? buffer->Des() : target.Des() ); |
|
228 // Note that ReplaceColumn does not update correct length in variable 'des', |
|
229 // because it is not a reference parameter :( |
|
230 AknLAFUtils::ReplaceColumn(des, &temp, &repl, '\t', pos); |
|
231 des.Set( buffer ? buffer->Des() : target.Des() ); |
|
232 |
|
233 // END OF ITEM MARKS! SAPLAF |
|
234 |
|
235 CPbk2ContactViewCustomListBoxData::TColors colors; |
|
236 colors.iText=iTextColor; |
|
237 colors.iBack=iBackColor; |
|
238 colors.iHighlightedText=iHighlightedTextColor; |
|
239 colors.iHighlightedBack=iHighlightedBackColor; |
|
240 |
|
241 if (ColumnData()->CurrentMarqueeItemIndex() != aItemIndex && aItemIsCurrent) |
|
242 { |
|
243 ColumnData()->ResetMarquee(); |
|
244 ColumnData()->SetCurrentMarqueeItemIndex(aItemIndex); |
|
245 } |
|
246 ColumnData()->SetCurrentItemIndex(aItemIndex); |
|
247 ColumnData()->Draw(Properties(aItemIndex), *iGc,&des,aItemTextRect,(aItemIsCurrent /*|| aViewIsEmphasized*/),colors, aItemIndex); |
|
248 |
|
249 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
250 if ( transApi ) |
|
251 { |
|
252 transApi->StartDrawing( MAknListBoxTfxInternal::EListNotSpecified ); |
|
253 } |
|
254 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
255 iGc->DiscardFont(); |
|
256 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
257 if ( transApi ) |
|
258 { |
|
259 transApi->StopDrawing(); |
|
260 } |
|
261 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
262 // end of SERIES60 LAF code. |
|
263 |
|
264 delete buffer; |
|
265 } |
|
266 |
|
267 TAny* CPbk2ContactViewCustomListBoxItemDrawer::Reserved_1() |
|
268 { |
|
269 return NULL; |
|
270 } |
|
271 |
|
272 |
|
273 void CPbk2ContactViewCustomListBoxItemDrawer::ClearAllPropertiesL() |
|
274 { |
|
275 delete iPropertyArray; |
|
276 iPropertyArray = NULL; |
|
277 iPropertyArray = new (ELeave) CArrayFixFlat<SListProperties>(2); |
|
278 } |
|
279 |
|
280 void CPbk2ContactViewCustomListBoxItemDrawer::SetPropertiesL(TInt aItemIndex, TListItemProperties aProperty) |
|
281 { |
|
282 if (!iPropertyArray) ClearAllPropertiesL(); |
|
283 TInt index; |
|
284 TKeyArrayFix key(0,ECmpTInt); |
|
285 SListProperties prop; |
|
286 prop.iItem = aItemIndex; |
|
287 |
|
288 if (iPropertyArray->FindIsq(prop, key, index)) |
|
289 { |
|
290 iPropertyArray->InsertIsqL(prop, key); |
|
291 iPropertyArray->FindIsq(prop, key, index); |
|
292 } |
|
293 iPropertyArray->At(index).iProperties = aProperty; |
|
294 } |
|
295 |
|
296 |
|
297 TListItemProperties CPbk2ContactViewCustomListBoxItemDrawer::Properties(TInt aItemIndex) const |
|
298 { |
|
299 if (!iPropertyArray) return CTextListItemDrawer::Properties(aItemIndex); |
|
300 CAknListBoxFilterItems *filter = STATIC_CAST(CAknFilteredTextListBoxModel*,iModel)->Filter(); |
|
301 if (filter) |
|
302 { |
|
303 aItemIndex = filter->FilteredItemIndex(aItemIndex); |
|
304 } |
|
305 TKeyArrayFix key(0,ECmpTInt); |
|
306 SListProperties prop; |
|
307 prop.iItem = aItemIndex; |
|
308 TInt index; |
|
309 if (iPropertyArray->FindIsq(prop, key, index)) return CTextListItemDrawer::Properties(aItemIndex); |
|
310 return iPropertyArray->At(index).iProperties; |
|
311 } |
|
312 |
|
313 void CPbk2ContactViewCustomListBoxItemDrawer::CPbk2ContactViewCustomListBoxItemDrawer_Reserved() |
|
314 { |
|
315 } |
|
316 |
|
317 // End of File |