Symbian S60: ownership of bitmap data for listbox icons.

By April 21, 2010Symbian

For those who have worked with the Symbian S60 listbox control before, you will know that the notion of ownership with regard to the text items maintained by the list is very important. Essentially, ownership in this context relates to who has the ultimate responsibility of freeing the resources tied to the backing array of the listbox.

At a basic level, the ownership of the items either lies with the listbox – the items get destroyed with the deletion of the listbox – or it lies externally to be handled independently of the listbox. Listbox ownership is typically dictated at the creation of the listbox, like so:?

CTextListBoxModel* model = iListBox->Model();
model->SetItemTextArray( iSettingItemArray );

// Item ownership with listbox
model->SetOwnershipType( ELbmOwnsItemArray );
// Item ownership externally managed
model->SetOwnershipType( EbmDoesNotOwnItemArray );

Suffice it to say that there is an abundance of documentation surrounding this, so I won’t get into any more details here. However, when it comes to the ownership of bitmap data for listbox icons, the documentation seems to become scarce. Generally, what you will find is that there does not seem to be a means to dictate ownership with a listbox icon array in a similar fashion to that of a listbox text item array. Most existing examples will indicate that the ownership of the icons is transfered to the listbox when the icon array is associated with the listbox, such as:

// Sets the icon array.
CCustomListItemDrawer* itemDrawer = static_cast
itemDrawer->SetIconArray(iconArray); // transfers ownership

While this is entirely true, what if this is not the desired behavior; for instance, you may want to cache bitmap data (for the icons) from an external source and do not wish for the data to be destroyed with the listbox. Fortunately, Symbian allows for this by specifying the terms of ownership when creating an icon object from bitmap data, such as:

CFbsBitmap* iBitmap;
// bitmap initialization...

CGulIcon* iIcon = CGulIcon::NewL(iBitmap);

// Ownership of the bitmap data is not transferred to the icon.
iIcon->SetBitmapsOwnedExternally( ETrue );

This ensures that when a listbox and its icon objects are deleted, the bitmap data associated with the icons remains intact.


Leave a Reply