Saturday, August 1, 1998

Programming controls in PalmOS

PROGRAMMING POWER

By Alan Jay Weiner

We looked at resources in June, and started looking at forms and controls. Last month, I provided several utility routines for working with controls. This month, let's take a look at several different types of controls--what we can do with them, and how they work.

What are controls?

Just to clarify what we're talking about, what are controls? They're the user-interface elements with which we interact--they're the buttons we push, the pull-down lists, check boxes, and so forth. Officially, the PalmOS documentation defines control objects as buttons, pop-up trigger, selector trigger, repeat controls, pushbuttons, and check boxes.

Some of the controls are actually the "triggers" for other user interface (UI) objects. For example, the popup trigger tells a list to display itself on the screen. Pop-up lists have two controls: the trigger and the list itself. More on that in a bit.

You've already used these controls; they're used on the forms in the built-in applications and third-party programs. So you're familiar with using them. Let's take a look at how to work with them in our programs.

How do the controls work?

When we build a form and place various controls on it, the program contains the parameters we specify; the position of each control, its height and width, and so forth. When the form is used, the operating system keeps track of each control using a special data structure. As things happen which change the control, those changes are reflected within that data structure and on the screen.

Most of the time, users cause these changes by tapping on the screen--pressing a button or selecting something. Other times, some other event causes a change (for example, the tap on the pop-up trigger changing the pop-up list status so it will appear on the screen). Initially, only the trigger is displayed; the actual list is "unusable" so it won't show up. Once the user taps the trigger, the list changes to usable and is displayed.

Since PalmOS knows about the standard controls, most of the events related to these controls are handled by the operating system. When the user presses a button, the application ignores the pen-down and pen-up events and just lets PalmOS do the proper "pressing on button" actions. Our event loop sees these events, so if we wanted to intercept them for some special reason we can. But normally, we just ignore them. They ripple their way through the event handlers and finally the default form handler (within the OS) does what it should to make the control work properly. The button handler inverts the button when it's pressed, and returns it to normal when it's released.