textinput/peninputgenericitut/src/peninputitutwesternuistatespelling.cpp
changeset 0 eb1f2e154e89
child 5 a47de9135b21
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2002-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:  drop-down list control
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknFepGlobalEnums.h>
       
    20 #include <peninputgeneralitutnew.rsg>
       
    21 #include <peninputlayoutmultilineicf.h>
       
    22 #include <StringLoader.h>
       
    23 #include <peninputcommonbutton.h>
       
    24 #include <peninputlayout.h>
       
    25 #include <peninputcmd.h>
       
    26 #include <peninputlabel.h>
       
    27 
       
    28 #include "peninputitutwesternuistatespelling.h"
       
    29 #include "peninputgenericitutuimgrbase.h"
       
    30 #include "peninputgenericitutdatamgr.h"
       
    31 #include "peninputgenericitutlayoutcontext.h"
       
    32 #include "peninputgenericitutconverter.h"
       
    33 #include "peninputitutcustomizationresourcemgr.h"
       
    34 #include "peninputgenericitutlayout.h"
       
    35 #include "peninputcommonbgctrl.h"
       
    36 #include "peninputgenericitutwindowmanager.h"
       
    37 #include "peninputgenericitutwindow.h"
       
    38 
       
    39 CWesternItutUiStateSpelling* CWesternItutUiStateSpelling::NewL(CGenericItutUiMgrBase* aOwner)
       
    40     {
       
    41     CWesternItutUiStateSpelling* self = new (ELeave) CWesternItutUiStateSpelling(aOwner);
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL(); 
       
    44     CleanupStack::Pop(self);
       
    45     return self;
       
    46     }
       
    47 
       
    48 CWesternItutUiStateSpelling::~CWesternItutUiStateSpelling()
       
    49     {
       
    50     delete iRscMgr;
       
    51     }
       
    52 
       
    53 CWesternItutUiStateSpelling::CWesternItutUiStateSpelling(CGenericItutUiMgrBase* aOwner)
       
    54                                                         :CGenericItutUiStateBase(aOwner)
       
    55     {
       
    56     iICF = static_cast<CFepLayoutMultiLineIcf*>(iOwner->LayoutContext()->Control(ECtrlIdICF));
       
    57     }
       
    58 
       
    59 void CWesternItutUiStateSpelling::ConstructL()
       
    60     {
       
    61     CGenericItutUiStateBase::ConstructL();
       
    62     iRscMgr = CItutCustomizedRscMgr::NewL(iOwner->LayoutContext()->UiLayout(), 
       
    63                                           iOwner->LayoutContext());
       
    64     }
       
    65 
       
    66 void CWesternItutUiStateSpelling::CreateTextBtnIfNeededL(CAknFepCtrlCommonButton*& aBtn, 
       
    67                                                          TInt aCtrlId,
       
    68                                                          TInt aCtrlPos,
       
    69                                                          TInt aTextResId,
       
    70                                                          TAknTextLineLayout aTextFormat)
       
    71     {
       
    72     if (!aBtn)
       
    73         {
       
    74         aBtn = CAknFepCtrlCommonButton::NewL(iOwner->LayoutContext()->UiLayout(), 
       
    75                                              aCtrlId,
       
    76                                              KAknsIIDQsnFrFunctionButtonNormal,
       
    77                                              KAknsIIDQsnFrFunctionButtonPressed,
       
    78                                              KAknsIIDQsnFrFunctionButtonInactive);
       
    79         aBtn->SetRect(TItutDataConverter::AnyToRect(iOwner->DataMgr()->RequestData(aCtrlPos)));
       
    80         HBufC* btntext = StringLoader::LoadLC(aTextResId);
       
    81         aBtn->SetTextFormat(aTextFormat);
       
    82         aBtn->SetTextL(*btntext);
       
    83         aBtn->SetTextColorIndex( EAknsCIQsnTextColorsCG65 );
       
    84         CleanupStack::PopAndDestroy(btntext);
       
    85         iOwner->LayoutContext()->UiLayout()->AddControlL(aBtn);
       
    86         }
       
    87     }
       
    88 
       
    89 void CWesternItutUiStateSpelling::OnEntryL()
       
    90     {
       
    91     TInt keypadResId = KInvalidResId;
       
    92     switch (iOwner->DataMgr()->InputMode())
       
    93         {
       
    94         case ENumber:
       
    95             keypadResId = R_FINGER_INPUT_KEYPAD_NUMBER;
       
    96             break;
       
    97         case ELatin:
       
    98             keypadResId = iOwner->DataMgr()->KeypadResourceId();
       
    99             break;
       
   100         default:
       
   101             break;                
       
   102         }
       
   103     //hide bubble in the first place.
       
   104     iICF->HideBubble();
       
   105     // Show background of the spell popup window
       
   106     CAknFepCtrlCommonBgCtrl* bgCtrl = static_cast<CAknFepCtrlCommonBgCtrl*>
       
   107                                       (iOwner->LayoutContext()->Control(ECtrlIdBackground) );
       
   108     if(bgCtrl)
       
   109 		{
       
   110 		bgCtrl->ShowSubBgItem( 0, ETrue );	
       
   111 		}
       
   112 
       
   113     // update resource id of keypad
       
   114     iOwner->DataMgr()->NotifyChangeControlLayout(
       
   115         MItutPropertySubscriber::EItutPropertyKeypadResourceId, keypadResId);
       
   116 
       
   117     // hide not needed controls
       
   118     iOwner->LayoutContext()->Control(ECtrlIdSwitch)->Hide(ETrue);
       
   119     iOwner->LayoutContext()->Control(ECtrlIdArrowLeft)->Hide(ETrue);
       
   120     iOwner->LayoutContext()->Control(ECtrlIdArrowRight)->Hide(ETrue);
       
   121     iOwner->LayoutContext()->Control(ECtrlIdOptions)->Hide(ETrue);
       
   122     iOwner->LayoutContext()->Control(ECtrlIdClose)->Hide(ETrue);
       
   123     iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(ETrue);
       
   124 
       
   125     TAknTextLineLayout btntextformat = TItutDataConverter::AnyToTextLine(
       
   126                                                iOwner->DataMgr()->RequestData(EBtnTextLine));
       
   127     TAknTextLineLayout btntextCancel = TItutDataConverter::AnyToTextLine(
       
   128                                                iOwner->DataMgr()->RequestData(ESpellTextCancle));
       
   129     CreateTextBtnIfNeededL(iOk, ECtrlIdOkBtn, EItutPosOk, R_PENINPUT_FINGER_OK, btntextformat);
       
   130     iOk->SetReady(ETrue);
       
   131     iOk->Hide(EFalse);
       
   132     iICF->IsEmpty() ? iOk->SetDimmed(ETrue) : iOk->SetDimmed(EFalse);
       
   133 
       
   134     CreateTextBtnIfNeededL(iCancel, ECtrlIdCancelBtn, EItutPosCancel, 
       
   135                            R_PENINPUT_FINGER_CANCEL, btntextformat);
       
   136     iCancel->SetReady(ETrue);
       
   137     iCancel->Hide(EFalse);
       
   138 
       
   139     iOwner->DataMgr()->SetSpellMode(ETrue);
       
   140     iICF->SetLineSeparatorAfterPrompt(ETrue);
       
   141     
       
   142     ReCalcLayoutL();
       
   143     CAknFepCtrlLabel* indilabel = static_cast<CAknFepCtrlLabel*>
       
   144                                       (iOwner->LayoutContext()->Control(ECtrlIdSpellIndicator));	
       
   145     indilabel->Hide( EFalse );
       
   146     iOwner->DataMgr()->SetUpdate(ETrue);
       
   147     }
       
   148 
       
   149 void CWesternItutUiStateSpelling::OnExit()
       
   150     {
       
   151     CAknFepCtrlLabel* indilabel = static_cast<CAknFepCtrlLabel*>
       
   152     								                  (iOwner->LayoutContext()->Control(ECtrlIdSpellIndicator));
       
   153     indilabel->Hide( ETrue );
       
   154     iOk->Hide(ETrue);
       
   155     iCancel->Hide(ETrue);
       
   156     iOwner->DataMgr()->SetSpellMode(EFalse);
       
   157     iICF->SetLineSeparatorAfterPrompt(EFalse);
       
   158     // Hide background of the spell popup window
       
   159     CAknFepCtrlCommonBgCtrl* bgCtrl = static_cast<CAknFepCtrlCommonBgCtrl*>
       
   160                                       (iOwner->LayoutContext()->Control(ECtrlIdBackground) );
       
   161     if(bgCtrl)
       
   162 		{
       
   163 		bgCtrl->ShowSubBgItem( 0, EFalse );	
       
   164 		}    
       
   165     }
       
   166 
       
   167 CGenericItutUiMgrBase::TUiState CWesternItutUiStateSpelling::StateType()
       
   168     {
       
   169     return CGenericItutUiMgrBase::EStateSpelling;
       
   170     }
       
   171 
       
   172 TInt CWesternItutUiStateSpelling::HandleCommandL(TInt aCmd, TUint8* /*aData*/)
       
   173     {
       
   174     switch (aCmd) 
       
   175         {
       
   176         case EItutExtCmdSizeChanged:
       
   177             {
       
   178 			ReCalcLayoutL();
       
   179             return KErrNone;
       
   180             }
       
   181        	case EItutCmdCheckIcfEmpty:
       
   182        	    {
       
   183 		        iICF->IsEmpty() ? iOk->SetDimmed(ETrue) : iOk->SetDimmed(EFalse);
       
   184             return KErrNone;
       
   185        	    }
       
   186         default:
       
   187             break;
       
   188         }
       
   189 
       
   190     return KErrNotSupported;    
       
   191     }
       
   192 
       
   193 TBool CWesternItutUiStateSpelling::HandleCtrlEventL(TInt aEventType, 
       
   194                                                     CFepUiBaseCtrl* aCtrl, 
       
   195                                                     const TDesC& /*aEventData*/)
       
   196     {
       
   197     switch (aEventType)
       
   198         {
       
   199         case EEventButtonUp:
       
   200             {
       
   201             TInt ctrlid = aCtrl->ControlId();
       
   202 
       
   203             if (ctrlid != ECtrlIdOkBtn && ctrlid != ECtrlIdCancelBtn)
       
   204                 {
       
   205                 return EFalse;
       
   206                 }
       
   207 
       
   208             TBuf<4> buf;
       
   209             TBool exitbyok = (ctrlid == ECtrlIdOkBtn);
       
   210             buf.Append(reinterpret_cast<TText*>(&exitbyok), sizeof(TBool)/sizeof(TText));
       
   211             
       
   212             iOwner->LayoutContext()->UiLayout()->SignalOwner(ESignalExitSpellMode, buf);
       
   213             return ETrue;
       
   214             }
       
   215         default:
       
   216             break;
       
   217         }
       
   218 
       
   219     return EFalse;    
       
   220     }
       
   221 
       
   222 void CWesternItutUiStateSpelling::ReCalcLayoutL()
       
   223 	{
       
   224     TAknTextLineLayout btntextformat = TItutDataConverter::AnyToTextLine(
       
   225                                                  iOwner->DataMgr()->RequestData(EBtnTextLine));
       
   226     TAknTextLineLayout btntextCancel = TItutDataConverter::AnyToTextLine(
       
   227                                                  iOwner->DataMgr()->RequestData(ESpellTextCancle));
       
   228     TRect btnrect = TItutDataConverter::AnyToRect(iOwner->DataMgr()->RequestData(EItutPosOk));
       
   229     iOk->SetTextFormat(btntextformat);
       
   230     iOk->SizeChanged(btnrect, btnrect, ETrue);
       
   231 
       
   232     btnrect = TItutDataConverter::AnyToRect(iOwner->DataMgr()->RequestData(EItutPosCancel));
       
   233     iCancel->SetTextFormat(btntextCancel);
       
   234     iCancel->SizeChanged(btnrect, btnrect, ETrue);
       
   235     //iICF->SetRect( TItutDataConverter::AnyToRect(iOwner->DataMgr()->RequestData(ESpellICFRect)) );
       
   236     CFont* icffont = TItutDataConverter::AnyToFont(iOwner->DataMgr()->RequestData(EIcfFont));
       
   237     TRect rect = TItutDataConverter::AnyToRect(iOwner->DataMgr()->RequestData(ESpellICFRect) );
       
   238     
       
   239     //rect.iTl.iY -= 50;
       
   240     iICF->SetTextMargin ( 2,
       
   241     					  2,
       
   242     					  2,
       
   243     					  2);
       
   244  
       
   245     iICF->SetLineSpace( 1 );
       
   246     iICF->SizeChangedL(rect, 
       
   247                   //icffont->HeightInPixels(),
       
   248                   iOwner->DataMgr()->iIcfTextHeight,
       
   249                   icffont->FontMaxHeight(),
       
   250                   icffont);
       
   251 
       
   252     CAknFepCtrlCommonButton* clrBtn = static_cast<CAknFepCtrlCommonButton*>(
       
   253 									  iOwner->LayoutContext()->Control(ECtrlIdBackspace) );
       
   254 	
       
   255 	// When size changed in r-to-l language, it should be mirrored
       
   256 	TRect rt = TItutDataConverter::AnyToRect( iOwner->DataMgr()->RequestData(ESpellClrRect) );
       
   257 	TRect innerRect = TItutDataConverter::AnyToRect( 
       
   258 						iOwner->DataMgr()->RequestData(ESpellClrInnerRect) );
       
   259     TBool bSizedChanged = (rt.Size() != clrBtn->Rect().Size()) && 
       
   260 	    (innerRect.Size() != clrBtn->ForgroundBmpRect().Size());									  
       
   261     clrBtn->SizeChanged( rt, innerRect, ETrue );
       
   262 	
       
   263 	if( bSizedChanged && iOwner->DataMgr()->IsRtoLLanguage() )
       
   264 		{
       
   265 		iOwner->UiManager()->Window()->HandleButtonResOnLangDirChange( ECtrlIdBackspace );			
       
   266 		}
       
   267 	}
       
   268 	
       
   269 // End Of File