50 self->ConstructL(); |
50 self->ConstructL(); |
51 return self; |
51 return self; |
52 } |
52 } |
53 |
53 |
54 // --------------------------------------------------------------------------- |
54 // --------------------------------------------------------------------------- |
|
55 // CAknEdwinPhysicsHandler::NewL |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewL( CEikEdwin& aEdwin, CAknPhysics* aPhysics ) |
|
59 { |
|
60 CAknEdwinPhysicsHandler* self = CAknEdwinPhysicsHandler::NewLC( aEdwin, aPhysics ); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CAknEdwinPhysicsHandler::NewLC |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewLC( CEikEdwin& aEdwin, CAknPhysics* aPhysics ) |
|
70 { |
|
71 CAknEdwinPhysicsHandler* self = new ( ELeave ) CAknEdwinPhysicsHandler( |
|
72 aEdwin, aPhysics ); |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
55 // CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler |
79 // CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler |
56 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
57 // |
81 // |
58 CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler() |
82 CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler() |
59 { |
83 { |
60 delete iPhysics; |
84 if (iOwnsPhysics) |
|
85 { |
|
86 delete iPhysics; |
|
87 } |
61 } |
88 } |
62 |
89 |
63 // --------------------------------------------------------------------------- |
90 // --------------------------------------------------------------------------- |
64 // CAknEdwinPhysicsHandler::HandlePointerEvent |
91 // CAknEdwinPhysicsHandler::HandlePointerEvent |
65 // --------------------------------------------------------------------------- |
92 // --------------------------------------------------------------------------- |
66 // |
93 // |
67 void CAknEdwinPhysicsHandler::HandlePointerEvent( |
94 void CAknEdwinPhysicsHandler::HandlePointerEvent( |
68 const TPointerEvent& aPointerEvent ) |
95 const TPointerEvent& aPointerEvent ) |
69 { |
96 { |
70 if ( aPointerEvent.iType == TPointerEvent::EButton1Down && |
97 if (iOwnsPhysics) |
71 iViewRect.Contains( aPointerEvent.iPosition ) && |
98 { |
72 iEventUnblockingAllowed ) |
99 if ( aPointerEvent.iType == TPointerEvent::EButton1Down && |
73 { |
100 iViewRect.Contains( aPointerEvent.iPosition ) && |
74 BlockEvents( EFalse ); |
101 iEventUnblockingAllowed ) |
75 iPreviousYCoordinate = - KMaxWorldSize; |
102 { |
76 } |
103 BlockEvents( EFalse ); |
77 if ( iEventsBlocked ) |
104 iPreviousYCoordinate = - KMaxWorldSize; |
78 { |
105 } |
79 return; |
106 if ( iEventsBlocked ) |
80 } |
107 { |
81 |
108 return; |
82 // Dragging/flicking logic |
109 } |
83 |
110 |
84 if ( aPointerEvent.iType == TPointerEvent::EButton1Down && |
111 // Dragging/flicking logic |
85 iViewRect.Contains( aPointerEvent.iPosition ) ) |
112 |
86 { |
113 if ( aPointerEvent.iType == TPointerEvent::EButton1Down && |
87 // Pointer down inside view rect, set flag to allow dragging |
114 iViewRect.Contains( aPointerEvent.iPosition ) ) |
88 // and initialize values |
115 { |
89 iFlags.Set( EFlagDraggingAllowed ); |
116 // Pointer down inside view rect, set flag to allow dragging |
90 iStartPosition = aPointerEvent.iPosition; |
117 // and initialize values |
91 StopPhysics(); |
118 iFlags.Set( EFlagDraggingAllowed ); |
92 |
119 iStartPosition = aPointerEvent.iPosition; |
93 iStartTime.HomeTime(); |
120 StopPhysics(); |
94 iDragThresholdExceeded = EFalse; |
121 |
95 iFlags.Clear( EFlagBouncingUp ); |
122 iStartTime.HomeTime(); |
96 iFlags.Clear( EFlagBouncingDown ); |
123 iDragThresholdExceeded = EFalse; |
97 return; |
124 iFlags.Clear( EFlagBouncingUp ); |
98 } |
125 iFlags.Clear( EFlagBouncingDown ); |
99 if ( iFlags.IsClear( EFlagDraggingAllowed ) ) |
126 return; |
100 { |
127 } |
101 return; |
128 if ( iFlags.IsClear( EFlagDraggingAllowed ) ) |
102 } |
129 { |
103 |
130 return; |
104 if ( aPointerEvent.iType == TPointerEvent::EDrag ) |
131 } |
105 { |
132 |
106 if ( !iDragThresholdExceeded ) |
133 if ( aPointerEvent.iType == TPointerEvent::EDrag ) |
107 { |
134 { |
108 TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY ); |
135 if ( !iDragThresholdExceeded ) |
109 if ( Abs( drag ) > DragThreshold() ) |
|
110 { |
136 { |
111 iDragThresholdExceeded = ETrue; |
137 TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY ); |
|
138 if ( Abs( drag ) > DragThreshold() ) |
|
139 { |
|
140 iDragThresholdExceeded = ETrue; |
|
141 } |
112 } |
142 } |
113 } |
143 else |
114 else |
144 { |
115 { |
145 TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY ); |
116 TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY ); |
146 |
117 |
147 TPoint deltaPoint( 0, deltaY ); |
118 TPoint deltaPoint( 0, deltaY ); |
148 iPhysics->RegisterPanningPosition( deltaPoint ); |
119 iPhysics->RegisterPanningPosition( deltaPoint ); |
149 } |
120 } |
150 iPrevPosition = aPointerEvent.iPosition; |
121 |
151 } |
122 iPrevPosition = aPointerEvent.iPosition; |
152 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
123 } |
153 { |
124 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
154 if ( iFlags.IsClear( EFlagDraggingAllowed ) ) |
125 { |
155 { |
126 if ( iFlags.IsClear( EFlagDraggingAllowed ) ) |
156 return; |
127 { |
157 } |
128 return; |
158 |
129 } |
159 iFlags.Clear( EFlagDraggingAllowed ); |
130 |
160 TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY ); |
131 iFlags.Clear( EFlagDraggingAllowed ); |
161 iPhysics->StartPhysics( drag, iStartTime ); |
132 TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY ); |
162 } |
133 iPhysics->StartPhysics( drag, iStartTime ); |
|
134 } |
163 } |
135 } |
164 } |
136 |
165 |
137 // --------------------------------------------------------------------------- |
166 // --------------------------------------------------------------------------- |
138 // CAknEdwinPhysicsHandler::SetViewRect |
167 // CAknEdwinPhysicsHandler::SetViewRect |
147 // CAknEdwinPhysicsHandler::InitPhysicsL |
176 // CAknEdwinPhysicsHandler::InitPhysicsL |
148 // --------------------------------------------------------------------------- |
177 // --------------------------------------------------------------------------- |
149 // |
178 // |
150 void CAknEdwinPhysicsHandler::InitPhysicsL() |
179 void CAknEdwinPhysicsHandler::InitPhysicsL() |
151 { |
180 { |
152 TSize totalSize( iViewRect.Width(), iViewRect.Height() + KMaxWorldSize ); |
181 if (iOwnsPhysics) |
153 TSize viewSize( iViewRect.Width(), iViewRect.Height() ); |
182 { |
154 |
183 TSize totalSize( iViewRect.Width(), iViewRect.Height() |
155 |
184 + KMaxWorldSize ); |
156 CTextLayout* layout = iEdwin.TextLayout(); |
185 TSize viewSize( iViewRect.Width(), iViewRect.Height() ); |
157 |
186 |
158 if ( layout ) |
187 CTextLayout* layout = iEdwin.TextLayout(); |
159 { |
188 |
160 TInt pixelsAbove = layout->PixelsAboveBand(); |
189 if ( layout ) |
161 if ( pixelsAbove > 0 ) |
190 { |
162 { |
191 TInt pixelsAbove = layout->PixelsAboveBand(); |
163 MoveScrollIndex( -pixelsAbove ); |
192 if ( pixelsAbove > 0 ) |
164 } |
193 { |
165 } |
194 MoveScrollIndex( -pixelsAbove ); |
166 |
195 } |
167 iPhysics->InitPhysicsL( totalSize, viewSize, EFalse ); |
196 } |
168 } |
197 |
|
198 iPhysics->InitPhysicsL( totalSize, viewSize, EFalse ); |
|
199 } |
|
200 } |
169 |
201 |
170 // --------------------------------------------------------------------------- |
202 // --------------------------------------------------------------------------- |
171 // CAknEdwinPhysicsHandler::MoveScrollIndex |
203 // CAknEdwinPhysicsHandler::MoveScrollIndex |
172 // --------------------------------------------------------------------------- |
204 // --------------------------------------------------------------------------- |
173 // |
205 // |
318 |
355 |
319 // --------------------------------------------------------------------------- |
356 // --------------------------------------------------------------------------- |
320 // CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler |
357 // CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler |
321 // --------------------------------------------------------------------------- |
358 // --------------------------------------------------------------------------- |
322 // |
359 // |
323 CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin ) : |
360 CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin, |
|
361 CAknPhysics* aPhysics ) : |
324 iWorldIndex( 0 ), |
362 iWorldIndex( 0 ), |
325 iPreviousWorldIndex( 0 ), |
363 iPreviousWorldIndex( 0 ), |
326 iPhysics( NULL ), |
364 iPhysics( aPhysics ), |
327 iEdwin( aEdwin ) |
365 iEdwin( aEdwin ), |
|
366 iOwnsPhysics( aPhysics == NULL ) |
328 { |
367 { |
329 } |
368 } |
330 |
369 |
331 // --------------------------------------------------------------------------- |
370 // --------------------------------------------------------------------------- |
332 // CAknEdwinPhysicsHandler::ConstructL |
371 // CAknEdwinPhysicsHandler::ConstructL |
333 // --------------------------------------------------------------------------- |
372 // --------------------------------------------------------------------------- |
334 // |
373 // |
335 void CAknEdwinPhysicsHandler::ConstructL() |
374 void CAknEdwinPhysicsHandler::ConstructL() |
336 { |
375 { |
337 iPhysics = CAknPhysics::NewL( *this, &iEdwin ); |
376 if (iOwnsPhysics) |
|
377 { |
|
378 iPhysics = CAknPhysics::NewL( *this, &iEdwin ); |
|
379 } |
338 } |
380 } |
339 |
381 |
340 // --------------------------------------------------------------------------- |
382 // --------------------------------------------------------------------------- |
341 // CAknEdwinPhysicsHandler::ScrollView |
383 // CAknEdwinPhysicsHandler::ScrollView |
342 // --------------------------------------------------------------------------- |
384 // --------------------------------------------------------------------------- |