mapnavproviderrefapp/src/mnrpnavicontrol.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     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:  CMnrpNaviControl class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <coemain.h>
       
    21 #include <aknlists.h>
       
    22 #include <barsread.h>
       
    23 
       
    24 #include <aknlists.h>
       
    25 
       
    26 #include "mnrpnavimodel.h"
       
    27 #include "mnrpnaviview.h"
       
    28 #include "mnrpnavicontrol.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CMnrpNaviControl::CMnrpNaviControl( CMnrpNaviView& aView )
       
    36  :  iView( aView )
       
    37     { 
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CMnrpNaviControl::~CMnrpNaviControl()
       
    44     {
       
    45     delete iListBox;
       
    46     delete iModel;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMnrpNaviControl* CMnrpNaviControl::NewL( 
       
    53     CMnrpNaviView& aView, 
       
    54     const TRect& aRect,
       
    55     CMnrpEngine& aEngine )
       
    56     {
       
    57     CMnrpNaviControl* self = new (ELeave) CMnrpNaviControl( aView );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aRect, aEngine );
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CMnrpNaviControl::ConstructL( const TRect& aRect, CMnrpEngine& aEngine )
       
    68     {
       
    69     // Create a window for this application view
       
    70     CreateWindowL();
       
    71     CreateListBoxL();
       
    72     
       
    73     // Set the windows size
       
    74     SetRect( aRect );
       
    75     
       
    76     iModel = CMnrpNaviModel::NewL( *this, aEngine );
       
    77 
       
    78     // Activate the window, which makes it ready to be drawn
       
    79     ActivateL();
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CMnrpNaviControl::UpdateModelL( CPosLandmark& aDestination )
       
    86     {
       
    87     iModel->SetDestinationL( aDestination );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CMnrpNaviControl::HandleModelUpdateL()
       
    94     {
       
    95     TArray< CMnrpNaviModel::CListItem* > items = iModel->ListItemsL();
       
    96     
       
    97     const TInt KGranularity = 8;
       
    98     CDesCArraySeg* array = new (ELeave) CDesCArraySeg( KGranularity );
       
    99     CleanupStack::PushL( array );
       
   100     
       
   101     _LIT( KItemFormat, "%S\t%S\t\t" );
       
   102     for ( TInt i = 0; i < items.Count(); i++ )
       
   103         {
       
   104         CMnrpNaviModel::CListItem* item = items[i];
       
   105 
       
   106         const TInt KNumTabsAndOther = 10;
       
   107         HBufC* text = HBufC::NewLC(
       
   108             item->Header().Length() + item->Value().Length() + KNumTabsAndOther);
       
   109 
       
   110         text->Des().Format( KItemFormat, &(item->Header()), &(item->Value()) );
       
   111         
       
   112         array->AppendL( *text );
       
   113         CleanupStack::PopAndDestroy( text );
       
   114         }
       
   115         
       
   116     CleanupStack::Pop( array );
       
   117 
       
   118     CTextListBoxModel* model = iListBox->Model();
       
   119     model->SetItemTextArray( array );
       
   120     model->SetOwnershipType( ELbmOwnsItemArray );
       
   121     iListBox->HandleItemAdditionL();
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CMnrpNaviControl::CountComponentControls() const 
       
   128     { 
       
   129     return 1; 
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 CCoeControl* CMnrpNaviControl::ComponentControl(TInt aIndex) const
       
   136     {
       
   137     return (aIndex == 0) ? iListBox : NULL;
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TKeyResponse CMnrpNaviControl::OfferKeyEventL(
       
   144     const TKeyEvent& aKeyEvent, TEventCode aType)
       
   145     {
       
   146     TKeyResponse response = EKeyWasNotConsumed;
       
   147 
       
   148     switch (aKeyEvent.iCode)
       
   149         {
       
   150         case EKeyUpArrow:
       
   151         case EKeyDownArrow:
       
   152             // Scrolling the listbox. Forward to iListBox.
       
   153             response = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   154             break;
       
   155 
       
   156         case EKeyLeftArrow:
       
   157         case EKeyRightArrow:
       
   158             // Eat these to disable switching views
       
   159             response = EKeyWasConsumed;
       
   160             break;
       
   161 
       
   162         case EKeyDevice3:
       
   163             response = EKeyWasConsumed;
       
   164             break;
       
   165 
       
   166         default:
       
   167             // menu keys should be handled
       
   168             break;
       
   169         }
       
   170 
       
   171     return response;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CMnrpNaviControl::CreateListBoxL()
       
   178     {
       
   179     // Create a control to display a list of descriptors
       
   180     iListBox = new (ELeave) CAknSingleHeadingStyleListBox();
       
   181     iListBox->SetContainerWindowL( *this );
       
   182     iListBox->ConstructL(this, CEikListBox::EViewerFlag );
       
   183 
       
   184     // Create scrollbars
       
   185     CEikScrollBarFrame* scrollBar = iListBox->CreateScrollBarFrameL();
       
   186     scrollBar->SetScrollBarVisibilityL(
       
   187                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CMnrpNaviControl::SizeChanged()
       
   194     {
       
   195     iListBox->SetRect( Rect() );
       
   196     iListBox->DrawDeferred();
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CMnrpNaviControl::HandleResourceChange( TInt aType )
       
   203     {
       
   204     CCoeControl::HandleResourceChange( aType );
       
   205     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   206         {
       
   207         SetRect( iView.ClientRect() );
       
   208         }
       
   209     }