18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BUILDING APPLICATIONS WITH C++ AND CONTROL WIDGETS<br />

Controlling label editing in the TOCControl<br />

By default, the TOCControl allows users to automatically toggle the visibility of<br />

layers and to change map and layer names as they appear in the table of contents.<br />

You will add code to prevent users from editing a name and replacing it with an<br />

empty string.<br />

1. The TOCControl label editing events must be triggered. To do so, add the<br />

following code to MapViewer.cpp in main after FormSetup.<br />

FormSetup(argc, argv, &app_context);<br />

g_ipTOCControl->put_LabelEdit(esriTOCControlManual);<br />

2. You must listen for events in the TOCControl by writing a class that inherits<br />

from ITOCControlEventsHelper, as you did for the PageLayoutControl earlier.<br />

Start by creating TOCControlEvents.h, a new text file:<br />

#ifndef __TOCCONTROLEVENTS_H_<br />

#define __TOCCONTROLEVENTS_H_<br />

#include <br />

#include <br />

class TOCControlEvents : public ITOCControlEventsHelper<br />

{<br />

public:<br />

// IUnknown<br />

IUNKNOWN_METHOD_DEFS<br />

// ITOCControlEvents<br />

void OnMouseDown(long button, long shift, long x, long y);<br />

void OnMouseUp(long button, long shift, long x, long y);<br />

void OnMouseMove (long button, long shift, long x, long y);<br />

void OnDoubleClick (long button, long shift, long x, long y);<br />

void OnKeyDown (long keyCode, long shift);<br />

void OnKeyUp (long keyCode, long shift);<br />

void OnBeginLabelEdit (long x, long y, VARIANT_BOOL* CanEdit);<br />

void OnEndLabelEdit (long x, long y, BSTR newLabel, VARIANT_BOOL*<br />

CanEdit);<br />

};<br />

#endif // __TOCCONTROLEVENTS_H_<br />

3. Place the implementation for ITOCControlEventsHelper’s functions into<br />

TOCControlEvents.cpp, another new file. Since they are void functions, they<br />

can be left empty. However, you will implement OnEndLabelEdit. In that<br />

function, tell the TOC to forbid the edit if the new label is an empty string.<br />

#include "TOCControlEvents.h"<br />

void TOCControlEvents::OnMouseDown(long button, long shift, long x, long y)<br />

{<br />

380 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!