Custom items in List Container | developer.brewmp.com Custom items in List Container | developer.brewmp.com

Developer

Custom items in List Container

Forums:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}

Hi,

 

I am trying to understand how a custom container can be added to a list container.

My list will have an image, and two text items which will be aligned in a custom way. I have added them in a XYContainer.

 

I tried creating a list container and provided a callback based IListContainerModel using IListContainerModelFactory_CreateCallbackBased API.

 

 

Now, in the GetItemData callback function, we need to provide a ITypedValueModel which basically are a predefined type of contents. 

 

How can we provide custom containers as list members

 

Thanks

Ankur

/*-----------------------------------------------------------------------------
Includes and Variable Definitions
-----------------------------------------------------------------------------*/
#include "AEEModGen.h" // Module interface definitions.
#include "AEEAppGen.h" // Applet interface definitions.
#include "AEEShell.h" // Shell interface definitions.

#include "listcontainerapp.bid"
#include "listcontainerapp_res.h"

#include "AEEStdLib.h"

//List container and widgets includes
#include "AEEITypedListModelFactory.h"
#include "AEEITypedListModel.h"
#include "AEEIListContainerModelFactory.h"
#include "AEEIListContainerModel.h"
#include "AEEIVectorModel.h"
#include "AEEIModel.h"
#include "AEEIValueModel.h"

#include "AEEListContainer.bid"
#include "AEEVectorModel.bid"
#include "AEETypedListModelFactory.bid"
#include "AEEListContainerModelFactory.bid"
#include "AEEListWidget.h"
#include "AEETypedValueModel.bid"

#include "AEEIWidget.h"
#include "AEEIRootContainer.h"
#include "AEEIPropContainer.h"
#include "AEEIDisplayCanvas.h"
#include "AEEIDecorator.h"
#include "AEEImageWidget.h"
#include "AEEIXYContainer.h"
#include "AEEStaticWidget.h"

#include "AEEWidgetProperties.h"
#include "AEEResFile.bid"
#include "AEERootContainer.bid"
#include "AEEImageWidget.bid"
#include "AEEDisplayCanvas.bid"
#include "AEEPropContainer.bid"
#include "AEEStaticWidget.bid"
#include "AEEModel.bid"
#include "AEEPointerHelpers.h"
#include "AEEWidgetElement.h"
#include "AEEXYContainer.bid"
#include "AEEWidgetTCProperties.h"
// generic free memory function
#ifndef VF_FREE
#define VF_FREE (GET_HELPER()->free)
#endif

// Error handling macros
#define ERR_CATCH __errcatch
#define ERR_TRY(x) do { nErr = (x); if (AEE_SUCCESS != nErr) goto ERR_CATCH; } while(0)
#define ERR_THROW(e) do { nErr = (e); goto ERR_CATCH; } while(0)
#define ERR_CHECK_PTR(p) if (NULL == p) { ERR_THROW(AEE_EFAILED); }

