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.

C++ APPLICATION PROGRAMMING INTERFACE<br />

int main(int argc, char* argv[])<br />

{<br />

...<br />

GtkWidget* mapWidget;<br />

IMapControl3Ptr ipMapControl;<br />

mapWidget = gtk_axctl_new(AoPROGID_MapControl);<br />

gtk_axctl_get_interface(mapWidget, (IUnknown **)&ipMapControl);<br />

gtk_widget_set_size_request(mapWidget, -1, -1);<br />

gtk_container_add(GTK_CONTAINER(window), mapWidget);<br />

...<br />

}<br />

EVENT HANDLING ON ARCGIS CONTROLS<br />

Events occur any time there is interaction with an application during its runtime.<br />

When a new map is loaded, when the mouse moves inside the control window, or<br />

when a keyboard button is pressed are examples of when events occur, and at<br />

such times the information regarding the event is reported. If the application is<br />

listening for events, it will execute code associated with the event that has occurred.<br />

Although there are also Motif and GTK events,<br />

interacting with ArcObjects (such as popup<br />

menus) through those events is not recommended.<br />

Instead, you should interact through the<br />

ArcObjects event interfaces.<br />

To make an application that responds to events on the controls without having a<br />

tool or command selected, you will not only need to tell the application what to<br />

do when such events are received, but will also have to tell the computer to be<br />

listening for and reacting to such events. This document details how to listen for<br />

the events, but does not go into detail on how to write your event class. For help<br />

on writing an event class, see ‘Writing a MapControl Event class’ and ‘Writing a<br />

Transform Event class’ in the developer help system under Development Environments<br />

> C++ > Walkthroughs.<br />

If, however, you want to use a tool or a command, you will not need to listen for<br />

events. Custom tools and commands interact with the controls through their own<br />

functions, which are called upon similar events. See ‘Creating a custom command<br />

using AoBaseCommand’ or ‘Creating a custom tool using AoBaseTool’ in the<br />

developer help system under Development Environments > C++ ><br />

Walkthroughs.<br />

Events on the controls<br />

To handle control events you will need to write a class that inherits from the<br />

events with which you want to interact. For the main events on a control, which<br />

implement IDispatch, your C++ API event classes will inherit from a helper<br />

interface. Listening for these events is then simplified. The events this applies to<br />

are listed in the table below. For all other event types, you will implement a class<br />

that inherits from the ArcObjects interface with the events you want to listen<br />

for. Then you will listen for the events as outlined under ‘Other ArcObjects<br />

events—Implemented with custom interfaces’ below.<br />

246 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Once you have implemented your class, you will need to have your application<br />

listen for the events. To do so, you will use IEventHelper, which passes information<br />

between your application and the events, handling reference counting for<br />

you.

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

Saved successfully!

Ooh no, something went wrong!