uifw/EikStd/coctlsrc/EikCcpu.cpp
branchRCL_3
changeset 6 9f56a4e1b8ab
parent 3 8ca85d2f0db7
child 18 fcdfafb36fe7
--- a/uifw/EikStd/coctlsrc/EikCcpu.cpp	Fri Mar 12 15:43:43 2010 +0200
+++ b/uifw/EikStd/coctlsrc/EikCcpu.cpp	Mon Mar 15 12:41:34 2010 +0200
@@ -25,10 +25,40 @@
 #include <avkon.hrh>
 #include <eikappui.h>
 #include <eikdialg.h>
-const TInt ELeftSoftkeyIndex = 0;
-const TInt ERightSoftkeyIndex = 2;
-const TInt ENullCommandId = -1;
+const TInt KLeftSoftkeyIndex = 0;
+const TInt KRightSoftkeyIndex = 2;
+const TInt KNullCommandId = -1;
+
+/**
+* Internal extension class for CAknCcpuSupport.
+*
+* @since 9.2
+*
+* @internal
+*/
+NONSHARABLE_CLASS( CAknCcpuSupportExtension ) : public CBase
+    {
+public: // Construction and destruction
 
+    CAknCcpuSupportExtension();
+    ~CAknCcpuSupportExtension();
+
+public: // Data
+    TBool iIsCbaEmded;
+    // Owned
+    CEikButtonGroupContainer* iCba;
+    // not owned
+    CEikButtonGroupContainer* iDialogCba;
+    };
+
+CAknCcpuSupportExtension::CAknCcpuSupportExtension()
+    {
+    }
+
+CAknCcpuSupportExtension::~CAknCcpuSupportExtension()
+    {
+    delete iCba;
+    }
 
 //
 // CAknCcpuSupport
@@ -39,77 +69,85 @@
 	EFocused
 	};
 
-EXPORT_C CAknCcpuSupport::CAknCcpuSupport(MEikCcpuEditor* aEditor)
-: iEditor(aEditor)
+EXPORT_C CAknCcpuSupport::CAknCcpuSupport( MEikCcpuEditor* aEditor )
+: iEditor( aEditor )
 	{
 	}
 
 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport()
 	{
-	if (iMenu)
+	if ( iMenu )
+	    {
 		iMenu->RemoveEditMenuObserver(this);
-	//delete iCba;
-	TRAP_IGNORE(DeleteCBAL());
-	iEikonEnv->EikAppUi()->RemoveFromStack(this);
+	    }
+	TRAP_IGNORE( DeleteCBAL() );
+	iEikonEnv->EikAppUi()->RemoveFromStack( this );
+	delete iExtention;
 	}
 
 EXPORT_C void CAknCcpuSupport::ConstructL()
 	{
-	iEikonEnv->EikAppUi()->AddToStackL(this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus);
+    iExtention = new ( ELeave ) CAknCcpuSupportExtension;
+	iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus );
 	HandleFocusChangeL();
 	}
 
 EXPORT_C void CAknCcpuSupport::HandleSelectionChangeL()
 	{
-	if (iCba)
+	if ( iExtention->iCba )
+	    {
 		UpdateCBALabelsL();
+	    }
 	}
 
 EXPORT_C void CAknCcpuSupport::HandleFocusChangeL()
 	{
 	TBool focused = iEditor->CcpuIsFocused();
-	if (COMPARE_BOOLS(focused, iFlags[EFocused]))
+	if ( COMPARE_BOOLS( focused, iFlags[EFocused] ) )
+	    {
 		return;
+	    }
 
-	iFlags.Assign(EFocused, focused);
+	iFlags.Assign( EFocused, focused );
 
-	if (focused)
+	if ( focused )
 		{
-		MopGetObject(iMenu);
-
-		if (iMenu)
-			iMenu->SetEditMenuObserver(this);
+		MopGetObject( iMenu );
+		if ( iMenu )
+		    {
+			iMenu->SetEditMenuObserver( this );
+		    }
 		}
 	else
 		{
-		if (iMenu)
+		if ( iMenu )
 			{
-			iMenu->RemoveEditMenuObserver(this);
+			iMenu->RemoveEditMenuObserver( this );
 			iMenu = NULL;
 			}
 		}
 
-	if (iCba && !focused)
+	if ( iExtention->iCba && !focused )
 		{
 		// something has caused loss of focus while shift is pressed - drop everything.
-		//delete iCba;
-		//iCba = NULL;
 		DeleteCBAL();
 		}
 	}
 
-EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
+EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
 	{
-	if (!iFlags[EFocused])
+	if ( !iFlags[EFocused] )
+	    {
 		return EKeyWasNotConsumed;
+	    }
 
-	if (aKeyEvent.iCode == EKeyF21)		// FEP generates F21 on long shift press
+	if ( aKeyEvent.iCode == EKeyF21 )		// FEP generates F21 on long shift press
 		{
-		if (aType == EEventKey)
+		if ( aType == EEventKey )
 			{		
 			DeleteCBAL();
 			CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi();
-			if( eikAppUi!= NULL && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
+			if( eikAppUi && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
 				{
 				CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg );
 				if ( dlg )
@@ -121,76 +159,81 @@
 						CEikCba* dlgcba = static_cast<CEikCba*>( currentCba->ButtonGroup() );
 						TUint flags( 0 ); 
 						flags |= CEikButtonGroupContainer::EIsEmbedded | CEikButtonGroupContainer::EAddToStack;
-						iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, 
+                        iExtention->iCba = CEikButtonGroupContainer::NewL( 
+                                CEikButtonGroupContainer::ECba, 
+                                CEikButtonGroupContainer::EHorizontal, 
 								this, R_AVKON_SOFTKEYS_EMPTY, flags );
 						
 						CEikCba* cba = static_cast<CEikCba*>(
-								iCba->ButtonGroup() );					   
+                                iExtention->iCba->ButtonGroup() );					   
 						
-						if( ! isCbaEmded )
+                        if( !iExtention->iIsCbaEmded )
 							{
-							currentCba->AddCommandToStackL(ELeftSoftkeyIndex, -1, _L(""), NULL, NULL);
-							currentCba->AddCommandToStackL(ERightSoftkeyIndex, -1, _L(""), NULL, NULL);
+							currentCba->AddCommandToStackL( KLeftSoftkeyIndex, -1, KNullDesC, NULL, NULL );
+							currentCba->AddCommandToStackL( KRightSoftkeyIndex, -1, KNullDesC, NULL, NULL );
 							currentCba->ActivateL();
 							currentCba->DrawNow();
-							iDialogCba = currentCba;
-							isCbaEmded = ETrue;
+                            iExtention->iDialogCba = currentCba;
+                            iExtention->iIsCbaEmded = ETrue;
 							}
 					
-						cba->SetButtonGroupFlags( ~(EEikCbaFlagTransparent | EEikCbaFlagOutlineFont) );
+						cba->SetButtonGroupFlags( ~( EEikCbaFlagTransparent | EEikCbaFlagOutlineFont ) );
 						TRect dlgRect(dlg->Rect());
 						TRect cbaRect(currentCba->Rect());
-						iCba->SetRect( currentCba->Rect());
-						iCba->SetPosition(TPoint(dlg->DrawableWindow()->Position().iX,dlg->DrawableWindow()->Position().iY + dlgRect.Height() - cbaRect.Height()));
-						iCba->SetBoundingRect( dlg->Rect());
+                        iExtention->iCba->SetRect( currentCba->Rect());
+                        iExtention->iCba->SetPosition(
+                            TPoint( dlg->DrawableWindow()->Position().iX, 
+                                    dlg->DrawableWindow()->Position().iY + dlgRect.Height() - cbaRect.Height() ) );
+                        iExtention->iCba->SetBoundingRect( dlg->Rect() );
 						
-						}
-					
-					}
-				
+						}				
+					}	
 				}
