13 * |
13 * |
14 * Description: List pane component for UI fields |
14 * Description: List pane component for UI fields |
15 * |
15 * |
16 */ |
16 */ |
17 #include "cmrlistpane.h" |
17 #include "cmrlistpane.h" |
|
18 #include "mesmrfieldstorage.h" |
|
19 #include "mmrscrollbarobserver.h" |
|
20 #include "esmrdef.h" |
|
21 #include "cesmrfield.h" |
|
22 #include "cmrfieldcontainer.h" |
|
23 #include "cmrlistpanephysics.h" |
18 |
24 |
19 #include <eikscrlb.h> |
25 #include <eikscrlb.h> |
20 #include <AknUtils.h> |
26 #include <aknutils.h> |
21 #include <touchfeedback.h> |
27 |
22 |
28 //DEBUG |
23 #include "mesmrfieldstorage.h" |
|
24 #include "cesmrfield.h" |
|
25 |
|
26 #include "emailtrace.h" |
29 #include "emailtrace.h" |
27 |
30 |
28 namespace // codescanner::namespace |
31 namespace { // codescanner::namespace |
29 { |
32 |
30 /** |
33 const TInt KLongTapDelay( 700000 ); // 0,7 sec |
31 * Vertical scroll margin |
34 const TInt KLongTapAnimationDelay( 300000 ); // 0,3 sec |
32 */ |
35 |
33 const TInt KVerticalScrollMargin = 3; |
36 // ---------------- |
34 |
37 // IndexByFieldId |
35 // --------------------------------------------------------------------------- |
38 // ---------------- |
36 // IndexByFieldId |
39 // |
37 // --------------------------------------------------------------------------- |
40 TInt IndexByFieldId( const MESMRFieldStorage& aFactory, |
38 // |
41 TESMREntryFieldId aFieldId ) |
39 TInt IndexByFieldId( const MESMRFieldStorage& aFactory, |
42 { |
40 TESMREntryFieldId aFieldId ) |
43 TInt index( KErrNotFound ); |
41 { |
44 TInt count( aFactory.Count() ); |
42 TInt index( KErrNotFound ); |
45 |
43 TInt count( aFactory.Count() ); |
46 for ( TInt i = 0; i < count; ++i ) |
44 |
47 { |
45 for ( TInt i = 0; i < count; ++i ) |
48 if ( aFactory.Field( i )->FieldId() == aFieldId ) |
46 { |
49 { |
47 if ( aFactory.Field( i )->FieldId() == aFieldId ) |
50 index = i; |
48 { |
51 break; |
49 index = i; |
52 } |
50 break; |
53 } |
51 } |
54 |
52 } |
55 return index; |
53 |
56 } |
54 return index; |
57 |
55 } |
58 } |
56 } |
|
57 |
59 |
58 //----- MEMBER FUNCTIONS ---- |
60 //----- MEMBER FUNCTIONS ---- |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CMRListPane::CMRListPane |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CMRListPane::CMRListPane( MESMRFieldStorage& aFactory, |
|
67 TAknDoubleSpanScrollBarModel& aScrollModel, |
|
68 CAknDoubleSpanScrollBar& aScroll, |
|
69 MMRScrollBarObserver& aScrollBarObserver ) |
|
70 : iFactory( aFactory ), |
|
71 iScrollModel( aScrollModel ), |
|
72 iScroll( aScroll ), |
|
73 iScrollBarObserver( aScrollBarObserver ) |
|
74 { |
|
75 FUNC_LOG; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CMRListPane::~CMRListPane |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CMRListPane::~CMRListPane() |
|
83 { |
|
84 FUNC_LOG; |
|
85 delete iLongtapDetector; |
|
86 delete iPhysics; |
|
87 delete iFieldContainer; |
|
88 } |
59 |
89 |
60 // --------------------------------------------------------------------------- |
90 // --------------------------------------------------------------------------- |
61 // CMRListPane::NewL |
91 // CMRListPane::NewL |
62 // --------------------------------------------------------------------------- |
92 // --------------------------------------------------------------------------- |
63 // |
93 // |
64 CMRListPane* CMRListPane::NewL( const CCoeControl& aParent, |
94 CMRListPane* CMRListPane::NewL( const CCoeControl& aParent, |
65 MESMRFieldStorage& aFactory, |
95 MESMRFieldStorage& aFactory, |
66 TAknDoubleSpanScrollBarModel& aScrollModel ) |
96 TAknDoubleSpanScrollBarModel& aScrollModel, |
67 { |
97 CAknDoubleSpanScrollBar& aScroll, |
68 CMRListPane* self = new (ELeave) CMRListPane( aFactory, aScrollModel ); |
98 MMRScrollBarObserver& aScrollBarObserver ) |
|
99 { |
|
100 FUNC_LOG; |
|
101 CMRListPane* self = new( ELeave )CMRListPane( |
|
102 aFactory, |
|
103 aScrollModel, |
|
104 aScroll, |
|
105 aScrollBarObserver ); |
69 CleanupStack::PushL( self ); |
106 CleanupStack::PushL( self ); |
70 self->ConstructL( aParent ); |
107 self->ConstructL( aParent ); |
71 CleanupStack::Pop( self ); |
108 CleanupStack::Pop( self ); |
72 return self; |
109 return self; |
73 } |
110 } |
74 |
111 |
75 // --------------------------------------------------------------------------- |
112 // --------------------------------------------------------------------------- |
76 // CMRListPane::~CMRListPane |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CMRListPane::~CMRListPane() |
|
80 { |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CMRListPane::CMRListPane |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CMRListPane::CMRListPane( MESMRFieldStorage& aFactory, |
|
88 TAknDoubleSpanScrollBarModel& aScrollModel ) |
|
89 : iFactory( aFactory ), |
|
90 iScrollModel( aScrollModel ) |
|
91 { |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CMRListPane::ConstructL |
113 // CMRListPane::ConstructL |
96 // --------------------------------------------------------------------------- |
114 // --------------------------------------------------------------------------- |
97 // |
115 // |
98 void CMRListPane::ConstructL( const CCoeControl& aParent ) |
116 void CMRListPane::ConstructL( const CCoeControl& aParent ) |
99 { |
117 { |
|
118 FUNC_LOG; |
|
119 CCoeControl::SetComponentsToInheritVisibility( ETrue ); |
100 SetContainerWindowL( aParent ); |
120 SetContainerWindowL( aParent ); |
101 TBool focusSet = EFalse; |
121 |
|
122 iLongtapDetector = CAknLongTapDetector::NewL( this ); |
|
123 iLongtapDetector->SetLongTapDelay( KLongTapDelay ); |
|
124 iLongtapDetector->SetTimeDelayBeforeAnimation( KLongTapAnimationDelay ); |
|
125 |
|
126 iFieldContainer = CMRFieldContainer::NewL( iFactory, *this ); |
|
127 iFieldContainer->SetFieldContainerObserver( this ); |
|
128 |
|
129 // Physics: Create physics |
|
130 // Give pointer to control that should be able to flick/drag |
|
131 iPhysics = CMRListPanePhysics::NewL( *this, *iFieldContainer, *this ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CMRListPane::InitializeL() |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CMRListPane::InitializeL() |
|
139 { |
|
140 FUNC_LOG; |
102 const TInt count( iFactory.Count() ); |
141 const TInt count( iFactory.Count() ); |
103 for ( TInt i = 0; i < count; i++ ) |
142 for ( TInt i = 0; i < count; i++ ) |
104 { |
143 { |
105 iFactory.Field(i)->SetContainerWindowL( *this ); |
144 iFactory.Field(i)->InitializeL(); |
106 } |
145 } |
107 |
146 iClickedField = NULL; |
108 for ( TInt i = 0; i < count; i++ ) |
147 } |
109 { |
148 |
110 CESMRField* field = iFactory.Field( i ); |
149 |
111 |
150 // --------------------------------------------------------------------------- |
112 // Initialize field |
151 // CMRListPane::InternalizeL() |
113 field->InitializeL(); |
152 // --------------------------------------------------------------------------- |
114 User::LeaveIfError( field->SetParent( this ) ); |
153 // |
115 |
154 void CMRListPane::InternalizeL( MESMRCalEntry& aEntry ) |
116 if ( !focusSet |
155 { |
117 && field->IsVisible() |
156 FUNC_LOG; |
118 && !field->IsNonFocusing()) |
157 iFactory.InternalizeL( aEntry ); |
119 { |
158 |
120 field->SetOutlineFocusL( ETrue ); |
159 // This is called to make sure everything is drawn correctly |
121 focusSet = ETrue; |
160 DrawDeferred(); |
122 iFocus = i; |
161 } |
123 } |
162 |
124 } |
163 // --------------------------------------------------------------------------- |
125 } |
164 // CMRListPane::ExternalizeL() |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CMRListPane::ExternalizeL( |
|
168 MESMRCalEntry& aEntry, |
|
169 TBool aForceValidation ) |
|
170 { |
|
171 FUNC_LOG; |
|
172 CESMRField* currentFocus = FocusedField(); |
|
173 ASSERT( currentFocus ); |
|
174 TESMREntryFieldId id = currentFocus->FieldId(); |
|
175 |
|
176 if ( aForceValidation ) |
|
177 { |
|
178 // force validate the values: |
|
179 TInt err = iFactory.Validate( id, aForceValidation ); |
|
180 // fill the calendar entry with data in fields. |
|
181 iFactory.ExternalizeL( aEntry ); |
|
182 } |
|
183 else |
|
184 { |
|
185 TInt err = iFactory.Validate( id ); |
|
186 if ( err ) |
|
187 { |
|
188 //SetControlFocusedL( id ); Why would we set this focused here? |
|
189 User::Leave( err ); |
|
190 } |
|
191 else |
|
192 { |
|
193 // fill the calendar entry with data in fields. |
|
194 iFactory.ExternalizeL( aEntry ); |
|
195 } |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CMRListPane::DisableSizeChange() |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CMRListPane::DisableSizeChange(TBool aDisable ) |
|
204 { |
|
205 FUNC_LOG; |
|
206 iDisableSizeChanged = aDisable; |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CMRListPane::InitialScroll |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CMRListPane::InitialScrollL() |
|
214 { |
|
215 FUNC_LOG; |
|
216 // TODO: Fix or remove! L-Function called in non-leaving function! |
|
217 // Suggestion: Move functionality to viewerdialog and use existing |
|
218 // functions in listpane to do the required actions. |
|
219 |
|
220 // Check if the ResponseArea exist |
|
221 TESMREntryFieldId id = GetResponseFieldsFieldId(); |
|
222 |
|
223 if( id == EESMRFieldResponseArea ) |
|
224 { |
|
225 // Set the focus on the ResponseArea |
|
226 iFieldContainer->SetControlFocusedL( id ); |
|
227 //iFactory.FieldById(id)->SetFocus( ETrue ); |
|
228 |
|
229 // Scroll the list to put the ResponseArea on the top |
|
230 CESMRField* focusField = FocusedField(); |
|
231 TPoint pos( focusField->Position() ); |
|
232 ScrollFieldsUp(pos.iY); |
|
233 } |
|
234 } |
|
235 |
126 |
236 |
127 // --------------------------------------------------------------------------- |
237 // --------------------------------------------------------------------------- |
128 // CMRListPane::FocusedItem |
238 // CMRListPane::FocusedItem |
129 // --------------------------------------------------------------------------- |
239 // --------------------------------------------------------------------------- |
130 // |
240 // |
131 CESMRField* CMRListPane::FocusedItem() const |
241 CESMRField* CMRListPane::FocusedField() const |
132 { |
242 { |
133 FUNC_LOG; |
243 FUNC_LOG; |
134 CESMRField* field = NULL; |
244 return iFieldContainer->FocusedField(); |
135 if ( iFactory.Count() > 0 ) |
245 } |
136 { |
246 |
137 field = iFactory.Field( iFocus ); |
247 // --------------------------------------------------------------------------- |
138 } |
248 // CMRListPane::SetControlFocusedL |
139 return field; |
249 // --------------------------------------------------------------------------- |
140 } |
250 // |
141 |
251 void CMRListPane::SetControlFocusedL( TESMREntryFieldId aFieldId ) |
|
252 { |
|
253 FUNC_LOG; |
|
254 iFieldContainer->SetControlFocusedL( aFieldId ); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CMRListPane::ClickedItem |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 CESMRField* CMRListPane::ClickedField() const |
|
262 { |
|
263 return iClickedField; |
|
264 } |
|
265 |
142 // --------------------------------------------------------------------------- |
266 // --------------------------------------------------------------------------- |
143 // CMRListPane::CountComponentControls |
267 // CMRListPane::CountComponentControls |
144 // --------------------------------------------------------------------------- |
268 // --------------------------------------------------------------------------- |
145 // |
269 // |
146 TInt CMRListPane::CountComponentControls() const |
270 TInt CMRListPane::CountComponentControls() const |
147 { |
271 { |
148 return iFactory.Count(); |
272 FUNC_LOG; |
|
273 return 1; // iFieldContainer |
|
274 |
149 } |
275 } |
150 |
276 |
151 // --------------------------------------------------------------------------- |
277 // --------------------------------------------------------------------------- |
152 // CMRListPane::ComponentControl |
278 // CMRListPane::ComponentControl |
153 // --------------------------------------------------------------------------- |
279 // --------------------------------------------------------------------------- |
154 // |
280 // |
155 CCoeControl* CMRListPane::ComponentControl( TInt aIndex ) const |
281 CCoeControl* CMRListPane::ComponentControl( TInt /*aIndex*/ ) const |
156 { |
282 { |
157 return iFactory.Field( aIndex ); |
283 FUNC_LOG; |
|
284 return iFieldContainer; |
158 } |
285 } |
159 |
286 |
160 // --------------------------------------------------------------------------- |
287 // --------------------------------------------------------------------------- |
161 // CMRListPane::SizeChanged |
288 // CMRListPane::SizeChanged |
162 // --------------------------------------------------------------------------- |
289 // --------------------------------------------------------------------------- |
163 // |
290 // |
164 void CMRListPane::SizeChanged() |
291 void CMRListPane::SizeChanged() |
165 { |
292 { |
166 TPoint tl( Position() ); |
293 FUNC_LOG; |
167 TInt scrollSpan = 0; |
294 if ( iDisableSizeChanged || Rect() == TRect( 0, 0, 0, 0 ) ) |
168 // Loop all the visible fields and set size and position in the list |
295 { |
169 TBool topVisibleFound( EFalse ); |
296 return; |
170 |
297 } |
171 const TInt count( iFactory.Count() ); |
298 |
172 for ( TInt i = 0; i < count; i++ ) |
299 TSize containerSize( iFieldContainer->MinimumSize() ); |
173 { |
300 iFieldContainer->SetSize( containerSize ); |
174 CESMRField* field = iFactory.Field( i ); |
301 |
175 |
302 // Physics: |
176 if ( field->IsVisible() ) |
303 iPhysics->InitPhysics(); |
177 { |
304 |
178 LayoutField( *field, tl ); |
305 DoUpdateScrollBar(); |
179 |
|
180 if ( !topVisibleFound ) |
|
181 { |
|
182 iTopVisibleIndex = i; |
|
183 topVisibleFound = ETrue; |
|
184 } |
|
185 |
|
186 TInt height = field->Size().iHeight; |
|
187 tl.iY += height; |
|
188 scrollSpan += height; |
|
189 } |
|
190 } |
|
191 |
|
192 iScrollModel.SetScrollSpan( scrollSpan ); |
|
193 iScrollModel.SetWindowSize( iSize.iHeight ); |
|
194 UpdateFocusPosition(); |
|
195 } |
306 } |
196 |
307 |
197 // --------------------------------------------------------------------------- |
308 // --------------------------------------------------------------------------- |
198 // CMRListPane::OfferKeyEventL |
309 // CMRListPane::OfferKeyEventL |
199 // --------------------------------------------------------------------------- |
310 // --------------------------------------------------------------------------- |
200 // |
311 // |
201 TKeyResponse CMRListPane::OfferKeyEventL( const TKeyEvent &aKeyEvent, |
312 TKeyResponse CMRListPane::OfferKeyEventL( const TKeyEvent &aKeyEvent, |
202 TEventCode aType ) |
313 TEventCode aType ) |
203 { |
314 { |
|
315 FUNC_LOG; |
204 TKeyResponse response( EKeyWasNotConsumed ); |
316 TKeyResponse response( EKeyWasNotConsumed ); |
205 |
317 |
206 // If we have at least one item in the list |
318 // First check if the focused item needs the key event |
207 if ( iFocus < iFactory.Count() ) |
319 response = FocusedField()->OfferKeyEventL( aKeyEvent, aType ); |
208 { |
320 |
209 CESMRField* field = iFactory.Field( iFocus ); |
321 if ( aType == EEventKey |
210 // First check if the focused item needs the key event |
322 && response == EKeyWasNotConsumed ) |
211 response = field->OfferKeyEventL( aKeyEvent, aType ); |
323 { |
212 |
324 // Check if the focus should be changed |
213 if ( aType == EEventKey |
325 switch ( aKeyEvent.iScanCode ) |
214 && response == EKeyWasNotConsumed ) |
326 { |
215 { |
327 case EStdKeyUpArrow: |
216 // Check if the focus should be changed |
|
217 switch ( aKeyEvent.iScanCode ) |
|
218 { |
328 { |
219 case EStdKeyUpArrow: |
329 response = iFieldContainer->MoveFocusUpL( HiddenFocus() ); |
220 { |
330 |
221 response = MoveFocusUpL(); |
331 // Focus changed via keyboard, iClickedItem is no |
222 break; |
332 // longer valid |
223 } |
333 iClickedField = NULL; |
224 case EStdKeyDownArrow: |
|
225 { |
|
226 response = MoveFocusDownL(); |
|
227 break; |
|
228 } |
|
229 default: |
|
230 { |
|
231 break; |
|
232 } |
|
233 } |
|
234 } |
|
235 } |
|
236 return response; |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // CMRListPane::ControlSizeChanged |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CMRListPane::ControlSizeChanged( CESMRField* aCtrl ) |
|
244 { |
|
245 if ( !aCtrl ) |
|
246 { |
|
247 SizeChanged(); |
|
248 } |
|
249 else |
|
250 { |
|
251 TPoint tl( aCtrl->Position() ); |
|
252 TInt index = IndexByFieldId( iFactory, aCtrl->FieldId() ); |
|
253 |
|
254 // Relayout aCtrl |
|
255 TSize old( aCtrl->Size() ); |
|
256 TSize size( aCtrl->MinimumSize() ); |
|
257 if ( aCtrl->IsExpandable() ) |
|
258 { |
|
259 size.iHeight = aCtrl->ExpandedHeight(); |
|
260 } |
|
261 aCtrl->SetSize( size ); |
|
262 iScrollModel.SetScrollSpan( iScrollModel.ScrollSpan() |
|
263 + size.iHeight - old.iHeight ); |
|
264 |
|
265 // Move other fields |
|
266 ++index; |
|
267 tl.iY += size.iHeight; |
|
268 MoveFields( index, tl ); |
|
269 UpdateFocusPosition(); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CMRListPane::InsertControl |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CMRListPane::InsertControl( TESMREntryFieldId aField ) |
|
278 { |
|
279 CESMRField* field = iFactory.FieldById( aField ); |
|
280 |
|
281 if ( field && !field->IsVisible() ) |
|
282 { |
|
283 // Make field visible |
|
284 field->MakeVisible( ETrue ); |
|
285 TInt index = IndexByFieldId( iFactory, aField ); |
|
286 if ( index < iTopVisibleIndex ) |
|
287 { |
|
288 iTopVisibleIndex = index; |
|
289 } |
|
290 |
|
291 TPoint tl( Rect().iTl ); |
|
292 TInt prevIndex = index - 1; |
|
293 |
|
294 // Get previous visible field position |
|
295 if ( prevIndex >= 0 ) |
|
296 { |
|
297 CESMRField* previous = NULL; |
|
298 do |
|
299 { |
|
300 previous = iFactory.Field( prevIndex-- ); |
|
301 } |
|
302 while ( prevIndex >= 0 && !previous->IsVisible() ); |
|
303 |
|
304 tl.iY = previous->Rect().iBr.iY; |
|
305 } |
|
306 |
|
307 // Layout field |
|
308 LayoutField( *field, tl ); |
|
309 iScrollModel.SetScrollSpan( iScrollModel.ScrollSpan() |
|
310 + field->Size().iHeight ); |
|
311 |
|
312 // Move following fields |
|
313 tl.iY += field->Size().iHeight; |
|
314 MoveFields( ++index, tl ); |
|
315 UpdateFocusPosition(); |
|
316 } |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // CMRListPane::InsertControl |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 void CMRListPane::RemoveControl( TESMREntryFieldId aField ) |
|
324 { |
|
325 CESMRField* field = iFactory.FieldById( aField ); |
|
326 |
|
327 if ( field && field->IsVisible() ) |
|
328 { |
|
329 field->MakeVisible( EFalse ); |
|
330 iScrollModel.SetScrollSpan( iScrollModel.ScrollSpan() - field->Size().iHeight ); |
|
331 TInt index = IndexByFieldId( iFactory, aField ); |
|
332 TBool focused = ( index == iFocus )? ETrue : EFalse; |
|
333 |
|
334 if ( index == iTopVisibleIndex ) |
|
335 { |
|
336 // Find next |
|
337 TInt count( iFactory.Count() ); |
|
338 while ( index < count ) |
|
339 { |
|
340 if ( iFactory.Field( ++index )->IsVisible() ) |
|
341 { |
|
342 iTopVisibleIndex = index; |
|
343 break; |
|
344 } |
|
345 } |
|
346 } |
|
347 else |
|
348 { |
|
349 ++index; |
|
350 } |
|
351 TPoint pos( field->Position() ); |
|
352 MoveFields( index, pos ); |
|
353 if ( focused && !field->IsNonFocusing() ) |
|
354 { |
|
355 TRAP_IGNORE( DoSetFocusL( index ) ) |
|
356 } |
|
357 UpdateFocusPosition(); |
|
358 } |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // CMRListPane::IsControlVisible |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 TBool CMRListPane::IsControlVisible( TESMREntryFieldId aField ) |
|
366 { |
|
367 TBool visible( EFalse ); |
|
368 CESMRField* field = iFactory.FieldById( aField ); |
|
369 |
|
370 if ( field ) |
|
371 { |
|
372 visible = field->IsVisible(); |
|
373 } |
|
374 |
|
375 return visible; |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // CMRListPane::SetControlFocusedL |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 void CMRListPane::SetControlFocusedL( TESMREntryFieldId aField ) |
|
383 { |
|
384 TInt count = iFactory.Count(); |
|
385 for ( TInt i(0); i < count; i++ ) |
|
386 { |
|
387 CESMRField* field = iFactory.Field(i); |
|
388 |
|
389 if ( field->FieldId() == aField ) |
|
390 { |
|
391 if( field->IsVisible() && !field->IsNonFocusing() ) |
|
392 { |
|
393 // Remove current focus before setting new one |
|
394 CESMRField* focusedField = FocusedItem(); |
|
395 ASSERT( focusedField ); |
|
396 focusedField->SetOutlineFocusL( EFalse ); |
|
397 |
|
398 // Set new focus |
|
399 field->SetOutlineFocusL( ETrue ); |
|
400 iFocus = i; |
|
401 break; |
334 break; |
402 } |
335 } |
403 else |
336 case EStdKeyDownArrow: |
404 { |
337 { |
405 // Not possible to set focus to non-visible control |
338 response = iFieldContainer->MoveFocusDownL( HiddenFocus() ); |
406 User::Leave( KErrGeneral ); |
339 |
|
340 // Focus changed via keyboard, iClickedItem is no |
|
341 // longer valid |
|
342 iClickedField = NULL; |
|
343 break; |
407 } |
344 } |
408 } |
345 default: |
409 } |
346 { |
410 } |
347 break; |
411 |
348 } |
412 // SCROLLING_MOD: These two methods are for CESMRRichTextViewer to |
349 } |
413 // be able to control view area |
350 } |
414 // --------------------------------------------------------------------------- |
351 |
415 // CMRListPane::MoveListAreaDownL |
352 return response; |
416 // --------------------------------------------------------------------------- |
353 } |
417 // |
354 |
418 void CMRListPane::MoveListAreaDownL( TInt aAmount ) |
355 // --------------------------------------------------------------------------- |
419 { |
356 // CMRListPane::HandleLongTapEventL |
420 FUNC_LOG; |
357 // --------------------------------------------------------------------------- |
421 // Method for CESMRRichTextViewer for moving view area down if the text in |
358 // |
422 // text field does not fit on the screen. |
359 void CMRListPane::HandleLongTapEventL( |
423 |
360 const TPoint& aPenEventLocation, |
424 // Fetch the position info about the first visible field in field set: |
361 const TPoint& /* aPenEventScreenLocation */ ) |
425 CESMRField* field; |
362 { |
426 if( iTopVisibleIndex != KErrNotFound ) |
363 FUNC_LOG; |
427 { |
364 iLongTapEventConsumed = EFalse; |
428 field = iFactory.Field( iTopVisibleIndex ); |
365 // Long tap functionality may vary between fields |
|
366 // ==> Command field to execute action related to long tap |
|
367 TInt count( iFactory.Count() ); |
|
368 |
|
369 for ( TInt i = 0; i < count; ++i ) |
|
370 { |
|
371 CESMRField* field = iFactory.Field( i ); |
|
372 |
|
373 if ( field->IsVisible() |
|
374 && field->Rect().Contains( aPenEventLocation ) ) |
|
375 { |
|
376 field->LongtapDetectedL( aPenEventLocation ); |
|
377 iLongTapEventConsumed = ETrue; |
|
378 break; |
|
379 } |
|
380 } |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------------------------- |
|
384 // CMRListPane::DoUpdateScrollBar |
|
385 // --------------------------------------------------------------------------- |
|
386 // |
|
387 void CMRListPane::DoUpdateScrollBar( TInt aFocusPosition ) |
|
388 { |
|
389 FUNC_LOG; |
|
390 // Set this lispane's size as scroll bar's window size |
|
391 iScrollModel.SetWindowSize( iSize.iHeight ); |
|
392 // Set fieldcontainer's height as scrolbar's scroll span |
|
393 iScrollModel.SetScrollSpan( iFieldContainer->MinimumSize().iHeight ); |
|
394 |
|
395 // Update scrollbar focus position. |
|
396 if( aFocusPosition == KErrNotFound ) |
|
397 { |
|
398 iScrollModel.SetFocusPosition( iPhysics->VerticalScrollIndex() ); |
429 } |
399 } |
430 else |
400 else |
431 { |
401 { |
432 field = iFactory.Field( iFactory.Count() - 1 ); |
402 iScrollModel.SetFocusPosition( aFocusPosition ); |
433 } |
403 } |
434 TRect rect( field->Rect() ); |
404 |
435 |
405 iScroll.SetModel( &iScrollModel ); |
436 // check whether the first field is visible, if not, let's |
406 |
437 // check should we scroll less than needed to get the first |
407 // finally update the new thumb position to view's |
438 // field shown. |
408 // iScrollBarThumbPosition member. |
439 if ( rect.iTl.iY + aAmount > Rect().iTl.iY ) |
409 iScrollBarObserver.ScrollBarPositionChanged( |
440 { |
410 iScroll.ThumbPosition() ); |
441 aAmount = Rect().iTl.iY - rect.iTl.iY + KVerticalScrollMargin; |
411 } |
442 } |
412 |
443 else if ( rect.iTl.iY == Rect().iTl.iY ) |
413 // --------------------------------------------------------------------------- |
444 { |
414 // CMRListPane::UpdatedFocusPosition |
445 // field already visible, do not scroll. |
415 // --------------------------------------------------------------------------- |
446 aAmount = 0; |
416 // |
447 } |
417 TInt CMRListPane::UpdatedFocusPosition() |
448 |
418 { |
449 // Do the view scrolling if needed: |
419 FUNC_LOG; |
450 if ( aAmount ) |
|
451 { |
|
452 ScrollItemsDown( aAmount ); |
|
453 UpdateFocusPosition(); |
|
454 //UpdateScrollBar(); |
|
455 DrawDeferred(); |
|
456 } |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // CMRListPane::MoveListAreaUpL |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 void CMRListPane::MoveListAreaUpL( TInt aAmount ) |
|
464 { |
|
465 FUNC_LOG; |
|
466 // Fetch the position information about currently focused field: |
|
467 CESMRField* field = iFactory.Field( iFocus ); |
|
468 TRect rect( field->Rect() ); |
|
469 |
|
470 // check whether the scroll pixels should be less than normal |
|
471 // scroll sequence to let the field bottom to be placed at |
|
472 // the bottom of view rect. |
|
473 if ( rect.iBr.iY - aAmount < Rect().iBr.iY ) |
|
474 { |
|
475 aAmount = rect.iBr.iY - Rect().iBr.iY + KVerticalScrollMargin; |
|
476 } |
|
477 else if ( rect.iBr.iY + aAmount == Rect().iBr.iY ) |
|
478 { |
|
479 // field already visible, do not scroll. |
|
480 aAmount = 0; |
|
481 } |
|
482 |
|
483 // do the scrolling if needed: |
|
484 if ( aAmount > 0 ) |
|
485 { |
|
486 // if the focus is on last |
|
487 ScrollItemsUp( aAmount ); |
|
488 UpdateFocusPosition(); |
|
489 //UpdateScrollBar(); |
|
490 DrawDeferred(); |
|
491 } |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // CMRListPane::ListHeight |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 TInt CMRListPane::ListHeight() |
|
499 { |
|
500 FUNC_LOG; |
|
501 return iSize.iHeight; |
|
502 } |
|
503 |
|
504 // --------------------------------------------------------------------------- |
|
505 // CMRListPane::IsFieldBottomVisible |
|
506 // --------------------------------------------------------------------------- |
|
507 // |
|
508 TBool CMRListPane::IsFieldBottomVisible() |
|
509 { |
|
510 // Fetch the position information about currently focused field: |
|
511 CESMRField* field = iFactory.Field( iFocus ); |
|
512 TBool ret( EFalse ); |
|
513 if ( field->Rect().iBr.iY <= Rect().iBr.iY ) |
|
514 { |
|
515 ret = ETrue; |
|
516 } |
|
517 |
|
518 return ret; |
|
519 } |
|
520 |
|
521 // --------------------------------------------------------------------------- |
|
522 // CMRListPane::MoveFocusUpL |
|
523 // --------------------------------------------------------------------------- |
|
524 // |
|
525 TKeyResponse CMRListPane::MoveFocusUpL() |
|
526 { |
|
527 TInt ind( iFocus ); |
|
528 |
|
529 // search next visible focus item |
|
530 while ( ind > 0 ) |
|
531 { |
|
532 CESMRField* field = iFactory.Field( --ind ); |
|
533 |
|
534 if ( !field->IsNonFocusing() ) |
|
535 { |
|
536 field = iFactory.Field( ind ); |
|
537 |
|
538 CESMRField* focusedField = iFactory.Field( iFocus ); |
|
539 if ( field->IsVisible() ) |
|
540 { |
|
541 TBool canLoseFocus( |
|
542 focusedField->OkToLoseFocusL( field->FieldId() ) ); |
|
543 |
|
544 if ( canLoseFocus ) |
|
545 { |
|
546 iFocus = ind; |
|
547 |
|
548 // update focus index and scroll the item visible |
|
549 focusedField->SetOutlineFocusL( EFalse ); |
|
550 // This call changes the text color of previously |
|
551 // focused field |
|
552 focusedField->SetFocus( EFalse ); |
|
553 field->SetOutlineFocusL( ETrue ); |
|
554 // This call changes the text color of focused field |
|
555 field->SetFocus( ETrue ); |
|
556 |
|
557 ScrollItemVisible( iFocus ); |
|
558 } |
|
559 return EKeyWasConsumed; |
|
560 } |
|
561 } |
|
562 } |
|
563 return EKeyWasNotConsumed; |
|
564 } |
|
565 |
|
566 // --------------------------------------------------------------------------- |
|
567 // CMRListPane::MoveFocusDownL |
|
568 // --------------------------------------------------------------------------- |
|
569 // |
|
570 TKeyResponse CMRListPane::MoveFocusDownL() |
|
571 { |
|
572 TInt ind( iFocus ); |
|
573 |
|
574 // start searching next possible focus item |
|
575 TInt maxItemIndex = iFactory.Count() - 1; |
|
576 |
|
577 while ( ind < maxItemIndex ) |
|
578 { |
|
579 // only visible and focusable items can be focused |
|
580 CESMRField* field = iFactory.Field( ++ind ); |
|
581 |
|
582 if ( field->IsVisible() && !field->IsNonFocusing() ) |
|
583 { |
|
584 CESMRField* focusedField = iFactory.Field( iFocus ); |
|
585 |
|
586 TBool canLoseFocus( |
|
587 focusedField->OkToLoseFocusL( field->FieldId() ) ); |
|
588 |
|
589 // check it its ok for the old focus item to lose focus |
|
590 if ( canLoseFocus ) |
|
591 { |
|
592 iFocus = ind; |
|
593 |
|
594 // update focus index and scroll the item visible |
|
595 focusedField->SetOutlineFocusL( EFalse ); |
|
596 // This call changes the text color of previously |
|
597 // focused field |
|
598 focusedField->SetFocus( EFalse ); |
|
599 field->SetOutlineFocusL( ETrue ); |
|
600 // This call changes the text color of focused field |
|
601 field->SetFocus( ETrue ); |
|
602 |
|
603 ScrollItemVisible( iFocus ); |
|
604 } |
|
605 return EKeyWasConsumed; |
|
606 } |
|
607 } |
|
608 return EKeyWasNotConsumed; |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------------------------- |
|
612 // CMRListPane::MoveFocusL |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 TBool CMRListPane::MoveFocusL(TInt aNextFieldIndex) |
|
616 { |
|
617 // start searching next possible focus item |
|
618 TInt maxItemIndex = iFactory.Count() - 1; |
|
619 |
|
620 CESMRField* focusedField = iFactory.Field( iFocus ); |
|
621 |
|
622 // only visible and focusable items can be focused |
|
623 CESMRField* field = iFactory.Field( aNextFieldIndex ); |
|
624 |
|
625 if ( field->IsVisible() && !field->IsNonFocusing() ) |
|
626 { |
|
627 TBool canLoseFocus( |
|
628 focusedField->OkToLoseFocusL( field->FieldId() ) ); |
|
629 |
|
630 // check it its ok for the old focus item to lose focus |
|
631 if ( canLoseFocus ) |
|
632 { |
|
633 // tactile feedback if touch |
|
634 if ( AknLayoutUtils::PenEnabled() ) |
|
635 { |
|
636 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
637 if ( feedback ) |
|
638 { |
|
639 feedback->InstantFeedback( this, ETouchFeedbackBasic ); |
|
640 } |
|
641 } |
|
642 |
|
643 iFocus = aNextFieldIndex; |
|
644 |
|
645 // update focus index and scroll the item visible |
|
646 focusedField->SetOutlineFocusL( EFalse ); |
|
647 // This call changes the text color of previously |
|
648 // focused field |
|
649 focusedField->SetFocus( EFalse ); |
|
650 field->SetOutlineFocusL( ETrue ); |
|
651 // This call changes the text color of focused field |
|
652 field->SetFocus( ETrue ); |
|
653 DrawDeferred(); |
|
654 } |
|
655 return ETrue; // operation succeed |
|
656 } |
|
657 return EFalse; |
|
658 } |
|
659 |
|
660 // --------------------------------------------------------------------------- |
|
661 // CMRListPane::LayoutField |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 void CMRListPane::LayoutField( CESMRField& aField, |
|
665 const TPoint& aTl ) |
|
666 { |
|
667 TSize size( aField.MinimumSize() ); |
|
668 if ( aField.IsExpandable() ) |
|
669 { |
|
670 size.iHeight = aField.ExpandedHeight(); |
|
671 } |
|
672 aField.SetPosition( aTl ); |
|
673 aField.SetSize( size ); |
|
674 } |
|
675 |
|
676 // --------------------------------------------------------------------------- |
|
677 // CMRListPane::MoveFields |
|
678 // --------------------------------------------------------------------------- |
|
679 // |
|
680 void CMRListPane::MoveFields( TInt aIndex, |
|
681 TPoint& aTl ) |
|
682 { |
|
683 const TInt count( iFactory.Count() ); |
|
684 |
|
685 for ( TInt i = aIndex; i < count; ++i ) |
|
686 { |
|
687 CESMRField* field = iFactory.Field( i ); |
|
688 |
|
689 if ( field->IsVisible() ) |
|
690 { |
|
691 field->SetPosition( aTl ); |
|
692 |
|
693 aTl.iY += field->Size().iHeight; |
|
694 } |
|
695 } |
|
696 } |
|
697 |
|
698 // --------------------------------------------------------------------------- |
|
699 // CMRListPane::DoSetFocusL |
|
700 // --------------------------------------------------------------------------- |
|
701 // |
|
702 void CMRListPane::DoSetFocusL( TInt aFocus ) |
|
703 { |
|
704 TInt count( iFactory.Count() ); |
|
705 aFocus = Max( 0, Min( aFocus, count - 1 ) ); |
|
706 |
|
707 if ( aFocus != iFocus ) |
|
708 { |
|
709 // Get current focused field |
|
710 CESMRField* old = iFactory.Field( iFocus ); |
|
711 |
|
712 // Get next focused field |
|
713 CESMRField* field = iFactory.Field( aFocus ); |
|
714 while ( aFocus < count && !field->IsVisible() ) |
|
715 { |
|
716 field = iFactory.Field( aFocus++ ); |
|
717 } |
|
718 |
|
719 if ( !field->IsVisible() ) |
|
720 { |
|
721 aFocus = iFocus - 1; |
|
722 while ( aFocus > 0 && !field->IsVisible() ) |
|
723 { |
|
724 field = iFactory.Field( aFocus-- ); |
|
725 } |
|
726 } |
|
727 |
|
728 ASSERT( field->IsVisible() ); |
|
729 |
|
730 // Remove focus from old |
|
731 iFocus = aFocus; |
|
732 // update focus index and scroll the item visible |
|
733 old->SetOutlineFocusL( EFalse ); |
|
734 // Change the text color of previously focused field |
|
735 old->SetFocus( EFalse ); |
|
736 field->SetOutlineFocusL( ETrue ); |
|
737 // This call changes the text color of focused field |
|
738 field->SetFocus( ETrue ); |
|
739 } |
|
740 } |
|
741 |
|
742 // --------------------------------------------------------------------------- |
|
743 // CMRListPane::ScrollItemVisible |
|
744 // --------------------------------------------------------------------------- |
|
745 // |
|
746 void CMRListPane::ScrollItemVisible( TInt aInd ) |
|
747 { |
|
748 FUNC_LOG; |
|
749 CESMRField* field = NULL; |
|
750 if ( aInd == KErrNotFound ) |
|
751 { |
|
752 field = FocusedItem(); |
|
753 } |
|
754 else |
|
755 { |
|
756 field = iFactory.Field( aInd ); |
|
757 } |
|
758 |
|
759 ASSERT( field ); |
|
760 |
|
761 TRect rect( field->Rect() ); |
|
762 |
|
763 // move all items upwards |
|
764 TInt bottomRightY = Rect().iBr.iY; |
|
765 |
|
766 |
|
767 TInt fieldUpper(0); |
|
768 TInt fieldLower(0); |
|
769 field->GetMinimumVisibleVerticalArea( fieldUpper, fieldLower ); |
|
770 |
|
771 // desired position below view rect: |
|
772 if ( rect.iTl.iY + fieldLower > Rect().iBr.iY ) |
|
773 { |
|
774 // field rect Y position related to view rect: |
|
775 TInt fieldRelYPos = rect.iTl.iY - Size().iHeight; |
|
776 TInt px = fieldRelYPos + fieldLower; |
|
777 |
|
778 // if focus on first or last field: add margin height to |
|
779 // scroll amount. |
|
780 if ( iFocus == 0 || iFocus == iFactory.Count()-1 ) |
|
781 { |
|
782 px += 2 * KVerticalScrollMargin; |
|
783 } |
|
784 |
|
785 ScrollItemsUp( px ); |
|
786 } |
|
787 |
|
788 // move all items downwards. |
|
789 TInt topLeftY = Rect().iTl.iY; |
|
790 |
|
791 if ( rect.iBr.iY - (rect.Height() - fieldUpper ) < topLeftY ) |
|
792 { |
|
793 TInt fieldRelYPos = topLeftY - rect.iBr.iY; |
|
794 TInt px = fieldRelYPos + ( rect.Height() - fieldUpper); |
|
795 |
|
796 // if focus on first or last field: add margin height to |
|
797 // scroll amount. |
|
798 if ( iFocus == 0 || iFocus == iFactory.Count()-1 ) |
|
799 { |
|
800 px += KVerticalScrollMargin; |
|
801 } |
|
802 |
|
803 ScrollItemsDown( px ); |
|
804 } |
|
805 |
|
806 UpdateFocusPosition();//UpdateScrollBar(); |
|
807 DrawDeferred(); |
|
808 } |
|
809 |
|
810 // --------------------------------------------------------------------------- |
|
811 // CMRListPane::UpdateScrollBar |
|
812 // --------------------------------------------------------------------------- |
|
813 // |
|
814 void CMRListPane::UpdateScrollBar() |
|
815 { |
|
816 FUNC_LOG; |
|
817 // Scroll span is the size of the scrolled list, |
|
818 // including the items that doesn't fit in the screen |
|
819 TInt spanSize( 0 ); |
|
820 TInt hidden( 0 ); |
|
821 const TInt count(iFactory.Count()); |
|
822 for ( TInt i(0); i < count; i++ ) |
|
823 { |
|
824 CESMRField* field = iFactory.Field( i ); |
|
825 if ( field->IsVisible() ) |
|
826 { |
|
827 TRect rect( field->Rect() ); |
|
828 spanSize += rect.Height(); |
|
829 // Check if the field's top Y-position is hidden. |
|
830 if ( rect.iTl.iY < 0 ) |
|
831 { |
|
832 // whole field is hidden |
|
833 if ( rect.iBr.iY < 0 ) |
|
834 { |
|
835 hidden += rect.Height(); |
|
836 } |
|
837 // partly hidden: |
|
838 else |
|
839 { |
|
840 hidden += Abs( rect.iTl.iY ); |
|
841 } |
|
842 } |
|
843 } |
|
844 } |
|
845 |
|
846 iScrollModel.SetScrollSpan( spanSize ); |
|
847 iScrollModel.SetWindowSize( iSize.iHeight ); |
|
848 iScrollModel.SetFocusPosition( hidden ); |
|
849 |
|
850 } |
|
851 |
|
852 // --------------------------------------------------------------------------- |
|
853 // CMRListPane::ScrollItemsUp |
|
854 // --------------------------------------------------------------------------- |
|
855 // |
|
856 void CMRListPane::ScrollItemsUp( TInt aPx ) |
|
857 { |
|
858 FUNC_LOG; |
|
859 TInt count( iFactory.Count() ); |
|
860 for ( TInt i = 0; i < count; ++i ) |
|
861 { |
|
862 CESMRField* field = iFactory.Field(i); |
|
863 if ( field->IsVisible() ) |
|
864 { |
|
865 TPoint pos( field->Position() ); |
|
866 pos.iY -= aPx; |
|
867 if ( i == iTopVisibleIndex && pos.iY < 0 ) |
|
868 { |
|
869 iTopVisibleIndex = KErrNotFound; |
|
870 } |
|
871 else if ( iTopVisibleIndex == KErrNotFound && pos.iY >= 0 ) |
|
872 { |
|
873 iTopVisibleIndex = i; |
|
874 } |
|
875 field->SetPosition( pos ); |
|
876 } |
|
877 } |
|
878 } |
|
879 |
|
880 // --------------------------------------------------------------------------- |
|
881 // CMRListPane::ScrollItemsDown |
|
882 // --------------------------------------------------------------------------- |
|
883 // |
|
884 void CMRListPane::ScrollItemsDown( TInt aPx ) |
|
885 { |
|
886 FUNC_LOG; |
|
887 TInt count( iFactory.Count() ); |
|
888 for ( TInt i = 0; i < count; ++i ) |
|
889 { |
|
890 CESMRField* field = iFactory.Field( i ); |
|
891 if ( field->IsVisible() ) |
|
892 { |
|
893 TPoint pos( field->Position() ); |
|
894 pos.iY += aPx; |
|
895 if ( pos.iY >= 0 && ( i < iTopVisibleIndex || iTopVisibleIndex == KErrNotFound ) ) |
|
896 { |
|
897 iTopVisibleIndex = i; |
|
898 } |
|
899 field->SetPosition( pos ); |
|
900 } |
|
901 } |
|
902 } |
|
903 |
|
904 // --------------------------------------------------------------------------- |
|
905 // CMRListPane::ScrollView |
|
906 // --------------------------------------------------------------------------- |
|
907 // |
|
908 void CMRListPane::ScrollView( TInt aAmount ) |
|
909 { |
|
910 FUNC_LOG; |
|
911 |
|
912 if ( aAmount > 0 ) |
|
913 { |
|
914 // move list up |
|
915 ScrollItemsUp( aAmount ); |
|
916 UpdateFocusPosition(); |
|
917 DrawDeferred(); |
|
918 } |
|
919 else if ( aAmount < 0 ) |
|
920 { |
|
921 // move list down |
|
922 ScrollItemsDown( -aAmount ); |
|
923 UpdateFocusPosition(); |
|
924 DrawDeferred(); |
|
925 } |
|
926 } |
|
927 |
|
928 |
|
929 // --------------------------------------------------------------------------- |
|
930 // CMRListPane::UpdateFocusPosition |
|
931 // --------------------------------------------------------------------------- |
|
932 // |
|
933 void CMRListPane::UpdateFocusPosition() |
|
934 { |
|
935 TInt focusPos = 0; |
420 TInt focusPos = 0; |
936 TInt count = iFactory.Count(); |
421 TInt count = iFactory.Count(); |
937 for ( TInt i = 0; i < count; ++i ) |
422 for ( TInt i = 0; i < count; ++i ) |
938 { |
423 { |
939 CESMRField* field = iFactory.Field( i ); |
424 CESMRField* field = iFactory.Field( i ); |
959 // Rest of the fields are below scroll area origo |
444 // Rest of the fields are below scroll area origo |
960 break; |
445 break; |
961 } |
446 } |
962 } |
447 } |
963 } |
448 } |
964 |
449 |
965 iScrollModel.SetFocusPosition( focusPos ); |
450 return focusPos; |
966 } |
451 } |
967 |
452 |
968 |
453 // --------------------------------------------------------------------------- |
969 // ----------------------------------------------------------------------------- |
454 // CMRListPane::ScrollFieldsUp |
970 // CMRListPane::GetViewCenterPosition |
455 // --------------------------------------------------------------------------- |
971 // ----------------------------------------------------------------------------- |
456 // |
972 // |
457 void CMRListPane::ScrollFieldsUp( TInt aPx ) |
973 TPoint CMRListPane::GetViewCenterPosition() const |
458 { |
974 { |
459 FUNC_LOG; |
975 const TInt count( iFactory.Count() ); |
460 TPoint point = iFieldContainer->Position(); |
976 TInt topFieldYPos( 0 ); |
461 point.iY -= aPx; |
977 for ( TInt i = 0; i < count; i++ ) |
462 |
|
463 // This initializes Draw also |
|
464 iFieldContainer->SetPosition( point ); |
|
465 |
|
466 // Non-kinetic scrolling executed. Update |
|
467 // new position to physics. |
|
468 iPhysics->UpdateVerticalScrollIndex( UpdatedFocusPosition() ); |
|
469 |
|
470 DoUpdateScrollBar( UpdatedFocusPosition() ); |
|
471 } |
|
472 |
|
473 // --------------------------------------------------------------------------- |
|
474 // CMRListPane::ScrollFieldsDown |
|
475 // --------------------------------------------------------------------------- |
|
476 // |
|
477 void CMRListPane::ScrollFieldsDown( TInt aPx ) |
|
478 { |
|
479 FUNC_LOG; |
|
480 TPoint point = iFieldContainer->Position(); |
|
481 point.iY += aPx; |
|
482 |
|
483 // This initializes Draw also |
|
484 iFieldContainer->SetPosition( point ); |
|
485 // Non-kinetic scrolling executed. Update |
|
486 // new position to physics. |
|
487 iPhysics->UpdateVerticalScrollIndex( UpdatedFocusPosition() ); |
|
488 |
|
489 DoUpdateScrollBar( UpdatedFocusPosition() ); |
|
490 } |
|
491 |
|
492 |
|
493 // --------------------------------------------------------------------------- |
|
494 // CMRListPane::UpdateScrollBarAndPhysics |
|
495 // --------------------------------------------------------------------------- |
|
496 // |
|
497 void CMRListPane::UpdateScrollBarAndPhysics() |
|
498 { |
|
499 // Update physics world size |
|
500 iPhysics->InitPhysics(); |
|
501 |
|
502 // Update scrollbar |
|
503 DoUpdateScrollBar(); |
|
504 } |
|
505 |
|
506 |
|
507 // --------------------------------------------------------------------------- |
|
508 // CMRListPane::ShowControl |
|
509 // --------------------------------------------------------------------------- |
|
510 // |
|
511 void CMRListPane::ShowControl( TESMREntryFieldId aFieldId ) |
|
512 { |
|
513 iFieldContainer->ShowControl( aFieldId ); |
|
514 } |
|
515 |
|
516 // --------------------------------------------------------------------------- |
|
517 // CMRListPane::ShowControl |
|
518 // --------------------------------------------------------------------------- |
|
519 // |
|
520 TBool CMRListPane::IsControlVisible( TESMREntryFieldId aFieldId ) |
|
521 { |
|
522 return iFieldContainer->IsControlVisible( aFieldId ); |
|
523 } |
|
524 // --------------------------------------------------------------------------- |
|
525 // CMRListPane::GetResponseFieldsFieldId |
|
526 // --------------------------------------------------------------------------- |
|
527 // |
|
528 TESMREntryFieldId CMRListPane::GetResponseFieldsFieldId() |
|
529 { |
|
530 // TODO: Should be removed. This shouldn't be even a public function! |
|
531 CESMRField* rfield = iFactory.FieldById( EESMRFieldResponseArea ); |
|
532 |
|
533 if ( rfield && rfield->IsVisible() && !rfield->IsNonFocusing() ) |
|
534 { |
|
535 return EESMRFieldResponseArea; |
|
536 } |
|
537 else |
|
538 { |
|
539 return iFactory.Field(0)->FieldId(); |
|
540 } |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------------------------- |
|
544 // CMRListPane::ReActivateL |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 void CMRListPane::ReActivateL() |
|
548 { |
|
549 FUNC_LOG; |
|
550 TInt count = iFactory.Count(); |
|
551 |
|
552 for ( TInt i = 0; i < count; ++i ) |
978 { |
553 { |
979 CESMRField* field = iFactory.Field( i ); |
554 CESMRField* field = iFactory.Field( i ); |
980 |
555 |
981 if ( field->IsVisible() ) |
556 if ( !field->IsFieldActivated() ) |
982 { |
557 { |
983 topFieldYPos = field->Position().iY; |
558 field->SetContainerWindowL( *iFieldContainer ); |
984 break; |
559 field->SetListObserver( iFieldContainer ); |
985 } |
560 } |
986 } |
561 } |
987 TInt centerX = iSize.iWidth / 2; |
562 |
988 TInt visibleHeight = iSize.iHeight; |
563 // This "for" circle can not be mixed with the above one, since the |
989 |
564 // field->ActivateL() will call some functions which will traverse |
990 TInt centerY = visibleHeight / 2 - topFieldYPos; |
565 // all the fields, but that time, not all the fields have set the |
991 |
566 // container window. |
992 |
567 for ( TInt i = 0; i < count; ++i ) |
993 return TPoint( centerX, centerY ); |
568 { |
994 } |
569 CESMRField* field = iFactory.Field( i ); |
995 |
570 if ( !field->IsFieldActivated() ) |
996 |
571 { |
997 // ----------------------------------------------------------------------------- |
572 field->ActivateL(); |
|
573 } |
|
574 } |
|
575 } |
|
576 |
|
577 // --------------------------------------------------------------------------- |
998 // CMRListPane::HandlePointerEventL |
578 // CMRListPane::HandlePointerEventL |
999 // ----------------------------------------------------------------------------- |
579 // --------------------------------------------------------------------------- |
1000 // |
580 // |
1001 void CMRListPane::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
581 void CMRListPane::HandlePointerEventL( const TPointerEvent &aPointerEvent ) |
1002 { |
582 { |
1003 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
583 // Check if touch is enabled or not |
1004 { |
584 if( !AknLayoutUtils::PenEnabled() ) |
1005 TInt count = iFactory.Count(); |
585 { |
1006 for ( TInt i = 0; i < count; ++i ) |
586 return; |
1007 { |
587 } |
1008 CESMRField* field = static_cast<CESMRField*>(iFactory.Field( i ) ); |
588 |
1009 TRect r = field->Rect(); |
589 // Forward all listpane related events to physics api first. |
1010 TBool tapped = field->Rect().Contains( aPointerEvent.iPosition ); |
590 if ( iPhysics->HandlePointerEventL( aPointerEvent, iPhysicsActionOngoing ) ) |
1011 if (tapped && field->IsVisible() && !field->IsFocused() ) |
591 { |
|
592 DoUpdateScrollBar(); |
|
593 // Physics in action. If long tap detection is active, |
|
594 // it should be cancelled. |
|
595 if( iLongtapDetector->IsActive() ) |
|
596 { |
|
597 iLongtapDetector->Cancel(); |
|
598 } |
|
599 } |
|
600 |
|
601 if( !iPhysicsActionOngoing ) |
|
602 { |
|
603 // Offer pointer event to long tap detector |
|
604 iLongtapDetector->PointerEventL( aPointerEvent ); |
|
605 |
|
606 SetFocusAfterPointerEventL( aPointerEvent ); |
|
607 |
|
608 // If longtap event has been handled, then do not handle signal event anymore. |
|
609 if( !iLongTapEventConsumed ) |
|
610 { |
|
611 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
612 } |
|
613 else |
|
614 { |
|
615 iLongTapEventConsumed = EFalse; |
|
616 } |
|
617 |
|
618 UpdateClickedField( aPointerEvent ); |
|
619 } |
|
620 } |
|
621 |
|
622 // --------------------------------------------------------------------------- |
|
623 // CMRListPane::ActivateL |
|
624 // --------------------------------------------------------------------------- |
|
625 // |
|
626 void CMRListPane::ActivateL() |
|
627 { |
|
628 FUNC_LOG; |
|
629 // This ActiveteL is required only for setting the initial position |
|
630 // of the field container. After setting the position, physics is |
|
631 // initialized with new values also. |
|
632 |
|
633 CCoeControl::ActivateL(); |
|
634 iFieldContainer->SetPosition( Position() ); |
|
635 |
|
636 // Physics: |
|
637 iPhysics->InitPhysics(); |
|
638 } |
|
639 |
|
640 // --------------------------------------------------------------------------- |
|
641 // CMRListPane::PhysicsEmulationEnded |
|
642 // --------------------------------------------------------------------------- |
|
643 // |
|
644 void CMRListPane::PhysicsEmulationEnded() |
|
645 { |
|
646 FUNC_LOG; |
|
647 DoUpdateScrollBar(); |
|
648 iPhysicsActionOngoing = EFalse; |
|
649 Parent()->DrawDeferred(); |
|
650 } |
|
651 |
|
652 // --------------------------------------------------------------------------- |
|
653 // CMRListPane::SetFocusAfterPointerEventL |
|
654 // --------------------------------------------------------------------------- |
|
655 // |
|
656 void CMRListPane::SetFocusAfterPointerEventL( |
|
657 const TPointerEvent &aPointerEvent ) |
|
658 { |
|
659 FUNC_LOG; |
|
660 |
|
661 if( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
662 { |
|
663 TInt count( iFactory.Count() ); |
|
664 for( TInt i = 0; i < count; ++i ) |
|
665 { |
|
666 CESMRField* field = iFactory.Field( i ); |
|
667 if ( field->IsVisible() && |
|
668 field->Rect().Contains( aPointerEvent.iPosition ) ) |
|
669 { |
|
670 CESMRField* focusedField = iFieldContainer->FocusedField(); |
|
671 |
|
672 if ( field != focusedField ) |
|
673 { |
|
674 TBool canLoseFocus( |
|
675 focusedField->OkToLoseFocusL( field->FieldId() ) ); |
|
676 |
|
677 if ( canLoseFocus ) |
|
678 { |
|
679 iFieldContainer->SetControlFocusedL( field->FieldId() ); |
|
680 } |
|
681 } |
|
682 |
|
683 break; |
|
684 } |
|
685 } |
|
686 } |
|
687 } |
|
688 |
|
689 // --------------------------------------------------------------------------- |
|
690 // CMRListPane::UpdateClickedField |
|
691 // --------------------------------------------------------------------------- |
|
692 // |
|
693 void CMRListPane::UpdateClickedField( const TPointerEvent &aPointerEvent ) |
|
694 { |
|
695 FUNC_LOG; |
|
696 TInt fieldCount( iFactory.Count() ); |
|
697 |
|
698 for( TInt i = 0; i < fieldCount; ++i ) |
|
699 { |
|
700 if( iFactory.Field( i )->Rect().Contains( |
|
701 aPointerEvent.iPosition ) ) |
|
702 { |
|
703 if( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
1012 { |
704 { |
1013 MoveFocusL( i ); |
705 iClickedField = iFactory.Field( i ); |
1014 break; |
|
1015 } |
706 } |
1016 } |
707 } |
1017 } |
708 } |
1018 // here some fields can further adjust their state (for example, CESMRResponseField has sub-fields) |
709 } |
1019 CCoeControl::HandlePointerEventL(aPointerEvent); |
710 |
1020 } |
711 // --------------------------------------------------------------------------- |
|
712 // CMRListPane::HiddenFocus |
|
713 // --------------------------------------------------------------------------- |
|
714 // |
|
715 TBool CMRListPane::HiddenFocus() |
|
716 { |
|
717 FUNC_LOG; |
|
718 TBool hiddenFocus( EFalse ); |
|
719 |
|
720 CESMRField* focusedField( iFieldContainer->FocusedField() ); |
|
721 TInt focusedFieldIndex( IndexByFieldId( |
|
722 iFactory, focusedField->FieldId() ) ); |
|
723 |
|
724 if ( focusedFieldIndex < iFactory.Count() ) |
|
725 { |
|
726 TRect focusedFieldRect( focusedField->Rect() ); |
|
727 TRect listPaneRect( Rect() ); |
|
728 |
|
729 TInt fieldTopY( focusedFieldRect.iTl.iY ); |
|
730 TInt fieldBottomY( focusedFieldRect.iBr.iY ); |
|
731 |
|
732 TInt listTopY( listPaneRect.iTl.iY ); |
|
733 TInt listBottomY( listPaneRect.iBr.iY ); |
|
734 |
|
735 if ( ( fieldBottomY > listBottomY || |
|
736 fieldTopY < listTopY ) && |
|
737 focusedFieldRect.Height() < listPaneRect.Height() ) |
|
738 { |
|
739 hiddenFocus = ETrue; |
|
740 } |
|
741 } |
|
742 return hiddenFocus; |
|
743 } |
|
744 |
1021 // End of file |
745 // End of file |
1022 |
|