#ifndef RELEASEIF
#define RELEASEIF(p) listcontainerapp_ReleaseIf((IBase**)(void **)&p)
static void listcontainerapp_ReleaseIf(IBase **ppif) {
if (*ppif) {
IBASE_Release(*ppif);
*ppif = 0;
}

#endif

#ifndef ADDREFIF
#define ADDREFIF(p) do { if (p) IBASE_AddRef((IBase*) (void *) p); } while(0)
#endif

// clean casting macro
#ifndef CAST
#define CAST(t, exp) ((t)(void*)(exp))
#endif

typedef struct WidgetList{
IWidget *piwName;
IWidget *piwCmpny;
IWidget *piwImg;
IResFile *piResFile;
WidgetList;

typedef struct userContext
{
IVectorModel *piVectorModel;
IShell *piShell;
ModelListener ml[10];
WidgetList piwList[10];
int nmlCount;

IResFile *piResFile;
userContext;

typedef struct _listcontainerapp {
AEEApplet Applet; // First element of this structure must be AEEApplet.
IDisplay * piDisplay; // Copy of IDisplay Interface pointer for easy access.
IShell * piShell; // Copy of IShell Interface pointer for easy access.
AEEDeviceInfo deviceInfo; // Copy of device info for easy access.
// Add your own variables here...
IWidget *piwRoot;
IRootContainer *picRoot;
IWidget *piwListC;

userContext lcUserCtx;

listcontainerapp;

typedef struct _CustomData
{
int nIdName;
int nIdCmpny;
int nIdImg;
CustomData;

/*-----------------------------------------------------------------------------
Function Prototypes
-----------------------------------------------------------------------------*/
static boolean listcontainerapp_HandleEvent(listcontainerapp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean listcontainerapp_InitAppData(listcontainerapp* pMe);
void listcontainerapp_FreeAppData(listcontainerapp* pMe);
static void listcontainerapp_DrawScreen(listcontainerapp * pMe);

static int listcontainerapp_CreateListContainer(listcontainerapp *me);
/*-----------------------------------------------------------------------------
Function Definitions
-----------------------------------------------------------------------------*/

int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
void ** ppObj)
{
*ppObj = NULL;

// Confirm this applet is the one intended to be created (classID matches):
if( AEECLSID_LISTCONTAINERAPP == ClsId ) {
// Create the applet and make room for the applet structure.
// NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
if( TRUE == AEEApplet_New(sizeof(listcontainerapp),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)listcontainerapp_HandleEvent,
(PFNFREEAPPDATA)listcontainerapp_FreeAppData) ) {

// Initialize applet data. This is called before EVT_APP_START is
// sent to the HandleEvent function.
if(TRUE == listcontainerapp_InitAppData((listcontainerapp*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
// Release the applet. This will free the memory allocated for
// the applet when AEEApplet_New was called.
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;

boolean listcontainerapp_InitAppData(listcontainerapp * pMe)
{
// Save local copy for easy access:
pMe->piDisplay = pMe->Applet.m_pIDisplay;
pMe->piShell = pMe->Applet.m_pIShell;

// Get the device information for this handset.
// Reference all the data by looking at the pMe->deviceInfo structure.
// Check the API reference guide for all the handy device info you can get.
pMe->deviceInfo.wStructSize = sizeof(pMe->deviceInfo);
ISHELL_GetDeviceInfo(pMe->Applet.m_pIShell,&pMe->deviceInfo);

return TRUE;// No failures up to this point, so return success.

void listcontainerapp_FreeAppData(listcontainerapp * me)
{
// Insert your code here for freeing any resources you have allocated...
RELEASEIF(me->picRoot);
RELEASEIF(me->piwRoot);
RELEASEIF(me->piwListC);

static boolean listcontainerapp_HandleEvent(listcontainerapp* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {
// Event to inform app to start, so start-up code is here:
case EVT_APP_START:
listcontainerapp_DrawScreen(pMe); // Draw text on display screen.
return TRUE;

// Event to inform app to exit, so shut-down code is here:
case EVT_APP_STOP:
return TRUE;

// Event to inform app to suspend, so suspend code is here:
case EVT_APP_SUSPEND:
return TRUE;

// Event to inform app to resume, so resume code is here:
case EVT_APP_RESUME:
listcontainerapp_DrawScreen(pMe); // Redraw text on display screen.
return TRUE;

// An SMS message has arrived for this app.
// The Message is in the dwParam above as (char *).
// sender simply uses this format "//BREW:ClassId:Message",
// example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
return TRUE;

// A key was pressed:
case EVT_KEY:
return FALSE;

// Clamshell has opened/closed
// wParam = TRUE if open, FALSE if closed
case EVT_FLIP:
return TRUE;

// Clamtype device is closed and reexposed when opened, and LCD
// is blocked, or keys are locked by software.
// wParam = TRUE if keygaurd is on
case EVT_KEYGUARD:
return TRUE;

// If event wasn't handled here, then break out:
default:
break;
}
return (pMe->piwRoot == NULL)?FALSE: IWidget_HandleEvent(pMe->piwRoot, eCode, wParam, dwParam);

static void listcontainerapp_DrawScreen(listcontainerapp * me)
{
AEEResult nErr;
AEERect rect;
IDisplayCanvas *piDisplayCanvas = NULL;
ICanvas *piCanvas = NULL;

SETAEERECT(&rect, 0, 0, me->deviceInfo.cxScreen, me->deviceInfo.cyScreen);

// Create the root container that serves as the root of any widget tree
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_RootContainer, (void**)&me->picRoot) );
ERR_TRY( IRootContainer_QueryInterface(me->picRoot, AEEIID_IWidget, (void**)&me->piwRoot) );

// And give it a display canvas to use so we can see the widgets get drawn to the screen
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_DisplayCanvas, (void**)&piDisplayCanvas) );
ERR_TRY( IDisplayCanvas_SetDisplay(piDisplayCanvas, me->piDisplay) );
ERR_TRY( IDisplayCanvas_QueryInterface(piDisplayCanvas, AEEIID_ICanvas, (void**)&piCanvas) );
IRootContainer_SetCanvas(me->picRoot, piCanvas, &rect);
DBGPRINTF("Enable touch on root");

ERR_TRY( IWidget_EnableTouch(me->piwRoot) );
// Give our canvas a nice neutral color.
ERR_TRY( IWidget_SetBGColor(me->piwRoot, MAKE_RGBA(0xCC, 0xCC, 0xCC, 0xFF)) );

{
WidgetPos wp;
WidgetExtent we = {0};

wp.bVisible = TRUE;

ERR_TRY( listcontainerapp_CreateListContainer(me) );

wp.x = 0;
wp.y = 0;
ERR_TRY( IRootContainer_Insert(me->picRoot, me->piwListC, WIDGET_ZTOPMOST, &wp) );

}

// If there have been no failures up to this point then return success
ERR_CATCH:
RELEASEIF(piCanvas);
RELEASEIF(piDisplayCanvas);
//return AEE_SUCCESS == nErr;

/********************************************
///////////////////////////////////////////
Create list container & widgets
*********************************************/
int IPropContainer_InsertEx(IPropContainer *me, IWidget *piw, uint16 nProp,
boolean bVisible, int16 padBefore, int16 padAfter)
{
AEEResult nErr;
WidgetProp wp;
wp.prop = nProp;
wp.bVisible = bVisible;

IWidget_SetPreferredExtent(piw, NULL);

ERR_TRY( IPropContainer_Insert(me, piw, WIDGET_ZNORMAL, &wp) );
ERR_TRY( IPropContainer_SetPaddingExact(me, piw, padBefore, padAfter) );

ERR_CATCH:
return nErr;

int IWidget_SetStaticText(IWidget* piw, const AECHAR* textValue)
{
IValueModel *pivm = NULL;
AEEResult nErr;

if (NULL == piw) {
return AEE_EBADPARM;
}

ERR_TRY( IWidget_GetModel(piw, AEEIID_IValueModel, CAST(IModel**, &pivm)) );

IValueModel_SetValue(pivm, (void*)textValue, WSTRLEN(textValue), NULL);

ERR_CATCH:
RELEASEIF(pivm);
return nErr;

int listcontainerapp_CreateStaticWidget(IShell* piShell, const AECHAR* text, IWidget** ppiw, IFont *pif, uint32 flags)
{
AEEResult nErr;

ERR_TRY( ISHELL_CreateInstance(piShell, AEECLSID_StaticWidget, (void**)ppiw) );
ERR_TRY( IWidget_SetFlags(*ppiw, flags) );

if (NULL != pif) {
ERR_TRY( IWidget_SetFont(*ppiw, pif) );
}
if (NULL != text) {
ERR_TRY( IWidget_SetStaticText(*ppiw, text) );
}
ERR_CATCH:
if (AEE_SUCCESS != nErr) {
RELEASEIF(*ppiw);
}
return nErr;

/*
Callback function to get the "item type" at a specific index.
*/
int listcontainerapp_GetItemType (void *pvCtx, int nIndex, int *pnType)
{
(void)nIndex;
(void)pvCtx;
*pnType = 1;
return 0;

static int listcontainerapp_GetResString(IResFile *piResFile, int nResId, AECHAR **ppDest)
{
AEEResult nErr;
AECHAR *pwsz = NULL;
uint32 nLen = 0;

ERR_TRY( IResFile_Get(piResFile, (uint32)nResId, RESTYPE_STRING, (AECHAR*)-1, &nLen) );

if (nLen > 2) {
pwsz = MALLOC(nLen);
if (NULL == pwsz) {
ERR_THROW(AEE_ENOMEMORY);
}
}

ERR_TRY( IResFile_Get(piResFile, (uint32)nResId, RESTYPE_STRING, pwsz, &nLen) );

*ppDest = pwsz;

ERR_CATCH:
if (AEE_SUCCESS != nErr) {
*ppDest = NULL;
FREEIF(pwsz);
}
return nErr;

static int listcontainerapp_GetResImage(IResFile *piResFile, int nResId, IImage** ppDest)
{
AEEResult nErr;
void *pObj = NULL;

ERR_TRY( IResFile_GetObject(piResFile, (uint32)nResId, AEECLSID_VIEW, &pObj) );

*ppDest = pObj;

ERR_CATCH:
return nErr;

void listcontainerapp_ItemModelListener(WidgetList* me, ModelEvent *pEvent)
{
AEEUID nType;
CustomData *pValue; int nLen;
AECHAR *pszTxt;
IImage *pii = NULL;
AEEResult nErr;

ERR_TRY( ITypedValueModel_GetValue(CAST(ITypedValueModel *,pEvent->pModel), &nType, (void **)&pValue, &nLen));

ERR_TRY( listcontainerapp_GetResString(me->piResFile, pValue->nIdName, &pszTxt));
ERR_TRY( IWidget_SetStaticText(me->piwName, pszTxt) );

ERR_TRY( listcontainerapp_GetResString(me->piResFile, pValue->nIdCmpny, &pszTxt) );
ERR_TRY( IWidget_SetStaticText(me->piwCmpny, pszTxt) );

ERR_TRY( listcontainerapp_GetResImage(me->piResFile, pValue->nIdImg, &pii) );
ERR_TRY( IWidget_SetImage(me->piwImg, pii) );
RELEASEIF(pii);

ERR_CATCH:
;

/*
Callback function to get the "item widget" of certain type.
*/
int listcontainerapp_GetItemWidget(void *pvCtx, int nType, int nState, IWidget **ppiwItem)
{
ITypedValueModel *piTVM =NULL;
WidgetExtent weStatic;
userContext *pData = (userContext *)pvCtx;

IPropContainer *picMainContainer = NULL;
IValueModel *pivm = NULL;
IWidget *piwListItem = NULL;
IWidget *piwName = NULL;
IWidget *piwImg = NULL;
IWidget *piwCmpny = NULL;
int nErr;
(void) nType; (void) nState;
pData->piwList[pData->nmlCount].piResFile = pData->piResFile;

// Create the image
ERR_TRY( ISHELL_CreateInstance(pData->piShell, AEECLSID_ImageWidget, (void**)&piwImg) );
ERR_TRY( IWidget_SetFlags(piwImg, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE) );
pData->piwList[pData->nmlCount].piwImg = piwImg ;

// Create static widget that holds the name
ERR_TRY( listcontainerapp_CreateStaticWidget(pData->piShell, NULL, &piwName, 0,
IDF_ALIGN_LEFT | IDF_ALIGN_TOP) );

pData->piwList[pData->nmlCount].piwName = piwName;

// Create static widget that holds the company name
ERR_TRY( listcontainerapp_CreateStaticWidget(pData->piShell, NULL, &piwCmpny, 0,
IDF_ALIGN_LEFT | IDF_ALIGN_TOP) );
pData->piwList[pData->nmlCount].piwCmpny = piwCmpny;

// Create Prop Container for list item
ERR_TRY( ISHELL_CreateInstance(pData->piShell, AEECLSID_PropContainer, (void**)&picMainContainer) );

//Insert the image into container
ERR_TRY( IPropContainer_InsertEx(picMainContainer, piwImg, WIDGET_KEEP_EXTENT, TRUE, 0, 0) );

// Insert from name and company into a container
ERR_TRY( IPropContainer_InsertEx(picMainContainer, piwName, WIDGET_KEEP_EXTENT, TRUE, 2, 0) );
ERR_TRY( IPropContainer_InsertEx(picMainContainer, piwCmpny, WIDGET_KEEP_EXTENT, TRUE, 2, 0) );

ERR_TRY( IPropContainer_QueryInterface(picMainContainer, AEEIID_IWidget, (void**)&piwListItem) );
ERR_TRY( IWidget_SetLayoutStyle(piwListItem, AEEWIDGET_LAYOUT_VERT) );

ERR_TRY( IWidget_SetBorderWidth(piwListItem, 1) );
ERR_TRY( IWidget_SetBorderColor(piwListItem, MAKE_RGBA(255, 255, 255, 180)) );

ERR_TRY( IWidget_SetBGColor(piwListItem, MAKE_RGBA(157, 204, 255, 200)) );

ERR_TRY( IWidget_SetSelectedBGColor(piwListItem, MAKE_RGBA( 73, 163, 255, 255)) );

ERR_TRY( IWidget_SetShadowOffset(piwListItem, 0) );

// CI TypedValueModel
ERR_TRY( ISHELL_CreateInstance(pData->piShell, AEECLSID_TypedValueModel, (void**)&piTVM) );

// Attach a TypedValueModel to this widget
ERR_TRY( IWidget_SetModel(piwListItem, ITypedValueModel_to_IModel(piTVM)) );

ERR_TRY( IModel_AddListenerEx(CAST(IModel *,piTVM), &pData->ml[pData->nmlCount], (PFNLISTENER)listcontainerapp_ItemModelListener, (void*)&pData->piwList[pData->nmlCount]) );
// Set widget extent
weStatic.width = 200;
weStatic.height = 80;
IWidget_SetExtent(piwListItem, &weStatic);

*ppiwItem = piwListItem;
ADDREFIF(*ppiwItem);
pData->nmlCount++;

ERR_CATCH:
RELEASEIF(piwListItem);
RELEASEIF(piTVM);
RELEASEIF(picMainContainer);
RELEASEIF(pivm);
RELEASEIF(piwListItem);
RELEASEIF(piwImg);
RELEASEIF(piwName);
RELEASEIF(piwCmpny);
return nErr;

/*
Callback function to get the "item data" for a specific index.
*/
int listcontainerapp_GetItemData(void *pvCtx, int nIndex, int nState, ITypedValueModel *piTVM)
{
userContext *pUserData = (userContext *)pvCtx;
int nType = 0;
int nErr = 0;
CustomData *pData;
(void) nState;

ERR_TRY( IVectorModel_GetAt(pUserData->piVectorModel, /*int32touint32*/nIndex, (void *)&pData) );
ERR_TRY( listcontainerapp_GetItemType(pvCtx, nIndex, &nType) );
ERR_TRY( ITypedValueModel_SetValue(piTVM, 100, pData, sizeof(CustomData *), NULL, NULL) );

ERR_CATCH:
return nErr;

/*
Callback function to get total number of items in the list.
*/
int listcontainerapp_GetNumItems(void *pvCtx, int *pnNumItems)
{
userContext *pData = (userContext *)pvCtx;
*pnNumItems = IVectorModel_Size(pData->piVectorModel);
//*pnNumItems = 1;
return 0;

/*
Callback function for cleaning up user context.
*/
void listcontainerapp_CleanUp(void *pvCtx)
{
userContext *pData = (userContext *)pvCtx;
RELEASEIF(pData->piVectorModel);
RELEASEIF(pData->piResFile);

static void ListItem_Delete(CustomData *me)
{
FREE(me);

static int listcontainerapp_InitUserContext(listcontainerapp *me)
{
IVectorModel *piVectorModel;
CustomData *pData = NULL;
int i = 0;
int nErr = 0;

me->lcUserCtx.piShell = me->piShell;

RELEASEIF(me->lcUserCtx.piResFile);
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_ResFile, (void**)&me->lcUserCtx.piResFile) );
ERR_TRY( IResFile_Open(me->lcUserCtx.piResFile , LISTCONTAINERAPP_RES_FILE) );

ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_VectorModel, (void**) &piVectorModel) );

// Populate the vector model with the images & strings this list will display.
for( i = 0; i < 5; i++) {
pData = MALLOCREC(CustomData);
if (NULL == pData) ERR_THROW(AEE_EFAILED);
pData->nIdName = IDS_STR_NAME_1 + i;
pData->nIdCmpny = IDS_COMPANY_1 + i;
pData->nIdImg = IDI_PHOTO_1 + i;
ERR_TRY( IVectorModel_Add(piVectorModel, pData) );
}

(void)IVectorModel_SetPfnFree(piVectorModel, (PFNNOTIFY)ListItem_Delete);
me->lcUserCtx.piVectorModel = piVectorModel;

ERR_CATCH:
;
return nErr;

static int listcontainerapp_CreateListContainer(listcontainerapp *me)
{
IListContainerModelFactory *piLCMF = 0;
IListContainerModel *piLCM = 0;
IWidget *piw = 0;
WidgetExtent extent;
int nErr = 0;
int i;

RGBAVAL rgb_red = MAKE_RGBA(255,0,0,255); // red
RGBAVAL rgb_blue = MAKE_RGBA(0,0,255,255); // green

DBGPRINTF("Grid LC ClassID based");

ERR_TRY( ISHELL_CreateInstance(me->Applet.m_pIShell, AEECLSID_ListContainer, (void**)&piw) );

// Initialize user context
ERR_TRY( listcontainerapp_InitUserContext(me) );

// CI ListContainerModelFactory
ERR_TRY( ISHELL_CreateInstance(me->Applet.m_pIShell, AEECLSID_ListContainerModelFactory, (void**)&piLCMF) );
// Get ListContainerModel instance from CreateCallbackBased method of ListContainerModelFactory.
(void ) IListContainerModelFactory_CreateCallbackBased (piLCMF, &me->lcUserCtx,
listcontainerapp_GetItemType,
listcontainerapp_GetItemWidget,
listcontainerapp_GetItemData,
listcontainerapp_GetNumItems,
listcontainerapp_CleanUp,
&piLCM);

ERR_TRY( IWidget_SetModel(piw, IListContainerModel_to_IModel (piLCM)) );

(void) IWidget_SetFlags(piw, LWF_PIXELSCROLL|LWF_LIVESCROLL );

(void) IWidget_SetHintRows(piw, 10);
IWidget_GetPreferredExtent(piw, &extent);
extent.width = me->deviceInfo.cxScreen - 20;
extent.height = me->deviceInfo.cyScreen - 20;
IWidget_SetExtent(piw, &extent);

(void) IWidget_SetBorderWidth(piw, 5);
(void) IWidget_SetBorderColor(piw, rgb_red);
(void) IWidget_SetPadding(piw, 5);
(void) IWidget_SetBGColor(piw, rgb_blue);

me->piwListC = piw;
(void) IWidget_AddRef(me->piwListC);

ERR_CATCH:
RELEASEIF(piw);
RELEASEIF(piLCMF);
RELEASEIF(piLCM);

return nErr;

/*-----------------------------------------------------------------------------
Includes and Variable Definitions
-----------------------------------------------------------------------------*/
#include "AEEModGen.h" // Module interface definitions.
#include "AEEAppGen.h" // Applet interface definitions.
#include "AEEShell.h" // Shell interface definitions.

#include "listcontainerapp.bid"
#include "listcontainerapp_res.h"

#include "AEEStdLib.h"

//List container and widgets includes
#include "AEEITypedListModelFactory.h"
#include "AEEITypedListModel.h"
#include "AEEIListContainerModelFactory.h"
#include "AEEIListContainerModel.h"
#include "AEEIVectorModel.h"
#include "AEEIModel.h"
#include "AEEIValueModel.h"

#include "AEEListContainer.bid"
#include "AEEVectorModel.bid"
#include "AEETypedListModelFactory.bid"
#include "AEEListContainerModelFactory.bid"
#include "AEEListWidget.h"
#include "AEETypedValueModel.bid"

#include "AEEIWidget.h"
#include "AEEIRootContainer.h"
#include "AEEIPropContainer.h"
#include "AEEIDisplayCanvas.h"
#include "AEEIDecorator.h"
#include "AEEImageWidget.h"
#include "AEEIXYContainer.h"
#include "AEEStaticWidget.h"

#include "AEEWidgetProperties.h"
#include "AEEResFile.bid"
#include "AEERootContainer.bid"
#include "AEEImageWidget.bid"
#include "AEEDisplayCanvas.bid"
#include "AEEPropContainer.bid"
#include "AEEStaticWidget.bid"
#include "AEEModel.bid"
#include "AEEPointerHelpers.h"
#include "AEEWidgetElement.h"
#include "AEEXYContainer.bid"
#include "AEEWidgetTCProperties.h"
// generic free memory function
#ifndef VF_FREE
#define VF_FREE (GET_HELPER()->free)
#endif

// Error handling macros
#define ERR_CATCH __errcatch
#define ERR_TRY(x) do { nErr = (x); if (AEE_SUCCESS != nErr) goto ERR_CATCH; } while(0)
#define ERR_THROW(e) do { nErr = (e); goto ERR_CATCH; } while(0)
#define ERR_CHECK_PTR(p) if (NULL == p) { ERR_THROW(AEE_EFAILED); }

#ifndef RELEASEIF
#define RELEASEIF(p) listcontainerapp_ReleaseIf((IBase**)(void **)&p)
static void listcontainerapp_ReleaseIf(IBase **ppif) {
if (*ppif) {
IBASE_Release(*ppif);
*ppif = 0;
}

#endif

#ifndef ADDREFIF
#define ADDREFIF(p) do { if (p) IBASE_AddRef((IBase*) (void *) p); } while(0)
#endif

// clean casting macro
#ifndef CAST
#define CAST(t, exp) ((t)(void*)(exp))
#endif

typedef struct WidgetList{
IWidget *piwName;
IWidget *piwCmpny;
IWidget *piwImg;
IResFile *piResFile;
WidgetList;

typedef struct userContext
{
IVectorModel *piVectorModel;
IShell *piShell;
ModelListener ml[10];
WidgetList piwList[10];
int nmlCount;

IResFile *piResFile;
userContext;

typedef struct _listcontainerapp {
AEEApplet Applet; // First element of this structure must be AEEApplet.
IDisplay * piDisplay; // Copy of IDisplay Interface pointer for easy access.
IShell * piShell; // Copy of IShell Interface pointer for easy access.
AEEDeviceInfo deviceInfo; // Copy of device info for easy access.
// Add your own variables here...
IWidget *piwRoot;
IRootContainer *picRoot;
IWidget *piwListC;

userContext lcUserCtx;

listcontainerapp;

typedef struct _CustomData
{
int nIdName;
int nIdCmpny;
int nIdImg;
CustomData;

/*-----------------------------------------------------------------------------
Function Prototypes
-----------------------------------------------------------------------------*/
static boolean listcontainerapp_HandleEvent(listcontainerapp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean listcontainerapp_InitAppData(listcontainerapp* pMe);
void listcontainerapp_FreeAppData(listcontainerapp* pMe);
static void listcontainerapp_DrawScreen(listcontainerapp * pMe);

static int listcontainerapp_CreateListContainer(listcontainerapp *me);
/*-----------------------------------------------------------------------------
Function Definitions
-----------------------------------------------------------------------------*/

int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
void ** ppObj)
{
*ppObj = NULL;

// Confirm this applet is the one intended to be created (classID matches):
if( AEECLSID_LISTCONTAINERAPP == ClsId ) {
// Create the applet and make room for the applet structure.
// NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
if( TRUE == AEEApplet_New(sizeof(listcontainerapp),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)listcontainerapp_HandleEvent,
(PFNFREEAPPDATA)listcontainerapp_FreeAppData) ) {

// Initialize applet data. This is called before EVT_APP_START is
// sent to the HandleEvent function.
if(TRUE == listcontainerapp_InitAppData((listcontainerapp*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
// Release the applet. This will free the memory allocated for
// the applet when AEEApplet_New was called.
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;

boolean listcontainerapp_InitAppData(listcontainerapp * pMe)
{
// Save local copy for easy access:
pMe->piDisplay = pMe->Applet.m_pIDisplay;
pMe->piShell = pMe->Applet.m_pIShell;

// Get the device information for this handset.
// Reference all the data by looking at the pMe->deviceInfo structure.
// Check the API reference guide for all the handy device info you can get.
pMe->deviceInfo.wStructSize = sizeof(pMe->deviceInfo);
ISHELL_GetDeviceInfo(pMe->Applet.m_pIShell,&pMe->deviceInfo);

return TRUE;// No failures up to this point, so return success.

void listcontainerapp_FreeAppData(listcontainerapp * me)
{
// Insert your code here for freeing any resources you have allocated...
RELEASEIF(me->picRoot);
RELEASEIF(me->piwRoot);
RELEASEIF(me->piwListC);

static boolean listcontainerapp_HandleEvent(listcontainerapp* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {
// Event to inform app to start, so start-up code is here:
case EVT_APP_START:
listcontainerapp_DrawScreen(pMe); // Draw text on display screen.
return TRUE;

// Event to inform app to exit, so shut-down code is here:
case EVT_APP_STOP:
return TRUE;

// Event to inform app to suspend, so suspend code is here:
case EVT_APP_SUSPEND:
return TRUE;

// Event to inform app to resume, so resume code is here:
case EVT_APP_RESUME:
listcontainerapp_DrawScreen(pMe); // Redraw text on display screen.
return TRUE;

// An SMS message has arrived for this app.
// The Message is in the dwParam above as (char *).
// sender simply uses this format "//BREW:ClassId:Message",
// example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
return TRUE;

// A key was pressed:
case EVT_KEY:
return FALSE;

// Clamshell has opened/closed
// wParam = TRUE if open, FALSE if closed
case EVT_FLIP:
return TRUE;

// Clamtype device is closed and reexposed when opened, and LCD
// is blocked, or keys are locked by software.
// wParam = TRUE if keygaurd is on
case EVT_KEYGUARD:
return TRUE;

// If event wasn't handled here, then break out:
default:
break;
}
return (pMe->piwRoot == NULL)?FALSE: IWidget_HandleEvent(pMe->piwRoot, eCode, wParam, dwParam);

static void listcontainerapp_DrawScreen(listcontainerapp * me)
{
AEEResult nErr;
AEERect rect;
IDisplayCanvas *piDisplayCanvas = NULL;
ICanvas *piCanvas = NULL;

SETAEERECT(&rect, 0, 0, me->deviceInfo.cxScreen, me->deviceInfo.cyScreen);

// Create the root container that serves as the root of any widget tree
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_RootContainer, (void**)&me->picRoot) );
ERR_TRY( IRootContainer_QueryInterface(me->picRoot, AEEIID_IWidget, (void**)&me->piwRoot) );

// And give it a display canvas to use so we can see the widgets get drawn to the screen
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_DisplayCanvas, (void**)&piDisplayCanvas) );
ERR_TRY( IDisplayCanvas_SetDisplay(piDisplayCanvas, me->piDisplay) );
ERR_TRY( IDisplayCanvas_QueryInterface(piDisplayCanvas, AEEIID_ICanvas, (void**)&piCanvas) );
IRootContainer_SetCanvas(me->picRoot, piCanvas, &rect);
DBGPRINTF("Enable touch on root");

ERR_TRY( IWidget_EnableTouch(me->piwRoot) );
// Give our canvas a nice neutral color.
ERR_TRY( IWidget_SetBGColor(me->piwRoot, MAKE_RGBA(0xCC, 0xCC, 0xCC, 0xFF)) );

{
WidgetPos wp;
WidgetExtent we = {0};

wp.bVisible = TRUE;

ERR_TRY( listcontainerapp_CreateListContainer(me) );

wp.x = 0;
wp.y = 0;
ERR_TRY( IRootContainer_Insert(me->picRoot, me->piwListC, WIDGET_ZTOPMOST, &wp) );

}

// If there have been no failures up to this point then return success
ERR_CATCH:
RELEASEIF(piCanvas);
RELEASEIF(piDisplayCanvas);
//return AEE_SUCCESS == nErr;

/********************************************
///////////////////////////////////////////
Create list container & widgets
*********************************************/
int IPropContainer_InsertEx(IPropContainer *me, IWidget *piw, uint16 nProp,
boolean bVisible, int16 padBefore, int16 padAfter)
{
AEEResult nErr;
WidgetProp wp;
wp.prop = nProp;
wp.bVisible = bVisible;

IWidget_SetPreferredExtent(piw, NULL);

ERR_TRY( IPropContainer_Insert(me, piw, WIDGET_ZNORMAL, &wp) );
ERR_TRY( IPropContainer_SetPaddingExact(me, piw, padBefore, padAfter) );

ERR_CATCH:
return nErr;

int IWidget_SetStaticText(IWidget* piw, const AECHAR* textValue)
{
IValueModel *pivm = NULL;
AEEResult nErr;

if (NULL == piw) {
return AEE_EBADPARM;
}

ERR_TRY( IWidget_GetModel(piw, AEEIID_IValueModel, CAST(IModel**, &pivm)) );

IValueModel_SetValue(pivm, (void*)textValue, WSTRLEN(textValue), NULL);

ERR_CATCH:
RELEASEIF(pivm);
return nErr;

int listcontainerapp_CreateStaticWidget(IShell* piShell, const AECHAR* text, IWidget** ppiw, IFont *pif, uint32 flags)
{
AEEResult nErr;

ERR_TRY( ISHELL_CreateInstance(piShell, AEECLSID_StaticWidget, (void**)ppiw) );
ERR_TRY( IWidget_SetFlags(*ppiw, flags) );

if (NULL != pif) {
ERR_TRY( IWidget_SetFont(*ppiw, pif) );
}
if (NULL != text) {
ERR_TRY( IWidget_SetStaticText(*ppiw, text) );
}
ERR_CATCH:
if (AEE_SUCCESS != nErr) {
RELEASEIF(*ppiw);
}
return nErr;

/*
Callback function to get the "item type" at a specific index.
*/
int listcontainerapp_GetItemType (void *pvCtx, int nIndex, int *pnType)
{
(void)nIndex;
(void)pvCtx;
*pnType = 1;
return 0;

static int listcontainerapp_GetResString(IResFile *piResFile, int nResId, AECHAR **ppDest)
{
AEEResult nErr;
AECHAR *pwsz = NULL;
uint32 nLen = 0;

ERR_TRY( IResFile_Get(piResFile, (uint32)nResId, RESTYPE_STRING, (AECHAR*)-1, &nLen) );

if (nLen > 2) {
pwsz = MALLOC(nLen);
if (NULL == pwsz) {
ERR_THROW(AEE_ENOMEMORY);
}
}

ERR_TRY( IResFile_Get(piResFile, (uint32)nResId, RESTYPE_STRING, pwsz, &nLen) );

*ppDest = pwsz;

ERR_CATCH:
if (AEE_SUCCESS != nErr) {
*ppDest = NULL;
FREEIF(pwsz);
}
return nErr;

static int listcontainerapp_GetResImage(IResFile *piResFile, int nResId, IImage** ppDest)
{
AEEResult nErr;
void *pObj = NULL;

ERR_TRY( IResFile_GetObject(piResFile, (uint32)nResId, AEECLSID_VIEW, &pObj) );

*ppDest = pObj;

ERR_CATCH:
return nErr;

void listcontainerapp_ItemModelListener(WidgetList* me, ModelEvent *pEvent)
{
AEEUID nType;
CustomData *pValue; int nLen;
AECHAR *pszTxt;
IImage *pii = NULL;
AEEResult nErr;

ERR_TRY( ITypedValueModel_GetValue(CAST(ITypedValueModel *,pEvent->pModel), &nType, (void **)&pValue, &nLen));

ERR_TRY( listcontainerapp_GetResString(me->piResFile, pValue->nIdName, &pszTxt));
ERR_TRY( IWidget_SetStaticText(me->piwName, pszTxt) );

ERR_TRY( listcontainerapp_GetResString(me->piResFile, pValue->nIdCmpny, &pszTxt) );
ERR_TRY( IWidget_SetStaticText(me->piwCmpny, pszTxt) );

ERR_TRY( listcontainerapp_GetResImage(me->piResFile, pValue->nIdImg, &pii) );
ERR_TRY( IWidget_SetImage(me->piwImg, pii) );
RELEASEIF(pii);

ERR_CATCH:
;

/*
Callback function to get the "item widget" of certain type.
*/
int listcontainerapp_GetItemWidget(void *pvCtx, int nType, int nState, IWidget **ppiwItem)
{
ITypedValueModel *piTVM =NULL;
WidgetExtent weStatic;
userContext *pData = (userContext *)pvCtx;

IPropContainer *picMainContainer = NULL;
IValueModel *pivm = NULL;
IWidget *piwListItem = NULL;
IWidget *piwName = NULL;
IWidget *piwImg = NULL;
IWidget *piwCmpny = NULL;
int nErr;
(void) nType; (void) nState;
pData->piwList[pData->nmlCount].piResFile = pData->piResFile;

// Create the image
ERR_TRY( ISHELL_CreateInstance(pData->piShell, AEECLSID_ImageWidget, (void**)&piwImg) );
ERR_TRY( IWidget_SetFlags(piwImg, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE) );
pData->piwList[pData->nmlCount].piwImg = piwImg ;

// Create static widget that holds the name
ERR_TRY( listcontainerapp_CreateStaticWidget(pData->piShell, NULL, &piwName, 0,
IDF_ALIGN_LEFT | IDF_ALIGN_TOP) );

pData->piwList[pData->nmlCount].piwName = piwName;

// Create static widget that holds the company name
ERR_TRY( listcontainerapp_CreateStaticWidget(pData->piShell, NULL, &piwCmpny, 0,
IDF_ALIGN_LEFT | IDF_ALIGN_TOP) );
pData->piwList[pData->nmlCount].piwCmpny = piwCmpny;

// Create Prop Container for list item
ERR_TRY( ISHELL_CreateInstance(pData->piShell, AEECLSID_PropContainer, (void**)&picMainContainer) );

//Insert the image into container
ERR_TRY( IPropContainer_InsertEx(picMainContainer, piwImg, WIDGET_KEEP_EXTENT, TRUE, 0, 0) );

// Insert from name and company into a container
ERR_TRY( IPropContainer_InsertEx(picMainContainer, piwName, WIDGET_KEEP_EXTENT, TRUE, 2, 0) );
ERR_TRY( IPropContainer_InsertEx(picMainContainer, piwCmpny, WIDGET_KEEP_EXTENT, TRUE, 2, 0) );

ERR_TRY( IPropContainer_QueryInterface(picMainContainer, AEEIID_IWidget, (void**)&piwListItem) );
ERR_TRY( IWidget_SetLayoutStyle(piwListItem, AEEWIDGET_LAYOUT_VERT) );

ERR_TRY( IWidget_SetBorderWidth(piwListItem, 1) );
ERR_TRY( IWidget_SetBorderColor(piwListItem, MAKE_RGBA(255, 255, 255, 180)) );

ERR_TRY( IWidget_SetBGColor(piwListItem, MAKE_RGBA(157, 204, 255, 200)) );

ERR_TRY( IWidget_SetSelectedBGColor(piwListItem, MAKE_RGBA( 73, 163, 255, 255)) );

ERR_TRY( IWidget_SetShadowOffset(piwListItem, 0) );

// CI TypedValueModel
ERR_TRY( ISHELL_CreateInstance(pData->piShell, AEECLSID_TypedValueModel, (void**)&piTVM) );

// Attach a TypedValueModel to this widget
ERR_TRY( IWidget_SetModel(piwListItem, ITypedValueModel_to_IModel(piTVM)) );

ERR_TRY( IModel_AddListenerEx(CAST(IModel *,piTVM), &pData->ml[pData->nmlCount], (PFNLISTENER)listcontainerapp_ItemModelListener, (void*)&pData->piwList[pData->nmlCount]) );
// Set widget extent
weStatic.width = 200;
weStatic.height = 80;
IWidget_SetExtent(piwListItem, &weStatic);

*ppiwItem = piwListItem;
ADDREFIF(*ppiwItem);
pData->nmlCount++;

ERR_CATCH:
RELEASEIF(piwListItem);
RELEASEIF(piTVM);
RELEASEIF(picMainContainer);
RELEASEIF(pivm);
RELEASEIF(piwListItem);
RELEASEIF(piwImg);
RELEASEIF(piwName);
RELEASEIF(piwCmpny);
return nErr;

/*
Callback function to get the "item data" for a specific index.
*/
int listcontainerapp_GetItemData(void *pvCtx, int nIndex, int nState, ITypedValueModel *piTVM)
{
userContext *pUserData = (userContext *)pvCtx;
int nType = 0;
int nErr = 0;
CustomData *pData;
(void) nState;

ERR_TRY( IVectorModel_GetAt(pUserData->piVectorModel, /*int32touint32*/nIndex, (void *)&pData) );
ERR_TRY( listcontainerapp_GetItemType(pvCtx, nIndex, &nType) );
ERR_TRY( ITypedValueModel_SetValue(piTVM, 100, pData, sizeof(CustomData *), NULL, NULL) );

ERR_CATCH:
return nErr;

/*
Callback function to get total number of items in the list.
*/
int listcontainerapp_GetNumItems(void *pvCtx, int *pnNumItems)
{
userContext *pData = (userContext *)pvCtx;
*pnNumItems = IVectorModel_Size(pData->piVectorModel);
//*pnNumItems = 1;
return 0;

/*
Callback function for cleaning up user context.
*/
void listcontainerapp_CleanUp(void *pvCtx)
{
userContext *pData = (userContext *)pvCtx;
RELEASEIF(pData->piVectorModel);
RELEASEIF(pData->piResFile);

static void ListItem_Delete(CustomData *me)
{
FREE(me);

static int listcontainerapp_InitUserContext(listcontainerapp *me)
{
IVectorModel *piVectorModel;
CustomData *pData = NULL;
int i = 0;
int nErr = 0;

me->lcUserCtx.piShell = me->piShell;

RELEASEIF(me->lcUserCtx.piResFile);
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_ResFile, (void**)&me->lcUserCtx.piResFile) );
ERR_TRY( IResFile_Open(me->lcUserCtx.piResFile , LISTCONTAINERAPP_RES_FILE) );

ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_VectorModel, (void**) &piVectorModel) );

// Populate the vector model with the images & strings this list will display.
for( i = 0; i < 5; i++) {
pData = MALLOCREC(CustomData);
if (NULL == pData) ERR_THROW(AEE_EFAILED);
pData->nIdName = IDS_STR_NAME_1 + i;
pData->nIdCmpny = IDS_COMPANY_1 + i;
pData->nIdImg = IDI_PHOTO_1 + i;
ERR_TRY( IVectorModel_Add(piVectorModel, pData) );
}

(void)IVectorModel_SetPfnFree(piVectorModel, (PFNNOTIFY)ListItem_Delete);
me->lcUserCtx.piVectorModel = piVectorModel;

ERR_CATCH:
;
return nErr;

static int listcontainerapp_CreateListContainer(listcontainerapp *me)
{
IListContainerModelFactory *piLCMF = 0;
IListContainerModel *piLCM = 0;
IWidget *piw = 0;
WidgetExtent extent;
int nErr = 0;
int i;

RGBAVAL rgb_red = MAKE_RGBA(255,0,0,255); // red
RGBAVAL rgb_blue = MAKE_RGBA(0,0,255,255); // green

DBGPRINTF("Grid LC ClassID based");

ERR_TRY( ISHELL_CreateInstance(me->Applet.m_pIShell, AEECLSID_ListContainer, (void**)&piw) );

// Initialize user context
ERR_TRY( listcontainerapp_InitUserContext(me) );

// CI ListContainerModelFactory
ERR_TRY( ISHELL_CreateInstance(me->Applet.m_pIShell, AEECLSID_ListContainerModelFactory, (void**)&piLCMF) );
// Get ListContainerModel instance from CreateCallbackBased method of ListContainerModelFactory.
(void ) IListContainerModelFactory_CreateCallbackBased (piLCMF, &me->lcUserCtx,
listcontainerapp_GetItemType,
listcontainerapp_GetItemWidget,
listcontainerapp_GetItemData,
listcontainerapp_GetNumItems,
listcontainerapp_CleanUp,
&piLCM);

ERR_TRY( IWidget_SetModel(piw, IListContainerModel_to_IModel (piLCM)) );

(void) IWidget_SetFlags(piw, LWF_PIXELSCROLL|LWF_LIVESCROLL );

(void) IWidget_SetHintRows(piw, 10);
IWidget_GetPreferredExtent(piw, &extent);
extent.width = me->deviceInfo.cxScreen - 20;
extent.height = me->deviceInfo.cyScreen - 20;
IWidget_SetExtent(piw, &extent);

(void) IWidget_SetBorderWidth(piw, 5);
(void) IWidget_SetBorderColor(piw, rgb_red);
(void) IWidget_SetPadding(piw, 5);
(void) IWidget_SetBGColor(piw, rgb_blue);

me->piwListC = piw;
(void) IWidget_AddRef(me->piwListC);

ERR_CATCH:
RELEASEIF(piw);
RELEASEIF(piLCMF);
RELEASEIF(piLCM);

return nErr;

Hi,
   In the above code focus is highlighting only for double click,How to Highlight this using single click.

Hi,
   In the above code focus is highlighting only for double click,How to Highlight this using single click.

Single click is not sent by list/prop container view model notifiers so I think item cannot be highlighted on single click.

Single click is not sent by list/prop container view model notifiers so I think item cannot be highlighted on single click.

HI Adhudase
I used the above code ..... i want to attach vertical scroll bar to the list container. for that i just modified the listcontainerapp_DrawScreen function with the scroll bar attached to the me->piwListC widget, but i am bale to see the scrolling part but not the scroll bar inside the scrolling section.. Please suggest how can i get it????? below is the code where i modified listcontainerapp_DrawScreen function.
 

static void listcontainerapp_DrawScreen(listcontainerapp * me)
 
{
 
   AEEResult nErr;
 
   AEERect  rect;
   WidgetExtent extent;
   IDisplayCanvas *piDisplayCanvas = NULL;
 
   ICanvas        *piCanvas        = NULL;
 
   IWidget* piwHandle;
 
   SETAEERECT(&rect, 0, 0, me->deviceInfo.cxScreen, me->deviceInfo.cyScreen);
 
   // Create the root container that serves as the root of any widget tree
 
   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_RootContainer, (void**)&me->picRoot) );
 
   ERR_TRY( IRootContainer_QueryInterface(me->picRoot, AEEIID_IWidget, (void**)&me->piwRoot) );
 
 
 //Create the View Port 
nErr =ISHELL_CreateInstance(me->piShell,AEECLSID_ViewportWidget,(void**)&me->pviewport);
 
//Create the Scroll bar
nErr =ISHELL_CreateInstance(me->piShell, AEECLSID_ScrollbarWidget , (void **)&me->pidScrollbar);
 
   // And give it a display canvas to use so we can see the widgets get drawn to the screen
 
   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_DisplayCanvas, (void**)&piDisplayCanvas) );
 
   ERR_TRY( IDisplayCanvas_SetDisplay(piDisplayCanvas, me->piDisplay) );
 
   ERR_TRY( IDisplayCanvas_QueryInterface(piDisplayCanvas, AEEIID_ICanvas, (void**)&piCanvas) );
 
   IRootContainer_SetCanvas(me->picRoot, piCanvas, &rect);
 
   DBGPRINTF("Enable touch on root");
 
 
   ERR_TRY( IWidget_EnableTouch(me->piwRoot) );
 
   // Give our canvas a nice neutral color.
 
   ERR_TRY( IWidget_SetBGColor(me->piwRoot, MAKE_RGBA(0xCC, 0xCC, 0xCC, 0xFF)) );
 
   {
 
      WidgetPos    wp;
 
      WidgetExtent we = {0};
 
 
 
      wp.bVisible = TRUE;
 
      ERR_TRY( listcontainerapp_CreateListContainer(me) );
//////scroll barr implementation/////////////////////
 
     IWidget_GetPreferredExtent(me->piwListC,&extent);
     extent.width = me->deviceInfo.cxScreen - 20;
 
     extent.height = me->deviceInfo.cyScreen - 20;
//IWidget_SetExtent(me->piwListC,&extent);
IWidget_SetExtent(me->pviewport,&extent);

IWidget_SetFlags(me->pidScrollbar,SBWF_NOAUTOHIDE|SCROLL_BOTH|SBWF_ARROWS|SBWF_FOCUSTRACK);
 
IWidget_SetScrollHandleWidth(me->pidScrollbar,10);
 
IDecorator_SetWidget((IDecorator*)me->pviewport,me->piwListC);
 
IDecorator_SetWidget((IDecorator*)me->pidScrollbar,me->pviewport);
 
IWidget_SetTargetWidget(me->pidScrollbar,me->pviewport);
 
      wp.x  = 0;
      wp.y = 0;
 
      ERR_TRY( IRootContainer_Insert(me->picRoot, me->pidScrollbar, WIDGET_ZTOPMOST, &wp) );
 
        }
 
      // If there have been no failures up to this point then return success
 
ERR_CATCH:
 
   RELEASEIF(piCanvas);
 
   RELEASEIF(piDisplayCanvas);
 
   //return AEE_SUCCESS == nErr;
 
}

 
Please help me how to get scroll bar attached to the above code what u have posted n wats wrong in my code.
 
Regards
gautam

HI Adhudase
I used the above code ..... i want to attach vertical scroll bar to the list container. for that i just modified the listcontainerapp_DrawScreen function with the scroll bar attached to the me->piwListC widget, but i am bale to see the scrolling part but not the scroll bar inside the scrolling section.. Please suggest how can i get it????? below is the code where i modified listcontainerapp_DrawScreen function.
 

static void listcontainerapp_DrawScreen(listcontainerapp * me)
 
{
 
   AEEResult nErr;
 
   AEERect  rect;
   WidgetExtent extent;
   IDisplayCanvas *piDisplayCanvas = NULL;
 
   ICanvas        *piCanvas        = NULL;
 
   IWidget* piwHandle;
 
   SETAEERECT(&rect, 0, 0, me->deviceInfo.cxScreen, me->deviceInfo.cyScreen);
 
   // Create the root container that serves as the root of any widget tree
 
   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_RootContainer, (void**)&me->picRoot) );
 
   ERR_TRY( IRootContainer_QueryInterface(me->picRoot, AEEIID_IWidget, (void**)&me->piwRoot) );
 
 
 //Create the View Port 
nErr =ISHELL_CreateInstance(me->piShell,AEECLSID_ViewportWidget,(void**)&me->pviewport);
 
//Create the Scroll bar
nErr =ISHELL_CreateInstance(me->piShell, AEECLSID_ScrollbarWidget , (void **)&me->pidScrollbar);
 
   // And give it a display canvas to use so we can see the widgets get drawn to the screen
 
   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_DisplayCanvas, (void**)&piDisplayCanvas) );
 
   ERR_TRY( IDisplayCanvas_SetDisplay(piDisplayCanvas, me->piDisplay) );
 
   ERR_TRY( IDisplayCanvas_QueryInterface(piDisplayCanvas, AEEIID_ICanvas, (void**)&piCanvas) );
 
   IRootContainer_SetCanvas(me->picRoot, piCanvas, &rect);
 
   DBGPRINTF("Enable touch on root");
 
 
   ERR_TRY( IWidget_EnableTouch(me->piwRoot) );
 
   // Give our canvas a nice neutral color.
 
   ERR_TRY( IWidget_SetBGColor(me->piwRoot, MAKE_RGBA(0xCC, 0xCC, 0xCC, 0xFF)) );
 
   {
 
      WidgetPos    wp;
 
      WidgetExtent we = {0};
 
 
 
      wp.bVisible = TRUE;
 
      ERR_TRY( listcontainerapp_CreateListContainer(me) );
//////scroll barr implementation/////////////////////
 
     IWidget_GetPreferredExtent(me->piwListC,&extent);
     extent.width = me->deviceInfo.cxScreen - 20;
 
     extent.height = me->deviceInfo.cyScreen - 20;
//IWidget_SetExtent(me->piwListC,&extent);
IWidget_SetExtent(me->pviewport,&extent);

IWidget_SetFlags(me->pidScrollbar,SBWF_NOAUTOHIDE|SCROLL_BOTH|SBWF_ARROWS|SBWF_FOCUSTRACK);
 
IWidget_SetScrollHandleWidth(me->pidScrollbar,10);
 
IDecorator_SetWidget((IDecorator*)me->pviewport,me->piwListC);
 
IDecorator_SetWidget((IDecorator*)me->pidScrollbar,me->pviewport);
 
IWidget_SetTargetWidget(me->pidScrollbar,me->pviewport);
 
      wp.x  = 0;
      wp.y = 0;
 
      ERR_TRY( IRootContainer_Insert(me->picRoot, me->pidScrollbar, WIDGET_ZTOPMOST, &wp) );
 
        }
 
      // If there have been no failures up to this point then return success
 
ERR_CATCH:
 
   RELEASEIF(piCanvas);
 
   RELEASEIF(piDisplayCanvas);
 
   //return AEE_SUCCESS == nErr;
 
}

 
Please help me how to get scroll bar attached to the above code what u have posted n wats wrong in my code.
 
Regards
gautam

HI Can anyone tell how to handle key events for the above code???????

HI Can anyone tell how to handle key events for the above code???????

Here is a code to attach scrollbar:
IWidget *piwScrollBar = NULL;
// Wrap scrollbar around list container.
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_ScrollbarWidget, (void**) &piwScrollBar));
IDecorator_SetWidget(CAST(IDecorator *, piwScrollBar), me->piwListC);
(void) IWidget_SetScrollStyle(piwScrollBar, SCROLL_VERT);
(void) IWidget_SetActiveScrollHandleColor(piwScrollBar, MAKE_RGBA(0,255,0,0));
(void) IWidget_SetInactiveScrollHandleColor(piwScrollBar, MAKE_RGBA(0,255,0,0));
(void) IWidget_SetScrollFillColor(piwScrollBar, MAKE_RGBA(0,0,199,0));

wp.x = 0;
wp.y = 0;
ERR_TRY( IRootContainer_Insert(me->picRoot, piwScrollBar/*me->piwListC*/, WIDGET_ZTOPMOST, &wp) );

RELEASEIF(piwScrollBar);
You mean doing some action on item selection/focus change? If yes, you need to add view model listener for list container and listen for model events. Here is sample code:
IModel *pimModel;
ModelListener ButtonListener;

LISTENER_Init((ModelListener *)&me->ButtonListener, Menu_BtnListener, (void *)me);
IWidget_GetViewModel(me->piwListC, &pimModel);
IMODEL_AddListener(pimModel, (ModelListener *)&me->ButtonListener);
IMODEL_Release(pimModel);

static void Menu_BtnListener(listcontainerapp *me, ModelEvent *pEvt)
{
uint32 val;
WidgetElemStateEvent* wese = (WidgetElemStateEvent*)pEvt;
switch(pEvt->evCode)
{
case EVT_MDL_FOCUS_CHANGE:
case EVT_MDL_SCROLL_CHANGE:
break;
case EVT_MDL_FOCUS_SELECT:
//show something
break;

 

Here is a code to attach scrollbar:
IWidget *piwScrollBar = NULL;
// Wrap scrollbar around list container.
ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_ScrollbarWidget, (void**) &piwScrollBar));
IDecorator_SetWidget(CAST(IDecorator *, piwScrollBar), me->piwListC);
(void) IWidget_SetScrollStyle(piwScrollBar, SCROLL_VERT);
(void) IWidget_SetActiveScrollHandleColor(piwScrollBar, MAKE_RGBA(0,255,0,0));
(void) IWidget_SetInactiveScrollHandleColor(piwScrollBar, MAKE_RGBA(0,255,0,0));
(void) IWidget_SetScrollFillColor(piwScrollBar, MAKE_RGBA(0,0,199,0));

wp.x = 0;
wp.y = 0;
ERR_TRY( IRootContainer_Insert(me->picRoot, piwScrollBar/*me->piwListC*/, WIDGET_ZTOPMOST, &wp) );

RELEASEIF(piwScrollBar);
You mean doing some action on item selection/focus change? If yes, you need to add view model listener for list container and listen for model events. Here is sample code:
IModel *pimModel;
ModelListener ButtonListener;

LISTENER_Init((ModelListener *)&me->ButtonListener, Menu_BtnListener, (void *)me);
IWidget_GetViewModel(me->piwListC, &pimModel);
IMODEL_AddListener(pimModel, (ModelListener *)&me->ButtonListener);
IMODEL_Release(pimModel);

static void Menu_BtnListener(listcontainerapp *me, ModelEvent *pEvt)
{
uint32 val;
WidgetElemStateEvent* wese = (WidgetElemStateEvent*)pEvt;
switch(pEvt->evCode)
{
case EVT_MDL_FOCUS_CHANGE:
case EVT_MDL_SCROLL_CHANGE:
break;
case EVT_MDL_FOCUS_SELECT:
//show something
break;

 

HI
 
Thanks for ur reply I was able to attach the scroll bar to the code but i want the focus to be moved wen i press DOWN key/Up Key events.
 
Regards
Gautam

HI
 
Thanks for ur reply I was able to attach the scroll bar to the code but i want the focus to be moved wen i press DOWN key/Up Key events.
 
Regards
Gautam

Passing all the key events (not handled by app) to root container handle event should take care of this. Make sure that return TRUE/ FALSE is not there in case EVT_KEY in your applet main handle event. By default it has return FALSE from EVT_KEY. In that case key events won't go to root container and in turn to list container.
 
Up/Down: changes focus. sends EVT_MDL_FOCUS_CHANGE event.
Select/OK: selects the item and sends EVT_MDL_FOCUS_SELECT.
 
Your app should take care of BG colors of item widget to distinguish selected/unselected/focused items.
Use IWidget_SetActiveBGColor, IWidget_SetSelectedActiveBGColor, IWidget_SetBGColor on list item widget to set the BG color for different states. (in listcontainerapp_GetItemWidget)

Passing all the key events (not handled by app) to root container handle event should take care of this. Make sure that return TRUE/ FALSE is not there in case EVT_KEY in your applet main handle event. By default it has return FALSE from EVT_KEY. In that case key events won't go to root container and in turn to list container.
 
Up/Down: changes focus. sends EVT_MDL_FOCUS_CHANGE event.
Select/OK: selects the item and sends EVT_MDL_FOCUS_SELECT.
 
Your app should take care of BG colors of item widget to distinguish selected/unselected/focused items.
Use IWidget_SetActiveBGColor, IWidget_SetSelectedActiveBGColor, IWidget_SetBGColor on list item widget to set the BG color for different states. (in listcontainerapp_GetItemWidget)

hi adhudase
FOR THE ABOVE CODE I HAD SET SOME STATIC WIDGET WHICH I WANT THE TEXT TO TICKER. I SET THE PROPERTY IWidget_SetProperty(piwCmpny, PROP_ANIMATE, TRUE); BUT STILL THE TICKERING IS NOT HAPPENING, CAN U PLS TELL WHAT MIGHT BE THE PROBLEM?????????????
regards
Gautam
 
 

hi adhudase
FOR THE ABOVE CODE I HAD SET SOME STATIC WIDGET WHICH I WANT THE TEXT TO TICKER. I SET THE PROPERTY IWidget_SetProperty(piwCmpny, PROP_ANIMATE, TRUE); BUT STILL THE TICKERING IS NOT HAPPENING, CAN U PLS TELL WHAT MIGHT BE THE PROBLEM?????????????
regards
Gautam
 
 

I tried calling IWidget_Animate(piwName, TRUE); or IWidget_SetProperty(piwName, PROP_ANIMATE, TRUE); after creating static widget in listcontainerapp_GetItemWidget() function and it worked for me. Please make sure that static text is long enough to scroll.

I tried calling IWidget_Animate(piwName, TRUE); or IWidget_SetProperty(piwName, PROP_ANIMATE, TRUE); after creating static widget in listcontainerapp_GetItemWidget() function and it worked for me. Please make sure that static text is long enough to scroll.

HI Adhudase
Thanks i was able to achieve it, the problem was wit the IWidget_SetExtent.
NOw i hav one more issue, i had set the focus on the first row whenever i start my application.but the tickering wont stop when the change the focus to the next row, it keeps tickering, what i need to do to stop it?????????????????
 
Regards
Gautam

HI Adhudase
Thanks i was able to achieve it, the problem was wit the IWidget_SetExtent.
NOw i hav one more issue, i had set the focus on the first row whenever i start my application.but the tickering wont stop when the change the focus to the next row, it keeps tickering, what i need to do to stop it?????????????????
 
Regards
Gautam

Hi Gautam, do you mean scrolling should happen for only focused item? If yes, then start/stop animation from view model listener on focus change event. Here is how I would do it.
void listcontainerapp_listviewlistener(listcontainerapp* me, ModelEvent *pEvt)
{
switch(pEvt->evCode)
{
.......
case EVT_MDL_FOCUS_CHANGE:
{
//stop animation of previously focused item
IWidget_Animate((me->lcUserCtx.piwList[me->prevfocus]).piwName, FALSE);
//start animation of currently focused teim. IWidget_Animate((me->lcUserCtx.piwList[pEvt->dwParam + 1]).piwName, TRUE);
//save focused item index for next focus change
me->prevfocus = pEvt->dwParam + 1;
}
break;
..........

Hi Gautam, do you mean scrolling should happen for only focused item? If yes, then start/stop animation from view model listener on focus change event. Here is how I would do it.
void listcontainerapp_listviewlistener(listcontainerapp* me, ModelEvent *pEvt)
{
switch(pEvt->evCode)
{
.......
case EVT_MDL_FOCUS_CHANGE:
{
//stop animation of previously focused item
IWidget_Animate((me->lcUserCtx.piwList[me->prevfocus]).piwName, FALSE);
//start animation of currently focused teim. IWidget_Animate((me->lcUserCtx.piwList[pEvt->dwParam + 1]).piwName, TRUE);
//save focused item index for next focus change
me->prevfocus = pEvt->dwParam + 1;
}
break;
..........

HI Adhudase
I was able to achive it. Thanks for ur support.........
 
Regards
Gautam
 

HI Adhudase
I was able to achive it. Thanks for ur support.........
 
Regards
Gautam
 

hi Adhudase,
For the above code i wanted to attach TAB widget. SO in the listcontainerapp_DrawScreen function the created the tab widgets and i decorated it to the me->piwListC widget, then i inserted the Tab widget to the root container. My problem is that when i traverse to the next tab i want to remove the list contianer, but as i have not insterted it i am not able to remove it. I can get the object of that decoratedwidget by using IDecorator_GetWidget, but how can i remove the list conatiner whcih i decorated it??????????
 
Regards 
Srinag
 

hi Adhudase,
For the above code i wanted to attach TAB widget. SO in the listcontainerapp_DrawScreen function the created the tab widgets and i decorated it to the me->piwListC widget, then i inserted the Tab widget to the root container. My problem is that when i traverse to the next tab i want to remove the list contianer, but as i have not insterted it i am not able to remove it. I can get the object of that decoratedwidget by using IDecorator_GetWidget, but how can i remove the list conatiner whcih i decorated it??????????
 
Regards 
Srinag
 

Passing taregt widget (second param) as NULL to IDecorator_SetWidget() should detach decorator from any child widgets.

Passing taregt widget (second param) as NULL to IDecorator_SetWidget() should detach decorator from any child widgets.

HI Adhudase,
 
I have one more issue to the code what i implemented above. I have mutiple images and text inside list container item. i want each item within the list item to be made actionable. but if i attach listener to the inside list items i m not getting item id for it.
Please suggest what should be the approach.
 
Regards
Gautam

HI Adhudase,
 
I have one more issue to the code what i implemented above. I have mutiple images and text inside list container item. i want each item within the list item to be made actionable. but if i attach listener to the inside list items i m not getting item id for it.
Please suggest what should be the approach.
 
Regards
Gautam

Please somebody reply
 
Regards
Gautam

Please somebody reply
 
Regards
Gautam

In that case you need to add listener for each item widget.

In that case you need to add listener for each item widget.