The LISTBOX object

This is a list of selectable items, similar to the ones used in the file dialogs. The list is define by the p_list structure we explained in t_list section. You are able to put the new listbox into your application with the function:


listbox_init ()
     Description:
       Creates a new listbox object.

     Syntax:
       p_listbox  listbox_init ( p_listbox o, t_rect r, p_list list, 
                                 l_byte rows, l_int flags );

     Parameters:
       o           Allocated memory to store the object in.
       r           Rectangle to create the listbox in.
       list        The list to be used in the listbox. Items in this
                   list must be of the type t_listbox_item.
       rows        The number of rows in the listbox. If the value of
                   "number" <=1 then it scrolls vertically. If it is
                   less than 1 it scrolls horisontally.
       flags       Can be one of the following:

                      LF_UNDERSEL   - Select item whenever mouse is over it.
                      LF_SELECTABLE - Select more items for copying. 

     Returns:
       The new listbox object.



new_listbox_item ()
     Description:
       Creates a new listbox item.

     Syntax:
       p_listbox_item   new_listbox_item ( l_text name, BITMAP *icon, 
                                           l_bool sel, l_int flags );

     Parameters:
       name        Name of the item. Is inserted with the
                   _strdup() function.
       icom        A bitmap to use for the item in the list.
       sel         Set to true if the item is selected.
                   Is false otherwise.
       flags       May be one of the following:

                    LIF_MEMORY - The icon has its own memory for
                                 the item that must be freed when
                                 the item is freed.
                    LIF_NONE   - The icon doesn't have its own memory.

     Returns:
       The new listbox item.




The t_listbox_item structure

Variables:

     Name:         l_text  name;

     Description:  Name of the item.



     Name:         BITMAP  *icon;

     Description:  Icon to use for the item in the listbox.



     Name:         l_bool  sel;

     Description:  Is True if the item is selected. False if not.



     Name:         l_int  flags;

     Description:  Can be one of the following:

                      LIF_MEMORY - The icon has its own memory for
                                   the item that must be freed when
                                   the item is freed.
                      LIF_NONE   - The icon doesn't have its own memory.



     Name:         l_char  reserved[12];

     Description:  Reserved for future versions.




Example:


        p_list get_list ( void )
        {
           p_list list = list_init(malloc(sizeof(t_list)),
                                   &free_listbox_item, 
                                   DAT_LIST); 

                /* The list's items->rec will be freed
                   by the function free_listbox_item.  */


           if ( list ) {
              list->insert(list, new_listbox_item("Name", 
                                                  NULL,      /* No icon */
                                                  true,
                                                  LIF_NONE));
              list->insert(list, new_listbox_item("New Name", 
                                                  NULL,      /* No icon */
                                                  true,
                                                  LIF_NONE));
           };
           return list;
        };



        t_rect r = rect_assign(100, 100, 200, 200);

        p_listbox box = listbox_init(malloc(sizeof(t_listbox)),
                                     r, 
                                     get_list(),
                                     1,
                                     0);

        OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(box));