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 />

Step 6: Begin the event handling loop<br />

The next step for this application is to idle until a user generates an event.<br />

gtk_widget_show_all(window);<br />

gtk_main();<br />

Step 7: Shut down the application<br />

As mentioned above, this application will run indefinitely unless it receives an<br />

event that tells it to do otherwise. To allow proper shutdown of the application,<br />

you will handle the signals that tell you the window is going to be closed.<br />

After the widgets are shown and before the event loop is started by gtk_main,<br />

you will listen for those signals:<br />

gtk_widget_show_all(window);<br />

g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event),<br />

NULL);<br />

g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy_event), NULL);<br />

You will also provide the callbacks DeleteEvent and DestroyEvent that have the<br />

application close when the signals are recieved. As for the other callback, make<br />

sure you place a forward declaration before main.<br />

static void destroy_event(GtkWidget *widget, gpointer data)<br />

{<br />

gtk_main_quit();<br />

}<br />

For <strong>ArcGIS</strong> <strong>Engine</strong> C++ programming, you must<br />

call AoExit before returning. You must call<br />

AoUninitialize before shutting down the<br />

application with AoExit.<br />

static gboolean delete_event(GtkWidget *widget, GdkEvent *event,<br />

gpointer data)<br />

{<br />

return FALSE; // must return false to trigger destroy event for window<br />

}<br />

Trying it out<br />

To compile your GTK program, you will need to link against libraries for GTK,<br />

Xt, and X11, in that order. If you are programming on Solaris, you will compile<br />

with the Sun Workshop (Forte), and if you are programming on Linux you will<br />

use GCC.<br />

Solaris:<br />

CC pbExample.cpp -o pbExample ‘pkg-config gtk+-2.0 —cflags —libs‘<br />

Linux:<br />

g++ pbExample.cpp -o pbExample ‘pkg-config gtk+-2.0 —cflags —libs‘<br />

Run the program:<br />

./pbExample<br />

As you click the button, you will see the number of the button you pressed<br />

appear in your terminal window.<br />

Now that you have a feeling for GTK programming, look at the C++ samples for<br />

GTK, and see these steps applied there.<br />

244 • <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!