34
|
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 |
TPoint CMmGridView::ItemPos( TInt aItemIndex ) const
|
|
84 |
{
|
|
85 |
if ( aItemIndex < 0 )
|
|
86 |
{
|
|
87 |
// let avkon handle the insane cases
|
|
88 |
return CAknGridView::ItemPos( aItemIndex );
|
|
89 |
}
|
|
90 |
|
|
91 |
if ( AknLayoutUtils::LayoutMirrored() )
|
|
92 |
{
|
|
93 |
const TInt colNum = NumberOfColsInView();
|
|
94 |
TInt itemCol = aItemIndex % colNum;
|
|
95 |
TInt mirroredItemCol = colNum - itemCol - 1;
|
|
96 |
aItemIndex = aItemIndex - itemCol + mirroredItemCol;
|
|
97 |
}
|
|
98 |
|
|
99 |
// return CAknGridView::ItemPos( aItemIndex );
|
|
100 |
return CorrectItemPos( aItemIndex );
|
|
101 |
}
|
|
102 |
|
|
103 |
// -----------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
TPoint CMmGridView::CorrectItemPos( TInt aItemIndex ) const
|
|
108 |
{
|
|
109 |
// it the assertion below fails, review this implementation to make sure that
|
|
110 |
// primary vertical case is handled correctly
|
|
111 |
ASSERT( !IsPrimaryVertical() );
|
|
112 |
|
|
113 |
ASSERT( aItemIndex >= 0 );
|
|
114 |
const TInt colNum = NumberOfColsInView();
|
|
115 |
TInt itemRow = aItemIndex / colNum;
|
|
116 |
TInt itemCol = aItemIndex % colNum;
|
|
117 |
|
|
118 |
TInt topItemRow = TopItemIndex() / colNum;
|
|
119 |
// __ASSERT_DEBUG( TopItemIndex() % colNum == 0, User::Invariant() );
|
|
120 |
|
|
121 |
// it is safe to assume that size between items is (0, 0) because we
|
|
122 |
// explicitly set such value in CMmGrid::DoSetupLayoutL
|
|
123 |
const TSize sizeBetweenItems( 0, 0 );
|
|
124 |
|
|
125 |
TPoint itemPos(
|
|
126 |
iViewRect.iTl.iX + itemCol *
|
|
127 |
( ColumnWidth() + sizeBetweenItems.iWidth ),
|
|
128 |
iViewRect.iTl.iY + (itemRow - topItemRow) *
|
|
129 |
( iItemHeight + sizeBetweenItems.iHeight ) + iVerticalOffset );
|
|
130 |
|
|
131 |
return itemPos;
|
|
132 |
}
|
|
133 |
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
// -----------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
TBool CMmGridView::XYPosToItemIndex( TPoint aPosition, TInt& aItemIndex ) const
|
|
139 |
{
|
|
140 |
if ( AknLayoutUtils::LayoutMirrored() )
|
|
141 |
{
|
|
142 |
aPosition.iX = iViewRect.Width() - ( aPosition.iX - iViewRect.iTl.iX );
|
|
143 |
}
|
|
144 |
return CAknGridView::XYPosToItemIndex( aPosition, aItemIndex );
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
CWindowGc* CMmGridView::Gc()
|
|
152 |
{
|
|
153 |
return iGc;
|
|
154 |
}
|
|
155 |
|
|
156 |
// -----------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
// -----------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
void CMmGridView::MoveCursorL( TCursorMovement aCursorMovement,
|
|
161 |
TSelectionMode aSelectionMode )
|
|
162 |
{
|
|
163 |
#ifdef RD_UI_TRANSITION_EFFECTS_LIST
|
|
164 |
iLastCurMove = aCursorMovement;
|
|
165 |
iOldIndex = iCurrentItemIndex;
|
|
166 |
#endif // RD_UI_TRANSITION_EFFECTS_LIST
|
|
167 |
|
|
168 |
CAknGridView::MoveCursorL( aCursorMovement, aSelectionMode );
|
|
169 |
|
|
170 |
#ifdef RD_UI_TRANSITION_EFFECTS_LIST
|
|
171 |
iLastCurMove = ECursorFirstItem;
|
|
172 |
iOldIndex = KErrNotFound;
|
|
173 |
#endif // RD_UI_TRANSITION_EFFECTS_LIST
|
|
174 |
}
|
|
175 |
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
void CMmGridView::UpdateSelectionL( TSelectionMode aSelectionMode )
|
|
181 |
{
|
|
182 |
#ifdef RD_UI_TRANSITION_EFFECTS_LIST
|
|
183 |
if ( AknLayoutUtils::LayoutMirrored() )
|
|
184 |
{
|
|
185 |
MAknListBoxTfxInternal* api = CAknListLoader::TfxApiInternal( Gc() );
|
|
186 |
TInt row( 0 );
|
|
187 |
TInt col( 0 );
|
|
188 |
TInt newRow( 0 );
|
|
189 |
TInt newCol( 0 );
|
|
190 |
LogicalPosFromListBoxIndex( iOldIndex, row, col );
|
|
191 |
LogicalPosFromListBoxIndex( iCurrentItemIndex, newRow, newCol );
|
|
192 |
if ( api )
|
|
193 |
{
|
|
194 |
if ( iLastCurMove == CAknGridView::ECursorNextColumn )
|
|
195 |
{
|
|
196 |
if ( newCol < col || newRow != row )
|
|
197 |
api->SetMoveType( MAknListBoxTfxInternal::EListNoMovement );
|
|
198 |
}
|
|
199 |
else if ( iLastCurMove == CAknGridView::ECursorPreviousColumn )
|
|
200 |
{
|
|
201 |
if ( newCol > col || newRow != row )
|
|
202 |
api->SetMoveType( MAknListBoxTfxInternal::EListNoMovement );
|
|
203 |
}
|
|
204 |
}
|
|
205 |
}
|
|
206 |
#endif // RD_UI_TRANSITION_EFFECTS_LIST
|
|
207 |
|
|
208 |
CAknGridView::UpdateSelectionL( aSelectionMode );
|
|
209 |
}
|
|
210 |
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
//
|
|
213 |
// -----------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
void CMmGridView::Draw(const TRect* aClipRect) const
|
|
216 |
{
|
|
217 |
const_cast<CMmGridView*>( this )->UpdateItemHeightAndWidth();
|
|
218 |
DoDraw( aClipRect );
|
|
219 |
}
|
|
220 |
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
void CMmGridView::DoDraw(const TRect* aClipRect) const
|
|
226 |
{
|
|
227 |
CMmListBoxItemDrawer* itemDrawer = static_cast< CMmListBoxItemDrawer*> ( ItemDrawer() );
|
|
228 |
TBool drawingInitiated(EFalse);
|
|
229 |
if ( CAknEnv::Static()->TransparencyEnabled() &&
|
|
230 |
iWin && iWin->GetDrawRect() == TRect::EUninitialized )
|
|
231 |
{
|
|
232 |
TRect a;
|
|
233 |
if (!aClipRect || *aClipRect == TRect(0,0,0,0) )
|
|
234 |
{
|
|
235 |
a = ViewRect();
|
|
236 |
aClipRect = &a;
|
|
237 |
}
|
|
238 |
|
|
239 |
drawingInitiated=ETrue;
|
|
240 |
iWin->Invalidate( *aClipRect );
|
|
241 |
iWin->BeginRedraw( *aClipRect );
|
|
242 |
}
|
|
243 |
|
|
244 |
if ( !itemDrawer->IsEditMode() )
|
|
245 |
{
|
|
246 |
itemDrawer->DrawBackground(ViewRect());
|
|
247 |
itemDrawer->SetRedrawItemBackground( EFalse );
|
|
248 |
CAknGridView::Draw( aClipRect );
|
|
249 |
itemDrawer->SetRedrawItemBackground( ETrue );
|
|
250 |
}
|
|
251 |
else
|
|
252 |
{
|
|
253 |
CAknGridView::Draw( aClipRect );
|
|
254 |
}
|
|
255 |
|
|
256 |
if ( aClipRect )
|
|
257 |
{
|
|
258 |
TRect rect(*aClipRect);
|
|
259 |
TInt lastItemInView = (iModel->NumberOfItems() <= BottomItemIndex() )
|
|
260 |
? iModel->NumberOfItems()-1 : BottomItemIndex();
|
|
261 |
rect.iTl.iY = ItemPos( lastItemInView ).iY + ItemSize( lastItemInView ).iHeight;
|
|
262 |
// iGc->SetClippingRect( rect );
|
|
263 |
// removed to prevent non-redraw drawing. Was present to prevent out of view drawing when effects are on.
|
|
264 |
// could be removed because effects were disabled at some point in edit mode to enhance performance.
|
|
265 |
itemDrawer->DrawFloatingItems( rect );
|
|
266 |
// iGc->CancelClippingRect();
|
|
267 |
}
|
|
268 |
|
|
269 |
// if (aClipRect)
|
|
270 |
// {
|
|
271 |
// const_cast< CMmGridView* >(this)->Gc()->DrawRect(*aClipRect);
|
|
272 |
// }
|
|
273 |
|
|
274 |
if ( CAknEnv::Static()->TransparencyEnabled() &&
|
|
275 |
iWin && drawingInitiated )
|
|
276 |
{
|
|
277 |
drawingInitiated = EFalse;
|
|
278 |
iWin->EndRedraw( );
|
|
279 |
}
|
|
280 |
|
|
281 |
}
|
|
282 |
|
|
283 |
// -----------------------------------------------------------------------------
|
|
284 |
//
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
TInt CMmGridView::VerticalItemOffset() const
|
|
288 |
{
|
|
289 |
return iVerticalOffset;
|
|
290 |
}
|
|
291 |
|
|
292 |
// -----------------------------------------------------------------------------
|
|
293 |
//
|
|
294 |
// -----------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
void CMmGridView::SetItemHeight(TInt aItemHeight)
|
|
297 |
{
|
|
298 |
// 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)
|
|
299 |
CMmListBoxItemDrawer* itemDrawer =
|
|
300 |
STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() );
|
|
301 |
static_cast<CMmGrid*>(itemDrawer->Widget())->SetItemHeight( aItemHeight );
|
|
302 |
|
|
303 |
CAknGridView::SetItemHeight(aItemHeight);
|
|
304 |
}
|
|
305 |
|
|
306 |
// -----------------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
// -----------------------------------------------------------------------------
|
|
309 |
//
|
|
310 |
void CMmGridView::UpdateItemHeightAndWidth()
|
|
311 |
{
|
|
312 |
if ( iModel && iModel->NumberOfItems() )
|
|
313 |
{
|
|
314 |
CMmListBoxItemDrawer* itemDrawer =
|
|
315 |
STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() );
|
|
316 |
TSize size = itemDrawer->GetItemSize( 0, EFalse );
|
|
317 |
if ( itemDrawer->ItemCellSize() != size )
|
|
318 |
{
|
|
319 |
const_cast<CMmGridView*>( this )->SetItemHeight( size.iHeight );
|
|
320 |
const_cast<CMmGridView*>( this )->SetColumnWidth( size.iWidth );
|
|
321 |
}
|
|
322 |
}
|
|
323 |
}
|
|
324 |
|
|
325 |
//End of file
|