I have seen this question popup (ha!) a lot recently. I wrote this nice
handy dandy popup list fcn to handle all my popup list needs. It requires
the list ID, the trigger ID and a string list resource ID to function
properly.
I call it from my event loop when the trigger is selected (ctlSelect). It
could be argued that I am doing work the OS does for free but I like the
control I have here. I then do what I need with the return value (be aware
-1 is returned on "nothing selected").
I then return true from my event handler when this is finished so the OS
knows I have done all I need and shortcut the trigger event etc.

ttfn.
E/.

/*********
 * PopupListHandler
 *
 * Change the label of the selected popup control to that selected in the
 * list. It also returns the index of the item selected
 */
Int16 PopupListHandler( UInt32 inListID, UInt32 inControlID, UInt32
inStrListID )
{
        VoidHand strHandle = DmGetResource( strListRscType, inStrListID );
        VoidHand strArrayH = NULL;
        Int16 indx = -1;
        
        if ( strHandle != NULL )
        {
                StrListPtr strListPtr = (StrListPtr)MemHandleLock( strHandle
);
                
                strArrayH = SysFormPointerArrayToStrings(
strListPtr->firstString, strListPtr->numStrings );
                                
                ListPtr lst = (ListPtr)GetObjectPtr( inListID );
                ControlType* popTrigger = (ControlType*)GetObjectPtr(
inControlID );

                LstSetListChoices( lst, (char**)MemHandleLock( strArrayH ),
(int)(strListPtr->numStrings) );
                
                indx = LstPopupList( lst );

                // indx will be -1 if user did not select something in the
list
                if ( indx >= 0 )
                {
                        char *selText = LstGetSelectionText( lst, indx );
                        CtlSetLabel( popTrigger, selText );
                }
                
                MemHandleUnlock( strArrayH );
                MemHandleUnlock( strHandle );
                
                MemHandleFree( strArrayH );
                DmReleaseResource( strHandle );
        }
        return indx;
}

// used by any fcns that wish to use string lists
typedef struct StrListType
{
        char prefixString;      // assumed empty
        char numStringsHiByte;  // assumed 0
        char numStrings;        // low byte of count allows 255
        char firstString[1];
} *StrListPtr;

________________________________________________________
This message sent using the Infowave Wireless Business Engine(tm)
Evan Wise
Sprite Herder
infowave
E: [EMAIL PROTECTED]


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