Overview
PageLayoutControlEvents.cpp
// Copyright 2011 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 "PageLayoutControlEvents.h"

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

void PageLayoutControlEvents::OnAfterScreenDraw(long hdc)
{
}

void PageLayoutControlEvents::OnBeforeScreenDraw(long hdc)
{
} 

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

void PageLayoutControlEvents::OnExtentUpdated(VARIANT displayTransformation,
                                              VARIANT_BOOL sizeChanged, 
                                              VARIANT newEnvelope)
{
  // Get the IElement interface by finding an element by its name
  IElementPtr ipElement = 0;
  g_ipOverviewPageLayout->FindElementByName(CComBSTR(L"ZoomExtent"), 1, 
                                            &ipElement);
  if (ipElement != 0)
  {
    // Delete it
    IGraphicsContainerPtr ipGraphicsContainer;
    g_ipOverviewPageLayout->get_GraphicsContainer(&ipGraphicsContainer);
    ipGraphicsContainer->DeleteElement(ipElement);
  }

  ipElement = IElementPtr(CLSID_RectangleElement);

  CreateOverviewSymbol();

  // QI for IFillShapeElement interface through IElement interface
  IFillShapeElementPtr ipFillShapeElement = ipElement;
  ipFillShapeElement->put_Symbol(g_ipFillSymbol);

  // Add the element
  CComVariant noParam;
  noParam.vt = VT_ERROR;
  noParam.scode = DISP_E_PARAMNOTFOUND;
  g_ipOverviewPageLayout->AddElement(ipElement, newEnvelope, noParam,
                                     CComVariant(L"ZoomExtent"), 0);
  // Refresh the graphics
  g_ipOverviewPageLayout->Refresh(esriViewGraphics);
}

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

void PageLayoutControlEvents::OnKeyDown(long keyCode, long shift)
{
}

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

void PageLayoutControlEvents::OnFocusMapChanged()
{
}

void PageLayoutControlEvents::OnPageLayoutReplaced(VARIANT newPageLayout)
{
  // Get file path
  char* fileName = XmTextGetString(g_loadText);

  // Validate and load the doc into the overview window
  VARIANT_BOOL varBool;
  g_ipOverviewPageLayout->CheckMxFile(CComBSTR(fileName), &varBool);
  if (varBool)
    g_ipOverviewPageLayout->LoadMxFile(CComBSTR(fileName));
}

void PageLayoutControlEvents::OnPageSizeChanged()
{
}

void PageLayoutControlEvents::OnMouseDown(long button, long shift, long x, 
                                          long y, double mapX, double mapY)
{
  if (button == 1)
  {
    // Zoom in
    IEnvelopePtr ipEnv;
    g_ipMainPageLayout->TrackRectangle(&ipEnv);
    g_ipMainPageLayout->put_Extent(ipEnv);
  }
  else if (button == 2)
  {
    // Pan
    g_ipMainPageLayout->Pan();
  }
}

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

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

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

void PageLayoutControlEvents::OnSelectionChanged()
{
}

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

HRESULT PageLayoutControlEvents::CreateOverviewSymbol()
{  
  // IRgbColor interface
  IRgbColorPtr ipColor(CLSID_RgbColor);
  ipColor->put_Red(255);
  ipColor->put_Green(0);
  ipColor->put_Blue(0);
  ipColor->put_Transparency(255);
  
  // ILine symbol interface
  ILineSymbolPtr ipOutline(CLSID_SimpleLineSymbol);
  ipOutline->put_Width(2);
  ipOutline->put_Color(ipColor);
  
  // Set color properties
  ipColor = IRgbColorPtr(CLSID_RgbColor);
  ipColor->put_Red(255);
  ipColor->put_Green(0);
  ipColor->put_Blue(0);
  ipColor->put_Transparency(0);
  
  // IFillSymbol properties
  g_ipFillSymbol = IFillSymbolPtr(CLSID_SimpleFillSymbol);
  ipColor->put_Transparency(0);
  g_ipFillSymbol->put_Color(ipColor);
  g_ipFillSymbol->put_Outline(ipOutline);
  
  return S_OK;
}