textinput/peninputhwrfscn/src/peninputfullscrlayoutbase.cpp
branchRCL_3
changeset 44 ecbabf52600f
parent 0 eb1f2e154e89
equal deleted inserted replaced
43:ebd48d2de13c 44:ecbabf52600f
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:  Implementation for layout base
       
    15 *
       
    16 */
       
    17 
       
    18 //SYSTEM INCLUDES
       
    19 #include <e32math.h>
       
    20 
       
    21 //FEP Includes
       
    22 #include <peninputcmd.h>
       
    23 
       
    24 //USER INCLUDES
       
    25 #include "peninputfullscrlayoutbase.h"
       
    26 
       
    27 // Test for Scroll bar laf read
       
    28 #include "peninputhwrfscnlafmanager.h"
       
    29 
       
    30 
       
    31 //CONST DEFINATION
       
    32 const TInt KMaxBufferEventNum = 30;
       
    33 const TInt KMinBufEventsCount = 2;
       
    34 
       
    35 const TInt KAngle90 = 90;
       
    36 const TInt KAngle180 = 180;
       
    37 const TInt KAngle270 = 270;
       
    38 const TInt KAngle360 = 360;
       
    39 const TInt KPendownHoldTime = 800 * 1000;
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CPenInputFullScreenLayoutBase::CPenInputFullScreenLayoutBase
       
    45 // Constructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CPenInputFullScreenLayoutBase::
       
    49     CPenInputFullScreenLayoutBase( MLayoutOwner* aLayoutOwner )
       
    50     :CFepUiLayout( aLayoutOwner )
       
    51     {
       
    52     iEnableStrokeFilter = ETrue;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CPenInputFullScreenLayoutBase::~CPenInputFullScreenLayoutBase
       
    57 // Destructor
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CPenInputFullScreenLayoutBase::~CPenInputFullScreenLayoutBase()
       
    61     {
       
    62     delete iLongTapPeriodic;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CPenInputFullScreenLayoutBase::BaseConstructL
       
    67 // Do basic contructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CPenInputFullScreenLayoutBase::BaseConstructL()
       
    71     {
       
    72     CFepUiLayout::BaseConstructL();
       
    73 
       
    74 	iLongTapPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CPenInputFullScreenLayoutBase::PeriodicCallBack
       
    79 // .
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 TInt CPenInputFullScreenLayoutBase::PeriodicCallBack( TAny *aAnyPtr )
       
    83 	{
       
    84 	CPenInputFullScreenLayoutBase *pThis = 
       
    85 	    static_cast<CPenInputFullScreenLayoutBase*>( aAnyPtr );
       
    86 	return pThis->OnLongTapTimeOut();
       
    87 	}
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CPenInputFullScreenLayoutBase::StartLongTapTimer
       
    91 // .
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CPenInputFullScreenLayoutBase::StartLongTapTimer()
       
    95 	{
       
    96 	if ( !iLongTapPeriodic->IsActive() )
       
    97 	    {
       
    98         iLongTapPeriodic->Start( KPendownHoldTime/*0.8s*/, 0, 
       
    99             TCallBack( PeriodicCallBack, this ) );	    
       
   100 	    }
       
   101 	}
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CPenInputFullScreenLayoutBase::StopLongTapTimer
       
   105 // .
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CPenInputFullScreenLayoutBase::StopLongTapTimer()
       
   109 	{
       
   110 	iLongTapPeriodic->Cancel();
       
   111 	}
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CPenInputFullScreenLayoutBase::RecordPointerEvent
       
   115 // .
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CPenInputFullScreenLayoutBase::
       
   119     RecordPointerEvent( const TRawEvent &aEvent )
       
   120 	{
       
   121 	if( iEventBuf.Count() == KMaxBufferEventNum )
       
   122 		{
       
   123 		//replace the last pointer move event with new one;
       
   124 		if( iEventBuf[KMaxBufferEventNum - 1].Type() == 
       
   125 		    TRawEvent::EPointerMove )
       
   126 			{
       
   127 			iEventBuf[KMaxBufferEventNum - 1] = aEvent;
       
   128 			}
       
   129 		}
       
   130 	else
       
   131 		{
       
   132 		iEventBuf.Append( aEvent );
       
   133 		}
       
   134 	}
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CPenInputFullScreenLayoutBase::SendBufferEventToLayoutL
       
   138 // .
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CPenInputFullScreenLayoutBase::SendBufferEventToLayoutL()
       
   142 	{
       
   143 	TInt count = iEventBuf.Count();
       
   144     for( TInt i = 0; i < count; i++ )
       
   145 	    {
       
   146 	    CFepUiLayout::HandleEventL( ERawEvent, &iEventBuf[i] );
       
   147 	    }
       
   148 
       
   149 	iEventBuf.Reset();
       
   150 	}
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CPenInputFullScreenLayoutBase::SendBufferEventToBackground
       
   154 // .
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CPenInputFullScreenLayoutBase::SendBufferEventToBackground()
       
   158 	{
       
   159 	BeforeSendingEventsToBackground();
       
   160 	TInt count = iEventBuf.Count();
       
   161     for( TInt i = 0; i < count; i++ )
       
   162         {
       
   163     	TPtrC data;
       
   164     	data.Set( reinterpret_cast<TUint16*>( &iEventBuf[i] ), 
       
   165     	sizeof( TRawEvent ) / sizeof( TUint16 ) );
       
   166 
       
   167         SignalOwner( ESignalSimulateEvent, data );
       
   168         }
       
   169 
       
   170     iEventBuf.Reset();
       
   171 	}
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CPenInputFullScreenLayoutBase::CalcDiagonalDistance
       
   175 // .
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 TReal CPenInputFullScreenLayoutBase::CalcDiagonalDistance()
       
   179 	{
       
   180 	//init left top right bottom
       
   181 	TPoint leftTop = iEventBuf[0].Pos();
       
   182 	TPoint rightBottom = iEventBuf[iEventBuf.Count() - 1].Pos();
       
   183 
       
   184 	//find min left top and max right bottom
       
   185 	TInt count = iEventBuf.Count();
       
   186 	for( TInt i = 1; i < count - 1; ++i )
       
   187 		{
       
   188 		TPoint pt = iEventBuf[i].Pos();
       
   189 		leftTop.iX = Min( leftTop.iX, pt.iX );
       
   190 		leftTop.iY = Min( leftTop.iY, pt.iY );
       
   191 		rightBottom.iX = Max( rightBottom.iX, pt.iX );
       
   192 		rightBottom.iY = Max( rightBottom.iY, pt.iY );
       
   193 		}
       
   194 
       
   195 	//calculate width and height
       
   196 	TInt nWidth = rightBottom.iX - leftTop.iX;
       
   197 	TInt nHeight = rightBottom.iY - leftTop.iY;
       
   198 
       
   199 	//calculate diagonaDistance accroding "Pythagorean proposition"
       
   200 	TReal diagonaDistanceSquare = nWidth * nWidth + nHeight * nHeight;
       
   201 	TReal diagonaDistance = 0;
       
   202 	Math::Sqrt( diagonaDistance, diagonaDistanceSquare );
       
   203 
       
   204 	return diagonaDistance;
       
   205 	}
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CPenInputFullScreenLayoutBase::CalcAngle
       
   209 // .
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 TInt CPenInputFullScreenLayoutBase::CalcAngle()
       
   213 	{
       
   214 	TPoint startPos = iEventBuf[0].Pos();
       
   215 	TPoint endPos = iEventBuf[iEventBuf.Count() - 1].Pos();
       
   216 
       
   217     TReal x = endPos.iX - startPos.iX;
       
   218     TReal y = startPos.iY - endPos.iY;
       
   219 
       
   220     if ( ( endPos.iX - startPos.iX ) == 0 )
       
   221         {
       
   222         if ( y > 0 )
       
   223             {
       
   224             return KAngle90;
       
   225             }
       
   226         else
       
   227             {
       
   228             return KAngle270;
       
   229             }
       
   230         }
       
   231 
       
   232     TReal radians = 0;
       
   233     Math::ATan( radians, y, x );
       
   234     TReal angle = radians * KAngle180 / KPi;
       
   235 
       
   236     if ( x < 0 )
       
   237         {
       
   238         angle += KAngle180;
       
   239         }
       
   240     else if ( x > 0 )
       
   241         {
       
   242         angle += KAngle360;
       
   243         }
       
   244 
       
   245     if ( angle >= KAngle360 )
       
   246         {
       
   247         angle -= KAngle360;
       
   248         }
       
   249 
       
   250     return angle;
       
   251 	}
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CPenInputFullScreenLayoutBase::IsStroke
       
   255 // .
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 TBool CPenInputFullScreenLayoutBase::IsStroke()
       
   259 	{
       
   260 	if( iEventBuf.Count() < KMinBufEventsCount )
       
   261 		{
       
   262 		return EFalse;
       
   263 		}
       
   264 
       
   265 	//diagonal distance in pixel
       
   266 	TReal n = CalcDiagonalDistance();
       
   267 
       
   268 	//anti-clockwise angle of the two lines from origin to point.
       
   269 	TInt m = CalcAngle();
       
   270 
       
   271 	if( iEventBuf[iEventBuf.Count() - 1].Type() == TRawEvent::EButton1Up )
       
   272 		{
       
   273 		//if end with button up event then it's a quickly tap
       
   274 		if( n > 14 )
       
   275 			{
       
   276 			return ETrue;
       
   277 			}
       
   278 		else if( n > 7.02 )
       
   279 			{
       
   280 			if( m < 80 || m > 260 )
       
   281 				{
       
   282 				return ETrue;
       
   283 				}
       
   284 			}
       
   285 		}
       
   286 	else
       
   287 		{
       
   288 		//else pen is moving
       
   289 		if( n > 14 )
       
   290 			{
       
   291 			return ETrue;
       
   292 			}
       
   293 		}
       
   294 
       
   295 	return EFalse;
       
   296 	}
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // CPenInputFullScreenLayoutBase::OnRawEvent_Button1Down
       
   300 // .
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 TBool CPenInputFullScreenLayoutBase::
       
   304     OnRawEvent_Button1Down( const TRawEvent &aEvent )
       
   305 	{
       
   306 	//tap start from non-hwrbox
       
   307 	if( RootControl()->NonHwrStartingPtRegion().Contains( aEvent.Pos() ) )
       
   308 		{
       
   309 		iPenState = EPenStateStroke;
       
   310 		return EFalse;
       
   311 		}
       
   312 		
       
   313     // Just test scroll bar rect problem
       
   314 	TRect scrollBarRect = PeninputHwrfscnLAFManager::ScrollBarRect();
       
   315 	if ( scrollBarRect.Contains( aEvent.Pos() ) )
       
   316 	    {
       
   317 	    RecordPointerEvent( aEvent );
       
   318 		iPenState = EPenStateLongTap;
       
   319 		SendBufferEventToBackground();
       
   320 		return ETrue;
       
   321 	    }
       
   322 
       
   323 	StartLongTapTimer();
       
   324 
       
   325 	RecordPointerEvent( aEvent );
       
   326 
       
   327 	iPenState = EPenStateUnknown;
       
   328 
       
   329 	return ETrue;
       
   330 	}
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // CPenInputFullScreenLayoutBase::OnLongTapTimeOut
       
   334 // .
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 TInt CPenInputFullScreenLayoutBase::OnLongTapTimeOut()
       
   338 	{
       
   339 	StopLongTapTimer();
       
   340 
       
   341 	if( IsStroke() )
       
   342 		{
       
   343 		iPenState = EPenStateStroke;
       
   344 		TRAP_IGNORE( SendBufferEventToLayoutL() );
       
   345 		}
       
   346 	else
       
   347 		{
       
   348 		iPenState = EPenStateLongTap;
       
   349 		SendBufferEventToBackground();
       
   350 		}
       
   351 
       
   352 	return KErrNone;
       
   353 	}
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // CPenInputFullScreenLayoutBase::OnRawEvent_PointerMove
       
   357 // .
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 TBool CPenInputFullScreenLayoutBase::
       
   361     OnRawEvent_PointerMove( const TRawEvent &aEvent )
       
   362 	{
       
   363 	if( iPenState == EPenStateStroke )
       
   364 		{
       
   365 		return EFalse;
       
   366 		}
       
   367 
       
   368 	RecordPointerEvent( aEvent );
       
   369 
       
   370 	if( iPenState == EPenStateUnknown )
       
   371 		{
       
   372 		if( IsStroke() )
       
   373 			{
       
   374 			iPenState = EPenStateStroke;
       
   375 
       
   376 	    	StopLongTapTimer();
       
   377 
       
   378 			TRAP_IGNORE( SendBufferEventToLayoutL() );
       
   379 			}
       
   380 		}
       
   381 	else if( iPenState == EPenStateLongTap )
       
   382 		{
       
   383 		SendBufferEventToBackground();
       
   384 		}
       
   385 
       
   386 	return ETrue;
       
   387 	}
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CPenInputFullScreenLayoutBase::OnRawEvent_Button1Up
       
   391 // .
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 TBool CPenInputFullScreenLayoutBase::
       
   395     OnRawEvent_Button1Up( const TRawEvent &aEvent )
       
   396 	{
       
   397 	StopLongTapTimer();
       
   398 
       
   399 	if( iPenState == EPenStateStroke )
       
   400 		{
       
   401 		return EFalse;
       
   402 		}
       
   403 
       
   404 	RecordPointerEvent( aEvent );
       
   405 
       
   406 	if( iPenState == EPenStateUnknown )
       
   407 		{
       
   408 		if( IsStroke() )
       
   409 			{
       
   410 			//send event to layout
       
   411 			TRAP_IGNORE( SendBufferEventToLayoutL() );
       
   412 			}
       
   413 		else
       
   414 			{
       
   415 			//send event to background app
       
   416 			SendBufferEventToBackground();
       
   417 			}
       
   418 		}
       
   419 	else if( iPenState == EPenStateLongTap )
       
   420 		{
       
   421 		////send event to background app
       
   422 		SendBufferEventToBackground();
       
   423 		}
       
   424 
       
   425 	return ETrue;
       
   426 	}
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // CPenInputFullScreenLayoutBase::HandleEventL
       
   430 // .
       
   431 // ---------------------------------------------------------------------------
       
   432 //
       
   433 TBool CPenInputFullScreenLayoutBase::
       
   434     HandleEventL( TEventType aType, const TAny* aData )
       
   435     {
       
   436     const TRawEvent &event = *( ( TRawEvent* ) aData );
       
   437     
       
   438     PreHandleEvent( aType, event );
       
   439 
       
   440 	TBool handled = EFalse;
       
   441 
       
   442     //if pointer is captured, don't buffer the event.
       
   443     if( RootControl()->CtrlCapPointer() )
       
   444     	{
       
   445     	return CFepUiLayout::HandleEventL( aType, aData );
       
   446     	}
       
   447 
       
   448 	if( iEnableStrokeFilter && aType == ERawEvent )
       
   449 		{
       
   450 		switch( event.Type() )
       
   451 			{
       
   452 			case TRawEvent::EButton1Down:
       
   453 				{
       
   454 				handled = OnRawEvent_Button1Down( event );
       
   455 				break;
       
   456 				}
       
   457 
       
   458 			case TRawEvent::EButton1Up:
       
   459 				{
       
   460 				handled = OnRawEvent_Button1Up( event );
       
   461 				break;
       
   462 				}
       
   463 
       
   464 			case TRawEvent::EPointerMove:
       
   465 				{
       
   466 				handled = OnRawEvent_PointerMove( event );
       
   467 				break;
       
   468 				}
       
   469 
       
   470 			default:
       
   471 				break;
       
   472 			}
       
   473 		}
       
   474 
       
   475     if( handled )
       
   476     	{
       
   477     	return ETrue;
       
   478     	}
       
   479 
       
   480 
       
   481 	if( !iEnableStrokeFilter && aType == ERawEvent )
       
   482 		{
       
   483 		switch( event.Type() )
       
   484 			{
       
   485 			case TRawEvent::EButton1Down:
       
   486 				{
       
   487 				RecordPointerEvent( event );
       
   488 				return EFalse;
       
   489 				}
       
   490 			case TRawEvent::EButton1Up:
       
   491 				{
       
   492 				RecordPointerEvent( event );
       
   493 			    SendBufferEventToLayoutL();
       
   494 			    return ETrue;
       
   495 				}
       
   496 			case TRawEvent::EPointerMove:
       
   497 				{
       
   498 				RecordPointerEvent( event );
       
   499 				CFepUiBaseCtrl* hwrWnd = RootControl()->ControlByType(ECtrlTransparentHwrWnd);
       
   500 				if(IsStroke() && hwrWnd)
       
   501             	    {
       
   502         	        hwrWnd->CapturePointer();
       
   503         	        SendBufferEventToLayoutL();
       
   504             	    }
       
   505 				return ETrue;
       
   506 				}
       
   507 			default:
       
   508 				break;
       
   509 			}
       
   510 		}
       
   511     iEventBuf.Reset();
       
   512    	return CFepUiLayout::HandleEventL( aType, aData );
       
   513     }
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // CPenInputFullScreenLayoutBase::SemiTransparencyRequired
       
   517 // .
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 TBool CPenInputFullScreenLayoutBase::SemiTransparencyRequired()
       
   521     {
       
   522     return EFalse;
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // CPenInputFullScreenLayoutBase::EnableStrokeFilter
       
   527 // .
       
   528 // ---------------------------------------------------------------------------
       
   529 //
       
   530 void CPenInputFullScreenLayoutBase::EnableStrokeFilter( TBool aEnable )
       
   531     {
       
   532     iEnableStrokeFilter = aEnable;
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------------------------
       
   536 // CPenInputFullScreenLayoutBase::StrokeFilter
       
   537 // .
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 TBool CPenInputFullScreenLayoutBase::StrokeFilter() const
       
   541     {
       
   542     return iEnableStrokeFilter;
       
   543     }
       
   544 // ---------------------------------------------------------------------------
       
   545 // CPenInputFullScreenLayoutBase::PreHandleEvent
       
   546 // .
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 void CPenInputFullScreenLayoutBase::
       
   550     PreHandleEvent( TEventType /*aType*/, const TRawEvent &/*aEvent*/ )
       
   551 	{
       
   552 	//do nothing
       
   553 	}
       
   554 
       
   555 // ---------------------------------------------------------------------------
       
   556 // CPenInputFullScreenLayoutBase::BeforeSendingEventsToBackground
       
   557 // .
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 void CPenInputFullScreenLayoutBase::BeforeSendingEventsToBackground()
       
   561     {
       
   562     //do noting
       
   563     }
       
   564 //End of file