Arrow key pan
MapControlEvents.cpp
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

  
#include "MapControlEvents.h"

void MapControlEvents::OnAfterDraw(VARIANT display, long viewDrawPhase)
{
}

void MapControlEvents::OnAfterScreenDraw(long hdc)
{
}

void MapControlEvents::OnBeforeScreenDraw(long hdc)
{
}

void MapControlEvents::OnDoubleClick(long button, long shift, long x,
                                     long y, double mapX, double mapY)
{
}

void MapControlEvents::OnExtentUpdated(VARIANT displayTransformation,
                                       VARIANT_BOOL sizeChanged, 
                                       VARIANT newEnvelope)
{
}

void MapControlEvents::OnFullExtentUpdated(VARIANT displayTransformation,
                                           VARIANT newEnvelope)
{
}

void MapControlEvents::OnKeyDown(long keyCode, long shift)
{
  switch(keyCode)
  {
  case 37:    // left arrow
    PanMap(-0.5, 0);
    break;
  case 38:    // up arrow
    PanMap(0, 0.5);
    break;
  case 39:    // right arrow
    PanMap(0.5, 0);
    break;
  case 40:    // down arrow
    PanMap(0, -0.5);
    break;
  default:  ; // ignore all other keys
  }
}

void MapControlEvents::OnKeyUp(long keyCode, long shift)
{
}

void MapControlEvents::OnMapReplaced(VARIANT newMap)
{
}

void MapControlEvents::OnMouseDown(long button, long shift, long x, long y, 
                                   double mapX,double mapY)
{
}

void MapControlEvents::OnMouseMove(long button, long shift, long x, long y,
                                   double mapX, double mapY)
{
}

void MapControlEvents::OnMouseUp(long button, long shift, long x, long y,
                                 double mapX, double mapY)
{
}

void MapControlEvents::OnOleDrop(esriControlsDropAction dropAction, 
                                 VARIANT dataObjectHelper, long* effect, 
                                 long button, long shift, long x, long y)
{
}

void MapControlEvents::OnSelectionChanged()
{
}

void MapControlEvents::OnViewRefreshed(VARIANT ActiveView, long viewDrawPhase,
                                       VARIANT layerOrElement, 
                                       VARIANT envelope)
{
}

// Pans the map by the amount specified
// Given a fraction of the extent (ex: ratioX=.5, pan right by half a screen)
void MapControlEvents::PanMap(double ratioX, double ratioY)
{
  double height;
  double width;
  IEnvelopePtr ipEnv;
  
  // Reset the MapControl's extent
  g_ipMapControl->get_Extent(&ipEnv);
  ipEnv->get_Width(&width);
  ipEnv->get_Height(&height);
  ipEnv->Offset(height * ratioX, width * ratioY);
  g_ipMapControl->put_Extent(ipEnv);
}