-			if(iCba == NULL)//if iCba was not create in the above branch but was deleted by DeleteCBA
+			if( !iExtention->iCba )//if iCba was not create in the above branch but was deleted by DeleteCBA
 				{
-				iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY);
-				iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect());
+			    iExtention->iCba = CEikButtonGroupContainer::NewL( 
+			            CEikButtonGroupContainer::ECba,
+			            CEikButtonGroupContainer::EHorizontal,
+			            this, R_AVKON_SOFTKEYS_EMPTY );
+			    iExtention->iCba->SetBoundingRect( iEikonEnv->EikAppUi()->ApplicationRect() );
 				}
 			UpdateCBALabelsL();
 			}
 		return EKeyWasConsumed;
 		}  
-    else if (aType == EEventKey &&
-             aKeyEvent.iCode == EKeyF18 &&
-             (aKeyEvent.iModifiers & EModifierCtrl))			
+    else if ( aType == EEventKey &&
+              aKeyEvent.iCode == EKeyF18 &&
+              ( aKeyEvent.iModifiers & EModifierCtrl ) )			
         {
         // FEP requests Ccpu actions with CTRL + F18         
         // Requested action is encoded in iScanCode.
-        ProcessCommandL(aKeyEvent.iScanCode);
+        ProcessCommandL( aKeyEvent.iScanCode );
        	return EKeyWasConsumed;
         }					
-	else if ((aKeyEvent.iScanCode == EStdKeyLeftShift || aKeyEvent.iScanCode == EStdKeyRightShift) && aType == EEventKeyUp)
+	else if ( ( aKeyEvent.iScanCode == EStdKeyLeftShift || 
+	            aKeyEvent.iScanCode == EStdKeyRightShift ) && 
+	            aType == EEventKeyUp )
 		{
-		//delete iCba;
-		//iCba = NULL;
 		DeleteCBAL();
 		}
 	
 	return EKeyWasNotConsumed;
 	}
 
-EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
+EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL( TInt aResourceId,CEikMenuPane* aMenuPane )
 	{
-	if (aResourceId == R_AVKON_EDIT_MODE_MENU || 
-		aResourceId == R_AVKON_EDIT_TEXT_MENU)
+	if ( aResourceId == R_AVKON_EDIT_MODE_MENU || 
+		aResourceId == R_AVKON_EDIT_TEXT_MENU )
 		{
-		aMenuPane->SetItemDimmed(EEikCmdEditCut,!iEditor->CcpuCanCut());
-		aMenuPane->SetItemDimmed(EEikCmdEditCopy,!iEditor->CcpuCanCopy());
-		aMenuPane->SetItemDimmed(EEikCmdEditPaste,!iEditor->CcpuCanPaste());
+		aMenuPane->SetItemDimmed( EEikCmdEditCut,!iEditor->CcpuCanCut() );
+		aMenuPane->SetItemDimmed( EEikCmdEditCopy,!iEditor->CcpuCanCopy() );
+		aMenuPane->SetItemDimmed( EEikCmdEditPaste,!iEditor->CcpuCanPaste() );
 		}
 	}
 
