uifw/EikStd/coctlsrc/EikCcpu.cpp
branchRCL_3
changeset 4 8ca85d2f0db7
parent 0 2f259fa3e83a
child 10 9f56a4e1b8ab
equal deleted inserted replaced
0:2f259fa3e83a 4:8ca85d2f0db7
    22 #include <eikbtgpc.h>
    22 #include <eikbtgpc.h>
    23 #include <aknenv.h>
    23 #include <aknenv.h>
    24 #include <avkon.rsg>
    24 #include <avkon.rsg>
    25 #include <avkon.hrh>
    25 #include <avkon.hrh>
    26 #include <eikappui.h>
    26 #include <eikappui.h>
    27 
    27 #include <eikdialg.h>
    28 const TInt ELeftSoftkeyIndex = 0;
    28 const TInt ELeftSoftkeyIndex = 0;
    29 const TInt ERightSoftkeyIndex = 2;
    29 const TInt ERightSoftkeyIndex = 2;
    30 const TInt ENullCommandId = -1;
    30 const TInt ENullCommandId = -1;
    31 
    31 
    32 
    32 
    46 
    46 
    47 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport()
    47 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport()
    48 	{
    48 	{
    49 	if (iMenu)
    49 	if (iMenu)
    50 		iMenu->RemoveEditMenuObserver(this);
    50 		iMenu->RemoveEditMenuObserver(this);
    51 	delete iCba;
    51 	//delete iCba;
       
    52 	TRAP_IGNORE(DeleteCBAL());
    52 	iEikonEnv->EikAppUi()->RemoveFromStack(this);
    53 	iEikonEnv->EikAppUi()->RemoveFromStack(this);
    53 	}
    54 	}
    54 
    55 
    55 EXPORT_C void CAknCcpuSupport::ConstructL()
    56 EXPORT_C void CAknCcpuSupport::ConstructL()
    56 	{
    57 	{
    89 		}
    90 		}
    90 
    91 
    91 	if (iCba && !focused)
    92 	if (iCba && !focused)
    92 		{
    93 		{
    93 		// something has caused loss of focus while shift is pressed - drop everything.
    94 		// something has caused loss of focus while shift is pressed - drop everything.
    94 		delete iCba;
    95 		//delete iCba;
    95 		iCba = NULL;
    96 		//iCba = NULL;
       
    97 		DeleteCBAL();
    96 		}
    98 		}
    97 	}
    99 	}
    98 
   100 
    99 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
   101 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
   100 	{
   102 	{
   102 		return EKeyWasNotConsumed;
   104 		return EKeyWasNotConsumed;
   103 
   105 
   104 	if (aKeyEvent.iCode == EKeyF21)		// FEP generates F21 on long shift press
   106 	if (aKeyEvent.iCode == EKeyF21)		// FEP generates F21 on long shift press
   105 		{
   107 		{
   106 		if (aType == EEventKey)
   108 		if (aType == EEventKey)
   107 			{
   109 			{		
   108 			delete iCba;
   110 			DeleteCBAL();
   109 			iCba = NULL;
   111 			CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi();
   110 			iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY);
   112 			if( eikAppUi!= NULL && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
   111 			iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect());
   113 				{
       
   114 				CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg );
       
   115 				if ( dlg )
       
   116 					{
       
   117 					CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba );
       
   118 					
       
   119 					if ( currentCba )
       
   120 						{
       
   121 						CEikCba* dlgcba = static_cast<CEikCba*>( currentCba->ButtonGroup() );
       
   122 						TUint flags( 0 ); 
       
   123 						flags |= CEikButtonGroupContainer::EIsEmbedded | CEikButtonGroupContainer::EAddToStack;
       
   124 						iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, 
       
   125 								this, R_AVKON_SOFTKEYS_EMPTY, flags );
       
   126 						
       
   127 						CEikCba* cba = static_cast<CEikCba*>(
       
   128 								iCba->ButtonGroup() );					   
       
   129 						
       
   130 						if( ! isCbaEmded )
       
   131 							{
       
   132 							currentCba->AddCommandToStackL(ELeftSoftkeyIndex, -1, _L(""), NULL, NULL);
       
   133 							currentCba->AddCommandToStackL(ERightSoftkeyIndex, -1, _L(""), NULL, NULL);
       
   134 							currentCba->ActivateL();
       
   135 							currentCba->DrawNow();
       
   136 							iDialogCba = currentCba;
       
   137 							isCbaEmded = ETrue;
       
   138 							}
       
   139 					
       
   140 						cba->SetButtonGroupFlags( ~(EEikCbaFlagTransparent | EEikCbaFlagOutlineFont) );
       
   141 						TRect dlgRect(dlg->Rect());
       
   142 						TRect cbaRect(currentCba->Rect());
       
   143 						iCba->SetRect( currentCba->Rect());
       
   144 						iCba->SetPosition(TPoint(dlg->DrawableWindow()->Position().iX,dlg->DrawableWindow()->Position().iY + dlgRect.Height() - cbaRect.Height()));
       
   145 						iCba->SetBoundingRect( dlg->Rect());
       
   146 						
       
   147 						}
       
   148 					
       
   149 					}
       
   150 				
       
   151 				}
       
   152 			if(iCba == NULL)//if iCba was not create in the above branch but was deleted by DeleteCBA
       
   153 				{
       
   154 				iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY);
       
   155 				iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect());
       
   156 				}
   112 			UpdateCBALabelsL();
   157 			UpdateCBALabelsL();
   113 			}
   158 			}
   114 		return EKeyWasConsumed;
   159 		return EKeyWasConsumed;
   115 		}  
   160 		}  
   116     else if (aType == EEventKey &&
   161     else if (aType == EEventKey &&
   122         ProcessCommandL(aKeyEvent.iScanCode);
   167         ProcessCommandL(aKeyEvent.iScanCode);
   123        	return EKeyWasConsumed;
   168        	return EKeyWasConsumed;
   124         }					
   169         }					
   125 	else if ((aKeyEvent.iScanCode == EStdKeyLeftShift || aKeyEvent.iScanCode == EStdKeyRightShift) && aType == EEventKeyUp)
   170 	else if ((aKeyEvent.iScanCode == EStdKeyLeftShift || aKeyEvent.iScanCode == EStdKeyRightShift) && aType == EEventKeyUp)
   126 		{
   171 		{
   127 		delete iCba;
   172 		//delete iCba;
   128 		iCba = NULL;
   173 		//iCba = NULL;
       
   174 		DeleteCBAL();
   129 		}
   175 		}
   130 	
   176 	
   131 	return EKeyWasNotConsumed;
   177 	return EKeyWasNotConsumed;
   132 	}
   178 	}
   133 
   179 
   176 		change = UpdateCBALabelL(ERightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE) || change;
   222 		change = UpdateCBALabelL(ERightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE) || change;
   177 	else
   223 	else
   178 		change = UpdateCBALabelL(ERightSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change;
   224 		change = UpdateCBALabelL(ERightSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change;
   179 
   225 
   180 	if (change)
   226 	if (change)
       
   227 		{
   181 		iCba->DrawNow();
   228 		iCba->DrawNow();
       
   229 		}
   182 	}
   230 	}
   183 
   231 
   184 TBool CAknCcpuSupport::UpdateCBALabelL(TInt aPosition, TInt aCommandId, TInt aTextResId)
   232 TBool CAknCcpuSupport::UpdateCBALabelL(TInt aPosition, TInt aCommandId, TInt aTextResId)
   185 	{
   233 	{
   186 	if (iCba->ButtonGroup()->CommandId(aPosition) != aCommandId)
   234 	if (iCba->ButtonGroup()->CommandId(aPosition) != aCommandId)
   204 
   252 
   205 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ )
   253 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ )
   206     {
   254     {
   207     return NULL;
   255     return NULL;
   208     }
   256     }
   209 
   257 void CAknCcpuSupport::DeleteCBAL()
   210 
   258 	{
       
   259 	if ( iCba != NULL )
       
   260 		{
       
   261 	    delete iCba;
       
   262 	    iCba = NULL;
       
   263 		}
       
   264 	if (isCbaEmded)
       
   265 		{
       
   266 		CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi();
       
   267 		    if( eikAppUi!= NULL && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
       
   268 		        {
       
   269 		        CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg );
       
   270 		        if ( dlg )
       
   271 		        	{
       
   272 		            CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba );
       
   273 	        	    CEikCba* dlgcba = static_cast<CEikCba*>(
       
   274 	        	        currentCba->ButtonGroup() );
       
   275 	        	    if ( currentCba && iDialogCba == currentCba )
       
   276 		        	    {
       
   277 		        	    currentCba->RemoveCommandFromStack(ELeftSoftkeyIndex,-1);
       
   278 		        	    currentCba->RemoveCommandFromStack(ERightSoftkeyIndex,-1);
       
   279 
       
   280 		        	    //dlgcba->UpdateCbaLabels(EFalse);
       
   281 		        	    currentCba->DrawNow();
       
   282 		        	    currentCba->ActivateL();
       
   283 		        	    iDialogCba = NULL;
       
   284                         isCbaEmded = EFalse;
       
   285 		        	    }
       
   286 		        	}
       
   287 		        }
       
   288 		}
       
   289 
       
   290 	}