|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikfrlbd.h> |
|
20 |
|
21 #include "mmgridview.h" |
|
22 #include "mmgrid.h" |
|
23 #include "mmlistboxitemdrawer.h" |
|
24 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
25 #include <aknlistloadertfx.h> |
|
26 #include <aknlistboxtfxinternal.h> |
|
27 #endif |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CMmGridView::CMmGridView() : |
|
35 iLastCurMove( ECursorFirstItem ), iOldIndex( KErrNotFound ) |
|
36 { |
|
37 // No implementation required |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CMmGridView::~CMmGridView() |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CMmGridView* CMmGridView::NewLC() |
|
53 { |
|
54 CMmGridView* self = new (ELeave)CMmGridView(); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CMmGridView* CMmGridView::NewL() |
|
65 { |
|
66 CMmGridView* self = CMmGridView::NewLC(); |
|
67 CleanupStack::Pop( self ); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CMmGridView::ConstructL() |
|
76 { |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CMmGridView::DrawItem(TInt aItemIndex) const |
|
84 { |
|
85 CMmListBoxItemDrawer* itemDrawer = |
|
86 STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() ); |
|
87 TSize size = itemDrawer->GetItemSize( 0, ETrue ); |
|
88 if ( itemDrawer->ItemCellSize() != size ) |
|
89 { |
|
90 const_cast<CMmGridView*>( this )->SetItemHeight(size.iHeight); |
|
91 const_cast<CMmGridView*>( this )->SetColumnWidth(size.iWidth); |
|
92 } |
|
93 |
|
94 CAknGridView::DrawItem( aItemIndex ); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TPoint CMmGridView::ItemPos( TInt aItemIndex ) const |
|
102 { |
|
103 if ( aItemIndex < 0 ) |
|
104 { |
|
105 // let avkon handle the insane cases |
|
106 return CAknGridView::ItemPos( aItemIndex ); |
|
107 } |
|
108 |
|
109 if ( AknLayoutUtils::LayoutMirrored() ) |
|
110 { |
|
111 const TInt colNum = NumberOfColsInView(); |
|
112 TInt itemCol = aItemIndex % colNum; |
|
113 TInt mirroredItemCol = colNum - itemCol - 1; |
|
114 aItemIndex = aItemIndex - itemCol + mirroredItemCol; |
|
115 } |
|
116 |
|
117 // return CAknGridView::ItemPos( aItemIndex ); |
|
118 return CorrectItemPos( aItemIndex ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TPoint CMmGridView::CorrectItemPos( TInt aItemIndex ) const |
|
126 { |
|
127 // it the assertion below fails, review this implementation to make sure that |
|
128 // primary vertical case is handled correctly |
|
129 ASSERT( !IsPrimaryVertical() ); |
|
130 |
|
131 ASSERT( aItemIndex >= 0 ); |
|
132 const TInt colNum = NumberOfColsInView(); |
|
133 TInt itemRow = aItemIndex / colNum; |
|
134 TInt itemCol = aItemIndex % colNum; |
|
135 |
|
136 TInt topItemRow = TopItemIndex() / colNum; |
|
137 // __ASSERT_DEBUG( TopItemIndex() % colNum == 0, User::Invariant() ); |
|
138 |
|
139 // it is safe to assume that size between items is (0, 0) because we |
|
140 // explicitly set such value in CMmGrid::DoSetupLayoutL |
|
141 const TSize sizeBetweenItems( 0, 0 ); |
|
142 |
|
143 TPoint itemPos( |
|
144 iViewRect.iTl.iX + itemCol * |
|
145 ( ColumnWidth() + sizeBetweenItems.iWidth ), |
|
146 iViewRect.iTl.iY + (itemRow - topItemRow) * |
|
147 ( iItemHeight + sizeBetweenItems.iHeight ) + iVerticalOffset ); |
|
148 |
|
149 return itemPos; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TBool CMmGridView::XYPosToItemIndex( TPoint aPosition, TInt& aItemIndex ) const |
|
157 { |
|
158 if ( AknLayoutUtils::LayoutMirrored() ) |
|
159 { |
|
160 aPosition.iX = iViewRect.Width() - ( aPosition.iX - iViewRect.iTl.iX ); |
|
161 } |
|
162 return CAknGridView::XYPosToItemIndex( aPosition, aItemIndex ); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 CWindowGc* CMmGridView::Gc() |
|
170 { |
|
171 return iGc; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CMmGridView::MoveCursorL( TCursorMovement aCursorMovement, |
|
179 TSelectionMode aSelectionMode ) |
|
180 { |
|
181 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
182 iLastCurMove = aCursorMovement; |
|
183 iOldIndex = iCurrentItemIndex; |
|
184 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
185 |
|
186 CAknGridView::MoveCursorL( aCursorMovement, aSelectionMode ); |
|
187 |
|
188 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
189 iLastCurMove = ECursorFirstItem; |
|
190 iOldIndex = KErrNotFound; |
|
191 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CMmGridView::UpdateSelectionL( TSelectionMode aSelectionMode ) |
|
199 { |
|
200 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
201 if ( AknLayoutUtils::LayoutMirrored() ) |
|
202 { |
|
203 MAknListBoxTfxInternal* api = CAknListLoader::TfxApiInternal( Gc() ); |
|
204 TInt row( 0 ); |
|
205 TInt col( 0 ); |
|
206 TInt newRow( 0 ); |
|
207 TInt newCol( 0 ); |
|
208 LogicalPosFromListBoxIndex( iOldIndex, row, col ); |
|
209 LogicalPosFromListBoxIndex( iCurrentItemIndex, newRow, newCol ); |
|
210 if ( api ) |
|
211 { |
|
212 if ( iLastCurMove == CAknGridView::ECursorNextColumn ) |
|
213 { |
|
214 if ( newCol < col || newRow != row ) |
|
215 api->SetMoveType( MAknListBoxTfxInternal::EListNoMovement ); |
|
216 } |
|
217 else if ( iLastCurMove == CAknGridView::ECursorPreviousColumn ) |
|
218 { |
|
219 if ( newCol > col || newRow != row ) |
|
220 api->SetMoveType( MAknListBoxTfxInternal::EListNoMovement ); |
|
221 } |
|
222 } |
|
223 } |
|
224 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
225 |
|
226 CAknGridView::UpdateSelectionL( aSelectionMode ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CMmGridView::Draw(const TRect* aClipRect) const |
|
234 { |
|
235 DoDraw( aClipRect ); |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CMmGridView::DoDraw(const TRect* aClipRect) const |
|
243 { |
|
244 CMmListBoxItemDrawer* itemDrawer = static_cast< CMmListBoxItemDrawer*> ( ItemDrawer() ); |
|
245 TBool drawingInitiated(EFalse); |
|
246 if ( CAknEnv::Static()->TransparencyEnabled() && |
|
247 iWin && iWin->GetDrawRect() == TRect::EUninitialized ) |
|
248 { |
|
249 TRect a; |
|
250 if (!aClipRect || *aClipRect == TRect(0,0,0,0) ) |
|
251 { |
|
252 a = ViewRect(); |
|
253 aClipRect = &a; |
|
254 } |
|
255 |
|
256 drawingInitiated=ETrue; |
|
257 iWin->Invalidate( *aClipRect ); |
|
258 iWin->BeginRedraw( *aClipRect ); |
|
259 } |
|
260 CAknGridView::Draw( aClipRect ); |
|
261 |
|
262 if ( aClipRect ) |
|
263 { |
|
264 TRect rect(*aClipRect); |
|
265 TInt lastItemInView = (iModel->NumberOfItems() <= BottomItemIndex() ) |
|
266 ? iModel->NumberOfItems()-1 : BottomItemIndex(); |
|
267 rect.iTl.iY = ItemPos( lastItemInView ).iY + ItemSize( lastItemInView ).iHeight; |
|
268 // iGc->SetClippingRect( rect ); |
|
269 // removed to prevent non-redraw drawing. Was present to prevent out of view drawing when effects are on. |
|
270 // could be removed because effects were disabled at some point in edit mode to enhance performance. |
|
271 itemDrawer->DrawFloatingItems( rect ); |
|
272 // iGc->CancelClippingRect(); |
|
273 } |
|
274 |
|
275 // if (aClipRect) |
|
276 // { |
|
277 // const_cast< CMmGridView* >(this)->Gc()->DrawRect(*aClipRect); |
|
278 // } |
|
279 |
|
280 if ( CAknEnv::Static()->TransparencyEnabled() && |
|
281 iWin && drawingInitiated ) |
|
282 { |
|
283 drawingInitiated = EFalse; |
|
284 iWin->EndRedraw( ); |
|
285 } |
|
286 |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 TInt CMmGridView::VerticalItemOffset() const |
|
294 { |
|
295 return iVerticalOffset; |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 void CMmGridView::SetItemHeight(TInt aItemHeight) |
|
303 { |
|
304 // we need to update the iItemHeight member in grid also (there are two different item height value holders - in grid and here in grid view) |
|
305 CMmListBoxItemDrawer* itemDrawer = |
|
306 STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() ); |
|
307 static_cast<CMmGrid*>(itemDrawer->Widget())->SetItemHeight( aItemHeight ); |
|
308 |
|
309 CAknGridView::SetItemHeight(aItemHeight); |
|
310 } |
|
311 |
|
312 //End of file |