18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C++ APPLICATION PROGRAMMING INTERFACE<br />

• “button_press_event”—the signal to respond to. Here you will listen for the<br />

button being pressed. For other options, see the GTK reference at the end of<br />

this topic.<br />

• ClickCallback—the function to call when the signal is received.<br />

• NULL—data to pass into the callback function. Here there is no data the<br />

function will need, so NULL is passed.<br />

Callback functions<br />

For the callback to work, you must implement the function that is being called<br />

on the event. Callbacks will generally follow the following function signature:<br />

Make sure that the data passed to<br />

callback_data will be in scope later when the<br />

callback routine is executed.<br />

void callback_func(GtkWidget *widget, gpointer callback_data);<br />

However, as in this case, you will sometimes want additional information about<br />

the event. To get that information, the following function signature can be used:<br />

void ClickCallback(GtkWidget *widget, GdkEventButton *event, gpointer<br />

callback_data);<br />

The parameters are:<br />

• widget—the widget that gave the signal<br />

• event—tells what button press or release event triggered the function<br />

• callback_data—any data passed into the function, as indicated in the last<br />

parameter of g_signal_connect<br />

For this example, place this function after main in pbExample.cpp, and have it<br />

print to cerr which mouse button was used to click (for example, “button:<br />

1”). Remember to also place a forward declaration of it before main.<br />

To get the button that was clicked, you must use the information in the<br />

GdkEventButton struct.<br />

void ClickCallback(GtkWidget *widget, GdkEventButton *event,<br />

gpointer callback_data)<br />

{<br />

// show which button was clicked<br />

std::cerr

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

Saved successfully!

Ooh no, something went wrong!