csxhelp/src/CSXHGenericContainer.cpp
changeset 0 1f04cf54edd8
equal deleted inserted replaced
-1:000000000000 0:1f04cf54edd8
       
     1 /*
       
     2 * Copyright (c) 2006 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:  CCSXHGenericContainer class definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CSXHGenericContainer.h"
       
    20 #include "CSXHGenericView.h"
       
    21 #include "CSXHDocument.h"
       
    22 #include "CSXHAppUi.h"
       
    23 #include "CSXHHelpDataBase.h"
       
    24 #include "CSXHGenericTOC1.h"
       
    25 #include "CSXHGenericTOC2.h"
       
    26 
       
    27 #ifdef FF_HELP_TUTORIAL_MERGE
       
    28 #include "CSXHHtmlTOC2.h"
       
    29 #endif
       
    30 
       
    31 #include "CsHelp.hrh"
       
    32 #include "csxhconstants.h"
       
    33 
       
    34 #include "CSXHViewIDs.h"
       
    35 #include <eikclbd.h>
       
    36 #include <aknlists.h>
       
    37 #include <featmgr.h>
       
    38 #include <AknPriv.hrh>
       
    39 
       
    40 const TInt KFindNameLength = 40;
       
    41 const TInt KComponentCount = 2;     
       
    42 
       
    43 #ifdef FF_HELP_TUTORIAL_MERGE
       
    44 CCSXHGenericContainer* CCSXHGenericContainer::NewL(const TRect& aRect,CCSXHDocument& aDocument,CCSXHGenericView* aView)
       
    45 	{
       
    46 	CCSXHGenericContainer* self = CCSXHGenericContainer::NewLC(aRect,aDocument,aView);
       
    47     CleanupStack::Pop(self);
       
    48     return self;
       
    49 	}
       
    50 #else
       
    51 CCSXHGenericContainer* CCSXHGenericContainer::NewL(const TRect& aRect,CCSXHDocument& aDocument)
       
    52     {
       
    53     CCSXHGenericContainer* self = CCSXHGenericContainer::NewLC(aRect,aDocument);
       
    54     CleanupStack::Pop(self);
       
    55     return self;
       
    56     }
       
    57 #endif
       
    58     
       
    59 #ifdef FF_HELP_TUTORIAL_MERGE
       
    60 CCSXHGenericContainer* CCSXHGenericContainer::NewLC(const TRect& aRect,CCSXHDocument& aDocument,CCSXHGenericView* aView)
       
    61     {
       
    62     CCSXHGenericContainer* self = new(ELeave) CCSXHGenericContainer(aDocument,aView);
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL(aRect);
       
    65     return self;
       
    66     }
       
    67 #else
       
    68 CCSXHGenericContainer* CCSXHGenericContainer::NewLC(const TRect& aRect,CCSXHDocument& aDocument)
       
    69     {
       
    70     CCSXHGenericContainer* self = new(ELeave) CCSXHGenericContainer(aDocument);
       
    71     CleanupStack::PushL(self);
       
    72     self->ConstructL(aRect);
       
    73     return self;
       
    74     }
       
    75 #endif
       
    76 
       
    77 #ifdef FF_HELP_TUTORIAL_MERGE
       
    78 CCSXHGenericContainer::CCSXHGenericContainer(CCSXHDocument& aDocument,CCSXHGenericView* aView) : 
       
    79 iDocument(aDocument),iView(aView)
       
    80 #else
       
    81 CCSXHGenericContainer::CCSXHGenericContainer(CCSXHDocument& aDocument) : iDocument(aDocument)
       
    82 #endif
       
    83     {//No implementation required
       
    84     }
       
    85     
       
    86 CCSXHGenericContainer::~CCSXHGenericContainer()
       
    87     {
       
    88     delete iListBox;
       
    89     delete iFindPane;
       
    90     }
       
    91     
       
    92 void CCSXHGenericContainer::ConstructL(const TRect& aRect)
       
    93     {
       
    94     CreateWindowL();
       
    95 
       
    96     CreateAndPopulateListL();
       
    97 
       
    98     iListBox->SetListBoxObserver(this); 
       
    99     SetRect(aRect);
       
   100     ActivateL();    
       
   101     }
       
   102 // --------------------------------------------------------------------------
       
   103 // Does the following
       
   104 // 1) Creates and populates the listbox
       
   105 // 2) Highlights an item in the listbox
       
   106 // 3) Check for MSK
       
   107 // --------------------------------------------------------------------------
       
   108 void CCSXHGenericContainer::CreateAndPopulateListL()
       
   109     {
       
   110     // First phase construction
       
   111     iListBox = new (ELeave) CAknSingleStyleListBox;
       
   112     iListBox->SetContainerWindowL(*this);
       
   113 
       
   114     iListBox->ConstructL(this, 0);
       
   115     iListBox->CreateScrollBarFrameL(ETrue);
       
   116     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   117                                                 CEikScrollBarFrame::EOff,
       
   118                                                 CEikScrollBarFrame::EAuto);
       
   119     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue); 
       
   120               
       
   121     CTextListBoxModel* model = iListBox->Model();  // not taking ownership
       
   122     model->SetOwnershipType (ELbmOwnsItemArray);
       
   123     CDesCArray* testArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
       
   124     
       
   125     CCSXHGenericTOC1* displayTopic = STATIC_CAST(CCSXHGenericTOC1*,iDocument.GetDisplayTopic());
       
   126     
       
   127     displayTopic->FillChildDataL(testArray);
       
   128     
       
   129     //Find panel Begin
       
   130     CAknSearchField::TSearchFieldStyle flags(CAknSearchField::ESearch);
       
   131     iFindPane = CAknSearchField::NewL(*this, flags, 
       
   132                                        NULL,KFindNameLength);
       
   133 
       
   134     STATIC_CAST(CAknFilteredTextListBoxModel*, iListBox->Model())
       
   135         ->CreateFilterL(iListBox, iFindPane);
       
   136     
       
   137     STATIC_CAST(CAknFilteredTextListBoxModel*, iListBox->Model())
       
   138             ->Filter()->HandleOfferkeyEventL();  
       
   139 	//Corrections to TSW Error:  KMAI-6WNACA with New UI CR: EVIA-6XAJ46            
       
   140     if (FeatureManager::FeatureSupported(KFeatureIdJapanese) &&
       
   141         (User::Language() == ELangJapanese))
       
   142         {        
       
   143         iFindPane->Editor().SetAknEditorInputMode(EAknEditorHiraganaKanjiInputMode);
       
   144         }
       
   145     else
       
   146     	{
       
   147     	iFindPane->Editor().SetAknEditorCurrentInputMode(EAknEditorTextInputMode);
       
   148     	}
       
   149 
       
   150     HightLightItemL();    
       
   151     }
       
   152     
       
   153 void CCSXHGenericContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
       
   154     {
       
   155     switch ( aListBoxEvent )
       
   156         {
       
   157         case MEikListBoxObserver::EEventEnterKeyPressed:
       
   158         case MEikListBoxObserver::EEventItemSingleClicked:
       
   159 #ifdef FF_HELP_TUTORIAL_MERGE
       
   160   	        if(IsShowTutorialItemSelectedL())
       
   161 	        	{
       
   162                 CCSXHAppUi::GetInstance()->CallTutorialAiwProviderL();
       
   163 	        	}
       
   164 	        else
       
   165 
       
   166 #endif	        
       
   167 	        	{
       
   168 	        	iDocument.SendMessageToAppUiL( ECSXHOpenItemPropagated );
       
   169 	        	}	        	   
       
   170 
       
   171             break;
       
   172         default:
       
   173             break;// do nothing with the rest of the events
       
   174         }       
       
   175     }
       
   176     
       
   177 void CCSXHGenericContainer::SizeChanged()
       
   178     {
       
   179     iListBox->SetRect(Rect());
       
   180     AknFind::HandleFixedFindSizeChanged(this, iListBox, iFindPane);
       
   181     }
       
   182     
       
   183 void CCSXHGenericContainer::FocusChanged(TDrawNow aDrawNow)
       
   184     {
       
   185     if (iListBox)
       
   186         {
       
   187         iListBox->SetFocus(IsFocused(), aDrawNow);
       
   188         }
       
   189     if ( iFindPane )
       
   190         {
       
   191         iFindPane->SetFocus( IsFocused(), aDrawNow );
       
   192         }
       
   193     }
       
   194         
       
   195 TInt CCSXHGenericContainer::CountComponentControls() const
       
   196     {
       
   197     return KComponentCount;
       
   198     }
       
   199     
       
   200 CCoeControl* CCSXHGenericContainer::ComponentControl(TInt aIndex) const
       
   201     {
       
   202     switch (aIndex)
       
   203         {
       
   204         case 0:
       
   205             return iListBox;
       
   206         case 1:
       
   207             return iFindPane;
       
   208         default:
       
   209             return NULL;
       
   210         }
       
   211     }
       
   212         
       
   213 void CCSXHGenericContainer::Draw(const TRect& aRect) const
       
   214     {
       
   215     CWindowGc& gc = SystemGc();
       
   216     gc.Clear(aRect);
       
   217     }
       
   218     
       
   219 TKeyResponse CCSXHGenericContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   220     {
       
   221     TKeyResponse result(EKeyWasNotConsumed);
       
   222     
       
   223     TBool needRefresh;
       
   224     result = AknFind::HandleFindOfferKeyEventL(aKeyEvent, aType,
       
   225                         this, iListBox, iFindPane, EFalse, needRefresh);
       
   226     CheckForMSK();              
       
   227     if (result == EKeyWasNotConsumed)
       
   228         {
       
   229         result = iListBox->OfferKeyEventL (aKeyEvent, aType);
       
   230         }
       
   231     return result; 
       
   232     }
       
   233     
       
   234 void CCSXHGenericContainer::HandleResourceChange(TInt aType)
       
   235     {
       
   236     CCSXHAppUi::GetInstance()->PropagateResourceChange(aType);
       
   237 
       
   238     if (KAknSplitInputEnabled == aType || KAknSplitInputDisabled == aType)
       
   239         {
       
   240     // Bug fixing, SetFocus can't be called with these aType, it will lead to infinite loop in fep.
       
   241         return;
       
   242         }
       
   243     
       
   244     if ( IsFocused() )
       
   245         {
       
   246         SetFocus( IsFocused(), EDrawNow );
       
   247         }
       
   248 
       
   249     }
       
   250     
       
   251 void CCSXHGenericContainer::HandleResourceChangeImpl(TInt aType)
       
   252     {
       
   253     if (aType == KEikDynamicLayoutVariantSwitch)
       
   254         {
       
   255         iListBox->HandleResourceChange(aType);
       
   256         TRect mainRect; 
       
   257         SizeChanged();
       
   258         TRect statusPaneRect;
       
   259         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainRect);
       
   260         SetRect(mainRect);
       
   261         DrawNow();
       
   262         }
       
   263     else
       
   264         {
       
   265         CCoeControl::HandleResourceChange(aType);   
       
   266         }
       
   267     }
       
   268 // --------------------------------------------------------------------------
       
   269 // Sets the next topic to be displayed based on the selected item
       
   270 // --------------------------------------------------------------------------    
       
   271 void CCSXHGenericContainer::SetDisplayTopicL()
       
   272     {
       
   273     TInt index = iListBox->CurrentItemIndex();
       
   274     if(KErrNotFound == index)
       
   275         return;
       
   276         
       
   277     TBuf<KMaxFileName> selectedTOC2 = iListBox->Model()->ItemText(index);
       
   278     selectedTOC2 = selectedTOC2.Mid(1);
       
   279     
       
   280     CCSXHGenericTOC1* displayTopic = STATIC_CAST(CCSXHGenericTOC1*,iDocument.GetDisplayTopic());
       
   281     if( displayTopic->GetChildL(selectedTOC2) )
       
   282         {
       
   283     	iDocument.SetDisplayAndPrevTopic(displayTopic->GetChildL(selectedTOC2));
       
   284         }
       
   285     }
       
   286 
       
   287 TInt CCSXHGenericContainer::GetNumberOfListItems()
       
   288     {
       
   289     return iListBox->Model()->NumberOfItems();
       
   290     }
       
   291     
       
   292 void CCSXHGenericContainer::SetCurrentView(CCSXHGenericView* aView)
       
   293     {
       
   294     iView = aView;
       
   295     }
       
   296     
       
   297 void CCSXHGenericContainer::HightLightItemL()    
       
   298     {
       
   299     CCSXHHelpContentBase* prevTopic = iDocument.GetPrevTopic();    
       
   300     if(!prevTopic)
       
   301         return;
       
   302         
       
   303     TInt visibleItemcount = GetNumberOfListItems();
       
   304     for (TInt index = 0; index < visibleItemcount ; ++index )
       
   305         {
       
   306         TBuf<KMaxFileName> txt = iListBox->Model()->ItemText(index);
       
   307         txt = txt.Mid(1);//remove the '/t'
       
   308         if(txt.Compare(prevTopic->GetName()) == 0)
       
   309             {
       
   310             if(iListBox->CurrentItemIndex() != index)
       
   311                 iListBox->SetCurrentItemIndex(index);
       
   312             return;
       
   313             }
       
   314         }
       
   315     }
       
   316     
       
   317 void CCSXHGenericContainer::CheckForMSK()   
       
   318     {
       
   319 #ifndef __SERIES60_30__ 
       
   320     if(AknLayoutUtils::MSKEnabled())
       
   321         {   
       
   322         if(iListBox->Model()->NumberOfItems())
       
   323             {
       
   324             iView->SetMiddleSoftKey(ETrue);         
       
   325             }
       
   326         else
       
   327             {
       
   328             iView->SetMiddleSoftKey(EFalse);                
       
   329             }
       
   330         }
       
   331 #endif      
       
   332     }
       
   333       
       
   334 #ifdef FF_HELP_TUTORIAL_MERGE
       
   335 // --------------------------------------------------------------------------
       
   336 // CCSXHAppUi::IsShowTutorialItemSelectedL
       
   337 // If the selected item is a tutorial item.
       
   338 // --------------------------------------------------------------------------
       
   339 TBool CCSXHGenericContainer::IsShowTutorialItemSelectedL()
       
   340     {
       
   341     TBool bShowTutorial = EFalse;
       
   342     //TODO:
       
   343     // if keyword page supported tutorial, the comments should be opened
       
   344     if( 0 != GetNumberOfListItems /*&&  KCSXHKywdToc2ViewID != iView->Id() */)
       
   345         {
       
   346         TInt index = iListBox->CurrentItemIndex();
       
   347         if(KErrNotFound == index)
       
   348             return bShowTutorial;
       
   349         //Get Next View
       
   350         TBuf<KMaxFileName> selectedTOC2 = iListBox->Model()->ItemText(index);
       
   351 
       
   352         selectedTOC2 = selectedTOC2.Mid(1);
       
   353         CCSXHGenericTOC1* displayTopic = STATIC_CAST(CCSXHGenericTOC1*,
       
   354                                                iDocument.GetDisplayTopic());
       
   355         TUid NextViewId = displayTopic->GetChildL(selectedTOC2)->GetViewID();
       
   356 
       
   357         //Check Tutorial is present for Application topic [TOC2]
       
   358         if(NextViewId == KCSXHHtmlTopicViewID)
       
   359             {
       
   360             CCSXHHtmlTOC2* HTMLTOC2Ptr = STATIC_CAST(CCSXHHtmlTOC2*,
       
   361                                       displayTopic->GetChildL(selectedTOC2));
       
   362             TFileName filename;
       
   363             HTMLTOC2Ptr->GetHtmlUrlL( filename );
       
   364             if( KErrNotFound != filename.Find( KTutorialFileExtn ))
       
   365                 {
       
   366                 bShowTutorial = ETrue;
       
   367                 TCoeHelpContext helpContext;
       
   368                 HTMLTOC2Ptr->GetHelpContext(helpContext);
       
   369                 CCSXHAppUi::GetInstance()->SetHelpContext( helpContext );
       
   370                 }
       
   371             }
       
   372         }
       
   373     return bShowTutorial;
       
   374     }
       
   375 
       
   376 #endif // FF_HELP_TUTORIAL_MERGE
       
   377 
       
   378 
       
   379 void CCSXHGenericContainer::MakeVisible(TBool aVisible)
       
   380     {
       
   381     CCoeControl::MakeVisible(aVisible);
       
   382     iListBox->ScrollBarFrame()->ComponentControl(0)->MakeVisible(aVisible);
       
   383     }