19 |
19 |
20 |
20 |
21 // INCLUDES |
21 // INCLUDES |
22 #include <eikrted.h> |
22 #include <eikrted.h> |
23 #include <txtrich.h> // for CRichText |
23 #include <txtrich.h> // for CRichText |
24 #include "ItemFinder.h" |
24 #include <ItemFinder.h> |
|
25 #include <itemfinderobserver.h> |
|
26 #include <aknphysicscrkeys.h> |
25 #include <finditemengine.h> |
27 #include <finditemengine.h> |
26 #include <commonphoneparser.h> |
28 #include <commonphoneparser.h> |
27 #include <txtfrmat.h> |
29 #include <txtfrmat.h> |
28 #include <AknUtils.h> // for AknUtils |
30 #include <AknUtils.h> // for AknUtils |
29 #include <AknsUtils.h> |
31 #include <AknsUtils.h> |
|
32 #include <touchfeedback.h> |
30 |
33 |
31 // scheme recog |
34 // scheme recog |
32 #include <ecom/ecom.h> |
35 #include <ecom/ecom.h> |
33 #include <ecom/implementationinformation.h> |
36 #include <ecom/implementationinformation.h> |
|
37 #include <coemain.h> |
34 |
38 |
35 #include <centralrepository.h> |
39 #include <centralrepository.h> |
36 #include <CommonUiInternalCRKeys.h> |
40 #include <CommonUiInternalCRKeys.h> |
37 |
41 |
38 // CONSTANTS |
42 // CONSTANTS |
39 const TInt KMINTAGLENGTH(5); |
43 const TInt KMINTAGLENGTH(5); |
|
44 const TInt KDragTresholdDefault(20); |
40 _LIT( KHTTPPREFIX, "http://"); |
45 _LIT( KHTTPPREFIX, "http://"); |
41 _LIT( RTSP, "rtsp"); |
46 _LIT( RTSP, "rtsp"); |
42 _LIT( KTELPREFIX, "tel:"); |
47 _LIT( KTELPREFIX, "tel:"); |
43 |
48 |
44 const TInt KItemFinderMinDigitsToFind = 5; |
49 const TInt KItemFinderMinDigitsToFind = 5; |
194 } |
199 } |
195 if ( iSchemeResolver ) |
200 if ( iSchemeResolver ) |
196 { |
201 { |
197 delete iSchemeResolver; |
202 delete iSchemeResolver; |
198 } |
203 } |
199 } |
204 if ( iItemFinderObserver && iCoeEnv ) // if still listening to events |
200 |
205 { |
201 CItemFinder::CItemFinder( TInt aFindFlags ): iFlags( aFindFlags ) |
206 iCoeEnv->RemoveMessageMonitorObserver( *this ); |
|
207 } |
|
208 } |
|
209 |
|
210 CItemFinder::CItemFinder( TInt aFindFlags ): iFlags( aFindFlags ), |
|
211 iCoeEnv( CCoeEnv::Static() ) |
202 {} |
212 {} |
203 |
213 |
204 void CItemFinder::ConstructL() |
214 void CItemFinder::ConstructL() |
205 { |
215 { |
206 iMinDigitsToFind = KItemFinderMinDigitsToFind; // default |
216 iMinDigitsToFind = KItemFinderMinDigitsToFind; // default |
207 iCurrentItemExt = new (ELeave) CFindItemExt(); |
217 iCurrentItemExt = new (ELeave) CFindItemExt(); |
208 CRichText::ActivateParserL(this); |
218 CRichText::ActivateParserL(this); |
209 iSchemeResolver = CSchemeResolver::NewL(); |
219 iSchemeResolver = CSchemeResolver::NewL(); |
210 iMinDigitsToFind = GetMinDigitsToFindL(); // variated. |
220 iMinDigitsToFind = GetMinDigitsToFindL(); // variated. |
|
221 iFeedback = MTouchFeedback::Instance(); |
211 } |
222 } |
212 |
223 |
213 TInt CItemFinder::GetMinDigitsToFindL() |
224 TInt CItemFinder::GetMinDigitsToFindL() |
214 { |
225 { |
215 TInt err = KErrNone; |
226 TInt err = KErrNone; |
1105 return KNullDesC(); |
1132 return KNullDesC(); |
1106 } |
1133 } |
1107 } |
1134 } |
1108 } |
1135 } |
1109 |
1136 |
|
1137 // ----------------------------------------------------------------------------- |
|
1138 // CItemFinder::SetItemFinderObserverL() |
|
1139 // ----------------------------------------------------------------------------- |
|
1140 // |
|
1141 EXPORT_C void CItemFinder::SetItemFinderObserverL( |
|
1142 MAknItemFinderObserver* aObserver ) |
|
1143 { |
|
1144 if ( !iItemFinderObserver && aObserver ) // client registers |
|
1145 { |
|
1146 if ( iCoeEnv ) |
|
1147 { |
|
1148 iCoeEnv->AddMessageMonitorObserverL( *this ); |
|
1149 } |
|
1150 } |
|
1151 else if ( iItemFinderObserver && !aObserver ) // client unregisters |
|
1152 { |
|
1153 if ( iCoeEnv ) |
|
1154 { |
|
1155 iCoeEnv->RemoveMessageMonitorObserver( *this ); |
|
1156 } |
|
1157 } |
|
1158 |
|
1159 iItemFinderObserver = aObserver; |
|
1160 } |
|
1161 |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // CItemFinder::MonitorWsMessage |
|
1164 // ----------------------------------------------------------------------------- |
|
1165 // |
|
1166 void CItemFinder::MonitorWsMessage( const TWsEvent& aEvent ) |
|
1167 { |
|
1168 if ( !iItemFinderObserver ) |
|
1169 { |
|
1170 // if no observer given, nothing is done here. |
|
1171 return; |
|
1172 } |
|
1173 if ( !iEditor ) |
|
1174 { |
|
1175 return; |
|
1176 } |
|
1177 if ( EEventPointer == aEvent.Type() ) |
|
1178 { |
|
1179 CCoeControl* targetControl = |
|
1180 reinterpret_cast<CCoeControl*>( aEvent.Handle() ); |
|
1181 if ( targetControl ) |
|
1182 { |
|
1183 TRAP_IGNORE ( MonitorPointerEventL( |
|
1184 *aEvent.Pointer(), targetControl ) ); |
|
1185 } |
|
1186 } |
|
1187 else if ( aEvent.Type() == EEventKeyDown ) |
|
1188 { |
|
1189 iAllowHighlight = ETrue; |
|
1190 |
|
1191 // if an item is selected and select was pressed, send key event |
|
1192 TKeyEvent* keyEvent = aEvent.Key(); |
|
1193 |
|
1194 if ( keyEvent && ( EStdKeyDevice3 == keyEvent->iScanCode |
|
1195 || EStdKeyEnter == keyEvent->iScanCode |
|
1196 || EStdKeyNkpEnter == keyEvent->iScanCode ) |
|
1197 && iItemFinderObserver |
|
1198 && ( KNullDesC().Compare ( CurrentSelection() ) ) ) |
|
1199 { |
|
1200 // calling observer |
|
1201 TRAP_IGNORE( iItemFinderObserver->HandleFindItemEventL( |
|
1202 *iCurrentItemExt, MAknItemFinderObserver::EKeyEvent ) ); |
|
1203 } |
|
1204 } |
|
1205 else if ( aEvent.Type() == EEventKeyUp ) |
|
1206 { |
|
1207 iAllowHighlight = EFalse; |
|
1208 } |
|
1209 } |
|
1210 |
|
1211 // ----------------------------------------------------------------------------- |
|
1212 // CItemFinder::RefreshEditor |
|
1213 // ----------------------------------------------------------------------------- |
|
1214 // |
1110 TInt CItemFinder::RefreshEditor() |
1215 TInt CItemFinder::RefreshEditor() |
1111 { |
1216 { |
1112 TInt error = KErrNone; |
1217 TInt error = KErrNone; |
1113 TRAP( error, // Non-leaving method. |
1218 TRAP( error, // Non-leaving method. |
1114 { |
1219 { |
1135 } |
1240 } |
1136 } ); // TRAP |
1241 } ); // TRAP |
1137 return error; |
1242 return error; |
1138 } |
1243 } |
1139 |
1244 |
|
1245 // --------------------------------------------------------------------------- |
|
1246 // CItemFinder::SetWindowControl |
|
1247 // --------------------------------------------------------------------------- |
|
1248 // |
|
1249 void CItemFinder::SetWindowControl( CCoeControl* aControl ) |
|
1250 { |
|
1251 if ( aControl ) |
|
1252 { |
|
1253 CCoeControl* windowControl( aControl ); |
|
1254 while ( windowControl && !windowControl->OwnsWindow() ) |
|
1255 { |
|
1256 if ( windowControl == windowControl->Parent() ) |
|
1257 { |
|
1258 return; |
|
1259 } |
|
1260 windowControl = windowControl->Parent(); |
|
1261 } |
|
1262 if ( windowControl ) |
|
1263 { |
|
1264 iWindowControl = windowControl; |
|
1265 } |
|
1266 } |
|
1267 } |
|
1268 |
|
1269 // -------------------------------------------------------------------------- |
|
1270 // CItemFinder::MonitorPointerEventL |
|
1271 // -------------------------------------------------------------------------- |
|
1272 // |
|
1273 void CItemFinder::MonitorPointerEventL( TPointerEvent &aPointerEvent, |
|
1274 CCoeControl* aTargetControl ) |
|
1275 { |
|
1276 if ( !iWindowControl ) |
|
1277 { |
|
1278 SetWindowControl( *iEditor ); |
|
1279 } |
|
1280 if ( aTargetControl == iWindowControl ) |
|
1281 { |
|
1282 TPoint tapPoint ( aPointerEvent.iPosition ); |
|
1283 ModifyPointerEvent( tapPoint ); |
|
1284 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
1285 { |
|
1286 iAllowHighlight = ETrue; |
|
1287 TBool tapped ( EFalse ); |
|
1288 // Trapping because iAllowHighlight needs to be set to value EFalse |
|
1289 // also if ItemWasTappedL leaves |
|
1290 TRAP_IGNORE( tapped = ItemWasTappedL( tapPoint ) ); |
|
1291 iAllowHighlight = EFalse; |
|
1292 // if no item was tapped remove selection |
|
1293 if ( tapped ) |
|
1294 { |
|
1295 if ( iFeedback ) |
|
1296 { |
|
1297 iFeedback->InstantFeedback( ETouchFeedbackBasicButton ); |
|
1298 } |
|
1299 iTapPoint = tapPoint; |
|
1300 } |
|
1301 else |
|
1302 { |
|
1303 (*iEditor)->ClearSelectionL(); |
|
1304 ResetCurrentItem(); |
|
1305 } |
|
1306 } |
|
1307 else if ( aPointerEvent.iType == TPointerEvent::EDrag ) |
|
1308 { |
|
1309 if ( iCurrentItemExt->iItemType != ENoneSelected ) |
|
1310 { |
|
1311 if ( Abs( iTapPoint.iX - tapPoint.iX ) > DragThresholdL() || |
|
1312 Abs( iTapPoint.iY - tapPoint.iY ) > DragThresholdL() ) |
|
1313 { |
|
1314 (*iEditor)->ClearSelectionL(); |
|
1315 ResetCurrentItem(); |
|
1316 } |
|
1317 } |
|
1318 } |
|
1319 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
1320 { |
|
1321 if ( iCurrentItemExt->iItemType != ENoneSelected ) |
|
1322 { |
|
1323 if ( iItemFinderObserver ) |
|
1324 { |
|
1325 // calling observer |
|
1326 iItemFinderObserver->HandleFindItemEventL( |
|
1327 *iCurrentItemExt, |
|
1328 MAknItemFinderObserver::EPointerEvent ); |
|
1329 } |
|
1330 // remove selection with button up event |
|
1331 (*iEditor)->ClearSelectionL(); |
|
1332 if ( !(*iEditor)->IsFocused() ) |
|
1333 { |
|
1334 // ClearSelectionL() does not draw itself if focus was lost |
|
1335 |
|
1336 TRect rect = (*iEditor)->TextLayout()->GetLineRectL( |
|
1337 iCurrentItemExt->iStart, iCurrentItemExt->iEnd ); |
|
1338 rect.Move( (*iEditor)->Position() ); |
|
1339 rect.iTl.iX = 0; |
|
1340 rect.iBr.iX = (*iEditor)->Rect().iBr.iX; |
|
1341 |
|
1342 TPoint begin ( 0, 0 ); |
|
1343 TPoint end ( 0, 0 ); |
|
1344 (*iEditor)->TextLayout()->DocPosToXyPosL( |
|
1345 iCurrentItemExt->iStart, begin ); |
|
1346 (*iEditor)->TextLayout()->DocPosToXyPosL( |
|
1347 iCurrentItemExt->iEnd, end ); |
|
1348 |
|
1349 if ( begin.iY != end.iY ) |
|
1350 { |
|
1351 // item spawns two lines |
|
1352 // make rectangle cover both lines |
|
1353 rect.iBr.iY += ( end.iY - begin.iY ); |
|
1354 } |
|
1355 // draw clearable area |
|
1356 (*iEditor)->DrawNow( rect ); |
|
1357 } |
|
1358 } |
|
1359 } |
|
1360 } |
|
1361 } |
|
1362 |
|
1363 // -------------------------------------------------------------------------- |
|
1364 // CItemFinder::ModifyPointerEvent |
|
1365 // -------------------------------------------------------------------------- |
|
1366 // |
|
1367 void CItemFinder::ModifyPointerEvent( TPoint &aTapPoint ) |
|
1368 { |
|
1369 aTapPoint -= (*iEditor)->Position(); |
|
1370 } |
|
1371 |
|
1372 // -------------------------------------------------------------------------- |
|
1373 // CItemFinder::DragThresholdL |
|
1374 // -------------------------------------------------------------------------- |
|
1375 // |
|
1376 TInt CItemFinder::DragThresholdL() |
|
1377 { |
|
1378 if ( 0 == iDragThreshold ) |
|
1379 { |
|
1380 CRepository* cenrep ( NULL ); |
|
1381 TRAPD( err, cenrep = CRepository::NewL( KCRUidAknPhysicsSettings ) ); |
|
1382 if ( KErrNone == err && cenrep ) |
|
1383 { |
|
1384 CleanupStack::PushL( cenrep ); |
|
1385 cenrep->Get( KDragTreshold, iDragThreshold ); |
|
1386 CleanupStack::PopAndDestroy( cenrep ); |
|
1387 } |
|
1388 } |
|
1389 if ( 0 == iDragThreshold ) |
|
1390 { |
|
1391 // cenrep failed, use fallback value |
|
1392 iDragThreshold = KDragTresholdDefault; |
|
1393 } |
|
1394 return iDragThreshold; |
|
1395 } |
|
1396 |
|
1397 // -------------------------------------------------------------------------- |
|
1398 // CItemFinder::HasSelection |
|
1399 // -------------------------------------------------------------------------- |
|
1400 // |
|
1401 TBool CItemFinder::HasSelection() const |
|
1402 { |
|
1403 return static_cast<TBool>( (*iEditor)->SelectionLength() ); |
|
1404 } |
|
1405 |
1140 // End of File |
1406 // End of File |