|
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: Application UI class |
|
15 * Version : %version: 3 % << Don't touch! Updated by Synergy at check-out. |
|
16 */ |
|
17 |
|
18 |
|
19 #include "hnitemfocushandler.h" |
|
20 #include "hnglobals.h" |
|
21 #include "hnsuitemodel.h" |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // TFocusQueueItem::TFocusQueueItem( TInt aItemId, TInt aEventId ) |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 TFocusQueueItem::TFocusQueueItem( TInt aItemId, TInt aEventId ): |
|
28 iItemId( aItemId ), iEventId( aEventId ) |
|
29 { |
|
30 iTriggerTime.HomeTime(); |
|
31 } |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // TFocusQueueItem::TriggerTime() |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 TTime TFocusQueueItem::TriggerTime() |
|
38 { |
|
39 return iTriggerTime; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // TFocusQueueItem::ItemId() |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 TInt TFocusQueueItem::ItemId() |
|
47 { |
|
48 return iItemId; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // TFocusQueueItem::EventId() |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 TInt TFocusQueueItem::EventId() |
|
56 { |
|
57 return iEventId; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // TFocusQueueItem::CompareByTriggerTime( const TFocusQueueItem& aItem1, |
|
62 // const TFocusQueueItem& aItem2 ) |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 TInt TFocusQueueItem::CompareByTriggerTime( const TFocusQueueItem& aItem1, |
|
66 const TFocusQueueItem& aItem2 ) |
|
67 { |
|
68 if ( aItem1.iTriggerTime < aItem2.iTriggerTime ) |
|
69 { |
|
70 return -1; |
|
71 } |
|
72 else |
|
73 { |
|
74 return 1; |
|
75 } |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // TFocusQueueItem::CompareByItemId( const TFocusQueueItem& aItem1, |
|
80 // const TFocusQueueItem& aItem2 ) |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 TBool TFocusQueueItem::CompareByItemId( const TFocusQueueItem& aItem1, |
|
84 const TFocusQueueItem& aItem2 ) |
|
85 { |
|
86 return aItem1.iItemId == aItem2.iItemId; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CHnItemFocusHandler::CHnItemFocusHandler() |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CHnItemFocusHandler::CHnItemFocusHandler() : |
|
94 CActive(EPriorityLow) // Standard priority |
|
95 { |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CHnItemFocusHandler* CHnItemFocusHandler::NewLC() |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CHnItemFocusHandler* CHnItemFocusHandler::NewLC( CHnSuiteModel* aSuiteModel ) |
|
103 { |
|
104 CHnItemFocusHandler* self = new (ELeave) CHnItemFocusHandler(); |
|
105 CleanupStack::PushL(self); |
|
106 self->ConstructL( aSuiteModel ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CHnItemFocusHandler* CHnItemFocusHandler::NewL() |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 CHnItemFocusHandler* CHnItemFocusHandler::NewL( CHnSuiteModel* aSuiteModel ) |
|
115 { |
|
116 CHnItemFocusHandler* self = CHnItemFocusHandler::NewLC( aSuiteModel ); |
|
117 CleanupStack::Pop(); // self; |
|
118 return self; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CHnItemFocusHandler::ConstructL() |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CHnItemFocusHandler::ConstructL( CHnSuiteModel* aSuiteModel ) |
|
126 { |
|
127 CActiveScheduler::Add( this); // Add to scheduler |
|
128 iSuiteModel = aSuiteModel; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CHnItemFocusHandler::~CHnItemFocusHandler( |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 CHnItemFocusHandler::~CHnItemFocusHandler() |
|
136 { |
|
137 Cancel(); // Cancel any request, if outstanding |
|
138 |
|
139 // handle all pending unfocus events synchronously. |
|
140 for(TInt i = 0; i < iFocusQueue.Count(); i++ ) |
|
141 { |
|
142 if ( KIdFocusLost == iFocusQueue[i].EventId() ) |
|
143 { |
|
144 if( iSuiteModel ) |
|
145 { |
|
146 TRAP_IGNORE( iSuiteModel->OfferHnEventL( |
|
147 KIdFocusLost, iFocusQueue[i].ItemId(), NULL ) ); |
|
148 } |
|
149 } |
|
150 } |
|
151 iFocusQueue.Reset(); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CHnItemFocusHandler::DoCancel() |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CHnItemFocusHandler::DoCancel() |
|
159 { |
|
160 // TRequestStatus* status = &iStatus; |
|
161 // User::RequestComplete( status, KErrCancel); |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CHnItemFocusHandler::StartL(TTimeIntervalMicroSeconds32 aDelay) |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CHnItemFocusHandler::SetFocusL( TInt aEventId, TBool aItemId ) |
|
169 { |
|
170 TLinearOrder<TFocusQueueItem> byTriggerTime( |
|
171 TFocusQueueItem::CompareByTriggerTime ); |
|
172 TFocusQueueItem focusItem(aItemId, aEventId); |
|
173 RemoveDuplicatedItem( focusItem ); |
|
174 iFocusQueue.InsertInOrderL( focusItem, byTriggerTime ); |
|
175 if ( !IsActive() ) |
|
176 { |
|
177 SetActive(); |
|
178 TRequestStatus* status = &iStatus; |
|
179 User::RequestComplete( status, KErrNone ); |
|
180 } |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CHnItemFocusHandler::RunL() |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CHnItemFocusHandler::RunL() |
|
188 { |
|
189 TRAP_IGNORE( iSuiteModel->OfferHnEventL( |
|
190 iFocusQueue[0].EventId(), iFocusQueue[0].ItemId() , NULL ) ); |
|
191 iFocusQueue.Remove(0); |
|
192 |
|
193 if ( iFocusQueue.Count() > 0) |
|
194 { |
|
195 SetActive(); // Tell scheduler a request is active |
|
196 TRequestStatus* status = &iStatus; |
|
197 User::RequestComplete( status, KErrNone ); |
|
198 } |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CHnItemFocusHandler::RunError(TInt aError) |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CHnItemFocusHandler::RunError(TInt aError) |
|
206 { |
|
207 return aError; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // RemoveDuplicatedItem( const TFocusQueueItem& aFocusItem ) |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 void CHnItemFocusHandler::RemoveDuplicatedItem( const TFocusQueueItem& aFocusItem ) |
|
215 { |
|
216 if ( iFocusQueue.Count() != 0 ) |
|
217 { |
|
218 TIdentityRelation< TFocusQueueItem > byItemId( |
|
219 TFocusQueueItem::CompareByItemId ); |
|
220 TInt itemPosition; |
|
221 itemPosition = iFocusQueue.Find( aFocusItem, byItemId ); |
|
222 if ( KErrNotFound != itemPosition ) |
|
223 { |
|
224 iFocusQueue.Remove( itemPosition ); |
|
225 } |
|
226 } |
|
227 } |
|
228 |
|
229 // End of file |
|
230 |