-EXPORT_C void CAknCcpuSupport::ProcessCommandL(TInt aCommandId)
+EXPORT_C void CAknCcpuSupport::ProcessCommandL( TInt aCommandId )
 	{
-	switch (aCommandId)
+	switch ( aCommandId )
 		{
 		case EEikCmdEditCut:
 			iEditor->CcpuCutL();
@@ -213,41 +256,49 @@
 	{
 	TBool change = EFalse;
 
-	if (iEditor->CcpuCanCopy())
-		change = UpdateCBALabelL(ELeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY) || change;
+	if ( iEditor->CcpuCanCopy() )
+	    {
+		change = UpdateCBALabelL( KLeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY ) || change;
+	    }
 	else
-		change = UpdateCBALabelL(ELeftSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change;
+	    {
+		change = UpdateCBALabelL( KLeftSoftkeyIndex, KNullCommandId, R_TEXT_SOFTKEY_EMPTY ) || change;
+	    }
 
-	if (iEditor->CcpuCanPaste())
-		change = UpdateCBALabelL(ERightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE) || change;
+	if ( iEditor->CcpuCanPaste() )
+	    {
+		change = UpdateCBALabelL( KRightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE ) || change;
+	    }
 	else
-		change = UpdateCBALabelL(ERightSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change;
+	    {
+		change = UpdateCBALabelL( KRightSoftkeyIndex, KNullCommandId, R_TEXT_SOFTKEY_EMPTY ) || change;
+	    }
 
-	if (change)
+	if ( change )
 		{
-		iCba->DrawNow();
+        iExtention->iCba->DrawNow();
 		}
 	}
 
-TBool CAknCcpuSupport::UpdateCBALabelL(TInt aPosition, TInt aCommandId, TInt aTextResId)
+TBool CAknCcpuSupport::UpdateCBALabelL( TInt aPosition, TInt aCommandId, TInt aTextResId )
 	{
-	if (iCba->ButtonGroup()->CommandId(aPosition) != aCommandId)
+	if ( iExtention->iCba->ButtonGroup()->CommandId(aPosition) != aCommandId )
 		{
-		HBufC* buf = iEikonEnv->AllocReadResourceLC(aTextResId);
-		iCba->SetCommandL(aPosition, aCommandId, *buf);
-		CleanupStack::PopAndDestroy(buf);
+		HBufC* buf = iEikonEnv->AllocReadResourceLC( aTextResId );
+		iExtention->iCba->SetCommandL( aPosition, aCommandId, *buf );
+		CleanupStack::PopAndDestroy( buf );
 		return ETrue;
 		}
 	return EFalse;
 	}
 
-void CAknCcpuSupport::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)
+void CAknCcpuSupport::SetEmphasis( CCoeControl* /*aMenuControl*/, TBool /*aEmphasis*/ )
 	{
 	}
 
-EXPORT_C void CAknCcpuSupport::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
+EXPORT_C void CAknCcpuSupport::HandlePointerEventL( const TPointerEvent& aPointerEvent ) 
     { 
-    CAknControl::HandlePointerEventL(aPointerEvent); 
+    CAknControl::HandlePointerEventL( aPointerEvent ); 
     }
 
 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ )
@@ -256,35 +307,32 @@
     }
 void CAknCcpuSupport::DeleteCBAL()
 	{
-	if ( iCba != NULL )
+	if ( iExtention->iCba )
 		{
-	    delete iCba;
-	    iCba = NULL;
+	    delete iExtention->iCba;
+	    iExtention->iCba = NULL;
 		}
-	if (isCbaEmded)
+	if ( iExtention->iIsCbaEmded )
 		{
 		CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi();
-		    if( eikAppUi!= NULL && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
-		        {
-		        CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg );
-		        if ( dlg )
-		        	{
-		            CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba );
-	        	    CEikCba* dlgcba = static_cast<CEikCba*>(
-	        	        currentCba->ButtonGroup() );
-	        	    if ( currentCba && iDialogCba == currentCba )
-		        	    {
-		        	    currentCba->RemoveCommandFromStack(ELeftSoftkeyIndex,-1);
-		        	    currentCba->RemoveCommandFromStack(ERightSoftkeyIndex,-1);
-
-		        	    //dlgcba->UpdateCbaLabels(EFalse);
-		        	    currentCba->DrawNow();
-		        	    currentCba->ActivateL();
-		        	    iDialogCba = NULL;
-                        isCbaEmded = EFalse;
-		        	    }
-		        	}
-		        }
+        if( eikAppUi && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
+            {
+            CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg );
+            if ( dlg )
+                {
+                CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba );
+                CEikCba* dlgcba = static_cast<CEikCba*>(
+                    currentCba->ButtonGroup() );
+                if ( currentCba && iExtention->iDialogCba == currentCba )
+                    {
+                    currentCba->RemoveCommandFromStack( KLeftSoftkeyIndex, -1 );
+                    currentCba->RemoveCommandFromStack( KRightSoftkeyIndex, -1 );
+                    currentCba->DrawNow();
+                    currentCba->ActivateL();
+                    iExtention->iDialogCba = NULL;
+                    iExtention->iIsCbaEmded = EFalse;
+                    }
+                }
+            }
 		}
-
 	}