> How do you add options to a pop up trigger in the
> Codewarrior Constructor? Thanks!


I'm in the process of writing some "recipe"-style sample code for
situations like this, and happen to have already done one on popup lists.
Here's what is written, though it hasn't been checked by anyone else but me
yet... let me know if this doesn't make sense or if there's anything wrong!

-David Fedor
Palm, Inc.



Static Popups are for uses such as the volume selector in Preferences,
which has choices "Off", "Low", "Medium", "High". The choices will never
change, except when translated into a different language.

Static Popups are actually constructed from two objects: a popup trigger
and a list.

In Constructor:

1.      Create a list object and place it on the form. Only worry about its
top-left position for now. Usually it should be on the right of a
right-justified label.
2.      Set the object identifier, e.g. "Volume".
3.      Turn off "Usable".
4.      Add the strings for the list items. (Add items by tapping on "List
Items" and choosing "New Item Text", or command/control K.) For this
example, add four items, and fill them in with "Off", "Low", "Medium", and
"High"
5.      Change the list's width so it is just wide enough for your longest
string. You can change the "Visible Items" value to see more items, to help
determine the correct width.
6.      If you want, temporarily change the list's "Visible Items" to two,
so it is easier to work with.
7.      Place a popup trigger control on your form, with the same top-left
coordinates as the list.
8.      Set the object identifier, e.g. "Volume", same as what you said for
the list.
9.      Keep the trigger's height at 12 pixels, but set the width at least
12 pixels wider than the list.
10.     By default the popup is usable and anchored left, and uses the
standard font; those are rarely changed.
11.     Clear the Label text on the popup. (You'll be setting it at runtime
and probably don't want two copies of the string.)
12.     Set the List ID on the popup to match the ID of the list. If not,
it won't know which list to pop up.
13.     Change the list's "Visible Items" to zero, so it won't be visible
on the form.

When the form is opening, you need to set the default choice in the list,
and set the popup trigger's text based on that setting Add this code to the
form's event handler:

   case frmOpenEvent: {
      void *theList;
      void *theTrigger;
      void *frm;
      UInt16 defaultValue;

      // initialize the popup's selection, and set the popup trigger's text
      defaultValue = 0;  // or whatever you want
      frm = FrmGetActiveForm();

      theList = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, mainVolumeList));
      LstSetSelection(theList, defaultValue);

      theTrigger = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
mainVolumePopTrigger));
      CtlSetLabel(theTrigger, LstGetSelectionText(theList, defaultValue));
   }


You now have a functioning popup. All that remains is to read its value at
the right time, like this:

   theSetting = LstGetSelection(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
mainVolumeList)));

Or if you want to react as soon as a selection is chosen from the popup,
add a handler for the popSelectEvent:

   case popSelectEvent:
      if (event->data.popSelect.controlID == mainVolumePopTrigger) 
         theSetting = event->data.popSelect.selection;


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to