accesspointcontrol/apcontrollistplugin/src/apcontrollistplugincontainer.cpp
branchGCC_SURGE
changeset 49 faa5ef4f80da
parent 39 f10336de0cd6
parent 47 cb7afde124a3
equal deleted inserted replaced
39:f10336de0cd6 49:faa5ef4f80da
     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:  APControl list Plugin container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <hlplch.h>          //for help
       
    21 #include <csxhelp/cp.hlp.hrh>
       
    22 
       
    23 
       
    24 #include <akntitle.h>        //for CAknTitlePane
       
    25 #include <barsread.h>        //for TResourceReader
       
    26 #include <aknlists.h>        //for CListBox
       
    27 #include <aknnavi.h>         //for CNaviPane
       
    28 #include <aknnavide.h>       //for CAknNavigationDecorator
       
    29 #include <apcontrollistpluginrsc.rsg>
       
    30 #include <etelmm.h>
       
    31 
       
    32 #include "apcontrollistplugincontainer.h"
       
    33 #include "apcontrollistplugin.h"
       
    34 #include "apcontrollistplugin.hrh"
       
    35 #include "apcontrollistbox.h"
       
    36 #include "apcontrollistboxmodel.h"
       
    37 #include "apcontrollistpluginlogger.h"
       
    38 
       
    39 // CONSTANTS
       
    40 _LIT( KEmpty, "");
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 // ---------------------------------------------------------
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CAPControlListPluginContainer::ConstructL
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 void CAPControlListPluginContainer::ConstructL( const TRect& aRect, 
       
    50                                               MEikListBoxObserver* aListObserver )
       
    51     {       
       
    52     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::ConstructL" ) ) );
       
    53     if ( !iListBox )
       
    54         {
       
    55 
       
    56         TResourceReader rr;
       
    57 
       
    58         //creates resource reader. reader is pushed to cleaup stack
       
    59         ControlEnv()->CreateResourceReaderLC( rr, R_APCONTROL_LISTBOX );
       
    60 
       
    61         CreateWindowL();
       
    62 
       
    63         iListBox = new( ELeave ) CApControlListbox;
       
    64         iListBox->SetContainerWindowL( *this );
       
    65 
       
    66         iListBox->CreateScrollBarFrameL( ETrue );
       
    67         iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
    68                                         CEikScrollBarFrame::EOff, 
       
    69                                         CEikScrollBarFrame::EAuto );
       
    70 
       
    71         iListBox->ConstructFromResourceL( rr );
       
    72 	    
       
    73 	    //Put in empty text thing
       
    74 	    iListBox->SetListEmptyTextL();
       
    75         iListBox->SetListBoxObserver( aListObserver );
       
    76 
       
    77     	iModel = new( ELeave )CApControlListboxModel;
       
    78     	iModel->ConstructL();
       
    79     	iListBox->Model()->SetItemTextArray( iModel );//give ownership of
       
    80     	// iModel to iListBox
       
    81         
       
    82         CleanupStack::PopAndDestroy(); //resource reader
       
    83         
       
    84         SetRect( aRect );
       
    85                                                            
       
    86         HandleResourceChange( KEikDynamicLayoutVariantSwitch );
       
    87         }      
       
    88         
       
    89 
       
    90     TitlePaneTextsL( R_APCLPLUGIN_TITLE );
       
    91     ActivateL();
       
    92     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::ConstructL" ) ) );
       
    93     }
       
    94     
       
    95 // ---------------------------------------------------------
       
    96 // CAPControlListPluginContainer::AddToListBoxL
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 void CAPControlListPluginContainer::AddToListBoxL(TPtrC& newItem)
       
   100     {
       
   101     CLOG( ( ESelector, 0, _L( 
       
   102         "-> CAPControlListPluginContainer::AddToListBoxL" ) ) );
       
   103 	MDesCArray* textArray = iModel->ItemTextArray();
       
   104 	CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);
       
   105 
       
   106 	TBuf<RMobilePhone::KMaxApnName> item;
       
   107 	// RMobilePhone::KMaxApnName - label length + TAB = 
       
   108 	// RMobilePhone::KMaxApnName 
       
   109 	item.Format(_L("\t%S"), &newItem); 
       
   110 	listBoxItems->AppendL(item);
       
   111 
       
   112 	iListBox->HandleItemAdditionL(); // Update listbox
       
   113 	iListBox->SetCurrentItemIndexAndDraw(
       
   114 	    listBoxItems->Count() - 1); // select new item
       
   115     CLOG( ( ESelector, 0, _L( 
       
   116         "<- CAPControlListPluginContainer::AddToListBoxL" ) ) );
       
   117     }
       
   118 // ---------------------------------------------------------
       
   119 // CAPControlListPluginContainer::CurrentItemIndex
       
   120 // ---------------------------------------------------------
       
   121 //
       
   122 TInt CAPControlListPluginContainer::CurrentItemIndex()
       
   123     {
       
   124     CLOG( ( ESelector, 0, _L( 
       
   125         "-> CAPControlListPluginContainer::CurrentItemIndex" ) ) );
       
   126     CLOG( ( ESelector, 0, _L( 
       
   127         "<- CAPControlListPluginContainer::CurrentItemIndex" ) ) );
       
   128 	return iListBox->CurrentItemIndex(); 
       
   129     }
       
   130     
       
   131 // ---------------------------------------------------------
       
   132 // CAPControlListPluginContainer::SetCurrentItemIndex
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 void CAPControlListPluginContainer::SetCurrentItemIndex(TInt index)
       
   136     {
       
   137     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::SetCurrentItemIndex" ) ) );
       
   138 	iListBox->SetCurrentItemIndexAndDraw(index); 
       
   139     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::SetCurrentItemIndex" ) ) );
       
   140     }
       
   141     
       
   142 // ---------------------------------------------------------
       
   143 // CAPControlListPluginContainer::RemoveFromListBoxL
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CAPControlListPluginContainer::RemoveFromListBoxL()
       
   147     {
       
   148     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::RemoveFromListBoxL" ) ) );
       
   149 	TInt currentItem = iListBox->CurrentItemIndex();
       
   150 
       
   151 	MDesCArray* textArray = iModel->ItemTextArray();
       
   152 	CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);
       
   153 	listBoxItems->Delete(currentItem, 1); // 1 = how many items to delete
       
   154 	AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iListBox, currentItem, ETrue);
       
   155 	iListBox->DrawNow(); // Update listbox    
       
   156     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::RemoveFromListBoxL" ) ) );
       
   157 	}
       
   158 
       
   159 // ---------------------------------------------------------
       
   160 // CAPControlListPluginContainer::~CAPControlListPluginContainer
       
   161 // ---------------------------------------------------------
       
   162 //
       
   163 CAPControlListPluginContainer::~CAPControlListPluginContainer()
       
   164     {
       
   165     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::~CAPControlListPluginContainer" ) ) );
       
   166     delete iListBox;
       
   167     if (iNaviPane)
       
   168         {
       
   169         iNaviPane->Pop(iNaviDecorator);        
       
   170         }
       
   171     delete iNaviDecorator;    
       
   172     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::~CAPControlListPluginContainer" ) ) );
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------
       
   176 // CAPControlListPluginContainer::CountComponentControls
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 TInt CAPControlListPluginContainer::CountComponentControls() const
       
   180     {
       
   181     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::CountComponentControls" ) ) );
       
   182     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::CountComponentControls" ) ) );
       
   183     return 1;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CAPControlListPluginContainer::ComponentControl
       
   188 // ---------------------------------------------------------
       
   189 //
       
   190 CCoeControl* CAPControlListPluginContainer::ComponentControl( TInt aIndex ) const
       
   191     {
       
   192     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::ComponentControl" ) ) );
       
   193     switch( aIndex )
       
   194         {
       
   195         case 0 :
       
   196             {
       
   197     		CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::ComponentControl 1" ) ) );
       
   198             return iListBox;
       
   199             }
       
   200         default:
       
   201             {
       
   202     		CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::ComponentControl 2" ) ) );
       
   203             return 0;
       
   204             } 
       
   205         }
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------
       
   209 // CAPControlListPluginContainer::OfferKeyEventL
       
   210 // ---------------------------------------------------------
       
   211 //
       
   212 TKeyResponse CAPControlListPluginContainer::OfferKeyEventL( 
       
   213                                             const TKeyEvent& aKeyEvent, 
       
   214                                             TEventCode aType )
       
   215     {
       
   216     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::OfferKeyEventL" ) ) );
       
   217     TKeyResponse response = EKeyWasNotConsumed;
       
   218     if ( aType == EEventKey )
       
   219         {
       
   220         response = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   221         }
       
   222     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::OfferKeyEventL" ) ) );
       
   223     return response;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // CAPControlListPluginContainer::SizeChanged
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 void CAPControlListPluginContainer::SizeChanged()
       
   231     {
       
   232     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::SizeChanged" ) ) );
       
   233     iListBox->SetRect( Rect() );
       
   234     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::SizeChanged" ) ) );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------
       
   238 // CAPControlListPluginContainer::GetHelpContext()
       
   239 // ---------------------------------------------------------
       
   240 //
       
   241 void CAPControlListPluginContainer::GetHelpContext( TCoeHelpContext& aContext) const
       
   242     {
       
   243     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::GetHelpContext" ) ) );
       
   244     aContext.iMajor = KHelpUidAPControlList;
       
   245     aContext.iContext = KACL_HLP_MAIN;
       
   246     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::GetHelpContext" ) ) );
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // CAPControlListPluginContainer::TitlePaneTextsL
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 void CAPControlListPluginContainer::TitlePaneTextsL( TInt aResourceId )
       
   254     {
       
   255     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::TitlePaneTextsL" ) ) );
       
   256     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   257     CAknTitlePane* titlePane =
       
   258         ( CAknTitlePane* )statusPane->ControlL(
       
   259                             TUid::Uid( EEikStatusPaneUidTitle ) );
       
   260 
       
   261     //creates and sets title. title is pushed to cleanup stack
       
   262     HBufC* title = iEikonEnv->AllocReadResourceLC( aResourceId );
       
   263     titlePane->SetTextL( *title );
       
   264 
       
   265     iNaviPane = STATIC_CAST( CAknNavigationControlContainer*, 
       
   266                  statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   267     
       
   268     iNaviDecorator = iNaviPane->CreateNavigationLabelL( KEmpty );
       
   269     iNaviPane->PushL( *iNaviDecorator );
       
   270 
       
   271     CleanupStack::PopAndDestroy(title);
       
   272     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::TitlePaneTextsL" ) ) );
       
   273     }
       
   274 
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CAPControlListPluginContainer::HandleResourceChange
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 void CAPControlListPluginContainer::HandleResourceChange( TInt aType )
       
   281     {
       
   282     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::HandleResourceChange" ) ) );
       
   283     CCoeControl::HandleResourceChange( aType );
       
   284     if( aType == KEikDynamicLayoutVariantSwitch )
       
   285         {
       
   286         TRect mainPaneRect;
       
   287         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
   288                                            mainPaneRect );
       
   289         SetRect( mainPaneRect );
       
   290         DrawNow();
       
   291         }
       
   292     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::HandleResourceChange" ) ) );
       
   293     }
       
   294     
       
   295 // ---------------------------------------------------------
       
   296 // CAPControlListPluginContainer::FocusChanged
       
   297 // ---------------------------------------------------------
       
   298 //
       
   299 void CAPControlListPluginContainer::FocusChanged( TDrawNow aDrawNow )
       
   300     {
       
   301     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::FocusChanged" ) ) );
       
   302     CCoeControl::FocusChanged( aDrawNow );
       
   303     if( iListBox )
       
   304         {
       
   305         iListBox->SetFocus( IsFocused() );
       
   306         }        
       
   307     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::FocusChanged" ) ) );
       
   308     }
       
   309            
       
   310 // ---------------------------------------------------------
       
   311 // CAPControlListPluginContainer::CurrentItemNameL
       
   312 // ---------------------------------------------------------
       
   313 //
       
   314 TInt CAPControlListPluginContainer::NumberOfItems()  const
       
   315     {
       
   316     CLOG( ( ESelector, 0, _L( "-> CAPControlListPluginContainer::NumberOfItems" ) ) );
       
   317     CLOG( ( ESelector, 0, _L( "<- CAPControlListPluginContainer::NumberOfItems" ) ) );
       
   318     return iListBox->Model()->ItemTextArray()->MdcaCount();
       
   319     }
       
   320     
       
   321 // ---------------------------------------------------------
       
   322 // CAPControlListPluginContainer::WriteToNaviPaneL
       
   323 // ---------------------------------------------------------
       
   324 //
       
   325 void CAPControlListPluginContainer::WriteToNaviPaneL( TInt aResourceId )
       
   326     {
       
   327     CLOG( ( ESelector, 0, 
       
   328         _L( "-> CAPControlListPluginContainer::WriteToNaviPaneL" ) ) );
       
   329     HBufC* text = iCoeEnv->AllocReadResourceLC( aResourceId );
       
   330     if ( iNaviDecorator )
       
   331         {
       
   332         iNaviPane->Pop(iNaviDecorator);
       
   333         delete iNaviDecorator;
       
   334         iNaviDecorator = NULL;// CodeScanner needs this line
       
   335         }
       
   336     iNaviDecorator = iNaviPane->CreateNavigationLabelL( *text );
       
   337     iNaviPane->PushL( *iNaviDecorator );
       
   338     
       
   339     CleanupStack::PopAndDestroy( text );
       
   340     CLOG( ( ESelector, 0, 
       
   341         _L( "<- CAPControlListPluginContainer::WriteToNaviPaneL" ) ) );
       
   342     }
       
   343     
       
   344 // End of File