|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <ganes/HgScrollerWithTitle.h> |
|
21 #include <ganes/HgDoubleGraphicList.h> |
|
22 #include <ganes/HgDoubleTextList.h> |
|
23 #include <ganes/HgSingleGraphicList.h> |
|
24 #include <ganes/HgSingleLargeList.h> |
|
25 #include <ganes/HgSingleTextList.h> |
|
26 #include <ganes/HgSingleTextListWithIcon.h> |
|
27 #include <ganes/HgGrid.h> |
|
28 #include <ganes/HgItem.h> |
|
29 |
|
30 #include "HgConstants.h" |
|
31 #include "HgLayoutData.h" |
|
32 |
|
33 #include <ganes.mbg> |
|
34 |
|
35 #include <AknIconUtils.h> |
|
36 #include <avkon.mbg> |
|
37 #include <AknsDrawUtils.h> |
|
38 #include <touchfeedback.h> |
|
39 #include <gulicon.h> |
|
40 #include <AknUtils.h> |
|
41 #include <layoutmetadata.cdl.h> |
|
42 #include <aknlayoutscalable_avkon.cdl.h> |
|
43 #include <AknLayout2ScalableDef.h> |
|
44 |
|
45 using namespace AknLayoutScalable_Avkon; |
|
46 |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CHgScrollerWithTitle::NewL() |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CHgScrollerWithTitle* CHgScrollerWithTitle::NewL( |
|
55 const TRect& aRect, |
|
56 TInt aItemCount, |
|
57 THgScrollerType aScrollerType, |
|
58 CGulIcon* aDefaultIcon ) |
|
59 { |
|
60 CHgScrollerWithTitle* self = new (ELeave) CHgScrollerWithTitle(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( aRect, aItemCount, aScrollerType, aDefaultIcon ); |
|
63 CleanupStack::Pop( self ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CHgScrollerWithTitle::ConstructL() |
|
69 // Symbian 2nd phase constructor can leave. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CHgScrollerWithTitle::ConstructL (const TRect& aRect, |
|
73 TInt aItemCount, |
|
74 THgScrollerType aScrollerType, |
|
75 CGulIcon* aDefaultIcon ) |
|
76 { |
|
77 // Create a window for this application view |
|
78 CreateWindowL ( ); |
|
79 |
|
80 switch( aScrollerType ) |
|
81 { |
|
82 case EHgScrollerDoubleGraphicList: |
|
83 { |
|
84 iScroller = |
|
85 CHgDoubleGraphicList::NewL( aRect, aItemCount, aDefaultIcon ); |
|
86 break; |
|
87 } |
|
88 case EHgScrollerDoubleTextList: |
|
89 { |
|
90 iScroller = |
|
91 CHgDoubleTextList::NewL( aRect, aItemCount, aDefaultIcon ); |
|
92 break; |
|
93 } |
|
94 case EHgScrollerSingleGraphicList: |
|
95 { |
|
96 iScroller = |
|
97 CHgSingleGraphicList::NewL( aRect, aItemCount, aDefaultIcon ); |
|
98 break; |
|
99 } |
|
100 case EHgScrollerSingleLargeList: |
|
101 { |
|
102 iScroller = |
|
103 CHgSingleLargeList::NewL( aRect, aItemCount, aDefaultIcon ); |
|
104 break; |
|
105 } |
|
106 case EHgScrollerSingleTextList: |
|
107 { |
|
108 iScroller = |
|
109 CHgSingleTextList::NewL( aRect, aItemCount, aDefaultIcon ); |
|
110 break; |
|
111 } |
|
112 case EHgScrollerGrid: |
|
113 { |
|
114 iScroller = |
|
115 CHgGrid::NewL( aRect, aItemCount, aDefaultIcon ); |
|
116 break; |
|
117 } |
|
118 case EHgScrollerSingleTextListWithIcon: |
|
119 { |
|
120 iScroller = |
|
121 CHgSingleTextListWithIcon::NewL( aRect, aItemCount, aDefaultIcon ); |
|
122 break; |
|
123 } |
|
124 case EHgScrollerDoubleGraphicListFlat: |
|
125 { |
|
126 iScroller = |
|
127 CHgDoubleGraphicList::NewL( aRect, aItemCount, aDefaultIcon ); |
|
128 break; |
|
129 } |
|
130 default: |
|
131 User::Leave( KErrArgument ); |
|
132 } |
|
133 |
|
134 iScroller->SetMopParent( this ); |
|
135 |
|
136 iLayoutData = CHgListLayoutData::NewL(); |
|
137 iTitleItem = CHgItem::NewL( ); |
|
138 |
|
139 ActivateL(); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CHgScrollerWithTitle::Scroller() |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C CHgScroller& CHgScrollerWithTitle::Scroller() |
|
147 { |
|
148 return *iScroller; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CHgScrollerWithTitle::InitScreenL() |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C void CHgScrollerWithTitle::InitScreenL( const TRect& aRect ) |
|
156 { |
|
157 // Set the windows size |
|
158 SetRect ( aRect ); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CHgScrollerWithTitle::TitleItem() |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C CHgItem& CHgScrollerWithTitle::TitleItem() |
|
166 { |
|
167 return *iTitleItem; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CHgScrollerWithTitle::CHgScrollerWithTitle() |
|
172 // C++ default constructor can NOT contain any code, that might leave. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 CHgScrollerWithTitle::CHgScrollerWithTitle() |
|
176 { |
|
177 // No implementation required |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CHgScrollerWithTitle::~CHgScrollerWithTitle() |
|
182 // Destructor. |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 EXPORT_C CHgScrollerWithTitle::~CHgScrollerWithTitle ( ) |
|
186 { |
|
187 delete iLayoutData; |
|
188 delete iScroller; |
|
189 delete iTitleItem; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CHgScrollerWithTitle::Draw() |
|
194 // Draws the display. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CHgScrollerWithTitle::Draw ( const TRect& /*aRect*/ ) const |
|
198 { |
|
199 // Draw background skin |
|
200 CWindowGc& gc = SystemGc(); |
|
201 |
|
202 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
203 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); |
|
204 AknsDrawUtils::DrawBackground( skin, cc, this, gc, |
|
205 TPoint(0,0), iTitleRect, KAknsDrawParamDefault ); |
|
206 |
|
207 // Draw background rect. Rect is just a little smaller |
|
208 // than the actual item slot. |
|
209 TRect recthg(iTitleRect); |
|
210 TRect rect(recthg); |
|
211 rect.Shrink(2,2); |
|
212 AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), |
|
213 gc, |
|
214 recthg, |
|
215 rect, |
|
216 KAknsIIDQsnFrPopup, |
|
217 KAknsIIDQsnFrPopupCenter ); |
|
218 |
|
219 // Draw title icon if it exists. |
|
220 CGulIcon* icon = iTitleItem->Icon(); |
|
221 |
|
222 if(icon) |
|
223 { |
|
224 // Draw the icon |
|
225 TAknLayoutRect image; |
|
226 image.LayoutRect(iTitleRect, iLayoutData->IconLayout()); |
|
227 image.DrawImage(gc, icon->Bitmap(), icon->Mask()); |
|
228 } |
|
229 |
|
230 // Draw first text line. |
|
231 TAknLayoutText textLayout; |
|
232 textLayout.LayoutText(iTitleRect, iLayoutData->TitleLayout(0) ); |
|
233 textLayout.DrawText(gc, iTitleItem->Title(), ETrue, iColor ); |
|
234 |
|
235 // Draw second text line. |
|
236 textLayout.LayoutText(iTitleRect, iLayoutData->TextLayout() ); |
|
237 textLayout.DrawText(gc, iTitleItem->Text(), ETrue, iColor ); |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CHgScrollerWithTitle::SizeChanged() |
|
242 // Called by framework when the view size is changed. |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CHgScrollerWithTitle::SizeChanged ( ) |
|
246 { |
|
247 // Initialize layout data object |
|
248 iLayoutData->SetItemLayout(list_double_large_graphic_pane( 0 )); |
|
249 iLayoutData->SetIconLayout(list_double_large_graphic_pane_g1( 2 )); |
|
250 for(TInt i = 0; i <= KMaxNumberOfTitleIndicators; ++i) |
|
251 iLayoutData->SetTitleLayout(i, list_double_large_graphic_pane_t1( i )); |
|
252 iLayoutData->SetTextLayout(list_double_large_graphic_pane_t2( 2 )); |
|
253 iLayoutData->SetFirstIndicatorLayout(list_double_large_graphic_pane_g3(0)); |
|
254 iLayoutData->SetSecondIndicatorLayout(list_double_large_graphic_pane_g2(0)); |
|
255 iLayoutData->SetBaseLayout(AknLayoutScalable_Avkon::list_gen_pane(0)); |
|
256 |
|
257 TAknLayoutRect layout; |
|
258 layout.LayoutRect(Rect(), iLayoutData->ItemLayout()); |
|
259 |
|
260 // Rect for the title item. |
|
261 iTitleRect = layout.Rect(); |
|
262 |
|
263 // Set size for the compound control. |
|
264 TRect scrollerRect( PositionRelativeToScreen(), Size() ); |
|
265 scrollerRect.iTl.iY += iTitleRect.Height(); |
|
266 TRAP_IGNORE( iScroller->InitScreenL( scrollerRect ); ) |
|
267 |
|
268 // Resolve color for normal items |
|
269 if ( AknsUtils::AvkonSkinEnabled() ) |
|
270 { |
|
271 // this does not modify color unless it gets a correct one |
|
272 // no real need to check errors |
|
273 AknsUtils::GetCachedColor( |
|
274 AknsUtils::SkinInstance(), |
|
275 iColor, |
|
276 KAknsIIDQsnTextColors, |
|
277 EAknsCIQsnTextColorsCG6 ); |
|
278 } |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CHgScrollerWithTitle::CountComponentControls() |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 TInt CHgScrollerWithTitle::CountComponentControls() const |
|
286 { |
|
287 // We have only one child |
|
288 return 1; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CHgScrollerWithTitle::ComponentControl() |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 CCoeControl* CHgScrollerWithTitle::ComponentControl(TInt aIndex) const |
|
296 { |
|
297 if( aIndex == 0 ) |
|
298 { |
|
299 return iScroller; |
|
300 } |
|
301 |
|
302 return NULL; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CHgScrollerWithTitle::ComponentControl() |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 void CHgScrollerWithTitle::FocusChanged(TDrawNow aDrawNow) |
|
310 { |
|
311 if(iScroller) |
|
312 { |
|
313 iScroller->SetFocus(IsFocused(), aDrawNow); |
|
314 } |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CHgScrollerWithTitle::OfferKeyEventL() |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 TKeyResponse CHgScrollerWithTitle::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
322 { |
|
323 // send key events to children. |
|
324 return iScroller->OfferKeyEventL( aKeyEvent, aType ); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CHgScrollerWithTitle::PreferredImageSize() |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 EXPORT_C TSize CHgScrollerWithTitle::PreferredImageSize() |
|
332 { |
|
333 // Fetch icon size from the layout. |
|
334 TAknLayoutRect image; |
|
335 image.LayoutRect(TRect(), AknLayoutScalable_Avkon::list_double_large_graphic_pane_g1( 2 )); |
|
336 return image.Rect().Size(); |
|
337 } |
|
338 |
|
339 |
|
340 // End of File |