uifw/EikStd/coctlsrc/EikCcpu.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
--- a/uifw/EikStd/coctlsrc/EikCcpu.cpp	Tue Aug 31 15:28:30 2010 +0300
+++ b/uifw/EikStd/coctlsrc/EikCcpu.cpp	Wed Sep 01 12:16:19 2010 +0100
@@ -24,11 +24,44 @@
 #include <avkon.rsg>
 #include <avkon.hrh>
 #include <eikappui.h>
+#include <eikdialg.h>
+const TInt KLeftSoftkeyIndex = 0;
+const TInt KRightSoftkeyIndex = 2;
+const TInt KNullCommandId = -1;
 
-const TInt ELeftSoftkeyIndex = 0;
-const TInt ERightSoftkeyIndex = 2;
-const TInt ENullCommandId = -1;
+// declare the function IsCbaEmbeddedInDialog
+TBool IsCbaEmbeddedInDialog( const TInt& aFlags );
+
+/**
+* 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,112 +72,171 @@
 	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;
-	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)
-			{
-			delete iCba;
-			iCba = NULL;
-			iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY);
-			iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect());
+		if ( aType == EEventKey )
+			{		
+			DeleteCBAL();
+			CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi();
+			if( eikAppUi && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() )
+				{
+				CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg );
+				if ( dlg && IsCbaEmbeddedInDialog( dlg->DialogFlags() ) )
+					{
+					CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba );
+					
+					if ( currentCba )
+						{
+						CEikCba* dlgcba = static_cast<CEikCba*>( currentCba->ButtonGroup() );
+						TUint flags( 0 ); 
+						flags |= CEikButtonGroupContainer::EIsEmbedded | CEikButtonGroupContainer::EAddToStack;
+                        iExtention->iCba = CEikButtonGroupContainer::NewL( 
+                                CEikButtonGroupContainer::ECba, 
+                                CEikButtonGroupContainer::EHorizontal, 
+								this, R_AVKON_SOFTKEYS_EMPTY, flags );
+						
+						CEikCba* cba = static_cast<CEikCba*>(
+                                iExtention->iCba->ButtonGroup() );					   
+						
+                        if( !iExtention->iIsCbaEmded )
+							{
+							currentCba->AddCommandToStackL( KLeftSoftkeyIndex, -1, KNullDesC, NULL, NULL );
+							currentCba->AddCommandToStackL( KRightSoftkeyIndex, -1, KNullDesC, NULL, NULL );
+							currentCba->ActivateL();
+							currentCba->DrawNow();
+                            iExtention->iDialogCba = currentCba;
+                            iExtention->iIsCbaEmded = ETrue;
+							}
+					
+						cba->SetButtonGroupFlags( ~( EEikCbaFlagTransparent | EEikCbaFlagOutlineFont ) );
+						TRect dlgRect(dlg->Rect());
+						TRect cbaRect(currentCba->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( !iExtention->iCba )//if iCba was not create in the above branch but was deleted by DeleteCBA
+				{
+			    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();
@@ -167,44 +259,99 @@
 	{
 	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)
-		iCba->DrawNow();
+	if ( change )
+		{
+        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*/ )
     {
     return NULL;
     }
+void CAknCcpuSupport::DeleteCBAL()
+	{
+	if ( iExtention->iCba )
+		{
+	    delete iExtention->iCba;
+	    iExtention->iCba = NULL;
+		}
+	if ( iExtention->iIsCbaEmded )
+		{
+		CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi();
+        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;
+                    }
+                }
+            }
+		}
+	}
+
+/**
+ * To detect if CBA is embedded in the diaplog.
+ * @param aFlags it should be CEikDialog::DialogFlags()
+ * @return if an CBA is embedded in the dialog return ETrue 
+ *         else return EFalse
+ */
+TBool IsCbaEmbeddedInDialog( const TInt& aFlags )
+    {
+    return !( aFlags & EEikDialogFlagFillAppClientRect ) &&
+        !( aFlags & EEikDialogFlagFillScreen ) &&
+        !( aFlags & EEikDialogFlagVirtualInput ) &&
+        !( aFlags & EEikDialogFlagNoEmbeddedSoftkeys );
+    }