O'Reilly logo

Learning Carbon by Apple Computer Inc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MoonTravel Planner: Writing an Event Handler

Now that you know what an event handler is supposed to look like, we’re ready to add one to the Moon Travel Planner application. Here’s what you’ll do:

  1. Identify the events your handler processes.

  2. Write the main window event handler and the compute travel time function called by the handler.

  3. Install the main window event handler.

  4. Call the application event loop function.

  5. Make sure the code works.

Identify Events

As you recall from Chapter 2 a user can select a mode of transportation, then click a button to compute the travel time to the moon. When you created the interface, you assigned a command to the Compute Travel Time button. Your application needs to handle this command when it’s issued—a command class event kEventClassCommand.

Everything else that happens in the window—moving it, minimizing it, clicking a radio button—can be handled by the default handler for the window. (Recall you selected Standard Handler in Chapter 4.)

Now that you’ve identified the event (a command class event) in which your application is interested, you need to declare an event type specifier to indicate to the Carbon Event Manager the event for which to call the handler.

Open the Moon Travel Planner project. In the main.c file file, copy the following to the main function, after the declaration OSStatus err:

 EventTypeSpec      mainSpec = {kEventClassCommand,
                                    kEventCommandProcess};

Write the Main Window Event Handler

In this section, you’ll write an event handler, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required