uifw/AvKon/src/AknTextSettingPage.cpp
changeset 0 2f259fa3e83a
child 6 9f56a4e1b8ab
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *   This class handles setting_text_pane and setting_code_pane (the latter in 
       
    16 *	the case of integers.  There is a common base class to soak up some common 
       
    17 *	textual functionality.
       
    18 *
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 #include "akntextsettingpage.h"
       
    24 #include "aknsettingpage.h"
       
    25 
       
    26 #include "akntextcontrol.h"
       
    27 #include <AknsDrawUtils.h>
       
    28 
       
    29 #include <AknLayout2ScalableDef.h>
       
    30 #include <aknlayoutscalable_avkon.cdl.h>
       
    31 
       
    32 #include <AknsControlContext.h>
       
    33 #include <AknsFrameBackgroundControlContext.h>
       
    34 #include <eikedwob.h>
       
    35 
       
    36 #include <AknTasHook.h>
       
    37 
       
    38 class CAknTextSettingPageExtension : public CBase
       
    39 								   , public MEikEdwinObserver
       
    40     {
       
    41 public:
       
    42     static CAknTextSettingPageExtension* NewL(CAknTextSettingPage* aExtensionOwner )
       
    43         {
       
    44         CAknTextSettingPageExtension* extension = new (ELeave) CAknTextSettingPageExtension( aExtensionOwner );
       
    45         CleanupStack::PushL(extension);
       
    46         extension->ConstructL();
       
    47         CleanupStack::Pop(extension);
       
    48         return extension;
       
    49         }
       
    50         
       
    51     ~CAknTextSettingPageExtension()
       
    52         {
       
    53         iExtensionOwner = 0;
       
    54         }
       
    55         
       
    56     TInt PreviousCba()
       
    57         {
       
    58         return iPreviousCba;
       
    59         };
       
    60     void SetPreviousCba(TInt aCbaId)
       
    61         {
       
    62         iPreviousCba = aCbaId;
       
    63         }
       
    64 	TBool PopupState()
       
    65 	 	{
       
    66 		return iPopupState;
       
    67 		}
       
    68 
       
    69 	virtual void HandleEdwinEventL( CEikEdwin* /*aEdwin*/, TEdwinEvent aEventType )
       
    70 		{
       
    71 		if( iExtensionOwner && MEikEdwinObserver::EEventChinesePopupClose == aEventType )
       
    72 			{
       
    73 			iPopupState = EFalse;
       
    74 			iExtensionOwner->ProcessPopupStateChangesL();
       
    75 			}
       
    76 	     else if(iExtensionOwner && MEikEdwinObserver::EEventChinesePopupOpen == aEventType)
       
    77 	     	{
       
    78 	     	iPopupState = ETrue;
       
    79 	     	}			
       
    80 		}
       
    81     
       
    82 private:
       
    83     void ConstructL()
       
    84         {
       
    85         }
       
    86         
       
    87     CAknTextSettingPageExtension(CAknTextSettingPage*  aExtensionOwner )
       
    88         : iPreviousCba( 0 ), iExtensionOwner( aExtensionOwner )
       
    89         , iPopupState( EFalse )
       
    90         {
       
    91         }
       
    92         
       
    93 private:
       
    94     TInt iPreviousCba;
       
    95     CAknTextSettingPage* iExtensionOwner;
       
    96     TBool iPopupState;  // when open the popup set popup state flag  to 1
       
    97     };
       
    98 
       
    99 /**
       
   100  * Exported in case others want to derive from this class
       
   101  *
       
   102  */
       
   103 EXPORT_C CAknEdwinSettingPage::CAknEdwinSettingPage( TInt aResourceId ) 
       
   104 	: CAknSettingPage(aResourceId)
       
   105 	{
       
   106 	AKNTASHOOK_ADD( this, "CAknEdwinSettingPage" );
       
   107 	}
       
   108 
       
   109 
       
   110 EXPORT_C CAknEdwinSettingPage::CAknEdwinSettingPage(	
       
   111 								const TDesC* aSettingText, 
       
   112 								TInt aSettingNumber, 
       
   113 								TInt aControlType,
       
   114 								TInt aEditorResourceId, 
       
   115 								TInt aSettingPageResourceId ) 
       
   116 								:	CAknSettingPage( 
       
   117 									aSettingText, 
       
   118 									aSettingNumber, 
       
   119 									aControlType, 
       
   120 									aEditorResourceId, 
       
   121 									aSettingPageResourceId )
       
   122 	{
       
   123 	AKNTASHOOK_ADD( this, "CAknEdwinSettingPage" );
       
   124 	}
       
   125 
       
   126 /**
       
   127  * All setting pages containing edwins will have the same draw code
       
   128  *
       
   129  */
       
   130 EXPORT_C void CAknEdwinSettingPage::Draw(const TRect& aRect) const
       
   131 	{
       
   132 	BaseDraw( aRect );
       
   133 	}
       
   134 
       
   135 /** 
       
   136  *
       
   137  * Type-specific access to the text editor control
       
   138  *
       
   139  */
       
   140 EXPORT_C CEikEdwin* CAknEdwinSettingPage::TextControl()
       
   141 	{
       
   142 	return STATIC_CAST( CEikEdwin*, EditorControl());
       
   143 	}
       
   144 	
       
   145 EXPORT_C void CAknEdwinSettingPage::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   146     { 
       
   147     CAknSettingPage::HandlePointerEventL(aPointerEvent); 
       
   148     }	
       
   149 
       
   150 EXPORT_C void* CAknEdwinSettingPage::ExtensionInterface( TUid /*aInterface*/ ) 
       
   151     { 
       
   152     return NULL;
       
   153     }
       
   154 
       
   155 /**
       
   156 * CAknEdwinSettingPage reserved methods
       
   157 */
       
   158 EXPORT_C void CAknEdwinSettingPage::CAknEdwinSettingPage_Reserved_1()
       
   159 	{
       
   160 	}
       
   161 
       
   162 
       
   163 
       
   164 ///////////////////////////////////////////////////////////////////////
       
   165 //
       
   166 // CAknTextSettingPage
       
   167 //
       
   168 ///////////////////////////////////////////////////////////////////////
       
   169 
       
   170 /**
       
   171  *
       
   172  * Constructor from setting page resource id + referenced text + flags
       
   173  *
       
   174  */
       
   175 EXPORT_C CAknTextSettingPage::CAknTextSettingPage( TInt aResourceId, TDes& aText, TInt aFlags ):
       
   176 	 CAknEdwinSettingPage(aResourceId),iText(aText), iTextSettingPageFlags( aFlags )
       
   177 	{
       
   178 	AKNTASHOOK_ADD( this, "CAknTextSettingPage" );
       
   179 	}
       
   180 
       
   181 EXPORT_C CAknTextSettingPage::CAknTextSettingPage(	
       
   182 								const TDesC* aSettingText, 
       
   183 								TInt aSettingNumber, 
       
   184 								TInt aControlType,
       
   185 								TInt aEditorResourceId, 
       
   186 								TInt aSettingPageResourceId, 
       
   187 								TDes& aText, 
       
   188 								TInt aTextSettingPageFlags)
       
   189 								:	CAknEdwinSettingPage( 
       
   190 									aSettingText, 
       
   191 									aSettingNumber, 
       
   192 									aControlType, 
       
   193 									aEditorResourceId, 
       
   194 									aSettingPageResourceId ), 
       
   195 									iText( aText ),  
       
   196 									iTextSettingPageFlags( aTextSettingPageFlags )
       
   197 	{
       
   198 	AKNTASHOOK_ADD( this, "CAknTextSettingPage" );
       
   199 	}
       
   200 
       
   201 /**
       
   202  * Destructor
       
   203  *
       
   204  */
       
   205 EXPORT_C CAknTextSettingPage::~CAknTextSettingPage()
       
   206 	{
       
   207 	if( TextControl( ) )
       
   208 		{	
       
   209 	    TextControl( )->RemoveEdwinObserver( iExtension );
       
   210 		}
       
   211 	AKNTASHOOK_REMOVE();
       
   212 	delete iBackupText;
       
   213 	
       
   214     delete iExtension;
       
   215 	}
       
   216 
       
   217 
       
   218 /** 
       
   219  *
       
   220  * The 2nd stage construction. Stored internal resource is used to perform the
       
   221  * construction.
       
   222  *
       
   223  */
       
   224 EXPORT_C void CAknTextSettingPage::ConstructL()
       
   225 	{
       
   226 	BaseConstructL();
       
   227 	iBackupText = iText.AllocL();
       
   228 	CEikEdwin* editor = TextControl();
       
   229 
       
   230 	// Inhibit predictive text entry unless allowed by API
       
   231 	if ( !(iTextSettingPageFlags & EPredictiveTextEntryPermitted) )
       
   232 		editor->SetAknEditorFlags( EAknEditorFlagNoT9 | editor->AknEdwinFlags() );
       
   233 	
       
   234 	if(!IsEditable())
       
   235 	    {
       
   236 	    editor->SetReadOnly(ETrue);
       
   237 	    editor->SetAknEditorFlags( CEikEdwin::EDisplayOnly | editor->AknEdwinFlags() );
       
   238 	    }
       
   239 
       
   240 	// Determine the maximum size of the text.
       
   241 
       
   242 	// First get the maximum extent that may have been set by resource
       
   243 	TInt maxLen = editor->MaxLength();
       
   244 	
       
   245 	// Get maximum length from the iText
       
   246 	TInt desMaxLen = iText.MaxLength();
       
   247 
       
   248 	// Use the minimum value of the two
       
   249 	if ( maxLen == 0 ) // Not set in resource
       
   250 		{
       
   251 		editor->SetMaxLength( desMaxLen );
       
   252 		}
       
   253 	else
       
   254 		{
       
   255 		editor->SetMaxLength( Min( maxLen, desMaxLen ) );
       
   256 		}
       
   257 
       
   258 	// Note that this will set the text to be the length in the passed descriptor, despite the maxlength 
       
   259 	// set above; subsequent editing will ensure that the editor can only decrease in size.
       
   260 	editor->SetTextL( &iText );
       
   261 	
       
   262 	iExtension = CAknTextSettingPageExtension::NewL(this);
       
   263 
       
   264 	editor->AddEdwinObserverL( iExtension );
       
   265 	// Initialize the validity and CBAs
       
   266 	CheckAndSetDataValidity();
       
   267 	UpdateCbaL();
       
   268 
       
   269 	// Construct an appropriate control context for the contained editor areas.
       
   270 	// Context produced is owned by CAknSettingPage. 
       
   271     SetEditedItemFrameIID( KAknsIIDQsnFrInput, KAknsIIDQsnFrInputCenter );
       
   272 	TextControl()->ScrollBarFrame()->VerticalScrollBar()->SetMopParent(this);
       
   273 	}
       
   274 
       
   275 /**
       
   276  * Acts upon changes in the hosted control's state. 
       
   277  *
       
   278  * @param	aControl	The control changing its state (not used)
       
   279  * @param	aEventType	The type of control event 
       
   280  */
       
   281 EXPORT_C void CAknTextSettingPage::HandleControlEventL(CCoeControl* /*aControl*/,
       
   282 				 MCoeControlObserver::TCoeEvent aEventType)
       
   283 	{
       
   284 	// This event is used as it is called at least every time an edit is made to 
       
   285 	// the edwin.
       
   286 	if ( aEventType == EEventStateChanged )
       
   287 		{
       
   288 		if ( iUpdateMode == EUpdateWhenChanged)
       
   289 			UpdateSettingL();
       
   290 
       
   291 		// This updates the CBA depending on text length
       
   292 		CheckAndSetDataValidity();
       
   293 		UpdateCbaL();
       
   294 		}
       
   295 	}
       
   296 
       
   297 /**
       
   298  *
       
   299  * This routine is called before the editor when the editor is first displayed.  This routine
       
   300  * puts in altered softkey bindings if there is zero-length text.
       
   301  *
       
   302  */
       
   303 EXPORT_C void CAknTextSettingPage::DynamicInitL()
       
   304 	{
       
   305 	UpdateCbaL();
       
   306 	}
       
   307 /**
       
   308  *
       
   309  * This routine is called when the a change is detected in the editor.
       
   310  * The text is copied out to the referenced descriptor using a utility routine.
       
   311  *
       
   312  */
       
   313 EXPORT_C void CAknTextSettingPage::UpdateSettingL()
       
   314 	{
       
   315 	UpdateTextL();
       
   316 
       
   317 	if( iSettingPageObserver )
       
   318 		iSettingPageObserver->HandleSettingPageEventL(this, MAknSettingPageObserver::EEventSettingChanged);	
       
   319 	}
       
   320 /**
       
   321  * Soak up function to do the safe copying of the editor to the referenced value
       
   322  *
       
   323  */
       
   324 EXPORT_C void CAknTextSettingPage::UpdateTextL()
       
   325 	{
       
   326 	CEikEdwin* edwin = TextControl();
       
   327 	edwin->CheckValidityOfChars(0, edwin->TextLength());
       
   328 
       
   329 	HBufC* heapText = edwin->GetTextInHBufL();
       
   330 	// GetTextInHBufL returns a null pointer if the text length is zero!
       
   331 	if ( heapText )
       
   332 		{
       
   333 		iText.Copy(heapText->Left( iText.MaxLength() ) );
       
   334 		delete heapText;
       
   335 		}
       
   336 	else
       
   337 		{
       
   338 		iText.SetLength( 0 );
       
   339 		}
       
   340 	}
       
   341 /**
       
   342  *
       
   343  * The value is copied out and the call back called if there is an observer
       
   344  *
       
   345  */
       
   346 EXPORT_C void CAknTextSettingPage::AcceptSettingL()
       
   347 	{
       
   348 	UpdateTextL();
       
   349 	}
       
   350 
       
   351 /** 
       
   352  * 
       
   353  * If the setting page is cancelled, this is called to restore the backed up copy of the 
       
   354  * input text
       
   355  *
       
   356  */
       
   357 EXPORT_C void CAknTextSettingPage::RestoreOriginalSettingL()
       
   358 	{
       
   359 	iText.Copy( *iBackupText );
       
   360 	}
       
   361 
       
   362 void CAknTextSettingPage::ProcessPopupStateChangesL()
       
   363 	{
       
   364 	UpdateCbaL();
       
   365 	}
       
   366 EXPORT_C void CAknTextSettingPage::UpdateCbaL()
       
   367 	{
       
   368 	if ( IsStopActiveSchudlerCalled() )
       
   369 	    {
       
   370 	    CAknSettingPage::UpdateCbaL();
       
   371 	    return;
       
   372 	    }
       
   373 
       
   374 	// Modify the CBA labels if the text goes to zero length or becomes non-zero
       
   375     TInt cbaId = 0;    
       
   376 	if ( !DataValidity() || !IsEditable() )
       
   377 	    {
       
   378 	    cbaId = InvalidDataCbaResourceId();	    
       
   379 	    }		
       
   380 	else
       
   381 	    {
       
   382 	    cbaId = DefaultCbaResourceId(); 
       
   383 	    }
       
   384     if( (iExtension->PreviousCba() != cbaId) && ( !iExtension->PopupState() ) )
       
   385 	    {
       
   386 	    Cba()->SetCommandSetL( cbaId );
       
   387 	    Cba()->DrawDeferred();
       
   388 	    iExtension->SetPreviousCba( cbaId );
       
   389 	    }	
       
   390 	}
       
   391 
       
   392 EXPORT_C void CAknTextSettingPage::SizeChanged()
       
   393 	{
       
   394 	StandardSettingPageLayout();  // Must be part of any re-implementation
       
   395 	
       
   396 	TAknLayoutRect layoutRect;
       
   397 	
       
   398 	layoutRect.LayoutRect(
       
   399 	    SettingItemContentRect( ETrue ),
       
   400         AknLayoutScalable_Avkon::setting_text_pane_copy1( 0 ) );
       
   401 	TRect parentRect( layoutRect.Rect() );
       
   402 	
       
   403 	layoutRect.LayoutRect(
       
   404 	   parentRect,
       
   405 	   AknLayoutScalable_Avkon::input_focus_pane_cp1_copy1() );
       
   406 	TRect edwinFrameRect( layoutRect.Rect() );
       
   407 
       
   408 	layoutRect.LayoutRect(
       
   409 	    parentRect,
       
   410 	    AknLayoutScalable_Avkon::indicator_popup_pane_cp5() );
       
   411 	TRect indicatorRect( layoutRect.Rect() );
       
   412 	    
       
   413 	iEdwinLayoutRect.LayoutRect(
       
   414 	    parentRect,
       
   415 	    AknLayoutScalable_Avkon::list_set_text_pane_copy1( 0 ) );
       
   416 	TRect edwinRect( iEdwinLayoutRect.Rect() );
       
   417 
       
   418     TAknLayoutScalableParameterLimits textLimits(
       
   419         AknLayoutScalable_Avkon::set_text_pane_t1_copy1_ParamLimits() );
       
   420 	
       
   421     TAknTextComponentLayout layout;
       
   422     RArray<TAknTextComponentLayout> array;
       
   423     
       
   424     for ( TInt i = textLimits.FirstRow(); i <= textLimits.LastRow(); ++i )
       
   425         {
       
   426         array.Append(
       
   427             AknLayoutScalable_Avkon::set_text_pane_t1_copy1( 0, 0, i ) );
       
   428         }
       
   429     
       
   430     AknLayoutUtils::LayoutEdwin( TextControl(),
       
   431                                  edwinRect,
       
   432                                  layout.Multiline( array ),
       
   433                                  EAknsCIQsnTextColorsCG26 );
       
   434             
       
   435     array.Close();
       
   436 
       
   437     layoutRect.LayoutRect(
       
   438         edwinFrameRect,
       
   439         AknLayoutScalable_Avkon::set_opt_bg_pane_g1_copy1() );
       
   440     SetEditedItemFrameRects( edwinFrameRect, layoutRect.Rect() );
       
   441     
       
   442     SetEditorIndicatorRect( indicatorRect );
       
   443 
       
   444     if ( !TextControl()->ScrollBarFrame() )
       
   445         {
       
   446         TRAP_IGNORE(
       
   447             {
       
   448             TextControl()->CreateScrollBarFrameL();
       
   449             TextControl()->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   450                 CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOn );
       
   451             });
       
   452         }
       
   453     
       
   454     if ( TextControl()->ScrollBarFrame() )
       
   455         {
       
   456         layoutRect.LayoutRect(
       
   457             Rect(), 
       
   458             TAknWindowComponentLayout::Compose(
       
   459                 AknLayoutScalable_Avkon::settings_container_pane( 0 ),
       
   460                 AknLayoutScalable_Avkon::listscroll_set_pane_copy1( 0 ) ) );
       
   461         
       
   462         AknLayoutUtils::LayoutVerticalScrollBar(
       
   463             TextControl()->ScrollBarFrame(), 
       
   464             layoutRect.Rect(),
       
   465             AknLayoutScalable_Avkon::scroll_pane_cp121_copy1( 0 ) );       
       
   466         }
       
   467 	}
       
   468 
       
   469 /**
       
   470 * Validity is alway ETrue unless the flag asking for some non-whitespace data is set.
       
   471 * If set, and if there is an edwin, then check to see that there is a valid character 
       
   472 * somewhere in the text
       
   473 */
       
   474 EXPORT_C void CAknTextSettingPage::CheckAndSetDataValidity()
       
   475 	{
       
   476     TBool validity(ETrue);
       
   477 	
       
   478 	if ( ! (iTextSettingPageFlags & EZeroLengthAllowed ) )
       
   479 		{
       
   480 		CEikEdwin* edwin =  TextControl();
       
   481 		if ( edwin )
       
   482 			{
       
   483 			// Use access to Text() to get at text without allocating anything
       
   484 			TPtrC text = edwin->Text()->Read(0);
       
   485 			
       
   486             // we shold not have only spaces in the text    
       
   487 			validity &= AknTextUtils::IsEmptyText( text );
       
   488 			
       
   489 			_LIT( KEnterSymbol, "\x21b2\x2029" );
       
   490 			if ( text.Compare( KEnterSymbol ) == 0 )
       
   491 			    {
       
   492 			    validity = EFalse;
       
   493 			    }
       
   494 			
       
   495 			// check that enter char does not come here
       
   496 			TInt flags = edwin->UserFlags();
       
   497 			TInt flags2 = edwin->AknEdwinFlags();
       
   498 			
       
   499 			
       
   500 			// check that all chars are valid
       
   501 			for(TInt n=0;validity && n<text.Length();n++)
       
   502 			    {
       
   503 			    TChar ch = text[n];
       
   504 			    //validity &= ch.IsAlpha();
       
   505 			    }
       
   506 			}
       
   507 		else
       
   508 			{
       
   509 			validity = EFalse;			
       
   510 			}
       
   511 		}
       
   512 	SetDataValidity( validity );
       
   513 	}
       
   514 
       
   515 /**
       
   516  * Writes the internal state of the control and its components to aStream.
       
   517  * Does nothing in release mode.
       
   518  * Designed to be overidden and base called by subclasses.
       
   519  */
       
   520 #ifndef _DEBUG
       
   521 EXPORT_C void CAknTextSettingPage::WriteInternalStateL(RWriteStream& /*aWriteStream*/) const
       
   522 	{}
       
   523 #else
       
   524 EXPORT_C void CAknTextSettingPage::WriteInternalStateL(RWriteStream& aWriteStream) const
       
   525 	{
       
   526 	CAknSettingPage::WriteInternalStateL(aWriteStream);
       
   527 	}
       
   528 #endif
       
   529 
       
   530 EXPORT_C void CAknTextSettingPage::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   531     { 
       
   532     CAknEdwinSettingPage::HandlePointerEventL(aPointerEvent); 
       
   533     }
       
   534 
       
   535 EXPORT_C void* CAknTextSettingPage::ExtensionInterface( TUid /*aInterface*/ ) 
       
   536     { 
       
   537     return NULL;
       
   538     }
       
   539 
       
   540 
       
   541 /** 
       
   542 *
       
   543 * This routes the keys to the editor. 
       
   544 * However, if the menu is showing, then events have to be forwarded manually to it. 
       
   545 *
       
   546 */
       
   547 EXPORT_C TKeyResponse CAknTextSettingPage::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType) 
       
   548 	{
       
   549     if( IsStopActiveSchudlerCalled() )
       
   550         {
       
   551         return EKeyWasConsumed;
       
   552         }
       
   553 	if ( aType == EEventKey )
       
   554 	    {
       
   555 	    if( aKeyEvent.iCode == EKeyEnter )
       
   556 	        {
       
   557 	        CEikEdwin* ed = STATIC_CAST( CEikEdwin*, EditorControl());
       
   558 	        return ed->OfferKeyEventL(aKeyEvent, aType);
       
   559 	        }
       
   560 	    }
       
   561     return CAknSettingPage::OfferKeyEventL(aKeyEvent, aType);
       
   562 	}
       
   563 
       
   564 /**
       
   565 * Framework method to determine if it OK to exit the setting page.
       
   566 * Derived classes may check for valid data before allowing the dismissal of the 
       
   567 * setting page.
       
   568 */
       
   569 EXPORT_C TBool CAknTextSettingPage::OkToExitL(TBool aAccept)
       
   570     {
       
   571 	// FEP may reject input causing editing be cancelled
       
   572 	// user in between keypress and editing cancellation may press Ok
       
   573 		
       
   574 	// here we will force fep either to commit or to cancel by changing focus
       
   575     CEikEdwin* ed = STATIC_CAST( CEikEdwin*, EditorControl());
       
   576     TInt cursorPos = ed->CursorPos();
       
   577     
       
   578     CCoeEnv *coeEnv = CCoeEnv::Static();
       
   579     CCoeFep* fep = coeEnv->Fep();
       
   580     if(fep)
       
   581         fep->HandleChangeInFocus(); // will also commit changes in fep
       
   582     
       
   583     ed->SetFocus(ETrue); // return focus and selection
       
   584     ed->ClearSelectionL();
       
   585     ed->SetCursorPosL(cursorPos, EFalse);
       
   586 	
       
   587 	if(aAccept)
       
   588 	    return(DataValidity());
       
   589 	else
       
   590 	    return ETrue;
       
   591     }
       
   592 
       
   593 /**
       
   594  *	Reserved method derived from CCoeControl
       
   595  */
       
   596 EXPORT_C void CAknTextSettingPage::Reserved_2()
       
   597 	{
       
   598 	}
       
   599 
       
   600 /**
       
   601 * Setting Page reserved methods 
       
   602 */ 
       
   603 EXPORT_C void CAknTextSettingPage::CAknSettingPage_Reserved_1()
       
   604 	{
       
   605 	}
       
   606 EXPORT_C void CAknTextSettingPage::CAknSettingPage_Reserved_2()
       
   607 	{
       
   608 	}
       
   609 
       
   610 /**
       
   611 * CAknEdwinSettingPage reserved methods
       
   612 */
       
   613 EXPORT_C void CAknTextSettingPage::CAknEdwinSettingPage_Reserved_1()
       
   614 	{
       
   615 	}
       
   616 
       
   617 /////////////////////////////////////////////////////////////////////////
       
   618 //
       
   619 // Integer Edwin
       
   620 //
       
   621 /////////////////////////////////////////////////////////////////////////
       
   622 
       
   623 /**
       
   624  *
       
   625  * Constructor from setting page resource id + referenced text + flags
       
   626  *
       
   627  */
       
   628 EXPORT_C CAknIntegerSettingPage::CAknIntegerSettingPage( TInt aResourceId, TInt& aValue, TInt aFlags ):
       
   629 	 CAknEdwinSettingPage(aResourceId),iValue(aValue), iIntegerSettingPageFlags( aFlags )
       
   630 	{
       
   631 	AKNTASHOOK_ADD( this, "CAknIntegerSettingPage" );
       
   632 	}
       
   633 
       
   634 EXPORT_C CAknIntegerSettingPage::CAknIntegerSettingPage(	
       
   635 								const TDesC* aSettingText, 
       
   636 								TInt aSettingNumber, 
       
   637 								TInt aControlType,
       
   638 								TInt aEditorResourceId, 
       
   639 								TInt aSettingPageResourceId, 
       
   640 								TInt& aValue, 
       
   641 								TInt aIntegerSettingPageFlags)
       
   642 								:	CAknEdwinSettingPage( 
       
   643 									aSettingText, 
       
   644 									aSettingNumber, 
       
   645 									aControlType, 
       
   646 									aEditorResourceId, 
       
   647 									aSettingPageResourceId ), 
       
   648 									iValue( aValue ),  iIntegerSettingPageFlags( aIntegerSettingPageFlags )
       
   649 	{
       
   650 	AKNTASHOOK_ADD( this, "CAknIntegerSettingPage" );
       
   651 	}
       
   652 
       
   653 
       
   654 
       
   655 /** 
       
   656  *
       
   657  * The 2nd stage construction. Stored internal resource is used to perform the
       
   658  * construction.
       
   659  *
       
   660  */
       
   661 EXPORT_C void CAknIntegerSettingPage::ConstructL()
       
   662 	{
       
   663 	BaseConstructL();
       
   664 	iBackupValue = iValue;
       
   665 
       
   666 	CEikEdwin* editor = TextControl();
       
   667 
       
   668 	// Editor Flags are over-ridden
       
   669 	editor->RemoveFlagFromUserFlags( CEikEdwin::ENoAutoSelection );
       
   670 
       
   671 	if ( iIntegerSettingPageFlags & ENoInitialSelection  ) 
       
   672 		{
       
   673 		editor->AddFlagToUserFlags( CEikEdwin::ENoAutoSelection );
       
   674 		editor->AddFlagToUserFlags( CEikEdwin::EJustAutoCurEnd );
       
   675 		}
       
   676 	if ( iIntegerSettingPageFlags & EPutCursorAtBeginning )
       
   677 		{
       
   678 		editor->RemoveFlagFromUserFlags( CEikEdwin::EJustAutoCurEnd );
       
   679 		}
       
   680 	
       
   681 	IntegerEditorControl()->SetValueL( iValue );
       
   682 	
       
   683 	if(!IsEditable())
       
   684 	    IntegerEditorControl()->SetReadOnly(ETrue);
       
   685 
       
   686 	CheckAndSetDataValidity();
       
   687 	UpdateCbaL();
       
   688 
       
   689 	// Construct an appropriate control context for the contained editor areas.
       
   690 	// Context produced is owned by CAknSettingPage. 
       
   691     SetEditedItemFrameIID( KAknsIIDQsnFrInput, KAknsIIDQsnFrInputCenter );
       
   692 	}
       
   693 
       
   694 /**
       
   695  * Acts upon changes in the hosted control's state. 
       
   696  *
       
   697  * @param	aControl	The control changing its state (not used)
       
   698  * @param	aEventType	The type of control event 
       
   699  */
       
   700 EXPORT_C void CAknIntegerSettingPage::HandleControlEventL(CCoeControl* /*aControl*/,
       
   701 				 MCoeControlObserver::TCoeEvent aEventType)
       
   702 	{
       
   703 	// This event is used as it is called at least every time an edit is made to 
       
   704 	// the edwin.
       
   705 	if ( aEventType == EEventStateChanged )
       
   706 		{
       
   707 		if ( iUpdateMode == EUpdateWhenChanged)
       
   708 			UpdateSettingL();
       
   709 
       
   710 		// This updates the CBA depending on text length
       
   711 		CheckAndSetDataValidity();
       
   712 		UpdateCbaL();
       
   713 		}
       
   714 	}
       
   715 
       
   716 /**
       
   717  *
       
   718  * This routine is called before the editor when the editor is first displayed.  This routine
       
   719  * puts in altered softkey bindings if there is zero-length text.
       
   720  *
       
   721  */
       
   722 EXPORT_C void CAknIntegerSettingPage::DynamicInitL()
       
   723 	{
       
   724 	UpdateCbaL();
       
   725 	}
       
   726 /**
       
   727  *
       
   728  * This routine may be called when the a change is detected in the editor.
       
   729  * The text is copied out to the referenced descriptor using a utility routine.
       
   730  *
       
   731  */
       
   732 EXPORT_C void CAknIntegerSettingPage::UpdateSettingL()
       
   733 	{
       
   734 //  Status currently thrown away to prevent warning
       
   735 	IntegerEditorControl()->GetTextAsInteger( iValue );
       
   736 
       
   737 	if( iSettingPageObserver )
       
   738 		iSettingPageObserver->HandleSettingPageEventL(this, MAknSettingPageObserver::EEventSettingChanged);	
       
   739 
       
   740 	}
       
   741 
       
   742 
       
   743 
       
   744 /** 
       
   745  * 
       
   746  * If the setting page is cancelled, this is called to restore the backed up copy of the 
       
   747  * input text
       
   748  *
       
   749  */
       
   750 EXPORT_C void CAknIntegerSettingPage::RestoreOriginalSettingL()
       
   751 	{
       
   752 	iValue = iBackupValue;
       
   753 	}
       
   754 
       
   755 /** 
       
   756  *
       
   757  * Type-specific access to the text editor control
       
   758  *
       
   759  */
       
   760 EXPORT_C CAknIntegerEdwin* CAknIntegerSettingPage::IntegerEditorControl()
       
   761 	{
       
   762 	return STATIC_CAST( CAknIntegerEdwin*, EditorControl());
       
   763 	}
       
   764 
       
   765 EXPORT_C void CAknIntegerSettingPage::UpdateCbaL()
       
   766 	{
       
   767 	CAknSettingPage::UpdateCbaL();
       
   768 
       
   769 	}
       
   770 
       
   771 EXPORT_C void CAknIntegerSettingPage::SizeChanged()
       
   772 	{
       
   773 	StandardSettingPageLayout();  // Must be part of any re-implementation
       
   774 	
       
   775     TRect rect( SettingItemContentRect( EFalse ) );
       
   776     
       
   777     iEdwinLayoutRect.LayoutRect(
       
   778         rect,
       
   779         AknLayoutScalable_Avkon::setting_code_pane_copy1() );
       
   780     TRect edwinRect( iEdwinLayoutRect.Rect() );
       
   781 
       
   782     TAknLayoutRect layoutRect;
       
   783     layoutRect.LayoutRect(
       
   784         edwinRect,
       
   785         AknLayoutScalable_Avkon::input_focus_pane_cp2_copy1() );
       
   786     TRect edwinFrameRect( layoutRect.Rect() );
       
   787 
       
   788     layoutRect.LayoutRect(
       
   789         edwinRect,
       
   790         AknLayoutScalable_Avkon::indicator_popup_pane_cp6() );
       
   791     TRect indicatorRect( layoutRect.Rect() );
       
   792     
       
   793     AknLayoutUtils::LayoutEdwin(
       
   794             IntegerEditorControl(),
       
   795             edwinRect, 
       
   796             AknLayoutScalable_Avkon::setting_code_pane_t1_copy1().LayoutLine(),
       
   797             EAknsCIQsnTextColorsCG26,
       
   798             0,
       
   799             ETrue );
       
   800 
       
   801     layoutRect.LayoutRect( edwinFrameRect,
       
   802                            AknLayoutScalable_Avkon::set_opt_bg_pane_g1() );
       
   803     SetEditedItemFrameRects( edwinFrameRect, layoutRect.Rect() );
       
   804     
       
   805     SetEditorIndicatorRect( indicatorRect );
       
   806 	}
       
   807 
       
   808 
       
   809 EXPORT_C void CAknIntegerSettingPage::CheckAndSetDataValidity()
       
   810 	{
       
   811 	TInt anInt;
       
   812 	CAknIntegerEdwin::TValidationStatus intStatus = IntegerEditorControl()->GetTextAsInteger( anInt );
       
   813 	SetDataValidity( intStatus == CAknIntegerEdwin::EValueValid );
       
   814 
       
   815 	// Check other flags if not valid
       
   816 	if ( !DataValidity() )
       
   817 		{
       
   818 		if ( iIntegerSettingPageFlags & EEmptyValueAllowed )
       
   819 			SetDataValidity( (intStatus == CAknIntegerEdwin::EEmpty) );
       
   820 		}
       
   821 	// check next flag if data still not valid
       
   822 	if ( !DataValidity() )
       
   823 		{
       
   824 		if ( iIntegerSettingPageFlags & EInvalidValueAllowed )
       
   825 			SetDataValidity ( ETrue );
       
   826 		}
       
   827 
       
   828 	}
       
   829 
       
   830 /**
       
   831  * Writes the internal state of the control and its components to aStream.
       
   832  * Does nothing in release mode.
       
   833  * Designed to be overidden and base called by subclasses.
       
   834  */
       
   835 #ifndef _DEBUG
       
   836 EXPORT_C void CAknIntegerSettingPage::WriteInternalStateL(RWriteStream& /*aWriteStream*/) const
       
   837 	{}
       
   838 #else
       
   839 EXPORT_C void CAknIntegerSettingPage::WriteInternalStateL(RWriteStream& aWriteStream) const
       
   840 	{
       
   841 	CAknSettingPage::WriteInternalStateL(aWriteStream);
       
   842 	}
       
   843 #endif
       
   844 
       
   845 EXPORT_C void CAknIntegerSettingPage::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   846     { 
       
   847     CAknEdwinSettingPage::HandlePointerEventL(aPointerEvent); 
       
   848     }
       
   849 
       
   850 EXPORT_C void* CAknIntegerSettingPage::ExtensionInterface( TUid /*aInterface*/ ) 
       
   851     { 
       
   852     return NULL;
       
   853     }
       
   854 
       
   855 /**
       
   856  *	Reserved method derived from CCoeControl
       
   857  */
       
   858 EXPORT_C void CAknIntegerSettingPage::Reserved_2()
       
   859 	{
       
   860 	}
       
   861 
       
   862 /**
       
   863 * Setting Page reserved methods 
       
   864 */ 
       
   865 EXPORT_C void CAknIntegerSettingPage::CAknSettingPage_Reserved_1()
       
   866 	{
       
   867 	}
       
   868 EXPORT_C void CAknIntegerSettingPage::CAknSettingPage_Reserved_2()
       
   869 	{
       
   870 	}
       
   871 /**
       
   872 * CAknEdwinSettingPage reserved methods
       
   873 */
       
   874 EXPORT_C void CAknIntegerSettingPage::CAknEdwinSettingPage_Reserved_1()
       
   875 	{
       
   876 	}
       
   877 
       
   878 // End of File