15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 // System includes |
18 // System includes |
19 #include <AknUtils.h> |
19 #include <AknUtils.h> |
|
20 #include <AknPriv.hrh> |
20 |
21 |
21 // User includes |
22 // User includes |
22 #include "xnappuiadapter.h" |
23 #include "xnappuiadapter.h" |
|
24 #include "xnviewadapter.h" |
23 #include "xnfocuscontrol.h" |
25 #include "xnfocuscontrol.h" |
24 #include "xnkeyeventdispatcher.h" |
26 #include "xnkeyeventdispatcher.h" |
25 #include "xntype.h" |
27 #include "xntype.h" |
26 #include "xncomponentnodeimpl.h" |
28 #include "xncomponentnodeimpl.h" |
27 #include "xnproperty.h" |
29 #include "xnproperty.h" |
38 // Local macros |
40 // Local macros |
39 #define IS_ARROW_KEY( k ) \ |
41 #define IS_ARROW_KEY( k ) \ |
40 ( k == EStdKeyLeftArrow || k == EStdKeyRightArrow || \ |
42 ( k == EStdKeyLeftArrow || k == EStdKeyRightArrow || \ |
41 k == EStdKeyUpArrow || k == EStdKeyDownArrow ) |
43 k == EStdKeyUpArrow || k == EStdKeyDownArrow ) |
42 |
44 |
43 const TInt KOneView = 1; |
45 // Constants |
|
46 const TInt KOneView( 1 ); |
|
47 |
|
48 _LIT8( KEnablePartialInput, "splitinputenabled" ); |
|
49 _LIT8( KTextEditor, "texteditor" ); |
44 |
50 |
45 // ----------------------------------------------------------------------------- |
51 // ----------------------------------------------------------------------------- |
46 // SetInitialFocusL |
52 // SetInitialFocusL |
47 // ----------------------------------------------------------------------------- |
53 // ----------------------------------------------------------------------------- |
48 // |
54 // |
169 // |
179 // |
170 void CXnKeyEventDispatcher::ConstructL() |
180 void CXnKeyEventDispatcher::ConstructL() |
171 { |
181 { |
172 MakeVisible( EFalse ); |
182 MakeVisible( EFalse ); |
173 |
183 |
174 iUiEngine.ViewManager()->AddObserver( *this ); |
184 CXnAppUiAdapter& appui( iUiEngine.AppUiAdapter() ); |
|
185 |
|
186 appui.UiStateListener().AddObserver( *this ); |
|
187 |
|
188 appui.ViewManager().AddObserver( *this ); |
175 |
189 |
176 iCoeEnv->AddMessageMonitorObserverL( *this ); |
190 iCoeEnv->AddMessageMonitorObserverL( *this ); |
177 } |
191 } |
178 |
192 |
179 // ----------------------------------------------------------------------------- |
193 // ----------------------------------------------------------------------------- |
226 } |
240 } |
227 } |
241 } |
228 } |
242 } |
229 |
243 |
230 // ----------------------------------------------------------------------------- |
244 // ----------------------------------------------------------------------------- |
|
245 // CXnKeyEventDispatcher::NotifyStatusPaneSizeChanged() |
|
246 // |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CXnKeyEventDispatcher::NotifyStatusPaneSizeChanged() |
|
250 { |
|
251 // No implementation required |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CXnKeyEventDispatcher::NotifyResourceChanged() |
|
256 // |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CXnKeyEventDispatcher::NotifyResourceChanged( TInt aType ) |
|
260 { |
|
261 if ( aType == KAknSplitInputEnabled ) |
|
262 { |
|
263 if ( iActiveTextEditor ) |
|
264 { |
|
265 CXnProperty* prop( NULL ); |
|
266 |
|
267 TRAP_IGNORE( prop = |
|
268 iActiveTextEditor->GetPropertyL( KEnablePartialInput ) ); |
|
269 |
|
270 if ( prop && prop->StringValue() == XnPropertyNames::KTrue ) |
|
271 { |
|
272 iUiEngine.EnablePartialTouchInput( iActiveTextEditor, ETrue ); |
|
273 } |
|
274 } |
|
275 } |
|
276 else if ( aType == KAknSplitInputDisabled ) |
|
277 { |
|
278 iUiEngine.EnablePartialTouchInput( NULL, EFalse ); |
|
279 } |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
231 // CXnKeyEventDispatcher::PointerEvent() |
283 // CXnKeyEventDispatcher::PointerEvent() |
232 // |
284 // |
233 // ----------------------------------------------------------------------------- |
285 // ----------------------------------------------------------------------------- |
234 // |
286 // |
235 const TPointerEvent& CXnKeyEventDispatcher::PointerEvent() const |
287 const TPointerEvent& CXnKeyEventDispatcher::PointerEvent() const |
236 { |
288 { |
237 return iPointerEvent; |
289 return iPointerEvent; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CXnKeyEventDispatcher::SetTextEditorActive() |
|
294 // |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void CXnKeyEventDispatcher::SetTextEditorActive( CXnNode* aNode, |
|
298 TBool aActivate ) |
|
299 { |
|
300 if ( iActiveTextEditor && iActiveTextEditor != aNode ) |
|
301 { |
|
302 CXnNode* activeTextEditor( iActiveTextEditor ); |
|
303 iActiveTextEditor = NULL; |
|
304 |
|
305 // Run lose focus to text editor node |
|
306 TRAP_IGNORE( SetNodeL( activeTextEditor, NULL, ETrue ) ); |
|
307 } |
|
308 |
|
309 if ( aActivate && aNode && aNode->Type()->Type() == KTextEditor ) |
|
310 { |
|
311 iActiveTextEditor = aNode; |
|
312 } |
|
313 else |
|
314 { |
|
315 iActiveTextEditor = NULL; |
|
316 } |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CXnKeyEventDispatcher::IsTextEditorActive |
|
321 // |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 TBool CXnKeyEventDispatcher::IsTextEditorActive() const |
|
325 { |
|
326 return iActiveTextEditor ? ETrue : EFalse; |
238 } |
327 } |
239 |
328 |
240 // ----------------------------------------------------------------------------- |
329 // ----------------------------------------------------------------------------- |
241 // CXnKeyEventDispatcher::OfferKeyEventL |
330 // CXnKeyEventDispatcher::OfferKeyEventL |
242 // Handles key events. |
331 // Handles key events. |
267 aKeyEvent.iScanCode == EStdKeyYes || |
356 aKeyEvent.iScanCode == EStdKeyYes || |
268 aKeyEvent.iScanCode == EStdKeyNo ) |
357 aKeyEvent.iScanCode == EStdKeyNo ) |
269 { |
358 { |
270 keyYesNoApps = ETrue; |
359 keyYesNoApps = ETrue; |
271 |
360 |
|
361 if ( aKeyEvent.iScanCode == EStdKeyNo && aType == EEventKey ) |
|
362 { |
|
363 iUiEngine.AppUiAdapter().ViewAdapter().CloseAllPopupsL(); |
|
364 } |
|
365 |
272 iFocusChanged = EFalse; |
366 iFocusChanged = EFalse; |
273 |
367 |
274 // AppsKey, YesKey, NoKey events must be always handled, and if we don't |
368 // AppsKey, YesKey, NoKey events must be always handled, and if we don't |
275 // have a focused node, then let the view handle the event |
369 // have a focused node, then let the view handle the event |
276 node = ( !iNode ) ? iUiEngine.ActiveView() : iNode; |
370 node = ( !iNode ) ? iUiEngine.ActiveView() : iNode; |
279 { |
373 { |
280 CXnAppUiAdapter& appui( iUiEngine.AppUiAdapter() ); |
374 CXnAppUiAdapter& appui( iUiEngine.AppUiAdapter() ); |
281 |
375 |
282 if ( IS_ARROW_KEY( aKeyEvent.iScanCode ) && aType == EEventKey ) |
376 if ( IS_ARROW_KEY( aKeyEvent.iScanCode ) && aType == EEventKey ) |
283 { |
377 { |
284 if ( !appui.FocusShown() ) |
378 if ( !appui.FocusShown() || !iNode ) |
285 { |
379 { |
286 appui.ShowFocus(); |
380 appui.ShowFocus(); |
287 |
381 |
288 if ( !iNode ) |
382 if ( !iNode ) |
289 { |
383 { |
290 // Find initial location for focus |
384 if ( iActiveTextEditor ) |
291 ResolveAndSetFocusL(); |
|
292 |
|
293 // If focus is still not set, we are in normal mode and the view is empty. |
|
294 // left and right arrows lead to next/previous view. When other arrows |
|
295 // are pressed, the focus is hidden. |
|
296 if( !iNode ) |
|
297 { |
385 { |
298 if( iUiEngine.ViewManager()->ViewAmount() != KOneView && |
386 iNode = iActiveTextEditor; |
299 aKeyEvent.iScanCode == EStdKeyRightArrow ) |
387 } |
|
388 else |
|
389 { |
|
390 // Find initial location for focus |
|
391 ResolveAndSetFocusL(); |
|
392 |
|
393 // If focus is still not set, we are in normal mode and the view is empty. |
|
394 // left and right arrows lead to next/previous view. When other arrows |
|
395 // are pressed, the focus is hidden. |
|
396 if( !iNode ) |
300 { |
397 { |
301 iUiEngine.ViewManager()->ActivateNextViewL(); |
398 if( iUiEngine.ViewManager()->ViewAmount() != KOneView && |
|
399 aKeyEvent.iScanCode == EStdKeyRightArrow ) |
|
400 { |
|
401 iUiEngine.ViewManager()->ActivateNextViewL(); |
|
402 } |
|
403 else if( iUiEngine.ViewManager()->ViewAmount() != KOneView && |
|
404 aKeyEvent.iScanCode == EStdKeyLeftArrow ) |
|
405 { |
|
406 iUiEngine.ViewManager()->ActivatePreviousViewL(); |
|
407 } |
|
408 else |
|
409 { |
|
410 // hide focus if view is not switched |
|
411 appui.HideFocus(); |
|
412 } |
302 } |
413 } |
303 else if( iUiEngine.ViewManager()->ViewAmount() != KOneView && |
414 |
304 aKeyEvent.iScanCode == EStdKeyLeftArrow ) |
415 return EKeyWasConsumed; |
305 { |
|
306 iUiEngine.ViewManager()->ActivatePreviousViewL(); |
|
307 } |
|
308 else |
|
309 { |
|
310 // hide focus if view is not switched |
|
311 appui.HideFocus(); |
|
312 } |
|
313 } |
416 } |
314 |
|
315 return EKeyWasConsumed; |
|
316 } |
417 } |
317 } |
418 } |
318 } |
419 } |
319 |
420 |
320 CCoeControl* editmode( iUiEngine.EditMode() ); |
421 CCoeControl* editmode( iUiEngine.EditMode() ); |
429 void CXnKeyEventDispatcher::SetNodeL( CXnNode* aToLose, CXnNode* aToGain, |
530 void CXnKeyEventDispatcher::SetNodeL( CXnNode* aToLose, CXnNode* aToGain, |
430 TBool aNotify, TInt aSource ) |
531 TBool aNotify, TInt aSource ) |
431 { |
532 { |
432 if ( aToLose ) |
533 if ( aToLose ) |
433 { |
534 { |
|
535 CXnControlAdapter* adapter( aToLose->Control() ); |
|
536 |
|
537 // Don't change control focus when <texteditor> element is focused |
|
538 if ( adapter && !iActiveTextEditor ) |
|
539 { |
|
540 adapter->SetFocus( EFalse ); |
|
541 } |
|
542 |
434 aToLose->SetDirtyL( XnDirtyLevel::ERender ); |
543 aToLose->SetDirtyL( XnDirtyLevel::ERender ); |
435 |
544 |
436 aToLose->UnsetStateL( XnPropertyNames::style::common::KFocus ); |
545 aToLose->UnsetStateL( XnPropertyNames::style::common::KFocus ); |
437 aToLose->UnsetStateL( XnPropertyNames::style::common::KHold ); |
546 aToLose->UnsetStateL( XnPropertyNames::style::common::KHold ); |
438 aToLose->UnsetStateL( XnPropertyNames::style::common::KActive ); |
547 aToLose->UnsetStateL( XnPropertyNames::style::common::KActive ); |
442 if ( !iLoseFocus ) |
551 if ( !iLoseFocus ) |
443 { |
552 { |
444 iLoseFocus = BuildTriggerNodeL( iUiEngine, |
553 iLoseFocus = BuildTriggerNodeL( iUiEngine, |
445 XnPropertyNames::action::trigger::name::KLoseFocus ); |
554 XnPropertyNames::action::trigger::name::KLoseFocus ); |
446 } |
555 } |
447 |
556 |
448 aToLose->ReportXuikonEventL( *iLoseFocus ); |
557 if ( iActiveTextEditor != aToLose ) |
449 } |
558 { |
450 |
559 aToLose->ReportXuikonEventL( *iLoseFocus ); |
451 CXnControlAdapter* adapter( aToLose->Control() ); |
560 } |
452 |
|
453 if ( adapter ) |
|
454 { |
|
455 adapter->SetFocus( EFalse ); |
|
456 } |
561 } |
457 } |
562 } |
458 |
563 |
459 if ( aToGain ) |
564 if ( aToGain ) |
460 { |
565 { |
|
566 TBool isTextEditor( aToGain->Type()->Type() == KTextEditor ); |
|
567 |
|
568 if ( iActiveTextEditor && ( ( aSource != XnEventSource::EStylus && !isTextEditor ) || |
|
569 ( iActiveTextEditor->Namespace() != aToGain->Namespace() ) || |
|
570 ( isTextEditor && iActiveTextEditor != aToGain ) ) ) |
|
571 { |
|
572 // Remove focus from active <texteditor> element |
|
573 SetTextEditorActive( NULL, EFalse ); |
|
574 } |
|
575 |
|
576 CXnControlAdapter* adapter( aToGain->Control() ); |
|
577 |
|
578 // Don't change control focus when <texteditor> element is focused |
|
579 if ( adapter && !iActiveTextEditor ) |
|
580 { |
|
581 adapter->SetFocus( ETrue ); |
|
582 } |
|
583 |
461 aToGain->SetDirtyL( XnDirtyLevel::ERender ); |
584 aToGain->SetDirtyL( XnDirtyLevel::ERender ); |
462 |
585 |
463 if ( aNotify ) |
586 if ( aNotify ) |
464 { |
587 { |
465 if ( !iGainFocus ) |
588 if ( !iGainFocus ) |
466 { |
589 { |
467 iGainFocus = BuildTriggerNodeL( iUiEngine, |
590 iGainFocus = BuildTriggerNodeL( iUiEngine, |
468 XnPropertyNames::action::trigger::name::KGainFocus ); |
591 XnPropertyNames::action::trigger::name::KGainFocus ); |
469 } |
592 } |
470 |
593 |
471 aToGain->ReportXuikonEventL( *iGainFocus, aSource ); |
594 if ( iActiveTextEditor != aToGain ) |
472 } |
595 { |
473 |
596 aToGain->ReportXuikonEventL( *iGainFocus, aSource ); |
474 CXnControlAdapter* adapter( aToGain->Control() ); |
597 } |
475 |
598 } |
476 if ( adapter ) |
599 |
477 { |
600 if ( isTextEditor ) |
478 adapter->SetFocus( ETrue ); |
601 { |
479 } |
602 // Set active <texteditor> element |
|
603 SetTextEditorActive( aToGain, ETrue ); |
|
604 } |
480 } |
605 } |
481 } |
606 } |
482 |
607 |
483 // ----------------------------------------------------------------------------- |
608 // ----------------------------------------------------------------------------- |
484 // CXnKeyEventDispatcher::FocusedNode |
609 // CXnKeyEventDispatcher::FocusedNode |
665 { |
793 { |
666 if ( aPluginData.Active() ) |
794 if ( aPluginData.Active() ) |
667 { |
795 { |
668 ClearPassiveFocusedNodesL(); |
796 ClearPassiveFocusedNodesL(); |
669 |
797 |
|
798 CXnViewData& activeViewData( |
|
799 iUiEngine.ViewManager()->ActiveViewData() ); |
|
800 |
670 if ( iNode ) |
801 if ( iNode ) |
671 { |
802 { |
672 CXnViewData& activeViewData( |
|
673 iUiEngine.ViewManager()->ActiveViewData() ); |
|
674 |
|
675 const CXnPluginData* pluginData( |
803 const CXnPluginData* pluginData( |
676 activeViewData.Plugin( iNode ) ); |
804 activeViewData.Plugin( iNode ) ); |
677 |
805 |
678 if ( pluginData == &aPluginData ) |
806 if ( pluginData == &aPluginData ) |
679 { |
807 { |
680 // The plugin is removed which was holding focus |
808 // The plugin is removed which was holding focus |
681 ClearStateL(); |
809 ClearStateL(); |
682 } |
810 } |
|
811 } |
|
812 |
|
813 if ( iActiveTextEditor ) |
|
814 { |
|
815 const CXnPluginData* pluginData( |
|
816 activeViewData.Plugin( iActiveTextEditor ) ); |
|
817 |
|
818 if ( pluginData == &aPluginData ) |
|
819 { |
|
820 SetTextEditorActive( NULL, EFalse ); |
|
821 } |
683 } |
822 } |
684 } |
823 } |
685 } |
824 } |
686 |
825 |
687 // ----------------------------------------------------------------------------- |
826 // ----------------------------------------------------------------------------- |