mapnavproviderrefapp/src/mnrpmapcontrol.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:  CMnrpMapControl class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h>
       
    20 #include <aknlists.h>
       
    21 #include <barsread.h>
       
    22 #include <aknnotewrappers.h>
       
    23 
       
    24 #include <bitstd.h>
       
    25 #include <bitdev.h>
       
    26 
       
    27 #include <lbsposition.h>
       
    28 
       
    29 #include "debug.h"
       
    30 
       
    31 #include "mnrputils.h"
       
    32 #include "mnrpmapview.h"
       
    33 #include "mnrpmapcontrol.h"
       
    34 
       
    35 const TInt KCodeKeyLeft = 0x34;
       
    36 const TInt KCodeKeyRight = 0x36;
       
    37 const TInt KCodeKeyUp = 0x32;
       
    38 const TInt KCodeKeyDown = 0x38;
       
    39 const TInt KCodeKeyCenter = 0x35;
       
    40 
       
    41 const TInt KCodeKeySelect = EKeyDevice3;
       
    42 const TInt KCodeKeySelect2 = 0x13;
       
    43 
       
    44 const TInt KCodeKeyZoomIn = 42;
       
    45 const TInt KCodeKeyZoomOut = 35;
       
    46 const TInt KCodeKeyZoomIn2 = 0x33;
       
    47 const TInt KCodeKeyZoomOut2 = 0x39;
       
    48 
       
    49 const TRgb KCursorColor( 255, 255, 255 );
       
    50 const TRgb KGridTextColor( 0, 0, 0 );
       
    51 const TRgb KOriginMarkColor( 0, 0, 255 );
       
    52 
       
    53 const TInt KTextFontHeightInTwips = 100;
       
    54 const TInt KItemFontHeightInTwips = 120;
       
    55 const TReal KBorderSizeFactor = 2;
       
    56 
       
    57 const TInt KCursorMarginSize = 20; // pixels
       
    58 const TInt KCursorArrowSize = 4; // pixels
       
    59 const TInt KCursorCircleRadius = 4; // pixels
       
    60 
       
    61 const TInt KCursorMove = 10; // pixels
       
    62 const TInt KWindowMove = 20; // pixels
       
    63 const TReal KJumpFactor = 5;
       
    64 const TReal KCrawlFactor = 2.0 / KCursorMove;
       
    65 
       
    66 const TReal KZoomOutRate = 1.5;
       
    67 const TReal KZoomInRate =  1 / KZoomOutRate;
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CMnrpMapControl::CMnrpMapControl( CMnrpMapView& aView )
       
    73  :  iView( aView )
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CMnrpMapControl::~CMnrpMapControl()
       
    81     {
       
    82     delete iModel;
       
    83     delete iOffScreenBitmap;
       
    84     DestroyFonts();
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CMnrpMapControl* CMnrpMapControl::NewL( 
       
    91     CMnrpMapView& aView,
       
    92     const TRect& aRect,
       
    93     CMnrpEngine& aEngine )
       
    94     {
       
    95     CMnrpMapControl* self = new ( ELeave ) CMnrpMapControl( aView );
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL( aRect, aEngine );
       
    98     CleanupStack::Pop( self );
       
    99     return self;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CMnrpMapControl::UpdateModelL( CMnrpMapViewService& aService )
       
   106     {
       
   107     iModel->UpdateModelL( aService );
       
   108     }
       
   109     
       
   110 // -----------------------------------------------------------------------------
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CMnrpMapControl::SetSelectionModeL( TBool aSelectionMode ) 
       
   114     {
       
   115     iSelectionMode = aSelectionMode;
       
   116     iAbsoluteCursor = iModel->Center();
       
   117     iCursor = iModel->AbsoluteToScreen( iAbsoluteCursor );
       
   118     DrawDeferred();
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TCoordinate CMnrpMapControl::CurrentLocation()
       
   125     {
       
   126     return iAbsoluteCursor;
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CMnrpMapControl::ConstructL( 
       
   133     const TRect& aRect,
       
   134     CMnrpEngine& aEngine )
       
   135     {
       
   136     // Create a window for this application view
       
   137     CreateWindowL();
       
   138 
       
   139     iModel = CMnrpMapModel::NewL( *this, aEngine );
       
   140 
       
   141     // Set the windows size
       
   142     SetRect( aRect );
       
   143     
       
   144     iAbsoluteCursor = TCoordinate( 0, 0 );
       
   145     iCursor = iModel->AbsoluteToScreen( iAbsoluteCursor );
       
   146     
       
   147     CreateFonts();
       
   148     CreateScreenBufferL( aRect.Size() );
       
   149 
       
   150     // Activate the window, which makes it ready to be drawn
       
   151     ActivateL();
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TKeyResponse CMnrpMapControl::OfferKeyEventL(
       
   158     const TKeyEvent& aKeyEvent, 
       
   159     TEventCode /*aType*/ )
       
   160     {
       
   161     TKeyResponse response = EKeyWasConsumed;
       
   162     
       
   163     TInt step = iSelectionMode ? KCursorMove : KWindowMove;
       
   164     TBool isShift = aKeyEvent.iModifiers & EModifierShift;
       
   165     TReal crawlFactor = isShift ? KCrawlFactor : 1;
       
   166 
       
   167     TInt xmove = 0;
       
   168     TInt ymove = 0;
       
   169     
       
   170     TBool redraw = ETrue;
       
   171 
       
   172     switch ( aKeyEvent.iCode )
       
   173         {
       
   174         case EKeyLeftArrow:
       
   175             xmove = -step * crawlFactor;
       
   176             break;
       
   177 
       
   178         case KCodeKeyLeft:
       
   179             xmove = -step * KJumpFactor;
       
   180             break;
       
   181 
       
   182         case EKeyRightArrow:
       
   183             xmove = step * crawlFactor;
       
   184             break;
       
   185 
       
   186         case KCodeKeyRight:
       
   187             xmove = step * KJumpFactor;
       
   188             break;
       
   189 
       
   190         case EKeyUpArrow:
       
   191             ymove = -step * crawlFactor;
       
   192             break;
       
   193 
       
   194         case KCodeKeyUp:
       
   195         case EKeyPageUp:
       
   196             ymove = -step * KJumpFactor;
       
   197             break;
       
   198 
       
   199         case EKeyDownArrow:
       
   200             ymove = step * crawlFactor;
       
   201             break;
       
   202             
       
   203         case KCodeKeyDown:
       
   204         case EKeyPageDown:
       
   205             ymove = step * KJumpFactor;
       
   206             break;
       
   207 
       
   208         case KCodeKeyZoomIn:
       
   209         case KCodeKeyZoomIn2:
       
   210             Zoom( KZoomInRate );
       
   211             break;
       
   212 
       
   213         case KCodeKeyZoomOut:
       
   214         case KCodeKeyZoomOut2:
       
   215             Zoom( KZoomOutRate );
       
   216             break;
       
   217 
       
   218         case KCodeKeyCenter:
       
   219             iModel->GoCenter();
       
   220             iCursor = iModel->AbsoluteToScreen( TCoordinate( 0, 0 ) );
       
   221             break;
       
   222 
       
   223         case KCodeKeySelect:
       
   224         case KCodeKeySelect2:
       
   225             if ( iSelectionMode )
       
   226                 {
       
   227                 iView.HandleUserSelectionL( KErrNone );
       
   228                 redraw = EFalse;
       
   229                 }
       
   230             break;
       
   231 
       
   232         default:
       
   233             response = EKeyWasNotConsumed;
       
   234             redraw = EFalse;
       
   235             break;
       
   236         }
       
   237 
       
   238     if ( xmove || ymove )
       
   239         {
       
   240         if ( iSelectionMode )
       
   241             {
       
   242             MoveCursor( xmove, ymove );
       
   243             }
       
   244         else
       
   245             {
       
   246             TCoordinate center = iModel->Center();
       
   247             TCoordinate moveTo( 
       
   248                 center.Latitude() - iModel->ScreenToAbsolute( ymove ),
       
   249                 center.Longitude() + iModel->ScreenToAbsolute( xmove ) );
       
   250             iModel->MoveTo( moveTo );
       
   251             }
       
   252         }
       
   253 
       
   254     if ( redraw )
       
   255         {
       
   256         RenderL();
       
   257         DrawDeferred();
       
   258         }
       
   259 
       
   260     return response;
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CMnrpMapControl::HandleModelUpdateL()
       
   267     {
       
   268     RenderL();
       
   269     DrawDeferred();
       
   270     
       
   271     TInt ignored = iModel->NumIgnoredLandmarks();
       
   272     if ( ignored )
       
   273     	{
       
   274         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   275         _LIT( KMessageIgnoredLm, "One landmark\nhas no coordinates\nand can't be shown." );
       
   276         _LIT( KMessageIgnoredLms, "%d landmarks\nhave no coordinates\nand can't be shown." );
       
   277         if ( ignored == 1 )
       
   278         	{
       
   279         	note->ExecuteLD( KMessageIgnoredLm() );
       
   280         	}
       
   281         else
       
   282         	{
       
   283             TBuf<64> message;
       
   284         	message.Format( KMessageIgnoredLms, ignored );
       
   285         	note->ExecuteLD( message );
       
   286         	}
       
   287     	}
       
   288     }
       
   289     
       
   290 // -----------------------------------------------------------------------------
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CMnrpMapControl::CreateScreenBufferL( const TSize& aSize )
       
   294 	{
       
   295 	CGraphicsDevice* screenDevice = iEikonEnv->ScreenDevice();
       
   296 
       
   297 	// create a bitmap to be used off-screen
       
   298 	CFbsBitmap* offScreenBitmap = new (ELeave) CFbsBitmap();
       
   299 	User::LeaveIfError( offScreenBitmap->Create( aSize, screenDevice->DisplayMode() ) );
       
   300 	CleanupStack::PushL( offScreenBitmap );
       
   301 
       
   302 	if ( iOffScreenBitmap )
       
   303 		{
       
   304 		delete iOffScreenBitmap;
       
   305 		}
       
   306 	iOffScreenBitmap = offScreenBitmap;
       
   307 
       
   308 	CleanupStack::Pop( offScreenBitmap );
       
   309 	}
       
   310 
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 void CMnrpMapControl::CreateFonts()
       
   316 	{
       
   317     CGraphicsDevice* screenDevice = iEikonEnv->ScreenDevice();
       
   318 
       
   319     const CFont* denseFont = iEikonEnv->DenseFont();
       
   320     TFontSpec fs = denseFont->FontSpecInTwips();
       
   321 
       
   322     fs.iHeight = KTextFontHeightInTwips;
       
   323     screenDevice->GetNearestFontInTwips( iTextFont, fs );
       
   324     
       
   325     fs.iHeight = KItemFontHeightInTwips;
       
   326     screenDevice->GetNearestFontInTwips( iItemFont, fs );
       
   327 	}
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CMnrpMapControl::DestroyFonts()
       
   333 	{
       
   334 	CGraphicsDevice* screenDevice = iEikonEnv->ScreenDevice();
       
   335 	
       
   336     screenDevice->ReleaseFont( iItemFont );
       
   337     iItemFont = NULL;
       
   338     screenDevice->ReleaseFont( iTextFont );
       
   339     iTextFont = NULL;
       
   340 	}
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CMnrpMapControl::Draw( const TRect& /*aRect*/ ) const
       
   346     {
       
   347     // Get the standard graphics context
       
   348     CWindowGc& gc = SystemGc();
       
   349 
       
   350     TRect rect = Rect();
       
   351     TRect border( rect );
       
   352     border.Shrink( BorderSize() );
       
   353 	
       
   354     gc.Clear( TRect( rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, border.iBr.iY ) );
       
   355     gc.Clear( TRect( rect.iTl.iX, border.iBr.iY, rect.iBr.iX, rect.iBr.iY ) );
       
   356     gc.Clear( TRect( rect.iTl.iX, border.iTl.iY, border.iTl.iX, border.iBr.iY ) );
       
   357     gc.Clear( TRect( border.iBr.iX, border.iTl.iY, rect.iBr.iX, border.iBr.iY ) );
       
   358 
       
   359     CMnrpMapModel::TGrid grid;
       
   360     iModel->GetGrid( grid );
       
   361     DrawGridText( gc, border, rect, iTextFont, grid );
       
   362 
       
   363 	if ( iOffScreenBitmap )
       
   364 		{
       
   365 		gc.BitBlt( border.iTl, iOffScreenBitmap );
       
   366 		}
       
   367 	else
       
   368 		{
       
   369 		gc.Clear();	
       
   370 		}
       
   371 			
       
   372     if ( iSelectionMode )
       
   373         {
       
   374         gc.SetOrigin( border.iTl );
       
   375         DrawCursor( gc );
       
   376         }
       
   377 
       
   378     // draw border
       
   379     gc.SetPenColor( KRgbGray );
       
   380     gc.SetPenSize( TSize( 1, 1 ) );
       
   381     gc.SetOrigin( rect.iTl );
       
   382     gc.DrawRect( border );
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void CMnrpMapControl::DrawGridText( 
       
   389     CWindowGc& aGc, 
       
   390     const TRect& aInnerBox,
       
   391     const TRect& aOuterBox,
       
   392     const CFont* aFont,
       
   393     CMnrpMapModel::TGrid& aGrid ) const
       
   394     {
       
   395     aGc.UseFont( aFont );
       
   396     
       
   397     TBuf<KMaxCoordStrSize> latTopStr, latBottomStr, lonLeftStr, lonRightStr;
       
   398     TBuf<KMaxCoordStrSize> gridMajorStr, latStr, lonStr;
       
   399     
       
   400     MnrpUtils::CoordinateToString( iModel->Left(), lonLeftStr, ETrue );
       
   401     MnrpUtils::CoordinateToString( iModel->Top(), latTopStr, ETrue );
       
   402     MnrpUtils::CoordinateToString( iModel->Right(), lonRightStr, ETrue );
       
   403     MnrpUtils::CoordinateToString( iModel->Bottom(), latBottomStr, ETrue );
       
   404 
       
   405     if ( !iSelectionMode )
       
   406         {
       
   407         MnrpUtils::CoordinateToString( ( iModel->Right() + iModel->Left() ) / 2, lonStr, ETrue );
       
   408         MnrpUtils::CoordinateToString( ( iModel->Top() + iModel->Bottom() ) / 2, latStr, ETrue );
       
   409         }
       
   410     else
       
   411         {
       
   412         MnrpUtils::CoordinateToString( iAbsoluteCursor.Longitude(), lonStr, ETrue );
       
   413         MnrpUtils::CoordinateToString( iAbsoluteCursor.Latitude(), latStr, ETrue );
       
   414         }
       
   415 
       
   416     MnrpUtils::CoordinateToString( aGrid.iAbsoluteGridStep, gridMajorStr );
       
   417 
       
   418     TRect lonBox( aInnerBox.iTl.iX, 0, aInnerBox.iBr.iX, aInnerBox.iBr.iY );
       
   419     TRect latBox( 0, aInnerBox.iTl.iY, aInnerBox.iTl.iX, aInnerBox.iBr.iY );
       
   420     TRect centerBox( aInnerBox.iTl.iX, aInnerBox.iBr.iY, aInnerBox.iBr.iX, aOuterBox.iBr.iY );
       
   421 
       
   422     TInt textBaseLine = aFont->AscentInPixels() + KBorderSizeFactor / 2;
       
   423     TInt vertTextBaseLine = aFont->AscentInPixels() + KBorderSizeFactor / 2;
       
   424 
       
   425     aGc.SetPenColor( KGridTextColor );
       
   426 
       
   427     aGc.DrawText( lonLeftStr, lonBox, textBaseLine, CGraphicsContext::ELeft );
       
   428     aGc.DrawText( lonRightStr, lonBox, textBaseLine, CGraphicsContext::ERight );
       
   429     aGc.DrawTextVertical( latTopStr, latBox, vertTextBaseLine, EFalse, CGraphicsContext::ELeft );
       
   430     aGc.DrawTextVertical( latBottomStr, latBox, vertTextBaseLine, EFalse, CGraphicsContext::ERight );
       
   431 
       
   432     aGc.DrawText( gridMajorStr, lonBox, textBaseLine, CGraphicsContext::ECenter );
       
   433 
       
   434     aGc.SetPenColor( KOriginMarkColor );
       
   435     aGc.DrawText( latStr, centerBox, textBaseLine, CGraphicsContext::ELeft );
       
   436     aGc.DrawText( lonStr, centerBox, textBaseLine, CGraphicsContext::ERight );
       
   437     
       
   438     aGc.DiscardFont();
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CMnrpMapControl::DrawCursor( CWindowGc& aGc ) const
       
   445     {
       
   446     aGc.SetPenColor( KCursorColor );
       
   447     aGc.SetPenSize( TSize( 1, 1 ) );
       
   448     aGc.SetDrawMode( CGraphicsContext::EDrawModeNOTSCREEN );
       
   449     
       
   450     TRect cursorCircleRect( iCursor, TSize( 0, 0 ) );
       
   451     cursorCircleRect.Grow( KCursorCircleRadius, KCursorCircleRadius );
       
   452     aGc.DrawEllipse( cursorCircleRect );
       
   453     
       
   454     // upper vertical line
       
   455     aGc.DrawLine( TPoint( iCursor.iX, cursorCircleRect.iTl.iY ), 
       
   456                   TPoint( iCursor.iX, cursorCircleRect.iTl.iY - KCursorArrowSize ) );
       
   457     // lower vertical line
       
   458     aGc.DrawLine( TPoint( iCursor.iX, cursorCircleRect.iBr.iY ), 
       
   459                   TPoint( iCursor.iX, cursorCircleRect.iBr.iY + KCursorArrowSize ) );
       
   460 
       
   461     // left horiz line
       
   462     aGc.DrawLine( TPoint( cursorCircleRect.iTl.iX, iCursor.iY ), 
       
   463                   TPoint( cursorCircleRect.iTl.iX - KCursorArrowSize, iCursor.iY ) );
       
   464     // right horiz line
       
   465     aGc.DrawLine( TPoint( cursorCircleRect.iBr.iX, iCursor.iY ), 
       
   466                   TPoint( cursorCircleRect.iBr.iX + KCursorArrowSize, iCursor.iY ) );
       
   467 
       
   468     aGc.SetDrawMode( CGraphicsContext::EDrawModePEN );
       
   469     }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CMnrpMapControl::SizeChanged()
       
   475     {
       
   476     TRect rect( Rect() );
       
   477     
       
   478     DestroyFonts();
       
   479     CreateFonts();
       
   480     
       
   481     rect.Shrink( BorderSize() );
       
   482     iViewSize = rect.Size();
       
   483     iModel->SetScreenSize( iViewSize );
       
   484     TRAP_IGNORE( CreateScreenBufferL( rect.Size() ) );
       
   485     TRAP_IGNORE( RenderL() );
       
   486     DrawDeferred();
       
   487     }
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void CMnrpMapControl::HandleResourceChange( TInt aType )
       
   493     {
       
   494     CCoeControl::HandleResourceChange( aType );
       
   495     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   496         {
       
   497         SetFullScreen( iIsFullScreen );
       
   498         }
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 void CMnrpMapControl::ToggleFullScreen()
       
   505     {
       
   506     SetFullScreen( !iIsFullScreen );
       
   507     }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 void CMnrpMapControl::SetFullScreen( TBool aFullScreen )
       
   513     {
       
   514     iIsFullScreen = aFullScreen;
       
   515     if ( iIsFullScreen)
       
   516         {
       
   517         SetExtentToWholeScreen();
       
   518         }
       
   519     else
       
   520         {
       
   521         SetRect( iView.ClientRect() );
       
   522         }
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CMnrpMapControl::MoveCursor( TInt aXmove, TInt aYmove )
       
   529     {
       
   530     iCursor += TPoint( aXmove, aYmove );
       
   531 
       
   532     iCursor.iX = Max( 0, iCursor.iX );
       
   533     iCursor.iX = Min( iViewSize.iWidth, iCursor.iX );
       
   534 
       
   535     iCursor.iY = Max( 0, iCursor.iY );
       
   536     iCursor.iY = Min( iViewSize.iHeight, iCursor.iY );
       
   537 
       
   538     // verify cursor margin
       
   539     TRect cursorMargin = CursorMargin();
       
   540     
       
   541     iAbsoluteCursor = iModel->ScreenToAbsolute( iCursor );
       
   542     
       
   543     TReal xcorrection = 0;
       
   544     TReal ycorrection = 0;
       
   545 
       
   546     if ( aXmove > 0 ) // moving right
       
   547         {
       
   548         TInt toMargin = iCursor.iX - cursorMargin.iBr.iX;
       
   549         if ( toMargin > 0 ) // cursor went beyond cursor margin, move view
       
   550             {
       
   551             xcorrection = iModel->ScreenToAbsolute( toMargin );
       
   552             }
       
   553         }
       
   554     else if ( aXmove < 0 ) // moving left
       
   555         {
       
   556         TInt toMargin = iCursor.iX - cursorMargin.iTl.iX;
       
   557         if ( toMargin < 0 )
       
   558             {
       
   559             xcorrection = iModel->ScreenToAbsolute( toMargin );
       
   560             }
       
   561         }
       
   562 
       
   563     if ( aYmove > 0 ) // moving down
       
   564         {
       
   565         TInt toMargin = iCursor.iY - cursorMargin.iBr.iY;
       
   566         if ( toMargin > 0 )
       
   567             {
       
   568             ycorrection = -iModel->ScreenToAbsolute( toMargin );
       
   569             }
       
   570         }
       
   571     else if ( aYmove < 0 ) // moving up
       
   572         {
       
   573         TInt toMargin = iCursor.iY - cursorMargin.iTl.iY;
       
   574         if ( toMargin < 0 )
       
   575             {
       
   576             ycorrection = -iModel->ScreenToAbsolute( toMargin );
       
   577             }
       
   578         }
       
   579     
       
   580     TCoordinate center = iModel->Center();
       
   581     TCoordinate moveTo( 
       
   582         center.Latitude() + ycorrection,
       
   583         center.Longitude() + xcorrection );
       
   584     iModel->MoveTo( moveTo );
       
   585 
       
   586     iCursor = iModel->AbsoluteToScreen( iAbsoluteCursor );
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 TRect CMnrpMapControl::CursorMargin()
       
   593     {
       
   594     TRect rect( iViewSize );
       
   595     rect.Shrink( KCursorMarginSize, KCursorMarginSize );
       
   596     return rect;
       
   597     }
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 void CMnrpMapControl::Zoom( TReal aRate )
       
   603     {
       
   604     if ( iSelectionMode )
       
   605         {
       
   606         iModel->MoveTo( iAbsoluteCursor );
       
   607         iModel->Zoom( aRate );
       
   608         iCursor = iModel->AbsoluteToScreen( iAbsoluteCursor );
       
   609         }
       
   610     else
       
   611         {
       
   612         iModel->Zoom( aRate );
       
   613         }
       
   614     }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // -----------------------------------------------------------------------------
       
   618 //
       
   619 TSize CMnrpMapControl::BorderSize() const 
       
   620     {
       
   621 	TSize size( 0, 0 );
       
   622 	if ( iTextFont )
       
   623 		{
       
   624 	    TInt fontHeight = iTextFont->HeightInPixels();
       
   625 	    
       
   626 	    size.iWidth = size.iHeight = TInt( fontHeight + KBorderSizeFactor );
       
   627 		}
       
   628     return size;
       
   629     }
       
   630 
       
   631 // -----------------------------------------------------------------------------
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 void CMnrpMapControl::RenderL()
       
   635     {
       
   636     TRect rect = Rect();
       
   637     TRect border( rect );
       
   638     border.Shrink( BorderSize() );
       
   639 
       
   640     if ( iOffScreenBitmap && iTextFont && iItemFont )
       
   641         {
       
   642         iModel->RenderL( *iOffScreenBitmap, TRect( border.Size() ), iTextFont, iItemFont );
       
   643         }
       
   644     }