|
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: highlight control class |
|
15 * |
|
16 */ |
|
17 #include <eiklbi.h> |
|
18 |
|
19 #include "mmhighlighttimer.h" |
|
20 #include "mmwidgetcontainer.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 CMmHighlightTimer::CMmHighlightTimer(CMmWidgetContainer* aContainer) : |
|
27 CActive(EPriorityStandard), iState(EInactivityState), |
|
28 iContainer( aContainer ) |
|
29 { |
|
30 } |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C CMmHighlightTimer* CMmHighlightTimer::NewLC( |
|
37 CMmWidgetContainer* aContainer) |
|
38 { |
|
39 ASSERT(aContainer); |
|
40 CMmHighlightTimer* self = new (ELeave) CMmHighlightTimer( aContainer ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CMmHighlightTimer* CMmHighlightTimer::NewL( |
|
51 CMmWidgetContainer* aContainer) |
|
52 { |
|
53 CMmHighlightTimer* self = CMmHighlightTimer::NewLC( aContainer ); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 void CMmHighlightTimer::ConstructL() |
|
63 { |
|
64 User::LeaveIfError( iTimer.CreateLocal() ); |
|
65 CActiveScheduler::Add( this ); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CMmHighlightTimer::~CMmHighlightTimer() |
|
73 { |
|
74 Cancel(); |
|
75 iTimer.Close(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CMmHighlightTimer::DoCancel() |
|
83 { |
|
84 if (iState == ETimerExpirationCompletionState) |
|
85 { |
|
86 iTimer.Cancel(); |
|
87 } |
|
88 else if (iState == EExternalCompletionState) |
|
89 { |
|
90 TRequestStatus* status = &iStatus; |
|
91 User::RequestComplete( status, KErrCancel ); |
|
92 } |
|
93 iState = EInactivityState; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void CMmHighlightTimer::StartL( TInt aTime, TBool aPressDownState ) |
|
101 { |
|
102 CListBoxView* view = iContainer->Widget()->View(); |
|
103 if ( IsActive() && |
|
104 iTimerHighlightIndex != iContainer->Widget()->CurrentItemIndex()) |
|
105 { |
|
106 // draw over previous highlight |
|
107 // this occurs when e.g. highlight is set by rocker and later another |
|
108 // item is pressed. |
|
109 DrawHighlightL( iTimerHighlightIndex ); |
|
110 } |
|
111 Cancel(); |
|
112 if (aTime > 0) |
|
113 { |
|
114 iTimer.After(iStatus, aTime); |
|
115 iState = ETimerExpirationCompletionState; |
|
116 } |
|
117 else |
|
118 { |
|
119 iStatus = KRequestPending; |
|
120 iState = EExternalCompletionState; |
|
121 } |
|
122 |
|
123 SetActive(); |
|
124 iContainer->SetHighlightVisibilityL( ETrue ); |
|
125 { |
|
126 SetPressDownState( aPressDownState ); |
|
127 TInt currentItemIndex = |
|
128 iContainer->Widget()->View()->CurrentItemIndex(); |
|
129 DrawHighlightL( currentItemIndex ); |
|
130 iTimerHighlightIndex = currentItemIndex; |
|
131 } |
|
132 iContainer->SetHighlightVisibilityL( EFalse ); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CMmHighlightTimer::RunL() |
|
140 { |
|
141 DrawHighlightL(iContainer->Widget()->View()->CurrentItemIndex()); |
|
142 iState = EInactivityState; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CMmHighlightTimer::RunError(TInt /*aError*/) |
|
150 { |
|
151 iState = EInactivityState; |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CMmHighlightTimer::StopL( TBool aDrawOverHighlight ) |
|
160 { |
|
161 if (IsActive()) |
|
162 { |
|
163 Cancel(); |
|
164 if ( aDrawOverHighlight ) |
|
165 { |
|
166 DrawHighlightL( iContainer->Widget()->View()->CurrentItemIndex() ); |
|
167 } |
|
168 } |
|
169 iState = EInactivityState; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CMmHighlightTimer::TimerHighlightIndex() const |
|
177 { |
|
178 return iTimerHighlightIndex; |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CMmHighlightTimer::DrawHighlightL(TInt aItemIndex) |
|
186 { |
|
187 if ( iContainer->IsVisible() ) |
|
188 { |
|
189 CListBoxView* view = iContainer->Widget()->View(); |
|
190 iContainer->Widget()->DrawNow( TRect( |
|
191 view->ItemPos( aItemIndex ), view->ItemSize( |
|
192 aItemIndex) ) ); |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CMmHighlightTimer::SetPressDownState(TBool aPressDownState) |
|
201 { |
|
202 if ( aPressDownState ) |
|
203 { |
|
204 iContainer->Widget()->View()->ItemDrawer()->SetFlags( |
|
205 CListItemDrawer::EPressedDownState ); |
|
206 } |
|
207 else |
|
208 { |
|
209 iContainer->Widget()->View()->ItemDrawer()->ClearFlags( |
|
210 CListItemDrawer::EPressedDownState ); |
|
211 } |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CMmHighlightTimer::ContinueL( TInt aTime ) |
|
219 { |
|
220 if ( IsActive() ) |
|
221 { |
|
222 Cancel(); |
|
223 if ( aTime > 0 ) |
|
224 { |
|
225 iTimer.After( iStatus, aTime ); |
|
226 iState = ETimerExpirationCompletionState; |
|
227 } |
|
228 else |
|
229 { |
|
230 iStatus = KRequestPending; |
|
231 iState = EExternalCompletionState; |
|
232 } |
|
233 SetActive(); |
|
234 } |
|
235 } |
|
236 // End of file |