mobilemessaging/postcard/postcardsrc/PostcardTextDialog.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005 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 *       Provides CPostcardTextDialog class methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32def.h>
       
    23 #include <AknDef.h>
       
    24 #include <aknappui.h>
       
    25 #include <featmgr.h>                // for Feature Manager
       
    26 #include <bldvariant.hrh>           // for Feature Flags
       
    27 #include <eikmenub.h>               // for CEikMenuBar
       
    28 #include <ConeResLoader.h>          // for RConeResourceLoader
       
    29 #include <data_caging_path_literals.hrh> 
       
    30 #include <csxhelp/postcard.hlp.hrh>
       
    31 
       
    32 // AVKON
       
    33 #include <akntitle.h>               // for CAknTitlePane
       
    34 #include <AknIndicatorContainer.h>	// for CAknIndicatorContainer
       
    35 #include <aknEditStateIndicator.h>	// for MAknEditStateIndicator
       
    36 #include <aknenv.h>                 // for AppShutter
       
    37 #include <AknWaitDialog.h>          // CAknWaitNoteWrapper
       
    38 #include <aknnotewrappers.h>        // CAknInformationNote
       
    39 #include <AknColourSelectionGrid.h> // CAknColourSelectionGrid
       
    40 #include <aknlayout.cdl.h>
       
    41 #include <AknUtils.h>
       
    42 #include <applayout.cdl.h>
       
    43 #include <aknlayoutscalable_apps.cdl.h>
       
    44 #include <aknlayoutscalable_avkon.cdl.h>
       
    45 
       
    46 // For drawing
       
    47 #include <AknsConstants.h>           // For skinnable icons
       
    48 #include <AknsBasicBackgroundControlContext.h> // For skin stuff, too
       
    49 #include <AknsDrawUtils.h>
       
    50 
       
    51 // Richtextstuff
       
    52 #include <eikrted.h>
       
    53 #include <txtrich.h>
       
    54 #include <txtetext.h>
       
    55 
       
    56 // COMMON ENGINE
       
    57 #include <StringLoader.h>           // for StringLoader::
       
    58 
       
    59 // MSG EDITOR BASE
       
    60 #include <MsgEditorAppUi.rsg>
       
    61 #include <MsgEditorCommon.h>
       
    62 #include "MsgAttachmentUtils.h"		// for fetchdialogs
       
    63 
       
    64 #include <NpdApi.h>                 // Notepad API
       
    65 
       
    66 #include <mmsmsventry.h>
       
    67 
       
    68 #include <centralrepository.h>      // link against centralrepository.lib
       
    69 #include <MmsEngineInternalCRKeys.h>// for Central Repository keys
       
    70 
       
    71 #include "MsgAttachmentUtils.h"
       
    72 
       
    73 #include <Postcard.rsg>
       
    74 #include "Postcard.hrh"
       
    75 #include "PostcardLaf.h"
       
    76 #include "PostcardTextDialog.h"
       
    77 #include "PostcardDocument.h"
       
    78 #include "PostcardAppUi.h"
       
    79 #include "PostcardTextDialogCustomDraw.h"
       
    80 
       
    81 // ================= MEMBER FUNCTIONS =======================
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 //  Two-phased constructor
       
    85 // ---------------------------------------------------------
       
    86 CPostcardTextDialog* CPostcardTextDialog::NewL( CPostcardAppUi& aAppUi, CPostcardDocument& aDocument, CPlainText& aText, TInt& aRetValue, TKeyEvent aKeyEvent )
       
    87     {
       
    88     CPostcardTextDialog* self = 
       
    89         new (ELeave) CPostcardTextDialog( aAppUi, aDocument, aText, aRetValue, aKeyEvent );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL( );
       
    92     CleanupStack::Pop( self );
       
    93     return self;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------
       
    97 //  Default destructor
       
    98 // ---------------------------------------------------------
       
    99 CPostcardTextDialog::~CPostcardTextDialog()
       
   100     {
       
   101     // Remove the navidecorator from status pane
       
   102     CEikStatusPane *sp = iEikonEnv->AppUiFactory( )->StatusPane( );
       
   103     TRAP_IGNORE(
       
   104         static_cast<CAknNavigationControlContainer*>
       
   105             ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) )->Pop( );
       
   106     ); // TRAP_IGNORE
       
   107     
       
   108     delete iNaviDecorator;
       
   109     delete iTextEditor;
       
   110     delete iCustomDraw;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // CPostcardTextDialog
       
   115 // ---------------------------------------------------------
       
   116 CPostcardTextDialog::CPostcardTextDialog( 
       
   117 			CPostcardAppUi& aAppUi, 
       
   118 			CPostcardDocument& aDocument, 
       
   119 			CPlainText& aText, 
       
   120 			TInt& aRetValue, 
       
   121 			TKeyEvent aKeyEvent  ) :
       
   122     iAppUi( aAppUi ),   
       
   123     iDocument( aDocument ),
       
   124     iOrigText( aText ),
       
   125     iKeyEvent( aKeyEvent ),
       
   126     iRetValue( aRetValue )
       
   127     {
       
   128     } 
       
   129 
       
   130 // ---------------------------------------------------------
       
   131 // ExecLD()
       
   132 // ---------------------------------------------------------
       
   133 TInt CPostcardTextDialog::ExecLD( )
       
   134     {
       
   135     PrepareLC( R_POSTCARD_TEXT_DIALOG );
       
   136         
       
   137     return CAknDialog::RunLD( );
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 //  EPOC constructor
       
   142 // ---------------------------------------------------------
       
   143 void CPostcardTextDialog::ConstructL( )
       
   144     {
       
   145     // Feature manager
       
   146     FeatureManager::InitializeLibL( );
       
   147 
       
   148     if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   149         {
       
   150         iTextFlags |= EPostcardTextHelpSupported;
       
   151         }
       
   152 
       
   153     FeatureManager::UnInitializeLib( );
       
   154 
       
   155     iMaxLen = iAppUi.MaxTextLength( EPostcardTextEditor );
       
   156 
       
   157     // Call the base class' two-phased constructor
       
   158     CAknDialog::ConstructL( R_POSTCARD_TEXT_MENUBAR );
       
   159 
       
   160     iMenuBar->SetContextMenuTitleResourceId( R_POSTCARD_TEXT_CONTEXT_MENUBAR );
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------
       
   164 // CPostcardTextDialog::PreLayoutDynInitL
       
   165 // ----------------------------------------------------
       
   166 void CPostcardTextDialog::PreLayoutDynInitL( )
       
   167     {
       
   168     TInt edwinFlags =
       
   169         CEikEdwin::ENoHorizScrolling
       
   170         | CEikEdwin::ENoAutoSelection
       
   171         | CEikEdwin::EWidthInPixels
       
   172         | CEikEdwin::EAllowUndo
       
   173         | CEikEdwin::ELineCursor
       
   174         | CEikEdwin::EResizable
       
   175         | CEikEdwin::EInclusiveSizeFixed;
       
   176 
       
   177     if( iDocument.MessageType() == EPostcardSent )
       
   178     	{
       
   179 		edwinFlags |= CEikEdwin::EReadOnly;
       
   180 		edwinFlags |= CEikEdwin::EAvkonDisableCursor;
       
   181     	}
       
   182 
       
   183     iTextEditor = new (ELeave) CEikRichTextEditor( TGulBorder( TGulBorder::EShallowRaised ) );
       
   184     iTextEditor->ConstructL(    this, 
       
   185                                 0, 
       
   186                                 iMaxLen, 
       
   187                                 edwinFlags );    
       
   188 
       
   189     TRect mainPane = PostcardLaf::WholeMainPaneForDialogs();
       
   190     TInt height = mainPane.Height( );
       
   191     TInt diff = height%MsgEditorCommons::MsgBaseLineDelta();
       
   192     height -= diff; // decrease the height if it is not dividable by baselinedelta
       
   193     mainPane.iBr.iY = height;
       
   194 
       
   195     TMargins8 edwinMargins;
       
   196     edwinMargins.SetAllValuesTo(2);
       
   197     // This needs to be before SetRect() in order to take effect
       
   198     iTextEditor->SetBorderViewMargins( edwinMargins );
       
   199 
       
   200     // Set scrollbar size
       
   201     TInt sbWidth = PostcardLaf::ScrollBarWidth();
       
   202     TRect edwinPane = mainPane;
       
   203     if ( AknLayoutUtils::LayoutMirrored() )
       
   204         {
       
   205         edwinPane.iTl.iX += sbWidth;
       
   206         }
       
   207     else
       
   208         {
       
   209         edwinPane.iBr.iX -= sbWidth;
       
   210         }
       
   211     iTextEditor->SetRect( edwinPane );
       
   212 
       
   213     SetCharParaFormat();
       
   214 
       
   215     CAknAppUiBase* appUi = static_cast<CAknAppUiBase*>( iEikonEnv->EikAppUi() );
       
   216     if (AknLayoutUtils::DefaultScrollBarType(appUi) == CEikScrollBarFrame::EDoubleSpan)
       
   217         { // Create scrollbar only if double scrollbars supported
       
   218         iTextEditor->CreateScrollBarFrameL( );
       
   219         iTextEditor->ScrollBarFrame( )->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan);
       
   220         iTextEditor->ScrollBarFrame( )->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOn);
       
   221         }
       
   222 
       
   223     // Layout scrollbar correctly with text editor.
       
   224     AknLayoutUtils::LayoutVerticalScrollBar(
       
   225         iTextEditor->ScrollBarFrame(),
       
   226         mainPane,
       
   227         AknLayoutScalable_Apps::scroll_pane_cp06().LayoutLine() );
       
   228 
       
   229 
       
   230     iTextEditor->SetContainerWindowL( *this );
       
   231 
       
   232 	UpdateNavipaneL( ETrue );
       
   233     }
       
   234 
       
   235 // ----------------------------------------------------
       
   236 // CPostcardTextDialog::PostLayoutDynInitL
       
   237 // ----------------------------------------------------
       
   238 void CPostcardTextDialog::PostLayoutDynInitL()
       
   239     {
       
   240     TInt docLength = iOrigText.DocumentLength();
       
   241     if( docLength > 0 )
       
   242     	{
       
   243     	const TPtrC ptr = iOrigText.Read( 0, docLength );
       
   244     	iTextEditor->SetTextL( &ptr );
       
   245     	}
       
   246 
       
   247     // Set middle softkey button and menu resource to show on button press
       
   248     SetMiddleSoftkeyL();
       
   249    }
       
   250 
       
   251 // ---------------------------------------------------------
       
   252 // HandleEdwinEventL
       
   253 // ---------------------------------------------------------
       
   254 void CPostcardTextDialog::HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType)
       
   255 	{
       
   256 	if( aEdwin && aEventType == EEventTextUpdate )
       
   257 		{ // The functionality has been removed to HandleControlEventL
       
   258 		}
       
   259 	}
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // Draw
       
   263 // ---------------------------------------------------------
       
   264 void CPostcardTextDialog::Draw(const TRect& /*aRect*/ ) const
       
   265 	{
       
   266     CWindowGc& gc = SystemGc();
       
   267     TRect rect( PostcardLaf::WholeMainPaneForDialogs( ) );
       
   268 
       
   269     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   270     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   271     
       
   272     if( !AknsDrawUtils::Background( skin, cc, this, gc, rect ) )
       
   273 		{
       
   274 	    // clear entire header area.
       
   275 	    gc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
       
   276 		gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   277 		gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   278 		gc.DrawRect( rect );
       
   279 		}
       
   280     gc.SetPenColor( AKN_LAF_COLOR( 12 ) );
       
   281 	}
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // UpdateNavipaneL
       
   285 // ---------------------------------------------------------
       
   286 void CPostcardTextDialog::UpdateNavipaneL( TBool aForce )
       
   287 	{
       
   288 	if( !aForce )
       
   289 		{
       
   290 		return;
       
   291 		}
       
   292 
       
   293 	if( iDocument.MessageType( ) == EPostcardSent ) 
       
   294 	    {
       
   295 	    if( !iNaviDecorator )
       
   296 	        {
       
   297             CEikStatusPane *sp = iEikonEnv->AppUiFactory( )->StatusPane( );
       
   298 	        
       
   299 	        CAknNavigationControlContainer* container = 
       
   300                 static_cast<CAknNavigationControlContainer*>
       
   301                     ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   302 	        
       
   303             HBufC* buf = HBufC::NewLC(0);
       
   304             iNaviDecorator = container->CreateMessageLabelL( *buf );
       
   305             iNaviDecorator->MakeScrollButtonVisible( EFalse );
       
   306             
       
   307             container->PushL( *iNaviDecorator );
       
   308             CleanupStack::PopAndDestroy( buf ); // buf
       
   309 	        }
       
   310 	    return;
       
   311 	    }
       
   312 
       
   313     MAknEditingStateIndicator* editIndi = 
       
   314         static_cast< CAknEnv* >( iEikonEnv->Extension( ) )->EditingStateIndicator();
       
   315 	if( editIndi )
       
   316 		{
       
   317         CAknIndicatorContainer* indiContainer = editIndi->IndicatorContainer( );
       
   318         if ( indiContainer )
       
   319             {
       
   320 
       
   321 			TInt cur = iTextEditor->TextLength( );
       
   322 	        CArrayFixFlat<TInt>* array = new(ELeave) CArrayFixFlat<TInt>( 2 );
       
   323 	        CleanupStack::PushL( array );
       
   324 	        array->AppendL( cur );
       
   325 	        array->AppendL( iMaxLen );
       
   326 	        HBufC* paneString = 
       
   327 	            StringLoader::LoadL( R_POSTCARD_CHARACTER_COUNTER, *array, iCoeEnv );
       
   328 	        CleanupStack::PopAndDestroy( array ); //array
       
   329 	        CleanupStack::PushL( paneString );
       
   330 
       
   331             indiContainer->SetIndicatorState(
       
   332                 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ),  
       
   333                 EAknIndicatorStateOn );
       
   334             indiContainer->SetIndicatorValueL(
       
   335                 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ), 
       
   336                 *paneString );
       
   337                 
       
   338 	        CleanupStack::PopAndDestroy( paneString );   //paneString
       
   339             }
       
   340 		
       
   341 		}
       
   342 	}
       
   343 
       
   344 // ---------------------------------------------------------
       
   345 // SetCharParaFormat
       
   346 // ---------------------------------------------------------
       
   347 void CPostcardTextDialog::SetCharParaFormat()
       
   348     {
       
   349     // CParaFormat can be created on the stack if it is not
       
   350     // used to store tab stops, bullets or borders
       
   351     CParaFormat paraFormat;
       
   352     TParaFormatMask paraFormatMask;
       
   353 	TCharFormat charFormat;
       
   354 	TCharFormatMask charFormatMask;
       
   355 
       
   356 	PostcardLaf::ActiveFont( charFormat, charFormatMask, paraFormat, paraFormatMask );
       
   357 
       
   358     CParaFormatLayer* paraFormatLayer = NULL;
       
   359     CCharFormatLayer* charFormatLayer = NULL;
       
   360 
       
   361     TRAPD( error,
       
   362         {
       
   363         paraFormatLayer = CParaFormatLayer::NewL( &paraFormat, paraFormatMask );
       
   364         charFormatLayer = CCharFormatLayer::NewL( charFormat, charFormatMask );
       
   365         } );
       
   366 
       
   367 	if( error )
       
   368 		{
       
   369         delete paraFormatLayer;
       
   370         delete charFormatLayer;
       
   371         return;
       
   372 		}
       
   373 	// ownership moves
       
   374 	iTextEditor->SetParaFormatLayer( paraFormatLayer );
       
   375 	iTextEditor->SetCharFormatLayer( charFormatLayer );
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------
       
   379 // CPostcardTextDialog::ProcessCommandL( TInt aCommandId )
       
   380 // ---------------------------------------------------------
       
   381 void CPostcardTextDialog::ProcessCommandL( TInt aCommandId )
       
   382     {
       
   383     HideMenu( );
       
   384 
       
   385     switch ( aCommandId )
       
   386         {
       
   387         case EPostcardCmdSend:
       
   388             SendL( );
       
   389             break;
       
   390             
       
   391         case EPostcardCmdForward:
       
   392             ForwardMessageL( );
       
   393             break;
       
   394 
       
   395        	case EPostcardCmdMessageInfo:
       
   396 			MessageInfoL( );
       
   397         	break;
       
   398 
       
   399        	case EPostcardCmdInsertTemplate:
       
   400        		InsertFromL( EFalse );
       
   401         	break;
       
   402         	
       
   403        	case EPostcardCmdInsertNote:
       
   404 	       	InsertFromL( ETrue );
       
   405         	break;
       
   406         	
       
   407         case EMsgDispSizeAutomatic:
       
   408         case EMsgDispSizeLarge:
       
   409         case EMsgDispSizeNormal:        	
       
   410         case EMsgDispSizeSmall:
       
   411             iAppUi.HandleLocalZoomChangeL( (TMsgCommonCommands)aCommandId );
       
   412             break;  
       
   413         case EAknCmdHelp: 
       
   414             LaunchHelpL( );
       
   415             break;
       
   416 
       
   417         case EAknCmdExit:
       
   418         case EEikCmdExit:
       
   419             if( OkToExitL( aCommandId ) )
       
   420                 {
       
   421             	iRetValue = EPostcardDialogExit;	
       
   422                 TryExitL( EAknSoftkeyDone );
       
   423                 }
       
   424             break;
       
   425 
       
   426         default :
       
   427             CAknDialog::ProcessCommandL( aCommandId );
       
   428             break;
       
   429         }
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------
       
   433 // OfferKeyEventL
       
   434 // ---------------------------------------------------------
       
   435 TKeyResponse CPostcardTextDialog::OfferKeyEventL(
       
   436     const TKeyEvent& aKeyEvent,
       
   437     TEventCode aType )
       
   438     {
       
   439     // If a menu is showing offer key events to it.
       
   440     if ( CAknDialog::MenuShowing( ) )
       
   441         {
       
   442         return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   443         }
       
   444 
       
   445     TUint code = aKeyEvent.iCode;
       
   446 
       
   447     TKeyResponse resp = EKeyWasNotConsumed;
       
   448 
       
   449     switch ( code )
       
   450         {
       
   451         case EKeyOK:
       
   452             {
       
   453             if ( iDocument.MessageType() != EPostcardSent )
       
   454                 {
       
   455                 iMenuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
   456                 iMenuBar->TryDisplayContextMenuBarL();                
       
   457                 }
       
   458             resp = EKeyWasConsumed;
       
   459             break;
       
   460             }
       
   461 
       
   462         case EKeyBackspace:
       
   463         case EKeyDelete:
       
   464             {
       
   465             resp = iTextEditor->OfferKeyEventL( aKeyEvent, aType );
       
   466             // Has to call draw here. Otherwise a couple of characters are left
       
   467             // on the screen at the beginning of each line.
       
   468             iTextEditor->DrawDeferred();
       
   469             UpdateNavipaneL( ETrue );
       
   470             CheckTextExceedingL();
       
   471             break;
       
   472             }
       
   473         
       
   474         case EKeyYes:
       
   475             {
       
   476         	if( iDocument.MessageType( ) != EPostcardSent ) 
       
   477         	    { // This is draft message
       
   478         	    SendL();
       
   479        			resp = EKeyWasConsumed;   
       
   480    			    break;
       
   481         	    }
       
   482         	// If message is sent -> intentionally let it fall thru
       
   483             }
       
   484             //lint -fallthrough
       
   485         case EKeyApplication:
       
   486         case EKeyPhoneEnd:
       
   487         case EKeyPowerOff:
       
   488         case EKeyGripOpen:
       
   489         case EKeyGripClose:
       
   490         case EKeySide:
       
   491         case EKeyEscape:
       
   492             resp = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   493             break;
       
   494  
       
   495         default:
       
   496             {
       
   497             resp = iTextEditor->OfferKeyEventL( aKeyEvent, aType );
       
   498        		UpdateNavipaneL( ETrue );
       
   499     		CheckTextExceedingL();
       
   500             }
       
   501         }
       
   502     return resp;
       
   503     }
       
   504 
       
   505 // ---------------------------------------------------------
       
   506 // DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
       
   507 // ---------------------------------------------------------
       
   508 void CPostcardTextDialog::DynInitMenuPaneL(
       
   509     TInt aMenuId, 
       
   510     CEikMenuPane* aMenuPane)
       
   511     {
       
   512     switch ( aMenuId )
       
   513         {
       
   514         case R_POSTCARD_TEXT_OPTIONS:
       
   515             DynInitMainMenuL( aMenuPane );
       
   516             break;
       
   517 
       
   518         case R_POSTCARD_TEXT_CONTEXT_OPTIONS:
       
   519             DynInitContextMenuL( aMenuPane );
       
   520             break;
       
   521 
       
   522         case R_POSTCARD_ZOOM_SUBMENU:
       
   523             {
       
   524             TInt zoomLevel = KErrGeneral;
       
   525             iAppUi.GetZoomLevelL( zoomLevel );
       
   526             switch ( zoomLevel )
       
   527                 {
       
   528                 case EAknUiZoomAutomatic:
       
   529                     aMenuPane->SetItemButtonState( EMsgDispSizeAutomatic,
       
   530                                      EEikMenuItemSymbolOn );
       
   531                     break;
       
   532                 case EAknUiZoomNormal:
       
   533                     aMenuPane->SetItemButtonState( EMsgDispSizeNormal,
       
   534                                      EEikMenuItemSymbolOn );
       
   535                     break;
       
   536                 case EAknUiZoomSmall:
       
   537                     aMenuPane->SetItemButtonState( EMsgDispSizeSmall,
       
   538                                      EEikMenuItemSymbolOn );
       
   539                     break;
       
   540                 case EAknUiZoomLarge:
       
   541                     aMenuPane->SetItemButtonState( EMsgDispSizeLarge,
       
   542                                      EEikMenuItemSymbolOn );
       
   543                     break;
       
   544                 default:
       
   545                     break;
       
   546                 }
       
   547             }
       
   548             break;
       
   549         default:
       
   550             break;
       
   551         }
       
   552 
       
   553     }
       
   554 
       
   555 // ---------------------------------------------------------
       
   556 // DynInitMainMenuL
       
   557 // ---------------------------------------------------------
       
   558 void CPostcardTextDialog::DynInitMainMenuL( CEikMenuPane* aMenuPane )
       
   559     {
       
   560     aMenuPane->SetItemDimmed( EPostcardCmdSend, 
       
   561         IsMainMenuOptionInvisible( EPostcardCmdSend ));
       
   562     aMenuPane->SetItemDimmed( EPostcardCmdInsertSubmenu, 
       
   563         IsMainMenuOptionInvisible( EPostcardCmdInsertSubmenu ));
       
   564     aMenuPane->SetItemDimmed( EPostcardCmdForward, 
       
   565             IsMainMenuOptionInvisible( EPostcardCmdForward ));
       
   566     aMenuPane->SetItemDimmed( EPostcardCmdMessageInfo, 
       
   567         IsMainMenuOptionInvisible( EPostcardCmdMessageInfo ));
       
   568     aMenuPane->SetItemDimmed( EAknCmdHelp, iTextFlags & EPostcardTextHelpSupported?EFalse:ETrue ); 
       
   569     aMenuPane->SetItemDimmed( EAknCmdExit, EFalse ); 
       
   570     }
       
   571     
       
   572 // ---------------------------------------------------------
       
   573 // IsMainMenuOptionInvisible
       
   574 // ---------------------------------------------------------
       
   575 TBool CPostcardTextDialog::IsMainMenuOptionInvisible( TInt aMenuOptionId )
       
   576     {
       
   577     TBool retVal = ETrue;
       
   578     TPostcardMsgType msgType = iDocument.MessageType( );
       
   579 
       
   580     switch ( aMenuOptionId )
       
   581         {
       
   582 
       
   583         case EPostcardCmdSend:
       
   584        		if( msgType != EPostcardSent ) 
       
   585        			{
       
   586        			if( iAppUi.ContactHasData( ) )
       
   587        			    {
       
   588     	            retVal = EFalse;
       
   589        			    }
       
   590        			}
       
   591             break;
       
   592         case EPostcardCmdInsertSubmenu:
       
   593        		if( msgType != EPostcardSent ) 
       
   594        			{
       
   595  				if( iTextEditor->TextLength( ) < iMaxLen )
       
   596  					{
       
   597 		            retVal = EFalse;					
       
   598  					}
       
   599        			}
       
   600    			break;
       
   601         case EPostcardCmdForward:
       
   602             if( msgType == EPostcardSent ) 
       
   603                 {
       
   604                 retVal = EFalse;                
       
   605                 }
       
   606             break;
       
   607        	case EPostcardCmdMessageInfo:
       
   608        	    {
       
   609 			retVal = EFalse;
       
   610         	break;        	
       
   611        	    }
       
   612         case EAknCmdHelp: 
       
   613         	if( iTextFlags & EPostcardTextHelpSupported )
       
   614         		{
       
   615 	        	retVal = EFalse;
       
   616         		}
       
   617             break;
       
   618 
       
   619         case EAknCmdExit:
       
   620         	retVal = EFalse;
       
   621             break;        	
       
   622         default:
       
   623             ;
       
   624         }
       
   625 
       
   626     return retVal;
       
   627     }
       
   628 
       
   629 
       
   630 // ---------------------------------------------------------
       
   631 // DynInitInsertSubMenuL
       
   632 // ---------------------------------------------------------
       
   633 void CPostcardTextDialog::DynInitInsertSubMenuL( CEikMenuPane* aMenuPane )
       
   634     { // These are always shown when the submenu is shown
       
   635     aMenuPane->SetItemDimmed( EPostcardCmdInsertTemplate, EFalse );
       
   636     aMenuPane->SetItemDimmed( EPostcardCmdInsertNote, EFalse );
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------
       
   640 // DynInitContextMenuL
       
   641 // ---------------------------------------------------------
       
   642 void CPostcardTextDialog::DynInitContextMenuL( CEikMenuPane* aMenuPane )
       
   643     { // This is always shown when context menu is supported
       
   644     TPostcardMsgType msgType = iDocument.MessageType( );
       
   645 	if( msgType != EPostcardSent ) 
       
   646 		{
       
   647 	    aMenuPane->SetItemDimmed( EPostcardCmdInsertSubmenu, 
       
   648 	    			iTextEditor->TextLength() < iMaxLen ? EFalse : ETrue );
       
   649         aMenuPane->SetItemDimmed( EPostcardCmdForward, ETrue );
       
   650 	    aMenuPane->SetItemDimmed( EPostcardCmdMessageInfo, ETrue );
       
   651 		}
       
   652 	else
       
   653 		{
       
   654 	    aMenuPane->SetItemDimmed( EPostcardCmdInsertSubmenu, ETrue );
       
   655         aMenuPane->SetItemDimmed( EPostcardCmdForward, EFalse );
       
   656 	    aMenuPane->SetItemDimmed( EPostcardCmdMessageInfo, EFalse );
       
   657 		}
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------
       
   661 // CountComponentControls
       
   662 // ---------------------------------------------------------
       
   663 TInt CPostcardTextDialog::CountComponentControls( ) const
       
   664     {
       
   665     TInt count = 0;
       
   666     
       
   667     if ( iTextEditor )
       
   668         {
       
   669         count++;
       
   670         }
       
   671 
       
   672     return count;
       
   673     }
       
   674 
       
   675 // ---------------------------------------------------------
       
   676 // ComponentControl(TInt aIndex) const
       
   677 // ---------------------------------------------------------
       
   678 CCoeControl* CPostcardTextDialog::ComponentControl( TInt /*aIndex*/ ) const
       
   679     {
       
   680     CCoeControl* control = NULL;
       
   681     
       
   682     if ( iTextEditor )
       
   683         {
       
   684         control = iTextEditor;
       
   685         }
       
   686         
       
   687     return control;
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------
       
   691 // OkToExitL(TInt aButtonId)
       
   692 // called by framework when softkey button is pressed
       
   693 // ---------------------------------------------------------
       
   694 TBool CPostcardTextDialog::OkToExitL( TInt aButtonId )
       
   695     {
       
   696     if( aButtonId == EAknCmdExit )
       
   697         {
       
   698         return ETrue;
       
   699         }
       
   700     if( aButtonId == EAknSoftkeyContextOptions )
       
   701         {
       
   702         // Middle softkey was pressed. Display context menu.
       
   703         // MSK is not active in viewer mode.
       
   704         iMenuBar->TryDisplayContextMenuBarL();
       
   705         return EFalse;
       
   706         }
       
   707     TBool okToExit = CAknDialog::OkToExitL( aButtonId );
       
   708     if( !okToExit )
       
   709     	{
       
   710     	return okToExit;
       
   711     	}
       
   712     if( aButtonId == EAknSoftkeyBack ||
       
   713     	aButtonId == EAknSoftkeyExit || 
       
   714     	aButtonId == EAknSoftkeyDone ||
       
   715     	aButtonId == EAknCmdExit ||
       
   716     	aButtonId == EEikCmdExit ||
       
   717     	aButtonId == EAknSoftkeyCancel ||
       
   718     	aButtonId == EPostcardCmdSend )
       
   719     	{
       
   720     	if( iDocument.MessageType( ) != EPostcardSent )
       
   721     		{
       
   722 		    CPlainText* text = CPlainText::NewL( CEditableText::ESegmentedStorage, KPostcardDefaultGreetingSegment );
       
   723 	    	CleanupStack::PushL( text );
       
   724 	    	
       
   725 			if( iTextEditor->TextLength() )
       
   726 				{
       
   727 		    	text->InsertL( 0, iTextEditor->GlobalText( )->Read( 0, iTextEditor->TextLength( ) ) );
       
   728 				}
       
   729 	    	iAppUi.SetTextL( *text );
       
   730 	        // Greeting changed, so we can change field to modified.
       
   731             iDocument.SetChanged( EPostcardText );
       
   732 	    	CleanupStack::Pop( text ); //ownership moves to AppUi
       
   733     		}
       
   734     	return okToExit;
       
   735     	}
       
   736     return EFalse;
       
   737     }
       
   738 
       
   739 // ---------------------------------------------------------
       
   740 // ActivateL()
       
   741 // ---------------------------------------------------------
       
   742 void CPostcardTextDialog::ActivateL( )
       
   743     {
       
   744     SetFocus( ETrue );
       
   745     iTextEditor->SetFocus( ETrue );
       
   746     if( iDocument.MessageType() == EPostcardSent )
       
   747     	{
       
   748 	    iTextEditor->TextView()->SetCursorVisibilityL( 
       
   749 	    		TCursor::EFCursorInvisible, TCursor::EFCursorInvisible );
       
   750          // Prevent text exceeding confirmation query in viewer mode
       
   751         iTextFlags |= EPostcardTextExceeded;
       
   752     	}
       
   753 	else
       
   754 		{
       
   755 	    iTextEditor->TextView()->SetCursorVisibilityL( 
       
   756 	    		TCursor::EFCursorFlashing, TCursor::EFCursorFlashing );
       
   757     	}
       
   758     iTextEditor->SetObserver( this ); // MCoeControlObserver
       
   759     CCoeControl::ActivateL();
       
   760     // Swap the custom drawer to our own to show text lines. 
       
   761     // Lines are shown only in editor mode.
       
   762     // Custom drawer must be set after call to CCoeControl::ActivateL.
       
   763     if ( iDocument.MessageType() != EPostcardSent )
       
   764         {
       
   765         if ( !iCustomDraw )
       
   766             {
       
   767             const MFormCustomDraw* customDraw = iTextEditor->TextLayout()->CustomDraw();
       
   768 
       
   769             iCustomDraw = CPostcardTextDialogCustomDraw::NewL( customDraw, this );
       
   770         
       
   771             iTextEditor->TextLayout()->SetCustomDraw( iCustomDraw );
       
   772             }
       
   773         }
       
   774     // Set cursor to the end only if it is not sent.
       
   775     if( iDocument.MessageType() != EPostcardSent &&
       
   776         iTextEditor->TextLength() > 0 )
       
   777     	{
       
   778 	 	iTextEditor->SetCursorPosL( iTextEditor->TextLength(), EFalse );		
       
   779     	}
       
   780     UpdateNavipaneL( ETrue );
       
   781 	if( iKeyEvent.iCode != 0 )
       
   782 		{
       
   783 		TEventCode type = EEventKey;
       
   784         iCoeEnv->SyncNotifyFocusObserversOfChangeInFocus();
       
   785         iCoeEnv->SimulateKeyEventL( iKeyEvent, type );						
       
   786 		}
       
   787     CheckTextExceedingL();
       
   788     }
       
   789 
       
   790 // ---------------------------------------------------------
       
   791 // Panic
       
   792 // ---------------------------------------------------------
       
   793 void CPostcardTextDialog::Panic( TInt aReason )
       
   794     {
       
   795     User::Panic( _L("CPostcardTextDialog"), aReason);
       
   796     }
       
   797 
       
   798 // ---------------------------------------------------------
       
   799 // HandleResourceChange
       
   800 // ---------------------------------------------------------
       
   801 void CPostcardTextDialog::HandleResourceChange(TInt aType )
       
   802     {
       
   803     CAknDialog::HandleResourceChange( aType );
       
   804 
       
   805 	if(aType == KEikDynamicLayoutVariantSwitch )
       
   806         {
       
   807 		if( iTextEditor )
       
   808 			{
       
   809             TRect mainPane = PostcardLaf::WholeMainPaneForDialogs();
       
   810             TInt height = mainPane.Height( );
       
   811             TInt diff = height%MsgEditorCommons::MsgBaseLineDelta();
       
   812             height -= diff; // decrease the height if it is not dividable by baselinedelta
       
   813             mainPane.iBr.iY = height;
       
   814 
       
   815             // Set scrollbar size
       
   816             TInt sbWidth = PostcardLaf::ScrollBarWidth();
       
   817             TRect edwinPane = mainPane;
       
   818             if ( AknLayoutUtils::LayoutMirrored() )
       
   819                 {
       
   820                 edwinPane.iTl.iX += sbWidth;
       
   821                 }
       
   822             else
       
   823                 {
       
   824                 edwinPane.iBr.iX -= sbWidth;
       
   825                 }
       
   826             iTextEditor->SetRect( edwinPane );
       
   827 
       
   828             // Layout scrollbar correctly with text editor.
       
   829             AknLayoutUtils::LayoutVerticalScrollBar(
       
   830                 iTextEditor->ScrollBarFrame(),
       
   831                 mainPane,
       
   832                 AknLayoutScalable_Apps::scroll_pane_cp06().LayoutLine() );
       
   833 
       
   834             SetCharParaFormat();
       
   835 
       
   836             TRAP_IGNORE( iTextEditor->NotifyNewFormatL() );
       
   837 			}
       
   838 	    // Line rects needs also refreshing.
       
   839 	    if ( iCustomDraw )
       
   840 	        {
       
   841 	        iCustomDraw->ResolveLayouts();
       
   842 	        }
       
   843         }
       
   844 	else if( aType == KAknsMessageSkinChange )
       
   845 		{
       
   846 		if( iTextEditor )
       
   847 			{
       
   848             SetCharParaFormat( );
       
   849 			}
       
   850 		}
       
   851     }
       
   852 
       
   853 // ---------------------------------------------------------
       
   854 // FocusChanged
       
   855 // ---------------------------------------------------------
       
   856 void CPostcardTextDialog::FocusChanged( TDrawNow aDrawNow )
       
   857     {
       
   858     if ( iTextEditor )
       
   859         {
       
   860         iTextEditor->SetFocus( IsFocused(), aDrawNow );
       
   861         }
       
   862     }
       
   863  
       
   864 // ---------------------------------------------------------
       
   865 // SendL
       
   866 // ---------------------------------------------------------
       
   867 void CPostcardTextDialog::SendL( )
       
   868 	{
       
   869 	iRetValue = EPostcardDialogSend;	
       
   870     TryExitL( EPostcardCmdSend );		
       
   871 	}
       
   872 
       
   873 // ---------------------------------------------------------
       
   874 // ForwardMessageL
       
   875 // ---------------------------------------------------------
       
   876 void CPostcardTextDialog::ForwardMessageL( )
       
   877     {
       
   878     iRetValue = EPostcardDialogForward;    
       
   879     TryExitL( EAknSoftkeyDone );        
       
   880     }
       
   881 
       
   882 // ---------------------------------------------------------
       
   883 // MessageInfoL
       
   884 // ---------------------------------------------------------
       
   885 void CPostcardTextDialog::MessageInfoL( )
       
   886 	{
       
   887     TPostcardMsgType msgType = iDocument.MessageType( );
       
   888 	if( msgType != EPostcardSent ) 
       
   889         { // We are dealing with unsent message -> save recipient details for now
       
   890         TMmsMsvEntry tEntry = static_cast<TMmsMsvEntry>( iDocument.Entry() );
       
   891         tEntry.iDate.UniversalTime();
       
   892         tEntry.iDescription.Set( iTextEditor->Text( )->Read( 0, iTextEditor->TextLength( ) ) );
       
   893     	tEntry.iBioType = KUidMsgSubTypeMmsPostcard.iUid;
       
   894         iDocument.CurrentEntry().ChangeL( tEntry );
       
   895         }		
       
   896 	iAppUi.DoShowMessageInfoL( );
       
   897 	}
       
   898 
       
   899 // ---------------------------------------------------------
       
   900 // InsertFromL
       
   901 // ---------------------------------------------------------
       
   902 void CPostcardTextDialog::InsertFromL( TBool aNote )
       
   903     {
       
   904     
       
   905     TInt resId = NULL;
       
   906     
       
   907     if( aNote )
       
   908         {
       
   909         resId = R_QTN_NMAKE_FETCH_MEMO_PRMPT;
       
   910         }
       
   911     else
       
   912         {
       
   913         resId = R_QTN_MAIL_POPUP_TEXT_SEL_TEMP;        
       
   914         }
       
   915     
       
   916     HBufC* title = iAppUi.ReadFromResourceLC( resId );
       
   917     HBufC* buf = NULL;
       
   918         
       
   919     if( aNote )
       
   920         { // Read it from Notepad memos
       
   921         buf = CNotepadApi::FetchMemoL( title );
       
   922         if( !buf )
       
   923             { // Cancel or empty
       
   924             CleanupStack::PopAndDestroy( title ); // title
       
   925             return;
       
   926             }
       
   927         CleanupStack::PushL( buf );
       
   928         }
       
   929     else
       
   930         { // Read it from Notepad templates
       
   931         buf = CNotepadApi::FetchTemplateL( title );
       
   932         if( !buf )
       
   933             { // Cancel or empty
       
   934             CleanupStack::PopAndDestroy( title ); // title
       
   935             return;
       
   936             }
       
   937         CleanupStack::PushL( buf );
       
   938         }
       
   939     
       
   940     TCursorSelection selection = iTextEditor->TextView( )->Selection( );
       
   941     const TInt selLength = selection.Length( );
       
   942 
       
   943     if ( selLength )
       
   944         {
       
   945         iTextEditor->ClearSelectionL( );
       
   946         iTextEditor->RichText( )->DeleteL( selection.LowerPos( ), selLength );
       
   947         TCursorSelection sel( selection.LowerPos( ), selection.LowerPos( ) );
       
   948         iTextEditor->TextView( )->HandleInsertDeleteL( sel, selLength );        
       
   949         }
       
   950     iTextEditor->RichText( )->InsertL( selection.LowerPos( ), *buf );
       
   951     if ( buf->Length() > 1 )
       
   952         {
       
   953         TCursorSelection sel( selection.LowerPos( ) + buf->Length( ), selection.LowerPos( ) );
       
   954         iTextEditor->TextView( )->HandleInsertDeleteL( sel, 0 );
       
   955         }
       
   956     else
       
   957         {
       
   958         iTextEditor->TextView( )->HandleCharEditL( CTextLayout::EFCharacterInsert );
       
   959         }
       
   960     TInt newPos=selection.iCursorPos + buf->Length( );
       
   961     iTextEditor->SetCursorPosL( newPos,EFalse );
       
   962 
       
   963     CleanupStack::PopAndDestroy( 2, title ); // title, buf
       
   964     UpdateNavipaneL( ETrue );
       
   965     CheckTextExceedingL( );
       
   966     
       
   967     }
       
   968 
       
   969 // ---------------------------------------------------------
       
   970 // LaunchHelpL
       
   971 // ---------------------------------------------------------
       
   972 void CPostcardTextDialog::LaunchHelpL( )
       
   973 	{
       
   974 	if( iDocument.MessageType( ) == EPostcardSent ) 
       
   975 	    {
       
   976         iAppUi.LaunchHelpL( KPOSTCARD_HLP_GREETING_VIEW() );
       
   977 	    }
       
   978     else
       
   979         {
       
   980         iAppUi.LaunchHelpL( KPOSTCARD_HLP_GREETING_EDIT() );    
       
   981         }	
       
   982 	}
       
   983 
       
   984 // ---------------------------------------------------------
       
   985 // CheckTextExceedingL
       
   986 // ---------------------------------------------------------
       
   987 void CPostcardTextDialog::CheckTextExceedingL( )
       
   988 	{
       
   989 	if( iTextEditor->TextLength( ) >= iMaxLen )
       
   990 		{
       
   991 		TInt howMany = iTextEditor->TextLength( ) - iMaxLen;
       
   992 		switch( howMany )
       
   993 			{
       
   994 			case 0:
       
   995 				{
       
   996                 // No note shown anymore.
       
   997 				break;
       
   998 				}
       
   999 			case 1:
       
  1000 				{
       
  1001 				if( !(iTextFlags & EPostcardTextExceeded ) ) 
       
  1002 					{
       
  1003     				iAppUi.ShowConfirmationQueryL( R_POSTCARD_GREETING_EXCEEDED, ETrue );
       
  1004 					}
       
  1005 				break;					
       
  1006 				}
       
  1007 			default:
       
  1008 				{
       
  1009 				if( !(iTextFlags & EPostcardTextExceeded ) ) 
       
  1010 					{
       
  1011     		        HBufC* warningString = 
       
  1012     		            StringLoader::LoadLC( R_POSTCARD_GREETING_EXCEEDED_MANY, howMany, iCoeEnv );
       
  1013     				iAppUi.ShowConfirmationQueryL( *warningString, ETrue );
       
  1014     		        CleanupStack::PopAndDestroy( warningString );
       
  1015 					}
       
  1016 				break;					
       
  1017 				}
       
  1018 			}
       
  1019 		iTextFlags |= EPostcardTextExceeded;			
       
  1020 		}
       
  1021 	else
       
  1022 	    {
       
  1023 	    iTextFlags &= ~EPostcardTextExceeded;
       
  1024 	    }
       
  1025 	SetMiddleSoftkeyL();
       
  1026 	}
       
  1027 
       
  1028 // ---------------------------------------------------------
       
  1029 // HandleControlEventL
       
  1030 // ---------------------------------------------------------
       
  1031 void CPostcardTextDialog::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType)
       
  1032     {
       
  1033     if( aEventType == EEventStateChanged )
       
  1034         {
       
  1035 		UpdateNavipaneL( ETrue );
       
  1036 		//  The length check is done in OfferKeyEventL
       
  1037         }
       
  1038     }
       
  1039     
       
  1040 
       
  1041 // ---------------------------------------------------------
       
  1042 // SetMiddleSoftkeyL
       
  1043 // ---------------------------------------------------------
       
  1044 void CPostcardTextDialog::SetMiddleSoftkeyL()
       
  1045     {
       
  1046     TInt resourceId;
       
  1047     
       
  1048     if( iDocument.MessageType() != EPostcardSent && 
       
  1049         iTextEditor->TextLength() < iMaxLen )
       
  1050         {
       
  1051         resourceId = R_POSTCARD_MSK_BUTTON_OPTIONS;
       
  1052         }
       
  1053     else
       
  1054         {
       
  1055         resourceId = R_POSTCARD_MSK_BUTTON_EMPTY;
       
  1056         }
       
  1057         
       
  1058     if ( resourceId != iMskResource )
       
  1059         {
       
  1060         const TInt KMskPosition = 3;
       
  1061         CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  1062         cba.SetCommandL( KMskPosition, resourceId );
       
  1063         cba.DrawDeferred();
       
  1064         iMskResource = resourceId;
       
  1065         }
       
  1066     }
       
  1067 
       
  1068 // End of File
       
  1069