Resources | Resources |



Using the list container widget

This topic describes how to create a list, using IListContainerModel.

The sample application creates a list of images which are grouped together. This list is a heterogeneous list that has two types of items, one type (LIST_ITEMTYPE_TEXT) represents an image category, for example, Alien or Bird, and the second type (LIST_ITEMTYPE_TEXTANDIMAGE) represents images inside a particular category, for example, Alien_1, Bird_1, Bird_2 and so forth. List container uses static widgets to render image category. Items inside the category are rendered using ImageStaticWidget.

For more information on list container, see List container widget and the

The figure below shows the sample application running on the Simulator.

Required header files

These include files are needed to create a list container that uses IListContainerModel.

#include "AEEIListContainerModelFactory.h"    
#include ""    
#include "AEEIListContainerModel.h"    
#include ""    
#include "AEEITypedValueModel.h"    
#include ""    

Create an instance of list container

Create an instance of list container, as follows:

ERR_TRY( ISHELL_CreateInstance(pMe->Applet.m_pIShell, AEECLSID_CListContainer,
            (void**) &piwList) );

Create an IListContainerModel and attach it to the list container

In this example, the application calls ISHELL_CreateInstance() to create an instance of IListContainerModelFactory, then calls IListContainerModelFactory_CreateCallbackBased() to get an instance of IListContainerModel that is then attached to the list container.

    // Initialize user context    
   pMe->lcUserCtx.piVectorModel = piVectorModel;    
   pMe->lcUserCtx.piShell = pMe->Applet.m_pIShell;    
   // CI ListContainerModelFactory    
   ERR_TRY( ISHELL_CreateInstance(pMe->Applet.m_pIShell,
               AEECLSID_CListContainerModelFactory, (void**)&piLCMF) );    
   // Get ListContainerModel instance from CreateCallbackBased method
   // of ListContainerModelFactory.    
   (void ) IListContainerModelFactory_CreateCallbackBased (piLCMF, &pMe->lcUserCtx,     
   //Attach that list container model with the ListContainer we created.    
   ERR_TRY(IWidget_SetModel(piwList,IListContainerModel_to_IModel(piLCM)) );    
   //Attach model listener to ListContainer's view model.    
   ERR_TRY(IWidget_SetFocusListener(piwList, &pMe->mView,

Callback function c_listcontainer_app_GetItemType()

This function retrieves the item type at a specific index. In the sample application, the list has two types of items. The first type is an image category, and the second type is an item that is used to display the image along with its name.

For each index in this function, the function retrieves text from the vector model (user context) and tries to load the image with that name. If no image is found, the function returns the type as LIST_ITEMTYPE_TEXT, and if the image is found, the function returns type as LIST_ITEMTYPE_TEXTANDIMAGE.

Note: LIST_ITEMTYPE_TEXT and LIST_ITEMTYPE_TEXTANDIMAGE are user defined list item types.

int c_listcontainer_app_GetItemType (void *pvCtx, int nIndex, int *pnType) 

Callback function c_listcontainer_app_GetItemWidget()

This function is used to create the widget that will hold the item. In the sample application, the function creates StaticWidget for type LIST_ITEMTYPE_TEXT and creates ImageStaticWidget for type LIST_ITEMTYPE_TEXTANDIMAGE.
// Create static widget for item type LIST_ITEMTYPE_TEXT,
// else create image static widget    
   ERR_TRY(ISHELL_CreateInstance(pData->piShell, AEECLSID_CStaticWidget,

Note: Item widget should have ITypedValueModel attached to it, as ListContainerModel uses ITypedValueModel to set the data of the item.

//CI TypedValueModel    
ERR_TRY(ISHELL_CreateInstance(pData->piShell, AEECLSID_CTypedValueModel,
//Attach a TypedValueModel to this widget    
ERR_TRY(IWidget_SetModel(piwListItem, ITypedValueModel_to_IModel(piTVM)) );

Callback function c_listcontainer_app_GetItemData()

This function updates the item data in the supplied ITypedValueModel.

int c_listcontainer_app_GetItemData(void *pvCtx, int nIndex,
            int nState, ITypedValueModel *piTVM)    
   userContext *pUserData = (userContext *)pvCtx;    
   ImageStaticInfo *pImgStaticInfo = NULL;    
   int nType = 0;    
   int nErr = 0;    
   (void) nState;     
   ERR_TRY( IVectorModel_GetAt(pUserData->piVectorModel, (uint32)nIndex,
               (void *)&pImgStaticInfo) );    
   ERR_TRY( c_listcontainer_app_GetItemType(pvCtx, nIndex, &nType) );    
   if (nType == LIST_ITEMTYPE_TEXT) {    
      ERR_TRY( ITypedValueModel_SetTextPtr(piTVM, pImgStaticInfo->pwText, -1) );    
   } else {    
      ERR_TRY( ITypedValueModel_SetValue(piTVM, TypedValueModel_ImageStaticInfo,
                  pImgStaticInfo, sizeof(ImageStaticInfo *), NULL, NULL) );    
   return nErr;