voicerecorder/RecViewSrc/CVRButtonPanel.cpp
branchRCL_3
changeset 20 072a5fa0c63b
parent 19 2f5c9ee7098c
child 21 c6bafb5162d8
equal deleted inserted replaced
19:2f5c9ee7098c 20:072a5fa0c63b
     1 /*
       
     2 * Copyright (c) 2002 - 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: 
       
    15 *     A compound control class. It is responsible for drawing and updating
       
    16 *     a set of buttons. Button selections are also handled and forwarded
       
    17 *     as commands to the AppUi.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include <avkon.hrh>
       
    25 #include <eikenv.h> 
       
    26 #include <AknsUtils.h> 
       
    27 #include <voicerecorder.rsg> 
       
    28 #include <aknbutton.h> 					
       
    29 #include <e32base.h> 					
       
    30 #include <barsread.h> 					// TResourceReader
       
    31 #include <w32std.h>
       
    32 #include <aknlayoutscalable_apps.cdl.h> // New button highlight
       
    33 #include <e32std.h> 					// Timer
       
    34 #include <AknsDrawUtils.h>
       
    35 #include <applayout.cdl.h>
       
    36 #include <AknsConstants.h> 
       
    37 #include <AknIconUtils.h>
       
    38 #include <data_caging_path_literals.hrh>
       
    39 #include <eikappui.h> 
       
    40 #include <aknViewAppUi.h>
       
    41 #include <aknview.h>
       
    42 
       
    43 #include <voicerecorder.mbg>
       
    44 #include "CVRButtonPanel.h"
       
    45 #include "MVRButtonPanelModel.h"
       
    46 #include "voicerecorder.hrh"
       
    47 #include "VRConsts.h"
       
    48 
       
    49 // CONSTANTS
       
    50 
       
    51 // Timer delays
       
    52 const TInt KVRFastForwStartDelay( 500000 );
       
    53 const TInt KVRFastForwUpdateDelay( 170000 );
       
    54 
       
    55 const TInt KVRButtonCount( 5 );			   // Total number of buttons
       
    56 const TInt KVRAmountOfFocusShrink( 5 );
       
    57 
       
    58 
       
    59 // ================= MEMBER FUNCTIONS ========================================
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CVRButtonPanel::CVRButtonPanel
       
    63 // 
       
    64 // ---------------------------------------------------------------------------
       
    65 //	
       
    66 CVRButtonPanel::CVRButtonPanel( MVRButtonPanelModel* aModel )
       
    67     : iModel( aModel ),
       
    68     iVRButtons( KVRButtonCount )
       
    69 	{
       
    70 	__ASSERT_DEBUG( iModel, User::Panic( KVRPanic, KErrNotFound ) );
       
    71 	iModel->SetButtonPanelObserver( this );
       
    72 	}
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CVRButtonPanel::CVRButtonPanel
       
    77 // 
       
    78 // ---------------------------------------------------------------------------
       
    79 //	
       
    80 CVRButtonPanel::CVRButtonPanel( MVRButtonPanelModel* aModel,
       
    81                                TUid aParentViewUid )
       
    82     : iModel( aModel ),  
       
    83     iParentViewUid( aParentViewUid ),
       
    84     iVRButtons( KVRButtonCount )
       
    85 	{
       
    86 	__ASSERT_DEBUG( iModel, User::Panic( KVRPanic, KErrNotFound ) );
       
    87 	iModel->SetButtonPanelObserver( this );
       
    88 	}
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CVRButtonPanel::~CVRButtonPanel
       
    93 // Destructor
       
    94 // ---------------------------------------------------------------------------
       
    95 //	
       
    96 CVRButtonPanel::~CVRButtonPanel()
       
    97 	{
       
    98 	if ( iModel )
       
    99 		{
       
   100 		iModel->SetButtonPanelObserver( NULL );
       
   101 		}
       
   102 
       
   103 	iVRButtons.ResetAndDestroy();
       
   104 	delete iTimer;
       
   105 	iModel = NULL;
       
   106 	iSkin = NULL;
       
   107 	}
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CVRButtonPanel::ConstructL
       
   112 // 
       
   113 // ---------------------------------------------------------------------------
       
   114 //	
       
   115 void CVRButtonPanel::ConstructL()
       
   116 	{
       
   117 	iSkin = AknsUtils::SkinInstance();
       
   118 	
       
   119 	// Create buttons from resources
       
   120    	CreateButtonsFromResourcesL( R_VR_BUTTON_PANEL_BUTTONS );
       
   121    	UpdateButtons();
       
   122    	
       
   123    	// Has to be done to get the buttons' background shown correctly
       
   124    	for ( TInt i = 0; i < iVRButtons.Count(); i++ )
       
   125     	{
       
   126     	iVRButtons.At( i )->SetBackground( this );
       
   127     	}
       
   128 	}
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CVRButtonPanel::CreateButtonsFromResourcesL
       
   133 // Creates buttons from resources
       
   134 // ---------------------------------------------------------------------------
       
   135 //    
       
   136 void CVRButtonPanel::CreateButtonsFromResourcesL( TInt aButtonsResourceId )
       
   137 	{	
       
   138 	TResourceReader reader;
       
   139 	iEikonEnv->CreateResourceReaderLC( reader, aButtonsResourceId );
       
   140 	
       
   141 	TInt numButtons( reader.ReadInt16() );
       
   142 
       
   143 	// Create buttons
       
   144 	for (TInt i = 0; i < numButtons; i++ )
       
   145 		{
       
   146 		CAknButton* aknButton = CAknButton::NewL();
       
   147 		CleanupStack::PushL( aknButton );
       
   148 		
       
   149 		aknButton->SetContainerWindowL( *this );
       
   150 		aknButton->SetMopParent( this ); 
       
   151 	    aknButton->ConstructFromResourceL( reader );
       
   152 		aknButton->SetObserver( this );
       
   153 	    
       
   154 	    // Set ready to be drawn and add it to array
       
   155 	    aknButton->ActivateL();
       
   156 	   	iVRButtons.AppendL( aknButton );
       
   157 	   	
       
   158 	   	CleanupStack::Pop( aknButton ); // aknButton
       
   159 		}
       
   160 		
       
   161 	CleanupStack::PopAndDestroy(); // reader;
       
   162 	}
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CVRButtonPanel::Update
       
   167 // This method can be called via MVRObserver class when Button Panel needs 
       
   168 // to be updated. 
       
   169 // ---------------------------------------------------------------------------
       
   170 //	
       
   171 void CVRButtonPanel::Update( TVRUpdateCommand aCommand )
       
   172 	{
       
   173 	
       
   174 	TBool drawNow( ETrue );
       
   175 	
       
   176 	// Recorder calls this after each tick, we have to check if button reset
       
   177 	// is needed. Redraw is needed also after 1 secs playback to enable
       
   178 	// rewind button.
       
   179     switch( aCommand )
       
   180         {
       
   181         case EVRUpdate1Second:
       
   182 	case EVRUpdate:
       
   183         case EVRUpdateStateChange:
       
   184             {
       
   185             // Redraw
       
   186            	drawNow = ETrue;
       
   187             break;
       
   188             }
       
   189         case EVRUpdatePositionChange:
       
   190         	{
       
   191 			// Skip redraw
       
   192 			drawNow = EFalse;
       
   193             break;
       
   194             }    
       
   195         default:
       
   196             {
       
   197             // Skip redraw
       
   198             drawNow = EFalse;
       
   199             return;
       
   200             }
       
   201         }
       
   202 
       
   203 	if ( iModel->ResetNeeded() )
       
   204 		{
       
   205 		iFocusedButton = iModel->InitialFocusButtonId();
       
   206 		}
       
   207 		
       
   208 	UpdateButtons();
       
   209 	
       
   210 	// Change focus if focused button is dimmed
       
   211 	TuneButtonFocus();
       
   212 	
       
   213 	if ( drawNow )	
       
   214 		{
       
   215 	    DrawNow();				
       
   216 		}
       
   217 	}
       
   218 
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CVRButtonPanel::SizeChanged
       
   222 // Called when Button Panel layout needs to be updated 
       
   223 // ---------------------------------------------------------------------------
       
   224 //	
       
   225 void CVRButtonPanel::SizeChanged()
       
   226 	{
       
   227     TInt count( iModel->ButtonCount() );
       
   228 
       
   229     TSize size; // Size of the bitmap
       
   230 
       
   231     for ( TInt i( 0 ); i < count; i++ )
       
   232 		{
       
   233 		// Layout button.
       
   234         TAknWindowLineLayout cell = AppLayout::cell_vorec_pane( i );
       
   235         
       
   236     	TAknLayoutRect buttonLayout;
       
   237 		buttonLayout.LayoutRect( Rect(), cell );
       
   238 		TRect buttonRect = buttonLayout.Rect();
       
   239 		TInt newSize = (TInt)(buttonRect.Width() * 0.1); // used to reduce the size of button
       
   240 		buttonRect.Shrink( TSize(newSize,newSize) );
       
   241     	iVRButtons.At( i )->SetRect( buttonRect );
       
   242    		} 
       
   243 	}
       
   244 	
       
   245 	
       
   246 // ---------------------------------------------------------------------------
       
   247 // CVRButtonPanel::OfferKeyEventL
       
   248 // Key event handling
       
   249 // ---------------------------------------------------------------------------
       
   250 //	
       
   251 TKeyResponse CVRButtonPanel::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   252 											 TEventCode aType )
       
   253 	{
       
   254 	if ( aType != EEventKey )
       
   255 		{
       
   256 		if( aType == EEventKeyDown )
       
   257 			{
       
   258 			// Rocker key pressed
       
   259 			if ( aKeyEvent.iScanCode == EStdKeyDevice3 )
       
   260 				{
       
   261 				// Start timer to get continuous timercallbacks for 
       
   262 				// FastForwarding and FastRewinding
       
   263 				StartTimerL();
       
   264 				}
       
   265 			}	
       
   266 		else if( aType == EEventKeyUp )
       
   267 			{
       
   268 			// Rocker key pressed
       
   269 			if ( aKeyEvent.iScanCode == EStdKeyDevice3 )
       
   270 				{
       
   271 				StopTimer();
       
   272 				}
       
   273 			}			
       
   274 		return EKeyWasNotConsumed;
       
   275 		}
       
   276 	// EEventKey
       
   277 	switch ( aKeyEvent.iCode )
       
   278 		{
       
   279 		case EKeyDownArrow:
       
   280 			{
       
   281 			MoveFocus( EFocusDown, ETrue );
       
   282 			break;
       
   283 			}
       
   284 		case EKeyUpArrow:
       
   285 			{
       
   286 			MoveFocus( EFocusUp, ETrue );
       
   287 			break;
       
   288 			}
       
   289 		case EKeyEnter:	
       
   290 		case EKeyOK:
       
   291 			{	
       
   292 			// This is in use as long as there are only 2 CBA buttons. When MSK
       
   293 			// enabled, execution goes straight to CVRRecView::HandleCommandL
       
   294 			FetchAndSendCommandL();
       
   295 			break;
       
   296 			}
       
   297 		default:
       
   298 			{
       
   299 			return EKeyWasNotConsumed;
       
   300 			}
       
   301 		}
       
   302 
       
   303 	return EKeyWasConsumed;
       
   304 	}
       
   305 
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CVRButtonPanel::Draw
       
   309 // Needed to get correct focus drawing with AknButtons
       
   310 // ---------------------------------------------------------------------------
       
   311 //		
       
   312 void CVRButtonPanel::Draw( CWindowGc& /*aGc*/, const CCoeControl& /*aControl*/, 
       
   313 		const TRect& /*aRect*/ ) const
       
   314 	{
       
   315 	}
       
   316 
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CVRButtonPanel::Draw
       
   320 // 
       
   321 // ---------------------------------------------------------------------------
       
   322 //		
       
   323 void CVRButtonPanel::Draw( const TRect& /*aRect*/ ) const
       
   324 	{
       
   325 	CWindowGc& gc = SystemGc();
       
   326 	// Acquire the control context through the MOP-chain
       
   327 	MAknsControlContext* context = AknsDrawUtils::ControlContext( this );
       
   328 
       
   329 	// Draw the background using the control context
       
   330 	// Note: if there is no skin, the background is just cleared
       
   331 	// (which is OK for us)
       
   332 	AknsDrawUtils::Background( iSkin, context, this, gc, Rect() );
       
   333 
       
   334 	// Draw button highlight
       
   335 	DrawFocus( gc );
       
   336 	}
       
   337 
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // CVRButtonPanel::CountComponentControls
       
   341 // 
       
   342 // ---------------------------------------------------------------------------
       
   343 //	
       
   344 TInt CVRButtonPanel::CountComponentControls() const
       
   345 	{
       
   346 	return iVRButtons.Count();
       
   347 	}
       
   348 
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CVRButtonPanel::ComponentControl
       
   352 // 
       
   353 // ---------------------------------------------------------------------------
       
   354 //	
       
   355 CCoeControl* CVRButtonPanel::ComponentControl( TInt aIndex ) const
       
   356 	{
       
   357 	return iVRButtons.At( aIndex );
       
   358 	}
       
   359 
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CVRButtonPanel::MoveFocus
       
   363 // Moves the focus to next button up or down. aDirection tells the which.
       
   364 // ---------------------------------------------------------------------------
       
   365 //	
       
   366 void CVRButtonPanel::MoveFocus( const TFocusChange aDirection, TBool aDrawNow )
       
   367 	{
       
   368 	TInt buttonCount( iModel->ButtonCount() );
       
   369 	TInt newButton( iFocusedButton );
       
   370 
       
   371 	for ( TInt i( 0 ); i < buttonCount; i++ )
       
   372 		{
       
   373 		// calculate new button id. the modulo operator (%) handles looping
       
   374 		newButton = ( newButton + aDirection + buttonCount ) % buttonCount;
       
   375 		// dimmed buttons are skipped
       
   376 		if ( iModel->ButtonState( newButton ) != EDimmed )
       
   377 			{
       
   378 			iFocusedButton = newButton;
       
   379 			
       
   380 			// Timer is used for FastForward/-Rewind. Stop that when focus is 
       
   381 			// changed.
       
   382 			StopTimer();
       
   383 			break;
       
   384 			}
       
   385 		}
       
   386 	
       
   387 	if ( aDrawNow )
       
   388 		{
       
   389 		DrawNow();	
       
   390 		}
       
   391 	}
       
   392 
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CVRButtonPanel::UpdateLayoutL
       
   396 // 
       
   397 // ---------------------------------------------------------------------------
       
   398 //	
       
   399 void CVRButtonPanel::UpdateLayoutL( )
       
   400 	{
       
   401 	SizeChanged();
       
   402 	}
       
   403 
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CVRButtonPanel::HandleResourceChangeL
       
   407 // 
       
   408 // ---------------------------------------------------------------------------
       
   409 //	
       
   410 void CVRButtonPanel::HandleResourceChangeL( TInt aType )
       
   411 	{
       
   412 	CCoeControl::HandleResourceChange( aType );
       
   413 	
       
   414 	if ( aType == KEikDynamicLayoutVariantSwitch )
       
   415 		{
       
   416 		UpdateLayoutL();
       
   417 		}
       
   418 	else if ( aType == KAknsMessageSkinChange )
       
   419 		{
       
   420 		// New skin instance is loaded
       
   421 		iSkin = AknsUtils::SkinInstance();
       
   422 		}
       
   423 	
       
   424 	// Inform Avkon Buttons		
       
   425 	for( TInt buttonIndex = 0; buttonIndex < iVRButtons.Count() ; 
       
   426 			buttonIndex++ )
       
   427 		{
       
   428 		iVRButtons.At( buttonIndex )->HandleResourceChange( aType );
       
   429 		}
       
   430 	}
       
   431 
       
   432 	
       
   433 // ---------------------------------------------------------------------------
       
   434 // CVRButtonPanel::UpdateButtons
       
   435 // Updates all Button Panel buttons to correct visual state. Also few  
       
   436 // exceptional cases are handled here (1. clip position is at the beginning 
       
   437 // 2. clip position is at the end)
       
   438 // ---------------------------------------------------------------------------
       
   439 //		
       
   440 void CVRButtonPanel::UpdateButtons()
       
   441 	{
       
   442 	TUint stateId;
       
   443 	// Update all the buttons	
       
   444 	for( TInt buttonIndex = 0; buttonIndex < iVRButtons.Count() ; 
       
   445 			buttonIndex++ )
       
   446 		{
       
   447 		stateId = iModel->VisualStateId();
       
   448 		
       
   449 		// dim rewind button if there is nothing to rewind
       
   450 		if ( buttonIndex == EButtonRewind && 
       
   451 				iModel->ButtonState( buttonIndex ) == EDimmed )
       
   452 			{
       
   453 			iVRButtons.At( buttonIndex )->SetDimmed(ETrue);			
       
   454 			stateId = EStateDisableButtons;
       
   455 			}
       
   456 		if ( buttonIndex == EButtonRewind && 
       
   457 				iModel->ButtonState( buttonIndex ) != EDimmed )
       
   458 			{
       
   459 			iVRButtons.At( buttonIndex )->SetDimmed(EFalse);			
       
   460 			}
       
   461 		// dim forward button if there is nothing to forward
       
   462 		if( buttonIndex == EButtonForward && 
       
   463 				iModel->ButtonState( buttonIndex ) == EDimmed )
       
   464 			{
       
   465 			iVRButtons.At( buttonIndex )->SetDimmed(ETrue);		
       
   466 			stateId = EStateDisableButtons;	
       
   467 			}
       
   468 		if( buttonIndex == EButtonForward && 
       
   469 				iModel->ButtonState( buttonIndex ) != EDimmed )
       
   470 			{
       
   471 			iVRButtons.At( buttonIndex )->SetDimmed(EFalse);		
       
   472 			}
       
   473 		
       
   474 		// ************ADDED CODE STARTS****************************
       
   475 		if( buttonIndex == EButtonRecord && 
       
   476 				iModel->ButtonState( buttonIndex ) == EDimmed )
       
   477 			{								
       
   478 			stateId = EStateDisableButtons;	
       
   479 			}
       
   480 		// ************ADDED CODE ENDS******************************
       
   481 
       
   482 		if( iModel->ButtonState( buttonIndex ) == EDimmed )
       
   483 			{
       
   484 			iVRButtons.At( buttonIndex )->SetDimmed(ETrue);		
       
   485 			}
       
   486 		else
       
   487 			{
       
   488 			iVRButtons.At( buttonIndex )->SetDimmed(EFalse);	
       
   489 			}	
       
   490 		
       
   491 		// Change the button state, don't redraw
       
   492 		iVRButtons.At( buttonIndex )->SetCurrentState( stateId , EFalse );
       
   493 		}
       
   494 	}	
       
   495 	
       
   496 
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // CVRButtonPanel::DrawFocus() 
       
   500 // Draws the focus rectangle around the currently focused button
       
   501 // ---------------------------------------------------------------------------
       
   502 //    
       
   503 void CVRButtonPanel::DrawFocus( CWindowGc& aGc ) const
       
   504 	{
       
   505 	
       
   506 	aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   507 
       
   508 	if ( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   509 		{
       
   510 		// From LAF-table
       
   511 //		TAknWindowLineLayout area = 
       
   512 //			AknLayoutScalable_Apps::grid_highlight_pane_cp05().LayoutLine();
       
   513 		
       
   514 //		TRect buttonRect = iVRButtons.At( iFocusedButton )->Rect();
       
   515 		TAknWindowLineLayout area = AppLayout::cell_vorec_pane( iFocusedButton );
       
   516 
       
   517 		TAknLayoutRect layoutRect;
       
   518 		layoutRect.LayoutRect( Rect(), area );
       
   519 //		layoutRect.LayoutRect( buttonRect, area );
       
   520 		
       
   521 		// The outer rectangle is calculated from the layoutRect
       
   522 		TRect outerRect = TRect( layoutRect.Rect().iTl, layoutRect.Rect().iBr );
       
   523 		
       
   524 		// Inner rectangle is generated by shrinking the outer rect.
       
   525 		TRect innerRect = outerRect;
       
   526 		innerRect.Shrink( TSize( KVRAmountOfFocusShrink, 
       
   527 									KVRAmountOfFocusShrink ) );
       
   528 		
       
   529 		if (iModel->ButtonState( iFocusedButton ) != EDimmed )
       
   530 			{
       
   531 			//Focus frame is drawn
       
   532 			aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   533 			TBool highlightDrawn = AknsDrawUtils::DrawFrame( iSkin, aGc, 
       
   534 					outerRect, innerRect, KAknsIIDQsnFrGrid, KAknsIIDNone );
       
   535 			} 
       
   536 		}
       
   537 	else
       
   538 		{
       
   539 		if ( iModel->ButtonState( iFocusedButton ) != EDimmed )
       
   540 			{
       
   541 			// Old basic rectangle is drawn
       
   542 			aGc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   543 			aGc.DrawRect( iVRButtons.At( iFocusedButton )->Rect() );
       
   544 			}
       
   545 		}
       
   546 	
       
   547 	}
       
   548 
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // CVRButtonPanel::FocusedButton() 
       
   552 // Returns the index for the currently focused button
       
   553 // ---------------------------------------------------------------------------
       
   554 //
       
   555 TInt CVRButtonPanel::FocusedButton() const
       
   556 	{
       
   557 	return iFocusedButton;
       
   558 	}
       
   559 	
       
   560 	
       
   561 // ---------------------------------------------------------------------------
       
   562 // CVRButtonPanel::StartTimerL
       
   563 // Create and start a timer with initial delay of KVRFastForwStartDelay
       
   564 // and with callback frequency of KVRFastForwUpdateDelay
       
   565 // ---------------------------------------------------------------------------
       
   566 //	
       
   567 void CVRButtonPanel::StartTimerL()
       
   568 	{
       
   569 	if ( iTimer )
       
   570 		{
       
   571 		// stop if iTimer is already running
       
   572 		StopTimer();	
       
   573 		}
       
   574 
       
   575 	TCallBack cb( TimerCallBack, this );
       
   576 	iTimer = CPeriodic::NewL( 0 );
       
   577 	iTimer->Start( KVRFastForwStartDelay, KVRFastForwUpdateDelay, cb );
       
   578 	}
       
   579 
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // CVRButtonPanel::StopTimer
       
   583 // Stop the timer by deleting the CPeriodic object
       
   584 // ---------------------------------------------------------------------------
       
   585 //	
       
   586 void CVRButtonPanel::StopTimer()
       
   587 	{
       
   588 	delete iTimer;
       
   589 	iTimer = NULL;
       
   590 	}
       
   591 
       
   592 
       
   593 // ---------------------------------------------------------------------------
       
   594 // CVRButtonPanel::TimerCallBack
       
   595 // Timer callback for iTimer. Time between callbacks is KVRFastForwUpdateDelay
       
   596 // ---------------------------------------------------------------------------
       
   597 //	
       
   598 TInt CVRButtonPanel::TimerCallBack( TAny* aButtonPanel )
       
   599 	{
       
   600 	CVRButtonPanel* buttonPanel = reinterpret_cast< CVRButtonPanel* >
       
   601 															( aButtonPanel );
       
   602 	
       
   603 	buttonPanel->HandleTimerCallBack();
       
   604 		
       
   605 	return ETrue;
       
   606 	}
       
   607 
       
   608 
       
   609 // ---------------------------------------------------------------------------
       
   610 // CVRButtonPanel::HandleTimerCallBack
       
   611 // Non-static variant of TimerCallBack (more convinient to implement)
       
   612 // ---------------------------------------------------------------------------
       
   613 //
       
   614 void CVRButtonPanel::HandleTimerCallBack()
       
   615 	{
       
   616 	// Callbacks are handled only if focus is on rewind or forward button
       
   617 	if (iFocusedButton == EButtonRewind || iFocusedButton == EButtonForward)
       
   618 		{
       
   619 		TRAPD( err, FetchAndSendCommandL() );
       
   620 		
       
   621 		if ( err )
       
   622 			{
       
   623 		RDebug::Print(_L("VoiceRecorder: FetchAndSendCommandL, error ID: %d"), 
       
   624 				err);
       
   625 			StopTimer();
       
   626 			}
       
   627 		}
       
   628 	}
       
   629 	
       
   630 	
       
   631 // ---------------------------------------------------------------------------
       
   632 // CVRButtonPanel::FetchAndSendCommand
       
   633 // Fetches the command relating to focused button from the model. Command is 
       
   634 // sent on to active view.
       
   635 // ---------------------------------------------------------------------------
       
   636 //	
       
   637 void CVRButtonPanel::FetchAndSendCommandL()
       
   638 	{
       
   639 	// Don't forward the command if dimmed button was clicked or 
       
   640 	// if model can't handle commands
       
   641 	if ( iModel->ButtonState( iFocusedButton ) == EDimmed || 
       
   642 		!iModel->CanHandleCommands() )
       
   643 		{
       
   644 		return;
       
   645 		}
       
   646 	
       
   647 	// Send a command id to the active view specified in the button
       
   648 	CAknViewAppUi* appUi = reinterpret_cast< CAknViewAppUi* >(
       
   649 									CEikonEnv::Static()->EikAppUi() );
       
   650 	CAknView* view = appUi->View( iParentViewUid );
       
   651 	view->HandleCommandL( iModel->CommandId( iFocusedButton ) );
       
   652 	
       
   653 	Update( EVRUpdateStateChange );
       
   654 
       
   655 	}
       
   656 	
       
   657 	
       
   658 // ---------------------------------------------------------------------------
       
   659 // CVRButtonPanel::TuneButtonFocus
       
   660 // The special cases when button focus has to be moved are handled here
       
   661 // ---------------------------------------------------------------------------
       
   662 //	
       
   663 void CVRButtonPanel::TuneButtonFocus()
       
   664 	{
       
   665 	
       
   666 	// CVRRecViewModel::ButtonState() returns EDimmed for EButtonRewind if
       
   667 	// the position of the clip is at the beginning
       
   668 	if ( iFocusedButton == EButtonRewind && 
       
   669 			iModel->ButtonState( iFocusedButton ) == EDimmed )
       
   670 		{
       
   671 		iVRButtons.At( iFocusedButton )->SetDimmed(ETrue);	
       
   672 		MoveFocus( EFocusDown, EFalse );	
       
   673 		}
       
   674 		
       
   675 	// CVRRecViewModel::ButtonState() returns EDimmed for EButtonForward if
       
   676 	// the position of the clip is at the end	
       
   677 	else if( iFocusedButton == EButtonForward && 
       
   678 				iModel->ButtonState( iFocusedButton ) == EDimmed )	
       
   679 		{
       
   680 		iVRButtons.At( iFocusedButton )->SetDimmed(ETrue);	
       
   681 		MoveFocus( EFocusUp, EFalse );
       
   682 		}	
       
   683 	}
       
   684 
       
   685 
       
   686 // ---------------------------------------------------------------------------
       
   687 // CVRButtonPanel::HandleControlEventL
       
   688 // A callback function of Avkon buttons. Handles EEventStateChanged type events 
       
   689 // which happen every time when some of the buttons is pressed and button state 
       
   690 // changes. Event comes before CAknButton::Draw method is executed. 
       
   691 // ---------------------------------------------------------------------------
       
   692 //			
       
   693 void CVRButtonPanel::HandleControlEventL( CCoeControl *aControl, 
       
   694 										  TCoeEvent aEventType )
       
   695 	{
       
   696 	if( AknLayoutUtils::PenEnabled() )
       
   697 		{	
       
   698 		
       
   699 		switch( aEventType )
       
   700 			{
       
   701 			case EEventStateChanged:
       
   702 				{
       
   703 				
       
   704 				TInt newFocusedButton( 0 );
       
   705 				for( TInt i = 0; i < iVRButtons.Count() ; i++ )
       
   706 					{
       
   707 					// Which of buttons was pressed 
       
   708 					if ( aControl == iVRButtons.At( i ) )
       
   709 						{
       
   710 						// When new state is the first state, we have to set 
       
   711 						// new state to ENumStates to be able to se a correct 
       
   712 						// state in SetCurrentState( stateId - 1 , EFalse );
       
   713 						TInt stateId( iVRButtons.At( i )->StateIndex() );
       
   714 						if( stateId == 0 )
       
   715 							{
       
   716 							stateId = ENumStates;
       
   717 							}
       
   718 						
       
   719 						// CAknButton automatically changes the state to next 
       
   720 						// one always when it's ,pressed whether we want it or 
       
   721 						// not. To prevent this we set the previous state 
       
   722 						// before button draws itself
       
   723 						iVRButtons.At( i )->SetCurrentState( stateId - 1,
       
   724 															 EFalse );
       
   725 						newFocusedButton = i;
       
   726 						break;
       
   727 						}
       
   728 					}
       
   729 				
       
   730 				// Focus already was on pressed button so button's command is 
       
   731 				// executed	
       
   732 				if ( iFocusedButton == newFocusedButton )
       
   733 					{
       
   734 					// Don't forward the command if dimmed button was clicked
       
   735 					if ( iModel->ButtonState( iFocusedButton ) == EDimmed )
       
   736 						{
       
   737 						break;
       
   738 						}
       
   739 					
       
   740 					// Send a command id specified in the button to an 
       
   741 					// active view 
       
   742 					CAknViewAppUi* appUi = reinterpret_cast< CAknViewAppUi* >(
       
   743 											CEikonEnv::Static()->EikAppUi() );
       
   744 					CAknView* view = appUi->View( iParentViewUid );
       
   745 					view->HandleCommandL( iModel->CommandId( iFocusedButton ) );
       
   746 					
       
   747 					// To make FastForwarding/FastRewinding possible
       
   748 					if ( iFocusedButton == EButtonRewind || 
       
   749 						 iFocusedButton == EButtonForward )
       
   750 						{
       
   751 						if ( iLastPointerEvent == EVRButtonDownEvent )
       
   752 							{
       
   753 							StartTimerL();	
       
   754 							}							
       
   755 						}
       
   756 					
       
   757 					Update( EVRUpdateStateChange );
       
   758 					}
       
   759 				// Focus was not on the focused button -> 
       
   760 				// Focus should be changed	
       
   761 				else if ( newFocusedButton >= 0 && 
       
   762 						  newFocusedButton < iVRButtons.Count() )
       
   763 					{
       
   764 					//draw focus
       
   765 					if ( iModel->ButtonState( newFocusedButton ) != EDimmed )
       
   766 						{
       
   767 						iFocusedButton = newFocusedButton;
       
   768 						DrawNow();
       
   769 
       
   770 						// Send a command id specified in the button to an 
       
   771 						// active view 
       
   772 						CAknViewAppUi* appUi = reinterpret_cast< CAknViewAppUi* >(
       
   773 											CEikonEnv::Static()->EikAppUi() );
       
   774 						CAknView* view = appUi->View( iParentViewUid );
       
   775 						view->HandleCommandL( iModel->CommandId( iFocusedButton ) );
       
   776 						// To make FastForwarding/FastRewinding possible
       
   777 						if ( iFocusedButton == EButtonRewind || 
       
   778 							 iFocusedButton == EButtonForward )
       
   779 							{
       
   780 							if ( iLastPointerEvent == EVRButtonDownEvent )
       
   781 								{
       
   782 								StartTimerL();	
       
   783 								}							
       
   784 							}
       
   785 						}
       
   786                 // for one error about touch UI, when click a dimmed button, the dimmed
       
   787                 // button should not go back to umdimmed.                   
       
   788 				else
       
   789 					{
       
   790 					DrawNow();	
       
   791 					}
       
   792 				}													
       
   793 				break;	
       
   794 				}
       
   795 			default:
       
   796 				{
       
   797 				// No default behaviour
       
   798 				break;	
       
   799 				}
       
   800 			}
       
   801 			
       
   802 		}
       
   803 	}
       
   804 
       
   805 
       
   806 // ---------------------------------------------------------------------------
       
   807 // CVRButtonPanel::HandlePointerEventL
       
   808 // Handles Button panel pointer events. True functionality is to stop 
       
   809 // FastForward timer when FF should be stopped.
       
   810 // ---------------------------------------------------------------------------
       
   811 //		
       
   812 void CVRButtonPanel::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   813 	{
       
   814 	if( AknLayoutUtils::PenEnabled() )
       
   815 		{
       
   816 		
       
   817 		
       
   818 		switch( aPointerEvent.iType )
       
   819 			{
       
   820 			case TPointerEvent::EButton1Down:
       
   821 				{
       
   822 				// Don't start timer here. It's started in HandleControlEventL() 
       
   823 				iLastPointerEvent = EVRButtonDownEvent;
       
   824 				break;
       
   825 				}
       
   826 			case TPointerEvent::EDrag:
       
   827 				{
       
   828 				// Don't stop timer if just dragging inside the currently 
       
   829 				// focused button
       
   830 				TRect focusedButtonRect( 
       
   831 									 iVRButtons.At( iFocusedButton )->Rect() );
       
   832 				if( !focusedButtonRect.Contains( aPointerEvent.iPosition ) )
       
   833 					{
       
   834 					// Dragged outside
       
   835 					iLastPointerEvent = EVRButtonDragOutsideEvent;
       
   836 					StopTimer();	
       
   837 					}
       
   838 				break;		
       
   839 				}
       
   840 			case TPointerEvent::EButton1Up:
       
   841 				{
       
   842 				// Pen up
       
   843 				iLastPointerEvent = EVRButtonUpEvent;
       
   844 				StopTimer();	
       
   845 				break;
       
   846 				}		
       
   847 			default:
       
   848 				{
       
   849 				break;	
       
   850 				}	
       
   851 			}
       
   852 		
       
   853 		CCoeControl::HandlePointerEventL( aPointerEvent );
       
   854 		}
       
   855 	}
       
   856 
       
   857 // End of file