mapnavproviderrefapp/src/mnrpmapview.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:  CMnrpMapView class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <lbsposition.h>
       
    21 
       
    22 #include <eikmenup.h>
       
    23 #include <eikbtgpc.h>
       
    24 #include <avkon.rsg>
       
    25 
       
    26 #include <mnrefprovider.rsg>
       
    27 #include "mnrp.hrh"
       
    28 
       
    29 #include "debug.h"
       
    30 
       
    31 #include "mnrputils.h"
       
    32 #include "mnrpengine.h"
       
    33 
       
    34 #include "mnrpappui.h"
       
    35 #include "mnrpmapview.h"
       
    36 #include "mnrpmapcontrol.h"
       
    37 #include "mnrpmapviewservice.h"
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMnrpMapView::CMnrpMapView( CMnrpEngine& aEngine ) 
       
    45 : iEngine( aEngine )
       
    46     {
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMnrpMapView::~CMnrpMapView()
       
    53     {
       
    54     TRAP_IGNORE( HandleUserSelectionL( KErrCancel ) );
       
    55     delete iControl;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CMnrpMapView* CMnrpMapView::NewL( TBool aChained, CMnrpEngine& aEngine )
       
    62     {
       
    63     CMnrpMapView* self = new (ELeave) CMnrpMapView( aEngine );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( aChained );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CMnrpMapView::ConstructL( TBool aChained )
       
    74     {
       
    75     iChained = aChained;
       
    76     if ( aChained )
       
    77         {
       
    78         BaseConstructL( R_MNREFPROVIDER_MAP_VIEW_CHAINED );
       
    79         }
       
    80     else
       
    81         {
       
    82         BaseConstructL( R_MNREFPROVIDER_MAP_VIEW );
       
    83         }
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CMnrpMapView::SetMapModeL( CMnrpMapViewService& aService )
       
    90     {
       
    91     iSelectionCallback = NULL;
       
    92     iMapViewService = &aService;
       
    93 /*
       
    94     if ( iChained )
       
    95         {
       
    96         Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
    97         }
       
    98     else
       
    99         {
       
   100         Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_EXIT );
       
   101         }
       
   102 */        
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CMnrpMapView::SetSelectionModeL( 
       
   109     CMnrpMapViewService& aService,  
       
   110     MMapSelectionCallback& aCallback )
       
   111     {
       
   112     iMapViewService = &aService;
       
   113     iSelectionCallback = &aCallback;
       
   114     Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_CANCEL );
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CMnrpMapView::StopSelection()
       
   121     {
       
   122     iSelectionCallback = NULL;
       
   123     iMapViewService = NULL;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CMnrpMapView::HandleUserSelectionL( TInt aError )
       
   130     {
       
   131     if ( iSelectionCallback && iControl )
       
   132         {
       
   133         if ( !aError )
       
   134             {
       
   135             iSelectionCallback->HandleSelectionL( iControl->CurrentLocation() );
       
   136             }
       
   137         else
       
   138             {
       
   139             iSelectionCallback->HandleSelectionErrorL( aError );
       
   140             }
       
   141         iSelectionCallback = NULL;            
       
   142         }
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TUid CMnrpMapView::Id() const
       
   149     {
       
   150     return TUid::Uid( EMnrpMapViewId );
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CMnrpMapView::HandleCommandL( TInt aCommand )
       
   157     {
       
   158     switch ( aCommand )
       
   159         {
       
   160         case EMnrpCommandFullScreen:
       
   161             if ( iControl ) 
       
   162                 {
       
   163                 iControl->ToggleFullScreen();
       
   164                 }
       
   165             break;
       
   166 
       
   167         case EMnrpCommandSelect:
       
   168             HandleUserSelectionL( KErrNone );
       
   169             break;
       
   170 
       
   171         case EEikCmdExit:
       
   172         case EAknSoftkeyBack:
       
   173         case EAknSoftkeyExit:
       
   174             HandleUserSelectionL( KErrCancel );
       
   175             AppUi()->HandleCommandL( aCommand );
       
   176             break;
       
   177 
       
   178         default:
       
   179             AppUi()->HandleCommandL( aCommand );
       
   180             break;
       
   181         }
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CMnrpMapView::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane *aMenuPane )
       
   188     {
       
   189     if ( aResourceId == R_MNREFPROVIDER_MAP_VIEW_MENU )
       
   190         {
       
   191         TBool isSelectionMode = iSelectionCallback != NULL;
       
   192         aMenuPane->SetItemDimmed( EMnrpCommandSelect, !isSelectionMode );
       
   193         }
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMnrpMapView::DoActivateL(
       
   200     const TVwsViewId& /*aPrevViewId*/,
       
   201     TUid /* aCustomMessageId */,
       
   202     const TDesC8& /* aCustomMessage */)
       
   203     {
       
   204     if ( !iControl )
       
   205         {
       
   206         iControl = CMnrpMapControl::NewL( *this, ClientRect(), iEngine );
       
   207         iControl->SetMopParent( this );
       
   208         }
       
   209 
       
   210     iControl->SetRect( ClientRect() );
       
   211     if ( iMapViewService )
       
   212         {
       
   213         iControl->UpdateModelL( *iMapViewService );
       
   214         }
       
   215     iControl->SetSelectionModeL( ( iSelectionCallback == NULL ) ? EFalse : ETrue );
       
   216 
       
   217     // Enable receiving of keyboard events.
       
   218     CMnrpAppUi* ui = ( CMnrpAppUi* ) AppUi();
       
   219     ui->AddToStackL( *this, iControl );
       
   220 
       
   221     if ( iSelectionCallback )
       
   222         {
       
   223         ui->SetNaviPaneTitleL( iMapViewService->SelectionRequestText() );
       
   224         }
       
   225     else
       
   226         {
       
   227         _LIT( KMapView, "MapView" );
       
   228 	    ui->SetNaviPaneTitleL( KMapView );
       
   229         }
       
   230 
       
   231     // Make view visible.
       
   232     iControl->MakeVisible( ETrue );
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CMnrpMapView::DoDeactivate()
       
   239     {
       
   240     if ( iControl )
       
   241         {
       
   242         // Hide view.
       
   243         iControl->MakeVisible( EFalse );
       
   244 
       
   245         // Disable receiving keyboard events.
       
   246         AppUi()->RemoveFromStack( iControl );
       
   247         }
       
   248     }
       
   249