textinput/peninputhwrtrui/src/truitextsettingpagecontainer.cpp
changeset 0 eb1f2e154e89
child 3 f5a1e66df979
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Implement of class CTruiTextSettingPageContainer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknlayoutscalable_apps.cdl.h>
       
    20 #include <aknscontrolcontext.h>
       
    21 #include <aknpreviewpopupcontroller.h>
       
    22 #include <aknpreviewpopupobserver.h>
       
    23 #include <layoutmetadata.cdl.h>
       
    24 
       
    25 #include "truitextsettingpagecontainer.h"
       
    26 #include "truihwrbox.h"
       
    27 #include "truiappui.h"
       
    28 #include "truiengine.h"
       
    29 #include "truishortcutsview.h"
       
    30 #include "truiapplication.h"
       
    31 #include "truiinfomessageview.h"
       
    32 #include "truishortcuteditview.h"
       
    33 #include "truishortcutedittextview.h"
       
    34 #include "trui.hrh"
       
    35 #include "truicontainerbase.h"
       
    36 
       
    37 // Initialized size for hwrbox
       
    38 const TSize KHwrboxSize = TSize( 100, 100 );
       
    39 
       
    40 // The x-cordination of hwrbox pos
       
    41 const TInt KHwrBoxPosPortraitX = 60;
       
    42 const TInt KHwrBoxPosLandscapeX = 100;
       
    43 
       
    44 const TInt KPopupWindowVarity = 1;
       
    45 
       
    46 const TInt KParaDelimiterSize = 1;
       
    47 
       
    48 _LIT( KParaDelimiterFormat, "%c" );
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Constructor.
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CTruiTextSettingPageContainer::CTruiTextSettingPageContainer
       
    57                 ( TInt aResourceID, TDes& aText, TInt aTextSettingPageFlags )
       
    58              :CAknTextSettingPage( aResourceID, aText, aTextSettingPageFlags )
       
    59     {  
       
    60     }
       
    61     
       
    62 // ---------------------------------------------------------------------------
       
    63 // Perform the second phase construction of a CTruiMainViewContainer object.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CTruiTextSettingPageContainer::ConstructL( const TRect& aRect, TBool aEnableHwrBox )
       
    67     {
       
    68     CAknTextSettingPage::ConstructL();
       
    69     TextControl()->SetObserver( this );
       
    70     // Check character model 
       
    71     CEikEdwin* edwin = static_cast<CEikEdwin*>( EditorControl() );
       
    72     HBufC* shortcutText = edwin->GetTextInHBufL();    
       
    73     if ( shortcutText )
       
    74         {        
       
    75         // Replace paragraph seperator to line break
       
    76         TPtr ptr = shortcutText->Des();
       
    77         TBuf<KParaDelimiterSize> paraDelimiter;
       
    78         paraDelimiter.Format( KParaDelimiterFormat, EKeyEnter ); 
       
    79         AknTextUtils::ReplaceCharacters( ptr, paraDelimiter, 
       
    80                                 TChar( CEditableText::EParagraphDelimiter ) );
       
    81         CleanupStack::PushL( shortcutText );
       
    82         edwin->SetTextL( shortcutText );
       
    83         CleanupStack::PopAndDestroy( shortcutText );
       
    84         }    
       
    85         
       
    86     if ( aEnableHwrBox )
       
    87         {
       
    88         CTruiAppUi* appUi = static_cast<CTruiAppUi*>( iAvkonViewAppUi );
       
    89         CTruiEngine* engine = appUi->HwrEngine();
       
    90         if ( engine->CheckShortcutModel( engine->Shortcut() ) )
       
    91             {
       
    92             // Create hwrbox            
       
    93             iHwrBox = CTruiHwrBox::NewL( NULL, NULL );
       
    94             iHwrBox->SetHwrBoxFlag( CTruiHwrBox::ENoFrameHwrBox 
       
    95                                     | CTruiHwrBox::EReadOnlyHwrBox);
       
    96             
       
    97             // Create preview popup
       
    98             iPopupController = CAknPreviewPopUpController::NewL
       
    99                       ( *iHwrBox, CAknPreviewPopUpController::EPermanentMode );            
       
   100             iPopupController->AddObserverL( *this );
       
   101             // Set guide line
       
   102             iHwrBox->SetDisplayBottomGuideLine( ETrue );
       
   103             if ( engine->CurrentLanguageScript() == EMainViewSubmenuHebrew )
       
   104                 {
       
   105                 iHwrBox->SetDisplayTopGuideLine( ETrue );
       
   106                 }
       
   107             iPopupController->SetPopUpShowDelay( 0 );            
       
   108             }                          
       
   109         }
       
   110     SetRect( aRect );
       
   111     if ( iPopupController )
       
   112         {
       
   113         iPopupController->ShowPopUp();
       
   114         }    
       
   115     ActivateL();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Two-phased constructor.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 CTruiTextSettingPageContainer* CTruiTextSettingPageContainer::NewL
       
   123                                                 ( TInt aResourceId, 
       
   124                                                   TDes& aText,
       
   125                                                   const TRect& aRect,
       
   126                                                   TBool aEnableHwrBox,
       
   127                                                   TInt aTextSettingPageFlags )
       
   128     {
       
   129     CTruiTextSettingPageContainer* self = CTruiTextSettingPageContainer::NewLC
       
   130                                                   ( aResourceId, aText,
       
   131                                                     aRect,
       
   132                                                     aEnableHwrBox,
       
   133                                                     aTextSettingPageFlags );
       
   134     CleanupStack::Pop( self );
       
   135     return self;
       
   136     }
       
   137     
       
   138 // ---------------------------------------------------------------------------
       
   139 // Two-phased constructor.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 CTruiTextSettingPageContainer* CTruiTextSettingPageContainer::NewLC
       
   143                                                 ( TInt aResourceId, 
       
   144                                                   TDes& aText, 
       
   145                                                   const TRect& aRect,
       
   146                                                   TBool aEnableHwrBox,
       
   147                                                   TInt aTextSettingPageFlags )
       
   148     {
       
   149     CTruiTextSettingPageContainer* self = new (ELeave) 
       
   150                                           CTruiTextSettingPageContainer
       
   151                                                  ( aResourceId, aText,
       
   152                                                    aTextSettingPageFlags );
       
   153     CleanupStack::PushL( self );
       
   154     self->ConstructL( aRect, aEnableHwrBox );
       
   155     return self;
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // Destructor.
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 
       
   163 CTruiTextSettingPageContainer::~CTruiTextSettingPageContainer()
       
   164     {
       
   165     delete iPopupController;
       
   166     delete iHwrBox;
       
   167     }
       
   168     
       
   169 // ---------------------------------------------------------------------------
       
   170 // Responds to changes to the size and position of the contents of this control.
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CTruiTextSettingPageContainer::SizeChanged()
       
   174     {
       
   175     CAknTextSettingPage::SizeChanged();
       
   176     
       
   177     if ( iHwrBox )
       
   178         {
       
   179         // caculate main pane
       
   180         TRect rect = Rect();    
       
   181         TAknWindowComponentLayout main_pane_layout = 
       
   182                                 AknLayoutScalable_Apps::main_hwr_training_pane();
       
   183         TAknLayoutRect main_pane_layout_rect;
       
   184         main_pane_layout_rect.LayoutRect( rect, main_pane_layout );
       
   185         TRect main_pane_rect = main_pane_layout_rect.Rect();
       
   186         
       
   187         // Calculate popup_hwr_training_preview_window
       
   188         TAknWindowComponentLayout preview_popup_layout = 
       
   189                    AknLayoutScalable_Apps::popup_hwr_training_preview_window
       
   190                                                          ( KPopupWindowVarity );
       
   191         TAknLayoutRect preview_popup_layout_rect;
       
   192         preview_popup_layout_rect.LayoutRect( main_pane_rect, preview_popup_layout );
       
   193                 
       
   194         TPoint labelPos = TextLabel()->PositionRelativeToScreen();
       
   195         TPoint hwrPos = TPoint( 0, 0 );
       
   196         if ( TBidiText::ScriptDirectionality( User::Language() )
       
   197                                               ==  TBidiText::ELeftToRight )
       
   198             {
       
   199             TInt offset = Layout_Meta_Data::IsLandscapeOrientation() ?
       
   200                           KHwrBoxPosLandscapeX : KHwrBoxPosPortraitX;
       
   201             hwrPos = labelPos + TPoint( offset, TextLabel()->Size().iHeight );
       
   202             }
       
   203         else
       
   204             {
       
   205             hwrPos = labelPos + TPoint( TextLabel()->Size().iWidth, 
       
   206                             		TextLabel()->Size().iHeight );
       
   207             }
       
   208 
       
   209         iHwrBox->SetSize( preview_popup_layout_rect.Rect().Size() );
       
   210         iPopupController->SetPosition( hwrPos );
       
   211         }
       
   212     }
       
   213     
       
   214 // ---------------------------------------------------------------------------
       
   215 // Processes events from the softkeys.     
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CTruiTextSettingPageContainer::ProcessCommandL( TInt aCommandId )
       
   219     {
       
   220     HideMenu();    
       
   221     switch ( aCommandId )
       
   222         {
       
   223         case EAknSoftkeyOk:
       
   224         case EAknSoftkeySelect:
       
   225             {
       
   226             // Get the current text in setting page
       
   227             CTruiAppUi* appUi = static_cast<CTruiAppUi*>( iAvkonViewAppUi );
       
   228             CTruiEngine* engine = appUi->HwrEngine();
       
   229             CEikEdwin* edwin = static_cast<CEikEdwin*>( EditorControl() );
       
   230             HBufC* shortcutText = edwin->GetTextInHBufL();
       
   231             CleanupStack::PushL( shortcutText );
       
   232             // Replace paragraph seperator to line break            
       
   233             TPtr ptr = shortcutText->Des();
       
   234             TBuf<KParaDelimiterSize> paraDelimiter;
       
   235             paraDelimiter.Format( KParaDelimiterFormat, CEditableText::EParagraphDelimiter );
       
   236             AknTextUtils::ReplaceCharacters( ptr, paraDelimiter, TChar( EKeyEnter ) );
       
   237             // Update new text
       
   238             engine->ChangeShortcutTextL( *shortcutText );
       
   239             // Recalculate selected index of shortcut list
       
   240             // Update shortcut list
       
   241             engine->UpdateShortcutListL();
       
   242             // Find the current shortcut's index in shortcut list
       
   243             TInt index = 0;
       
   244             CDesCArray* shortcutList = engine->ShortcutTextList();
       
   245             if ( shortcutList )
       
   246                 {                
       
   247                 TInt ret = 0;
       
   248                 ret = shortcutList->Find( *shortcutText, index );
       
   249                 if ( ret == KErrNotFound )
       
   250                     {
       
   251                     TInt oldIndex = engine->CurrentSelectedIndex();
       
   252                     index = ( oldIndex > shortcutList->Count() ) 
       
   253                                        ? shortcutList->Count() : oldIndex;
       
   254                     }
       
   255                 }
       
   256             // Set current index in Engine
       
   257             engine->SetCurrentSelectedIndex( index + 1 );           
       
   258             CleanupStack::PopAndDestroy( shortcutText );            
       
   259             // Store the content of setting page
       
   260             UpdateSettingL();
       
   261             CTruiShortcutEditTextView* view = 
       
   262                                      static_cast<CTruiShortcutEditTextView*>
       
   263                               ( appUi->View( KTruiShortcutEditTextViewId ) );
       
   264             if ( view->StartViewId() == 
       
   265                         TVwsViewId( KUidtruiApp, KTruiInfoMessageViewId ) )
       
   266                 {
       
   267                 ProcessCommandL( EAknSoftkeyNext );
       
   268                 }
       
   269             else
       
   270                 {
       
   271                 // Switch to shortcuts view.
       
   272                 iAvkonViewAppUi->ActivateLocalViewL
       
   273                                             ( view->StartViewId().iViewUid );
       
   274                 }
       
   275             break;
       
   276             }
       
   277         case EAknSoftkeyCancel:
       
   278             {
       
   279             iAvkonViewAppUi->ActivateLocalViewL( KTruiShortcutsViewId );
       
   280             break;
       
   281             }
       
   282         case EAknSoftkeyNext:
       
   283             {
       
   284             UpdateSettingL();
       
   285             // Get the current text in setting page
       
   286             CTruiAppUi* appUi = static_cast<CTruiAppUi*>( iAvkonViewAppUi );
       
   287             CTruiEngine* engine = appUi->HwrEngine();
       
   288             CEikEdwin* edwin = static_cast<CEikEdwin*>( EditorControl() );
       
   289             HBufC* shortcutText = edwin->GetTextInHBufL();
       
   290             CleanupStack::PushL( shortcutText );
       
   291             // Replace paragraph seperator to line break            
       
   292             TPtr ptr = shortcutText->Des();
       
   293             TBuf<KParaDelimiterSize> paraDelimiter;
       
   294             paraDelimiter.Format( KParaDelimiterFormat, CEditableText::EParagraphDelimiter );
       
   295             AknTextUtils::ReplaceCharacters( ptr, paraDelimiter, TChar( EKeyEnter ) );
       
   296             engine->SetShortcut( ptr );            
       
   297             CleanupStack::PopAndDestroy( shortcutText );                        
       
   298             iAvkonViewAppUi->ActivateLocalViewL( KTruiShortcutEditViewId );
       
   299             break;
       
   300             }
       
   301         case EAknSoftkeyBack:
       
   302             {
       
   303             CTruiAppUi* appUi = static_cast<CTruiAppUi*>( iAvkonViewAppUi );
       
   304             CTruiEngine* engine = appUi->HwrEngine();            
       
   305             if ( engine->DisplayWizard() )
       
   306                 {
       
   307                 iAvkonViewAppUi->ActivateLocalViewL( KTruiInfoMessageViewId );
       
   308                 }
       
   309             else
       
   310                 {
       
   311                 iAvkonViewAppUi->ActivateLocalViewL( KTruiShortcutsViewId );
       
   312                 }
       
   313             break;
       
   314             }
       
   315         }
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // From MAknPreviewPopUpObserver
       
   320 // Called by the preview popup when an appropriate event takes place.
       
   321 // ---------------------------------------------------------------------------
       
   322 // 
       
   323 void CTruiTextSettingPageContainer::HandlePreviewPopUpEventL(
       
   324       CAknPreviewPopUpController* aController, TPreviewPopUpEvent aEvent )
       
   325     {
       
   326     if ( aController == iPopupController && aEvent == EPreviewPopUpShown )
       
   327         {
       
   328         CTruiAppUi* appUi = static_cast<CTruiAppUi*>( iAvkonViewAppUi );
       
   329         CTruiEngine* engine = appUi->HwrEngine();
       
   330         CEikEdwin* edwin = TextControl();
       
   331         HBufC* shortcutText = edwin->GetTextInHBufL();
       
   332         CleanupStack::PushL( shortcutText );
       
   333         // Get character model
       
   334         TUint unicode = 0;
       
   335         TRAPD( err, engine->GetShortcutModelL( engine->Shortcut(), iHwrBox->Model(), unicode ) );
       
   336         if ( err == KErrNone )
       
   337             {
       
   338             TSize refSize = CTruiContainerBase::OriginSymbolSize();
       
   339             iHwrBox->ShowTrails( iHwrBox->Model(), ETrue, refSize );
       
   340             }    
       
   341         CleanupStack::PopAndDestroy( shortcutText );
       
   342         }
       
   343     }